alStream

A MCU like STM32F405 have multiple serial devices and though their hardware is very different they perform the same job of sending/receiving ino. alStream is a base class for all components with a serial stream interface like USB, UART, CAN, SPI, I2C and even UDP/Ethernet. The objective is to provide a uniform messaging service where all interfaces of this type is equal except the Init() call that need to soft-wire the hardware. The draft consist of the following: 

  • Open() Open the stream.
  • Close() Close the stream.
  • Send() Send a message.
  • Receive() Receive a message.
  • SetReceiveTask() Set task to be notified  about received content.
  • SetSendTask() Set task to be notified about empty send queues.

The interface about will be repeated on all serial classes simply by using alSerial as base. alOS provide standard interface functions allowing alStream to interact with OS functions without any direct binding, so I use alOS::SetSignal() to make callbacks. That will signal a task to execute. Setting signals is better than a direct callback because it allows me to do the processing from within a tight interrupt routine. Also keep in mind that SetSignal increase a counter and that the task will be called once for each signal, meaning you have a natural mechanism for spreading bursts of messages out in time.

Leave a Reply