26 #ifndef LELY_NO_CO_LSS
53 #ifndef LELY_NO_CO_MASTER
63 #ifndef LELY_NO_CO_MASTER
73 #ifndef LELY_NO_CO_MASTER
106 #ifndef LELY_NO_CO_MASTER
133 #ifndef LELY_NO_CO_MASTER
135 static int co_lss_timer(
const struct timespec *tp,
void *data);
153 #ifndef LELY_NO_CO_MASTER
178 #ifndef LELY_NO_CO_MASTER
193 #define LELY_CO_DEFINE_STATE(name, ...) \
194 static co_lss_state_t *const name = &(co_lss_state_t){ __VA_ARGS__ };
238 #ifndef LELY_NO_CO_MASTER
246 co_lss_t *lss,
const struct timespec *tp);
275 co_lss_t *lss, const struct timespec *tp);
291 co_lss_t *lss, const struct timespec *tp);
311 co_lss_t *lss, const struct timespec *tp);
331 co_lss_t *lss, const struct timespec *tp);
350 co_lss_t *lss, const struct timespec *tp);
372 co_lss_t *lss, const struct timespec *tp);
392 co_lss_t *lss, const struct timespec *tp);
411 co_lss_t *lss, const struct timespec *tp);
436 co_lss_t *lss, const struct timespec *tp);
470 co_lss_t *lss, const struct timespec *tp);
489 co_lss_t *lss, const struct timespec *tp);
508 co_lss_t *lss, const struct timespec *tp);
534 #undef LELY_CO_DEFINE_STATE
547 co_lss_t *lss, co_unsigned8_t cs, co_unsigned32_t
id);
558 co_lss_t *lss, co_unsigned8_t cs, co_unsigned32_t
id);
581 co_unsigned8_t bitchk, co_unsigned8_t lsssub,
582 co_unsigned8_t lssnext);
594 #ifndef LELY_NO_CO_MASTER
637 co_unsigned8_t bitchk, co_unsigned8_t lsssub,
638 co_unsigned8_t lssnext);
656 static inline co_unsigned32_t *
co_id_sub(
struct co_id *
id, co_unsigned8_t sub);
663 void *ptr = malloc(
sizeof(
struct __co_lss));
670 __co_lss_free(
void *ptr)
689 #ifndef LELY_NO_CO_MASTER
698 goto error_create_recv;
702 #ifndef LELY_NO_CO_MASTER
708 goto error_create_timer;
715 #ifndef LELY_NO_CO_MASTER
732 #ifndef LELY_NO_CO_MASTER
748 #ifndef LELY_NO_CO_MASTER
763 #ifndef LELY_NO_CO_MASTER
772 trace(
"creating LSS");
779 goto error_alloc_lss;
782 if (!__co_lss_init(lss, nmt)) {
800 trace(
"destroying LSS");
855 #ifndef LELY_NO_CO_MASTER
886 if (lss->
timeout && timeout <= 0)
897 #ifdef LELY_NO_CO_MASTER
908 #ifndef LELY_NO_CO_MASTER
939 trace(
"LSS: switch state global");
959 trace(
"LSS: switch state selective");
984 trace(
"LSS: configure node-ID");
1017 case 1000: req.
data[2] = 0;
break;
1018 case 800: req.
data[2] = 1;
break;
1019 case 500: req.
data[2] = 2;
break;
1020 case 250: req.
data[2] = 3;
break;
1021 case 125: req.
data[2] = 4;
break;
1022 case 50: req.
data[2] = 6;
break;
1023 case 20: req.
data[2] = 7;
break;
1024 case 10: req.
data[2] = 8;
break;
1025 case 0: req.
data[2] = 9;
break;
1029 trace(
"LSS: configure bit timing parameters");
1056 trace(
"LSS: activate bit timing parameters");
1074 trace(
"LSS: store configuration");
1099 trace(
"LSS: inquire identity vendor-ID");
1124 trace(
"LSS: inquire identity product-code");
1149 trace(
"LSS: inquire identity revision-number");
1175 trace(
"LSS: inquire identity serial number");
1201 trace(
"LSS: inquire node-ID");
1238 trace(
"LSS: identify remote slave");
1260 trace(
"LSS: identify non-configured remote slave");
1298 trace(
"LSS: Slowscan");
1323 trace(
"LSS: Fastscan");
1373 #ifndef LELY_NO_CO_MASTER
1413 #ifndef LELY_NO_CO_MASTER
1428 #ifdef LELY_NO_CO_MASTER
1465 co_unsigned8_t cs = msg->
data[0];
1471 switch (msg->
data[1]) {
1474 trace(
"LSS: switching to waiting state");
1478 trace(
"LSS: switching to configuration state");
1527 co_unsigned8_t cs = msg->
data[0];
1533 switch (msg->
data[1]) {
1536 trace(
"LSS: switching to waiting state");
1540 trace(
"LSS: switching to configuration state");
1549 trace(
"LSS: configuring node-ID");
1564 trace(
"LSS: configuring bit timing parameters");
1570 switch (msg->
data[2]) {
1607 default: req.
data[1] = 1;
break;
1619 trace(
"LSS: activating bit timing parameters");
1625 trace(
"LSS: storing configuration");
1658 trace(
"LSS: sending vendor-ID");
1660 stle_u32(req.
data + 1, co_obj_get_val_u32(obj_1018, 0x01));
1665 trace(
"LSS: sending product-code");
1667 stle_u32(req.
data + 1, co_obj_get_val_u32(obj_1018, 0x02));
1672 trace(
"LSS: sending revision-number");
1674 stle_u32(req.
data + 1, co_obj_get_val_u32(obj_1018, 0x03));
1679 trace(
"LSS: sending serial-number");
1681 stle_u32(req.
data + 1, co_obj_get_val_u32(obj_1018, 0x04));
1686 trace(
"LSS: sending node-ID");
1705 #ifndef LELY_NO_CO_MASTER
1713 if (msg->
len < 1 || msg->
data[0] != lss->
cs)
1773 if (lss->
cs == 0x44)
1786 if (msg->
len < 3 || msg->
data[0] != lss->
cs)
1822 if (msg->
len < 5 || msg->
data[0] != lss->
cs)
1857 if (msg->
len < 2 || msg->
data[0] != lss->
cs)
1910 if (lss->
cs == 0x4f)
1933 if (msg->
len < 1 || msg->
data[0] != lss->
cs)
1946 if (lss->
cs == 0x4f) {
1974 id->serial_nr += (lss->
hi.
serial_nr -
id->serial_nr) / 2;
1988 if (msg->
len < 1 || msg->
data[0] != lss->
cs)
2001 if (lss->
cs == 0x4f)
2002 return co_lss_slowscan_scan_on_res(lss, 1);
2016 co_lss_slowscan_scan_on_res(
co_lss_t *lss,
int timeout)
2063 return co_lss_slowscan_scan_on_res(lss, 0);
2082 if (msg->
len < 1 || msg->
data[0] != lss->
cs)
2095 if (lss->
cs == 0x44) {
2138 if (msg->
len < 1 || msg->
data[0] != lss->
cs)
2167 for (; lss->
bitchk && (*pmask & (UINT32_C(1) << lss->
bitchk));
2171 co_unsigned8_t lssnext = lss->
lsssub;
2174 if (!lss->
bitchk && (*pmask & 1)) {
2203 if (msg->
len < 1 || msg->
data[0] != lss->
cs)
2216 return co_lss_fastscan_scan_on_res(lss, 1);
2220 co_lss_fastscan_scan_on_res(
co_lss_t *lss,
int timeout)
2223 assert(lss->
bitchk <= 31);
2231 if (!lss->
bitchk && (*pmask & 1)) {
2244 *pid |= UINT32_C(1) << lss->
bitchk;
2245 *pmask |= UINT32_C(1) << lss->
bitchk;
2269 return co_lss_fastscan_scan_on_res(lss, 0);
2305 if (
id != co_obj_get_val_u32(obj_1018, 0x01)) {
2312 if (cs != lss->
cs ||
id != co_obj_get_val_u32(obj_1018, 0x02)) {
2319 if (cs != lss->
cs ||
id != co_obj_get_val_u32(obj_1018, 0x03)) {
2326 if (cs != lss->
cs ||
id != co_obj_get_val_u32(obj_1018, 0x04)) {
2335 trace(
"LSS: switching to configuration state");
2337 default:
return NULL;
2352 if (
id != co_obj_get_val_u32(obj_1018, 0x01)) {
2360 if (cs != lss->
cs ||
id != co_obj_get_val_u32(obj_1018, 0x02)) {
2368 if (cs != lss->
cs ||
id > co_obj_get_val_u32(obj_1018, 0x03)) {
2376 if (cs != lss->
cs ||
id < co_obj_get_val_u32(obj_1018, 0x03)) {
2384 if (cs != lss->
cs ||
id > co_obj_get_val_u32(obj_1018, 0x04)) {
2392 if (cs != lss->
cs ||
id < co_obj_get_val_u32(obj_1018, 0x04)) {
2428 co_unsigned8_t lsssub, co_unsigned8_t lssnext)
2436 if (bitchk > 31 && bitchk != 0x80)
2439 if (bitchk == 0x80) {
2445 co_unsigned32_t pid[] = { co_obj_get_val_u32(obj_1018, 0x01),
2446 co_obj_get_val_u32(obj_1018, 0x02),
2447 co_obj_get_val_u32(obj_1018, 0x03),
2448 co_obj_get_val_u32(obj_1018, 0x04) };
2449 if ((
id ^ pid[lss->
lsspos]) & ~((UINT32_C(1) << bitchk) - 1))
2453 if (!bitchk && lss->
lsspos < lsssub)
2476 #ifndef LELY_NO_CO_MASTER
2485 switch (lss->
next) {
2507 if (++lss->
next < 4) {
2510 struct timespec start = { 0, 0 };
2535 switch (lss->
next) {
2565 if (++lss->
next < 6) {
2568 struct timespec start = { 0, 0 };
2582 co_unsigned8_t bitchk, co_unsigned8_t lsssub,
2583 co_unsigned8_t lssnext)
2589 req.
data[5] = bitchk;
2590 req.
data[6] = lsssub;
2591 req.
data[7] = lssnext;
2610 static inline co_unsigned32_t *
2617 case 0:
return &
id->vendor_id;
2618 case 1:
return &
id->product_code;
2619 case 2:
return &
id->revision;
2620 case 3:
return &
id->serial_nr;
2621 default:
return NULL;
#define CAN_MAX_LEN
The maximum number of bytes in the payload of a CAN format frame.
#define CAN_MSG_INIT
The static initializer for can_msg.
co_unsigned8_t co_dev_get_id(const co_dev_t *dev)
Returns the node-ID of a CANopen device.
#define CO_BAUD_20
A bit rate of 20 kbit/s.
#define CO_BAUD_AUTO
Automatic bit rate detection.
#define CO_BAUD_125
A bit rate of 125 kbit/s.
#define CO_NUM_NODES
The maximum number of nodes in a CANopen network.
co_unsigned16_t co_dev_get_rate(const co_dev_t *dev)
Returns the (pending) baudrate of a CANopen device (in kbit/s).
#define CO_ID_INIT
The static initializer for struct co_id.
#define CO_BAUD_10
A bit rate of 10 kbit/s.
#define CO_BAUD_250
A bit rate of 250 kbit/s.
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_dev_set_rate(co_dev_t *dev, co_unsigned16_t rate)
Sets the (pending) baudrate of a CANopen device.
#define CO_BAUD_1000
A bit rate of 1 Mbit/s.
#define CO_BAUD_500
A bit rate of 500 kbit/s.
#define CO_BAUD_800
A bit rate of 800 kbit/s.
unsigned int co_dev_get_baud(const co_dev_t *dev)
Returns the supported bit rates of a CANopen device (any combination of CO_BAUD_1000,...
#define CO_BAUD_50
A bit rate of 50 kbit/s.
This header file is part of the utilities library; it contains the byte order (endianness) function d...
uint_least32_t ldle_u32(const uint_least8_t src[4])
Loads a 32-bit unsigned integer in little-endian byte order.
uint_least16_t ldle_u16(const uint_least8_t src[2])
Loads a 16-bit unsigned integer in little-endian byte order.
void stle_u16(uint_least8_t dst[2], uint_least16_t x)
Stores a 16-bit unsigned integer in little-endian byte order.
void stle_u32(uint_least8_t dst[4], uint_least32_t x)
Stores a 32-bit unsigned integer in little-endian byte order.
This header file is part of the utilities library; it contains the native and platform-independent er...
@ ERRNUM_PERM
Operation not permitted.
@ ERRNUM_INVAL
Invalid argument.
int get_errc(void)
Returns the last (thread-specific) native error code set by a system call or library function.
void set_errc(int errc)
Sets the current (thread-specific) native error code to errc.
int errno2c(int errnum)
Transforms a standard C error number to a native error code.
void set_errnum(errnum_t errnum)
Sets the current (thread-specific) platform-independent error number to errnum.
This header file is part of the CANopen library; it contains the object dictionary declarations.
#define MAX(a, b)
Returns the maximum of a and b.
static co_lss_state_t * co_lss_cs_on_recv(co_lss_t *lss, const struct can_msg *msg)
The 'CAN frame received' transition function of the command received state.
static co_lss_state_t *const co_lss_slowscan_wait_state
The Slowscan waiting state.
static co_lss_state_t * co_lss_slowscan_wait_on_recv(co_lss_t *lss, const struct can_msg *msg)
The 'CAN frame received' transition function of the Slowscan waiting state.
int co_lss_get_vendor_id_req(co_lss_t *lss, co_lss_lssid_ind_t *ind, void *data)
Requests the 'inquire identity vendor-ID' service.
void co_lss_destroy(co_lss_t *lss)
Destroys a CANopen LSS master/slave service.
static co_lss_state_t * co_lss_switch_sel_on_time(co_lss_t *lss, const struct timespec *tp)
The 'timeout' transition function of the 'switch state selective' state.
static void co_lss_cs_fini_on_leave(co_lss_t *lss)
The exit function of the command received finalization state.
static co_lss_state_t * co_lss_slowscan_init_on_time(co_lss_t *lss, const struct timespec *tp)
The 'timeout' transition function of the Slowscan initialization state.
static int co_lss_send_fastscan_req(const co_lss_t *lss, co_unsigned32_t id, co_unsigned8_t bitchk, co_unsigned8_t lsssub, co_unsigned8_t lssnext)
Sends an LSS Fastscan request (see Fig.
static co_lss_state_t * co_lss_slowscan_scan_on_time(co_lss_t *lss, const struct timespec *tp)
The 'timeout' transition function of the Slowscan scanning state.
static co_lss_state_t * co_lss_slowscan_switch_on_enter(co_lss_t *lss)
The entry function of the Slowscan 'switch state selective' state.
static co_lss_state_t * co_lss_nid_on_time(co_lss_t *lss, const struct timespec *tp)
The 'timeout' transition function of the inquire node-ID state.
static void co_lss_fastscan_fini_on_leave(co_lss_t *lss)
The exit function of the Fastscan finalization state.
static co_lss_state_t *const co_lss_slowscan_scan_state
The Slowscan scanning state.
static co_lss_state_t *const co_lss_fastscan_fini_state
The Fastscan finalization state.
static co_lss_state_t *const co_lss_cs_state
The command received state.
int co_lss_is_master(const co_lss_t *lss)
Returns 1 if the specified CANopen LSS service is a master, and 0 if not.
static co_lss_state_t *const co_lss_slowscan_init_state
The Slowscan initialization state.
int co_lss_set_id_req(co_lss_t *lss, co_unsigned8_t id, co_lss_err_ind_t *ind, void *data)
Requests the 'configure node-ID' service.
void co_lss_set_timeout(co_lss_t *lss, int timeout)
Sets the timeout of an LSS master service.
static co_lss_state_t * co_lss_fastscan_fini_on_enter(co_lss_t *lss)
The entry function of the Fastscan finalization state.
static co_lss_state_t * co_lss_fastscan_scan_on_enter(co_lss_t *lss)
The entry function of the Fastscan scanning state.
static co_lss_state_t *const co_lss_wait_state
The 'waiting' state of an LSS master or slave.
static void co_lss_id_slave(co_lss_t *lss, co_unsigned8_t cs, co_unsigned32_t id)
Implements the LSS identify remote slave service for an LSS slave.
static void co_lss_err_on_leave(co_lss_t *lss)
The exit function of the error received state.
co_unsigned16_t co_lss_get_inhibit(const co_lss_t *lss)
Returns the inhibit time (in multiples of 100 microseconds) of an LSS master service.
static void co_lss_init_req(const co_lss_t *lss, struct can_msg *msg, co_unsigned8_t cs)
Initializes an LSS request CAN frame.
int co_lss_slowscan_req(co_lss_t *lss, const struct co_id *lo, const struct co_id *hi, co_lss_scan_ind_t *ind, void *data)
Requests the 'LSS Slowscan' service.
int co_lss_switch_rate_req(co_lss_t *lss, int delay)
Requests the 'activate bit timing parameters' service.
static co_lss_state_t * co_lss_nid_on_recv(co_lss_t *lss, const struct can_msg *msg)
The 'CAN frame received' transition function of the inquire node-ID state.
static co_lss_state_t * co_lss_slowscan_switch_on_time(co_lss_t *lss, const struct timespec *tp)
The 'timeout' transition function of the Slowscan 'switch state selective' state.
int co_lss_get_id_req(co_lss_t *lss, co_lss_nid_ind_t *ind, void *data)
Requests the 'inquire node-ID' service.
static co_lss_state_t * co_lss_fastscan_scan_on_recv(co_lss_t *lss, const struct can_msg *msg)
The 'CAN frame received' transition function of the Fastscan scanning state.
static void co_lss_init_ind(co_lss_t *lss, co_unsigned8_t cs)
Prepares an LSS master to receive an indication from a slave.
static co_lss_state_t * co_lss_id_slave_on_enter(co_lss_t *lss)
The entry function of the 'identify remote slave' state.
int co_lss_get_revision_req(co_lss_t *lss, co_lss_lssid_ind_t *ind, void *data)
Requests the 'inquire identity revision-number' service.
void co_lss_set_store_ind(co_lss_t *lss, co_lss_store_ind_t *ind, void *data)
Sets the indication function invoked when an LSS 'store configuration' request is received.
int co_lss_switch_sel_req(co_lss_t *lss, const struct co_id *id, co_lss_cs_ind_t *ind, void *data)
Requests the 'switch state selective' service.
static co_lss_state_t * co_lss_cs_fini_on_enter(co_lss_t *lss)
The entry function of the command received finalization state.
static co_lss_state_t * co_lss_slowscan_switch_on_recv(co_lss_t *lss, const struct can_msg *msg)
The 'CAN frame received' transition function of the Slowscan 'switch state selective' state.
void co_lss_get_rate_ind(const co_lss_t *lss, co_lss_rate_ind_t **pind, void **pdata)
Retrieves the indication function invoked when an LSS 'activate bit timing' request is received.
int co_lss_switch_req(co_lss_t *lss, co_unsigned8_t mode)
Requests the 'switch state global' service.
static void co_lss_emit_recv(co_lss_t *lss, const struct can_msg *msg)
Invokes the 'CAN frame received' transition function of the current state of an LSS service.
int co_lss_set_rate_req(co_lss_t *lss, co_unsigned16_t rate, co_lss_err_ind_t *ind, void *data)
Requests the 'configure bit timing parameters' service.
static co_lss_state_t *const co_lss_cfg_state
The 'configuration' state of an LSS slave.
int co_lss_is_idle(const co_lss_t *lss)
Returns 1 if the specified LSS master is idle, and 0 if a request is ongoing.
static co_lss_state_t *const co_lss_fastscan_scan_state
The Fastscan scanning state.
void co_lss_set_rate_ind(co_lss_t *lss, co_lss_rate_ind_t *ind, void *data)
Sets the indication function invoked when an LSS 'activate bit timing' request is received.
static co_lss_state_t * co_lss_cfg_on_recv(co_lss_t *lss, const struct can_msg *msg)
The 'CAN frame received' transition function of the 'configuration' state of an LSS slave.
int co_lss_get_timeout(const co_lss_t *lss)
Returns the timeout (in milliseconds) of an LSS master service.
static co_lss_state_t * co_lss_fastscan_init_on_time(co_lss_t *lss, const struct timespec *tp)
The 'timeout' transition function of the Fastscan initialization state.
int co_lss_get_product_code_req(co_lss_t *lss, co_lss_lssid_ind_t *ind, void *data)
Requests the 'inquire identity product-code' service.
static co_lss_state_t *const co_lss_id_slave_state
The 'identify remote slave' state.
static co_lss_state_t *const co_lss_slowscan_fini_state
The Slowscan finalization state.
co_nmt_t * co_lss_get_nmt(const co_lss_t *lss)
Returns a pointer to the NMT service of an LSS master/slave service.
int co_lss_id_slave_req(co_lss_t *lss, const struct co_id *lo, const struct co_id *hi, co_lss_cs_ind_t *ind, void *data)
Requests the 'LSS identify remote slave' service.
static co_lss_state_t *const co_lss_nid_state
The inquire node-ID state.
static void co_lss_slowscan_fini_on_leave(co_lss_t *lss)
The exit function of the Slowscan finalization state.
static co_lss_state_t * co_lss_fastscan_wait_on_recv(co_lss_t *lss, const struct can_msg *msg)
The 'CAN frame received' transition function of the Fastscan waiting state.
int co_lss_store_req(co_lss_t *lss, co_lss_err_ind_t *ind, void *data)
Requests the 'store configuration' service.
static co_lss_state_t * co_lss_fastscan_wait_on_time(co_lss_t *lss, const struct timespec *tp)
The 'timeout' transition function of the Fastscan waiting state.
static co_lss_state_t * co_lss_slowscan_init_on_recv(co_lss_t *lss, const struct can_msg *msg)
The 'CAN frame received' transition function of the Slowscan initialization state.
static co_lss_state_t * co_lss_cs_on_time(co_lss_t *lss, const struct timespec *tp)
The 'timeout' transition function of the command received state.
static co_lss_state_t * co_lss_id_slave_on_time(co_lss_t *lss, const struct timespec *tp)
The 'timeout' transition function of the 'identify remote slave' state.
static co_lss_state_t * co_lss_lssid_on_recv(co_lss_t *lss, const struct can_msg *msg)
The 'CAN frame received' transition function of the inquire identity state.
int co_lss_id_non_cfg_slave_req(co_lss_t *lss, co_lss_cs_ind_t *ind, void *data)
Requests the 'LSS identify non-configured remote slave' service.
static co_lss_state_t *const co_lss_fastscan_wait_state
The Fastscan waiting state.
static co_lss_state_t * co_lss_slowscan_fini_on_enter(co_lss_t *lss)
The entry function of the Slowscan finalization state.
static co_lss_state_t * co_lss_slowscan_scan_on_enter(co_lss_t *lss)
The entry function of the Slowscan scanning state.
static int co_lss_send_id_slave_req(co_lss_t *lss, const struct co_id *lo, const struct co_id *hi)
Sends a single frame of an LSS identify remote slave request (see Fig.
static int co_lss_timer(const struct timespec *tp, void *data)
The CAN timer callback function for an LSS service.
static co_lss_state_t * co_lss_wait_slave_on_enter(co_lss_t *lss)
The entry function of the 'waiting' state of an LSS slave.
static co_lss_state_t *const co_lss_cs_fini_state
The command received finalization state.
static co_lss_state_t * co_lss_slowscan_init_on_enter(co_lss_t *lss)
The entry function of the Slowscan initialization state.
static co_lss_state_t *const co_lss_slowscan_switch_state
The Slowscan 'switch state selective' state.
co_lss_t * co_lss_create(co_nmt_t *nmt)
Creates a new CANopen LSS master/slave service.
static co_lss_state_t * co_lss_slowscan_wait_on_time(co_lss_t *lss, const struct timespec *tp)
The 'timeout' transition function of the Slowscan waiting state.
static co_lss_state_t * co_lss_fastscan(co_lss_t *lss, co_unsigned32_t id, co_unsigned8_t bitchk, co_unsigned8_t lsssub, co_unsigned8_t lssnext)
Implements the LSS fastscan service for an LSS slave.
int co_lss_fastscan_req(co_lss_t *lss, const struct co_id *id, const struct co_id *mask, co_lss_scan_ind_t *ind, void *data)
Requests the 'LSS Fastscan' service.
static void co_lss_enter(co_lss_t *lss, co_lss_state_t *next)
Enters the specified state of an LSS service and invokes the exit and entry functions.
static void co_lss_id_non_cfg_slave(const co_lss_t *lss)
Implements the LSS identify non-configured remote slave service for an LSS slave.
static co_lss_state_t * co_lss_wait_slave_on_recv(co_lss_t *lss, const struct can_msg *msg)
The 'CAN frame received' transition function of the 'waiting' state of an LSS slave.
static co_unsigned32_t * co_id_sub(struct co_id *id, co_unsigned8_t sub)
Returns a pointer to the specified number in an LSS address.
static co_lss_state_t *const co_lss_err_state
The error received state.
static void co_lss_nid_on_leave(co_lss_t *lss)
The exit function of the inquire node-ID state.
static co_lss_state_t *const co_lss_switch_sel_state
The 'switch state selective' state.
int co_lss_get_serial_nr_req(co_lss_t *lss, co_lss_lssid_ind_t *ind, void *data)
Requests the 'inquire identity serial-number' service.
static co_lss_state_t * co_lss_fastscan_init_on_recv(co_lss_t *lss, const struct can_msg *msg)
The 'CAN frame received' transition function of the Fastscan initialization state.
void co_lss_abort_req(co_lss_t *lss)
Aborts the current LSS master request.
static co_lss_state_t * co_lss_switch_sel(co_lss_t *lss, co_unsigned8_t cs, co_unsigned32_t id)
Implements the switch state selective service for an LSS slave.
static co_lss_state_t * co_lss_lssid_on_time(co_lss_t *lss, const struct timespec *tp)
The 'timeout' transition function of the inquire identity state.
static int co_lss_recv(const struct can_msg *msg, void *data)
The CAN receive callback function for an LSS service.
static void co_lss_lssid_on_leave(co_lss_t *lss)
The exit function of the inquire identity state.
static co_lss_state_t * co_lss_wait_on_enter(co_lss_t *lss)
The entry function of the 'waiting' state an LSS master or slave.
static void co_lss_emit_time(co_lss_t *lss, const struct timespec *tp)
Invokes the 'timeout' transition function of the current state of an LSS service.
static co_lss_state_t *const co_lss_fastscan_init_state
The Fastscan initialization state.
static co_lss_state_t * co_lss_fastscan_scan_on_time(co_lss_t *lss, const struct timespec *tp)
The 'timeout' transition function of the Fastscan scanning state.
static co_lss_state_t *const co_lss_wait_slave_state
The 'waiting' state of an LSS slave.
static co_lss_state_t * co_lss_switch_sel_on_enter(co_lss_t *lss)
The entry function of the 'switch state selective' state.
static co_lss_state_t *const co_lss_lssid_state
The inquire identity state.
static co_lss_state_t * co_lss_err_on_recv(co_lss_t *lss, const struct can_msg *msg)
The 'CAN frame received' transition function of the error received state.
static co_lss_state_t * co_lss_slowscan_scan_on_recv(co_lss_t *lss, const struct can_msg *msg)
The 'CAN frame received' transition function of the Slowscan scanning state.
static co_lss_state_t * co_lss_err_on_time(co_lss_t *lss, const struct timespec *tp)
The 'timeout' transition function of the error received state.
void co_lss_get_store_ind(const co_lss_t *lss, co_lss_store_ind_t **pind, void **pdata)
Retrieves the indication function invoked when an LSS 'store configuration' request is received.
static int co_lss_send_switch_sel_req(co_lss_t *lss, const struct co_id *id)
Sends a single frame of a switch state selective request (see Fig.
void co_lss_set_inhibit(co_lss_t *lss, co_unsigned16_t inhibit)
Sets the inhibit time between successive LSS messages of an LSS master service.
This header file is part of the CANopen library; it contains the Layer Setting Services (LSS) and pro...
void co_lss_lssid_ind_t(co_lss_t *lss, co_unsigned8_t cs, co_unsigned32_t id, void *data)
The type of a CANopen LSS inquire identity indication function, invoked when an 'inquire identity ven...
int co_lss_store_ind_t(co_lss_t *lss, co_unsigned8_t id, co_unsigned16_t rate, void *data)
The type of a CANopen LSS 'store configuration' indication function, invoked when the pending node-ID...
#define CO_LSS_CANID(master)
The CAN identifier used for LSS by the master (1) or the slave (0).
void co_lss_err_ind_t(co_lss_t *lss, co_unsigned8_t cs, co_unsigned8_t err, co_unsigned8_t spec, void *data)
The type of a CANopen LSS error received indication function, invoked when a 'configure node-ID',...
void co_lss_nid_ind_t(co_lss_t *lss, co_unsigned8_t cs, co_unsigned8_t id, void *data)
The type of a CANopen LSS inquire node-ID indication function, invoked when an 'inquire node-ID' requ...
void co_lss_scan_ind_t(co_lss_t *lss, co_unsigned8_t cs, const struct co_id *id, void *data)
The type of a CANopen LSS identify remote slave indication function, invoked when a 'Slowscan' or 'Fa...
#define LELY_CO_LSS_INHIBIT
The default LSS inhibit time (in multiples of 100 microseconds).
void co_lss_cs_ind_t(co_lss_t *lss, co_unsigned8_t cs, void *data)
The type of a CANopen LSS command received indication function, invoked when a 'switch state selectiv...
void co_lss_rate_ind_t(co_lss_t *lss, co_unsigned16_t rate, int delay, void *data)
The type of a CANopen LSS 'activate bit timing' indication function, invoked when a baudrate switch i...
#define LELY_CO_LSS_TIMEOUT
The default LSS timeout (in milliseconds).
void can_timer_stop(can_timer_t *timer)
Stops a CAN timer and unregisters it with a network interface.
int can_net_send(can_net_t *net, const struct can_msg *msg)
Sends a CAN frame from a network interface.
void can_timer_start(can_timer_t *timer, can_net_t *net, const struct timespec *start, const struct timespec *interval)
Starts a CAN timer and registers it with a network interface.
void can_net_get_time(const can_net_t *net, struct timespec *tp)
Retrieves the current time of a CAN 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.
This header file is part of the CANopen library; it contains the network management (NMT) declaration...
can_net_t * co_nmt_get_net(const co_nmt_t *nmt)
Returns a pointer to the CAN network of an NMT master/slave service.
#define CO_NMT_ST_BOOTUP
The NMT state 'boot-up'.
co_dev_t * co_nmt_get_dev(const co_nmt_t *nmt)
Returns a pointer to the CANopen device of an NMT master/slave service.
co_unsigned8_t co_nmt_get_id(const co_nmt_t *nmt)
Returns 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,...
#define CO_NMT_ST_RESET_NODE
The NMT sub-state 'reset application'.
#define CO_NMT_ST_RESET_COMM
The NMT sub-state 'reset communication'.
int co_nmt_set_id(co_nmt_t *nmt, co_unsigned8_t id)
Sets the pending node-ID.
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.
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....
co_lss_state_t *(* on_recv)(co_lss_t *lss, const struct can_msg *msg)
A pointer to the transition function invoked when a CAN frame has been received.
co_lss_state_t *(* on_enter)(co_lss_t *lss)
A pointer to the function invoked when a new state is entered.
co_lss_state_t *(* on_time)(co_lss_t *lss, const struct timespec *tp)
A pointer to the transition function invoked when a timeout occurs.
void(* on_leave)(co_lss_t *lss)
A pointer to the function invoked when the current state is left.
A CANopen LSS master/slave service.
void * err_data
A pointer to user-specified data for err_ind.
co_unsigned8_t spec
The received implementation-specific error code.
int next
The index of the next frame to be sent.
co_unsigned8_t cs
The expected command specifier.
struct co_id id
The LSS address obtained from the LSS Slowscan or Fastscan service.
co_unsigned16_t inhibit
The inhibit time (in multiples of 100 microseconds).
can_timer_t * timer
A pointer to the CAN timer.
co_nmt_t * nmt
A pointer to an NMT master/slave service.
co_unsigned8_t lsspos
The LSSPos value.
co_lss_nid_ind_t * nid_ind
A pointer to the inquire node-ID indication function.
co_lss_scan_ind_t * scan_ind
A pointer to the identify remote slave indication function.
co_unsigned8_t err
The received error code.
void * nid_data
A pointer to user-specified data for nid_ind.
can_recv_t * recv
A pointer to the CAN frame receiver.
void * cs_data
A pointer to user-specified data for cs_ind.
co_lss_lssid_ind_t * lssid_ind
A pointer to the inquire identity indication function.
co_lss_err_ind_t * err_ind
A pointer to the error indication function.
co_unsigned8_t nid
The received node-ID.
void * lssid_data
A pointer to user-specified data for lssid_ind.
int master
A flag specifying whether the LSS service is a master or a slave.
co_unsigned8_t lsssub
The index of the current LSS number being checked during the Fastscan service.
void * rate_data
A pointer to user-specified data for rate_ind.
struct co_id mask
The mask used during the Fastscan service.
co_dev_t * dev
A pointer to a CANopen device.
co_unsigned8_t bitchk
The least-significant bit being checked during the Fastscan service.
struct co_id lo
The lower bound of the LSS address used during the Slowscan service.
int timeout
The timeout (in milliseconds).
void * scan_data
A pointer to user-specified data for scan_ind.
void * store_data
A pointer to user-specified data for store_ind.
co_unsigned32_t lssid
The received LSS number.
co_lss_store_ind_t * store_ind
A pointer to the 'store configuration' indication function.
co_lss_cs_ind_t * cs_ind
A pointer to the command indication function.
co_lss_state_t * state
A pointer to the current state.
co_lss_rate_ind_t * rate_ind
A pointer to the 'activate bit timing' indication function.
struct co_id hi
The upper bound of the LSS address used during the Slowscan service.
can_net_t * net
A pointer to a CAN network interface.
A CANopen NMT master/slave service.
A CAN or CAN FD format frame.
uint_least8_t data[CAN_MSG_MAX_LEN]
The frame payload (in case of a data frame).
uint_least32_t id
The identifier (11 or 29 bits, depending on the CAN_FLAG_IDE flag).
uint_least8_t len
The number of bytes in data (or the requested number of bytes in case of a remote frame).
co_unsigned32_t product_code
Product code.
co_unsigned32_t revision
Revision number.
co_unsigned8_t n
Highest sub-index supported.
co_unsigned32_t vendor_id
Vendor-ID.
co_unsigned32_t serial_nr
Serial number.
This header file is part of the utilities library; it contains the time function declarations.
void timespec_add_usec(struct timespec *tp, uint_least64_t usec)
Adds usec microseconds to the time at tp.
This header file is part of the CANopen library; it contains the CANopen value declarations.
#define CO_UNSIGNED16_MAX
The maximum value of a 16-bit unsigned integer.