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: 2020-09-28 09:41:57 -0500 (Mon, 28 Sep 2020) $
39  * $Revision: 55932 $
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 #ifdef __cplusplus
53 extern "C" {
54 #endif
55 
56 /***** Definitions *****/
57 
60 #define UART_ALTERNATE_CLOCK_HZ 7372800
61 
68 typedef enum {
95 
98 typedef enum {
103 } uart_size_t;
104 
107 typedef enum {
111 } uart_stop_t;
112 
115 typedef enum {
119 
122 typedef enum {
126 
127 #if (TARGET != 32660)
128 
130 typedef enum {
133 } uart_clksel_t;
134 #endif
135 
138 typedef struct {
139  uart_parity_t parity;
140  uart_size_t size;
141  uart_stop_t stop;
142  uart_flow_ctrl_t flow;
143  uart_flow_pol_t pol;
144  uint32_t baud;
145 #if (TARGET != 32660)
146  uart_clksel_t clksel;
147 #endif
148 } uart_cfg_t;
149 
152 typedef struct uart_req uart_req_t;
153 struct uart_req {
154  uint8_t *data;
155  int len;
156  int num;
165  void(*callback)(uart_req_t*, int);
166 };
167 
168 
169 /***** Functions Prototypes *****/
170 
171 
180 int UART_Init(mxc_uart_regs_t *uart, const uart_cfg_t *cfg, const sys_cfg_uart_t* sys_cfg);
181 
188 int UART_Shutdown(mxc_uart_regs_t *uart);
189 
200 void UART_Handler(mxc_uart_regs_t *uart);
201 
212 int UART_Read(mxc_uart_regs_t *uart, uint8_t *data, int len, int *num);
213 
224 int UART_Write(mxc_uart_regs_t *uart, const uint8_t *data, int len);
225 
235 int UART_ReadAsync(mxc_uart_regs_t *uart, uart_req_t *req);
236 
247 int UART_WriteAsync(mxc_uart_regs_t *uart, uart_req_t *req);
248 
256 uint8_t UART_ReadByte(mxc_uart_regs_t *uart);
257 
266 void UART_WriteByte(mxc_uart_regs_t *uart, uint8_t data);
267 
275 int UART_Busy(mxc_uart_regs_t *uart);
276 
289 
298 int UART_AbortAsync(uart_req_t *req);
299 
307 unsigned UART_NumWriteAvail(mxc_uart_regs_t *uart);
308 
316 unsigned UART_NumReadAvail(mxc_uart_regs_t *uart);
317 
325 void UART_ClearFlags(mxc_uart_regs_t *uart, uint32_t mask);
326 
334 unsigned UART_GetFlags(mxc_uart_regs_t *uart);
335 
342 void UART_Disable(mxc_uart_regs_t *uart);
343 
350 void UART_Enable(mxc_uart_regs_t *uart);
351 
357 void UART_DrainRX(mxc_uart_regs_t *uart);
358 
364 void UART_DrainTX(mxc_uart_regs_t *uart);
367 #ifdef __cplusplus
368 }
369 #endif
370 
371 #endif /* _UART_H_ */
Non-blocking UART transaction request.
Definition: uart.h:153
Use the device&#39;s alternate UART bit rate clock.
Definition: uart.h:132
Use for mark parity 0.
Definition: uart.h:82
Conventional odd parity.
Definition: uart.h:81
UART configuration type.
Definition: uart.h:138
uart_flow_ctrl_t
Flow control.
Definition: uart.h:115
void UART_Disable(mxc_uart_regs_t *uart)
Disable the UART.
uart_stop_t
Stop bit settings.
Definition: uart.h:107
void UART_Enable(mxc_uart_regs_t *uart)
Enables the UART.
UART Stop 1.5 clock cycle.
Definition: uart.h:109
#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:189
#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:85
uart_flow_pol_t pol
Configure hardware flow control.
Definition: uart.h:143
Data Size 7 Bits.
Definition: uart.h:101
uint32_t baud
Configure hardware flow control.
Definition: uart.h:144
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:140
uart_parity_t
Parity settings type.
Definition: uart.h:68
Use for odd parity 1.
Definition: uart.h:79
#define MXC_S_UART_CTRL_CHAR_SIZE_5
CTRL_CHAR_SIZE_5 Setting.
Definition: uart_regs.h:158
Conventional mark parity.
Definition: uart.h:87
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:100
#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:124
Parity disabled.
Definition: uart.h:69
#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:156
Conventional space parity.
Definition: uart.h:93
Use for space parity 1.
Definition: uart.h:91
Conventional even parity.
Definition: uart.h:75
uart_stop_t stop
Configure character size.
Definition: uart.h:141
Use for odd parity 0.
Definition: uart.h:76
uart_flow_ctrl_t flow
Configure the number of stop bits to use.
Definition: uart.h:142
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:98
Use for even parity 1.
Definition: uart.h:73
uart_clksel_t clksel
Configure baud rate.
Definition: uart.h:146
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:131
RTS/CTS flow is enabled.
Definition: uart.h:117
uart_clksel_t
Clock Source Select.
Definition: uart.h:130
#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:99
Data Size 8 Bits.
Definition: uart.h:102
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:165
UART Stop 1 clock cycle.
Definition: uart.h:108
#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:155
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:70
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:116
RTS/CTS asserted is low.
Definition: uart.h:123
Use for space parity 0.
Definition: uart.h:88
UART Stop 2 clock cycle.
Definition: uart.h:110
uart_flow_pol_t
Flow control Polarity.
Definition: uart.h:122