diff --git a/.cproject b/.cproject index 8fe4097..1798d45 100644 --- a/.cproject +++ b/.cproject @@ -59,6 +59,7 @@ + @@ -90,6 +91,7 @@ + diff --git a/CMakeLists.txt b/CMakeLists.txt index 08e85b3..3c5257d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,15 +49,13 @@ else () add_compile_options(-Og -g) endif () -include_directories(Core/Inc Core/External/Proto/Buffer Core/External/Proto/Buffer/Request Core/External/Proto/Buffer/Response Core/External/Sensor Core/External/Proto/Helper Core/External/Proto/Codec Core/External/Proto/Generated Core/External/Proto/Generated/Content Core/External/Scheduler Core/External/Scheduler/Handler Core/External/State Core/External/Tools/Indicator Core/External/Tools/Sequence ThirdParty/Inc Drivers/STM32L4xx_HAL_Driver/Inc Drivers/STM32L4xx_HAL_Driver/Inc/Legacy Drivers/CMSIS/Device/ST/STM32L4xx/Include Drivers/CMSIS/Include) +include_directories(Core/Inc Core/External/Proto/Buffer Core/External/Proto/Buffer/Request Core/External/Proto/Buffer/Response Core/External/Sensor Core/External/Proto/Helper Core/External/Proto/Codec Core/External/Proto/Generated Core/External/Proto/Generated/Content Core/External/Scheduler Core/External/Scheduler/Handler Core/External/State Core/External/Tools/Indicator Core/External/Tools/Mutex Core/External/Tools/Sequence ThirdParty/Inc Drivers/STM32L4xx_HAL_Driver/Inc Drivers/STM32L4xx_HAL_Driver/Inc/Legacy Drivers/CMSIS/Device/ST/STM32L4xx/Include Drivers/CMSIS/Include) add_definitions(-DDEBUG -DUSE_HAL_DRIVER -DSTM32L476xx) file(GLOB_RECURSE SOURCES "ThirdParty/*.*" "Core/*.*" "Drivers/*.*") -set(LINKER_SCRIPT ${CMAKE_SOURCE_DIR}/STM32L476RGTX_FLASH.ld - Core/External/Tools/Mutex/mutex.cpp - Core/External/Tools/Mutex/mutex.h) +set(LINKER_SCRIPT ${CMAKE_SOURCE_DIR}/STM32L476RGTX_FLASH.ld) add_link_options(-Wl,-gc-sections,--print-memory-usage,-Map=${PROJECT_BINARY_DIR}/${PROJECT_NAME}.map) add_link_options(-mcpu=cortex-m4 -mthumb -mthumb-interwork) diff --git a/Core/External/Scheduler/scheduler.cpp b/Core/External/Scheduler/scheduler.cpp index 66d979c..53c478c 100644 --- a/Core/External/Scheduler/scheduler.cpp +++ b/Core/External/Scheduler/scheduler.cpp @@ -26,6 +26,8 @@ void Scheduler::schedule_status_check() { Indicator::toggle_action_failure(); } + State::get_button_mutex().unlock(); + return EXIT_SUCCESS; }); } \ No newline at end of file diff --git a/Core/External/State/state.cpp b/Core/External/State/state.cpp index c3a8873..0b35ad0 100644 --- a/Core/External/State/state.cpp +++ b/Core/External/State/state.cpp @@ -4,6 +4,8 @@ int State::amount_of_processed_requests = 0; int State::current_response_nonce = 0; +Mutex State::button_mutex = Mutex(); + Sequence> State::task_sequence = Sequence>(); @@ -18,6 +20,10 @@ int State::allocate_response_nonce() { return current_response_nonce++; } +Mutex& State::get_button_mutex() { + return button_mutex; +} + Sequence>& State::get_task_sequence() { return task_sequence; } diff --git a/Core/External/State/state.h b/Core/External/State/state.h index 0d5a489..e23d76a 100644 --- a/Core/External/State/state.h +++ b/Core/External/State/state.h @@ -2,6 +2,7 @@ #define LIGHT_DETECTOR_STATE_H #include "request.h" +#include "mutex.h" #include "sequence.h" #include @@ -25,6 +26,13 @@ class State { */ static int allocate_response_nonce(); + /** + * Retrieves button mutex. + * + * @return retrieved button mutex. + */ + static Mutex& get_button_mutex(); + /** * Retrieves task sequence used to perform scheduled tasks execution. * @@ -50,6 +58,11 @@ class State { */ static int current_response_nonce; + /** + * Represents button mutex used to manage pressed button operations invokation. + */ + static Mutex button_mutex; + /** * Represents scheduled tasks sequence. */ diff --git a/Core/External/Tools/Mutex/mutex.cpp b/Core/External/Tools/Mutex/mutex.cpp index 7ccb5f9..945db3a 100644 --- a/Core/External/Tools/Mutex/mutex.cpp +++ b/Core/External/Tools/Mutex/mutex.cpp @@ -1,3 +1,13 @@ -// -// Created by Yaroslav Svitlytskyi on 02.04.2024. -// +#include "mutex.h" + +void Mutex::lock() { + locked = true; +} + +void Mutex::unlock() { + locked = false; +} + +bool Mutex::is_locked() const { + return locked; +} \ No newline at end of file diff --git a/Core/External/Tools/Mutex/mutex.h b/Core/External/Tools/Mutex/mutex.h index b07ff35..4925e89 100644 --- a/Core/External/Tools/Mutex/mutex.h +++ b/Core/External/Tools/Mutex/mutex.h @@ -21,7 +21,7 @@ class Mutex { * * @return retrieved state of the mutex. */ - bool is_locked(); + bool is_locked() const; private: /** * Represents current state of the mutex. diff --git a/Core/Inc/main.h b/Core/Inc/main.h index 6170593..15b7880 100644 --- a/Core/Inc/main.h +++ b/Core/Inc/main.h @@ -23,6 +23,7 @@ #define __MAIN_H #include "scheduler.h" +#include "state.h" #ifdef __cplusplus extern "C" { diff --git a/Core/Src/main.cpp b/Core/Src/main.cpp index 7a99a6c..a7b7ba9 100644 --- a/Core/Src/main.cpp +++ b/Core/Src/main.cpp @@ -68,7 +68,11 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) { */ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) { if (GPIO_Pin == GPIO_PIN_13) { - Scheduler::schedule_status_check(); + if (!State::get_button_mutex().is_locked()) { + State::get_button_mutex().lock(); + + Scheduler::schedule_status_check(); + } } else { __NOP(); }