15 #include "rv_timer_regs.h"
17 static_assert(RV_TIMER_INTR_STATE0_IS_0_BIT == RV_TIMER_INTR_ENABLE0_IE_0_BIT,
18 "Expected IRQ bit offsets to match across STATE/ENABLE regs.");
19 static_assert(RV_TIMER_INTR_STATE0_IS_0_BIT == RV_TIMER_INTR_TEST0_T_0_BIT,
20 "Expected IRQ bit offsets to match across STATE/ENABLE regs.");
25 if (rv_timer == NULL) {
36 if (rv_timer == NULL) {
43 alert_idx = RV_TIMER_ALERT_TEST_FATAL_FAULT_BIT;
51 (ptrdiff_t)RV_TIMER_ALERT_TEST_REG_OFFSET,
57 typedef enum dif_rv_timer_intr_reg {
58 kDifRvTimerIntrRegState = 0,
59 kDifRvTimerIntrRegEnable = 1,
60 kDifRvTimerIntrRegTest = 2,
61 } dif_rv_timer_intr_reg_t;
63 static bool rv_timer_get_irq_reg_offset(dif_rv_timer_intr_reg_t intr_reg,
65 uint32_t *intr_reg_offset) {
67 case kDifRvTimerIntrRegState:
70 *intr_reg_offset = RV_TIMER_INTR_STATE0_REG_OFFSET;
76 case kDifRvTimerIntrRegEnable:
79 *intr_reg_offset = RV_TIMER_INTR_ENABLE0_REG_OFFSET;
85 case kDifRvTimerIntrRegTest:
88 *intr_reg_offset = RV_TIMER_INTR_TEST0_REG_OFFSET;
108 *index_out = RV_TIMER_INTR_STATE0_IS_0_BIT;
125 if (rv_timer == NULL || type == NULL ||
130 *type = irq_types[irq];
139 if (rv_timer == NULL || snapshot == NULL) {
145 *snapshot = mmio_region_read32(
146 rv_timer->
base_addr, (ptrdiff_t)RV_TIMER_INTR_STATE0_REG_OFFSET);
160 if (rv_timer == NULL) {
167 (ptrdiff_t)RV_TIMER_INTR_STATE0_REG_OFFSET, snapshot);
181 if (rv_timer == NULL || is_pending == NULL) {
186 if (!rv_timer_get_irq_bit_index(irq, &index)) {
190 uint32_t reg_offset = 0;
191 if (!rv_timer_get_irq_reg_offset(kDifRvTimerIntrRegState, irq, ®_offset)) {
194 uint32_t intr_state_reg =
195 mmio_region_read32(rv_timer->
base_addr, (ptrdiff_t)reg_offset);
205 if (rv_timer == NULL) {
213 (ptrdiff_t)RV_TIMER_INTR_STATE0_REG_OFFSET,
227 if (rv_timer == NULL) {
232 if (!rv_timer_get_irq_bit_index(irq, &index)) {
238 uint32_t reg_offset = 0;
239 if (!rv_timer_get_irq_reg_offset(kDifRvTimerIntrRegState, irq, ®_offset)) {
242 mmio_region_write32(rv_timer->
base_addr, (ptrdiff_t)reg_offset,
251 if (rv_timer == NULL) {
256 if (!rv_timer_get_irq_bit_index(irq, &index)) {
261 uint32_t reg_offset = 0;
262 if (!rv_timer_get_irq_reg_offset(kDifRvTimerIntrRegTest, irq, ®_offset)) {
265 mmio_region_write32(rv_timer->
base_addr, (ptrdiff_t)reg_offset,
275 if (rv_timer == NULL || state == NULL) {
280 if (!rv_timer_get_irq_bit_index(irq, &index)) {
284 uint32_t reg_offset = 0;
285 if (!rv_timer_get_irq_reg_offset(kDifRvTimerIntrRegEnable, irq,
289 uint32_t intr_enable_reg =
290 mmio_region_read32(rv_timer->
base_addr, (ptrdiff_t)reg_offset);
302 if (rv_timer == NULL) {
307 if (!rv_timer_get_irq_bit_index(irq, &index)) {
311 uint32_t reg_offset = 0;
312 if (!rv_timer_get_irq_reg_offset(kDifRvTimerIntrRegEnable, irq,
316 uint32_t intr_enable_reg =
317 mmio_region_read32(rv_timer->
base_addr, (ptrdiff_t)reg_offset);
321 mmio_region_write32(rv_timer->
base_addr, (ptrdiff_t)reg_offset,
331 if (rv_timer == NULL) {
336 if (snapshot != NULL) {
339 *snapshot = mmio_region_read32(
340 rv_timer->
base_addr, (ptrdiff_t)RV_TIMER_INTR_ENABLE0_REG_OFFSET);
352 (ptrdiff_t)RV_TIMER_INTR_ENABLE0_REG_OFFSET, 0u);
366 if (rv_timer == NULL || snapshot == NULL) {
373 (ptrdiff_t)RV_TIMER_INTR_ENABLE0_REG_OFFSET,