Functions of the application interface
The application interface consists of two
sets of functions. There is a set of direct functions that can be called from within the
application to initialize the MicroCANopen communication stack and to pass process data to
the communication stack.
The second set of functions are call-back
functions that MicroCANopen calls to inform the application of important events or the
reception of process data.
Direct Functions
Lets have a look at the direct functions
defined in mco.h:
void MCO_Init (
UNSIGNED16 Baudrate,
UNSIGNED8 Node_ID,
UNSIGNED16
heartbeat
);
This function initializes the CANopen protocol stack.
It must be called from within the user call-back function MCOUSER_ResetApplication which
is called by MicroCANopen upon receiving a Reset command. The baud rate may be one of the
values 1000, 800, 500, 250, 125, 50, 25 or 10. The node ID may be in the range of 1 to 127
and the heartbeat time is specified in milliseconds. So to generate a heartbeat message
once every 2 seconds, enter 2000.
void MCO_InitTPDO (
UNSIGNED8 PDO_NR,
UNSIGNED16 CAN_ID,
UNSIGNED16 event_tim,
UNSIGNED16 inhibit_tim,
UNSIGNED8 len,
UNSIGNED8 offset
);
This function initializes a transmit PDO - Process Data
Object. That is a single CAN message with up to 8 bytes of process data.
Multiple variables can be combined into one CAN message, however - they must
all be located in consecutive bytes in the process image starting at the
location indicated by offset. Once initialized, the MicroCANopen stack
automatically handles transmitting the PDO. The application can directly change the data
at any time. NOTE: For data consistency, the application should not write to the data
while function MCO_ProcessStack executes.
The parameter PDO_NR needs to be in the range of 1 to 4, the CAN_ID can be set to 0 if the
CANopen default ID should be used. If the event_tim is unequal zero, the message will be
transmitted every event_tim milliseconds. In case the inhibit_tim is unequal zero, the
message is transmitted on a change-of-state basis with a minimal timeout of inhibit_tim
milliseconds.
void MCO_InitRPDO (
UNSIGNED8 PDO_NR,
UNSIGNED16 CAN_ID,
UNSIGNED8 len,
UNSIGNED8 offset
);
This function initializes a receive PDO. Once initialized, the
MicroCANopen stack automatically writes received data to the destination pointer location.
The parameter PDO_NR needs to be in the range of 1 to 4, the CAN_ID can be set to 0 if the
CANopen default ID should be used.
UNSIGNED8 MCO_ProcessStack ( void );
This function implements the main MicroCANopen protocol
stack. It must be called frequently to ensure proper operation of the communication stack.
Typically it is called from the while(1) loop in main.
Call-Back Functions
The following call-back functions must be implemented by the
application:
void MCOUSER_ResetApplication ( void );
This function resets the application. It is called from within the CANopen protocol stack,
if a NMT master message was received that demanded "Reset Application". With
embedded microcontroller it is typically best to implement this as a "watchdog
trap". Enable the watchdog of your embedded microcontroller, but do not feed or pet
it...
void MCOUSER_ResetCommunication ( void );
This function both resets and initializes both the CAN interface and the CANopen protocol
stack. It is called from within the CANopen protocol stack, if a NMT master message was
received that demanded "Reset Communication". This function should call MCO_Init
and MCO_InitTPDO/MCO_InitRPDO.
void MCOUSER_FatalError ( WORD ErrCode );
This function is called if a fatal error occurred. Error codes of mcohwxxx.c are in the
range of 0x8000 to 0x87FF. Error codes of mco.c are in the range of 0x8800 to 0x8FFF. All
other error codes may be used by the application.
Return to
MicroCANopen Home
© Embedded Systems Academy, Inc.
All Rights Reserved. |