Lely core libraries 2.3.4
nmt.c File Reference

This file is part of the CANopen library; it contains the implementation of the network management (NMT) functions. More...

#include "co.h"
#include <lely/util/diag.h>
#include <lely/can/buf.h>
#include <lely/co/csdo.h>
#include <lely/util/time.h>
#include <lely/co/dev.h>
#include <lely/co/emcy.h>
#include <lely/co/nmt.h>
#include <lely/co/obj.h>
#include <lely/co/rpdo.h>
#include <lely/co/sdo.h>
#include <lely/co/tpdo.h>
#include <lely/co/val.h>
#include "nmt_boot.h"
#include "nmt_cfg.h"
#include "nmt_hb.h"
#include "nmt_srv.h"
#include <assert.h>
#include <stdlib.h>
Include dependency graph for nmt.c:

Go to the source code of this file.

Data Structures

struct  co_nmt_slave
 A struct containing the state of an NMT slave. More...
 
struct  __co_nmt
 A CANopen NMT master/slave service. More...
 
struct  __co_nmt_state
 A CANopen NMT state. More...
 

Macros

#define CO_NMT_PREOP_SRV
 The services enabled in the NMT 'pre-operational' state.
 
#define CO_NMT_START_SRV   (CO_NMT_PREOP_SRV | CO_NMT_SRV_PDO)
 The services enabled in the NMT 'operational' state.
 
#define CO_NMT_STOP_SRV   CO_NMT_SRV_LSS
 The services enabled in the NMT 'stopped' state.
 

Typedefs

typedef const struct __co_nmt_state co_nmt_state_t
 An opaque CANopen NMT state type.
 

Functions

static co_unsigned32_t co_100c_dn_ind (co_sub_t *sub, struct co_sdo_req *req, void *data)
 The download indication function for CANopen object 100C (Guard time).
 
static co_unsigned32_t co_100d_dn_ind (co_sub_t *sub, struct co_sdo_req *req, void *data)
 The download indication function for CANopen object 100D (Life time factor).
 
static co_unsigned32_t co_1016_dn_ind (co_sub_t *sub, struct co_sdo_req *req, void *data)
 The download indication function for CANopen object 1016 (Consumer heartbeat time).
 
static co_unsigned32_t co_1017_dn_ind (co_sub_t *sub, struct co_sdo_req *req, void *data)
 The download indication function for CANopen object 1017 (Producer heartbeat time).
 
static co_unsigned32_t co_1f25_dn_ind (co_sub_t *sub, struct co_sdo_req *req, void *data)
 The download indication function for (all sub-objects of) CANopen object 1F25 (Configuration request).
 
static co_unsigned32_t co_1f80_dn_ind (co_sub_t *sub, struct co_sdo_req *req, void *data)
 The download indication function for (all sub-objects of) CANopen object 1F80 (NMT startup).
 
static co_unsigned32_t co_1f82_dn_ind (co_sub_t *sub, struct co_sdo_req *req, void *data)
 The download indication function for (all sub-objects of) CANopen object 1F80 (Request NMT).
 
static int co_nmt_recv_000 (const struct can_msg *msg, void *data)
 The CAN receive callback function for NMT messages.
 
static int co_nmt_recv_700 (const struct can_msg *msg, void *data)
 The CAN receive callback function for NMT error control (node guarding RTR) messages.
 
static int co_nmt_ng_timer (const struct timespec *tp, void *data)
 The CAN timer callback function for node guarding.
 
static int co_nmt_ec_timer (const struct timespec *tp, void *data)
 The CAN timer callback function for life guarding or heartbeat production.
 
static int co_nmt_cs_timer (const struct timespec *tp, void *data)
 The CAN timer callback function for sending buffered NMT messages.
 
static void co_nmt_st_ind (co_nmt_t *nmt, co_unsigned8_t id, co_unsigned8_t st)
 The indication function for state change events.
 
static void default_ng_ind (co_nmt_t *nmt, co_unsigned8_t id, int state, int reason, void *data)
 The default node guarding event handler.
 
static void default_lg_ind (co_nmt_t *nmt, int state, void *data)
 The default life guarding event handler.
 
static void default_hb_ind (co_nmt_t *nmt, co_unsigned8_t id, int state, int reason, void *data)
 The default heartbeat event handler.
 
static void default_st_ind (co_nmt_t *nmt, co_unsigned8_t id, co_unsigned8_t st, void *data)
 The default state change event handler.
 
static void co_nmt_dn_ind (const co_csdo_t *sdo, co_unsigned16_t idx, co_unsigned8_t subidx, size_t size, size_t nbyte, void *data)
 The SDO download progress indication function.
 
static void co_nmt_up_ind (const co_csdo_t *sdo, co_unsigned16_t idx, co_unsigned8_t subidx, size_t size, size_t nbyte, void *data)
 The SDO upload progress indication function.
 
static void co_nmt_tpdo_event_ind (co_unsigned16_t n, void *data)
 The Transmit-PDO event indication function.
 
static void co_nmt_sam_mpdo_event_ind (co_unsigned16_t n, co_unsigned16_t idx, co_unsigned8_t subidx, void *data)
 The SAM-MPDO event indication function.
 
static void co_nmt_enter (co_nmt_t *nmt, co_nmt_state_t *next)
 Enters the specified state of an NMT master/slave service and invokes the exit and entry functions.
 
static void co_nmt_emit_cs (co_nmt_t *nmt, co_unsigned8_t cs)
 Invokes the 'NMT command received' transition function of the current state of an NMT master/slave service.
 
static void co_nmt_emit_boot (co_nmt_t *nmt, co_unsigned8_t id, co_unsigned8_t st, char es)
 Invokes the 'boot slave completed' transition function of the current state of an NMT master service.
 
static co_nmt_state_tco_nmt_default_on_boot (co_nmt_t *nmt, co_unsigned8_t id, co_unsigned8_t st, char es)
 The default 'boot slave completed' transition function.
 
static co_nmt_state_tco_nmt_init_on_cs (co_nmt_t *nmt, co_unsigned8_t cs)
 The 'NMT command received' transition function of the 'initializing' state.
 
static co_nmt_state_tco_nmt_reset_node_on_enter (co_nmt_t *nmt)
 The entry function of the 'reset application' state.
 
static co_nmt_state_tco_nmt_reset_comm_on_enter (co_nmt_t *nmt)
 The entry function of the 'reset communication' state.
 
static co_nmt_state_tco_nmt_reset_comm_on_cs (co_nmt_t *nmt, co_unsigned8_t cs)
 The 'NMT command received' transition function of the 'reset communication' state.
 
static co_nmt_state_tco_nmt_bootup_on_enter (co_nmt_t *nmt)
 The entry function of the 'boot-up' state.
 
static co_nmt_state_tco_nmt_bootup_on_cs (co_nmt_t *nmt, co_unsigned8_t cs)
 The 'NMT command received' transition function of the 'boot-up' state.
 
static co_nmt_state_tco_nmt_preop_on_enter (co_nmt_t *nmt)
 The entry function of the 'pre-operational' state.
 
static co_nmt_state_tco_nmt_preop_on_cs (co_nmt_t *nmt, co_unsigned8_t cs)
 The 'NMT command received' transition function of the 'pre-operational' state.
 
static co_nmt_state_tco_nmt_preop_on_boot (co_nmt_t *nmt, co_unsigned8_t id, co_unsigned8_t st, char es)
 The 'boot slave completed' transition function of the 'pre-operational' state.
 
static co_nmt_state_tco_nmt_start_on_enter (co_nmt_t *nmt)
 The entry function of the 'operational' state.
 
static co_nmt_state_tco_nmt_start_on_cs (co_nmt_t *nmt, co_unsigned8_t cs)
 The 'NMT command received' transition function of the 'operational' state.
 
static co_nmt_state_tco_nmt_stop_on_enter (co_nmt_t *nmt)
 The entry function of the 'stopped' state.
 
