Mouse code for the MacroRat
mbed-dev/targets/TARGET_NUVOTON/TARGET_NUC472/device/StdDriver/nuc472_can.h@46:b156ef445742, 2017-06-03 (annotated)
- Committer:
- sahilmgandhi
- Date:
- Sat Jun 03 00:22:44 2017 +0000
- Revision:
- 46:b156ef445742
- Parent:
- 18:6a4db94011d3
Final code for internal battlebot competition.
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 V1.00 |
sahilmgandhi | 18:6a4db94011d3 | 4 | * $Revision: 8 $ |
sahilmgandhi | 18:6a4db94011d3 | 5 | * $Date: 14/09/26 3:38p $ |
sahilmgandhi | 18:6a4db94011d3 | 6 | * @brief NUC472/NUC442 CAN driver header file |
sahilmgandhi | 18:6a4db94011d3 | 7 | * |
sahilmgandhi | 18:6a4db94011d3 | 8 | * @note |
sahilmgandhi | 18:6a4db94011d3 | 9 | * Copyright (C) 2013 Nuvoton Technology Corp. All rights reserved. |
sahilmgandhi | 18:6a4db94011d3 | 10 | *****************************************************************************/ |
sahilmgandhi | 18:6a4db94011d3 | 11 | #ifndef __CAN_H__ |
sahilmgandhi | 18:6a4db94011d3 | 12 | #define __CAN_H__ |
sahilmgandhi | 18:6a4db94011d3 | 13 | |
sahilmgandhi | 18:6a4db94011d3 | 14 | #ifdef __cplusplus |
sahilmgandhi | 18:6a4db94011d3 | 15 | extern "C" |
sahilmgandhi | 18:6a4db94011d3 | 16 | { |
sahilmgandhi | 18:6a4db94011d3 | 17 | #endif |
sahilmgandhi | 18:6a4db94011d3 | 18 | |
sahilmgandhi | 18:6a4db94011d3 | 19 | /** @addtogroup NUC472_442_Device_Driver NUC472/NUC442 Device Driver |
sahilmgandhi | 18:6a4db94011d3 | 20 | @{ |
sahilmgandhi | 18:6a4db94011d3 | 21 | */ |
sahilmgandhi | 18:6a4db94011d3 | 22 | |
sahilmgandhi | 18:6a4db94011d3 | 23 | /** @addtogroup NUC472_442_CAN_Driver CAN Driver |
sahilmgandhi | 18:6a4db94011d3 | 24 | @{ |
sahilmgandhi | 18:6a4db94011d3 | 25 | */ |
sahilmgandhi | 18:6a4db94011d3 | 26 | |
sahilmgandhi | 18:6a4db94011d3 | 27 | /** @addtogroup NUC472_442_CAN_EXPORTED_TYPEDEF CAN Exported Type Defines |
sahilmgandhi | 18:6a4db94011d3 | 28 | @{ |
sahilmgandhi | 18:6a4db94011d3 | 29 | */ |
sahilmgandhi | 18:6a4db94011d3 | 30 | |
sahilmgandhi | 18:6a4db94011d3 | 31 | /** |
sahilmgandhi | 18:6a4db94011d3 | 32 | * @details Message ID types. |
sahilmgandhi | 18:6a4db94011d3 | 33 | */ |
sahilmgandhi | 18:6a4db94011d3 | 34 | typedef enum { |
sahilmgandhi | 18:6a4db94011d3 | 35 | CAN_STD_ID = 0, /*!< Standard Identifier */ |
sahilmgandhi | 18:6a4db94011d3 | 36 | CAN_EXT_ID = 1 /*!< Extended Identifier */ |
sahilmgandhi | 18:6a4db94011d3 | 37 | } E_CAN_ID_TYPE; |
sahilmgandhi | 18:6a4db94011d3 | 38 | |
sahilmgandhi | 18:6a4db94011d3 | 39 | /** |
sahilmgandhi | 18:6a4db94011d3 | 40 | * @details Message Frame types. |
sahilmgandhi | 18:6a4db94011d3 | 41 | */ |
sahilmgandhi | 18:6a4db94011d3 | 42 | typedef enum { |
sahilmgandhi | 18:6a4db94011d3 | 43 | REMOTE_FRAME = 0, /*!< Remote Frame */ |
sahilmgandhi | 18:6a4db94011d3 | 44 | DATA_FRAME = 1 /*!< Data Frame */ |
sahilmgandhi | 18:6a4db94011d3 | 45 | } E_CAN_FRAME_TYPE; |
sahilmgandhi | 18:6a4db94011d3 | 46 | |
sahilmgandhi | 18:6a4db94011d3 | 47 | /** |
sahilmgandhi | 18:6a4db94011d3 | 48 | * @details CAN message structure. |
sahilmgandhi | 18:6a4db94011d3 | 49 | */ |
sahilmgandhi | 18:6a4db94011d3 | 50 | typedef struct { |
sahilmgandhi | 18:6a4db94011d3 | 51 | uint32_t IdType; /*!< Identifier Type */ |
sahilmgandhi | 18:6a4db94011d3 | 52 | uint32_t FrameType; /*!< Frame Type */ |
sahilmgandhi | 18:6a4db94011d3 | 53 | uint32_t Id; /*!< Message Identifier */ |
sahilmgandhi | 18:6a4db94011d3 | 54 | uint8_t DLC; /*!< Data Length Code */ |
sahilmgandhi | 18:6a4db94011d3 | 55 | uint8_t Data[8]; /*!< Data byte 0 ~ 7 */ |
sahilmgandhi | 18:6a4db94011d3 | 56 | } STR_CANMSG_T; |
sahilmgandhi | 18:6a4db94011d3 | 57 | |
sahilmgandhi | 18:6a4db94011d3 | 58 | /** |
sahilmgandhi | 18:6a4db94011d3 | 59 | * @details CAN mask message structure. |
sahilmgandhi | 18:6a4db94011d3 | 60 | */ |
sahilmgandhi | 18:6a4db94011d3 | 61 | typedef struct { |
sahilmgandhi | 18:6a4db94011d3 | 62 | uint8_t u8Xtd; /*!< Extended Identifier */ |
sahilmgandhi | 18:6a4db94011d3 | 63 | uint8_t u8Dir; /*!< Message Direction */ |
sahilmgandhi | 18:6a4db94011d3 | 64 | uint32_t u32Id; /*!< Message Identifier */ |
sahilmgandhi | 18:6a4db94011d3 | 65 | uint8_t u8IdType; /*!< Identifier Type */ |
sahilmgandhi | 18:6a4db94011d3 | 66 | } STR_CANMASK_T; |
sahilmgandhi | 18:6a4db94011d3 | 67 | |
sahilmgandhi | 18:6a4db94011d3 | 68 | /** |
sahilmgandhi | 18:6a4db94011d3 | 69 | * @details CAN operation mode: normal/basic mode. |
sahilmgandhi | 18:6a4db94011d3 | 70 | */ |
sahilmgandhi | 18:6a4db94011d3 | 71 | typedef enum { |
sahilmgandhi | 18:6a4db94011d3 | 72 | CAN_NORMAL_MODE = 1, /*!< Normal Mode */ |
sahilmgandhi | 18:6a4db94011d3 | 73 | CAN_BASIC_MODE = 2 /*!< Basic Mode */ |
sahilmgandhi | 18:6a4db94011d3 | 74 | } CAN_MODE_SELECT; |
sahilmgandhi | 18:6a4db94011d3 | 75 | |
sahilmgandhi | 18:6a4db94011d3 | 76 | #define ALL_MSG 32 /*!< All Message ram number */ |
sahilmgandhi | 18:6a4db94011d3 | 77 | #define MSG(id) id /*!< Message ram number */ |
sahilmgandhi | 18:6a4db94011d3 | 78 | |
sahilmgandhi | 18:6a4db94011d3 | 79 | |
sahilmgandhi | 18:6a4db94011d3 | 80 | /*@}*/ /* end of group NUC472_442_CAN_EXPORTED_TYPEDEF */ |
sahilmgandhi | 18:6a4db94011d3 | 81 | |
sahilmgandhi | 18:6a4db94011d3 | 82 | |
sahilmgandhi | 18:6a4db94011d3 | 83 | /** @addtogroup NUC472_442_CAN_EXPORTED_FUNCTIONS CAN Exported Functions |
sahilmgandhi | 18:6a4db94011d3 | 84 | @{ |
sahilmgandhi | 18:6a4db94011d3 | 85 | */ |
sahilmgandhi | 18:6a4db94011d3 | 86 | |
sahilmgandhi | 18:6a4db94011d3 | 87 | /** |
sahilmgandhi | 18:6a4db94011d3 | 88 | * @brief Get interrupt status |
sahilmgandhi | 18:6a4db94011d3 | 89 | * |
sahilmgandhi | 18:6a4db94011d3 | 90 | * @param[in] can The base address of can module |
sahilmgandhi | 18:6a4db94011d3 | 91 | * |
sahilmgandhi | 18:6a4db94011d3 | 92 | * @return CAN module status register value |
sahilmgandhi | 18:6a4db94011d3 | 93 | * \hideinitializer |
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 | * \hideinitializer |
sahilmgandhi | 18:6a4db94011d3 | 104 | */ |
sahilmgandhi | 18:6a4db94011d3 | 105 | #define CAN_GET_INT_PENDING_STATUS(can) (can->IIDR) |
sahilmgandhi | 18:6a4db94011d3 | 106 | |
sahilmgandhi | 18:6a4db94011d3 | 107 | /** |
sahilmgandhi | 18:6a4db94011d3 | 108 | * @brief Disable Wakeup function |
sahilmgandhi | 18:6a4db94011d3 | 109 | * |
sahilmgandhi | 18:6a4db94011d3 | 110 | * @param[in] can The base address of can module |
sahilmgandhi | 18:6a4db94011d3 | 111 | * |
sahilmgandhi | 18:6a4db94011d3 | 112 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 113 | * \hideinitializer |
sahilmgandhi | 18:6a4db94011d3 | 114 | */ |
sahilmgandhi | 18:6a4db94011d3 | 115 | #define CAN_DISABLE_WAKEUP(can) (can->WU_IE = 0) |
sahilmgandhi | 18:6a4db94011d3 | 116 | |
sahilmgandhi | 18:6a4db94011d3 | 117 | /** |
sahilmgandhi | 18:6a4db94011d3 | 118 | * @brief Enable Wakeup function |
sahilmgandhi | 18:6a4db94011d3 | 119 | * |
sahilmgandhi | 18:6a4db94011d3 | 120 | * @param[in] can The base address of can module |
sahilmgandhi | 18:6a4db94011d3 | 121 | * |
sahilmgandhi | 18:6a4db94011d3 | 122 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 123 | * \hideinitializer |
sahilmgandhi | 18:6a4db94011d3 | 124 | */ |
sahilmgandhi | 18:6a4db94011d3 | 125 | #define CAN_ENABLE_WAKEUP(can) (can->WU_IE = CAN_WUEN_WAKUP_EN_Msk) |
sahilmgandhi | 18:6a4db94011d3 | 126 | |
sahilmgandhi | 18:6a4db94011d3 | 127 | /** |
sahilmgandhi | 18:6a4db94011d3 | 128 | * @brief Get specified Message Object new data into bit value |
sahilmgandhi | 18:6a4db94011d3 | 129 | * |
sahilmgandhi | 18:6a4db94011d3 | 130 | * @param[in] can The base address of can module |
sahilmgandhi | 18:6a4db94011d3 | 131 | * @param[in] u32MsgNum Specified Message Object number. (0 ~ 31) |
sahilmgandhi | 18:6a4db94011d3 | 132 | * |
sahilmgandhi | 18:6a4db94011d3 | 133 | * @return Specified Message Object new data into bit value. |
sahilmgandhi | 18:6a4db94011d3 | 134 | * \hideinitializer |
sahilmgandhi | 18:6a4db94011d3 | 135 | */ |
sahilmgandhi | 18:6a4db94011d3 | 136 | #define CAN_GET_NEW_DATA_IN_BIT(can, u32MsgNum) (u32MsgNum < 16 ? can->NDAT1 & (1 << u32MsgNum) : can->NDAT2 & (1 << (u32MsgNum-16))) |
sahilmgandhi | 18:6a4db94011d3 | 137 | |
sahilmgandhi | 18:6a4db94011d3 | 138 | |
sahilmgandhi | 18:6a4db94011d3 | 139 | /*---------------------------------------------------------------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 140 | /* Define CAN functions prototype */ |
sahilmgandhi | 18:6a4db94011d3 | 141 | /*---------------------------------------------------------------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 142 | uint32_t CAN_SetBaudRate(CAN_T *tCAN, uint32_t u32BaudRate); |
sahilmgandhi | 18:6a4db94011d3 | 143 | uint32_t CAN_Open(CAN_T *tCAN, uint32_t u32BaudRate, uint32_t u32Mode); |
sahilmgandhi | 18:6a4db94011d3 | 144 | int32_t CAN_Transmit(CAN_T *tCAN, uint32_t u32MsgNum , STR_CANMSG_T* pCanMsg); |
sahilmgandhi | 18:6a4db94011d3 | 145 | int32_t CAN_Receive(CAN_T *tCAN, uint32_t u32MsgNum , STR_CANMSG_T* pCanMsg); |
sahilmgandhi | 18:6a4db94011d3 | 146 | void CAN_CLR_INT_PENDING_BIT(CAN_T *tCAN, uint8_t u32MsgNum); |
sahilmgandhi | 18:6a4db94011d3 | 147 | void CAN_EnableInt(CAN_T *tCAN, uint32_t u32Mask); |
sahilmgandhi | 18:6a4db94011d3 | 148 | void CAN_DisableInt(CAN_T *tCAN, uint32_t u32Mask); |
sahilmgandhi | 18:6a4db94011d3 | 149 | int32_t CAN_SetMultiRxMsg(CAN_T *tCAN, uint32_t u32MsgNum , uint32_t u32MsgCount, uint32_t u32IDType, uint32_t u32ID); |
sahilmgandhi | 18:6a4db94011d3 | 150 | int32_t CAN_SetRxMsg(CAN_T *tCAN, uint32_t u32MsgNum , uint32_t u32IDType, uint32_t u32ID); |
sahilmgandhi | 18:6a4db94011d3 | 151 | int32_t CAN_SetTxMsg(CAN_T *tCAN, uint32_t u32MsgNum , STR_CANMSG_T* pCanMsg); |
sahilmgandhi | 18:6a4db94011d3 | 152 | int32_t CAN_TriggerTxMsg(CAN_T *tCAN, uint32_t u32MsgNum); |
sahilmgandhi | 18:6a4db94011d3 | 153 | uint32_t CAN_GetCANBitRate(CAN_T *tCAN); |
sahilmgandhi | 18:6a4db94011d3 | 154 | void CAN_EnterInitMode(CAN_T *tCAN); |
sahilmgandhi | 18:6a4db94011d3 | 155 | void CAN_LeaveInitMode(CAN_T *tCAN); |
sahilmgandhi | 18:6a4db94011d3 | 156 | void CAN_EnterTestMode(CAN_T *tCAN, uint8_t u8TestMask); |
sahilmgandhi | 18:6a4db94011d3 | 157 | void CAN_LeaveTestMode(CAN_T *tCAN); |
sahilmgandhi | 18:6a4db94011d3 | 158 | |
sahilmgandhi | 18:6a4db94011d3 | 159 | /*@}*/ /* end of group NUC472_442_CAN_EXPORTED_FUNCTIONS */ |
sahilmgandhi | 18:6a4db94011d3 | 160 | |
sahilmgandhi | 18:6a4db94011d3 | 161 | /*@}*/ /* end of group NUC472_442_CAN_Driver */ |
sahilmgandhi | 18:6a4db94011d3 | 162 | |
sahilmgandhi | 18:6a4db94011d3 | 163 | /*@}*/ /* end of group NUC472_442_Device_Driver */ |
sahilmgandhi | 18:6a4db94011d3 | 164 | |
sahilmgandhi | 18:6a4db94011d3 | 165 | #ifdef __cplusplus |
sahilmgandhi | 18:6a4db94011d3 | 166 | } |
sahilmgandhi | 18:6a4db94011d3 | 167 | #endif |
sahilmgandhi | 18:6a4db94011d3 | 168 | |
sahilmgandhi | 18:6a4db94011d3 | 169 | #endif //__CAN_H__ |
sahilmgandhi | 18:6a4db94011d3 | 170 | |
sahilmgandhi | 18:6a4db94011d3 | 171 | /*** (C) COPYRIGHT 2013 Nuvoton Technology Corp. ***/ |
sahilmgandhi | 18:6a4db94011d3 | 172 | |
sahilmgandhi | 18:6a4db94011d3 | 173 | |
sahilmgandhi | 18:6a4db94011d3 | 174 | |
sahilmgandhi | 18:6a4db94011d3 | 175 | |
sahilmgandhi | 18:6a4db94011d3 | 176 |