Skip to content

Commit f5de023

Browse files
committed
hw/misc: implement RTC CNTL scratch registers properly on the ESP32-C3 target
Implement the scratch registers in RTC CTNL controller for the ESP32-C3 brings support to Real-Time clock in ESP-IDF applications.
1 parent 3a2d76b commit f5de023

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

hw/misc/esp32c3_rtc_cntl.c

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,24 @@ static uint64_t esp32c3_rtc_cntl_read(void* opaque, hwaddr addr, unsigned int si
4848
case A_RTC_CNTL_RTC_RESET_STATE:
4949
r = s->reason;
5050
break;
51+
52+
case A_RTC_CNTL_RTC_STORE0:
53+
case A_RTC_CNTL_RTC_STORE1:
54+
case A_RTC_CNTL_RTC_STORE2:
55+
case A_RTC_CNTL_RTC_STORE3:
56+
r = s->scratch_reg[(addr - A_RTC_CNTL_RTC_STORE0) / 4];
57+
break;
58+
5159
case A_RTC_CNTL_RTC_STORE4:
52-
/* XTAL frequency: 40MHz, must be in both upper and lower half-word */
53-
r = 0x00280028;
60+
case A_RTC_CNTL_RTC_STORE5:
61+
case A_RTC_CNTL_RTC_STORE6:
62+
case A_RTC_CNTL_RTC_STORE7:
63+
r = s->scratch_reg[(addr - A_RTC_CNTL_RTC_STORE4) / 4 + 4];
5464
break;
5565
default:
5666
#if RTCCNTL_WARNING
5767
/* Other registers are not supported yet */
58-
warn_report("[RTCCNTL] Unsupported read to %08lx\n", addr);
68+
warn_report("[RTCCNTL] Unsupported read to %08lx", addr);
5969
#endif
6070
break;
6171
}
@@ -81,10 +91,25 @@ static void esp32c3_rtc_cntl_write(void* opaque, hwaddr addr, uint64_t value, un
8191
esp32c3_reset_request(opaque, ESP32C3_RTC_SW_CPU_RESET, 1);
8292
}
8393
break;
94+
95+
case A_RTC_CNTL_RTC_STORE0:
96+
case A_RTC_CNTL_RTC_STORE1:
97+
case A_RTC_CNTL_RTC_STORE2:
98+
case A_RTC_CNTL_RTC_STORE3:
99+
s->scratch_reg[(addr - A_RTC_CNTL_RTC_STORE0) / 4] = value;
100+
break;
101+
102+
case A_RTC_CNTL_RTC_STORE4:
103+
case A_RTC_CNTL_RTC_STORE5:
104+
case A_RTC_CNTL_RTC_STORE6:
105+
case A_RTC_CNTL_RTC_STORE7:
106+
s->scratch_reg[(addr - A_RTC_CNTL_RTC_STORE4) / 4 + 4] = value;
107+
break;
108+
84109
default:
85110
#if RTCCNTL_WARNING
86111
/* Other registers are not supported yet */
87-
warn_report("[RTCCNTL] Unsupported write to %08lx (%08lx)\n", addr, value);
112+
warn_report("[RTCCNTL] Unsupported write to %08lx (%08lx)", addr, value);
88113
#endif
89114
break;
90115
}

include/hw/misc/esp32c3_rtc_cntl.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,15 @@ typedef enum ESP32C3ResetReason {
4444
ESP32C3_COUNT_RESET = 24
4545
} ESP32C3ResetReason;
4646

47+
#define ESP32C3_RTC_CNTL_SCRATCH_REG_COUNT 8
4748

4849
typedef struct ESP32C3RtcCntlState {
4950
SysBusDevice parent_obj;
5051
MemoryRegion iomem;
5152

5253
uint32_t options0;
54+
uint32_t scratch_reg[ESP32C3_RTC_CNTL_SCRATCH_REG_COUNT];
55+
5356
ESP32C3ResetReason reason;
5457
/* IRQ used to notify the machine that we need a reset */
5558
qemu_irq cpu_reset;

0 commit comments

Comments
 (0)