diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index e7006164a..16bf0e616 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -123,49 +123,3 @@ define(SCHEDULER) define(LF_SOURCE_DIRECTORY) define(LF_PACKAGE_DIRECTORY) define(LF_FILE_SEPARATOR) - - - -# ========================================================== -# Stuff I added -# ========================================================== - -if(${CMAKE_SYSTEM_NAME} MATCHES "Stm32") - set(CPU_PARAMETERS - -mcpu=cortex-m4 - -mthumb - -mfpu=fpv4-sp-d16 - -mfloat-abi=softfp ) - - set(MCU_FAMILY STM32F4xx ) - set(MCU_MODEL STM32F446xx ) - - target_compile_definitions(core PRIVATE - ${MCU_MODEL} - USE_HAL_DRIVER ) - - target_compile_options(core PRIVATE - ${CPU_PARAMETERS} - -Wall - -Wextra - -Wpedantic - -Wno-unused-parameter - $<$: - -Wno-volatile - -Wold-style-cast - -Wuseless-cast - -Wsuggest-override> - $<$:-Og -g3 -ggdb> - $<$:-Og -g0> ) - - set(CUBEMX_INCLUDE_DIRECTORIES - ../STM_sdk/Core/Inc - ../STM_sdk/Drivers/${MCU_FAMILY}_HAL_Driver/Inc - ../STM_sdk/Drivers/${MCU_FAMILY}_HAL_Driver/Inc/Legacy - ../STM_sdk/Drivers/CMSIS/Device/ST/${MCU_FAMILY}/Include - ../STM_sdk/Drivers/CMSIS/Include ) - - target_include_directories(core PUBLIC - ${CUBEMX_INCLUDE_DIRECTORIES} ) -endif() -# ========================================================== \ No newline at end of file diff --git a/core/platform/lf_STM32f4_support.c b/core/platform/lf_STM32f4_support.c index dcd944113..01eed54e0 100644 --- a/core/platform/lf_STM32f4_support.c +++ b/core/platform/lf_STM32f4_support.c @@ -119,46 +119,44 @@ static void lf_busy_wait_until(instant_t wakeup_time) { // I am pretty sure this function doesnt work // Ill try to fix it once i know what the fuck its supposed to do, LOL -int _lf_interruptable_sleep_until_locked(environment_t *env, instant_t wakeup_time) { - // // Get the current time and sleep time - // instant_t now; - // _lf_clock_now(&now); - // interval_t duration = wakeup_time - now; - - // // Edge case handling for super small duration - // if (duration <= 0) { - // return 0; - // } else if (duration < 10) { - // lf_busy_wait_until(wakeup_time); - // return 0; - // } - - // // Enable interrupts and prepare to wait - // _lf_async_event = false; - // instant_t curr; - // lf_enable_interrupts_nested(); - - // do { - // _lf_clock_now(&curr); - - // // Exit wither when the timer is up or there is an exception - // } while (!_lf_async_event && (now < wakeup_time)); - - // // Disable interrupts again on exit - // lf_disable_interrupts_nested(); - - // if (!_lf_async_event) { - // return 0; - // } else { - // LF_PRINT_DEBUG(" *The STM32 rises from sleep* \n"); - // return -1; - // } +/* sleep until wakeup time + But, wake up if there is an async event +*/ +int _lf_interruptable_sleep_until_locked(environment_t *env, instant_t wakeup_time) { + // Get the current time and sleep time instant_t now; + _lf_clock_now(&now); + interval_t duration = wakeup_time - now; + + // Edge case handling for super small duration + if (duration <= 0) { + return 0; + } else if (duration < 10) { + lf_busy_wait_until(wakeup_time); + return 0; + } + + // Enable interrupts and prepare to wait + _lf_async_event = false; + lf_enable_interrupts_nested(); + do { _lf_clock_now(&now); - } while (now < wakeup_time); - return 0; + + // Exit when the timer is up or there is an exception + } while (!_lf_async_event && (now < wakeup_time)); + + // Disable interrupts again on exit + lf_disable_interrupts_nested(); + + if (!_lf_async_event) { + return 0; + } else { + LF_PRINT_DEBUG(" *The STM32 rises from sleep* \n"); + return -1; + } + } // + -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- +