Interfaces

The interesting interfaces are defined in the temu-c/Bus/Spacewire.h header.

typedef enum {
  teSMT_Data = 1,
  teSMT_Err = 2,
  teSMT_Time = 3,
} temu_SpwPacketType;

typedef struct temu_SpwPacket {
  temu_SpwPacketType MsgType;
  temu_Buff PktData;
  uint8_t Flags;
} temu_SpwPacket;

typedef enum {
  teSPWLS_ErrorReset = 1,
  teSPWLS_Ready = 2,
  teSPWLS_Started = 3,
  teSPWLS_Connecting = 4,
  teSPWLS_Run = 5
} temu_SpwLinkState;

struct temu_SpwPortIface {
  void (*receive)(void *Device, void *Sender, temu_SpwPacket *Pkt);
  void (*signalLinkStateChange)(void* Device, temu_SpwLinkState LinkState);
  temu_SpwLinkState (*getOtherSideLinkState)(void* Device);
  void (*connect)(void *Device, temu_SpwPortIfaceRef Dest);
  void (*disconnect)(void *Device);
  uint64_t (*timeToSendPacketNs)(void* Device, uint64_t PacketLength);
};

While the SpaceWire protocol is character based, to have better performances TEMU transfers full messages with a single call on the port interface. Example of messages are a data packet, an RMAP packet and a time code. Control characters like FCT (flow control) are abstracted away.

The SpaceWire packet structure is used to pass a packet between nodes. The MsgType field identifies if the packet is a timecode, a complete data packet (ending with EOP) or an incomplete data packet (ending with EEP). The PktData field contains the packet data or the time code value.

A TEMU buffer is used to hold the data. This data structure has been implemented to handle SpaceWire packets in a performant way. It allows to acquire a reference to a part of the original data so that a copy of data is not required for each node due to wormhole routing stripping. It also free the memory used to store the original message when no more references are active. This way, destination devices can maintain the data as long as needed without coping it.

SpaceWire links are full-duplex. The SpaceWire link is modeled by simply having each device implementing a port interface and holding a reference to other end port. This allows comunication in both directions simultaneously.

SpaceWire devices often have several connections port. The SpwPortIface is meant to be implement for each port a device intends to provide.

temu-c/Bus/Spacewire.h header also define functions to help decode RMAP packets:

Name Description

temu_spwRmapDecodePacket

Provided a SpaceWire Rmap packet attempts to decode it.

temu_spwRmapDecodeBuffer

Provided a buffer containing a SpaceWire Rmap packet attempts to decode it.

temu_spwRmapHeaderReplySize

Returns the total packet-size required to reply to the command.

temu_spwRmapEncodeReadReplyHeaderForPacket

Encodes the reply for a read command.

temu_spwRmapEncodeRmwHeaderForPacket

Encodes the reply for a rmw command.

temu_spwRmapEncodeWriteReplyHeaderForPacket

Encodes the reply for a write command.

temu_spwRmapCRCNextCode

Provided the previous calculated crc and a the current byte returns the next CRC value.

temu_spwRmapCRC

Calculates the CRC over the specified data.