Skip to content

Commit

Permalink
fix: fixed bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
YarikRevich committed Apr 2, 2024
1 parent 6ab5847 commit 45433b0
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .cproject
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
<listOptionValue builtIn="false" value="../Core/External/Scheduler/Handler"/>
<listOptionValue builtIn="false" value="../Core/External/State"/>
<listOptionValue builtIn="false" value="../Core/External/Tools/Indicator"/>
<listOptionValue builtIn="false" value="../Core/External/Tools/Mutex"/>
<listOptionValue builtIn="false" value="../Core/External/Tools/Sequence"/>
<listOptionValue builtIn="false" value="../ThirdParty/Inc"/>
<listOptionValue builtIn="false" value="../Drivers/STM32L4xx_HAL_Driver/Inc"/>
Expand Down Expand Up @@ -90,6 +91,7 @@
<listOptionValue builtIn="false" value="../Core/External/State"/>
<listOptionValue builtIn="false" value="../Core/External/Scheduler/Handler"/>
<listOptionValue builtIn="false" value="../Core/External/Tools/Indicator"/>
<listOptionValue builtIn="false" value="../Core/External/Tools/Mutex"/>
<listOptionValue builtIn="false" value="../Core/External/Tools/Sequence"/>
<listOptionValue builtIn="false" value="../ThirdParty/Inc"/>
<listOptionValue builtIn="false" value="../Drivers/STM32L4xx_HAL_Driver/Inc"/>
Expand Down
6 changes: 2 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions Core/External/Scheduler/scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ void Scheduler::schedule_status_check() {
Indicator::toggle_action_failure();
}

State::get_button_mutex().unlock();

return EXIT_SUCCESS;
});
}
6 changes: 6 additions & 0 deletions Core/External/State/state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ int State::amount_of_processed_requests = 0;

int State::current_response_nonce = 0;

Mutex State::button_mutex = Mutex();

Sequence<std::function<int()>> State::task_sequence =
Sequence<std::function<int()>>();

Expand All @@ -18,6 +20,10 @@ int State::allocate_response_nonce() {
return current_response_nonce++;
}

Mutex& State::get_button_mutex() {
return button_mutex;
}

Sequence<std::function<int()>>& State::get_task_sequence() {
return task_sequence;
}
Expand Down
13 changes: 13 additions & 0 deletions Core/External/State/state.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define LIGHT_DETECTOR_STATE_H

#include "request.h"
#include "mutex.h"
#include "sequence.h"

#include <queue>
Expand All @@ -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.
*
Expand All @@ -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.
*/
Expand Down
16 changes: 13 additions & 3 deletions Core/External/Tools/Mutex/mutex.cpp
Original file line number Diff line number Diff line change
@@ -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;
}
2 changes: 1 addition & 1 deletion Core/External/Tools/Mutex/mutex.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions Core/Inc/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#define __MAIN_H

#include "scheduler.h"
#include "state.h"

#ifdef __cplusplus
extern "C" {
Expand Down
6 changes: 5 additions & 1 deletion Core/Src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit 45433b0

Please sign in to comment.