📄 lpc2000_can_driver.c
字号:
{
// CAN Channel 1
case 1: Address_TFI_ID_DATA = (UInt32)&CAN1TFI1 + TXB_Offset;
Address_CMR = (UInt32)&CAN1CMR;
Address_GSR = (UInt32)&CAN1GSR;
break;
// CAN Channel 2
case 2: Address_TFI_ID_DATA = (UInt32)&CAN1TFI1 + 0x00004000 + TXB_Offset;
Address_CMR = (UInt32)&CAN1CMR + 0x00004000;
Address_GSR = (UInt32)&CAN1GSR + 0x00004000;
break;
// CAN Channel 3
case 3: Address_TFI_ID_DATA = (UInt32)&CAN1TFI1 + 0x00008000 + TXB_Offset;
Address_CMR = (UInt32)&CAN1CMR + 0x00008000;
Address_GSR = (UInt32)&CAN1GSR + 0x00008000;
break;
// CAN Channel 4
case 4: Address_TFI_ID_DATA = (UInt32)&CAN1TFI1 + 0x0000C000 + TXB_Offset;
Address_CMR = (UInt32)&CAN1CMR + 0x0000C000;
Address_GSR = (UInt32)&CAN1GSR + 0x0000C000;
break;
default: // wrong channel number
return (LPC2000_CANDRIVER_ERR_WRONG_CAN_CHANNEL_NUMBER);
}
// Copy message contents into local variable(s)
OUTW( Address_TFI_ID_DATA + 0, pTransmitBuf -> TFI);
OUTW( Address_TFI_ID_DATA + 4, pTransmitBuf -> ID);
OUTW( Address_TFI_ID_DATA + 8, pTransmitBuf -> DataField[0]);
OUTW( Address_TFI_ID_DATA +12, pTransmitBuf -> DataField[1]);
OUTB( Address_CMR, Transmit_TxBuf_Start );
while ( (INW(Address_GSR) & 0x0048) == 0x0000 ); // Wait Trans successed or error counter reach limit
if( (INW(Address_GSR) & 0x0040) == 0x0040 ) // if error, stop transmit
{ // for demo used, stop screen roll
OUTB( Address_CMR, 0x02 );
}
return (LPC2000_CANDRIVER_OK);
} // lpc2000CANdriver_PrepareTransmitMessage;
// **************************************************************************
// FUNCTION: lpc2000CANdriver_ReceiveMessageCh1
//
// DESCRIPTION: This function reads the received CAN message and stores
// the data in the CPU User RAM
//
// GLOBAL VARIABLES USED:
//
// PARAMETERS:
//
// RETURN: CanStatusCode: Status of operation
//
// LPC2000_CANDRIVER_OK - successful
//
// **************************************************************************
CanStatusCode
lpc2000CANdriver_ReceiveMessageCh1 (plpc2000CANdriver_RXObj_t pReceiveBuf)
{
// CAN Channel 1
pReceiveBuf -> RFS = CAN1RFS;
pReceiveBuf -> ID = CAN1RID;
pReceiveBuf -> DataField[0] = CAN1RDA;
pReceiveBuf -> DataField[1] = CAN1RDB;
// Release Receive Buffer
CAN1CMR = 0x04; // Release Rx Buffer
return (1);
} // lpc2000CANdriver_ReceiveMessageCh0;
// **************************************************************************
// FUNCTION: lpc2000CANdriver_ReceiveMessageCh2
//
// DESCRIPTION: This function reads the received CAN message and stores
// the data in the CPU User RAM
//
// GLOBAL VARIABLES USED:
//
// PARAMETERS:
//
// RETURN: CanStatusCode: Status of operation
//
// LPC2000_CANDRIVER_OK - successful
//
// **************************************************************************
CanStatusCode
lpc2000CANdriver_ReceiveMessageCh2 (plpc2000CANdriver_RXObj_t pReceiveBuf)
{
// CAN Channel 2
pReceiveBuf -> RFS = CAN2RFS;
pReceiveBuf -> ID = CAN2RID;
pReceiveBuf -> DataField[0] = CAN2RDA;
pReceiveBuf -> DataField[1] = CAN2RDB;
// Release Receive Buffer
CAN2CMR = 0x04; // Release Rx Buffer
return (1);
} // lpc2000CANdriver_ReceiveMessageCh2;
// **************************************************************************
// FUNCTION: lpc2000CANdriver_ReceiveMessageCh3
//
// DESCRIPTION: This function reads the received CAN message and stores
// the data in the CPU User RAM
//
// GLOBAL VARIABLES USED:
//
// PARAMETERS:
//
// RETURN: CanStatusCode: Status of operation
//
// LPC2000_CANDRIVER_OK - successful
//
// **************************************************************************
CanStatusCode
lpc2000CANdriver_ReceiveMessageCh3 (plpc2000CANdriver_RXObj_t pReceiveBuf)
{
// CAN Channel 3
pReceiveBuf -> RFS = CAN3RFS;
pReceiveBuf -> ID = CAN3RID;
pReceiveBuf -> DataField[0] = CAN3RDA;
pReceiveBuf -> DataField[1] = CAN3RDB;
// Release Receive Buffer
CAN3CMR = 0x04; // Release Rx Buffer
return (1);
} // lpc2000CANdriver_ReceiveMessageCh3;
// **************************************************************************
// FUNCTION: lpc2000CANdriver_ReceiveMessageCh4
//
// DESCRIPTION: This function reads the received CAN message and stores
// the data in the CPU User RAM
//
// GLOBAL VARIABLES USED:
//
// PARAMETERS:
//
// RETURN: CanStatusCode: Status of operation
//
// LPC2000_CANDRIVER_OK - successful
//
// **************************************************************************
CanStatusCode
lpc2000CANdriver_ReceiveMessageCh4 (plpc2000CANdriver_RXObj_t pReceiveBuf)
{
// CAN Channel 4
pReceiveBuf -> RFS = CAN4RFS;
pReceiveBuf -> ID = CAN4RID;
pReceiveBuf -> DataField[0] = CAN4RDA;
pReceiveBuf -> DataField[1] = CAN4RDB;
// Release Receive Buffer
CAN4CMR = 0x04; // Release Rx Buffer
return (1);
} // lpc2000CANdriver_ReceiveMessageCh4;
// **************************************************************************
// FUNCTION: lpc2000CANdriver_LoadAcceptanceFilter
//
// DESCRIPTION: The function lpc2000hwCANdriver_LoadAcceptanceFilter configures
// the Acceptance Filter Memory. Filter constants which are
// pre-defined in the configuration file lpc2000CANdriver_cfg.h
// are used for programming.
// In addition to the filter memory configuration, this
// function also configures the acceptance filter start address
// registers according to the number of CAN identifiers.
//
// GLOBAL VARIABLES USED:
//
// PARAMETERS:
//
// RETURN: CanStatusCode: Status of operation
//
// LPC2000_CANDRIVER_OK - successful
//
// LPC2000_CANDRIVER_ERR - not successful -> table error
// **************************************************************************
CanStatusCode
lpc2000CANdriver_LoadAcceptanceFilter (void)
{
UInt32 address;
UInt32 memory_address;
UInt32 IDcount;
UInt32 i;
UInt32 acfword_pre;
UInt32 acfword_upper;
UInt32 acfword_lower;
address = 0;
// Set Standard Frame Individual Startaddress
CANSFF_sa = address;
// ----------------------------------------------------------
// ---------- Fill Standard Individual Section ------------
// ----------------------------------------------------------
#ifdef LPC2000_CANDRIVER_STD_INDIVIDUAL
IDcount = LPC2000_CANDRIVER_NUMBER_OF_STD_INDIVIDUAL_IDS;
acfword_pre = 0;
i = 0;
while (IDcount != 0)
{
acfword_lower = (gklpc2000CANdriver_StdIndividualSection[i].ID << 16)
+ (gklpc2000CANdriver_StdIndividualSection[i].Channel << 29);
IDcount--;
if (IDcount == 0)
{
// odd number of identifiers -> disable ID !
acfword_upper = 0x00001FFF
+ (gklpc2000CANdriver_StdIndividualSection[i].Channel << 13);
}
else
{
acfword_upper = (gklpc2000CANdriver_StdIndividualSection[i+1].ID)
+ (gklpc2000CANdriver_StdIndividualSection[i+1].Channel << 13);
IDcount--;
}
// Check ascending numerical order
if ((acfword_lower >> 16) >= acfword_upper)
{
// table error - violation of ascending numerical order
return(LPC2000_CANDRIVER_ERR_TABLE_ERROR_IN_STD_INDIVIDUAL_SECTION);
}
else
{
if (acfword_pre >= (acfword_lower >> 16))
{
// table error - violation of ascending numerical order
return(LPC2000_CANDRIVER_ERR_TABLE_ERROR_IN_STD_INDIVIDUAL_SECTION);
}
else
{
// write configuration into Acceptance Filter Memeory
OUTW( CAFMEM + address, acfword_lower + acfword_upper);
acfword_pre = acfword_upper;
}
}
// increment configuration table index
i = i + 2;
// next Acceptance Filter Memory address
address = address + 4;
};
#endif
// Set Standard Frame Group Startaddress
CANSFF_GRP_sa = address;
// ----------------------------------------------------------
// ---------- Fill Standard Group Section -----------------
// ----------------------------------------------------------
#ifdef LPC2000_CANDRIVER_STD_GROUP
IDcount = LPC2000_CANDRIVER_NUMBER_OF_STD_GROUP_IDS;
acfword_pre = 0;
i = 0;
while (IDcount != 0)
{
acfword_lower = (gklpc2000CANdriver_StdGroupSection[i].ID << 16)
+ (gklpc2000CANdriver_StdGroupSection[i].Channel << 29);
IDcount--;
if (IDcount == 0)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -