]> git.sur5r.net Git - freertos/blob - FreeRTOS-Plus/Demo/FreeRTOS_Plus_UDP_and_CLI_LPC1830_GCC/ThirdParty/CMSISv2p10_LPC18xx_DriverLib/inc/lpc18xx_can.h
e1d7f48b5559dd22d4c821b10dad0f8620ff9a13
[freertos] / FreeRTOS-Plus / Demo / FreeRTOS_Plus_UDP_and_CLI_LPC1830_GCC / ThirdParty / CMSISv2p10_LPC18xx_DriverLib / inc / lpc18xx_can.h
1 /**********************************************************************\r
2 * $Id$          lpc18xx_can.h                   2011-06-02\r
3 *//**\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
7 * @version      1.0\r
8 * @date         02. June. 2011\r
9 * @author       NXP MCU SW Application Team\r
10 *\r
11 * Copyright(C) 2011, NXP Semiconductor\r
12 * All rights reserved.\r
13 *\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
26 \r
27 /* Peripheral group ----------------------------------------------------------- */\r
28 /** @defgroup C_CAN C_CAN (Controller Area Network)\r
29  * @ingroup LPC1800CMSIS_FwLib_Drivers\r
30  * @{\r
31  */\r
32 \r
33 #ifndef __LPC18XX_CAN_H\r
34 #define __LPC18XX_CAN_H\r
35 \r
36 /* Includes ------------------------------------------------------------------- */\r
37 #include "LPC18xx.h"\r
38 #include "lpc_types.h"\r
39 \r
40 \r
41 #ifdef __cplusplus\r
42 extern "C"\r
43 {\r
44 #endif\r
45 \r
46 /* Public Macros -------------------------------------------------------------- */\r
47 /** @defgroup C_CAN_Public_Macros  C_CAN Public Macros\r
48  * @{\r
49  */\r
50 \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
53  */\r
54 #define BASIC_MODE              0\r
55 \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
58  */\r
59 #define SILENT_MODE             0\r
60 \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
63  */\r
64 #define LOOPBACK_MODE   0\r
65 \r
66 /** Enables receiving remote frame requests */\r
67 #define REMOTE_ENABLE   1\r
68 \r
69 /**\r
70  * @}\r
71  */\r
72 \r
73 /* Private Macros -------------------------------------------------------------- */\r
74 /** @defgroup C_CAN_Private_Macros  C_CAN Private Macros\r
75  * @{\r
76  */\r
77 \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
82 \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
92  * or\r
93  *  BitRate = Fcclk/(APBDIV * (BRP+1) * ((Tseg1+1)+(Tseg2+1)+1))\r
94  */\r
95 \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
109 \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
121 \r
122 \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
136 \r
137 /**\r
138  * @}\r
139  */\r
140 \r
141 \r
142 /* Public Types --------------------------------------------------------------- */\r
143 /** @defgroup CAN_Public_Types CAN Public Types\r
144  * @{\r
145  */\r
146 \r
147 /*********************************************************************//**\r
148  * @brief CAN enumeration\r
149  **********************************************************************/\r
150 \r
151 /**\r
152  * @brief CAN interface register type definition\r
153  */\r
154 typedef enum CCAN_IFREG\r
155 {\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
167 }CCAN_IFREG_Type;\r
168 \r
169 /**\r
170  * @brief CAN Clock division rate type definition\r
171  */\r
172 typedef enum CCAN_CLKDIV\r
173 {\r
174         CLKDIV1         = 0,\r
175         CLKDIV2         = 1,\r
176         CLKDIV3         = 2,\r
177         CLKDIV5         = 3,\r
178         CLKDIV9         = 4,\r
179         CLKDIV17        = 5,\r
180         CLKDIV33        = 6,\r
181         CLKDIV65        = 7\r
182 }CCAN_CLKDIV_Type;\r
183 \r
184 \r
185 /********************************************************************//**\r
186 * @brief Data structure definition for a CAN message\r
187 **********************************************************************/\r
188 /**\r
189  * @brief CAN message object structure\r
190  */\r
191 typedef struct\r
192 {\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
196 } message_object;\r
197 \r
198 /**\r
199  * @brief CAN call-back function\r
200  */\r
201 typedef void (*MSG_CB)(uint32_t msg_no);\r
202 \r
203 /**\r
204  * @}\r
205  */\r
206 \r
207 \r
208 \r
209 /* Public Functions ----------------------------------------------------------- */\r
210 /** @defgroup CAN_Public_Functions CAN Public Functions\r
211  * @{\r
212  */\r
213 \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
216 \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
220 \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
224 /**\r
225  * @}\r
226  */\r
227 \r
228 #ifdef __cplusplus\r
229 }\r
230 #endif\r
231 \r
232 \r
233 #endif /* __LPC18XX_CAN_H */\r
234 \r
235 /**\r
236  * @}\r
237  */\r
238 /*****************************************************************************\r
239 **                            End Of File\r
240 ******************************************************************************/\r
241 \r