Lely core libraries 2.3.4
tpdo.c File Reference

This file is part of the CANopen library; it contains the implementation of the Transmit-PDO functions. More...

#include "co.h"
#include <lely/co/dev.h>
#include <lely/co/obj.h>
#include <lely/co/sdo.h>
#include <lely/co/tpdo.h>
#include <lely/co/val.h>
#include <lely/util/endian.h>
#include <lely/util/errnum.h>
#include <lely/util/time.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
Include dependency graph for tpdo.c:

Go to the source code of this file.

Data Structures

struct  __co_tpdo
 A CANopen Transmit-PDO. More...
 

Functions

static void co_tpdo_init_recv (co_tpdo_t *pdo)
 Initializes the CAN frame receiver of a Transmit-PDO service.
 
static void co_tpdo_init_timer_event (co_tpdo_t *pdo)
 Initializes the CAN timer for events of a Transmit-PDO service.
 
static void co_tpdo_init_timer_swnd (co_tpdo_t *pdo)
 Initializes the CAN timer for the synchronous time window of a Transmit-PDO service.
 
static co_unsigned32_t co_1800_dn_ind (co_sub_t *sub, struct co_sdo_req *req, void *data)
 The download indication function for (all sub-objects of) CANopen objects 1800..19FF (TPDO communication parameter).
 
static co_unsigned32_t co_1a00_dn_ind (co_sub_t *sub, struct co_sdo_req *req, void *data)
 The download indication function for (all sub-objects of) CANopen objects 1A00..1BFF (TPDO mapping parameter).
 
static int co_tpdo_recv (const struct can_msg *msg, void *data)
 The CAN receive callback function for a Transmit-PDO service.
 
static int co_tpdo_timer_event (const struct timespec *tp, void *data)
 The CAN timer callback function for events of a Transmit-PDO service.
 
static int co_tpdo_timer_swnd (const struct timespec *tp, void *data)
 The CAN timer callback function for the synchronous time window of a Transmit-PDO service.
 
static int default_sample_ind (co_tpdo_t *pdo, void *data)
 The default sampling indication function.
 
static int co_tpdo_init_frame (co_tpdo_t *pdo, struct can_msg *msg)
 Initializes a CAN frame to be sent by a Transmit-PDO service.
 
static int co_tpdo_send_frame (co_tpdo_t *pdo, const struct can_msg *msg)
 Sends a CAN frame from a Transmit-PDO service and invokes the indication function.
 
co_tpdo_tco_tpdo_create (can_net_t *net, co_dev_t *dev, co_unsigned16_t num)
 Creates a new CANopen Transmit-PDO service.
 
void co_tpdo_destroy (co_tpdo_t *tpdo)
 Destroys a CANopen Transmit-PDO service.
 
int co_tpdo_start (co_tpdo_t *pdo)
 Starts a Transmit-PDO service.
 
void co_tpdo_stop (co_tpdo_t *pdo)
 Stops a Transmit-PDO service.
 
int co_tpdo_is_stopped (const co_tpdo_t *pdo)
 Retuns 1 if the specified Transmit-PDO service is stopped, and 0 if not.
 
can_net_tco_tpdo_get_net (const co_tpdo_t *pdo)
 Returns a pointer to the CAN network of a Transmit-PDO.
 
co_dev_tco_tpdo_get_dev (const co_tpdo_t *pdo)
 Returns a pointer to the CANopen device of a Transmit-PDO.
 
co_unsigned16_t co_tpdo_get_num (const co_tpdo_t *pdo)
 Returns the PDO number of a Transmit-PDO.
 
const struct co_pdo_comm_parco_tpdo_get_comm_par (const co_tpdo_t *pdo)
 Returns a pointer to the PDO communication parameter record of a Transmit-PDO.
 
const struct co_pdo_map_parco_tpdo_get_map_par (const co_tpdo_t *pdo)
 Returns a pointer to the PDO mapping parameter record of a Transmit-PDO.
 
