Back to ESAcademy Home Page


MicroCANopen
Implementation

 

Implementation of MicroCANopen

The following features are implemented in MicroCANopen:

  • Support of a CANopen Object Dictionary, accessible with expedited SDO transfers (limited to a maximum size of 4-bytes per OD entry).
    • In CANopen terms: one SDO server with expedited access.
  • Object Dictionary contains read-only values in look-up table.
    • Optional look-up table for read-write entries.
  • Network Management (NMT) state machine with autostart option
  • Up to 4 Transmit Process Data Objects (TPDO)
  • Up to 4 Receive Process Data Objects (RPDO)

See the examples on how to use MicroCANopen.

In addition to the public functions, MicroCANopen uses several local functions:

UNSIGNED8 Search_OD (
  UNSIGNED16 index,
  UNSIGNED8 subindex
);
Searches the Object Dictionary table for the index and subindex specified. This function is used to find out if a requested OD entry is implemented by the lookup-table.

UNSIGNED8 Handle_SDO_Request ( UNSIGNED8 *pData );
This function is called with a pointer to the 8 bytes received with a SDO access (read or write request to OD). It handles the entire search and access to the OD.

void Prepare_TPDOs ( void );
MicroCANopen implements the CANopen NMT state machine. PDOs are only handled in the state "operational" and are not active in any other state. So with each transition into the "operational" state, all Transmit PDOs must be transmitted. This function prepares all TPDOs for transmittal.

To get a better understanding of how the MicroCANopen communication protocol stock works, have a look at the following pseudo code for the function MCO_ProcessStack(). This function must be called frequently (for example with in the main while(1) loop) by the application program to ensure operation of the CANopen communication.

BEGIN MCO_ProcessStack

__IF CAN message received
____IF NMT master message received
______Handle NMT state machine
______Exit MCO_ProcessStack
____ELSEIF SDO request (OD access) received
______Handle SDO request
______Exit MCO_ProcessStack
____ELSEIF PDO message received
______Copy data received to destination location
______Exit MCO_ProcessStack
____ENDIF
__ENDIF CAN message received

__IF NMT state is "operational"
____Check next TPDO (one with each call to this function),
____is TPDO due for transmit?:
____IF EVENT_TIME is specified and EVENT_TIME is expired
______Copy process data to transmit message buffer
______Reset event timer
______Queue TPDO message for transmit
______Exit MCO_ProcessStack
____ELSEIF INHIBIT_TIME is specified
______IF message is already pending (waiting for inhibit to expire)
________Reset inhibit timer
________Queue TPDO message for transmit
________Exit MCO_ProcessStack
______ELSEIF data changed since last transmit
________Copy process data to transmit message buffer
________IF inhibit time already expired
__________Reset inhibit timer
__________Queue TPDO message for transmit
__________Exit MCO_ProcessStack
________ELSE
__________Mark message as pending (waiting for inhibit to expire)
________ENDIF
______ENDIF
____ENDIF EVENT_TIME / INHIBIT_TIME used
__ENDIF NMT state "operational"

__IF heartbeat expired
____Reset Heartbeat timer
____Queue Heartbeat message for transmit
__ENDIF

END MCO_ProcessStack

Return to MicroCANopen Home

© Embedded Systems Academy, Inc. All Rights Reserved.

San Jose, CA
Tel. (877) 812-6393
Fax. (877) 812-6382

www.esacademy.com
info@esacademy.com