CANopenNode
CANopen protocol stack
Loading...
Searching...
No Matches
CO_driver.h File Reference

Interface between CAN hardware and CANopenNode. More...

#include <string.h>
#include "CO_config.h"
#include "CO_driver_target.h"
+ Include dependency graph for CO_driver.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  CO_CANrx_t
 Configuration object for CAN received message for specific CANopenNode Object. More...
 
struct  CO_CANtx_t
 Configuration object for CAN transmit message for specific CANopenNode Object. More...
 
struct  CO_CANmodule_t
 Complete CAN module object. More...
 
struct  CO_storage_entry_t
 Data storage object for one entry. More...
 

Macros

#define CO_VERSION_MAJOR   4
 Major version number of CANopenNode.
 
#define CO_VERSION_MINOR   0
 Minor version number of CANopenNode.
 
#define CO_LITTLE_ENDIAN
 CO_LITTLE_ENDIAN or CO_BIG_ENDIAN must be defined.
 
#define CO_SWAP_16(x)   x
 Macro must swap bytes, if CO_BIG_ENDIAN is defined.
 
#define CO_SWAP_32(x)   x
 Macro must swap bytes, if CO_BIG_ENDIAN is defined.
 
#define CO_SWAP_64(x)   x
 Macro must swap bytes, if CO_BIG_ENDIAN is defined.
 
#define NULL   (0)
 NULL, for general usage.
 
#define true   1
 Logical true, for general use.
 
#define false   0
 Logical false, for general use.
 
#define CO_LOCK_CAN_SEND(CAN_MODULE)   /**< Lock critical section in CO_CANsend() */
 Lock critical section in CO_CANsend()
 
#define CO_UNLOCK_CAN_SEND(CAN_MODULE)   /**< Unlock critical section in CO_CANsend() */
 Unlock critical section in CO_CANsend()
 
#define CO_LOCK_EMCY(CAN_MODULE)   /**< Lock critical section in CO_errorReport() or CO_errorReset() */
 Lock critical section in CO_errorReport() or CO_errorReset()
 
#define CO_UNLOCK_EMCY(CAN_MODULE)   /**< Unlock critical section in CO_errorReport() or CO_errorReset() */
 Unlock critical section in CO_errorReport() or CO_errorReset()
 
#define CO_LOCK_OD(CAN_MODULE)   /**< Lock critical section when accessing Object Dictionary */
 Lock critical section when accessing Object Dictionary.
 
#define CO_UNLOCK_OD(CAN_MODULE)   /**< Unock critical section when accessing Object Dictionary */
 Unock critical section when accessing Object Dictionary.
 
#define CO_FLAG_READ(rxNew)   ((rxNew) != NULL)
 Check if new message has arrived.
 
#define CO_FLAG_SET(rxNew)
 Set new message flag.
 
#define CO_FLAG_CLEAR(rxNew)
 Clear new message flag.
 
#define CO_CAN_ID_NMT_SERVICE   0x000U
 0x000 Network management
 
#define CO_CAN_ID_GFC   0x001U
 0x001 Global fail-safe command
 
#define CO_CAN_ID_SYNC   0x080U
 0x080 Synchronous message
 
#define CO_CAN_ID_EMERGENCY   0x080U
 0x080 Emergency messages (+nodeID)
 
#define CO_CAN_ID_TIME   0x100U
 0x100 Time message
 
#define CO_CAN_ID_SRDO_1   0x0FFU
 0x0FF Default SRDO1 (+2*nodeID)
 
#define CO_CAN_ID_TPDO_1   0x180U
 0x180 Default TPDO1 (+nodeID)
 
#define CO_CAN_ID_RPDO_1   0x200U
 0x200 Default RPDO1 (+nodeID)
 
#define CO_CAN_ID_TPDO_2   0x280U
 0x280 Default TPDO2 (+nodeID)
 
#define CO_CAN_ID_RPDO_2   0x300U
 0x300 Default RPDO2 (+nodeID)
 
