4646
4747// msec to RTC subsec ticks (4 kHz)
4848#define MSEC_TO_SS_ALARM (x ) \
49- (0 - ((x * 4096) / \
50- 1000)) /* Converts a time in milleseconds to the equivalent RSSA register value. */
49+ (0 - ((x * 4096) / \
50+ 1000)) /* Converts a time in milleseconds to the equivalent RSSA register value. */
5151
5252// Externs defined by linker .ld file
5353extern uint32_t _stack , _heap , _estack , _eheap ;
@@ -70,7 +70,7 @@ safe_mode_t port_init(void) {
7070 int err = E_NO_ERROR ;
7171
7272 // Enable GPIO (enables clocks + common init for ports)
73- for (int i = 0 ; i < MXC_CFG_GPIO_INSTANCES ; i ++ ){
73+ for (int i = 0 ; i < MXC_CFG_GPIO_INSTANCES ; i ++ ) {
7474 err = MXC_GPIO_Init (0x1 << i );
7575 if (err ) {
7676 return SAFE_MODE_PROGRAMMATIC ;
@@ -93,22 +93,28 @@ safe_mode_t port_init(void) {
9393
9494 // Enable clock to RTC peripheral
9595 MXC_GCR -> clkctrl |= MXC_F_GCR_CLKCTRL_ERTCO_EN ;
96- while (!(MXC_GCR -> clkctrl & MXC_F_GCR_CLKCTRL_ERTCO_RDY ));
96+ while (!(MXC_GCR -> clkctrl & MXC_F_GCR_CLKCTRL_ERTCO_RDY )) {
97+ ;
98+ }
9799
98100 NVIC_EnableIRQ (RTC_IRQn );
99101 NVIC_EnableIRQ (USB_IRQn );
100102
101103 // Init RTC w/ 0sec, 0subsec
102104 // Driven by 32.768 kHz ERTCO, with ssec= 1/4096 s
103- while ( MXC_RTC_Init (0 ,0 ) != E_SUCCESS ) {};
105+ while (MXC_RTC_Init (0 , 0 ) != E_SUCCESS ) {
106+ }
107+ ;
104108
105109 // enable 1 sec RTC SSEC alarm
106110 MXC_RTC_DisableInt (MXC_F_RTC_CTRL_SSEC_ALARM_IE );
107111 MXC_RTC_SetSubsecondAlarm (MSEC_TO_SS_ALARM (1000 ));
108112 MXC_RTC_EnableInt (MXC_F_RTC_CTRL_SSEC_ALARM_IE );
109113
110114 // Enable RTC
111- while ( MXC_RTC_Start () != E_SUCCESS ) {};
115+ while (MXC_RTC_Start () != E_SUCCESS ) {
116+ }
117+ ;
112118
113119 return SAFE_MODE_NONE ;
114120}
@@ -191,9 +197,10 @@ uint64_t port_get_raw_ticks(uint8_t *subticks) {
191197 __disable_irq ();
192198 if (MXC_RTC -> ctrl & MXC_F_RTC_CTRL_EN ) {
193199 // NOTE: RTC_GetTime always returns BUSY if RTC is not running
194- while ( (MXC_RTC_GetTime (& sec , & subsec )) != E_NO_ERROR );
195- }
196- else {
200+ while ((MXC_RTC_GetTime (& sec , & subsec )) != E_NO_ERROR ) {
201+ ;
202+ }
203+ } else {
197204 sec = MXC_RTC -> sec ;
198205 subsec = MXC_RTC -> ssec ;
199206 }
@@ -232,15 +239,19 @@ void port_interrupt_after_ticks(uint32_t ticks) {
232239 ticks_msec = 1000 * ticks / TICKS_PER_SEC ;
233240
234241 while (MXC_RTC_DisableInt (MXC_F_RTC_CTRL_SSEC_ALARM_IE |
235- MXC_F_RTC_CTRL_TOD_ALARM_IE ) == E_BUSY ) {};
242+ MXC_F_RTC_CTRL_TOD_ALARM_IE ) == E_BUSY ) {
243+ }
244+ ;
236245
237246 // Clear the flag to be set by the RTC Handler
238247 tick_flag = 0 ;
239248
240249 // Subsec alarm is the starting/reload value of the SSEC counter.
241250 // ISR triggered when SSEC rolls over from 0xFFFF_FFFF to 0x0
242- while ( MXC_RTC_SetSubsecondAlarm (MSEC_TO_SS_ALARM (ticks_msec ) ) == E_BUSY ) {}
243- while (MXC_RTC_EnableInt (MXC_F_RTC_CTRL_SSEC_ALARM_IE ) == E_BUSY ) {}
251+ while (MXC_RTC_SetSubsecondAlarm (MSEC_TO_SS_ALARM (ticks_msec )) == E_BUSY ) {
252+ }
253+ while (MXC_RTC_EnableInt (MXC_F_RTC_CTRL_SSEC_ALARM_IE ) == E_BUSY ) {
254+ }
244255
245256 NVIC_EnableIRQ (RTC_IRQn );
246257
@@ -249,10 +260,10 @@ void port_interrupt_after_ticks(uint32_t ticks) {
249260
250261void port_idle_until_interrupt (void ) {
251262 #if CIRCUITPY_RTC
252- // Check if alarm triggers before we even got here
253- if (MXC_RTC_GetFlags () == (MXC_F_RTC_CTRL_TOD_ALARM | MXC_F_RTC_CTRL_SSEC_ALARM )) {
254- return ;
255- }
263+ // Check if alarm triggers before we even got here
264+ if (MXC_RTC_GetFlags () == (MXC_F_RTC_CTRL_TOD_ALARM | MXC_F_RTC_CTRL_SSEC_ALARM )) {
265+ return ;
266+ }
256267 #endif
257268
258269 // Interrupts should be disabled to ensure the ISR queue is flushed
0 commit comments