⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lpc2000_can_driver.c

📁 在lpc2468上使用
💻 C
📖 第 1 页 / 共 4 页
字号:
/**************************************************************************
* FILENAME:      LPC2000_CAN_Driver.c                                     *         
*                                                                         *  
* VERSION:       V2.0                                                     *  
*                                                                         *  
* DESCRIPTION:   NXP LPC2300 CAN Controller Driver 
*	       		 Demo by UART0 with KEIL MCB2300 Evaluation Board		  *
*                                                                         *  
* TOOLS:         KEIL uVision3                                     		  *
*                KEIL MCB2300 Evaluation Board               			  *
*                                                                         *  
* REVISION HISTORY                                                        *  
* Version  Author           Date        Remarks							  *
* 1.0      Anthony Xie      10/10/2005    - -                             *         
***************************************************************************/

/**
 * @file
 * These CAN Controller driver routines are designed to provide the
 * application programmer with a higher level interface for the communication
 * with each CAN Controller module.
 * The CAN Controller Driver routines perform the following functions:
 *    Initialization of the CAN Controller
 *    Configuration of the CAN Controller for various baud rates
 *    Preparation and transmission of CAN messages
 *    Store received CAN messages in appropriate message buffers
 *    Providing pre-defined values for a set of bit-rates for various
 *        clock frequencies
 *    Mode switching of the CAN Controller
 *    Easy read/write access to CAN Controller registers
 */

// **************************************************************************
// Standard include files                                                    
// **************************************************************************

// **************************************************************************
// Project include files                                                     
// **************************************************************************
#include "LPC230x.h"
#include  "type.h"
#include  "LPC2000_CAN.h"
#include  "LPC2000_CAN_GAF.h"   // Includes Global Acceptance Filter   


// **************************************************************************
// Types                                                                     
// **************************************************************************

// **************************************************************************
// Defines                                                                   
// **************************************************************************


//#define SEMAPHORE_00                    0x00000000
//#define SEMAPHORE_01                    0x01000000
//#define SEMAPHORE_11                    0x03000000


// --------------------------------------------------------------------------
// ---------------------------   hwAccess Layer -----------------------------
// --------------------------------------------------------------------------

#define    OUTB(x,y)    (*((volatile UInt8 *)(x)) = y)
#define    INB(x)       (*((volatile UInt8 *)(x)))

#define    OUTW(x,y)    (*((volatile UInt32 *)(x)) = y)
#define    INW(x)       (*((volatile UInt32 *)(x)))

// **************************************************************************
// External Functions                                                        
// **************************************************************************

// **************************************************************************
// External Variables                                                        
// **************************************************************************

// **************************************************************************
// Global Variables                                                          
// **************************************************************************
lpc2000CANdriver_TXObj_t CAN_Send_Data[] =
 { {0x00080000,0x00000020,0x04030201,0x08070605},
   {0x00080000,0x000001BC,0x14131211,0x18171615},
   {0x00080000,0x00000255,0x24232221,0x28272625},
   {0x00080000,0x0000026F,0x34333231,0x38373635},
   {0x00080000,0x00000010,0x44434241,0x48474645},
   {0x00080000,0x000001AC,0x54535251,0x58575655},
   {0x00080000,0x00000245,0x64636261,0x68676665},
   {0x00080000,0x0000025F,0x74737271,0x78777675},
   {0x00080000,0x00000310,0x84838281,0x88878685},
   {0x80080000,0x18EF101E ,0x94939291,0x98979695},
   {0x80080000,0x18EF1E10,0x44332211,0x88776655} };

lpc2000CANdriver_RXObj_t CAN_Rcv_Data[5];

/*---------------------------------------------------------------------------*/
/* Defines for Global Acceptance Filter                                      */                             
/*---------------------------------------------------------------------------*/

//Size of Acceptance Filter Sections

#define LPC2000_CANDRIVER_SIZE_OF_ACFMEMORY   2048 /* Size of LPC2300 Look_up Table RAM    */