#define CO_CAN_ID_TPDO_3   0x380U
 0x380 Default TPDO3 (+nodeID)
 
#define CO_CAN_ID_RPDO_3   0x400U
 0x400 Default RPDO3 (+nodeID)
 
#define CO_CAN_ID_TPDO_4   0x480U
 0x480 Default TPDO4 (+nodeID)
 
#define CO_CAN_ID_RPDO_4   0x500U
 0x500 Default RPDO5 (+nodeID)
 
#define CO_CAN_ID_SDO_SRV   0x580U
 0x580 SDO response from server (+nodeID)
 
#define CO_CAN_ID_SDO_CLI   0x600U
 0x600 SDO request from client (+nodeID)
 
#define CO_CAN_ID_HEARTBEAT   0x700U
 0x700 Heartbeat message
 
#define CO_CAN_ID_LSS_SLV   0x7E4U
 0x7E4 LSS response from slave
 
#define CO_CAN_ID_LSS_MST   0x7E5U
 0x7E5 LSS request from master
 
#define CO_IS_RESTRICTED_CAN_ID(CAN_ID)
 Restricted CAN-IDs.
 
#define CO_CAN_ERRTX_WARNING   0x0001U
 0x0001 CAN transmitter warning
 
#define CO_CAN_ERRTX_PASSIVE   0x0002U
 0x0002 CAN transmitter passive
 
#define CO_CAN_ERRTX_BUS_OFF   0x0004U
 0x0004 CAN transmitter bus off
 
#define CO_CAN_ERRTX_OVERFLOW   0x0008U
 0x0008 CAN transmitter overflow
 
#define CO_CAN_ERRTX_PDO_LATE   0x0080U
 0x0080 TPDO is outside sync window
 
#define CO_CAN_ERRRX_WARNING   0x0100U
 0x0100 CAN receiver warning
 
#define CO_CAN_ERRRX_PASSIVE   0x0200U
 0x0200 CAN receiver passive
 
#define CO_CAN_ERRRX_OVERFLOW   0x0800U
 0x0800 CAN receiver overflow
 
#define CO_CAN_ERR_WARN_PASSIVE   0x0303U
 0x0303 combination
 

Typedefs

typedef uint_fast8_t bool_t
 Boolean data type for general use.
 
typedef signed char int8_t
 INTEGER8 in CANopen (0002h), 8-bit signed integer.
 
typedef signed int int16_t
 INTEGER16 in CANopen (0003h), 16-bit signed integer.
 
typedef signed long int int32_t
 INTEGER32 in CANopen (0004h), 32-bit signed integer.
 
typedef signed long long int int64_t
 INTEGER64 in CANopen (0015h), 64-bit signed integer.
 
typedef unsigned char uint8_t
 UNSIGNED8 in CANopen (0005h), 8-bit unsigned integer.
 
typedef unsigned int uint16_t
 UNSIGNED16 in CANopen (0006h), 16-bit unsigned integer.
 
typedef unsigned long int uint32_t
 UNSIGNED32 in CANopen (0007h), 32-bit unsigned integer.
 
typedef unsigned long long int uint64_t
 UNSIGNED64 in CANopen (001Bh), 64-bit unsigned integer.
 
typedef float float32_t
 REAL32 in CANopen (0008h), single precision floating point value, 32-bit.
 
typedef double float64_t
 REAL64 in CANopen (0011h), double precision floating point value, 64-bit.
 

Enumerations