static co_nmt_state_tco_nmt_stop_on_cs (co_nmt_t *nmt, co_unsigned8_t cs)
 The 'NMT command received' transition function of the 'stopped' state.
 
static co_nmt_state_tco_nmt_startup (co_nmt_t *nmt)
 The NMT startup procedure (see Fig. 1 & 2 in CiA 302-2 version 4.1.0).
 
static co_nmt_state_tco_nmt_startup_master (co_nmt_t *nmt)
 The NMT master startup procedure.
 
static co_nmt_state_tco_nmt_startup_slave (co_nmt_t *nmt)
 The NMT slave startup procedure.
 
static void co_nmt_ec_init (co_nmt_t *nmt)
 Initializes the error control services.
 
static void co_nmt_ec_fini (co_nmt_t *nmt)
 Finalizes the error control services.
 
static void co_nmt_ec_update (co_nmt_t *nmt)
 Updates and (de)activates the life guarding or heartbeat production services.
 
static int co_nmt_ec_send_res (co_nmt_t *nmt, co_unsigned8_t st)
 Sends an NMT error control response message.
 
static void co_nmt_hb_init (co_nmt_t *nmt)
 Initializes the heartbeat consumer services.
 
static void co_nmt_hb_fini (co_nmt_t *nmt)
 Finalizes the heartbeat consumer services.
 
static co_nmt_hb_tco_nmt_hb_find (co_nmt_t *nmt, co_unsigned8_t id, co_unsigned16_t *pms)
 Find the heartbeat consumer for the specified node.
 
static void co_nmt_slaves_init (co_nmt_t *nmt)
 Initializes NMT slave management.
 
static void co_nmt_slaves_fini (co_nmt_t *nmt)
 Finalizes NMT slave management.
 
static int co_nmt_slaves_boot (co_nmt_t *nmt)
 Starts the NMT 'boot slave' processes.
 
static int co_nmt_chk_bootup_slaves (const co_nmt_t *nmt)
 Checks if boot-up messages have been received from all mandatory slaves.
 
co_unsigned32_t co_dev_cfg_hb (co_dev_t *dev, co_unsigned8_t id, co_unsigned16_t ms)
 Configures heartbeat consumption for the specified node by updating CANopen object 1016 (Consumer heartbeat time).
 
const char * co_nmt_es2str (char es)
 Returns a pointer to a string describing an NMT boot error status.
 
co_nmt_tco_nmt_create (can_net_t *net, co_dev_t *dev)
 Creates a new CANopen NMT master/slave service.
 
void co_nmt_destroy (co_nmt_t *nmt)
 Destroys a CANopen NMT master/slave service.
 
can_net_tco_nmt_get_net (const co_nmt_t *nmt)
 Returns a pointer to the CAN network of an NMT master/slave service.
 
co_dev_tco_nmt_get_dev (const co_nmt_t *nmt)
 Returns a pointer to the CANopen device of an NMT master/slave service.
 
void co_nmt_get_cs_ind (const co_nmt_t *nmt, co_nmt_cs_ind_t **pind, void **pdata)
 Retrieves the indication function invoked when an NMT command is received.
 
void co_nmt_set_cs_ind (co_nmt_t *nmt, co_nmt_cs_ind_t *ind, void *data)
 Sets the indication function invoked when an NMT command is received.
 
void co_nmt_get_ng_ind (const co_nmt_t *nmt, co_nmt_ng_ind_t **pind, void **pdata)
 Retrieves the indication function invoked when a node guarding event occurs.
 
void co_nmt_set_ng_ind (co_nmt_t *nmt, co_nmt_ng_ind_t *ind, void *data)
 Sets the indication function invoked when a node guarding event occurs.
 
void co_nmt_on_ng (co_nmt_t *nmt, co_unsigned8_t id, int state, int reason)
 Implements the default behavior when a node guarding event occurs (see sections 7.2.8.2.2.1 and 7.2.8.3.2.1 in CiA 301 version 4.2.0).
 
void co_nmt_get_lg_ind (const co_nmt_t *nmt, co_nmt_lg_ind_t **pind, void **pdata)
 Retrieves the indication function invoked when a life guarding event occurs.
 
void co_nmt_set_lg_ind (co_nmt_t *nmt, co_nmt_lg_ind_t *ind, void *data)
 Sets the indication function invoked when a life guarding event occurs.
 
void co_nmt_on_lg (co_nmt_t *nmt, int state)
 Implements the default behavior when a life guarding event occurs (see section 7.2.8.2.2.2 in CiA 301 version 4.2.0).
 
void co_nmt_get_hb_ind (const co_nmt_t *nmt, co_nmt_hb_ind_t **pind, void **pdata)
 Retrieves the indication function invoked when a heartbeat event occurs.
 
void co_nmt_set_hb_ind (co_nmt_t *nmt, co_nmt_hb_ind_t *ind, void *data)
 Sets the indication function invoked when a heartbeat event occurs.
 
void co_nmt_on_hb (co_nmt_t *nmt, co_unsigned8_t id, int state, int reason)
 Implements the default behavior when a heartbeat event occurs (see sections 7.2.8.2.2.3 and 7.2.8.3.2.2 in CiA 301 version 4.2.0).
 
void co_nmt_get_st_ind (const co_nmt_t *nmt, co_nmt_st_ind_t **pind, void **pdata)
 Retrieves the indication function invoked when a state change is detected.
 
void co_nmt_set_st_ind (co_nmt_t *nmt, co_nmt_st_ind_t *ind, void *data)
 Sets the indication function invoked when a state change is detected.
 
void co_nmt_on_st (co_nmt_t *nmt, co_unsigned8_t id, co_unsigned8_t st)
 Implements the default behavior when a state change is detected by the node guarding or heartbeat protocol.
 
void co_nmt_get_lss_req (const co_nmt_t *nmt, co_nmt_lss_req_t **pind, void **pdata)
 Retrieves the request function invoked to perform LSS when booting an NMT master.
 
void co_nmt_set_lss_req (co_nmt_t *nmt, co_nmt_lss_req_t *ind, void *data)
 Sets the request function invoked to perform LSS when booting an NMT master.
 
void co_nmt_get_boot_ind (const co_nmt_t *nmt, co_nmt_boot_ind_t **pind, void **pdata)
 Retrieves the indication function invoked when a CANopen NMT 'boot slave' process completes.
 
void co_nmt_set_boot_ind (co_nmt_t *nmt, co_nmt_boot_ind_t *ind, void *data)
 Sets the indication function invoked when a CANopen NMT 'boot slave' process completes.
 
void co_nmt_get_cfg_ind (const co_nmt_t *nmt, co_nmt_cfg_ind_t **pind, void **pdata)
 Retrieves the indication function invoked when a CANopen NMT 'configuration request' is received.
 
void co_nmt_set_cfg_ind (co_nmt_t *nmt, co_nmt_cfg_ind_t *ind, void *data)
 Sets the indication function invoked when a CANopen NMT 'configuration request' process is received.
 
void co_nmt_get_dn_ind (const co_nmt_t *nmt, co_nmt_sdo_ind_t **pind, void **pdata)
 Retrieves the indication function used to notify the user of the progress of the current SDO download request during the CANopen NMT 'boot slave' process.
 
void co_nmt_set_dn_ind (co_nmt_t *nmt, co_nmt_sdo_ind_t *ind, void *data)
 Sets the indication function used to notify the user of the progress of the current SDO download request during the CANopen NMT 'boot slave' process.
 
void co_nmt_get_up_ind (const co_nmt_t *nmt, co_nmt_sdo_ind_t **pind, void **pdata)
 Retrieves the indication function used to notify the user of the progress of the current SDO upload request during the CANopen NMT 'boot slave' process.
 
void co_nmt_set_up_ind (co_nmt_t *nmt, co_nmt_sdo_ind_t *ind, void *data)
 Sets the indication function used to notify the user of the progress of the current SDO upload request during the CANopen NMT 'boot slave' process.
 
