Lely core libraries 2.3.4
pdo.c File Reference

This file is part of the CANopen library; it contains the implementation of the Process Data Object (PDO) functions. More...

#include "co.h"
#include <lely/can/msg.h>
#include <lely/co/dev.h>
#include <lely/co/obj.h>
#include <lely/co/pdo.h>
#include <lely/co/sdo.h>
#include <lely/util/endian.h>
#include <assert.h>
Include dependency graph for pdo.c:

Go to the source code of this file.

Functions

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_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_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 - 15FF (RPDO communication parameter).
 
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 (RPDO mapping parameter).
 
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_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_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 - 19FF (TPDO communication parameter).
 
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 (TPDO mapping parameter).
 
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 transmitted with a SAM-MPDO.
 
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..1FFF) and can be mapped to a local object with a SAM-MPDO.
 
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.
 
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_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_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_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 local SDO upload request.
 

Detailed Description

This file is part of the CANopen library; it contains the implementation of the Process Data Object (PDO) functions.

See also
lely/co/pdo.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 pdo.c.

Function Documentation

◆ co_dev_chk_rpdo()

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.

Parameters
deva pointer to a CANopen device.
idxthe object index.
subidxthe object sub-index.
Returns
0 if the object is valid and can be mapped, or an SDO abort code on error.

Definition at line 51 of file pdo.c.

◆ co_dev_cfg_rpdo()

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.

This function disables the RPDO before configuring the parameters and re-enables it on success.

Parameters
deva pointer to a CANopen device.
numthe PDO number (in the range [1..512]).
comma pointer to the communication parameters.
mapa pointer to the mapping parameters.
Returns
0 on success, or an SDO abort code on error.
See also
co_dev_cfg_rpdo_comm(), co_dev_cfg_rpdo_map()

Definition at line 80 of file pdo.c.

◆ co_dev_cfg_rpdo_comm()

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 - 15FF (RPDO communication parameter).

Parameters
deva pointer to a CANopen device.
numthe PDO number (in the range [1..512]).
para pointer to the communication parameters.
Returns
0 on success, or an SDO abort code on error.

Definition at line 106 of file pdo.c.

◆ co_dev_cfg_rpdo_map()

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 (RPDO mapping parameter).

It is the responsibility of the caller to disable the RPDO before changing the mapping.

Parameters
deva pointer to a CANopen device.
numthe PDO number (in the range [1..512]).
para pointer to the mapping parameters.
Returns
0 on success, or an SDO abort code on error.

Definition at line 116 of file pdo.c.

◆ co_dev_chk_tpdo()

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.

Parameters
deva pointer to a CANopen device.
idxthe object index.
subidxthe object sub-index.
Returns
0 if the object is valid and can be mapped, or an SDO abort code on error.

Definition at line 130 of file pdo.c.

◆ co_dev_cfg_tpdo()

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.

This function disables the TPDO before configuring the parameters and re-enables it on success.

Parameters
deva pointer to a CANopen device.
numthe PDO number (in the range [1..512]).
comma pointer to the communication parameters.
mapa pointer to the mapping parameters.
Returns
0 on success, or an SDO abort code on error.
See also
co_dev_cfg_tpdo_comm(), co_dev_cfg_tpdo_map()

Definition at line 153 of file pdo.c.

◆ co_dev_cfg_tpdo_comm()

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 - 19FF (TPDO communication parameter).

Parameters
deva pointer to a CANopen device.
numthe PDO number (in the range [1..512]).
para pointer to the communication parameters.
Returns
0 on success, or an SDO abort code on error.

Definition at line 179 of file pdo.c.

◆ co_dev_cfg_tpdo_map()

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 (TPDO mapping parameter).

It is the responsibility of the caller to disable the TPDO before changing the mapping.

Parameters
deva pointer to a CANopen device.
numthe PDO number (in the range [1..512]).
para pointer to the mapping parameters.
Returns
0 on success, or an SDO abort code on error.

