mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
cpu/atmega_common: RTC: implement rtc_get_time_ms()
This commit is contained in:
parent
40d952bceb
commit
7c1b5630d2
@ -20,6 +20,7 @@ config CPU_COMMON_ATMEGA
|
||||
select HAS_PERIPH_GPIO
|
||||
select HAS_PERIPH_GPIO_IRQ
|
||||
select HAS_PERIPH_PM
|
||||
select HAS_PERIPH_RTC_MS
|
||||
select HAS_PERIPH_RTT_SET_COUNTER
|
||||
select HAS_PERIPH_TIMER_PERIODIC
|
||||
select HAS_PERIPH_WDT
|
||||
|
@ -10,6 +10,7 @@ FEATURES_PROVIDED += periph_cpuid
|
||||
FEATURES_PROVIDED += periph_eeprom
|
||||
FEATURES_PROVIDED += periph_gpio periph_gpio_irq
|
||||
FEATURES_PROVIDED += periph_pm
|
||||
FEATURES_PROVIDED += periph_rtc_ms
|
||||
FEATURES_PROVIDED += periph_rtt_set_counter
|
||||
FEATURES_PROVIDED += periph_timer_periodic
|
||||
FEATURES_PROVIDED += periph_wdt
|
||||
|
@ -102,6 +102,28 @@ int rtc_get_time(struct tm *time)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int rtc_get_time_ms(struct tm *time, uint16_t *ms)
|
||||
{
|
||||
uint8_t cnt_before, cnt_after;
|
||||
|
||||
/* loop in case of overflow */
|
||||
do {
|
||||
cnt_before = TCNT2;
|
||||
|
||||
/* prevent compiler from reordering memory access to tm_now,
|
||||
* including moving it out of the loop
|
||||
*/
|
||||
__asm__ volatile ("" : : : "memory");
|
||||
*time = tm_now;
|
||||
|
||||
cnt_after = TCNT2;
|
||||
} while (cnt_before > cnt_after);
|
||||
|
||||
*ms = (cnt_after * 1000UL) >> 8;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int rtc_get_alarm(struct tm *time)
|
||||
{
|
||||
*time = tm_alarm;
|
||||
|
Loading…
Reference in New Issue
Block a user