Skip to content

Commit

Permalink
periphery: add iwdg
Browse files Browse the repository at this point in the history
  • Loading branch information
PonomarevDA committed Mar 12, 2024
1 parent 0857904 commit 7cf6fb9
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 12 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ add_executable(${EXECUTABLE}
${BUILD_SRC_DIR}/params.cpp
${ROOT_DIR}/Src/platform/${APP_PLATFORM}/adc.cpp
${ROOT_DIR}/Src/platform/${APP_PLATFORM}/pwm.cpp
${ROOT_DIR}/Src/platform/${APP_PLATFORM}/iwdg.cpp
${ROOT_DIR}/Src/platform/${APP_PLATFORM}/led.cpp
${ROOT_DIR}/Src/platform/${APP_PLATFORM}/platform_specific.cpp
)
Expand Down Expand Up @@ -110,7 +111,7 @@ else()
)

target_link_options(${EXECUTABLE} PRIVATE
-T${stm32cubeMxProjectPath}/STM32F103T8Ux_FLASH.ld
-T${stm32cubeMxProjectPath}/STM32F103T8UX_FLASH.ld
-mcpu=cortex-m3
-mthumb
--specs=nosys.specs
Expand Down
3 changes: 3 additions & 0 deletions Src/cyphal_application/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "feedback/feedback.hpp"
#include "circuit_status/circuit_status.hpp"
#include "periphery/led/led.hpp"
#include "periphery/iwdg/iwdg.hpp"

void init_persistent_storage() {
paramsInit(static_cast<uint8_t>(IntParamsIndexes::INTEGER_PARAMS_AMOUNT), NUM_OF_STR_PARAMS);
Expand Down Expand Up @@ -46,5 +47,7 @@ void application_entry_point() {
auto crnt_time_ms = HAL_GetTick();
feedback.process(crnt_time_ms);
crct.process(crnt_time_ms);

WatchdogPeriphery::refresh();
}
}
9 changes: 2 additions & 7 deletions Src/dronecan_application/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
#include "main.h"
#include "params.hpp"
#include "periphery/led/led.hpp"

#ifdef HAL_IWDG_MODULE_ENABLED
extern IWDG_HandleTypeDef hiwdg;
#endif /* HAL_IWDG_MODULE_ENABLED */
#include "periphery/iwdg/iwdg.hpp"

void application_entry_point() {
paramsInit(static_cast<uint8_t>(IntParamsIndexes::INTEGER_PARAMS_AMOUNT), NUM_OF_STR_PARAMS);
Expand All @@ -29,8 +26,6 @@ void application_entry_point() {
LedPeriphery::toggle(LedColor::BLUE_COLOR);
uavcanSpinOnce();

#ifdef HAL_IWDG_MODULE_ENABLED
HAL_IWDG_Refresh(&hiwdg);
#endif // HAL_IWDG_MODULE_ENABLED
WatchdogPeriphery::refresh();
}
}
15 changes: 15 additions & 0 deletions Src/periphery/iwdg/iwdg.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* This program is free software under the GNU General Public License v3.
* See <https://www.gnu.org/licenses/> for details.
* Author: Dmitry Ponomarev <[email protected]>
*/

#ifndef SRC_PERIPHERY_IWDG_HPP_
#define SRC_PERIPHERY_IWDG_HPP_

class WatchdogPeriphery {
public:
static void refresh();
};

#endif // SRC_PERIPHERY_IWDG_HPP_
18 changes: 18 additions & 0 deletions Src/platform/stm32f103/iwdg.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* This program is free software under the GNU General Public License v3.
* See <https://www.gnu.org/licenses/> for details.
* Author: Dmitry Ponomarev <[email protected]>
*/

#include "periphery/iwdg/iwdg.hpp"
#include "main.h"

#ifdef HAL_IWDG_MODULE_ENABLED
extern IWDG_HandleTypeDef hiwdg;
#endif // HAL_IWDG_MODULE_ENABLED

void WatchdogPeriphery::refresh() {
#ifdef HAL_IWDG_MODULE_ENABLED
HAL_IWDG_Refresh(&hiwdg);
#endif // HAL_IWDG_MODULE_ENABLED
}
6 changes: 3 additions & 3 deletions Src/platform/stm32f103/led.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
#include "main.h"

static void write_red(GPIO_PinState state) {
HAL_GPIO_WritePin(INTERNAL_LED_RED_GPIO_Port, INTERNAL_LED_RED_Pin, state);
HAL_GPIO_WritePin(INT_RGB_LED_RED_GPIO_Port, INT_RGB_LED_RED_Pin, state);
}
static void write_green(GPIO_PinState state) {
HAL_GPIO_WritePin(INTERNAL_LED_GREEN_GPIO_Port, INTERNAL_LED_GREEN_Pin, state);
HAL_GPIO_WritePin(INT_RGB_LED_GREEN_GPIO_Port, INT_RGB_LED_GREEN_Pin, state);
}
static void write_blue(GPIO_PinState state) {
HAL_GPIO_WritePin(INTERNAL_LED_BLUE_GPIO_Port, INTERNAL_LED_BLUE_Pin, state);
HAL_GPIO_WritePin(INT_RGB_LED_BLUE_GPIO_Port, INT_RGB_LED_BLUE_Pin, state);
}

void LedPeriphery::reset() {
Expand Down
11 changes: 11 additions & 0 deletions Src/platform/ubuntu/iwdg.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* This program is free software under the GNU General Public License v3.
* See <https://www.gnu.org/licenses/> for details.
* Author: Dmitry Ponomarev <[email protected]>
*/

#include "periphery/iwdg/iwdg.hpp"

void WatchdogPeriphery::refresh() {
// do nothing
}
2 changes: 2 additions & 0 deletions Src/platform/ubuntu/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
extern "C" {
#endif

#include <cstdint>

static inline uint32_t HAL_GetUIDw0() {return 0;}
static inline uint32_t HAL_GetUIDw1() {return 0;}
static inline uint32_t HAL_GetUIDw2() {return 0;}
Expand Down

0 comments on commit 7cf6fb9

Please sign in to comment.