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 Sep 18 14:00:17 2014 +0100
Revision:
324:406fd2029f23
Synchronized with git revision a73f28e6fbca9559fbed2726410eeb4c0534a4a5

Full URL: https://github.com/mbedmicro/mbed/commit/a73f28e6fbca9559fbed2726410eeb4c0534a4a5/

Extended #476, which does not break ethernet for K64F

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 324:406fd2029f23 1 /*
mbed_official 324:406fd2029f23 2 * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
mbed_official 324:406fd2029f23 3 * All rights reserved.
mbed_official 324:406fd2029f23 4 *
mbed_official 324:406fd2029f23 5 * Redistribution and use in source and binary forms, with or without modification,
mbed_official 324:406fd2029f23 6 * are permitted provided that the following conditions are met:
mbed_official 324:406fd2029f23 7 *
mbed_official 324:406fd2029f23 8 * o Redistributions of source code must retain the above copyright notice, this list
mbed_official 324:406fd2029f23 9 * of conditions and the following disclaimer.
mbed_official 324:406fd2029f23 10 *
mbed_official 324:406fd2029f23 11 * o Redistributions in binary form must reproduce the above copyright notice, this
mbed_official 324:406fd2029f23 12 * list of conditions and the following disclaimer in the documentation and/or
mbed_official 324:406fd2029f23 13 * other materials provided with the distribution.
mbed_official 324:406fd2029f23 14 *
mbed_official 324:406fd2029f23 15 * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
mbed_official 324:406fd2029f23 16 * contributors may be used to endorse or promote products derived from this
mbed_official 324:406fd2029f23 17 * software without specific prior written permission.
mbed_official 324:406fd2029f23 18 *
mbed_official 324:406fd2029f23 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
mbed_official 324:406fd2029f23 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
mbed_official 324:406fd2029f23 21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 324:406fd2029f23 22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
mbed_official 324:406fd2029f23 23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
mbed_official 324:406fd2029f23 24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
mbed_official 324:406fd2029f23 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
mbed_official 324:406fd2029f23 26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
mbed_official 324:406fd2029f23 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
mbed_official 324:406fd2029f23 28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 324:406fd2029f23 29 */
mbed_official 324:406fd2029f23 30 #include "fsl_lpuart_hal.h"
mbed_official 324:406fd2029f23 31
mbed_official 324:406fd2029f23 32 #ifndef MBED_NO_LPUART
mbed_official 324:406fd2029f23 33
mbed_official 324:406fd2029f23 34 /*******************************************************************************
mbed_official 324:406fd2029f23 35 * Code
mbed_official 324:406fd2029f23 36 ******************************************************************************/
mbed_official 324:406fd2029f23 37 /*FUNCTION**********************************************************************
mbed_official 324:406fd2029f23 38 *
mbed_official 324:406fd2029f23 39 * Function Name : LPUART_HAL_Init
mbed_official 324:406fd2029f23 40 * Description : Initializes the LPUART controller to known state.
mbed_official 324:406fd2029f23 41 *
mbed_official 324:406fd2029f23 42 *END**************************************************************************/
mbed_official 324:406fd2029f23 43 void LPUART_HAL_Init(uint32_t baseAddr)
mbed_official 324:406fd2029f23 44 {
mbed_official 324:406fd2029f23 45 HW_LPUART_BAUD_WR(baseAddr, 0x0F000004);
mbed_official 324:406fd2029f23 46 HW_LPUART_STAT_WR(baseAddr, 0xC01FC000);
mbed_official 324:406fd2029f23 47 HW_LPUART_CTRL_WR(baseAddr, 0x00000000);
mbed_official 324:406fd2029f23 48 HW_LPUART_MATCH_WR(baseAddr, 0x00000000);
mbed_official 324:406fd2029f23 49 HW_LPUART_MODIR_WR(baseAddr, 0x00000000);
mbed_official 324:406fd2029f23 50 }
mbed_official 324:406fd2029f23 51
mbed_official 324:406fd2029f23 52 /*FUNCTION**********************************************************************
mbed_official 324:406fd2029f23 53 *
mbed_official 324:406fd2029f23 54 * Function Name : LPUART_HAL_SetBaudRate
mbed_official 324:406fd2029f23 55 * Description : Configures the LPUART baud rate.
mbed_official 324:406fd2029f23 56 * In some LPUART instances the user must disable the transmitter/receiver
mbed_official 324:406fd2029f23 57 * before calling this function.
mbed_official 324:406fd2029f23 58 * Generally, this may be applied to all LPUARTs to ensure safe operation.
mbed_official 324:406fd2029f23 59 *
mbed_official 324:406fd2029f23 60 *END**************************************************************************/
mbed_official 324:406fd2029f23 61 lpuart_status_t LPUART_HAL_SetBaudRate(uint32_t baseAddr, uint32_t sourceClockInHz,
mbed_official 324:406fd2029f23 62 uint32_t desiredBaudRate)
mbed_official 324:406fd2029f23 63 {
mbed_official 324:406fd2029f23 64 uint16_t sbr, sbrTemp, i;
mbed_official 324:406fd2029f23 65 uint32_t osr, tempDiff, calculatedBaud, baudDiff;
mbed_official 324:406fd2029f23 66
mbed_official 324:406fd2029f23 67 /* This lpuart instantiation uses a slightly different baud rate calculation */
mbed_official 324:406fd2029f23 68 /* The idea is to use the best OSR (over-sampling rate) possible */
mbed_official 324:406fd2029f23 69 /* Note, osr is typically hard-set to 16 in other lpuart instantiations */
mbed_official 324:406fd2029f23 70 /* First calculate the baud rate using the minimum OSR possible (4) */
mbed_official 324:406fd2029f23 71 osr = 4;
mbed_official 324:406fd2029f23 72 sbr = (sourceClockInHz/(desiredBaudRate * osr));
mbed_official 324:406fd2029f23 73 calculatedBaud = (sourceClockInHz / (osr * sbr));
mbed_official 324:406fd2029f23 74
mbed_official 324:406fd2029f23 75 if (calculatedBaud > desiredBaudRate)
mbed_official 324:406fd2029f23 76 {
mbed_official 324:406fd2029f23 77 baudDiff = calculatedBaud - desiredBaudRate;
mbed_official 324:406fd2029f23 78 }
mbed_official 324:406fd2029f23 79 else
mbed_official 324:406fd2029f23 80 {
mbed_official 324:406fd2029f23 81 baudDiff = desiredBaudRate - calculatedBaud;
mbed_official 324:406fd2029f23 82 }
mbed_official 324:406fd2029f23 83
mbed_official 324:406fd2029f23 84 /* loop to find the best osr value possible, one that generates minimum baudDiff */
mbed_official 324:406fd2029f23 85 /* iterate through the rest of the supported values of osr */
mbed_official 324:406fd2029f23 86 for (i = 5; i <= 32; i++)
mbed_official 324:406fd2029f23 87 {
mbed_official 324:406fd2029f23 88 /* calculate the temporary sbr value */
mbed_official 324:406fd2029f23 89 sbrTemp = (sourceClockInHz/(desiredBaudRate * i));
mbed_official 324:406fd2029f23 90 /* calculate the baud rate based on the temporary osr and sbr values */
mbed_official 324:406fd2029f23 91 calculatedBaud = (sourceClockInHz / (i * sbrTemp));
mbed_official 324:406fd2029f23 92
mbed_official 324:406fd2029f23 93 if (calculatedBaud > desiredBaudRate)
mbed_official 324:406fd2029f23 94 {
mbed_official 324:406fd2029f23 95 tempDiff = calculatedBaud - desiredBaudRate;
mbed_official 324:406fd2029f23 96 }
mbed_official 324:406fd2029f23 97 else
mbed_official 324:406fd2029f23 98 {
mbed_official 324:406fd2029f23 99 tempDiff = desiredBaudRate - calculatedBaud;
mbed_official 324:406fd2029f23 100 }
mbed_official 324:406fd2029f23 101
mbed_official 324:406fd2029f23 102 if (tempDiff <= baudDiff)
mbed_official 324:406fd2029f23 103 {
mbed_official 324:406fd2029f23 104 baudDiff = tempDiff;
mbed_official 324:406fd2029f23 105 osr = i; /* update and store the best osr value calculated */
mbed_official 324:406fd2029f23 106 sbr = sbrTemp; /* update store the best sbr value calculated */
mbed_official 324:406fd2029f23 107 }
mbed_official 324:406fd2029f23 108 }
mbed_official 324:406fd2029f23 109
mbed_official 324:406fd2029f23 110 /* next, check to see if actual baud rate is within 3% of desired baud rate */
mbed_official 324:406fd2029f23 111 /* based on the best calculate osr value */
mbed_official 324:406fd2029f23 112 if (baudDiff < ((desiredBaudRate / 100) * 3))
mbed_official 324:406fd2029f23 113 {
mbed_official 324:406fd2029f23 114 /* Acceptable baud rate */
mbed_official 324:406fd2029f23 115 /* Check if osr is between 4x and 7x oversampling */
mbed_official 324:406fd2029f23 116 /* If so, then "BOTHEDGE" sampling must be turned on */
mbed_official 324:406fd2029f23 117 if ((osr > 3) && (osr < 8))
mbed_official 324:406fd2029f23 118 {
mbed_official 324:406fd2029f23 119 BW_LPUART_BAUD_BOTHEDGE(baseAddr, 1);
mbed_official 324:406fd2029f23 120 }
mbed_official 324:406fd2029f23 121
mbed_official 324:406fd2029f23 122 /* program the osr value (bit value is one less than actual value) */
mbed_official 324:406fd2029f23 123 BW_LPUART_BAUD_OSR(baseAddr, (osr-1));
mbed_official 324:406fd2029f23 124
mbed_official 324:406fd2029f23 125 /* write the sbr value to the BAUD registers */
mbed_official 324:406fd2029f23 126 BW_LPUART_BAUD_SBR(baseAddr, sbr);
mbed_official 324:406fd2029f23 127 }
mbed_official 324:406fd2029f23 128 else
mbed_official 324:406fd2029f23 129 {
mbed_official 324:406fd2029f23 130 /* Unacceptable baud rate difference of more than 3% */
mbed_official 324:406fd2029f23 131 return kStatus_LPUART_BaudRatePercentDiffExceeded;
mbed_official 324:406fd2029f23 132 }
mbed_official 324:406fd2029f23 133
mbed_official 324:406fd2029f23 134 return kStatus_LPUART_Success;
mbed_official 324:406fd2029f23 135 }
mbed_official 324:406fd2029f23 136
mbed_official 324:406fd2029f23 137 /*FUNCTION**********************************************************************
mbed_official 324:406fd2029f23 138 *
mbed_official 324:406fd2029f23 139 * Function Name : LPUART_HAL_SetBitCountPerChar
mbed_official 324:406fd2029f23 140 * Description : Configures the number of bits per character in the LPUART controller.
mbed_official 324:406fd2029f23 141 * In some LPUART instances, the user should disable the transmitter/receiver
mbed_official 324:406fd2029f23 142 * before calling this function.
mbed_official 324:406fd2029f23 143 * Generally, this may be applied to all LPUARTs to ensure safe operation.
mbed_official 324:406fd2029f23 144 *
mbed_official 324:406fd2029f23 145 *END**************************************************************************/
mbed_official 324:406fd2029f23 146 void LPUART_HAL_SetBitCountPerChar(uint32_t baseAddr, lpuart_bit_count_per_char_t bitCountPerChar)
mbed_official 324:406fd2029f23 147 {
mbed_official 324:406fd2029f23 148 if(bitCountPerChar == kLpuart10BitsPerChar)
mbed_official 324:406fd2029f23 149 {
mbed_official 324:406fd2029f23 150 BW_LPUART_BAUD_M10(baseAddr, 1); /* set M10 for 10-bit mode, M bit in C1 is don't care */
mbed_official 324:406fd2029f23 151 }
mbed_official 324:406fd2029f23 152 else
mbed_official 324:406fd2029f23 153 {
mbed_official 324:406fd2029f23 154 BW_LPUART_CTRL_M(baseAddr, bitCountPerChar); /* config 8- (M=0) or 9-bits (M=1) */
mbed_official 324:406fd2029f23 155 BW_LPUART_BAUD_M10(baseAddr, 0); /* clear M10 to make sure not 10-bit mode */
mbed_official 324:406fd2029f23 156 }
mbed_official 324:406fd2029f23 157 }
mbed_official 324:406fd2029f23 158
mbed_official 324:406fd2029f23 159 /*FUNCTION**********************************************************************
mbed_official 324:406fd2029f23 160 *
mbed_official 324:406fd2029f23 161 * Function Name : LPUART_HAL_SetParityMode
mbed_official 324:406fd2029f23 162 * Description : Configures parity mode in the LPUART controller.
mbed_official 324:406fd2029f23 163 * In some LPUART instances, the user should disable the transmitter/receiver
mbed_official 324:406fd2029f23 164 * before calling this function.
mbed_official 324:406fd2029f23 165 * Generally, this may be applied to all LPUARTs to ensure safe operation.
mbed_official 324:406fd2029f23 166 *
mbed_official 324:406fd2029f23 167 *END**************************************************************************/
mbed_official 324:406fd2029f23 168 void LPUART_HAL_SetParityMode(uint32_t baseAddr, lpuart_parity_mode_t parityModeType)
mbed_official 324:406fd2029f23 169 {
mbed_official 324:406fd2029f23 170 /* configure the parity enable/type */
mbed_official 324:406fd2029f23 171
mbed_official 324:406fd2029f23 172 if ((parityModeType) == kLpuartParityDisabled)
mbed_official 324:406fd2029f23 173 {
mbed_official 324:406fd2029f23 174 /* parity disabled, hence parity type is don't care */
mbed_official 324:406fd2029f23 175 BW_LPUART_CTRL_PE(baseAddr, 0);
mbed_official 324:406fd2029f23 176 }
mbed_official 324:406fd2029f23 177 else
mbed_official 324:406fd2029f23 178 {
mbed_official 324:406fd2029f23 179 /* parity enabled */
mbed_official 324:406fd2029f23 180 BW_LPUART_CTRL_PE(baseAddr, 1);
mbed_official 324:406fd2029f23 181 /* parity odd/even depending on parity mode setting */
mbed_official 324:406fd2029f23 182 BW_LPUART_CTRL_PT(baseAddr, (parityModeType) & 0x1);
mbed_official 324:406fd2029f23 183 }
mbed_official 324:406fd2029f23 184
mbed_official 324:406fd2029f23 185 }
mbed_official 324:406fd2029f23 186
mbed_official 324:406fd2029f23 187 /*FUNCTION**********************************************************************
mbed_official 324:406fd2029f23 188 *
mbed_official 324:406fd2029f23 189 * Function Name : LPUART_HAL_SetTxRxInversionCmd
mbed_official 324:406fd2029f23 190 * Description : Configures the transmit and receive inversion control in the LPUART controller.
mbed_official 324:406fd2029f23 191 * This function should only be called when the LPUART is between transmit and receive packets.
mbed_official 324:406fd2029f23 192 *
mbed_official 324:406fd2029f23 193 *END**************************************************************************/
mbed_official 324:406fd2029f23 194 void LPUART_HAL_SetTxRxInversionCmd(uint32_t baseAddr, uint32_t rxInvert, uint32_t txInvert)
mbed_official 324:406fd2029f23 195 {
mbed_official 324:406fd2029f23 196 /* 0 - receive data not inverted, 1 - receive data inverted */
mbed_official 324:406fd2029f23 197 BW_LPUART_STAT_RXINV(baseAddr, rxInvert);
mbed_official 324:406fd2029f23 198 /* 0 - transmit data not inverted, 1 - transmit data inverted */
mbed_official 324:406fd2029f23 199 BW_LPUART_CTRL_TXINV(baseAddr, txInvert);
mbed_official 324:406fd2029f23 200 }
mbed_official 324:406fd2029f23 201
mbed_official 324:406fd2029f23 202 /*FUNCTION**********************************************************************
mbed_official 324:406fd2029f23 203 *
mbed_official 324:406fd2029f23 204 * Function Name : LPUART_HAL_EnableTransmitter
mbed_official 324:406fd2029f23 205 * Description : Enables the LPUART transmitter.
mbed_official 324:406fd2029f23 206 *
mbed_official 324:406fd2029f23 207 *END**************************************************************************/
mbed_official 324:406fd2029f23 208 void LPUART_HAL_EnableTransmitter(uint32_t baseAddr)
mbed_official 324:406fd2029f23 209 {
mbed_official 324:406fd2029f23 210 /* enable the transmitter based on the lpuart baseAddr */
mbed_official 324:406fd2029f23 211
mbed_official 324:406fd2029f23 212 /* for this lpuart baseAddr, there is a two step process to clear the transmit complete */
mbed_official 324:406fd2029f23 213 /* status flag: */
mbed_official 324:406fd2029f23 214 /* 1. Read the status register with the status bit set */
mbed_official 324:406fd2029f23 215 /* 2. enable the transmitter (change TE from 0 to 1) */
mbed_official 324:406fd2029f23 216 /* first read the status register */
mbed_official 324:406fd2029f23 217
mbed_official 324:406fd2029f23 218 /* no need to store the read value, it's assumed the status bit is set */
mbed_official 324:406fd2029f23 219 HW_LPUART_STAT_RD(baseAddr);
mbed_official 324:406fd2029f23 220 /* second, enable the transmitter */
mbed_official 324:406fd2029f23 221 BW_LPUART_CTRL_TE(baseAddr, 1);
mbed_official 324:406fd2029f23 222 }
mbed_official 324:406fd2029f23 223
mbed_official 324:406fd2029f23 224 /*FUNCTION**********************************************************************
mbed_official 324:406fd2029f23 225 *
mbed_official 324:406fd2029f23 226 * Function Name : LPUART_HAL_SetIntMode
mbed_official 324:406fd2029f23 227 * Description : Configures the LPUART module interrupts to enable/disable various interrupt sources.
mbed_official 324:406fd2029f23 228 *
mbed_official 324:406fd2029f23 229 *END**************************************************************************/
mbed_official 324:406fd2029f23 230 void LPUART_HAL_SetIntMode(uint32_t baseAddr, lpuart_interrupt_t interrupt, bool enable)
mbed_official 324:406fd2029f23 231 {
mbed_official 324:406fd2029f23 232 uint32_t reg = (uint32_t)(interrupt) >> LPUART_SHIFT;
mbed_official 324:406fd2029f23 233 uint32_t temp = 1U << (uint32_t)interrupt;
mbed_official 324:406fd2029f23 234
mbed_official 324:406fd2029f23 235 switch ( reg )
mbed_official 324:406fd2029f23 236 {
mbed_official 324:406fd2029f23 237 case LPUART_BAUD_REG_ID:
mbed_official 324:406fd2029f23 238 enable ? HW_LPUART_BAUD_SET(baseAddr, temp) : HW_LPUART_BAUD_CLR(baseAddr, temp);
mbed_official 324:406fd2029f23 239 break;
mbed_official 324:406fd2029f23 240 case LPUART_STAT_REG_ID:
mbed_official 324:406fd2029f23 241 enable ? HW_LPUART_STAT_SET(baseAddr, temp) : HW_LPUART_STAT_CLR(baseAddr, temp);
mbed_official 324:406fd2029f23 242 break;
mbed_official 324:406fd2029f23 243 case LPUART_CTRL_REG_ID:
mbed_official 324:406fd2029f23 244 enable ? HW_LPUART_CTRL_SET(baseAddr, temp) : HW_LPUART_CTRL_CLR(baseAddr, temp);
mbed_official 324:406fd2029f23 245 break;
mbed_official 324:406fd2029f23 246 case LPUART_DATA_REG_ID:
mbed_official 324:406fd2029f23 247 enable ? HW_LPUART_DATA_SET(baseAddr, temp) : HW_LPUART_DATA_CLR(baseAddr, temp);
mbed_official 324:406fd2029f23 248 break;
mbed_official 324:406fd2029f23 249 case LPUART_MATCH_REG_ID:
mbed_official 324:406fd2029f23 250 enable ? HW_LPUART_MATCH_SET(baseAddr, temp) : HW_LPUART_MATCH_CLR(baseAddr, temp);
mbed_official 324:406fd2029f23 251 break;
mbed_official 324:406fd2029f23 252 case LPUART_MODIR_REG_ID:
mbed_official 324:406fd2029f23 253 enable ? HW_LPUART_MODIR_SET(baseAddr, temp) : HW_LPUART_MODIR_CLR(baseAddr, temp);
mbed_official 324:406fd2029f23 254 break;
mbed_official 324:406fd2029f23 255 default :
mbed_official 324:406fd2029f23 256 break;
mbed_official 324:406fd2029f23 257 }
mbed_official 324:406fd2029f23 258 }
mbed_official 324:406fd2029f23 259
mbed_official 324:406fd2029f23 260 /*FUNCTION**********************************************************************
mbed_official 324:406fd2029f23 261 *
mbed_official 324:406fd2029f23 262 * Function Name : LPUART_HAL_GetIntMode
mbed_official 324:406fd2029f23 263 * Description : Returns whether the LPUART module interrupts is enabled/disabled.
mbed_official 324:406fd2029f23 264 *
mbed_official 324:406fd2029f23 265 *END**************************************************************************/
mbed_official 324:406fd2029f23 266 bool LPUART_HAL_GetIntMode(uint32_t baseAddr, lpuart_interrupt_t interrupt)
mbed_official 324:406fd2029f23 267 {
mbed_official 324:406fd2029f23 268 uint32_t reg = (uint32_t)(interrupt) >> LPUART_SHIFT;
mbed_official 324:406fd2029f23 269 bool retVal = false;
mbed_official 324:406fd2029f23 270
mbed_official 324:406fd2029f23 271 switch ( reg )
mbed_official 324:406fd2029f23 272 {
mbed_official 324:406fd2029f23 273 case LPUART_BAUD_REG_ID:
mbed_official 324:406fd2029f23 274 retVal = HW_LPUART_BAUD_RD(baseAddr) >> (uint32_t)(interrupt) & 1U;
mbed_official 324:406fd2029f23 275 break;
mbed_official 324:406fd2029f23 276 case LPUART_STAT_REG_ID:
mbed_official 324:406fd2029f23 277 retVal = HW_LPUART_STAT_RD(baseAddr) >> (uint32_t)(interrupt) & 1U;
mbed_official 324:406fd2029f23 278 break;
mbed_official 324:406fd2029f23 279 case LPUART_CTRL_REG_ID:
mbed_official 324:406fd2029f23 280 retVal = HW_LPUART_CTRL_RD(baseAddr) >> (uint32_t)(interrupt) & 1U;
mbed_official 324:406fd2029f23 281 break;
mbed_official 324:406fd2029f23 282 case LPUART_DATA_REG_ID:
mbed_official 324:406fd2029f23 283 retVal = HW_LPUART_DATA_RD(baseAddr) >> (uint32_t)(interrupt) & 1U;
mbed_official 324:406fd2029f23 284 break;
mbed_official 324:406fd2029f23 285 case LPUART_MATCH_REG_ID:
mbed_official 324:406fd2029f23 286 retVal = HW_LPUART_MATCH_RD(baseAddr) >> (uint32_t)(interrupt) & 1U;
mbed_official 324:406fd2029f23 287 break;
mbed_official 324:406fd2029f23 288 case LPUART_MODIR_REG_ID:
mbed_official 324:406fd2029f23 289 retVal = HW_LPUART_MODIR_RD(baseAddr) >> (uint32_t)(interrupt) & 1U;
mbed_official 324:406fd2029f23 290 break;
mbed_official 324:406fd2029f23 291 default :
mbed_official 324:406fd2029f23 292 break;
mbed_official 324:406fd2029f23 293 }
mbed_official 324:406fd2029f23 294
mbed_official 324:406fd2029f23 295 return retVal;
mbed_official 324:406fd2029f23 296 }
mbed_official 324:406fd2029f23 297
mbed_official 324:406fd2029f23 298 #if FSL_FEATURE_LPUART_HAS_DMA_ENABLE
mbed_official 324:406fd2029f23 299 /*FUNCTION**********************************************************************
mbed_official 324:406fd2029f23 300 *
mbed_official 324:406fd2029f23 301 * Function Name : LPUART_HAL_ConfigureDma
mbed_official 324:406fd2029f23 302 * Description : LPUART configures DMA requests for Transmitter and Receiver.
mbed_official 324:406fd2029f23 303 *
mbed_official 324:406fd2029f23 304 *END**************************************************************************/
mbed_official 324:406fd2029f23 305 void LPUART_HAL_ConfigureDma(uint32_t baseAddr, bool txDmaConfig, bool rxDmaConfig)
mbed_official 324:406fd2029f23 306 {
mbed_official 324:406fd2029f23 307 /* TDMAE configures the transmit data register empty flag, S1[TDRE], */
mbed_official 324:406fd2029f23 308 /* to generate a DMA request. */
mbed_official 324:406fd2029f23 309 BW_LPUART_BAUD_TDMAE(baseAddr, txDmaConfig) ;/* set TDMAE to enable, clear to disable */
mbed_official 324:406fd2029f23 310 /* RDMAE configures the receive data register fell flag, S1[RDRF], */
mbed_official 324:406fd2029f23 311 /* to generate a DMA request. */
mbed_official 324:406fd2029f23 312 BW_LPUART_BAUD_RDMAE(baseAddr, rxDmaConfig); /* set RDMAE to enable, clear to disable */
mbed_official 324:406fd2029f23 313 }
mbed_official 324:406fd2029f23 314 #endif
mbed_official 324:406fd2029f23 315
mbed_official 324:406fd2029f23 316 /*FUNCTION**********************************************************************
mbed_official 324:406fd2029f23 317 *
mbed_official 324:406fd2029f23 318 * Function Name : LPUART_HAL_GetWaitModeOperationConfig
mbed_official 324:406fd2029f23 319 * Description : LPUART configures DMA requests for Transmitter and Receiver.
mbed_official 324:406fd2029f23 320 *
mbed_official 324:406fd2029f23 321 *END**************************************************************************/
mbed_official 324:406fd2029f23 322 lpuart_operation_config_t LPUART_HAL_GetWaitModeOperationConfig(uint32_t baseAddr)
mbed_official 324:406fd2029f23 323 {
mbed_official 324:406fd2029f23 324 /* get configuration lpuart operation in wait mode */
mbed_official 324:406fd2029f23 325 /* In CPU wait mode: 0 - lpuart clocks continue to run; 1 - lpuart clocks freeze */
mbed_official 324:406fd2029f23 326 if (BR_LPUART_CTRL_DOZEEN(baseAddr) == 0)
mbed_official 324:406fd2029f23 327 {
mbed_official 324:406fd2029f23 328 return kLpuartOperates;
mbed_official 324:406fd2029f23 329 }
mbed_official 324:406fd2029f23 330 else
mbed_official 324:406fd2029f23 331 {
mbed_official 324:406fd2029f23 332 return kLpuartStops;
mbed_official 324:406fd2029f23 333 }
mbed_official 324:406fd2029f23 334
mbed_official 324:406fd2029f23 335 }
mbed_official 324:406fd2029f23 336
mbed_official 324:406fd2029f23 337 /*FUNCTION**********************************************************************
mbed_official 324:406fd2029f23 338 *
mbed_official 324:406fd2029f23 339 * Function Name : LPUART_HAL_SedLoopbackCmd
mbed_official 324:406fd2029f23 340 * Description : Configures the LPUART loopback operation (enable/disable loopback operation)
mbed_official 324:406fd2029f23 341 * In some LPUART instances, the user should disable the transmitter/receiver
mbed_official 324:406fd2029f23 342 * before calling this function.
mbed_official 324:406fd2029f23 343 * Generally, this may be applied to all LPUARTs to ensure safe operation.
mbed_official 324:406fd2029f23 344 *
mbed_official 324:406fd2029f23 345 *END**************************************************************************/
mbed_official 324:406fd2029f23 346 void LPUART_HAL_SedLoopbackCmd(uint32_t baseAddr, bool enable)
mbed_official 324:406fd2029f23 347 {
mbed_official 324:406fd2029f23 348 /* configure lpuart to enable/disable operation in loopback mode */
mbed_official 324:406fd2029f23 349
mbed_official 324:406fd2029f23 350 /* configure LOOPS bit to enable(1)/disable(0) loopback mode, but also need to clear RSRC */
mbed_official 324:406fd2029f23 351 BW_LPUART_CTRL_LOOPS(baseAddr, enable);
mbed_official 324:406fd2029f23 352
mbed_official 324:406fd2029f23 353 /* clear RSRC for loopback mode, and if loopback disabled, */
mbed_official 324:406fd2029f23 354 /* this bit has no meaning but clear anyway */
mbed_official 324:406fd2029f23 355 /* to set it back to default value */
mbed_official 324:406fd2029f23 356 BW_LPUART_CTRL_RSRC(baseAddr, 0);
mbed_official 324:406fd2029f23 357
mbed_official 324:406fd2029f23 358 }
mbed_official 324:406fd2029f23 359
mbed_official 324:406fd2029f23 360 /*FUNCTION**********************************************************************
mbed_official 324:406fd2029f23 361 *
mbed_official 324:406fd2029f23 362 * Function Name : LPUART_HAL_SetSingleWireCmd
mbed_official 324:406fd2029f23 363 * Description : Configures the LPUART single-wire operation (enable/disable single-wire mode)
mbed_official 324:406fd2029f23 364 * In some LPUART instances, the user should disable the transmitter/receiver
mbed_official 324:406fd2029f23 365 * before calling this function.
mbed_official 324:406fd2029f23 366 * Generally, this may be applied to all LPUARTs to ensure safe operation.
mbed_official 324:406fd2029f23 367 *
mbed_official 324:406fd2029f23 368 *END**************************************************************************/
mbed_official 324:406fd2029f23 369 void LPUART_HAL_SetSingleWireCmd(uint32_t baseAddr, bool enable)
mbed_official 324:406fd2029f23 370 {
mbed_official 324:406fd2029f23 371 /* configure lpuart to enable/disable operation in single mode */
mbed_official 324:406fd2029f23 372
mbed_official 324:406fd2029f23 373 /* to enable single-wire mode, need both LOOPS and RSRC set, to disable, clear both */
mbed_official 324:406fd2029f23 374 BW_LPUART_CTRL_LOOPS(baseAddr, enable);
mbed_official 324:406fd2029f23 375 BW_LPUART_CTRL_RSRC(baseAddr, enable);
mbed_official 324:406fd2029f23 376 }
mbed_official 324:406fd2029f23 377
mbed_official 324:406fd2029f23 378 /*FUNCTION**********************************************************************
mbed_official 324:406fd2029f23 379 *
mbed_official 324:406fd2029f23 380 * Function Name : LPUART_HAL_PutReceiverInStandbyMode
mbed_official 324:406fd2029f23 381 * Description : Places the LPUART receiver in standby mode.
mbed_official 324:406fd2029f23 382 * In some LPUART instances,
mbed_official 324:406fd2029f23 383 * before placing LPUART in standby mode, first determine whether the receiver is set to
mbed_official 324:406fd2029f23 384 * wake on idle or whether it is already in idle state.
mbed_official 324:406fd2029f23 385 * NOTE that the RWU should only be set with C1[WAKE] = 0 (wakeup on idle) if the channel is currently
mbed_official 324:406fd2029f23 386 * not idle.
mbed_official 324:406fd2029f23 387 * This can be determined by the S2[RAF] flag. If it is set to wake up an IDLE event and the channel is
mbed_official 324:406fd2029f23 388 * already idle, it is possible that the LPUART will discard data since data must be received
mbed_official 324:406fd2029f23 389 * (or a LIN break detect) after an IDLE is detected and before IDLE is allowed to reasserted.
mbed_official 324:406fd2029f23 390 *
mbed_official 324:406fd2029f23 391 *END**************************************************************************/
mbed_official 324:406fd2029f23 392 lpuart_status_t LPUART_HAL_PutReceiverInStandbyMode(uint32_t baseAddr)
mbed_official 324:406fd2029f23 393 {
mbed_official 324:406fd2029f23 394 /* In some lpuart instances, there is a condition that must be met before placing */
mbed_official 324:406fd2029f23 395 /* rx in standby mode. */
mbed_official 324:406fd2029f23 396 /* Before placing lpuart in standby, need to first determine if receiver is set to */
mbed_official 324:406fd2029f23 397 /* wake on idle and if receiver is already in idle state. Per ref manual: */
mbed_official 324:406fd2029f23 398 /* NOTE: RWU should only be set with C1[WAKE] = 0 (wakeup on idle) if the channel is */
mbed_official 324:406fd2029f23 399 /* currently not idle. */
mbed_official 324:406fd2029f23 400 /* This can be determined by the STAT[RAF] flag. If set to wake up an IDLE event and */
mbed_official 324:406fd2029f23 401 /* the channel is already idle, it is possible that the LPUART will discard data since data */
mbed_official 324:406fd2029f23 402 /* must be received (or a LIN break detect) after an IDLE is detected before IDLE is */
mbed_official 324:406fd2029f23 403 /* allowed to reasserted. */
mbed_official 324:406fd2029f23 404 lpuart_wakeup_method_t rxWakeMethod;
mbed_official 324:406fd2029f23 405 bool lpuart_current_rx_state;
mbed_official 324:406fd2029f23 406
mbed_official 324:406fd2029f23 407 /* see if wake is set for idle or */
mbed_official 324:406fd2029f23 408 rxWakeMethod = LPUART_HAL_GetReceiverWakeupMethod(baseAddr);
mbed_official 324:406fd2029f23 409 lpuart_current_rx_state = LPUART_HAL_GetStatusFlag(baseAddr, kLpuartRxActive);
mbed_official 324:406fd2029f23 410
mbed_official 324:406fd2029f23 411 /* if both rxWakeMethod is set for idle and current rx state is idle, don't put in standy */
mbed_official 324:406fd2029f23 412 if ((rxWakeMethod == kLpuartIdleLineWake) && (lpuart_current_rx_state == 0))
mbed_official 324:406fd2029f23 413 {
mbed_official 324:406fd2029f23 414 return kStatus_LPUART_RxStandbyModeError;
mbed_official 324:406fd2029f23 415 }
mbed_official 324:406fd2029f23 416 else
mbed_official 324:406fd2029f23 417 {
mbed_official 324:406fd2029f23 418 /* set the RWU bit to place receiver into standby mode */
mbed_official 324:406fd2029f23 419 BW_LPUART_CTRL_RWU(baseAddr, 1);
mbed_official 324:406fd2029f23 420 return kStatus_LPUART_Success;
mbed_official 324:406fd2029f23 421 }
mbed_official 324:406fd2029f23 422 }
mbed_official 324:406fd2029f23 423
mbed_official 324:406fd2029f23 424 /*FUNCTION**********************************************************************
mbed_official 324:406fd2029f23 425 *
mbed_official 324:406fd2029f23 426 * Function Name : LPUART_HAL_GetReceiverWakeupMethod
mbed_official 324:406fd2029f23 427 * Description : Gets the LPUART receiver wakeup method (idle line or addr-mark) from standby mode.
mbed_official 324:406fd2029f23 428 *
mbed_official 324:406fd2029f23 429 *END**************************************************************************/
mbed_official 324:406fd2029f23 430 lpuart_wakeup_method_t LPUART_HAL_GetReceiverWakeupMethod(uint32_t baseAddr)
mbed_official 324:406fd2029f23 431 {
mbed_official 324:406fd2029f23 432 /* get configuration of the WAKE bit for idle line wake or address mark wake */
mbed_official 324:406fd2029f23 433 if(HW_LPUART_CTRL(baseAddr).B.WAKE == 1)
mbed_official 324:406fd2029f23 434 {
mbed_official 324:406fd2029f23 435 return kLpuartAddrMarkWake;
mbed_official 324:406fd2029f23 436 }
mbed_official 324:406fd2029f23 437 else
mbed_official 324:406fd2029f23 438 {
mbed_official 324:406fd2029f23 439 return kLpuartIdleLineWake;
mbed_official 324:406fd2029f23 440 }
mbed_official 324:406fd2029f23 441 }
mbed_official 324:406fd2029f23 442
mbed_official 324:406fd2029f23 443 /*FUNCTION**********************************************************************
mbed_official 324:406fd2029f23 444 *
mbed_official 324:406fd2029f23 445 * Function Name : LPUART_HAL_ConfigureIdleLineDetect
mbed_official 324:406fd2029f23 446 * Description : LPUART idle-line detect operation configuration (idle line bit-count start and wake
mbed_official 324:406fd2029f23 447 * up affect on IDLE status bit).
mbed_official 324:406fd2029f23 448 * In some LPUART instances, the user should disable the transmitter/receiver
mbed_official 324:406fd2029f23 449 * before calling this function.
mbed_official 324:406fd2029f23 450 * Generally, this may be applied to all LPUARTs to ensure safe operation.
mbed_official 324:406fd2029f23 451 *
mbed_official 324:406fd2029f23 452 *END**************************************************************************/
mbed_official 324:406fd2029f23 453 void LPUART_HAL_ConfigureIdleLineDetect(uint32_t baseAddr,
mbed_official 324:406fd2029f23 454 const lpuart_idle_line_config_t *config)
mbed_official 324:406fd2029f23 455 {
mbed_official 324:406fd2029f23 456 /* Configure the idle line detection configuration as follows: */
mbed_official 324:406fd2029f23 457 /* configure the ILT to bit count after start bit or stop bit */
mbed_official 324:406fd2029f23 458 /* configure RWUID to set or not set IDLE status bit upon detection of */
mbed_official 324:406fd2029f23 459 /* an idle character when recevier in standby */
mbed_official 324:406fd2029f23 460 BW_LPUART_CTRL_ILT(baseAddr, config->idleLineType);
mbed_official 324:406fd2029f23 461 BW_LPUART_STAT_RWUID(baseAddr, config->rxWakeIdleDetect);
mbed_official 324:406fd2029f23 462 }
mbed_official 324:406fd2029f23 463
mbed_official 324:406fd2029f23 464 /*FUNCTION**********************************************************************
mbed_official 324:406fd2029f23 465 *
mbed_official 324:406fd2029f23 466 * Function Name : LPUART_HAL_SetMatchAddressOperation
mbed_official 324:406fd2029f23 467 * Description : LPUART configures match address mode control (Note: Feature available on
mbed_official 324:406fd2029f23 468 * select LPUART instances)
mbed_official 324:406fd2029f23 469 *
mbed_official 324:406fd2029f23 470 *END**************************************************************************/
mbed_official 324:406fd2029f23 471 lpuart_status_t LPUART_HAL_SetMatchAddressOperation( uint32_t baseAddr,
mbed_official 324:406fd2029f23 472 bool matchAddrMode1, bool matchAddrMode2,
mbed_official 324:406fd2029f23 473 uint8_t matchAddrValue1, uint8_t matchAddrValue2, lpuart_match_config_t config)
mbed_official 324:406fd2029f23 474 {
mbed_official 324:406fd2029f23 475 BW_LPUART_BAUD_MAEN1(baseAddr, matchAddrMode1); /* Match Address Mode Enable 1 */
mbed_official 324:406fd2029f23 476 BW_LPUART_BAUD_MAEN2(baseAddr, matchAddrMode2); /* Match Address Mode Enable 2 */
mbed_official 324:406fd2029f23 477 BW_LPUART_MATCH_MA1(baseAddr, matchAddrValue1); /* match address register 1 */
mbed_official 324:406fd2029f23 478 BW_LPUART_MATCH_MA2(baseAddr, matchAddrValue2); /* match address register 2 */
mbed_official 324:406fd2029f23 479 BW_LPUART_BAUD_MATCFG(baseAddr, config); /* Match Configuration */
mbed_official 324:406fd2029f23 480
mbed_official 324:406fd2029f23 481 return kStatus_LPUART_Success;
mbed_official 324:406fd2029f23 482 }
mbed_official 324:406fd2029f23 483
mbed_official 324:406fd2029f23 484 #if FSL_FEATURE_LPUART_HAS_IR_SUPPORT
mbed_official 324:406fd2029f23 485 /*FUNCTION**********************************************************************
mbed_official 324:406fd2029f23 486 *
mbed_official 324:406fd2029f23 487 * Function Name : LPUART_HAL_SetInfraredOperation
mbed_official 324:406fd2029f23 488 * Description : Configures the LPUART infrared operation.
mbed_official 324:406fd2029f23 489 *
mbed_official 324:406fd2029f23 490 *END**************************************************************************/
mbed_official 324:406fd2029f23 491 void LPUART_HAL_SetInfraredOperation(uint32_t baseAddr, bool enable,
mbed_official 324:406fd2029f23 492 lpuart_ir_tx_pulsewidth_t pulseWidth)
mbed_official 324:406fd2029f23 493 {
mbed_official 324:406fd2029f23 494 /* enable or disable infrared */
mbed_official 324:406fd2029f23 495 BW_LPUART_MODIR_IREN(baseAddr, enable);
mbed_official 324:406fd2029f23 496
mbed_official 324:406fd2029f23 497 /* configure the narrow pulse width of the IR pulse */
mbed_official 324:406fd2029f23 498 BW_LPUART_MODIR_TNP(baseAddr, pulseWidth);
mbed_official 324:406fd2029f23 499 }
mbed_official 324:406fd2029f23 500 #endif /* FSL_FEATURE_LPUART_HAS_IR_SUPPORT */
mbed_official 324:406fd2029f23 501
mbed_official 324:406fd2029f23 502 /*FUNCTION**********************************************************************
mbed_official 324:406fd2029f23 503 *
mbed_official 324:406fd2029f23 504 * Function Name : LPUART_HAL_GetStatusFlag
mbed_official 324:406fd2029f23 505 * Description : LPUART get status flag by passing flag enum.
mbed_official 324:406fd2029f23 506 *
mbed_official 324:406fd2029f23 507 *END**************************************************************************/
mbed_official 324:406fd2029f23 508 bool LPUART_HAL_GetStatusFlag(uint32_t baseAddr, lpuart_status_flag_t statusFlag)
mbed_official 324:406fd2029f23 509 {
mbed_official 324:406fd2029f23 510 uint32_t reg = (uint32_t)(statusFlag) >> LPUART_SHIFT;
mbed_official 324:406fd2029f23 511 bool retVal = false;
mbed_official 324:406fd2029f23 512
mbed_official 324:406fd2029f23 513 switch ( reg )
mbed_official 324:406fd2029f23 514 {
mbed_official 324:406fd2029f23 515 case LPUART_BAUD_REG_ID:
mbed_official 324:406fd2029f23 516 retVal = HW_LPUART_BAUD_RD(baseAddr) >> (uint32_t)(statusFlag) & 1U;
mbed_official 324:406fd2029f23 517 break;
mbed_official 324:406fd2029f23 518 case LPUART_STAT_REG_ID:
mbed_official 324:406fd2029f23 519 retVal = HW_LPUART_STAT_RD(baseAddr) >> (uint32_t)(statusFlag) & 1U;
mbed_official 324:406fd2029f23 520 break;
mbed_official 324:406fd2029f23 521 case LPUART_CTRL_REG_ID:
mbed_official 324:406fd2029f23 522 retVal = HW_LPUART_CTRL_RD(baseAddr) >> (uint32_t)(statusFlag) & 1U;
mbed_official 324:406fd2029f23 523 break;
mbed_official 324:406fd2029f23 524 case LPUART_DATA_REG_ID:
mbed_official 324:406fd2029f23 525 retVal = HW_LPUART_DATA_RD(baseAddr) >> (uint32_t)(statusFlag) & 1U;
mbed_official 324:406fd2029f23 526 break;
mbed_official 324:406fd2029f23 527 case LPUART_MATCH_REG_ID:
mbed_official 324:406fd2029f23 528 retVal = HW_LPUART_MATCH_RD(baseAddr) >> (uint32_t)(statusFlag) & 1U;
mbed_official 324:406fd2029f23 529 break;
mbed_official 324:406fd2029f23 530 case LPUART_MODIR_REG_ID:
mbed_official 324:406fd2029f23 531 retVal = HW_LPUART_MODIR_RD(baseAddr) >> (uint32_t)(statusFlag) & 1U;
mbed_official 324:406fd2029f23 532 break;
mbed_official 324:406fd2029f23 533 default:
mbed_official 324:406fd2029f23 534 break;
mbed_official 324:406fd2029f23 535 }
mbed_official 324:406fd2029f23 536
mbed_official 324:406fd2029f23 537 return retVal;
mbed_official 324:406fd2029f23 538 }
mbed_official 324:406fd2029f23 539
mbed_official 324:406fd2029f23 540 /*FUNCTION**********************************************************************
mbed_official 324:406fd2029f23 541 *
mbed_official 324:406fd2029f23 542 * Function Name : LPUART_HAL_ClearStatusFlag
mbed_official 324:406fd2029f23 543 * Description : LPUART clears an individual status flag
mbed_official 324:406fd2029f23 544 * (see lpuart_status_flag_t for list of status bits).
mbed_official 324:406fd2029f23 545 *
mbed_official 324:406fd2029f23 546 *END**************************************************************************/
mbed_official 324:406fd2029f23 547 lpuart_status_t LPUART_HAL_ClearStatusFlag(uint32_t baseAddr, lpuart_status_flag_t statusFlag)
mbed_official 324:406fd2029f23 548 {
mbed_official 324:406fd2029f23 549 lpuart_status_t returnCode = kStatus_LPUART_Success;
mbed_official 324:406fd2029f23 550
mbed_official 324:406fd2029f23 551 /* clear the desired, individual status flag as passed in through statusFlag */
mbed_official 324:406fd2029f23 552 switch(statusFlag)
mbed_official 324:406fd2029f23 553 {
mbed_official 324:406fd2029f23 554 case kLpuartTxDataRegEmpty:
mbed_official 324:406fd2029f23 555 /* This flag is cleared automatically by other lpuart operations */
mbed_official 324:406fd2029f23 556 /* and cannot be manually cleared, return error code */
mbed_official 324:406fd2029f23 557 returnCode = kStatus_LPUART_ClearStatusFlagError;
mbed_official 324:406fd2029f23 558 break;
mbed_official 324:406fd2029f23 559
mbed_official 324:406fd2029f23 560 case kLpuartTxComplete:
mbed_official 324:406fd2029f23 561 /* This flag is cleared automatically by other lpuart operations */
mbed_official 324:406fd2029f23 562 /* and cannot be manually cleared, return error code */
mbed_official 324:406fd2029f23 563 returnCode = kStatus_LPUART_ClearStatusFlagError;
mbed_official 324:406fd2029f23 564 break;
mbed_official 324:406fd2029f23 565
mbed_official 324:406fd2029f23 566 case kLpuartRxDataRegFull:
mbed_official 324:406fd2029f23 567 /* This flag is cleared automatically by other lpuart operations and */
mbed_official 324:406fd2029f23 568 /* cannot be manually cleared, return error code */
mbed_official 324:406fd2029f23 569 returnCode = kStatus_LPUART_ClearStatusFlagError;
mbed_official 324:406fd2029f23 570 break;
mbed_official 324:406fd2029f23 571
mbed_official 324:406fd2029f23 572 case kLpuartIdleLineDetect:
mbed_official 324:406fd2029f23 573 /* write one to clear status flag */
mbed_official 324:406fd2029f23 574 BW_LPUART_STAT_IDLE(baseAddr, 1);
mbed_official 324:406fd2029f23 575 break;
mbed_official 324:406fd2029f23 576
mbed_official 324:406fd2029f23 577 case kLpuartRxOverrun:
mbed_official 324:406fd2029f23 578 /* write one to clear status flag */
mbed_official 324:406fd2029f23 579 BW_LPUART_STAT_OR(baseAddr, 1);
mbed_official 324:406fd2029f23 580 break;
mbed_official 324:406fd2029f23 581
mbed_official 324:406fd2029f23 582 case kLpuartNoiseDetect:
mbed_official 324:406fd2029f23 583 /* write one to clear status flag */
mbed_official 324:406fd2029f23 584 BW_LPUART_STAT_NF(baseAddr, 1);
mbed_official 324:406fd2029f23 585 break;
mbed_official 324:406fd2029f23 586
mbed_official 324:406fd2029f23 587 case kLpuartFrameErr:
mbed_official 324:406fd2029f23 588 /* write one to clear status flag */
mbed_official 324:406fd2029f23 589 BW_LPUART_STAT_FE(baseAddr, 1);
mbed_official 324:406fd2029f23 590 break;
mbed_official 324:406fd2029f23 591
mbed_official 324:406fd2029f23 592 case kLpuartParityErr:
mbed_official 324:406fd2029f23 593 /* write one to clear status flag */
mbed_official 324:406fd2029f23 594 BW_LPUART_STAT_PF(baseAddr, 1);
mbed_official 324:406fd2029f23 595 break;
mbed_official 324:406fd2029f23 596
mbed_official 324:406fd2029f23 597 case kLpuartLineBreakDetect:
mbed_official 324:406fd2029f23 598 /* write one to clear status flag */
mbed_official 324:406fd2029f23 599 BW_LPUART_STAT_LBKDIF(baseAddr, 1);
mbed_official 324:406fd2029f23 600 break;
mbed_official 324:406fd2029f23 601
mbed_official 324:406fd2029f23 602 case kLpuartRxActiveEdgeDetect:
mbed_official 324:406fd2029f23 603 /* write one to clear status flag */
mbed_official 324:406fd2029f23 604 BW_LPUART_STAT_RXEDGIF(baseAddr, (1U));
mbed_official 324:406fd2029f23 605 break;
mbed_official 324:406fd2029f23 606
mbed_official 324:406fd2029f23 607 case kLpuartRxActive:
mbed_official 324:406fd2029f23 608 /* This flag is cleared automatically by other lpuart operations and */
mbed_official 324:406fd2029f23 609 /* cannot be manually cleared, return error code */
mbed_official 324:406fd2029f23 610 returnCode = kStatus_LPUART_ClearStatusFlagError;
mbed_official 324:406fd2029f23 611 break;
mbed_official 324:406fd2029f23 612
mbed_official 324:406fd2029f23 613 #if FSL_FEATURE_LPUART_HAS_EXTENDED_DATA_REGISTER_FLAGS
mbed_official 324:406fd2029f23 614 case kLpuartNoiseInCurrentWord:
mbed_official 324:406fd2029f23 615 /* This flag is not clearable, it simply reflects the status in the */
mbed_official 324:406fd2029f23 616 /* current data word and changes with each new data word */
mbed_official 324:406fd2029f23 617 returnCode = kStatus_LPUART_ClearStatusFlagError;
mbed_official 324:406fd2029f23 618 break;
mbed_official 324:406fd2029f23 619
mbed_official 324:406fd2029f23 620 case kLpuartParityErrInCurrentWord:
mbed_official 324:406fd2029f23 621 /* This flag is not clearable, it simply reflects the status in the */
mbed_official 324:406fd2029f23 622 /* current data word and changes with each new data word */
mbed_official 324:406fd2029f23 623 returnCode = kStatus_LPUART_ClearStatusFlagError;
mbed_official 324:406fd2029f23 624 break;
mbed_official 324:406fd2029f23 625 #endif
mbed_official 324:406fd2029f23 626
mbed_official 324:406fd2029f23 627 #if FSL_FEATURE_LPUART_HAS_ADDRESS_MATCHING
mbed_official 324:406fd2029f23 628 case kLpuartMatchAddrOne:
mbed_official 324:406fd2029f23 629 /* write one to clear status flag */
mbed_official 324:406fd2029f23 630 BW_LPUART_STAT_MA1F(baseAddr, 1);
mbed_official 324:406fd2029f23 631 break;
mbed_official 324:406fd2029f23 632 case kLpuartMatchAddrTwo:
mbed_official 324:406fd2029f23 633 /* write one to clear status flag */
mbed_official 324:406fd2029f23 634 BW_LPUART_STAT_MA2F(baseAddr, 1);
mbed_official 324:406fd2029f23 635 break;
mbed_official 324:406fd2029f23 636 #endif
mbed_official 324:406fd2029f23 637
mbed_official 324:406fd2029f23 638 default: /* catch inputs that are not recognized */
mbed_official 324:406fd2029f23 639 returnCode = kStatus_LPUART_ClearStatusFlagError;
mbed_official 324:406fd2029f23 640 break;
mbed_official 324:406fd2029f23 641 }
mbed_official 324:406fd2029f23 642
mbed_official 324:406fd2029f23 643 return (returnCode);
mbed_official 324:406fd2029f23 644 }
mbed_official 324:406fd2029f23 645
mbed_official 324:406fd2029f23 646 /*FUNCTION**********************************************************************
mbed_official 324:406fd2029f23 647 *
mbed_official 324:406fd2029f23 648 * Function Name : LPUART_HAL_ClearAllNonAutoclearStatusFlags
mbed_official 324:406fd2029f23 649 * Description : LPUART clears ALL status flags.
mbed_official 324:406fd2029f23 650 *
mbed_official 324:406fd2029f23 651 *END**************************************************************************/
mbed_official 324:406fd2029f23 652 void LPUART_HAL_ClearAllNonAutoclearStatusFlags(uint32_t baseAddr)
mbed_official 324:406fd2029f23 653 {
mbed_official 324:406fd2029f23 654 /* clear the status flags that can be manually cleared */
mbed_official 324:406fd2029f23 655 /* note, some flags are automatically cleared and cannot be cleared automatically */
mbed_official 324:406fd2029f23 656 LPUART_HAL_ClearStatusFlag(baseAddr, kLpuartIdleLineDetect);
mbed_official 324:406fd2029f23 657 LPUART_HAL_ClearStatusFlag(baseAddr, kLpuartRxOverrun);
mbed_official 324:406fd2029f23 658 LPUART_HAL_ClearStatusFlag(baseAddr, kLpuartNoiseDetect);
mbed_official 324:406fd2029f23 659 LPUART_HAL_ClearStatusFlag(baseAddr, kLpuartFrameErr);
mbed_official 324:406fd2029f23 660 LPUART_HAL_ClearStatusFlag(baseAddr, kLpuartParityErr);
mbed_official 324:406fd2029f23 661 LPUART_HAL_ClearStatusFlag(baseAddr, kLpuartLineBreakDetect);
mbed_official 324:406fd2029f23 662 LPUART_HAL_ClearStatusFlag(baseAddr, kLpuartRxActiveEdgeDetect);
mbed_official 324:406fd2029f23 663 }
mbed_official 324:406fd2029f23 664
mbed_official 324:406fd2029f23 665 /*FUNCTION**********************************************************************
mbed_official 324:406fd2029f23 666 *
mbed_official 324:406fd2029f23 667 * Function Name : LPUART_HAL_Putchar9
mbed_official 324:406fd2029f23 668 * Description : Sends the LPUART 9-bit character.
mbed_official 324:406fd2029f23 669 *
mbed_official 324:406fd2029f23 670 *END**************************************************************************/
mbed_official 324:406fd2029f23 671 void LPUART_HAL_Putchar9(uint32_t baseAddr, uint16_t data)
mbed_official 324:406fd2029f23 672 {
mbed_official 324:406fd2029f23 673 uint8_t ninthDataBit;
mbed_official 324:406fd2029f23 674
mbed_official 324:406fd2029f23 675 ninthDataBit = (data >> 8U) & 0x1U; /* isolate the ninth data bit */
mbed_official 324:406fd2029f23 676
mbed_official 324:406fd2029f23 677 /* put 9-bit data to transmit */
mbed_official 324:406fd2029f23 678
mbed_official 324:406fd2029f23 679 /* first, write to the ninth data bit (bit position T8, where T[0:7]=8-bits, T8=9th bit) */
mbed_official 324:406fd2029f23 680 BW_LPUART_CTRL_R9T8(baseAddr, ninthDataBit);
mbed_official 324:406fd2029f23 681
mbed_official 324:406fd2029f23 682 /* write to the data register last since this will trigger transmit complete status flag */
mbed_official 324:406fd2029f23 683 /* also typecast to uint8_t to match register type */
mbed_official 324:406fd2029f23 684 HW_LPUART_DATA_WR(baseAddr, (uint8_t)data);
mbed_official 324:406fd2029f23 685 }
mbed_official 324:406fd2029f23 686
mbed_official 324:406fd2029f23 687 /*FUNCTION**********************************************************************
mbed_official 324:406fd2029f23 688 *
mbed_official 324:406fd2029f23 689 * Function Name : LPUART_HAL_Putchar10
mbed_official 324:406fd2029f23 690 * Description : Sends the LPUART 10-bit character.
mbed_official 324:406fd2029f23 691 *
mbed_official 324:406fd2029f23 692 *END**************************************************************************/
mbed_official 324:406fd2029f23 693 lpuart_status_t LPUART_HAL_Putchar10(uint32_t baseAddr, uint16_t data)
mbed_official 324:406fd2029f23 694 {
mbed_official 324:406fd2029f23 695 uint8_t ninthDataBit;
mbed_official 324:406fd2029f23 696 uint8_t tenthDataBit;
mbed_official 324:406fd2029f23 697
mbed_official 324:406fd2029f23 698 /* put 10-bit data to transmit */
mbed_official 324:406fd2029f23 699 ninthDataBit = (data >> 8U) & 0x1U; /* isolate the ninth data bit */
mbed_official 324:406fd2029f23 700 tenthDataBit = (data >> 9U) & 0x1U; /* isolate the tenth data bit */
mbed_official 324:406fd2029f23 701
mbed_official 324:406fd2029f23 702 /* first, write to the tenth data bit (bit position T9, where T[0:7]=8-bits, */
mbed_official 324:406fd2029f23 703 /* T9=10th bit, T8=9th bit) */
mbed_official 324:406fd2029f23 704 BW_LPUART_CTRL_R8T9(baseAddr, tenthDataBit);
mbed_official 324:406fd2029f23 705
mbed_official 324:406fd2029f23 706 /* next, write to the ninth data bit (bit position T8, where T[0:7]=8-bits, */
mbed_official 324:406fd2029f23 707 /* T9=10th bit, T8=9th bit) */
mbed_official 324:406fd2029f23 708 BW_LPUART_CTRL_R9T8(baseAddr, ninthDataBit);
mbed_official 324:406fd2029f23 709
mbed_official 324:406fd2029f23 710 /* write to the data register last since this will trigger transmit complete status flag */
mbed_official 324:406fd2029f23 711 /* also typecast to uint8_t to match register type */
mbed_official 324:406fd2029f23 712 HW_LPUART_DATA_WR(baseAddr, (uint8_t)data);
mbed_official 324:406fd2029f23 713
mbed_official 324:406fd2029f23 714 return kStatus_LPUART_Success;
mbed_official 324:406fd2029f23 715 }
mbed_official 324:406fd2029f23 716
mbed_official 324:406fd2029f23 717 /*FUNCTION**********************************************************************
mbed_official 324:406fd2029f23 718 *
mbed_official 324:406fd2029f23 719 * Function Name : LPUART_HAL_Getchar
mbed_official 324:406fd2029f23 720 * Description : Gets the LPUART 8-bit character.
mbed_official 324:406fd2029f23 721 *
mbed_official 324:406fd2029f23 722 *END**************************************************************************/
mbed_official 324:406fd2029f23 723 void LPUART_HAL_Getchar(uint32_t baseAddr, uint8_t *readData)
mbed_official 324:406fd2029f23 724 {
mbed_official 324:406fd2029f23 725 /* get 8-bit data from the lpuart data register */
mbed_official 324:406fd2029f23 726 *readData = (uint8_t)HW_LPUART_DATA_RD(baseAddr); /* read 8-bit data from data register */
mbed_official 324:406fd2029f23 727 }
mbed_official 324:406fd2029f23 728
mbed_official 324:406fd2029f23 729 /*FUNCTION**********************************************************************
mbed_official 324:406fd2029f23 730 *
mbed_official 324:406fd2029f23 731 * Function Name : LPUART_HAL_Getchar9
mbed_official 324:406fd2029f23 732 * Description : Gets the LPUART 9-bit character.
mbed_official 324:406fd2029f23 733 *
mbed_official 324:406fd2029f23 734 *END**************************************************************************/
mbed_official 324:406fd2029f23 735 void LPUART_HAL_Getchar9(uint32_t baseAddr, uint16_t *readData)
mbed_official 324:406fd2029f23 736 {
mbed_official 324:406fd2029f23 737 uint16_t temp;
mbed_official 324:406fd2029f23 738
mbed_official 324:406fd2029f23 739 /* get 9-bit data from the lpuart data register */
mbed_official 324:406fd2029f23 740 /* read ninth data bit and left shift to bit position R8 before reading */
mbed_official 324:406fd2029f23 741 /* the 8 other data bits R[7:0] */
mbed_official 324:406fd2029f23 742 temp = HW_LPUART_CTRL(baseAddr).B.R8T9; /* need this two step process to work around mishra rule */
mbed_official 324:406fd2029f23 743 *readData = temp << 8;
mbed_official 324:406fd2029f23 744
mbed_official 324:406fd2029f23 745 /* do last: get 8-bit data from the lpuart data register, will clear certain */
mbed_official 324:406fd2029f23 746 /* receive status bits once completed */
mbed_official 324:406fd2029f23 747 /* need to OR these 8-bits with the ninth bit value above */
mbed_official 324:406fd2029f23 748 *readData |= (uint8_t)HW_LPUART_DATA_RD(baseAddr); /* read 8-bit data from data register */
mbed_official 324:406fd2029f23 749 }
mbed_official 324:406fd2029f23 750
mbed_official 324:406fd2029f23 751 /*FUNCTION**********************************************************************
mbed_official 324:406fd2029f23 752 *
mbed_official 324:406fd2029f23 753 * Function Name : LPUART_HAL_Getchar10
mbed_official 324:406fd2029f23 754 * Description : Gets the LPUART 10-bit character.
mbed_official 324:406fd2029f23 755 *
mbed_official 324:406fd2029f23 756 *END**************************************************************************/
mbed_official 324:406fd2029f23 757 lpuart_status_t LPUART_HAL_Getchar10(uint32_t baseAddr, uint16_t *readData)
mbed_official 324:406fd2029f23 758 {
mbed_official 324:406fd2029f23 759 /* get 10-bit data from the lpuart data register, available only on supported lpuarts */
mbed_official 324:406fd2029f23 760
mbed_official 324:406fd2029f23 761 /* read tenth data bit and left shift to bit position R9 before reading the 9 other */
mbed_official 324:406fd2029f23 762 /* data bits: R8 and R[7:0] */
mbed_official 324:406fd2029f23 763 *readData = (uint16_t)((uint32_t)(HW_LPUART_CTRL(baseAddr).B.R9T8) << 9U);
mbed_official 324:406fd2029f23 764
mbed_official 324:406fd2029f23 765 /* read ninth data bit and left shift to bit position R8 before reading the 8 other */
mbed_official 324:406fd2029f23 766 /* data bits R[7:0] */
mbed_official 324:406fd2029f23 767 *readData |= (uint16_t)((uint32_t)(HW_LPUART_CTRL(baseAddr).B.R8T9) << 8U);
mbed_official 324:406fd2029f23 768
mbed_official 324:406fd2029f23 769 /* do last: get 8-bit data from the lpuart data register, will clear certain receive */
mbed_official 324:406fd2029f23 770 /* status bits once completed */
mbed_official 324:406fd2029f23 771 /* need to OR these 8-bits with the ninth bit value above */
mbed_official 324:406fd2029f23 772 *readData |= HW_LPUART_DATA_RD(baseAddr); /* read 8-bit data from data register */
mbed_official 324:406fd2029f23 773
mbed_official 324:406fd2029f23 774 return kStatus_LPUART_Success;
mbed_official 324:406fd2029f23 775 }
mbed_official 324:406fd2029f23 776
mbed_official 324:406fd2029f23 777 #endif /* MBED_NO_LPUART */
mbed_official 324:406fd2029f23 778
mbed_official 324:406fd2029f23 779 /*******************************************************************************
mbed_official 324:406fd2029f23 780 * EOF
mbed_official 324:406fd2029f23 781 ******************************************************************************/
mbed_official 324:406fd2029f23 782