26 #if !LELY_NO_CO_RPDO || !LELY_NO_CO_TPDO
37 static co_unsigned32_t co_dev_cfg_pdo_comm(
const co_dev_t *dev,
40 static co_unsigned32_t co_dev_cfg_pdo_map(
const co_dev_t *dev,
43 #if !LELY_NO_CO_RPDO && !LELY_NO_CO_MPDO
45 struct co_sdo_req *req,
const uint_least8_t *buf,
size_t n);
86 co_unsigned32_t ac = 0;
112 return co_dev_cfg_pdo_comm(dev, 0x1400 + num - 1, par);
122 return co_dev_cfg_pdo_map(dev, 0x1600 + num - 1, par);
159 co_unsigned32_t ac = 0;
185 return co_dev_cfg_pdo_comm(dev, 0x1800 + num - 1, par);
195 return co_dev_cfg_pdo_map(dev, 0x1a00 + num - 1, par);
204 const co_dev_t *dev, co_unsigned16_t idx, co_unsigned8_t subidx)
210 for (co_unsigned16_t i = 0x1fa0; !obj && i <= 0x1fcf; i++)
213 co_unsigned8_t
n = co_obj_get_val_u8(obj, 0);
219 co_unsigned32_t val = co_sub_get_val_u32(sub);
223 if (((val >> 8) & 0xffff) != idx)
227 co_unsigned8_t min = val & 0xff;
230 co_unsigned8_t max = min;
231 co_unsigned8_t blk = (val >> 24) & 0xff;
233 max +=
MIN(blk - 1, 0xff - min);
246 co_unsigned8_t subidx, co_unsigned16_t *pidx,
247 co_unsigned8_t *psubidx)
254 for (co_unsigned16_t i = 0x1fd0; !obj && i <= 0x1fff; i++)
257 co_unsigned8_t
n = co_obj_get_val_u8(obj, 0);
263 co_unsigned64_t val = co_sub_get_val_u64(sub);
267 if ((val & 0xff) !=
id)
269 if (((val >> 16) & 0xffff) != idx)
273 co_unsigned8_t min = (val >> 8) & 0xff;
276 co_unsigned8_t max = min;
277 co_unsigned8_t blk = (val >> 54) & 0xff;
279 max +=
MIN(blk - 1, 0xff - min);
284 *pidx = (val >> 40) & 0xffff;
286 *psubidx = (val >> 32) & 0xff;
287 *psubidx += subidx - min;
300 co_unsigned8_t
n, uint_least8_t *buf,
size_t *pn)
309 for (
size_t i = 0; i < par->
n; i++) {
310 co_unsigned32_t map = par->
map[i];
314 co_unsigned8_t len = map & 0xff;
318 uint_least8_t tmp[
sizeof(co_unsigned64_t)] = { 0 };
320 if (buf && pn && offset + len <= *pn * 8)
321 bcpyle(buf, offset, tmp, 0, len);
327 *pn = (offset + 7) / 8;
334 size_t n, co_unsigned64_t *val, co_unsigned8_t *pn)
343 for (
size_t i = 0; i < par->
n; i++) {
344 co_unsigned32_t map = par->
map[i];
348 co_unsigned8_t len = map & 0xff;
349 if (offset + len >
n * 8)
352 uint_least8_t tmp[
sizeof(co_unsigned64_t)] = { 0 };
353 bcpyle(tmp, 0, buf, offset, len);
354 if (val && pn && i < *pn)
369 struct co_sdo_req *req,
const uint_least8_t *buf,
size_t n,
381 return co_mpdo_dn(par, dev, req, buf,
n);
389 for (
size_t i = 0; i < par->
n; i++) {
390 co_unsigned32_t map = par->
map[i];
394 co_unsigned16_t idx = (map >> 16) & 0xffff;
395 co_unsigned8_t subidx = (map >> 8) & 0xff;
396 co_unsigned8_t len = map & 0xff;
399 if (offset + len >
n * 8)
404 co_unsigned32_t ac = 0;
412 bcpyle(tmp, 0, buf, offset, len);
414 req->
size = (len + 7) / 8;
433 struct co_sdo_req *req, uint_least8_t *buf,
size_t *pn,
int chk)
443 for (
size_t i = 0; i < par->
n; i++) {
444 co_unsigned32_t map = par->
map[i];
448 co_unsigned16_t idx = (map >> 16) & 0xffff;
449 co_unsigned8_t subidx = (map >> 8) & 0xff;
450 co_unsigned8_t len = map & 0xff;
458 co_unsigned32_t ac = 0;
469 if (buf && pn && offset + len <= *pn * 8)
476 *pn = (offset + 7) / 8;
508 memcpy(buf, req->
buf, req->
size);
509 for (
size_t i = req->
size; i < 4; i++)
519 static co_unsigned32_t
520 co_dev_cfg_pdo_comm(
const co_dev_t *dev, co_unsigned16_t idx,
526 co_unsigned32_t ac = 0;
533 co_unsigned8_t
n = co_obj_get_val_u8(obj, 0x00);
546 if (par->
n >= 2 && !ac) {
554 if (par->
n >= 3 && !ac) {
563 if (par->
n >= 5 && !ac) {
571 if (par->
n >= 6 && !ac) {
581 static co_unsigned32_t
582 co_dev_cfg_pdo_map(
const co_dev_t *dev, co_unsigned16_t idx,
588 co_unsigned32_t ac = 0;
606 for (co_unsigned8_t i = 1; i <= par->
n; i++) {
621 #if !LELY_NO_CO_RPDO && !LELY_NO_CO_MPDO
624 struct co_sdo_req *req,
const uint_least8_t *buf,
size_t n)
635 co_unsigned8_t
id = buf[0];
636 co_unsigned16_t idx =
ldle_u16(buf + 1);
637 co_unsigned8_t subidx = buf[3];
This header file is part of the CAN library; it contains the CAN frame declarations.
#define CAN_MAX_LEN
The maximum number of bytes in the payload of a CAN format frame.
This header file is part of the CANopen library; it contains the device description declarations.
co_sub_t * co_dev_find_sub(const co_dev_t *dev, co_unsigned16_t idx, co_unsigned8_t subidx)
Finds a sub-object in the object dictionary of a CANopen device.
co_unsigned8_t co_dev_get_id(const co_dev_t *dev)
Returns the node-ID of a CANopen device.
co_unsigned32_t co_dev_get_dummy(const co_dev_t *dev)
Returns the data types supported by a CANopen device for mapping dummy entries in PDOs (one bit for e...
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.
This header file is part of the utilities library; it contains the byte order (endianness) function d...
void stle_u64(uint_least8_t dst[8], uint_least64_t x)
Stores a 64-bit unsigned integer in little-endian byte order.
void bcpyle(uint_least8_t *dst, int dstbit, const uint_least8_t *src, int srcbit, size_t n)
Copies n bits from a source to a destination buffer.
uint_least16_t ldle_u16(const uint_least8_t src[2])
Loads a 16-bit unsigned integer in little-endian byte order.
uint_least64_t ldle_u64(const uint_least8_t src[8])
Loads a 64-bit unsigned integer in little-endian byte order.
This header file is part of the CANopen library; it contains the Service Data Object (SDO) declaratio...
int co_sdo_req_first(const struct co_sdo_req *req)
Returns 1 if the specified request includes the first segment, and 0 otherwise.
#define CO_SDO_AC_NO_READ
SDO abort code: Attempt to read a write only object.
#define CO_SDO_AC_NO_OBJ
SDO abort code: Object does not exist in the object dictionary.
void co_sdo_req_clear(struct co_sdo_req *req)
Clears a CANopen SDO upload/download request, including its buffer.
#define CO_SDO_AC_NO_SUB
SDO abort code: Sub-index does not exist.
int co_sdo_req_last(const struct co_sdo_req *req)
Returns 1 if the specified request includes the last segment, and 0 otherwise.
#define CO_SDO_AC_PDO_LEN
SDO abort code: The number and length of the objects to be mapped would exceed the PDO length.
#define CO_SDO_AC_NO_PDO
SDO abort code: Object cannot be mapped to the PDO.
#define CO_SDO_AC_NO_WRITE
SDO abort code: Attempt to write a read only object.
#define MIN(a, b)
Returns the minimum of a and b.
This header file is part of the CANopen library; it contains the object dictionary declarations.
#define CO_ACCESS_READ
The object can be read.
co_unsigned8_t co_sub_get_subidx(const co_sub_t *sub)
Returns the sub-index of a CANopen sub-object.
co_unsigned32_t co_sub_dn_ind(co_sub_t *sub, struct co_sdo_req *req)
Invokes the download indication function of a CANopen sub-object, registered with co_sub_set_dn_ind()...
co_sub_t * co_sub_next(const co_sub_t *sub)
Finds the next sub-object in a CANopen object.
co_unsigned16_t co_obj_get_idx(const co_obj_t *obj)
Returns the index of a CANopen object.
co_unsigned32_t co_sub_up_ind(const co_sub_t *sub, struct co_sdo_req *req)
Invokes the upload indication function of a CANopen sub-object, registered with co_sub_set_up_ind().
co_unsigned32_t co_sub_dn_ind_val(co_sub_t *sub, co_unsigned16_t type, const void *val)
Invokes the download indication function of a CANopen sub-object, registered with co_sub_set_dn_ind()...
#define CO_ACCESS_RPDO
The object can be mapped to an RPDO.
int co_sub_get_pdo_mapping(const co_sub_t *sub)
Returns 1 if it is possible to map the specified CANopen sub-object into a PDO, and 0 if not.
co_obj_t * co_obj_next(const co_obj_t *obj)
Finds the next object in the object dictionary of a CANopen device.
co_sub_t * co_obj_find_sub(const co_obj_t *obj, co_unsigned8_t subidx)
Finds a sub-object in a CANopen object.
co_sub_t * co_obj_first_sub(const co_obj_t *obj)
Finds the first sub-object (with the lowest sub-index) in a CANopen object.
#define CO_ACCESS_TPDO
The object can be mapped to a TPDO.
#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.
co_unsigned32_t co_pdo_unmap(const struct co_pdo_map_par *par, const uint_least8_t *buf, size_t n, co_unsigned64_t *val, co_unsigned8_t *pn)
Unmaps a PDO into its constituent values.
co_unsigned32_t co_dev_chk_rpdo(const co_dev_t *dev, co_unsigned16_t idx, co_unsigned8_t subidx)
Checks if the specified object is valid and can be mapped into a Receive-PDO.
co_unsigned32_t co_pdo_up(const struct co_pdo_map_par *par, const co_dev_t *dev, struct co_sdo_req *req, uint_least8_t *buf, size_t *pn, int chk)
Reads mapped PDO values from the object dictionary through a local SDO upload request.
co_unsigned32_t co_dev_cfg_rpdo_comm(const co_dev_t *dev, co_unsigned16_t num, const struct co_pdo_comm_par *par)
Configures the communication parameters of a Receive-PDO service by updating CANopen object 1400 - 15...
co_unsigned32_t co_dev_cfg_tpdo_comm(const co_dev_t *dev, co_unsigned16_t num, const struct co_pdo_comm_par *par)
Configures the communication parameters of a Transmit-PDO service by updating CANopen object 1800 - 1...
co_unsigned32_t co_sam_mpdo_up(const co_dev_t *dev, co_unsigned16_t idx, co_unsigned8_t subidx, struct co_sdo_req *req, uint_least8_t buf[4])
Reads the value of the specified SAM-MPDO-mapped object from the local object dictionary through a lo...
co_unsigned32_t co_dev_cfg_rpdo(const co_dev_t *dev, co_unsigned16_t num, const struct co_pdo_comm_par *comm, const struct co_pdo_map_par *map)
Configures the communication and parameters of a Receive-PDO service.
co_unsigned32_t co_dev_cfg_tpdo(const co_dev_t *dev, co_unsigned16_t num, const struct co_pdo_comm_par *comm, const struct co_pdo_map_par *map)
Configures the communication and parameters of a Transmit-PDO service.
co_unsigned32_t co_dev_chk_tpdo(const co_dev_t *dev, co_unsigned16_t idx, co_unsigned8_t subidx)
Checks if the specified object is valid and can be mapped into a Transmit-PDO.
co_unsigned32_t co_pdo_map(const struct co_pdo_map_par *par, const co_unsigned64_t *val, co_unsigned8_t n, uint_least8_t *buf, size_t *pn)
Maps values into a PDO.
int co_dev_map_sam_mpdo(const co_dev_t *dev, co_unsigned8_t id, co_unsigned16_t idx, co_unsigned8_t subidx, co_unsigned16_t *pidx, co_unsigned8_t *psubidx)
Checks if the specified remote object is part of the object dispatching list (objects 1FD0....
co_unsigned32_t co_pdo_dn(const struct co_pdo_map_par *par, co_dev_t *dev, struct co_sdo_req *req, const uint_least8_t *buf, size_t n, int chk)
Writes mapped PDO values to the object dictionary through a local SDO download request.
co_unsigned32_t co_dev_cfg_tpdo_map(const co_dev_t *dev, co_unsigned16_t num, const struct co_pdo_map_par *par)
Configures the mapping parameters of a Transmit-PDO service by updating CANopen object 1A00 - 1BFF (T...
int co_dev_chk_sam_mpdo(const co_dev_t *dev, co_unsigned16_t idx, co_unsigned8_t subidx)
Checks if the specified object is part of the object scanner list (objects 1FA0..1FCF) and can be tra...
co_unsigned32_t co_dev_cfg_rpdo_map(const co_dev_t *dev, co_unsigned16_t num, const struct co_pdo_map_par *par)
Configures the mapping parameters of a Receive-PDO service by updating CANopen object 1600 - 17FF (RP...
This header file is part of the CANopen library; it contains the Process Data Object (PDO) declaratio...
#define CO_PDO_NUM_MAPS
The maximum number of mapped application objects in a single PDO.
#define CO_PDO_COBID_VALID
The bit in the PDO COB-ID specifying whether the PDO exists and is valid.
#define CO_NUM_PDOS
The maximum number of Receive/Transmit-PDOs.
#define CO_PDO_MAP_DAM_MPDO
The value of sub-index 0 of the PDO mapping parameter record indicating a a destination address mode ...
#define CO_PDO_MAP_SAM_MPDO
The value of sub-index 0 of the PDO mapping parameter record indicating a a source address mode multi...
This is the internal header file of the CANopen library.
A PDO communication parameter record.
co_unsigned8_t sync
SYNC start value.
co_unsigned16_t inhibit
Inhibit time.
co_unsigned16_t event
Event timer.
co_unsigned32_t cobid
COB-ID.
co_unsigned8_t trans
Transmission type.
co_unsigned8_t n
Highest sub-index supported.
A PDO mapping parameter record.
co_unsigned8_t n
Number of mapped objects in PDO.
co_unsigned32_t map[CO_PDO_NUM_MAPS]
An array of objects to be mapped.
A CANopen SDO upload/download request.
size_t size
The total size (in bytes) of the value to be uploaded/downloaded.
const void * buf
A pointer to the next bytes to be uploaded/downloaded.
size_t nbyte
The number of bytes available at buf.
#define CO_DEFTYPE_UNSIGNED16
The data type (and object index) of a 16-bit unsigned integer.
#define CO_DEFTYPE_UNSIGNED8
The data type (and object index) of an 8-bit unsigned integer.
size_t co_type_sizeof(co_unsigned16_t type)
Returns the native size (in bytes) of a value of the specified data type, or 1 if it is not a static ...
#define CO_DEFTYPE_UNSIGNED32
The data type (and object index) of a 32-bit unsigned integer.
int co_type_is_basic(co_unsigned16_t type)
Returns 1 if the specified (static) data type is a basic type, and 0 if not.