@@ -229,24 +229,24 @@ static void LPTIM1_IRQHandler(void)
229229 if (__HAL_LPTIM_GET_IT_SOURCE (& LptimHandle , LPTIM_IT_CMPOK ) != RESET ) {
230230 __HAL_LPTIM_CLEAR_FLAG (& LptimHandle , LPTIM_FLAG_CMPOK );
231231 lp_cmpok = true;
232- if (sleep_manager_locked ) {
232+ if (sleep_manager_locked ) {
233233 sleep_manager_unlock_deep_sleep ();
234234 sleep_manager_locked = false;
235235 }
236- if (lp_delayed_prog ) {
237- if (roll_over_flag ) {
238- /* If we were close to the roll over of the ticker counter
239- * change current tick so it can be compared with buffer.
236+ if (lp_delayed_prog ) {
237+ if (roll_over_flag ) {
238+ /* If we were close to the roll over of the ticker counter
239+ * change current tick so it can be compared with buffer.
240240 * If this event got outdated fire interrupt right now,
241241 * else schedule it normally. */
242- if (lp_delayed_counter <= ((lp_ticker_read () + LP_TIMER_SAFE_GUARD + 1 ) & 0xFFFF )){
242+ if (lp_delayed_counter <= ((lp_ticker_read () + LP_TIMER_SAFE_GUARD + 1 ) & 0xFFFF )) {
243243 lp_ticker_fire_interrupt ();
244244 } else {
245245 lp_ticker_set_interrupt ((lp_delayed_counter - LP_TIMER_SAFE_GUARD - 1 ) & 0xFFFF );
246246 }
247247 roll_over_flag = false;
248248 } else {
249- if (future_event_flag && (lp_delayed_counter <= lp_ticker_read ())) {
249+ if (future_event_flag && (lp_delayed_counter <= lp_ticker_read ())) {
250250 /* If this event got outdated fire interrupt right now,
251251 * else schedule it normally. */
252252 lp_ticker_fire_interrupt ();
@@ -255,7 +255,7 @@ static void LPTIM1_IRQHandler(void)
255255 lp_ticker_set_interrupt (lp_delayed_counter );
256256 }
257257 }
258-
258+
259259 lp_delayed_prog = false;
260260 }
261261 }
@@ -284,7 +284,7 @@ uint32_t lp_ticker_read(void)
284284void lp_ticker_set_interrupt (timestamp_t timestamp )
285285{
286286 core_util_critical_section_enter ();
287-
287+
288288 timestamp_t last_read_counter = lp_ticker_read ();
289289
290290 /* Always store the last requested timestamp */
@@ -298,11 +298,10 @@ void lp_ticker_set_interrupt(timestamp_t timestamp)
298298 if (lp_cmpok == false) {
299299 /* if this is not safe to write, then delay the programing to the
300300 * time when CMPOK interrupt will trigger */
301-
301+
302302 /* If this target timestamp is close to the roll over of the ticker counter
303303 * and current tick is also close to the roll over, then we are in danger zone.*/
304- if (((0xFFFF - LP_TIMER_SAFE_GUARD < timestamp ) || (timestamp < LP_TIMER_SAFE_GUARD )) && (0xFFFA < last_read_counter ))
305- {
304+ if (((0xFFFF - LP_TIMER_SAFE_GUARD < timestamp ) || (timestamp < LP_TIMER_SAFE_GUARD )) && (0xFFFA < last_read_counter )) {
306305 roll_over_flag = true;
307306 /* Change the lp_delayed_counter buffer in that way so the value of (0xFFFF - LP_TIMER_SAFE_GUARD) is equal to 0.
308307 * By doing this it is easy to check if the value of timestamp get outdated by delaying its programming
@@ -315,7 +314,7 @@ void lp_ticker_set_interrupt(timestamp_t timestamp)
315314 } else {
316315 roll_over_flag = false;
317316 /* Check if event was meant to be in the past. */
318- if (lp_delayed_counter >= last_read_counter ) {
317+ if (lp_delayed_counter >= last_read_counter ) {
319318 future_event_flag = true;
320319 } else {
321320 future_event_flag = false;
@@ -324,18 +323,18 @@ void lp_ticker_set_interrupt(timestamp_t timestamp)
324323
325324 lp_delayed_prog = true;
326325 } else {
327-
326+
328327 lp_ticker_clear_interrupt ();
329328
330329 /* HW is not able to trig a very short term interrupt, that is
331330 * not less than few ticks away (LP_TIMER_SAFE_GUARD). So let's make sure it'
332331 * s at least current tick + LP_TIMER_SAFE_GUARD */
333- for (uint8_t i = 0 ; i < LP_TIMER_SAFE_GUARD ; i ++ ) {
332+ for (uint8_t i = 0 ; i < LP_TIMER_SAFE_GUARD ; i ++ ) {
334333 if (LP_TIMER_WRAP ((last_read_counter + i )) == timestamp ) {
335334 timestamp = LP_TIMER_WRAP ((timestamp + LP_TIMER_SAFE_GUARD ));
336335 }
337336 }
338-
337+
339338 /* Then check if this target timestamp is not in the past, or close to wrap-around
340339 * Let's assume last_read_counter = 0xFFFC, and we want to program timestamp = 0x100
341340 * The interrupt will not fire before the CMPOK flag is OK, so there are 2 cases:
@@ -347,7 +346,7 @@ void lp_ticker_set_interrupt(timestamp_t timestamp)
347346 * There might be crossing cases where it would also fire @ 0xFFFE, but by the time we read the counter,
348347 * it may already have moved to the next one, so for now we've taken this as margin of error.
349348 */
350- if ((timestamp < last_read_counter ) && (last_read_counter <= (0xFFFF - LP_TIMER_SAFE_GUARD ))) {
349+ if ((timestamp < last_read_counter ) && (last_read_counter <= (0xFFFF - LP_TIMER_SAFE_GUARD ))) {
351350 /* Workaround, because limitation */
352351 __HAL_LPTIM_COMPARE_SET (& LptimHandle , ~0 );
353352 } else {
@@ -360,7 +359,7 @@ void lp_ticker_set_interrupt(timestamp_t timestamp)
360359 lp_cmpok = false;
361360 /* Prevent from sleeping after compare register was set as we need CMPOK
362361 * interrupt to fire (in ~3x30us cycles) before we can safely enter deep sleep mode */
363- if (!sleep_manager_locked ) {
362+ if (!sleep_manager_locked ) {
364363 sleep_manager_lock_deep_sleep ();
365364 sleep_manager_locked = true;
366365 }
@@ -383,14 +382,14 @@ void lp_ticker_disable_interrupt(void)
383382{
384383 core_util_critical_section_enter ();
385384
386- if (!lp_cmpok ) {
385+ if (!lp_cmpok ) {
387386 while (__HAL_LPTIM_GET_FLAG (& LptimHandle , LPTIM_FLAG_CMPOK ) == RESET ) {
388387 }
389388 __HAL_LPTIM_CLEAR_FLAG (& LptimHandle , LPTIM_FLAG_CMPOK );
390389 lp_cmpok = true;
391390 }
392391 /* now that CMPOK is set, allow deep sleep again */
393- if (sleep_manager_locked ) {
392+ if (sleep_manager_locked ) {
394393 sleep_manager_unlock_deep_sleep ();
395394 sleep_manager_locked = false;
396395 }
0 commit comments