ModuleCommunication

class

Abstract class that defines redpine module communication through a hardware interface. Subclasses of this should utilize UART, USB or SPI communication.

Public Functions

virtual bool mono::redpine::ModuleCommunication::initializeInterface()
= 0

Send a interface initialization command to the module.

virtual void mono::redpine::ModuleCommunication::resetModule()
= 0

Trigger the reset line to the module. A reset will put the module into bootloader, where a firmware image can be selected. Before calling initializeInterface, you must reset the module.

The reset command has to wait while the module resets, this means the function will block for approx 3 ms.

virtual bool ModuleCommunication::bufferIsMgmtFrame(DataReceiveBuffer &buffer)

Test the data inside a buffer to see if it is a management frame

Parameters
  • buffer -

    The buffer to test

virtual bool ModuleCommunication::bufferIsDataFrame(DataReceiveBuffer &buffer)

Test if a buffer is a data Frame

virtual bool mono::redpine::ModuleCommunication::pollInputQueue()
= 0

Polls the module for waiting input data. This can be frame responses or any other data, waiting to be read by us.

The method uses the current communication interface method to wait for pending input data. This function blocks, until data is ready.

This function can be used it interrupts are not applicable

Return
true if there is data to read, false otherwise

virtual bool mono::redpine::ModuleCommunication::interruptActive()
= 0

Return true if interrupt is active.

The module will keep the interrupt pin high until no more input is present.

virtual bool mono::redpine::ModuleCommunication::readFrame(DataReceiveBuffer &rawFrame)
= 0

Read the frame header (the first 16 bytes)

Use this to probe what kind of frame is coming from the module and read the frame payload later using the dedicated methods.

Return
True on read success, false otherwise
Parameters
  • rawFrame -

    A pointer to the pre-alloced memory to hold the header

virtual bool mono::redpine::ModuleCommunication::readManagementFrame(DataReceiveBuffer &buffer, ManagementFrame &frame)
= 0

Read the first available frame from the modules input queue This function should be called when you are sure there is data pending

Return
True on success, false otherwise
Parameters
  • frame -

    A reference to management frame placeholder object

virtual bool mono::redpine::ModuleCommunication::readManagementFrameResponse(DataReceiveBuffer &buffer, ManagementFrame &request)
= 0

Read a pending frame from the module, and interpret it as a response to an earlier frame.

The response frame (the one that is read) and the provided frame (the request), are compared by commandId and the response status is validated.

This there is any response payload data, this data is passed to the request frames ManagementFrame::responsePayloadHandler function.

When this method returns the request frame object is converted to an response frame (RX_FRAME) with status and any payload data.

Return
true on success, false otherwise.
Parameters
  • request -

    A reference to the request frame, that is awaiting a response

virtual bool mono::redpine::ModuleCommunication::readDataFrame(DataReceiveBuffer &buffer, DataPayloadHandler &payloadHandler)
= 0

Read a pending frame a Data frame.

Data frame arrive out-of-order with anything else. Also, we expect that they deliver data to any open socket. This method read the data from the module and call the DataPayloadHandler function provided. This function then takes care of the actual data payload!

Return
trueon succs, false otherwise
Parameters
  • payloadHandler -

    A reference the data payload callback handler

virtual uint16_t mono::redpine::ModuleCommunication::readMemory(uint32_t memoryAddress)
= 0

Internal function to read from a memory address. This is used when communicating with the Redpine Modules Bootloader.

Return
The 16-bit content of that address
Parameters
  • memoryAddress -

    The address position to read from

virtual void mono::redpine::ModuleCommunication::writeMemory(uint32_t memoryAddress, uint16_t value)
= 0

Method to write to the module memory. This can be used when communicating with the bootloader of the module.

Parameters
  • memoryAddress -

    The address to write to

  • value -

    The 16-bit value to write at the address

virtual bool mono::redpine::ModuleCommunication::writeFrame(ManagementFrame *frame)
= 0

Send a frame to the module

Return
true on success, false otherwise
Parameters
  • frame -

    A pointer to the frame to send

virtual bool mono::redpine::ModuleCommunication::writePayloadData(const uint8_t *data, uint16_t byteLength, bool force4ByteMultiple)
= 0

Sends a frame’s payload data to the module.

This payload data must be sent after the command / management frame has been sent to the module.

This format of the data is determined by which command that was sent by the Command/Management frame. The RS9113 Software PRM is not clear on this data frame matter. But this code is from reverse engineering the example code by RSI.

Return
true upon success, false otherwise.
Parameters
  • data -

    A pointer to the raw data to write to the module

  • byteLength -

    The length of the data in bytes

  • force4ByteMultiple -

    Optional: Set to false, to bot enforce payload to be a 4-byte multiple

Public Members

uint16_t mono::redpine::ModuleCommunication::InterfaceVersion

Defines the communication protocol version to use. Redpine change the way FrameDescriptor headers return frame length in bootloader version 1.6. Version 1.5 uses a slightly different procedure.

The Module should write the communication protocol version here. So far we have only seen the values:

  • Bootloader 1.5: 0xAB15
  • Bootloader 1.6: 0xAB16

mbed::FunctionPointer mono::redpine::ModuleCommunication::interruptCallback

Interrupt callback function, called by the communication interface. The module provides the callback function, that gets called when ever the module triggers an interrupt.

struct

Method that must be implemented, that will be called by the run loop It should only be scheduled by an hardware interrupt handler, and remove it self again from the run loop, after it has run.Structure to describe the data payload pointer and length for Data frame payloads