Skip to content

Commit

Permalink
DA1469x: Clock time shifts on reboots (apache#3321)
Browse files Browse the repository at this point in the history
- Add missing services to the driver API. It also makes the
actual calibration of the XTAL32K clock a syscfg option, defaulting to 0.
- Eliminate magic numbers
- Streamline the LP clock API, by offering clean access to the
LP clock selected via syscfg.
- Add the function that calculates the RTC divider registers and
invoke it when the LP clock frequency changes.
- Fix slightly incorrect time-keeping
If the LP clock's frequency is not an integer multiple of the specified OS tick
frequency, the period of OS ticks will be incorrect due to an integer division
truncation error (to the tune of almost 1% for RCX), resulting in OS Time
gradually creeping away from the actual time. This commit fixes the issue, by
maintaining the fractional OS tick value and advancing OS Time accordingly.
  • Loading branch information
apc067 authored Oct 29, 2024
1 parent c0caa90 commit 64e8e16
Show file tree
Hide file tree
Showing 8 changed files with 359 additions and 80 deletions.
59 changes: 57 additions & 2 deletions hw/mcu/dialog/da1469x/include/mcu/da1469x_clock.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,21 @@ void da1469x_clock_sys_xtal32m_switch_safe(void);
*/
void da1469x_clock_sys_rc32m_disable(void);

/**
* Enable RC32M
*/
void da1469x_clock_sys_rc32m_enable(void);

/**
* Switch sys_clk to RC32M
*/
void da1469x_clock_sys_rc32m_switch(void);

/**
* Disable XTAL32K
*/
void da1469x_clock_lp_xtal32k_disable(void);

/**
* Enable XTAL32K
*/
Expand All @@ -73,6 +88,21 @@ void da1469x_clock_lp_xtal32k_enable(void);
*/
void da1469x_clock_lp_xtal32k_switch(void);

/**
* Disable RC32K
*/
void da1469x_clock_lp_rc32k_disable(void);

/**
* Enable RC32K
*/
void da1469x_clock_lp_rc32k_enable(void);

/**
* Switch lp_clk to RC32K
*/
void da1469x_clock_lp_rc32k_switch(void);

/**
* Enable RCX
*/
Expand All @@ -95,10 +125,20 @@ void da1469x_clock_lp_rcx_calibrate(void);
*/
void da1469x_clock_lp_rc32k_calibrate(void);

/**
* Calibrate XTAL32K
*/
void da1469x_clock_lp_xtal32k_calibrate(void);

/**
* Calibrate selected LP clock
*/
void da1469x_clock_lp_calibrate(void);

/**
* Calibrate RC32M
*/
void da1469x_clock_lp_rc32m_calibrate(void);
void da1469x_clock_sys_rc32m_calibrate(void);

/**
* Get calibrated (measured) RCX frequency
Expand All @@ -110,16 +150,31 @@ uint32_t da1469x_clock_lp_rcx_freq_get(void);
*/
uint32_t da1469x_clock_lp_rc32k_freq_get(void);

/**
* Get calibrated XTAL32K frequency
*/
uint32_t da1469x_clock_lp_xtal32k_freq_get(void);

/**
* Get seleted LP clock's frequency
*/
uint32_t da1469x_clock_lp_freq_get(void);

/**
* Get calibrated (measured) RC32M frequency
*/
uint32_t da1469x_clock_lp_rc32m_freq_get(void);
uint32_t da1469x_clock_sys_rc32m_freq_get(void);

/**
* Disable RCX
*/
void da1469x_clock_lp_rcx_disable(void);

/**
* Set the RTC dividers
*/
void da1469x_clock_lp_set_rtc_divs(uint32_t rtc_clock_freq);

/**
* Enable AMBA clock(s)
*
Expand Down
7 changes: 7 additions & 0 deletions hw/mcu/dialog/da1469x/include/mcu/da1469x_hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ extern const int qspi_flash_config_array_size;

const struct qspi_flash_config *da1469x_qspi_get_config(void);

/**
* Calculate the OS tick parameters.
*
* @param cycles_per_sec Input frequency of timer generating OS ticks
*/
void hal_os_tick_calc_params(uint32_t cycles_per_sec);

#ifdef __cplusplus
}
#endif
Expand Down
3 changes: 3 additions & 0 deletions hw/mcu/dialog/da1469x/include/mcu/da1469x_lpclk.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ void da1469x_lpclk_register_cmac_cb(da1469x_lpclk_cb *cb);
void da1469x_lpclk_enabled(void);
/* Frequency of lp clock changed (e.g. after RCX recalibration) */
void da1469x_lpclk_updated(void);
/* Initialize selected LP RC clock */
void da1469x_lpclk_rc_init();


#ifdef __cplusplus
}
Expand Down
Loading

0 comments on commit 64e8e16

Please sign in to comment.