stationeers.de Mod workshop · Dominik1199
DE Sign in
  1. Home
  2. IC10 academy
  3. Day 346

Day 346 of 365 · Expert · Month 12: Masterpieces

Big project: interfaces

Interfaces of a big project: define memory addresses, document the protocol as a table and a version number every chip checks before executing commands.

Lesson 22 min Week 50

What you learn today

  • Fix memory addresses
  • Document the protocol
  • Versions

Two chips that talk to each other need a common language. For people that is a protocol on paper, for chips a list of addresses with a fixed meaning. Without that list, sooner or later one chip writes the temperature where another expects the battery level.

Defining memory addresses

For a few values one Logic Memory per value is enough. When there are many, a data bus pays off: the stack of a housing of its own, which all chips read and write via fixed addresses. get reads an address, put writes it, and the chip fetches the ReferenceId of the bus housing via lbn:

define GEHAEUSE HASH("StructureCircuitHousing") # IC housing
lbn bus GEHAEUSE HASH("Datenbus") ReferenceId Average
get version bus 0          # address 0: interface version
get value bus 3            # address 3: power status
put bus 2 status           # address 2: only life support writes here

Documenting the protocol

Every address gets a line in a table that sits in every chip involved as a header comment or lives in the library next to the scripts:

AddressNameWriterMeaningRange
0Versioncentralinterface version1, 2, …
1Pulscentralheartbeatcounts up
2LS_Statuslife support0 ok, 1 warning, 2 fault0–2
3EN_Statuspower0 ok, 1 warning, 2 fault0–2
4EN_Auftragcentralload shedding stage0–2

Three columns are mandatory: who writes, what it means and which values are allowed. Anything outside the range is treated as an error by the reader.

Versions

Sooner or later you change the protocol: a field is added, a meaning changes. Then old and new chips run together for a while. So that this does not go wrong silently, the interface version sits at a fixed place. Every chip compares it with the version it understands itself and only executes commands if both match:

seq ok version SCHNITTSTELLE     # NaN or wrong version: 0
select command ok command 0  # no command without the matching version

If the version does not match, the chip goes into the safe state, reports the error and writes its own version into its status. That way the central unit sees immediately which chip still speaks the old language.

Tip

Only raise the version when a meaning changes. If only a new field is added at the end that old chips do not read, the version stays the same.

Exercise

Task

Build the yard sub-chip. The central unit writes the interface version into “Bus_Version” and a command into “Bus_Befehl” (bit 0 light “Hof”, bit 1 pump “Brunnen”). This chip understands version 2. If the version does not match or a memory is missing: both outputs off, flashing light “Versionsfehler” on. In the status “Bus_Status”: bit 0 light, bit 1 pump, bit 2 fault, from bit 8 its own version (4 bits).

Hints

Hint 1

seq ok version SCHNITTSTELLE – NaN gives 0. Plus snanz for the command.

Hint 2

Without ok set the command to 0, then take the two bits with ext.

Hint 3

Insert the own version with ins status SCHNITTSTELLE VERSIONSBIT 4.

Quiz

4 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

Esc
↑ ↓ selectEnter open/ opens search anywhere