mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Committer:
mbed_official
Date:
Thu Apr 03 11:45:06 2014 +0100
Revision:
149:1fb5f62b92bd
Parent:
targets/hal/TARGET_Freescale/TARGET_KSDK_MCUS/TARGET_KSDK_CODE/hal/uart/fsl_uart_hal_common_configurations.c@146:f64d43ff0c18
Synchronized with git revision 220c0bb39ceee40016e1e86350c058963d01ed42

Full URL: https://github.com/mbedmicro/mbed/commit/220c0bb39ceee40016e1e86350c058963d01ed42/

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 146:f64d43ff0c18 1 /*
mbed_official 146:f64d43ff0c18 2 * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
mbed_official 146:f64d43ff0c18 3 * All rights reserved.
mbed_official 146:f64d43ff0c18 4 *
mbed_official 146:f64d43ff0c18 5 * Redistribution and use in source and binary forms, with or without modification,
mbed_official 146:f64d43ff0c18 6 * are permitted provided that the following conditions are met:
mbed_official 146:f64d43ff0c18 7 *
mbed_official 146:f64d43ff0c18 8 * o Redistributions of source code must retain the above copyright notice, this list
mbed_official 146:f64d43ff0c18 9 * of conditions and the following disclaimer.
mbed_official 146:f64d43ff0c18 10 *
mbed_official 146:f64d43ff0c18 11 * o Redistributions in binary form must reproduce the above copyright notice, this
mbed_official 146:f64d43ff0c18 12 * list of conditions and the following disclaimer in the documentation and/or
mbed_official 146:f64d43ff0c18 13 * other materials provided with the distribution.
mbed_official 146:f64d43ff0c18 14 *
mbed_official 146:f64d43ff0c18 15 * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
mbed_official 146:f64d43ff0c18 16 * contributors may be used to endorse or promote products derived from this
mbed_official 146:f64d43ff0c18 17 * software without specific prior written permission.
mbed_official 146:f64d43ff0c18 18 *
mbed_official 146:f64d43ff0c18 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
mbed_official 146:f64d43ff0c18 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
mbed_official 146:f64d43ff0c18 21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 146:f64d43ff0c18 22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
mbed_official 146:f64d43ff0c18 23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
mbed_official 146:f64d43ff0c18 24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
mbed_official 146:f64d43ff0c18 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
mbed_official 146:f64d43ff0c18 26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
mbed_official 146:f64d43ff0c18 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
mbed_official 146:f64d43ff0c18 28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 146:f64d43ff0c18 29 */
mbed_official 146:f64d43ff0c18 30 #include "fsl_uart_hal.h"
mbed_official 146:f64d43ff0c18 31
mbed_official 146:f64d43ff0c18 32 /*******************************************************************************
mbed_official 146:f64d43ff0c18 33 * Definitions
mbed_official 146:f64d43ff0c18 34 ******************************************************************************/
mbed_official 146:f64d43ff0c18 35
mbed_official 146:f64d43ff0c18 36 /*******************************************************************************
mbed_official 146:f64d43ff0c18 37 * Code
mbed_official 146:f64d43ff0c18 38 ******************************************************************************/
mbed_official 146:f64d43ff0c18 39
mbed_official 146:f64d43ff0c18 40 /*FUNCTION**********************************************************************
mbed_official 146:f64d43ff0c18 41 *
mbed_official 146:f64d43ff0c18 42 * Function Name : uart_hal_init
mbed_official 146:f64d43ff0c18 43 * Description : Initialize the UART controller.
mbed_official 146:f64d43ff0c18 44 * This function will initialize the module to user defined settings and default settings.
mbed_official 146:f64d43ff0c18 45 * Here is an example demonstrating how to define the uart_config_t structure and call
mbed_official 146:f64d43ff0c18 46 * the uart_hal_init function:
mbed_official 146:f64d43ff0c18 47 * uart_config_t uartConfig;
mbed_official 146:f64d43ff0c18 48 * uartConfig.uartSourceClockInHz = uartSourceClock;
mbed_official 146:f64d43ff0c18 49 * uartConfig.baudRate = baudRate;
mbed_official 146:f64d43ff0c18 50 * uartConfig.bitCountPerChar = kUart8BitsPerChar;
mbed_official 146:f64d43ff0c18 51 * uartConfig.parityMode = kUartParityDisabled;
mbed_official 146:f64d43ff0c18 52 * uartConfig.stopBitCount = kUartOneStopBit;
mbed_official 146:f64d43ff0c18 53 * uartConfig.txDataInvert = 0; uartConfig.rxDataInvert = 0;
mbed_official 146:f64d43ff0c18 54 * uart_hal_init(uartInstance, &uartConfig);
mbed_official 146:f64d43ff0c18 55 *
mbed_official 146:f64d43ff0c18 56 *END**************************************************************************/
mbed_official 146:f64d43ff0c18 57 uart_status_t uart_hal_init(uint32_t uartInstance, const uart_config_t *config)
mbed_official 146:f64d43ff0c18 58 {
mbed_official 146:f64d43ff0c18 59 assert(uartInstance < UART_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 60
mbed_official 146:f64d43ff0c18 61 /* first, disable the UART transmitter and receiver*/
mbed_official 146:f64d43ff0c18 62 uart_hal_disable_transmitter(uartInstance);
mbed_official 146:f64d43ff0c18 63 uart_hal_disable_receiver(uartInstance);
mbed_official 146:f64d43ff0c18 64
mbed_official 146:f64d43ff0c18 65 /*********************************************************/
mbed_official 146:f64d43ff0c18 66 /* calculate baud rate settings */
mbed_official 146:f64d43ff0c18 67 /*********************************************************/
mbed_official 146:f64d43ff0c18 68 if (uart_hal_set_baud_rate(uartInstance, config->uartSourceClockInHz, config->baudRate)
mbed_official 146:f64d43ff0c18 69 != kStatus_UART_Success)
mbed_official 146:f64d43ff0c18 70 {
mbed_official 146:f64d43ff0c18 71 return kStatus_UART_BaudRateCalculationError;
mbed_official 146:f64d43ff0c18 72 }
mbed_official 146:f64d43ff0c18 73
mbed_official 146:f64d43ff0c18 74 /*********************************************************/
mbed_official 146:f64d43ff0c18 75 /* configure number of bits in a char */
mbed_official 146:f64d43ff0c18 76 /*********************************************************/
mbed_official 146:f64d43ff0c18 77 if (uart_hal_configure_bit_count_per_char(uartInstance, config->bitCountPerChar)
mbed_official 146:f64d43ff0c18 78 != kStatus_UART_Success)
mbed_official 146:f64d43ff0c18 79 {
mbed_official 146:f64d43ff0c18 80 return kStatus_UART_BitCountNotSupported;
mbed_official 146:f64d43ff0c18 81 }
mbed_official 146:f64d43ff0c18 82
mbed_official 146:f64d43ff0c18 83 /*********************************************************/
mbed_official 146:f64d43ff0c18 84 /* configure the parity enable/type */
mbed_official 146:f64d43ff0c18 85 /*********************************************************/
mbed_official 146:f64d43ff0c18 86 uart_hal_configure_parity_mode(uartInstance, config->parityMode);
mbed_official 146:f64d43ff0c18 87
mbed_official 146:f64d43ff0c18 88 /*********************************************************/
mbed_official 146:f64d43ff0c18 89 /* configure the number of stop bits */
mbed_official 146:f64d43ff0c18 90 /*********************************************************/
mbed_official 146:f64d43ff0c18 91 if (uart_hal_configure_stop_bit_count(uartInstance, config->stopBitCount) !=
mbed_official 146:f64d43ff0c18 92 kStatus_UART_Success)
mbed_official 146:f64d43ff0c18 93 {
mbed_official 146:f64d43ff0c18 94 return kStatus_UART_StopBitCountNotSupported;
mbed_official 146:f64d43ff0c18 95 }
mbed_official 146:f64d43ff0c18 96
mbed_official 146:f64d43ff0c18 97 /*********************************************************/
mbed_official 146:f64d43ff0c18 98 /* configure tx and rx inversions */
mbed_official 146:f64d43ff0c18 99 /*********************************************************/
mbed_official 146:f64d43ff0c18 100 uart_hal_configure_tx_rx_inversion(uartInstance, config->rxDataInvert, config->txDataInvert);
mbed_official 146:f64d43ff0c18 101
mbed_official 146:f64d43ff0c18 102 /* finally, enable the UART transmitter and receiver*/
mbed_official 146:f64d43ff0c18 103 uart_hal_enable_transmitter(uartInstance);
mbed_official 146:f64d43ff0c18 104 uart_hal_enable_receiver(uartInstance);
mbed_official 146:f64d43ff0c18 105
mbed_official 146:f64d43ff0c18 106 return kStatus_UART_Success;
mbed_official 146:f64d43ff0c18 107 }
mbed_official 146:f64d43ff0c18 108
mbed_official 146:f64d43ff0c18 109 /*FUNCTION**********************************************************************
mbed_official 146:f64d43ff0c18 110 *
mbed_official 146:f64d43ff0c18 111 * Function Name : uart_hal_set_baud_rate
mbed_official 146:f64d43ff0c18 112 * Description : Configure the UART baud rate.
mbed_official 146:f64d43ff0c18 113 * This function programs the UART baud rate to the desired value passed in by the user. The user
mbed_official 146:f64d43ff0c18 114 * must also pass in the module source clock so that the function can calculate the baud
mbed_official 146:f64d43ff0c18 115 * rate divisors to their appropriate values.
mbed_official 146:f64d43ff0c18 116 * In some UART instances it is required that the transmitter/receiver should be disabled
mbed_official 146:f64d43ff0c18 117 * before calling this function.
mbed_official 146:f64d43ff0c18 118 * Generally this is be applied to all UARTs to ensure safe operation.
mbed_official 146:f64d43ff0c18 119 *
mbed_official 146:f64d43ff0c18 120 *END**************************************************************************/
mbed_official 146:f64d43ff0c18 121 uart_status_t uart_hal_set_baud_rate(uint32_t uartInstance, uint32_t sourceClockInHz,
mbed_official 146:f64d43ff0c18 122 uint32_t desiredBaudRate)
mbed_official 146:f64d43ff0c18 123 {
mbed_official 146:f64d43ff0c18 124 uint16_t sbr;
mbed_official 146:f64d43ff0c18 125
mbed_official 146:f64d43ff0c18 126 assert(uartInstance < UART_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 127
mbed_official 146:f64d43ff0c18 128 /* SoCs with low power uart support differ in how they calculate the baud rate
mbed_official 146:f64d43ff0c18 129 * for various instances of the uart from SoCs without low power uart support
mbed_official 146:f64d43ff0c18 130 */
mbed_official 146:f64d43ff0c18 131 #if FSL_FEATURE_UART_HAS_LOW_POWER_UART_SUPPORT
mbed_official 146:f64d43ff0c18 132 uint16_t sbrTemp;
mbed_official 146:f64d43ff0c18 133 uint32_t osr;
mbed_official 146:f64d43ff0c18 134 uint8_t i;
mbed_official 146:f64d43ff0c18 135 uint32_t tempDiff;
mbed_official 146:f64d43ff0c18 136 uint32_t calculatedBaud, baudDiff;
mbed_official 146:f64d43ff0c18 137
mbed_official 146:f64d43ff0c18 138 /* calculate baud rate settings*/
mbed_official 146:f64d43ff0c18 139 if (uartInstance == 0)
mbed_official 146:f64d43ff0c18 140 {
mbed_official 146:f64d43ff0c18 141 /* This uart instantiation uses a slightly different baud rate calculation
mbed_official 146:f64d43ff0c18 142 * The idea is to use the best OSR (over-sampling rate) possible
mbed_official 146:f64d43ff0c18 143 * Note, osr is typically hard-set to 16 in other uart instantiations
mbed_official 146:f64d43ff0c18 144 * First calculate the baud rate using the minimum OSR possible (4)
mbed_official 146:f64d43ff0c18 145 */
mbed_official 146:f64d43ff0c18 146 osr = 4;
mbed_official 146:f64d43ff0c18 147 sbr = (sourceClockInHz/(desiredBaudRate * osr));
mbed_official 146:f64d43ff0c18 148 calculatedBaud = (sourceClockInHz / (osr * sbr));
mbed_official 146:f64d43ff0c18 149
mbed_official 146:f64d43ff0c18 150 if (calculatedBaud > desiredBaudRate)
mbed_official 146:f64d43ff0c18 151 {
mbed_official 146:f64d43ff0c18 152 baudDiff = calculatedBaud - desiredBaudRate;
mbed_official 146:f64d43ff0c18 153 }
mbed_official 146:f64d43ff0c18 154 else
mbed_official 146:f64d43ff0c18 155 {
mbed_official 146:f64d43ff0c18 156 baudDiff = desiredBaudRate - calculatedBaud;
mbed_official 146:f64d43ff0c18 157 }
mbed_official 146:f64d43ff0c18 158
mbed_official 146:f64d43ff0c18 159 /* loop to find the best osr value possible, one that generates minimum baudDiff
mbed_official 146:f64d43ff0c18 160 * iterate through the rest of the supported values of osr
mbed_official 146:f64d43ff0c18 161 */
mbed_official 146:f64d43ff0c18 162 for (i = 5; i <= 32; i++)
mbed_official 146:f64d43ff0c18 163 {
mbed_official 146:f64d43ff0c18 164 /* calculate the temporary sbr value */
mbed_official 146:f64d43ff0c18 165 sbrTemp = (sourceClockInHz/(desiredBaudRate * i));
mbed_official 146:f64d43ff0c18 166 /* calculate the baud rate based on the temporary osr and sbr values*/
mbed_official 146:f64d43ff0c18 167 calculatedBaud = (sourceClockInHz / (i * sbrTemp));
mbed_official 146:f64d43ff0c18 168
mbed_official 146:f64d43ff0c18 169 if (calculatedBaud > desiredBaudRate)
mbed_official 146:f64d43ff0c18 170 {
mbed_official 146:f64d43ff0c18 171 tempDiff = calculatedBaud - desiredBaudRate;
mbed_official 146:f64d43ff0c18 172 }
mbed_official 146:f64d43ff0c18 173 else
mbed_official 146:f64d43ff0c18 174 {
mbed_official 146:f64d43ff0c18 175 tempDiff = desiredBaudRate - calculatedBaud;
mbed_official 146:f64d43ff0c18 176 }
mbed_official 146:f64d43ff0c18 177
mbed_official 146:f64d43ff0c18 178 if (tempDiff <= baudDiff)
mbed_official 146:f64d43ff0c18 179 {
mbed_official 146:f64d43ff0c18 180 baudDiff = tempDiff;
mbed_official 146:f64d43ff0c18 181 osr = i; /* update and store the best osr value calculated*/
mbed_official 146:f64d43ff0c18 182 sbr = sbrTemp; /* update store the best sbr value calculated*/
mbed_official 146:f64d43ff0c18 183 }
mbed_official 146:f64d43ff0c18 184 }
mbed_official 146:f64d43ff0c18 185
mbed_official 146:f64d43ff0c18 186 /* next, check to see if actual baud rate is within 3% of desired baud rate
mbed_official 146:f64d43ff0c18 187 * based on the best calculate osr value
mbed_official 146:f64d43ff0c18 188 */
mbed_official 146:f64d43ff0c18 189 if (baudDiff < ((desiredBaudRate / 100) * 3))
mbed_official 146:f64d43ff0c18 190 {
mbed_official 146:f64d43ff0c18 191 /* Acceptable baud rate */
mbed_official 146:f64d43ff0c18 192 /* Check if osr is between 4x and 7x oversampling*/
mbed_official 146:f64d43ff0c18 193 /* If so, then "BOTHEDGE" sampling must be turned on*/
mbed_official 146:f64d43ff0c18 194 if ((osr > 3) && (osr < 8))
mbed_official 146:f64d43ff0c18 195 {
mbed_official 146:f64d43ff0c18 196 HW_UART0_C5_SET(BM_UART0_C5_BOTHEDGE);
mbed_official 146:f64d43ff0c18 197 }
mbed_official 146:f64d43ff0c18 198
mbed_official 146:f64d43ff0c18 199 /* program the osr value (bit value is one less than actual value)*/
mbed_official 146:f64d43ff0c18 200 BW_UART0_C4_OSR(osr-1);
mbed_official 146:f64d43ff0c18 201
mbed_official 146:f64d43ff0c18 202 /* program the sbr (divider) value obtained above*/
mbed_official 146:f64d43ff0c18 203 BW_UART0_BDH_SBR((uint8_t)(sbr >> 8));
mbed_official 146:f64d43ff0c18 204 BW_UART0_BDL_SBR((uint8_t)sbr);
mbed_official 146:f64d43ff0c18 205 }
mbed_official 146:f64d43ff0c18 206 else
mbed_official 146:f64d43ff0c18 207 {
mbed_official 146:f64d43ff0c18 208 /* Unacceptable baud rate difference of more than 3%*/
mbed_official 146:f64d43ff0c18 209 return kStatus_UART_BaudRatePercentDiffExceeded;
mbed_official 146:f64d43ff0c18 210 }
mbed_official 146:f64d43ff0c18 211 }
mbed_official 146:f64d43ff0c18 212 else
mbed_official 146:f64d43ff0c18 213 {
mbed_official 146:f64d43ff0c18 214 /* calculate the baud rate modulo divisor, sbr*/
mbed_official 146:f64d43ff0c18 215 sbr = sourceClockInHz / (desiredBaudRate * 16);
mbed_official 146:f64d43ff0c18 216
mbed_official 146:f64d43ff0c18 217 /* check to see if sbr is out of range of register bits */
mbed_official 146:f64d43ff0c18 218 if ( (sbr > 0x1FFF) || (sbr < 1) )
mbed_official 146:f64d43ff0c18 219 {
mbed_official 146:f64d43ff0c18 220 /* unsupported baud rate for given source clock input*/
mbed_official 146:f64d43ff0c18 221 return kStatus_UART_BaudRateCalculationError;
mbed_official 146:f64d43ff0c18 222 }
mbed_official 146:f64d43ff0c18 223
mbed_official 146:f64d43ff0c18 224 /* next, check to see if actual baud rate is within 3% of desired baud rate
mbed_official 146:f64d43ff0c18 225 * calculate baud rate based on previosuly calculated sbr
mbed_official 146:f64d43ff0c18 226 */
mbed_official 146:f64d43ff0c18 227 calculatedBaud = (sourceClockInHz / (16 * sbr));
mbed_official 146:f64d43ff0c18 228
mbed_official 146:f64d43ff0c18 229 if (calculatedBaud > desiredBaudRate)
mbed_official 146:f64d43ff0c18 230 {
mbed_official 146:f64d43ff0c18 231 baudDiff = calculatedBaud - desiredBaudRate;
mbed_official 146:f64d43ff0c18 232 }
mbed_official 146:f64d43ff0c18 233 else
mbed_official 146:f64d43ff0c18 234 {
mbed_official 146:f64d43ff0c18 235 baudDiff = desiredBaudRate - calculatedBaud;
mbed_official 146:f64d43ff0c18 236 }
mbed_official 146:f64d43ff0c18 237
mbed_official 146:f64d43ff0c18 238 /* check for baud rate to be within 3%*/
mbed_official 146:f64d43ff0c18 239 if (baudDiff > ((desiredBaudRate / 100) * 3))
mbed_official 146:f64d43ff0c18 240 {
mbed_official 146:f64d43ff0c18 241 /* Unacceptable baud rate difference of more than 3%*/
mbed_official 146:f64d43ff0c18 242 return kStatus_UART_BaudRatePercentDiffExceeded;
mbed_official 146:f64d43ff0c18 243 }
mbed_official 146:f64d43ff0c18 244
mbed_official 146:f64d43ff0c18 245 /* Else, baud rate is ok and write to the SBR bits in the BDH and BDL registers*/
mbed_official 146:f64d43ff0c18 246 BW_UART_BDH_SBR(uartInstance, (uint8_t)(sbr >> 8));
mbed_official 146:f64d43ff0c18 247 BW_UART_BDL_SBR(uartInstance, (uint8_t)sbr);
mbed_official 146:f64d43ff0c18 248 }
mbed_official 146:f64d43ff0c18 249 #else
mbed_official 146:f64d43ff0c18 250 /* BaudRate = (SourceClkInHz)/[16 * (SBR + BRFA)]
mbed_official 146:f64d43ff0c18 251 * First, calculate SBR (integer part) then calculate the BRFA (fine adjust fractional field)
mbed_official 146:f64d43ff0c18 252 */
mbed_official 146:f64d43ff0c18 253 uint16_t brfa;
mbed_official 146:f64d43ff0c18 254
mbed_official 146:f64d43ff0c18 255 /* calculate the baud rate modulo divisor, sbr*/
mbed_official 146:f64d43ff0c18 256 sbr = sourceClockInHz / (desiredBaudRate * 16);
mbed_official 146:f64d43ff0c18 257
mbed_official 146:f64d43ff0c18 258 /* check to see if sbr is out of range of register bits */
mbed_official 146:f64d43ff0c18 259 if ( (sbr > 0x1FFF) || (sbr < 1) )
mbed_official 146:f64d43ff0c18 260 {
mbed_official 146:f64d43ff0c18 261 /* unsupported baud rate for given source clock input*/
mbed_official 146:f64d43ff0c18 262 return kStatus_UART_BaudRateCalculationError;
mbed_official 146:f64d43ff0c18 263 }
mbed_official 146:f64d43ff0c18 264
mbed_official 146:f64d43ff0c18 265 /* write the sbr value to the BDH and BDL registers*/
mbed_official 146:f64d43ff0c18 266 BW_UART_BDH_SBR(uartInstance, (uint8_t)(sbr >> 8));
mbed_official 146:f64d43ff0c18 267 BW_UART_BDL_SBR(uartInstance, (uint8_t)sbr);
mbed_official 146:f64d43ff0c18 268
mbed_official 146:f64d43ff0c18 269 /* determine if a fractional divider is needed to fine tune closer to the desired baud
mbed_official 146:f64d43ff0c18 270 * each value of brfa is in 1/32 increments, hence the multiply-by-32
mbed_official 146:f64d43ff0c18 271 */
mbed_official 146:f64d43ff0c18 272 brfa = (32*sourceClockInHz/(desiredBaudRate*16)) - 32*sbr;
mbed_official 146:f64d43ff0c18 273
mbed_official 146:f64d43ff0c18 274 /* write the brfa value to the register*/
mbed_official 146:f64d43ff0c18 275 BW_UART_C4_BRFA(uartInstance, brfa);
mbed_official 146:f64d43ff0c18 276 #endif
mbed_official 146:f64d43ff0c18 277
mbed_official 146:f64d43ff0c18 278 return kStatus_UART_Success;
mbed_official 146:f64d43ff0c18 279 }
mbed_official 146:f64d43ff0c18 280
mbed_official 146:f64d43ff0c18 281 /*FUNCTION**********************************************************************
mbed_official 146:f64d43ff0c18 282 *
mbed_official 146:f64d43ff0c18 283 * Function Name : uart_hal_set_baud_rate_divisor
mbed_official 146:f64d43ff0c18 284 * Description : Set the UART baud rate modulo divisor value.
mbed_official 146:f64d43ff0c18 285 * This function allows the user to program the baud rate divisor directly in situations
mbed_official 146:f64d43ff0c18 286 * where the divisor value is known. In this case, the user may not want to call the
mbed_official 146:f64d43ff0c18 287 * uart_hal_set_baud_rate() function as the divisor is already known to them.
mbed_official 146:f64d43ff0c18 288 *
mbed_official 146:f64d43ff0c18 289 *END**************************************************************************/
mbed_official 146:f64d43ff0c18 290 uart_status_t uart_hal_set_baud_rate_divisor(uint32_t uartInstance, uint32_t baudRateDivisor)
mbed_official 146:f64d43ff0c18 291 {
mbed_official 146:f64d43ff0c18 292 assert(uartInstance < UART_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 293
mbed_official 146:f64d43ff0c18 294 /* check to see if baudRateDivisor is out of range of register bits */
mbed_official 146:f64d43ff0c18 295 if ( (baudRateDivisor > 0x1FFF) || (baudRateDivisor < 1) )
mbed_official 146:f64d43ff0c18 296 {
mbed_official 146:f64d43ff0c18 297 /* unsupported bit setting*/
mbed_official 146:f64d43ff0c18 298 return kStatus_UART_InvalidBitSetting;
mbed_official 146:f64d43ff0c18 299 }
mbed_official 146:f64d43ff0c18 300
mbed_official 146:f64d43ff0c18 301 #if FSL_FEATURE_UART_HAS_LOW_POWER_UART_SUPPORT
mbed_official 146:f64d43ff0c18 302 if (uartInstance == 0)
mbed_official 146:f64d43ff0c18 303 {
mbed_official 146:f64d43ff0c18 304 /* program the sbr (baudRateDivisor) value to the BDH and BDL registers*/
mbed_official 146:f64d43ff0c18 305 BW_UART0_BDH_SBR((uint8_t)(baudRateDivisor >> 8));
mbed_official 146:f64d43ff0c18 306 BW_UART0_BDL_SBR((uint8_t)baudRateDivisor);
mbed_official 146:f64d43ff0c18 307 }
mbed_official 146:f64d43ff0c18 308 else
mbed_official 146:f64d43ff0c18 309 #endif
mbed_official 146:f64d43ff0c18 310 {
mbed_official 146:f64d43ff0c18 311 /* program the sbr (baudRateDivisor) value to the BDH and BDL registers*/
mbed_official 146:f64d43ff0c18 312 BW_UART_BDH_SBR(uartInstance, (uint8_t)(baudRateDivisor >> 8));
mbed_official 146:f64d43ff0c18 313 BW_UART_BDL_SBR(uartInstance, (uint8_t)baudRateDivisor);
mbed_official 146:f64d43ff0c18 314 }
mbed_official 146:f64d43ff0c18 315
mbed_official 146:f64d43ff0c18 316 return kStatus_UART_Success;
mbed_official 146:f64d43ff0c18 317 }
mbed_official 146:f64d43ff0c18 318
mbed_official 146:f64d43ff0c18 319 #if FSL_FEATURE_UART_HAS_BAUD_RATE_FINE_ADJUST_SUPPORT
mbed_official 146:f64d43ff0c18 320 /*FUNCTION**********************************************************************
mbed_official 146:f64d43ff0c18 321 *
mbed_official 146:f64d43ff0c18 322 * Function Name : uart_hal_set_baud_rate_fine_adjust
mbed_official 146:f64d43ff0c18 323 * Description : Set the UART baud rate fine adjust. (Note: Feature available on select
mbed_official 146:f64d43ff0c18 324 * UART instances used in conjunction with baud rate programming)
mbed_official 146:f64d43ff0c18 325 * This function, which programs the baud rate fine adjust, is used in conjuction with
mbed_official 146:f64d43ff0c18 326 * programming the baud rate modulo divisor in situations where these divisors value are known
mbed_official 146:f64d43ff0c18 327 * In this case, the user may not want to call the uart_hal_set_baud_rate() function as the
mbed_official 146:f64d43ff0c18 328 * divisors are already known to them.
mbed_official 146:f64d43ff0c18 329 *
mbed_official 146:f64d43ff0c18 330 *END**************************************************************************/
mbed_official 146:f64d43ff0c18 331 uart_status_t uart_hal_set_baud_rate_fine_adjust(uint32_t uartInstance, uint8_t baudFineAdjust)
mbed_official 146:f64d43ff0c18 332 {
mbed_official 146:f64d43ff0c18 333 assert(uartInstance < UART_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 334
mbed_official 146:f64d43ff0c18 335 if (baudFineAdjust > 0x1F)
mbed_official 146:f64d43ff0c18 336 {
mbed_official 146:f64d43ff0c18 337 /* unsupported bit setting*/
mbed_official 146:f64d43ff0c18 338 return kStatus_UART_InvalidBitSetting;
mbed_official 146:f64d43ff0c18 339 }
mbed_official 146:f64d43ff0c18 340
mbed_official 146:f64d43ff0c18 341 BW_UART_C4_BRFA(uartInstance, baudFineAdjust);
mbed_official 146:f64d43ff0c18 342
mbed_official 146:f64d43ff0c18 343 return kStatus_UART_Success;
mbed_official 146:f64d43ff0c18 344 }
mbed_official 146:f64d43ff0c18 345 #endif
mbed_official 146:f64d43ff0c18 346
mbed_official 146:f64d43ff0c18 347 #if FSL_FEATURE_UART_HAS_BAUD_RATE_OVER_SAMPLING_SUPPORT
mbed_official 146:f64d43ff0c18 348 /*FUNCTION**********************************************************************
mbed_official 146:f64d43ff0c18 349 *
mbed_official 146:f64d43ff0c18 350 * Function Name : uart_hal_set_oversampling_ratio
mbed_official 146:f64d43ff0c18 351 * Description : Set the UART baud rate oversampling ratio. (Note: Feature available on select
mbed_official 146:f64d43ff0c18 352 * UART instances used in conjunction with baud rate programming)
mbed_official 146:f64d43ff0c18 353 * This function allows the user to directly configure the oversampling ratio (OSR). Normally this
mbed_official 146:f64d43ff0c18 354 * ratio is automatically configured when calling the uart_hal_set_baud_rate(). However, if the user
mbed_official 146:f64d43ff0c18 355 * knows the necessary dividers and wishes to directly program them, they also have the option to
mbed_official 146:f64d43ff0c18 356 * directly program the OSR.
mbed_official 146:f64d43ff0c18 357 * The oversampling ratio should be set between 4x (00011) and 32x (11111), writing
mbed_official 146:f64d43ff0c18 358 * an invalid oversampling ratio with result in an error and will be set to a default
mbed_official 146:f64d43ff0c18 359 * 16x (01111) oversampling ratio.
mbed_official 146:f64d43ff0c18 360 * It is required that the transmitter/receiver be disabled before calling
mbed_official 146:f64d43ff0c18 361 * this function.
mbed_official 146:f64d43ff0c18 362 *
mbed_official 146:f64d43ff0c18 363 *END**************************************************************************/
mbed_official 146:f64d43ff0c18 364 uart_status_t uart_hal_set_oversampling_ratio(uint32_t uartInstance, uint32_t overSamplingRatio)
mbed_official 146:f64d43ff0c18 365 {
mbed_official 146:f64d43ff0c18 366 assert(uartInstance < UART_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 367
mbed_official 146:f64d43ff0c18 368 if (overSamplingRatio > 0x1F)
mbed_official 146:f64d43ff0c18 369 {
mbed_official 146:f64d43ff0c18 370 /* unsupported bit setting*/
mbed_official 146:f64d43ff0c18 371 return kStatus_UART_InvalidBitSetting;
mbed_official 146:f64d43ff0c18 372 }
mbed_official 146:f64d43ff0c18 373
mbed_official 146:f64d43ff0c18 374 if (uartInstance == 0)
mbed_official 146:f64d43ff0c18 375 {
mbed_official 146:f64d43ff0c18 376 BW_UART0_C4_OSR(overSamplingRatio);
mbed_official 146:f64d43ff0c18 377 return kStatus_UART_Success;
mbed_official 146:f64d43ff0c18 378 }
mbed_official 146:f64d43ff0c18 379 else
mbed_official 146:f64d43ff0c18 380 {
mbed_official 146:f64d43ff0c18 381 return kStatus_UART_OverSamplingNotSupported;
mbed_official 146:f64d43ff0c18 382 }
mbed_official 146:f64d43ff0c18 383 }
mbed_official 146:f64d43ff0c18 384 #endif
mbed_official 146:f64d43ff0c18 385
mbed_official 146:f64d43ff0c18 386 #if FSL_FEATURE_UART_HAS_BOTH_EDGE_SAMPLING_SUPPORT
mbed_official 146:f64d43ff0c18 387 /*FUNCTION**********************************************************************
mbed_official 146:f64d43ff0c18 388 *
mbed_official 146:f64d43ff0c18 389 * Function Name : uart_hal_configure_both_edge_sampling
mbed_official 146:f64d43ff0c18 390 * Description : Configure the UART baud rate both edge sampling option.
mbed_official 146:f64d43ff0c18 391 * (Note: Feature available on select UART instances used in conjunction with
mbed_official 146:f64d43ff0c18 392 * baud rate programming)
mbed_official 146:f64d43ff0c18 393 * This function allows the user to directly configure the both edge sampling option.
mbed_official 146:f64d43ff0c18 394 * When enabled, the received data is sampled on both edges of the baud rate clock.
mbed_official 146:f64d43ff0c18 395 * This must be set when the oversampling ratio is between 4x and 7x.
mbed_official 146:f64d43ff0c18 396 * This function should only be called when the receiver is disabled.
mbed_official 146:f64d43ff0c18 397 *
mbed_official 146:f64d43ff0c18 398 *END**************************************************************************/
mbed_official 146:f64d43ff0c18 399 uart_status_t uart_hal_configure_both_edge_sampling(uint32_t uartInstance,
mbed_official 146:f64d43ff0c18 400 bool enableBothEdgeSampling)
mbed_official 146:f64d43ff0c18 401 {
mbed_official 146:f64d43ff0c18 402 assert(uartInstance < UART_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 403
mbed_official 146:f64d43ff0c18 404 if (uartInstance == 0)
mbed_official 146:f64d43ff0c18 405 {
mbed_official 146:f64d43ff0c18 406 BW_UART0_C5_BOTHEDGE(enableBothEdgeSampling);
mbed_official 146:f64d43ff0c18 407 return kStatus_UART_Success;
mbed_official 146:f64d43ff0c18 408 }
mbed_official 146:f64d43ff0c18 409 else
mbed_official 146:f64d43ff0c18 410 {
mbed_official 146:f64d43ff0c18 411 return kStatus_UART_BothEdgeNotSupported;
mbed_official 146:f64d43ff0c18 412 }
mbed_official 146:f64d43ff0c18 413 }
mbed_official 146:f64d43ff0c18 414 #endif
mbed_official 146:f64d43ff0c18 415
mbed_official 146:f64d43ff0c18 416 /*FUNCTION**********************************************************************
mbed_official 146:f64d43ff0c18 417 *
mbed_official 146:f64d43ff0c18 418 * Function Name : uart_hal_configure_both_edge_sampling
mbed_official 146:f64d43ff0c18 419 * Description : Configure number of bits per character in the UART controller.
mbed_official 146:f64d43ff0c18 420 * This function allows the user to configure the number of bits per character according to the
mbed_official 146:f64d43ff0c18 421 * typedef uart_bit_count_per_char_t.
mbed_official 146:f64d43ff0c18 422 * In some UART instances it is required that the transmitter/receiver should be disabled
mbed_official 146:f64d43ff0c18 423 * before calling this function.
mbed_official 146:f64d43ff0c18 424 * Generally this may be applied to all UARTs to ensure safe operation.
mbed_official 146:f64d43ff0c18 425 *
mbed_official 146:f64d43ff0c18 426 *END**************************************************************************/
mbed_official 146:f64d43ff0c18 427 uart_status_t uart_hal_configure_bit_count_per_char(uint32_t uartInstance,
mbed_official 146:f64d43ff0c18 428 uart_bit_count_per_char_t bitCountPerChar)
mbed_official 146:f64d43ff0c18 429 {
mbed_official 146:f64d43ff0c18 430 assert(uartInstance < UART_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 431
mbed_official 146:f64d43ff0c18 432 /* configure number of bits in a char*/
mbed_official 146:f64d43ff0c18 433 #if FSL_FEATURE_UART_HAS_10BIT_DATA_SUPPORT
mbed_official 146:f64d43ff0c18 434 if (uartInstance == 0)
mbed_official 146:f64d43ff0c18 435 {
mbed_official 146:f64d43ff0c18 436 if(bitCountPerChar == kUart10BitsPerChar)
mbed_official 146:f64d43ff0c18 437 {
mbed_official 146:f64d43ff0c18 438 HW_UART0_C4_SET(BM_UART0_C4_M10); /*set M10 for 10-bit mode, M bit in C1 is don't care*/
mbed_official 146:f64d43ff0c18 439 }
mbed_official 146:f64d43ff0c18 440 else
mbed_official 146:f64d43ff0c18 441 {
mbed_official 146:f64d43ff0c18 442 BW_UART0_C1_M(bitCountPerChar); /* config 8- (M=0) or 9-bits (M=1) */
mbed_official 146:f64d43ff0c18 443 HW_UART0_C4_CLR(BM_UART0_C4_M10); /* clear M10 to make sure not 10-bit mode*/
mbed_official 146:f64d43ff0c18 444 }
mbed_official 146:f64d43ff0c18 445 }
mbed_official 146:f64d43ff0c18 446 else
mbed_official 146:f64d43ff0c18 447 #endif
mbed_official 146:f64d43ff0c18 448 {
mbed_official 146:f64d43ff0c18 449 if(bitCountPerChar == kUart10BitsPerChar)
mbed_official 146:f64d43ff0c18 450 {
mbed_official 146:f64d43ff0c18 451 /* re-enable the UART transmitter and receiver*/
mbed_official 146:f64d43ff0c18 452 uart_hal_enable_transmitter(uartInstance);
mbed_official 146:f64d43ff0c18 453 uart_hal_enable_receiver(uartInstance);
mbed_official 146:f64d43ff0c18 454
mbed_official 146:f64d43ff0c18 455 /* illegal value, this uart instance does not support 10-bit*/
mbed_official 146:f64d43ff0c18 456 return kStatus_UART_BitCountNotSupported;
mbed_official 146:f64d43ff0c18 457 }
mbed_official 146:f64d43ff0c18 458 else
mbed_official 146:f64d43ff0c18 459 {
mbed_official 146:f64d43ff0c18 460 BW_UART_C1_M(uartInstance, bitCountPerChar); /* config 8- (M=0) or 9-bits (M=1) */
mbed_official 146:f64d43ff0c18 461 }
mbed_official 146:f64d43ff0c18 462 }
mbed_official 146:f64d43ff0c18 463
mbed_official 146:f64d43ff0c18 464 return kStatus_UART_Success;
mbed_official 146:f64d43ff0c18 465 }
mbed_official 146:f64d43ff0c18 466
mbed_official 146:f64d43ff0c18 467 /*FUNCTION**********************************************************************
mbed_official 146:f64d43ff0c18 468 *
mbed_official 146:f64d43ff0c18 469 * Function Name : uart_hal_configure_parity_mode
mbed_official 146:f64d43ff0c18 470 * Description : Configure the parity mode in the UART controller.
mbed_official 146:f64d43ff0c18 471 * This function allows the user to configure the parity mode of the UART controller to disable
mbed_official 146:f64d43ff0c18 472 * it or enable it for even parity or for odd parity.
mbed_official 146:f64d43ff0c18 473 * In some UART instances it is required that the transmitter/receiver should be disabled
mbed_official 146:f64d43ff0c18 474 * before calling this function.
mbed_official 146:f64d43ff0c18 475 * Generally this may be applied to all UARTs to ensure safe operation.
mbed_official 146:f64d43ff0c18 476 *
mbed_official 146:f64d43ff0c18 477 *END**************************************************************************/
mbed_official 146:f64d43ff0c18 478 void uart_hal_configure_parity_mode(uint32_t uartInstance, uart_parity_mode_t parityModeType)
mbed_official 146:f64d43ff0c18 479 {
mbed_official 146:f64d43ff0c18 480 assert(uartInstance < UART_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 481
mbed_official 146:f64d43ff0c18 482 /* configure the parity enable/type */
mbed_official 146:f64d43ff0c18 483 #if FSL_FEATURE_UART_HAS_LOW_POWER_UART_SUPPORT
mbed_official 146:f64d43ff0c18 484 if (uartInstance == 0)
mbed_official 146:f64d43ff0c18 485 {
mbed_official 146:f64d43ff0c18 486 if ((parityModeType) == 0)
mbed_official 146:f64d43ff0c18 487 {
mbed_official 146:f64d43ff0c18 488 /* parity disabled, hence parity type is don't care*/
mbed_official 146:f64d43ff0c18 489 HW_UART0_C1_CLR(BM_UART0_C1_PE);
mbed_official 146:f64d43ff0c18 490 }
mbed_official 146:f64d43ff0c18 491 else
mbed_official 146:f64d43ff0c18 492 {
mbed_official 146:f64d43ff0c18 493 /* parity enabled*/
mbed_official 146:f64d43ff0c18 494 HW_UART0_C1_SET(BM_UART0_C1_PE);
mbed_official 146:f64d43ff0c18 495 /* parity odd/even depending on parity mode setting*/
mbed_official 146:f64d43ff0c18 496 BW_UART0_C1_PT((parityModeType) & 0x1);
mbed_official 146:f64d43ff0c18 497 }
mbed_official 146:f64d43ff0c18 498 }
mbed_official 146:f64d43ff0c18 499 else
mbed_official 146:f64d43ff0c18 500 #endif
mbed_official 146:f64d43ff0c18 501 {
mbed_official 146:f64d43ff0c18 502 if ((parityModeType) == 0)
mbed_official 146:f64d43ff0c18 503 {
mbed_official 146:f64d43ff0c18 504 /* parity disabled, hence parity type is don't care*/
mbed_official 146:f64d43ff0c18 505 HW_UART_C1_CLR(uartInstance, BM_UART_C1_PE);
mbed_official 146:f64d43ff0c18 506 }
mbed_official 146:f64d43ff0c18 507 else
mbed_official 146:f64d43ff0c18 508 {
mbed_official 146:f64d43ff0c18 509 /* parity enabled*/
mbed_official 146:f64d43ff0c18 510 HW_UART_C1_SET(uartInstance, BM_UART_C1_PE);
mbed_official 146:f64d43ff0c18 511 /* parity odd/even depending on parity mode setting*/
mbed_official 146:f64d43ff0c18 512 BW_UART_C1_PT(uartInstance, (parityModeType) & 0x1);
mbed_official 146:f64d43ff0c18 513 }
mbed_official 146:f64d43ff0c18 514 }
mbed_official 146:f64d43ff0c18 515 }
mbed_official 146:f64d43ff0c18 516
mbed_official 146:f64d43ff0c18 517 /*FUNCTION**********************************************************************
mbed_official 146:f64d43ff0c18 518 *
mbed_official 146:f64d43ff0c18 519 * Function Name : uart_hal_configure_stop_bit_count
mbed_official 146:f64d43ff0c18 520 * Description : Configure the number of stop bits in the UART controller.
mbed_official 146:f64d43ff0c18 521 * This function allows the user to configure the number of stop bits in the UART controller
mbed_official 146:f64d43ff0c18 522 * to be one or two stop bits.
mbed_official 146:f64d43ff0c18 523 * In some UART instances it is required that the transmitter/receiver should be disabled
mbed_official 146:f64d43ff0c18 524 * before calling this function.
mbed_official 146:f64d43ff0c18 525 * Generally this may be applied to all UARTs to ensure safe operation.
mbed_official 146:f64d43ff0c18 526 *
mbed_official 146:f64d43ff0c18 527 *END**************************************************************************/
mbed_official 146:f64d43ff0c18 528 uart_status_t uart_hal_configure_stop_bit_count(uint32_t uartInstance,
mbed_official 146:f64d43ff0c18 529 uart_stop_bit_count_t stopBitCount)
mbed_official 146:f64d43ff0c18 530 {
mbed_official 146:f64d43ff0c18 531 assert(uartInstance < UART_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 532
mbed_official 146:f64d43ff0c18 533 #if FSL_FEATURE_UART_HAS_STOP_BIT_CONFIG_SUPPORT
mbed_official 146:f64d43ff0c18 534 /* configure the number of stop bits*/
mbed_official 146:f64d43ff0c18 535 if (uartInstance == 0)
mbed_official 146:f64d43ff0c18 536 {
mbed_official 146:f64d43ff0c18 537 BW_UART0_BDH_SBNS(stopBitCount);
mbed_official 146:f64d43ff0c18 538 }
mbed_official 146:f64d43ff0c18 539 else
mbed_official 146:f64d43ff0c18 540 {
mbed_official 146:f64d43ff0c18 541 BW_UART_BDH_SBNS(uartInstance, stopBitCount);
mbed_official 146:f64d43ff0c18 542 }
mbed_official 146:f64d43ff0c18 543
mbed_official 146:f64d43ff0c18 544 return kStatus_UART_Success;
mbed_official 146:f64d43ff0c18 545 #else
mbed_official 146:f64d43ff0c18 546 /* stop bit configuration not supported, only one stop bit is supported*/
mbed_official 146:f64d43ff0c18 547 if(stopBitCount != kUartOneStopBit)
mbed_official 146:f64d43ff0c18 548 {
mbed_official 146:f64d43ff0c18 549 return kStatus_UART_StopBitCountNotSupported;
mbed_official 146:f64d43ff0c18 550 }
mbed_official 146:f64d43ff0c18 551 else
mbed_official 146:f64d43ff0c18 552 {
mbed_official 146:f64d43ff0c18 553 return kStatus_UART_Success;
mbed_official 146:f64d43ff0c18 554 }
mbed_official 146:f64d43ff0c18 555 #endif
mbed_official 146:f64d43ff0c18 556 }
mbed_official 146:f64d43ff0c18 557
mbed_official 146:f64d43ff0c18 558 /*FUNCTION**********************************************************************
mbed_official 146:f64d43ff0c18 559 *
mbed_official 146:f64d43ff0c18 560 * Function Name : uart_hal_configure_tx_rx_inversion
mbed_official 146:f64d43ff0c18 561 * Description : Configure the transmit and receive inversion control in UART controller.
mbed_official 146:f64d43ff0c18 562 * This function allows the user to invert the transmit and receive signals, independently.
mbed_official 146:f64d43ff0c18 563 * This function should only be called when the UART is between transmit and receive packets.
mbed_official 146:f64d43ff0c18 564 *
mbed_official 146:f64d43ff0c18 565 *END**************************************************************************/
mbed_official 146:f64d43ff0c18 566 void uart_hal_configure_tx_rx_inversion(uint32_t uartInstance, uint32_t rxInvert, uint32_t txInvert)
mbed_official 146:f64d43ff0c18 567 {
mbed_official 146:f64d43ff0c18 568 assert(uartInstance < UART_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 569
mbed_official 146:f64d43ff0c18 570 /* configure tx and rx inversions*/
mbed_official 146:f64d43ff0c18 571 #if FSL_FEATURE_UART_HAS_LOW_POWER_UART_SUPPORT
mbed_official 146:f64d43ff0c18 572 if (uartInstance == 0)
mbed_official 146:f64d43ff0c18 573 {
mbed_official 146:f64d43ff0c18 574 /* 0 - receive data not inverted, 1 - receive data inverted */
mbed_official 146:f64d43ff0c18 575 BW_UART0_S2_RXINV(rxInvert);
mbed_official 146:f64d43ff0c18 576 /* 0 - transmit data not inverted, 1 - transmit data inverted*/
mbed_official 146:f64d43ff0c18 577 BW_UART0_C3_TXINV(txInvert);
mbed_official 146:f64d43ff0c18 578 }
mbed_official 146:f64d43ff0c18 579 else
mbed_official 146:f64d43ff0c18 580 #endif
mbed_official 146:f64d43ff0c18 581 {
mbed_official 146:f64d43ff0c18 582 /* 0 - receive data not inverted, 1 - receive data inverted */
mbed_official 146:f64d43ff0c18 583 BW_UART_S2_RXINV(uartInstance, rxInvert);
mbed_official 146:f64d43ff0c18 584 /* 0 - transmit data not inverted, 1 - transmit data inverted*/
mbed_official 146:f64d43ff0c18 585 BW_UART_C3_TXINV(uartInstance, txInvert);
mbed_official 146:f64d43ff0c18 586 }
mbed_official 146:f64d43ff0c18 587 }
mbed_official 146:f64d43ff0c18 588
mbed_official 146:f64d43ff0c18 589
mbed_official 146:f64d43ff0c18 590 /*FUNCTION**********************************************************************
mbed_official 146:f64d43ff0c18 591 *
mbed_official 146:f64d43ff0c18 592 * Function Name : uart_hal_enable_transmitter
mbed_official 146:f64d43ff0c18 593 * Description : Enable the UART transmitter.
mbed_official 146:f64d43ff0c18 594 * This function allows the user to enable the UART transmitter.
mbed_official 146:f64d43ff0c18 595 *
mbed_official 146:f64d43ff0c18 596 *END**************************************************************************/
mbed_official 146:f64d43ff0c18 597 void uart_hal_enable_transmitter(uint32_t uartInstance)
mbed_official 146:f64d43ff0c18 598 {
mbed_official 146:f64d43ff0c18 599 assert(uartInstance < UART_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 600
mbed_official 146:f64d43ff0c18 601 /* enable the transmitter based on the uart instance*/
mbed_official 146:f64d43ff0c18 602 #if FSL_FEATURE_UART_HAS_LOW_POWER_UART_SUPPORT
mbed_official 146:f64d43ff0c18 603 if (uartInstance == 0)
mbed_official 146:f64d43ff0c18 604 {
mbed_official 146:f64d43ff0c18 605 HW_UART0_C2_SET(BM_UART0_C2_TE);
mbed_official 146:f64d43ff0c18 606 }
mbed_official 146:f64d43ff0c18 607 else
mbed_official 146:f64d43ff0c18 608 #endif
mbed_official 146:f64d43ff0c18 609 {
mbed_official 146:f64d43ff0c18 610 /* for this uart instance, there is a two step process to clear the transmit complete
mbed_official 146:f64d43ff0c18 611 * status flag:
mbed_official 146:f64d43ff0c18 612 * 1. Read the status register with the status bit set
mbed_official 146:f64d43ff0c18 613 * 2. enable the transmitter (change TE from 0 to 1)
mbed_official 146:f64d43ff0c18 614 */
mbed_official 146:f64d43ff0c18 615
mbed_official 146:f64d43ff0c18 616 /* first read the status register
mbed_official 146:f64d43ff0c18 617 * no need to store the read value, it's assumed the status bit is set
mbed_official 146:f64d43ff0c18 618 */
mbed_official 146:f64d43ff0c18 619 HW_UART_S1_RD(uartInstance);
mbed_official 146:f64d43ff0c18 620 /* second, enable the transmitter */
mbed_official 146:f64d43ff0c18 621 HW_UART_C2_SET(uartInstance, BM_UART_C2_TE);
mbed_official 146:f64d43ff0c18 622 }
mbed_official 146:f64d43ff0c18 623 }
mbed_official 146:f64d43ff0c18 624
mbed_official 146:f64d43ff0c18 625 /*FUNCTION**********************************************************************
mbed_official 146:f64d43ff0c18 626 *
mbed_official 146:f64d43ff0c18 627 * Function Name : uart_hal_disable_transmitter
mbed_official 146:f64d43ff0c18 628 * Description : Disable the UART transmitter.
mbed_official 146:f64d43ff0c18 629 * This function allows the user to disable the UART transmitter.
mbed_official 146:f64d43ff0c18 630 *
mbed_official 146:f64d43ff0c18 631 *END**************************************************************************/
mbed_official 146:f64d43ff0c18 632 void uart_hal_disable_transmitter(uint32_t uartInstance)
mbed_official 146:f64d43ff0c18 633 {
mbed_official 146:f64d43ff0c18 634 assert(uartInstance < UART_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 635
mbed_official 146:f64d43ff0c18 636 /* disable the transmitter based on the uart instance*/
mbed_official 146:f64d43ff0c18 637 #if FSL_FEATURE_UART_HAS_LOW_POWER_UART_SUPPORT
mbed_official 146:f64d43ff0c18 638 if (uartInstance == 0)
mbed_official 146:f64d43ff0c18 639 {
mbed_official 146:f64d43ff0c18 640 HW_UART0_C2_CLR(BM_UART0_C2_TE);
mbed_official 146:f64d43ff0c18 641 }
mbed_official 146:f64d43ff0c18 642 else
mbed_official 146:f64d43ff0c18 643 #endif
mbed_official 146:f64d43ff0c18 644 {
mbed_official 146:f64d43ff0c18 645 HW_UART_C2_CLR(uartInstance, BM_UART_C2_TE);
mbed_official 146:f64d43ff0c18 646 }
mbed_official 146:f64d43ff0c18 647 }
mbed_official 146:f64d43ff0c18 648
mbed_official 146:f64d43ff0c18 649 /*FUNCTION**********************************************************************
mbed_official 146:f64d43ff0c18 650 *
mbed_official 146:f64d43ff0c18 651 * Function Name : uart_hal_is_transmitter_enabled
mbed_official 146:f64d43ff0c18 652 * Description : Get the UART transmitter enabled/disabled configuration setting.
mbed_official 146:f64d43ff0c18 653 * This function allows the user to get the setting of the UART transmitter.
mbed_official 146:f64d43ff0c18 654 *
mbed_official 146:f64d43ff0c18 655 *END**************************************************************************/
mbed_official 146:f64d43ff0c18 656 bool uart_hal_is_transmitter_enabled(uint32_t uartInstance)
mbed_official 146:f64d43ff0c18 657 {
mbed_official 146:f64d43ff0c18 658 assert(uartInstance < UART_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 659
mbed_official 146:f64d43ff0c18 660 /* get the transmitter config based on the uart instance*/
mbed_official 146:f64d43ff0c18 661 #if FSL_FEATURE_UART_HAS_LOW_POWER_UART_SUPPORT
mbed_official 146:f64d43ff0c18 662 if (uartInstance == 0)
mbed_official 146:f64d43ff0c18 663 {
mbed_official 146:f64d43ff0c18 664 return HW_UART0_C2.B.TE;
mbed_official 146:f64d43ff0c18 665 }
mbed_official 146:f64d43ff0c18 666 else
mbed_official 146:f64d43ff0c18 667 #endif
mbed_official 146:f64d43ff0c18 668 {
mbed_official 146:f64d43ff0c18 669 return HW_UART_C2(uartInstance).B.TE;
mbed_official 146:f64d43ff0c18 670 }
mbed_official 146:f64d43ff0c18 671 }
mbed_official 146:f64d43ff0c18 672
mbed_official 146:f64d43ff0c18 673 /*FUNCTION**********************************************************************
mbed_official 146:f64d43ff0c18 674 *
mbed_official 146:f64d43ff0c18 675 * Function Name : uart_hal_enable_receiver
mbed_official 146:f64d43ff0c18 676 * Description : Enable the UART receiver.
mbed_official 146:f64d43ff0c18 677 * This function allows the user to enable the UART receiver.
mbed_official 146:f64d43ff0c18 678 *
mbed_official 146:f64d43ff0c18 679 *END**************************************************************************/
mbed_official 146:f64d43ff0c18 680 void uart_hal_enable_receiver(uint32_t uartInstance)
mbed_official 146:f64d43ff0c18 681 {
mbed_official 146:f64d43ff0c18 682 assert(uartInstance < UART_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 683
mbed_official 146:f64d43ff0c18 684 /* enable the receiver based on the uart instance*/
mbed_official 146:f64d43ff0c18 685 #if FSL_FEATURE_UART_HAS_LOW_POWER_UART_SUPPORT
mbed_official 146:f64d43ff0c18 686 if (uartInstance == 0)
mbed_official 146:f64d43ff0c18 687 {
mbed_official 146:f64d43ff0c18 688 HW_UART0_C2_SET(BM_UART0_C2_RE);
mbed_official 146:f64d43ff0c18 689 }
mbed_official 146:f64d43ff0c18 690 else
mbed_official 146:f64d43ff0c18 691 #endif
mbed_official 146:f64d43ff0c18 692 {
mbed_official 146:f64d43ff0c18 693 HW_UART_C2_SET(uartInstance, BM_UART_C2_RE);
mbed_official 146:f64d43ff0c18 694 }
mbed_official 146:f64d43ff0c18 695 }
mbed_official 146:f64d43ff0c18 696
mbed_official 146:f64d43ff0c18 697 /*FUNCTION**********************************************************************
mbed_official 146:f64d43ff0c18 698 *
mbed_official 146:f64d43ff0c18 699 * Function Name : uart_hal_disable_receiver
mbed_official 146:f64d43ff0c18 700 * Description : Disable the UART receiver.
mbed_official 146:f64d43ff0c18 701 * This function allows the user to disable the UART receiver.
mbed_official 146:f64d43ff0c18 702 *
mbed_official 146:f64d43ff0c18 703 *END**************************************************************************/
mbed_official 146:f64d43ff0c18 704 void uart_hal_disable_receiver(uint32_t uartInstance)
mbed_official 146:f64d43ff0c18 705 {
mbed_official 146:f64d43ff0c18 706 assert(uartInstance < UART_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 707
mbed_official 146:f64d43ff0c18 708 /* disable the receiver based on the uart instance*/
mbed_official 146:f64d43ff0c18 709 #if FSL_FEATURE_UART_HAS_LOW_POWER_UART_SUPPORT
mbed_official 146:f64d43ff0c18 710 if (uartInstance == 0)
mbed_official 146:f64d43ff0c18 711 {
mbed_official 146:f64d43ff0c18 712 HW_UART0_C2_CLR(BM_UART0_C2_RE);
mbed_official 146:f64d43ff0c18 713 }
mbed_official 146:f64d43ff0c18 714 else
mbed_official 146:f64d43ff0c18 715 #endif
mbed_official 146:f64d43ff0c18 716 {
mbed_official 146:f64d43ff0c18 717 HW_UART_C2_CLR(uartInstance, BM_UART_C2_RE);
mbed_official 146:f64d43ff0c18 718 }
mbed_official 146:f64d43ff0c18 719 }
mbed_official 146:f64d43ff0c18 720
mbed_official 146:f64d43ff0c18 721 /*FUNCTION**********************************************************************
mbed_official 146:f64d43ff0c18 722 *
mbed_official 146:f64d43ff0c18 723 * Function Name : uart_hal_is_receiver_enabled
mbed_official 146:f64d43ff0c18 724 * Description : Get the UART receiver enabled/disabled configuration setting.
mbed_official 146:f64d43ff0c18 725 * This function allows the user to get the setting of the UART receiver.
mbed_official 146:f64d43ff0c18 726 *
mbed_official 146:f64d43ff0c18 727 *END**************************************************************************/
mbed_official 146:f64d43ff0c18 728 bool uart_hal_is_receiver_enabled(uint32_t uartInstance)
mbed_official 146:f64d43ff0c18 729 {
mbed_official 146:f64d43ff0c18 730 assert(uartInstance < UART_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 731
mbed_official 146:f64d43ff0c18 732 /* get the receiver config based on the uart instance*/
mbed_official 146:f64d43ff0c18 733 #if FSL_FEATURE_UART_HAS_LOW_POWER_UART_SUPPORT
mbed_official 146:f64d43ff0c18 734 if (uartInstance == 0)
mbed_official 146:f64d43ff0c18 735 {
mbed_official 146:f64d43ff0c18 736 return HW_UART0_C2.B.RE;
mbed_official 146:f64d43ff0c18 737 }
mbed_official 146:f64d43ff0c18 738 else
mbed_official 146:f64d43ff0c18 739 #endif
mbed_official 146:f64d43ff0c18 740 {
mbed_official 146:f64d43ff0c18 741 return HW_UART_C2(uartInstance).B.RE;
mbed_official 146:f64d43ff0c18 742 }
mbed_official 146:f64d43ff0c18 743 }
mbed_official 146:f64d43ff0c18 744
mbed_official 146:f64d43ff0c18 745 /*******************************************************************************
mbed_official 146:f64d43ff0c18 746 * EOF
mbed_official 146:f64d43ff0c18 747 ******************************************************************************/
mbed_official 146:f64d43ff0c18 748