26 #ifndef LELY_NO_CO_TIME 104 tp->tv_sec += (14 * 365 + 3) * 24 * 60 * 60;
118 tp->tv_sec - (14 * 365 + 3) * 24 * 60 * 60,
129 tp->tv_sec = (time_t)td->days * 24 * 60 * 60 + td->ms / 1000;
130 tp->tv_nsec = (
long)(td->ms % 1000) * 1000000;
140 td->ms = (tp->tv_sec % (24 * 60 * 60)) * 1000 + tp->tv_nsec / 1000000;
142 td->days = (co_unsigned16_t)(tp->tv_sec / (24 * 60 * 60));
146 __co_time_alloc(
void)
148 void *ptr = malloc(
sizeof(
struct __co_time));
155 __co_time_free(
void *ptr)
179 time->
cobid = co_obj_get_val_u32(obj_1012, 0x00);
225 trace(
"creating TIME service");
232 goto error_alloc_time;
235 if (!__co_time_init(time, net, dev)) {
237 goto error_init_time;
243 __co_time_free(time);
253 trace(
"destroying TIME service");
254 __co_time_fini(time);
255 __co_time_free(time);
297 const struct timespec *interval)
327 uint_least32_t
id = time->
cobid;
328 uint_least8_t flags = 0;
336 }
else if (time->
recv) {
348 }
else if (time->
timer) {
356 static co_unsigned32_t
365 co_unsigned32_t ac = 0;
378 co_unsigned32_t
cobid = val.u32;
379 co_unsigned32_t cobid_old = co_sub_get_val_u32(sub);
380 if (cobid == cobid_old)
388 || (cobid_old & CO_TIME_COBID_CONSUMER);
391 if (active && active_old && canid != canid_old) {
427 #ifndef LELY_NO_CANFD 429 if (msg->
flags & CAN_FLAG_EDL)
436 co_time_of_day_t tod;
444 time->
ind(time, &tv, time->
data);
463 co_time_of_day_t tod = { 0, 0 };
482 #endif // !LELY_NO_CO_TIME A CANopen SDO upload/download request.
A CAN or CAN FD format frame.
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).
static int co_time_recv(const struct can_msg *msg, void *data)
The CAN receive callback function for a TIME consumer service.
can_net_t * co_time_get_net(const co_time_t *time)
Returns a pointer to the CAN network of a TIME producer/consumer service.
uint_least8_t len
The number of bytes in data (or the requested number of bytes in case of a remote frame)...
void co_time_of_day_set(co_time_of_day_t *tod, const struct timespec *tp)
Stores the absolute time into a CANopen TIME_OF_DAY value.
uint_least16_t ldle_u16(const uint_least8_t src[2])
Loads a 16-bit unsigned integer in little-endian byte order.
int errnum2c(errnum_t errnum)
Transforms a platform-independent error number to a native error code.
co_dev_t * co_time_get_dev(const co_time_t *time)
Returns a pointer to the CANopen device of a TIME producer/consumer service.
void stle_u16(uint_least8_t dst[2], uint_least16_t x)
Stores a 16-bit unsigned integer in little-endian byte order.
#define CO_SDO_AC_PARAM_VAL
SDO abort code: Invalid value for parameter (download only).
A union of the CANopen static data types.
co_sub_t * sub_1013_00
A pointer to the high-resolution time stamp sub-object.
void can_net_get_time(const can_net_t *net, struct timespec *tp)
Retrieves the current time of a CAN network interface.
co_time_ind_t * ind
A pointer to the indication function.
co_unsigned32_t cobid
The TIME COB-ID.
void co_time_start(co_time_t *time, const struct timespec *start, const struct timespec *interval)
Starts a CANopen TIME producer.
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.
#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...
co_time_t * co_time_create(can_net_t *net, co_dev_t *dev)
Creates a new CANopen TIME producer/consumer service.
void co_time_get_ind(const co_time_t *time, co_time_ind_t **pind, void **pdata)
Retrieves the indication function invoked when a CANopen time stamp is received.
This header file is part of the CANopen library; it contains the CANopen value declarations.
can_timer_t * timer
A pointer to the CAN timer.
void set_errc(int errc)
Sets the current (thread-specific) native error code to errc.
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.
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.
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...
This header file is part of the utilities library; it contains the time function declarations.
void can_timer_stop(can_timer_t *timer)
Stops a CAN timer and unregisters it with a network interface.
void can_recv_destroy(can_recv_t *recv)
Destroys a CAN frame receiver.
This header file is part of the utilities library; it contains the byte order (endianness) function d...
The Remote Transmission Request (RTR) flag (unavailable in CAN FD format frames). ...
This is the internal header file of the CANopen library.
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...
static int co_time_timer(const struct timespec *tp, void *data)
The CAN timer callback function for a TIME producer service.
A CANopen TIME producer/consumer service.
int errno2c(int errnum)
Transforms a standard C error number to a native error code.
void co_time_diff_set(co_time_diff_t *td, const struct timespec *tp)
Stores a time difference into a CANopen TIME_DIFFERENCE value.
void stle_u32(uint_least8_t dst[4], uint_least32_t x)
Stores a 32-bit unsigned integer in little-endian byte order.
static int co_time_update(co_time_t *time)
Updates and (de)activates a TIME producer/consumer service.
void co_time_set_ind(co_time_t *time, co_time_ind_t *ind, void *data)
Sets the indication function invoked when a CANopen time stamp is received.
This header file is part of the CANopen library; it contains the time stamp (TIME) object declaration...
void co_time_of_day_get(const co_time_of_day_t *tod, struct timespec *tp)
Loads the absolute time from a CANopen TIME_OF_DAY value.
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.
int_least64_t timespec_diff_usec(const struct timespec *t1, const struct timespec *t2)
Returns the time difference (in microseconds) between *t1 and *t2.
can_timer_t * can_timer_create(void)
Creates a new CAN timer.
void co_time_ind_t(co_time_t *time, const struct timespec *tp, void *data)
The type of a CANopen TIME indication function, invoked when a time stamp is received.
struct timespec start
The creation time of the service.
void co_time_stop(co_time_t *time)
Stops a CANopen TIME producer.
co_sub_t * co_dev_find_sub(const co_dev_t *dev, co_unsigned16_t idx, co_unsigned8_t subidx)
Finds a sub-object in the object dictionary of a CANopen device.
static co_unsigned32_t co_1012_dn_ind(co_sub_t *sub, struct co_sdo_req *req, void *data)
The download indication function for (all sub-objects of) CANopen object 1012 (COB-ID time stamp obje...
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.
#define CO_SDO_AC_NO_SUB
SDO abort code: Sub-index does not exist.
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...
This header file is part of the CANopen library; it contains the device description declarations...
#define CO_TIME_COBID_FRAME
The bit in the TIME COB-ID specifying whether to use an 11-bit (0) or 29-bit (1) CAN-ID.
can_net_t * net
A pointer to a CAN network interface.
void * data
A pointer to user-specified data for ind.
#define CO_TIME_COBID_CONSUMER
The bit in the TIME COB-ID specifying whether the device is a consumer.
co_unsigned8_t co_sub_get_subidx(const co_sub_t *sub)
Returns the sub-index of a CANopen sub-object.
can_recv_t * recv
A pointer to the CAN frame receiver.
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.
co_dev_t * dev
A pointer to a CANopen device.
void co_time_destroy(co_time_t *time)
Destroys a CANopen TIME producer/consumer service.
co_unsigned16_t co_obj_get_idx(const co_obj_t *obj)
Returns the index of a CANopen object.
#define CO_TIME_COBID_PRODUCER
The bit in the TIME COB-ID specifying whether the device is a producer.
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.
void co_time_diff_get(const co_time_diff_t *td, struct timespec *tp)
Loads a time difference from a CANopen TIME_DIFFERENCE value.
uint_least32_t ldle_u32(const uint_least8_t src[4])
Loads a 32-bit unsigned integer in little-endian byte order.
#define CAN_MASK_EID
The mask used to extract the 29-bit Extended Identifier from a CAN frame.