Skip to content

Commit

Permalink
add response on restart request by updating Cyphal from v0.8.15 to v0…
Browse files Browse the repository at this point in the history
….9.0 and DroneCAN from v0.4.5 to v0.5.0 submodules and refactoring iwdg and platform specific functions
  • Loading branch information
PonomarevDA committed Sep 25, 2024
1 parent 655b2ce commit ce5fd23
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Libs/Cyphal
2 changes: 1 addition & 1 deletion Src/common/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,6 @@ __attribute__((noreturn)) void application_entry_point() {
while (true) {
ModuleManager::process();
blink_board_led();
WatchdogPeriphery::refresh();
HAL::Watchdog::refresh();
}
}
19 changes: 16 additions & 3 deletions Src/peripheral/iwdg/iwdg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,26 @@
#ifndef SRC_PERIPHERY_IWDG_HPP_
#define SRC_PERIPHERY_IWDG_HPP_

class WatchdogPeriphery {
namespace HAL {

class Watchdog {
public:
/**
* @brief Refresh the IWDG
* Reload IWDG counter with value defined in the reload register
* @brief Reload IWDG counter with value defined in the reload register
*/
static void refresh();

/**
* @brief Block all refresh calls, so the application will be rebooted soon
*/
static void request_reboot() {
reboot_required = true;
}

private:
static inline bool reboot_required{false};
};

} // namespace HAL

#endif // SRC_PERIPHERY_IWDG_HPP_
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,14 @@
extern IWDG_HandleTypeDef hiwdg;
#endif // HAL_IWDG_MODULE_ENABLED

void WatchdogPeriphery::refresh() {
namespace HAL {

void Watchdog::refresh() {
if (!reboot_required) {
#ifdef HAL_IWDG_MODULE_ENABLED
HAL_IWDG_Refresh(&hiwdg);
HAL_IWDG_Refresh(&hiwdg);
#endif // HAL_IWDG_MODULE_ENABLED
}
}

} // namespace HAL
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@

#include <string.h>
#include "main.h"
#include "peripheral/iwdg/iwdg.hpp"

#ifdef __cplusplus
extern "C" {
#endif

void uavcanReadUniqueID(uint8_t out_uid[4]) {
void platformSpecificReadUniqueID(uint8_t out_uid[4]) {
const uint32_t UNIQUE_ID_16_BYTES[4] = {
HAL_GetUIDw0(),
HAL_GetUIDw1(),
Expand All @@ -21,11 +22,16 @@ void uavcanReadUniqueID(uint8_t out_uid[4]) {
memcpy(out_uid, UNIQUE_ID_16_BYTES, 16);
}

void uavcanRestartNode() {
bool platformSpecificRequestRestart() {
HAL::Watchdog::request_reboot();
return true;
}

void platformSpecificRebootForce() {
HAL_NVIC_SystemReset();
}

uint32_t uavcanGetTimeMs() {
uint32_t platformSpecificGetTimeMs() {
return HAL_GetTick();
}

Expand Down
4 changes: 2 additions & 2 deletions Src/platform/stm32f103/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ add_executable(${EXECUTABLE}
${CMAKE_CURRENT_LIST_DIR}/adc.cpp
${ROOT_DIR}/Src/platform/stm32/pwm/pwm.cpp
${CMAKE_CURRENT_LIST_DIR}/pwm.cpp
${CMAKE_CURRENT_LIST_DIR}/iwdg.cpp
${ROOT_DIR}/Src/platform/stm32/iwdg/iwdg.cpp
${CMAKE_CURRENT_LIST_DIR}/led.cpp
${CMAKE_CURRENT_LIST_DIR}/temperature_sensor.cpp
${CMAKE_CURRENT_LIST_DIR}/platform_specific.cpp
${ROOT_DIR}/Src/platform/stm32/platform_specific.cpp

${coreSources}
${driversSources}
Expand Down
4 changes: 2 additions & 2 deletions Src/platform/stm32g0b1/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ add_executable(${EXECUTABLE}
${CMAKE_CURRENT_LIST_DIR}/gpio.cpp
${PLATFORM_DIR}/stm32g0b1/pwm.cpp
${PLATFORM_DIR}/stm32g0b1/spi.cpp
${PLATFORM_DIR}/stm32f103/iwdg.cpp
${ROOT_DIR}/Src/platform/stm32/iwdg/iwdg.cpp
${PLATFORM_DIR}/stm32f103/led.cpp
${PLATFORM_DIR}/stm32f103/temperature_sensor.cpp
${PLATFORM_DIR}/stm32f103/platform_specific.cpp
${ROOT_DIR}/Src/platform/stm32/platform_specific.cpp

${coreSources}
${driversSources}
Expand Down
17 changes: 15 additions & 2 deletions Src/platform/ubuntu/iwdg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,20 @@
*/

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

void WatchdogPeriphery::refresh() {
// do nothing
namespace HAL {

static uint32_t watchdog_deadline_ms = 500;

void Watchdog::refresh() {
if (!reboot_required) {
watchdog_deadline_ms = platformSpecificGetTimeMs() + 500;
}

if (platformSpecificGetTimeMs() > watchdog_deadline_ms) {
platformSpecificRebootForce();
}
}

} // namespace HAL
5 changes: 3 additions & 2 deletions Src/platform/ubuntu/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ static inline uint32_t HAL_GetUIDw2() {return 0;}

uint32_t HAL_GetTick();
void HAL_NVIC_SystemReset();
void uavcanRestartNode();
void platformSpecificRebootForce();
bool platformSpecificRequestRestart();

uint32_t uavcanGetTimeMs();
uint32_t platformSpecificGetTimeMs();

#ifdef __cplusplus
}
Expand Down
13 changes: 10 additions & 3 deletions Src/platform/ubuntu/platform_specific.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include "main.h"
#include "application.hpp"
#include "rom.h"
#include "main.h"
#include "peripheral/iwdg/iwdg.hpp"

int main() {
std::cout << "The app has been started." << std::endl;
Expand All @@ -20,11 +22,16 @@ int main() {
return 0;
}

void uavcanReadUniqueID(uint8_t out_uid[4]) {
void platformSpecificReadUniqueID(uint8_t out_uid[4]) {
memset(out_uid, 0x00, 16);
}

void uavcanRestartNode() {
bool platformSpecificRequestRestart() {
HAL::Watchdog::request_reboot();
return true;
}

void platformSpecificRebootForce() {
constexpr const char* EXECUTABLE_SYMBOLIC_LINK = "/proc/self/exe";
constexpr const int MAX_PATH_LENGTH = 1024;

Expand All @@ -47,7 +54,7 @@ void uavcanRestartNode() {
exit(1);
}

uint32_t uavcanGetTimeMs() {
uint32_t platformSpecificGetTimeMs() {
return HAL_GetTick();
}

Expand Down

0 comments on commit ce5fd23

Please sign in to comment.