hw/rtc: Add RTC PCF8563 module
PATCH v3 1/1 hw/rtc: Add RTC PCF8563 module
Add PCF8563 a real-time clock with calendar and I2C interface. This commit adds support for interfacing with it and implements functionality of setting timer, alarm, reading and writing time.
Add a unit test for pcf8563_rtc module, that checks:
- default value after initialization
- set/get time
- minute alarm
- hour alarm
- day alarm
- wday alarm
- minute & hour alarm
- minute & day alarm
- day & wday alarm
- timer
---v2->v3
Bernhard:
- Fix typo in test header comment section
- Move defines and pcf8563 struct to the header
- Merge test and production code patches
- Remove casting from void*
- Fix pcf8563 reset according datasheet
- Remove pcf8563_reset from pcf8563_init
- Inline pcf8563_reset inside pcf8563_reset_hold
--- hw/rtc/Kconfig | 5 + hw/rtc/meson.build | 1 + hw/rtc/pcf8563_rtc.c | 665 +++++++++++++++++++++++++++++++++++ hw/rtc/trace-events | 12 + include/hw/rtc/pcf8563_rtc.h | 80 +++++ tests/qtest/meson.build | 1 + tests/qtest/pcf8563-test.c | 466 ++++++++++++++++++++++++ 7 files changed, 1230 insertions(+) create mode 100644 hw/rtc/pcf8563_rtc.c create mode 100644 include/hw/rtc/pcf8563_rtc.h create mode 100644 tests/qtest/pcf8563-test.c
hw/rtc/Kconfig +5 -0
@@ -27,5 +27,10 @@ config GOLDFISH_RTC config LS7A_RTC bool +config PCF8563_RTC + bool + depends on I2C + default y if I2C_DEVICES + config STM32_RTC bool
hw/rtc/meson.build +1 -0
@@ -13,4 +13,5 @@ system_ss.add(when: 'CONFIG_GOLDFISH_RTC', if_true: files('goldfish_rtc.c')) system_ss.add(when: 'CONFIG_LS7A_RTC', if_true: files('ls7a_rtc.c')) system_ss.add(when: 'CONFIG_ALLWINNER_H3', if_true: files('allwinner-rtc.c')) system_ss.add(when: 'CONFIG_MC146818RTC', if_true: files('mc146818rtc.c')) +system_ss.add(when: 'CONFIG_PCF8563_RTC', if_true: files('pcf8563_rtc.c')) system_ss.add(when: 'CONFIG_STM32_RTC', if_true: files('stm32-rtc.c'))
hw/rtc/pcf8563_rtc.c new file +665 -0
665 lines not on this page · raw message
hw/rtc/trace-events +12 -0
@@ -43,3 +43,15 @@ stm32_rtc_arm_ointr(uint64_t tocks, uint64_t nsecs) "overflow interrupt in %" PR stm32_rtc_arm_aintr(uint64_t tocks, uint64_t nsecs) "alarm interrupt in %" PRIu64 " ticks, %" PRIu64" nsecs" stm32_rtc_read(uint64_t addr, uint64_t value, uint32_t size) "addr 0x%02" PRIx64 " value 0x%08" PRIx64" size %u" stm32_rtc_write(uint64_t addr, uint64_t value, uint32_t size) "addr 0x%02" PRIx64 " value 0x%08" PRIx64" size %u" + +# pcf8563_rtc.c +pcf8563_rtc_write_data(uint8_t data) "data: 0x%x" +pcf8563_rtc_write_addr(uint8_t addr) "register address: 0x%x" +pcf8563_rtc_read(uint8_t addr, uint8_t data) "addr: 0x%x, data: 0x%x" +pcf8563_rtc_event(uint8_t event) "Event: 0x%x" +pcf8563_rtc_init(void) +pcf8563_rtc_reset(void) +pcf8563_rtc_set_time(void) +pcf8563_rtc_get_time(void) +pcf8563_rtc_set_alarm(void) +pcf8563_rtc_capture_time(void)
include/hw/rtc/pcf8563_rtc.h new file +80 -0
80 lines not on this page · raw message
tests/qtest/meson.build +1 -0
@@ -293,6 +293,7 @@ qos_test_ss.add( 'tulip-test.c', 'nvme-test.c', 'pca9552-test.c', + 'pcf8563-test.c', 'pci-test.c', 'pcnet-test.c', 'sdhci-test.c',
tests/qtest/pcf8563-test.c new file +466 -0
466 lines not on this page · raw message
Signature · 1 line
2.34.1