26 #ifndef LELY_NO_CO_MASTER
39 #ifndef LELY_CO_NMT_CFG_RESET_TIMEOUT
44 #define LELY_CO_NMT_CFG_RESET_TIMEOUT 1000
102 co_unsigned8_t subidx, co_unsigned32_t ac,
void *data);
140 co_unsigned16_t idx, co_unsigned8_t subidx, co_unsigned32_t ac);
198 co_unsigned8_t subidx, co_unsigned32_t ac);
203 #define LELY_CO_DEFINE_STATE(name, ...) \
204 static co_nmt_cfg_state_t *const name = \
205 &(co_nmt_cfg_state_t){ __VA_ARGS__ };
211 LELY_CO_DEFINE_STATE(co_nmt_cfg_abort_state,
224 co_unsigned16_t idx, co_unsigned8_t subidx, co_unsigned32_t ac);
227 LELY_CO_DEFINE_STATE(co_nmt_cfg_restore_state,
245 LELY_CO_DEFINE_STATE(co_nmt_cfg_reset_state,
260 co_unsigned16_t idx, co_unsigned8_t subidx, co_unsigned32_t ac);
266 LELY_CO_DEFINE_STATE(co_nmt_cfg_store_1f20_state,
281 co_unsigned16_t idx, co_unsigned8_t subidx, co_unsigned32_t ac);
284 LELY_CO_DEFINE_STATE(co_nmt_cfg_store_1f22_state,
298 LELY_CO_DEFINE_STATE(co_nmt_cfg_user_state,
304 #undef LELY_CO_DEFINE_STATE
307 __co_nmt_cfg_alloc(
void)
316 __co_nmt_cfg_free(
void *ptr)
341 goto error_create_recv;
348 goto error_create_timer;
395 goto error_alloc_cfg;
398 if (!__co_nmt_cfg_init(cfg,
net,
dev,
nmt)) {
406 __co_nmt_cfg_free(cfg);
416 __co_nmt_cfg_fini(cfg);
417 __co_nmt_cfg_free(cfg);
488 co_unsigned32_t
ac,
void *data)
535 co_unsigned8_t subidx, co_unsigned32_t
ac)
580 return co_nmt_cfg_abort_state;
584 return co_nmt_cfg_store_1f20_state;
588 co_unsigned8_t subidx = co_dev_get_val_u8(cfg->
dev, 0x1f8a, cfg->
id);
592 return co_nmt_cfg_store_1f20_state;
597 &(co_unsigned32_t){ UINT32_C(0x64616f6c) },
601 return co_nmt_cfg_abort_state;
609 co_unsigned8_t subidx, co_unsigned32_t
ac)
616 return co_nmt_cfg_abort_state;
632 return co_nmt_cfg_reset_state;
655 return co_nmt_cfg_store_1f20_state;
665 return co_nmt_cfg_abort_state;
674 return co_nmt_cfg_store_1f22_state;
680 if (!sub || co_dev_get_val_u8(cfg->
dev, 0x1f21, cfg->
id) != 0)
681 return co_nmt_cfg_store_1f22_state;
689 "SDO abort code %08" PRIX32
690 " on upload request of object 1F20:%02X (Store DCF): %s",
692 return co_nmt_cfg_abort_state;
697 "object 1F20:%02X (Store DCF) unusable for configuration request",
699 return co_nmt_cfg_store_1f22_state;
704 return co_nmt_cfg_store_1f22_state;
709 req->
buf, (
const char *)req->
buf + req->
nbyte, NULL);
712 return co_nmt_cfg_abort_state;
721 co_unsigned8_t subidx, co_unsigned32_t ac)
728 return co_nmt_cfg_abort_state;
743 return co_nmt_cfg_store_1f22_state;
748 co_unsigned16_t type;
754 return co_nmt_cfg_store_1f22_state;
766 #ifndef LELY_NO_CO_OBJ_DEFAULT
782 return co_nmt_cfg_abort_state;
804 return co_nmt_cfg_user_state;
812 "SDO abort code %08" PRIX32
813 " on upload request of object 1F22:%02X (Concise DCF): %s",
815 return co_nmt_cfg_abort_state;
820 "object 1F22:%02X (Concise DCF) unusable for configuration request",
822 return co_nmt_cfg_user_state;
827 return co_nmt_cfg_user_state;
829 const uint_least8_t *begin = req->
buf;
830 const uint_least8_t *end = begin + req->
nbyte;
835 return co_nmt_cfg_abort_state;
839 req->
nbyte = end - begin;
840 req->
offset = begin - (
const uint_least8_t *)req->
buf;
847 co_unsigned8_t subidx, co_unsigned32_t ac)
854 return co_nmt_cfg_abort_state;
858 return co_nmt_cfg_user_state;
860 const uint_least8_t *begin =
861 (
const uint_least8_t *)req->
buf + req->
offset;
862 const uint_least8_t *end = begin + req->
nbyte;
867 return co_nmt_cfg_abort_state;
873 return co_nmt_cfg_abort_state;
877 co_unsigned32_t
size;
880 return co_nmt_cfg_abort_state;
884 if (end - begin < (ptrdiff_t)
size) {
886 return co_nmt_cfg_abort_state;
890 req->
offset = begin +
size - (
const uint_least8_t *)req->
buf;
898 return co_nmt_cfg_abort_state;
920 return co_nmt_cfg_abort_state;
This header file is part of the CANopen library; it contains the device description declarations.
co_sub_t * co_dev_find_sub(const co_dev_t *dev, co_unsigned16_t idx, co_unsigned8_t subidx)
Finds a sub-object in the object dictionary of a CANopen device.
#define CO_NUM_NODES
The maximum number of nodes in a CANopen network.
co_obj_t * co_dev_first_obj(const co_dev_t *dev)
Finds the first object (with the lowest index) in the object dictionary of a CANopen device.
void co_dev_destroy(co_dev_t *dev)
Destroys a CANopen device, including all objects in its object dictionary.
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.
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 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.
void co_csdo_set_timeout(co_csdo_t *sdo, int timeout)
Sets the timeout of a Client-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...
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 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...
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.
void co_csdo_destroy(co_csdo_t *sdo)
Destroys a CANopen Client-SDO service.
This header file is part of the CANopen library; it contains the Electronic Data Sheet (EDS) and Devi...
co_dev_t * co_dev_create_from_dcf_text(const char *begin, const char *end, struct floc *at)
Creates a CANopen device from an EDS or DCF text string.
This header file is part of the utilities library; it contains the diagnostic declarations.
void diag(enum diag_severity severity, int errc, const char *format,...)
Emits a diagnostic message.
@ ERRNUM_INVAL
Invalid argument.
@ ERRNUM_INPROGRESS
Operation in progress.
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.
const void * co_sub_get_val(const co_sub_t *sub)
Returns a pointer to the current value of a CANopen sub-object.
co_sub_t * co_sub_next(const co_sub_t *sub)
Finds the next sub-object in a CANopen object.
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().
const void * co_sub_get_def(const co_sub_t *sub)
Returns a pointer to the default value of a CANopen sub-object.
unsigned int co_sub_get_flags(const co_sub_t *sub)
Returns the object flags of a CANopen sub-object.
co_obj_t * co_obj_next(const co_obj_t *obj)
Finds the next object in the object dictionary of a CANopen device.
co_sub_t * co_obj_find_sub(const co_obj_t *obj, co_unsigned8_t subidx)
Finds a sub-object in a CANopen object.
co_sub_t * co_obj_first_sub(const co_obj_t *obj)
Finds the first sub-object (with the lowest sub-index) in a CANopen object.
#define CO_OBJ_FLAGS_DOWNLOAD_FILE
If a write access is performed for the object, the data is stored in a file.
#define CO_ACCESS_WRITE
The object can be written.
unsigned int co_sub_get_access(const co_sub_t *sub)
Returns the access type of a CANopen sub-object.
co_unsigned16_t co_sub_get_type(const co_sub_t *sub)
Returns the data type of a CANopen sub-object.
int co_sdo_req_first(const struct co_sdo_req *req)
Returns 1 if the specified request includes the first segment, and 0 otherwise.
#define CO_SDO_AC_TYPE_LEN_LO
SDO abort code: Data type does not match, length of service parameter too low.
void co_sdo_req_fini(struct co_sdo_req *req)
Finalizes a CANopen SDO upload/download request.
#define CO_SDO_AC_ERROR
SDO abort code: General error.
void co_sdo_req_clear(struct co_sdo_req *req)
Clears a CANopen SDO upload/download request, including its buffer.
int co_sdo_req_last(const struct co_sdo_req *req)
Returns 1 if the specified request includes the last segment, and 0 otherwise.
const char * co_sdo_ac2str(co_unsigned32_t ac)
Returns a string describing an SDO abort code.
void co_sdo_req_init(struct co_sdo_req *req)
Initializes a CANopen SDO upload/download request.
#define CO_SDO_AC_TIMEOUT
SDO abort code: SDO protocol timed out.
void can_timer_stop(can_timer_t *timer)
Stops a CAN timer and unregisters it with a 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_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.
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.
void co_nmt_cfg_ind(co_nmt_t *nmt, co_unsigned8_t id, co_csdo_t *sdo)
The CANopen NMT 'update configuration' indication function, invoked when a configuration request is r...
void co_nmt_cfg_con(co_nmt_t *nmt, co_unsigned8_t id, co_unsigned32_t ac)
The CANopen NMT 'configuration request' confirmation function, invoked when a configuration request c...
#define CO_NMT_EC_CANID(id)
The CAN identifier used for both node guarding and heartbeat monitoring.
#define CO_NMT_CS_RESET_NODE
The NMT command specifier 'reset node'.
int co_nmt_cs_req(co_nmt_t *nmt, co_unsigned8_t cs, co_unsigned8_t id)
Submits an NMT request to a slave.
#define CO_NMT_CS_RESET_COMM
The NMT command specifier 'reset communication'.
static co_nmt_cfg_state_t * co_nmt_cfg_store_1f20_on_dn_con(co_nmt_cfg_t *cfg, co_unsigned16_t idx, co_unsigned8_t subidx, co_unsigned32_t ac)
The 'SDO download confirmation' transition function of the 'store object 1F20' state.
static co_nmt_cfg_state_t * co_nmt_cfg_store_1f22_on_enter(co_nmt_cfg_t *cfg)
The entry function of the 'store object 1F22' state.
static void co_nmt_cfg_enter(co_nmt_cfg_t *cfg, co_nmt_cfg_state_t *next)
Enters the specified state of a 'configuration request; and invokes the exit and entry functions.
static co_nmt_cfg_state_t * co_nmt_cfg_abort_on_enter(co_nmt_cfg_t *cfg)
The entry function of the 'abort' state.
static co_nmt_cfg_state_t * co_nmt_cfg_reset_on_recv(co_nmt_cfg_t *cfg, const struct can_msg *msg)
The 'CAN frame received' transition function of the 'reset' state.
void co_nmt_cfg_destroy(co_nmt_cfg_t *cfg)
Destroys a CANopen NMT 'configuration request'.
static co_nmt_cfg_state_t * co_nmt_cfg_user_on_enter(co_nmt_cfg_t *cfg)
The entry function of the 'user-defined configuration' state.
static co_nmt_cfg_state_t * co_nmt_cfg_reset_on_enter(co_nmt_cfg_t *cfg)
The entry function of the 'reset' state.
int co_nmt_cfg_cfg_req(co_nmt_cfg_t *cfg, co_unsigned8_t id, int timeout, co_csdo_ind_t *dn_ind, co_csdo_ind_t *up_ind, void *data)
Starts a CANopen NMT 'configuration request'.
static co_nmt_cfg_state_t * co_nmt_cfg_store_1f20_on_enter(co_nmt_cfg_t *cfg)
The entry function of the 'store object 1F20' state.
static int co_nmt_cfg_recv(const struct can_msg *msg, void *data)
The CAN receive callback function for a 'configuration request'.
co_nmt_cfg_t * co_nmt_cfg_create(can_net_t *net, co_dev_t *dev, co_nmt_t *nmt)
Creates a new CANopen NMT 'configuration request'.
static co_nmt_cfg_state_t * co_nmt_cfg_user_on_res(co_nmt_cfg_t *cfg, co_unsigned32_t ac)
The 'result received' function of the 'user-defined configuration' state.
static co_nmt_cfg_state_t * co_nmt_cfg_restore_on_dn_con(co_nmt_cfg_t *cfg, co_unsigned16_t idx, co_unsigned8_t subidx, co_unsigned32_t ac)
The 'SDO download confirmation' transition function of the 'restore configuration' state.
static co_nmt_cfg_state_t * co_nmt_cfg_reset_on_time(co_nmt_cfg_t *cfg, const struct timespec *tp)
The 'timeout' transition function of the 'reset' state.
static void co_nmt_cfg_emit_recv(co_nmt_cfg_t *cfg, const struct can_msg *msg)
Invokes the 'CAN frame received' transition function of the current state of a 'configuration request...
int co_nmt_cfg_cfg_res(co_nmt_cfg_t *cfg, co_unsigned32_t ac)
Indicates the result of the 'update configuration' step of an NMT 'configuration request'.
static co_nmt_cfg_state_t * co_nmt_cfg_restore_on_enter(co_nmt_cfg_t *cfg)
The entry function of the 'restore configuration' state.
static co_nmt_cfg_state_t * co_nmt_cfg_store_1f22_on_dn_con(co_nmt_cfg_t *cfg, co_unsigned16_t idx, co_unsigned8_t subidx, co_unsigned32_t ac)
The 'SDO download confirmation' transition function of the 'store object 1F22' state.
static int co_nmt_cfg_timer(const struct timespec *tp, void *data)
The CAN timer callback function for a 'configuration request'.
static void co_nmt_cfg_dn_con(co_csdo_t *sdo, co_unsigned16_t idx, co_unsigned8_t subidx, co_unsigned32_t ac, void *data)
The CANopen SDO download confirmation callback function for a 'configuration request'.
static void co_nmt_cfg_emit_dn_con(co_nmt_cfg_t *cfg, co_unsigned16_t idx, co_unsigned8_t subidx, co_unsigned32_t ac)
Invokes the 'SDO download confirmation' transition function of the current state of a 'configuration ...
#define LELY_CO_NMT_CFG_RESET_TIMEOUT
The timeout (in milliseconds) after sending the NMT 'reset communication' or 'reset node' command.
static void co_nmt_cfg_store_1f20_on_leave(co_nmt_cfg_t *cfg)
The exit function of the 'store object 1F20' state.
static void co_nmt_cfg_emit_time(co_nmt_cfg_t *cfg, const struct timespec *tp)
Invokes the 'timeout' transition function of the current state of a 'configuration request'.
static void co_nmt_cfg_emit_res(co_nmt_cfg_t *cfg, co_unsigned32_t ac)
Invokes the 'result received' transition function of the current state of a 'configuration request'.
This is the internal header file of the NMT 'configuration request' declarations.
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....
A CANopen NMT 'configuration request' state.
void(* on_leave)(co_nmt_cfg_t *cfg)
A pointer to the function invoked when the current state is left.
co_nmt_cfg_state_t *(* on_enter)(co_nmt_cfg_t *cfg)
A pointer to the function invoked when a new state is entered.
co_nmt_cfg_state_t *(* on_time)(co_nmt_cfg_t *cfg, const struct timespec *tp)
A pointer to the transition function invoked when a timeout occurs.
co_nmt_cfg_state_t *(* on_recv)(co_nmt_cfg_t *cfg, const struct can_msg *msg)
A pointer to the transition function invoked when a CAN frame has been received.
co_nmt_cfg_state_t *(* on_res)(co_nmt_cfg_t *cfg, co_unsigned32_t ac)
A pointer to the transition function invoked when an NMT'update configuration' step completes.
co_nmt_cfg_state_t *(* on_dn_con)(co_nmt_cfg_t *cfg, co_unsigned16_t idx, co_unsigned8_t subidx, co_unsigned32_t ac)
A pointer to the transition function invoked when an SDO download request completes.
A CANopen NMT 'configuration request' service.
co_nmt_t * nmt
A pointer to an NMT master service.
co_nmt_cfg_state_t * state
A pointer to the current state.
can_timer_t * timer
A pointer to the CAN timer.
co_unsigned32_t ac
The SDO abort code.
co_dev_t * dev
A pointer to a CANopen device.
co_unsigned32_t assignment
The NMT slave assignment (object 1F81).
co_dev_t * dev_1f20
The object dictionary stored in object 1F20 (Store DCF).
can_net_t * net
A pointer to a CAN network interface.
co_unsigned8_t id
The node-ID.
struct co_sdo_req req
The CANopen SDO upload request used for reading sub-objects.
co_unsigned32_t n_1f22
The number of entries in the concise DCF in object 1F22.
can_recv_t * recv
A pointer to the CAN frame receiver.
co_csdo_t * sdo
A pointer to the Client-SDO used to access slave objects.
A CANopen NMT master/slave service.
A CAN or CAN FD format frame.
A CANopen SDO upload/download request.
size_t offset
The offset of the bytes at buf.
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.
#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.
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.
int co_val_cmp(co_unsigned16_t type, const void *v1, const void *v2)
Compares two values of the specified data type.