26 #ifndef LELY_NO_CO_CSDO 127 static int co_csdo_timer(
const struct timespec *tp,
void *data);
199 #define LELY_CO_DEFINE_STATE(name, ...) \ 200 static co_csdo_state_t *const name = &(co_csdo_state_t){ __VA_ARGS__ }; 238 co_csdo_t *sdo, const struct timespec *tp);
265 co_csdo_t *sdo, const struct timespec *tp);
289 co_csdo_t *sdo, const struct timespec *tp);
310 co_csdo_t *sdo, const struct timespec *tp);
331 co_csdo_t *sdo, const struct timespec *tp);
358 co_csdo_t *sdo, const struct timespec *tp);
383 co_csdo_t *sdo, const struct timespec *tp);
407 co_csdo_t *sdo, const struct timespec *tp);
431 co_csdo_t *sdo, const struct timespec *tp);
455 co_csdo_t *sdo, const struct timespec *tp);
472 #undef LELY_CO_DEFINE_STATE 504 co_unsigned8_t subidx,
const void *ptr,
size_t n,
608 co_unsigned32_t ac = 0;
629 con(NULL, idx, subidx, ac, data);
646 co_unsigned32_t ac = 0;
667 con(NULL, idx, subidx, ac, data);
682 co_unsigned32_t ac = 0;
698 &&
__unlikely(subidx > co_obj_get_val_u8(obj, 0))) {
719 con(NULL, idx, subidx, ac, ac ? NULL :
buf.begin,
728 __co_csdo_alloc(
void)
730 void *ptr = malloc(
sizeof(
struct __co_csdo));
737 __co_csdo_free(
void *ptr)
784 goto error_create_recv;
793 goto error_create_timer;
850 assert(sdo->
num >= 1 && sdo->
num <= 128);
869 trace(
"creating Client-SDO %d",
num);
876 goto error_alloc_sdo;
897 trace(
"destroying Client-SDO %d", csdo->
num);
898 __co_csdo_fini(csdo);
899 __co_csdo_free(csdo);
948 if (sdo->
timeout && timeout <= 0)
1022 trace(
"CSDO: %04X:%02X: initiate download", idx, subidx);
1051 uint8_t *buf =
n ? malloc(
n) : NULL;
1054 goto error_malloc_buf;
1059 goto error_write_val;
1088 trace(
"CSDO: %04X:%02X: initiate upload", idx, subidx);
1110 trace(
"CSDO: %04X:%02X: initiate block download", idx, subidx);
1129 trace(
"CSDO: %04X:%02X: initiate block upload", idx, subidx);
1152 if (valid_req && valid_res) {
1169 static co_unsigned32_t
1178 co_unsigned32_t ac = 0;
1189 co_unsigned32_t cobid = val.u32;
1190 co_unsigned32_t cobid_old = co_sub_get_val_u32(sub);
1191 if (cobid == cobid_old)
1200 if (
__unlikely(valid && valid_old && canid != canid_old)) {
1219 co_unsigned32_t cobid = val.u32;
1220 co_unsigned32_t cobid_old = co_sub_get_val_u32(sub);
1221 if (cobid == cobid_old)
1230 if (
__unlikely(valid && valid_old && canid != canid_old)) {
1249 co_unsigned8_t
id = val.u8;
1250 co_unsigned8_t id_old = co_sub_get_val_u8(sub);
1282 #ifndef LELY_NO_CANFD 1369 uint8_t cs = msg->
data[0];
1376 default:
return NULL;
1406 dn_con(sdo, sdo->
idx, sdo->
subidx, sdo->
ac, dn_con_data);
1407 }
else if (up_con) {
1437 uint8_t cs = msg->
data[0];
1453 co_unsigned8_t subidx = msg->
data[3];
1501 uint8_t cs = msg->
data[0];
1542 uint8_t cs = msg->
data[0];
1558 co_unsigned8_t subidx = msg->
data[3];
1619 uint8_t cs = msg->
data[0];
1690 uint8_t cs = msg->
data[0];
1713 co_unsigned8_t subidx = msg->
data[3];
1742 for (uint8_t seqno = 1; seqno <= sdo->
blksize; seqno++)
1773 uint8_t cs = msg->
data[0];
1791 uint8_t ackseq = msg->
data[1];
1792 if (ackseq < sdo->blksize) {
1834 uint8_t cs = msg->
data[0];
1875 uint8_t cs = msg->
data[0];
1902 co_unsigned8_t subidx = msg->
data[3];
1948 uint8_t cs = msg->
data[0];
1960 if (seqno == sdo->
ackseq + 1) {
1973 if (seqno == sdo->
blksize || last) {
2005 uint8_t cs = msg->
data[0];
2078 sdo->
size = ptr ? n : 0;
2159 assert(sdo->
size && sdo->
size <= 4);
2174 assert(!sdo->
size || sdo->
size > 4);
2278 uint8_t n = sdo->
size ? (sdo->
size - 1) % 7 + 1 : 0;
2389 #endif // !LELY_NO_CO_CSDO A CANopen SDO upload/download request.
#define CO_SDO_SCS_UP_INI_RES
The SDO server command specifier 'upload initiate' response.
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_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.
A CAN or CAN FD format frame.
void stle_u32(void *ptr, uint_least32_t x)
Stores a 32-bit unsigned integer in little-endian byte order.
size_t membuf_write(struct membuf *buf, const void *ptr, size_t size)
Writes data to a memory buffer.
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 int co_csdo_recv(const struct can_msg *msg, void *data)
The CAN receive callback function for a Client-SDO service.
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.
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.
static void co_csdo_send_blk_up_sub_res(co_csdo_t *sdo)
Sends a Client-SDO 'block upload sub-block' response.
#define CO_SDO_AC_BLK_SIZE
SDO abort code: Invalid block size (block mode only).
uint_least32_t id
The identifier (11 or 29 bits, depending on the CAN_FLAG_IDE flag).
can_net_t * net
A pointer to a CAN network interface.
size_t co_obj_sizeof_val(const co_obj_t *obj)
Returns size (in bytes) of the value of a CANopen object.
co_unsigned8_t n
Highest sub-index supported.
co_unsigned32_t cobid_res
COB-ID server -> client.
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.
co_unsigned8_t num
The SDO number.
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_sub_state
The 'block download sub-block' state.
#define CO_SDO_SEG_SIZE_SET(n)
Sets the SDO size indicator, indicating n bytes contain segment data (in the range [0...
#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)...
void co_csdo_set_timeout(co_csdo_t *sdo, int timeout)
Sets the timeout of a Client-SDO.
co_csdo_up_con_t * up_con
A pointer to the upload confirmation function.
size_t size
The total size (in bytes) of the value to be uploaded/downloaded.
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.
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.
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.
#define CO_SDO_AC_NO_DATA
SDO abort code: No data available.
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.
int errnum2c(errnum_t errnum)
Transforms a platform-independent error number to a native error code.
static co_csdo_state_t *const co_csdo_up_ini_state
The 'upload initiate' state.
static void co_csdo_send_up_ini_req(co_csdo_t *sdo)
Sends a Client-SDO 'upload initiate' 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_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...
#define CAN_MSG_INIT
The static initializer for can_msg.
void * up_con_data
A pointer to user-specified data for up_con.
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.
uint32_t size
The data set size (in bytes).
void set_errnum(errnum_t errnum)
Sets the current (thread-specific) platform-independent error number to errnum.
#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_DN_INI_RES
The SDO server command specifier 'download initiate' response.
void membuf_clear(struct membuf *buf)
Clears a memory buffer.
#define MEMBUF_INIT
The static initializer for struct membuf.
#define CO_SDO_BLK_CRC
The SDO CRC support flag.
void membuf_init(struct membuf *buf)
Initializes a memory buffer.
#define CO_SDO_AC_PARAM_VAL
SDO abort code: Invalid value for parameter (download only).
#define CO_SDO_COBID_VALID
The bit in the SDO COB-ID specifying whether the SDO exists and is valid.
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...
A union of the CANopen static data types.
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.
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.
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.
#define CO_SDO_SCS_UP_SEG_RES
The SDO server command specifier 'upload segment' response.
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.
uint_least16_t ldle_u16(const void *ptr)
Loads a 16-bit unsigned integer in little-endian byte order.
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.
#define CO_SDO_AC_ERROR
SDO abort code: General error.
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.
#define CO_SDO_CS_ABORT
The SDO client/server command specifier 'abort transfer' request.
#define MIN(a, b)
Returns the minimum of a and b.
#define CO_SDO_BLK_SIZE_IND
The SDO size indicator flag indicating that the data set size is indicated.
#define CAN_MASK_BID
The mask used to extract the 11-bit Base Identifier from a CAN frame.
int co_type_is_array(co_unsigned16_t type)
Returns 1 if the specified (static) data type is an array, and 0 if not.
co_unsigned32_t cobid_req
COB-ID client -> server.
#define CO_SDO_INI_SIZE_EXP_GET(cs)
Retrieves the number of bytes containing expedited data from the SDO size indicator.
co_unsigned8_t co_obj_get_code(const co_obj_t *obj)
Returns the object code of a CANopen object.
This header file is part of the CANopen library; it contains the Cyclic Redundancy Check (CRC) declar...
static int co_csdo_up_ind(co_csdo_t *sdo, co_unsigned16_t idx, co_unsigned8_t subidx, co_csdo_up_con_t *con, void *data)
Processes an upload request from a Client-SDO by checking and updating the state. ...
co_csdo_ind_t * up_ind
A pointer to the upload progress indication function.
This header file is part of the CANopen library; it contains the Client-SDO declarations.
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_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...
#define CO_SDO_AC_BLK_CRC
SDO abort code: CRC error (block mode only).
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.
#define CO_SDO_AC_NO_SDO
SDO abort code: Resource not available: SDO connection.
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...
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.
#define CO_SDO_CCS_DN_INI_REQ
The SDO client command specifier 'download initiate' request.
#define CO_SDO_CCS_BLK_UP_REQ
The SDO client command specifier 'block upload' request.
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.
A CANopen Client-SDO state.
co_unsigned8_t subidx
The current object sub-index.
void co_csdo_destroy(co_csdo_t *csdo)
Destroys a CANopen Client-SDO service.
static void co_csdo_send_blk_dn_sub_req(co_csdo_t *sdo, uint8_t seqno)
Sends a Client-SDO 'block download sub-block' request.
#define CO_SDO_INI_SIZE_EXP
The SDO size indicator flag indicating expedited transfer.
void * dn_con_data
A pointer to user-specified data for dn_con.
struct membuf buf
The buffer.
#define CO_SDO_SC_INI_BLK
The SDO server/client subcommand 'initiate download/upload'.
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 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.
#define CO_DEFTYPE_UNSIGNED32
The data type (and object index) of a 32-bit unsigned integer.
#define CO_SDO_AC_TOGGLE
SDO abort code: Toggle bit not altered.
static void co_csdo_send_blk_up_ini_req(co_csdo_t *sdo, uint8_t pst)
Sends a Client-SDO 'block upload initiate' request.
uint_least8_t data[CAN_MSG_MAX_LEN]
The frame payload (in case of a data frame).
int co_csdo_get_timeout(const co_csdo_t *sdo)
Returns the timeout (in milliseconds) of a Client-SDO.
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_send_blk_up_end_res(co_csdo_t *sdo)
Sends a Client-SDO 'block upload end' response.
This header file is part of the utilities library; it contains the native and platform-independent er...
char * begin
A pointer to the first byte in the buffer.
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...
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.
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...
static co_csdo_state_t *const co_csdo_abort_state
The 'abort transfer' state.
void can_timer_stop(can_timer_t *timer)
Stops a CAN timer and unregisters it with a network interface.
static co_csdo_state_t *const co_csdo_dn_ini_state
The 'download initiate' state.
#define CAN_FLAG_IDE
The Identifier Extension (IDE) flag.
static void co_csdo_send_start_up_req(co_csdo_t *sdo)
Sends a Client-SDO 'start upload' request.
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 void co_csdo_abort_on_leave(co_csdo_t *sdo)
The exit function of the 'abort transfer' state.
static co_csdo_state_t * co_csdo_dn_seg_on_enter(co_csdo_t *sdo)
The entry function of the 'download segment' state.
#define CAN_FLAG_EDL
The Extended Data Length (EDL) flag.
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.
void can_recv_destroy(can_recv_t *recv)
Destroys a CAN frame receiver.
This header file is part of the utilities library; it contains the byte order (endianness) function d...
#define CO_SDO_SCS_BLK_DN_RES
The SDO server command specifier 'block download' response.
#define CO_SDO_AC_TIMEOUT
SDO abort code: SDO protocol timed out.
static co_csdo_state_t *const co_csdo_blk_dn_end_state
The 'block download end' state.
#define CO_SDO_CCS_UP_INI_REQ
The SDO client command specifier 'upload initiate' request.
This is the internal header file of the CANopen library.
char * cur
A pointer to one past the last byte written to the buffer.
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.
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.
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_blk_dn_end_on_time(co_csdo_t *sdo, const struct timespec *tp)
The 'timeout' transition function of the 'block download end' state.
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().
#define CO_SDO_INI_SIZE_IND
The SDO size indicator flag indicating that the data set size is indicated.
can_timer_t * timer
A pointer to the CAN timer.
static co_csdo_state_t *const co_csdo_up_seg_state
The 'upload segment' state.
co_csdo_state_t * state
A pointer to the current state.
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.
int get_errc(void)
Returns the last (thread-specific) native error code set by a system call or library function...
#define CO_SDO_SC_END_BLK
The SDO server/client subcommand 'end block download/upload'.
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.
#define MAX(a, b)
Returns the maximum of a and b.
static co_csdo_state_t *const co_csdo_dn_seg_state
The 'download segment' state.
#define CO_SDO_CCS_DN_SEG_REQ
The SDO client command specifier 'download segment' request.
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...
#define CO_DEFTYPE_UNSIGNED8
The data type (and object index) of an 8-bit unsigned integer.
static void co_csdo_send_blk_dn_end_req(co_csdo_t *sdo)
Sends a Client-SDO 'block download end' request.
#define CO_NUM_NODES
The maximum number of nodes in a CANopen network.
static co_csdo_state_t *const co_csdo_blk_up_end_state
The 'block upload end' state.
void(* on_leave)(co_csdo_t *sdo)
A pointer to the function invoked when the current state is left.
co_dev_t * co_csdo_get_dev(const co_csdo_t *sdo)
Returns a pointer to the CANopen device of a Client-SDO.
int co_csdo_blk_up_req(co_csdo_t *sdo, co_unsigned16_t idx, co_unsigned8_t subidx, uint8_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 * 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_wait_state
The 'waiting' state.
static co_csdo_state_t * co_csdo_abort_on_enter(co_csdo_t *sdo)
The entry function of the 'abort transfer' state.
void stle_u16(void *ptr, uint_least16_t x)
Stores a 16-bit unsigned integer in little-endian byte order.
uint8_t toggle
The current value of the toggle bit.
co_unsigned16_t idx
The current object index.
#define CO_SDO_BLK_SIZE_GET(cs)
Retrieves the number of bytes containing segment data from the SDO size indicator.
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.
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_emit_abort(co_csdo_t *sdo, co_unsigned32_t ac)
Invokes the 'abort' transition function of the current state of a Client-SDO service.
uint16_t co_crc(uint16_t crc, const void *ptr, size_t n)
Computes a CRC-16 checksum.
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 * co_csdo_wait_on_recv(co_csdo_t *sdo, const struct can_msg *msg)
The 'CAN frame received' transition function of the 'waiting' state.
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.
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...
void * up_ind_data
A pointer to user-specified data for up_ind.
static co_csdo_state_t *const co_csdo_blk_up_ini_state
The 'block upload initiate' 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 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_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().
static void co_csdo_send_dn_ini_req(co_csdo_t *sdo)
Sends a Client-SDO 'download initiate' request.
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_blk_up_sub_state
The 'block upload sub-block' state.
#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_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...
#define CO_SDO_SCS_DN_SEG_RES
The SDO server command specifier 'download segment' response.
unsigned crc
A flag indicating whether a CRC should be generated.
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.
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...
#define CO_SDO_AC_NO_CS
SDO abort code: Client/server command specifier not valid or unknown.
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_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.
can_timer_t * can_timer_create(void)
Creates a new CAN timer.
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.
#define CO_SDO_SCS_BLK_UP_RES
The SDO server command specifier 'block upload' response.
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.
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.
int timeout
The SDO timeout (in milliseconds).
void membuf_fini(struct membuf *buf)
Finalizes a memory buffer.
void can_recv_stop(can_recv_t *recv)
Stops a CAN frame receiver from processing frames and unregisters it with the network interface...
This header file is part of the CANopen library; it contains the device description declarations...
#define CO_SDO_SC_START_UP
The SDO client subcommand 'start upload'.
co_csdo_ind_t * dn_ind
A pointer to the download progress indication function.
static void co_csdo_init_seg_req(co_csdo_t *sdo, struct can_msg *msg, uint8_t cs)
Initializes a Client-SDO download/upload segment request CAN frame.
void co_val_fini(co_unsigned16_t type, void *val)
Finalizes a value of the specified data type.
struct co_sdo_par par
The SDO parameter record.
co_unsigned8_t id
Node-ID of SDO's client resp. server.
int can_net_send(can_net_t *net, const struct can_msg *msg)
Sends a CAN frame from a network interface.
#define CO_SDO_SEG_SIZE_GET(cs)
Retrieves the number of bytes containing segment data from the SDO size indicator.
#define CO_SDO_CS_MASK
The mask to extract the command specifier (CS) from an SDO command byte.
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.
#define CO_SDO_AC_NO_SUB
SDO abort code: Sub-index does not exist.
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_send_dn_seg_req(co_csdo_t *sdo, uint32_t n, int last)
Sends a Client-SDO 'download segment' request.
#define CO_SDO_AC_NO_MEM
SDO abort code: Out of memory.
#define CO_SDO_SC_BLK_RES
The SDO client/client subcommand 'block download/upload' response.
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...
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...
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...
size_t nbyte
The number of bytes available at buf.
co_csdo_dn_con_t * dn_con
A pointer to the download confirmation function.
const void * buf
A pointer to the next bytes to be uploaded/downloaded.
#define CO_SDO_SEG_LAST
The mask to get/set the last segment bit from an SDO command byte.
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.
uint8_t ackseq
The sequence number of the last successfully received segment.
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.
static co_csdo_state_t *const co_csdo_blk_dn_ini_state
The 'block download initiate' state.
co_csdo_state_t *(* on_enter)(co_csdo_t *sdo)
A pointer to the function invoked when a new state is entered.
can_recv_t * recv
A pointer to the CAN frame receiver.
#define CAN_FLAG_RTR
The Remote Transmission Request (RTR) flag (unavailable in CAN FD format frames). ...
#define CO_SDO_BLK_SIZE_SET(n)
Sets the SDO size indicator, indicating n bytes contain segment data (in the range [0...
co_unsigned8_t co_sub_get_subidx(const co_sub_t *sub)
Returns the sub-index of a CANopen sub-object.
#define CO_SDO_CCS_UP_SEG_REQ
The SDO client command specifier 'upload segment' request.
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.
#define CO_SDO_SC_MASK
The mask to extract the subcommand (SC) from an SDO command byte.
static void co_csdo_send_dn_exp_req(co_csdo_t *sdo)
Sends a Client-SDO 'download initiate' (expedited) request.
size_t membuf_size(const struct membuf *buf)
Returns the total number of bytes written to a memory buffer.
co_unsigned16_t co_sub_get_type(const co_sub_t *sub)
Returns the data type of a CANopen sub-object.
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_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.
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.
#define CAN_MAX_LEN
The maximum number of bytes in the payload of a CAN format frame.
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.
#define CO_SDO_CCS_BLK_DN_REQ
The SDO client command specifier 'block download' request.
static int co_csdo_timer(const struct timespec *tp, void *data)
The CAN timer callback function for 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.
#define CO_SDO_AC_BLK_SEQ
SDO abort code: Invalid sequence number (block mode only).
size_t co_val_write(co_unsigned16_t type, const void *val, uint8_t *begin, uint8_t *end)
Writes a value of the specified data type to a memory buffer.
static void co_csdo_send_blk_dn_ini_req(co_csdo_t *sdo)
Sends a Client-SDO 'block download initiate' request.
void * dn_ind_data
A pointer to user-specified data for dn_ind.
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 void co_csdo_send_up_seg_req(co_csdo_t *sdo)
Sends a Client-SDO 'upload segment' request.
This header file is part of the CANopen library; it contains the object dictionary declarations...
co_unsigned32_t ac
The current abort code.
#define CO_SDO_SEG_TOGGLE
The mask to get/set the toggle bit from an SDO command byte.
#define CO_SDO_AC_TYPE_LEN
SDO abort code: Data type does not match, length of service parameter does not match.
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...
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.
#define CO_SDO_MAX_SEQNO
The maximum sequence number (or segments per block).
uint_least32_t ldle_u32(const void *ptr)
Loads a 32-bit unsigned integer in little-endian byte order.
static void co_csdo_init_ini_req(co_csdo_t *sdo, struct can_msg *msg, uint8_t cs)
Initializes a Client-SDO download/upload initiate request CAN frame.
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...
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_REQ_INIT
The static initializer for struct co_sdo_req.
void * co_obj_addressof_val(const co_obj_t *obj)
Returns the address of the value 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...
uint8_t blksize
The number of segments per block.
This is the internal header file of the Service Data Object (SDO) declarations.
co_unsigned8_t co_csdo_get_num(const co_csdo_t *sdo)
Returns the SDO number of a Client-SDO.
static int co_csdo_update(co_csdo_t *sdo)
Updates and (de)activates a Client-SDO service.
#define CO_SDO_AC_NO_OBJ
SDO abort code: Object does not exist in the object dictionary.
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.
#define CO_SDO_SEQ_LAST
The mask to get/set the last segment bit from an SDO command byte.
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_time(co_csdo_t *sdo, const struct timespec *tp)
The 'timeout' transition function of the 'block upload end' state.