Skip to content

Commit

Permalink
hw/misc: implement RTC CNTL scratch registers properly on the ESP32-C…
Browse files Browse the repository at this point in the history
…3 target

Implement the scratch registers in RTC CTNL controller for the ESP32-C3 brings
support to Real-Time clock in ESP-IDF applications.
  • Loading branch information
o-marshmallow committed Dec 12, 2023
1 parent 3a2d76b commit f5de023
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
33 changes: 29 additions & 4 deletions hw/misc/esp32c3_rtc_cntl.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,24 @@ static uint64_t esp32c3_rtc_cntl_read(void* opaque, hwaddr addr, unsigned int si
case A_RTC_CNTL_RTC_RESET_STATE:
r = s->reason;
break;

case A_RTC_CNTL_RTC_STORE0:
case A_RTC_CNTL_RTC_STORE1:
case A_RTC_CNTL_RTC_STORE2:
case A_RTC_CNTL_RTC_STORE3:
r = s->scratch_reg[(addr - A_RTC_CNTL_RTC_STORE0) / 4];
break;

case A_RTC_CNTL_RTC_STORE4:
/* XTAL frequency: 40MHz, must be in both upper and lower half-word */
r = 0x00280028;
case A_RTC_CNTL_RTC_STORE5:
case A_RTC_CNTL_RTC_STORE6:
case A_RTC_CNTL_RTC_STORE7:
r = s->scratch_reg[(addr - A_RTC_CNTL_RTC_STORE4) / 4 + 4];
break;
default:
#if RTCCNTL_WARNING
/* Other registers are not supported yet */
warn_report("[RTCCNTL] Unsupported read to %08lx\n", addr);
warn_report("[RTCCNTL] Unsupported read to %08lx", addr);
#endif
break;
}
Expand All @@ -81,10 +91,25 @@ static void esp32c3_rtc_cntl_write(void* opaque, hwaddr addr, uint64_t value, un
esp32c3_reset_request(opaque, ESP32C3_RTC_SW_CPU_RESET, 1);
}
break;

case A_RTC_CNTL_RTC_STORE0:
case A_RTC_CNTL_RTC_STORE1:
case A_RTC_CNTL_RTC_STORE2:
case A_RTC_CNTL_RTC_STORE3:
s->scratch_reg[(addr - A_RTC_CNTL_RTC_STORE0) / 4] = value;
break;

case A_RTC_CNTL_RTC_STORE4:
case A_RTC_CNTL_RTC_STORE5:
case A_RTC_CNTL_RTC_STORE6:
case A_RTC_CNTL_RTC_STORE7:
s->scratch_reg[(addr - A_RTC_CNTL_RTC_STORE4) / 4 + 4] = value;
break;

default:
#if RTCCNTL_WARNING
/* Other registers are not supported yet */
warn_report("[RTCCNTL] Unsupported write to %08lx (%08lx)\n", addr, value);
warn_report("[RTCCNTL] Unsupported write to %08lx (%08lx)", addr, value);
#endif
break;
}
Expand Down
3 changes: 3 additions & 0 deletions include/hw/misc/esp32c3_rtc_cntl.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,15 @@ typedef enum ESP32C3ResetReason {
ESP32C3_COUNT_RESET = 24
} ESP32C3ResetReason;

#define ESP32C3_RTC_CNTL_SCRATCH_REG_COUNT 8

typedef struct ESP32C3RtcCntlState {
SysBusDevice parent_obj;
MemoryRegion iomem;

uint32_t options0;
uint32_t scratch_reg[ESP32C3_RTC_CNTL_SCRATCH_REG_COUNT];

ESP32C3ResetReason reason;
/* IRQ used to notify the machine that we need a reset */
qemu_irq cpu_reset;
Expand Down

0 comments on commit f5de023

Please sign in to comment.