-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-Authored-By: Maxime Blanc <[email protected]> Co-Authored-By: SamHadjes <[email protected]>
- Loading branch information
1 parent
9da3fb3
commit da278ac
Showing
13 changed files
with
286 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Leka - LekaOS | ||
# Copyright 2024 APF France handicap | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
add_library(CoreDAC STATIC) | ||
|
||
target_include_directories(CoreDAC | ||
PUBLIC | ||
include | ||
) | ||
|
||
target_sources(CoreDAC | ||
PRIVATE | ||
source/CoreSTM32HalBasicTimer.cpp | ||
) | ||
|
||
if(NOT(${CMAKE_PROJECT_NAME} STREQUAL "LekaOSUnitTests")) | ||
target_sources(CoreDAC | ||
PUBLIC | ||
source/HAL_IRQHandlers.cpp | ||
) | ||
endif() | ||
|
||
target_link_libraries(CoreDAC | ||
mbed-os | ||
CoreSTM32Hal | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Leka - LekaOS | ||
// Copyright 2024 APF France handicap | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#pragma once | ||
|
||
#include <functional> | ||
|
||
#include "interface/STM32HalBasicTimer.h" | ||
|
||
namespace leka { | ||
|
||
class CoreSTM32HalBasicTimer : public interface::STM32HalBasicTimer | ||
{ | ||
public: | ||
CoreSTM32HalBasicTimer(interface::STM32Hal &hal); | ||
|
||
[[nodiscard]] auto getHandle() -> TIM_HandleTypeDef & final; | ||
|
||
void registerCallback(std::function<void()> const &callback); | ||
|
||
void initialize(uint32_t frequency) final; | ||
void terminate() final; | ||
|
||
void start() final; | ||
void stop() final; | ||
|
||
private: | ||
void _registerMspCallbacks(); | ||
|
||
interface::STM32Hal &_hal; | ||
|
||
TIM_HandleTypeDef _htim {}; | ||
|
||
std::function<void()> _callback = [] {}; | ||
}; | ||
|
||
} // namespace leka |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Leka - LekaOS | ||
// Copyright 2024 APF France handicap | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#pragma once | ||
|
||
#include "interface/drivers/STM32Hal.h" | ||
|
||
namespace leka::interface { | ||
|
||
class STM32HalBasicTimer | ||
{ | ||
public: | ||
virtual ~STM32HalBasicTimer() = default; | ||
|
||
[[nodiscard]] virtual auto getHandle() -> TIM_HandleTypeDef & = 0; | ||
|
||
virtual void initialize(uint32_t frequency) = 0; | ||
virtual void terminate() = 0; | ||
|
||
virtual void start() = 0; | ||
virtual void stop() = 0; | ||
}; | ||
|
||
} // namespace leka::interface |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// Leka - LekaOS | ||
// Copyright 2024 APF France handicap | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#include "CoreSTM32HalBasicTimer.h" | ||
|
||
using namespace leka; | ||
|
||
CoreSTM32HalBasicTimer::CoreSTM32HalBasicTimer(interface::STM32Hal &hal) : _hal(hal) | ||
{ | ||
_htim.Instance = TIM6; // TIM7 is also possible | ||
} | ||
|
||
auto CoreSTM32HalBasicTimer::getHandle() -> TIM_HandleTypeDef & | ||
{ | ||
return _htim; | ||
} | ||
|
||
void CoreSTM32HalBasicTimer::registerCallback(std::function<void()> const &callback) | ||
{ | ||
_callback = callback; | ||
} | ||
|
||
void CoreSTM32HalBasicTimer::initialize(uint32_t frequency) | ||
{ | ||
_registerMspCallbacks(); | ||
|
||
// CK_Timer = CK_Int / ((Prescaler + 1) * (Period + 1)) | ||
auto divider = 54'000'000 / frequency; | ||
|
||
_htim.Init.Prescaler = divider / 100; | ||
_htim.Init.Period = 100; // ? min 1 | ||
_htim.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; // Disable shadow write | ||
// _htim.Init.CounterMode; // NOT AVAILABLE for BasicTimer | ||
// _htim.Init.ClockDivision; // NOT AVAILABLE for BasicTimer | ||
// _htim.Init.RepetitionCounter; // NOT AVAILABLE for BasicTimer | ||
_hal.HAL_TIM_Base_Init(&_htim); | ||
|
||
auto timerMasterConfig = TIM_MasterConfigTypeDef {}; | ||
timerMasterConfig.MasterOutputTrigger = TIM_TRGO_UPDATE; // Use hardware trigger | ||
// timerMasterConfig.MasterSlaveMode; // NOT AVAILABLE for BasicTimer | ||
_hal.HAL_TIMEx_MasterConfigSynchronization(&_htim, &timerMasterConfig); | ||
|
||
static auto &self = *this; | ||
_hal.HAL_TIM_RegisterCallback(&_htim, HAL_TIM_PERIOD_ELAPSED_CB_ID, | ||
[](TIM_HandleTypeDef *htim) { self._callback(); }); | ||
} | ||
|
||
void CoreSTM32HalBasicTimer::_registerMspCallbacks() | ||
{ | ||
static auto &self = *this; | ||
|
||
_hal.HAL_TIM_RegisterCallback(&_htim, HAL_TIM_BASE_MSPINIT_CB_ID, [](TIM_HandleTypeDef *htim) { | ||
self._hal.HAL_RCC_TIM6_CLK_ENABLE(); | ||
|
||
self._hal.HAL_NVIC_SetPriority(TIM6_DAC_IRQn, 0x00, 0x00); | ||
self._hal.HAL_NVIC_EnableIRQ(TIM6_DAC_IRQn); | ||
}); | ||
|
||
_hal.HAL_TIM_RegisterCallback(&_htim, HAL_TIM_BASE_MSPDEINIT_CB_ID, | ||
[](TIM_HandleTypeDef *htim) { self._hal.HAL_RCC_TIM6_CLK_DISABLE(); }); | ||
} | ||
|
||
void CoreSTM32HalBasicTimer::terminate() | ||
{ | ||
_hal.HAL_TIM_Base_DeInit(&_htim); | ||
} | ||
|
||
void CoreSTM32HalBasicTimer::start() | ||
{ | ||
_hal.HAL_TIM_Base_Start_IT(&_htim); | ||
} | ||
|
||
void CoreSTM32HalBasicTimer::stop() | ||
{ | ||
_hal.HAL_TIM_Base_Stop_IT(&_htim); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#include "CoreSTM32HalBasicTimer.h" | ||
|
||
extern "C" { | ||
|
||
extern leka::CoreSTM32HalBasicTimer hal_timer; | ||
|
||
void TIM6_DAC_IRQHandler() | ||
{ | ||
HAL_TIM_IRQHandler(&hal_timer.getHandle()); | ||
} | ||
|
||
} // extern "C" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Leka - LekaOS | ||
// Copyright 2024 APF France handicap | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#pragma once | ||
|
||
#include "gmock/gmock.h" | ||
#include "interface/STM32HalBasicTimer.h" | ||
|
||
namespace leka::mock { | ||
|
||
class STM32HalTimer : public interface::STM32HalBasicTimer | ||
{ | ||
public: | ||
MOCK_METHOD(TIM_HandleTypeDef &, getHandle, (), (override)); | ||
|
||
MOCK_METHOD(void, initialize, (uint32_t), (override)); | ||
MOCK_METHOD(void, terminate, (), (override)); | ||
|
||
MOCK_METHOD(void, start, (), (override)); | ||
MOCK_METHOD(void, stop, (), (override)); | ||
}; | ||
|
||
} // namespace leka::mock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters