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

📄 lpc2000_can_driver.c

📁 这是NXP公司的LPC2000系列ARM7内核处理器
💻 C
📖 第 1 页 / 共 4 页
字号:
/**************************************************************************
* FILENAME:      LPC2000_CAN_Driver.c                                     *         
*                                                                         *  
* VERSION:       V1.0                                                     *  
*                                                                         *  
* DESCRIPTION:   Philips LPC2000 CAN Controller Driver with SJA1000       *                         
*				 Demo by UART0 with KEIL MCB2100 Evaluation Board		  *
*                                                                         *  
* TOOLS:         KEIL uVision3                                     		  *
*                ARM Development Suite ADS1.2 							  *
*                KEIL MCB2100 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  "..\LPC2294.h"
#include  "..\config.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,0x00000001,0x04030201,0x08070605},
   {0x00080000,0x000001AC,0x14131211,0x18171615},
   {0x00080000,0x00000310,0x24232221,0x28272625},
   {0x80080000,0x00003377,0x34333231,0x38373635},
   {0x80080000,0x00007755,0x44434241,0x48474645} };

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 SJA1000 Look_up Table RAM    */

// Pre-defined CAN Acceptance Filter RAM Address

#define CAFMEM                                0xE0038000


/*---------------------------------------------------------------------------*/
/*Sections can be enabled or disabled to the application specific needs		 */
/*---------------------------------------------------------------------------*/
 #define LPC2000_CANDRIVER_STD_INDIVIDUAL
 #define LPC2000_CANDRIVER_STD_GROUP      
 #define LPC2000_CANDRIVER_EXT_INDIVIDUAL 
 #define LPC2000_CANDRIVER_EXT_GROUP      

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

#define LPC2000_CANDRIVER_SCC_1                     1	// SCC: Source CAN Cannel
#define LPC2000_CANDRIVER_SCC_2                     2
#define LPC2000_CANDRIVER_SCC_3                     3
#define LPC2000_CANDRIVER_SCC_4                     4


#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,       0x00002288},
     {LPC2000_CANDRIVER_SCC_2,       0x00003377},
	 {LPC2000_CANDRIVER_SCC_2,       0x00005566},
	 {LPC2000_CANDRIVER_SCC_2,       0x00006677}
   };
#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 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_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 Demo_Start[] = "\f\
$$$$$$$ PHILIPS LPC2000 CAN BUS DRIVER DEMO - with SJA1000 $$$$$$$\n\n\r\
***Demo Files:    LPC2000_CAN_SYS.C\n\r\
***               LPC2000_CAN_Driver.c\n\n\r\
***Demo Tools:    Keil MCB2100 Demo Board ( CAN1-Trans, CAN2-Rcv )\n\n\r\
***Demo Function: Press 1 - simple communication ( GLOBAL ACC FILTER Bypass )\n\r\
***               Press 2 - communication with GLOBAL ACC FILTER\n\r\
\n\r";

const UInt8 Demo_Sent_Choice[]="\n\r\
***If you want demo again \n\r\
***Enter your choice: 1 for ACC Bypass, 2 for ACC On\n\r";

const UInt8 Demo_Sent_Data[] = "\n\r\
***Total 40 bytes data (using 5 frames) will be transmitted by CAN1 to CAN BUS\n\r\
***Frame1: Data - 01,02,03,04,05,06,07,08 with Standard 11bits ID:0x001;\n\r\
***Frame2: Data - 11,12,13,14,15,16,17,18 with Standard 11bits ID:0x1AC;\n\r\
***Frame3: Data - 21,22,23,24,25,26,27,28 with Standard 11bits ID:0x310;\n\r\
***Frame4: Data - 31,32,33,34,35,36,37,38 with Extended 29bits ID:0x3377;\n\r\
***Frame5: Data - 41,42,43,44,45,46,47,48 with Extended 29bits ID:0x7755;\n\r\
\n\r";

const UInt8 Data_Sent_Start_or_Not[] = "\
***Start transmit now? Press y or Y - start\n\r\
***                    Press n or N - Not start\
\n\r";


const UInt8 Rcv_Data_OK[] = "\n\r\
*** Communication Successful!  data Rcved OK!   From CAN BUS by CAN2: \

⌨️ 快捷键说明

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