Lely core libraries 2.3.4
emcy.h File Reference

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

#include <lely/can/net.h>
#include <lely/co/type.h>
Include dependency graph for emcy.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define CO_EMCY_COBID_VALID   UINT32_C(0x80000000)
 The bit in the EMCY COB-ID specifying whether the EMCY exists and is valid.
 
#define CO_EMCY_COBID_FRAME   UINT32_C(0x20000000)
 The bit in the EMCY COB-ID specifying whether to use an 11-bit (0) or 29-bit (1) CAN-ID.
 

Typedefs

typedef void co_emcy_ind_t(co_emcy_t *emcy, co_unsigned8_t id, co_unsigned16_t eec, co_unsigned8_t er, co_unsigned8_t msef[5], void *data)
 The type of a CANopen EMCY indication function, invoked when an EMCY message is received. More...
 

Functions

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...
 
int co_emcy_start (co_emcy_t *emcy)
 Starts an EMCY service. More...
 
void co_emcy_stop (co_emcy_t *emcy)
 Stops an EMCY service. More...
 
int co_emcy_is_stopped (const co_emcy_t *emcy)
 Retuns 1 if the specified EMCY service is stopped, and 0 if not. 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_remove (co_emcy_t *emcy, size_t n)
 Pops a CANopen EMCY message from the stack, even if it is not the most recent message, and broadcasts an 'error reset' message if the EMCY producer service is active. More...
 
ssize_t co_emcy_find (const co_emcy_t *emcy, co_unsigned16_t eec)
 Finds a CANopen EMCY message in 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 header file is part of the CANopen library; it contains the emergency (EMCY) object declarations.

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.h.

Typedef Documentation

◆ co_emcy_ind_t

typedef void co_emcy_ind_t(co_emcy_t *emcy, co_unsigned8_t id, co_unsigned16_t eec, co_unsigned8_t er, co_unsigned8_t msef[5], void *data)

The type of a CANopen EMCY indication function, invoked when an EMCY message is received.

Parameters
emcya pointer to an EMCY consumer service.
idthe node-ID of the producer.
eecthe emergency error code.
erthe error register.
msefthe manufacturer-specific error code.
dataa pointer to user-specified data.

Definition at line 52 of file emcy.h.

Function Documentation

◆ 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.

The service is started as if by co_emcy_start().

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 333 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 360 of file emcy.c.

◆ co_emcy_start()

int co_emcy_start ( co_emcy_t emcy)

Starts an EMCY service.

Postcondition
on success, co_emcy_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_emcy_stop()

Definition at line 370 of file emcy.c.

◆ co_emcy_stop()

void co_emcy_stop ( co_emcy_t emcy)

Stops an EMCY service.

Postcondition
co_emcy_is_stopped() returns 1.
See also
co_emcy_start()

Definition at line 410 of file emcy.c.

◆ co_emcy_is_stopped()

int co_emcy_is_stopped ( const co_emcy_t emcy)

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

See also
co_emcy_start, co_emcy_stop()

Definition at line 446 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 470 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 526 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 536 of file emcy.c.

◆ co_emcy_remove()

int co_emcy_remove ( co_emcy_t emcy,
size_t  n 
)

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

Parameters
emcya pointer to an EMCY producer service.
nthe index of the message to be popped, where 0 is the most recent message.
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_find()

Definition at line 551 of file emcy.c.

◆ co_emcy_find()

ssize_t co_emcy_find ( const co_emcy_t emcy,
co_unsigned16_t  eec 
)

Finds a CANopen EMCY message in the stack.

This function returns the index of the first matching message in LIFO order.

Parameters
emcya pointer to an EMCY consumer service.
eecthe emergency error code of the message to be found.
Returns
the index of the first matching message, or -1 if not found.
See also
co_emcy_remove()

Definition at line 582 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 595 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 614 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 625 of file emcy.c.