Lely core libraries  2.2.5
emcy.c File Reference

This file is part of the CANopen library; it contains the implementation of the emergency (EMCY) object functions. More...

#include "co.h"
#include <lely/can/buf.h>
#include <lely/co/dev.h>
#include <lely/co/emcy.h>
#include <lely/co/obj.h>
#include <lely/co/sdo.h>
#include <lely/co/val.h>
#include <lely/util/diag.h>
#include <lely/util/endian.h>
#include <lely/util/time.h>
#include <assert.h>
#include <stdlib.h>
Include dependency graph for emcy.c:

Go to the source code of this file.

Data Structures

struct  co_emcy_msg
 An EMCY message. More...
 
struct  co_emcy_node
 A remote CANopen EMCY producer node. More...
 
struct  __co_emcy
 A CANopen EMCY producer/consumer service. More...
 
struct  co_1003
 The pre-defined error field. More...
 

Functions

static struct co_emcy_nodeco_emcy_node_create (co_emcy_t *emcy, co_unsigned8_t id)
 Creates a new remote CANopen EMCY producer node. More...
 
static void co_emcy_node_destroy (struct co_emcy_node *node)
 Destroys a remote CANopen EMCY producer node. More...
 
static int co_emcy_node_recv (const struct can_msg *msg, void *data)
 The CAN receive callback function for a remote CANopen EMCY producer node. More...
 
static int co_emcy_set_1003 (co_emcy_t *emcy)
 Sets the value of CANopen object 1003 (Pre-defined error field). More...
 
static co_unsigned32_t co_1003_dn_ind (co_sub_t *sub, struct co_sdo_req *req, void *data)
 The download indication function for (all sub-objects of) CANopen object 1003 (Pre-defined error field). More...
 
static co_unsigned32_t co_1014_dn_ind (co_sub_t *sub, struct co_sdo_req *req, void *data)
 The download indication function for (all sub-objects of) CANopen object 1014 (COB-ID emergency message). More...
 
static int co_emcy_set_1028 (co_emcy_t *emcy, co_unsigned8_t id, co_unsigned32_t cobid)
 Sets the value of CANopen object 1028 (Emergency consumer object). More...
 
static co_unsigned32_t co_1028_dn_ind (co_sub_t *sub, struct co_sdo_req *req, void *data)
 The download indication function for (all sub-objects of) CANopen object 1028 (Emergency consumer object). More...
 
static int co_emcy_timer (const struct timespec *tp, void *data)
 The CAN timer callback function for an EMCY service. More...
 
static int co_emcy_send (co_emcy_t *emcy, co_unsigned16_t eec, co_unsigned8_t er, const co_unsigned8_t msef[5])
 Adds an EMCY message to the CAN frame buffer and sends it if possible. More...
 
static void co_emcy_flush (co_emcy_t *emcy)
 Sends any messages in the CAN frame buffer unless the inhibit time has not yet elapsed, in which case it sets the CAN timer.
 
co_emcy_tco_emcy_create (can_net_t *net, co_dev_t *dev)
 Creates a new CANopen EMCY producer/consumer service. More...
 
void co_emcy_destroy (co_emcy_t *emcy)
 Destroys a CANopen EMCY producer/consumer service. More...
 
can_net_tco_emcy_get_net (const co_emcy_t *emcy)
 Returns a pointer to the CAN network of an EMCY producer/consumer service.
 
co_dev_tco_emcy_get_dev (const co_emcy_t *emcy)
 Returns a pointer to the CANopen device of an EMCY producer/consumer service.
 
int co_emcy_push (co_emcy_t *emcy, co_unsigned16_t eec, co_unsigned8_t er, const co_unsigned8_t msef[5])
 Pushes a CANopen EMCY message to the stack and broadcasts it if the EMCY producer service is active. More...
 
int co_emcy_pop (co_emcy_t *emcy, co_unsigned16_t *peec, co_unsigned8_t *per)
 Pops the most recent CANopen EMCY message from the stack and broadcasts an 'error reset' message if the EMCY producer service is active. More...
 
void co_emcy_peek (const co_emcy_t *emcy, co_unsigned16_t *peec, co_unsigned8_t *per)
 Retrieves, but does not pop, the most recent CANopen EMCY message from the stack. More...
 
int co_emcy_clear (co_emcy_t *emcy)
 Clears the CANopen EMCY message stack and broadcasts the 'error reset/no error' message if the EMCY producer service is active. More...
 
void co_emcy_get_ind (const co_emcy_t *emcy, co_emcy_ind_t **pind, void **pdata)
 Retrieves the indication function invoked when a CANopen EMCY message is received. More...
 
void co_emcy_set_ind (co_emcy_t *emcy, co_emcy_ind_t *ind, void *data)
 Sets the indication function invoked when a CANopen EMCY message is received. More...
 

Detailed Description

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

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

Function Documentation

◆ co_emcy_node_create()

struct co_emcy_node * co_emcy_node_create ( co_emcy_t emcy,
co_unsigned8_t  id 
)
static

Creates a new remote CANopen EMCY producer node.

Parameters
emcya pointer to an EMCY service.
idthe node-ID.
Returns
a pointer to a new remote node, or NULL on error.
See also
co_emcy_node_destroy()

Definition at line 503 of file emcy.c.

◆ co_emcy_node_destroy()

void co_emcy_node_destroy ( struct co_emcy_node node)
static

Destroys a remote CANopen EMCY producer node.

See also
co_emcy_node_create()

Definition at line 538 of file emcy.c.

