Lely core libraries
2.3.4
|
Go to the documentation of this file.
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));
129 __co_sync_free(
void *ptr)
162 goto error_create_recv;
169 goto error_create_timer;
213 trace(
"creating SYNC service");
220 goto error_alloc_sync;
223 if (!__co_sync_init(sync,
net,
dev)) {
225 goto error_init_sync;
231 __co_sync_free(sync);
241 trace(
"destroying SYNC service");
242 __co_sync_fini(sync);
243 __co_sync_free(sync);
257 sync->
cobid = co_obj_get_val_u32(obj_1005, 0x00);
263 sync->
us = co_obj_get_val_u32(obj_1006, 0x00);
271 sync->
max_cnt = co_obj_get_val_u8(obj_1019, 0x00);
386 uint_least32_t
id = sync->
cobid;
387 uint_least8_t flags = 0;
404 struct timespec start = { 0, 0 };
406 int_least64_t nsec = start.tv_sec * INT64_C(1000000000)
408 nsec %= (uint_least64_t)sync->
us * 1000;
411 struct timespec interval = { 0, 0 };
423 static co_unsigned32_t
436 co_unsigned32_t ac = 0;
444 co_unsigned32_t cobid = val.u32;
445 co_unsigned32_t cobid_old = co_sub_get_val_u32(sub);
446 if (cobid == cobid_old)
455 if (active && active_old && canid != canid_old)
471 static co_unsigned32_t
484 co_unsigned32_t ac = 0;
492 co_unsigned32_t us = val.u32;
493 co_unsigned32_t us_old = co_sub_get_val_u32(sub);
505 static co_unsigned32_t
518 co_unsigned32_t ac = 0;
526 co_unsigned8_t max_cnt = val.u8;
527 co_unsigned8_t max_cnt_old = co_sub_get_val_u8(sub);
528 if (max_cnt == max_cnt_old)
536 if (max_cnt == 1 || max_cnt > 240)
553 assert(!(msg->
flags & CAN_FLAG_EDL));
558 co_unsigned8_t len = sync->
max_cnt ? 1 : 0;
559 if (msg->
len != len && sync->
err)
562 co_unsigned8_t cnt = len && msg->
len == len ? msg->
data[0] : 0;
591 co_unsigned8_t cnt = msg.
len ? msg.
data[0] : 0;
598 #endif // !LELY_NO_CO_SYNC
can_timer_t * timer
A pointer to the CAN timer.
void can_recv_destroy(can_recv_t *recv)
Destroys a CAN frame receiver.
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...
can_recv_t * recv
A pointer to the CAN frame 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...
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...
void timespec_sub_nsec(struct timespec *tp, uint_least64_t nsec)
Subtracts nsec nanoseconds from the time at tp.
uint_least8_t data[CAN_MSG_MAX_LEN]
The frame payload (in case of a data frame).
co_unsigned8_t cnt
The counter value.
#define CAN_MASK_EID
The mask used to extract the 29-bit Extended Identifier from a CAN frame.
void can_net_get_time(const can_net_t *net, struct timespec *tp)
Retrieves the current time of a CAN network interface.
#define CO_DEFTYPE_UNSIGNED32
The data type (and object index) of a 32-bit unsigned integer.
#define CAN_MASK_BID
The mask used to extract the 11-bit Base Identifier from a CAN frame.
co_unsigned32_t cobid
The SYNC COB-ID.
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.
A CAN or CAN FD format frame.
#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.
uint_least8_t len
The number of bytes in data (or the requested number of bytes in case of a remote frame).
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.
void can_timer_stop(can_timer_t *timer)
Stops a CAN timer and unregisters it with a network interface.
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 * 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.
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.
void co_sync_stop(co_sync_t *sync)
Stops a SYNC service.
int get_errc(void)
Returns the last (thread-specific) native error code set by a system call or library function.
int errno2c(int errnum)
Transforms a standard C error number to a native error code.
#define CO_DEFTYPE_UNSIGNED8
The data type (and object index) of an 8-bit unsigned integer.
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.
co_unsigned32_t us
The communication cycle period (in microseconds).
#define CAN_MSG_INIT
The static initializer for can_msg.
co_unsigned8_t max_cnt
The synchronous counter overflow value.
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.
void set_errc(int errc)
Sets the current (thread-specific) native error code to errc.
void can_timer_destroy(can_timer_t *timer)
Destroys a CAN timer.
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.
#define CO_SDO_AC_NO_SUB
SDO abort code: Sub-index does not exist.
int errnum2c(errnum_t errnum)
Transforms a platform-independent error number to a native error code.
A CANopen SDO upload/download request.
int stopped
A flag specifying whether the SYNC service is stopped.
static void co_sync_update(co_sync_t *sync)
Updates and (de)activates a SYNC producer/consumer service.
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.
void co_sync_destroy(co_sync_t *sync)
Destroys a CANopen SYNC producer/consumer service.
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_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.
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...
co_sync_ind_t * ind
A pointer to the indication function.
A union of the CANopen static data types.
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.
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,...
co_unsigned16_t co_sub_get_type(const co_sub_t *sub)
Returns the data type of a CANopen sub-object.
#define CO_SDO_AC_PARAM_VAL
SDO abort code: Invalid value for parameter (download only).
co_sync_err_t * err
A pointer to the error handling function.
@ CAN_FLAG_RTR
The Remote Transmission Request (RTR) flag (unavailable in CAN FD format frames).
int can_net_send(can_net_t *net, const struct can_msg *msg)
Sends a CAN frame from a network interface.
can_net_t * net
A pointer to a CAN network interface.
co_unsigned8_t co_sub_get_subidx(const co_sub_t *sub)
Returns the sub-index of a CANopen sub-object.
co_dev_t * dev
A pointer to a CANopen device.
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...
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.
int co_sync_start(co_sync_t *sync)
Starts a SYNC service.
#define CO_SYNC_COBID_PRODUCER
The bit in the SYNC COB-ID specifying whether the device is a producer.
static int co_sync_timer(const struct timespec *tp, void *data)
The CAN timer callback function for a SYNC producer service.
co_sync_t * co_sync_create(can_net_t *net, co_dev_t *dev)
Creates a new CANopen SYNC producer/consumer service.
int co_sync_is_stopped(const co_sync_t *sync)
Retuns 1 if the specified SYNC service is stopped, and 0 if not.
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.
static int co_sync_recv(const struct can_msg *msg, void *data)
The CAN receive callback function for a SYNC consumer service.
@ CAN_FLAG_IDE
The Identifier Extension (IDE) flag.
A CANopen SYNC producer/consumer service.
void can_recv_stop(can_recv_t *recv)
Stops a CAN frame receiver from processing frames and unregisters it with the network interface.
void timespec_add_usec(struct timespec *tp, uint_least64_t usec)
Adds usec microseconds to the time at tp.
co_unsigned16_t co_obj_get_idx(const co_obj_t *obj)
Returns the index of a CANopen object.
can_recv_t * can_recv_create(void)
Creates a new CAN frame receiver.
can_timer_t * can_timer_create(void)
Creates a new CAN timer.
@ ERRNUM_NOSYS
Function not supported.
uint_least32_t id
The identifier (11 or 29 bits, depending on the CAN_FLAG_IDE flag).
#define CO_SDO_AC_DATA_DEV
SDO abort code: Data cannot be transferred or stored to the application because of the present device...
int co_type_is_array(co_unsigned16_t type)
Returns 1 if the specified (static) data type is an array, and 0 if not.
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.