26 #ifndef LELY_NO_CO_TPDO 164 __co_tpdo_alloc(
void)
166 void *ptr = malloc(
sizeof(
struct __co_tpdo));
173 __co_tpdo_free(
void *ptr)
206 memset(&pdo->
comm, 0,
sizeof(pdo->
comm));
211 memset(&pdo->
map, 0,
sizeof(pdo->
map));
242 goto error_init_recv;
247 goto error_init_timer_event;
259 error_init_timer_event:
273 assert(pdo->
num >= 1 && pdo->
num <= 512);
289 can_buf_destroy(pdo->
buf);
300 trace(
"creating Transmit-PDO %d",
num);
307 goto error_alloc_pdo;
328 trace(
"destroying Transmit-PDO %d", tpdo->
num);
329 __co_tpdo_fini(tpdo);
330 __co_tpdo_free(tpdo);
458 if (pdo->
sync && cnt) {
459 if (pdo->
sync != cnt)
537 }
else if (pdo->
recv) {
577 co_unsigned32_t swnd = co_dev_get_val_u32(pdo->
dev, 0x1007, 0x00);
609 }
else if (pdo->
buf) {
610 can_buf_destroy(pdo->
buf);
617 static co_unsigned32_t
626 co_unsigned32_t ac = 0;
637 co_unsigned32_t cobid = val.u32;
638 co_unsigned32_t cobid_old = co_sub_get_val_u32(sub);
639 if (cobid == cobid_old)
648 if (
__unlikely(valid && valid_old && canid != canid_old)) {
664 if (valid && !valid_old) {
679 co_unsigned8_t trans = val.u8;
680 co_unsigned8_t trans_old = co_sub_get_val_u8(sub);
681 if (trans == trans_old)
685 if (
__unlikely(trans > 0xf0 && trans < 0xfc)) {
692 if (
__unlikely((trans == 0xfc || trans == 0xfd)
711 co_unsigned16_t inhibit = val.u16;
712 co_unsigned16_t inhibit_old = co_sub_get_val_u16(sub);
713 if (inhibit == inhibit_old)
728 co_unsigned16_t
event = val.u16;
729 co_unsigned16_t event_old = co_sub_get_val_u16(sub);
730 if (event == event_old)
740 co_unsigned8_t sync = val.u8;
741 co_unsigned8_t sync_old = co_sub_get_val_u8(sub);
742 if (sync == sync_old)
764 static co_unsigned32_t
773 co_unsigned32_t ac = 0;
784 co_unsigned8_t n = val.u8;
785 co_unsigned8_t n_old = co_sub_get_val_u8(sub);
796 for (
size_t i = 1; i <= n; i++) {
797 co_unsigned32_t map = pdo->
map.
map[i - 1];
798 co_unsigned16_t idx = (map >> 16) & 0xffff;
799 co_unsigned8_t subidx = (map >> 8) & 0xff;
800 co_unsigned8_t len = map & 0xff;
818 co_unsigned32_t map = val.u32;
819 co_unsigned32_t map_old = co_sub_get_val_u32(sub);
830 co_unsigned16_t idx = (map >> 16) & 0xffff;
831 co_unsigned8_t subidx = (map >> 8) & 0xff;
872 pdo->
ind(pdo, ac, ac ? NULL : msg.
data,
900 trace(
"TPDO %d: no event occurred in synchronous window", pdo->
num);
908 static co_unsigned32_t
933 #endif // !LELY_NO_CO_TPDO A CANopen SDO upload/download request.
static co_unsigned32_t co_1800_dn_ind(co_sub_t *sub, struct co_sdo_req *req, void *data)
The download indication function for (all sub-objects of) CANopen objects 1800..19FF (TPDO communicat...
int co_tpdo_event(co_tpdo_t *pdo)
Triggers the transmission of an event-driven (asynchronous) PDO.
A PDO mapping parameter record.
static int co_tpdo_init_timer_swnd(co_tpdo_t *pdo)
Initializes the CAN timer for the synchronous time window of a Transmit-PDO service.
A CAN or CAN FD format frame.
co_unsigned8_t sync
SYNC start value.
struct can_buf * buf
A CAN frame buffer.
void co_tpdo_destroy(co_tpdo_t *tpdo)
Destroys a CANopen Transmit-PDO service.
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 co_tpdo_get_next(const co_tpdo_t *pdo, struct timespec *tp)
Retrieves the time at which the next event-driven TPDO may be sent.
uint_least32_t id
The identifier (11 or 29 bits, depending on the CAN_FLAG_IDE flag).
size_t co_obj_sizeof_val(const co_obj_t *obj)
Returns size (in bytes) of the value of a CANopen object.
static int co_tpdo_recv(const struct can_msg *msg, void *data)
The CAN receive callback function for a Transmit-PDO service.
#define CAN_MASK_EID
The mask used to extract the 29-bit Extended Identifier from a CAN frame.
uint_least8_t len
The number of bytes in data (or the requested number of bytes in case of a remote frame)...
#define CO_PDO_COBID_RTR
The bit in the PDO COB-ID specifying whether RTR is allowed.
This header file is part of the CANopen library; it contains the Transmit-PDO declarations.
void can_timer_timeout(can_timer_t *timer, can_net_t *net, int timeout)
Starts a CAN timer and registers it with a network interface.
co_tpdo_ind_t * ind
A pointer to the indication function.
int errnum2c(errnum_t errnum)
Transforms a platform-independent error number to a native error code.
can_timer_t * timer_event
A pointer to the CAN timer for events.
#define CAN_MSG_INIT
The static initializer for can_msg.
void set_errnum(errnum_t errnum)
Sets the current (thread-specific) platform-independent error number to errnum.
co_unsigned8_t n
Number of mapped objects in PDO.
#define CO_SDO_AC_PARAM_VAL
SDO abort code: Invalid value for parameter (download only).
A union of the CANopen static data types.
can_recv_t * recv
A pointer to the CAN frame receiver.
co_unsigned8_t sync
The SYNC start value.
void can_net_get_time(const can_net_t *net, struct timespec *tp)
Retrieves the current time of a CAN network interface.
A PDO communication parameter record.
#define MIN(a, b)
Returns the minimum of a and b.
#define CAN_MASK_BID
The mask used to extract the 11-bit Base Identifier from a CAN frame.
void co_tpdo_ind_t(co_tpdo_t *pdo, co_unsigned32_t ac, const void *ptr, size_t n, void *data)
The type of a CANopen Transmit-PDO indication function, invoked when a PDO is sent or an error occurs...
co_unsigned32_t cobid
COB-ID.
This header file is part of the CANopen library; it contains the Service Data Object (SDO) declaratio...
static int co_tpdo_timer_swnd(const struct timespec *tp, void *data)
The CAN timer callback function for the synchronous time window of a Transmit-PDO service...
void co_tpdo_set_ind(co_tpdo_t *pdo, co_tpdo_ind_t *ind, void *data)
Sets the indication function invoked when a Transmit-PDO error occurs.
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.
const struct co_pdo_comm_par * co_tpdo_get_comm_par(const co_tpdo_t *pdo)
Returns a pointer to the PDO communication parameter record of a Transmit-PDO.
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.
static int co_tpdo_init_recv(co_tpdo_t *pdo)
Initializes the CAN frame receiver of a Transmit-PDO service.
void * data
A pointer to user-specified data for ind.
#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).
co_unsigned16_t num
The PDO number.
This header file is part of the utilities library; it contains the native and platform-independent er...
co_unsigned16_t event
Event timer.
#define __likely(x)
Indicates to the compiler that the expression is most-likely true.
This header file is part of the utilities library; it contains the time function declarations.
#define CAN_FLAG_IDE
The Identifier Extension (IDE) flag.
#define CO_PDO_COBID_FRAME
The bit in the PDO COB-ID specifying whether to use an 11-bit (0) or 29-bit (1) CAN-ID.
struct co_pdo_comm_par comm
The PDO communication parameter.
#define CO_DEFTYPE_UNSIGNED16
The data type (and object index) of a 16-bit unsigned integer.
const struct co_pdo_map_par * co_tpdo_get_map_par(const co_tpdo_t *pdo)
Returns a pointer to the PDO mapping parameter record of a Transmit-PDO.
void can_recv_destroy(can_recv_t *recv)
Destroys a CAN frame receiver.
#define CO_SDO_AC_TIMEOUT
SDO abort code: SDO protocol timed out.
can_net_t * net
A pointer to a CAN network interface.
This is the internal header file of the CANopen library.
size_t can_buf_reserve(struct can_buf *buf, size_t n)
Resizes a CAN frame buffer, if necessary, to make room for at least n additional frames.
This header file is part of the CAN library; it contains the CAN frame buffer declarations.
void co_tpdo_get_ind(const co_tpdo_t *pdo, co_tpdo_ind_t **pind, void **pdata)
Retrieves the indication function invoked when a Transmit-PDO error occurs.
#define CO_PDO_COBID_VALID
The bit in the PDO COB-ID specifying whether the PDO exists and is valid.
int get_errc(void)
Returns the last (thread-specific) native error code set by a system call or library function...
Resource unavailable, try again.
#define CO_SDO_AC_PDO_LEN
SDO abort code: The number and length of the objects to be mapped would exceed the PDO length...
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...
co_dev_t * co_tpdo_get_dev(const co_tpdo_t *pdo)
Returns a pointer to the CANopen device of a Transmit-PDO.
#define CO_DEFTYPE_UNSIGNED8
The data type (and object index) of an 8-bit unsigned integer.
unsigned int event
A flag indicating the occurrence of an event.
int co_tpdo_sync(co_tpdo_t *pdo, co_unsigned8_t cnt)
Triggers the transmission of a synchronous PDO.
co_tpdo_t * co_tpdo_create(can_net_t *net, co_dev_t *dev, co_unsigned16_t num)
Creates a new CANopen Transmit-PDO service.
int errno2c(int errnum)
Transforms a standard C error number to a native error code.
#define CO_SDO_AC_NO_WRITE
SDO abort code: Attempt to write a read only object.
#define __unlikely(x)
Indicates to the compiler that the expression is most-likely false.
int timespec_cmp(const void *p1, const void *p2)
Compares two times.
size_t can_buf_read(struct can_buf *buf, struct can_msg *ptr, size_t n)
Reads, and removes, frames from a CAN frame buffer.
struct timespec inhibit
The time at which the next event-driven TPDO may be sent.
co_unsigned8_t cnt
The SYNC counter value.
co_unsigned32_t co_pdo_up(const struct co_pdo_map_par *par, const co_dev_t *dev, struct co_sdo_req *req, uint8_t *buf, size_t *pn)
Reads mapped PDO values from the object dictionary through a local SDO upload request.
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_EDL, 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.
can_timer_t * can_timer_create(void)
Creates a new CAN timer.
struct can_buf * can_buf_create(size_t size)
Allocates and initializes a CAN frame buffer.
This header file is part of the CANopen library; it contains the device description declarations...
static int co_tpdo_init_buf(co_tpdo_t *pdo)
Initializes the CAN frame buffer of a Transmit-PDO service.
static co_unsigned32_t co_1a00_dn_ind(co_sub_t *sub, struct co_sdo_req *req, void *data)
The download indication function for (all sub-objects of) CANopen objects 1A00..1BFF (TPDO mapping pa...
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.
struct co_pdo_map_par map
The PDO mapping parameter.
unsigned int swnd
A flag indicating the synchronous time window has expired.
#define CO_SDO_AC_NO_SUB
SDO abort code: Sub-index does not exist.
void co_sdo_req_init(struct co_sdo_req *req)
Initializes a CANopen SDO upload/download request.
size_t can_buf_write(struct can_buf *buf, const struct can_msg *ptr, size_t n)
Writes frames to a CAN frame buffer.
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_dev_t * dev
A pointer to a CANopen device.
co_unsigned32_t map[0x40]
An array of objects to be mapped.
#define CAN_FLAG_RTR
The Remote Transmission Request (RTR) flag (unavailable in CAN FD format frames). ...
co_unsigned8_t co_sub_get_subidx(const co_sub_t *sub)
Returns the sub-index of a CANopen sub-object.
This header file is part of the C11 and POSIX compatibility library; it includes <stdlib.h> and defines any missing functionality.
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_sdo_req_fini(struct co_sdo_req *req)
Finalizes a CANopen SDO upload/download request.
co_unsigned16_t co_sub_get_type(const co_sub_t *sub)
Returns the data type of a CANopen sub-object.
#define CAN_MAX_LEN
The maximum number of bytes in the payload of a CAN format frame.
co_unsigned16_t co_tpdo_get_num(const co_tpdo_t *pdo)
Returns the PDO number of a Transmit-PDO.
co_unsigned16_t co_obj_get_idx(const co_obj_t *obj)
Returns the index of a CANopen object.
can_timer_t * timer_swnd
A pointer to the CAN timer for the synchronous time window.
co_unsigned16_t inhibit
Inhibit time.
This header file is part of the CANopen library; it contains the object dictionary declarations...
co_unsigned32_t co_dev_chk_tpdo(const co_dev_t *dev, co_unsigned16_t idx, co_unsigned8_t subidx)
Checks if the specified object is valid and can be mapped into a Transmit-PDO.
struct co_sdo_req req
The CANopen SDO upload request used for reading sub-objects.
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.
static int co_tpdo_timer_event(const struct timespec *tp, void *data)
The CAN timer callback function for events of a Transmit-PDO service.
co_unsigned8_t trans
Transmission type.
void * co_obj_addressof_val(const co_obj_t *obj)
Returns the address of the value of a CANopen object.
static co_unsigned32_t co_tpdo_init_frame(co_tpdo_t *pdo, struct can_msg *msg)
Initializes a CAN frame to be sent by a Transmit-PDO service.
can_net_t * co_tpdo_get_net(const co_tpdo_t *pdo)
Returns a pointer to the CAN network of a Transmit-PDO.
static int co_tpdo_init_timer_event(co_tpdo_t *pdo)
Initializes the CAN timer for events of a Transmit-PDO service.