1
0
Fork 0

Example files moved to own directory.

This commit is contained in:
JanezXD 2015-08-01 22:30:23 +02:00
parent 12f33a4a7b
commit 6d6a068c51
11 changed files with 48 additions and 215 deletions

View file

@ -3,10 +3,12 @@
STACK_SRC = stack
STACKDRV_SRC = stack/drvTemplate
APPL_SRC = example
INCLUDE_DIRS = $(STACK_SRC) \
-I$(STACKDRV_SRC) \
-I$(APPL_SRC) \
-I.
@ -20,9 +22,9 @@ SOURCES = $(STACKDRV_SRC)/CO_driver.c \
$(STACK_SRC)/CO_PDO.c \
$(STACK_SRC)/CO_HBconsumer.c \
$(STACK_SRC)/CO_SDOmaster.c \
CANopen.c \
CO_OD.c \
main.c
$(APPL_SRC)/CO_OD.c \
$(APPL_SRC)/main.c \
CANopen.c
OBJS = ${SOURCES:%.c=%.o}

View file

@ -1,10 +1,9 @@
/*
* CAN module object for BECK SC243 computer.
* CAN module object for Linux SocketCAN.
*
* @file CO_driver.c
* @version SVN: \$Id$
* @author Janez Paternoster
* @copyright 2004 - 2013 Janez Paternoster
* @copyright 2015 Janez Paternoster
*
* This file is part of CANopenNode, an opensource CANopen Stack.
* Project home page is <http://canopennode.sourceforge.net>.
@ -29,11 +28,6 @@
#include "CO_Emergency.h"
#include <string.h> /* for memcpy */
#ifdef USE_CAN_CALLBACKS
int CAN1callback(CanEvent event, const CanMsg *msg);
int CAN2callback(CanEvent event, const CanMsg *msg);
#endif
/******************************************************************************/
void CO_CANsetConfigurationMode(uint16_t CANbaseAddress){
@ -65,8 +59,8 @@ CO_ReturnError_t CO_CANmodule_init(
CANmodule->rxSize = rxSize;
CANmodule->txArray = txArray;
CANmodule->txSize = txSize;
CANmodule->bufferInhibitFlag = CO_false; /* True, if CAN message was sent, reset by interrupt. */
CANmodule->firstCANtxMessage = CO_true;
CANmodule->bufferInhibitFlag = false;
CANmodule->firstCANtxMessage = true;
CANmodule->error = 0;
CANmodule->CANtxCount = 0U;
CANmodule->errOld = 0U;
@ -77,7 +71,7 @@ CO_ReturnError_t CO_CANmodule_init(
rxArray[i].pFunct = NULL;
}
for(i=0U; i<txSize; i++){
txArray[i].bufferFull = CO_false;
txArray[i].bufferFull = false;
}
/* initialize port */
@ -107,14 +101,6 @@ CO_ReturnError_t CO_CANmodule_init(
canPurgeRx(CANbaseAddress);
canPurgeTx(CANbaseAddress, FALSE);
/* register callback function */
#ifdef USE_CAN_CALLBACKS
if(CANbaseAddress == CAN_PORT_CAN1)
canRegisterCallback(CANbaseAddress, CAN1callback, (1 << CAN_EVENT_RX) | (1 << CAN_EVENT_TX) | (1 << CAN_EVENT_BUS_OFF) | (1 << CAN_EVENT_OVERRUN));
else if(CANbaseAddress == CAN_PORT_CAN2)
canRegisterCallback(CANbaseAddress, CAN2callback, (1 << CAN_EVENT_RX) | (1 << CAN_EVENT_TX) | (1 << CAN_EVENT_BUS_OFF) | (1 << CAN_EVENT_OVERRUN));
#endif
return CO_ERROR_NO;
}
@ -137,7 +123,7 @@ CO_ReturnError_t CO_CANrxBufferInit(
uint16_t index,
uint16_t ident,
uint16_t mask,
CO_bool_t rtr,
bool_t rtr,
void *object,
void (*pFunct)(void *object, const CO_CANrxMsg_t *message))
{
@ -169,9 +155,9 @@ CO_CANtx_t *CO_CANtxBufferInit(
CO_CANmodule_t *CANmodule,
uint16_t index,
uint16_t ident,
CO_bool_t rtr,
bool_t rtr,
uint8_t noOfBytes,
CO_bool_t syncFlag)
bool_t syncFlag)
{
CO_CANtx_t *buffer = NULL;
@ -183,7 +169,7 @@ CO_CANtx_t *CO_CANtxBufferInit(
buffer->ident = canEncodeId(ident, FALSE, rtr);
buffer->DLC = noOfBytes;
buffer->bufferFull = CO_false;
buffer->bufferFull = false;
buffer->syncFlag = syncFlag;
}
@ -196,33 +182,6 @@ CO_ReturnError_t CO_CANsend(CO_CANmodule_t *CANmodule, CO_CANtx_t *buffer){
CO_ReturnError_t err = CO_ERROR_NO;
CanError canErr = CAN_ERROR_NO;
#ifdef USE_CAN_CALLBACKS
/* Verify overflow */
if(buffer->bufferFull){
if(!CANmodule->firstCANtxMessage){
/* don't set error, if bootup message is still on buffers */
CO_errorReport((CO_EM_t*)CANmodule->em, ERROR_CAN_TX_OVERFLOW, CO_EMC_CAN_OVERRUN, canDecodeId(buffer->ident));
}
err = CO_ERROR_TX_OVERFLOW;
}
CO_DISABLE_INTERRUPTS();
/* if CAN TX buffer is free, copy message to it */
if(CANmodule->bufferInhibitFlag == CO_false && CANmodule->CANtxCount == 0){
canErr = canSend(CANmodule->CANbaseAddress, (const CanMsg*) buffer, FALSE);
CANmodule->bufferInhibitFlag = CO_true; /* indicate, that message is on CAN module */
#ifdef CO_LOG_CAN_MESSAGES
memcpy((void*)&CANmodule->txRecord, (void*)buffer, sizeof(CO_CANtx_t));
#endif
}
/* if no buffer is free, message will be sent by interrupt */
else{
buffer->bufferFull = CO_true;
CANmodule->CANtxCount++;
}
CO_ENABLE_INTERRUPTS();
#else
CO_DISABLE_INTERRUPTS();
canErr = canSend(CANmodule->CANbaseAddress, (const CanMsg*) buffer, FALSE);
#ifdef CO_LOG_CAN_MESSAGES
@ -230,7 +189,6 @@ CO_ReturnError_t CO_CANsend(CO_CANmodule_t *CANmodule, CO_CANtx_t *buffer){
CO_logMessage((const CanMsg*) buffer);
#endif
CO_ENABLE_INTERRUPTS();
#endif
if(canErr != CAN_ERROR_NO){
CO_errorReport((CO_EM_t*)CANmodule->em, CO_EM_GENERIC_ERROR, CO_EMC_GENERIC, canErr);
@ -243,35 +201,6 @@ CO_ReturnError_t CO_CANsend(CO_CANmodule_t *CANmodule, CO_CANtx_t *buffer){
/******************************************************************************/
void CO_CANclearPendingSyncPDOs(CO_CANmodule_t *CANmodule){
#ifdef USE_CAN_CALLBACKS
uint32_t tpdoDeleted = 0U;
CO_DISABLE_INTERRUPTS();
/* Abort message from CAN module, if there is synchronous TPDO.
* Functionality is not used. */
/* delete also pending synchronous TPDOs in TX buffers */
if(CANmodule->CANtxCount != 0U){
uint16_t i;
CO_CANtx_t *buffer = &CANmodule->txArray[0];
for(i = CANmodule->txSize; i > 0U; i--){
if(buffer->bufferFull){
if(buffer->syncFlag){
buffer->bufferFull = CO_false;
CANmodule->CANtxCount--;
tpdoDeleted = 2U;
}
}
buffer++;
}
}
CO_ENABLE_INTERRUPTS();
if(tpdoDeleted != 0U){
CO_errorReport((CO_EM_t*)CANmodule->em, CO_EM_TPDO_OUTSIDE_WINDOW, CO_EMC_COMMUNICATION, tpdoDeleted);
}
#endif
}
@ -314,7 +243,7 @@ void CO_CANverifyErrors(CO_CANmodule_t *CANmodule){
}
}
else{
CO_bool_t isError = CO_isError(em, CO_EM_CAN_TX_BUS_PASSIVE);
bool_t isError = CO_isError(em, CO_EM_CAN_TX_BUS_PASSIVE);
if(isError){
CO_errorReset(em, CO_EM_CAN_TX_BUS_PASSIVE, err);
CO_errorReset(em, CO_EM_CAN_TX_OVERFLOW, err);
@ -322,7 +251,7 @@ void CO_CANverifyErrors(CO_CANmodule_t *CANmodule){
}
if((rxErrors < 96U) && (txErrors < 96U)){ /* no error */
CO_bool_t isError = CO_isError(em, CO_EM_CAN_BUS_WARNING);
bool_t isError = CO_isError(em, CO_EM_CAN_BUS_WARNING);
if(isError){
CO_errorReset(em, CO_EM_CAN_BUS_WARNING, err);
CO_errorReset(em, CO_EM_CAN_TX_OVERFLOW, err);
@ -338,109 +267,20 @@ void CO_CANverifyErrors(CO_CANmodule_t *CANmodule){
}
#ifdef USE_CAN_CALLBACKS
/******************************************************************************/
int CO_CANinterrupt(CO_CANmodule_t *CANmodule, CanEvent event, const CanMsg *msg){
/* receive interrupt (New CAN messagge is available in RX FIFO buffer) */
if(event == CAN_EVENT_RX){
CO_CANrxMsg_t *rcvMsg; /* pointer to received message in CAN module */
uint16_t i; /* index of received message */
CO_CANrx_t *buffer = NULL; /* receive message buffer from CO_CANmodule_t object. */
CO_bool_t msgMatched = CO_false;
rcvMsg = (CO_CANrxMsg_t *) msg; /* structures are aligned */
/* CAN module filters are not used, message with any standard 11-bit identifier */
/* has been received. Search rxArray form CANmodule for the same CAN-ID. */
buffer = &CANmodule->rxArray[0];
for(i = CANmodule->rxSize; i > 0; i--){
if(((rcvMsg->ident ^ buffer->ident) & buffer->mask) == 0){
msgMatched = CO_true;
break;
}
buffer++;
}
/* Call specific function, which will process the message */
if(msgMatched && (buffer != NULL) && (buffer->pFunct != NULL)){
buffer->pFunct(buffer->object, rcvMsg);
}
#ifdef CO_LOG_CAN_MESSAGES
void CO_logMessage(const CanMsg *msg);
CO_logMessage(msg);
#endif
return 0;
}
/* transmit interrupt (TX buffer is free) */
if(event == CAN_EVENT_TX){
/* First CAN message (bootup) was sent successfully */
CANmodule->firstCANtxMessage = CO_false;
/* clear flag from previous message */
CANmodule->bufferInhibitFlag = CO_false;
#ifdef CO_LOG_CAN_MESSAGES
void CO_logMessage(const CanMsg *msg);
CO_logMessage((const CanMsg*) &CANmodule->txRecord);
#endif
/* Are there any new messages waiting to be send */
if(CANmodule->CANtxCount > 0U){
uint16_t i; /* index of transmitting message */
/* first buffer */
CO_CANtx_t *buffer = &CANmodule->txArray[0];
/* search through whole array of pointers to transmit message buffers. */
for(i = CANmodule->txSize; i > 0U; i--){
/* if message buffer is full, send it. */
if(buffer->bufferFull){
buffer->bufferFull = CO_false;
CANmodule->CANtxCount--;
CANmodule->bufferInhibitFlag = CO_true; /* indicate, that message is on CAN module */
/* Copy message to CAN buffer and exit for loop. */
canSend(CANmodule->CANbaseAddress, (const CanMsg*) buffer, FALSE);
#ifdef CO_LOG_CAN_MESSAGES
memcpy((void*)&CANmodule->txRecord, (void*)buffer, sizeof(CO_CANtx_t));
#endif
break; /* exit for loop */
}
buffer++;
}/* end of for loop */
/* Clear counter if no more messages */
if(i == 0U){
CANmodule->CANtxCount = 0U;
}
}
return 0;
}
if(event == CAN_EVENT_BUS_OFF){
CANmodule->error |= 0x01;
return 0;
}
if(event == CAN_EVENT_OVERRUN){
CANmodule->error |= 0x02;
return 0;
}
return 0;
}
#else
void CO_CANreceive(CO_CANmodule_t *CANmodule){
/* pool the messages from receive buffer */
while(canPeek(CANmodule->CANbaseAddress, 0) == CAN_ERROR_NO){
CO_CANrxMsg_t rcvMsg;
uint16_t i; /* index of received message */
CO_CANrx_t *buffer;/* receive message buffer from CO_CANmodule_t object. */
CO_bool_t msgMatched = CO_false;
bool_t msgMatched = false;
canRecv(CANmodule->CANbaseAddress, (CanMsg*)&rcvMsg, 0);
buffer = &CANmodule->rxArray[0];
for(i = CANmodule->rxSize; i > 0; i--){
if(((rcvMsg.ident ^ buffer->ident) & buffer->mask) == 0){
msgMatched = CO_true;
msgMatched = true;
break;
}
buffer++;
@ -457,4 +297,3 @@ void CO_CANreceive(CO_CANmodule_t *CANmodule){
#endif
}
}
#endif

View file

@ -1,10 +1,9 @@
/*
* CAN module object for BECK SC243 computer.
* CAN module object for Linux SocketCAN.
*
* @file CO_driver.h
* @version SVN: \$Id$
* @author Janez Paternoster
* @copyright 2004 - 2013 Janez Paternoster
* @copyright 2015 Janez Paternoster
*
* This file is part of CANopenNode, an opensource CANopen Stack.
* Project home page is <http://canopennode.sourceforge.net>.
@ -29,34 +28,31 @@
#define CO_DRIVER_H
#include <clib.h> /* processor header file */
/* For documentation see file drvTemplate/CO_driver.h */
#include <stddef.h> /* for 'NULL' */
#include <stdint.h> /* for 'int8_t' to 'uint64_t' */
/* Peripheral addresses */
/* CAN module base address */
#define ADDR_CAN1 CAN_PORT_CAN1
#define ADDR_CAN2 CAN_PORT_CAN2
/* Disabling interrupts */
#define CO_DISABLE_INTERRUPTS() MaskInterrupts()
#define CO_ENABLE_INTERRUPTS() EnableInterrupts()
#define CO_DISABLE_INTERRUPTS() //MaskInterrupts()
#define CO_ENABLE_INTERRUPTS() //EnableInterrupts()
/* Other configuration */
#define CO_LOG_CAN_MESSAGES /* Call external function for each received
or transmitted CAN message. */
#define CO_SDO_BUFFER_SIZE 889 /* Override default SDO buffer size. */
//#define USE_CAN_CALLBACKS /* If defined, callbacks will be used for CAN RX and TX instead pooling.
/* Data types */
typedef unsigned char CO_bool_t;
typedef enum{
CO_false = 0,
CO_true = 1
}CO_boolval_t;
/* int8_t to uint64_t are defined in stdint.h */
typedef _Bool bool_t;
typedef float float32_t;
typedef double float64_t;
typedef char char_t;
@ -84,8 +80,7 @@ typedef enum{
}CO_ReturnError_t;
/* CAN receive message structure as aligned in CAN module. In SC2x3 this
* structure has the same alignment as in the _CanMsg_ structure from canAPI.h */
/* CAN receive message structure as aligned in CAN module. */
typedef struct{
uint32_t ident;
uint8_t DLC;
@ -102,14 +97,13 @@ typedef struct{
}CO_CANrx_t;
/* Transmit message object. In SC2x3 this structure has the same alignment
* of first three members as in the _CanMsg_ structure from canAPI.h */
/* Transmit message object. */
typedef struct{
uint32_t ident;
uint8_t DLC;
uint8_t data[8];
volatile CO_bool_t bufferFull;
volatile CO_bool_t syncFlag;
volatile bool_t bufferFull;
volatile bool_t syncFlag;
}CO_CANtx_t;
@ -123,8 +117,8 @@ typedef struct{
uint16_t rxSize;
CO_CANtx_t *txArray;
uint16_t txSize;
volatile CO_bool_t bufferInhibitFlag;
volatile CO_bool_t firstCANtxMessage;
volatile bool_t bufferInhibitFlag;
volatile bool_t firstCANtxMessage;
volatile uint8_t error;
volatile uint16_t CANtxCount;
uint32_t errOld;
@ -133,7 +127,7 @@ typedef struct{
/* Endianes */
#define CO_BIG_ENDIAN
#define CO_LITTLE_ENDIAN
/* Request CAN configuration or normal mode */
@ -166,7 +160,7 @@ CO_ReturnError_t CO_CANrxBufferInit(
uint16_t index,
uint16_t ident,
uint16_t mask,
CO_bool_t rtr,
bool_t rtr,
void *object,
void (*pFunct)(void *object, const CO_CANrxMsg_t *message));
@ -176,9 +170,9 @@ CO_CANtx_t *CO_CANtxBufferInit(
CO_CANmodule_t *CANmodule,
uint16_t index,
uint16_t ident,
CO_bool_t rtr,
bool_t rtr,
uint8_t noOfBytes,
CO_bool_t syncFlag);
bool_t syncFlag);
/* Send CAN message. */

View file

@ -1,10 +1,9 @@
/*
* Eeprom object for BECK SC243 computer.
* Eeprom object for Linux SocketCAN.
*
* @file eeprom.c
* @version SVN: \$Id$
* @author Janez Paternoster
* @copyright 2004 - 2013 Janez Paternoster
* @copyright 2015 Janez Paternoster
*
* This file is part of CANopenNode, an opensource CANopen Stack.
* Project home page is <http://canopennode.sourceforge.net>.
@ -34,7 +33,7 @@
#include <string.h> /* for memcpy */
#include <stdlib.h> /* for malloc, free */
/******************************************************************************/
/* Store parameters ***********************************************************/
static CO_SDO_abortCode_t CO_ODF_1010(CO_ODF_arg_t *ODF_arg){
CO_EE_t *ee;
uint32_t value;
@ -101,7 +100,7 @@ static CO_SDO_abortCode_t CO_ODF_1010(CO_ODF_arg_t *ODF_arg){
}
/******************************************************************************/
/* Restore default parameters *************************************************/
static CO_SDO_abortCode_t CO_ODF_1011(CO_ODF_arg_t *ODF_arg){
CO_EE_t *ee;
uint32_t value;
@ -159,7 +158,7 @@ CO_ReturnError_t CO_EE_init_1(
ee->OD_ROMAddress = OD_ROMAddress;
ee->OD_ROMSize = OD_ROMSize;
ee->OD_EEPROMCurrentIndex = 0;
ee->OD_EEPROMWriteEnable = CO_false;
ee->OD_EEPROMWriteEnable = false;
/* read the CO_OD_EEPROM from SRAM, first verify, if data are OK */
if(ee->pSRAM == 0) return CO_ERROR_OUT_OF_MEMORY;
@ -171,7 +170,7 @@ CO_ReturnError_t CO_EE_init_1(
for(i=0; i<ee->OD_EEPROMSize; i++)
(ee->OD_EEPROMAddress)[i] = (ee->pSRAM)[i];
}
ee->OD_EEPROMWriteEnable = CO_true;
ee->OD_EEPROMWriteEnable = true;
/* read the CO_OD_ROM from file and verify CRC */
void *buf = malloc(ee->OD_ROMSize);

View file

@ -1,10 +1,9 @@
/*
* Eeprom object for BECK SC243 computer.
* Eeprom object for Linux SocketCAN.
*
* @file eeprom.h
* @version SVN: \$Id$
* @author Janez Paternoster
* @copyright 2004 - 2013 Janez Paternoster
* @copyright 2015 Janez Paternoster
*
* This file is part of CANopenNode, an opensource CANopen Stack.
* Project home page is <http://canopennode.sourceforge.net>.
@ -29,11 +28,11 @@
#define EEPROM_H
/* For documentation see file genericDriver/eeprom.h */
/* For documentation see file drvTemplate/eeprom.h */
/*
* SC243 specific
* Linux specific
*
* Usage of device file system or SRAM for storing non-volatile variables.
*
@ -68,7 +67,7 @@ typedef struct{
uint32_t *pSRAM; /* SC243 specific: Pointer to start
address of the battery powered SRAM */
uint32_t OD_EEPROMCurrentIndex;
CO_bool_t OD_EEPROMWriteEnable;
bool_t OD_EEPROMWriteEnable;
}CO_EE_t;