Lely core libraries
2.2.5
|
Go to the documentation of this file.
26 #ifndef LELY_NO_CO_TPDO
146 __co_tpdo_alloc(
void)
148 void *ptr = malloc(
sizeof(
struct __co_tpdo));
155 __co_tpdo_free(
void *ptr)
178 if (!obj_1800 || !obj_1a00) {
188 memset(&pdo->
comm, 0,
sizeof(pdo->
comm));
193 memset(&pdo->
map, 0,
sizeof(pdo->
map));
222 goto error_init_recv;
227 goto error_init_timer_event;
233 error_init_timer_event:
247 assert(pdo->
num >= 1 && pdo->
num <= 512);
271 trace(
"creating Transmit-PDO %d", num);
278 goto error_alloc_pdo;
281 if (!__co_tpdo_init(pdo, net, dev, num)) {
299 trace(
"destroying Transmit-PDO %d", tpdo->
num);
300 __co_tpdo_fini(tpdo);
301 __co_tpdo_free(tpdo);
375 case 0x00: pdo->
event = 1;
break;
430 if (pdo->
sync && cnt) {
431 if (pdo->
sync != cnt)
493 }
else if (pdo->
recv) {
526 static co_unsigned32_t
535 co_unsigned32_t ac = 0;
546 co_unsigned32_t cobid = val.u32;
547 co_unsigned32_t cobid_old = co_sub_get_val_u32(sub);
548 if (cobid == cobid_old)
557 if (valid && valid_old && canid != canid_old) {
571 if (valid && !valid_old) {
587 co_unsigned8_t trans = val.u8;
588 co_unsigned8_t trans_old = co_sub_get_val_u8(sub);
589 if (trans == trans_old)
593 if (trans > 0xf0 && trans < 0xfc) {
599 if ((trans == 0xfc || trans == 0xfd)
612 co_unsigned16_t inhibit = val.u16;
613 co_unsigned16_t inhibit_old = co_sub_get_val_u16(sub);
614 if (inhibit == inhibit_old)
629 co_unsigned16_t
event = val.u16;
630 co_unsigned16_t event_old = co_sub_get_val_u16(sub);
631 if (event == event_old)
641 co_unsigned8_t sync = val.u8;
642 co_unsigned8_t sync_old = co_sub_get_val_u8(sub);
643 if (sync == sync_old)
665 static co_unsigned32_t
674 co_unsigned32_t ac = 0;
685 co_unsigned8_t n = val.u8;
686 co_unsigned8_t n_old = co_sub_get_val_u8(sub);
691 if (valid || n > 0x40) {
697 for (
size_t i = 1; i <= n; i++) {
698 co_unsigned32_t map = pdo->
map.
map[i - 1];
702 co_unsigned16_t idx = (map >> 16) & 0xffff;
703 co_unsigned8_t subidx = (map >> 8) & 0xff;
704 co_unsigned8_t len = map & 0xff;
722 co_unsigned32_t map = val.u32;
723 co_unsigned32_t map_old = co_sub_get_val_u32(sub);
729 if (valid || pdo->
map.
n) {
735 co_unsigned16_t idx = (map >> 16) & 0xffff;
736 co_unsigned8_t subidx = (map >> 8) & 0xff;
815 pdo->
ind(pdo, ac, NULL, 0, pdo->
data);
838 #endif // !LELY_NO_CO_TPDO
#define CO_PDO_COBID_VALID
The bit in the PDO COB-ID specifying whether the PDO exists and is valid.
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...
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_unsigned8_t sync
SYNC start value.
uint_least8_t data[CAN_MSG_MAX_LEN]
The frame payload (in case of a data frame).
co_unsigned8_t sync
The SYNC start 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_PDO_COBID_FRAME
The bit in the PDO COB-ID specifying whether to use an 11-bit (0) or 29-bit (1) CAN-ID.
void co_val_fini(co_unsigned16_t type, void *val)
Finalizes a value of the specified data type.
#define CO_DEFTYPE_UNSIGNED32
The data type (and object index) of a 32-bit unsigned integer.
void * co_obj_addressof_val(const co_obj_t *obj)
Returns the address of the value of a CANopen object.
#define CAN_MASK_BID
The mask used to extract the 11-bit Base Identifier from a CAN frame.
size_t co_obj_sizeof_val(const co_obj_t *obj)
Returns size (in bytes) of the value of a CANopen object.
A CAN or CAN FD format frame.
co_unsigned16_t event
Event timer.
#define CO_DEFTYPE_UNSIGNED16
The data type (and object index) of a 16-bit unsigned integer.
struct co_sdo_req req
The CANopen SDO upload request used for reading sub-objects.
uint_least8_t len
The number of bytes in data (or the requested number of bytes in case of a remote frame).
co_unsigned32_t co_pdo_up(const struct co_pdo_map_par *par, const co_dev_t *dev, struct co_sdo_req *req, uint_least8_t *buf, size_t *pn)
Reads mapped PDO values from the object dictionary through a local SDO upload request.
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.
#define MIN(a, b)
Returns the minimum of a and b.
struct can_msg msg
A buffered CAN frame, used for RTR-only or event-driven TPDOs.
co_unsigned16_t co_obj_get_idx(const co_obj_t *obj)
Returns the index of a CANopen object.
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.
struct co_pdo_comm_par comm
The PDO communication parameter.
co_dev_t * dev
A pointer to a CANopen device.
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.
int get_errc(void)
Returns the last (thread-specific) native error code set by a system call or library function.
int co_tpdo_event(co_tpdo_t *pdo)
Triggers the transmission of an acyclic or event-driven PDO.
int timespec_cmp(const void *p1, const void *p2)
Compares two times.
int errno2c(int errnum)
Transforms a standard C error number to a native error code.
static int co_tpdo_send_frame(co_tpdo_t *pdo, const struct can_msg *msg)
Sends a CAN frame from a Transmit-PDO service and invokes the indication function.
#define CO_DEFTYPE_UNSIGNED8
The data type (and object index) of an 8-bit unsigned integer.
A PDO communication parameter record.
co_unsigned8_t trans
Transmission type.
static int co_tpdo_timer_event(const struct timespec *tp, void *data)
The CAN timer callback function for events of a Transmit-PDO service.
#define CAN_MSG_INIT
The static initializer for can_msg.
co_unsigned8_t n
Number of mapped objects in PDO.
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...
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.
#define CAN_MAX_LEN
The maximum number of bytes in the payload of a CAN format frame.
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...
co_tpdo_ind_t * ind
A pointer to the indication function.
void set_errnum(errnum_t errnum)
Sets the current (thread-specific) platform-independent error number to errnum.
void set_errc(int errc)
Sets the current (thread-specific) native error code to errc.
static int co_tpdo_init_frame(co_tpdo_t *pdo, struct can_msg *msg)
Initializes a CAN frame to be sent by a Transmit-PDO service.
void can_timer_destroy(can_timer_t *timer)
Destroys a CAN timer.
#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.
co_unsigned16_t num
The PDO number.
co_unsigned8_t cnt
The SYNC counter value.
#define CO_SDO_AC_ERROR
SDO abort code: General error.
@ ERRNUM_INVAL
Invalid argument.
void co_sdo_req_init(struct co_sdo_req *req)
Initializes a CANopen SDO upload/download request.
co_unsigned16_t inhibit
Inhibit time.
struct co_pdo_map_par map
The PDO mapping parameter.
#define CO_SDO_AC_PDO_LEN
SDO abort code: The number and length of the objects to be mapped would exceed the PDO length.
#define CO_SDO_AC_NO_WRITE
SDO abort code: Attempt to write a read only object.
co_unsigned16_t co_tpdo_get_num(const co_tpdo_t *pdo)
Returns the PDO number of a Transmit-PDO.
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.
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.
A union of the CANopen static data types.
unsigned int event
A flag indicating the occurrence of an event.
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_net_t * co_tpdo_get_net(const co_tpdo_t *pdo)
Returns a pointer to the CAN network of a Transmit-PDO.
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 * co_tpdo_get_dev(const co_tpdo_t *pdo)
Returns a pointer to the CANopen device of a Transmit-PDO.
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.
#define CO_SDO_AC_PARAM_VAL
SDO abort code: Invalid value for parameter (download only).
struct timespec inhibit
The time at which the next event-driven TPDO may be sent.
@ CAN_FLAG_RTR
The Remote Transmission Request (RTR) flag (unavailable in CAN FD format frames).
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.
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.
int can_net_send(can_net_t *net, const struct can_msg *msg)
Sends a CAN frame from a network interface.
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.
static int co_tpdo_init_recv(co_tpdo_t *pdo)
Initializes the CAN frame receiver of a Transmit-PDO service.
void co_tpdo_destroy(co_tpdo_t *tpdo)
Destroys a CANopen Transmit-PDO service.
co_unsigned32_t cobid
COB-ID.
int co_tpdo_sync(co_tpdo_t *pdo, co_unsigned8_t cnt)
Triggers the transmission of a synchronous PDO.
static int co_tpdo_init_timer_event(co_tpdo_t *pdo)
Initializes the CAN timer for events of a Transmit-PDO service.
co_unsigned8_t co_sub_get_subidx(const co_sub_t *sub)
Returns the sub-index of a CANopen sub-object.
#define CO_PDO_COBID_RTR
The bit in the PDO COB-ID specifying whether RTR is allowed.
void co_sdo_req_fini(struct co_sdo_req *req)
Finalizes a CANopen SDO upload/download request.
can_net_t * net
A pointer to a CAN network interface.
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.
can_recv_t * recv
A pointer to the CAN frame receiver.
co_unsigned16_t co_sub_get_type(const co_sub_t *sub)
Returns the data type of a CANopen sub-object.
can_timer_t * timer_event
A pointer to the CAN timer for events.
static int co_tpdo_recv(const struct can_msg *msg, void *data)
The CAN receive callback function for a Transmit-PDO service.
@ CAN_FLAG_IDE
The Identifier Extension (IDE) flag.
A PDO mapping parameter record.
@ ERRNUM_AGAIN
Resource unavailable, try again.
void timespec_add_usec(struct timespec *tp, uint_least64_t usec)
Adds usec microseconds to the time at tp.
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.
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 * data
A pointer to user-specified data for ind.
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...
uint_least32_t id
The identifier (11 or 29 bits, depending on the CAN_FLAG_IDE flag).
co_unsigned32_t map[0x40]
An array of objects to be mapped.
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.