// Pre-defined CAN Acceptance Filter RAM Address

#define CAFMEM    0xE0038000   //Acceptance Filter RAM 的起始地址


/*---------------------------------------------------------------------------*/
/* Acceptance Filter Configuration Table Constants                           */
/*---------------------------------------------------------------------------*/

#define LPC2000_CANDRIVER_SCC_1                     0	// SCC: Source CAN Channel
#define LPC2000_CANDRIVER_SCC_2                     1
#define LPC2000_CANDRIVER_SCC_3                     2
#define LPC2000_CANDRIVER_SCC_4                     3

#ifdef LPC2000_CANDRIVER_STD_FULLCAN
/* Please, add or change the list of pre-defined   */
/* entries to the application specific needs       */
const lpc2000CANdriver_ACFilter_t  gklpc2000CANdriver_StdFULLCAN_Section[] =
   {
     /* Channel(1-4) ,              11-bit Identifier ( <7FF Double than ram size ) */
     {LPC2000_CANDRIVER_SCC_2,       0x0020},
     {LPC2000_CANDRIVER_SCC_2,       0x01BC},
     {LPC2000_CANDRIVER_SCC_2,       0x0255},
     {LPC2000_CANDRIVER_SCC_2,       0x026F}
   };								   

        
#define LPC2000_CANDRIVER_NUMBER_OF_STD_FULLCAN_IDS (\
        sizeof gklpc2000CANdriver_StdFULLCAN_Section /\
        sizeof gklpc2000CANdriver_StdFULLCAN_Section[0])

#else
#define LPC2000_CANDRIVER_NUMBER_OF_STD_FULLCAN_IDS  0
#endif

#ifdef LPC2000_CANDRIVER_STD_INDIVIDUAL
/* Please, add or change the list of pre-defined   */
/* entries to the application specific needs       */
const lpc2000CANdriver_ACFilter_t  gklpc2000CANdriver_StdIndividualSection[] =
   {
     /* Channel(1-4) ,              11-bit Identifier ( <7FF Double than ram size ) */
     {LPC2000_CANDRIVER_SCC_2,       0x0010},
     {LPC2000_CANDRIVER_SCC_2,       0x01AC},
     {LPC2000_CANDRIVER_SCC_2,       0x0245},
     {LPC2000_CANDRIVER_SCC_2,       0x025F}
   };								   

        
#define LPC2000_CANDRIVER_NUMBER_OF_STD_INDIVIDUAL_IDS (\
        sizeof gklpc2000CANdriver_StdIndividualSection /\
        sizeof gklpc2000CANdriver_StdIndividualSection[0])

#else
#define LPC2000_CANDRIVER_NUMBER_OF_STD_INDIVIDUAL_IDS  0
#endif


#ifdef LPC2000_CANDRIVER_STD_GROUP 
/* Please, add or change the list of pre-defined   */
/* entries to the application specific needs       */
const lpc2000CANdriver_ACFilter_t  gklpc2000CANdriver_StdGroupSection[] =
   {
     /* Channel                11-bit Identifier */
     {LPC2000_CANDRIVER_SCC_2,       0x0300},        // lower bound, Group 1 
     {LPC2000_CANDRIVER_SCC_2,       0x037F},        // upper bound, Group 1 
     {LPC2000_CANDRIVER_SCC_2,       0x0400},        // lower bound, Group 2 
     {LPC2000_CANDRIVER_SCC_2,       0x047F}         // upper bound, Group 1 
   };
#define LPC2000_CANDRIVER_NUMBER_OF_STD_GROUP_IDS (\
        sizeof gklpc2000CANdriver_StdGroupSection /\
        sizeof gklpc2000CANdriver_StdGroupSection[0])

#else
#define LPC2000_CANDRIVER_NUMBER_OF_STD_GROUP_IDS  0
#endif

