26 #ifndef LELY_NO_CO_SYNC 115 static int co_sync_timer(
const struct timespec *tp,
void *data);
118 __co_sync_alloc(
void)
120 void *ptr = malloc(
sizeof(
struct __co_sync));
127 __co_sync_free(
void *ptr)
151 sync->
cobid = co_obj_get_val_u32(obj_1005, 0x00);
155 sync->
us = co_obj_get_val_u32(obj_1006, 0x00);
159 sync->
max_cnt = co_obj_get_val_u8(obj_1019, 0x00);
232 trace(
"creating SYNC service");
239 goto error_alloc_sync;
242 if (!__co_sync_init(sync, net, dev)) {
244 goto error_init_sync;
250 __co_sync_free(sync);
260 trace(
"destroying SYNC service");
261 __co_sync_fini(sync);
262 __co_sync_free(sync);
335 uint_least32_t
id = sync->
cobid;
336 uint_least8_t flags = 0;
344 }
else if (sync->
recv) {
360 struct timespec start = { 0, 0 };
362 int_least64_t nsec = start.tv_sec * INT64_C(1000000000)
364 nsec %= (uint_least64_t)sync->
us * 1000;
367 struct timespec interval = { 0, 0 };
370 }
else if (sync->
timer) {
382 static co_unsigned32_t
391 co_unsigned32_t ac = 0;
404 co_unsigned32_t
cobid = val.u32;
405 co_unsigned32_t cobid_old = co_sub_get_val_u32(sub);
406 if (cobid == cobid_old)
415 if (active && active_old && canid != canid_old) {
440 static co_unsigned32_t
449 co_unsigned32_t ac = 0;
462 co_unsigned32_t
us = val.u32;
463 co_unsigned32_t us_old = co_sub_get_val_u32(sub);
480 static co_unsigned32_t
489 co_unsigned32_t ac = 0;
502 co_unsigned8_t
max_cnt = val.u8;
503 co_unsigned8_t max_cnt_old = co_sub_get_val_u8(sub);
504 if (max_cnt == max_cnt_old)
514 if (max_cnt == 1 || max_cnt > 240) {
543 #ifndef LELY_NO_CANFD 545 if (msg->
flags & CAN_FLAG_EDL)
549 co_unsigned8_t len = sync->
max_cnt ? 1 : 0;
550 if (msg->
len != len && sync->
err)
553 co_unsigned8_t
cnt = len && msg->
len == len ? msg->
data[0] : 0;
582 co_unsigned8_t
cnt = msg.
len ? msg.
data[0] : 0;
589 #endif // !LELY_NO_CO_SYNC A CANopen SDO upload/download request.
A CAN or CAN FD format frame.
static int co_sync_timer(const struct timespec *tp, void *data)
The CAN timer callback function for a SYNC producer service.
can_timer_t * timer
A pointer to the CAN timer.
void co_obj_set_dn_ind(co_obj_t *obj, co_sub_dn_ind_t *ind, void *data)
Sets the download indication function for a CANopen object.
uint_least32_t id
The identifier (11 or 29 bits, depending on the CAN_FLAG_IDE flag).
can_recv_t * recv
A pointer to the CAN frame receiver.
static co_unsigned32_t co_1019_dn_ind(co_sub_t *sub, struct co_sdo_req *req, void *data)
The download indication function for (all sub-objects of) CANopen object 1019 (Synchronous counter ov...
uint_least8_t len
The number of bytes in data (or the requested number of bytes in case of a remote frame)...
co_dev_t * dev
A pointer to a CANopen device.
int errnum2c(errnum_t errnum)
Transforms a platform-independent error number to a native error code.
can_net_t * co_sync_get_net(const co_sync_t *sync)
Returns a pointer to the CAN network of a SYNC producer/consumer service.
#define CO_SDO_AC_PARAM_VAL
SDO abort code: Invalid value for parameter (download only).
A union of the CANopen static data types.
void can_net_get_time(const can_net_t *net, struct timespec *tp)
Retrieves the current time of a CAN network interface.
co_unsigned8_t max_cnt
The synchronous counter overflow value.
void can_timer_start(can_timer_t *timer, can_net_t *net, const struct timespec *start, const struct timespec *interval)
Starts a CAN timer and registers it with a network interface.
void * ind_data
A pointer to user-specified data for ind.
#define CAN_MASK_BID
The mask used to extract the 11-bit Base Identifier from a CAN frame.
This header file is part of the CANopen library; it contains the Service Data Object (SDO) declaratio...
This header file is part of the CANopen library; it contains the CANopen value declarations.
void set_errc(int errc)
Sets the current (thread-specific) native error code to errc.
static int co_sync_update(co_sync_t *sync)
Updates and (de)activates a SYNC producer/consumer service.
static co_unsigned32_t co_1006_dn_ind(co_sub_t *sub, struct co_sdo_req *req, void *data)
The download indication function for (all sub-objects of) CANopen object 1006 (Communication cycle pe...
void can_timer_set_func(can_timer_t *timer, can_timer_func_t *func, void *data)
Sets the callback function invoked when a CAN timer is triggered.
co_unsigned32_t us
The communication cycle period (in microseconds).
can_recv_t * can_recv_create(void)
Creates a new CAN frame receiver.
#define CO_DEFTYPE_UNSIGNED32
The data type (and object index) of a 32-bit unsigned integer.
void timespec_add_usec(struct timespec *tp, uint_least64_t usec)
Adds usec microseconds to the time at tp.
uint_least8_t data[CAN_MSG_MAX_LEN]
The frame payload (in case of a data frame).
This header file is part of the utilities library; it contains the native and platform-independent er...
void co_sync_set_err(co_sync_t *sync, co_sync_err_t *err, void *data)
Sets the error handling function of a SYNC consumer service.
This header file is part of the utilities library; it contains the time function declarations.
static co_unsigned32_t co_1005_dn_ind(co_sub_t *sub, struct co_sdo_req *req, void *data)
The download indication function for (all sub-objects of) CANopen object 1005 (COB-ID SYNC message)...
void co_sync_get_ind(const co_sync_t *sync, co_sync_ind_t **pind, void **pdata)
Retrieves the indication function invoked after a CANopen SYNC message is received or transmitted...
void can_recv_destroy(can_recv_t *recv)
Destroys a CAN frame receiver.
The Remote Transmission Request (RTR) flag (unavailable in CAN FD format frames). ...
This is the internal header file of the CANopen library.
co_sync_ind_t * ind
A pointer to the indication function.
int get_errc(void)
Returns the last (thread-specific) native error code set by a system call or library function...
void can_timer_destroy(can_timer_t *timer)
Destroys a CAN timer.
int co_sub_dn(co_sub_t *sub, void *val)
Downloads (moves) a value into a CANopen sub-object if the refuse-write-on-download flag (CO_OBJ_FLAG...
#define CO_DEFTYPE_UNSIGNED8
The data type (and object index) of an 8-bit unsigned integer.
#define CO_SYNC_COBID_PRODUCER
The bit in the SYNC COB-ID specifying whether the device is a producer.
co_sync_t * co_sync_create(can_net_t *net, co_dev_t *dev)
Creates a new CANopen SYNC producer/consumer service.
int errno2c(int errnum)
Transforms a standard C error number to a native error code.
can_net_t * net
A pointer to a CAN network interface.
void * err_data
A pointer to user-specified data for err.
void can_recv_set_func(can_recv_t *recv, can_recv_func_t *func, void *data)
Sets the callback function used to process CAN frames with a receiver.
uint_least8_t flags
The flags (any combination of CAN_FLAG_IDE, CAN_FLAG_RTR, CAN_FLAG_FDF, CAN_FLAG_BRS and CAN_FLAG_ESI...
co_obj_t * co_sub_get_obj(const co_sub_t *sub)
Returns the a pointer to the CANopen object containing the specified sub-object.
The Identifier Extension (IDE) flag.
can_timer_t * can_timer_create(void)
Creates a new CAN timer.
void co_val_fini(co_unsigned16_t type, void *val)
Finalizes a value of the specified data type.
int can_net_send(can_net_t *net, const struct can_msg *msg)
Sends a CAN frame from a network interface.
void co_sync_ind_t(co_sync_t *sync, co_unsigned8_t cnt, void *data)
The type of a CANopen SYNC indication function, invoked after a SYNC message is received or transmitt...
co_unsigned8_t cnt
The counter value.
#define CO_SDO_AC_NO_SUB
SDO abort code: Sub-index does not exist.
static int co_sync_recv(const struct can_msg *msg, void *data)
The CAN receive callback function for a SYNC consumer service.
co_sync_err_t * err
A pointer to the error handling function.
This header file is part of the CANopen library; it contains the synchronization (SYNC) object declar...
int co_sdo_req_dn_val(struct co_sdo_req *req, co_unsigned16_t type, void *val, co_unsigned32_t *pac)
Copies the next segment of the specified CANopen SDO download request to the internal buffer and...
#define CO_SYNC_COBID_FRAME
The bit in the SYNC COB-ID specifying whether to use an 11-bit (0) or 29-bit (1) CAN-ID.
This header file is part of the CANopen library; it contains the device description declarations...
void co_sync_destroy(co_sync_t *sync)
Destroys a CANopen SYNC producer/consumer service.
co_unsigned32_t cobid
The SYNC COB-ID.
co_dev_t * co_sync_get_dev(const co_sync_t *sync)
Returns a pointer to the CANopen device of a SYNC producer/consumer service.
#define CO_SDO_AC_DATA_DEV
SDO abort code: Data cannot be transferred or stored to the application because of the present device...
co_unsigned8_t co_sub_get_subidx(const co_sub_t *sub)
Returns the sub-index of a CANopen sub-object.
void timespec_sub_nsec(struct timespec *tp, uint_least64_t nsec)
Subtracts nsec nanoseconds from the time at tp.
This header file is part of the C11 and POSIX compatibility library; it includes <stdlib.h> and defines any missing functionality.
co_unsigned16_t co_sub_get_type(const co_sub_t *sub)
Returns the data type of a CANopen sub-object.
A CANopen SYNC producer/consumer service.
co_unsigned16_t co_obj_get_idx(const co_obj_t *obj)
Returns the index of a CANopen object.
void co_sync_set_ind(co_sync_t *sync, co_sync_ind_t *ind, void *data)
Sets the indication function invoked after a CANopen SYNC message is received or transmitted.
void co_sync_get_err(const co_sync_t *sync, co_sync_err_t **perr, void **pdata)
Retrieves the error handling function of a SYNC consumer service.
This header file is part of the CANopen library; it contains the object dictionary declarations...
#define CAN_MSG_INIT
The static initializer for can_msg.
void can_recv_start(can_recv_t *recv, can_net_t *net, uint_least32_t id, uint_least8_t flags)
Registers a CAN frame receiver with a network interface and starts processing frames.
co_obj_t * co_dev_find_obj(const co_dev_t *dev, co_unsigned16_t idx)
Finds an object in the object dictionary of a CANopen device.
#define CAN_MASK_EID
The mask used to extract the 29-bit Extended Identifier from a CAN frame.
void co_sync_err_t(co_sync_t *sync, co_unsigned16_t eec, co_unsigned8_t er, void *data)
The type of a CANopen SYNC error handling function, invoked when the SYNC data length does not match...