42#ifndef CO_CSDO_MEMBUF_SIZE
48#define CO_CSDO_MEMBUF_SIZE 8
63 const uint_least8_t *
end;
118 char begin[CO_CSDO_MEMBUF_SIZE];
241#define LELY_CO_DEFINE_STATE(name, ...) \
242 static co_csdo_state_t *const name = &(co_csdo_state_t){ __VA_ARGS__ };
291 co_csdo_t *sdo, const struct timespec *tp);
318 co_csdo_t *sdo, const struct timespec *tp);
342 co_csdo_t *sdo, const struct timespec *tp);
363 co_csdo_t *sdo, const struct timespec *tp);
384 co_csdo_t *sdo, const struct timespec *tp);
411 co_csdo_t *sdo, const struct timespec *tp);
436 co_csdo_t *sdo, const struct timespec *tp);
460 co_csdo_t *sdo, const struct timespec *tp);
484 co_csdo_t *sdo, const struct timespec *tp);
508 co_csdo_t *sdo, const struct timespec *tp);
525#undef LELY_CO_DEFINE_STATE
557 co_unsigned8_t subidx,
const void *ptr,
size_t n,
569 co_unsigned8_t subidx,
struct membuf *buf,
595 co_csdo_t *sdo, co_unsigned32_t n,
int last);
661 co_unsigned8_t subidx, co_unsigned32_t ac,
void *
data);
672 co_unsigned32_t ac = 0;
693 con(NULL, idx, subidx, ac, data);
710 co_unsigned32_t ac = 0;
731 con(NULL, idx, subidx, ac, data);
744 assert(end >= begin);
749 co_unsigned16_t idx = 0;
750 co_unsigned8_t subidx = 0;
751 co_unsigned32_t ac = 0;
761 for (
size_t i = 0; i < n && !ac; i++) {
774 co_unsigned32_t
size;
778 if (end - begin < (ptrdiff_t)
size)
804 con(NULL, idx, subidx, ac, data);
819 co_unsigned32_t ac = 0;
835 && subidx > co_obj_get_val_u8(obj, 0)) {
856 con(NULL, idx, subidx, ac, ac ? NULL :
buf.begin,
867 void *ptr = malloc(
sizeof(
struct __co_csdo));
876__co_csdo_free(
void *ptr)
898 if (
dev && !obj_1280) {
916 goto error_create_recv;
925 goto error_create_timer;
945 memset(sdo->begin, 0, CO_CSDO_MEMBUF_SIZE);
999 trace(
"creating Client-SDO %d", num);
1006 goto error_alloc_sdo;
1009 if (!__co_csdo_init(sdo, net, dev, num)) {
1011 goto error_init_sdo;
1017 __co_csdo_free(sdo);
1027 trace(
"destroying Client-SDO %d", csdo->
num);
1028 __co_csdo_fini(csdo);
1029 __co_csdo_free(csdo);
1042 co_unsigned16_t idx_1280 = 0x1280 + sdo->
num - 1;
1046 memset(&sdo->
par, 0,
sizeof(sdo->
par));
1047 sdo->
par.
n = co_dev_get_val_u8(sdo->
dev, idx_1280, 0);
1050 sdo->
par.
id = co_dev_get_val_u8(sdo->
dev, idx_1280, 3);
1146 if (sdo->
timeout && timeout <= 0)
1199 return valid_req && valid_res;
1227 trace(
"CSDO: %04X:%02X: initiate download", idx, subidx);
1258 if (
co_val_write(type, val, ptr, (uint_least8_t *)ptr + n) != n)
1278 co_unsigned32_t ac = 0;
1302 trace(
"CSDO: %04X:%02X: initiate upload", idx, subidx);
1321 trace(
"CSDO: %04X:%02X: initiate block download", idx, subidx);
1333 co_unsigned8_t subidx, co_unsigned16_t type,
const void *val,
1349 if (
co_val_write(type, val, ptr, (uint_least8_t *)ptr + n) != n)
1364 trace(
"CSDO: %04X:%02X: initiate block upload", idx, subidx);
1387 uint_least8_t flags = 0;
1402static co_unsigned32_t
1415 co_unsigned32_t ac = 0;
1423 co_unsigned32_t cobid = val.u32;
1424 co_unsigned32_t cobid_old = co_sub_get_val_u32(sub);
1425 if (cobid == cobid_old)
1434 if (valid && valid_old && canid != canid_old)
1447 co_unsigned32_t cobid = val.u32;
1448 co_unsigned32_t cobid_old = co_sub_get_val_u32(sub);
1449 if (cobid == cobid_old)
1458 if (valid && valid_old && canid != canid_old)
1471 co_unsigned8_t
id = val.u8;
1472 co_unsigned8_t id_old = co_sub_get_val_u8(sub);
1501 if (msg->
flags & CAN_FLAG_EDL)
1595 co_unsigned8_t cs = msg->
data[0];
1602 default:
return NULL;
1632 dn_con(sdo, sdo->
idx, sdo->
subidx, sdo->
ac, dn_con_data);
1633 }
else if (up_con) {
1665 co_unsigned8_t cs = msg->
data[0];
1681 co_unsigned8_t subidx = msg->
data[3];
1682 if (idx != sdo->
idx || subidx != sdo->
subidx)
1730 co_unsigned8_t cs = msg->
data[0];
1773 co_unsigned8_t cs = msg->
data[0];
1789 co_unsigned8_t subidx = msg->
data[3];
1790 if (idx != sdo->
idx || subidx != sdo->
subidx)
1795 uint_least8_t data[4] = { 0 };
1796 memcpy(data, msg->
data + 4, msg->
len - 4);
1854 co_unsigned8_t cs = msg->
data[0];
1872 if (msg->
len < 1 + n)
1921 co_unsigned8_t cs = msg->
data[0];
1944 co_unsigned8_t subidx = msg->
data[3];
1945 if (idx != sdo->
idx || subidx != sdo->
subidx)
1974 for (co_unsigned8_t seqno = 1; seqno <= sdo->
blksize; seqno++)
2006 co_unsigned8_t cs = msg->
data[0];
2024 co_unsigned8_t ackseq = msg->
data[1];
2025 if (ackseq < sdo->blksize) {
2065 co_unsigned8_t cs = msg->
data[0];
2108 co_unsigned8_t cs = msg->
data[0];
2135 co_unsigned8_t subidx = msg->
data[3];
2136 if (idx != sdo->
idx || subidx != sdo->
subidx)
2144 uint_least8_t data[4] = { 0 };
2145 memcpy(data, msg->
data + 4, msg->
len - 4);
2185 co_unsigned8_t cs = msg->
data[0];
2192 co_unsigned8_t seqno = cs & ~CO_SDO_SEQ_LAST;
2197 if (seqno == sdo->
ackseq + 1) {
2212 if (seqno == sdo->
blksize || last) {
2246 co_unsigned8_t cs = msg->
data[0];
2267 co_unsigned8_t n = sdo->
size ? (sdo->
size - 1) % 7 + 1 : 0;
2313 sdo->
size = ptr ? n : 0;
2382 assert(sdo->
size && sdo->
size <= 4);
2399 assert(!sdo->
size || sdo->
size > 4);
2428 memcpy(msg.
data + 1, buf->
cur, n);
2488 co_unsigned8_t cs = seqno;
2494 memcpy(msg.
data + 1, buf->
cur, n);
2506 co_unsigned8_t n = sdo->
size ? (sdo->
size - 1) % 7 + 1 : 0;
2511 co_unsigned16_t crc = sdo->
crc
2624 co_unsigned8_t subidx, co_unsigned32_t ac,
void *
data)
2631 if (!ac && dcf->
n--) {
2650 co_unsigned32_t size;
2657 if (dcf->
end - dcf->
begin < (ptrdiff_t)size)
2659 const void *ptr = dcf->
begin;
2675 con(sdo, idx, subidx, ac, data);
@ 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.
#define CO_NUM_NODES
The maximum number of nodes in a CANopen network.
This header file is part of the CANopen library; it contains the Cyclic Redundancy Check (CRC) declar...
uint_least16_t co_crc(uint_least16_t crc, const uint_least8_t *bp, size_t n)
Computes a CRC-16 checksum.
static co_unsigned32_t co_1280_dn_ind(co_sub_t *sub, struct co_sdo_req *req, void *data)
The download indication function for (all sub-objects of) CANopen objects 1280..12FF (SDO client para...
static int co_csdo_recv(const struct can_msg *msg, void *data)
The CAN receive callback function for a Client-SDO service.
static void co_csdo_emit_recv(co_csdo_t *sdo, const struct can_msg *msg)
Invokes the 'CAN frame received' transition function of the current state of a Client-SDO service.
static void co_csdo_send_dn_ini_req(co_csdo_t *sdo)
Sends a Client-SDO 'download initiate' request.
static void co_csdo_init_seg_req(co_csdo_t *sdo, struct can_msg *msg, co_unsigned8_t cs)
Initializes a Client-SDO download/upload segment request CAN frame.
int co_csdo_up_req(co_csdo_t *sdo, co_unsigned16_t idx, co_unsigned8_t subidx, co_csdo_up_con_t *con, void *data)
Submits an upload request to a remote Server-SDO.
static void co_csdo_send_up_ini_req(co_csdo_t *sdo)
Sends a Client-SDO 'upload initiate' request.
int co_dev_up_req(const co_dev_t *dev, co_unsigned16_t idx, co_unsigned8_t subidx, co_csdo_up_con_t *con, void *data)
Submits an upload request to a local device.
void co_csdo_stop(co_csdo_t *sdo)
Stops a Client-SDO service.
static co_csdo_state_t * co_csdo_up_seg_on_recv(co_csdo_t *sdo, const struct can_msg *msg)
The 'CAN frame received' transition function of the 'upload segment' state.
static co_csdo_state_t * co_csdo_blk_up_end_on_recv(co_csdo_t *sdo, const struct can_msg *msg)
The 'CAN frame received' transition function of the 'block upload end' state.
static int co_csdo_timer(const struct timespec *tp, void *data)
The CAN timer callback function for a Client-SDO service.
static void co_csdo_dn_dcf_dn_con(co_csdo_t *sdo, co_unsigned16_t idx, co_unsigned8_t subidx, co_unsigned32_t ac, void *data)
The confirmation function of a single SDO download request during a concise DCF download.
static co_csdo_state_t * co_csdo_blk_up_ini_on_recv(co_csdo_t *sdo, const struct can_msg *msg)
The 'CAN frame received' transition function of the 'block upload initiate' state.
static co_csdo_state_t * co_csdo_dn_seg_on_recv(co_csdo_t *sdo, const struct can_msg *msg)
The 'CAN frame received' transition function of the 'download segment' state.
int co_csdo_is_idle(const co_csdo_t *sdo)
Returns 1 if the specified Client-SDO service is idle, and 0 if a transfer is ongoing.
static co_csdo_state_t *const co_csdo_blk_up_end_state
The 'block upload end' state.
static co_csdo_state_t * co_csdo_up_seg_on_abort(co_csdo_t *sdo, co_unsigned32_t ac)
The 'abort' transition function of the 'upload segment' state.
static co_csdo_state_t * co_csdo_blk_up_end_on_time(co_csdo_t *sdo, const struct timespec *tp)
The 'timeout' transition function of the 'block upload end' state.
static co_csdo_state_t * co_csdo_up_seg_on_time(co_csdo_t *sdo, const struct timespec *tp)
The 'timeout' transition function of the 'upload segment' state.
static co_csdo_state_t *const co_csdo_blk_dn_end_state
The 'block download end' state.
static co_csdo_state_t * co_csdo_blk_dn_end_on_time(co_csdo_t *sdo, const struct timespec *tp)
The 'timeout' transition function of the 'block download end' state.
static void co_csdo_send_up_seg_req(co_csdo_t *sdo)
Sends a Client-SDO 'upload segment' request.
int co_csdo_is_stopped(const co_csdo_t *sdo)
Retuns 1 if the specified Client-SDO service is stopped, and 0 if not.
int co_csdo_dn_req(co_csdo_t *sdo, co_unsigned16_t idx, co_unsigned8_t subidx, const void *ptr, size_t n, co_csdo_dn_con_t *con, void *data)
Submits a download request to a remote Server-SDO.
int co_dev_dn_val_req(co_dev_t *dev, co_unsigned16_t idx, co_unsigned8_t subidx, co_unsigned16_t type, const void *val, co_csdo_dn_con_t *con, void *data)
Submits a download request to a local device.
static co_csdo_state_t * co_csdo_abort_ind(co_csdo_t *sdo, co_unsigned32_t ac)
Processes an abort transfer indication by aborting any ongoing transfer of a Client-SDO and returning...
static co_csdo_state_t *const co_csdo_blk_up_ini_state
The 'block upload initiate' state.
static int co_csdo_update(co_csdo_t *sdo)
Updates and (de)activates a Client-SDO service.
int co_dev_dn_req(co_dev_t *dev, co_unsigned16_t idx, co_unsigned8_t subidx, const void *ptr, size_t n, co_csdo_dn_con_t *con, void *data)
Submits a download request to a local device.
static co_csdo_state_t * co_csdo_wait_on_recv(co_csdo_t *sdo, const struct can_msg *msg)
The 'CAN frame received' transition function of the 'waiting' state.
static co_csdo_state_t * co_csdo_dn_ini_on_time(co_csdo_t *sdo, const struct timespec *tp)
The 'timeout' transition function of the 'download initiate' state.
static co_csdo_state_t * co_csdo_blk_dn_ini_on_abort(co_csdo_t *sdo, co_unsigned32_t ac)
The 'abort' transition function of the 'block download initiate' state.
int co_dev_dn_dcf_req(co_dev_t *dev, const uint_least8_t *begin, const uint_least8_t *end, co_csdo_dn_con_t *con, void *data)
Submits a series of download requests to a local device.
static co_csdo_state_t * co_csdo_blk_up_sub_on_recv(co_csdo_t *sdo, const struct can_msg *msg)
The 'CAN frame received' transition function of the 'block upload sub-block' state.
static co_csdo_state_t * co_csdo_blk_up_sub_on_time(co_csdo_t *sdo, const struct timespec *tp)
The 'timeout' transition function of the 'block upload sub-block' state.
can_net_t * co_csdo_get_net(const co_csdo_t *sdo)
Returns a pointer to the CAN network of a Client-SDO.
static void co_csdo_enter(co_csdo_t *sdo, co_csdo_state_t *next)
Enters the specified state of a Client-SDO service and invokes the exit and entry functions.
co_dev_t * co_csdo_get_dev(const co_csdo_t *sdo)
Returns a pointer to the CANopen device of a Client-SDO.
static co_csdo_state_t *const co_csdo_stopped_state
The 'stopped' state.
static co_csdo_state_t * co_csdo_stopped_on_abort(co_csdo_t *sdo, co_unsigned32_t ac)
The 'abort' transition function of the 'stopped' state.
static void co_csdo_send_blk_up_sub_res(co_csdo_t *sdo)
Sends a Client-SDO 'block upload sub-block' response.
void co_csdo_set_timeout(co_csdo_t *sdo, int timeout)
Sets the timeout of a Client-SDO.
static void co_csdo_send_blk_up_ini_req(co_csdo_t *sdo, co_unsigned8_t pst)
Sends a Client-SDO 'block upload initiate' request.
static co_csdo_state_t * co_csdo_abort_res(co_csdo_t *sdo, co_unsigned32_t ac)
Sends an abort transfer request and aborts any ongoing transfer by invoking co_csdo_abort_ind().
int co_csdo_get_timeout(const co_csdo_t *sdo)
Returns the timeout (in milliseconds) of a Client-SDO.
void co_csdo_destroy(co_csdo_t *csdo)
Destroys a CANopen Client-SDO service.
static void co_csdo_send_blk_up_end_res(co_csdo_t *sdo)
Sends a Client-SDO 'block upload end' response.
int co_csdo_start(co_csdo_t *sdo)
Starts a Client-SDO service.
static co_csdo_state_t *const co_csdo_dn_seg_state
The 'download segment' state.
int co_csdo_blk_up_req(co_csdo_t *sdo, co_unsigned16_t idx, co_unsigned8_t subidx, co_unsigned8_t pst, co_csdo_up_con_t *con, void *data)
Submits a block upload request to a remote Server-SDO.
static co_csdo_state_t *const co_csdo_abort_state
The 'abort transfer' state.
int co_csdo_blk_dn_req(co_csdo_t *sdo, co_unsigned16_t idx, co_unsigned8_t subidx, const void *ptr, size_t n, co_csdo_dn_con_t *con, void *data)
Submits a block download request to a remote Server-SDO.
int co_csdo_blk_dn_val_req(co_csdo_t *sdo, co_unsigned16_t idx, co_unsigned8_t subidx, co_unsigned16_t type, const void *val, co_csdo_dn_con_t *con, void *data)
Submits a block download request to a remote Server-SDO.
void co_csdo_set_up_ind(co_csdo_t *sdo, co_csdo_ind_t *ind, void *data)
Sets the indication function used to notify the user of the progress of the current SDO upload reques...
static co_csdo_state_t * co_csdo_blk_up_sub_on_abort(co_csdo_t *sdo, co_unsigned32_t ac)
The 'abort' transition function of the 'block upload sub-block' state.
static void co_csdo_emit_time(co_csdo_t *sdo, const struct timespec *tp)
Invokes the 'timeout' transition function of the current state of a Client-SDO service.
static co_csdo_state_t *const co_csdo_up_ini_state
The 'upload initiate' state.
static co_csdo_state_t * co_csdo_abort_on_enter(co_csdo_t *sdo)
The entry function of the 'abort transfer' state.
static void co_csdo_init_ini_req(co_csdo_t *sdo, struct can_msg *msg, co_unsigned8_t cs)
Initializes a Client-SDO download/upload initiate request CAN frame.
static co_csdo_state_t * co_csdo_dn_ini_on_recv(co_csdo_t *sdo, const struct can_msg *msg)
The 'CAN frame received' transition function of the 'download initiate' state.
void co_csdo_abort_req(co_csdo_t *sdo, co_unsigned32_t ac)
Submits an abort transfer request to a remote Server-SDO.
static co_csdo_state_t * co_csdo_dn_ini_on_abort(co_csdo_t *sdo, co_unsigned32_t ac)
The 'abort' transition function of the 'download initiate' state.
static co_csdo_state_t * co_csdo_dn_seg_on_abort(co_csdo_t *sdo, co_unsigned32_t ac)
The 'abort' transition function of the 'download segment' state.
int co_csdo_dn_dcf_req(co_csdo_t *sdo, const uint_least8_t *begin, const uint_least8_t *end, co_csdo_dn_con_t *con, void *data)
Submits a series of download requests to a remote Server-SDO.
static co_csdo_state_t * co_csdo_blk_dn_end_on_recv(co_csdo_t *sdo, const struct can_msg *msg)
The 'CAN frame received' transition function of the 'block download end' state.
static co_csdo_state_t *const co_csdo_wait_state
The 'waiting' state.
void co_csdo_get_up_ind(const co_csdo_t *sdo, co_csdo_ind_t **pind, void **pdata)
Retrieves the indication function used to notify the user of the progress of the current SDO upload r...
static void co_csdo_send_blk_dn_end_req(co_csdo_t *sdo)
Sends a Client-SDO 'block download end' request.
static co_csdo_state_t * co_csdo_dn_seg_on_enter(co_csdo_t *sdo)
The entry function of the 'download segment' state.
const struct co_sdo_par * co_csdo_get_par(const co_csdo_t *sdo)
Returns a pointer to the SDO parameter record of a Client-SDO.
static co_csdo_state_t *const co_csdo_blk_dn_ini_state
The 'block download initiate' state.
static int co_csdo_up_ind(co_csdo_t *sdo, co_unsigned16_t idx, co_unsigned8_t subidx, struct membuf *buf, co_csdo_up_con_t *con, void *data)
Processes an upload request from a Client-SDO by checking and updating the state.
static co_csdo_state_t * co_csdo_blk_dn_ini_on_time(co_csdo_t *sdo, const struct timespec *tp)
The 'timeout' transition function of the 'block download initiate' state.
static void co_csdo_emit_abort(co_csdo_t *sdo, co_unsigned32_t ac)
Invokes the 'abort' transition function of the current state of a Client-SDO service.
static co_csdo_state_t *const co_csdo_blk_up_sub_state
The 'block upload sub-block' state.
static co_csdo_state_t * co_csdo_blk_up_ini_on_time(co_csdo_t *sdo, const struct timespec *tp)
The 'timeout' transition function of the 'block upload initiate' state.
static co_csdo_state_t * co_csdo_blk_up_end_on_abort(co_csdo_t *sdo, co_unsigned32_t ac)
The 'abort' transition function of the 'block upload end' state.
static void co_csdo_send_start_up_req(co_csdo_t *sdo)
Sends a Client-SDO 'start upload' request.
static void co_csdo_send_dn_seg_req(co_csdo_t *sdo, co_unsigned32_t n, int last)
Sends a Client-SDO 'download segment' request.
static co_csdo_state_t * co_csdo_wait_on_abort(co_csdo_t *sdo, co_unsigned32_t ac)
The 'abort' transition function of the 'waiting' state.
static co_csdo_state_t * co_csdo_blk_dn_sub_on_time(co_csdo_t *sdo, const struct timespec *tp)
The 'timeout' transition function of the 'block download sub-block' state.
static co_csdo_state_t * co_csdo_up_ini_on_recv(co_csdo_t *sdo, const struct can_msg *msg)
The 'CAN frame received' transition function of the 'upload initiate' state.
void co_csdo_set_dn_ind(co_csdo_t *sdo, co_csdo_ind_t *ind, void *data)
Sets the indication function used to notify the user of the progress of the current SDO download requ...
static int co_csdo_dn_ind(co_csdo_t *sdo, co_unsigned16_t idx, co_unsigned8_t subidx, const void *ptr, size_t n, co_csdo_dn_con_t *con, void *data)
Processes a download request from a Client-SDO by checking and updating the state and copying the val...
static void co_csdo_send_blk_dn_ini_req(co_csdo_t *sdo)
Sends a Client-SDO 'block download initiate' request.
co_csdo_t * co_csdo_create(can_net_t *net, co_dev_t *dev, co_unsigned8_t num)
Creates a new CANopen Client-SDO service.
static co_csdo_state_t * co_csdo_up_ini_on_time(co_csdo_t *sdo, const struct timespec *tp)
The 'timeout' transition function of the 'upload initiate' state.
static co_csdo_state_t *const co_csdo_blk_dn_sub_state
The 'block download sub-block' state.
co_unsigned8_t co_csdo_get_num(const co_csdo_t *sdo)
Returns the SDO number of a Client-SDO.
static co_csdo_state_t * co_csdo_blk_dn_sub_on_abort(co_csdo_t *sdo, co_unsigned32_t ac)
The 'abort' transition function of the 'block download sub-block' state.
static co_csdo_state_t *const co_csdo_dn_ini_state
The 'download initiate' state.
int co_csdo_is_valid(const co_csdo_t *sdo)
Returns 1 of the COB-IDs of the specified Client-SDO service are valid, and 0 if not.
void co_csdo_get_dn_ind(const co_csdo_t *sdo, co_csdo_ind_t **pind, void **pdata)
Retrieves the indication function used to notify the user of the progress of the current SDO download...
static void co_csdo_send_dn_exp_req(co_csdo_t *sdo)
Sends a Client-SDO 'download initiate' (expedited) request.
int co_csdo_dn_val_req(co_csdo_t *sdo, co_unsigned16_t idx, co_unsigned8_t subidx, co_unsigned16_t type, const void *val, co_csdo_dn_con_t *con, void *data)
Submits a download request to a remote Server-SDO.
static void co_csdo_abort_on_leave(co_csdo_t *sdo)
The exit function of the 'abort transfer' state.
static void co_csdo_send_abort(co_csdo_t *sdo, co_unsigned32_t ac)
Sends an abort transfer request.
static co_csdo_state_t * co_csdo_blk_up_ini_on_abort(co_csdo_t *sdo, co_unsigned32_t ac)
The 'abort' transition function of the 'block upload initiate' state.
static void co_csdo_send_blk_dn_sub_req(co_csdo_t *sdo, co_unsigned8_t seqno)
Sends a Client-SDO 'block download sub-block' request.
static co_csdo_state_t * co_csdo_blk_dn_sub_on_recv(co_csdo_t *sdo, const struct can_msg *msg)
The 'CAN frame received' transition function of the 'block download sub-block' state.
static co_csdo_state_t *const co_csdo_up_seg_state
The 'upload segment' state.
static co_csdo_state_t * co_csdo_up_ini_on_abort(co_csdo_t *sdo, co_unsigned32_t ac)
The 'abort' transition function of the 'upload initiate' state.
static co_csdo_state_t * co_csdo_dn_seg_on_time(co_csdo_t *sdo, const struct timespec *tp)
The 'timeout' transition function of the 'download segment' state.
static co_csdo_state_t * co_csdo_blk_dn_sub_on_enter(co_csdo_t *sdo)
The entry function of the 'block download sub-block' state.
static co_csdo_state_t * co_csdo_blk_dn_ini_on_recv(co_csdo_t *sdo, const struct can_msg *msg)
The 'CAN frame received' transition function of the 'block download initiate' state.
static co_csdo_state_t * co_csdo_blk_dn_end_on_abort(co_csdo_t *sdo, co_unsigned32_t ac)
The 'abort' transition function of the 'block download end' state.
This header file is part of the CANopen library; it contains the Client-SDO declarations.
void co_csdo_up_con_t(co_csdo_t *sdo, co_unsigned16_t idx, co_unsigned8_t subidx, co_unsigned32_t ac, const void *ptr, size_t n, void *data)
The type of a CANopen Client-SDO upload confirmation callback function, invoked when an upload reques...
void co_csdo_dn_con_t(co_csdo_t *sdo, co_unsigned16_t idx, co_unsigned8_t subidx, co_unsigned32_t ac, void *data)
The type of a CANopen Client-SDO download confirmation callback function, invoked when a download req...
void co_csdo_ind_t(const co_csdo_t *sdo, co_unsigned16_t idx, co_unsigned8_t subidx, size_t size, size_t nbyte, void *data)
The type of a CANopen Client-SDO request progress indication function, used to notify the user of the...
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_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.
#define CO_SDO_AC_TYPE_LEN_LO
SDO abort code: Data type does not match, length of service parameter too low.
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_TOGGLE
SDO abort code: Toggle bit not altered.
#define CO_SDO_REQ_INIT
The static initializer for struct co_sdo_req.
#define CO_SDO_AC_TYPE_LEN_HI
SDO abort code: Data type does not match, length of service parameter too high.
int co_sdo_req_up_val(struct co_sdo_req *req, co_unsigned16_t type, const void *val, co_unsigned32_t *pac)
Writes the specified value to a buffer and constructs a CANopen SDO upload request.
int co_sdo_req_up(struct co_sdo_req *req, const void *ptr, size_t n, co_unsigned32_t *pac)
Writes the specified bytes to a buffer and constructs a CANopen SDO upload request.
#define CO_SDO_AC_NO_CS
SDO abort code: Client/server command specifier not valid or unknown.
void co_sdo_req_fini(struct co_sdo_req *req)
Finalizes a CANopen SDO upload/download request.
#define CO_SDO_AC_BLK_SEQ
SDO abort code: Invalid sequence number (block mode only).
#define CO_SDO_AC_ERROR
SDO abort code: General error.
#define CO_SDO_AC_NO_SDO
SDO abort code: Resource not available: SDO connection.
#define CO_SDO_AC_NO_OBJ
SDO abort code: Object does not exist in the object dictionary.
#define CO_SDO_COBID_FRAME
The bit in the SDO COB-ID specifying whether to use an 11-bit (0) or 29-bit (1) CAN-ID.
void co_sdo_req_clear(struct co_sdo_req *req)
Clears a CANopen SDO upload/download request, including its buffer.
#define CO_SDO_AC_NO_DATA
SDO abort code: No data available.
#define CO_SDO_AC_NO_SUB
SDO abort code: Sub-index does not exist.
#define CO_SDO_AC_BLK_SIZE
SDO abort code: Invalid block size (block mode only).
#define CO_SDO_COBID_VALID
The bit in the SDO COB-ID specifying whether the SDO exists and is valid.
int co_sdo_req_last(const struct co_sdo_req *req)
Returns 1 if the specified request includes the last segment, and 0 otherwise.
#define CO_SDO_AC_PARAM_VAL
SDO abort code: Invalid value for parameter (download only).
#define CO_SDO_AC_TIMEOUT
SDO abort code: SDO protocol timed out.
#define CO_SDO_AC_BLK_CRC
SDO abort code: CRC error (block mode only).
#define CO_NUM_SDOS
The maximum number of Client/Server-SDOs.
#define CO_SDO_AC_NO_MEM
SDO abort code: Out of memory.
#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.
#define MAX(a, b)
Returns the maximum of a and b.
size_t membuf_reserve(struct membuf *buf, size_t size)
Resizes a memory buffer, if necessary, to make room for at least an additional size bytes.
void membuf_fini(struct membuf *buf)
Finalizes a memory buffer.
size_t membuf_capacity(const struct membuf *buf)
Returns the number of unused bytes remaining in a memory buffer.
void membuf_init(struct membuf *buf, void *ptr, size_t size)
Initializes a memory buffer.
size_t membuf_write(struct membuf *buf, const void *ptr, size_t size)
Writes data to a memory buffer.
void * membuf_alloc(struct membuf *buf, size_t *size)
Creates region of *size bytes in a memory buffer, starting at the current position indicator given by...
void membuf_clear(struct membuf *buf)
Clears a memory buffer.
#define MEMBUF_INIT
The static initializer for struct membuf.
size_t membuf_size(const struct membuf *buf)
Returns the total number of bytes written to a memory buffer.
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.
can_timer_t * can_timer_create(void)
Creates a new CAN timer.
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_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.
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_unsigned32_t co_sub_dn_ind(co_sub_t *sub, struct co_sdo_req *req)
Invokes the download indication function of a CANopen sub-object, registered with co_sub_set_dn_ind()...
co_unsigned16_t co_obj_get_idx(const co_obj_t *obj)
Returns the index of a CANopen object.
co_unsigned32_t co_sub_up_ind(const co_sub_t *sub, struct co_sdo_req *req)
Invokes the upload indication function of a CANopen sub-object, registered with co_sub_set_up_ind().
co_sub_t * co_obj_find_sub(const co_obj_t *obj, co_unsigned8_t subidx)
Finds a sub-object in 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...
co_unsigned8_t co_obj_get_code(const co_obj_t *obj)
Returns the object code of a CANopen object.
#define CO_OBJECT_ARRAY
A multiple data field object where each data field is a simple variable of the same basic data type.
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 is the internal header file of the Service Data Object (SDO) declarations.
#define CO_SDO_SEQ_LAST
The mask to get/set the last segment bit from an SDO command byte.
#define CO_SDO_SEG_TOGGLE
The mask to get/set the toggle bit from an SDO command byte.
#define CO_SDO_CCS_DN_INI_REQ
The SDO client command specifier 'download initiate' request.
#define CO_SDO_BLK_SIZE_IND
The SDO size indicator flag indicating that the data set size is indicated.
#define CO_SDO_CS_MASK
The mask to extract the command specifier (CS) from an SDO command byte.
#define CO_SDO_BLK_SIZE_SET(n)
Sets the SDO size indicator, indicating n bytes contain segment data (in the range [0....
#define CO_SDO_INI_SIZE_EXP_GET(cs)
Retrieves the number of bytes containing expedited data from the SDO size indicator.
#define CO_SDO_SCS_UP_SEG_RES
The SDO server command specifier 'upload segment' response.
#define CO_SDO_SEG_SIZE_SET(n)
Sets the SDO size indicator, indicating n bytes contain segment data (in the range [0....
#define CO_SDO_SC_END_BLK
The SDO server/client subcommand 'end block download/upload'.
#define CO_SDO_SCS_UP_INI_RES
The SDO server command specifier 'upload initiate' response.
#define CO_SDO_SCS_DN_SEG_RES
The SDO server command specifier 'download segment' response.
#define CO_SDO_CS_ABORT
The SDO client/server command specifier 'abort transfer' request.
#define CO_SDO_CCS_BLK_DN_REQ
The SDO client command specifier 'block download' request.
#define CO_SDO_CCS_UP_INI_REQ
The SDO client command specifier 'upload initiate' request.
#define CO_SDO_SC_MASK
The mask to extract the subcommand (SC) from an SDO command byte.
#define CO_SDO_BLK_CRC
The SDO CRC support flag.
#define CO_SDO_CCS_DN_SEG_REQ
The SDO client command specifier 'download segment' request.
#define CO_SDO_INI_SIZE_IND
The SDO size indicator flag indicating that the data set size is indicated.
#define CO_SDO_SCS_BLK_DN_RES
The SDO server command specifier 'block download' response.
#define CO_SDO_INI_SIZE_EXP_SET(n)
Sets the SDO size indicator, indicating the expedited transfer of n bytes (in the range [1....
#define CO_SDO_SCS_BLK_UP_RES
The SDO server command specifier 'block upload' response.
#define CO_SDO_MAX_SEQNO
The maximum sequence number (or segments per block).
#define CO_SDO_SEG_SIZE_GET(cs)
Retrieves the number of bytes containing segment data from the SDO size indicator.
#define CO_SDO_SEG_LAST
The mask to get/set the last segment bit from an SDO command byte.
#define CO_SDO_BLK_SIZE_GET(cs)
Retrieves the number of bytes containing segment data from the SDO size indicator.
#define CO_SDO_SC_START_UP
The SDO client subcommand 'start upload'.
#define CO_SDO_SC_BLK_RES
The SDO client/client subcommand 'block download/upload' response.
#define CO_SDO_CCS_BLK_UP_REQ
The SDO client command specifier 'block upload' request.
#define CO_SDO_INI_SIZE_EXP
The SDO size indicator flag indicating expedited transfer.
#define CO_SDO_SCS_DN_INI_RES
The SDO server command specifier 'download initiate' response.
#define CO_SDO_CCS_UP_SEG_REQ
The SDO client command specifier 'upload segment' request.
#define CO_SDO_SC_INI_BLK
The SDO server/client subcommand 'initiate download/upload'.
This header file is part of the C11 and POSIX compatibility library; it includes <stdlib....
This header file is part of the C11 and POSIX compatibility library; it includes <string....
A CANopen Client-SDO state.
co_csdo_state_t *(* on_enter)(co_csdo_t *sdo)
A pointer to the function invoked when a new state is entered.
co_csdo_state_t *(* on_recv)(co_csdo_t *sdo, const struct can_msg *msg)
A pointer to the transition function invoked when a CAN frame has been received.
void(* on_leave)(co_csdo_t *sdo)
A pointer to the function invoked when the current state is left.
co_csdo_state_t *(* on_time)(co_csdo_t *sdo, const struct timespec *tp)
A pointer to the transition function invoked when a timeout occurs.
co_csdo_state_t *(* on_abort)(co_csdo_t *sdo, co_unsigned32_t ac)
A pointer to the transition function invoked when an abort code has been received.
co_unsigned8_t ackseq
The sequence number of the last successfully received segment.
void * up_ind_data
A pointer to user-specified data for up_ind.
void * dn_con_data
A pointer to user-specified data for dn_con.
can_timer_t * timer
A pointer to the CAN timer.
co_csdo_ind_t * up_ind
A pointer to the upload progress indication function.
void * up_con_data
A pointer to user-specified data for up_con.
co_unsigned8_t subidx
The current object sub-index.
int timeout
The SDO timeout (in milliseconds).
co_unsigned16_t idx
The current object index.
co_unsigned8_t num
The SDO number.
co_csdo_up_con_t * up_con
A pointer to the upload confirmation function.
co_unsigned8_t blksize
The number of segments per block.
void * dn_ind_data
A pointer to user-specified data for dn_ind.
struct membuf * up_buf
A pointer to the memory buffer used for upload requests.
co_csdo_ind_t * dn_ind
A pointer to the download progress indication function.
co_unsigned8_t toggle
The current value of the toggle bit.
struct co_csdo_dn_dcf dn_dcf
The state of the concise DCF download request.
co_csdo_dn_con_t * dn_con
A pointer to the download confirmation function.
co_unsigned32_t size
The data set size (in bytes).
co_unsigned32_t ac
The current abort code.
struct membuf buf
The memory buffer used for storing serialized values in the absence of a user-specified buffer.
struct membuf dn_buf
The memory buffer used for download requests.
can_recv_t * recv
A pointer to the CAN frame receiver.
co_csdo_state_t * state
A pointer to the current state.
struct co_sdo_par par
The SDO parameter record.
can_net_t * net
A pointer to a CAN network interface.
co_dev_t * dev
A pointer to a CANopen device.
unsigned crc
A flag indicating whether a CRC should be generated.
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).
The state of a concise DCF download request.
const uint_least8_t * end
A pointer to one past the last byte in the concise DCF.
void * data
A pointer to user-specified data for con.
co_unsigned32_t n
The number of remaining entries in the concise DCF.
co_csdo_dn_con_t * con
A pointer to the download confirmation function.
const uint_least8_t * begin
A pointer to the next byte in the concise DCF.
co_unsigned32_t cobid_res
COB-ID server -> client.
co_unsigned8_t n
Highest sub-index supported.
co_unsigned32_t cobid_req
COB-ID client -> server.
co_unsigned8_t id
Node-ID of SDO's client resp. server.
A CANopen SDO upload/download request.
size_t size
The total size (in bytes) of the value to be uploaded/downloaded.
const void * buf
A pointer to the next bytes to be uploaded/downloaded.
size_t nbyte
The number of bytes available at buf.
char * end
A pointer to one past the last byte in the buffer.
char * begin
A pointer to the first byte in the buffer.
char * cur
A pointer to one past the last byte written to the buffer.
#define CO_DEFTYPE_UNSIGNED16
The data type (and object index) of a 16-bit unsigned integer.
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_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 CANopen library; it contains the CANopen value declarations.
size_t co_val_read(co_unsigned16_t type, void *val, const uint_least8_t *begin, const uint_least8_t *end)
Reads a value of the specified data type from a memory buffer.
size_t co_val_write(co_unsigned16_t type, const void *val, uint_least8_t *begin, uint_least8_t *end)
Writes a value of the specified data type to a memory buffer.
size_t co_val_sizeof(co_unsigned16_t type, const void *val)
Returns the size (in bytes) of a value of the specified data type.