M module-bsp/board/linux/board.cpp => module-bsp/board/linux/board.cpp +11 -0
@@ 7,6 7,17 @@ namespace bsp
{
// dummy
}
+
+ void BoardPowerOff()
+ {
+ // dummy
+ }
+
+ void BoardReboot()
+ {
+ // dummy
+ }
+
} // namespace bsp
namespace bsp::bell_switches
M module-bsp/board/rt1051/bsp/lpm/RT1051LPM.cpp => module-bsp/board/rt1051/bsp/lpm/RT1051LPM.cpp +3 -2
@@ 10,6 10,7 @@
#include "bsp/watchdog/watchdog.hpp"
#include <board/clock_config.h>
#include <fsl_clock.h>
+#include <bsp/bsp.hpp>
#include "ClockState.hpp"
#include "Oscillator.hpp"
#include "critical.hpp"
@@ 44,7 45,7 @@ namespace bsp
int32_t RT1051LPM::PowerOff()
{
- gpio_1->WritePin(static_cast<uint32_t>(BoardDefinitions::POWER_SWITCH_HOLD_BUTTON), 0);
+ bsp::BoardPowerOff();
return 0;
}
@@ 64,7 65,7 @@ namespace bsp
SNVS->LPGPR[0] = bsp::rebootCode::rebootNormalCode;
break;
}
- NVIC_SystemReset();
+ BoardReboot();
return 0;
}
M module-bsp/board/rt1051/common/board.cpp => module-bsp/board/rt1051/common/board.cpp +42 -0
@@ 1,5 1,7 @@
#include "board.h"
+#include "fsl_gpio.h"
+#include <stdint.h>
extern "C"
{
#include "fsl_common.h"
@@ 25,6 27,15 @@ extern std::uint32_t __sdram_cached_start[];
namespace bsp
{
+ namespace {
+ enum class rebootState : uintptr_t {
+ none,
+ poweroff,
+ reboot
+ };
+ volatile rebootState rebootProgress {rebootState::none};
+ }
+
/* MPU configuration. */
static void BOARD_ConfigMPU(void)
{
@@ 165,4 176,35 @@ namespace bsp
clearAndPrintBootReason();
}
+ //! Board PowerOff function by cutdown power
+ void BoardPowerOff()
+ {
+ rebootProgress = rebootState::poweroff;
+ }
+
+ //! Board reboot by the SVNC code
+ void BoardReboot()
+ {
+ rebootProgress = rebootState::reboot;
+ }
+
+ extern "C" {
+ void _platform_exit(void)
+ {
+ static constexpr auto POWER_SWITCH_PIN = 7;
+ static const auto POWER_SWITCH_PORT = GPIO2;
+ switch(rebootProgress)
+ {
+ case rebootState::none:
+ break;
+ case rebootState::poweroff:
+ GPIO_PinWrite(POWER_SWITCH_PORT, POWER_SWITCH_PIN, 0);
+ break;
+ case rebootState::reboot:
+ NVIC_SystemReset();
+ break;
+ }
+ }
+ }
+
} // namespace bsp
M module-bsp/board/rt1051/common/startup_mimxrt1052.cpp => module-bsp/board/rt1051/common/startup_mimxrt1052.cpp +6 -2
@@ 71,7 71,11 @@ extern "C"
extern "C"
{
#endif
-
+ /* Platform exit function it is a last function called after system
+ * deinitalization. It should be used to cutoff power
+ */
+ WEAK void _platform_exit(void)
+ {}
//*****************************************************************************
// Variable to store CRP value in. Will be placed automatically
// by the linker when "Enable Code Read Protect" selected.
@@ 746,7 750,7 @@ __attribute__((section(".after_vectors.reset"))) void ResetISR(void)
#else
main();
#endif
-
+ _platform_exit();
//
// main() shouldn't return, but if it does, we'll just enter an infinite loop
//
M module-bsp/bsp/bsp.hpp => module-bsp/bsp/bsp.hpp +6 -1
@@ 3,9 3,14 @@
namespace bsp
{
-
+ //! Board hardware init
void BoardInit();
+ // Board cuttoff power
+ void BoardPowerOff();
+
+ // Board system reset
+ void BoardReboot();
}
M module-os/board/rt1051/_exit.cpp => module-os/board/rt1051/_exit.cpp +2 -1
@@ 40,6 40,7 @@
#include <string.h>
#include <exit_backtrace.h>
#include <purefs/vfs_subsystem.hpp>
+#include <bsp/bsp.hpp>
static void __attribute__((noreturn)) stop_system(void)
@@ 57,8 58,8 @@ static void __attribute__((noreturn)) stop_system(void)
}
LOG_INFO("Restarting the system...");
haltIfDebugging();
+ bsp::BoardReboot();
vTaskEndScheduler();
- NVIC_SystemReset();
// waiting for system reset
while (1) {
#ifndef DEBUG
M module-sys/SystemManager/SystemManagerCommon.cpp => module-sys/SystemManager/SystemManagerCommon.cpp +4 -2
@@ 182,10 182,12 @@ namespace sys
systemDeinit();
}
+ // Power off request (pending)
+ PowerOff();
+
+ // End of scheduler and back to the main and poweroff
EndScheduler();
- // Power off system
- PowerOff();
}
void SystemManagerCommon::initialize()