void co_nmt_get_sync_ind (const co_nmt_t *nmt, co_nmt_sync_ind_t **pind, void **pdata)
 Retrieves the indication function invoked by co_nmt_on_sync() after all PDOs have been transmitted/processed.
 
void co_nmt_set_sync_ind (co_nmt_t *nmt, co_nmt_sync_ind_t *ind, void *data)
 Sets the indication function invoked by co_nmt_on_sync() after all PDOs have been transmitted/processed.
 
void co_nmt_on_sync (co_nmt_t *nmt, co_unsigned8_t cnt)
 Implements the default behavior after a SYNC object is received or transmitted.
 
void co_nmt_on_err (co_nmt_t *nmt, co_unsigned16_t eec, co_unsigned8_t er, const co_unsigned8_t msef[5])
 Implements the default error handling behavior by generating an EMCY message with co_emcy_push() and invoking co_nmt_comm_err_ind() in case of a communication error (emergency error code 0x81xx).
 
void co_nmt_on_tpdo_event (co_nmt_t *nmt, co_unsigned16_t n)
 Implements the default behavior when an event is indicated for an event-driven (asynchronous) Transmit-PDO by triggering the transmission of the PDO with co_tpdo_event().
 
void co_nmt_on_tpdo_event_lock (co_nmt_t *nmt)
 Postpones the transmission of PDOs triggered by co_nmt_on_tpdo_event() until a matching call to co_nmt_on_tpdo_event_unlock().
 
void co_nmt_on_tpdo_event_unlock (co_nmt_t *nmt)
 Undoes the effect of a single call to co_nmt_on_tpdo_event_lock() and possibly triggers the transmission of postponed PDOs.
 
void co_nmt_on_sam_mpdo_event (co_nmt_t *nmt, co_unsigned16_t n, co_unsigned16_t idx, co_unsigned8_t subidx)
 Implements the default behavior when an event is indicated for a source address mode multiplex PDO by triggering the transmission of the PDO with co_sam_mpdo_event().
 
co_unsigned8_t co_nmt_get_id (const co_nmt_t *nmt)
 Returns the pending node-ID.
 
int co_nmt_set_id (co_nmt_t *nmt, co_unsigned8_t id)
 Sets the pending node-ID.
 
co_unsigned8_t co_nmt_get_st (const co_nmt_t *nmt)
 Returns the current state of a CANopen NMT service (one of CO_NMT_ST_BOOTUP, CO_NMT_ST_STOP, CO_NMT_ST_START, CO_NMT_ST_RESET_NODE, CO_NMT_ST_RESET_COMM or CO_NMT_ST_PREOP).
 
int co_nmt_is_master (const co_nmt_t *nmt)
 Returns 1 if the specified CANopen NMT service is a master, and 0 if not.
 
int co_nmt_get_timeout (const co_nmt_t *nmt)
 Returns the default SDO timeout used during the NMT 'boot slave' and 'check configuration' processes.
 
void co_nmt_set_timeout (co_nmt_t *nmt, int timeout)
 Sets the default SDO timeout used during the NMT 'boot slave' and 'check configuration' processes.
 
int co_nmt_cs_req (co_nmt_t *nmt, co_unsigned8_t cs, co_unsigned8_t id)
 Submits an NMT request to a slave.
 
int co_nmt_lss_con (co_nmt_t *nmt)
 Confirms the completion of the process when booting an NMT master.
 
int co_nmt_boot_req (co_nmt_t *nmt, co_unsigned8_t id, int timeout)
 Requests the NMT 'boot slave' process for the specified node.
 
int co_nmt_is_booting (const co_nmt_t *nmt, co_unsigned8_t id)
 Returns 1 if the NMT 'boot slave' process is currently running for the specified node, and 0 if not.
 
int co_nmt_chk_bootup (const co_nmt_t *nmt, co_unsigned8_t id)
 Checks if a boot-up message has been received from the specified node(s).
 
int co_nmt_cfg_req (co_nmt_t *nmt, co_unsigned8_t id, int timeout, co_nmt_cfg_con_t *con, void *data)
 Issues the NMT 'configuration request' for the specified node.
 
