CANopenNode
CO_driver.h File Reference

Interface between CAN hardware and CANopenNode. More...

#include <string.h>
#include "CO_config.h"
#include "CO_driver_target.h"

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

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()
 Lock critical section in CO_CANsend()
 
#define CO_UNLOCK_CAN_SEND()
 Unlock critical section in CO_CANsend()
 
#define CO_LOCK_EMCY()
 Lock critical section in CO_errorReport() or CO_errorReset()
 
#define CO_UNLOCK_EMCY()
 Unlock critical section in CO_errorReport() or CO_errorReset()
 
#define CO_LOCK_OD()
 Lock critical section when accessing Object Dictionary.
 
#define CO_UNLOCK_OD()
 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)   { __sync_synchronize(); rxNew = (void *)1L; }
 Set new message flag.
 
#define CO_FLAG_CLEAR(rxNew)   { __sync_synchronize(); rxNew = NULL; }
 Clear new message flag.
 
#define CO_errinfo(CANmodule, err)
 Macro for passing additional information about error. More...
 

Typedefs

typedef unsigned char 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.
 
typedef char char_t
 VISIBLE_STRING in CANopen (0009h), string of signed 8-bit values.
 
typedef unsigned char oChar_t
 OCTET_STRING in CANopen (000Ah), string of unsigned 8-bit values.
 
typedef unsigned char domain_t
 DOMAIN in CANopen (000Fh), used to transfer a large block of data.
 

Enumerations

enum  CO_Default_CAN_ID_t {
  CO_CAN_ID_NMT_SERVICE = 0x000, CO_CAN_ID_GFC = 0x001, CO_CAN_ID_SYNC = 0x080, CO_CAN_ID_EMERGENCY = 0x080,
  CO_CAN_ID_TIME = 0x100, CO_CAN_ID_SRDO_1 = 0x0FF, CO_CAN_ID_TPDO_1 = 0x180, CO_CAN_ID_RPDO_1 = 0x200,
  CO_CAN_ID_TPDO_2 = 0x280, CO_CAN_ID_RPDO_2 = 0x300, CO_CAN_ID_TPDO_3 = 0x380, CO_CAN_ID_RPDO_3 = 0x400,
  CO_CAN_ID_TPDO_4 = 0x480, CO_CAN_ID_RPDO_4 = 0x500, CO_CAN_ID_SDO_SRV = 0x580, CO_CAN_ID_SDO_CLI = 0x600,
  CO_CAN_ID_HEARTBEAT = 0x700, CO_CAN_ID_LSS_SLV = 0x7E4, CO_CAN_ID_LSS_MST = 0x7E5
}
 Default CANopen identifiers. More...
 
enum  CO_CAN_ERR_status_t {
  CO_CAN_ERRTX_WARNING = 0x0001, CO_CAN_ERRTX_PASSIVE = 0x0002, CO_CAN_ERRTX_BUS_OFF = 0x0004, CO_CAN_ERRTX_OVERFLOW = 0x0008,
  CO_CAN_ERRTX_PDO_LATE = 0x0080, CO_CAN_ERRRX_WARNING = 0x0100, CO_CAN_ERRRX_PASSIVE = 0x0200, CO_CAN_ERRRX_OVERFLOW = 0x0800,
  CO_CAN_ERR_WARN_PASSIVE = 0x0303
}
 CAN error status bitmasks. More...
 
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 = -19
}
 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. More...
 
static uint16_t CO_CANrxMsg_readIdent (void *rxMsg)
 CANrx_callback() can read CAN identifier from received CAN message. More...
 
static uint8_t CO_CANrxMsg_readDLC (void *rxMsg)
 CANrx_callback() can read Data Length Code from received CAN message. More...
 
static uint8_tCO_CANrxMsg_readData (void *rxMsg)
 CANrx_callback() can read pointer to data from received CAN message. More...
 
void CO_CANsetConfigurationMode (void *CANptr)
 Request CAN configuration (stopped) mode and wait until it is set. More...
 
void CO_CANsetNormalMode (CO_CANmodule_t *CANmodule)
 Request CAN normal (operational) mode and wait until it is set. More...
 
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. More...
 
void CO_CANmodule_disable (CO_CANmodule_t *CANmodule)
 Switch off CANmodule. More...
 
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. More...
 
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. More...
 
CO_ReturnError_t CO_CANsend (CO_CANmodule_t *CANmodule, CO_CANtx_t *buffer)
 Send CAN message. More...
 
void CO_CANclearPendingSyncPDOs (CO_CANmodule_t *CANmodule)
 Clear all synchronous TPDOs from CAN module transmit buffers. More...
 
void CO_CANmodule_process (CO_CANmodule_t *CANmodule)
 Process can module - verify CAN errors. More...
 
static uint8_t CO_getUint8 (const void *buf)
 Get uint8_t value from memory buffer. More...
 
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. More...
 
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 CANopenNode, an opensource CANopen Stack. Project home page is https://github.com/CANopenNode/CANopenNode. For more information on CANopen see http://www.can-cia.org/.

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.