1. Two major decompositions:
System
State (Buttons)
Temperature
Controller (T, Fan)
Stack
Management (V,I,MOSFETS)
Hydrogen
Control (Sensors, Valves)
Another
student suggested that we have a separate sensor and safety task.
Good
idea from engineering partitioning perspective but it results in lots of
communication and
potential
unreliability in the safety channel.
2. One had defined all of the messages that have to
back and forth -- signals and shared memory
System: send MODE, receive:
TOOHOT,TOOCOLD,WARM,OVERLOAD,ILEAK,H2LEAK
Temp:
send TOOHOT, TOOCOLD, WARM. Receive
MODE
Stack:
send OVERLOAD, STACK, ILEAK. Receive MODE
H2:
send H2LEAK, receive STACK, MODE
3. Types of communication:
Shared
Variable (missed events and multiple reads are okay),
Signals (must guarantee one
read per event)
4. How to deal with shared variables (depends on
what happens more often)
copy-on-write
(asynchronous, update latency)
copy-on-read
(latest value, but read delay is high)
5. What should this might look like from a
programmer's perspective
key_numbers.h
//pipe
ids
#define
MSG 1
//shared
variable ids
#define
STATE 1
#define
STACK 2
//states
#define
STARTUP 0
#define
WARMUP 1
...
//messages
#define
TOOHOT 0x01
#define
OVRLD 0x02
#define
ILEAK 0x04
...
#include
key_numbers.h
//
void
modeControl() {
signal(SIGERR,
shutdown);
//
initializations
publish(STATE,
CW); // declare that this task will be
the writer for STATE and will use Copy-on-Write policy
subscribe(STATE,CW); // blocking, must have an error procedure
messages
m = pipe(MSG,READONLY);
//
startup routine
post(STATE,STARTUP); // local subscriptions will be
updated immediately
start
= getTime();
while
(timeDiff(start,getTime() < 60) { //
stay in STARTUP for 60 seconds
if (read(m,&msg)) { // meanwhile look for error conditions
if
(msg & (TOOHOT | TOOCOLD | ILEAK | HLEAK))
post(STATE,SHUTDOWN);
shutdown();
}
}
post(STATE,
WARMUP); // local subscriptions
updated
turn_on_main_h2_valve();
while(1)
{
if (read(m,&msg)) {sh
switch(msg)
{
WARM:
post(STATE,WARMUP);
break;
...
}
}
}
}
void
shutdown() {
post(STATE,SHUTDOWN);
turn_off_main_h2_valve();
while(1);
}
-------------------
now let's look at the H2 controll task --------------
#include
key_numbers.h
void
H2() {
signal(SIGERR,
shutdown);
//
initializations
int
state = STARTUP;
int
current_state = STARTUP;
subscribe(STATE,CW);
// need time out and error procedure
subscribe(STACK,CW);
messages
m;
m
= pipe(MSG,WRITEONLY); // blocking --
timeout and error procedure
//
startup routine
close_all_valves();
stay_closed = false;
while(1)
{
update(STATE,
&state);
update(STACK,&stack);
if
(current_state != state)
switch(state)
{
STARTUP:
close_all_valves();
WARMUP:
if (!stay_closed) open_all_valves();
SHTDN:
shutdown();
}
if
(state == (ONLINE | OFFLINE))
if
(!stay_closed) set_valves_accordiing_to_stack(stack);
if
(detect_H2()) {
close_all_valves();
stay_closed
= true;
write(m,H2LEAK);
}
}
}
void
shutdown() {
close_all_valves();
stay_closed
= true;
while(1);
}
6. Discuss layers: application, session, datalink,
physical
-
Modularity
- Spooling
(non-blocking semantics)
-
Virtual Connections between layers (horizontal)
-
Actual Connections between layers (veritical)
7. Questions for Monday Discussion:
what does publish() do in the session layer?
what does subscribe do in the session layer ?.
what does post do in the session layer?
How does the session layer process incoming data
from the data-link layer?
How does the data-link layer process incoming data
from the session layer?
How do the two layer share data?