3232#include <stdlib.h>
3333#include <uart_messaging.h>
3434#include <ui/rgb_leds/front_leds/front_leds.h>
35+ #include <zephyr/drivers/gpio.h>
3536#include <zephyr/kernel.h>
3637
3738#if defined(CONFIG_BOARD_DIAMOND_MAIN )
3839#include "ui/rgb_leds/cone_leds/cone_leds.h"
3940#include "ui/white_leds/white_leds.h"
41+
42+ static const struct gpio_dt_spec exp_mcu_rst_rqst_gpio_spec =
43+ GPIO_DT_SPEC_GET (DT_PATH (zephyr_user ), exp_mcu_rst_rqst_gpios );
4044#endif
4145
4246#if defined(CONFIG_MEMFAULT_METRICS_CONNECTIVITY_CONNECTED_TIME )
@@ -1196,6 +1200,55 @@ handle_power_cycle(job_t *job)
11961200}
11971201
11981202#ifdef CONFIG_BOARD_DIAMOND_MAIN
1203+ static void
1204+ handle_reboot_security_mcu (job_t * job )
1205+ {
1206+ orb_mcu_main_JetsonToMcu * msg = & job -> message .jetson_cmd ;
1207+ MAKE_ASSERTS (orb_mcu_main_JetsonToMcu_reboot_security_mcu_tag );
1208+
1209+ int ret ;
1210+
1211+ orb_mcu_Hardware hw_revision = version_get ();
1212+ if (hw_revision .version <
1213+ orb_mcu_Hardware_OrbVersion_HW_VERSION_DIAMOND_V4_5 ) {
1214+ job_ack (orb_mcu_Ack_ErrorCode_VERSION , job );
1215+ return ;
1216+ }
1217+
1218+ if (!gpio_is_ready_dt (& exp_mcu_rst_rqst_gpio_spec )) {
1219+ LOG_ERR ("GPIO for security MCU reset request not ready" );
1220+ job_ack (orb_mcu_Ack_ErrorCode_FAIL , job );
1221+ return ;
1222+ }
1223+
1224+ ret = gpio_pin_configure_dt (& exp_mcu_rst_rqst_gpio_spec ,
1225+ GPIO_OUTPUT_INACTIVE );
1226+ if (ret != 0 ) {
1227+ LOG_ERR ("Failed to configure GPIO: %d" , ret );
1228+ job_ack (orb_mcu_Ack_ErrorCode_FAIL , job );
1229+ return ;
1230+ }
1231+
1232+ ret = gpio_pin_set_dt (& exp_mcu_rst_rqst_gpio_spec , 1 );
1233+ if (ret != 0 ) {
1234+ LOG_ERR ("Failed to set GPIO high: %d" , ret );
1235+ job_ack (orb_mcu_Ack_ErrorCode_FAIL , job );
1236+ return ;
1237+ }
1238+
1239+ k_msleep (100 );
1240+
1241+ ret = gpio_pin_set_dt (& exp_mcu_rst_rqst_gpio_spec , 0 );
1242+ if (ret != 0 ) {
1243+ LOG_ERR ("Failed to set GPIO low: %d" , ret );
1244+ job_ack (orb_mcu_Ack_ErrorCode_FAIL , job );
1245+ return ;
1246+ }
1247+
1248+ LOG_INF ("Security MCU reboot requested" );
1249+ job_ack (orb_mcu_Ack_ErrorCode_SUCCESS , job );
1250+ }
1251+
11991252static void
12001253handle_polarizer (job_t * job )
12011254{
@@ -1834,6 +1887,8 @@ static const hm_callback handle_message_callbacks[] = {
18341887 [orb_mcu_main_JetsonToMcu_polarizer_tag ] = handle_polarizer ,
18351888 [orb_mcu_main_JetsonToMcu_polarizer_wheel_settings_tag ] =
18361889 handle_polarizer_wheel_settings ,
1890+ [orb_mcu_main_JetsonToMcu_reboot_security_mcu_tag ] =
1891+ handle_reboot_security_mcu ,
18371892#elif defined(CONFIG_BOARD_PEARL_MAIN )
18381893 [orb_mcu_main_JetsonToMcu_cone_leds_sequence_tag ] = handle_not_supported ,
18391894 [orb_mcu_main_JetsonToMcu_cone_leds_pattern_tag ] = handle_not_supported ,
@@ -1843,7 +1898,7 @@ static const hm_callback handle_message_callbacks[] = {
18431898#endif
18441899};
18451900
1846- BUILD_ASSERT ((ARRAY_SIZE (handle_message_callbacks ) <= 57 ),
1901+ BUILD_ASSERT ((ARRAY_SIZE (handle_message_callbacks ) <= 58 ),
18471902 "It seems like the `handle_message_callbacks` array is too large" );
18481903
18491904_Noreturn static void
0 commit comments