MAX32655 Peripheral Driver API
Peripheral Driver API for the MAX32655
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  *************************************************************************** */
38 
39  /* Define to prevent redundant inclusion */
40 #ifndef _MXC_UART_H_
41 #define _MXC_UART_H_
42 
43 /***** Definitions *****/
44 #include "uart_regs.h"
45 #include "mxc_sys.h"
46 
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50 
57 typedef struct _mxc_uart_req_t mxc_uart_req_t;
62 typedef enum {
66 
71 typedef enum {
78 
83 typedef enum {
87 
90 typedef enum {
91  /*For UART3 APB clock source is the 8MHz clock*/
92  MXC_UART_APB_CLK = 0,
93  /*8MHz clock can only be used for UART 0, 1 & 2*/
94  MXC_UART_8M_CLK = 2,
95  /*32K & 80K clock can only be used for UART3*/
96  MXC_UART_32K_CLK = 1,
97  //MXC_UART_80K_CLK = 2,
99 
106 typedef void (*mxc_uart_complete_cb_t)(mxc_uart_req_t* req, int result);
107 
115 typedef void (*mxc_uart_dma_complete_cb_t)(mxc_uart_req_t* req, int num, int result);
116 
127  const uint8_t *txData;
128  uint8_t *rxData;
132  uint32_t txLen;
136  uint32_t rxLen;
137  uint32_t txCnt;
138  uint32_t rxCnt;
139  /*** @} */ // end of required group
140 
145  /*** @} */ // end of async group
146 };
147 
148 /***** Function Prototypes *****/
149 
150 /* ************************************************************************* */
151 /* Control/Configuration functions */
152 /* ************************************************************************* */
153 
174 int MXC_UART_Init(mxc_uart_regs_t* uart, unsigned int baud, mxc_uart_clock_t clock);
175 
184 
198 
209 int MXC_UART_SetFrequency(mxc_uart_regs_t* uart, unsigned int baud, mxc_uart_clock_t clock);
210 
221 
230 int MXC_UART_SetDataSize(mxc_uart_regs_t* uart, int dataSize);
231 
240 int MXC_UART_SetStopBits(mxc_uart_regs_t* uart, mxc_uart_stop_t stopBits);
241 
250 int MXC_UART_SetParity(mxc_uart_regs_t* uart, mxc_uart_parity_t parity);
251 
261 int MXC_UART_SetFlowCtrl(mxc_uart_regs_t* uart, mxc_uart_flow_t flowCtrl, int rtsThreshold);
262 
273 
274 /* ************************************************************************* */
275 /* Low-level functions */
276 /* ************************************************************************* */
277 
288 
297 
307 
317 int MXC_UART_WriteCharacterRaw (mxc_uart_regs_t* uart, uint8_t character);
318 
327 
336 int MXC_UART_WriteCharacter(mxc_uart_regs_t* uart, uint8_t character);
337 
349 int MXC_UART_Read(mxc_uart_regs_t* uart, uint8_t* buffer, int* len);
350 
360 int MXC_UART_Write(mxc_uart_regs_t* uart, const uint8_t* byte, int* len);
361 
371 unsigned int MXC_UART_ReadRXFIFO(mxc_uart_regs_t* uart, unsigned char* bytes,
372  unsigned int len);
373 
384 int MXC_UART_ReadRXFIFODMA(mxc_uart_regs_t* uart, unsigned char* bytes,
385  unsigned int len, mxc_uart_dma_complete_cb_t callback);
386 
395 
405 unsigned int MXC_UART_WriteTXFIFO(mxc_uart_regs_t* uart, const unsigned char* bytes,
406  unsigned int len);
407 
418 int MXC_UART_WriteTXFIFODMA(mxc_uart_regs_t* uart, const unsigned char* bytes,
419  unsigned int len, mxc_uart_dma_complete_cb_t callback);
420 
429 
438 
447 
465 int MXC_UART_SetRXThreshold(mxc_uart_regs_t* uart, unsigned int numBytes);
466 
475 
493 int MXC_UART_SetTXThreshold(mxc_uart_regs_t* uart, unsigned int numBytes);
494 
503 
514 unsigned int MXC_UART_GetFlags(mxc_uart_regs_t* uart);
515 
527 int MXC_UART_ClearFlags(mxc_uart_regs_t* uart, unsigned int flags);
528 
540 int MXC_UART_EnableInt(mxc_uart_regs_t* uart, unsigned int mask);
541 
553 int MXC_UART_DisableInt(mxc_uart_regs_t* uart, unsigned int mask);
554 
563 
564 /* ************************************************************************* */
565 /* Transaction level functions */
566 /* ************************************************************************* */
567 
579 int MXC_UART_Transaction(mxc_uart_req_t* req);
580 
591 int MXC_UART_TransactionAsync(mxc_uart_req_t* req);
592 
606 int MXC_UART_TransactionDMA(mxc_uart_req_t* req);
607 
616 int MXC_UART_AsyncCallback (mxc_uart_regs_t* uart, int retVal);
617 
626 
639 
652 
661 int MXC_UART_DMACallback (int ch, int error);
662 
665 #ifdef __cplusplus
666 }
667 #endif
668 
669 #endif /* _MXC_UART_H_ */
int MXC_UART_DisableInt(mxc_uart_regs_t *uart, unsigned int mask)
Disables specific interrupts.
int MXC_UART_ReadyForSleep(mxc_uart_regs_t *uart)
Checks if the given UART bus can be placed in sleep more.
uint8_t * rxData
Definition: uart.h:131
UART Parity Odd, 1 based.
Definition: uart.h:76
unsigned int MXC_UART_GetStatus(mxc_uart_regs_t *uart)
Gets the status flags that are currently set.
int MXC_UART_SetDataSize(mxc_uart_regs_t *uart, int dataSize)
Sets the number of bits per character.
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.
The information required to perform a complete UART transaction.
Definition: uart.h:122
int MXC_UART_AsyncHandler(mxc_uart_regs_t *uart)
The processing function for asynchronous transactions.
int MXC_UART_AsyncCallback(mxc_uart_regs_t *uart, int retVal)
Async callback.
int MXC_UART_SetTXThreshold(mxc_uart_regs_t *uart, unsigned int numBytes)
Set the transmit threshold level.
int MXC_UART_Transaction(mxc_uart_req_t *req)
Performs a blocking UART transaction.
mxc_uart_complete_cb_t callback
Pointer to function called when transaction is complete.
Definition: uart.h:144
int MXC_UART_GetFrequency(mxc_uart_regs_t *uart)
Get the frequency of the UART interface.
UART Parity Odd, 0 based.
Definition: uart.h:75
uint32_t txCnt
Number of bytes actually transmitted from txData.
Definition: uart.h:137
mxc_uart_parity_t
The list of UART Parity options supported.
Definition: uart.h:71
mxc_uart_stop_t
The list of UART stop bit lengths supported.
Definition: uart.h:62
int MXC_UART_SetFrequency(mxc_uart_regs_t *uart, unsigned int baud, mxc_uart_clock_t clock)
Set the frequency of the UART interface.
unsigned int MXC_UART_GetRXFIFOAvailable(mxc_uart_regs_t *uart)
Get the number of bytes currently available in the receive FIFO.
int MXC_UART_ClearTXFIFO(mxc_uart_regs_t *uart)
Removes and discards all bytes currently in the transmit FIFO.
int MXC_UART_AbortAsync(mxc_uart_regs_t *uart)
Abort any asynchronous requests in progress.
int MXC_UART_ClearRXFIFO(mxc_uart_regs_t *uart)
Removes and discards all bytes currently in the receive FIFO.
mxc_uart_regs_t * uart
Point to UART registers.
Definition: uart.h:126
Definition: uart_regs.h:88
mxc_uart_clock_t
Clock settings.
Definition: uart.h:90
UART Parity Even, 0 based.
Definition: uart.h:73
int MXC_UART_WriteCharacter(mxc_uart_regs_t *uart, uint8_t character)
Writes a character on the UART.
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...
UART Parity Disabled.
Definition: uart.h:72
mxc_uart_flow_t
The list of UART flow control options supported.
Definition: uart.h:83
int MXC_UART_SetParity(mxc_uart_regs_t *uart, mxc_uart_parity_t parity)
Sets the type of parity generation used.
int MXC_UART_SetFlowCtrl(mxc_uart_regs_t *uart, mxc_uart_flow_t flowCtrl, int rtsThreshold)
Sets the flow control used.
int MXC_UART_TransactionAsync(mxc_uart_req_t *req)
Setup an interrupt-driven UART transaction.
int MXC_UART_Read(mxc_uart_regs_t *uart, uint8_t *buffer, int *len)
Reads the next available character.
unsigned int MXC_UART_GetRXThreshold(mxc_uart_regs_t *uart)
Get the current receive threshold level.
UART Flow Control Enabled.
Definition: uart.h:85
UART Stop 1 clock cycle.
Definition: uart.h:63
unsigned int MXC_UART_GetTXFIFOAvailable(mxc_uart_regs_t *uart)
Get the amount of free space available in the transmit FIFO.
unsigned int MXC_UART_GetTXThreshold(mxc_uart_regs_t *uart)
Get the current transmit threshold level.
int MXC_UART_Write(mxc_uart_regs_t *uart, const uint8_t *byte, int *len)
Writes a byte on the UART.
int MXC_UART_ClearFlags(mxc_uart_regs_t *uart, unsigned int flags)
Clears the interrupt flags that are currently set.
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...
UART Flow Control Disabled.
Definition: uart.h:84
UART Stop 2 clock cycle (1.5 clocks for 5 bit characters)
Definition: uart.h:64
int MXC_UART_WriteTXFIFODMA(mxc_uart_regs_t *uart, const unsigned char *bytes, unsigned int len, mxc_uart_dma_complete_cb_t callback)
Loads bytes into the transmit FIFO using DMA for longer writes.
unsigned int MXC_UART_ReadRXFIFO(mxc_uart_regs_t *uart, unsigned char *bytes, unsigned int len)
Unloads bytes from the receive FIFO.
int MXC_UART_SetClockSource(mxc_uart_regs_t *uart, mxc_uart_clock_t clock)
Sets the clock source for the baud rate generator.
int MXC_UART_EnableInt(mxc_uart_regs_t *uart, unsigned int mask)
Enables specific interrupts.
int MXC_UART_TransactionDMA(mxc_uart_req_t *req)
Setup a DMA driven UART transaction.
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:115
int MXC_UART_SetRXThreshold(mxc_uart_regs_t *uart, unsigned int numBytes)
Set the receive threshold level.
int MXC_UART_AsyncStop(mxc_uart_regs_t *uart)
stop any async callbacks
const uint8_t * txData
Definition: uart.h:127
uint32_t rxCnt
Number of bytes stored in rxData.
Definition: uart.h:138
uint32_t rxLen
Number of bytes to be stored in rxData.
Definition: uart.h:136
unsigned int MXC_UART_GetFlags(mxc_uart_regs_t *uart)
Gets the interrupt flags that are currently set.
int MXC_UART_AbortTransmission(mxc_uart_regs_t *uart)
Aborts an ongoing UART Transmission.
unsigned int MXC_UART_WriteTXFIFO(mxc_uart_regs_t *uart, const unsigned char *bytes, unsigned int len)
Loads bytes into the transmit FIFO.
int MXC_UART_GetActive(mxc_uart_regs_t *uart)
Checks the UART Peripheral for an ongoing transmission.
int MXC_UART_ReadCharacter(mxc_uart_regs_t *uart)
Reads the next available character.
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:106
int MXC_UART_DMACallback(int ch, int error)
DMA Callback function.
int MXC_UART_Init(mxc_uart_regs_t *uart, unsigned int baud, mxc_uart_clock_t clock)
Initialize and enable UART peripheral.
uint32_t txLen
Number of bytes to be sent from txData.
Definition: uart.h:135
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.
UART Parity Even, 1 based.
Definition: uart.h:74
int MXC_UART_Shutdown(mxc_uart_regs_t *uart)
Disable and shutdown UART peripheral.