-
Notifications
You must be signed in to change notification settings - Fork 3
Messages
This library has been implemented using message structs that simplifies the management of communications between threads in case of using OS based applications.
The motion control bus protocol defines two communications states that use two different message types:
Configuration messages are stored into the next struct:
/** Frame data struct */
typedef struct
{
/** Destination / source node */
uint16_t u16Node;
/** Target register address */
uint16_t u16Addr;
/** Master / slave command */
uint16_t u16Cmd;
/** Message total size (words) */
uint16_t u16Size;
/** Static data */
uint16_t u16Data[MCB_MAX_DATA_SZ];
/** Message status */
Mcb_EStatus eStatus;
} Mcb_TMsg;
Mcb_Write & Mcb_Read are the functions used to operate with configuration messages. The arguments of these functions are Mcb_TMsg which are use as input and outputs. The operation steps are:
- Create and / or fill a Mcb_TMsg (Fields: u16Node, u16Addr, u16Size and u16Data)
- Send the message as argument of Mcb_Write or Mcb_Read
- Process the overwritten message to see the result: eStatus indicates the result of the operation, the other parameters contains the reply of the slave.
In blocking mode, both functions blocks the program until they get the reply of the slave or a timeout expires, so the returned eStatus might be:
- MCB_SUCCESS
- MCB_WRITE_ERROR
- MCB_READ_ERROR
- MCB_ERROR
In non-blocking mode, the developer must managed all the states of the write/read operation:
/** Transmission successful */
- MCB_SUCCESS
/** Bus in stand by */
- MCB_STANDBY
/** Sending a write request */
- MCB_WRITE_REQUEST
/** Processing answer from write request */
- MCB_WRITE_ANSWER
/** Sending a read request */
- MCB_READ_REQUEST
/** Processing answer from read request */
- MCB_READ_ANSWER
/** Write config request error */
- MCB_WRITE_ERROR
/** Read config request error */
- MCB_READ_ERROR
/** Transaction error */
- MCB_ERROR
Cyclic messages have been designed to get a high update loop rate of critical task for control purpose. The configuration and use of cyclics requires the next steps:
- Mapping the desired registers. This procedure configures the slaves to synchronize the data into the frames. The functions Mcb_TxMap and Mcb_RxMap returns a pointer to these frames so the user is able to use exchanged data as standard variables.
- Enabling cyclic mode into the slave. Mcb_SetCyclicMode is the responsible of enabling the cyclic capabilities of the slave
- Calling cyclic process periodically. The cycle of the communications is fully managed by the master, so the user is the responsible of calling periodically the Mcb_CyclicProcess (Mcb_CyclicProcessLatch and Mcb_CyclicFrameProcess from version 0.4.8. or higher).
Once the cyclic mode is enabled, the configuration messages are transmitted through cyclic messages so special function must be activated in order to keep configuration messages active.
A user function callback must be linked to cyclic process through the Mcb_AttachCfgOverCyclicCB function. Then the Mcb_Write & Mcb_Read will request a configuration transmission but instead of blocking the thread until the slave reply, it will return immediately and the linked functin will be called once the transmission is finished.