enum  CO_ReturnError_t {
  CO_ERROR_NO = 0 , CO_ERROR_ILLEGAL_ARGUMENT = -1 , CO_ERROR_OUT_OF_MEMORY = -2 , CO_ERROR_TIMEOUT = -3 ,
  CO_ERROR_ILLEGAL_BAUDRATE = -4 , CO_ERROR_RX_OVERFLOW = -5 , CO_ERROR_RX_PDO_OVERFLOW = -6 , CO_ERROR_RX_MSG_LENGTH = -7 ,
  CO_ERROR_RX_PDO_LENGTH = -8 , CO_ERROR_TX_OVERFLOW = -9 , CO_ERROR_TX_PDO_WINDOW = -10 , CO_ERROR_TX_UNCONFIGURED = -11 ,
  CO_ERROR_OD_PARAMETERS = -12 , CO_ERROR_DATA_CORRUPT = -13 , CO_ERROR_CRC = -14 , CO_ERROR_TX_BUSY = -15 ,
  CO_ERROR_WRONG_NMT_STATE = -16 , CO_ERROR_SYSCALL = -17 , CO_ERROR_INVALID_STATE = -18 , CO_ERROR_NODE_ID_UNCONFIGURED_LSS
}
 Return values of some CANopen functions. More...
 

Functions

void CANrx_callback (void *object, void *rxMsg)
 CAN receive callback function which pre-processes received CAN message.
 
static uint16_t CO_CANrxMsg_readIdent (void *rxMsg)
 CANrx_callback() can read CAN identifier from received CAN message.
 
static uint8_t CO_CANrxMsg_readDLC (void *rxMsg)
 CANrx_callback() can read Data Length Code from received CAN message.
 
static const uint8_tCO_CANrxMsg_readData (void *rxMsg)
 CANrx_callback() can read pointer to data from received CAN message.
 
void CO_CANsetConfigurationMode (void *CANptr)
 Request CAN configuration (stopped) mode and wait until it is set.
 
void CO_CANsetNormalMode (CO_CANmodule_t *CANmodule)
 Request CAN normal (operational) mode and wait until it is set.
 
CO_ReturnError_t CO_CANmodule_init (CO_CANmodule_t *CANmodule, void *CANptr, CO_CANrx_t rxArray[], uint16_t rxSize, CO_CANtx_t txArray[], uint16_t txSize, uint16_t CANbitRate)
 Initialize CAN module object.
 
void CO_CANmodule_disable (CO_CANmodule_t *CANmodule)
 Switch off CANmodule.
 
CO_ReturnError_t CO_CANrxBufferInit (CO_CANmodule_t *CANmodule, uint16_t index, uint16_t ident, uint16_t mask, bool_t rtr, void *object, void(*CANrx_callback)(void *object, void *message))
 Configure CAN message receive buffer.
 
CO_CANtx_tCO_CANtxBufferInit (CO_CANmodule_t *CANmodule, uint16_t index, uint16_t ident, bool_t rtr, uint8_t noOfBytes, bool_t syncFlag)
 Configure CAN message transmit buffer.
 
CO_ReturnError_t CO_CANsend (CO_CANmodule_t *CANmodule, CO_CANtx_t *buffer)
 Send CAN message.
 
void CO_CANclearPendingSyncPDOs (CO_CANmodule_t *CANmodule)
 Clear all synchronous TPDOs from CAN module transmit buffers.
 
void CO_CANmodule_process (CO_CANmodule_t *CANmodule)
 Process can module - verify CAN errors.
 
static uint8_t CO_getUint8 (const void *buf)
 Get uint8_t value from memory buffer.
 
static uint16_t CO_getUint16 (const void *buf)
 Get uint16_t value from memory buffer, see CO_getUint8.
 
static uint32_t CO_getUint32 (const void *buf)
 Get uint32_t value from memory buffer, see CO_getUint8.
 
static uint8_t CO_setUint8 (void *buf, uint8_t value)
 Write uint8_t value into memory buffer.
 
static uint8_t CO_setUint16 (void *buf, uint16_t value)
 Write uint16_t value into memory buffer, see CO_setUint8.
 
static uint8_t CO_setUint32 (void *buf, uint32_t value)
 Write uint32_t value into memory buffer, see CO_setUint8.
 

Detailed Description

Interface between CAN hardware and CANopenNode.

Author
Janez Paternoster

This file is part of https://github.com/CANopenNode/CANopenNode, a CANopen Stack.

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.