]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_MPU_M23_Nuvoton_NuMaker_PFM_M2351_IAR_GCC/Nuvoton_Code/StdDriver/inc/can.h
Add Cortex M23 GCC and IAR ports. Add demo projects for Nuvoton NuMaker-PFM-2351.
[freertos] / FreeRTOS / Demo / CORTEX_MPU_M23_Nuvoton_NuMaker_PFM_M2351_IAR_GCC / Nuvoton_Code / StdDriver / inc / can.h
1 /**************************************************************************//**\r
2  * @file     can.h\r
3  * @version  V1.00\r
4  * @brief    M2351 Series CAN Driver Header File\r
5  *\r
6  * @copyright (C) 2016 Nuvoton Technology Corp. All rights reserved.\r
7  *\r
8  ******************************************************************************/\r
9 #ifndef __CAN_H__\r
10 #define __CAN_H__\r
11 \r
12 \r
13 #ifdef __cplusplus\r
14 extern "C"\r
15 {\r
16 #endif\r
17 \r
18 \r
19 /** @addtogroup Standard_Driver Standard Driver\r
20   @{\r
21 */\r
22 \r
23 /** @addtogroup CAN_Driver CAN Driver\r
24   @{\r
25 */\r
26 \r
27 /** @addtogroup CAN_EXPORTED_CONSTANTS CAN Exported Constants\r
28   @{\r
29 */\r
30 /*---------------------------------------------------------------------------------------------------------*/\r
31 /* CAN Test Mode Constant Definitions                                                                      */\r
32 /*---------------------------------------------------------------------------------------------------------*/\r
33 #define    CAN_NORMAL_MODE   0U    /*!< CAN select normal mode */\r
34 #define    CAN_BASIC_MODE    1U    /*!< CAN select basic mode */\r
35 \r
36 /*---------------------------------------------------------------------------------------------------------*/\r
37 /* Message ID Type Constant Definitions                                                                    */\r
38 /*---------------------------------------------------------------------------------------------------------*/\r
39 #define    CAN_STD_ID    0UL    /*!< CAN select standard ID */\r
40 #define    CAN_EXT_ID    1UL    /*!< CAN select extended ID */\r
41 \r
42 /*---------------------------------------------------------------------------------------------------------*/\r
43 /* Message Frame Type Constant Definitions                                                                 */\r
44 /*---------------------------------------------------------------------------------------------------------*/\r
45 #define    CAN_REMOTE_FRAME    0    /*!< CAN frame select remote frame */\r
46 #define    CAN_DATA_FRAME    1      /*!< CAN frame select data frame */\r
47 \r
48 /*@}*/ /* end of group CAN_EXPORTED_CONSTANTS */\r
49 \r
50 \r
51 /** @addtogroup CAN_EXPORTED_STRUCTS CAN Exported Structs\r
52   @{\r
53 */\r
54 /**\r
55   * @details    CAN message structure\r
56   */\r
57 typedef struct\r
58 {\r
59     uint32_t  IdType;       /*!< ID type */\r
60     uint32_t  FrameType;    /*!< Frame type */\r
61     uint32_t  Id;           /*!< Message ID */\r
62     uint8_t   DLC;          /*!< Data length */\r
63     uint8_t   Data[8];      /*!< Data */\r
64 } STR_CANMSG_T;\r
65 \r
66 /**\r
67   * @details    CAN mask message structure\r
68   */\r
69 typedef struct\r
70 {\r
71     uint8_t   u8Xtd;      /*!< Extended ID */\r
72     uint8_t   u8Dir;      /*!< Direction */\r
73     uint32_t  u32Id;      /*!< Message ID */\r
74     uint8_t   u8IdType;   /*!< ID type*/\r
75 } STR_CANMASK_T;\r
76 \r
77 /*@}*/ /* end of group CAN_EXPORTED_STRUCTS */\r
78 \r
79 /** @cond HIDDEN_SYMBOLS */\r
80 #define MSG(id)  (id)\r
81 /** @endcond HIDDEN_SYMBOLS */\r
82 \r
83 /** @addtogroup CAN_EXPORTED_FUNCTIONS CAN Exported Functions\r
84   @{\r
85 */\r
86 \r
87 /**\r
88  * @brief Get interrupt status.\r
89  *\r
90  * @param[in] can The base address of can module.\r
91  *\r
92  * @return CAN module status register value.\r
93  *\r
94  * @details Status Interrupt is generated by bits BOff (CAN_STATUS[7]), EWarn (CAN_STATUS[6]),\r
95  *          EPass (CAN_STATUS[5]), RxOk (CAN_STATUS[4]), TxOk (CAN_STATUS[3]), and LEC (CAN_STATUS[2:0]).\r
96  */\r
97 #define CAN_GET_INT_STATUS(can) ((can)->STATUS)\r
98 \r
99 /**\r
100  * @brief Get specified interrupt pending status.\r
101  *\r
102  * @param[in] can The base address of can module.\r
103  *\r
104  * @return The source of the interrupt.\r
105  *\r
106  * @details If several interrupts are pending, the CAN Interrupt Register will point to the pending interrupt\r
107  *          with the highest priority, disregarding their chronological order.\r
108  */\r
109 #define CAN_GET_INT_PENDING_STATUS(can) ((can)->IIDR)\r
110 \r
111 /**\r
112  * @brief Disable wake-up function.\r
113  *\r
114  * @param[in] can The base address of can module.\r
115  *\r
116  * @return None\r
117  *\r
118  * @details  The macro is used to disable wake-up function.\r
119  */\r
120 #define CAN_DISABLE_WAKEUP(can) ((can)->WU_EN = 0)\r
121 \r
122 /**\r
123  * @brief Enable wake-up function.\r
124  *\r
125  * @param[in] can The base address of can module.\r
126  *\r
127  * @return None\r
128  *\r
129  * @details User can wake-up system when there is a falling edge in the CAN_Rx pin.\r
130  */\r
131 #define CAN_ENABLE_WAKEUP(can) ((can)->WU_EN = CAN_WU_EN_WAKUP_EN_Msk)\r
132 \r
133 /**\r
134  * @brief Get specified Message Object new data into bit value.\r
135  *\r
136  * @param[in] can The base address of can module.\r
137  * @param[in] u32MsgNum Specified Message Object number, valid value are from 0 to 31.\r
138  *\r
139  * @return Specified Message Object new data into bit value.\r
140  *\r
141  * @details The NewDat bit (CAN_IFn_MCON[15]) of a specific Message Object can be set/reset by the software through the IFn Message Interface Registers\r
142  *          or by the Message Handler after reception of a Data Frame or after a successful transmission.\r
143  */\r
144 #define CAN_GET_NEW_DATA_IN_BIT(can, u32MsgNum) ((u32MsgNum) < 16 ? (can)->NDAT1 & (1 << (u32MsgNum)) : (can)->NDAT2 & (1 << ((u32MsgNum)-16)))\r
145 \r
146 \r
147 /*---------------------------------------------------------------------------------------------------------*/\r
148 /* Define CAN functions prototype                                                                          */\r
149 /*---------------------------------------------------------------------------------------------------------*/\r
150 uint32_t CAN_SetBaudRate(CAN_T *tCAN, uint32_t u32BaudRate);\r
151 void CAN_Close(CAN_T *tCAN);\r
152 uint32_t CAN_Open(CAN_T *tCAN, uint32_t u32BaudRate, uint32_t u32Mode);\r
153 void CAN_CLR_INT_PENDING_BIT(CAN_T *tCAN, uint8_t u32MsgNum);\r
154 void CAN_EnableInt(CAN_T *tCAN, uint32_t u32Mask);\r
155 void CAN_DisableInt(CAN_T *tCAN, uint32_t u32Mask);\r
156 int32_t CAN_Transmit(CAN_T *tCAN, uint32_t u32MsgNum, STR_CANMSG_T* pCanMsg);\r
157 int32_t CAN_Receive(CAN_T *tCAN, uint32_t u32MsgNum, STR_CANMSG_T* pCanMsg);\r
158 int32_t CAN_SetMultiRxMsg(CAN_T *tCAN, uint32_t u32MsgNum, uint32_t u32MsgCount, uint32_t u32IDType, uint32_t u32ID);\r
159 int32_t CAN_SetRxMsg(CAN_T *tCAN, uint32_t u32MsgNum, uint32_t u32IDType, uint32_t u32ID);\r
160 int32_t CAN_SetRxMsgAndMsk(CAN_T *tCAN, uint32_t u32MsgNum, uint32_t u32IDType, uint32_t u32ID, uint32_t u32IDMask);\r
161 int32_t CAN_SetTxMsg(CAN_T *tCAN, uint32_t u32MsgNum, STR_CANMSG_T* pCanMsg);\r
162 int32_t CAN_TriggerTxMsg(CAN_T  *tCAN, uint32_t u32MsgNum);\r
163 void CAN_EnterInitMode(CAN_T *tCAN, uint8_t u8Mask);\r
164 void CAN_LeaveInitMode(CAN_T *tCAN);\r
165 void CAN_WaitMsg(CAN_T *tCAN);\r
166 uint32_t CAN_GetCANBitRate(CAN_T *tCAN);\r
167 void CAN_EnterTestMode(CAN_T *tCAN, uint8_t u8TestMask);\r
168 void CAN_LeaveTestMode(CAN_T *tCAN);\r
169 uint32_t CAN_IsNewDataReceived(CAN_T *tCAN, uint8_t u8MsgObj);\r
170 int32_t CAN_BasicSendMsg(CAN_T *tCAN, STR_CANMSG_T* pCanMsg);\r
171 int32_t CAN_BasicReceiveMsg(CAN_T *tCAN, STR_CANMSG_T* pCanMsg);\r
172 int32_t CAN_SetRxMsgObjAndMsk(CAN_T *tCAN, uint8_t u8MsgObj, uint8_t u8idType, uint32_t u32id, uint32_t u32idmask, uint8_t u8singleOrFifoLast);\r
173 int32_t CAN_SetRxMsgObj(CAN_T *tCAN, uint8_t u8MsgObj, uint8_t u8idType, uint32_t u32id, uint8_t u8singleOrFifoLast);\r
174 int32_t CAN_ReadMsgObj(CAN_T *tCAN, uint8_t u8MsgObj, uint8_t u8Release, STR_CANMSG_T* pCanMsg);\r
175 \r
176 \r
177 /*@}*/ /* end of group CAN_EXPORTED_FUNCTIONS */\r
178 \r
179 /*@}*/ /* end of group CAN_Driver */\r
180 \r
181 /*@}*/ /* end of group Standard_Driver */\r
182 \r
183 #ifdef __cplusplus\r
184 }\r
185 #endif\r
186 \r
187 #endif /* __CAN_H__ */\r
188 \r
189 /*** (C) COPYRIGHT 2016 Nuvoton Technology Corp. ***/\r