void co_tpdo_get_ind (const co_tpdo_t *pdo, co_tpdo_ind_t **pind, void **pdata)
 Retrieves the indication function invoked when a Transmit-PDO is sent or an error occurs.
 
void co_tpdo_set_ind (co_tpdo_t *pdo, co_tpdo_ind_t *ind, void *data)
 Sets the indication function invoked when a Transmit-PDO is sent or an error occurs.
 
void co_tpdo_get_sample_ind (const co_tpdo_t *pdo, co_tpdo_sample_ind_t **pind, void **pdata)
 Retrieves the indication function invoked when a Transmit-PDO starts sampling after the reception of a SYNC event.
 
void co_tpdo_set_sample_ind (co_tpdo_t *pdo, co_tpdo_sample_ind_t *ind, void *data)
 Sets the indication function invoked when a Transmit-PDO starts sampling after the reception of a SYNC event.
 
int co_tpdo_event (co_tpdo_t *pdo)
 Triggers the transmission of an acyclic or event-driven PDO.
 
int co_tpdo_sync (co_tpdo_t *pdo, co_unsigned8_t cnt)
 Triggers the transmission of a synchronous PDO.
 
int co_tpdo_sample_res (co_tpdo_t *pdo, co_unsigned32_t ac)
 Indicates the result of the sampling step after the reception of a SYNC event.
 
void co_tpdo_get_next (const co_tpdo_t *pdo, struct timespec *tp)
 Retrieves the time at which the next event-driven TPDO may be sent.
 
int co_dam_mpdo_event (co_tpdo_t *pdo, co_unsigned8_t id, co_unsigned16_t idx, co_unsigned8_t subidx, const co_unsigned8_t data[4])
 Triggers the transmission of a DAM-MPDO.
 
int co_sam_mpdo_event (co_tpdo_t *pdo, co_unsigned16_t idx, co_unsigned8_t subidx)
 Triggers the transmission of a DAM-MPDO.
 

Detailed Description

This file is part of the CANopen library; it contains the implementation of the Transmit-PDO functions.

The implementation follows CiA 301 version 4.2.0. See section 7.2.2 for the definition of the PDO services and protocols. The following objects determine the behavior of TPDOs:

  • 1007: Synchronous window length
  • 1800..19FF: TPDO communication parameter
  • 1A00..1BFF: TPDO mapping parameter See table 72 for a description of the transmission type in the communication parameters and table 73 for a description of the mapping parameters.
See also
lely/co/tpdo.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 tpdo.c.

Function Documentation

◆ co_tpdo_init_recv()

static void co_tpdo_init_recv ( co_tpdo_t pdo)
static

Initializes the CAN frame receiver of a Transmit-PDO service.

This function is invoked when one of the TPDO communication parameters (objects 1800..19FF) is updated.

Definition at line 802 of file tpdo.c.

◆ co_tpdo_init_timer_event()

static void co_tpdo_init_timer_event ( co_tpdo_t pdo)
static

Initializes the CAN timer for events of a Transmit-PDO service.

This function is invoked when one of the TPDO communication parameters (objects 1800..19FF) is updated.

Definition at line 825 of file tpdo.c.

◆ co_1800_dn_ind()

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

The download indication function for (all sub-objects of) CANopen objects 1800..19FF (TPDO communication parameter).

See also
co_sub_dn_ind_t

Definition at line 856 of file tpdo.c.

◆ co_1a00_dn_ind()

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

The download indication function for (all sub-objects of) CANopen objects 1A00..1BFF (TPDO mapping parameter).

See also
co_sub_dn_ind_t

Definition at line 987 of file tpdo.c.

◆ co_tpdo_recv()

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

The CAN receive callback function for a Transmit-PDO service.

See also
can_recv_func_t

Definition at line 1083 of file tpdo.c.