Definition at line 189 of file pdo.c.

◆ co_dev_chk_sam_mpdo()

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 transmitted with a SAM-MPDO.

Note that this function does not check if the object is valid and can be mapped into a TPDO.

Parameters
deva pointer to a CANopen device.
idxthe object index.
subidxthe object sub-index.
Returns
1 if the object was found in the object scanner list, and 0 if not.
See also
co_dev_chk_tpdo()

Definition at line 203 of file pdo.c.

◆ co_dev_map_sam_mpdo()

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..1FFF) and can be mapped to a local object with a SAM-MPDO.

Note that this function does not check if the local object is valid and can be mapped to an RPDO.

Parameters
deva pointer to a CANopen device.
idthe remote node-ID (in the range [1..127]).
idxthe remote object index.
subidxthe remote object sub-index.
pidxthe address at which to store the local object index (can be NULL).
psubidxthe address at which to store the object sub-index (can be NULL).
Returns
1 if the remote object was found in the object dispatching list, and 0 if not.
See also
co_dev_chk_rpdo()

Definition at line 245 of file pdo.c.

◆ co_pdo_map()

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.

Parameters
para pointer to the PDO mapping parameters.
vala pointer to the values to map.
nthe number of values at val.
bufthe address at which to store the mapped values (can be NULL).
pnthe address of a value containing the size (in bytes) of the buffer at buf. On exit, if pn is not NULL, *pn contains the number of bytes that would have been written had the buffer at buf been sufficiently large.
Returns
0 on success, or an SDO abort code on error.
See also
co_pdo_unmap()

Definition at line 299 of file pdo.c.

◆ co_pdo_unmap()

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.

Parameters
para pointer to the PDO mapping parameters.
bufa pointer to the mapped values.
nthe number of bytes at buf.
valthe address at which to store the unmapped values (can be NULL).
pnthe address of a value containing the size (in number of values) of the buffer at val. On exit, if pn is not NULL, *pn contains the number of values that would have been written had the buffer at val been sufficiently large.
Returns
0 on success, or an SDO abort code on error.
See also
co_pdo_map()

Definition at line 333 of file pdo.c.

◆ co_pdo_dn()

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.

Parameters
para pointer to the PDO mapping parameters.
deva pointer to a CANopen device.
reqa pointer to the CANopen SDO download request used for writing to the object dictionary.
bufa pointer to the mapped values.
nthe number of bytes at buf.
chka flag indicating whether co_dev_chk_rpdo() should be invoked before writing values to the object dictionary.
Returns
0 on success, or an SDO abort code on error.
See also
co_dev_chk_rpdo(), co_dev_map_sam_mpdo()

Definition at line 368 of file pdo.c.

◆ co_pdo_up()

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.

Note that this function does not support multiplex PDOs (see co_sam_mpdo_up()).

Parameters
para pointer to the PDO mapping parameters.
deva pointer to a CANopen device.
reqa pointer to the CANopen SDO upload request used for reading from the object dictionary.
bufthe address at which to store the mapped values (can be NULL).
pnthe address of a value containing the size (in bytes) of the buffer at buf. On exit, if pn is not NULL, *pn contains the number of bytes that would have been written had the buffer at buf been sufficiently large.
chka flag indicating whether co_dev_chk_tpdo() should be invoked before reading values from the object dictionary.
Returns
0 on success, or an SDO abort code on error.
See also
co_dev_chk_tpdo()

Definition at line 432 of file pdo.c.

◆ co_sam_mpdo_up()

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 local SDO upload request.

Parameters
deva pointer to a CANopen device.
idxthe object index.
subidxthe object sub-index.
reqa pointer to the CANopen SDO upload request used for reading from the object dictionary.
bufthe address at which to store the mapped value (can be NULL).
Returns
0 on success, or an SDO abort code on error.
See also
co_dev_chk_tpdo(), co_dev_chk_sam_mpdo()

Definition at line 483 of file pdo.c.