int co_nmt_cfg_res (co_nmt_t *nmt, co_unsigned8_t id, co_unsigned32_t ac)
 Indicates the result of the 'update configuration' step of an NMT 'request configuration' request for the specified node (see Fig.
 
int co_nmt_ng_req (co_nmt_t *nmt, co_unsigned8_t id, co_unsigned16_t gt, co_unsigned8_t ltf)
 Request the node guarding service for the specified node, even if it is not in the network list.
 
int co_nmt_cs_ind (co_nmt_t *nmt, co_unsigned8_t cs)
 Processes an NMT command from the master or the application.
 
void co_nmt_comm_err_ind (co_nmt_t *nmt)
 Indicates the occurrence of a communication error and invokes the specified error behavior (object 1029:01).
 
int co_nmt_node_err_ind (co_nmt_t *nmt, co_unsigned8_t id)
 Indicates the occurrence of an error event and triggers the error handling process (see Fig.
 
co_rpdo_tco_nmt_get_rpdo (const co_nmt_t *nmt, co_unsigned16_t n)
 Returns a pointer to a Receive-PDO service.
 
co_tpdo_tco_nmt_get_tpdo (const co_nmt_t *nmt, co_unsigned16_t n)
 Returns a pointer to a Transmit-PDO service.
 
co_ssdo_tco_nmt_get_ssdo (const co_nmt_t *nmt, co_unsigned8_t n)
 Returns a pointer to a Server-SDO service.
 
co_csdo_tco_nmt_get_csdo (const co_nmt_t *nmt, co_unsigned8_t n)
 Returns a pointer to a Client-SDO service.
 
co_sync_tco_nmt_get_sync (const co_nmt_t *nmt)
 Returns a pointer to the SYNC producer/consumer service.
 
co_time_tco_nmt_get_time (const co_nmt_t *nmt)
 Returns a pointer to the TIME producer/consumer service.
 
co_emcy_tco_nmt_get_emcy (const co_nmt_t *nmt)
 Returns a pointer to the EMCY producer/consumer service.
 
co_lss_tco_nmt_get_lss (const co_nmt_t *nmt)
 Returns a pointer to the LSS master/slave service.
 
void co_nmt_boot_con (co_nmt_t *nmt, co_unsigned8_t id, co_unsigned8_t st, char es)
 The CANopen NMT 'boot slave' confirmation function, invoked when the 'boot slave' process completes.
 
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 received.
 
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 completes (with success or failure).
 
void co_nmt_hb_ind (co_nmt_t *nmt, co_unsigned8_t id, int state, int reason, co_unsigned8_t st)
 The CANopen NMT heartbeat indication function, invoked when a heartbeat event occurs.
 

Variables

static co_nmt_state_t *const co_nmt_init_state = &(co_nmt_state_t){ .on_cs = &co_nmt_init_on_cs }
 The 'initializing' state.
 
static co_nmt_state_t *const co_nmt_reset_node_state = &(co_nmt_state_t){ .on_enter = &co_nmt_reset_node_on_enter }
 The NMT 'reset application' state.
 
static co_nmt_state_t *const co_nmt_reset_comm_state = &(co_nmt_state_t){ .on_enter = &co_nmt_reset_comm_on_enter, .on_cs = &co_nmt_reset_comm_on_cs }
 The NMT 'reset communication' state.
 
static co_nmt_state_t *const co_nmt_bootup_state = &(co_nmt_state_t){ .on_enter = &co_nmt_bootup_on_enter, .on_cs = &co_nmt_bootup_on_cs }
 The NMT 'boot-up' state.
 
static co_nmt_state_t *const co_nmt_preop_state = &(co_nmt_state_t){ .on_enter = &co_nmt_preop_on_enter, .on_cs = &co_nmt_preop_on_cs, .on_boot = &co_nmt_preop_on_boot }
 The NMT 'pre-operational' state.
 
static co_nmt_state_t *const co_nmt_start_state = &(co_nmt_state_t){ .on_enter = &co_nmt_start_on_enter, .on_cs = &co_nmt_start_on_cs, .on_boot = &co_nmt_default_on_boot }
 The NMT 'operational' state.
 
static co_nmt_state_t *const co_nmt_stop_state = &(co_nmt_state_t){ .on_enter = &co_nmt_stop_on_enter, .on_cs = &co_nmt_stop_on_cs, .on_boot = &co_nmt_default_on_boot }
 The NMT 'stopped' state.
 

Detailed Description

This file is part of the CANopen library; it contains the implementation of the network management (NMT) functions.

See also
lely/co/nmt.h
Author
J. S. Seldenthuis jseld.nosp@m.enth.nosp@m.uis@l.nosp@m.ely..nosp@m.com

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Definition in file nmt.c.

Function Documentation

◆ co_100c_dn_ind()

static co_unsigned32_t co_100c_dn_ind ( co_sub_t sub,
struct co_sdo_req req,
void *  data 
)
static

The download indication function for CANopen object 100C (Guard time).

See also
co_sub_dn_ind_t

Definition at line 2438 of file nmt.c.

◆ co_100d_dn_ind()

static co_unsigned32_t co_100d_dn_ind ( co_sub_t sub,
struct co_sdo_req req,
void *  data 
)
static

The download indication function for CANopen object 100D (Life time factor).

See also
co_sub_dn_ind_t

Definition at line 2472 of file nmt.c.

◆ co_1016_dn_ind()

static co_unsigned32_t co_1016_dn_ind ( co_sub_t sub,
struct co_sdo_req req,
void *  data 
)
static

The download indication function for CANopen object 1016 (Consumer heartbeat time).

See also
co_sub_dn_ind_t

Definition at line 2508 of file nmt.c.

◆ co_1017_dn_ind()

static co_unsigned32_t co_1017_dn_ind ( co_sub_t sub,
struct co_sdo_req req,
void *  data 
)
static

The download indication function for CANopen object 1017 (Producer heartbeat time).

See also
co_sub_dn_ind_t

Definition at line 2572 of file nmt.c.

◆ co_1f25_dn_ind()

static co_unsigned32_t co_1f25_dn_ind ( co_sub_t sub,
struct co_sdo_req req,
void *  data 
)
static

The download indication function for (all sub-objects of) CANopen object 1F25 (Configuration request).

See also
co_sub_dn_ind_t

Definition at line 2607 of file nmt.c.

◆ co_1f80_dn_ind()

static co_unsigned32_t co_1f80_dn_ind ( co_sub_t sub,
struct co_sdo_req req,
void *  data 
)
static

The download indication function for (all sub-objects of) CANopen object 1F80 (NMT startup).

See also
co_sub_dn_ind_t

Definition at line 2679 of file nmt.c.

◆ co_1f82_dn_ind()

static co_unsigned32_t co_1f82_dn_ind ( co_sub_t sub,
struct co_sdo_req req,
void *  data 
)
static

The download indication function for (all sub-objects of) CANopen object 1F80 (Request NMT).

See also
co_sub_dn_ind_t

Definition at line 2714 of file nmt.c.

◆ co_nmt_recv_000()

static int co_nmt_recv_000 ( const struct can_msg msg,
void *  data 
)
static

The CAN receive callback function for NMT messages.

See also
can_recv_func_t

Definition at line 2766 of file nmt.c.

◆ co_nmt_recv_700()

static int co_nmt_recv_700 ( const struct can_msg msg,
void *  data 
)
static

The CAN receive callback function for NMT error control (node guarding RTR) messages.

In case of an NMT master, this function also receives and processes the boot-up events (see Fig. 13 in CiA 302-2 version 4.1.0).

See also
can_recv_func_t

Definition at line 2791 of file nmt.c.

◆ co_nmt_ng_timer()

static int co_nmt_ng_timer ( const struct timespec tp,
void *  data 
)
static

The CAN timer callback function for node guarding.

See also
can_timer_func_t

Definition at line 2915 of file nmt.c.

◆ co_nmt_ec_timer()

static int co_nmt_ec_timer ( const struct timespec tp,
void *  data 
)
static

The CAN timer callback function for life guarding or heartbeat production.

See also
can_timer_func_t

Definition at line 2958 of file nmt.c.

◆ co_nmt_cs_timer()

static int co_nmt_cs_timer ( const struct timespec tp,
void *  data 
)
static

The CAN timer callback function for sending buffered NMT messages.

See also
can_timer_func_t

Definition at line 2982 of file nmt.c.

◆ co_nmt_st_ind()

static void co_nmt_st_ind ( co_nmt_t nmt,
co_unsigned8_t  id,
co_unsigned8_t  st 
)
static

The indication function for state change events.

Parameters
nmta pointer to an NMT master/slave service.
idthe node-ID (in the range [1..127]).
stthe state of the node.

Definition at line 3039 of file nmt.c.

◆ default_ng_ind()

static void default_ng_ind ( co_nmt_t nmt,
co_unsigned8_t  id,
int  state,
int  reason,
void *  data 
)
static

The default node guarding event handler.

See also
co_nmt_ng_ind_t

Definition at line 3065 of file nmt.c.

◆ default_lg_ind()

static void default_lg_ind ( co_nmt_t nmt,
int  state,
void *  data 
)
static

The default life guarding event handler.

See also
co_nmt_lg_ind_t

Definition at line 3075 of file nmt.c.

◆ default_hb_ind()

static void default_hb_ind ( co_nmt_t nmt,
co_unsigned8_t  id,
int  state,
int  reason,
void *  data 
)
static

The default heartbeat event handler.

See also
co_nmt_hb_ind_t

Definition at line 3085 of file nmt.c.

◆ default_st_ind()

static void default_st_ind ( co_nmt_t nmt,
co_unsigned8_t  id,
co_unsigned8_t  st,
void *  data 
)
static

The default state change event handler.

See also
co_nmt_st_ind_t

Definition at line 3094 of file nmt.c.

◆ co_nmt_dn_ind()

static void co_nmt_dn_ind ( const co_csdo_t sdo,
co_unsigned16_t  idx,
co_unsigned8_t  subidx,
size_t  size,
size_t  nbyte,
void *  data 
)
static

The SDO download progress indication function.

See also
co_csdo_ind_t

Definition at line 3104 of file nmt.c.

◆ co_nmt_up_ind()

static void co_nmt_up_ind ( const co_csdo_t sdo,
co_unsigned16_t  idx,
co_unsigned8_t  subidx,
size_t  size,
size_t  nbyte,
void *  data 
)
static

The SDO upload progress indication function.

See also
co_csdo_ind_t

Definition at line 3116 of file nmt.c.

◆ co_nmt_tpdo_event_ind()

static void co_nmt_tpdo_event_ind ( co_unsigned16_t  n,
void *  data 
)
static

The Transmit-PDO event indication function.

See also
co_dev_tpdo_event_ind_t

Definition at line 3132 of file nmt.c.

◆ co_nmt_sam_mpdo_event_ind()

static void co_nmt_sam_mpdo_event_ind ( co_unsigned16_t  n,
co_unsigned16_t  idx,
co_unsigned8_t  subidx,
void *  data 
)
static

The SAM-MPDO event indication function.

See also
co_dev_sam_mpdo_event_ind_t

Definition at line 3142 of file nmt.c.

◆ co_nmt_emit_cs()

static void co_nmt_emit_cs ( co_nmt_t nmt,
co_unsigned8_t  cs 
)
inlinestatic

Invokes the 'NMT command received' transition function of the current state of an NMT master/slave service.

Parameters
nmta pointer to an NMT master/slave service.
csthe NMT command specifier (one of CO_NMT_CS_START, CO_NMT_CS_STOP, CO_NMT_CS_ENTER_PREOP, CO_NMT_CS_RESET_NODE or CO_NMT_CS_RESET_COMM).

Definition at line 3171 of file nmt.c.

◆ co_nmt_emit_boot()

static void co_nmt_emit_boot ( co_nmt_t nmt,
co_unsigned8_t  id,
co_unsigned8_t  st,
char  es 
)
inlinestatic

Invokes the 'boot slave completed' transition function of the current state of an NMT master service.

Parameters
nmta pointer to an NMT master service.
idthe node-ID of the slave.
stthe state of the node (including the toggle bit).
esthe error status (in the range ['A'..'O'], or 0 on success).

Definition at line 3183 of file nmt.c.

◆ co_nmt_ec_init()

static void co_nmt_ec_init ( co_nmt_t nmt)
static

Initializes the error control services.

See also
co_nmt_ec_fini()

Definition at line 3636 of file nmt.c.

◆ co_nmt_ec_fini()

static void co_nmt_ec_fini ( co_nmt_t nmt)
static

Finalizes the error control services.

See also
co_nmt_ec_init()

Definition at line 3655 of file nmt.c.

◆ co_nmt_ec_update()

static void co_nmt_ec_update ( co_nmt_t nmt)
static

Updates and (de)activates the life guarding or heartbeat production services.

This function is invoked by the download indication functions when object 100C (Guard time), 100D (Life time factor) or 1017 (Producer heartbeat time) is updated.

Definition at line 3674 of file nmt.c.

◆ co_nmt_ec_send_res()

static int co_nmt_ec_send_res ( co_nmt_t nmt,
co_unsigned8_t  st 
)
static

Sends an NMT error control response message.

Parameters
nmta pointer to an NMT master/slave service.
stthe node state and toggle bit.
Returns
0 on success, or -1 on error.

Definition at line 3713 of file nmt.c.

◆ co_nmt_hb_init()

static void co_nmt_hb_init ( co_nmt_t nmt)
static

Initializes the heartbeat consumer services.

See also
co_nmt_hb_fini()

Definition at line 3726 of file nmt.c.

◆ co_nmt_hb_fini()

static void co_nmt_hb_fini ( co_nmt_t nmt)
static

Finalizes the heartbeat consumer services.

See also
co_nmt_hb_init()

Definition at line 3773 of file nmt.c.

◆ co_nmt_slaves_init()

static void co_nmt_slaves_init ( co_nmt_t nmt)
static

Initializes NMT slave management.

See also
co_nmt_slaves_fini()

Definition at line 3813 of file nmt.c.

◆ co_nmt_slaves_fini()

static void co_nmt_slaves_fini ( co_nmt_t nmt)
static

Finalizes NMT slave management.

See also
co_nmt_slaves_fini()

Definition at line 3835 of file nmt.c.

◆ co_nmt_slaves_boot()

static int co_nmt_slaves_boot ( co_nmt_t nmt)
static

Starts the NMT 'boot slave' processes.

Returns
1 if at least one mandatory slave is booting, 0 if there are no mandatory slaves, or -1 if an error occurred for a mandatory slave.

Definition at line 3882 of file nmt.c.

◆ co_nmt_chk_bootup_slaves()

static int co_nmt_chk_bootup_slaves ( const co_nmt_t nmt)
static

Checks if boot-up messages have been received from all mandatory slaves.

Returns
1 if all boot-up messages were received, 0 if not.

Definition at line 3912 of file nmt.c.

◆ co_dev_cfg_hb()

co_unsigned32_t co_dev_cfg_hb ( co_dev_t dev,
co_unsigned8_t  id,
co_unsigned16_t  ms 
)

Configures heartbeat consumption for the specified node by updating CANopen object 1016 (Consumer heartbeat time).

Parameters
deva pointer to a CANopen device.
idthe node-ID (in the range [1..127]).
msthe heartbeat time (in milliseconds). If ms is 0, the heartbeat consumer is disabled.
Returns
0 on success, or an SDO abort code on error.

Definition at line 744 of file nmt.c.

◆ co_nmt_create()

co_nmt_t * co_nmt_create ( can_net_t net,
co_dev_t dev 
)

Creates a new CANopen NMT master/slave service.

Parameters
neta pointer to a CAN network.
deva pointer to a CANopen device.
Returns
a pointer to a new NMT service, or NULL on error. In the latter case, the error number can be obtained with get_errc().
See also
co_nmt_destroy()

Definition at line 1233 of file nmt.c.

◆ co_nmt_destroy()

void co_nmt_destroy ( co_nmt_t nmt)

Destroys a CANopen NMT master/slave service.

See also
co_nmt_create()

Definition at line 1258 of file nmt.c.

◆ co_nmt_get_cs_ind()

void co_nmt_get_cs_ind ( const co_nmt_t nmt,
co_nmt_cs_ind_t **  pind,
void **  pdata 
)

Retrieves the indication function invoked when an NMT command is received.

Parameters
nmta pointer to an NMT master/slave service.
pindthe address at which to store a pointer to the indication function (can be NULL).
pdatathe address at which to store a pointer to user-specified data (can be NULL).
See also
co_nmt_set_cs_ind()

Definition at line 1283 of file nmt.c.

◆ co_nmt_set_cs_ind()

void co_nmt_set_cs_ind ( co_nmt_t nmt,
co_nmt_cs_ind_t ind,
void *  data 
)

Sets the indication function invoked when an NMT command is received.

Parameters
nmta pointer to an NMT master/slave service.
inda pointer to the function to be invoked.
dataa pointer to user-specified data (can be NULL). data is passed as the last parameter to ind.
See also
co_nmt_get_cs_ind()

Definition at line 1294 of file nmt.c.

◆ co_nmt_get_ng_ind()

void co_nmt_get_ng_ind ( const co_nmt_t nmt,
co_nmt_ng_ind_t **  pind,
void **  pdata 
)

Retrieves the indication function invoked when a node guarding event occurs.

Parameters
nmta pointer to an NMT master service.
pindthe address at which to store a pointer to the indication function (can be NULL).
pdatathe address at which to store a pointer to user-specified data (can be NULL).
See also
co_nmt_set_ng_ind()

Definition at line 1307 of file nmt.c.

◆ co_nmt_set_ng_ind()

void co_nmt_set_ng_ind ( co_nmt_t nmt,
co_nmt_ng_ind_t ind,
void *  data 
)

Sets the indication function invoked when a node guarding event occurs.

Parameters
nmta pointer to an NMT master service.
inda pointer to the function to be invoked. If ind is NULL, the default indication function will be used (which invokes co_nmt_on_ng()).
dataa pointer to user-specified data (can be NULL). data is passed as the last parameter to ind.
See also
co_nmt_get_ng_ind()

Definition at line 1318 of file nmt.c.

◆ co_nmt_on_ng()

void co_nmt_on_ng ( co_nmt_t nmt,
co_unsigned8_t  id,
int  state,
int  reason 
)

Implements the default behavior when a node guarding event occurs (see sections 7.2.8.2.2.1 and 7.2.8.3.2.1 in CiA 301 version 4.2.0).

This function invokes co_nmt_comm_err_ind() when an event occurs.

See also
co_nmt_ng_ind_t

Definition at line 1327 of file nmt.c.

◆ co_nmt_get_lg_ind()

void co_nmt_get_lg_ind ( const co_nmt_t nmt,
co_nmt_lg_ind_t **  pind,
void **  pdata 
)

Retrieves the indication function invoked when a life guarding event occurs.

Parameters
nmta pointer to an NMT slave service.
pindthe address at which to store a pointer to the indication function (can be NULL).
pdatathe address at which to store a pointer to user-specified data (can be NULL).
See also
co_nmt_set_lg_ind()

Definition at line 1342 of file nmt.c.

◆ co_nmt_set_lg_ind()

void co_nmt_set_lg_ind ( co_nmt_t nmt,
co_nmt_lg_ind_t ind,
void *  data 
)

Sets the indication function invoked when a life guarding event occurs.

Parameters
nmta pointer to an NMT slave service.
inda pointer to the function to be invoked. If ind is NULL, the default indication function will be used (which invokes co_nmt_on_lg()).
dataa pointer to user-specified data (can be NULL). data is passed as the last parameter to ind.
See also
co_nmt_get_lg_ind()

Definition at line 1353 of file nmt.c.

◆ co_nmt_on_lg()

void co_nmt_on_lg ( co_nmt_t nmt,
int  state 
)

Implements the default behavior when a life guarding event occurs (see section 7.2.8.2.2.2 in CiA 301 version 4.2.0).

This function invokes co_nmt_comm_err_ind() when an event occurs.

See also
co_nmt_lg_ind_t

Definition at line 1362 of file nmt.c.

◆ co_nmt_get_hb_ind()

void co_nmt_get_hb_ind ( const co_nmt_t nmt,
co_nmt_hb_ind_t **  pind,
void **  pdata 
)

Retrieves the indication function invoked when a heartbeat event occurs.

Parameters
nmta pointer to an NMT master/slave service.
pindthe address at which to store a pointer to the indication function (can be NULL).
pdatathe address at which to store a pointer to user-specified data (can be NULL).
See also
co_nmt_set_hb_ind()

Definition at line 1381 of file nmt.c.

◆ co_nmt_set_hb_ind()

void co_nmt_set_hb_ind ( co_nmt_t nmt,
co_nmt_hb_ind_t ind,
void *  data 
)

Sets the indication function invoked when a heartbeat event occurs.

Parameters
nmta pointer to an NMT master/slave service.
inda pointer to the function to be invoked. If ind is NULL, the default indication function will be used (which invokes co_nmt_on_hb()).
dataa pointer to user-specified data (can be NULL). data is passed as the last parameter to ind.
See also
co_nmt_get_hb_ind()

Definition at line 1392 of file nmt.c.

◆ co_nmt_on_hb()

void co_nmt_on_hb ( co_nmt_t nmt,
co_unsigned8_t  id,
int  state,
int  reason 
)

Implements the default behavior when a heartbeat event occurs (see sections 7.2.8.2.2.3 and 7.2.8.3.2.2 in CiA 301 version 4.2.0).

This function invokes co_nmt_node_err_ind() or co_nmt_comm_err_ind() when a timeout event occurs, depending on whether the NMT service is a master or not (see co_nmt_is_master()).

See also
co_nmt_hb_ind_t

Definition at line 1401 of file nmt.c.

◆ co_nmt_get_st_ind()

void co_nmt_get_st_ind ( const co_nmt_t nmt,
co_nmt_st_ind_t **  pind,
void **  pdata 
)

Retrieves the indication function invoked when a state change is detected.

Parameters
nmta pointer to an NMT master/slave service.
pindthe address at which to store a pointer to the indication function (can be NULL).
pdatathe address at which to store a pointer to user-specified data (can be NULL).
See also
co_nmt_set_st_ind()

Definition at line 1434 of file nmt.c.

◆ co_nmt_set_st_ind()

void co_nmt_set_st_ind ( co_nmt_t nmt,
co_nmt_st_ind_t ind,
void *  data 
)

Sets the indication function invoked when a state change is detected.

Parameters
nmta pointer to an NMT master/slave service.
inda pointer to the function to be invoked. If ind is NULL, the default indication function will be used (which invokes co_nmt_on_st()).
dataa pointer to user-specified data (can be NULL). data is passed as the last parameter to ind.
See also
co_nmt_get_st_ind()

Definition at line 1445 of file nmt.c.

◆ co_nmt_on_st()

void co_nmt_on_st ( co_nmt_t nmt,
co_unsigned8_t  id,
co_unsigned8_t  st 
)

Implements the default behavior when a state change is detected by the node guarding or heartbeat protocol.

In case of a boot-up event (and the NMT service is a master), this function invokes co_nmt_boot_req() to boot the slave (see Fig. 13 in CiA 302-2).

See also
co_nmt_st_ind_t

Definition at line 1454 of file nmt.c.

◆ co_nmt_get_lss_req()

void co_nmt_get_lss_req ( const co_nmt_t nmt,
co_nmt_lss_req_t **  pind,
void **  pdata 
)

Retrieves the request function invoked to perform LSS when booting an NMT master.

Parameters
nmta pointer to an NMT master service.
pindthe address at which to store a pointer to the indication function (can be NULL).
pdatathe address at which to store a pointer to user-specified data (can be NULL).
See also
co_nmt_set_lss_req()

Definition at line 1478 of file nmt.c.

◆ co_nmt_set_lss_req()

void co_nmt_set_lss_req ( co_nmt_t nmt,
co_nmt_lss_req_t ind,
void *  data 
)

Sets the request function invoked to perform LSS when booting an NMT master.

Setting this function means LSS is required (see Fig. 1 in CiA 302-2 version 4.1.0).

Parameters
nmta pointer to an NMT master service.
inda pointer to the function to be invoked.
dataa pointer to user-specified data (can be NULL). data is passed as the last parameter to ind.
See also
co_nmt_get_lss_req()

Definition at line 1489 of file nmt.c.

◆ co_nmt_get_boot_ind()

void co_nmt_get_boot_ind ( const co_nmt_t nmt,
co_nmt_boot_ind_t **  pind,
void **  pdata 
)

Retrieves the indication function invoked when a CANopen NMT 'boot slave' process completes.

Parameters
nmta pointer to an NMT master service.
pindthe address at which to store a pointer to the indication function (can be NULL).
pdatathe address at which to store a pointer to user-specified data (can be NULL).
See also
co_nmt_set_boot_ind()

Definition at line 1502 of file nmt.c.

◆ co_nmt_set_boot_ind()

void co_nmt_set_boot_ind ( co_nmt_t nmt,
co_nmt_boot_ind_t ind,
void *  data 
)

Sets the indication function invoked when a CANopen NMT 'boot slave' process completes.

Parameters
nmta pointer to an NMT master service.
inda pointer to the function to be invoked.
dataa pointer to user-specified data (can be NULL). data is passed as the last parameter to ind.
See also
co_nmt_get_boot_ind()

Definition at line 1513 of file nmt.c.

◆ co_nmt_get_cfg_ind()

void co_nmt_get_cfg_ind ( const co_nmt_t nmt,
co_nmt_cfg_ind_t **  pind,
void **  pdata 
)

Retrieves the indication function invoked when a CANopen NMT 'configuration request' is received.

Parameters
nmta pointer to an NMT master service.
pindthe address at which to store a pointer to the indication function (can be NULL).
pdatathe address at which to store a pointer to user-specified data (can be NULL).
See also
co_nmt_set_cfg_ind()

Definition at line 1526 of file nmt.c.

◆ co_nmt_set_cfg_ind()

void co_nmt_set_cfg_ind ( co_nmt_t nmt,
co_nmt_cfg_ind_t ind,
void *  data 
)

Sets the indication function invoked when a CANopen NMT 'configuration request' process is received.

Parameters
nmta pointer to an NMT master service.
inda pointer to the function to be invoked.
dataa pointer to user-specified data (can be NULL). data is passed as the last parameter to ind.
See also
co_nmt_get_cfg_ind()

Definition at line 1537 of file nmt.c.

◆ co_nmt_get_dn_ind()

void co_nmt_get_dn_ind ( const co_nmt_t nmt,
co_nmt_sdo_ind_t **  pind,
void **  pdata 
)

Retrieves the indication function used to notify the user of the progress of the current SDO download request during the CANopen NMT 'boot slave' process.

Parameters
nmta pointer to an NMT master service.
pindthe address at which to store a pointer to the indication function (can be NULL).
pdatathe address at which to store a pointer to user-specified data (can be NULL).
See also
co_nmt_set_dn_ind()

Definition at line 1548 of file nmt.c.

◆ co_nmt_set_dn_ind()

void co_nmt_set_dn_ind ( co_nmt_t nmt,
co_nmt_sdo_ind_t ind,
void *  data 
)

Sets the indication function used to notify the user of the progress of the current SDO download request during the CANopen NMT 'boot slave' process.

Parameters
nmta pointer to an NMT master service.
inda pointer to the function to be invoked.
dataa pointer to user-specified data (can be NULL). data is passed as the last parameter to ind.
See also
co_nmt_get_dn_ind()

Definition at line 1559 of file nmt.c.

◆ co_nmt_get_up_ind()

void co_nmt_get_up_ind ( const co_nmt_t nmt,
co_nmt_sdo_ind_t **  pind,
void **  pdata 
)

Retrieves the indication function used to notify the user of the progress of the current SDO upload request during the CANopen NMT 'boot slave' process.

Parameters
nmta pointer to an NMT master service.
pindthe address at which to store a pointer to the indication function (can be NULL).
pdatathe address at which to store a pointer to user-specified data (can be NULL).
See also
co_nmt_set_up_ind()

Definition at line 1568 of file nmt.c.

◆ co_nmt_set_up_ind()

void co_nmt_set_up_ind ( co_nmt_t nmt,
co_nmt_sdo_ind_t ind,
void *  data 
)

Sets the indication function used to notify the user of the progress of the current SDO upload request during the CANopen NMT 'boot slave' process.

Parameters
nmta pointer to an NMT master service.
inda pointer to the function to be invoked.
dataa pointer to user-specified data (can be NULL). data is passed as the last parameter to ind.
See also
co_nmt_get_up_ind()

Definition at line 1579 of file nmt.c.

◆ co_nmt_get_sync_ind()

void co_nmt_get_sync_ind ( const co_nmt_t nmt,
co_nmt_sync_ind_t **  pind,
void **  pdata 
)

Retrieves the indication function invoked by co_nmt_on_sync() after all PDOs have been transmitted/processed.

Parameters
nmta pointer to an NMT master/slave service.
pindthe address at which to store a pointer to the indication function (can be NULL).
pdatathe address at which to store a pointer to user-specified data (can be NULL).
See also
co_nmt_set_sync_ind()

Definition at line 1590 of file nmt.c.

◆ co_nmt_set_sync_ind()

void co_nmt_set_sync_ind ( co_nmt_t nmt,
co_nmt_sync_ind_t ind,
void *  data 
)

Sets the indication function invoked by co_nmt_on_sync() after all PDOs have been transmitted/processed.

Parameters
nmta pointer to an NMT master/slave service.
inda pointer to the function to be invoked.
dataa pointer to user-specified data (can be NULL). data is passed as the last parameter to ind.
See also
co_nmt_get_sync_ind()

Definition at line 1601 of file nmt.c.

◆ co_nmt_on_sync()

void co_nmt_on_sync ( co_nmt_t nmt,
co_unsigned8_t  cnt 
)

Implements the default behavior after a SYNC object is received or transmitted.

First all synchronous Transmit-PDOs are sent with co_tpdo_sync(). Then all synchronous Receive-PDOs are actuated with co_rpdo_sync(). Finally the user-defined callback function set with co_nmt_set_sync_ind() is invoked.

See also
co_sync_ind_t, co_nmt_sync_ind_t

Definition at line 1610 of file nmt.c.

◆ co_nmt_on_err()

void co_nmt_on_err ( co_nmt_t nmt,
co_unsigned16_t  eec,
co_unsigned8_t  er,
const co_unsigned8_t  msef[5] 
)

Implements the default error handling behavior by generating an EMCY message with co_emcy_push() and invoking co_nmt_comm_err_ind() in case of a communication error (emergency error code 0x81xx).

See also
co_rpdo_err_t, co_sync_err_t

Definition at line 1636 of file nmt.c.

◆ co_nmt_on_tpdo_event()

void co_nmt_on_tpdo_event ( co_nmt_t nmt,
co_unsigned16_t  n 
)

Implements the default behavior when an event is indicated for an event-driven (asynchronous) Transmit-PDO by triggering the transmission of the PDO with co_tpdo_event().

The transmission of PDOs can be postponed with co_nmt_on_tpdo_event_lock().

Parameters
nmta pointer to an NMT master/slave service.
nthe PDO number (in the range [1..512]). If n is 0, the transmission of all PDOs is triggered.
See also
co_dev_tpdo_event_ind_t

Definition at line 1659 of file nmt.c.

◆ co_nmt_on_tpdo_event_lock()

void co_nmt_on_tpdo_event_lock ( co_nmt_t nmt)

Postpones the transmission of PDOs triggered by co_nmt_on_tpdo_event() until a matching call to co_nmt_on_tpdo_event_unlock().

This function can be invoked multiple times. PDO transmission will resume after an equal number of calls to co_nmt_on_tpdo_event_unlock().

Definition at line 1690 of file nmt.c.

◆ co_nmt_on_sam_mpdo_event()

void co_nmt_on_sam_mpdo_event ( co_nmt_t nmt,
co_unsigned16_t  n,
co_unsigned16_t  idx,
co_unsigned8_t  subidx 
)

Implements the default behavior when an event is indicated for a source address mode multiplex PDO by triggering the transmission of the PDO with co_sam_mpdo_event().

Parameters
nmta pointer to an NMT master/slave service.
nthe PDO number (in the range [1..512]).
idxthe object index.
subidxthe object sub-index.
See also
co_dev_sam_mpdo_event_ind_t

Definition at line 1729 of file nmt.c.

◆ co_nmt_get_id()

co_unsigned8_t co_nmt_get_id ( const co_nmt_t nmt)

Returns the pending node-ID.

See also
co_nmt_set_id()

Definition at line 1743 of file nmt.c.

◆ co_nmt_set_id()

int co_nmt_set_id ( co_nmt_t nmt,
co_unsigned8_t  id 
)

Sets the pending node-ID.

The node-ID of the device will be updated once the NMT 'reset communication command' is received. This is used for the LSS configure node-ID protocol.

Parameters
nmta pointer to an NMT master/slave service.
idthe node-ID of the device (in the range [1..127, 255]).
Returns
0 on success, or -1 on error. In the latter case, the error number can be obtained with get_errc().
See also
co_nmt_get_id(), co_dev_set_id()

Definition at line 1751 of file nmt.c.

◆ co_nmt_get_timeout()

int co_nmt_get_timeout ( const co_nmt_t nmt)

Returns the default SDO timeout used during the NMT 'boot slave' and 'check configuration' processes.

See also
co_nmt_set_timeout()

Definition at line 1790 of file nmt.c.

◆ co_nmt_set_timeout()

void co_nmt_set_timeout ( co_nmt_t nmt,
int  timeout 
)

Sets the default SDO timeout used during the NMT 'boot slave' and 'check configuration' processes.

Parameters
nmta pointer to an NMT master service.
timeoutthe SDO timeout (in milliseconds). See co_csdo_set_timeout().
See also
co_nmt_get_timeout()

Definition at line 1798 of file nmt.c.

◆ co_nmt_cs_req()

int co_nmt_cs_req ( co_nmt_t nmt,
co_unsigned8_t  cs,
co_unsigned8_t  id 
)

Submits an NMT request to a slave.

If id equals the node-ID of the master, this is equivalent to co_nmt_cs_ind(nmt, cs).

Parameters
nmta pointer to an NMT master service.
csthe NMT command specifier (one of CO_NMT_CS_START, CO_NMT_CS_STOP, CO_NMT_CS_ENTER_PREOP, CO_NMT_CS_RESET_NODE or CO_NMT_CS_RESET_COMM).
idthe node-ID (0 for all nodes, [1..127] for a specific slave).
Returns
0 on success, or -1 on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 1806 of file nmt.c.

◆ co_nmt_lss_con()

int co_nmt_lss_con ( co_nmt_t nmt)

Confirms the completion of the process when booting an NMT master.

The function specified to co_nmt_set_lss_req() MUST cause this function to be invoked.

Returns
0 on success, or -1 on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 1853 of file nmt.c.

◆ co_nmt_boot_req()

int co_nmt_boot_req ( co_nmt_t nmt,
co_unsigned8_t  id,
int  timeout 
)

Requests the NMT 'boot slave' process for the specified node.

The function specified to co_nmt_set_boot_ind() is invoked on completion.

Parameters
nmta pointer to an NMT master service.
idthe node-ID (in the range [1..127]).
timeoutthe SDO timeout (in milliseconds). See co_csdo_set_timeout().
Returns
0 on success, or -1 on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 1871 of file nmt.c.

◆ co_nmt_chk_bootup()

int co_nmt_chk_bootup ( const co_nmt_t nmt,
co_unsigned8_t  id 
)

Checks if a boot-up message has been received from the specified node(s).

Parameters
nmta pointer to an NMT master service.
idthe node-ID (0 for all mandatory nodes, [1..127] for a specific slave).
Returns
1 if a boot-up message was received, 0 if not, or -1 on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 1946 of file nmt.c.

◆ co_nmt_cfg_req()

int co_nmt_cfg_req ( co_nmt_t nmt,
co_unsigned8_t  id,
int  timeout,
co_nmt_cfg_con_t con,
void *  data 
)

Issues the NMT 'configuration request' for the specified node.

The function specified to co_nmt_set_cfg_ind() is invoked to complete the request.

Parameters
nmta pointer to an NMT master service.
idthe node-ID (0 for all nodes, [1..127] for a specific slave).
timeoutthe SDO timeout (in milliseconds). See co_csdo_set_timeout().
cona pointer to the confirmation function (can be NULL).
dataa pointer to user-specified data (can be NULL). data is passed as the last parameter to con.
Returns
0 on success, or -1 on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 1979 of file nmt.c.

◆ co_nmt_cfg_res()

int co_nmt_cfg_res ( co_nmt_t nmt,
co_unsigned8_t  id,
co_unsigned32_t  ac 
)

Indicates the result of the 'update configuration' step of an NMT 'request configuration' request for the specified node (see Fig.

8 in CiA 302-2 version 4.1.0). This function MUST be called upon completion.

Parameters
nmta pointer to an NMT master service.
idthe node-ID (in the range [1..127]).
acthe SDO abort code (0 on success).
Returns
0 on success, or -1 on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 2040 of file nmt.c.

◆ co_nmt_ng_req()

int co_nmt_ng_req ( co_nmt_t nmt,
co_unsigned8_t  id,
co_unsigned16_t  gt,
co_unsigned8_t  ltf 
)

Request the node guarding service for the specified node, even if it is not in the network list.

If the guard time or lifetime factor is 0, node guarding is disabled.

Parameters
nmta pointer to an NMT master service.
idthe node-ID (in the range [1..127]).
gtthe guard time (in milliseconds).
ltfthe lifetime factor.
Returns
0 on success, or -1 on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 2061 of file nmt.c.

◆ co_nmt_cs_ind()

int co_nmt_cs_ind ( co_nmt_t nmt,
co_unsigned8_t  cs 
)

Processes an NMT command from the master or the application.

Note that this function MAY trigger a reset of one or more CANopen services and invalidate previously obtained results of co_nmt_get_rpdo(), co_nmt_get_tpdo(), co_nmt_get_ssdo(), co_nmt_get_csdo(), co_nmt_get_sync(), co_nmt_get_time() and/or co_nmt_get_emcy().

This function MUST NOT be invoked during an NMT state transition. It is therefore unsafe to call co_nmt_cs_ind() (or co_nmt_cs_req() with the node-ID of the master) from the co_nmt_cs_ind_t and co_nmt_st_ind_t indication functions.

Parameters
nmta pointer to an NMT master/slave service.
csthe NMT command specifier (one of CO_NMT_CS_START, CO_NMT_CS_STOP, CO_NMT_CS_ENTER_PREOP, CO_NMT_CS_RESET_NODE or CO_NMT_CS_RESET_COMM).
Returns
0 on success, or -1 on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 2098 of file nmt.c.

◆ co_nmt_comm_err_ind()

void co_nmt_comm_err_ind ( co_nmt_t nmt)

Indicates the occurrence of a communication error and invokes the specified error behavior (object 1029:01).

Note that this function MAY invoke co_nmt_cs_ind().

Definition at line 2116 of file nmt.c.

◆ co_nmt_node_err_ind()

int co_nmt_node_err_ind ( co_nmt_t nmt,
co_unsigned8_t  id 
)

Indicates the occurrence of an error event and triggers the error handling process (see Fig.

12 in CiA 302-2 version 4.1.0). Note that this function MAY invoke co_nmt_cs_ind().

Parameters
nmta pointer to an NMT master service.
idthe node-ID (in the range [1..127]).
Returns
0 on success, or -1 on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 2132 of file nmt.c.

◆ co_nmt_get_rpdo()

co_rpdo_t * co_nmt_get_rpdo ( const co_nmt_t nmt,
co_unsigned16_t  n 
)

Returns a pointer to a Receive-PDO service.

Parameters
nmta pointer to an NMT master/slave service.
nthe PDO number (in the range [1..512]).

Definition at line 2175 of file nmt.c.

◆ co_nmt_get_tpdo()

co_tpdo_t * co_nmt_get_tpdo ( const co_nmt_t nmt,
co_unsigned16_t  n 
)

Returns a pointer to a Transmit-PDO service.

Parameters
nmta pointer to an NMT master/slave service.
nthe PDO number (in the range [1..512]).

Definition at line 2193 of file nmt.c.

◆ co_nmt_get_ssdo()

co_ssdo_t * co_nmt_get_ssdo ( const co_nmt_t nmt,
co_unsigned8_t  n 
)

Returns a pointer to a Server-SDO service.

Parameters
nmta pointer to an NMT master/slave service.
nthe SDO number (in the range [1..128]).

Definition at line 2211 of file nmt.c.

◆ co_nmt_get_csdo()

co_csdo_t * co_nmt_get_csdo ( const co_nmt_t nmt,
co_unsigned8_t  n 
)

Returns a pointer to a Client-SDO service.

Parameters
nmta pointer to an NMT master/slave service.
nthe SDO number (in the range [1..128]).

Definition at line 2222 of file nmt.c.

◆ co_nmt_boot_con()

void co_nmt_boot_con ( co_nmt_t nmt,
co_unsigned8_t  id,
co_unsigned8_t  st,
char  es 
)

The CANopen NMT 'boot slave' confirmation function, invoked when the 'boot slave' process completes.

Parameters
nmta pointer to an NMT master service.
idthe node-ID of the slave (in the range [1..127]).
stthe state of the node (including the toggle bit).
esthe error status (in the range ['A'..'O'], or 0 on success).

Definition at line 2297 of file nmt.c.

◆ co_nmt_cfg_ind()

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 received.

Parameters
nmta pointer to an NMT master service.
idthe node-ID of the slave (in the range [1..127]).
sdoa pointer to a Client-SDO connected to the slave.

Definition at line 2375 of file nmt.c.

◆ co_nmt_cfg_con()

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 completes (with success or failure).

Parameters
nmta pointer to an NMT master service.
idthe node-ID of the slave (in the range [1..127]).
acthe SDO abort code (0 on success).

Definition at line 2389 of file nmt.c.

◆ co_nmt_hb_ind()

void co_nmt_hb_ind ( co_nmt_t nmt,
co_unsigned8_t  id,
int  state,
int  reason,
co_unsigned8_t  st 
)

The CANopen NMT heartbeat indication function, invoked when a heartbeat event occurs.

Parameters
nmta pointer to an NMT master/slave service.
idthe node-ID (in the range [1..127]).
stateindicates whether the event occurred (CO_NMT_EC_OCCURRED) or was resolved (CO_NMT_EC_RESOLVED). Note that heartbeat state change events only occur and are never resolved.
reasonindicates whether the event occurred because of a timeout (CO_NMT_EC_TIMEOUT) or a state change (CO_NMT_EC_STATE).
stthe state of the node (if reason is CO_NMT_EC_STATE).

Definition at line 2420 of file nmt.c.