1 /**************************************************************************//**
\r
4 * @brief M2351 Series CAN Driver Header File
\r
6 * @copyright (C) 2016 Nuvoton Technology Corp. All rights reserved.
\r
8 ******************************************************************************/
\r
19 /** @addtogroup Standard_Driver Standard Driver
\r
23 /** @addtogroup CAN_Driver CAN Driver
\r
27 /** @addtogroup CAN_EXPORTED_CONSTANTS CAN Exported Constants
\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
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
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
48 /*@}*/ /* end of group CAN_EXPORTED_CONSTANTS */
\r
51 /** @addtogroup CAN_EXPORTED_STRUCTS CAN Exported Structs
\r
55 * @details CAN message structure
\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
67 * @details CAN mask message structure
\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
77 /*@}*/ /* end of group CAN_EXPORTED_STRUCTS */
\r
79 /** @cond HIDDEN_SYMBOLS */
\r
80 #define MSG(id) (id)
\r
81 /** @endcond HIDDEN_SYMBOLS */
\r
83 /** @addtogroup CAN_EXPORTED_FUNCTIONS CAN Exported Functions
\r
88 * @brief Get interrupt status.
\r
90 * @param[in] can The base address of can module.
\r
92 * @return CAN module status register value.
\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
97 #define CAN_GET_INT_STATUS(can) ((can)->STATUS)
\r
100 * @brief Get specified interrupt pending status.
\r
102 * @param[in] can The base address of can module.
\r
104 * @return The source of the interrupt.
\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
109 #define CAN_GET_INT_PENDING_STATUS(can) ((can)->IIDR)
\r
112 * @brief Disable wake-up function.
\r
114 * @param[in] can The base address of can module.
\r
118 * @details The macro is used to disable wake-up function.
\r
120 #define CAN_DISABLE_WAKEUP(can) ((can)->WU_EN = 0)
\r
123 * @brief Enable wake-up function.
\r
125 * @param[in] can The base address of can module.
\r
129 * @details User can wake-up system when there is a falling edge in the CAN_Rx pin.
\r
131 #define CAN_ENABLE_WAKEUP(can) ((can)->WU_EN = CAN_WU_EN_WAKUP_EN_Msk)
\r
134 * @brief Get specified Message Object new data into bit value.
\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
139 * @return Specified Message Object new data into bit value.
\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
144 #define CAN_GET_NEW_DATA_IN_BIT(can, u32MsgNum) ((u32MsgNum) < 16 ? (can)->NDAT1 & (1 << (u32MsgNum)) : (can)->NDAT2 & (1 << ((u32MsgNum)-16)))
\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
177 /*@}*/ /* end of group CAN_EXPORTED_FUNCTIONS */
\r
179 /*@}*/ /* end of group CAN_Driver */
\r
181 /*@}*/ /* end of group Standard_Driver */
\r
187 #endif /* __CAN_H__ */
\r
189 /*** (C) COPYRIGHT 2016 Nuvoton Technology Corp. ***/
\r