MAX32675 Peripheral Driver API
Peripheral Driver API for the MAX32675
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Modules
uart.h
1
6/******************************************************************************
7 *
8 * Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by
9 * Analog Devices, Inc.),
10 * Copyright (C) 2023-2024 Analog Devices, Inc.
11 *
12 * Licensed under the Apache License, Version 2.0 (the "License");
13 * you may not use this file except in compliance with the License.
14 * You may obtain a copy of the License at
15 *
16 * http://www.apache.org/licenses/LICENSE-2.0
17 *
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
23 *
24 ******************************************************************************/
25
26/* Define to prevent redundant inclusion */
27#ifndef LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32675_UART_H_
28#define LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32675_UART_H_
29
30/***** Definitions *****/
31#include <stdbool.h>
32#include "uart_regs.h"
33#include "mxc_sys.h"
34
35#define UART_EXTCLK_FREQ EXTCLK_FREQ
36
37#ifdef __cplusplus
38extern "C" {
39#endif
40
47typedef struct _mxc_uart_req_t mxc_uart_req_t;
52typedef enum {
56
61typedef enum {
68
73typedef enum {
77
80typedef enum {
81 MXC_UART_APB_CLK = 0,
82 MXC_UART_EXT_CLK = 1,
83 /*8M (IBRO) and 32M (EFRO) clocks can be used for UARTs 0 and 2*/
84 MXC_UART_IBRO_CLK = 2,
85 MXC_UART_ERFO_CLK = 3,
87
94typedef void (*mxc_uart_complete_cb_t)(mxc_uart_req_t *req, int result);
95
103typedef void (*mxc_uart_dma_complete_cb_t)(mxc_uart_req_t *req, int num, int result);
104
113 const uint8_t *txData;
117 uint8_t *rxData;
121 uint32_t txLen;
122 uint32_t rxLen;
123 volatile uint32_t txCnt;
124 volatile uint32_t rxCnt;
125
127};
128
129/***** Function Prototypes *****/
130
131/* ************************************************************************* */
132/* Control/Configuration functions */
133/* ************************************************************************* */
134
159int MXC_UART_Init(mxc_uart_regs_t *uart, unsigned int baud, mxc_uart_clock_t clock);
160
169
183
194int MXC_UART_SetFrequency(mxc_uart_regs_t *uart, unsigned int baud, mxc_uart_clock_t clock);
195
206
215int MXC_UART_SetDataSize(mxc_uart_regs_t *uart, int dataSize);
216
226
236
246int MXC_UART_SetFlowCtrl(mxc_uart_regs_t *uart, mxc_uart_flow_t flowCtrl, int rtsThreshold);
247
258
259/* ************************************************************************* */
260/* Low-level functions */
261/* ************************************************************************* */
262
273
282
292
303int MXC_UART_WriteCharacterRaw(mxc_uart_regs_t *uart, uint8_t character);
304
313
322int MXC_UART_WriteCharacter(mxc_uart_regs_t *uart, uint8_t character);
323
335int MXC_UART_Read(mxc_uart_regs_t *uart, uint8_t *buffer, int *len);
336
346int MXC_UART_Write(mxc_uart_regs_t *uart, const uint8_t *byte, int *len);
347
357unsigned int MXC_UART_ReadRXFIFO(mxc_uart_regs_t *uart, unsigned char *bytes, unsigned int len);
358
369int MXC_UART_ReadRXFIFODMA(mxc_uart_regs_t *uart, unsigned char *bytes, unsigned int len,
371
380
390unsigned int MXC_UART_WriteTXFIFO(mxc_uart_regs_t *uart, const unsigned char *bytes,
391 unsigned int len);
392
403int MXC_UART_WriteTXFIFODMA(mxc_uart_regs_t *uart, const unsigned char *bytes, unsigned int len,
405
414
423
432
450int MXC_UART_SetRXThreshold(mxc_uart_regs_t *uart, unsigned int numBytes);
451
460
478int MXC_UART_SetTXThreshold(mxc_uart_regs_t *uart, unsigned int numBytes);
479
488
500
512int MXC_UART_ClearFlags(mxc_uart_regs_t *uart, unsigned int flags);
513
525int MXC_UART_EnableInt(mxc_uart_regs_t *uart, unsigned int mask);
526
538int MXC_UART_DisableInt(mxc_uart_regs_t *uart, unsigned int mask);
539
548
549/* ************************************************************************* */
550/* Transaction level functions */
551/* ************************************************************************* */
552
564int MXC_UART_Transaction(mxc_uart_req_t *req);
565
576int MXC_UART_TransactionAsync(mxc_uart_req_t *req);
577
591int MXC_UART_TransactionDMA(mxc_uart_req_t *req);
592
602void MXC_UART_DMACallback(int ch, int error);
603
613
622
635
648
656uint32_t MXC_UART_GetAsyncTXCount(mxc_uart_req_t *req);
657
665uint32_t MXC_UART_GetAsyncRXCount(mxc_uart_req_t *req);
666
685
695int MXC_UART_SetTXDMAChannel(mxc_uart_regs_t *uart, unsigned int channel);
696
707
717int MXC_UART_SetRXDMAChannel(mxc_uart_regs_t *uart, unsigned int channel);
718
729
732#ifdef __cplusplus
733}
734#endif
735
736#endif // LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32675_UART_H_
Definition: uart_regs.h:76
uint32_t rxLen
Number of bytes to be stored in rxData.
Definition: uart.h:122
mxc_uart_regs_t * uart
Point to UART registers.
Definition: uart.h:112
volatile uint32_t txCnt
Number of bytes actually transmitted from txData.
Definition: uart.h:123
volatile uint32_t rxCnt
Number of bytes stored in rxData.
Definition: uart.h:124
const uint8_t * txData
Definition: uart.h:113
uint8_t * rxData
Definition: uart.h:117
uint32_t txLen
Number of bytes to be sent from txData.
Definition: uart.h:121
mxc_uart_complete_cb_t callback
Pointer to function called when transaction is complete.
Definition: uart.h:126
int MXC_UART_SetRXThreshold(mxc_uart_regs_t *uart, unsigned int numBytes)
Set the receive threshold level.
int MXC_UART_Init(mxc_uart_regs_t *uart, unsigned int baud, mxc_uart_clock_t clock)
Initialize and enable UART peripheral.
uint32_t MXC_UART_GetAsyncRXCount(mxc_uart_req_t *req)
Provide RXCount for asynchronous transactions..
int MXC_UART_ClearRXFIFO(mxc_uart_regs_t *uart)
Removes and discards all bytes currently in the receive FIFO.
void MXC_UART_DMACallback(int ch, int error)
The processing function for DMA transactions.
int MXC_UART_ClearFlags(mxc_uart_regs_t *uart, unsigned int flags)
Clears the interrupt flags that are currently set.
int MXC_UART_Read(mxc_uart_regs_t *uart, uint8_t *buffer, int *len)
Reads the next available character.
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.
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_SetTXDMAChannel(mxc_uart_regs_t *uart, unsigned int channel)
Set the TX (Transmit) DMA channel for a UART module.
unsigned int MXC_UART_GetStatus(mxc_uart_regs_t *uart)
Gets the status flags that are currently set.
unsigned int MXC_UART_GetTXFIFOAvailable(mxc_uart_regs_t *uart)
Get the amount of free space available in the transmit FIFO.
int MXC_UART_AsyncStop(mxc_uart_regs_t *uart)
stop any async callbacks
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...
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.
int MXC_UART_AbortAsync(mxc_uart_regs_t *uart)
Abort any asynchronous requests in progress.
unsigned int MXC_UART_GetFlags(mxc_uart_regs_t *uart)
Gets the interrupt flags that are currently set.
int MXC_UART_Transaction(mxc_uart_req_t *req)
Performs a blocking UART transaction.
int MXC_UART_DisableInt(mxc_uart_regs_t *uart, unsigned int mask)
Disables specific interrupts.
int MXC_UART_ReadCharacter(mxc_uart_regs_t *uart)
Reads the next available character.
int MXC_UART_SetClockSource(mxc_uart_regs_t *uart, mxc_uart_clock_t clock)
Sets the clock source for the baud rate generator.
unsigned int MXC_UART_GetRXFIFOAvailable(mxc_uart_regs_t *uart)
Get the number of bytes currently available in the receive FIFO.
int MXC_UART_SetParity(mxc_uart_regs_t *uart, mxc_uart_parity_t parity)
Sets the type of parity generation used.
int MXC_UART_GetActive(mxc_uart_regs_t *uart)
Checks the UART Peripheral for an ongoing transmission.
mxc_uart_clock_t
Clock settings.
Definition: uart.h:80
int MXC_UART_SetFrequency(mxc_uart_regs_t *uart, unsigned int baud, mxc_uart_clock_t clock)
Set the frequency of the UART interface.
mxc_uart_parity_t
The list of UART Parity options supported.
Definition: uart.h:61
int MXC_UART_GetRXDMAChannel(mxc_uart_regs_t *uart)
Get the RX (Receive) DMA channel for a UART module.
int MXC_UART_ReadyForSleep(mxc_uart_regs_t *uart)
Checks if the given UART bus can be placed in sleep more.
int MXC_UART_Write(mxc_uart_regs_t *uart, const uint8_t *byte, int *len)
Writes a byte on the UART.
int MXC_UART_AsyncHandler(mxc_uart_regs_t *uart)
The processing function for asynchronous transactions.
int MXC_UART_ClearTXFIFO(mxc_uart_regs_t *uart)
Removes and discards all bytes currently in the transmit FIFO.
int MXC_UART_SetAutoDMAHandlers(mxc_uart_regs_t *uart, bool enable)
Enable or disable automatic DMA interrupt handlers for the UART module.
mxc_uart_stop_t
The list of UART stop bit lengths supported.
Definition: uart.h:52
int MXC_UART_GetTXDMAChannel(mxc_uart_regs_t *uart)
Get the TX (Transmit) DMA channel for a UART module.
int MXC_UART_Shutdown(mxc_uart_regs_t *uart)
Disable and shutdown UART peripheral.
int MXC_UART_SetRXDMAChannel(mxc_uart_regs_t *uart, unsigned int channel)
Set the RX (Receive) DMA channel for a UART module.
mxc_uart_flow_t
The list of UART flow control options supported.
Definition: uart.h:73
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:103
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.
int MXC_UART_AbortTransmission(mxc_uart_regs_t *uart)
Aborts an ongoing UART Transmission.
unsigned int MXC_UART_ReadRXFIFO(mxc_uart_regs_t *uart, unsigned char *bytes, unsigned int len)
Unloads bytes from the receive FIFO.
uint32_t MXC_UART_GetAsyncTXCount(mxc_uart_req_t *req)
Provide TXCount for asynchronous transactions..
int MXC_UART_TransactionAsync(mxc_uart_req_t *req)
Setup an interrupt-driven UART transaction.
int MXC_UART_SetTXThreshold(mxc_uart_regs_t *uart, unsigned int numBytes)
Set the transmit threshold level.
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.
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:94
int MXC_UART_GetFrequency(mxc_uart_regs_t *uart)
Get the frequency of the UART interface.
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.
int MXC_UART_WriteCharacter(mxc_uart_regs_t *uart, uint8_t character)
Writes a character on the UART. This is a blocking function.
unsigned int MXC_UART_GetRXThreshold(mxc_uart_regs_t *uart)
Get the current receive threshold level.
int MXC_UART_SetFlowCtrl(mxc_uart_regs_t *uart, mxc_uart_flow_t flowCtrl, int rtsThreshold)
Sets the flow control used.
int MXC_UART_SetDataSize(mxc_uart_regs_t *uart, int dataSize)
Sets the number of bits per character.
unsigned int MXC_UART_GetTXThreshold(mxc_uart_regs_t *uart)
Get the current transmit threshold level.
int MXC_UART_AsyncCallback(mxc_uart_regs_t *uart, int retVal)
Async callback.
@ MXC_UART_PARITY_ODD_1
UART Parity Odd, 1 based.
Definition: uart.h:66
@ MXC_UART_PARITY_EVEN_1
UART Parity Even, 1 based.
Definition: uart.h:64
@ MXC_UART_PARITY_EVEN_0
UART Parity Even, 0 based.
Definition: uart.h:63
@ MXC_UART_PARITY_ODD_0
UART Parity Odd, 0 based.
Definition: uart.h:65
@ MXC_UART_PARITY_DISABLE
UART Parity Disabled.
Definition: uart.h:62
@ MXC_UART_STOP_1
UART Stop 1 clock cycle.
Definition: uart.h:53
@ MXC_UART_STOP_2
UART Stop 2 clock cycle (1.5 clocks for 5 bit characters)
Definition: uart.h:54
@ MXC_UART_FLOW_EN
UART Flow Control Enabled.
Definition: uart.h:75
@ MXC_UART_FLOW_DIS
UART Flow Control Disabled.
Definition: uart.h:74
The information required to perform a complete UART transaction.
Definition: uart.h:111
Registers, Bit Masks and Bit Positions for the UART Peripheral Module.