| NUC472_NUC442_BSP V3.03.003 The Board Support Package for NUC472/NUC442

can.h
Go to the documentation of this file.
1/**************************************************************************/
12#ifndef __CAN_H__
13#define __CAN_H__
14
15#ifdef __cplusplus
16 extern "C"
17{
18#endif
19
35 typedef enum
36{
37 CAN_STD_ID = 0,
38 CAN_EXT_ID = 1
39} E_CAN_ID_TYPE;
40
44 typedef enum
45{
46 REMOTE_FRAME = 0,
47 DATA_FRAME = 1
48} E_CAN_FRAME_TYPE;
49
53 typedef struct
54{
55 uint32_t IdType;
56 uint32_t FrameType;
57 uint32_t Id;
58 uint8_t DLC;
59 uint8_t Data[8];
60} STR_CANMSG_T;
61
65 typedef struct
66{
67 uint8_t u8Xtd;
68 uint8_t u8Dir;
69 uint32_t u32Id;
70 uint8_t u8IdType;
71} STR_CANMASK_T;
72
76 typedef enum
77{
78 CAN_NORMAL_MODE = 1,
79 CAN_BASIC_MODE = 2
80} CAN_MODE_SELECT;
81
82#define ALL_MSG 32
83#define MSG(id) id /* end of group NUC472_442_CAN_EXPORTED_TYPEDEF */
87
88
101#define CAN_GET_INT_STATUS(can) (can->STATUS)
102
111#define CAN_GET_INT_PENDING_STATUS(can) (can->IIDR)
112
121#define CAN_DISABLE_WAKEUP(can) (can->WU_IE = 0)
122
131#define CAN_ENABLE_WAKEUP(can) (can->WU_IE = CAN_WUEN_WAKUP_EN_Msk)
132
142#define CAN_GET_NEW_DATA_IN_BIT(can, u32MsgNum) (u32MsgNum < 16 ? can->NDAT1 & (1 << u32MsgNum) : can->NDAT2 & (1 << (u32MsgNum-16)))
143
144
145/*---------------------------------------------------------------------------------------------------------*/
146/* Define CAN functions prototype */
147/*---------------------------------------------------------------------------------------------------------*/
148uint32_t CAN_SetBaudRate(CAN_T *tCAN, uint32_t u32BaudRate);
149uint32_t CAN_Open(CAN_T *tCAN, uint32_t u32BaudRate, uint32_t u32Mode);
150int32_t CAN_Transmit(CAN_T *tCAN, uint32_t u32MsgNum, STR_CANMSG_T* pCanMsg);
151int32_t CAN_Receive(CAN_T *tCAN, uint32_t u32MsgNum, STR_CANMSG_T* pCanMsg);
152 void CAN_CLR_INT_PENDING_BIT(CAN_T *tCAN, uint8_t u32MsgNum);
153 void CAN_EnableInt(CAN_T *tCAN, uint32_t u32Mask);
154 void CAN_DisableInt(CAN_T *tCAN, uint32_t u32Mask);
155int32_t CAN_SetMultiRxMsg(CAN_T *tCAN, uint32_t u32MsgNum, uint32_t u32MsgCount, uint32_t u32IDType, uint32_t u32ID);
156int32_t CAN_SetRxMsg(CAN_T *tCAN, uint32_t u32MsgNum, uint32_t u32IDType, uint32_t u32ID);
157int32_t CAN_SetTxMsg(CAN_T *tCAN, uint32_t u32MsgNum, STR_CANMSG_T* pCanMsg);
158int32_t CAN_TriggerTxMsg(CAN_T *tCAN, uint32_t u32MsgNum);
159 /* end of group NUC472_442_CAN_EXPORTED_FUNCTIONS */
161 /* end of group NUC472_442_CAN_Driver */
163 /* end of group NUC472_442_Device_Driver */
165
166#ifdef __cplusplus
167}
168#endif
169
170#endif //__CAN_H__
171
172/*** (C) COPYRIGHT 2013 Nuvoton Technology Corp. ***/
173
174
175
176
177
STR_CANMASK_T::u8Dir
uint8_t u8Dir
Definition: can.h:68
STR_CANMASK_T::u8IdType
uint8_t u8IdType
Definition: can.h:70
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:729
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:614
CAN_SetBaudRate
uint32_t CAN_SetBaudRate(CAN_T *tCAN, uint32_t u32BaudRate)
The function is used to set bus timing parameter according current clock and target baud-rate.
Definition: can.c:479
CAN_TriggerTxMsg
int32_t CAN_TriggerTxMsg(CAN_T *tCAN, uint32_t u32MsgNum)
Set transmit request bit.
Definition: can.c:670
CAN_Receive
int32_t CAN_Receive(CAN_T *tCAN, uint32_t u32MsgNum, STR_CANMSG_T *pCanMsg)
Gets the message, if received.
Definition: can.c:819
STR_CANMSG_T::DLC
uint8_t DLC
Definition: can.h:58
STR_CANMSG_T::FrameType
uint32_t FrameType
Definition: can.h:56
STR_CANMASK_T::u32Id
uint32_t u32Id
Definition: can.h:69
CAN_DisableInt
void CAN_DisableInt(CAN_T *tCAN, uint32_t u32Mask)
Disable CAN interrupt.
Definition: can.c:707
CAN_EnableInt
void CAN_EnableInt(CAN_T *tCAN, uint32_t u32Mask)
Enable CAN interrupt.
Definition: can.c:688
CAN_CLR_INT_PENDING_BIT
void CAN_CLR_INT_PENDING_BIT(CAN_T *tCAN, uint8_t u32MsgNum)
Clear interrupt pending bit.
Definition: can.c:839
CAN_Open
uint32_t CAN_Open(CAN_T *tCAN, uint32_t u32BaudRate, uint32_t u32Mode)
The function is sets bus timing parameter according current clock and target baud-rate....
Definition: can.c:589
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:758
STR_CANMASK_T::u8Xtd
uint8_t u8Xtd
Definition: can.h:67
STR_CANMSG_T::Id
uint32_t Id
Definition: can.h:57
STR_CANMSG_T::IdType
uint32_t IdType
Definition: can.h:55
CAN_Transmit
int32_t CAN_Transmit(CAN_T *tCAN, uint32_t u32MsgNum, STR_CANMSG_T *pCanMsg)
Send CAN message.
Definition: can.c:793
CAN_MODE_SELECT
CAN_MODE_SELECT
Definition: can.h:77
E_CAN_ID_TYPE
E_CAN_ID_TYPE
Definition: can.h:36
E_CAN_FRAME_TYPE
E_CAN_FRAME_TYPE
Definition: can.h:45
CAN_NORMAL_MODE
@ CAN_NORMAL_MODE
Definition: can.h:78
CAN_BASIC_MODE
@ CAN_BASIC_MODE
Definition: can.h:79
CAN_EXT_ID
@ CAN_EXT_ID
Definition: can.h:38
CAN_STD_ID
@ CAN_STD_ID
Definition: can.h:37
REMOTE_FRAME
@ REMOTE_FRAME
Definition: can.h:46
DATA_FRAME
@ DATA_FRAME
Definition: can.h:47
CAN_T
Definition: NUC472_442.h:1125
STR_CANMASK_T
Definition: can.h:66
STR_CANMSG_T
Definition: can.h:54