Lely core libraries  2.3.4
sync.c File Reference
#include "co.h"
#include <lely/co/dev.h>
#include <lely/co/obj.h>
#include <lely/co/sdo.h>
#include <lely/co/sync.h>
#include <lely/co/val.h>
#include <lely/util/errnum.h>
#include <lely/util/time.h>
#include <assert.h>
#include <stdlib.h>
Include dependency graph for sync.c:

Go to the source code of this file.

Data Structures

struct  __co_sync
 A CANopen SYNC producer/consumer service. More...
 

Functions

static void co_sync_update (co_sync_t *sync)
 Updates and (de)activates a SYNC producer/consumer service. More...
 
static co_unsigned32_t co_1005_dn_ind (co_sub_t *sub, struct co_sdo_req *req, void *data)
 The download indication function for (all sub-objects of) CANopen object 1005 (COB-ID SYNC message). More...
 
static co_unsigned32_t co_1006_dn_ind (co_sub_t *sub, struct co_sdo_req *req, void *data)
 The download indication function for (all sub-objects of) CANopen object 1006 (Communication cycle period). More...
 
static co_unsigned32_t co_1019_dn_ind (co_sub_t *sub, struct co_sdo_req *req, void *data)
 The download indication function for (all sub-objects of) CANopen object 1019 (Synchronous counter overflow value). More...
 
static int co_sync_recv (const struct can_msg *msg, void *data)
 The CAN receive callback function for a SYNC consumer service. More...
 
static int co_sync_timer (const struct timespec *tp, void *data)
 The CAN timer callback function for a SYNC producer service. More...
 
co_sync_tco_sync_create (can_net_t *net, co_dev_t *dev)
 Creates a new CANopen SYNC producer/consumer service. More...
 
void co_sync_destroy (co_sync_t *sync)
 Destroys a CANopen SYNC producer/consumer service. More...
 
int co_sync_start (co_sync_t *sync)
 Starts a SYNC service. More...
 
void co_sync_stop (co_sync_t *sync)
 Stops a SYNC service. More...
 
int co_sync_is_stopped (const co_sync_t *sync)
 Retuns 1 if the specified SYNC service is stopped, and 0 if not. More...
 
can_net_tco_sync_get_net (const co_sync_t *sync)
 Returns a pointer to the CAN network of a SYNC producer/consumer service.
 
co_dev_tco_sync_get_dev (const co_sync_t *sync)
 Returns a pointer to the CANopen device of a SYNC producer/consumer service.
 
void co_sync_get_ind (const co_sync_t *sync, co_sync_ind_t **pind, void **pdata)
 Retrieves the indication function invoked after a CANopen SYNC message is received or transmitted. More...
 
void co_sync_set_ind (co_sync_t *sync, co_sync_ind_t *ind, void *data)
 Sets the indication function invoked after a CANopen SYNC message is received or transmitted. More...
 
void co_sync_get_err (const co_sync_t *sync, co_sync_err_t **perr, void **pdata)
 Retrieves the error handling function of a SYNC consumer service. More...
 
void co_sync_set_err (co_sync_t *sync, co_sync_err_t *err, void *data)
 Sets the error handling function of a SYNC consumer service. More...
 

Detailed Description

This file is part of the CANopen library; it contains the implementation of the synchronization (SYNC) object functions.

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

Function Documentation

◆ co_sync_update()

static void co_sync_update ( co_sync_t sync)
static

Updates and (de)activates a SYNC producer/consumer service.

This function is invoked by the download indication functions when one of the SYNC configuration objects (1005, 1006 or 1019) is updated.

Definition at line 380 of file sync.c.

◆ co_1005_dn_ind()

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

The download indication function for (all sub-objects of) CANopen object 1005 (COB-ID SYNC message).

See also
co_sub_dn_ind_t

Definition at line 424 of file sync.c.

◆ co_1006_dn_ind()

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

The download indication function for (all sub-objects of) CANopen object 1006 (Communication cycle period).

See also
co_sub_dn_ind_t

Definition at line 472 of file sync.c.

◆ co_1019_dn_ind()

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

The download indication function for (all sub-objects of) CANopen object 1019 (Synchronous counter overflow value).

See also
co_sub_dn_ind_t

Definition at line 506 of file sync.c.

◆ co_sync_recv()

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

The CAN receive callback function for a SYNC consumer service.

See also
can_recv_func_t

Definition at line 548 of file sync.c.

◆ co_sync_timer()

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

The CAN timer callback function for a SYNC producer service.

See also
can_timer_func_t

Definition at line 570 of file sync.c.

◆ co_sync_create()

co_sync_t* co_sync_create ( can_net_t net,
co_dev_t dev 
)

Creates a new CANopen SYNC producer/consumer service.

The service is started as if by co_sync_start().

Parameters
neta pointer to a CAN network.
deva pointer to a CANopen device.
Returns
a pointer to a new SYNC service, or NULL on error. In the latter case, the error number can be obtained with get_errc().
See also
co_sync_destroy()

Definition at line 211 of file sync.c.

◆ co_sync_destroy()

void co_sync_destroy ( co_sync_t sync)

Destroys a CANopen SYNC producer/consumer service.

See also
co_sync_create()

Definition at line 238 of file sync.c.

◆ co_sync_start()

int co_sync_start ( co_sync_t sync)

Starts a SYNC service.

Postcondition
on success, co_sync_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_sync_stop()

Definition at line 248 of file sync.c.

◆ co_sync_stop()

void co_sync_stop ( co_sync_t sync)

Stops a SYNC service.

Postcondition
co_sync_is_stopped() returns 1.
See also
co_sync_start()

Definition at line 285 of file sync.c.

◆ co_sync_is_stopped()

int co_sync_is_stopped ( const co_sync_t sync)

Retuns 1 if the specified SYNC service is stopped, and 0 if not.

See also
co_sync_start, co_sync_stop()

Definition at line 316 of file sync.c.

◆ co_sync_get_ind()

void co_sync_get_ind ( const co_sync_t sync,
co_sync_ind_t **  pind,
void **  pdata 
)

Retrieves the indication function invoked after a CANopen SYNC message is received or transmitted.

Parameters
synca pointer to a SYNC consumer 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_sync_set_ind()

Definition at line 340 of file sync.c.

◆ co_sync_set_ind()

void co_sync_set_ind ( co_sync_t sync,
co_sync_ind_t ind,
void *  data 
)

Sets the indication function invoked after a CANopen SYNC message is received or transmitted.

Parameters
synca pointer to a SYNC consumer 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_sync_get_ind()

Definition at line 351 of file sync.c.

◆ co_sync_get_err()

void co_sync_get_err ( const co_sync_t sync,
co_sync_err_t **  perr,
void **  pdata 
)

Retrieves the error handling function of a SYNC consumer service.

Parameters
synca pointer to a SYNC consumer 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_sync_set_err()

Definition at line 360 of file sync.c.

◆ co_sync_set_err()

void co_sync_set_err ( co_sync_t sync,
co_sync_err_t err,
void *  data 
)

Sets the error handling function of a SYNC consumer service.

Parameters
synca pointer to a SYNC consumer 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_sync_get_err()

Definition at line 371 of file sync.c.