26#if !LELY_NO_CO_MASTER && !LELY_NO_CO_NMT_CFG
43#ifndef LELY_CO_NMT_CFG_RESET_TIMEOUT
48#define LELY_CO_NMT_CFG_RESET_TIMEOUT 1000
106 co_unsigned8_t subidx, co_unsigned32_t ac,
void *data);
144 co_unsigned16_t idx, co_unsigned8_t subidx, co_unsigned32_t ac);
202 co_unsigned8_t subidx, co_unsigned32_t ac);
207#define LELY_CO_DEFINE_STATE(name, ...) \
208 static co_nmt_cfg_state_t *const name = \
209 &(co_nmt_cfg_state_t){ __VA_ARGS__ };
215LELY_CO_DEFINE_STATE(co_nmt_cfg_abort_state,
228 co_unsigned16_t idx, co_unsigned8_t subidx, co_unsigned32_t ac);
231LELY_CO_DEFINE_STATE(co_nmt_cfg_restore_state,
249LELY_CO_DEFINE_STATE(co_nmt_cfg_reset_state,
266 co_unsigned16_t idx, co_unsigned8_t subidx, co_unsigned32_t ac);
272LELY_CO_DEFINE_STATE(co_nmt_cfg_store_1f20_state,
287 co_unsigned16_t idx, co_unsigned8_t subidx, co_unsigned32_t ac);
290LELY_CO_DEFINE_STATE(co_nmt_cfg_store_1f22_state,
306LELY_CO_DEFINE_STATE(co_nmt_cfg_user_state,
312#undef LELY_CO_DEFINE_STATE
315__co_nmt_cfg_alloc(
void)
326__co_nmt_cfg_free(
void *ptr)
351 goto error_create_recv;
358 goto error_create_timer;
408 goto error_alloc_cfg;
411 if (!__co_nmt_cfg_init(cfg,
net,
dev,
nmt)) {
419 __co_nmt_cfg_free(cfg);
429 __co_nmt_cfg_fini(cfg);
430 __co_nmt_cfg_free(cfg);
501 co_unsigned32_t
ac,
void *data)
548 co_unsigned8_t subidx, co_unsigned32_t
ac)
593 return co_nmt_cfg_abort_state;
598 return co_nmt_cfg_user_state;
600 return co_nmt_cfg_store_1f20_state;
605 co_unsigned8_t subidx = co_dev_get_val_u8(cfg->
dev, 0x1f8a, cfg->
id);
610 return co_nmt_cfg_user_state;
612 return co_nmt_cfg_store_1f20_state;
618 &(co_unsigned32_t){ UINT32_C(0x64616f6c) },
622 return co_nmt_cfg_abort_state;
630 co_unsigned8_t subidx, co_unsigned32_t
ac)
637 return co_nmt_cfg_abort_state;
653 return co_nmt_cfg_reset_state;
677 return co_nmt_cfg_user_state;
679 return co_nmt_cfg_store_1f20_state;
690 return co_nmt_cfg_abort_state;
701 return co_nmt_cfg_store_1f22_state;
707 if (!sub || co_dev_get_val_u8(cfg->
dev, 0x1f21, cfg->
id) != 0)
708 return co_nmt_cfg_store_1f22_state;
717 "SDO abort code %08" PRIX32
718 " on upload request of object 1F20:%02X (Store DCF): %s",
721 return co_nmt_cfg_abort_state;
727 "object 1F20:%02X (Store DCF) unusable for configuration request",
730 return co_nmt_cfg_store_1f22_state;
735 return co_nmt_cfg_store_1f22_state;
740 req->
buf, (
const char *)req->
buf + req->
nbyte, NULL);
743 return co_nmt_cfg_abort_state;
752 co_unsigned8_t subidx, co_unsigned32_t ac)
759 return co_nmt_cfg_abort_state;
774 return co_nmt_cfg_store_1f22_state;
779 co_unsigned16_t type;
785 return co_nmt_cfg_store_1f22_state;
797#if !LELY_NO_CO_OBJ_DEFAULT
813 return co_nmt_cfg_abort_state;
835 return co_nmt_cfg_user_state;
844 "SDO abort code %08" PRIX32
845 " on upload request of object 1F22:%02X (Concise DCF): %s",
848 return co_nmt_cfg_abort_state;
853 "object 1F22:%02X (Concise DCF) unusable for configuration request",
855 return co_nmt_cfg_user_state;
860 return co_nmt_cfg_user_state;
863 const uint_least8_t *begin = req->
buf;
864 const uint_least8_t *end = begin + req->
nbyte;
868 return co_nmt_cfg_abort_state;
876 co_unsigned8_t subidx, co_unsigned32_t ac)
884 return co_nmt_cfg_abort_state;
887 return co_nmt_cfg_user_state;
908 return co_nmt_cfg_abort_state;
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.
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.
void co_dev_destroy(co_dev_t *dev)
Destroys a CANopen device, including all objects in its object dictionary.
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_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...
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.
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...
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_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.
int co_sdo_req_first(const struct co_sdo_req *req)
Returns 1 if the specified request includes the first segment, and 0 otherwise.
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.
const char * co_sdo_ac2str(co_unsigned32_t ac)
Returns a string describing an SDO abort code.
int co_sdo_req_last(const struct co_sdo_req *req)
Returns 1 if the specified request includes the last segment, and 0 otherwise.
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.
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.
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'.
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.
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_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 header file is part of the CANopen library; it contains the object dictionary declarations.
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.
co_unsigned8_t co_sub_get_subidx(const co_sub_t *sub)
Returns the sub-index of a CANopen sub-object.
co_unsigned16_t co_obj_get_idx(const co_obj_t *obj)
Returns the index of a CANopen object.
const void * co_sub_get_def(const co_sub_t *sub)
Returns a pointer to the default value 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_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.
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.
#define CO_OBJ_FLAGS_DOWNLOAD_FILE
If a write access is performed for the object, the data is stored in a file.
co_sub_t * co_sub_next(const co_sub_t *sub)
Finds the next sub-object in a CANopen object.
#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.
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_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.
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_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_time)(co_nmt_cfg_t *cfg, const struct timespec *tp)
A pointer to the transition function invoked when a timeout occurs.
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.
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.
const void * buf
A pointer to the next bytes to be uploaded/downloaded.
size_t nbyte
The number of bytes available at buf.
A time type with nanosecond resolution.
#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.
int co_val_cmp(co_unsigned16_t type, const void *v1, const void *v2)
Compares two values of the specified data type.