103 const co_time_diff_t td = { .ms = tod->ms, .days = tod->days };
105 tp->
tv_sec += (14 * 365 + 3) * 24 * 60 * 60;
117 co_time_diff_t td = { 0, 0 };
120 tp->
tv_sec - (14 * 365 + 3) * 24 * 60 * 60,
133 tp->
tv_sec = (time_t)td->days * 24 * 60 * 60 + td->ms / 1000;
134 tp->
tv_nsec = (long)(td->ms % 1000) * 1000000;
144 td->ms = (tp->
tv_sec % (24 * 60 * 60)) * 1000 + tp->
tv_nsec / 1000000;
146 td->days = (co_unsigned16_t)(tp->
tv_sec / (24 * 60 * 60));
152 void *ptr = malloc(
sizeof(
struct __co_time));
161__co_time_free(
void *ptr)
193 goto error_create_recv;
200 goto error_create_timer;
242 trace(
"creating TIME service");
249 goto error_alloc_time;
252 if (!__co_time_init(time, net, dev)) {
254 goto error_init_time;
260 __co_time_free(time);
270 trace(
"destroying TIME service");
271 __co_time_fini(time);
272 __co_time_free(time);
286 time->
cobid = co_obj_get_val_u32(obj_1012, 0x00);
389 uint_least32_t
id = time->
cobid;
390 uint_least8_t flags = 0;
408static co_unsigned32_t
421 co_unsigned32_t ac = 0;
429 co_unsigned32_t cobid = val.u32;
430 co_unsigned32_t cobid_old = co_sub_get_val_u32(sub);
431 if (cobid == cobid_old)
442 if (active && active_old && canid != canid_old)
471 if (msg->
flags & CAN_FLAG_EDL)
478 co_time_of_day_t tod;
486 time->
ind(time, &tv, time->
data);
505 co_time_of_day_t tod = { 0, 0 };
@ CAN_FLAG_IDE
The Identifier Extension (IDE) flag.
@ CAN_FLAG_RTR
The Remote Transmission Request (RTR) flag (unavailable in CAN FD format frames).
#define CAN_MASK_EID
The mask used to extract the 29-bit Extended Identifier from a CAN frame.
#define CAN_MASK_BID
The mask used to extract the 11-bit Base Identifier from a CAN frame.
#define CAN_MSG_INIT
The static initializer for can_msg.
This header file is part of the CANopen library; it contains the device description declarations.
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.
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.
void co_time_stop(co_time_t *time)
Stops a TIME service.
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_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.
void co_time_stop_prod(co_time_t *time)
Stops a CANopen TIME producer.
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.
int co_time_is_stopped(const co_time_t *time)
Retuns 1 if the specified TIME service is stopped, and 0 if not.
void co_time_destroy(co_time_t *time)
Destroys a CANopen TIME producer/consumer service.
static int co_time_recv(const struct can_msg *msg, void *data)
The CAN receive callback function for a TIME consumer service.
static void co_time_update(co_time_t *time)
Updates and (de)activates a TIME producer/consumer service.
int co_time_start(co_time_t *time)
Starts a TIME service.
void co_time_start_prod(co_time_t *time, const struct timespec *start, const struct timespec *interval)
Starts a CANopen TIME producer.
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.
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.
void co_time_diff_get(const co_time_diff_t *td, struct timespec *tp)
Loads a time difference from a CANopen TIME_DIFFERENCE value.
void co_time_diff_set(co_time_diff_t *td, const struct timespec *tp)
Stores a time difference into a CANopen TIME_DIFFERENCE value.
static int co_time_timer(const struct timespec *tp, void *data)
The CAN timer callback function for a TIME producer service.
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.
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.
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...
This header file is part of the CANopen library; it contains the time stamp (TIME) object declaration...
#define CO_TIME_COBID_CONSUMER
The bit in the TIME COB-ID specifying whether the device is a consumer.
#define CO_TIME_COBID_PRODUCER
The bit in the TIME COB-ID specifying whether the device is a producer.
#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.
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.
This header file is part of the utilities library; it contains the byte order (endianness) function d...
uint_least32_t ldle_u32(const uint_least8_t src[4])
Loads a 32-bit unsigned integer in little-endian byte order.
uint_least16_t ldle_u16(const uint_least8_t src[2])
Loads a 16-bit unsigned integer in little-endian byte order.
void stle_u16(uint_least8_t dst[2], uint_least16_t x)
Stores a 16-bit unsigned integer in little-endian byte order.
void stle_u32(uint_least8_t dst[4], uint_least32_t x)
Stores a 32-bit unsigned integer in little-endian byte order.
This header file is part of the utilities library; it contains the native and platform-independent er...
int errnum2c(errnum_t errnum)
Transforms a platform-independent error number to a native error code.
@ ERRNUM_NOSYS
Function not supported.
int get_errc(void)
Returns the last (thread-specific) native error code set by a system call or library function.
void set_errc(int errc)
Sets the current (thread-specific) native error code to errc.
int errno2c(int errnum)
Transforms a standard C error number to a native error code.
This header file is part of the CANopen library; it contains the Service Data Object (SDO) declaratio...
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_SDO_AC_NO_SUB
SDO abort code: Sub-index does not exist.
#define CO_SDO_AC_PARAM_VAL
SDO abort code: Invalid value for parameter (download only).
void can_timer_stop(can_timer_t *timer)
Stops a CAN timer and unregisters it with a network interface.
int can_net_send(can_net_t *net, const struct can_msg *msg)
Sends a CAN frame from a network interface.
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.
can_timer_t * can_timer_create(void)
Creates a new CAN timer.
void can_net_get_time(const can_net_t *net, struct timespec *tp)
Retrieves the current time of a CAN network interface.
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_recv_stop(can_recv_t *recv)
Stops a CAN frame receiver from processing frames and unregisters it with the network interface.
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.
void can_recv_destroy(can_recv_t *recv)
Destroys a CAN frame receiver.
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.
can_recv_t * can_recv_create(void)
Creates a new CAN frame receiver.
void can_timer_destroy(can_timer_t *timer)
Destroys a CAN timer.
This header file is part of the CANopen library; it contains the object dictionary declarations.
co_unsigned8_t co_sub_get_subidx(const co_sub_t *sub)
Returns the sub-index of a CANopen sub-object.
co_unsigned16_t co_obj_get_idx(const co_obj_t *obj)
Returns the index of a CANopen object.
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...
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.
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.
co_unsigned16_t co_sub_get_type(const co_sub_t *sub)
Returns the data type of a CANopen sub-object.
This is the internal header file of the CANopen library.
This header file is part of the C11 and POSIX compatibility library; it includes <stdlib....
A CANopen TIME producer/consumer service.
can_timer_t * timer
A pointer to the CAN timer.
void * data
A pointer to user-specified data for ind.
can_recv_t * recv
A pointer to the CAN frame receiver.
co_sub_t * sub_1013_00
A pointer to the high-resolution time stamp sub-object.
int stopped
A flag specifying whether the TIME service is stopped.
co_unsigned32_t cobid
The TIME COB-ID.
can_net_t * net
A pointer to a CAN network interface.
co_time_ind_t * ind
A pointer to the indication function.
struct timespec start
The creation time of the service.
co_dev_t * dev
A pointer to a CANopen device.
A CAN or CAN FD format frame.
uint_least8_t data[CAN_MSG_MAX_LEN]
The frame payload (in case of a data frame).
uint_least32_t id
The identifier (11 or 29 bits, depending on the CAN_FLAG_IDE flag).
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...
uint_least8_t len
The number of bytes in data (or the requested number of bytes in case of a remote frame).
A CANopen SDO upload/download request.
A time type with nanosecond resolution.
long tv_nsec
Nanoseconds [0, 999999999].
time_t tv_sec
Whole seconds (>= 0).
int co_type_is_array(co_unsigned16_t type)
Returns 1 if the specified (static) data type is an array, and 0 if not.
#define CO_DEFTYPE_UNSIGNED32
The data type (and object index) of a 32-bit unsigned integer.
A union of the CANopen static data types.
This header file is part of the utilities library; it contains the time function declarations.
int_least64_t timespec_diff_usec(const struct timespec *t1, const struct timespec *t2)
Returns the time difference (in microseconds) between *t1 and *t2.
This header file is part of the CANopen library; it contains the CANopen value declarations.