26 #ifndef LELY_NO_CO_RPDO
156 __co_rpdo_alloc(
void)
158 void *ptr = malloc(
sizeof(
struct __co_rpdo));
165 __co_rpdo_free(
void *ptr)
188 if (!obj_1400 || !obj_1600) {
198 memset(&pdo->
comm, 0,
sizeof(pdo->
comm));
203 memset(&pdo->
map, 0,
sizeof(pdo->
map));
232 goto error_init_recv;
250 assert(pdo->
num >= 1 && pdo->
num <= 512);
275 trace(
"creating Receive-PDO %d", num);
282 goto error_alloc_pdo;
285 if (!__co_rpdo_init(pdo, net, dev, num)) {
303 trace(
"destroying Receive-PDO %d", rpdo->
num);
304 __co_rpdo_fini(rpdo);
305 __co_rpdo_free(rpdo);
450 uint_least8_t
flags = 0;
458 }
else if (pdo->
recv) {
495 co_unsigned32_t swnd = co_dev_get_val_u32(pdo->
dev, 0x1007, 0x00);
505 struct timespec start = { 0, 0 };
517 static co_unsigned32_t
526 co_unsigned32_t ac = 0;
537 co_unsigned32_t cobid = val.u32;
538 co_unsigned32_t cobid_old = co_sub_get_val_u32(sub);
539 if (cobid == cobid_old)
548 if (valid && valid_old && canid != canid_old) {
574 co_unsigned8_t trans = val.u8;
575 co_unsigned8_t trans_old = co_sub_get_val_u8(sub);
576 if (trans == trans_old)
580 if (trans > 0xf0 && trans < 0xfe) {
590 co_unsigned16_t inhibit = val.u16;
591 co_unsigned16_t inhibit_old = co_sub_get_val_u16(sub);
592 if (inhibit == inhibit_old)
607 co_unsigned16_t
event = val.u16;
608 co_unsigned16_t event_old = co_sub_get_val_u16(sub);
609 if (event == event_old)
624 static co_unsigned32_t
633 co_unsigned32_t ac = 0;
644 co_unsigned8_t n = val.u8;
645 co_unsigned8_t n_old = co_sub_get_val_u8(sub);
650 if (valid || n > 0x40) {
656 for (
size_t i = 1; i <= n; i++) {
657 co_unsigned32_t map = pdo->
map.
map[i - 1];
661 co_unsigned16_t idx = (map >> 16) & 0xffff;
662 co_unsigned8_t subidx = (map >> 8) & 0xff;
663 co_unsigned8_t len = map & 0xff;
681 co_unsigned32_t map = val.u32;
682 co_unsigned32_t map_old = co_sub_get_val_u32(sub);
688 if (valid || pdo->
map.
n) {
694 co_unsigned16_t idx = (map >> 16) & 0xffff;
695 co_unsigned8_t subidx = (map >> 8) & 0xff;
723 #ifndef LELY_NO_CANFD
725 if (msg->
flags & CAN_FLAG_EDL)
754 trace(
"RPDO %d: no PDO received in synchronous window", pdo->
num);
776 static co_unsigned32_t
788 trace(
"RPDO %d: PDO error %08" PRIX32
" (%s)", pdo->
num, ac,
803 for (
size_t i = 0; i <
MIN(pdo->
map.
n, 0x40u); i++)
804 offset += (pdo->
map.
map[i]) & 0xff;
805 if ((offset + 7) / 8 < n)
@ 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_MAX_LEN
The maximum number of bytes in the payload of a CAN format 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.
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_INVAL
Invalid argument.
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.
void set_errnum(errnum_t errnum)
Sets the current (thread-specific) platform-independent error number to errnum.
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.
void * co_obj_addressof_val(const co_obj_t *obj)
Returns the address of the value 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.
size_t co_obj_sizeof_val(const co_obj_t *obj)
Returns size (in bytes) of the value of a CANopen object.
co_unsigned16_t co_sub_get_type(const co_sub_t *sub)
Returns the data type of a CANopen sub-object.
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,...
void co_sdo_req_fini(struct co_sdo_req *req)
Finalizes a CANopen SDO upload/download request.
#define CO_SDO_AC_NO_SUB
SDO abort code: Sub-index does not exist.
const char * co_sdo_ac2str(co_unsigned32_t ac)
Returns a string describing an SDO abort code.
#define CO_SDO_AC_PARAM_VAL
SDO abort code: Invalid value for parameter (download only).
#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 co_sdo_req_init(struct co_sdo_req *req)
Initializes a CANopen SDO upload/download request.
#define CO_SDO_AC_NO_WRITE
SDO abort code: Attempt to write a read only object.
#define MIN(a, b)
Returns the minimum of a and b.
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.
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.
can_recv_t * can_recv_create(void)
Creates a new CAN frame receiver.
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.
can_timer_t * can_timer_create(void)
Creates a new CAN timer.
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.
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.
void can_timer_destroy(can_timer_t *timer)
Destroys a CAN timer.
co_unsigned32_t co_dev_chk_rpdo(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 Receive-PDO.
co_unsigned32_t co_pdo_dn(const struct co_pdo_map_par *par, co_dev_t *dev, struct co_sdo_req *req, const uint_least8_t *buf, size_t n)
Writes mapped PDO values to the object dictionary through a local SDO download request.
#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.
#define CO_PDO_COBID_VALID
The bit in the PDO COB-ID specifying whether the PDO exists and is valid.
void co_rpdo_get_err(const co_rpdo_t *pdo, co_rpdo_err_t **perr, void **pdata)
Retrieves the error handling function of a Receive-PDO service.
int co_rpdo_rtr(co_rpdo_t *pdo)
Requests the transmission of a PDO.
static int co_rpdo_timer_event(const struct timespec *tp, void *data)
The CAN timer callback function for deadline monitoring of a Receive-PDO service.
co_dev_t * co_rpdo_get_dev(const co_rpdo_t *pdo)
Returns a pointer to the CANopen device of a Receive-PDO.
co_rpdo_t * co_rpdo_create(can_net_t *net, co_dev_t *dev, co_unsigned16_t num)
Creates a new CANopen Receive-PDO service.
static int co_rpdo_timer_swnd(const struct timespec *tp, void *data)
The CAN timer callback function for the synchronous time window of a Receive-PDO service.
static co_unsigned32_t co_rpdo_read_frame(co_rpdo_t *pdo, const struct can_msg *msg)
Parses a CAN frame received by a Receive-PDO service and updates the corresponding objects in the obj...
int co_rpdo_sync(co_rpdo_t *pdo, co_unsigned8_t cnt)
Triggers the actuation of a received synchronous PDO.
void co_rpdo_set_err(co_rpdo_t *pdo, co_rpdo_err_t *err, void *data)
Sets the error handling function of a Receive-PDO service.
static co_unsigned32_t co_1400_dn_ind(co_sub_t *sub, struct co_sdo_req *req, void *data)
The download indication function for (all sub-objects of) CANopen objects 1400..15FF (RPDO communicat...
static int co_rpdo_init_timer_event(co_rpdo_t *pdo)
Initializes the CAN timer for deadline monitoring of a Receive-PDO service.
static int co_rpdo_init_timer_swnd(co_rpdo_t *pdo)
Initializes the CAN timer for the synchronous time window of a Receive-PDO service.
static co_unsigned32_t co_1600_dn_ind(co_sub_t *sub, struct co_sdo_req *req, void *data)
The download indication function for (all sub-objects of) CANopen objects 1600..17FF (RPDO mapping pa...
const struct co_pdo_map_par * co_rpdo_get_map_par(const co_rpdo_t *pdo)
Returns a pointer to the PDO mapping parameter record of a Receive-PDO.
void co_rpdo_get_ind(const co_rpdo_t *pdo, co_rpdo_ind_t **pind, void **pdata)
Retrieves the indication function invoked when a Receive-PDO error occurs.
co_unsigned16_t co_rpdo_get_num(const co_rpdo_t *pdo)
Returns the PDO number of a Receive-PDO.
static int co_rpdo_recv(const struct can_msg *msg, void *data)
The CAN receive callback function for a Receive-PDO service.
static int co_rpdo_init_recv(co_rpdo_t *pdo)
Initializes the CAN frame receiver of a Receive-PDO service.
can_net_t * co_rpdo_get_net(const co_rpdo_t *pdo)
Returns a pointer to the CAN network of a Receive-PDO.
void co_rpdo_set_ind(co_rpdo_t *pdo, co_rpdo_ind_t *ind, void *data)
Sets the indication function invoked when a Receive-PDO error occurs.
const struct co_pdo_comm_par * co_rpdo_get_comm_par(const co_rpdo_t *pdo)
Returns a pointer to the PDO communication parameter record of a Receive-PDO.
void co_rpdo_destroy(co_rpdo_t *rpdo)
Destroys a CANopen Receive-PDO service.
This header file is part of the CANopen library; it contains the Receive-PDO declarations.
void co_rpdo_err_t(co_rpdo_t *pdo, co_unsigned16_t eec, co_unsigned8_t er, void *data)
The type of a CANopen Receive-PDO error handling function, invoked in case of a timeout or length mis...
void co_rpdo_ind_t(co_rpdo_t *pdo, co_unsigned32_t ac, const void *ptr, size_t n, void *data)
The type of a CANopen Receive-PDO indication function, invoked when a PDO is received or an error occ...
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....
void * ind_data
A pointer to user-specified data for ind.
can_net_t * net
A pointer to a CAN network interface.
struct co_sdo_req req
The CANopen SDO download request used for writing sub-objects.
can_timer_t * timer_swnd
A pointer to the CAN timer for the synchronous time window.
unsigned int sync
A flag indicating we're waiting for a SYNC object to process msg.
unsigned int swnd
A flag indicating the synchronous time window has expired.
can_timer_t * timer_event
A pointer to the CAN timer for deadline monitoring.
co_unsigned16_t num
The PDO number.
struct co_pdo_comm_par comm
The PDO communication parameter.
co_dev_t * dev
A pointer to a CANopen device.
can_recv_t * recv
A pointer to the CAN frame receiver.
co_rpdo_ind_t * ind
A pointer to the indication function.
void * err_data
A pointer to user-specified data for err.
struct co_pdo_map_par map
The PDO mapping parameter.
co_rpdo_err_t * err
A pointer to the error handling function.
struct can_msg msg
A CAN frame waiting for a SYNC object to be processed.
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 PDO communication parameter record.
co_unsigned16_t inhibit
Inhibit time.
co_unsigned16_t event
Event timer.
co_unsigned32_t cobid
COB-ID.
co_unsigned8_t trans
Transmission type.
A PDO mapping parameter record.
co_unsigned8_t n
Number of mapped objects in PDO.
co_unsigned32_t map[0x40]
An array of objects to be mapped.
A CANopen SDO upload/download request.
#define CO_DEFTYPE_UNSIGNED16
The data type (and object index) of a 16-bit unsigned integer.
#define CO_DEFTYPE_UNSIGNED8
The data type (and object index) of an 8-bit unsigned integer.
#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.
void timespec_add_usec(struct timespec *tp, uint_least64_t usec)
Adds usec microseconds to the time at tp.
This header file is part of the CANopen library; it contains the CANopen value declarations.
void co_val_fini(co_unsigned16_t type, void *val)
Finalizes a value of the specified data type.