MAX32665 SDK Documentation  0.2
Software Development Kit Overview and API Documentation
uart.h
1 
7 /* ****************************************************************************
8  * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
9  *
10  * Permission is hereby granted, free of charge, to any person obtaining a
11  * copy of this software and associated documentation files (the "Software"),
12  * to deal in the Software without restriction, including without limitation
13  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14  * and/or sell copies of the Software, and to permit persons to whom the
15  * Software is furnished to do so, subject to the following conditions:
16  *
17  * The above copyright notice and this permission notice shall be included
18  * in all copies or substantial portions of the Software.
19  *
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23  * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
24  * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
25  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26  * OTHER DEALINGS IN THE SOFTWARE.
27  *
28  * Except as contained in this notice, the name of Maxim Integrated
29  * Products, Inc. shall not be used except as stated in the Maxim Integrated
30  * Products, Inc. Branding Policy.
31  *
32  * The mere transfer of this software does not imply any licenses
33  * of trade secrets, proprietary technology, copyrights, patents,
34  * trademarks, maskwork rights, or any other form of intellectual
35  * property whatsoever. Maxim Integrated Products, Inc. retains all
36  * ownership rights.
37  *
38  * $Date: 2019-02-14 09:36:39 -0600 (Thu, 14 Feb 2019) $
39  * $Revision: 41018 $
40  *
41  *************************************************************************** */
42 
43 
44 #ifndef _UART_H_
45 #define _UART_H_
46 
47 /***** Includes *****/
48 #include <stdint.h>
49 #include "uart_regs.h"
50 #include "mxc_sys.h"
51 
52 /***** Definitions *****/
53 
56 #define UART_ALTERNATE_CLOCK_HZ 7372800
57 
64 typedef enum {
91 
94 typedef enum {
99 } uart_size_t;
100 
103 typedef enum {
107 } uart_stop_t;
108 
111 typedef enum {
115 
118 typedef enum {
122 
123 #if (TARGET != 32660)
124 
126 typedef enum {
129 } uart_clksel_t;
130 #endif
131 
134 typedef struct {
135  uart_parity_t parity;
136  uart_size_t size;
137  uart_stop_t stop;
138  uart_flow_ctrl_t flow;
139  uart_flow_pol_t pol;
140  uint32_t baud;
141 #if (TARGET != 32660)
142  uart_clksel_t clksel;
143 #endif
144 } uart_cfg_t;
145 
148 typedef struct uart_req uart_req_t;
149 struct uart_req {
150  uint8_t *data;
151  int len;
152  int num;
161  void(*callback)(uart_req_t*, int);
162 };
163 
164 
165 /***** Functions Prototypes *****/
166 
167 
176 int UART_Init(mxc_uart_regs_t *uart, const uart_cfg_t *cfg, const sys_cfg_uart_t* sys_cfg);
177 
184 int UART_Shutdown(mxc_uart_regs_t *uart);
185 
196 void UART_Handler(mxc_uart_regs_t *uart);
197 
208 int UART_Read(mxc_uart_regs_t *uart, uint8_t *data, int len, int *num);
209 
220 int UART_Write(mxc_uart_regs_t *uart, const uint8_t *data, int len);
221 
231 int UART_ReadAsync(mxc_uart_regs_t *uart, uart_req_t *req);
232 
243 int UART_WriteAsync(mxc_uart_regs_t *uart, uart_req_t *req);
244 
252 uint8_t UART_ReadByte(mxc_uart_regs_t *uart);
253 
262 void UART_WriteByte(mxc_uart_regs_t *uart, uint8_t data);
263 
271 int UART_Busy(mxc_uart_regs_t *uart);
272 
285 
294 int UART_AbortAsync(uart_req_t *req);
295 
303 unsigned UART_NumWriteAvail(mxc_uart_regs_t *uart);
304 
312 unsigned UART_NumReadAvail(mxc_uart_regs_t *uart);
313 
321 void UART_ClearFlags(mxc_uart_regs_t *uart, uint32_t mask);
322 
330 unsigned UART_GetFlags(mxc_uart_regs_t *uart);
331 
338 void UART_Disable(mxc_uart_regs_t *uart);
339 
346 void UART_Enable(mxc_uart_regs_t *uart);
347 
353 void UART_DrainRX(mxc_uart_regs_t *uart);
354 
360 void UART_DrainTX(mxc_uart_regs_t *uart);
363 #endif /* _UART_H_ */
Non-blocking UART transaction request.
Definition: uart.h:149
Use the device&#39;s alternate UART bit rate clock.
Definition: uart.h:128
Use for mark parity 0.
Definition: uart.h:78
Conventional odd parity.
Definition: uart.h:77
UART configuration type.
Definition: uart.h:134
uart_flow_ctrl_t
Flow control.
Definition: uart.h:111
void UART_Disable(mxc_uart_regs_t *uart)
Disable the UART.
uart_stop_t
Stop bit settings.
Definition: uart.h:103
void UART_Enable(mxc_uart_regs_t *uart)
Enables the UART.
UART Stop 1.5 clock cycle.
Definition: uart.h:105
#define MXC_S_UART_CTRL_CHAR_SIZE_6
CTRL_CHAR_SIZE_6 Setting.
Definition: uart_regs.h:160
uint8_t UART_ReadByte(mxc_uart_regs_t *uart)
Read a single byte from the UART.
void UART_DrainTX(mxc_uart_regs_t *uart)
Drains/empties any data in the TX FIFO, discarding any bytes not yet transmitted. ...
#define MXC_S_UART_CTRL_PARITY_EVEN
CTRL_PARITY_EVEN Setting.
Definition: uart_regs.h:135
UART Configuration Object.
Definition: mxc_sys.h:186
#define MXC_S_UART_CTRL_CHAR_SIZE_8
CTRL_CHAR_SIZE_8 Setting.
Definition: uart_regs.h:164
int UART_Write(mxc_uart_regs_t *uart, const uint8_t *data, int len)
Write UART data.
Use for mark parity 1.
Definition: uart.h:81
uart_flow_pol_t pol
Configure hardware flow control.
Definition: uart.h:139
Data Size 7 Bits.
Definition: uart.h:97
uint32_t baud
Configure hardware flow control.
Definition: uart.h:140
void UART_DrainRX(mxc_uart_regs_t *uart)
Drains/empties and data in the RX FIFO, discarding any bytes not yet consumed.
uart_size_t size
Configure parity checking.
Definition: uart.h:136
uart_parity_t
Parity settings type.
Definition: uart.h:64
Use for odd parity 1.
Definition: uart.h:75
#define MXC_S_UART_CTRL_CHAR_SIZE_5
CTRL_CHAR_SIZE_5 Setting.
Definition: uart_regs.h:158
Conventional mark parity.
Definition: uart.h:83
int UART_Read(mxc_uart_regs_t *uart, uint8_t *data, int len, int *num)
Read UART data, blocking until transaction is complete.
#define MXC_F_UART_CTRL_FLOW_CTRL
CTRL_FLOW_CTRL Mask.
Definition: uart_regs.h:170
Data Size 6 Bits.
Definition: uart.h:96
#define MXC_S_UART_CTRL_PARITY_MARK
CTRL_PARITY_MARK Setting.
Definition: uart_regs.h:139
int UART_Init(mxc_uart_regs_t *uart, const uart_cfg_t *cfg, const sys_cfg_uart_t *sys_cfg)
Initialize and enable UART module.
RTS/CTS asserted is high.
Definition: uart.h:120
Parity disabled.
Definition: uart.h:65
#define MXC_F_UART_CTRL_FLOW_POL
CTRL_FLOW_POL Mask.
Definition: uart_regs.h:173
int UART_Busy(mxc_uart_regs_t *uart)
Check to see if the UART is busy.
int num
Length of characters in data to send or receive.
Definition: uart.h:152
Conventional space parity.
Definition: uart.h:89
Use for space parity 1.
Definition: uart.h:87
Conventional even parity.
Definition: uart.h:71
uart_stop_t stop
Configure character size.
Definition: uart.h:137
Use for odd parity 0.
Definition: uart.h:72
uart_flow_ctrl_t flow
Configure the number of stop bits to use.
Definition: uart.h:138
int UART_ReadAsync(mxc_uart_regs_t *uart, uart_req_t *req)
Asynchronously read UART data.
unsigned UART_NumReadAvail(mxc_uart_regs_t *uart)
Returns the number of bytes available to be read from the RX FIFO.
uart_size_t
Message size settings.
Definition: uart.h:94
Use for even parity 1.
Definition: uart.h:69
uart_clksel_t clksel
Configure baud rate.
Definition: uart.h:142
void UART_ClearFlags(mxc_uart_regs_t *uart, uint32_t mask)
Clears the specified interrupt flags.
int UART_WriteAsync(mxc_uart_regs_t *uart, uart_req_t *req)
Asynchronously write/transmit UART data.
Structure type to access the UART Registers.
Definition: uart_regs.h:88
unsigned UART_GetFlags(mxc_uart_regs_t *uart)
Get the UART interrupt flags.
#define MXC_F_UART_CTRL_CLKSEL
CTRL_CLKSEL Mask.
Definition: uart_regs.h:182
#define MXC_S_UART_CTRL_PARITY_SPACE
CTRL_PARITY_SPACE Setting.
Definition: uart_regs.h:141
void UART_WriteByte(mxc_uart_regs_t *uart, uint8_t data)
Write one byte at a time to the UART.
int UART_Shutdown(mxc_uart_regs_t *uart)
Shutdown UART module.
Peripheral clock will be used as the bit rate clock.
Definition: uart.h:127
RTS/CTS flow is enabled.
Definition: uart.h:113
uart_clksel_t
Clock Source Select.
Definition: uart.h:126
#define MXC_S_UART_CTRL_CHAR_SIZE_7
CTRL_CHAR_SIZE_7 Setting.
Definition: uart_regs.h:162
Data Size 5 Bits.
Definition: uart.h:95
Data Size 8 Bits.
Definition: uart.h:98
int UART_AbortAsync(uart_req_t *req)
Abort asynchronous request.
void(* callback)(uart_req_t *, int)
Number of characters actually sent or received.
Definition: uart.h:161
UART Stop 1 clock cycle.
Definition: uart.h:104
#define MXC_F_UART_CTRL_PARITY_EN
CTRL_PARITY_EN Mask.
Definition: uart_regs.h:130
#define MXC_F_UART_CTRL_PARMD
CTRL_PARMD Mask.
Definition: uart_regs.h:144
#define MXC_S_UART_CTRL_PARITY_ODD
CTRL_PARITY_ODD Setting.
Definition: uart_regs.h:137
#define MXC_F_UART_CTRL_STOPBITS
CTRL_STOPBITS Mask.
Definition: uart_regs.h:167
int len
Data buffer for characters.
Definition: uart.h:151
void UART_Handler(mxc_uart_regs_t *uart)
UART interrupt handler.
unsigned UART_NumWriteAvail(mxc_uart_regs_t *uart)
Returns the number of bytes still pending transmission in the UART TX FIFO.
Use for even parity 0.
Definition: uart.h:66
int UART_PrepForSleep(mxc_uart_regs_t *uart)
Prepare the UART for entry into a Low-Power mode (DEEPSLEEP/BACKUP).
RTS/CTS flow is disabled.
Definition: uart.h:112
RTS/CTS asserted is low.
Definition: uart.h:119
Use for space parity 0.
Definition: uart.h:84
UART Stop 2 clock cycle.
Definition: uart.h:106
uart_flow_pol_t
Flow control Polarity.
Definition: uart.h:118