Lely core libraries  2.3.4
rpdo.c File Reference

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

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

Go to the source code of this file.

Data Structures

struct  __co_rpdo
 A CANopen Receive-PDO. More...
 

Functions

static void co_rpdo_init_recv (co_rpdo_t *pdo)
 Initializes the CAN frame receiver of a Receive-PDO service. More...
 
static void co_rpdo_init_timer_event (co_rpdo_t *pdo)
 Initializes the CAN timer for deadline monitoring of a Receive-PDO service. More...
 
static void co_rpdo_init_timer_swnd (co_rpdo_t *pdo)
 Initializes the CAN timer for the synchronous time window of a Receive-PDO service. More...
 
static co_unsigned32_t co_1400_dn_ind (co_sub_t *sub, struct co_sdo_req *req, void *data)
 The download indication function for (all sub-objects of) CANopen objects 1400..15FF (RPDO communication parameter). More...
 
static co_unsigned32_t co_1600_dn_ind (co_sub_t *sub, struct co_sdo_req *req, void *data)
 The download indication function for (all sub-objects of) CANopen objects 1600..17FF (RPDO mapping parameter). More...
 
static int co_rpdo_recv (const struct can_msg *msg, void *data)
 The CAN receive callback function for a Receive-PDO service. More...
 
static int co_rpdo_timer_event (const struct timespec *tp, void *data)
 The CAN timer callback function for deadline monitoring of a Receive-PDO service. More...
 
static int co_rpdo_timer_swnd (const struct timespec *tp, void *data)
 The CAN timer callback function for the synchronous time window of a Receive-PDO service. More...
 
static co_unsigned32_t co_rpdo_read_frame (co_rpdo_t *pdo, const struct can_msg *msg)
 Parses a CAN frame received by a Receive-PDO service and updates the corresponding objects in the object dictionary. More...
 
co_rpdo_tco_rpdo_create (can_net_t *net, co_dev_t *dev, co_unsigned16_t num)
 Creates a new CANopen Receive-PDO service. More...
 
void co_rpdo_destroy (co_rpdo_t *rpdo)
 Destroys a CANopen Receive-PDO service. More...
 
int co_rpdo_start (co_rpdo_t *pdo)
 Starts a Receive-PDO service. More...
 
void co_rpdo_stop (co_rpdo_t *pdo)
 Stops a Receive-PDO service. More...
 
int co_rpdo_is_stopped (const co_rpdo_t *pdo)
 Retuns 1 if the specified Receive-PDO service is stopped, and 0 if not. More...
 
can_net_tco_rpdo_get_net (const co_rpdo_t *pdo)
 Returns a pointer to the CAN network of a Receive-PDO.
 
co_dev_tco_rpdo_get_dev (const co_rpdo_t *pdo)
 Returns a pointer to the CANopen device of a Receive-PDO.
 
co_unsigned16_t co_rpdo_get_num (const co_rpdo_t *pdo)
 Returns the PDO number of a Receive-PDO.
 
const struct co_pdo_comm_parco_rpdo_get_comm_par (const co_rpdo_t *pdo)
 Returns a pointer to the PDO communication parameter record of a Receive-PDO.
 
const struct co_pdo_map_parco_rpdo_get_map_par (const co_rpdo_t *pdo)
 Returns a pointer to the PDO mapping parameter record of a Receive-PDO.
 
void co_rpdo_get_ind (const co_rpdo_t *pdo, co_rpdo_ind_t **pind, void **pdata)
 Retrieves the indication function invoked when a Receive-PDO error occurs. More...
 
void co_rpdo_set_ind (co_rpdo_t *pdo, co_rpdo_ind_t *ind, void *data)
 Sets the indication function invoked when a Receive-PDO error occurs. More...
 
void co_rpdo_get_err (const co_rpdo_t *pdo, co_rpdo_err_t **perr, void **pdata)
 Retrieves the error handling function of a Receive-PDO service. More...
 
void co_rpdo_set_err (co_rpdo_t *pdo, co_rpdo_err_t *err, void *data)
 Sets the error handling function of a Receive-PDO service. More...
 
int co_rpdo_rtr (co_rpdo_t *pdo)
 Requests the transmission of a PDO. More...
 
int co_rpdo_sync (co_rpdo_t *pdo, co_unsigned8_t cnt)
 Triggers the actuation of a received synchronous PDO. More...
 

Detailed Description

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

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

Function Documentation

◆ co_rpdo_init_recv()

static void co_rpdo_init_recv ( co_rpdo_t pdo)
static

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

This function is invoked when one of the RPDO communication parameters (objects 1400..15FF) is updated.

Definition at line 519 of file rpdo.c.

◆ co_rpdo_init_timer_event()

static void co_rpdo_init_timer_event ( co_rpdo_t pdo)
static

Initializes the CAN timer for deadline monitoring of a Receive-PDO service.

This function is invoked by co_rpdo_recv() after receiving an RPDO.

Definition at line 541 of file rpdo.c.

◆ co_rpdo_init_timer_swnd()

static void co_rpdo_init_timer_swnd ( co_rpdo_t pdo)
static