#ifdef LPC2000_CANDRIVER_EXT_INDIVIDUAL
/* Please, add or change the list of pre-defined   */
/* entries to the application specific needs       */
const lpc2000CANdriver_ACFilterx_t  gklpc2000CANdriver_ExtIndividualSection[] =
   {
     /* Channel                29-bit Identifier   ( =< 0x1FFFFFFF) */
     {LPC2000_CANDRIVER_SCC_2,       0x18EF101E},
     {LPC2000_CANDRIVER_SCC_2,       0x18EF1E10},
     {LPC2000_CANDRIVER_SCC_2,       0x18EFFF10},
     {LPC2000_CANDRIVER_SCC_2,       0x18EFFFC2}
   };
#define LPC2000_CANDRIVER_NUMBER_OF_EXT_INDIVIDUAL_IDS (\
        sizeof gklpc2000CANdriver_ExtIndividualSection /\
        sizeof gklpc2000CANdriver_ExtIndividualSection[0])

#else
#define LPC2000_CANDRIVER_NUMBER_OF_EXT_INDIVIDUAL_IDS 0
#endif


#ifdef LPC2000_CANDRIVER_EXT_GROUP
/* Please, add or change the list of pre-defined   */
/* entries to the application specific needs       */
const lpc2000CANdriver_ACFilterx_t  gklpc2000CANdriver_ExtGroupSection[] =
   {
     /* Channel                29-bit Identifier ( =< 0x1FFFFFFF) */
     {LPC2000_CANDRIVER_SCC_2,       0x00007700},     // lower bound, Group 1 
     {LPC2000_CANDRIVER_SCC_2,       0x000077FF},     // upper bound, Group 1
     {LPC2000_CANDRIVER_SCC_2,       0x000085F7},     // lower bound, Group 2 
     {LPC2000_CANDRIVER_SCC_2,       0x00008802}      // upper bound, Group 2

   };
#define LPC2000_CANDRIVER_NUMBER_OF_EXT_GROUP_IDS (\
        sizeof gklpc2000CANdriver_ExtGroupSection /\
        sizeof gklpc2000CANdriver_ExtGroupSection[0])

#else
#define LPC2000_CANDRIVER_NUMBER_OF_EXT_GROUP_IDS      0
#endif


/*---------------------------------------------------------------------------*/
/* CAN Global Variable                                                       */
/*---------------------------------------------------------------------------*/
UInt32 CAN1Tx_Return_Message[5] = {0,0,0,0,0};
UInt32 CAN2Rx_Return_Message_Flag[10] = {0,0,0,0,0,0,0,0,0,0};
UInt8 CAN_Rcv_Data_Counter=0;
CanStatusCode Return_Value = LPC2000_CANDRIVER_INITIAL;
CanStatusCode CAN_Rcv_Status = 0;

/*---------------------------------------------------------------------------*/
/* CAN Uart Output char define                                                       */
/*---------------------------------------------------------------------------*/
const UInt8 LiuJiaju_Send[]="check_Send_successed\n\r";

const UInt8 LiuJiaju_Send1[]="Begin_Send\n\r";

const UInt8 LiuJiaju_IRQ[]="Enter_IRQ_Handle";

const UInt8 LiuJiaju_FULLCAN_Rec[]="Begin_FullCan_Recive";

const UInt8 LiuJiaju_AF_Rec[]="Enter_Rx_Rec2";

const UInt8 LiuJiaju_FULLCAN_Rec_complete[]="FULLCAN_Rec_succeed";

const UInt8 LiuJiaju_AF_Rec_complete[]="AF_Rec_succeed";

const UInt8 CAN_Error_10[] = "\n\r\
*** Error: LPC2000_CANDRIVER_ERR\n\r\
\n\r";

const UInt8 CAN_Error_30[] = "\n\r\
*** Error: LPC2000_CANDRIVER_ERR_WRONG_CAN_CHANNEL_NUMBER\n\r\
\n\r";

