MAX32660 Peripheral Driver API
Peripheral Driver API for the MAX32660
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_MAX32660_UART_H_
28#define LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32660_UART_H_
29
30/***** Definitions *****/
31#include <stdbool.h>
32#include "uart_regs.h"
33#include "mxc_sys.h"
34#include "mxc_pins.h"
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
46typedef struct _mxc_uart_req_t mxc_uart_req_t;
51typedef enum {
55
60typedef enum {
75
80typedef enum {
85
92typedef void (*mxc_uart_complete_cb_t)(mxc_uart_req_t *req, int result);
93
101typedef void (*mxc_uart_dma_complete_cb_t)(mxc_uart_req_t *req, int num, int result);
102
110 uint8_t *txData;
114 uint8_t *rxData;
118 uint32_t txLen;
119 uint32_t rxLen;
120 volatile uint32_t txCnt;
121 volatile uint32_t rxCnt;
122
124};
125
126/***** Function Prototypes *****/
127
128/* ************************************************************************* */
129/* Control/Configuration functions */
130/* ************************************************************************* */
131
154int MXC_UART_Init(mxc_uart_regs_t *uart, unsigned int baud, sys_map_t map);
155
164
178
190int MXC_UART_SetFrequency(mxc_uart_regs_t *uart, unsigned int baud);
191
202
211int MXC_UART_SetDataSize(mxc_uart_regs_t *uart, int dataSize);
212
222
232
242int MXC_UART_SetFlowCtrl(mxc_uart_regs_t *uart, mxc_uart_flow_t flowCtrl, int rtsThreshold);
243
257
267int MXC_UART_SetNullModem(mxc_uart_regs_t *uart, int nullModem);
268
269/* ************************************************************************* */
270/* Low-level functions */
271/* ************************************************************************* */
272
281
292
301
311
321int MXC_UART_WriteCharacter(mxc_uart_regs_t *uart, uint8_t character);
322
332
342int MXC_UART_WriteCharacterRaw(mxc_uart_regs_t *uart, uint8_t character);
343
355int MXC_UART_Read(mxc_uart_regs_t *uart, uint8_t *buffer, int *len);
356
366int MXC_UART_Write(mxc_uart_regs_t *uart, uint8_t *byte, int *len);
367
377unsigned int MXC_UART_ReadRXFIFO(mxc_uart_regs_t *uart, unsigned char *bytes, unsigned int len);
378
389int MXC_UART_ReadRXFIFODMA(mxc_uart_regs_t *uart, unsigned char *bytes, unsigned int len,
391
400
410unsigned int MXC_UART_WriteTXFIFO(mxc_uart_regs_t *uart, unsigned char *bytes, unsigned int len);
411
422int MXC_UART_WriteTXFIFODMA(mxc_uart_regs_t *uart, unsigned char *bytes, unsigned int len,
424
433
442
451
469int MXC_UART_SetRXThreshold(mxc_uart_regs_t *uart, unsigned int numBytes);
470
479
497int MXC_UART_SetTXThreshold(mxc_uart_regs_t *uart, unsigned int numBytes);
498
507
519
531int MXC_UART_ClearFlags(mxc_uart_regs_t *uart, unsigned int flags);
532
544int MXC_UART_EnableInt(mxc_uart_regs_t *uart, unsigned int mask);
545
557int MXC_UART_DisableInt(mxc_uart_regs_t *uart, unsigned int mask);
558
567
568int MXC_UART_Busy(mxc_uart_regs_t *uart);
569
570/* ************************************************************************* */
571/* Transaction level functions */
572/* ************************************************************************* */
573
585int MXC_UART_Transaction(mxc_uart_req_t *req);
586
597int MXC_UART_TransactionAsync(mxc_uart_req_t *req);
598
612int MXC_UART_TransactionDMA(mxc_uart_req_t *req);
613
623void MXC_UART_DMACallback(int ch, int error);
624
634int MXC_UART_TxAsyncCallback(mxc_uart_regs_t *uart, int retVal);
635int MXC_UART_RxAsyncCallback(mxc_uart_regs_t *uart, int retVal);
636
645int MXC_UART_TxAsyncStop(mxc_uart_regs_t *uart);
646int MXC_UART_RxAsyncStop(mxc_uart_regs_t *uart);
647
660int MXC_UART_TxAbortAsync(mxc_uart_regs_t *uart);
661int MXC_UART_RxAbortAsync(mxc_uart_regs_t *uart);
662
675
683uint32_t MXC_UART_GetAsyncTXCount(mxc_uart_req_t *req);
684
692uint32_t MXC_UART_GetAsyncRXCount(mxc_uart_req_t *req);
693
712
722int MXC_UART_SetTXDMAChannel(mxc_uart_regs_t *uart, unsigned int channel);
723
734
744int MXC_UART_SetRXDMAChannel(mxc_uart_regs_t *uart, unsigned int channel);
745
756
759#ifdef __cplusplus
760}
761#endif
762
763#endif // LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32660_UART_H_
Definition: uart_regs.h:76
uint8_t * txData
Definition: uart.h:110
uint32_t rxLen
Number of bytes to be stored in rxData.
Definition: uart.h:119
mxc_uart_regs_t * uart
Point to UART registers.
Definition: uart.h:109
volatile uint32_t txCnt
Number of bytes actually transmitted from txData.
Definition: uart.h:120
volatile uint32_t rxCnt
Number of bytes stored in rxData.
Definition: uart.h:121
uint8_t * rxData
Definition: uart.h:114
uint32_t txLen
Number of bytes to be sent from txData.
Definition: uart.h:118
mxc_uart_complete_cb_t callback
Pointer to function called when transaction is complete.
Definition: uart.h:123
unsigned int MXC_UART_WriteTXFIFO(mxc_uart_regs_t *uart, unsigned char *bytes, unsigned int len)
Loads bytes into the transmit FIFO.
int MXC_UART_SetRXThreshold(mxc_uart_regs_t *uart, unsigned int numBytes)
Set the receive threshold level.
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.
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_Init(mxc_uart_regs_t *uart, unsigned int baud, sys_map_t map)
Initialize and enable UART peripheral.
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...
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.
int MXC_UART_SetClockSource(mxc_uart_regs_t *uart, int usePCLK)
Sets the clock source for the baud rate generator.
mxc_uart_parity_t
The list of UART Parity options supported.
Definition: uart.h:60
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_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:51
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:80
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:101
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.
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.
int MXC_UART_SendBreak(mxc_uart_regs_t *uart)
Transmits a Break Frame (all bits 0)
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.
int MXC_UART_SetNullModem(mxc_uart_regs_t *uart, int nullModem)
Enables or Disables the built-in null modem.
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:92
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 function will block until the character has been placed in the T...
int MXC_UART_Write(mxc_uart_regs_t *uart, uint8_t *byte, int *len)
Writes a byte on the UART.
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.
int MXC_UART_SetFrequency(mxc_uart_regs_t *uart, unsigned int baud)
Set the frequency of the UART interface.
@ MXC_UART_PARITY_ODD_1
UART Parity Odd, 1 based.
Definition: uart.h:69
@ MXC_UART_PARITY_EVEN_1
UART Parity Even, 1 based.
Definition: uart.h:67
@ MXC_UART_PARITY_SPACE_0
UART Parity Space, 0 based.
Definition: uart.h:72
@ MXC_UART_PARITY_ODD
UART Parity Odd.
Definition: uart.h:63
@ MXC_UART_PARITY_MARK
UART Parity Mark.
Definition: uart.h:64
@ MXC_UART_PARITY_EVEN_0
UART Parity Even, 0 based.
Definition: uart.h:66
@ MXC_UART_PARITY_ODD_0
UART Parity Odd, 0 based.
Definition: uart.h:68
@ MXC_UART_PARITY_SPACE
UART Parity Space.
Definition: uart.h:65
@ MXC_UART_PARITY_SPACE_1
UART Parity Space, 1 based.
Definition: uart.h:73
@ MXC_UART_PARITY_MARK_1
UART Parity Mark, 1 based.
Definition: uart.h:71
@ MXC_UART_PARITY_MARK_0
UART Parity Mark, 0 based.
Definition: uart.h:70
@ MXC_UART_PARITY_EVEN
UART Parity Even.
Definition: uart.h:62
@ MXC_UART_PARITY_DISABLE
UART Parity Disabled.
Definition: uart.h:61
@ MXC_UART_STOP_1
UART Stop 1 clock cycle.
Definition: uart.h:52
@ MXC_UART_STOP_2
UART Stop 2 clock cycle (1.5 clocks for 5 bit characters)
Definition: uart.h:53
@ MXC_UART_FLOW_EN_LOW
UART Flow Control Enabled, Active Low.
Definition: uart.h:82
@ MXC_UART_FLOW_DIS
UART Flow Control Disabled.
Definition: uart.h:81
@ MXC_UART_FLOW_EN_HIGH
UART Flow Control Enabled, Active High.
Definition: uart.h:83
The information required to perform a complete UART transaction.
Definition: uart.h:108
Registers, Bit Masks and Bit Positions for the UART Peripheral Module.