◆ co_tpdo_timer_event()

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

The CAN timer callback function for events of a Transmit-PDO service.

See also
can_timer_func_t

Definition at line 1115 of file tpdo.c.

◆ co_tpdo_timer_swnd()

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

The CAN timer callback function for the synchronous time window of a Transmit-PDO service.

See also
can_timer_func_t

Definition at line 1132 of file tpdo.c.

◆ default_sample_ind()

static int default_sample_ind ( co_tpdo_t pdo,
void *  data 
)
static

The default sampling indication function.

See also
co_tpdo_sample_ind_t

Definition at line 1144 of file tpdo.c.

◆ co_tpdo_init_frame()

static int co_tpdo_init_frame ( co_tpdo_t pdo,
struct can_msg msg 
)
static

Initializes a CAN frame to be sent by a Transmit-PDO service.

Parameters
pdoa pointer to a Transmit-PDO service.
msga pointer to the CAN frame to be initialized.
Returns
0 on success, or -1 on error. In the latter case, the indication function is invoked.

Definition at line 1152 of file tpdo.c.

◆ co_tpdo_send_frame()

static int co_tpdo_send_frame ( co_tpdo_t pdo,
const struct can_msg msg 
)
static

Sends a CAN frame from a Transmit-PDO service and invokes the indication function.

Parameters
pdoa pointer to a Transmit-PDO service.
msga pointer to the CAN frame to be sent.
Returns
0 on success, or -1 on error.

Definition at line 1182 of file tpdo.c.

◆ co_tpdo_create()

co_tpdo_t * co_tpdo_create ( can_net_t net,
co_dev_t dev,
co_unsigned16_t  num 
)

Creates a new CANopen Transmit-PDO service.

The service is started as if by co_tpdo_start().

Parameters
neta pointer to a CAN network.
deva pointer to a CANopen device describing the server.
numthe PDO number (in the range [1..512]). The PDO communication and mapping parameter records MUST exist in the object dictionary of dev.
Returns
a pointer to a new Transmit-PDO service, or NULL on error. In the latter case, the error number can be obtained with get_errc().
See also
co_tpdo_destroy()

Definition at line 303 of file tpdo.c.

◆ co_tpdo_destroy()

void co_tpdo_destroy ( co_tpdo_t pdo)

Destroys a CANopen Transmit-PDO service.

See also
co_tpdo_create()

Definition at line 330 of file tpdo.c.

◆ co_tpdo_start()

int co_tpdo_start ( co_tpdo_t pdo)

Starts a Transmit-PDO service.

Postcondition
on success, co_tpdo_is_stopped() returns 0.
Returns
0 on success, or -1 on error. In the latter case, the error number can be obtained with get_errc().
See also
co_tpdo_stop()

Definition at line 340 of file tpdo.c.

◆ co_tpdo_stop()

void co_tpdo_stop ( co_tpdo_t pdo)

Stops a Transmit-PDO service.

Postcondition
co_tpdo_is_stopped() returns 1.
See also
co_tpdo_start()

Definition at line 392 of file tpdo.c.

◆ co_tpdo_is_stopped()

int co_tpdo_is_stopped ( const co_tpdo_t pdo)

Retuns 1 if the specified Transmit-PDO service is stopped, and 0 if not.

See also
co_tpdo_start, co_tpdo_stop()

Definition at line 420 of file tpdo.c.

◆ co_tpdo_get_ind()

void co_tpdo_get_ind ( const co_tpdo_t pdo,
co_tpdo_ind_t **  pind,
void **  pdata 
)

Retrieves the indication function invoked when a Transmit-PDO is sent or an error occurs.

Parameters
pdoa pointer to a Transmit-PDO 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_tpdo_set_ind()

Definition at line 468 of file tpdo.c.

◆ co_tpdo_set_ind()

void co_tpdo_set_ind ( co_tpdo_t pdo,
co_tpdo_ind_t ind,
void *  data 
)

