MAX32665 Peripheral Driver API
Peripheral Driver API for the MAX32665
uart.h
1 
6 /* ****************************************************************************
7  * Copyright (C) 2018 Maxim Integrated Products, Inc., All Rights Reserved.
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining a
10  * copy of this software and associated documentation files (the "Software"),
11  * to deal in the Software without restriction, including without limitation
12  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13  * and/or sell copies of the Software, and to permit persons to whom the
14  * Software is furnished to do so, subject to the following conditions:
15  *
16  * The above copyright notice and this permission notice shall be included
17  * in all copies or substantial portions of the Software.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22  * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
23  * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25  * OTHER DEALINGS IN THE SOFTWARE.
26  *
27  * Except as contained in this notice, the name of Maxim Integrated
28  * Products, Inc. shall not be used except as stated in the Maxim Integrated
29  * Products, Inc. Branding Policy.
30  *
31  * The mere transfer of this software does not imply any licenses
32  * of trade secrets, proprietary technology, copyrights, patents,
33  * trademarks, maskwork rights, or any other form of intellectual
34  * property whatsoever. Maxim Integrated Products, Inc. retains all
35  * ownership rights.
36  *
37  * $Date$
38  * $Revision$
39  *
40  *************************************************************************** */
41 
42 /* Define to prevent redundant inclusion */
43 #ifndef _MXC_UART_H_
44 #define _MXC_UART_H_
45 
46 /***** Definitions *****/
47 #include "uart_regs.h"
48 #include "mxc_sys.h"
49 #include "mxc_pins.h"
50 
51 #define IBRO_FREQ HIRC8_FREQ
52 
53 #ifdef __cplusplus
54 extern "C" {
55 #endif
56 
63 typedef struct _mxc_uart_req_t mxc_uart_req_t;
68 typedef enum {
72 
77 typedef enum {
92 
97 typedef enum {
102 
109 typedef void (*mxc_uart_complete_cb_t) (mxc_uart_req_t* req, int result);
110 
118 typedef void (*mxc_uart_dma_complete_cb_t) (mxc_uart_req_t* req, int num, int result);
119 
128  uint8_t *txData;
129  uint8_t *rxData;
133  uint32_t txLen;
137  uint32_t rxLen;
138  uint32_t txCnt;
139  uint32_t rxCnt;
140 
142 };
143 
144 /***** Function Prototypes *****/
145 
146 /* ************************************************************************* */
147 /* Control/Configuration functions */
148 /* ************************************************************************* */
149 
171 int MXC_UART_Init (mxc_uart_regs_t* uart, unsigned int baud, sys_map_t map);
172 
181 
195 
207 int MXC_UART_SetFrequency (mxc_uart_regs_t* uart, unsigned int baud);
208 
219 
228 int MXC_UART_SetDataSize (mxc_uart_regs_t* uart, int dataSize);
229 
239 
249 
260 int MXC_UART_SetFlowCtrl (mxc_uart_regs_t* uart, mxc_uart_flow_t flowCtrl, int rtsThreshold,sys_map_t map);
261 
274 int MXC_UART_SetClockSource (mxc_uart_regs_t* uart, int usePCLK);
275 
285 int MXC_UART_SetNullModem (mxc_uart_regs_t* uart, int nullModem);
286 
287 /* ************************************************************************* */
288 /* Low-level functions */
289 /* ************************************************************************* */
290 
299 
310 
319 
329 
339 int MXC_UART_WriteCharacter (mxc_uart_regs_t* uart, uint8_t character);
340 
350 
360 int MXC_UART_WriteCharacterRaw (mxc_uart_regs_t* uart, uint8_t character);
361 
373 int MXC_UART_Read (mxc_uart_regs_t* uart, uint8_t* buffer, int* len);
374 
384 int MXC_UART_Write (mxc_uart_regs_t* uart, uint8_t* byte, int* len);
385 
395 unsigned int MXC_UART_ReadRXFIFO (mxc_uart_regs_t* uart, unsigned char* bytes,
396  unsigned int len);
397 
408 int MXC_UART_ReadRXFIFODMA (mxc_uart_regs_t* uart, unsigned char* bytes,
409  unsigned int len, mxc_uart_dma_complete_cb_t callback);
410 
419 
429 unsigned int MXC_UART_WriteTXFIFO (mxc_uart_regs_t* uart, unsigned char* bytes,
430  unsigned int len);
431 
442 int MXC_UART_WriteTXFIFODMA (mxc_uart_regs_t* uart, unsigned char* bytes,
443  unsigned int len, mxc_uart_dma_complete_cb_t callback);
444 
453 
460 
467 
485 int MXC_UART_SetRXThreshold (mxc_uart_regs_t* uart, unsigned int numBytes);
486 
495 
513 int MXC_UART_SetTXThreshold (mxc_uart_regs_t* uart, unsigned int numBytes);
514 
523 
534 unsigned int MXC_UART_GetFlags (mxc_uart_regs_t* uart);
535 
546 void MXC_UART_ClearFlags (mxc_uart_regs_t* uart, unsigned int flags);
547 
557 void MXC_UART_EnableInt (mxc_uart_regs_t* uart, unsigned int intEn);
558 
568 void MXC_UART_DisableInt (mxc_uart_regs_t* uart, unsigned int intDis);
569 
577 unsigned int MXC_UART_GetStatus (mxc_uart_regs_t* uart);
578 
579 /* ************************************************************************* */
580 /* Transaction level functions */
581 /* ************************************************************************* */
582 
595 int MXC_UART_Transaction (mxc_uart_req_t* req);
596 
607 int MXC_UART_TransactionAsync (mxc_uart_req_t* req);
608 
623 int MXC_UART_TransactionDMA (mxc_uart_req_t* req);
624 
625 
632 void MXC_UART_AsyncCallback (mxc_uart_regs_t* uart, int retVal);
633 
634 
641 
652 
663 
666 #ifdef __cplusplus
667 }
668 #endif
669 
670 #endif /* _MXC_UART_H_ */
MXC_UART_AbortTransmission
int MXC_UART_AbortTransmission(mxc_uart_regs_t *uart)
Aborts an ongoing UART Transmission.
_mxc_uart_req_t::txCnt
uint32_t txCnt
Number of bytes actually transmitted from txData.
Definition: uart.h:138
mxc_uart_stop_t
mxc_uart_stop_t
The list of UART stop bit lengths supported.
Definition: uart.h:68
MXC_UART_PARITY_ODD
@ MXC_UART_PARITY_ODD
UART Parity Odd.
Definition: uart.h:80
MXC_UART_ReadyForSleep
int MXC_UART_ReadyForSleep(mxc_uart_regs_t *uart)
Checks if the given UART bus can be placed in sleep more.
MXC_UART_GetActive
int MXC_UART_GetActive(mxc_uart_regs_t *uart)
Checks the UART Peripheral for an ongoing transmission.
MXC_UART_SetDataSize
int MXC_UART_SetDataSize(mxc_uart_regs_t *uart, int dataSize)
Sets the number of bits per character.
MXC_UART_PARITY_MARK_1
@ MXC_UART_PARITY_MARK_1
UART Parity Mark, 1 based.
Definition: uart.h:88
MXC_UART_WriteTXFIFODMA
int MXC_UART_WriteTXFIFODMA(mxc_uart_regs_t *uart, unsigned char *bytes, unsigned int len, mxc_uart_dma_complete_cb_t callback)
Loads bytes into the transmit FIFO using DMA for longer writes.
_mxc_uart_req_t::txData
uint8_t * txData
Definition: uart.h:128
MXC_UART_WriteCharacter
int MXC_UART_WriteCharacter(mxc_uart_regs_t *uart, uint8_t character)
Writes a character on the UART. This function will block until the character has been placed in the T...
_mxc_uart_req_t::rxCnt
uint32_t rxCnt
Number of bytes stored in rxData.
Definition: uart.h:139
MXC_UART_SetRXThreshold
int MXC_UART_SetRXThreshold(mxc_uart_regs_t *uart, unsigned int numBytes)
Set the receive threshold level.
MXC_UART_SetClockSource
int MXC_UART_SetClockSource(mxc_uart_regs_t *uart, int usePCLK)
Sets the clock source for the baud rate generator.
MXC_UART_ReadRXFIFODMA
int MXC_UART_ReadRXFIFODMA(mxc_uart_regs_t *uart, unsigned char *bytes, unsigned int len, mxc_uart_dma_complete_cb_t callback)
Unloads bytes from the receive FIFO user DMA for longer reads.
MXC_UART_Init
int MXC_UART_Init(mxc_uart_regs_t *uart, unsigned int baud, sys_map_t map)
Initialize and enable UART peripheral.
MXC_UART_ReadRXFIFO
unsigned int MXC_UART_ReadRXFIFO(mxc_uart_regs_t *uart, unsigned char *bytes, unsigned int len)
Unloads bytes from the receive FIFO.
MXC_UART_PARITY_EVEN_1
@ MXC_UART_PARITY_EVEN_1
UART Parity Even, 1 based.
Definition: uart.h:84
MXC_UART_AsyncCallback
void MXC_UART_AsyncCallback(mxc_uart_regs_t *uart, int retVal)
Async callback.
MXC_UART_AsyncStop
void MXC_UART_AsyncStop(mxc_uart_regs_t *uart)
stop any async callbacks
_mxc_uart_req_t
The information required to perform a complete UART transaction.
Definition: uart.h:126
MXC_UART_DisableInt
void MXC_UART_DisableInt(mxc_uart_regs_t *uart, unsigned int intDis)
Disables specific interrupts.
MXC_UART_PARITY_SPACE_1
@ MXC_UART_PARITY_SPACE_1
UART Parity Space, 1 based.
Definition: uart.h:90
_mxc_uart_req_t::rxData
uint8_t * rxData
Definition: uart.h:132
MXC_UART_GetRXThreshold
unsigned int MXC_UART_GetRXThreshold(mxc_uart_regs_t *uart)
Get the current receive threshold level.
MXC_UART_PARITY_MARK
@ MXC_UART_PARITY_MARK
UART Parity Mark.
Definition: uart.h:81
_mxc_uart_req_t::txLen
uint32_t txLen
Number of bytes to be sent from txData.
Definition: uart.h:136
MXC_UART_GetStatus
unsigned int MXC_UART_GetStatus(mxc_uart_regs_t *uart)
Gets the status flags that are currently set.
MXC_UART_SetFrequency
int MXC_UART_SetFrequency(mxc_uart_regs_t *uart, unsigned int baud)
Set the frequency of the UART interface.
MXC_UART_STOP_1
@ MXC_UART_STOP_1
UART Stop 1 clock cycle.
Definition: uart.h:69
mxc_uart_flow_t
mxc_uart_flow_t
The list of UART flow control options supported.
Definition: uart.h:97
MXC_UART_STOP_2
@ MXC_UART_STOP_2
UART Stop 2 clock cycle (1.5 clocks for 5 bit characters)
Definition: uart.h:70
MXC_UART_SetStopBits
int MXC_UART_SetStopBits(mxc_uart_regs_t *uart, mxc_uart_stop_t stopBits)
Sets the number of stop bits sent at the end of a character.
mxc_uart_regs_t
Definition: uart_regs.h:88
MXC_UART_WriteTXFIFO
unsigned int MXC_UART_WriteTXFIFO(mxc_uart_regs_t *uart, unsigned char *bytes, unsigned int len)
Loads bytes into the transmit FIFO.
MXC_UART_ClearFlags
void MXC_UART_ClearFlags(mxc_uart_regs_t *uart, unsigned int flags)
Clears the interrupt flags that are currently set.
MXC_UART_SendBreak
int MXC_UART_SendBreak(mxc_uart_regs_t *uart)
Transmits a Break Frame (all bits 0)
MXC_UART_TransactionDMA
int MXC_UART_TransactionDMA(mxc_uart_req_t *req)
Setup a DMA driven UART transaction.
MXC_UART_ClearRXFIFO
void MXC_UART_ClearRXFIFO(mxc_uart_regs_t *uart)
Removes and discards all bytes currently in the receive FIFO.
_mxc_uart_req_t::callback
mxc_uart_complete_cb_t callback
Pointer to function called when transaction is complete.
Definition: uart.h:141
MXC_UART_GetTXThreshold
unsigned int MXC_UART_GetTXThreshold(mxc_uart_regs_t *uart)
Get the current transmit threshold level.
MXC_UART_AsyncHandler
void MXC_UART_AsyncHandler(mxc_uart_regs_t *uart)
The processing function for asynchronous transactions.
_mxc_uart_req_t::uart
mxc_uart_regs_t * uart
Point to UART registers.
Definition: uart.h:127
MXC_UART_Write
int MXC_UART_Write(mxc_uart_regs_t *uart, uint8_t *byte, int *len)
Writes a byte on the UART.
MXC_UART_SetTXThreshold
int MXC_UART_SetTXThreshold(mxc_uart_regs_t *uart, unsigned int numBytes)
Set the transmit threshold level.
MXC_UART_FLOW_EN_LOW
@ MXC_UART_FLOW_EN_LOW
UART Flow Control Enabled, Active Low.
Definition: uart.h:99
MXC_UART_FLOW_DIS
@ MXC_UART_FLOW_DIS
UART Flow Control Disabled.
Definition: uart.h:98
MXC_UART_GetTXFIFOAvailable
unsigned int MXC_UART_GetTXFIFOAvailable(mxc_uart_regs_t *uart)
Get the amount of free space available in the transmit FIFO.
mxc_uart_parity_t
mxc_uart_parity_t
The list of UART Parity options supported.
Definition: uart.h:77
MXC_UART_PARITY_EVEN_0
@ MXC_UART_PARITY_EVEN_0
UART Parity Even, 0 based.
Definition: uart.h:83
MXC_UART_PARITY_DISABLE
@ MXC_UART_PARITY_DISABLE
UART Parity Disabled.
Definition: uart.h:78
MXC_UART_SetParity
int MXC_UART_SetParity(mxc_uart_regs_t *uart, mxc_uart_parity_t parity)
Sets the type of parity generation used.
MXC_UART_ReadCharacter
int MXC_UART_ReadCharacter(mxc_uart_regs_t *uart)
Reads the next available character. This function will block until a character is available or a UART...
MXC_UART_SetFlowCtrl
int MXC_UART_SetFlowCtrl(mxc_uart_regs_t *uart, mxc_uart_flow_t flowCtrl, int rtsThreshold, sys_map_t map)
Sets the flow control used.
MXC_UART_AbortAsync
void MXC_UART_AbortAsync(mxc_uart_regs_t *uart)
Abort any asynchronous requests in progress.
MXC_UART_GetFrequency
int MXC_UART_GetFrequency(mxc_uart_regs_t *uart)
Get the frequency of the UART interface.
MXC_UART_TransactionAsync
int MXC_UART_TransactionAsync(mxc_uart_req_t *req)
Setup an interrupt-driven UART transaction.
MXC_UART_WriteCharacterRaw
int MXC_UART_WriteCharacterRaw(mxc_uart_regs_t *uart, uint8_t character)
Writes a character on the UART. If the character cannot be written because the transmit FIFO is curre...
MXC_UART_SetNullModem
int MXC_UART_SetNullModem(mxc_uart_regs_t *uart, int nullModem)
Enables or Disables the built-in null modem.
MXC_UART_PARITY_SPACE_0
@ MXC_UART_PARITY_SPACE_0
UART Parity Space, 0 based.
Definition: uart.h:89
MXC_UART_PARITY_MARK_0
@ MXC_UART_PARITY_MARK_0
UART Parity Mark, 0 based.
Definition: uart.h:87
MXC_UART_PARITY_SPACE
@ MXC_UART_PARITY_SPACE
UART Parity Space.
Definition: uart.h:82
MXC_UART_Shutdown
int MXC_UART_Shutdown(mxc_uart_regs_t *uart)
Disable and shutdown UART peripheral.
MXC_UART_Transaction
int MXC_UART_Transaction(mxc_uart_req_t *req)
Performs a blocking UART transaction.
MXC_UART_ReadCharacterRaw
int MXC_UART_ReadCharacterRaw(mxc_uart_regs_t *uart)
Reads the next available character. If no character is available, this function will return an error.
_mxc_uart_req_t::rxLen
uint32_t rxLen
Number of bytes to be stored in rxData.
Definition: uart.h:137
MXC_UART_EnableInt
void MXC_UART_EnableInt(mxc_uart_regs_t *uart, unsigned int intEn)
Enables specific interrupts.
MXC_UART_GetRXFIFOAvailable
unsigned int MXC_UART_GetRXFIFOAvailable(mxc_uart_regs_t *uart)
Get the number of bytes currently available in the receive FIFO.
MXC_UART_PARITY_EVEN
@ MXC_UART_PARITY_EVEN
UART Parity Even.
Definition: uart.h:79
MXC_UART_ClearTXFIFO
void MXC_UART_ClearTXFIFO(mxc_uart_regs_t *uart)
Removes and discards all bytes currently in the transmit FIFO.
mxc_uart_dma_complete_cb_t
void(* mxc_uart_dma_complete_cb_t)(mxc_uart_req_t *req, int num, int result)
The callback routine used to indicate the transaction has terminated.
Definition: uart.h:118
MXC_UART_FLOW_EN_HIGH
@ MXC_UART_FLOW_EN_HIGH
UART Flow Control Enabled, Active High.
Definition: uart.h:100
MXC_UART_PARITY_ODD_1
@ MXC_UART_PARITY_ODD_1
UART Parity Odd, 1 based.
Definition: uart.h:86
MXC_UART_GetFlags
unsigned int MXC_UART_GetFlags(mxc_uart_regs_t *uart)
Gets the interrupt flags that are currently set.
mxc_uart_complete_cb_t
void(* mxc_uart_complete_cb_t)(mxc_uart_req_t *req, int result)
The callback routine used to indicate the transaction has terminated.
Definition: uart.h:109
MXC_UART_PARITY_ODD_0
@ MXC_UART_PARITY_ODD_0
UART Parity Odd, 0 based.
Definition: uart.h:85
MXC_UART_Read
int MXC_UART_Read(mxc_uart_regs_t *uart, uint8_t *buffer, int *len)
Reads the next available character.