Skip to content

Commit

Permalink
Add delay after RTC write (Makes this compatible with EZO)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lorenzooone committed Nov 19, 2023
1 parent b943cf3 commit 1d3460c
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions source/rtc.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@
#define TIME_MASK (0x007F7F9F)
#define DATE_MASK (0x073F1FFF)

// Amount of iterations to wait after writing the data,
// before touching other RTC-related registers. Dependant on optimization level
#define TIMEOUT_WAIT_AFTER_WRITE 448

/* Compiler hacks */
#define assume(cond) do { if (!(cond)) __builtin_unreachable(); } while (0)
#define unlikely(cond) __builtin_expect(!!(cond), 0)
Expand Down Expand Up @@ -138,6 +142,8 @@ static void rtc_cmd_arg(const unsigned int cmd, unsigned int data, unsigned int

assume(len > 0 && len <= 32);
rtc_write(data, len);

for(volatile int a = 0; a < TIMEOUT_WAIT_AFTER_WRITE; a++);
}

static void rtc_cmd_arg_datetime(unsigned int cmd, __agbabi_datetime_t datetime, int is_12hr) {
Expand All @@ -148,6 +154,8 @@ static void rtc_cmd_arg_datetime(unsigned int cmd, __agbabi_datetime_t datetime,

rtc_write(date, 32);
rtc_write(time, 24);

for(volatile int a = 0; a < TIMEOUT_WAIT_AFTER_WRITE; a++);
}

static void rtc_reset(void) {
Expand Down

0 comments on commit 1d3460c

Please sign in to comment.