Files | |
file | CO_SDOserver.h |
CANopen Service Data Object - server protocol. | |
Data Structures | |
struct | CO_SDOserver_t |
SDO server object. More... | |
Macros | |
#define | CO_SDO_ST_FLAG_DOWNLOAD 0x10U |
Internal state flags indicate type of transfer. More... | |
Functions | |
CO_ReturnError_t | CO_SDOserver_init (CO_SDOserver_t *SDO, const OD_t *OD, const OD_entry_t *OD_1200_SDOsrvPar, uint8_t nodeId, uint16_t SDOtimeoutTime_ms, CO_CANmodule_t *CANdevRx, uint16_t CANdevRxIdx, CO_CANmodule_t *CANdevTx, uint16_t CANdevTxIdx) |
Initialize SDO object. More... | |
void | CO_SDOserver_initCallbackPre (CO_SDOserver_t *SDO, void *object, void(*pFunctSignalPre)(void *object)) |
Initialize SDOrx callback function. More... | |
CO_SDO_return_t | CO_SDOserver_process (CO_SDOserver_t *SDO, bool_t NMTisPreOrOperational, uint32_t timeDifference_us, uint32_t *timerNext_us) |
Process SDO communication. More... | |
CANopen Service Data Object - server protocol.
Service data objects (SDOs) allow the access to any entry of the CANopen Object dictionary. By SDO a peer-to-peer communication channel between two CANopen devices is established. In addition, the SDO protocol enables to transfer any amount of data in a segmented way. Therefore the SDO protocol is mainly used in order to communicate configuration data.
All CANopen devices must have implemented SDO server and first SDO server channel. Servers serves data from Object dictionary. Object dictionary is a collection of variables, arrays or records (structures), which can be used by the stack or by the application. This file (CO_SDOserver.h) implements SDO server.
SDO client can be (optionally) implemented on one (or multiple, if multiple SDO channels are used) device in CANopen network. Usually this is master device and provides also some kind of user interface, so configuration of the network is possible. Code for the SDO client is in file CO_SDOclient.h.
SDO communication cycle is initiated by the client. Client can upload (read) data from device or can download (write) data to device. If data size is less or equal to 4 bytes, communication is finished by one server response (expedited transfer). If data size is longer, data are split into multiple segments of request/response pairs (normal or segmented transfer). For longer data there is also a block transfer protocol, which transfers larger block of data in secure way with little protocol overhead. If error occurs during SDO transfer CO_SDO_abortCode_t is send by client or server and transfer is terminated. For more details see CO_SDO_state_t.
Access to Object dictionary is specified in OD interface.
#define CO_SDO_ST_FLAG_DOWNLOAD 0x10U |
Internal state flags indicate type of transfer.
These flags correspond to the upper nibble of the SDO state machine states and can be used to determine the type of state an SDO object is in.
enum CO_SDO_state_t |
Internal states of the SDO state machine.
Upper nibble of byte indicates type of state: 0x10: Download 0x20: Upload 0x40: Block Mode
Note: CANopen has little endian byte order.
Enumerator | |
---|---|
CO_SDO_ST_IDLE |
|
CO_SDO_ST_ABORT |
|
CO_SDO_ST_DOWNLOAD_LOCAL_TRANSFER |
|
CO_SDO_ST_DOWNLOAD_INITIATE_REQ |
|
CO_SDO_ST_DOWNLOAD_INITIATE_RSP |
|
CO_SDO_ST_DOWNLOAD_SEGMENT_REQ |
|
CO_SDO_ST_DOWNLOAD_SEGMENT_RSP |
|
CO_SDO_ST_UPLOAD_LOCAL_TRANSFER |
|
CO_SDO_ST_UPLOAD_INITIATE_REQ |
|
CO_SDO_ST_UPLOAD_INITIATE_RSP |
|
CO_SDO_ST_UPLOAD_SEGMENT_REQ |
|
CO_SDO_ST_UPLOAD_SEGMENT_RSP |
|
CO_SDO_ST_DOWNLOAD_BLK_INITIATE_REQ |
|
CO_SDO_ST_DOWNLOAD_BLK_INITIATE_RSP |
|
CO_SDO_ST_DOWNLOAD_BLK_SUBBLOCK_REQ |
|
CO_SDO_ST_DOWNLOAD_BLK_SUBBLOCK_RSP |
|
CO_SDO_ST_DOWNLOAD_BLK_END_REQ |
|
CO_SDO_ST_DOWNLOAD_BLK_END_RSP |
|
CO_SDO_ST_UPLOAD_BLK_INITIATE_REQ |
|
CO_SDO_ST_UPLOAD_BLK_INITIATE_RSP |
|
CO_SDO_ST_UPLOAD_BLK_INITIATE_REQ2 |
|
CO_SDO_ST_UPLOAD_BLK_SUBBLOCK_SREQ |
|
CO_SDO_ST_UPLOAD_BLK_SUBBLOCK_CRSP |
|
CO_SDO_ST_UPLOAD_BLK_END_SREQ |
|
CO_SDO_ST_UPLOAD_BLK_END_CRSP |
|
enum CO_SDO_abortCode_t |
SDO abort codes.
Send with Abort SDO transfer message.
The abort codes not listed here are reserved.
enum CO_SDO_return_t |
Return values from SDO server or client functions.
CO_ReturnError_t CO_SDOserver_init | ( | CO_SDOserver_t * | SDO, |
const OD_t * | OD, | ||
const OD_entry_t * | OD_1200_SDOsrvPar, | ||
uint8_t | nodeId, | ||
uint16_t | SDOtimeoutTime_ms, | ||
CO_CANmodule_t * | CANdevRx, | ||
uint16_t | CANdevRxIdx, | ||
CO_CANmodule_t * | CANdevTx, | ||
uint16_t | CANdevTxIdx | ||
) |
Initialize SDO object.
Function must be called in the communication reset section.
SDO | This object will be initialized. |
OD | Object Dictionary. |
OD_1200_SDOsrvPar | OD entry for SDO server parameter (0x1200+), can be NULL for default single SDO server and must not be NULL for additional SDO servers. With additional SDO servers it may also have IO extension enabled, to allow dynamic configuration (see also CO_CONFIG_FLAG_OD_DYNAMIC). |
nodeId | If this is first SDO channel, then "nodeId" is CANopen Node ID of this device. In all additional channels "nodeId" is ignored. |
SDOtimeoutTime_ms | Timeout time for SDO communication in milliseconds. |
CANdevRx | CAN device for SDO server reception. |
CANdevRxIdx | Index of receive buffer in the above CAN device. |
CANdevTx | CAN device for SDO server transmission. |
CANdevTxIdx | Index of transmit buffer in the above CAN device. |
void CO_SDOserver_initCallbackPre | ( | CO_SDOserver_t * | SDO, |
void * | object, | ||
void(*)(void *object) | pFunctSignalPre | ||
) |
Initialize SDOrx callback function.
Function initializes optional callback function, which should immediately start processing of CO_SDOserver_process() function. Callback is called after SDOserver message is received from the CAN bus or when new call without delay is necessary (SDO block transfer is in progress).
SDO | This object. |
object | Pointer to object, which will be passed to pFunctSignalPre(). Can be NULL |
pFunctSignalPre | Pointer to the callback function. Not called if NULL. |
CO_SDO_return_t CO_SDOserver_process | ( | CO_SDOserver_t * | SDO, |
bool_t | NMTisPreOrOperational, | ||
uint32_t | timeDifference_us, | ||
uint32_t * | timerNext_us | ||
) |
Process SDO communication.
Function must be called cyclically.
SDO | This object. | |
NMTisPreOrOperational | True if CO_NMT_internalState_t is NMT_PRE_OPERATIONAL or NMT_OPERATIONAL. | |
timeDifference_us | Time difference from previous function call in [microseconds]. | |
[out] | timerNext_us | info to OS - see CO_process(). |