CANopenNode
CANopen protocol stack
Loading...
Searching...
No Matches
CO_SYNC.h
Go to the documentation of this file.
1
21#ifndef CO_SYNC_H
22#define CO_SYNC_H
23
24#include "301/CO_driver.h"
25#include "301/CO_ODinterface.h"
26#include "301/CO_Emergency.h"
27
28/* default configuration, see CO_config.h */
29#ifndef CO_CONFIG_SYNC
30#define CO_CONFIG_SYNC \
31 (CO_CONFIG_SYNC_ENABLE | CO_CONFIG_SYNC_PRODUCER | CO_CONFIG_GLOBAL_RT_FLAG_CALLBACK_PRE \
32 | CO_CONFIG_GLOBAL_FLAG_TIMERNEXT | CO_CONFIG_GLOBAL_FLAG_OD_DYNAMIC)
33#endif
34
35#if (((CO_CONFIG_SYNC)&CO_CONFIG_SYNC_ENABLE) != 0) || defined CO_DOXYGEN
36
37#ifdef __cplusplus
38extern "C" {
39#endif
40
67typedef struct {
69 volatile void* CANrxNew;
82#if (((CO_CONFIG_SYNC)&CO_CONFIG_SYNC_PRODUCER) != 0) || defined CO_DOXYGEN
87#endif
88
89#if ((CO_CONFIG_SYNC)&CO_CONFIG_FLAG_OD_DYNAMIC) || defined CO_DOXYGEN
95#if (((CO_CONFIG_SYNC)&CO_CONFIG_SYNC_PRODUCER) != 0) || defined CO_DOXYGEN
98#endif
99#endif
100
101#if (((CO_CONFIG_SYNC)&CO_CONFIG_FLAG_CALLBACK_PRE) != 0) || defined CO_DOXYGEN
102 void (*pFunctSignalPre)(void* object);
104#endif
105} CO_SYNC_t;
106
115
138 OD_entry_t* OD_1006_commCyclePeriod, OD_entry_t* OD_1007_syncWindowLen,
139 OD_entry_t* OD_1019_syncCounterOvf, CO_CANmodule_t* CANdevRx, uint16_t CANdevRxIdx,
140#if (((CO_CONFIG_SYNC)&CO_CONFIG_SYNC_PRODUCER) != 0) || defined CO_DOXYGEN
141 CO_CANmodule_t* CANdevTx, uint16_t CANdevTxIdx,
142#endif
143 uint32_t* errInfo);
144
145#if (((CO_CONFIG_SYNC)&CO_CONFIG_FLAG_CALLBACK_PRE) != 0) || defined CO_DOXYGEN
156void CO_SYNC_initCallbackPre(CO_SYNC_t* SYNC, void* object, void (*pFunctSignalPre)(void* object));
157#endif
158
159#if (((CO_CONFIG_SYNC)&CO_CONFIG_SYNC_PRODUCER) != 0) || defined CO_DOXYGEN
170static inline CO_ReturnError_t
172 if (++SYNC->counter > SYNC->counterOverflowValue) {
173 SYNC->counter = 1;
174 }
175 SYNC->timer = 0;
176 SYNC->CANrxToggle = SYNC->CANrxToggle ? false : true;
177 SYNC->CANtxBuff->data[0] = SYNC->counter;
178 return CO_CANsend(SYNC->CANdevTx, SYNC->CANtxBuff);
179}
180#endif
181
194CO_SYNC_status_t CO_SYNC_process(CO_SYNC_t* SYNC, bool_t NMTisPreOrOperational, uint32_t timeDifference_us,
195 uint32_t* timerNext_us);
196
197 /* CO_SYNC */
198
199#ifdef __cplusplus
200}
201#endif /* __cplusplus */
202
203#endif /* (CO_CONFIG_SYNC) & CO_CONFIG_SYNC_ENABLE */
204
205#endif /* CO_SYNC_H */
CANopen Emergency protocol.
CANopen Object Dictionary interface.
Interface between CAN hardware and CANopenNode.
static CO_ReturnError_t CO_SYNCsend(CO_SYNC_t *SYNC)
Send SYNC message.
Definition CO_SYNC.h:171
CO_SYNC_status_t
Return value for CO_SYNC_process.
Definition CO_SYNC.h:110
CO_ReturnError_t CO_SYNC_init(CO_SYNC_t *SYNC, CO_EM_t *em, OD_entry_t *OD_1005_cobIdSync, OD_entry_t *OD_1006_commCyclePeriod, OD_entry_t *OD_1007_syncWindowLen, OD_entry_t *OD_1019_syncCounterOvf, CO_CANmodule_t *CANdevRx, uint16_t CANdevRxIdx, CO_CANmodule_t *CANdevTx, uint16_t CANdevTxIdx, uint32_t *errInfo)
Initialize SYNC object.
CO_SYNC_status_t CO_SYNC_process(CO_SYNC_t *SYNC, bool_t NMTisPreOrOperational, uint32_t timeDifference_us, uint32_t *timerNext_us)
Process SYNC communication.
void CO_SYNC_initCallbackPre(CO_SYNC_t *SYNC, void *object, void(*pFunctSignalPre)(void *object))
Initialize SYNC callback function.
@ CO_SYNC_PASSED_WINDOW
Time has just passed SYNC window (OD_1007) in last cycle.
Definition CO_SYNC.h:113
@ CO_SYNC_RX_TX
SYNC message was received or transmitted in last cycle.
Definition CO_SYNC.h:112
@ CO_SYNC_NONE
No SYNC event in last cycle.
Definition CO_SYNC.h:111
unsigned int uint16_t
UNSIGNED16 in CANopen (0006h), 16-bit unsigned integer.
Definition CO_driver.h:132
unsigned long int uint32_t
UNSIGNED32 in CANopen (0007h), 32-bit unsigned integer.
Definition CO_driver.h:133
uint_fast8_t bool_t
Boolean data type for general use.
Definition CO_driver.h:126
#define false
Logical false, for general use.
Definition CO_driver.h:125
unsigned char uint8_t
UNSIGNED8 in CANopen (0005h), 8-bit unsigned integer.
Definition CO_driver.h:131
CO_ReturnError_t
Return values of some CANopen functions.
Definition CO_driver.h:449
CO_ReturnError_t CO_CANsend(CO_CANmodule_t *CANmodule, CO_CANtx_t *buffer)
Send CAN message.
Complete CAN module object.
Definition CO_driver.h:268
Configuration object for CAN transmit message for specific CANopenNode Object.
Definition CO_driver.h:250
uint8_t data[8]
8 data bytes
Definition CO_driver.h:253
Emergency object.
Definition CO_Emergency.h:259
SYNC producer and consumer object.
Definition CO_SYNC.h:67
uint8_t counter
Counter of the SYNC message if counterOverflowValue is different than zero.
Definition CO_SYNC.h:75
uint8_t timeoutError
Sync timeout monitoring: 0 = not started; 1 = started; 2 = sync timeout error state.
Definition CO_SYNC.h:72
uint16_t CANdevRxIdx
From CO_SYNC_init()
Definition CO_SYNC.h:91
OD_extension_t OD_1005_extension
Extension for OD object.
Definition CO_SYNC.h:92
bool_t CANrxToggle
Variable toggles, if new SYNC message received from CAN bus.
Definition CO_SYNC.h:71
bool_t syncIsOutsideWindow
True, if current time is outside "synchronous window" (OD 1007)
Definition CO_SYNC.h:76
uint8_t receiveError
Set to nonzero value, if SYNC with wrong data length is received.
Definition CO_SYNC.h:70
CO_CANmodule_t * CANdevTx
From CO_SYNC_init()
Definition CO_SYNC.h:85
uint32_t * OD_1007_window
Pointer to variable in OD, "Synchronous window length" in microseconds.
Definition CO_SYNC.h:80
uint32_t timer
Timer for the SYNC message in [microseconds].
Definition CO_SYNC.h:77
void * functSignalObjectPre
From CO_SYNC_initCallbackPre() or NULL.
Definition CO_SYNC.h:103
uint32_t * OD_1006_period
Pointer to variable in OD, "Communication cycle period" in microseconds.
Definition CO_SYNC.h:79
CO_CANtx_t * CANtxBuff
CAN transmit buffer inside CANdevTx.
Definition CO_SYNC.h:86
uint16_t CAN_ID
CAN ID of the SYNC message.
Definition CO_SYNC.h:93
OD_extension_t OD_1019_extension
Extension for OD object.
Definition CO_SYNC.h:97
CO_EM_t * em
From CO_SYNC_init()
Definition CO_SYNC.h:68
uint16_t CANdevTxIdx
From CO_SYNC_init()
Definition CO_SYNC.h:96
CO_CANmodule_t * CANdevRx
From CO_SYNC_init()
Definition CO_SYNC.h:90
uint8_t counterOverflowValue
Value from Synchronous counter overflow value variable from Object dictionary (index 0x1019)
Definition CO_SYNC.h:73
bool_t isProducer
True, if device is SYNC producer.
Definition CO_SYNC.h:83
volatile void * CANrxNew
Indicates, if new SYNC message received from CAN bus.
Definition CO_SYNC.h:69
Object Dictionary entry for one OD object.
Definition CO_ODinterface.h:272
Extension of OD object, which can optionally be specified by application in initialization phase with...
Definition CO_ODinterface.h:245