What you learn today
- Messages from id and value
- Acknowledgement
- Ordering
A chip in the control room should tell a chip in the pump station what to do: pump on, setpoint 250, toggle the light. A logic memory between the two holds exactly one number. To turn that into a conversation, you need an agreement – a protocol.
Messages from id and value
A message has three parts, packed into one number:
| Bits | Field | Meaning |
|---|---|---|
| 0–15 | value | 0 to 65535 |
| 16–23 | id | what to do |
| 24–31 | number | running number of the message |
You define the ids and write them into both chips:
| Id | Command |
|---|---|
| 1 | pump “Haupt” on or off (value 1 or 0) |
| 2 | show setpoint |
| 3 | toggle light |
The sender packs with ins:
move msg value
ins msg id 16 8
ins msg seq 24 8
sbn MEMORY HASH("Postfach") Setting msg
Acknowledgement
The receiver reads the mailbox, executes the command and writes the message number into a second memory, the acknowledgement. From that the sender sees that its message has arrived.
Ordering and double execution
A logic memory keeps its value. So the receiver reads the same message again every tick. For “pump on” that does not matter, for “toggle light” it does: the light would toggle twice per second. Hence the number: the receiver remembers the last one and only executes when a new one arrives.
ext seq msg 24 8
beq seq last start # already handled
move last seq
For the ordering there is one rule: the sender only sends the next message once the acknowledgement shows its number. Otherwise it overwrites a message nobody has read yet. After 255 the number starts at 0 again – it only has to differ from the last one.
After a restart of the receiver, last is 0 at first. If an old message is still in the mailbox, it would execute it a second time. So read the acknowledgement into last at start – it holds the number that was handled most recently.
Diagram
Exercise
Task
Write the receiver. The mailbox “Postfach” holds messages following the table above:
- id 1: pump “Haupt”
On= value - id 2: display “Soll” = value
- id 3: toggle light “Licht”
- execute each new number exactly once, ignore unknown ids
- then write the number into “Quittung”
- if the mailbox is missing, nothing happens
Hints
Hint 1
ext seq msg 24 8, then beq seq last start – old message, do nothing.
Hint 2
For each id a bne id N next before the action.
Hint 3
Toggle: read the light, seqz, write back.
Quiz
3 questions. You pass from 60 % – the server does the grading.
Complete the day
- Passed the simulator exercise
- Passed the quiz with at least 60 %
Without an account progress is saved in this browser only.
Report a mistake in this lesson
Please sign in to report. Sign in