@@ -111,8 +111,7 @@ void RTC1_IRQHandler(void);
111
111
112
112
void common_rtc_init (void )
113
113
{
114
- if (m_common_rtc_enabled )
115
- {
114
+ if (m_common_rtc_enabled ) {
116
115
return ;
117
116
}
118
117
@@ -228,12 +227,10 @@ void common_rtc_set_interrupt(uint32_t us_timestamp, uint32_t cc_channel,
228
227
uint64_t current_time64 = common_rtc_64bit_us_get ();
229
228
// [add upper 32 bits from the current time to the timestamp value]
230
229
uint64_t timestamp64 = us_timestamp +
231
- (current_time64 & ~(uint64_t )0xFFFFFFFF );
232
-
230
+ (current_time64 & ~(uint64_t )0xFFFFFFFF );
233
231
// [if the original timestamp value happens to be after the 32 bit counter
234
232
// of microsends overflows, correct the upper 32 bits accordingly]
235
- if (us_timestamp < (uint32_t )(current_time64 & 0xFFFFFFFF ))
236
- {
233
+ if (us_timestamp < (uint32_t )(current_time64 & 0xFFFFFFFF )) {
237
234
timestamp64 += ((uint64_t )1 << 32 );
238
235
}
239
236
// [microseconds -> ticks, always round the result up to avoid too early
@@ -248,8 +245,7 @@ void common_rtc_set_interrupt(uint32_t us_timestamp, uint32_t cc_channel,
248
245
// value is 2 ticks. This guarantees that the compare trigger is properly
249
246
// setup before the compare condition occurs.
250
247
uint32_t closest_safe_compare = common_rtc_32bit_ticks_get () + 2 ;
251
- if ((int )(compare_value - closest_safe_compare ) <= 0 )
252
- {
248
+ if ((int )(compare_value - closest_safe_compare ) <= 0 ) {
253
249
compare_value = closest_safe_compare ;
254
250
}
255
251
@@ -314,7 +310,7 @@ static uint32_t previous_tick_cc_value = 0;
314
310
*/
315
311
MBED_WEAK uint32_t const os_trv ;
316
312
MBED_WEAK uint32_t const os_clockrate ;
317
- MBED_WEAK void OS_Tick_Handler ()
313
+ MBED_WEAK void OS_Tick_Handler (void )
318
314
{
319
315
}
320
316
@@ -461,14 +457,11 @@ static uint32_t get_next_tick_cc_delta()
461
457
{
462
458
uint32_t delta = 0 ;
463
459
464
- if (os_clockrate != 1000 )
465
- {
460
+ if (os_clockrate != 1000 ) {
466
461
// In RTX, by default SYSTICK is is used.
467
462
// A tick event is generated every os_trv + 1 clock cycles of the system timer.
468
463
delta = os_trv + 1 ;
469
- }
470
- else
471
- {
464
+ } else {
472
465
// If the clockrate is set to 1000us then 1000 tick should happen every second.
473
466
// Unfortunatelly, when clockrate is set to 1000, os_trv is equal to 31.
474
467
// If (os_trv + 1) is used as the delta value between two ticks, 1000 ticks will be
@@ -484,24 +477,19 @@ static uint32_t get_next_tick_cc_delta()
484
477
// Every five ticks (20%, 200 delta in one second), the delta is equal to 32
485
478
// The remaining (32) deltas equal to 32 are distributed using primes numbers.
486
479
static uint32_t counter = 0 ;
487
- if ((counter % 5 ) == 0 || (counter % 31 ) == 0 || (counter % 139 ) == 0 || (counter == 503 ))
488
- {
480
+ if ((counter % 5 ) == 0 || (counter % 31 ) == 0 || (counter % 139 ) == 0 || (counter == 503 )) {
489
481
delta = 32 ;
490
- }
491
- else
492
- {
482
+ } else {
493
483
delta = 33 ;
494
484
}
495
485
++ counter ;
496
- if (counter == 1000 )
497
- {
486
+ if (counter == 1000 ) {
498
487
counter = 0 ;
499
488
}
500
489
}
501
490
return delta ;
502
491
}
503
492
504
-
505
493
static inline void clear_tick_interrupt ()
506
494
{
507
495
nrf_rtc_event_clear (COMMON_RTC_INSTANCE , OS_TICK_EVENT );
@@ -519,27 +507,18 @@ static inline bool is_in_wrapped_range(uint32_t begin, uint32_t end, uint32_t va
519
507
{
520
508
// regular case, begin < end
521
509
// return true if begin <= val < end
522
- if (begin < end )
523
- {
524
- if (begin <= val && val < end )
525
- {
510
+ if (begin < end ) {
511
+ if (begin <= val && val < end ) {
526
512
return true;
527
- }
528
- else
529
- {
513
+ } else {
530
514
return false;
531
515
}
532
- }
533
- else
534
- {
516
+ } else {
535
517
// In this case end < begin because it has wrap around the limits
536
518
// return false if end < val < begin
537
- if (end < val && val < begin )
538
- {
519
+ if (end < val && val < begin ) {
539
520
return false;
540
- }
541
- else
542
- {
521
+ } else {
543
522
return true;
544
523
}
545
524
}
@@ -566,8 +545,7 @@ static void register_next_tick()
566
545
uint32_t current_counter = nrf_rtc_counter_get (COMMON_RTC_INSTANCE );
567
546
568
547
// If an overflow occur, set the next tick in COUNTER + delta clock cycles
569
- if (is_in_wrapped_range (previous_tick_cc_value , new_compare_value , current_counter + 1 ) == false)
570
- {
548
+ if (is_in_wrapped_range (previous_tick_cc_value , new_compare_value , current_counter + 1 ) == false) {
571
549
new_compare_value = current_counter + delta ;
572
550
}
573
551
nrf_rtc_cc_set (COMMON_RTC_INSTANCE , OS_TICK_CC_CHANNEL , new_compare_value );
@@ -633,29 +611,20 @@ uint32_t os_tick_val(void)
633
611
uint32_t next_tick_cc_value = nrf_rtc_cc_get (COMMON_RTC_INSTANCE , OS_TICK_CC_CHANNEL );
634
612
635
613
// do not use os_tick_ovf because its counter value can be different
636
- if (is_in_wrapped_range (previous_tick_cc_value , next_tick_cc_value , current_counter ))
637
- {
638
- if (next_tick_cc_value > previous_tick_cc_value )
639
- {
614
+ if (is_in_wrapped_range (previous_tick_cc_value , next_tick_cc_value , current_counter )) {
615
+ if (next_tick_cc_value > previous_tick_cc_value ) {
640
616
return next_tick_cc_value - current_counter ;
641
- }
642
- else if (current_counter <= next_tick_cc_value )
643
- {
617
+ } else if (current_counter <= next_tick_cc_value ) {
644
618
return next_tick_cc_value - current_counter ;
645
- }
646
- else
647
- {
619
+ } else {
648
620
return next_tick_cc_value + (MAX_RTC_COUNTER_VAL - current_counter );
649
621
}
650
- }
651
- else
652
- {
622
+ } else {
653
623
// use (os_trv + 1) has the base step, can be totally inacurate ...
654
624
uint32_t clock_cycles_by_tick = os_trv + 1 ;
655
625
656
626
// if current counter has wrap arround, add the limit to it.
657
- if (current_counter < next_tick_cc_value )
658
- {
627
+ if (current_counter < next_tick_cc_value ) {
659
628
current_counter = current_counter + MAX_RTC_COUNTER_VAL ;
660
629
}
661
630
0 commit comments