ISF  2.1
Intelligent Sensing Framework for Kinetis with Processor Expert
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
fsl_uart_hal.h
Go to the documentation of this file.
1 /*!
2 ********************************************************************************
3 * File: fsl_uart_hal.h
4 *
5 * Copyright (c) 2014, Freescale Semiconductor, Inc.
6 *
7 *******************************************************************************/
8 /*!
9 * @file fsl_uart_hal.h
10 * @brief \b fsl_uart_hal.h defines structures and types for the i2c master HAL layer.
11 */
12 #ifndef FSL_UART_HAL_H_
13 #define FSL_UART_HAL_H_
14 #include "isf_types.h"
15 #include <stdbool.h>
16 /*******************************************************************************
17  * Definitions
18  ******************************************************************************/
19 
20 /*! @brief Error codes for the UART driver. */
21 typedef enum _uart_status
22 {
24  kStatus_UART_BaudRateCalculationError,/*!< UART Baud Rate calculation error out of range. */
25  kStatus_UART_BaudRatePercentDiffExceeded, /*!< UART Baud Rate exceeds percentage difference */
26  kStatus_UART_BitCountNotSupported, /*!< UART bit count config not supported. */
27  kStatus_UART_StopBitCountNotSupported, /*!< UART stop bit count config not supported. */
28  kStatus_UART_RxStandbyModeError, /*!< UART unable to place receiver in standby mode. */
29  kStatus_UART_ClearStatusFlagError, /*!< UART clear status flag error. */
30  kStatus_UART_MSBFirstNotSupported, /*!< UART MSB first feature not supported. */
31  kStatus_UART_ResyncNotSupported, /*!< UART resync disable operation not supported. */
32  kStatus_UART_TxNotDisabled, /*!< UART Transmitter not disabled before enabling feature */
33  kStatus_UART_RxNotDisabled, /*!< UART Receiver not disabled before enabling feature */
34  kStatus_UART_TxOrRxNotDisabled, /*!< UART Transmitter or Receiver not disabled */
35  kStatus_UART_TxBusy, /*!< UART transmit still in progress. */
36  kStatus_UART_RxBusy, /*!< UART receive still in progress. */
37  kStatus_UART_NoTransmitInProgress, /*!< UART no transmit in progress. */
38  kStatus_UART_NoReceiveInProgress, /*!< UART no receive in progress. */
39  kStatus_UART_InvalidInstanceNumber, /*!< Invalid UART instance number. */
40  kStatus_UART_InvalidBitSetting, /*!< Invalid setting for desired UART register bit field. */
41  kStatus_UART_OverSamplingNotSupported, /*!< UART oversampling not supported. */
42  kStatus_UART_BothEdgeNotSupported, /*!< UART both edge sampling not supported. */
43  kStatus_UART_Timeout, /*!< UART transfer timed out.*/
44  kStatus_UART_Error, /*!< UART error.*/
46 /*!
47  * @brief UART number of stop bits.
48  *
49  * These constants define the number of allowable stop bits to configure in a UART instance.
50  */
51 typedef enum _uart_stop_bit_count {
52  kUartOneStopBit = 0, /*!< one stop bit. */
53  kUartTwoStopBit = 1, /*!< two stop bits. */
55 
56 /*!
57  * @brief UART parity mode.
58  *
59  * These constants define the UART parity mode options: disabled or enabled of type even or odd.
60  */
61 typedef enum _uart_parity_mode {
62  kUartParityDisabled = 0x0, /*!< parity disabled */
63  kUartParityEven = 0x2, /*!< parity enabled, type even, bit setting: PE|PT = 10 */
64  kUartParityOdd = 0x3, /*!< parity enabled, type odd, bit setting: PE|PT = 11 */
66 
67 /*!
68  * @brief UART number of bits in a character.
69  *
70  * These constants define the number of allowable data bits per UART character. Note, check the
71  * UART documentation to determine if the desired UART instance supports the desired number
72  * of data bits per UART character.
73  */
75  kUart8BitsPerChar = 0, /*!< 8-bit data characters */
76  kUart9BitsPerChar = 1, /*!< 9-bit data characters */
77  kUart10BitsPerChar = 2, /*!< 10-bit data characters */
79 
80 /*!
81  * @brief UART operation configuration constants.
82  *
83  * This provides constants for UART operational states: "operates normally"
84  * or "stops/siezes to operation"
85  */
86 typedef enum _uart_operation_config {
87  kUartOperates = 0, /*!< UART continues to operate normally */
88  kUartStops = 1, /*!< UART siezes operation */
90 
91 /*!
92  * @brief UART wakeup from standby method constants.
93  *
94  * This provides constants for the two UART wakeup methods: idle-line or address-mark.
95  */
96 typedef enum _uart_wakeup_method {
97  kUartIdleLineWake = 0, /*!< The idle-line wakes UART receiver from standby */
98  kUartAddrMarkWake = 1, /*!< The addr-mark wakes UART receiver from standby */
100 
101 /*!
102  * @brief UART idle line detect selection types.
103  *
104  * This provides constants for the UART idle character bit-count start: either after start or
105  * stop bit.
106  */
108  kUartIdleLineAfterStartBit = 0, /*!< UART idle character bit count start after start bit */
109  kUartIdleLineAfterStopBit = 1, /*!< UART idle character bit count start after stop bit */
111 
112 /*!
113  * @brief UART break character length settings for transmit/detect.
114  *
115  * This provides constants for the UART break character length for both transmission and detection
116  * purposes. Note that the actual maximum bit times may vary depending on the UART instance.
117  */
119  kUartBreakChar10BitMinimum = 0, /*!< UART break char length 10 bit times (if M = 0, SBNS = 0) or
120  11 (if M = 1, SBNS = 0 or M = 0, SBNS = 1) or 12 (if M = 1,
121  SBNS = 1 or M10 = 1, SNBS = 0) or 13 (if M10 = 1, SNBS = 1) */
122  kUartBreakChar13BitMinimum = 1, /*!< UART break char length 13 bit times (if M = 0, SBNS = 0) or
123  14 (if M = 1, SBNS = 0 or M = 0, SBNS = 1) or 15 (if M = 1,
124  SBNS = 1 or M10 = 1, SNBS = 0) or 16 (if M10 = 1, SNBS = 1) */
126 
127 
128 /*!
129  * @brief UART configuration structure.
130  *
131  * This structure contains the settings for the most common UART configurations including
132  * the UART module source clock, baud rate, parity mode, stop bit count, data bit count per
133  * character, and tx/rx inversion options (which is the least common of the configuration).
134  */
135 typedef struct UartConfig {
136  uint32 uartSourceClockInHz; /*!< UART module source clock in Hz */
137  uint32 baudRate; /*!< UART baud rate */
138  uart_parity_mode_t parityMode; /*!< Parity mode, disabled (default), even, or odd */
139  uart_stop_bit_count_t stopBitCount; /*!< Number of stop bits, 1 stop bit (default)
140  or 2 stop bits */
141  uart_bit_count_per_char_t bitCountPerChar; /*!< Number of bits, 8-bit (default) or 9-bit
142  in a word (up to 10-bits in
143  some UART instances) */
144  unsigned rxDataInvert : 1; /*!< Receive Data Inversion: 0 - not inverted (default),
145  1 - inverted */
146  unsigned txDataInvert : 1; /*!< Transmit Data Inversion: 0 - not inverted (default),
147  1 - inverted */
148 } uart_config_t;
149 /*!
150  * @brief Initialize the UART controller.
151  *
152  * This function will initialize the module to user defined settings and default settings.
153  * Here is an example demonstrating how to define the uart_config_t structure and call
154  * the uart_hal_init function:
155  @code
156  uart_config_t uartConfig;
157  uartConfig.uartSourceClockInHz = uartSourceClock;
158  uartConfig.baudRate = baudRate;
159  uartConfig.bitCountPerChar = kUart8BitsPerChar;
160  uartConfig.parityMode = kUartParityDisabled;
161  uartConfig.stopBitCount = kUartOneStopBit;
162  uartConfig.txDataInvert = 0;
163  uartConfig.rxDataInvert = 0;
164  uart_hal_init(uartInstance, &uartConfig);
165  @endcode
166  *
167  * @param uartInstance UART module instance number.
168  * @param config UART configuration data.
169  * @return An error code or kStatus_UART_Success.
170  */
171 uart_status_t uart_hal_init(uint32 uartInstance, const uart_config_t *config);
172 
173 /*!
174  * @brief Enable the UART transmitter.
175  *
176  * This function allows the user to enable the UART transmitter.
177  *
178  * @param uartInstance UART module instance number.
179  */
180 void uart_hal_enable_transmitter(uint32 uartInstance);
181 
182 /*!
183  * @brief Disable the UART transmitter.
184  *
185  * This function allows the user to disable the UART transmitter.
186  *
187  * @param uartInstance UART module instance number.
188  */
189 void uart_hal_disable_transmitter(uint32 uartInstance);
190 
191 
192 /*!
193  * @brief Enable the UART receiver.
194  *
195  * This function allows the user to enable the UART receiver.
196  *
197  * @param uartInstance UART module instance number.
198  */
199 void uart_hal_enable_receiver(uint32 uartInstance);
200 
201 /*!
202  * @brief Disable the UART receiver.
203  *
204  * This function allows the user to disable the UART receiver.
205  *
206  * @param uartInstance UART module instance number.
207  */
208 void uart_hal_disable_receiver(uint32 uartInstance);
209 
210 
211 #endif /* FSL_I2C_HAL_H_ */
212 
_uart_stop_bit_count
UART number of stop bits.
Definition: fsl_uart_hal.h:51
uint32 uartSourceClockInHz
Definition: fsl_uart_hal.h:136
void uart_hal_disable_transmitter(uint32 uartInstance)
Disable the UART transmitter.
_uart_parity_mode
UART parity mode.
Definition: fsl_uart_hal.h:61
enum _uart_stop_bit_count uart_stop_bit_count_t
UART number of stop bits.
_uart_operation_config
UART operation configuration constants.
Definition: fsl_uart_hal.h:86
void uart_hal_disable_receiver(uint32 uartInstance)
Disable the UART receiver.
enum _uart_parity_mode uart_parity_mode_t
UART parity mode.
_uart_bit_count_per_char
UART number of bits in a character.
Definition: fsl_uart_hal.h:74
UART configuration structure.
Definition: fsl_uart_hal.h:135
uart_stop_bit_count_t stopBitCount
Definition: fsl_uart_hal.h:139
unsigned long uint32
This defines uint32 as unsigned long.
Definition: isf_types.h:36
enum _uart_wakeup_method uart_wakeup_method_t
UART wakeup from standby method constants.
The isf_types.h file contains the ISF data type definitions and some of the globally used macros...
uart_parity_mode_t parityMode
Definition: fsl_uart_hal.h:138
uint32 baudRate
Definition: fsl_uart_hal.h:137
_uart_wakeup_method
UART wakeup from standby method constants.
Definition: fsl_uart_hal.h:96
enum _uart_bit_count_per_char uart_bit_count_per_char_t
UART number of bits in a character.
uart_bit_count_per_char_t bitCountPerChar
Definition: fsl_uart_hal.h:141
enum _uart_status uart_status_t
Error codes for the UART driver.
enum _uart_break_char_length uart_break_char_length_t
UART break character length settings for transmit/detect.
unsigned rxDataInvert
Definition: fsl_uart_hal.h:144
void uart_hal_enable_transmitter(uint32 uartInstance)
Enable the UART transmitter.
_uart_idle_line_select
UART idle line detect selection types.
Definition: fsl_uart_hal.h:107
_uart_break_char_length
UART break character length settings for transmit/detect.
Definition: fsl_uart_hal.h:118
enum _uart_idle_line_select uart_idle_line_select_t
UART idle line detect selection types.
unsigned txDataInvert
Definition: fsl_uart_hal.h:146
_uart_status
Error codes for the UART driver.
Definition: fsl_uart_hal.h:21
uart_status_t uart_hal_init(uint32 uartInstance, const uart_config_t *config)
Initialize the UART controller.
enum _uart_operation_config uart_operation_config_t
UART operation configuration constants.
struct UartConfig uart_config_t
UART configuration structure.
void uart_hal_enable_receiver(uint32 uartInstance)
Enable the UART receiver.