1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
|
/*
* Copyright : (C) 2022 Phytium Information Technology, Inc.
* All Rights Reserved.
*
* This program is OPEN SOURCE software: you can redistribute it and/or modify it
* under the terms of the Phytium Public License as published by the Phytium Technology Co.,Ltd,
* either version 1.0 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the Phytium Public License for more details.
*
*
* FilePath: fpl011_intr.c
* Date: 2022-02-10 14:53:42
* LastEditTime: 2022-02-18 09:06:30
* Description: This files is for uart irq functions
*
* Modify History:
* Ver Who Date Changes
* ----- ------ -------- --------------------------------------
*/
/***************************** Include Files *********************************/
#include "fpl011.h"
/************************** Constant Definitions *****************************/
/**************************** Type Definitions *******************************/
/***************** Macros (Inline Functions) Definitions *********************/
/************************** Variable Definitions *****************************/
/************************** Function Prototypes ******************************/
/*****************************************************************************/
extern u32 FPl011SendBuffer(FPl011 *uart_p);
extern u32 FPl011ReceiveBuffer(FPl011 *uart_p);
static void FPl011ReceiveErrorHandler(FPl011 *uart_p, u32 InterruptStatus);
static void FPl011ReceiveDataHandler(FPl011 *uart_p);
static void FPl011ReceiveTimeoutHandler(FPl011 *uart_p);
static void FPl011SendDataHandler(FPl011 *uart_p, u32 InterruptStatus);
/**
* @name: FPl011GetInterruptMask
* @msg: 此函数获取所有串口中断的mask。
* @param uart_p
* @return mask
*/
/**
* @name: FPl011GetInterruptMask
* @msg: This function gets the interrupt mask.
* @param uart_p is a pointer to the uart instance
* @return {*}
*/
u32 FPl011GetInterruptMask(FPl011 *uart_p)
{
FASSERT(uart_p != NULL);
return FUART_READREG32(uart_p->config.base_address, FPL011IMSC_OFFSET);
}
/**
* @name: FPl011SetInterruptMask
* @msg: This function sets the interrupt mask.
* @param uart_p is a pointer to the uart instance
* @param mask contains the interrupts to be enabled or disabled.
* A '1' enables an interrupt, and a '0' disables.
*/
void FPl011SetInterruptMask(FPl011 *uart_p, u32 mask)
{
u32 temp_mask = mask;
FASSERT(uart_p != NULL);
temp_mask &= FPL011IMSC_ALLM;
FUART_WRITEREG32(uart_p->config.base_address, FPL011IMSC_OFFSET, temp_mask);
}
/**
* @name: FPl011SetHandler
* @msg: This function sets the handler that will be called when an event (interrupt)
* occurs that needs application's attention.
* @param uart_p is a pointer to the uart instance
* @param fun_p is the pointer to the callback function.
* @param args is the upper layer callback reference passed back
* when the callback function is invoked.
* @return {*}
*/
void FPl011SetHandler(FPl011 *uart_p, FPl011EventHandler fun_p, void *args)
{
FASSERT(uart_p != NULL);
FASSERT(fun_p != NULL);
FASSERT(uart_p->is_ready == FT_COMPONENT_IS_READY);
uart_p->handler = fun_p;
uart_p->args = args;
}
/**
* @name: FPl011InterruptHandler
* @msg: This function is the interrupt handler for the driver.
* It must be connected to an interrupt system by the application such that it
* can be called when an interrupt occurs.
* @param vector Irq num ,Don't need attention .
* @param param contains a pointer to the driver instance
*/
void FPl011InterruptHandler(s32 vector, void *param)
{
FPl011 *uart_p = (FPl011 *)param;
u32 reg_value = 0;
FASSERT(uart_p != NULL);
FASSERT(uart_p->is_ready == FT_COMPONENT_IS_READY);
reg_value = FUART_READREG32(uart_p->config.base_address, FPL011IMSC_OFFSET);
reg_value &= FUART_READREG32(uart_p->config.base_address, FPL011MIS_OFFSET);
if ((reg_value & ((u32)FPL011MIS_RXMIS)) != (u32)0)
{
/* Received data interrupt */
FPl011ReceiveDataHandler(uart_p);
}
if ((reg_value & ((u32)FPL011MIS_TXMIS)) != (u32)0)
{
/* Transmit data interrupt */
FPl011SendDataHandler(uart_p, reg_value);
}
if (((reg_value) & ((u32)FPL011MIS_OEMIS | (u32)FPL011MIS_BEMIS | (u32)FPL011MIS_PEMIS | (u32)FPL011MIS_FEMIS)) != (u32)0)
{
/* Received Error Status interrupt */
FPl011ReceiveErrorHandler(uart_p, reg_value);
}
if ((reg_value & ((u32)FPL011MIS_RTMIS)) != (u32)0)
{
/* Received Timeout interrupt */
FPl011ReceiveTimeoutHandler(uart_p);
}
if (((reg_value) & ((u32)FPL011MIS_DSRMMIS | (u32)FPL011MIS_DCDMMIS | (u32)FPL011MIS_CTSMMIS | (u32)FPL011MIS_RIMMIS)) != (u32)0)
{
/* Modem status interrupt */
}
/* Clear the interrupt status. */
FUART_WRITEREG32(uart_p->config.base_address, FPL011ICR_OFFSET,
reg_value);
}
static void FPl011ReceiveErrorHandler(FPl011 *uart_p, u32 InterruptStatus)
{
uart_p->rxbs_error = 0;
if (((InterruptStatus) & ((u32)FPL011MIS_OEMIS | (u32)FPL011MIS_BEMIS | (u32)FPL011MIS_PEMIS | (u32)FPL011MIS_FEMIS)) != 0)
{
uart_p->rxbs_error = 1;
}
(void)FPl011ReceiveBuffer(uart_p);
if (0 == uart_p->rxbs_error)
{
if (uart_p->handler)
{
uart_p->handler(uart_p->args, FPL011_EVENT_RECV_ERROR, uart_p->receive_buffer.requested_bytes - uart_p->receive_buffer.remaining_bytes);
}
}
}
/**
* @name: FPl011ReceiveDataHandler
* @msg:
* @param {*}
* @return {*}
*/
static void FPl011ReceiveDataHandler(FPl011 *uart_p)
{
if ((u32)0 != uart_p->receive_buffer.remaining_bytes)
{
(void)FPl011ReceiveBuffer(uart_p);
}
if ((u32)0 == uart_p->receive_buffer.remaining_bytes)
{
if (uart_p->handler)
{
uart_p->handler(uart_p->args, FPL011_EVENT_RECV_DATA, uart_p->receive_buffer.requested_bytes - uart_p->receive_buffer.remaining_bytes);
}
}
}
static void FPl011ReceiveTimeoutHandler(FPl011 *uart_p)
{
u32 event;
if ((u32)0 != uart_p->receive_buffer.remaining_bytes)
{
(void)FPl011ReceiveBuffer(uart_p);
}
if ((u32)0 == uart_p->receive_buffer.remaining_bytes)
{
event = FPL011_EVENT_RECV_TOUT;
}
else
{
event = FPL011_EVENT_RECV_DATA;
}
if (uart_p->handler)
{
uart_p->handler(uart_p->args, event, uart_p->receive_buffer.requested_bytes - uart_p->receive_buffer.remaining_bytes);
}
}
static void FPl011SendDataHandler(FPl011 *uart_p, u32 InterruptStatus)
{
FPl011SendBuffer(uart_p);
if (uart_p->send_buffer.remaining_bytes == (u32)0)
{
if (uart_p->handler)
{
uart_p->handler(uart_p->args, FPL011_EVENT_SENT_DATA, uart_p->send_buffer.requested_bytes);
}
}
}
|