Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of mbed-dev by
targets/TARGET_NUVOTON/TARGET_M451/device/StdDriver/m451_can.h@150:02e0a0aed4ec, 2016-11-08 (annotated)
- Committer:
- <>
- Date:
- Tue Nov 08 17:45:16 2016 +0000
- Revision:
- 150:02e0a0aed4ec
- Parent:
- 149:156823d33999
This updates the lib to the mbed lib v129
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
<> | 149:156823d33999 | 1 | /**************************************************************************//** |
<> | 149:156823d33999 | 2 | * @file can.h |
<> | 149:156823d33999 | 3 | * @version V2.00 |
<> | 149:156823d33999 | 4 | * $Revision: 9 $ |
<> | 149:156823d33999 | 5 | * $Date: 15/08/11 10:26a $ |
<> | 149:156823d33999 | 6 | * @brief M451 Series CAN Driver Header File |
<> | 149:156823d33999 | 7 | * |
<> | 149:156823d33999 | 8 | * @note |
<> | 149:156823d33999 | 9 | * Copyright (C) 2014~2015 Nuvoton Technology Corp. All rights reserved. |
<> | 149:156823d33999 | 10 | * |
<> | 149:156823d33999 | 11 | ******************************************************************************/ |
<> | 149:156823d33999 | 12 | #ifndef __CAN_H__ |
<> | 149:156823d33999 | 13 | #define __CAN_H__ |
<> | 149:156823d33999 | 14 | |
<> | 149:156823d33999 | 15 | #include "M451Series.h" |
<> | 149:156823d33999 | 16 | |
<> | 149:156823d33999 | 17 | #ifdef __cplusplus |
<> | 149:156823d33999 | 18 | extern "C" |
<> | 149:156823d33999 | 19 | { |
<> | 149:156823d33999 | 20 | #endif |
<> | 149:156823d33999 | 21 | |
<> | 149:156823d33999 | 22 | |
<> | 149:156823d33999 | 23 | /** @addtogroup Standard_Driver Standard Driver |
<> | 149:156823d33999 | 24 | @{ |
<> | 149:156823d33999 | 25 | */ |
<> | 149:156823d33999 | 26 | |
<> | 149:156823d33999 | 27 | /** @addtogroup CAN_Driver CAN Driver |
<> | 149:156823d33999 | 28 | @{ |
<> | 149:156823d33999 | 29 | */ |
<> | 149:156823d33999 | 30 | |
<> | 149:156823d33999 | 31 | /** @addtogroup CAN_EXPORTED_CONSTANTS CAN Exported Constants |
<> | 149:156823d33999 | 32 | @{ |
<> | 149:156823d33999 | 33 | */ |
<> | 149:156823d33999 | 34 | /*---------------------------------------------------------------------------------------------------------*/ |
<> | 149:156823d33999 | 35 | /* CAN Test Mode Constant Definitions */ |
<> | 149:156823d33999 | 36 | /*---------------------------------------------------------------------------------------------------------*/ |
<> | 149:156823d33999 | 37 | #define CAN_NORMAL_MODE 0 |
<> | 149:156823d33999 | 38 | #define CAN_BASIC_MODE 1 |
<> | 149:156823d33999 | 39 | |
<> | 149:156823d33999 | 40 | /*---------------------------------------------------------------------------------------------------------*/ |
<> | 149:156823d33999 | 41 | /* Message ID Type Constant Definitions */ |
<> | 149:156823d33999 | 42 | /*---------------------------------------------------------------------------------------------------------*/ |
<> | 149:156823d33999 | 43 | #define CAN_STD_ID 0 |
<> | 149:156823d33999 | 44 | #define CAN_EXT_ID 1 |
<> | 149:156823d33999 | 45 | |
<> | 149:156823d33999 | 46 | /*---------------------------------------------------------------------------------------------------------*/ |
<> | 149:156823d33999 | 47 | /* Message Frame Type Constant Definitions */ |
<> | 149:156823d33999 | 48 | /*---------------------------------------------------------------------------------------------------------*/ |
<> | 149:156823d33999 | 49 | #define CAN_REMOTE_FRAME 0 |
<> | 149:156823d33999 | 50 | #define CAN_DATA_FRAME 1 |
<> | 149:156823d33999 | 51 | |
<> | 149:156823d33999 | 52 | /*---------------------------------------------------------------------------------------------------------*/ |
<> | 149:156823d33999 | 53 | /* CAN message structure */ |
<> | 149:156823d33999 | 54 | /*---------------------------------------------------------------------------------------------------------*/ |
<> | 149:156823d33999 | 55 | typedef struct |
<> | 149:156823d33999 | 56 | { |
<> | 149:156823d33999 | 57 | uint32_t IdType; |
<> | 149:156823d33999 | 58 | uint32_t FrameType; |
<> | 149:156823d33999 | 59 | uint32_t Id; |
<> | 149:156823d33999 | 60 | uint8_t DLC; |
<> | 149:156823d33999 | 61 | uint8_t Data[8]; |
<> | 149:156823d33999 | 62 | } STR_CANMSG_T; |
<> | 149:156823d33999 | 63 | |
<> | 149:156823d33999 | 64 | /*---------------------------------------------------------------------------------------------------------*/ |
<> | 149:156823d33999 | 65 | /* CAN mask message structure */ |
<> | 149:156823d33999 | 66 | /*---------------------------------------------------------------------------------------------------------*/ |
<> | 149:156823d33999 | 67 | typedef struct |
<> | 149:156823d33999 | 68 | { |
<> | 149:156823d33999 | 69 | uint8_t u8Xtd; |
<> | 149:156823d33999 | 70 | uint8_t u8Dir; |
<> | 149:156823d33999 | 71 | uint32_t u32Id; |
<> | 149:156823d33999 | 72 | uint8_t u8IdType; |
<> | 149:156823d33999 | 73 | } STR_CANMASK_T; |
<> | 149:156823d33999 | 74 | |
<> | 149:156823d33999 | 75 | #define MSG(id) (id) |
<> | 149:156823d33999 | 76 | |
<> | 149:156823d33999 | 77 | |
<> | 149:156823d33999 | 78 | /*@}*/ /* end of group CAN_EXPORTED_CONSTANTS */ |
<> | 149:156823d33999 | 79 | |
<> | 149:156823d33999 | 80 | |
<> | 149:156823d33999 | 81 | /** @addtogroup CAN_EXPORTED_FUNCTIONS CAN Exported Functions |
<> | 149:156823d33999 | 82 | @{ |
<> | 149:156823d33999 | 83 | */ |
<> | 149:156823d33999 | 84 | |
<> | 149:156823d33999 | 85 | /** |
<> | 149:156823d33999 | 86 | * @brief Get interrupt status. |
<> | 149:156823d33999 | 87 | * |
<> | 149:156823d33999 | 88 | * @param[in] can The base address of can module. |
<> | 149:156823d33999 | 89 | * |
<> | 149:156823d33999 | 90 | * @return CAN module status register value. |
<> | 149:156823d33999 | 91 | * |
<> | 149:156823d33999 | 92 | * @details Status Interrupt is generated by bits BOff (CAN_STATUS[7]), EWarn (CAN_STATUS[6]), |
<> | 149:156823d33999 | 93 | * EPass (CAN_STATUS[5]), RxOk (CAN_STATUS[4]), TxOk (CAN_STATUS[3]), and LEC (CAN_STATUS[2:0]). |
<> | 149:156823d33999 | 94 | */ |
<> | 149:156823d33999 | 95 | #define CAN_GET_INT_STATUS(can) ((can)->STATUS) |
<> | 149:156823d33999 | 96 | |
<> | 149:156823d33999 | 97 | /** |
<> | 149:156823d33999 | 98 | * @brief Get specified interrupt pending status. |
<> | 149:156823d33999 | 99 | * |
<> | 149:156823d33999 | 100 | * @param[in] can The base address of can module. |
<> | 149:156823d33999 | 101 | * |
<> | 149:156823d33999 | 102 | * @return The source of the interrupt. |
<> | 149:156823d33999 | 103 | * |
<> | 149:156823d33999 | 104 | * @details If several interrupts are pending, the CAN Interrupt Register will point to the pending interrupt |
<> | 149:156823d33999 | 105 | * with the highest priority, disregarding their chronological order. |
<> | 149:156823d33999 | 106 | */ |
<> | 149:156823d33999 | 107 | #define CAN_GET_INT_PENDING_STATUS(can) ((can)->IIDR) |
<> | 149:156823d33999 | 108 | |
<> | 149:156823d33999 | 109 | /** |
<> | 149:156823d33999 | 110 | * @brief Disable wake-up function. |
<> | 149:156823d33999 | 111 | * |
<> | 149:156823d33999 | 112 | * @param[in] can The base address of can module. |
<> | 149:156823d33999 | 113 | * |
<> | 149:156823d33999 | 114 | * @return None |
<> | 149:156823d33999 | 115 | * |
<> | 149:156823d33999 | 116 | * @details The macro is used to disable wake-up function. |
<> | 149:156823d33999 | 117 | */ |
<> | 149:156823d33999 | 118 | #define CAN_DISABLE_WAKEUP(can) ((can)->WU_EN = 0) |
<> | 149:156823d33999 | 119 | |
<> | 149:156823d33999 | 120 | /** |
<> | 149:156823d33999 | 121 | * @brief Enable wake-up function. |
<> | 149:156823d33999 | 122 | * |
<> | 149:156823d33999 | 123 | * @param[in] can The base address of can module. |
<> | 149:156823d33999 | 124 | * |
<> | 149:156823d33999 | 125 | * @return None |
<> | 149:156823d33999 | 126 | * |
<> | 149:156823d33999 | 127 | * @details User can wake-up system when there is a falling edge in the CAN_Rx pin. |
<> | 149:156823d33999 | 128 | */ |
<> | 149:156823d33999 | 129 | #define CAN_ENABLE_WAKEUP(can) ((can)->WU_EN = CAN_WUEN_WAKUP_EN_Msk) |
<> | 149:156823d33999 | 130 | |
<> | 149:156823d33999 | 131 | /** |
<> | 149:156823d33999 | 132 | * @brief Get specified Message Object new data into bit value. |
<> | 149:156823d33999 | 133 | * |
<> | 149:156823d33999 | 134 | * @param[in] can The base address of can module. |
<> | 149:156823d33999 | 135 | * @param[in] u32MsgNum Specified Message Object number, valid value are from 0 to 31. |
<> | 149:156823d33999 | 136 | * |
<> | 149:156823d33999 | 137 | * @return Specified Message Object new data into bit value. |
<> | 149:156823d33999 | 138 | * |
<> | 149:156823d33999 | 139 | * @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 |
<> | 149:156823d33999 | 140 | * or by the Message Handler after reception of a Data Frame or after a successful transmission. |
<> | 149:156823d33999 | 141 | */ |
<> | 149:156823d33999 | 142 | #define CAN_GET_NEW_DATA_IN_BIT(can, u32MsgNum) ((u32MsgNum) < 16 ? (can)->NDAT1 & (1 << (u32MsgNum)) : (can)->NDAT2 & (1 << ((u32MsgNum)-16))) |
<> | 149:156823d33999 | 143 | |
<> | 149:156823d33999 | 144 | |
<> | 149:156823d33999 | 145 | /*---------------------------------------------------------------------------------------------------------*/ |
<> | 149:156823d33999 | 146 | /* Define CAN functions prototype */ |
<> | 149:156823d33999 | 147 | /*---------------------------------------------------------------------------------------------------------*/ |
<> | 149:156823d33999 | 148 | uint32_t CAN_SetBaudRate(CAN_T *tCAN, uint32_t u32BaudRate); |
<> | 149:156823d33999 | 149 | uint32_t CAN_Open(CAN_T *tCAN, uint32_t u32BaudRate, uint32_t u32Mode); |
<> | 149:156823d33999 | 150 | void CAN_Close(CAN_T *tCAN); |
<> | 149:156823d33999 | 151 | void CAN_CLR_INT_PENDING_BIT(CAN_T *tCAN, uint8_t u32MsgNum); |
<> | 149:156823d33999 | 152 | void CAN_EnableInt(CAN_T *tCAN, uint32_t u32Mask); |
<> | 149:156823d33999 | 153 | void CAN_DisableInt(CAN_T *tCAN, uint32_t u32Mask); |
<> | 149:156823d33999 | 154 | int32_t CAN_Transmit(CAN_T *tCAN, uint32_t u32MsgNum , STR_CANMSG_T* pCanMsg); |
<> | 149:156823d33999 | 155 | int32_t CAN_Receive(CAN_T *tCAN, uint32_t u32MsgNum , STR_CANMSG_T* pCanMsg); |
<> | 149:156823d33999 | 156 | int32_t CAN_SetMultiRxMsg(CAN_T *tCAN, uint32_t u32MsgNum , uint32_t u32MsgCount, uint32_t u32IDType, uint32_t u32ID); |
<> | 149:156823d33999 | 157 | int32_t CAN_SetRxMsg(CAN_T *tCAN, uint32_t u32MsgNum , uint32_t u32IDType, uint32_t u32ID); |
<> | 149:156823d33999 | 158 | int32_t CAN_SetRxMsgAndMsk(CAN_T *tCAN, uint32_t u32MsgNum , uint32_t u32IDType, uint32_t u32ID, uint32_t u32IDMask); |
<> | 149:156823d33999 | 159 | int32_t CAN_SetTxMsg(CAN_T *tCAN, uint32_t u32MsgNum , STR_CANMSG_T* pCanMsg); |
<> | 149:156823d33999 | 160 | int32_t CAN_TriggerTxMsg(CAN_T *tCAN, uint32_t u32MsgNum); |
<> | 150:02e0a0aed4ec | 161 | uint32_t CAN_GetCANBitRate(CAN_T *tCAN); |
<> | 150:02e0a0aed4ec | 162 | void CAN_EnterInitMode(CAN_T *tCAN, uint8_t u8Mask); |
<> | 150:02e0a0aed4ec | 163 | void CAN_LeaveInitMode(CAN_T *tCAN); |
<> | 150:02e0a0aed4ec | 164 | void CAN_EnterTestMode(CAN_T *tCAN, uint8_t u8TestMask); |
<> | 150:02e0a0aed4ec | 165 | void CAN_LeaveTestMode(CAN_T *tCAN); |
<> | 149:156823d33999 | 166 | |
<> | 149:156823d33999 | 167 | /*@}*/ /* end of group CAN_EXPORTED_FUNCTIONS */ |
<> | 149:156823d33999 | 168 | |
<> | 149:156823d33999 | 169 | /*@}*/ /* end of group CAN_Driver */ |
<> | 149:156823d33999 | 170 | |
<> | 149:156823d33999 | 171 | /*@}*/ /* end of group Standard_Driver */ |
<> | 149:156823d33999 | 172 | |
<> | 149:156823d33999 | 173 | #ifdef __cplusplus |
<> | 149:156823d33999 | 174 | } |
<> | 149:156823d33999 | 175 | #endif |
<> | 149:156823d33999 | 176 | |
<> | 149:156823d33999 | 177 | #endif //__CAN_H__ |
<> | 149:156823d33999 | 178 | |
<> | 149:156823d33999 | 179 | /*** (C) COPYRIGHT 2014~2015 Nuvoton Technology Corp. ***/ |