]> git.sur5r.net Git - freertos/blob - FreeRTOS-Plus/Demo/FreeRTOS_Plus_UDP_and_CLI_LPC1830_GCC/ThirdParty/LPCOpen/lpc_core/lpc_ip/ccan_001.h
Update LPC18xx FreeRTOS+UDP demo to use LPCOpen USB and Ethernet drivers.
[freertos] / FreeRTOS-Plus / Demo / FreeRTOS_Plus_UDP_and_CLI_LPC1830_GCC / ThirdParty / LPCOpen / lpc_core / lpc_ip / ccan_001.h
1 /*\r
2  * @brief CCAN registers and control functions\r
3  *\r
4  * @note\r
5  * Copyright(C) NXP Semiconductors, 2012\r
6  * All rights reserved.\r
7  *\r
8  * @par\r
9  * Software that is described herein is for illustrative purposes only\r
10  * which provides customers with programming information regarding the\r
11  * LPC products.  This software is supplied "AS IS" without any warranties of\r
12  * any kind, and NXP Semiconductors and its licensor disclaim any and\r
13  * all warranties, express or implied, including all implied warranties of\r
14  * merchantability, fitness for a particular purpose and non-infringement of\r
15  * intellectual property rights.  NXP Semiconductors assumes no responsibility\r
16  * or liability for the use of the software, conveys no license or rights under any\r
17  * patent, copyright, mask work right, or any other intellectual property rights in\r
18  * or to any products. NXP Semiconductors reserves the right to make changes\r
19  * in the software without notification. NXP Semiconductors also makes no\r
20  * representation or warranty that such application will be suitable for the\r
21  * specified use without further testing or modification.\r
22  *\r
23  * @par\r
24  * Permission to use, copy, modify, and distribute this software and its\r
25  * documentation is hereby granted, under NXP Semiconductors' and its\r
26  * licensor's relevant copyrights in the software, without fee, provided that it\r
27  * is used in conjunction with NXP Semiconductors microcontrollers.  This\r
28  * copyright, permission, and disclaimer notice must appear in all copies of\r
29  * this code.\r
30  */\r
31 \r
32 #ifndef __CCAN_001_H_\r
33 #define __CCAN_001_H_\r
34 \r
35 #include "sys_config.h"\r
36 #include "cmsis.h"\r
37 \r
38 #ifdef __cplusplus\r
39 extern "C" {\r
40 #endif\r
41 \r
42 /** @defgroup IP_CCAN_001 IP: CCAN register block and driver\r
43  * @ingroup IP_Drivers\r
44  * @{\r
45  */\r
46 \r
47 /**\r
48  * @brief CCAN message interface register block structure\r
49  */\r
50 typedef struct {        /*!< C_CAN message interface Structure       */\r
51         __IO uint32_t IF_CMDREQ;                        /*!< Message interface command request  */\r
52         union {\r
53                 __IO uint32_t IF_CMDMSK_R;              /*!< Message interface command mask (read direction) */\r
54                 __IO uint32_t IF_CMDMSK_W;              /*!< Message interface command mask (write direction) */\r
55         };\r
56 \r
57         __IO uint32_t IF_MSK1;                          /*!< Message interface mask 1 */\r
58         __IO uint32_t IF_MSK2;                          /*!< Message interface mask 2 */\r
59         __IO uint32_t IF_ARB1;                          /*!< Message interface arbitration 1 */\r
60         __IO uint32_t IF_ARB2;                          /*!< Message interface arbitration 2 */\r
61         __IO uint32_t IF_MCTRL;                 /*!< Message interface message control */\r
62         __IO uint32_t IF_DA1;                           /*!< Message interface data A1 */\r
63         __IO uint32_t IF_DA2;                           /*!< Message interface data A2 */\r
64         __IO uint32_t IF_DB1;                           /*!< Message interface data B1 */\r
65         __IO uint32_t IF_DB2;                           /*!< Message interface data B2 */\r
66         __I  uint32_t  RESERVED[13];\r
67 } IP_CCAN_001_IF_T;\r
68 \r
69 /**\r
70  * @brief CCAN Controller Area Network register block structure\r
71  */\r
72 typedef struct {                                                /*!< C_CAN Structure       */\r
73         __IO uint32_t CNTL;                                     /*!< CAN control            */\r
74         __IO uint32_t STAT;                                     /*!< Status register        */\r
75         __I  uint32_t EC;                                       /*!< Error counter          */\r
76         __IO uint32_t BT;                                       /*!< Bit timing register    */\r
77         __I  uint32_t INT;                                      /*!< Interrupt register     */\r
78         __IO uint32_t TEST;                                     /*!< Test register          */\r
79         __IO uint32_t BRPE;                                     /*!< Baud rate prescaler extension register */\r
80         __I  uint32_t  RESERVED0;\r
81         IP_CCAN_001_IF_T IF[2];\r
82         __I  uint32_t  RESERVED2[8];\r
83         __I  uint32_t TXREQ1;                           /*!< Transmission request 1 */\r
84         __I  uint32_t TXREQ2;                           /*!< Transmission request 2 */\r
85         __I  uint32_t  RESERVED3[6];\r
86         __I  uint32_t ND1;                                      /*!< New data 1             */\r
87         __I  uint32_t ND2;                                      /*!< New data 2             */\r
88         __I  uint32_t  RESERVED4[6];\r
89         __I  uint32_t IR1;                                      /*!< Interrupt pending 1    */\r
90         __I  uint32_t IR2;                                      /*!< Interrupt pending 2    */\r
91         __I  uint32_t  RESERVED5[6];\r
92         __I  uint32_t MSGV1;                            /*!< Message valid 1        */\r
93         __I  uint32_t MSGV2;                            /*!< Message valid 2        */\r
94         __I  uint32_t  RESERVED6[6];\r
95         __IO uint32_t CLKDIV;                           /*!< CAN clock divider register */\r
96 } IP_CCAN_001_T;\r
97 \r
98 typedef enum IP_CCAN_TEST_MODE {\r
99         CCAN_BASIC_TEST_MODE = 1 << 2,\r
100         CCAN_SILENT_TEST_MODE = 1 << 3,\r
101         CCAN_LOOPBACK_TEST_MODE = 1 << 4\r
102 } IP_CCAN_TEST_MODE_T;\r
103 \r
104 typedef enum IP_CCAN_INT {\r
105         CCAN_MODULE_INT = 1 << 1,\r
106         CCAN_STATUS_CHANGE_INT = 1 << 2,\r
107         CCAN_ERR_INT = 1 << 3\r
108 } IP_CCAN_INT_T;\r
109 \r
110 /**\r
111  * @brief CAN message object structure\r
112  */\r
113 typedef struct {\r
114         uint32_t    id;         /**< ID of message, if bit 30 is set then this is extended frame */\r
115         uint32_t    dlc;        /**< Message data length */\r
116         uint8_t data[8];        /**< Message data */\r
117 } message_object;\r
118 typedef enum IP_CCAN_MSG_INTERFACE {\r
119         IF1 = 0x00,\r
120         IF2 = 1,\r
121 } IP_CCAN_MSG_INTERFACE_T;\r
122 typedef enum IP_CCAN_STATUS {\r
123         CCAN_STAT_LEC       = (0x7 << 0),\r
124         CCAN_STAT_TXOK      = (1 << 3),\r
125         CCAN_STAT_RXOK      = (1 << 4),\r
126         CCAN_STAT_EPASS = (1 << 5),\r
127         CCAN_STAT_EWARN = (1 << 6),\r
128         CCAN_STAT_BOFF      = (1 << 7)\r
129 } IP_CCAN_STATUS_T;\r
130 \r
131 /**\r
132  * @brief I2S transmit/receive mode for configuration\r
133  */\r
134 typedef enum IP_CCAN_TRX_MODE {\r
135         CCAN_TX_MODE,\r
136         CCAN_RX_MODE,\r
137 } IP_CCAN_TRX_MODE_T;\r
138 /* Private Macros ---------------------------------------------------------- */\r
139 #ifndef __GNUC__\r
140 /* Macro for reading and writing to CCAN IF registers */\r
141 #define CCAN_IF_Read(LPCx, reg, IFsel) (( ## LPCx ## ->IF ## [IFsel] ## . ## IF ## _ ## reg))\r
142 #define CCAN_IF_Write(LPCx, reg, IFsel, val) (( ## LPCx ## ->IF ## [IFsel] ## . ## IF ## _ ## reg) = (val))\r
143 #else\r
144 #define CCAN_IF_Read(LPCx, reg, IFsel) (LPCx->IF[IFsel].IF ## _ ## reg)\r
145 #define CCAN_IF_Write(LPCx, reg, IFsel, val) (LPCx->IF[IFsel].IF ## _ ## reg = val)\r
146 #endif\r
147 \r
148 #define CCAN_STATUS_INT 0x8000\r
149 \r
150 #define CCAN_TX_DIR 1UL\r
151 #define CCAN_RX_DIR 0UL\r
152 \r
153 /* bit field of IF command mask register */\r
154 #define CCAN_DATAB      (1 << 0)        /* 1 is transfer data byte 4-7 to message object, 0 is not */\r
155 #define CCAN_DATAA      (1 << 1)        /* 1 is transfer data byte 0-3 to message object, 0 is not */\r
156 #define CCAN_NEWDAT     (1 << 2)        /* Clear NEWDAT bit in the message object */\r
157 #define CCAN_CLRINTPND  (1 << 3)\r
158 #define CCAN_CTRL       (1 << 4)        /* 1 is transfer the CTRL bit to the message object, 0 is not */\r
159 #define CCAN_ARB        (1 << 5)        /* 1 is transfer the ARB bits to the message object, 0 is not */\r
160 #define CCAN_MASK       (1 << 6)        /* 1 is transfer the MASK bit to the message object, 0 is not */\r
161 #define CCAN_RW(n)      (((n) & 1UL) << 7)      /* 0 is READ, 1 is WRITE */\r
162 #define CCAN_WR 1UL\r
163 #define CCAN_RD 0UL\r
164 \r
165 /* bit field of IF mask 2 register */\r
166 #define CCAN_MASK_MXTD  (1 << 15)               /* 1 extended identifier bit is used in the RX filter unit, 0 is not */\r
167 #define CCAN_MASK_MDIR(n)   (((n) & 0x01) <<  14)               /* 1 direction bit is used in the RX filter unit, 0 is not */\r
168 \r
169 /* bit field of IF identifier 2 register */\r
170 #define CCAN_ID_MVAL    (1 << 15)               /* Message valid bit, 1 is valid in the MO handler, 0 is ignored */\r
171 #define CCAN_ID_MTD     (1 << 14)               /* 1 extended identifier bit is used in the RX filter unit, 0 is not */\r
172 #define CCAN_ID_DIR(n)  (((n) & 0x01) << 13)    /* 1 direction bit is used in the RX filter unit, 0 is not */\r
173 \r
174 /* bit field of IF message control register */\r
175 #define CCAN_NEWD       (1 << 15)               /* 1 indicates new data is in the message buffer.  */\r
176 #define CCAN_MLST       (1 << 14)               /* 1 indicates a message loss. */\r
177 #define CCAN_INTP       (1 << 13)               /* 1 indicates message object is an interrupt source */\r
178 #define CCAN_UMSK       (1 << 12)               /* 1 is to use the mask for the receive filter mask. */\r
179 #define CCAN_TXIE       (1 << 11)               /* 1 is TX interrupt enabled */\r
180 #define CCAN_RXIE       (1 << 10)               /* 1 is RX interrupt enabled */\r
181 \r
182 #define CCAN_RMTEN(n)       (((n) & 1UL) << 9)  /* 1 is remote frame enabled */\r
183 \r
184 #define CCAN_TXRQ       (1 << 8)                /* 1 is TxRqst enabled */\r
185 #define CCAN_EOB        (1 << 7)                /* End of buffer, always write to 1 */\r
186 #define CCAN_DLC        0x000F                  /* bit mask for DLC */\r
187 \r
188 #define CCAN_ID_STD_MASK    0x07FF\r
189 #define CCAN_ID_EXT_MASK    0x1FFFFFFF\r
190 #define CCAN_DLC_MASK       0x0F\r
191 \r
192 /* bit field of IF command request n register */\r
193 #define CCAN_IFCREQ_BUSY               0x8000   /* 1 is writing is progress, cleared when\r
194                                                                                                    RD/WR done */\r
195 /* CAN CTRL register */\r
196 #define CCAN_CTRL_INIT      (1 << 0)\r
197 #define CCAN_CTRL_IE            (1 << 1)\r
198 #define CCAN_CTRL_SIE       (1 << 2)\r
199 #define CCAN_CTRL_EIE       (1 << 3)\r
200 #define CCAN_CTRL_DAR       (1 << 5)\r
201 #define CCAN_CTRL_CCE       (1 << 6)\r
202 #define CCAN_CTRL_TEST      (1 << 7)\r
203 \r
204 /**\r
205  * @brief       Configure the bit timing for CCAN bus\r
206  * @param       pCCAN                           : The base of CCAN peripheral on the chip\r
207  * @param       ClkDiv                          : Set the clock divider\r
208  * @param       BaudRatePrescaler       : Set the baud rate Prescaler\r
209  * @param       SynJumpWidth            : Set the synchronization jump width\r
210  * @param       Tseg1                           : Set the Phase buffer segment 1\r
211  * @param       Tseg2                           : Set the Phase buffer segment 2\r
212  * @return      Nothing\r
213  */\r
214 void IP_CCAN_TimingCfg (IP_CCAN_001_T *pCCAN,\r
215                                                 uint32_t ClkDiv,\r
216                                                 uint32_t BaudRatePrescaler,\r
217                                                 uint8_t SynJumpWidth,\r
218                                                 uint8_t Tseg1,\r
219                                                 uint8_t Tseg2);\r
220 \r
221 /**\r
222  * @brief       Initialize the CAN controller\r
223  * @param       pCCAN                   : The base of CCAN peripheral on the chip\r
224  * @param       NewState                : New state, ENABLE for starting initialization, DISABLE for normal operation\r
225  * @return      Nothing\r
226  */\r
227 void IP_CCAN_SWInit (IP_CCAN_001_T *pCCAN, FunctionalState NewState);\r
228 \r
229 /**\r
230  * @brief       Enable/Disable CCAN Interrupts\r
231  * @param       pCCAN                   : The base of CCAN peripheral on the chip\r
232  * @param       Int_type                : Type of interrupt\r
233  * @param       NewState                : New state, ENABLE or DISABLE\r
234  * @return      Nothing\r
235  */\r
236 void IP_CCAN_IntEnable (IP_CCAN_001_T *pCCAN, IP_CCAN_INT_T Int_type, FunctionalState NewState);\r
237 \r
238 /**\r
239  * @brief       Enable/Disable automatic retransmission\r
240  * @param       pCCAN                   : The base of CCAN peripheral on the chip\r
241  * @param       NewState                : New state, ENABLE or DISABLE\r
242  * @return      Nothing\r
243  */\r
244 void IP_CCAN_AutoRetransmitEnable (IP_CCAN_001_T *pCCAN, FunctionalState NewState);\r
245 \r
246 /**\r
247  * @brief       Get the current value of the transmit/receive error counter\r
248  * @param       pCCAN   : The base of CCAN peripheral on the chip\r
249  * @param       TRMode  : Transmit/Receive mode, should be CCAN_TX_MODE or CCAN_RX_MODE\r
250  * @return      Current value of the transmit/receive error counter\r
251  */\r
252 uint8_t IP_CCAN_GetErrCounter (IP_CCAN_001_T *pCCAN, IP_CCAN_TRX_MODE_T TRMode);\r
253 \r
254 /**\r
255  * @brief       Get the CCAN status register\r
256  * @param       pCCAN   : The base of CCAN peripheral on the chip\r
257  * @return      CCAN status register\r
258  */\r
259 uint32_t IP_CCAN_GetStatus (IP_CCAN_001_T *pCCAN);\r
260 \r
261 /**\r
262  * @brief       Set the CCAN status\r
263  * @param       pCCAN   : The base of CCAN peripheral on the chip\r
264  * @param       val             : Value to be set for status register\r
265  * @return      Nothing\r
266  */\r
267 void IP_CCAN_SetStatus (IP_CCAN_001_T *pCCAN, uint32_t val);\r
268 \r
269 /**\r
270  * @brief       Get the source ID of an interrupt\r
271  * @param       pCCAN   : The base of CCAN peripheral on the chip\r
272  * @return      Interrupt source ID\r
273  */\r
274 uint32_t IP_CCAN_Get_IntID (IP_CCAN_001_T *pCCAN);\r
275 \r
276 /**\r
277  * @brief       Enable/Disable test mode in CCAN\r
278  * @param       pCCAN           : The base of CCAN peripheral on the chip\r
279  * @param       test_mode       : Selected mode, the different test functions may be combined\r
280  * @param       NewState        : New state, ENABLE or DISABLE\r
281  * @return      Nothing\r
282  */\r
283 void IP_CCAN_TestModeEnable(IP_CCAN_001_T *pCCAN, IP_CCAN_TEST_MODE_T test_mode, FunctionalState NewState);\r
284 \r
285 /**\r
286  * @brief       Clear interrupt pending bit in the message object\r
287  * @param       pCCAN   : The base of CCAN peripheral on the chip\r
288  * @param       IFsel   : The Message interface to be used\r
289  * @param       msg_num : Message number\r
290  * @return      Nothing\r
291  */\r
292 void IP_CCAN_ClearIntPend (IP_CCAN_001_T *pCCAN, IP_CCAN_MSG_INTERFACE_T IFsel, uint8_t msg_num);\r
293 \r
294 /**\r
295  * @brief       Clear new data flag bit in the message object\r
296  * @param       pCCAN   : The base of CCAN peripheral on the chip\r
297  * @param       IFsel   : The Message interface to be used\r
298  * @param       msg_num : Message number\r
299  * @return      Nothing\r
300  */\r
301 void IP_CCAN_Clear_NewDataFlag (IP_CCAN_001_T *pCCAN, IP_CCAN_MSG_INTERFACE_T IFsel, uint8_t msg_num);\r
302 \r
303 /**\r
304  * @brief       Enable/Disable the message object to valid\r
305  * @param       pCCAN   : The base of CCAN peripheral on the chip\r
306  * @param       IFsel   : The Message interface to be used\r
307  * @param       msg_num : Message number\r
308  * @param       NewState: New state, ENABLE or DISABLE\r
309  * @return      Nothing\r
310  */\r
311 void IP_CCAN_SetValidMsg(IP_CCAN_001_T *pCCAN, IP_CCAN_MSG_INTERFACE_T IFsel, uint8_t msg_num, FunctionalState NewState);\r
312 \r
313 /**\r
314  * @brief       Check the message objects is valid or not\r
315  * @param       pCCAN   : The base of CCAN peripheral on the chip\r
316  * @return      A 32 bits value, each bit corresponds to a message objects form 0 to 31 (1 is valid, 0 is invalid)\r
317  */\r
318 uint32_t IP_CCAN_GetValidMsg(IP_CCAN_001_T *pCCAN);\r
319 \r
320 /**\r
321  * @brief       Get the transmit repuest bit in all message objects\r
322  * @param       pCCAN   : The base of CCAN peripheral on the chip\r
323  * @return      A 32 bits value, each bit corresponds to transmit request bit in message objects\r
324  */\r
325 uint32_t IP_CCAN_GetTxRQST(IP_CCAN_001_T *pCCAN);\r
326 \r
327 /**\r
328  * @brief       Set a message into the message object in message RAM\r
329  * @param       pCCAN           : The base of CCAN peripheral on the chip\r
330  * @param       IFsel           : The Message interface to be used\r
331  * @param       direction       : Select the message object is used for transmiting or receiving, should be CCAN_TX_DIR or CCAN_RX_DIR\r
332  * @param       RemoteEnable: Enable/Disable passives transmit by using remote frame\r
333  * @param       msg_num         : Message number\r
334  * @param       msg_ptr         : Pointer of message to be set\r
335  * @return      Nothing\r
336  */\r
337 void IP_CCAN_SetMsgObject (IP_CCAN_001_T *pCCAN,\r
338                                                    IP_CCAN_MSG_INTERFACE_T IFsel,\r
339                                                    uint8_t direction,\r
340                                                    uint32_t RemoteEnable,\r
341                                                    uint8_t msg_num,\r
342                                                    const message_object *msg_ptr);\r
343 \r
344 /**\r
345  * @brief       Get a message object in message RAM into the message buffer\r
346  * @param       pCCAN           : The base of CCAN peripheral on the chip\r
347  * @param       IFsel           : The Message interface to be used\r
348  * @param       msg_num         : The number of message object in message RAM to be get\r
349  * @param       msg_buf         : Pointer of the message buffer\r
350  * @return      Nothing\r
351  */\r
352 void IP_CCAN_GetMsgObject (IP_CCAN_001_T *pCCAN,\r
353                                                    IP_CCAN_MSG_INTERFACE_T IFsel,\r
354                                                    uint8_t msg_num,\r
355                                                    message_object *msg_buf);\r
356 \r
357 /**\r
358  * @}\r
359  */\r
360 \r
361 #ifdef __cplusplus\r
362 }\r
363 #endif\r
364 \r
365 #endif /* __CCAN_001_H_ */\r