📄 lpc2000_can_driver.c
字号:
// table error - odd number of identifiers
// not allowed for group definitions
return (LPC2000_CANDRIVER_ERR_TABLE_ERROR_IN_STD_GROUP_SECTION);
}
else
{
acfword_upper = (gklpc2000CANdriver_StdGroupSection[i+1].ID)
+ (gklpc2000CANdriver_StdGroupSection[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_GROUP_SECTION);
}
else
{
if (acfword_pre >= (acfword_lower >> 16))
{
// table error - violation of ascending numerical order
return(LPC2000_CANDRIVER_ERR_TABLE_ERROR_IN_STD_GROUP_SECTION);
}
else
{
// write configuration into Acceptance Filter Memory
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 Extended Frame Individual Startaddress
CANEFF_sa = address;
// ----------------------------------------------------------
// ---------- Fill Extended Individual Section ------------
// ----------------------------------------------------------
#ifdef LPC2000_CANDRIVER_EXT_INDIVIDUAL
IDcount = LPC2000_CANDRIVER_NUMBER_OF_EXT_INDIVIDUAL_IDS;
i = 0;
acfword_pre = 0;
while (IDcount != 0)
{
acfword_lower = (gklpc2000CANdriver_ExtIndividualSection[i].IDx)
+ (gklpc2000CANdriver_ExtIndividualSection[i].Channel << 29);
IDcount--;
// Check ascending numerical order with previous table entity
if ((i > 0) && (acfword_pre >= acfword_lower))
{
// table error - violation of ascending numerical order
return(LPC2000_CANDRIVER_ERR_TABLE_ERROR_IN_EXT_INDIVIDUAL_SECTION);
}
else
{
OUTW(CAFMEM + address, acfword_lower);
// next Acceptance Filter Memory address
address = address + 4;
// increment configuration table index
i = i + 1;
acfword_pre = acfword_lower;
}
};
#endif
// Set Extended Frame Group Startaddress
CANEFF_GRP_sa = address;
// ----------------------------------------------------------
// ---------- Fill Extended Group Section -----------------
// ----------------------------------------------------------
#ifdef LPC2000_CANDRIVER_EXT_GROUP
IDcount = LPC2000_CANDRIVER_NUMBER_OF_EXT_GROUP_IDS;
i = 0;
acfword_pre = 0;
while (IDcount != 0)
{
acfword_lower = (gklpc2000CANdriver_ExtGroupSection[i].IDx)
+ (gklpc2000CANdriver_ExtGroupSection[i].Channel << 29);
// Check ascending numerical order with previous group
if ((i > 0) && (acfword_pre >= acfword_lower))
{
// table error - violation of ascending numerical order
return (LPC2000_CANDRIVER_ERR_TABLE_ERROR_IN_EXT_GROUP_SECTION);
}
else
{
IDcount--;
if (IDcount == 0)
{
// table error 'odd number of entities'
return (LPC2000_CANDRIVER_ERR_TABLE_ERROR_IN_EXT_GROUP_SECTION);
}
else
{
acfword_upper = (gklpc2000CANdriver_ExtGroupSection[i+1].IDx)
+ (gklpc2000CANdriver_ExtGroupSection[i].Channel << 29);
// Check ascending numerical order
if (acfword_lower >= acfword_upper)
{
// table error - violation of ascending numerical order
return (LPC2000_CANDRIVER_ERR_TABLE_ERROR_IN_EXT_GROUP_SECTION);
}
else
{
// write configuration into Acceptance Filter Memeory
OUTW(CAFMEM + address, acfword_lower);
// next Acceptance Filter Memory address
address = address + 4;
// write configuration into Acceptance Filter Memory
OUTW(CAFMEM + address, acfword_upper);
// next Acceptance Filter Memory address
address = address + 4;
acfword_pre = acfword_upper;
}
}
}
// increment configuration table index
i = i + 2;
IDcount--;
};
#endif
// Check Acceptance Filter Memory Space
memory_address = address ;
if (memory_address > LPC2000_CANDRIVER_SIZE_OF_ACFMEMORY)
{
// not enough memory space for CAN Identifiers
return (LPC2000_CANDRIVER_ERR_NOT_ENOUGH_MEMORY_SPACE);
}
else
{
// Set End of Table
CANENDofTable = address;
}
return (LPC2000_CANDRIVER_OK);
}
// **************************************************************************
// FUNCTION: Rcv_Data_Output_to_Screen
//
// DESCRIPTION: Print Data to PC Screen by Uart0
//
// GLOBAL VARIABLES USED:
//
// PARAMETERS:
//
// RETURN:
// **************************************************************************
UInt32 Rcv_Data_Output_to_Screen(plpc2000CANdriver_RXObj_t pReceiveBuf)
{
UInt32 Temp_Data_Output[2], i;
//Uart Output for CAN data define
UInt8 const Rcv_Data_To_Screen_1[] = "***Rcv-Frame:Data-";
UInt8 const Rcv_Data_To_Screen_2[] = " ID:";
UInt8 const Rcv_Data_To_Screen_3[] = " BP-Bit:";
UInt8 const Rcv_Data_To_Screen_4[] = " ID-Index:";
UInt8 const Rcv_Data_To_Screen_5[] = "\n\r";
Print_Chars_to_Screen( Rcv_Data_To_Screen_1 );
Temp_Data_Output[0] = pReceiveBuf -> DataField[0];
Temp_Data_Output[1] = pReceiveBuf -> DataField[1];
pReceiveBuf -> DataField[0] = 0; // clear Data0 in Rcv data Buffer
pReceiveBuf -> DataField[1] = 0; // clear Data1 in Rcv data Buffer
for(i=0;i<2;i++)
{
Print_4bits_to_Screen( (Temp_Data_Output[i] & 0x000000F0)>>4 ); // print 2nd 4bits
Print_4bits_to_Screen( (Temp_Data_Output[i] & 0x0000000F) ); // print 1st 4bits
Print_4bits_to_Screen( 44 ); // print ","
Print_4bits_to_Screen( (Temp_Data_Output[i] & 0x0000F000)>>12 );// print 4th 4bits
Print_4bits_to_Screen( (Temp_Data_Output[i] & 0x00000F00)>>8 ); // print 3rd 4bits
Print_4bits_to_Screen( 44 ); // print ","
Print_4bits_to_Screen( (Temp_Data_Output[i] & 0x00F00000)>>20 );// print 6th 4bits
Print_4bits_to_Screen( (Temp_Data_Output[i] & 0x000F0000)>>16 );// print 5th 4bits
Print_4bits_to_Screen( 44 ); // print ","
Print_4bits_to_Screen( (Temp_Data_Output[i] & 0xF0000000)>>28 );// print 8th 4bits
Print_4bits_to_Screen( (Temp_Data_Output[i] & 0x0F000000)>>24 );// print 7th 4bits
Print_4bits_to_Screen( 44 ); // print ","
}
Print_Chars_to_Screen( Rcv_Data_To_Screen_2 );
Temp_Data_Output[0] = pReceiveBuf -> ID; // clear ID in Rcv data Buffer
pReceiveBuf -> ID = 0;
Print_4bits_to_Screen( (Temp_Data_Output[0] & 0xF0000000)>>28 ); // print ID 8th 4bits
Print_4bits_to_Screen( (Temp_Data_Output[0] & 0x0F000000)>>24 ); // print ID 7th 4bits
Print_4bits_to_Screen( (Temp_Data_Output[0] & 0x00F00000)>>20 ); // print ID 6th 4bits
Print_4bits_to_Screen( (Temp_Data_Output[0] & 0x000F0000)>>16 ); // print ID 5th 4bits
Print_4bits_to_Screen( (Temp_Data_Output[0] & 0x0000F000)>>12 ); // print ID 4th 4bits
Print_4bits_to_Screen( (Temp_Data_Output[0] & 0x00000F00)>>8 ); // print ID 3rd 4bits
Print_4bits_to_Screen( (Temp_Data_Output[0] & 0x000000F0)>>4 ); // print ID 2nd 4bits
Print_4bits_to_Screen( (Temp_Data_Output[0] & 0x0000000F) ); // print ID 1st 4bits
Print_Chars_to_Screen( Rcv_Data_To_Screen_3 );
Temp_Data_Output[0] = pReceiveBuf -> RFS; // clear RFS in Rcv data Buffer
pReceiveBuf -> RFS = 0;
i = (Temp_Data_Output[0] & 0x00000400)>>10; // save BP bit
Print_4bits_to_Screen( (Temp_Data_Output[0] & 0x00000400)>>10 ); // print BP bit
Print_Chars_to_Screen( Rcv_Data_To_Screen_4 );
if( i == 0)
{
Temp_Data_Output[0] &= 0x000003FF;
Temp_Data_Output[1] = Temp_Data_Output[0] / 1000;
Print_4bits_to_Screen( Temp_Data_Output[1] ); // print ID Index thousand digit
Temp_Data_Output[0] %= 1000;
Temp_Data_Output[1] = Temp_Data_Output[0] / 100;
Print_4bits_to_Screen( Temp_Data_Output[1] ); // print ID Index centi-digit
Temp_Data_Output[0] %= 100;
Temp_Data_Output[1] = Temp_Data_Output[0] / 10;
Print_4bits_to_Screen( Temp_Data_Output[1] ); // print ID Index deca-digit
Temp_Data_Output[0] %= 10;
Print_4bits_to_Screen( Temp_Data_Output[0] ); // print ID Index below ten digit
}
else
{ for(i=0;i<4;i++) Print_4bits_to_Screen( 45 );} // print 4 "-"
Print_Chars_to_Screen( Rcv_Data_To_Screen_5 ); // change line + line feed
return(0);
}
// **************************************************************************
// FUNCTION: Print_Chars_to_Screen
//
// DESCRIPTION: Print Chars to Screen by Uart0
//
// GLOBAL VARIABLES USED:
//
// PARAMETERS:
//
// RETURN:
// **************************************************************************
UInt32 Print_Chars_to_Screen( UInt8 const * pscreen_print )
{
while( *pscreen_print != '\0' )
{
U0THR = *pscreen_print;
while( (U0LSR & 0x20) == 0 );
pscreen_print++;
}
return(0);
}
// **************************************************************************
// FUNCTION: Print_4bits_to_Screen
//
// DESCRIPTION: Print 4bits hex data to Screen by Uart0
//
// GLOBAL VARIABLES USED:
//
// PARAMETERS:
//
// RETURN:
// **************************************************************************
UInt32 Print_4bits_to_Screen( UInt32 Value_Hex_4bits)
{
switch(Value_Hex_4bits)
{
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9: U0THR = Value_Hex_4bits + 48; // print "0 - 9"
break;
case 10:
case 11:
case 12:
case 13:
case 14:
case 15: U0THR = Value_Hex_4bits + 55; // print "A - F"
break;
case 44: // print ","
case 45: U0THR = Value_Hex_4bits; // print "-"
break;
default:
break;
}
while( (U0LSR & 0x20) == 0 );
return(0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -