forked from arduino/ArduinoCore-renesas
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathIRQManager.h
274 lines (232 loc) · 6.83 KB
/
IRQManager.h
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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
#ifndef ARDUINO_IRQ_MANAGER_H
#define ARDUINO_IRQ_MANAGER_H
#include "analog.h"
#include "bsp_api.h"
#include "pins_arduino.h"
#include "elc_defines.h"
#if ETHERNET_HOWMANY > 0
#include "r_ether_api.h"
#endif
#if SERIAL_HOWMANY > 0
#include "r_uart_api.h"
#define UART_INTERRUPT_COUNT 4
#endif
#if EXT_INTERRUPTS_HOWMANY > 0
#include "r_external_irq_api.h"
#endif
#include "r_timer_api.h"
#ifdef ELC_EVENT_DMAC0_INT
#define HAS_DMAC 1
#include "r_dmac.h"
#endif
#include "r_gpt.h"
#include "r_agt.h"
typedef enum {
IRQ_RTC,
IRQ_USB,
IRQ_USB_HS,
IRQ_AGT,
IRQ_SCI_UART,
IRQ_I2C_MASTER,
IRQ_SCI_I2C_MASTER,
IRQ_I2C_SLAVE,
IRQ_EXTERNAL_PIN,
IRQ_SPI_MASTER,
IRQ_SCI_SPI_MASTER,
IRQ_CAN,
IRQ_ETHERNET,
IRQ_CANFD,
IRQ_SDCARD
} Peripheral_t;
#if SDCARD_HOWMANY > 0
#include "r_sdhi.h"
#endif
#if RTC_HOWMANY > 0
#include "r_rtc_api.h"
#include "r_rtc.h"
typedef enum {
RTC_ALARM,
RTC_PERIODIC,
RTC_CARRY
} RTCIrqReq_t;
typedef struct rtc_irq {
rtc_cfg_t *cfg;
rtc_instance_ctrl_t *ctrl;
RTCIrqReq_t req;
} RTCIrqCfg_t;
#endif
#if WIRE_HOWMANY > 0
#include "r_i2c_slave_api.h"
#include "r_i2c_master_api.h"
#include "r_iic_master.h"
#include "r_iic_slave.h"
typedef struct i2c_irq_req {
i2c_master_cfg_t *mcfg;
i2c_slave_cfg_t *scfg;
} I2CIrqReq_t;
#define WIRE_MASTER_INTERRUPT_COUNT 4
#define WIRE_SLAVE_INTERRUPT_COUNT 4
#define WIRE_SCI_MASTER_INTERRUPT_COUNT 3
#endif
#if SPI_HOWMANY > 0
#include "r_spi.h"
#include "r_sci_spi.h"
typedef struct spi_master_irq {
spi_instance_ctrl_t * ctrl;
spi_cfg_t * cfg;
uint8_t hw_channel;
} SpiMasterIrqReq_t;
typedef struct sci_spi_master_irq {
sci_spi_instance_ctrl_t * ctrl;
spi_cfg_t * cfg;
uint8_t hw_channel;
} SciSpiMasterIrqReq_t;
#define SPI_INTERRUPT_COUNT 4
#endif
#if CAN_HOWMANY > 0
# include "r_can.h"
typedef struct can_irq {
can_instance_ctrl_t * ctrl;
can_cfg_t * cfg;
} CanIrqReq_t;
#define CAN_INTERRUPT_COUNT 3
#endif /* CAN_HOWMANY > 0 */
#if CANFD_HOWMANY > 0
# include "r_canfd.h"
typedef struct canfd_irq {
canfd_instance_ctrl_t * ctrl;
can_cfg_t * cfg;
} CanFdIrqReq_t;
#define CANFD_INTERRUPT_COUNT 3
#endif /* CANFD_HOWMANY > 0 */
#define SD_INTERRUPT_COUNT 2
typedef struct usb {
uint32_t num_of_irqs_required;
uint32_t address_of_handler;
uint32_t first_irq_number;
} USBIrqCfg_t;
typedef struct timer {
timer_cfg_t *base_cfg;
gpt_extended_cfg_t *gpt_ext_cfg;
agt_extended_cfg_t *agt_ext_cfg;
} TimerIrqCfg_t;
typedef struct genericIrq {
IRQn_Type irq;
uint8_t ipl;
elc_event_t event;
} GenericIrqCfg_t;
#ifdef __cplusplus
extern "C" {
#endif
/* ISR prototypes */
void iic_master_rxi_isr(void);
void iic_master_txi_isr(void);
void iic_master_tei_isr(void);
void iic_master_eri_isr(void);
void spi_rxi_isr(void);
void spi_txi_isr(void);
void spi_tei_isr(void);
void spi_eri_isr(void);
void r_icu_isr(void);
void usbfs_interrupt_handler(void);
void usbfs_resume_handler(void);
void usbfs_d0fifo_handler(void);
void usbfs_d1fifo_handler(void);
void rtc_alarm_periodic_isr(void);
void rtc_carry_isr(void);
void agt_int_isr(void);
void sci_spi_rxi_isr(void);
void sci_spi_txi_isr(void);
void sci_spi_tei_isr(void);
void sci_spi_eri_isr(void);
void sci_i2c_rxi_isr(void);
void sci_i2c_txi_isr(void);
void sci_i2c_tei_isr(void);
void sci_uart_txi_isr(void);
void sci_uart_tei_isr(void);
void sci_uart_rxi_isr(void);
void sci_uart_eri_isr(void);
void iic_slave_rxi_isr(void);
void iic_slave_txi_isr(void);
void iic_slave_tei_isr(void);
void iic_slave_eri_isr(void);
void gpt_counter_overflow_isr(void);
void gpt_capture_a_isr(void);
void gpt_capture_b_isr(void);
void gpt_counter_underflow_isr(void);
void agt_int_isr(void);
void adc_scan_end_isr (void);
void adc_scan_end_b_isr (void);
void adc_window_compare_isr (void);
void dmac_int_isr(void);
void can_error_isr(void);
void can_rx_isr(void);
void can_tx_isr(void);
void ether_eint_isr (void);
void canfd_error_isr(void);
void canfd_rx_fifo_isr(void);
void canfd_channel_tx_isr(void);
void sdhimmc_dma_req_isr(void);
void sdhimmc_accs_isr(void);
void sdhimmc_card_isr(void);
#ifdef __cplusplus
}
#endif
using Irq_f = void (*)(void);
class IRQManager {
public:
bool addPeripheral(Peripheral_t p, void *cfg);
static IRQManager& getInstance();
#ifdef HAS_DMAC
/* add DMA interrupt. Channels from 0 to 4 for R4, from 0 to 7 on R6
if fnc is nullptr the standard dmac_int_isr is added
otherwise fnc is the interrupt handler function
it returns true if the interrupt is correctly added */
bool addDMA(dmac_extended_cfg_t &cfg, Irq_f fnc = nullptr);
#endif
bool addGenericInterrupt(GenericIrqCfg_t &cfg, Irq_f fnc = nullptr);
bool addTimerOverflow(TimerIrqCfg_t &cfg, Irq_f fnc = nullptr);
bool addTimerUnderflow(TimerIrqCfg_t &cfg, Irq_f fnc = nullptr);
bool addTimerCompareCaptureA(TimerIrqCfg_t &cfg, Irq_f fnc = nullptr);
bool addTimerCompareCaptureB(TimerIrqCfg_t &cfg, Irq_f fnc = nullptr);
bool addADCScanEnd(ADC_Container *adc, Irq_f fnc = nullptr);
bool addADCScanEndB(ADC_Container *adc, Irq_f fnc = nullptr);
bool addADCWinCmpA(ADC_Container *adc, Irq_f fnc = nullptr);
bool addADCWinCmpB(ADC_Container *adc, Irq_f fnc = nullptr);
IRQManager(IRQManager const&) = delete;
void operator=(IRQManager const&) = delete;
~IRQManager();
private:
size_t last_interrupt_index;
bool set_adc_end_link_event(int li, int ch);
bool set_adc_end_b_link_event(int li, int ch);
bool set_adc_win_a_link_event(int li, int ch);
bool set_adc_win_b_link_event(int li, int ch);
void set_sci_tx_link_event(int li, int ch);
void set_sci_rx_link_event(int li, int ch);
void set_sci_tei_link_event(int li, int ch);
void set_sci_eri_link_event(int li, int ch);
void set_iic_tx_link_event(int li, int ch);
void set_iic_rx_link_event(int li, int ch);
void set_iic_tei_link_event(int li, int ch);
void set_iic_eri_link_event(int li, int ch);
void set_ext_link_event(int li, int ch);
bool set_agt_link_event(int li, int ch);
bool set_gpt_over_link_event(int li, int ch);
bool set_gpt_under_link_event(int li, int ch);
bool set_gpt_compare_capture_A_link_event(int li, int ch);
bool set_gpt_compare_capture_B_link_event(int li, int ch);
void set_spi_tx_link_event(int li, int ch);
void set_spi_rx_link_event(int li, int ch);
void set_spi_tei_link_event(int li, int ch);
void set_spi_eri_link_event(int li, int ch);
void set_can_error_link_event(int li, int ch);
void set_can_rx_link_event(int li, int ch);
void set_can_tx_link_event(int li, int ch);
void set_canfd_error_link_event(int li, int ch);
void set_canfd_rx_link_event(int li, int ch);
void set_canfd_tx_link_event(int li, int ch);
bool set_dma_link_event(int li, int ch);
IRQManager();
};
#endif