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