mirror of
https://github.com/zephyrproject-rtos/canopennode.git
synced 2024-09-09 09:02:34 +02:00
Merge pull request #116 from odesenfans/can-base-address-void-ptr
Use a void pointer for the CAN device address
This commit is contained in:
commit
10cf9a30b0
30 changed files with 424 additions and 415 deletions
18
CANopen.c
18
CANopen.c
|
@ -391,17 +391,17 @@ CO_ReturnError_t CO_new(void)
|
|||
|
||||
/******************************************************************************/
|
||||
CO_ReturnError_t CO_CANinit(
|
||||
int32_t CANbaseAddress,
|
||||
void *CANdriverState,
|
||||
uint16_t bitRate)
|
||||
{
|
||||
CO_ReturnError_t err;
|
||||
|
||||
CO->CANmodule[0]->CANnormal = false;
|
||||
CO_CANsetConfigurationMode(CANbaseAddress);
|
||||
CO_CANsetConfigurationMode(CANdriverState);
|
||||
|
||||
err = CO_CANmodule_init(
|
||||
CO->CANmodule[0],
|
||||
CANbaseAddress,
|
||||
CANdriverState,
|
||||
CO_CANmodule_rxArray0,
|
||||
CO_RXCAN_NO_MSGS,
|
||||
CO_CANmodule_txArray0,
|
||||
|
@ -663,7 +663,7 @@ CO_ReturnError_t CO_CANopenInit(
|
|||
|
||||
/******************************************************************************/
|
||||
CO_ReturnError_t CO_init(
|
||||
int32_t CANbaseAddress,
|
||||
void *CANdriverState,
|
||||
uint8_t nodeId,
|
||||
uint16_t bitRate)
|
||||
{
|
||||
|
@ -674,15 +674,15 @@ CO_ReturnError_t CO_init(
|
|||
return err;
|
||||
}
|
||||
|
||||
err = CO_CANinit(CANbaseAddress, bitRate);
|
||||
err = CO_CANinit(CANdriverState, bitRate);
|
||||
if (err) {
|
||||
CO_delete(CANbaseAddress);
|
||||
CO_delete(CANdriverState);
|
||||
return err;
|
||||
}
|
||||
|
||||
err = CO_CANopenInit(nodeId);
|
||||
if (err) {
|
||||
CO_delete(CANbaseAddress);
|
||||
CO_delete(CANdriverState);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
@ -691,12 +691,12 @@ CO_ReturnError_t CO_init(
|
|||
|
||||
|
||||
/******************************************************************************/
|
||||
void CO_delete(int32_t CANbaseAddress){
|
||||
void CO_delete(void *CANdriverState){
|
||||
#ifndef CO_USE_GLOBALS
|
||||
int16_t i;
|
||||
#endif
|
||||
|
||||
CO_CANsetConfigurationMode(CANbaseAddress);
|
||||
CO_CANsetConfigurationMode(CANdriverState);
|
||||
CO_CANmodule_disable(CO->CANmodule[0]);
|
||||
|
||||
#ifndef CO_USE_GLOBALS
|
||||
|
|
12
CANopen.h
12
CANopen.h
|
@ -192,13 +192,13 @@ CO_ReturnError_t CO_new(void);
|
|||
*
|
||||
* Function must be called in the communication reset section.
|
||||
*
|
||||
* @param CANbaseAddress Address of the CAN module, passed to CO_CANmodule_init().
|
||||
* @param CANdriverState Pointer to the CAN module, passed to CO_CANmodule_init().
|
||||
* @param bitRate CAN bit rate.
|
||||
* @return #CO_ReturnError_t: CO_ERROR_NO, CO_ERROR_ILLEGAL_ARGUMENT,
|
||||
* CO_ERROR_ILLEGAL_BAUDRATE, CO_ERROR_OUT_OF_MEMORY
|
||||
*/
|
||||
CO_ReturnError_t CO_CANinit(
|
||||
int32_t CANbaseAddress,
|
||||
void *CANdriverState,
|
||||
uint16_t bitRate);
|
||||
|
||||
|
||||
|
@ -234,7 +234,7 @@ CO_ReturnError_t CO_CANopenInit(
|
|||
*
|
||||
* Function must be called in the communication reset section.
|
||||
*
|
||||
* @param CANbaseAddress Address of the CAN module, passed to CO_CANmodule_init().
|
||||
* @param CANdriverState Pointer to the user-defined CAN base structure, passed to CO_CANmodule_init().
|
||||
* @param nodeId Node ID of the CANopen device (1 ... 127).
|
||||
* @param bitRate CAN bit rate.
|
||||
*
|
||||
|
@ -242,7 +242,7 @@ CO_ReturnError_t CO_CANopenInit(
|
|||
* CO_ERROR_OUT_OF_MEMORY, CO_ERROR_ILLEGAL_BAUDRATE
|
||||
*/
|
||||
CO_ReturnError_t CO_init(
|
||||
int32_t CANbaseAddress,
|
||||
void *CANdriverState,
|
||||
uint8_t nodeId,
|
||||
uint16_t bitRate);
|
||||
|
||||
|
@ -252,9 +252,9 @@ CO_ReturnError_t CO_init(
|
|||
/**
|
||||
* Delete CANopen object and free memory. Must be called at program exit.
|
||||
*
|
||||
* @param CANbaseAddress Address of the CAN module, passed to CO_CANmodule_init().
|
||||
* @param CANdriverState Pointer to the user-defined CAN base structure, passed to CO_CANmodule_init().
|
||||
*/
|
||||
void CO_delete(int32_t CANbaseAddress);
|
||||
void CO_delete(void *CANdriverState);
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -51,6 +51,12 @@
|
|||
#define TMR_TASK_INTERVAL (1000) /* Interval of tmrTask thread in microseconds */
|
||||
#define INCREMENT_1MS(var) (var++) /* Increment 1ms variable in tmrTask */
|
||||
|
||||
/**
|
||||
* User-defined CAN base structure, passed as argument to CO_init.
|
||||
*/
|
||||
struct CANbase {
|
||||
uintptr_t baseAddress; /**< Base address of the CAN module */
|
||||
};
|
||||
|
||||
/* Global variables and objects */
|
||||
volatile uint16_t CO_timer1ms = 0U; /* variable increments each millisecond */
|
||||
|
@ -76,10 +82,12 @@ int main (void){
|
|||
uint16_t timer1msPrevious;
|
||||
|
||||
/* disable CAN and CAN interrupts */
|
||||
|
||||
struct CANbase canBase = {
|
||||
.baseAddress = 0u, /* CAN module address */
|
||||
};
|
||||
|
||||
/* initialize CANopen */
|
||||
err = CO_init(0/* CAN module address */, 10/* NodeID */, 125 /* bit rate */);
|
||||
err = CO_init(&canBase, 10/* NodeID */, 125 /* bit rate */);
|
||||
if(err != CO_ERROR_NO){
|
||||
while(1);
|
||||
/* CO_errorReport(CO->em, CO_EM_MEMORY_ALLOCATION_ERROR, CO_EMC_SOFTWARE_INTERNAL, err); */
|
||||
|
@ -122,7 +130,7 @@ int main (void){
|
|||
|
||||
|
||||
/* delete objects from memory */
|
||||
CO_delete(0/* CAN module address */);
|
||||
CO_delete((void*) 0/* CAN module address */);
|
||||
|
||||
|
||||
/* reset */
|
||||
|
|
|
@ -81,7 +81,7 @@ void fromCANMessage(CANMessage *msg, CO_CANrxMsg_t *CO_msg) {
|
|||
}
|
||||
|
||||
/******************************************************************************/
|
||||
void CO_CANsetConfigurationMode(int32_t CANbaseAddress){
|
||||
void CO_CANsetConfigurationMode(void *CANdriverState){
|
||||
/* Put CAN module in configuration mode */
|
||||
}
|
||||
|
||||
|
@ -100,7 +100,7 @@ void CO_CANsetNormalMode(CO_CANmodule_t *CANmodule){
|
|||
/******************************************************************************/
|
||||
CO_ReturnError_t CO_CANmodule_init(
|
||||
CO_CANmodule_t *CANmodule,
|
||||
int32_t CANbaseAddress,
|
||||
void *CANdriverState,
|
||||
CO_CANrx_t rxArray[],
|
||||
uint16_t rxSize,
|
||||
CO_CANtx_t txArray[],
|
||||
|
@ -116,7 +116,7 @@ CO_ReturnError_t CO_CANmodule_init(
|
|||
}
|
||||
|
||||
/* Configure object variables */
|
||||
CANmodule->CANbaseAddress = CANbaseAddress;
|
||||
CANmodule->CANdriverState = CANdriverState;
|
||||
CANmodule->rxArray = rxArray;
|
||||
CANmodule->rxSize = rxSize;
|
||||
CANmodule->txArray = txArray;
|
||||
|
|
|
@ -130,7 +130,7 @@ typedef struct{
|
|||
|
||||
/* CAN module object. */
|
||||
typedef struct{
|
||||
int32_t CANbaseAddress;
|
||||
void *CANdriverState;
|
||||
CO_CANrx_t *rxArray;
|
||||
uint16_t rxSize;
|
||||
CO_CANtx_t *txArray;
|
||||
|
@ -150,14 +150,14 @@ typedef struct{
|
|||
|
||||
|
||||
/* Request CAN configuration or normal mode */
|
||||
void CO_CANsetConfigurationMode(int32_t CANbaseAddress);
|
||||
void CO_CANsetConfigurationMode(void *CANdriverState);
|
||||
void CO_CANsetNormalMode(CO_CANmodule_t *CANmodule);
|
||||
|
||||
|
||||
/* Initialize CAN module object. */
|
||||
CO_ReturnError_t CO_CANmodule_init(
|
||||
CO_CANmodule_t *CANmodule,
|
||||
int32_t CANbaseAddress,
|
||||
void *CANdriverState,
|
||||
CO_CANrx_t rxArray[],
|
||||
uint16_t rxSize,
|
||||
CO_CANtx_t txArray[],
|
||||
|
|
|
@ -151,13 +151,13 @@ void CO_CANrxMsgHandler(void *object, const CO_CANrxMsg_t *message){
|
|||
}
|
||||
|
||||
/******************************************************************************/
|
||||
void CO_CANsetConfigurationMode(uint16_t CANbaseAddress){
|
||||
void CO_CANsetConfigurationMode(void *CANdriverState){
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************/
|
||||
void CO_CANsetNormalMode(CO_CANmodule_t *CANmodule){
|
||||
|
||||
|
||||
Chip_CAN_SetAFMode(LPC_CANAF, CAN_AF_NORMAL_MODE);
|
||||
|
||||
CANmodule->CANnormal = true;
|
||||
|
@ -167,7 +167,7 @@ void CO_CANsetNormalMode(CO_CANmodule_t *CANmodule){
|
|||
/******************************************************************************/
|
||||
CO_ReturnError_t CO_CANmodule_init(
|
||||
CO_CANmodule_t *CANmodule,
|
||||
uint16_t CANbaseAddress,
|
||||
void *CANdriverState,
|
||||
CO_CANrx_t rxArray[],
|
||||
uint16_t rxSize,
|
||||
CO_CANtx_t txArray[],
|
||||
|
@ -176,33 +176,33 @@ CO_ReturnError_t CO_CANmodule_init(
|
|||
{
|
||||
uint16_t i;
|
||||
uint8_t nodeId=0;
|
||||
|
||||
|
||||
/* verify arguments */
|
||||
if(CANmodule==NULL || rxArray==NULL || txArray==NULL){
|
||||
return CO_ERROR_ILLEGAL_ARGUMENT;
|
||||
}
|
||||
|
||||
/* Configure object variables */
|
||||
CANmodule->CANbaseAddress = CANbaseAddress;
|
||||
CANmodule->CANdriverState = CANdriverState;
|
||||
CANmodule->rxArray = rxArray;
|
||||
CANmodule->rxSize = rxSize;
|
||||
CANmodule->txArray = txArray;
|
||||
CANmodule->txSize = txSize;
|
||||
CANmodule->CANnormal = false;
|
||||
#if AF_LUT_USED
|
||||
#if AF_LUT_USED
|
||||
CANmodule->useCANrxFilters = (rxSize <= 32U) ? true : false;/* microcontroller dependent */
|
||||
#else
|
||||
CANmodule->useCANrxFilters = false;
|
||||
#endif
|
||||
#endif
|
||||
CANmodule->bufferInhibitFlag = false;
|
||||
CANmodule->firstCANtxMessage = true;
|
||||
CANmodule->CANtxCount = 0U;
|
||||
CANmodule->errOld = 0U;
|
||||
CANmodule->em = NULL;
|
||||
|
||||
|
||||
|
||||
DEBUGOUT("CO_CANmodule_init Baud: %d\r\n",(CANbitRate * 1000));
|
||||
|
||||
|
||||
for(i=0U; i<rxSize; i++){
|
||||
rxArray[i].ident = 0U;
|
||||
rxArray[i].pFunct = CO_CANrxMsgHandler;
|
||||
|
@ -214,7 +214,7 @@ CO_ReturnError_t CO_CANmodule_init(
|
|||
Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 4, (IOCON_FUNC2 | IOCON_MODE_INACT | IOCON_DIGMODE_EN));
|
||||
/* CAN_TD2*/
|
||||
Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 5, (IOCON_FUNC2 | IOCON_MODE_INACT | IOCON_DIGMODE_EN ));
|
||||
|
||||
|
||||
/* CAN_TERMINATION swapped over with nCAN_HEARTBEAT, so this pin is actually CAN_TERMINATION*/
|
||||
Chip_IOCON_PinMuxSet(LPC_IOCON, 1, 21, (IOCON_FUNC0 | IOCON_MODE_INACT ));
|
||||
Chip_GPIO_WriteDirBit(LPC_GPIO, 1, 21, true);
|
||||
|
@ -223,7 +223,7 @@ CO_ReturnError_t CO_CANmodule_init(
|
|||
Chip_IOCON_PinMuxSet(LPC_IOCON, CAN_RUN_LED_PORT, CAN_RUN_LED_PIN, IOCON_FUNC0);
|
||||
Chip_GPIO_WriteDirBit(LPC_GPIO, CAN_RUN_LED_PORT, CAN_RUN_LED_PIN, true);
|
||||
Chip_GPIO_WritePortBit(LPC_GPIO, CAN_RUN_LED_PORT,CAN_RUN_LED_PIN, true);
|
||||
|
||||
|
||||
Chip_IOCON_PinMuxSet(LPC_IOCON, CAN_NODE_ID_0_PORT, CAN_NODE_ID_0_PIN, (IOCON_FUNC0 | IOCON_MODE_INACT));
|
||||
Chip_GPIO_WriteDirBit(LPC_GPIO, CAN_NODE_ID_0_PORT, CAN_NODE_ID_0_PIN, false);
|
||||
Chip_IOCON_PinMuxSet(LPC_IOCON, CAN_NODE_ID_1_PORT, CAN_NODE_ID_1_PIN, (IOCON_FUNC0 | IOCON_MODE_INACT));
|
||||
|
@ -234,7 +234,7 @@ CO_ReturnError_t CO_CANmodule_init(
|
|||
Chip_GPIO_WriteDirBit(LPC_GPIO, CAN_NODE_ID_3_PORT, CAN_NODE_ID_3_PIN, false);
|
||||
Chip_IOCON_PinMuxSet(LPC_IOCON, CAN_NODE_ID_4_PORT, CAN_NODE_ID_4_PIN, (IOCON_FUNC0 | IOCON_MODE_INACT));
|
||||
Chip_GPIO_WriteDirBit(LPC_GPIO, CAN_NODE_ID_4_PORT, CAN_NODE_ID_4_PIN, false);
|
||||
|
||||
|
||||
nodeId = 0;
|
||||
nodeId |= (uint8_t)(Chip_GPIO_GetPinState(LPC_GPIO, CAN_NODE_ID_0_PORT, CAN_NODE_ID_0_PIN) ? 1: 0);
|
||||
nodeId |= (uint8_t)(Chip_GPIO_GetPinState(LPC_GPIO, CAN_NODE_ID_1_PORT, CAN_NODE_ID_1_PIN) ? (1<<1): 0);
|
||||
|
@ -244,7 +244,7 @@ CO_ReturnError_t CO_CANmodule_init(
|
|||
|
||||
DEBUGOUT("CO_CANmodule_init nodeId: 0x%x\r\n",nodeId);
|
||||
OD_CANNodeID = nodeId;
|
||||
|
||||
|
||||
/* Configure CAN module registers */
|
||||
Chip_CAN_Init(LPC_CAN, LPC_CANAF, LPC_CANAF_RAM);
|
||||
/* Configure CAN timing */
|
||||
|
@ -255,7 +255,7 @@ CO_ReturnError_t CO_CANmodule_init(
|
|||
/* Configure CAN module hardware filters */
|
||||
if(CANmodule->useCANrxFilters){
|
||||
DEBUGOUT("\tCAN Rx Acceptance Filters ON \r\n");
|
||||
#if AF_LUT_USED
|
||||
#if AF_LUT_USED
|
||||
/* CAN module filters are used, they will be configured with */
|
||||
/* CO_CANrxBufferInit() functions, called by separate CANopen */
|
||||
/* init functions. */
|
||||
|
@ -270,11 +270,11 @@ CO_ReturnError_t CO_CANmodule_init(
|
|||
#else
|
||||
Chip_CAN_SetAFMode(LPC_CANAF, CAN_AF_NORMAL_MODE);
|
||||
#endif /*FULL_CAN_AF_USED*/
|
||||
|
||||
#else
|
||||
|
||||
#else
|
||||
DEBUGOUT("\tCAN Rx Acceptance Filters NOT OPERATIONAL for the debug stages\r\n");
|
||||
Chip_CAN_SetAFMode(LPC_CANAF, CAN_AF_BYBASS_MODE);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -282,12 +282,12 @@ CO_ReturnError_t CO_CANmodule_init(
|
|||
/* identifier will be received */
|
||||
/* Configure mask 0 so, that all messages with standard identifier are accepted */
|
||||
Chip_CAN_SetAFMode(LPC_CANAF, CAN_AF_BYBASS_MODE);
|
||||
|
||||
|
||||
DEBUGOUT("\tCAN Rx Acceptance Filters Bypass \r\n");
|
||||
}
|
||||
/* configure CAN interrupt registers */
|
||||
NVIC_EnableIRQ(CAN_IRQn);
|
||||
|
||||
|
||||
return CO_ERROR_NO;
|
||||
}
|
||||
|
||||
|
@ -308,9 +308,9 @@ uint16_t CO_CANrxMsg_readIdent(const CO_CANrxMsg_t *rxMsg){
|
|||
uint16_t CO_CAN_Get_My_NodeID(void){
|
||||
|
||||
uint16_t myNodeId=0;
|
||||
|
||||
|
||||
myNodeId = Chip_GPIO_ReadPortBit(LPC_GPIO, CAN_NODE_ID_0_PORT, CAN_NODE_ID_0_PIN);
|
||||
|
||||
|
||||
return myNodeId;
|
||||
}
|
||||
/******************************************************************************/
|
||||
|
@ -324,7 +324,7 @@ CO_ReturnError_t CO_CANrxBufferInit(
|
|||
void (*pFunct)(void *object, const CO_CANrxMsg_t *message))
|
||||
{
|
||||
CO_ReturnError_t ret = CO_ERROR_NO;
|
||||
|
||||
|
||||
if((CANmodule!=NULL) && (object!=NULL) && (pFunct!=NULL) && (index < CANmodule->rxSize)){
|
||||
/* buffer, which will be configured */
|
||||
CO_CANrx_t *buffer = &CANmodule->rxArray[index];
|
||||
|
@ -359,7 +359,7 @@ CO_CANtx_t *CO_CANtxBufferInit(
|
|||
bool_t syncFlag)
|
||||
{
|
||||
CO_CANtx_t *buffer = NULL;
|
||||
|
||||
|
||||
if((CANmodule != NULL) && (index < CANmodule->txSize)){
|
||||
/* get specific buffer */
|
||||
buffer = &CANmodule->txArray[index];
|
||||
|
@ -382,7 +382,7 @@ CO_CANtx_t *CO_CANtxBufferInit(
|
|||
CO_ReturnError_t CO_CANsend(CO_CANmodule_t *CANmodule, CO_CANtx_t *buffer){
|
||||
CO_ReturnError_t err = CO_ERROR_NO;
|
||||
CAN_BUFFER_ID_T TxBuf;
|
||||
|
||||
|
||||
/* Verify overflow */
|
||||
if(buffer->bufferFull){
|
||||
if(!CANmodule->firstCANtxMessage){
|
||||
|
@ -391,16 +391,16 @@ CO_ReturnError_t CO_CANsend(CO_CANmodule_t *CANmodule, CO_CANtx_t *buffer){
|
|||
}
|
||||
err = CO_ERROR_TX_OVERFLOW;
|
||||
}
|
||||
|
||||
|
||||
CO_LOCK_CAN_SEND();
|
||||
|
||||
|
||||
/* if CAN TX buffer is free, copy message to it */
|
||||
TxBuf = Chip_CAN_GetFreeTxBuf(LPC_CAN);
|
||||
if( TxBuf < CAN_BUFFER_LAST && CANmodule->CANtxCount == 0){
|
||||
CANmodule->bufferInhibitFlag = buffer->syncFlag;
|
||||
/* copy message and txRequest */
|
||||
Chip_CAN_Send(LPC_CAN, TxBuf,(CAN_MSG_T*)buffer);
|
||||
|
||||
|
||||
/*DEBUGOUT("CO_CANsend!!!\r\n");*/
|
||||
/*PrintCANMsg((CAN_MSG_T*)buffer);*/
|
||||
}
|
||||
|
@ -422,12 +422,12 @@ void CO_CANclearPendingSyncPDOs(CO_CANmodule_t *CANmodule){
|
|||
uint32_t tpdoDeleted = 0U;
|
||||
|
||||
CO_LOCK_CAN_SEND();
|
||||
|
||||
|
||||
/* Abort message from CAN module, if there is synchronous TPDO.
|
||||
* Take special care with this functionality. */
|
||||
/*Check if any of the buffer is pending transmition and bufferInhibitFlag is true*/
|
||||
if(( 0 == (Chip_CAN_GetGlobalStatus(LPC_CAN) & CAN_GSR_TBS)) && CANmodule->bufferInhibitFlag){
|
||||
|
||||
|
||||
/* if not already in progress, a pending Transmission Request for
|
||||
the selected Transmit Buffer is cancelled. */
|
||||
Chip_CAN_SetCmd(LPC_CAN, CAN_CMR_STB(CAN_BUFFER_1) | CAN_CMR_AT);
|
||||
|
@ -470,8 +470,8 @@ void CO_CANverifyErrors(CO_CANmodule_t *CANmodule){
|
|||
|
||||
/* get error counters from module. Id possible, function may use different way to
|
||||
* determine errors. */
|
||||
rxErrors = CAN_GSR_RXERR(Chip_CAN_GetGlobalStatus(LPC_CAN));
|
||||
txErrors = CAN_GSR_TXERR(Chip_CAN_GetGlobalStatus(LPC_CAN));
|
||||
rxErrors = CAN_GSR_RXERR(Chip_CAN_GetGlobalStatus(LPC_CAN));
|
||||
txErrors = CAN_GSR_TXERR(Chip_CAN_GetGlobalStatus(LPC_CAN));
|
||||
overflow = (Chip_CAN_GetGlobalStatus(LPC_CAN) & CAN_GSR_DOS) ; /*CAN Data Overrun Status */ CANmodule->txSize;
|
||||
|
||||
err = ((uint32_t)txErrors << 16) | ((uint32_t)rxErrors << 8) | overflow;
|
||||
|
@ -532,19 +532,19 @@ void CO_CANinterrupt(CO_CANmodule_t *CANmodule){
|
|||
CO_CANrx_t *buffer = NULL; /* receive message buffer from CO_CANmodule_t object. */
|
||||
bool_t msgMatched = false;
|
||||
CAN_BUFFER_ID_T TxBuf;
|
||||
|
||||
|
||||
/*Read the int status register */
|
||||
IntStatus = Chip_CAN_GetIntStatus(LPC_CAN);
|
||||
|
||||
|
||||
|
||||
/* receive interrupt */
|
||||
if(IntStatus & CAN_ICR_RI){
|
||||
|
||||
|
||||
/* get message from module */
|
||||
Chip_CAN_Receive(LPC_CAN,(CAN_MSG_T*)&RcvMsgBuf);
|
||||
rcvMsg = &RcvMsgBuf;
|
||||
rcvMsgIdent = rcvMsg->ident;
|
||||
|
||||
|
||||
#if AF_LUT_USED /*Implement once AF will be used*/
|
||||
if(CANmodule->useCANrxFilters){
|
||||
|
||||
|
@ -560,7 +560,7 @@ void CO_CANinterrupt(CO_CANmodule_t *CANmodule){
|
|||
}
|
||||
}
|
||||
else
|
||||
#endif
|
||||
#endif
|
||||
{
|
||||
/* 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. */
|
||||
|
@ -572,18 +572,18 @@ void CO_CANinterrupt(CO_CANmodule_t *CANmodule){
|
|||
}
|
||||
buffer++;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/* Call specific function, which will process the message */
|
||||
if(msgMatched && (buffer != NULL) && (buffer->pFunct != NULL)){
|
||||
|
||||
|
||||
buffer->pFunct(buffer->object, rcvMsg);
|
||||
}
|
||||
else
|
||||
{
|
||||
DEBUGOUT("Unsupported Message Received!!!\r\n");
|
||||
PrintCANMsg((CAN_MSG_T*)rcvMsg);
|
||||
DEBUGOUT("Unsupported Message Received!!!\r\n");
|
||||
PrintCANMsg((CAN_MSG_T*)rcvMsg);
|
||||
}
|
||||
|
||||
/* Clear interrupt flag */
|
||||
|
@ -703,7 +703,7 @@ static void PrintAFLUT(void)
|
|||
CAN_EXT_ID_ENTRY_T ExtEntry;
|
||||
CAN_STD_ID_RANGE_ENTRY_T StdGrpEntry;
|
||||
CAN_EXT_ID_RANGE_ENTRY_T ExtGrpEntry;
|
||||
|
||||
|
||||
DEBUGOUT("Print AF LUT... \r\n");
|
||||
#if FULL_CAN_AF_USED
|
||||
/* Full CAN Table */
|
||||
|
@ -771,7 +771,7 @@ static void ChangeAFLUT(void)
|
|||
CAN_STD_ID_RANGE_ENTRY_T StdGrpEntry = {{CAN_CTRL_NO, 0, 0x7A0}, {CAN_CTRL_NO, 0, 0x7B0}};
|
||||
CAN_EXT_ID_RANGE_ENTRY_T ExtGrpEntry = {{CAN_CTRL_NO, ((1 << 11) | 0x7A0)}, {CAN_CTRL_NO, ((1 << 11) | 0x7B0)}};
|
||||
|
||||
|
||||
|
||||
#if FULL_CAN_AF_USED
|
||||
/* Edit Full CAN Table */
|
||||
Chip_CAN_InsertFullCANEntry(LPC_CANAF, LPC_CANAF_RAM, &FullEntry);
|
||||
|
@ -835,7 +835,7 @@ static void ChangeAFLUT(void)
|
|||
Chip_CAN_RemoveGroupEXTEntry(LPC_CANAF, LPC_CANAF_RAM, Chip_CAN_GetEntriesNum(LPC_CANAF, LPC_CANAF_RAM, CANAF_RAM_EFF_GRP_SEC) - 1);
|
||||
Chip_CAN_RemoveGroupEXTEntry(LPC_CANAF, LPC_CANAF_RAM, Chip_CAN_GetEntriesNum(LPC_CANAF, LPC_CANAF_RAM, CANAF_RAM_EFF_GRP_SEC) / 2);
|
||||
PrintAFLUT();
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -153,7 +153,7 @@ typedef struct{
|
|||
|
||||
/* CAN module object. */
|
||||
typedef struct{
|
||||
uint16_t CANbaseAddress;
|
||||
void *CANdriverState;
|
||||
CO_CANrx_t *rxArray;
|
||||
uint16_t rxSize;
|
||||
CO_CANtx_t *txArray;
|
||||
|
@ -173,14 +173,14 @@ typedef struct{
|
|||
|
||||
|
||||
/* Request CAN configuration or normal mode */
|
||||
void CO_CANsetConfigurationMode(uint16_t CANbaseAddress);
|
||||
void CO_CANsetConfigurationMode(void *CANdriverState);
|
||||
void CO_CANsetNormalMode(CO_CANmodule_t *CANmodule);
|
||||
|
||||
|
||||
/* Initialize CAN module object. */
|
||||
CO_ReturnError_t CO_CANmodule_init(
|
||||
CO_CANmodule_t *CANmodule,
|
||||
uint16_t CANbaseAddress,
|
||||
void *CANdriverState,
|
||||
CO_CANrx_t rxArray[],
|
||||
uint16_t rxSize,
|
||||
CO_CANtx_t txArray[],
|
||||
|
|
|
@ -52,7 +52,7 @@ extern const CO_CANbitRateData_t CO_CANbitRateData[8];
|
|||
|
||||
|
||||
/******************************************************************************/
|
||||
void CO_CANsetConfigurationMode(uint16_t CANbaseAddress){
|
||||
void CO_CANsetConfigurationMode(void *CANdriverState){
|
||||
|
||||
/* sets the module as running */
|
||||
MCF_FlexCAN_CANMCR &= ~MCF_FlexCAN_CANMCR_STOP;
|
||||
|
@ -80,7 +80,7 @@ void CO_CANsetNormalMode(CO_CANmodule_t *CANmodule){
|
|||
/******************************************************************************/
|
||||
CO_ReturnError_t CO_CANmodule_init(
|
||||
CO_CANmodule_t *CANmodule,
|
||||
uint16_t CANbaseAddress,
|
||||
void *CANdriverState,
|
||||
CO_CANrx_t rxArray[],
|
||||
uint16_t rxSize,
|
||||
CO_CANtx_t txArray[],
|
||||
|
@ -96,7 +96,7 @@ CO_ReturnError_t CO_CANmodule_init(
|
|||
}
|
||||
|
||||
/* Configure object variables */
|
||||
CANmodule->CANbaseAddress = CANbaseAddress;
|
||||
CANmodule->CANdriverState = CANdriverState;
|
||||
CANmodule->CANmsgBuffSize = nb_CANbuff;
|
||||
CANmodule->rxArray = rxArray;
|
||||
CANmodule->rxSize = rxSize;
|
||||
|
@ -209,7 +209,7 @@ CO_ReturnError_t CO_CANmodule_init(
|
|||
|
||||
/******************************************************************************/
|
||||
void CO_CANmodule_disable(CO_CANmodule_t *CANmodule){
|
||||
CO_CANsetConfigurationMode(CANmodule->CANbaseAddress);
|
||||
CO_CANsetConfigurationMode(CANmodule->CANdriverState);
|
||||
}
|
||||
|
||||
|
||||
|
@ -248,7 +248,7 @@ CO_ReturnError_t CO_CANrxBufferInit(
|
|||
|
||||
/* Set CAN hardware module filter and mask. */
|
||||
if(CANmodule->useCANrxFilters){
|
||||
//filters are not used.
|
||||
//filters are not used.
|
||||
}
|
||||
}
|
||||
else{
|
||||
|
@ -290,7 +290,6 @@ CO_CANtx_t *CO_CANtxBufferInit(
|
|||
/******************************************************************************/
|
||||
CO_ReturnError_t CO_CANsend(CO_CANmodule_t *CANmodule, CO_CANtx_t *buffer){
|
||||
CO_ReturnError_t err = CO_ERROR_NO;
|
||||
uint16_t addr = CANmodule->CANbaseAddress;
|
||||
uint8_t i;
|
||||
|
||||
/* Verify overflow */
|
||||
|
|
|
@ -359,7 +359,7 @@ typedef struct{
|
|||
|
||||
/* CAN module object. */
|
||||
typedef struct{
|
||||
uint16_t CANbaseAddress;
|
||||
void *CANdriverState;
|
||||
CO_CANrxMsg_t *CANmsgBuff;
|
||||
uint8_t CANmsgBuffSize;
|
||||
CO_CANrx_t *rxArray;
|
||||
|
@ -381,7 +381,7 @@ typedef struct{
|
|||
|
||||
|
||||
/* Request CAN configuration or normal mode */
|
||||
void CO_CANsetConfigurationMode(uint16_t CANbaseAddress);
|
||||
void CO_CANsetConfigurationMode(void *CANdriverState);
|
||||
void CO_CANsetNormalMode(CO_CANmodule_t *CANmodule);
|
||||
|
||||
|
||||
|
@ -393,7 +393,7 @@ void CO_CANsetNormalMode(CO_CANmodule_t *CANmodule);
|
|||
*/
|
||||
CO_ReturnError_t CO_CANmodule_init(
|
||||
CO_CANmodule_t *CANmodule,
|
||||
uint16_t CANbaseAddress,
|
||||
void *CANdriverState,
|
||||
CO_CANrx_t rxArray[],
|
||||
uint16_t rxSize,
|
||||
CO_CANtx_t txArray[],
|
||||
|
|
|
@ -61,7 +61,7 @@
|
|||
|
||||
|
||||
/* Macro and Constants - CAN module registers and DMA registers - offset. */
|
||||
#define CAN_REG(base, offset) (*((volatile uint16_t *) (base + offset)))
|
||||
#define CAN_REG(base, offset) (*((volatile uint16_t *) (((uintptr_t) base) + offset)))
|
||||
|
||||
#define C_CTRL1 0x00
|
||||
#define C_CTRL2 0x02
|
||||
|
@ -120,29 +120,29 @@
|
|||
|
||||
|
||||
/******************************************************************************/
|
||||
void CO_CANsetConfigurationMode(uint16_t CANbaseAddress){
|
||||
uint16_t C_CTRL1copy = CAN_REG(CANbaseAddress, C_CTRL1);
|
||||
void CO_CANsetConfigurationMode(void *CANdriverState){
|
||||
uint16_t C_CTRL1copy = CAN_REG(CANdriverState, C_CTRL1);
|
||||
|
||||
/* set REQOP = 0x4 */
|
||||
C_CTRL1copy &= 0xFCFF;
|
||||
C_CTRL1copy |= 0x0400;
|
||||
CAN_REG(CANbaseAddress, C_CTRL1) = C_CTRL1copy;
|
||||
CAN_REG(CANdriverState, C_CTRL1) = C_CTRL1copy;
|
||||
|
||||
/* while OPMODE != 4 */
|
||||
while((CAN_REG(CANbaseAddress, C_CTRL1) & 0x00E0) != 0x0080);
|
||||
while((CAN_REG(CANdriverState, C_CTRL1) & 0x00E0) != 0x0080);
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************/
|
||||
void CO_CANsetNormalMode(CO_CANmodule_t *CANmodule){
|
||||
uint16_t C_CTRL1copy = CAN_REG(CANmodule->CANbaseAddress, C_CTRL1);
|
||||
uint16_t C_CTRL1copy = CAN_REG(CANmodule->CANdriverState, C_CTRL1);
|
||||
|
||||
/* set REQOP = 0x0 */
|
||||
C_CTRL1copy &= 0xF8FF;
|
||||
CAN_REG(CANmodule->CANbaseAddress, C_CTRL1) = C_CTRL1copy;
|
||||
CAN_REG(CANmodule->CANdriverState, C_CTRL1) = C_CTRL1copy;
|
||||
|
||||
/* while OPMODE != 0 */
|
||||
while((CAN_REG(CANmodule->CANbaseAddress, C_CTRL1) & 0x00E0) != 0x0000);
|
||||
while((CAN_REG(CANmodule->CANdriverState, C_CTRL1) & 0x00E0) != 0x0000);
|
||||
|
||||
CANmodule->CANnormal = true;
|
||||
}
|
||||
|
@ -151,7 +151,7 @@ void CO_CANsetNormalMode(CO_CANmodule_t *CANmodule){
|
|||
/******************************************************************************/
|
||||
CO_ReturnError_t CO_CANmodule_init(
|
||||
CO_CANmodule_t *CANmodule,
|
||||
uint16_t CANbaseAddress,
|
||||
void *CANdriverState,
|
||||
CO_CANrx_t rxArray[],
|
||||
uint16_t rxSize,
|
||||
CO_CANtx_t txArray[],
|
||||
|
@ -176,7 +176,7 @@ CO_ReturnError_t CO_CANmodule_init(
|
|||
}
|
||||
|
||||
/* Get global addresses for CAN module 1 or 2. */
|
||||
if(CANbaseAddress == ADDR_CAN1) {
|
||||
if(CANdriverState == ADDR_CAN1) {
|
||||
DMArxBaseAddress = CO_CAN1_DMA0;
|
||||
DMAtxBaseAddress = CO_CAN1_DMA1;
|
||||
CANmsgBuff = &CO_CAN1msg[0];
|
||||
|
@ -187,7 +187,7 @@ CO_ReturnError_t CO_CANmodule_init(
|
|||
#endif
|
||||
}
|
||||
#if CO_CAN2msgBuffSize > 0
|
||||
else if(CANbaseAddress == ADDR_CAN2) {
|
||||
else if(((uintptr_t) CANdriverState) == ADDR_CAN2) {
|
||||
DMArxBaseAddress = CO_CAN2_DMA0;
|
||||
DMAtxBaseAddress = CO_CAN2_DMA1;
|
||||
CANmsgBuff = &CO_CAN2msg[0];
|
||||
|
@ -203,7 +203,7 @@ CO_ReturnError_t CO_CANmodule_init(
|
|||
}
|
||||
|
||||
/* Configure object variables */
|
||||
CANmodule->CANbaseAddress = CANbaseAddress;
|
||||
CANmodule->CANdriverState = CANdriverState;
|
||||
CANmodule->CANmsgBuff = CANmsgBuff;
|
||||
CANmodule->rxArray = rxArray;
|
||||
CANmodule->rxSize = rxSize;
|
||||
|
@ -227,8 +227,8 @@ CO_ReturnError_t CO_CANmodule_init(
|
|||
|
||||
|
||||
/* Configure control registers */
|
||||
CAN_REG(CANbaseAddress, C_CTRL1) = 0x0400;
|
||||
CAN_REG(CANbaseAddress, C_CTRL2) = 0x0000;
|
||||
CAN_REG(CANdriverState, C_CTRL1) = 0x0400;
|
||||
CAN_REG(CANdriverState, C_CTRL2) = 0x0000;
|
||||
|
||||
|
||||
/* Configure CAN timing */
|
||||
|
@ -245,40 +245,40 @@ CO_ReturnError_t CO_CANmodule_init(
|
|||
}
|
||||
|
||||
if(CO_CANbitRateData[i].scale == 2)
|
||||
CAN_REG(CANbaseAddress, C_CTRL1) |= 0x0800;
|
||||
CAN_REG(CANdriverState, C_CTRL1) |= 0x0800;
|
||||
|
||||
CAN_REG(CANbaseAddress, C_CFG1) = (CO_CANbitRateData[i].SJW - 1) << 6 |
|
||||
CAN_REG(CANdriverState, C_CFG1) = (CO_CANbitRateData[i].SJW - 1) << 6 |
|
||||
(CO_CANbitRateData[i].BRP - 1);
|
||||
|
||||
CAN_REG(CANbaseAddress, C_CFG2) = ((uint16_t)(CO_CANbitRateData[i].phSeg2 - 1)) << 8 |
|
||||
CAN_REG(CANdriverState, C_CFG2) = ((uint16_t)(CO_CANbitRateData[i].phSeg2 - 1)) << 8 |
|
||||
0x0080 |
|
||||
(CO_CANbitRateData[i].phSeg1 - 1) << 3 |
|
||||
(CO_CANbitRateData[i].PROP - 1);
|
||||
|
||||
|
||||
/* setup RX and TX control registers */
|
||||
CAN_REG(CANbaseAddress, C_CTRL1) &= 0xFFFE; /* WIN = 0 - use buffer registers */
|
||||
CAN_REG(CANbaseAddress, C_RXFUL1) = 0x0000;
|
||||
CAN_REG(CANbaseAddress, C_RXFUL2) = 0x0000;
|
||||
CAN_REG(CANbaseAddress, C_RXOVF1) = 0x0000;
|
||||
CAN_REG(CANbaseAddress, C_RXOVF2) = 0x0000;
|
||||
CAN_REG(CANbaseAddress, C_TR01CON) = 0x0080; /* use one buffer for transmission */
|
||||
CAN_REG(CANbaseAddress, C_TR23CON) = 0x0000;
|
||||
CAN_REG(CANbaseAddress, C_TR45CON) = 0x0000;
|
||||
CAN_REG(CANbaseAddress, C_TR67CON) = 0x0000;
|
||||
CAN_REG(CANdriverState, C_CTRL1) &= 0xFFFE; /* WIN = 0 - use buffer registers */
|
||||
CAN_REG(CANdriverState, C_RXFUL1) = 0x0000;
|
||||
CAN_REG(CANdriverState, C_RXFUL2) = 0x0000;
|
||||
CAN_REG(CANdriverState, C_RXOVF1) = 0x0000;
|
||||
CAN_REG(CANdriverState, C_RXOVF2) = 0x0000;
|
||||
CAN_REG(CANdriverState, C_TR01CON) = 0x0080; /* use one buffer for transmission */
|
||||
CAN_REG(CANdriverState, C_TR23CON) = 0x0000;
|
||||
CAN_REG(CANdriverState, C_TR45CON) = 0x0000;
|
||||
CAN_REG(CANdriverState, C_TR67CON) = 0x0000;
|
||||
|
||||
|
||||
/* CAN module hardware filters */
|
||||
CAN_REG(CANbaseAddress, C_CTRL1) |= 0x0001; /* WIN = 1 - use filter registers */
|
||||
CAN_REG(CANbaseAddress, C_FEN1) = 0xFFFF; /* enable all 16 filters */
|
||||
CAN_REG(CANbaseAddress, C_FMSKSEL1) = 0x0000; /* all filters are using mask 0 */
|
||||
CAN_REG(CANbaseAddress, C_FMSKSEL2) = 0x0000;
|
||||
CAN_REG(CANbaseAddress, C_BUFPNT1) = 0xFFFF; /* use FIFO for all filters */
|
||||
CAN_REG(CANbaseAddress, C_BUFPNT2) = 0xFFFF;
|
||||
CAN_REG(CANbaseAddress, C_BUFPNT3) = 0xFFFF;
|
||||
CAN_REG(CANbaseAddress, C_BUFPNT4) = 0xFFFF;
|
||||
CAN_REG(CANdriverState, C_CTRL1) |= 0x0001; /* WIN = 1 - use filter registers */
|
||||
CAN_REG(CANdriverState, C_FEN1) = 0xFFFF; /* enable all 16 filters */
|
||||
CAN_REG(CANdriverState, C_FMSKSEL1) = 0x0000; /* all filters are using mask 0 */
|
||||
CAN_REG(CANdriverState, C_FMSKSEL2) = 0x0000;
|
||||
CAN_REG(CANdriverState, C_BUFPNT1) = 0xFFFF; /* use FIFO for all filters */
|
||||
CAN_REG(CANdriverState, C_BUFPNT2) = 0xFFFF;
|
||||
CAN_REG(CANdriverState, C_BUFPNT3) = 0xFFFF;
|
||||
CAN_REG(CANdriverState, C_BUFPNT4) = 0xFFFF;
|
||||
/* set all filters to 0 */
|
||||
pRXF = &CAN_REG(CANbaseAddress, C_RXF0SID);
|
||||
pRXF = &CAN_REG(CANdriverState, C_RXF0SID);
|
||||
for(i=0; i<16; i++){
|
||||
*pRXF = 0x0000;
|
||||
pRXF += 2;
|
||||
|
@ -288,44 +288,44 @@ CO_ReturnError_t CO_CANmodule_init(
|
|||
/* CO_CANrxBufferInit() functions, called by separate CANopen */
|
||||
/* init functions. */
|
||||
/* All mask bits are 1, so received message must match filter */
|
||||
CAN_REG(CANbaseAddress, C_RXM0SID) = 0xFFE8;
|
||||
CAN_REG(CANbaseAddress, C_RXM1SID) = 0xFFE8;
|
||||
CAN_REG(CANbaseAddress, C_RXM2SID) = 0xFFE8;
|
||||
CAN_REG(CANdriverState, C_RXM0SID) = 0xFFE8;
|
||||
CAN_REG(CANdriverState, C_RXM1SID) = 0xFFE8;
|
||||
CAN_REG(CANdriverState, C_RXM2SID) = 0xFFE8;
|
||||
}
|
||||
else{
|
||||
/* CAN module filters are not used, all messages with standard 11-bit */
|
||||
/* identifier will be received */
|
||||
/* Set masks so, that all messages with standard identifier are accepted */
|
||||
CAN_REG(CANbaseAddress, C_RXM0SID) = 0x0008;
|
||||
CAN_REG(CANbaseAddress, C_RXM1SID) = 0x0008;
|
||||
CAN_REG(CANbaseAddress, C_RXM2SID) = 0x0008;
|
||||
CAN_REG(CANdriverState, C_RXM0SID) = 0x0008;
|
||||
CAN_REG(CANdriverState, C_RXM1SID) = 0x0008;
|
||||
CAN_REG(CANdriverState, C_RXM2SID) = 0x0008;
|
||||
}
|
||||
|
||||
/* WIN = 0 - use buffer registers for default */
|
||||
CAN_REG(CANbaseAddress, C_CTRL1) &= 0xFFFE;
|
||||
CAN_REG(CANdriverState, C_CTRL1) &= 0xFFFE;
|
||||
|
||||
|
||||
/* Configure DMA controller */
|
||||
/* Set size of buffer in DMA RAM (FIFO Area Starts with Tx/Rx buffer TRB1 (FSA = 1)) */
|
||||
/* Use maximum 16 buffers, because we have 16-bit system. */
|
||||
if (CANmsgBuffSize >= 16) {
|
||||
CAN_REG(CANbaseAddress, C_FCTRL) = 0x8001;
|
||||
CAN_REG(CANdriverState, C_FCTRL) = 0x8001;
|
||||
CANmodule->CANmsgBuffSize = 16;
|
||||
}
|
||||
else if(CANmsgBuffSize >= 12) {
|
||||
CAN_REG(CANbaseAddress, C_FCTRL) = 0x6001;
|
||||
CAN_REG(CANdriverState, C_FCTRL) = 0x6001;
|
||||
CANmodule->CANmsgBuffSize = 12;
|
||||
}
|
||||
else if(CANmsgBuffSize >= 8) {
|
||||
CAN_REG(CANbaseAddress, C_FCTRL) = 0x4001;
|
||||
CAN_REG(CANdriverState, C_FCTRL) = 0x4001;
|
||||
CANmodule->CANmsgBuffSize = 8;
|
||||
}
|
||||
else if(CANmsgBuffSize >= 6) {
|
||||
CAN_REG(CANbaseAddress, C_FCTRL) = 0x2001;
|
||||
CAN_REG(CANdriverState, C_FCTRL) = 0x2001;
|
||||
CANmodule->CANmsgBuffSize = 6;
|
||||
}
|
||||
else if(CANmsgBuffSize >= 4) {
|
||||
CAN_REG(CANbaseAddress, C_FCTRL) = 0x0001;
|
||||
CAN_REG(CANdriverState, C_FCTRL) = 0x0001;
|
||||
CANmodule->CANmsgBuffSize = 4;
|
||||
}
|
||||
else {
|
||||
|
@ -334,9 +334,9 @@ CO_ReturnError_t CO_CANmodule_init(
|
|||
|
||||
/* DMA chanel initialization for ECAN reception */
|
||||
DMA_REG(DMArxBaseAddress, DMA_CON) = 0x0020;
|
||||
DMA_REG(DMArxBaseAddress, DMA_PAD) = (volatile uint16_t) &CAN_REG(CANbaseAddress, C_RXD);
|
||||
DMA_REG(DMArxBaseAddress, DMA_PAD) = (volatile uint16_t) &CAN_REG(CANdriverState, C_RXD);
|
||||
DMA_REG(DMArxBaseAddress, DMA_CNT) = 7;
|
||||
DMA_REG(DMArxBaseAddress, DMA_REQ) = (CANbaseAddress==ADDR_CAN1) ? 34 : 55;
|
||||
DMA_REG(DMArxBaseAddress, DMA_REQ) = (CANdriverState==ADDR_CAN1) ? 34 : 55;
|
||||
|
||||
#ifndef __HAS_EDS__
|
||||
DMA_REG(DMArxBaseAddress, DMA_STA) = CANmsgBuffDMAoffset;
|
||||
|
@ -349,9 +349,9 @@ CO_ReturnError_t CO_CANmodule_init(
|
|||
|
||||
/* DMA chanel initialization for ECAN transmission */
|
||||
DMA_REG(DMAtxBaseAddress, DMA_CON) = 0x2020;
|
||||
DMA_REG(DMAtxBaseAddress, DMA_PAD) = (volatile uint16_t) &CAN_REG(CANbaseAddress, C_TXD);
|
||||
DMA_REG(DMAtxBaseAddress, DMA_PAD) = (volatile uint16_t) &CAN_REG(CANdriverState, C_TXD);
|
||||
DMA_REG(DMAtxBaseAddress, DMA_CNT) = 7;
|
||||
DMA_REG(DMAtxBaseAddress, DMA_REQ) = (CANbaseAddress==ADDR_CAN1) ? 70 : 71;
|
||||
DMA_REG(DMAtxBaseAddress, DMA_REQ) = (CANdriverState==ADDR_CAN1) ? 70 : 71;
|
||||
|
||||
#ifndef __HAS_EDS__
|
||||
DMA_REG(DMAtxBaseAddress, DMA_STA) = CANmsgBuffDMAoffset;
|
||||
|
@ -365,9 +365,9 @@ CO_ReturnError_t CO_CANmodule_init(
|
|||
|
||||
/* CAN interrupt registers */
|
||||
/* clear interrupt flags */
|
||||
CAN_REG(CANbaseAddress, C_INTF) = 0x0000;
|
||||
CAN_REG(CANdriverState, C_INTF) = 0x0000;
|
||||
/* enable receive and transmit interrupt */
|
||||
CAN_REG(CANbaseAddress, C_INTE) = 0x0003;
|
||||
CAN_REG(CANdriverState, C_INTE) = 0x0003;
|
||||
/* CAN interrupt (combined) must be configured by application */
|
||||
|
||||
return CO_ERROR_NO;
|
||||
|
@ -376,7 +376,7 @@ CO_ReturnError_t CO_CANmodule_init(
|
|||
|
||||
/******************************************************************************/
|
||||
void CO_CANmodule_disable(CO_CANmodule_t *CANmodule){
|
||||
CO_CANsetConfigurationMode(CANmodule->CANbaseAddress);
|
||||
CO_CANsetConfigurationMode(CANmodule->CANdriverState);
|
||||
}
|
||||
|
||||
|
||||
|
@ -402,7 +402,7 @@ CO_ReturnError_t CO_CANrxBufferInit(
|
|||
/* buffer, which will be configured */
|
||||
CO_CANrx_t *buffer = &CANmodule->rxArray[index];
|
||||
uint16_t RXF, RXM;
|
||||
uint16_t addr = CANmodule->CANbaseAddress;
|
||||
uint16_t addr = CANmodule->CANdriverState;
|
||||
|
||||
/* Configure object variables */
|
||||
buffer->object = object;
|
||||
|
@ -524,11 +524,11 @@ CO_CANtx_t *CO_CANtxBufferInit(
|
|||
|
||||
/* Copy message to CAN module - internal usage only.
|
||||
*
|
||||
* @param CANbaseAddress CAN module base address
|
||||
* @param CANdriverState CAN module base address
|
||||
* @param dest Pointer to CAN module transmit buffer
|
||||
* @param src Pointer to source message
|
||||
*/
|
||||
static void CO_CANsendToModule(uint16_t CANbaseAddress, __eds__ CO_CANrxMsg_t *dest, CO_CANtx_t *src){
|
||||
static void CO_CANsendToModule(void *CANdriverState, __eds__ CO_CANrxMsg_t *dest, CO_CANtx_t *src){
|
||||
uint8_t DLC;
|
||||
__eds__ uint8_t *CANdataBuffer;
|
||||
uint8_t *pData;
|
||||
|
@ -548,17 +548,17 @@ static void CO_CANsendToModule(uint16_t CANbaseAddress, __eds__ CO_CANrxMsg_t *d
|
|||
for(; DLC>0; DLC--) *(CANdataBuffer++) = *(pData++);
|
||||
|
||||
/* control register, transmit request */
|
||||
C_CTRL1old = CAN_REG(CANbaseAddress, C_CTRL1);
|
||||
CAN_REG(CANbaseAddress, C_CTRL1) = C_CTRL1old & 0xFFFE; /* WIN = 0 - use buffer registers */
|
||||
CAN_REG(CANbaseAddress, C_TR01CON) |= 0x08;
|
||||
CAN_REG(CANbaseAddress, C_CTRL1) = C_CTRL1old;
|
||||
C_CTRL1old = CAN_REG(CANdriverState, C_CTRL1);
|
||||
CAN_REG(CANdriverState, C_CTRL1) = C_CTRL1old & 0xFFFE; /* WIN = 0 - use buffer registers */
|
||||
CAN_REG(CANdriverState, C_TR01CON) |= 0x08;
|
||||
CAN_REG(CANdriverState, C_CTRL1) = C_CTRL1old;
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************/
|
||||
CO_ReturnError_t CO_CANsend(CO_CANmodule_t *CANmodule, CO_CANtx_t *buffer){
|
||||
CO_ReturnError_t err = CO_ERROR_NO;
|
||||
uint16_t addr = CANmodule->CANbaseAddress;
|
||||
uint16_t addr = CANmodule->CANdriverState;
|
||||
volatile uint16_t C_CTRL1old, C_TR01CONcopy;
|
||||
|
||||
/* Verify overflow */
|
||||
|
@ -601,10 +601,10 @@ void CO_CANclearPendingSyncPDOs(CO_CANmodule_t *CANmodule){
|
|||
/* Abort message from CAN module, if there is synchronous TPDO.
|
||||
* Take special care with this functionality. */
|
||||
if(CANmodule->bufferInhibitFlag){
|
||||
volatile uint16_t C_CTRL1old = CAN_REG(CANmodule->CANbaseAddress, C_CTRL1);
|
||||
CAN_REG(CANmodule->CANbaseAddress, C_CTRL1) = C_CTRL1old & 0xFFFE; /* WIN = 0 - use buffer registers */
|
||||
CAN_REG(CANmodule->CANbaseAddress, C_TR01CON) &= 0xFFF7; /* clear TXREQ */
|
||||
CAN_REG(CANmodule->CANbaseAddress, C_CTRL1) = C_CTRL1old;
|
||||
volatile uint16_t C_CTRL1old = CAN_REG(CANmodule->CANdriverState, C_CTRL1);
|
||||
CAN_REG(CANmodule->CANdriverState, C_CTRL1) = C_CTRL1old & 0xFFFE; /* WIN = 0 - use buffer registers */
|
||||
CAN_REG(CANmodule->CANdriverState, C_TR01CON) &= 0xFFF7; /* clear TXREQ */
|
||||
CAN_REG(CANmodule->CANdriverState, C_CTRL1) = C_CTRL1old;
|
||||
CANmodule->bufferInhibitFlag = false;
|
||||
tpdoDeleted = 1U;
|
||||
}
|
||||
|
@ -637,8 +637,8 @@ void CO_CANverifyErrors(CO_CANmodule_t *CANmodule){
|
|||
uint16_t err;
|
||||
CO_EM_t* em = (CO_EM_t*)CANmodule->em;
|
||||
|
||||
err = CAN_REG(CANmodule->CANbaseAddress, C_INTF) >> 8;
|
||||
if(CAN_REG(CANmodule->CANbaseAddress, C_INTF) & 4){
|
||||
err = CAN_REG(CANmodule->CANdriverState, C_INTF) >> 8;
|
||||
if(CAN_REG(CANmodule->CANdriverState, C_INTF) & 4){
|
||||
err |= 0x80;
|
||||
}
|
||||
|
||||
|
@ -648,7 +648,7 @@ void CO_CANverifyErrors(CO_CANmodule_t *CANmodule){
|
|||
/* CAN RX bus overflow */
|
||||
if(err & 0xC0){
|
||||
CO_errorReport(em, CO_EM_CAN_RXB_OVERFLOW, CO_EMC_CAN_OVERRUN, err);
|
||||
CAN_REG(CANmodule->CANbaseAddress, C_INTF) &= 0xFFFB;/* clear bits */
|
||||
CAN_REG(CANmodule->CANdriverState, C_INTF) &= 0xFFFB;/* clear bits */
|
||||
}
|
||||
|
||||
/* CAN TX bus off */
|
||||
|
@ -694,22 +694,22 @@ void CO_CANverifyErrors(CO_CANmodule_t *CANmodule){
|
|||
void CO_CANinterrupt(CO_CANmodule_t *CANmodule) {
|
||||
|
||||
/* receive interrupt (New CAN message is available in RX FIFO buffer) */
|
||||
if(CAN_REG(CANmodule->CANbaseAddress, C_INTF) & 0x02) {
|
||||
if(CAN_REG(CANmodule->CANdriverState, C_INTF) & 0x02) {
|
||||
uint16_t C_CTRL1old;
|
||||
uint16_t C_RXFUL1copy;
|
||||
uint16_t C_FIFOcopy;
|
||||
uint8_t FNRB, FBP;
|
||||
|
||||
CO_DISABLE_INTERRUPTS();
|
||||
C_CTRL1old = CAN_REG(CANmodule->CANbaseAddress, C_CTRL1);
|
||||
CAN_REG(CANmodule->CANbaseAddress, C_CTRL1) = C_CTRL1old & 0xFFFE; /* WIN = 0 - use buffer registers */
|
||||
C_RXFUL1copy = CAN_REG(CANmodule->CANbaseAddress, C_RXFUL1);
|
||||
CAN_REG(CANmodule->CANbaseAddress, C_CTRL1) = C_CTRL1old;
|
||||
C_CTRL1old = CAN_REG(CANmodule->CANdriverState, C_CTRL1);
|
||||
CAN_REG(CANmodule->CANdriverState, C_CTRL1) = C_CTRL1old & 0xFFFE; /* WIN = 0 - use buffer registers */
|
||||
C_RXFUL1copy = CAN_REG(CANmodule->CANdriverState, C_RXFUL1);
|
||||
CAN_REG(CANmodule->CANdriverState, C_CTRL1) = C_CTRL1old;
|
||||
|
||||
/* We will service the buffers indicated by RXFUL copy, clear interrupt
|
||||
* flag now and let interrupt hit again if more messages are received */
|
||||
CAN_REG(CANmodule->CANbaseAddress, C_INTF) &= 0xFFFD;
|
||||
C_FIFOcopy = CAN_REG(CANmodule->CANbaseAddress, C_FIFO);
|
||||
CAN_REG(CANmodule->CANdriverState, C_INTF) &= 0xFFFD;
|
||||
C_FIFOcopy = CAN_REG(CANmodule->CANdriverState, C_FIFO);
|
||||
CO_ENABLE_INTERRUPTS();
|
||||
|
||||
/* FNRB tells us which buffer to read in FIFO */
|
||||
|
@ -778,23 +778,23 @@ void CO_CANinterrupt(CO_CANmodule_t *CANmodule) {
|
|||
|
||||
/* Clear RXFUL flag */
|
||||
CO_DISABLE_INTERRUPTS();
|
||||
C_CTRL1old = CAN_REG(CANmodule->CANbaseAddress, C_CTRL1);
|
||||
CAN_REG(CANmodule->CANbaseAddress, C_CTRL1) = C_CTRL1old & 0xFFFE; /* WIN = 0 - use buffer registers */
|
||||
CAN_REG(CANmodule->CANbaseAddress, C_RXFUL1) &= ~(mask);
|
||||
CAN_REG(CANmodule->CANbaseAddress, C_CTRL1) = C_CTRL1old;
|
||||
C_CTRL1old = CAN_REG(CANmodule->CANdriverState, C_CTRL1);
|
||||
CAN_REG(CANmodule->CANdriverState, C_CTRL1) = C_CTRL1old & 0xFFFE; /* WIN = 0 - use buffer registers */
|
||||
CAN_REG(CANmodule->CANdriverState, C_RXFUL1) &= ~(mask);
|
||||
CAN_REG(CANmodule->CANdriverState, C_CTRL1) = C_CTRL1old;
|
||||
CO_ENABLE_INTERRUPTS();
|
||||
C_RXFUL1copy &= ~(mask);
|
||||
|
||||
/* Now update FNRB, it will point to a new buffer after RXFUL was cleared */
|
||||
FNRB = (CAN_REG(CANmodule->CANbaseAddress, C_FIFO) & 0x3F);
|
||||
FNRB = (CAN_REG(CANmodule->CANdriverState, C_FIFO) & 0x3F);
|
||||
}
|
||||
}
|
||||
|
||||
/* transmit interrupt (TX buffer is free) */
|
||||
if(CAN_REG(CANmodule->CANbaseAddress, C_INTF) & 0x01) {
|
||||
if(CAN_REG(CANmodule->CANdriverState, C_INTF) & 0x01) {
|
||||
|
||||
/* Clear interrupt flag */
|
||||
CAN_REG(CANmodule->CANbaseAddress, C_INTF) &= 0xFFFE;
|
||||
CAN_REG(CANmodule->CANdriverState, C_INTF) &= 0xFFFE;
|
||||
/* First CAN message (bootup) was sent successfully */
|
||||
CANmodule->firstCANtxMessage = false;
|
||||
/* clear flag from previous message */
|
||||
|
@ -814,7 +814,7 @@ void CO_CANinterrupt(CO_CANmodule_t *CANmodule) {
|
|||
|
||||
/* Copy message to CAN buffer */
|
||||
CANmodule->bufferInhibitFlag = buffer->syncFlag;
|
||||
CO_CANsendToModule(CANmodule->CANbaseAddress, CANmodule->CANmsgBuff, buffer);
|
||||
CO_CANsendToModule(CANmodule->CANdriverState, CANmodule->CANmsgBuff, buffer);
|
||||
break; /* exit for loop */
|
||||
}
|
||||
buffer++;
|
||||
|
|
|
@ -444,7 +444,7 @@ typedef struct{
|
|||
|
||||
/* CAN module object. */
|
||||
typedef struct{
|
||||
uint16_t CANbaseAddress;
|
||||
void *CANdriverState;
|
||||
__eds__ CO_CANrxMsg_t *CANmsgBuff; /* dsPIC33F specific: CAN message buffer for CAN module */
|
||||
uint8_t CANmsgBuffSize; /* dsPIC33F specific: Size of the above buffer */
|
||||
CO_CANrx_t *rxArray;
|
||||
|
@ -466,14 +466,14 @@ typedef struct{
|
|||
|
||||
|
||||
/* Request CAN configuration or normal mode */
|
||||
void CO_CANsetConfigurationMode(uint16_t CANbaseAddress);
|
||||
void CO_CANsetConfigurationMode(void *CANdriverState);
|
||||
void CO_CANsetNormalMode(CO_CANmodule_t *CANmodule);
|
||||
|
||||
|
||||
/* Initialize CAN module object. */
|
||||
CO_ReturnError_t CO_CANmodule_init(
|
||||
CO_CANmodule_t *CANmodule,
|
||||
uint16_t CANbaseAddress,
|
||||
void *CANdriverState,
|
||||
CO_CANrx_t rxArray[],
|
||||
uint16_t rxSize,
|
||||
CO_CANtx_t txArray[],
|
||||
|
|
|
@ -54,7 +54,7 @@ unsigned int CO_interruptStatus = 0;
|
|||
/**
|
||||
* Macro and Constants - CAN module registers
|
||||
*/
|
||||
#define CAN_REG(base, offset) (*((volatile uint32_t *) ((base) + _CAN1_BASE_ADDRESS + (offset))))
|
||||
#define CAN_REG(base, offset) (*((volatile uint32_t *) (((uintptr_t) base) + _CAN1_BASE_ADDRESS + (offset))))
|
||||
|
||||
#define CLR 0x04
|
||||
#define SET 0x08
|
||||
|
@ -91,20 +91,20 @@ unsigned int CO_interruptStatus = 0;
|
|||
|
||||
|
||||
/******************************************************************************/
|
||||
void CO_CANsetConfigurationMode(uint16_t CANbaseAddress){
|
||||
uint32_t C_CONcopy = CAN_REG(CANbaseAddress, C_CON);
|
||||
void CO_CANsetConfigurationMode(void *CANdriverState){
|
||||
uint32_t C_CONcopy = CAN_REG(CANdriverState, C_CON);
|
||||
|
||||
/* switch ON can module */
|
||||
C_CONcopy |= 0x00008000;
|
||||
CAN_REG(CANbaseAddress, C_CON) = C_CONcopy;
|
||||
CAN_REG(CANdriverState, C_CON) = C_CONcopy;
|
||||
|
||||
/* request configuration mode */
|
||||
C_CONcopy &= 0xF8FFFFFF;
|
||||
C_CONcopy |= 0x04000000;
|
||||
CAN_REG(CANbaseAddress, C_CON) = C_CONcopy;
|
||||
CAN_REG(CANdriverState, C_CON) = C_CONcopy;
|
||||
|
||||
/* wait for configuration mode */
|
||||
while((CAN_REG(CANbaseAddress, C_CON) & 0x00E00000) != 0x00800000);
|
||||
while((CAN_REG(CANdriverState, C_CON) & 0x00E00000) != 0x00800000);
|
||||
}
|
||||
|
||||
|
||||
|
@ -112,10 +112,10 @@ void CO_CANsetConfigurationMode(uint16_t CANbaseAddress){
|
|||
void CO_CANsetNormalMode(CO_CANmodule_t *CANmodule){
|
||||
|
||||
/* request normal mode */
|
||||
CAN_REG(CANmodule->CANbaseAddress, C_CON+CLR) = 0x07000000;
|
||||
CAN_REG(CANmodule->CANdriverState, C_CON+CLR) = 0x07000000;
|
||||
|
||||
/* wait for normal mode */
|
||||
while((CAN_REG(CANmodule->CANbaseAddress, C_CON) & 0x00E00000) != 0x00000000);
|
||||
while((CAN_REG(CANmodule->CANdriverState, C_CON) & 0x00E00000) != 0x00000000);
|
||||
|
||||
CANmodule->CANnormal = true;
|
||||
}
|
||||
|
@ -124,7 +124,7 @@ void CO_CANsetNormalMode(CO_CANmodule_t *CANmodule){
|
|||
/******************************************************************************/
|
||||
CO_ReturnError_t CO_CANmodule_init(
|
||||
CO_CANmodule_t *CANmodule,
|
||||
uint16_t CANbaseAddress,
|
||||
void *CANdriverState,
|
||||
CO_CANrx_t rxArray[],
|
||||
uint16_t rxSize,
|
||||
CO_CANtx_t txArray[],
|
||||
|
@ -139,7 +139,7 @@ CO_ReturnError_t CO_CANmodule_init(
|
|||
}
|
||||
|
||||
/* Configure object variables */
|
||||
CANmodule->CANbaseAddress = CANbaseAddress;
|
||||
CANmodule->CANdriverState = CANdriverState;
|
||||
CANmodule->CANmsgBuffSize = 33; /* Must be the same as size of CANmodule->CANmsgBuff array. */
|
||||
CANmodule->rxArray = rxArray;
|
||||
CANmodule->rxSize = rxSize;
|
||||
|
@ -170,13 +170,13 @@ CO_ReturnError_t CO_CANmodule_init(
|
|||
|
||||
|
||||
/* Configure control register (configuration mode, receive timer stamp is enabled, module is on) */
|
||||
CAN_REG(CANbaseAddress, C_CON) = 0x04108000;
|
||||
CAN_REG(CANdriverState, C_CON) = 0x04108000;
|
||||
|
||||
|
||||
/* Configure FIFO */
|
||||
CAN_REG(CANbaseAddress, C_FIFOBA) = CO_KVA_TO_PA(CANmodule->CANmsgBuff);/* FIFO base address */
|
||||
CAN_REG(CANbaseAddress, C_FIFOCON) = (NO_CAN_RXF==32) ? 0x001F0000 : 0x000F0000; /* FIFO0: receive FIFO, 32(16) buffers */
|
||||
CAN_REG(CANbaseAddress, C_FIFOCON+0x40) = 0x00000080;/* FIFO1: transmit FIFO, 1 buffer */
|
||||
CAN_REG(CANdriverState, C_FIFOBA) = CO_KVA_TO_PA(CANmodule->CANmsgBuff);/* FIFO base address */
|
||||
CAN_REG(CANdriverState, C_FIFOCON) = (NO_CAN_RXF==32) ? 0x001F0000 : 0x000F0000; /* FIFO0: receive FIFO, 32(16) buffers */
|
||||
CAN_REG(CANdriverState, C_FIFOCON+0x40) = 0x00000080;/* FIFO1: transmit FIFO, 1 buffer */
|
||||
|
||||
|
||||
/* Configure CAN timing */
|
||||
|
@ -191,7 +191,7 @@ CO_ReturnError_t CO_CANmodule_init(
|
|||
case 800: i=6; break;
|
||||
case 1000: i=7; break;
|
||||
}
|
||||
CAN_REG(CANbaseAddress, C_CFG) =
|
||||
CAN_REG(CANdriverState, C_CFG) =
|
||||
((uint32_t)(CO_CANbitRateData[i].phSeg2 - 1)) << 16 | /* SEG2PH */
|
||||
0x00008000 | /* SEG2PHTS = 1, SAM = 0 */
|
||||
((uint32_t)(CO_CANbitRateData[i].phSeg1 - 1)) << 11 | /* SEG1PH */
|
||||
|
@ -203,35 +203,35 @@ CO_ReturnError_t CO_CANmodule_init(
|
|||
/* CAN module hardware filters */
|
||||
/* clear all filter control registers (disable filters, mask 0 and FIFO 0 selected for all filters) */
|
||||
for(i=0; i<(NO_CAN_RXF/4); i++)
|
||||
CAN_REG(CANbaseAddress, C_FLTCON+i*0x10) = 0x00000000;
|
||||
CAN_REG(CANdriverState, C_FLTCON+i*0x10) = 0x00000000;
|
||||
if(CANmodule->useCANrxFilters){
|
||||
/* CAN module filters are used, they will be configured with */
|
||||
/* CO_CANrxBufferInit() functions, called by separate CANopen */
|
||||
/* init functions. */
|
||||
/* Configure all masks so, that received message must match filter */
|
||||
CAN_REG(CANbaseAddress, C_RXM) = 0xFFE80000;
|
||||
CAN_REG(CANbaseAddress, C_RXM+0x10) = 0xFFE80000;
|
||||
CAN_REG(CANbaseAddress, C_RXM+0x20) = 0xFFE80000;
|
||||
CAN_REG(CANbaseAddress, C_RXM+0x30) = 0xFFE80000;
|
||||
CAN_REG(CANdriverState, C_RXM) = 0xFFE80000;
|
||||
CAN_REG(CANdriverState, C_RXM+0x10) = 0xFFE80000;
|
||||
CAN_REG(CANdriverState, C_RXM+0x20) = 0xFFE80000;
|
||||
CAN_REG(CANdriverState, C_RXM+0x30) = 0xFFE80000;
|
||||
}
|
||||
else{
|
||||
/* CAN module filters are not used, all messages with standard 11-bit */
|
||||
/* identifier will be received */
|
||||
/* Configure mask 0 so, that all messages with standard identifier are accepted */
|
||||
CAN_REG(CANbaseAddress, C_RXM) = 0x00080000;
|
||||
CAN_REG(CANdriverState, C_RXM) = 0x00080000;
|
||||
/* configure one filter for FIFO 0 and enable it */
|
||||
CAN_REG(CANbaseAddress, C_RXF) = 0x00000000;
|
||||
CAN_REG(CANbaseAddress, C_FLTCON) = 0x00000080;
|
||||
CAN_REG(CANdriverState, C_RXF) = 0x00000000;
|
||||
CAN_REG(CANdriverState, C_FLTCON) = 0x00000080;
|
||||
}
|
||||
|
||||
|
||||
/* CAN interrupt registers */
|
||||
/* Enable 'RX buffer not empty' (RXNEMPTYIE) interrupt in FIFO 0 (third layer interrupt) */
|
||||
CAN_REG(CANbaseAddress, C_FIFOINT) = 0x00010000;
|
||||
CAN_REG(CANdriverState, C_FIFOINT) = 0x00010000;
|
||||
/* Enable 'Tx buffer empty' (TXEMPTYIE) interrupt in FIFO 1 (third layer interrupt) */
|
||||
CAN_REG(CANbaseAddress, C_FIFOINT+0x40) = 0x00000000; /* will be enabled in CO_CANsend */
|
||||
CAN_REG(CANdriverState, C_FIFOINT+0x40) = 0x00000000; /* will be enabled in CO_CANsend */
|
||||
/* Enable receive (RBIE) and transmit (TBIE) buffer interrupt (secont layer interrupt) */
|
||||
CAN_REG(CANbaseAddress, C_INT) = 0x00030000;
|
||||
CAN_REG(CANdriverState, C_INT) = 0x00030000;
|
||||
/* CAN interrupt (first layer) must be configured by application */
|
||||
|
||||
return CO_ERROR_NO;
|
||||
|
@ -240,7 +240,7 @@ CO_ReturnError_t CO_CANmodule_init(
|
|||
|
||||
/******************************************************************************/
|
||||
void CO_CANmodule_disable(CO_CANmodule_t *CANmodule){
|
||||
CO_CANsetConfigurationMode(CANmodule->CANbaseAddress);
|
||||
CO_CANsetConfigurationMode(CANmodule->CANdriverState);
|
||||
}
|
||||
|
||||
|
||||
|
@ -284,7 +284,7 @@ CO_ReturnError_t CO_CANrxBufferInit(
|
|||
volatile uint32_t *pRXM0, *pRXM1, *pRXM2, *pRXM3;
|
||||
volatile uint8_t *pFLTCON;
|
||||
uint8_t selectMask;
|
||||
uint16_t addr = CANmodule->CANbaseAddress;
|
||||
uint16_t addr = CANmodule->CANdriverState;
|
||||
|
||||
/* get correct part of the filter control register */
|
||||
pFLTCON = (volatile uint8_t*)(&CAN_REG(addr, C_FLTCON)); /* pointer to first filter control register */
|
||||
|
@ -374,7 +374,7 @@ CO_CANtx_t *CO_CANtxBufferInit(
|
|||
/******************************************************************************/
|
||||
CO_ReturnError_t CO_CANsend(CO_CANmodule_t *CANmodule, CO_CANtx_t *buffer){
|
||||
CO_ReturnError_t err = CO_ERROR_NO;
|
||||
uint16_t addr = CANmodule->CANbaseAddress;
|
||||
uint16_t addr = CANmodule->CANdriverState;
|
||||
volatile uint32_t* TX_FIFOcon = &CAN_REG(addr, C_FIFOCON+0x40);
|
||||
volatile uint32_t* TX_FIFOconSet = &CAN_REG(addr, C_FIFOCON+0x48);
|
||||
uint32_t* TXmsgBuffer = CO_PA_TO_KVA1(CAN_REG(addr, C_FIFOUA+0x40));
|
||||
|
@ -420,8 +420,8 @@ CO_ReturnError_t CO_CANsend(CO_CANmodule_t *CANmodule, CO_CANtx_t *buffer){
|
|||
/******************************************************************************/
|
||||
void CO_CANclearPendingSyncPDOs(CO_CANmodule_t *CANmodule){
|
||||
uint32_t tpdoDeleted = 0U;
|
||||
volatile uint32_t* TX_FIFOcon = & |