Initializes the CAN timer for the synchronous time window of a Receive-PDO service.

This function is invoked by co_rpdo_sync() or when one of the RPDO communication parameters (objects 1400..15FF) is updated.

Definition at line 551 of file rpdo.c.

◆ co_1400_dn_ind()

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

See also
co_sub_dn_ind_t

Definition at line 569 of file rpdo.c.

◆ co_1600_dn_ind()

static co_unsigned32_t co_1600_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 1600..17FF (RPDO mapping parameter).

See also
co_sub_dn_ind_t

Definition at line 666 of file rpdo.c.

◆ co_rpdo_recv()

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

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

See also
can_recv_func_t

Definition at line 760 of file rpdo.c.

◆ co_rpdo_timer_event()

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

The CAN timer callback function for deadline monitoring of a Receive-PDO service.

See also
can_timer_func_t

Definition at line 790 of file rpdo.c.

◆ co_rpdo_timer_swnd()

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

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

See also
can_timer_func_t

Definition at line 806 of file rpdo.c.

◆ co_rpdo_read_frame()

static co_unsigned32_t co_rpdo_read_frame ( co_rpdo_t pdo,
const struct can_msg msg 
)
static

Parses a CAN frame received by a Receive-PDO service and updates the corresponding objects in the object dictionary.

Parameters
pdoa pointer to a Receive-PDO service.
msga pointer to the received CAN frame.
Returns
0 on success, or an SDO abort code on error.

Definition at line 819 of file rpdo.c.

◆ co_rpdo_create()

co_rpdo_t* co_rpdo_create ( can_net_t net,
co_dev_t dev,
co_unsigned16_t  num 
)

Creates a new CANopen Receive-PDO service.

The service is started as if by co_rpdo_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 Receive-PDO service, or NULL on error. In the latter case, the error number can be obtained with get_errc().
See also
co_rpdo_destroy()

Definition at line 271 of file rpdo.c.

◆ co_rpdo_destroy()

void co_rpdo_destroy ( co_rpdo_t pdo)

Destroys a CANopen Receive-PDO service.

See also
co_rpdo_create()

Definition at line 298 of file rpdo.c.

◆ co_rpdo_start()

int co_rpdo_start ( co_rpdo_t pdo)

Starts a Receive-PDO service.

Postcondition
on success, co_rpdo_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_rpdo_stop()

Definition at line 308 of file rpdo.c.

◆ co_rpdo_stop()

void co_rpdo_stop ( co_rpdo_t pdo)

Stops a Receive-PDO service.

Postcondition
co_rpdo_is_stopped() returns 1.
See also
co_rpdo_start()

Definition at line 356 of file rpdo.c.

◆ co_rpdo_is_stopped()

int co_rpdo_is_stopped ( const co_rpdo_t pdo)

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

See also
co_rpdo_start, co_rpdo_stop()

Definition at line 384 of file rpdo.c.

◆ co_rpdo_get_ind()

void co_rpdo_get_ind ( const co_rpdo_t pdo,
co_rpdo_ind_t **  pind,
void **  pdata 
)

Retrieves the indication function invoked when a Receive-PDO error occurs.

Parameters
pdoa pointer to a Receive-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_rpdo_set_ind()

Definition at line 432 of file rpdo.c.

◆ co_rpdo_set_ind()

void co_rpdo_set_ind ( co_rpdo_t pdo,
co_rpdo_ind_t ind,
void *  data 
)

Sets the indication function invoked when a Receive-PDO error occurs.

Parameters
pdoa pointer to a Receive-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_rpdo_get_ind()

Definition at line 443 of file rpdo.c.

◆ co_rpdo_get_err()

void co_rpdo_get_err ( const co_rpdo_t pdo,
co_rpdo_err_t **  perr,
void **  pdata 
)

Retrieves the error handling function of a Receive-PDO service.

Parameters
pdoa pointer to a Receive-PDO service.
perrthe address at which to store a pointer to the error handling function (can be NULL).
pdatathe address at which to store a pointer to user-specified data (can be NULL).
See also
co_rpdo_set_err()

Definition at line 452 of file rpdo.c.

◆ co_rpdo_set_err()

void co_rpdo_set_err ( co_rpdo_t pdo,
co_rpdo_err_t err,
void *  data 
)

Sets the error handling function of a Receive-PDO service.

Parameters
pdoa pointer to a Receive-PDO service.
erra pointer to the function to be invoked.
dataa pointer to user-specified data (can be NULL). data is passed as the last parameter to err.
See also
co_rpdo_get_err()

Definition at line 463 of file rpdo.c.

◆ co_rpdo_rtr()

int co_rpdo_rtr ( co_rpdo_t pdo)

Requests the transmission of a PDO.

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

Definition at line 472 of file rpdo.c.

◆ co_rpdo_sync()

int co_rpdo_sync ( co_rpdo_t pdo,
co_unsigned8_t  cnt 
)

Triggers the actuation of a received synchronous PDO.

Parameters
pdoa pointer to a Receive-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().

Definition at line 493 of file rpdo.c.