Sets the indication function invoked when a Transmit-PDO is sent or an error occurs.

Parameters
pdoa pointer to a Transmit-PDO 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_tpdo_get_ind()

Definition at line 479 of file tpdo.c.

◆ co_tpdo_get_sample_ind()

void co_tpdo_get_sample_ind ( const co_tpdo_t pdo,
co_tpdo_sample_ind_t **  pind,
void **  pdata 
)

Retrieves the indication function invoked when a Transmit-PDO starts sampling after the reception of a SYNC event.

Parameters
pdoa pointer to a Transmit-PDO 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_tpdo_set_sample_ind()

Definition at line 488 of file tpdo.c.

◆ co_tpdo_set_sample_ind()

void co_tpdo_set_sample_ind ( co_tpdo_t pdo,
co_tpdo_sample_ind_t ind,
void *  data 
)

Sets the indication function invoked when a Transmit-PDO starts sampling after the reception of a SYNC event.

Parameters
pdoa pointer to a Transmit-PDO 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_tpdo_get_sample_ind()

Definition at line 500 of file tpdo.c.

◆ co_tpdo_event()

int co_tpdo_event ( co_tpdo_t pdo)

Triggers the transmission of an acyclic or event-driven PDO.

This function has no effect if the PDO is not valid, not event-driven or a multiplex PDO. An error is returned if the inhibit time has not yet elapsed.

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

Definition at line 509 of file tpdo.c.

◆ co_tpdo_sync()

int co_tpdo_sync ( co_tpdo_t pdo,
co_unsigned8_t  cnt 
)

Triggers the transmission of a synchronous PDO.

This function has no effect if the PDO is not valid or not SYNC-driven.

Parameters
pdoa pointer to a Transmit-PDO service.
cntthe counter value (in the range [0..240]).
Returns
0 on success, or -1 on error. In the latter case, the error number can be obtained with get_errc().
See also
co_tpdo_event()

Definition at line 565 of file tpdo.c.

◆ co_tpdo_sample_res()

int co_tpdo_sample_res ( co_tpdo_t pdo,
co_unsigned32_t  ac 
)

Indicates the result of the sampling step after the reception of a SYNC event.

This function MUST be called upon completion.

Parameters
pdoa pointer to a Transmit-PDO service.
acthe SDO abort code (0 on success). The PDO is not sent if ac != 0.
Returns
0 on success, or -1 on error. In the latter case, the error number can be obtained with get_errc().
See also
co_tpdo_sample_ind_t

Definition at line 614 of file tpdo.c.

◆ co_dam_mpdo_event()

int co_dam_mpdo_event ( co_tpdo_t pdo,
co_unsigned8_t  id,
co_unsigned16_t  idx,
co_unsigned8_t  subidx,
const co_unsigned8_t  data[4] 
)

Triggers the transmission of a DAM-MPDO.

This function has no effect if the PDO is not a valid DAM-MPDO. An error is returned if the inhibit time has not yet elapsed.

Parameters
pdoa pointer to a Transmit-PDO service.
idthe node-ID of the MPDO consumer (0 for all nodes, [1..127] for a specific node).
idxthe remote object index.
subidxthe remote object sub-index.
datathe bytes to be transmitted.
Returns
0 on success, or -1 on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 666 of file tpdo.c.

◆ co_sam_mpdo_event()

int co_sam_mpdo_event ( co_tpdo_t pdo,
co_unsigned16_t  idx,
co_unsigned8_t  subidx 
)

Triggers the transmission of a DAM-MPDO.

This function has no effect if the PDO is not a valid SAM-MPDO. An error is returned if the inhibit time has not yet elapsed.

Parameters
pdoa pointer to a Transmit-PDO service.
idxthe object index.
subidxthe object sub-index.
Returns
0 on success, or -1 on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 730 of file tpdo.c.