◆ co_emcy_node_recv()

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

The CAN receive callback function for a remote CANopen EMCY producer node.

See also
can_recv_func_t

Definition at line 548 of file emcy.c.

◆ co_emcy_set_1003()

static int co_emcy_set_1003 ( co_emcy_t emcy)
static

Sets the value of CANopen object 1003 (Pre-defined error field).

This function copies the list of active EMCY messages to the array at object 1003.

Returns
0 on success, or -1 on error.

Definition at line 585 of file emcy.c.

◆ co_1003_dn_ind()

static co_unsigned32_t co_1003_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 1003 (Pre-defined error field).

See also
co_sub_dn_ind_t

Definition at line 606 of file emcy.c.

◆ co_1014_dn_ind()

static co_unsigned32_t co_1014_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 1014 (COB-ID emergency message).

See also
co_sub_dn_ind_t

Definition at line 647 of file emcy.c.

◆ co_emcy_set_1028()

static int co_emcy_set_1028 ( co_emcy_t emcy,
co_unsigned8_t  id,
co_unsigned32_t  cobid 
)
static

Sets the value of CANopen object 1028 (Emergency consumer object).

Parameters
emcya pointer to an EMCY service.
idthe node-ID.
cobidthe COB-ID of the EMCY object.
Returns
0 on success, or -1 on error.

Definition at line 696 of file emcy.c.

◆ co_1028_dn_ind()

static co_unsigned32_t co_1028_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 1028 (Emergency consumer object).

See also
co_sub_dn_ind_t

Definition at line 728 of file emcy.c.

◆ co_emcy_timer()

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

The CAN timer callback function for an EMCY service.

See also
can_timer_func_t

Definition at line 790 of file emcy.c.

◆ co_emcy_send()

static int co_emcy_send ( co_emcy_t emcy,
co_unsigned16_t  eec,
co_unsigned8_t  er,
const co_unsigned8_t  msef[5] 
)
static

Adds an EMCY message to the CAN frame buffer and sends it if possible.

Parameters
emcya pointer to an EMCY service.
eecthe emergency error code.
erthe error register.
msefthe manufacturer-specific error code (can be NULL).
Returns
0 on success, or -1 on error.

Definition at line 802 of file emcy.c.

◆ co_emcy_create()

co_emcy_t* co_emcy_create ( can_net_t net,
co_dev_t dev 
)

Creates a new CANopen EMCY producer/consumer service.

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

Definition at line 324 of file emcy.c.

◆ co_emcy_destroy()

void co_emcy_destroy ( co_emcy_t emcy)

Destroys a CANopen EMCY producer/consumer service.

See also
co_emcy_create()

Definition at line 351 of file emcy.c.

◆ co_emcy_push()

int co_emcy_push ( co_emcy_t emcy,
co_unsigned16_t  eec,
co_unsigned8_t  er,
const co_unsigned8_t  msef[5] 
)

Pushes a CANopen EMCY message to the stack and broadcasts it if the EMCY producer service is active.

Parameters
emcya pointer to an EMCY producer service.
eecthe emergency error code.
erthe error register.
msefthe manufacturer-specific error code (can be NULL).
Returns
0 on success, or -1 on error. In the latter case, the error number can be obtained with get_errc().
See also
co_emcy_pop(), co_emcy_peek(), co_emcy_clear()

Definition at line 377 of file emcy.c.

◆ co_emcy_pop()

int co_emcy_pop ( co_emcy_t emcy,
co_unsigned16_t *  peec,
co_unsigned8_t *  per 
)

Pops the most recent CANopen EMCY message from the stack and broadcasts an 'error reset' message if the EMCY producer service is active.

Parameters
emcya pointer to an EMCY producer service.
peecthe address at which to store the emergency error code (can be NULL).
perthe address at which to store the error register (can be NULL).
Returns
0 on success, or -1 on error. In the latter case, the error number can be obtained with get_errc().
See also
co_emcy_push(), co_emcy_peek(), co_emcy_clear()

Definition at line 423 of file emcy.c.

◆ co_emcy_peek()

void co_emcy_peek ( const co_emcy_t emcy,
co_unsigned16_t *  peec,
co_unsigned8_t *  per 
)

Retrieves, but does not pop, the most recent CANopen EMCY message from the stack.

Parameters
emcya pointer to an EMCY producer service.
peecthe address at which to store the emergency error code (can be NULL).
perthe address at which to store the error register (can be NULL).
See also
co_emcy_push(), co_emcy_pop(), co_emcy_clear()

Definition at line 453 of file emcy.c.

◆ co_emcy_clear()

int co_emcy_clear ( co_emcy_t emcy)

Clears the CANopen EMCY message stack and broadcasts the 'error reset/no error' message if the EMCY producer service is active.

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

Definition at line 464 of file emcy.c.

◆ co_emcy_get_ind()

void co_emcy_get_ind ( const co_emcy_t emcy,
co_emcy_ind_t **  pind,
void **  pdata 
)

Retrieves the indication function invoked when a CANopen EMCY message is received.

Parameters
emcya pointer to an EMCY 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_emcy_set_ind()

Definition at line 483 of file emcy.c.

◆ co_emcy_set_ind()

void co_emcy_set_ind ( co_emcy_t emcy,
co_emcy_ind_t ind,
void *  data 
)

Sets the indication function invoked when a CANopen EMCY message is received.

Parameters
emcya pointer to an EMCY 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 func.
See also
co_emcy_get_ind()

Definition at line 494 of file emcy.c.