1 /******************************************************************************
2  *
3  * Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by
4  * Analog Devices, Inc.),
5  * Copyright (C) 2023-2024 Analog Devices, Inc.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  ******************************************************************************/
20 
21 #ifndef LIBRARIES_PERIPHDRIVERS_SOURCE_UART_UART_REVB_H_
22 #define LIBRARIES_PERIPHDRIVERS_SOURCE_UART_UART_REVB_H_
23 
24 #include "mxc_device.h"
25 #include "mxc_assert.h"
26 #include "dma.h"
27 #include "uart_revb_regs.h"
28 #include "uart_regs.h"
29 
30 typedef struct _mxc_uart_revb_req_t mxc_uart_revb_req_t;
31 
32 /**
33  * @brief      Clock settings */
34 typedef enum {
35     MXC_UART_REVB_APB_CLK = 0, // PCLK
36     MXC_UART_REVB_EXT_CLK = 1,
37     MXC_UART_REVB_CLK2 = 2,
38     MXC_UART_REVB_CLK3 = 3,
39     // For UART3, ERTCO and INRO clocks
40     MXC_UART_REVB_LPCLK2 = 4,
41     MXC_UART_REVB_LPCLK3 = 5
42 } mxc_uart_revb_clock_t;
43 
44 struct _mxc_uart_revb_req_t {
45     mxc_uart_revb_regs_t *uart;
46     uint8_t *txData;
47     uint8_t *rxData;
48     uint32_t txLen;
49     uint32_t rxLen;
50     uint32_t txCnt;
51     uint32_t rxCnt;
52     mxc_uart_complete_cb_t callback;
53 };
54 
55 int MXC_UART_RevB_Init(mxc_uart_revb_regs_t *uart, unsigned int baud, mxc_uart_revb_clock_t clock);
56 int MXC_UART_RevB_Shutdown(mxc_uart_revb_regs_t *uart);
57 int MXC_UART_RevB_ReadyForSleep(mxc_uart_revb_regs_t *uart);
58 int MXC_UART_RevB_SetFrequency(mxc_uart_revb_regs_t *uart, unsigned int baud,
59                                mxc_uart_revb_clock_t clock);
60 int MXC_UART_RevB_GetFrequency(mxc_uart_revb_regs_t *uart);
61 int MXC_UART_RevB_SetDataSize(mxc_uart_revb_regs_t *uart, int dataSize);
62 int MXC_UART_RevB_SetStopBits(mxc_uart_revb_regs_t *uart, mxc_uart_stop_t stopBits);
63 int MXC_UART_RevB_SetParity(mxc_uart_revb_regs_t *uart, mxc_uart_parity_t parity);
64 int MXC_UART_RevB_SetFlowCtrl(mxc_uart_revb_regs_t *uart, mxc_uart_flow_t flowCtrl,
65                               int rtsThreshold);
66 int MXC_UART_RevB_SetClockSource(mxc_uart_revb_regs_t *uart, mxc_uart_revb_clock_t clock);
67 int MXC_UART_RevB_GetActive(mxc_uart_revb_regs_t *uart);
68 int MXC_UART_RevB_AbortTransmission(mxc_uart_revb_regs_t *uart);
69 int MXC_UART_RevB_ReadCharacterRaw(mxc_uart_revb_regs_t *uart);
70 int MXC_UART_RevB_WriteCharacterRaw(mxc_uart_revb_regs_t *uart, uint8_t character);
71 int MXC_UART_RevB_ReadCharacter(mxc_uart_revb_regs_t *uart);
72 int MXC_UART_RevB_WriteCharacter(mxc_uart_revb_regs_t *uart, uint8_t character);
73 int MXC_UART_RevB_Read(mxc_uart_revb_regs_t *uart, uint8_t *buffer, int *len);
74 int MXC_UART_RevB_Write(mxc_uart_revb_regs_t *uart, const uint8_t *byte, int *len);
75 unsigned int MXC_UART_RevB_ReadRXFIFO(mxc_uart_revb_regs_t *uart, unsigned char *bytes,
76                                       unsigned int len);
77 int MXC_UART_RevB_ReadRXFIFODMA(mxc_uart_revb_regs_t *uart, unsigned char *bytes, unsigned int len,
78                                 mxc_uart_dma_complete_cb_t callback, mxc_dma_config_t config);
79 unsigned int MXC_UART_RevB_GetRXFIFOAvailable(mxc_uart_revb_regs_t *uart);
80 unsigned int MXC_UART_RevB_WriteTXFIFO(mxc_uart_revb_regs_t *uart, const unsigned char *bytes,
81                                        unsigned int len);
82 int MXC_UART_RevB_WriteTXFIFODMA(mxc_uart_revb_regs_t *uart, const unsigned char *bytes,
83                                  unsigned int len, mxc_uart_dma_complete_cb_t callback,
84                                  mxc_dma_config_t config);
85 unsigned int MXC_UART_RevB_GetTXFIFOAvailable(mxc_uart_revb_regs_t *uart);
86 int MXC_UART_RevB_ClearRXFIFO(mxc_uart_revb_regs_t *uart);
87 int MXC_UART_RevB_ClearTXFIFO(mxc_uart_revb_regs_t *uart);
88 int MXC_UART_RevB_SetRXThreshold(mxc_uart_revb_regs_t *uart, unsigned int numBytes);
89 unsigned int MXC_UART_RevB_GetRXThreshold(mxc_uart_revb_regs_t *uart);
90 int MXC_UART_RevB_SetTXThreshold(mxc_uart_revb_regs_t *uart, unsigned int numBytes);
91 unsigned int MXC_UART_RevB_GetTXThreshold(mxc_uart_revb_regs_t *uart);
92 unsigned int MXC_UART_RevB_GetFlags(mxc_uart_revb_regs_t *uart);
93 int MXC_UART_RevB_ClearFlags(mxc_uart_revb_regs_t *uart, unsigned int flags);
94 int MXC_UART_RevB_EnableInt(mxc_uart_revb_regs_t *uart, unsigned int mask);
95 int MXC_UART_RevB_DisableInt(mxc_uart_revb_regs_t *uart, unsigned int mask);
96 unsigned int MXC_UART_RevB_GetStatus(mxc_uart_revb_regs_t *uart);
97 int MXC_UART_RevB_Busy(mxc_uart_revb_regs_t *uart);
98 int MXC_UART_RevB_Transaction(mxc_uart_revb_req_t *req);
99 int MXC_UART_RevB_TransactionAsync(mxc_uart_revb_req_t *req);
100 int MXC_UART_RevB_TransactionDMA(mxc_uart_revb_req_t *req);
101 int MXC_UART_RevB_AbortAsync(mxc_uart_revb_regs_t *uart);
102 int MXC_UART_RevB_AsyncHandler(mxc_uart_revb_regs_t *uart);
103 int MXC_UART_RevB_AsyncStop(mxc_uart_revb_regs_t *uart);
104 int MXC_UART_RevB_AsyncCallback(mxc_uart_revb_regs_t *uart, int retVal);
105 void MXC_UART_RevB_DMACallback(int ch, int error);
106 
107 int MXC_UART_RevB_SetAutoDMAHandlers(mxc_uart_revb_regs_t *uart, bool enable);
108 int MXC_UART_RevB_SetTXDMAChannel(mxc_uart_revb_regs_t *uart, unsigned int channel);
109 int MXC_UART_RevB_GetTXDMAChannel(mxc_uart_revb_regs_t *uart);
110 int MXC_UART_RevB_SetRXDMAChannel(mxc_uart_revb_regs_t *uart, unsigned int channel);
111 int MXC_UART_RevB_GetRXDMAChannel(mxc_uart_revb_regs_t *uart);
112 
113 #endif // LIBRARIES_PERIPHDRIVERS_SOURCE_UART_UART_REVB_H_
114