2 * @brief CCAN registers and control functions
\r
5 * Copyright(C) NXP Semiconductors, 2012
\r
6 * All rights reserved.
\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
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
32 #ifndef __CCAN_001_H_
\r
33 #define __CCAN_001_H_
\r
35 #include "sys_config.h"
\r
42 /** @defgroup IP_CCAN_001 IP: CCAN register block and driver
\r
43 * @ingroup IP_Drivers
\r
48 * @brief CCAN message interface register block structure
\r
50 typedef struct { /*!< C_CAN message interface Structure */
\r
51 __IO uint32_t IF_CMDREQ; /*!< Message interface command request */
\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
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
70 * @brief CCAN Controller Area Network register block structure
\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
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
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
111 * @brief CAN message object structure
\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
118 typedef enum IP_CCAN_MSG_INTERFACE {
\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
132 * @brief I2S transmit/receive mode for configuration
\r
134 typedef enum IP_CCAN_TRX_MODE {
\r
137 } IP_CCAN_TRX_MODE_T;
\r
138 /* Private Macros ---------------------------------------------------------- */
\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
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
148 #define CCAN_STATUS_INT 0x8000
\r
150 #define CCAN_TX_DIR 1UL
\r
151 #define CCAN_RX_DIR 0UL
\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
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
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
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
182 #define CCAN_RMTEN(n) (((n) & 1UL) << 9) /* 1 is remote frame enabled */
\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
188 #define CCAN_ID_STD_MASK 0x07FF
\r
189 #define CCAN_ID_EXT_MASK 0x1FFFFFFF
\r
190 #define CCAN_DLC_MASK 0x0F
\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
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
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
214 void IP_CCAN_TimingCfg (IP_CCAN_001_T *pCCAN,
\r
216 uint32_t BaudRatePrescaler,
\r
217 uint8_t SynJumpWidth,
\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
227 void IP_CCAN_SWInit (IP_CCAN_001_T *pCCAN, FunctionalState NewState);
\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
236 void IP_CCAN_IntEnable (IP_CCAN_001_T *pCCAN, IP_CCAN_INT_T Int_type, FunctionalState NewState);
\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
244 void IP_CCAN_AutoRetransmitEnable (IP_CCAN_001_T *pCCAN, FunctionalState NewState);
\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
252 uint8_t IP_CCAN_GetErrCounter (IP_CCAN_001_T *pCCAN, IP_CCAN_TRX_MODE_T TRMode);
\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
259 uint32_t IP_CCAN_GetStatus (IP_CCAN_001_T *pCCAN);
\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
267 void IP_CCAN_SetStatus (IP_CCAN_001_T *pCCAN, uint32_t val);
\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
274 uint32_t IP_CCAN_Get_IntID (IP_CCAN_001_T *pCCAN);
\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
283 void IP_CCAN_TestModeEnable(IP_CCAN_001_T *pCCAN, IP_CCAN_TEST_MODE_T test_mode, FunctionalState NewState);
\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
292 void IP_CCAN_ClearIntPend (IP_CCAN_001_T *pCCAN, IP_CCAN_MSG_INTERFACE_T IFsel, uint8_t msg_num);
\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
301 void IP_CCAN_Clear_NewDataFlag (IP_CCAN_001_T *pCCAN, IP_CCAN_MSG_INTERFACE_T IFsel, uint8_t msg_num);
\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
311 void IP_CCAN_SetValidMsg(IP_CCAN_001_T *pCCAN, IP_CCAN_MSG_INTERFACE_T IFsel, uint8_t msg_num, FunctionalState NewState);
\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
318 uint32_t IP_CCAN_GetValidMsg(IP_CCAN_001_T *pCCAN);
\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
325 uint32_t IP_CCAN_GetTxRQST(IP_CCAN_001_T *pCCAN);
\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
337 void IP_CCAN_SetMsgObject (IP_CCAN_001_T *pCCAN,
\r
338 IP_CCAN_MSG_INTERFACE_T IFsel,
\r
340 uint32_t RemoteEnable,
\r
342 const message_object *msg_ptr);
\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
352 void IP_CCAN_GetMsgObject (IP_CCAN_001_T *pCCAN,
\r
353 IP_CCAN_MSG_INTERFACE_T IFsel,
\r
355 message_object *msg_buf);
\r
365 #endif /* __CCAN_001_H_ */
\r