From: Nathael Pajani Date: Mon, 3 Oct 2016 15:05:03 +0000 (+0200) Subject: Add a define for RTC callback installation retry delay. X-Git-Url: http://git.techno-innov.fr/?a=commitdiff_plain;h=61962f33519cfb1efd256ee75fe2bd3a98f800ff;p=soft%2Flpc122x%2Fcore Add a define for RTC callback installation retry delay. --- diff --git a/drivers/rtc.c b/drivers/rtc.c index f43163e..a15f12f 100644 --- a/drivers/rtc.c +++ b/drivers/rtc.c @@ -125,7 +125,7 @@ void rtc_set_date(uint32_t date) * If periodic is 1 then the rtc match register will be updated after the interrupt * has been handled by adding the offset. * If date is set, the match register will be set to date. (regardless of the periodic - * argument, wich allows to have the first interrupt at a given date, and the following + * argument, which allows to have the first interrupt at a given date, and the following * ones at a period set by the offset argument. * If date is 0, then the match register is set to current date + offset. * return -1 if RTC is not started and synced @@ -168,6 +168,11 @@ void setup_callback(uint32_t ticks) * periodic interrupts. 'period' is a number of RTC counter increments. * Return a positive integer if registration is OK and callback has a chance of being called. * Return a negative integer if the match configuration was not possible. + * Note : + * The callback becomes active only after the RTC starts returning valid data. set_rtc_callback() + * takes care of waiting for this event by installing a systick callback which tries to setup the + * RTC callback every RTC_CB_INST_RETRY_MS milli-seconds. This systick callback will be removed + * once the RTC callback is installed. */ int set_rtc_callback(void (*callback) (uint32_t), uint32_t when, uint32_t period) { @@ -180,7 +185,8 @@ int set_rtc_callback(void (*callback) (uint32_t), uint32_t when, uint32_t period rtc_set_match(when, period, ((period == 0) ? 0 : 1)); } else { /* Add callback for "config later" */ - ret = add_systick_callback(&setup_callback, (3000 / systick_get_tick_ms_period())); + uint32_t retry_period = (RTC_CB_INST_RETRY_MS / systick_get_tick_ms_period()); + ret = add_systick_callback(&setup_callback, retry_period); match_first = when; periodic_match = ((period == 0) ? 0 : 1); rtc_match_period = period; diff --git a/include/drivers/rtc.h b/include/drivers/rtc.h index b817547..e2b9a4c 100644 --- a/include/drivers/rtc.h +++ b/include/drivers/rtc.h @@ -46,7 +46,7 @@ uint32_t rtc_get_count(void); /* In case someone wants the RTC to count something different from seconds * No need to call this function if you only want to count seconds, this is the default. - * source selection values are defined in lpc_regs_12xx.h + * source selection values are defined below. * clk_div is only usefull when selected clock source is PCLK (peripheral clock). Use value * betwween 1 and 255 included. */ @@ -70,7 +70,7 @@ void rtc_set_date(uint32_t date); * If periodic is 1 then the rtc match register will be updated after the interrupt * has been handled by adding the offset. * If date is set, the match register will be set to date. (regardless of the periodic - * argument, wich allows to have the first interrupt at a given date, and the following + * argument, which allows to have the first interrupt at a given date, and the following * ones at a period set by the offset argument. * If date is 0, then the match register is set to current date + offset. * return -1 if RTC is not started and synced. @@ -82,7 +82,13 @@ int rtc_set_match(uint32_t date, uint32_t offset, uint8_t periodic); * periodic interrupts. 'period' is a number of RTC counter increments. * Return a positive integer if registration is OK and callback has a chance of being called. * Return a negative integer if the match configuration was not possible. + * Note : + * The callback becomes active only after the RTC starts returning valid data. set_rtc_callback() + * takes care of waiting for this event by installing a systick callback which tries to setup the + * RTC callback every RTC_CB_INST_RETRY_MS milli-seconds. This systick callback will be removed + * once the RTC callback is installed. */ +#define RTC_CB_INST_RETRY_MS 500 int set_rtc_callback(void (*callback) (uint32_t), uint32_t when, uint32_t period); void remove_rtc_callback();