@@ -119,46 +119,44 @@ static void lf_busy_wait_until(instant_t wakeup_time) {
119119
120120// I am pretty sure this function doesnt work
121121// Ill try to fix it once i know what the fuck its supposed to do, LOL
122- int _lf_interruptable_sleep_until_locked (environment_t * env , instant_t wakeup_time ) {
123- // // Get the current time and sleep time
124- // instant_t now;
125- // _lf_clock_now(&now);
126- // interval_t duration = wakeup_time - now;
127-
128- // // Edge case handling for super small duration
129- // if (duration <= 0) {
130- // return 0;
131- // } else if (duration < 10) {
132- // lf_busy_wait_until(wakeup_time);
133- // return 0;
134- // }
135-
136- // // Enable interrupts and prepare to wait
137- // _lf_async_event = false;
138- // instant_t curr;
139- // lf_enable_interrupts_nested();
140-
141- // do {
142- // _lf_clock_now(&curr);
143-
144- // // Exit wither when the timer is up or there is an exception
145- // } while (!_lf_async_event && (now < wakeup_time));
146-
147- // // Disable interrupts again on exit
148- // lf_disable_interrupts_nested();
149-
150- // if (!_lf_async_event) {
151- // return 0;
152- // } else {
153- // LF_PRINT_DEBUG(" *The STM32 rises from sleep* \n");
154- // return -1;
155- // }
122+ /* sleep until wakeup time
123+ But, wake up if there is an async event
156124
125+ */
126+ int _lf_interruptable_sleep_until_locked (environment_t * env , instant_t wakeup_time ) {
127+ // Get the current time and sleep time
157128 instant_t now ;
129+ _lf_clock_now (& now );
130+ interval_t duration = wakeup_time - now ;
131+
132+ // Edge case handling for super small duration
133+ if (duration <= 0 ) {
134+ return 0 ;
135+ } else if (duration < 10 ) {
136+ lf_busy_wait_until (wakeup_time );
137+ return 0 ;
138+ }
139+
140+ // Enable interrupts and prepare to wait
141+ _lf_async_event = false;
142+ lf_enable_interrupts_nested ();
143+
158144 do {
159145 _lf_clock_now (& now );
160- } while (now < wakeup_time );
161- return 0 ;
146+
147+ // Exit when the timer is up or there is an exception
148+ } while (!_lf_async_event && (now < wakeup_time ));
149+
150+ // Disable interrupts again on exit
151+ lf_disable_interrupts_nested ();
152+
153+ if (!_lf_async_event ) {
154+ return 0 ;
155+ } else {
156+ LF_PRINT_DEBUG (" *The STM32 rises from sleep* \n" );
157+ return -1 ;
158+ }
159+
162160}
163161
164162// + -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- +
0 commit comments