const UInt8 CAN_Error_31[] = "\n\r\
*** Error: LPC2000_CANDRIVER_ERR_WRONG_CAN_TxBUFFER_NUMBER\n\r\
\n\r";

const UInt8 CAN_Error_40[] = "\n\r\
*** Error: LPC2000_CANDRIVER_ERR_TRANSMIT_BUFFER1_NOT_FREE\n\r\
\n\r";

const UInt8 CAN_Error_50[] = "\n\r\
*** Error: LPC2000_CANDRIVER_ERR_TRANSMIT_BUFFER2_NOT_FREE\n\r\
\n\r";

const UInt8 CAN_Error_60[] = "\n\r\
*** Error: LPC2000_CANDRIVER_ERR_TRANSMIT_BUFFER3_NOT_FREE\n\r\
\n\r";

const UInt8 CAN_Error_80[] = "\n\r\
*** Error: LPC2000_CANDRIVER_ERR_TABLE_ERROR_IN_STD_FULLCAN_SECTION\n\r\
\n\r";

const UInt8 CAN_Error_90[] = "\n\r\
*** Error: LPC2000_CANDRIVER_ERR_TABLE_ERROR_IN_STD_INDIVIDUAL_SECTION\n\r\
\n\r";

const UInt8 CAN_Error_100[] = "\n\r\
*** Error: LPC2000_CANDRIVER_ERR_TABLE_ERROR_IN_STD_GROUP_SECTION\n\r\
\n\r";

const UInt8 CAN_Error_110[] = "\n\r\
*** Error: LPC2000_CANDRIVER_ERR_TABLE_ERROR_IN_EXT_INDIVIDUAL_SECTION\n\r\
\n\r";

const UInt8 CAN_Error_120[] = "\n\r\
*** Error: LPC2000_CANDRIVER_ERR_TABLE_ERROR_IN_EXT_GROUP_SECTION\n\r\
\n\r";

const UInt8 CAN_Error_130[] = "\n\r\
*** Error: LPC2000_CANDRIVER_ERR_NOT_ENOUGH_MEMORY_SPACE\n\r\
\n\r";



const UInt8 CAN2Rx_Return_Message_EI[] = "\n\r\
*** Error: Error Warning Interrupt-EI bit set\n\r\
\n\r";	  

const UInt8 CAN2Rx_Return_Message_DOI[] = "\n\r\
*** Error: Data Overrun Interrupt-DOI bit set\n\r\
\n\r";	  

const UInt8 CAN2Rx_Return_Message_WUI[] = "\n\r\
*** Error: Wake-Up Interrupt-WUI bit set\n\r\
\n\r";	  

const UInt8 CAN2Rx_Return_Message_EPI[] = "\n\r\
*** Error: Error Passive Interrupt-EPI bit set\n\r\
\n\r";	  

const UInt8 CAN2Rx_Return_Message_ALI[] = "\n\r\
*** Error: Arbitration Lost Interrupt-ALI bit set\n\r\
\n\r";	  

const UInt8 CAN2Rx_Return_Message_BEI[] = "\n\r\
*** Error: Bus Error Interrupt-BEI bit set\n\r\
\n\r";	  

const UInt8 CAN_ERROR_STOP_DEMO[] = "\
*** Pls. STOP demo.  Check board setting, wire connection. And restart demo.\
\n\r";	  
const UInt8 Label_Explanation[] = "BP: Received in Bypass Mode; ID-Index: AF matched entry index\n\r";

const UInt8 Demo_Start[] = "\f\
$$$$$$$ NXP LPC2468 CAN BUS DRIVER DEMO - FULLCAN $$$$$$$\n\n\r\
***Demo Files:    LPC2000_CAN_SYS.C\n\r\
***               LPC2000_CAN_Driver.c\n\n\r\
***Demo Tools:    linposh lpc2468 Demo Board ( CAN1-Trans, CAN2-Rcv )\n\n\r\

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -