| M480 BSP V3.05.001 The Board Support Package for M480 Series

can.h
Go to the documentation of this file.
1 /**************************************************************************/
9 #ifndef __CAN_H__
10 #define __CAN_H__
11
12 #ifdef __cplusplus
13 extern "C"
14 {
15 #endif
16
17
29 /*---------------------------------------------------------------------------------------------------------*/
30 /* CAN Test Mode Constant Definitions */
31 /*---------------------------------------------------------------------------------------------------------*/
32 #define CAN_NORMAL_MODE 0ul
33 #define CAN_BASIC_MODE 1ul
35 /*---------------------------------------------------------------------------------------------------------*/
36 /* Message ID Type Constant Definitions */
37 /*---------------------------------------------------------------------------------------------------------*/
38 #define CAN_STD_ID 0ul
39 #define CAN_EXT_ID 1ul
41 /*---------------------------------------------------------------------------------------------------------*/
42 /* Message Frame Type Constant Definitions */
43 /*---------------------------------------------------------------------------------------------------------*/
44 #define CAN_REMOTE_FRAME 0ul
45 #define CAN_DATA_FRAME 1ul
47 /* end of group CAN_EXPORTED_CONSTANTS */
48
49
56 typedef struct
57 {
58 uint32_t IdType;
59 uint32_t FrameType;
60 uint32_t Id;
61 uint8_t DLC;
62 uint8_t Data[8];
63 } STR_CANMSG_T;
64
68 typedef struct
69 {
70 uint8_t u8Xtd;
71 uint8_t u8Dir;
72 uint32_t u32Id;
73 uint8_t u8IdType;
74 } STR_CANMASK_T;
75 /* end of group CAN_EXPORTED_STRUCTS */
77
79 #define MSG(id) (id)
80
97 #define CAN_GET_INT_STATUS(can) ((can)->STATUS)
98
110 #define CAN_GET_INT_PENDING_STATUS(can) ((can)->IIDR)
111
122 #define CAN_DISABLE_WAKEUP(can) ((can)->WU_EN = 0ul)
123
134 #define CAN_ENABLE_WAKEUP(can) ((can)->WU_EN = CAN_WU_EN_WAKUP_EN_Msk)
135
148 #define CAN_GET_NEW_DATA_IN_BIT(can, u32MsgNum) ((u32MsgNum) < 16 ? (can)->NDAT1 & (1 << (u32MsgNum)) : (can)->NDAT2 & (1 << ((u32MsgNum)-16)))
149
150
151 /*---------------------------------------------------------------------------------------------------------*/
152 /* Define CAN functions prototype */
153 /*---------------------------------------------------------------------------------------------------------*/
154 uint32_t CAN_SetBaudRate(CAN_T *tCAN, uint32_t u32BaudRate);
155 uint32_t CAN_Open(CAN_T *tCAN, uint32_t u32BaudRate, uint32_t u32Mode);
156 void CAN_Close(CAN_T *tCAN);
157 void CAN_CLR_INT_PENDING_BIT(CAN_T *tCAN, uint8_t u32MsgNum);
158 void CAN_EnableInt(CAN_T *tCAN, uint32_t u32Mask);
159 void CAN_DisableInt(CAN_T *tCAN, uint32_t u32Mask);
160 int32_t CAN_Transmit(CAN_T *tCAN, uint32_t u32MsgNum, STR_CANMSG_T* pCanMsg);
161 int32_t CAN_Receive(CAN_T *tCAN, uint32_t u32MsgNum, STR_CANMSG_T* pCanMsg);
162 int32_t CAN_SetMultiRxMsg(CAN_T *tCAN, uint32_t u32MsgNum, uint32_t u32MsgCount, uint32_t u32IDType, uint32_t u32ID);
163 int32_t CAN_SetRxMsg(CAN_T *tCAN, uint32_t u32MsgNum, uint32_t u32IDType, uint32_t u32ID);
164 int32_t CAN_SetRxMsgAndMsk(CAN_T *tCAN, uint32_t u32MsgNum, uint32_t u32IDType, uint32_t u32ID, uint32_t u32IDMask);
165 int32_t CAN_SetTxMsg(CAN_T *tCAN, uint32_t u32MsgNum, STR_CANMSG_T* pCanMsg);
166 int32_t CAN_TriggerTxMsg(CAN_T *tCAN, uint32_t u32MsgNum);
167 int32_t CAN_BasicSendMsg(CAN_T *tCAN, STR_CANMSG_T* pCanMsg);
168 int32_t CAN_BasicReceiveMsg(CAN_T *tCAN, STR_CANMSG_T* pCanMsg);
169 void CAN_EnterInitMode(CAN_T *tCAN, uint8_t u8Mask);
170 void CAN_EnterTestMode(CAN_T *tCAN, uint8_t u8TestMask);
171 void CAN_LeaveTestMode(CAN_T *tCAN);
172 uint32_t CAN_GetCANBitRate(CAN_T *tCAN);
173 uint32_t CAN_IsNewDataReceived(CAN_T *tCAN, uint8_t u8MsgObj);
174 void CAN_LeaveInitMode(CAN_T *tCAN);
175 int32_t CAN_SetRxMsgObjAndMsk(CAN_T *tCAN, uint8_t u8MsgObj, uint8_t u8idType, uint32_t u32id, uint32_t u32idmask, uint8_t u8singleOrFifoLast);
176 int32_t CAN_SetRxMsgObj(CAN_T *tCAN, uint8_t u8MsgObj, uint8_t u8idType, uint32_t u32id, uint8_t u8singleOrFifoLast);
177 void CAN_WaitMsg(CAN_T *tCAN);
178 int32_t CAN_ReadMsgObj(CAN_T *tCAN, uint8_t u8MsgObj, uint8_t u8Release, STR_CANMSG_T* pCanMsg);
179 /* end of group CAN_EXPORTED_FUNCTIONS */
181 /* end of group CAN_Driver */
183 /* end of group Standard_Driver */
185
186 #ifdef __cplusplus
187 }
188 #endif
189
190 #endif /*__CAN_H__ */
191
192 /*** (C) COPYRIGHT 2016 Nuvoton Technology Corp. ***/
CAN_SetRxMsgObjAndMsk
int32_t CAN_SetRxMsgObjAndMsk(CAN_T *tCAN, uint8_t u8MsgObj, uint8_t u8idType, uint32_t u32id, uint32_t u32idmask, uint8_t u8singleOrFifoLast)
Set Rx message object, include ID mask.
Definition: can.c:538
CAN_Receive
int32_t CAN_Receive(CAN_T *tCAN, uint32_t u32MsgNum, STR_CANMSG_T *pCanMsg)
Gets the message, if received.
Definition: can.c:1238
STR_CANMASK_T::u8Dir
uint8_t u8Dir
Definition: can.h:71
CAN_DisableInt
void CAN_DisableInt(CAN_T *tCAN, uint32_t u32Mask)
Disable CAN interrupt.
Definition: can.c:1052
CAN_SetMultiRxMsg
int32_t CAN_SetMultiRxMsg(CAN_T *tCAN, uint32_t u32MsgNum, uint32_t u32MsgCount, uint32_t u32IDType, uint32_t u32ID)
The function is used to configure several receive message objects.
Definition: can.c:1148
CAN_SetRxMsgObj
int32_t CAN_SetRxMsgObj(CAN_T *tCAN, uint8_t u8MsgObj, uint8_t u8idType, uint32_t u32id, uint8_t u8singleOrFifoLast)
Set Rx message object.
Definition: can.c:608
CAN_SetRxMsg
int32_t CAN_SetRxMsg(CAN_T *tCAN, uint32_t u32MsgNum, uint32_t u32IDType, uint32_t u32ID)
The function is used to configure a receive message object.
Definition: can.c:1074
STR_CANMASK_T::u8IdType
uint8_t u8IdType
Definition: can.h:73
CAN_Transmit
int32_t CAN_Transmit(CAN_T *tCAN, uint32_t u32MsgNum, STR_CANMSG_T *pCanMsg)
Send CAN message.
Definition: can.c:1199
CAN_EnterInitMode
void CAN_EnterInitMode(CAN_T *tCAN, uint8_t u8Mask)
Enter initialization mode.
Definition: can.c:248
CAN_CLR_INT_PENDING_BIT
void CAN_CLR_INT_PENDING_BIT(CAN_T *tCAN, uint8_t u32MsgNum)
Clear interrupt pending bit.
Definition: can.c:1266
CAN_SetTxMsg
int32_t CAN_SetTxMsg(CAN_T *tCAN, uint32_t u32MsgNum, STR_CANMSG_T *pCanMsg)
The function is used to configure a transmit object.
Definition: can.c:928
STR_CANMSG_T::Id
uint32_t Id
Definition: can.h:60
STR_CANMSG_T
Definition: can.h:56
CAN_BasicSendMsg
int32_t CAN_BasicSendMsg(CAN_T *tCAN, STR_CANMSG_T *pCanMsg)
Send CAN message in BASIC mode of test mode.
Definition: can.c:385
CAN_Close
void CAN_Close(CAN_T *tCAN)
The function is used to disable all CAN interrupt.
Definition: can.c:880
STR_CANMSG_T::IdType
uint32_t IdType
Definition: can.h:58
CAN_Open
uint32_t CAN_Open(CAN_T *tCAN, uint32_t u32BaudRate, uint32_t u32Mode)
Set CAN operation mode and target baud-rate.
Definition: can.c:898
CAN_LeaveInitMode
void CAN_LeaveInitMode(CAN_T *tCAN)
Leave initialization mode.
Definition: can.c:261
CAN_LeaveTestMode
void CAN_LeaveTestMode(CAN_T *tCAN)
Leave the test mode.
Definition: can.c:354
CAN_TriggerTxMsg
int32_t CAN_TriggerTxMsg(CAN_T *tCAN, uint32_t u32MsgNum)
Set transmit request bit.
Definition: can.c:990
STR_CANMASK_T
Definition: can.h:68
STR_CANMASK_T::u32Id
uint32_t u32Id
Definition: can.h:72
CAN_SetRxMsgAndMsk
int32_t CAN_SetRxMsgAndMsk(CAN_T *tCAN, uint32_t u32MsgNum, uint32_t u32IDType, uint32_t u32ID, uint32_t u32IDMask)
The function is used to configure a receive message object.
Definition: can.c:1111
CAN_IsNewDataReceived
uint32_t CAN_IsNewDataReceived(CAN_T *tCAN, uint8_t u8MsgObj)
Get the waiting status of a received message.
Definition: can.c:369
CAN_T
Definition: can_reg.h:550
CAN_EnableInt
void CAN_EnableInt(CAN_T *tCAN, uint32_t u32Mask)
Enable CAN interrupt.
Definition: can.c:1036
STR_CANMSG_T::DLC
uint8_t DLC
Definition: can.h:61
CAN_EnterTestMode
void CAN_EnterTestMode(CAN_T *tCAN, uint8_t u8TestMask)
Switch the CAN into test mode.
Definition: can.c:341
CAN_WaitMsg
void CAN_WaitMsg(CAN_T *tCAN)
Wait message into message buffer in basic mode.
Definition: can.c:277
CAN_SetBaudRate
uint32_t CAN_SetBaudRate(CAN_T *tCAN, uint32_t u32BaudRate)
Set bus baud-rate.
Definition: can.c:748
STR_CANMSG_T::FrameType
uint32_t FrameType
Definition: can.h:59
STR_CANMASK_T::u8Xtd
uint8_t u8Xtd
Definition: can.h:70
CAN_BasicReceiveMsg
int32_t CAN_BasicReceiveMsg(CAN_T *tCAN, STR_CANMSG_T *pCanMsg)
Get a message information in BASIC mode.
Definition: can.c:470
CAN_GetCANBitRate
uint32_t CAN_GetCANBitRate(CAN_T *tCAN)
Get current bit rate.
Definition: can.c:316
CAN_ReadMsgObj
int32_t CAN_ReadMsgObj(CAN_T *tCAN, uint8_t u8MsgObj, uint8_t u8Release, STR_CANMSG_T *pCanMsg)
Gets the message.
Definition: can.c:671