1 /**********************************************************************
\r
2 * $Id$ lpc18xx_can.h 2011-06-02
\r
4 * @file lpc18xx_can.h
\r
5 * @brief Contains all macro definitions and function prototypes
\r
6 * support for CAN firmware library on LPC18xx
\r
8 * @date 02. June. 2011
\r
9 * @author NXP MCU SW Application Team
\r
11 * Copyright(C) 2011, NXP Semiconductor
\r
12 * All rights reserved.
\r
14 ***********************************************************************
\r
15 * Software that is described herein is for illustrative purposes only
\r
16 * which provides customers with programming information regarding the
\r
17 * products. This software is supplied "AS IS" without any warranties.
\r
18 * NXP Semiconductors assumes no responsibility or liability for the
\r
19 * use of the software, conveys no license or title under any patent,
\r
20 * copyright, or mask work right to the product. NXP Semiconductors
\r
21 * reserves the right to make changes in the software without
\r
22 * notification. NXP Semiconductors also make no representation or
\r
23 * warranty that such application will be suitable for the specified
\r
24 * use without further testing or modification.
\r
25 **********************************************************************/
\r
27 /* Peripheral group ----------------------------------------------------------- */
\r
28 /** @defgroup C_CAN C_CAN (Controller Area Network)
\r
29 * @ingroup LPC1800CMSIS_FwLib_Drivers
\r
33 #ifndef __LPC18XX_CAN_H
\r
34 #define __LPC18XX_CAN_H
\r
36 /* Includes ------------------------------------------------------------------- */
\r
37 #include "LPC18xx.h"
\r
38 #include "lpc_types.h"
\r
46 /* Public Macros -------------------------------------------------------------- */
\r
47 /** @defgroup C_CAN_Public_Macros C_CAN Public Macros
\r
51 /** In BASIC_MODE IF1 registers are used directly as TX buffer, IF2 registers are used as RX buffer.
\r
52 * If not BASIC_MODE use message objects and IF registers to communicate with message buffers
\r
54 #define BASIC_MODE 0
\r
56 /** In Silent Mode, the CAN controller is able to receive valid data frames and valid remote
\r
57 * frames, but it sends only recessive bits on the CAN bus, and it cannot start a transmission
\r
59 #define SILENT_MODE 0
\r
61 /** In Loop-back Mode, the CAN Core treats its own transmitted messages as received messages
\r
62 * and stores them (if they pass acceptance filtering) into a Receive Buffer.
\r
64 #define LOOPBACK_MODE 0
\r
66 /** Enables receiving remote frame requests */
\r
67 #define REMOTE_ENABLE 1
\r
73 /* Private Macros -------------------------------------------------------------- */
\r
74 /** @defgroup C_CAN_Private_Macros C_CAN Private Macros
\r
78 /** MAX CAN message obj */
\r
79 #define CAN_MSG_OBJ_MAX 0x0020
\r
80 /** MAX data length */
\r
81 #define CAN_DLC_MAX 8
\r
83 /********************************************************************//**
\r
84 * BRP+1 = Fpclk/(CANBitRate * QUANTAValue)
\r
85 * QUANTAValue = 1 + (Tseg1+1) + (Tseg2+1)
\r
86 * QUANTA value varies based on the Fpclk and sample point
\r
87 * e.g. (1) sample point is 87.5%, Fpclk is 48Mhz
\r
88 * the QUANTA should be 16
\r
89 * (2) sample point is 90%, Fpclk is 12.5Mhz
\r
90 * the QUANTA should be 10
\r
91 * Fpclk = Fclk /APBDIV
\r
93 * BitRate = Fcclk/(APBDIV * (BRP+1) * ((Tseg1+1)+(Tseg2+1)+1))
\r
96 /*********************************************************************//**
\r
97 * @brief CAN Bit Timing Values definitions at 8Mhz
\r
98 **********************************************************************/
\r
99 /** Bitrate: 100K */
\r
100 #define CAN_BITRATE100K12MHZ 0x00004509
\r
101 /** Bitrate: 125K */
\r
102 #define CAN_BITRATE125K12MHZ 0x00004507
\r
103 /** Bitrate: 250K */
\r
104 #define CAN_BITRATE250K12MHZ 0x00004503
\r
105 /** Bitrate: 500K */
\r
106 #define CAN_BITRATE500K12MHZ 0x00004501
\r
107 /** Bitrate: 1000K */
\r
108 #define CAN_BITRATE1000K12MHZ 0x00004500
\r
110 /*********************************************************************//**
\r
111 * @brief CAN Bit Timing Values definitions at 16Mhz
\r
112 **********************************************************************/
\r
113 /** Bitrate: 100K */
\r
114 #define CAN_BITRATE100K16MHZ 0x00005809
\r
115 /** Bitrate: 125K */
\r
116 #define CAN_BITRATE125K16MHZ 0x00005807
\r
117 /** Bitrate: 250K */
\r
118 #define CAN_BITRATE250K16MHZ 0x00005803
\r
119 /** Bitrate: 500K */
\r
120 #define CAN_BITRATE500K16MHZ 0x00005801
\r
123 /*********************************************************************//**
\r
124 * @brief CAN Bit Timing Values definitions at 24Mhz
\r
125 **********************************************************************/
\r
126 /** Bitrate: 100K */
\r
127 #define CAN_BITRATE100K24MHZ 0x00007E09
\r
128 /** Bitrate: 125K */
\r
129 #define CAN_BITRATE125K24MHZ 0x0000450F
\r
130 /** Bitrate: 250K */
\r
131 #define CAN_BITRATE250K24MHZ 0x00004507
\r
132 /** Bitrate: 500K */
\r
133 #define CAN_BITRATE500K24MHZ 0x00004503
\r
134 /** Bitrate: 1000K */
\r
135 #define CAN_BITRATE1000K24MHZ 0x00004501
\r
142 /* Public Types --------------------------------------------------------------- */
\r
143 /** @defgroup CAN_Public_Types CAN Public Types
\r
147 /*********************************************************************//**
\r
148 * @brief CAN enumeration
\r
149 **********************************************************************/
\r
152 * @brief CAN interface register type definition
\r
154 typedef enum CCAN_IFREG
\r
156 CMDREQ = 0, /**< Command request */
\r
157 CMDMSK = 1, /**< Command mask */
\r
158 MSK1 = 2, /**< Mask 1 */
\r
159 MSK2 = 3, /**< Mask 2 */
\r
160 ARB1 = 4, /**< Arbitration 1 */
\r
161 ARB2 = 5, /**< Arbitration 2 */
\r
162 MCTRL = 6, /**< Message control */
\r
163 DA1 = 7, /**< Data A1 */
\r
164 DA2 = 8, /**< Data A2 */
\r
165 DB1 = 9, /**< Data B1 */
\r
166 DB2 = 10 /**< Data B2 */
\r
170 * @brief CAN Clock division rate type definition
\r
172 typedef enum CCAN_CLKDIV
\r
185 /********************************************************************//**
\r
186 * @brief Data structure definition for a CAN message
\r
187 **********************************************************************/
\r
189 * @brief CAN message object structure
\r
193 uint32_t id; /**< ID of message, if bit 30 is set then this is extended frame */
\r
194 uint32_t dlc; /**< Message data length */
\r
195 uint8_t data[8]; /**< Message data */
\r
199 * @brief CAN call-back function
\r
201 typedef void (*MSG_CB)(uint32_t msg_no);
\r
209 /* Public Functions ----------------------------------------------------------- */
\r
210 /** @defgroup CAN_Public_Functions CAN Public Functions
\r
214 void CAN_IRQHandler (void);
\r
215 void CAN_Init( uint32_t BitClk, CCAN_CLKDIV_Type ClkDiv , MSG_CB Tx_cb, MSG_CB Rx_cb);
\r
217 void CAN_ConfigureRxMessageObjects( void );
\r
218 void CAN_RxInt_MessageProcess( uint8_t MsgObjNo );
\r
219 void CAN_TxInt_MessageProcess( uint8_t MsgObjNo );
\r
221 void CAN_Send(uint8_t msg_no, uint32_t *msg_ptr );
\r
222 void CAN_Recv(uint8_t msg_no, uint32_t *msg_ptr, Bool RemoteEnable);
\r
223 void CAN_ReadMsg(uint32_t msg_no, message_object* buff);
\r
233 #endif /* __LPC18XX_CAN_H */
\r
238 /*****************************************************************************
\r
240 ******************************************************************************/
\r