1 /* 2 * RTC (real-time clock) support for various devices. 3 * 4 * Copyright (C) 2023, 2024 Paul Boddie <paul@boddie.org.uk> 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License as 8 * published by the Free Software Foundation; either version 2 of 9 * the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 * Boston, MA 02110-1301, USA 20 */ 21 22 #pragma once 23 24 #ifdef __cplusplus 25 26 // Register locations. 27 28 enum Regs : unsigned 29 { 30 Rtc_control = 0x000, // RTCCR 31 Rtc_seconds = 0x004, // RTCSR 32 Rtc_alarm_seconds = 0x008, // RTCSAR 33 Rtc_regulator = 0x00c, // RTCGR 34 35 Hibernate_control = 0x020, // HCR 36 Hibernate_wakeup_filter_counter = 0x024, // HWFCR 37 Hibernate_reset_counter = 0x028, // HRCR 38 Hibernate_wakeup_control = 0x02c, // HWCR 39 Hibernate_wakeup_status = 0x030, // HWRSR 40 Hibernate_scratch_pattern = 0x034, // HSPR 41 Hibernate_write_enable_pattern = 0x03c, // WENR 42 Hibernate_wakeup_pin_configure = 0x048, // WKUPPINCR 43 }; 44 45 // Field definitions. 46 47 enum Control_bits : unsigned 48 { 49 Control_write_ready = 0x80, // WRDY 50 Control_1Hz = 0x40, // 1HZ 51 Control_1Hz_irq_enable = 0x20, // 1HZIE 52 Control_alarm = 0x10, // AF 53 Control_alarm_irq_enable = 0x08, // AIE 54 Control_alarm_enable = 0x04, // AE 55 Control_external_divided = 0x02, // SELEXC (JZ4780) 56 Control_rtc_enable = 0x01, // RTCE 57 }; 58 59 enum Regulator_bits : unsigned 60 { 61 Regulator_lock = 0x80000000, // LOCK 62 Regulator_adjust_count_mask = 0x03ff0000, // ADJC 63 Regulator_1Hz_cycle_count_mask = 0x0000ffff, // NC1HZ 64 }; 65 66 enum Regulator_limits : unsigned 67 { 68 Regulator_adjust_count_limit = 0x03ff, // ADJC 69 Regulator_1Hz_cycle_count_limit = 0xffff, // NC1HZ 70 }; 71 72 enum Regulator_shifts : unsigned 73 { 74 Regulator_adjust_count_shift = 16, // ADJC 75 Regulator_1Hz_cycle_count_shift = 0, // NC1HZ 76 }; 77 78 enum Hibernate_control_bits : unsigned 79 { 80 Hibernate_power_down = 0x01, // PD 81 }; 82 83 enum Hibernate_wakeup_filter_counter_bits : unsigned 84 { 85 Wakeup_minimum_time_mask = 0xffe0, // HWFCR 86 }; 87 88 enum Hibernate_reset_counter_bits : unsigned 89 { 90 Reset_assert_time_mask = 0x7800, // HRCR 91 }; 92 93 enum Hibernate_wakeup_control_bits : unsigned 94 { 95 Power_detect_enable_mask = 0xfffffff8, // EPDET 96 Rtc_alarm_wakeup_enable = 0x00000001, // EALM 97 }; 98 99 enum Hibernate_wakeup_status_bits : unsigned 100 { 101 Accident_power_down = 0x0100, // APD 102 Hibernate_reset = 0x0020, // HR 103 Pad_pin_reset = 0x0010, // PPR 104 Wakeup_pin_status = 0x0002, // PIN 105 Rtc_alarm_status = 0x0001, // ALM 106 }; 107 108 enum Hibernate_write_enable_pattern_bits : unsigned 109 { 110 Write_enable_status = 0x80000000, // WEN 111 Write_enable_pattern_mask = 0x0000ffff, // WENPAT 112 Write_enable_pattern = 0x0000a55a, // WENPAT 113 }; 114 115 enum Hibernate_wakeup_pin_configure_bits : unsigned 116 { 117 Rtc_oscillator_test_enable = 0x00080000, // OSC_TE 118 Oscillator_xtclk_rtclk = 0x00040000, // OSC_RETON 119 Oscillator_xtclk_low = 0x00000000, // OSC_RETON 120 Rtc_internal_oscillator_enable = 0x00010000, // OSC_EN 121 Wakeup_pin_extended_press_mask = 0x000000f0, // P_JUD_LEN 122 Wakeup_pin_extended_press_enable = 0x0000000f, // P_RST_LEN 123 }; 124 125 #endif /* __cplusplus */