Mouse code for the MacroRat
mbed-dev/targets/TARGET_NUVOTON/TARGET_M451/device/StdDriver/m451_uart.c@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 uart.c |
sahilmgandhi | 18:6a4db94011d3 | 3 | * @version V3.00 |
sahilmgandhi | 18:6a4db94011d3 | 4 | * $Revision: 22 $ |
sahilmgandhi | 18:6a4db94011d3 | 5 | * $Date: 15/08/11 10:26a $ |
sahilmgandhi | 18:6a4db94011d3 | 6 | * @brief M451 series UART driver source file |
sahilmgandhi | 18:6a4db94011d3 | 7 | * |
sahilmgandhi | 18:6a4db94011d3 | 8 | * @note |
sahilmgandhi | 18:6a4db94011d3 | 9 | * Copyright (C) 2013~2015 Nuvoton Technology Corp. All rights reserved. |
sahilmgandhi | 18:6a4db94011d3 | 10 | *****************************************************************************/ |
sahilmgandhi | 18:6a4db94011d3 | 11 | |
sahilmgandhi | 18:6a4db94011d3 | 12 | #include <stdio.h> |
sahilmgandhi | 18:6a4db94011d3 | 13 | #include "M451Series.h" |
sahilmgandhi | 18:6a4db94011d3 | 14 | |
sahilmgandhi | 18:6a4db94011d3 | 15 | /** @addtogroup Standard_Driver Standard Driver |
sahilmgandhi | 18:6a4db94011d3 | 16 | @{ |
sahilmgandhi | 18:6a4db94011d3 | 17 | */ |
sahilmgandhi | 18:6a4db94011d3 | 18 | |
sahilmgandhi | 18:6a4db94011d3 | 19 | /** @addtogroup UART_Driver UART Driver |
sahilmgandhi | 18:6a4db94011d3 | 20 | @{ |
sahilmgandhi | 18:6a4db94011d3 | 21 | */ |
sahilmgandhi | 18:6a4db94011d3 | 22 | |
sahilmgandhi | 18:6a4db94011d3 | 23 | /** @addtogroup UART_EXPORTED_FUNCTIONS UART Exported Functions |
sahilmgandhi | 18:6a4db94011d3 | 24 | @{ |
sahilmgandhi | 18:6a4db94011d3 | 25 | */ |
sahilmgandhi | 18:6a4db94011d3 | 26 | |
sahilmgandhi | 18:6a4db94011d3 | 27 | /** |
sahilmgandhi | 18:6a4db94011d3 | 28 | * @brief Clear UART specified interrupt flag |
sahilmgandhi | 18:6a4db94011d3 | 29 | * |
sahilmgandhi | 18:6a4db94011d3 | 30 | * @param[in] uart The pointer of the specified UART module. |
sahilmgandhi | 18:6a4db94011d3 | 31 | * @param[in] u32InterruptFlag The specified interrupt of UART module. |
sahilmgandhi | 18:6a4db94011d3 | 32 | * - \ref UART_INTSTS_LININT_Msk : LIN bus interrupt |
sahilmgandhi | 18:6a4db94011d3 | 33 | * - \ref UART_INTSTS_DATWKIF_Msk : Data Wake-up interrupt |
sahilmgandhi | 18:6a4db94011d3 | 34 | * - \ref UART_INTSTS_CTSWKIF_Msk : CTS Wake-up interrupt |
sahilmgandhi | 18:6a4db94011d3 | 35 | * - \ref UART_INTSTS_BUFERRINT_Msk : Buffer Error interrupt |
sahilmgandhi | 18:6a4db94011d3 | 36 | * - \ref UART_INTSTS_MODEMINT_Msk : Modem Status interrupt |
sahilmgandhi | 18:6a4db94011d3 | 37 | * - \ref UART_INTSTS_RLSINT_Msk : Receive Line Status interrupt |
sahilmgandhi | 18:6a4db94011d3 | 38 | * |
sahilmgandhi | 18:6a4db94011d3 | 39 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 40 | * |
sahilmgandhi | 18:6a4db94011d3 | 41 | * @details The function is used to clear UART specified interrupt flag. |
sahilmgandhi | 18:6a4db94011d3 | 42 | */ |
sahilmgandhi | 18:6a4db94011d3 | 43 | |
sahilmgandhi | 18:6a4db94011d3 | 44 | void UART_ClearIntFlag(UART_T* uart , uint32_t u32InterruptFlag) |
sahilmgandhi | 18:6a4db94011d3 | 45 | { |
sahilmgandhi | 18:6a4db94011d3 | 46 | |
sahilmgandhi | 18:6a4db94011d3 | 47 | if(u32InterruptFlag & UART_INTSTS_RLSINT_Msk) /* Clear Receive Line Status Interrupt */ |
sahilmgandhi | 18:6a4db94011d3 | 48 | { |
sahilmgandhi | 18:6a4db94011d3 | 49 | uart->FIFOSTS = UART_FIFOSTS_BIF_Msk | UART_FIFOSTS_FEF_Msk | UART_FIFOSTS_FEF_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 50 | uart->FIFOSTS = UART_FIFOSTS_ADDRDETF_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 51 | } |
sahilmgandhi | 18:6a4db94011d3 | 52 | |
sahilmgandhi | 18:6a4db94011d3 | 53 | if(u32InterruptFlag & UART_INTSTS_MODEMINT_Msk) /* Clear Modem Status Interrupt */ |
sahilmgandhi | 18:6a4db94011d3 | 54 | uart->MODEMSTS |= UART_MODEMSTS_CTSDETF_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 55 | |
sahilmgandhi | 18:6a4db94011d3 | 56 | if(u32InterruptFlag & UART_INTSTS_BUFERRINT_Msk) /* Clear Buffer Error Interrupt */ |
sahilmgandhi | 18:6a4db94011d3 | 57 | { |
sahilmgandhi | 18:6a4db94011d3 | 58 | uart->FIFOSTS = UART_FIFOSTS_RXOVIF_Msk | UART_FIFOSTS_TXOVIF_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 59 | } |
sahilmgandhi | 18:6a4db94011d3 | 60 | |
sahilmgandhi | 18:6a4db94011d3 | 61 | if(u32InterruptFlag & UART_INTSTS_CTSWKIF_Msk) /* Clear CTS Wake-up Interrupt */ |
sahilmgandhi | 18:6a4db94011d3 | 62 | { |
sahilmgandhi | 18:6a4db94011d3 | 63 | uart->INTSTS = UART_INTSTS_CTSWKIF_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 64 | } |
sahilmgandhi | 18:6a4db94011d3 | 65 | |
sahilmgandhi | 18:6a4db94011d3 | 66 | if(u32InterruptFlag & UART_INTSTS_DATWKIF_Msk) /* Clear Data Wake-up Interrupt */ |
sahilmgandhi | 18:6a4db94011d3 | 67 | { |
sahilmgandhi | 18:6a4db94011d3 | 68 | uart->INTSTS = UART_INTSTS_DATWKIF_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 69 | } |
sahilmgandhi | 18:6a4db94011d3 | 70 | |
sahilmgandhi | 18:6a4db94011d3 | 71 | if(u32InterruptFlag & UART_INTSTS_LININT_Msk) /* Clear LIN Bus Interrupt */ |
sahilmgandhi | 18:6a4db94011d3 | 72 | { |
sahilmgandhi | 18:6a4db94011d3 | 73 | uart->INTSTS = UART_INTSTS_LINIF_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 74 | uart->LINSTS = UART_LINSTS_BITEF_Msk | UART_LINSTS_BRKDETF_Msk | |
sahilmgandhi | 18:6a4db94011d3 | 75 | UART_LINSTS_SLVSYNCF_Msk | UART_LINSTS_SLVIDPEF_Msk | |
sahilmgandhi | 18:6a4db94011d3 | 76 | UART_LINSTS_SLVHEF_Msk | UART_LINSTS_SLVHDETF_Msk ; |
sahilmgandhi | 18:6a4db94011d3 | 77 | } |
sahilmgandhi | 18:6a4db94011d3 | 78 | } |
sahilmgandhi | 18:6a4db94011d3 | 79 | |
sahilmgandhi | 18:6a4db94011d3 | 80 | |
sahilmgandhi | 18:6a4db94011d3 | 81 | /** |
sahilmgandhi | 18:6a4db94011d3 | 82 | * @brief Disable UART interrupt |
sahilmgandhi | 18:6a4db94011d3 | 83 | * |
sahilmgandhi | 18:6a4db94011d3 | 84 | * @param[in] uart The pointer of the specified UART module. |
sahilmgandhi | 18:6a4db94011d3 | 85 | * |
sahilmgandhi | 18:6a4db94011d3 | 86 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 87 | * |
sahilmgandhi | 18:6a4db94011d3 | 88 | * @details The function is used to disable UART interrupt. |
sahilmgandhi | 18:6a4db94011d3 | 89 | */ |
sahilmgandhi | 18:6a4db94011d3 | 90 | void UART_Close(UART_T* uart) |
sahilmgandhi | 18:6a4db94011d3 | 91 | { |
sahilmgandhi | 18:6a4db94011d3 | 92 | uart->INTEN = 0; |
sahilmgandhi | 18:6a4db94011d3 | 93 | } |
sahilmgandhi | 18:6a4db94011d3 | 94 | |
sahilmgandhi | 18:6a4db94011d3 | 95 | |
sahilmgandhi | 18:6a4db94011d3 | 96 | /** |
sahilmgandhi | 18:6a4db94011d3 | 97 | * @brief Disable UART auto flow control function |
sahilmgandhi | 18:6a4db94011d3 | 98 | * |
sahilmgandhi | 18:6a4db94011d3 | 99 | * @param[in] uart The pointer of the specified UART module. |
sahilmgandhi | 18:6a4db94011d3 | 100 | * |
sahilmgandhi | 18:6a4db94011d3 | 101 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 102 | * |
sahilmgandhi | 18:6a4db94011d3 | 103 | * @details The function is used to disable UART auto flow control. |
sahilmgandhi | 18:6a4db94011d3 | 104 | */ |
sahilmgandhi | 18:6a4db94011d3 | 105 | void UART_DisableFlowCtrl(UART_T* uart) |
sahilmgandhi | 18:6a4db94011d3 | 106 | { |
sahilmgandhi | 18:6a4db94011d3 | 107 | uart->INTEN &= ~(UART_INTEN_ATORTSEN_Msk | UART_INTEN_ATOCTSEN_Msk); |
sahilmgandhi | 18:6a4db94011d3 | 108 | } |
sahilmgandhi | 18:6a4db94011d3 | 109 | |
sahilmgandhi | 18:6a4db94011d3 | 110 | |
sahilmgandhi | 18:6a4db94011d3 | 111 | /** |
sahilmgandhi | 18:6a4db94011d3 | 112 | * @brief Disable UART specified interrupt |
sahilmgandhi | 18:6a4db94011d3 | 113 | * |
sahilmgandhi | 18:6a4db94011d3 | 114 | * @param[in] uart The pointer of the specified UART module. |
sahilmgandhi | 18:6a4db94011d3 | 115 | * @param[in] u32InterruptFlag The specified interrupt of UART module. |
sahilmgandhi | 18:6a4db94011d3 | 116 | * - \ref UART_INTEN_WKCTSIEN_Msk : CTS wake-up interrupt |
sahilmgandhi | 18:6a4db94011d3 | 117 | * - \ref UART_INTEN_WKDATIEN_Msk : Data wake-up interrupt |
sahilmgandhi | 18:6a4db94011d3 | 118 | * - \ref UART_INTEN_LINIEN_Msk : Lin bus interrupt |
sahilmgandhi | 18:6a4db94011d3 | 119 | * - \ref UART_INTEN_BUFERRIEN_Msk : Buffer Error interrupt |
sahilmgandhi | 18:6a4db94011d3 | 120 | * - \ref UART_INTEN_RXTOIEN_Msk : Rx time-out interrupt |
sahilmgandhi | 18:6a4db94011d3 | 121 | * - \ref UART_INTEN_MODEMIEN_Msk : Modem status interrupt |
sahilmgandhi | 18:6a4db94011d3 | 122 | * - \ref UART_INTEN_RLSIEN_Msk : Receive Line status interrupt |
sahilmgandhi | 18:6a4db94011d3 | 123 | * - \ref UART_INTEN_THREIEN_Msk : Tx empty interrupt |
sahilmgandhi | 18:6a4db94011d3 | 124 | * - \ref UART_INTEN_RDAIEN_Msk : Rx ready interrupt * |
sahilmgandhi | 18:6a4db94011d3 | 125 | * |
sahilmgandhi | 18:6a4db94011d3 | 126 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 127 | * |
sahilmgandhi | 18:6a4db94011d3 | 128 | * @details The function is used to disable UART specified interrupt and disable NVIC UART IRQ. |
sahilmgandhi | 18:6a4db94011d3 | 129 | */ |
sahilmgandhi | 18:6a4db94011d3 | 130 | void UART_DisableInt(UART_T* uart, uint32_t u32InterruptFlag) |
sahilmgandhi | 18:6a4db94011d3 | 131 | { |
sahilmgandhi | 18:6a4db94011d3 | 132 | /* Disable UART specified interrupt */ |
sahilmgandhi | 18:6a4db94011d3 | 133 | UART_DISABLE_INT(uart, u32InterruptFlag); |
sahilmgandhi | 18:6a4db94011d3 | 134 | |
sahilmgandhi | 18:6a4db94011d3 | 135 | /* Disable NVIC UART IRQ */ |
sahilmgandhi | 18:6a4db94011d3 | 136 | if(uart == UART0) |
sahilmgandhi | 18:6a4db94011d3 | 137 | NVIC_DisableIRQ(UART0_IRQn); |
sahilmgandhi | 18:6a4db94011d3 | 138 | else if(uart == UART1) |
sahilmgandhi | 18:6a4db94011d3 | 139 | NVIC_DisableIRQ(UART1_IRQn); |
sahilmgandhi | 18:6a4db94011d3 | 140 | else if(uart == UART2) |
sahilmgandhi | 18:6a4db94011d3 | 141 | NVIC_DisableIRQ(UART2_IRQn); |
sahilmgandhi | 18:6a4db94011d3 | 142 | else |
sahilmgandhi | 18:6a4db94011d3 | 143 | NVIC_DisableIRQ(UART3_IRQn); |
sahilmgandhi | 18:6a4db94011d3 | 144 | } |
sahilmgandhi | 18:6a4db94011d3 | 145 | |
sahilmgandhi | 18:6a4db94011d3 | 146 | |
sahilmgandhi | 18:6a4db94011d3 | 147 | /** |
sahilmgandhi | 18:6a4db94011d3 | 148 | * @brief Enable UART auto flow control function |
sahilmgandhi | 18:6a4db94011d3 | 149 | * |
sahilmgandhi | 18:6a4db94011d3 | 150 | * @param[in] uart The pointer of the specified UART module. |
sahilmgandhi | 18:6a4db94011d3 | 151 | * |
sahilmgandhi | 18:6a4db94011d3 | 152 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 153 | * |
sahilmgandhi | 18:6a4db94011d3 | 154 | * @details The function is used to Enable UART auto flow control. |
sahilmgandhi | 18:6a4db94011d3 | 155 | */ |
sahilmgandhi | 18:6a4db94011d3 | 156 | void UART_EnableFlowCtrl(UART_T* uart) |
sahilmgandhi | 18:6a4db94011d3 | 157 | { |
sahilmgandhi | 18:6a4db94011d3 | 158 | /* Set RTS pin output is low level active */ |
sahilmgandhi | 18:6a4db94011d3 | 159 | uart->MODEM |= UART_MODEM_RTSACTLV_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 160 | |
sahilmgandhi | 18:6a4db94011d3 | 161 | /* Set CTS pin input is low level active */ |
sahilmgandhi | 18:6a4db94011d3 | 162 | uart->MODEMSTS |= UART_MODEMSTS_CTSACTLV_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 163 | |
sahilmgandhi | 18:6a4db94011d3 | 164 | /* Set RTS and CTS auto flow control enable */ |
sahilmgandhi | 18:6a4db94011d3 | 165 | uart->INTEN |= UART_INTEN_ATORTSEN_Msk | UART_INTEN_ATOCTSEN_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 166 | } |
sahilmgandhi | 18:6a4db94011d3 | 167 | |
sahilmgandhi | 18:6a4db94011d3 | 168 | |
sahilmgandhi | 18:6a4db94011d3 | 169 | /** |
sahilmgandhi | 18:6a4db94011d3 | 170 | * @brief The function is used to enable UART specified interrupt and enable NVIC UART IRQ. |
sahilmgandhi | 18:6a4db94011d3 | 171 | * |
sahilmgandhi | 18:6a4db94011d3 | 172 | * @param[in] uart The pointer of the specified UART module. |
sahilmgandhi | 18:6a4db94011d3 | 173 | * @param[in] u32InterruptFlag The specified interrupt of UART module: |
sahilmgandhi | 18:6a4db94011d3 | 174 | * - \ref UART_INTEN_WKCTSIEN_Msk : CTS wake-up interrupt |
sahilmgandhi | 18:6a4db94011d3 | 175 | * - \ref UART_INTEN_WKDATIEN_Msk : Data wake-up interrupt |
sahilmgandhi | 18:6a4db94011d3 | 176 | * - \ref UART_INTEN_LINIEN_Msk : Lin bus interrupt |
sahilmgandhi | 18:6a4db94011d3 | 177 | * - \ref UART_INTEN_BUFERRIEN_Msk : Buffer Error interrupt |
sahilmgandhi | 18:6a4db94011d3 | 178 | * - \ref UART_INTEN_RXTOIEN_Msk : Rx time-out interrupt |
sahilmgandhi | 18:6a4db94011d3 | 179 | * - \ref UART_INTEN_MODEMIEN_Msk : Modem status interrupt |
sahilmgandhi | 18:6a4db94011d3 | 180 | * - \ref UART_INTEN_RLSIEN_Msk : Receive Line status interrupt |
sahilmgandhi | 18:6a4db94011d3 | 181 | * - \ref UART_INTEN_THREIEN_Msk : Tx empty interrupt |
sahilmgandhi | 18:6a4db94011d3 | 182 | * - \ref UART_INTEN_RDAIEN_Msk : Rx ready interrupt * |
sahilmgandhi | 18:6a4db94011d3 | 183 | * |
sahilmgandhi | 18:6a4db94011d3 | 184 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 185 | * |
sahilmgandhi | 18:6a4db94011d3 | 186 | * @details The function is used to enable UART specified interrupt and enable NVIC UART IRQ. |
sahilmgandhi | 18:6a4db94011d3 | 187 | */ |
sahilmgandhi | 18:6a4db94011d3 | 188 | void UART_EnableInt(UART_T* uart, uint32_t u32InterruptFlag) |
sahilmgandhi | 18:6a4db94011d3 | 189 | { |
sahilmgandhi | 18:6a4db94011d3 | 190 | |
sahilmgandhi | 18:6a4db94011d3 | 191 | /* Enable UART specified interrupt */ |
sahilmgandhi | 18:6a4db94011d3 | 192 | UART_ENABLE_INT(uart, u32InterruptFlag); |
sahilmgandhi | 18:6a4db94011d3 | 193 | |
sahilmgandhi | 18:6a4db94011d3 | 194 | /* Enable NVIC UART IRQ */ |
sahilmgandhi | 18:6a4db94011d3 | 195 | if(uart == UART0) |
sahilmgandhi | 18:6a4db94011d3 | 196 | NVIC_EnableIRQ(UART0_IRQn); |
sahilmgandhi | 18:6a4db94011d3 | 197 | else if(uart == UART1) |
sahilmgandhi | 18:6a4db94011d3 | 198 | NVIC_EnableIRQ(UART1_IRQn); |
sahilmgandhi | 18:6a4db94011d3 | 199 | else if(uart == UART2) |
sahilmgandhi | 18:6a4db94011d3 | 200 | NVIC_EnableIRQ(UART2_IRQn); |
sahilmgandhi | 18:6a4db94011d3 | 201 | else |
sahilmgandhi | 18:6a4db94011d3 | 202 | NVIC_EnableIRQ(UART3_IRQn); |
sahilmgandhi | 18:6a4db94011d3 | 203 | |
sahilmgandhi | 18:6a4db94011d3 | 204 | } |
sahilmgandhi | 18:6a4db94011d3 | 205 | |
sahilmgandhi | 18:6a4db94011d3 | 206 | |
sahilmgandhi | 18:6a4db94011d3 | 207 | /** |
sahilmgandhi | 18:6a4db94011d3 | 208 | * @brief Open and set UART function |
sahilmgandhi | 18:6a4db94011d3 | 209 | * |
sahilmgandhi | 18:6a4db94011d3 | 210 | * @param[in] uart The pointer of the specified UART module. |
sahilmgandhi | 18:6a4db94011d3 | 211 | * @param[in] u32baudrate The baudrate of UART module. |
sahilmgandhi | 18:6a4db94011d3 | 212 | * |
sahilmgandhi | 18:6a4db94011d3 | 213 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 214 | * |
sahilmgandhi | 18:6a4db94011d3 | 215 | * @details This function use to enable UART function and set baud-rate. |
sahilmgandhi | 18:6a4db94011d3 | 216 | */ |
sahilmgandhi | 18:6a4db94011d3 | 217 | void UART_Open(UART_T* uart, uint32_t u32baudrate) |
sahilmgandhi | 18:6a4db94011d3 | 218 | { |
sahilmgandhi | 18:6a4db94011d3 | 219 | uint8_t u8UartClkSrcSel, u8UartClkDivNum; |
sahilmgandhi | 18:6a4db94011d3 | 220 | uint32_t u32ClkTbl[4] = {__HXT, 0, __LXT, __HIRC}; |
sahilmgandhi | 18:6a4db94011d3 | 221 | uint32_t u32Baud_Div = 0; |
sahilmgandhi | 18:6a4db94011d3 | 222 | |
sahilmgandhi | 18:6a4db94011d3 | 223 | /* Get UART clock source selection */ |
sahilmgandhi | 18:6a4db94011d3 | 224 | u8UartClkSrcSel = (CLK->CLKSEL1 & CLK_CLKSEL1_UARTSEL_Msk) >> CLK_CLKSEL1_UARTSEL_Pos; |
sahilmgandhi | 18:6a4db94011d3 | 225 | |
sahilmgandhi | 18:6a4db94011d3 | 226 | /* Get UART clock divider number */ |
sahilmgandhi | 18:6a4db94011d3 | 227 | u8UartClkDivNum = (CLK->CLKDIV0 & CLK_CLKDIV0_UARTDIV_Msk) >> CLK_CLKDIV0_UARTDIV_Pos; |
sahilmgandhi | 18:6a4db94011d3 | 228 | |
sahilmgandhi | 18:6a4db94011d3 | 229 | /* Select UART function */ |
sahilmgandhi | 18:6a4db94011d3 | 230 | uart->FUNCSEL = UART_FUNCSEL_UART; |
sahilmgandhi | 18:6a4db94011d3 | 231 | |
sahilmgandhi | 18:6a4db94011d3 | 232 | /* Set UART line configuration */ |
sahilmgandhi | 18:6a4db94011d3 | 233 | uart->LINE = UART_WORD_LEN_8 | UART_PARITY_NONE | UART_STOP_BIT_1; |
sahilmgandhi | 18:6a4db94011d3 | 234 | |
sahilmgandhi | 18:6a4db94011d3 | 235 | /* Set UART Rx and RTS trigger level */ |
sahilmgandhi | 18:6a4db94011d3 | 236 | uart->FIFO &= ~(UART_FIFO_RFITL_Msk | UART_FIFO_RTSTRGLV_Msk); |
sahilmgandhi | 18:6a4db94011d3 | 237 | |
sahilmgandhi | 18:6a4db94011d3 | 238 | /* Get PLL clock frequency if UART clock source selection is PLL */ |
sahilmgandhi | 18:6a4db94011d3 | 239 | if(u8UartClkSrcSel == 1) |
sahilmgandhi | 18:6a4db94011d3 | 240 | u32ClkTbl[u8UartClkSrcSel] = CLK_GetPLLClockFreq(); |
sahilmgandhi | 18:6a4db94011d3 | 241 | |
sahilmgandhi | 18:6a4db94011d3 | 242 | /* Set UART baud rate */ |
sahilmgandhi | 18:6a4db94011d3 | 243 | if(u32baudrate != 0) |
sahilmgandhi | 18:6a4db94011d3 | 244 | { |
sahilmgandhi | 18:6a4db94011d3 | 245 | u32Baud_Div = UART_BAUD_MODE2_DIVIDER((u32ClkTbl[u8UartClkSrcSel]) / (u8UartClkDivNum + 1), u32baudrate); |
sahilmgandhi | 18:6a4db94011d3 | 246 | |
sahilmgandhi | 18:6a4db94011d3 | 247 | if(u32Baud_Div > 0xFFFF) |
sahilmgandhi | 18:6a4db94011d3 | 248 | uart->BAUD = (UART_BAUD_MODE0 | UART_BAUD_MODE0_DIVIDER((u32ClkTbl[u8UartClkSrcSel]) / (u8UartClkDivNum + 1), u32baudrate)); |
sahilmgandhi | 18:6a4db94011d3 | 249 | else |
sahilmgandhi | 18:6a4db94011d3 | 250 | uart->BAUD = (UART_BAUD_MODE2 | u32Baud_Div); |
sahilmgandhi | 18:6a4db94011d3 | 251 | } |
sahilmgandhi | 18:6a4db94011d3 | 252 | } |
sahilmgandhi | 18:6a4db94011d3 | 253 | |
sahilmgandhi | 18:6a4db94011d3 | 254 | |
sahilmgandhi | 18:6a4db94011d3 | 255 | /** |
sahilmgandhi | 18:6a4db94011d3 | 256 | * @brief Read UART data |
sahilmgandhi | 18:6a4db94011d3 | 257 | * |
sahilmgandhi | 18:6a4db94011d3 | 258 | * @param[in] uart The pointer of the specified UART module. |
sahilmgandhi | 18:6a4db94011d3 | 259 | * @param[in] pu8RxBuf The buffer to receive the data of receive FIFO. |
sahilmgandhi | 18:6a4db94011d3 | 260 | * @param[in] u32ReadBytes The the read bytes number of data. |
sahilmgandhi | 18:6a4db94011d3 | 261 | * |
sahilmgandhi | 18:6a4db94011d3 | 262 | * @return u32Count Receive byte count |
sahilmgandhi | 18:6a4db94011d3 | 263 | * |
sahilmgandhi | 18:6a4db94011d3 | 264 | * @details The function is used to read Rx data from RX FIFO and the data will be stored in pu8RxBuf. |
sahilmgandhi | 18:6a4db94011d3 | 265 | */ |
sahilmgandhi | 18:6a4db94011d3 | 266 | uint32_t UART_Read(UART_T* uart, uint8_t *pu8RxBuf, uint32_t u32ReadBytes) |
sahilmgandhi | 18:6a4db94011d3 | 267 | { |
sahilmgandhi | 18:6a4db94011d3 | 268 | uint32_t u32Count, u32delayno; |
sahilmgandhi | 18:6a4db94011d3 | 269 | |
sahilmgandhi | 18:6a4db94011d3 | 270 | for(u32Count = 0; u32Count < u32ReadBytes; u32Count++) |
sahilmgandhi | 18:6a4db94011d3 | 271 | { |
sahilmgandhi | 18:6a4db94011d3 | 272 | u32delayno = 0; |
sahilmgandhi | 18:6a4db94011d3 | 273 | |
sahilmgandhi | 18:6a4db94011d3 | 274 | while(uart->FIFOSTS & UART_FIFOSTS_RXEMPTY_Msk) /* Check RX empty => failed */ |
sahilmgandhi | 18:6a4db94011d3 | 275 | { |
sahilmgandhi | 18:6a4db94011d3 | 276 | u32delayno++; |
sahilmgandhi | 18:6a4db94011d3 | 277 | if(u32delayno >= 0x40000000) |
sahilmgandhi | 18:6a4db94011d3 | 278 | return FALSE; |
sahilmgandhi | 18:6a4db94011d3 | 279 | } |
sahilmgandhi | 18:6a4db94011d3 | 280 | pu8RxBuf[u32Count] = uart->DAT; /* Get Data from UART RX */ |
sahilmgandhi | 18:6a4db94011d3 | 281 | } |
sahilmgandhi | 18:6a4db94011d3 | 282 | |
sahilmgandhi | 18:6a4db94011d3 | 283 | return u32Count; |
sahilmgandhi | 18:6a4db94011d3 | 284 | |
sahilmgandhi | 18:6a4db94011d3 | 285 | } |
sahilmgandhi | 18:6a4db94011d3 | 286 | |
sahilmgandhi | 18:6a4db94011d3 | 287 | |
sahilmgandhi | 18:6a4db94011d3 | 288 | /** |
sahilmgandhi | 18:6a4db94011d3 | 289 | * @brief Set UART line configuration |
sahilmgandhi | 18:6a4db94011d3 | 290 | * |
sahilmgandhi | 18:6a4db94011d3 | 291 | * @param[in] uart The pointer of the specified UART module. |
sahilmgandhi | 18:6a4db94011d3 | 292 | * @param[in] u32baudrate The register value of baudrate of UART module. |
sahilmgandhi | 18:6a4db94011d3 | 293 | * If u32baudrate = 0, UART baudrate will not change. |
sahilmgandhi | 18:6a4db94011d3 | 294 | * @param[in] u32data_width The data length of UART module. |
sahilmgandhi | 18:6a4db94011d3 | 295 | * - \ref UART_WORD_LEN_5 |
sahilmgandhi | 18:6a4db94011d3 | 296 | * - \ref UART_WORD_LEN_6 |
sahilmgandhi | 18:6a4db94011d3 | 297 | * - \ref UART_WORD_LEN_7 |
sahilmgandhi | 18:6a4db94011d3 | 298 | * - \ref UART_WORD_LEN_8 |
sahilmgandhi | 18:6a4db94011d3 | 299 | * @param[in] u32parity The parity setting (none/odd/even/mark/space) of UART module. |
sahilmgandhi | 18:6a4db94011d3 | 300 | * - \ref UART_PARITY_NONE |
sahilmgandhi | 18:6a4db94011d3 | 301 | * - \ref UART_PARITY_ODD |
sahilmgandhi | 18:6a4db94011d3 | 302 | * - \ref UART_PARITY_EVEN |
sahilmgandhi | 18:6a4db94011d3 | 303 | * - \ref UART_PARITY_MARK |
sahilmgandhi | 18:6a4db94011d3 | 304 | * - \ref UART_PARITY_SPACE |
sahilmgandhi | 18:6a4db94011d3 | 305 | * @param[in] u32stop_bits The stop bit length (1/1.5/2 bit) of UART module. |
sahilmgandhi | 18:6a4db94011d3 | 306 | * - \ref UART_STOP_BIT_1 |
sahilmgandhi | 18:6a4db94011d3 | 307 | * - \ref UART_STOP_BIT_1_5 |
sahilmgandhi | 18:6a4db94011d3 | 308 | * - \ref UART_STOP_BIT_2 |
sahilmgandhi | 18:6a4db94011d3 | 309 | * |
sahilmgandhi | 18:6a4db94011d3 | 310 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 311 | * |
sahilmgandhi | 18:6a4db94011d3 | 312 | * @details This function use to config UART line setting. |
sahilmgandhi | 18:6a4db94011d3 | 313 | */ |
sahilmgandhi | 18:6a4db94011d3 | 314 | void UART_SetLine_Config(UART_T* uart, uint32_t u32baudrate, uint32_t u32data_width, uint32_t u32parity, uint32_t u32stop_bits) |
sahilmgandhi | 18:6a4db94011d3 | 315 | { |
sahilmgandhi | 18:6a4db94011d3 | 316 | uint8_t u8UartClkSrcSel, u8UartClkDivNum; |
sahilmgandhi | 18:6a4db94011d3 | 317 | uint32_t u32ClkTbl[4] = {__HXT, 0, __LXT, __HIRC}; |
sahilmgandhi | 18:6a4db94011d3 | 318 | uint32_t u32Baud_Div = 0; |
sahilmgandhi | 18:6a4db94011d3 | 319 | |
sahilmgandhi | 18:6a4db94011d3 | 320 | /* Get UART clock source selection */ |
sahilmgandhi | 18:6a4db94011d3 | 321 | u8UartClkSrcSel = (CLK->CLKSEL1 & CLK_CLKSEL1_UARTSEL_Msk) >> CLK_CLKSEL1_UARTSEL_Pos; |
sahilmgandhi | 18:6a4db94011d3 | 322 | |
sahilmgandhi | 18:6a4db94011d3 | 323 | /* Get UART clock divider number */ |
sahilmgandhi | 18:6a4db94011d3 | 324 | u8UartClkDivNum = (CLK->CLKDIV0 & CLK_CLKDIV0_UARTDIV_Msk) >> CLK_CLKDIV0_UARTDIV_Pos; |
sahilmgandhi | 18:6a4db94011d3 | 325 | |
sahilmgandhi | 18:6a4db94011d3 | 326 | /* Get PLL clock frequency if UART clock source selection is PLL */ |
sahilmgandhi | 18:6a4db94011d3 | 327 | if(u8UartClkSrcSel == 1) |
sahilmgandhi | 18:6a4db94011d3 | 328 | u32ClkTbl[u8UartClkSrcSel] = CLK_GetPLLClockFreq(); |
sahilmgandhi | 18:6a4db94011d3 | 329 | |
sahilmgandhi | 18:6a4db94011d3 | 330 | /* Set UART baud rate */ |
sahilmgandhi | 18:6a4db94011d3 | 331 | if(u32baudrate != 0) |
sahilmgandhi | 18:6a4db94011d3 | 332 | { |
sahilmgandhi | 18:6a4db94011d3 | 333 | u32Baud_Div = UART_BAUD_MODE2_DIVIDER((u32ClkTbl[u8UartClkSrcSel]) / (u8UartClkDivNum + 1), u32baudrate); |
sahilmgandhi | 18:6a4db94011d3 | 334 | |
sahilmgandhi | 18:6a4db94011d3 | 335 | if(u32Baud_Div > 0xFFFF) |
sahilmgandhi | 18:6a4db94011d3 | 336 | uart->BAUD = (UART_BAUD_MODE0 | UART_BAUD_MODE0_DIVIDER((u32ClkTbl[u8UartClkSrcSel]) / (u8UartClkDivNum + 1), u32baudrate)); |
sahilmgandhi | 18:6a4db94011d3 | 337 | else |
sahilmgandhi | 18:6a4db94011d3 | 338 | uart->BAUD = (UART_BAUD_MODE2 | u32Baud_Div); |
sahilmgandhi | 18:6a4db94011d3 | 339 | } |
sahilmgandhi | 18:6a4db94011d3 | 340 | |
sahilmgandhi | 18:6a4db94011d3 | 341 | /* Set UART line configuration */ |
sahilmgandhi | 18:6a4db94011d3 | 342 | uart->LINE = u32data_width | u32parity | u32stop_bits; |
sahilmgandhi | 18:6a4db94011d3 | 343 | } |
sahilmgandhi | 18:6a4db94011d3 | 344 | |
sahilmgandhi | 18:6a4db94011d3 | 345 | |
sahilmgandhi | 18:6a4db94011d3 | 346 | /** |
sahilmgandhi | 18:6a4db94011d3 | 347 | * @brief Set Rx timeout count |
sahilmgandhi | 18:6a4db94011d3 | 348 | * |
sahilmgandhi | 18:6a4db94011d3 | 349 | * @param[in] uart The pointer of the specified UART module. |
sahilmgandhi | 18:6a4db94011d3 | 350 | * @param[in] u32TOC Rx timeout counter. |
sahilmgandhi | 18:6a4db94011d3 | 351 | * |
sahilmgandhi | 18:6a4db94011d3 | 352 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 353 | * |
sahilmgandhi | 18:6a4db94011d3 | 354 | * @details This function use to set Rx timeout count. |
sahilmgandhi | 18:6a4db94011d3 | 355 | */ |
sahilmgandhi | 18:6a4db94011d3 | 356 | void UART_SetTimeoutCnt(UART_T* uart, uint32_t u32TOC) |
sahilmgandhi | 18:6a4db94011d3 | 357 | { |
sahilmgandhi | 18:6a4db94011d3 | 358 | /* Set time-out interrupt comparator */ |
sahilmgandhi | 18:6a4db94011d3 | 359 | uart->TOUT = (uart->TOUT & ~UART_TOUT_TOIC_Msk) | (u32TOC); |
sahilmgandhi | 18:6a4db94011d3 | 360 | |
sahilmgandhi | 18:6a4db94011d3 | 361 | /* Set time-out counter enable */ |
sahilmgandhi | 18:6a4db94011d3 | 362 | uart->INTEN |= UART_INTEN_TOCNTEN_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 363 | } |
sahilmgandhi | 18:6a4db94011d3 | 364 | |
sahilmgandhi | 18:6a4db94011d3 | 365 | |
sahilmgandhi | 18:6a4db94011d3 | 366 | /** |
sahilmgandhi | 18:6a4db94011d3 | 367 | * @brief Select and configure IrDA function |
sahilmgandhi | 18:6a4db94011d3 | 368 | * |
sahilmgandhi | 18:6a4db94011d3 | 369 | * @param[in] uart The pointer of the specified UART module. |
sahilmgandhi | 18:6a4db94011d3 | 370 | * @param[in] u32Buadrate The baudrate of UART module. |
sahilmgandhi | 18:6a4db94011d3 | 371 | * @param[in] u32Direction The direction of UART module in IrDA mode: |
sahilmgandhi | 18:6a4db94011d3 | 372 | * - \ref UART_IRDA_TXEN |
sahilmgandhi | 18:6a4db94011d3 | 373 | * - \ref UART_IRDA_RXEN |
sahilmgandhi | 18:6a4db94011d3 | 374 | * |
sahilmgandhi | 18:6a4db94011d3 | 375 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 376 | * |
sahilmgandhi | 18:6a4db94011d3 | 377 | * @details The function is used to configure IrDA relative settings. It consists of TX or RX mode and baudrate. |
sahilmgandhi | 18:6a4db94011d3 | 378 | */ |
sahilmgandhi | 18:6a4db94011d3 | 379 | void UART_SelectIrDAMode(UART_T* uart, uint32_t u32Buadrate, uint32_t u32Direction) |
sahilmgandhi | 18:6a4db94011d3 | 380 | { |
sahilmgandhi | 18:6a4db94011d3 | 381 | uint8_t u8UartClkSrcSel, u8UartClkDivNum; |
sahilmgandhi | 18:6a4db94011d3 | 382 | uint32_t u32ClkTbl[4] = {__HXT, 0, __LXT, __HIRC}; |
sahilmgandhi | 18:6a4db94011d3 | 383 | uint32_t u32Baud_Div; |
sahilmgandhi | 18:6a4db94011d3 | 384 | |
sahilmgandhi | 18:6a4db94011d3 | 385 | /* Select IrDA function mode */ |
sahilmgandhi | 18:6a4db94011d3 | 386 | uart->FUNCSEL = UART_FUNCSEL_IrDA; |
sahilmgandhi | 18:6a4db94011d3 | 387 | |
sahilmgandhi | 18:6a4db94011d3 | 388 | /* Get UART clock source selection */ |
sahilmgandhi | 18:6a4db94011d3 | 389 | u8UartClkSrcSel = (CLK->CLKSEL1 & CLK_CLKSEL1_UARTSEL_Msk) >> CLK_CLKSEL1_UARTSEL_Pos; |
sahilmgandhi | 18:6a4db94011d3 | 390 | |
sahilmgandhi | 18:6a4db94011d3 | 391 | /* Get UART clock divider number */ |
sahilmgandhi | 18:6a4db94011d3 | 392 | u8UartClkDivNum = (CLK->CLKDIV0 & CLK_CLKDIV0_UARTDIV_Msk) >> CLK_CLKDIV0_UARTDIV_Pos; |
sahilmgandhi | 18:6a4db94011d3 | 393 | |
sahilmgandhi | 18:6a4db94011d3 | 394 | /* Get PLL clock frequency if UART clock source selection is PLL */ |
sahilmgandhi | 18:6a4db94011d3 | 395 | if(u8UartClkSrcSel == 1) |
sahilmgandhi | 18:6a4db94011d3 | 396 | u32ClkTbl[u8UartClkSrcSel] = CLK_GetPLLClockFreq(); |
sahilmgandhi | 18:6a4db94011d3 | 397 | |
sahilmgandhi | 18:6a4db94011d3 | 398 | /* Set UART IrDA baud rate in mode 0 */ |
sahilmgandhi | 18:6a4db94011d3 | 399 | if(u32Buadrate != 0) |
sahilmgandhi | 18:6a4db94011d3 | 400 | { |
sahilmgandhi | 18:6a4db94011d3 | 401 | u32Baud_Div = UART_BAUD_MODE0_DIVIDER((u32ClkTbl[u8UartClkSrcSel]) / (u8UartClkDivNum + 1), u32Buadrate); |
sahilmgandhi | 18:6a4db94011d3 | 402 | |
sahilmgandhi | 18:6a4db94011d3 | 403 | if(u32Baud_Div < 0xFFFF) |
sahilmgandhi | 18:6a4db94011d3 | 404 | uart->BAUD = (UART_BAUD_MODE0 | u32Baud_Div); |
sahilmgandhi | 18:6a4db94011d3 | 405 | } |
sahilmgandhi | 18:6a4db94011d3 | 406 | |
sahilmgandhi | 18:6a4db94011d3 | 407 | /* Configure IrDA relative settings */ |
sahilmgandhi | 18:6a4db94011d3 | 408 | if(u32Direction == UART_IRDA_RXEN) |
sahilmgandhi | 18:6a4db94011d3 | 409 | { |
sahilmgandhi | 18:6a4db94011d3 | 410 | uart->IRDA |= UART_IRDA_RXINV_Msk; //Rx signal is inverse |
sahilmgandhi | 18:6a4db94011d3 | 411 | uart->IRDA &= ~UART_IRDA_TXEN_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 412 | } |
sahilmgandhi | 18:6a4db94011d3 | 413 | else |
sahilmgandhi | 18:6a4db94011d3 | 414 | { |
sahilmgandhi | 18:6a4db94011d3 | 415 | uart->IRDA &= ~UART_IRDA_TXINV_Msk; //Tx signal is not inverse |
sahilmgandhi | 18:6a4db94011d3 | 416 | uart->IRDA |= UART_IRDA_TXEN_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 417 | } |
sahilmgandhi | 18:6a4db94011d3 | 418 | |
sahilmgandhi | 18:6a4db94011d3 | 419 | } |
sahilmgandhi | 18:6a4db94011d3 | 420 | |
sahilmgandhi | 18:6a4db94011d3 | 421 | |
sahilmgandhi | 18:6a4db94011d3 | 422 | /** |
sahilmgandhi | 18:6a4db94011d3 | 423 | * @brief Select and configure RS485 function |
sahilmgandhi | 18:6a4db94011d3 | 424 | * |
sahilmgandhi | 18:6a4db94011d3 | 425 | * @param[in] uart The pointer of the specified UART module. |
sahilmgandhi | 18:6a4db94011d3 | 426 | * @param[in] u32Mode The operation mode(NMM/AUD/AAD). |
sahilmgandhi | 18:6a4db94011d3 | 427 | * - \ref UART_ALTCTL_RS485NMM_Msk |
sahilmgandhi | 18:6a4db94011d3 | 428 | * - \ref UART_ALTCTL_RS485AUD_Msk |
sahilmgandhi | 18:6a4db94011d3 | 429 | * - \ref UART_ALTCTL_RS485AAD_Msk |
sahilmgandhi | 18:6a4db94011d3 | 430 | * @param[in] u32Addr The RS485 address. |
sahilmgandhi | 18:6a4db94011d3 | 431 | * |
sahilmgandhi | 18:6a4db94011d3 | 432 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 433 | * |
sahilmgandhi | 18:6a4db94011d3 | 434 | * @details The function is used to set RS485 relative setting. |
sahilmgandhi | 18:6a4db94011d3 | 435 | */ |
sahilmgandhi | 18:6a4db94011d3 | 436 | void UART_SelectRS485Mode(UART_T* uart, uint32_t u32Mode, uint32_t u32Addr) |
sahilmgandhi | 18:6a4db94011d3 | 437 | { |
sahilmgandhi | 18:6a4db94011d3 | 438 | /* Select UART RS485 function mode */ |
sahilmgandhi | 18:6a4db94011d3 | 439 | uart->FUNCSEL = UART_FUNCSEL_RS485; |
sahilmgandhi | 18:6a4db94011d3 | 440 | |
sahilmgandhi | 18:6a4db94011d3 | 441 | /* Set RS585 configuration */ |
sahilmgandhi | 18:6a4db94011d3 | 442 | uart->ALTCTL &= ~(UART_ALTCTL_RS485NMM_Msk | UART_ALTCTL_RS485AUD_Msk | UART_ALTCTL_RS485AAD_Msk | UART_ALTCTL_ADDRMV_Msk); |
sahilmgandhi | 18:6a4db94011d3 | 443 | uart->ALTCTL |= (u32Mode | (u32Addr << UART_ALTCTL_ADDRMV_Pos)); |
sahilmgandhi | 18:6a4db94011d3 | 444 | } |
sahilmgandhi | 18:6a4db94011d3 | 445 | |
sahilmgandhi | 18:6a4db94011d3 | 446 | |
sahilmgandhi | 18:6a4db94011d3 | 447 | /** |
sahilmgandhi | 18:6a4db94011d3 | 448 | * @brief Select and configure LIN function |
sahilmgandhi | 18:6a4db94011d3 | 449 | * |
sahilmgandhi | 18:6a4db94011d3 | 450 | * @param[in] uart The pointer of the specified UART module. |
sahilmgandhi | 18:6a4db94011d3 | 451 | * @param[in] u32Mode The LIN direction : |
sahilmgandhi | 18:6a4db94011d3 | 452 | * - \ref UART_ALTCTL_LINTXEN_Msk |
sahilmgandhi | 18:6a4db94011d3 | 453 | * - \ref UART_ALTCTL_LINRXEN_Msk |
sahilmgandhi | 18:6a4db94011d3 | 454 | * @param[in] u32BreakLength The breakfield length. |
sahilmgandhi | 18:6a4db94011d3 | 455 | * |
sahilmgandhi | 18:6a4db94011d3 | 456 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 457 | * |
sahilmgandhi | 18:6a4db94011d3 | 458 | * @details The function is used to set LIN relative setting. |
sahilmgandhi | 18:6a4db94011d3 | 459 | */ |
sahilmgandhi | 18:6a4db94011d3 | 460 | void UART_SelectLINMode(UART_T* uart, uint32_t u32Mode, uint32_t u32BreakLength) |
sahilmgandhi | 18:6a4db94011d3 | 461 | { |
sahilmgandhi | 18:6a4db94011d3 | 462 | /* Select LIN function mode */ |
sahilmgandhi | 18:6a4db94011d3 | 463 | uart->FUNCSEL = UART_FUNCSEL_LIN; |
sahilmgandhi | 18:6a4db94011d3 | 464 | |
sahilmgandhi | 18:6a4db94011d3 | 465 | /* Select LIN function setting : Tx enable, Rx enable and break field length */ |
sahilmgandhi | 18:6a4db94011d3 | 466 | uart->ALTCTL &= ~(UART_ALTCTL_LINTXEN_Msk | UART_ALTCTL_LINRXEN_Msk | UART_ALTCTL_BRKFL_Msk); |
sahilmgandhi | 18:6a4db94011d3 | 467 | uart->ALTCTL |= (u32Mode | (u32BreakLength << UART_ALTCTL_BRKFL_Pos)); |
sahilmgandhi | 18:6a4db94011d3 | 468 | } |
sahilmgandhi | 18:6a4db94011d3 | 469 | |
sahilmgandhi | 18:6a4db94011d3 | 470 | |
sahilmgandhi | 18:6a4db94011d3 | 471 | /** |
sahilmgandhi | 18:6a4db94011d3 | 472 | * @brief Write UART data |
sahilmgandhi | 18:6a4db94011d3 | 473 | * |
sahilmgandhi | 18:6a4db94011d3 | 474 | * @param[in] uart The pointer of the specified UART module. |
sahilmgandhi | 18:6a4db94011d3 | 475 | * @param[in] pu8TxBuf The buffer to send the data to UART transmission FIFO. |
sahilmgandhi | 18:6a4db94011d3 | 476 | * @param[out] u32WriteBytes The byte number of data. |
sahilmgandhi | 18:6a4db94011d3 | 477 | * |
sahilmgandhi | 18:6a4db94011d3 | 478 | * @return u32Count transfer byte count |
sahilmgandhi | 18:6a4db94011d3 | 479 | * |
sahilmgandhi | 18:6a4db94011d3 | 480 | * @details The function is to write data into TX buffer to transmit data by UART. |
sahilmgandhi | 18:6a4db94011d3 | 481 | */ |
sahilmgandhi | 18:6a4db94011d3 | 482 | uint32_t UART_Write(UART_T* uart, uint8_t *pu8TxBuf, uint32_t u32WriteBytes) |
sahilmgandhi | 18:6a4db94011d3 | 483 | { |
sahilmgandhi | 18:6a4db94011d3 | 484 | uint32_t u32Count, u32delayno; |
sahilmgandhi | 18:6a4db94011d3 | 485 | |
sahilmgandhi | 18:6a4db94011d3 | 486 | for(u32Count = 0; u32Count != u32WriteBytes; u32Count++) |
sahilmgandhi | 18:6a4db94011d3 | 487 | { |
sahilmgandhi | 18:6a4db94011d3 | 488 | u32delayno = 0; |
sahilmgandhi | 18:6a4db94011d3 | 489 | while((uart->FIFOSTS & UART_FIFOSTS_TXEMPTYF_Msk) == 0) /* Wait Tx empty and Time-out manner */ |
sahilmgandhi | 18:6a4db94011d3 | 490 | { |
sahilmgandhi | 18:6a4db94011d3 | 491 | u32delayno++; |
sahilmgandhi | 18:6a4db94011d3 | 492 | if(u32delayno >= 0x40000000) |
sahilmgandhi | 18:6a4db94011d3 | 493 | return FALSE; |
sahilmgandhi | 18:6a4db94011d3 | 494 | } |
sahilmgandhi | 18:6a4db94011d3 | 495 | uart->DAT = pu8TxBuf[u32Count]; /* Send UART Data from buffer */ |
sahilmgandhi | 18:6a4db94011d3 | 496 | } |
sahilmgandhi | 18:6a4db94011d3 | 497 | |
sahilmgandhi | 18:6a4db94011d3 | 498 | return u32Count; |
sahilmgandhi | 18:6a4db94011d3 | 499 | |
sahilmgandhi | 18:6a4db94011d3 | 500 | } |
sahilmgandhi | 18:6a4db94011d3 | 501 | |
sahilmgandhi | 18:6a4db94011d3 | 502 | |
sahilmgandhi | 18:6a4db94011d3 | 503 | /*@}*/ /* end of group UART_EXPORTED_FUNCTIONS */ |
sahilmgandhi | 18:6a4db94011d3 | 504 | |
sahilmgandhi | 18:6a4db94011d3 | 505 | /*@}*/ /* end of group UART_Driver */ |
sahilmgandhi | 18:6a4db94011d3 | 506 | |
sahilmgandhi | 18:6a4db94011d3 | 507 | /*@}*/ /* end of group Standard_Driver */ |
sahilmgandhi | 18:6a4db94011d3 | 508 | |
sahilmgandhi | 18:6a4db94011d3 | 509 | /*** (C) COPYRIGHT 2012~2015 Nuvoton Technology Corp. ***/ |
sahilmgandhi | 18:6a4db94011d3 | 510 | |
sahilmgandhi | 18:6a4db94011d3 | 511 | |
sahilmgandhi | 18:6a4db94011d3 | 512 |