diff --git a/firmware/app/structs/obdh_data.h b/firmware/app/structs/obdh_data.h index 98087a47..095bfe66 100644 --- a/firmware/app/structs/obdh_data.h +++ b/firmware/app/structs/obdh_data.h @@ -26,7 +26,7 @@ * \author Gabriel Mariano Marcelino * \author Carlos Augusto Porto Freitas * - * \version 0.10.18 + * \version 0.10.19 * * \date 2020/07/16 * @@ -115,6 +115,7 @@ /* Operation modes */ #define OBDH_MODE_NORMAL 0 #define OBDH_MODE_HIBERNATION 1 +#define OBDH_MODE_STAND_BY 2 /** * \brief Position data. diff --git a/firmware/app/structs/satellite.h b/firmware/app/structs/satellite.h index 0d7cfe80..2337fe73 100644 --- a/firmware/app/structs/satellite.h +++ b/firmware/app/structs/satellite.h @@ -24,8 +24,9 @@ * \brief Satellite data structure definition. * * \author Gabriel Mariano Marcelino + * \author Carlos Augusto Porto Freitas * - * \version 0.10.9 + * \version 0.10.19 * * \date 2020/07/16 * @@ -45,6 +46,7 @@ #include #include #include +#include #include "obdh_data.h" @@ -90,10 +92,20 @@ typedef struct typedef struct { sys_time_t timestamp; /**< Timestamp of the Payload data. */ - bool enabled; /**< Payload enable flag. */ + uint8_t id; /**< Payload id [Ex: PAYLOAD_EDC_0_ID] */ uint8_t data[220]; /**< Payload data. */ } payload_telemetry_t; +/** + * \brief Payloads state type. + */ +typedef struct +{ + payload_t active_payload; /**< Active payload. */ + payload_t main_edc; /**< Main EDC. */ + payload_telemetry_t *c_edc; /**< Pointer to the active EDC telemetry data. */ +} payload_state_t; + /** * \brief Satellite data. */ @@ -107,6 +119,7 @@ typedef struct payload_telemetry_t edc_0; /**< EDC 0 telemetry. */ payload_telemetry_t edc_1; /**< EDC 1 telemetry. */ payload_telemetry_t payload_x; /**< Payload-X telemetry. */ + payload_state_t state; /**< Payload state. */ } sat_data_t; /** diff --git a/firmware/app/tasks/antenna_deployment.c b/firmware/app/tasks/antenna_deployment.c index d22ce032..f245ee59 100644 --- a/firmware/app/tasks/antenna_deployment.c +++ b/firmware/app/tasks/antenna_deployment.c @@ -24,8 +24,9 @@ * \brief Antenna deployment task implementation. * * \author Gabriel Mariano Marcelino + * \author Carlos Augusto Porto Freitas * - * \version 0.10.7 + * \version 0.10.19 * * \date 2021/11/17 * @@ -53,7 +54,7 @@ void vTaskAntennaDeployment(void) uint8_t i = 0; - for(i = initial_hib_time_counter; i < CONFIG_ANTENNA_DEPLOYMENT_HIBERNATION_MIN; i++) + for(i = initial_hib_time_counter; (i < CONFIG_ANTENNA_DEPLOYMENT_HIBERNATION_MIN) && (!sat_data_buf.obdh.data.initial_hib_executed); i++) { vTaskDelay(pdMS_TO_TICKS(60000U)); diff --git a/firmware/app/tasks/beacon.c b/firmware/app/tasks/beacon.c index 547c4cc3..e148d33f 100644 --- a/firmware/app/tasks/beacon.c +++ b/firmware/app/tasks/beacon.c @@ -24,8 +24,9 @@ * \brief Beacon task implementation. * * \author Gabriel Mariano Marcelino + * \author Carlos Augusto Porto Freitas * - * \version 0.10.9 + * \version 0.10.19 * * \date 2019/10/27 * @@ -137,25 +138,8 @@ void vTaskBeacon(void) beacon_pl.payload[63] = sat_data_buf.eps.data.battery_monitor_temperature & 0xFF; beacon_pl.payload[64] = sat_data_buf.eps.data.battery_heater_1_duty_cycle; beacon_pl.payload[65] = sat_data_buf.eps.data.battery_heater_2_duty_cycle; - - if (!sat_data_buf.edc_0.enabled && !sat_data_buf.edc_0.enabled) - { - beacon_pl.payload[66] = 0x00U; - } - else if (sat_data_buf.edc_0.enabled && !sat_data_buf.edc_0.enabled) - { - beacon_pl.payload[66] = 0x01U; - } - else if (!sat_data_buf.edc_0.enabled && sat_data_buf.edc_0.enabled) - { - beacon_pl.payload[66] = 0x02U; - } - else - { - beacon_pl.payload[66] = 0x03U; - } - - beacon_pl.payload[67] = sat_data_buf.payload_x.enabled ? 0x01U : 0x00U; + beacon_pl.payload[66] = sat_data_buf.state.main_edc; + beacon_pl.payload[67] = sat_data_buf.state.active_payload; beacon_pl.length = 68U; diff --git a/firmware/app/tasks/data_log.c b/firmware/app/tasks/data_log.c index b1dc9194..e3866dce 100644 --- a/firmware/app/tasks/data_log.c +++ b/firmware/app/tasks/data_log.c @@ -25,8 +25,8 @@ * * \author Gabriel Mariano Marcelino * \author Carlos Augusto Porto Freitas - * - * \version 0.10.18 + * + * \version 0.10.19 * * \date 2021/05/24 * @@ -114,7 +114,7 @@ void vTaskDataLog(void) (void)memset(&page_buf[0], 0, 256); /* EDC data */ - (void)memcpy(&page_buf[0], &sat_data_buf.edc_0, sizeof(payload_telemetry_t)); + (void)memcpy(&page_buf[0], sat_data_buf.state.c_edc, sizeof(payload_telemetry_t)); if (mem_mng_write_data_to_flash_page(page_buf, &sat_data_buf.obdh.data.media.last_page_edc_data, nor_info.page_size, CONFIG_MEM_EDC_DATA_START_PAGE, CONFIG_MEM_EDC_DATA_END_PAGE) != 0) { sys_log_print_event_from_module(SYS_LOG_ERROR, TASK_DATA_LOG_NAME, "Error writing the EDC data to the flash memory!"); diff --git a/firmware/app/tasks/housekeeping.c b/firmware/app/tasks/housekeeping.c index 4ec7506a..673502ff 100644 --- a/firmware/app/tasks/housekeeping.c +++ b/firmware/app/tasks/housekeeping.c @@ -26,7 +26,7 @@ * \author Gabriel Mariano Marcelino * \author Carlos Augusto Porto Freitas * - * \version 0.10.18 + * \version 0.10.19 * * \date 2021/04/27 * @@ -39,6 +39,7 @@ #include #include #include +#include #include @@ -56,29 +57,16 @@ void vTaskHousekeeping(void) { TickType_t last_cycle = xTaskGetTickCount(); - /* Hibernation mode check */ - if (sat_data_buf.obdh.data.mode == OBDH_MODE_HIBERNATION) + /* Save the last available OBDH data at every minute */ + if (mem_mng_save_obdh_data_to_fram(&sat_data_buf.obdh) != 0) { - if ((sat_data_buf.obdh.data.ts_last_mode_change + sat_data_buf.obdh.data.mode_duration) >= system_get_time()) - { - sat_data_buf.obdh.data.mode = OBDH_MODE_NORMAL; - sat_data_buf.obdh.data.ts_last_mode_change = system_get_time(); - } + sys_log_print_event_from_module(SYS_LOG_ERROR, TASK_HOUSEKEEPING_NAME, "Error writing data to the FRAM memory!"); + sys_log_new_line(); } - - /* Save the last available OBDH data at every minute */ - if ((system_get_time() % 60U) == 0U) + else { - if (mem_mng_save_obdh_data_to_fram(&sat_data_buf.obdh) != 0) - { - sys_log_print_event_from_module(SYS_LOG_ERROR, TASK_HOUSEKEEPING_NAME, "Error writing data to the FRAM memory!"); - sys_log_new_line(); - } - else - { - sys_log_print_event_from_module(SYS_LOG_INFO, TASK_HOUSEKEEPING_NAME, "Saving obdh data to fram..."); - sys_log_new_line(); - } + sys_log_print_event_from_module(SYS_LOG_INFO, TASK_HOUSEKEEPING_NAME, "Saving obdh data to fram..."); + sys_log_new_line(); } vTaskDelayUntil(&last_cycle, pdMS_TO_TICKS(TASK_HOUSEKEEPING_PERIOD_MS)); diff --git a/firmware/app/tasks/housekeeping.h b/firmware/app/tasks/housekeeping.h index d474d851..fa77649a 100644 --- a/firmware/app/tasks/housekeeping.h +++ b/firmware/app/tasks/housekeeping.h @@ -24,8 +24,9 @@ * \brief Housekeeping task definition. * * \author Gabriel Mariano Marcelino + * \author Carlos Augusto Porto Freitas * - * \version 0.10.17 + * \version 0.10.19 * * \date 2021/04/27 * @@ -43,7 +44,7 @@ #define TASK_HOUSEKEEPING_NAME "Housekeeping" /**< Task name. */ #define TASK_HOUSEKEEPING_STACK_SIZE 225 /**< Stack size in bytes. */ #define TASK_HOUSEKEEPING_PRIORITY 3 /**< Task priority. */ -#define TASK_HOUSEKEEPING_PERIOD_MS (10000) /**< Task period in milliseconds. */ +#define TASK_HOUSEKEEPING_PERIOD_MS (60000) /**< Task period in milliseconds. */ #define TASK_HOUSEKEEPING_INIT_TIMEOUT_MS 2000 /**< Wait time to initialize the task in milliseconds. */ /** diff --git a/firmware/app/tasks/mem_check.c b/firmware/app/tasks/mem_check.c index c4e573da..e6dd1893 100644 --- a/firmware/app/tasks/mem_check.c +++ b/firmware/app/tasks/mem_check.c @@ -25,7 +25,7 @@ * * \author Carlos Augusto Porto Freitas * - * \version 0.10.18 + * \version 0.10.19 * * \date 2024/07/24 * @@ -47,11 +47,12 @@ #include "mem_check.h" #include "startup.h" +#include "mode_check.h" #define PAGE_SIZE ((uint32_t)256UL) #define SEG_SIZE ((uint32_t)128UL) #define PAGE_TO_ADDR(page) ((page) * PAGE_SIZE) -#define PAGE_CHECK_DEPTH ((uint32_t)10UL) +#define PAGE_CHECK_DEPTH ((uint32_t)CONFIG_HEALTH_CHECK_PAGES_TO_VALIDATE) #define ARR_SIZE(arr) (sizeof((arr))/sizeof((arr)[0])) #define ADDR_TO_PAGE(addr) ((uint32_t)(addr) / PAGE_SIZE) @@ -207,6 +208,9 @@ void vTaskHealthCheckMem(void) sys_log_print_event_from_module(SYS_LOG_INFO, TASK_HEALTH_CHECK_MEM_NAME, "Health Check finished!!"); sys_log_new_line(); + /* Notify Next Health Check */ + xTaskNotify(xTaskHealthCheckModeHandle, 0U, eNoAction); + vTaskSuspend(NULL); } } diff --git a/firmware/app/tasks/mode_check.c b/firmware/app/tasks/mode_check.c new file mode 100644 index 00000000..66bb3bd2 --- /dev/null +++ b/firmware/app/tasks/mode_check.c @@ -0,0 +1,182 @@ +/* + * mode_check.c + * + * Copyright The OBDH 2.0 Contributors. + * + * This file is part of OBDH 2.0. + * + * OBDH 2.0 is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * OBDH 2.0 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with OBDH 2.0. If not, see . + * + */ + +/** + * \brief Operation Mode Health Check Tasks implementation + * + * \author Carlos Augusto Porto Freitas + * + * \version 0.10.19 + * + * \date 2024/08/09 + * + * \addtogroup mode_check + * \{ + */ + +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "mode_check.h" +#include "op_ctrl.h" + +TaskHandle_t xTaskHealthCheckModeHandle; + +static void vTimeControlMockup(TimerHandle_t timer) +{ + (void)timer; + system_increment_time(); +} + +void vTaskHealthCheckMode(void) +{ + TimerHandle_t sys_timer = xTimerCreate("System Timer", pdMS_TO_TICKS(1000U), pdTRUE, NULL, vTimeControlMockup); + + xTimerStart(sys_timer, pdMS_TO_TICKS(10U)); + + while(1) + { + bool test_result; + + if (xTaskNotifyWait(0UL, UINT32_MAX, NULL, portMAX_DELAY) == pdTRUE) + { + sys_log_print_event_from_module(SYS_LOG_INFO, TASK_HEALTH_CHECK_MODE_NAME, "Starting Operation Mode Health Check..."); + sys_log_new_line(); + + notify_op_ctrl(SAT_NOTIFY_IN_BRAZIL); + + vTaskDelay(pdMS_TO_TICKS(2000U)); + + test_result = (sat_data_buf.obdh.data.mode == OBDH_MODE_NORMAL) && ((sat_data_buf.state.active_payload == PAYLOAD_EDC_0) || (sat_data_buf.state.active_payload == PAYLOAD_EDC_1)); + + sys_log_print_test_result(test_result, "In Brazil Notify Test"); + sys_log_new_line(); + + notify_op_ctrl(SAT_NOTIFY_OUT_OF_BRAZIL); + + vTaskDelay(pdMS_TO_TICKS(2000U)); + + test_result = (sat_data_buf.obdh.data.mode == OBDH_MODE_NORMAL) && (sat_data_buf.state.active_payload == PAYLOAD_X); + + sys_log_print_test_result(test_result, "Out of Brazil Notify Test"); + sys_log_new_line(); + + notify_op_ctrl(SAT_NOTIFY_PX_FINISHED); + + vTaskDelay(pdMS_TO_TICKS(2000U)); + + test_result = (sat_data_buf.obdh.data.mode == OBDH_MODE_STAND_BY) && (sat_data_buf.state.active_payload == PAYLOAD_NONE); + + sys_log_print_test_result(test_result, "Payload X finished Notify Test"); + sys_log_new_line(); + + notify_op_ctrl(SAT_NOTIFY_IN_BRAZIL); + taskYIELD(); + notify_op_ctrl(SAT_NOTIFY_OUT_OF_BRAZIL); + taskYIELD(); + notify_op_ctrl(SAT_NOTIFY_PX_FINISHED); + + vTaskDelay(pdMS_TO_TICKS(2000U)); + + test_result = (sat_data_buf.obdh.data.mode == OBDH_MODE_STAND_BY) && (sat_data_buf.state.active_payload == PAYLOAD_NONE); + + sys_log_print_test_result(test_result, "Position relative Notifications Test"); + sys_log_new_line(); + + sat_data_buf.obdh.data.mode_duration = 10; + notify_op_ctrl(SAT_NOTIFY_ENTER_HIBERNATION); + + vTaskDelay(pdMS_TO_TICKS(2000U)); + + test_result = (sat_data_buf.obdh.data.mode == OBDH_MODE_HIBERNATION); + + sys_log_print_test_result(test_result, "Enter hibernation Test"); + sys_log_new_line(); + + notify_op_ctrl(SAT_NOTIFY_LEAVE_HIBERNATION); + + vTaskDelay(pdMS_TO_TICKS(2000U)); + + test_result = (sat_data_buf.obdh.data.mode == OBDH_MODE_STAND_BY); + + sys_log_print_test_result(test_result, "Leave hibernation Test"); + sys_log_new_line(); + + sat_data_buf.obdh.data.mode_duration = 10; + notify_op_ctrl(SAT_NOTIFY_ENTER_HIBERNATION); + + vTaskDelay(pdMS_TO_TICKS(2000U)); + + TickType_t hib_time_init = xTaskGetTickCount(); + + vTaskDelayUntil(&hib_time_init, pdMS_TO_TICKS(11000U)); + + test_result = (sat_data_buf.obdh.data.mode != OBDH_MODE_HIBERNATION); + + sys_log_print_test_result(test_result, "Hibernation time Test"); + sys_log_new_line(); + + sat_data_buf.obdh.data.mode_duration = 10; + notify_op_ctrl(SAT_NOTIFY_ENTER_HIBERNATION); + + taskYIELD(); + + notify_op_ctrl(SAT_NOTIFY_IN_BRAZIL); + + vTaskDelay(pdMS_TO_TICKS(2000U)); + + test_result = (sat_data_buf.obdh.data.mode == OBDH_MODE_HIBERNATION); + + sys_log_print_test_result(test_result, "Hibernation mode persistency Test [EDC]"); + sys_log_new_line(); + + taskYIELD(); + + notify_op_ctrl(SAT_NOTIFY_OUT_OF_BRAZIL); + + vTaskDelay(pdMS_TO_TICKS(2000U)); + + test_result = (sat_data_buf.obdh.data.mode == OBDH_MODE_HIBERNATION); + + sys_log_print_test_result(test_result, "Hibernation mode persistency Test [PX]"); + sys_log_new_line(); + } + + sys_log_print_event_from_module(SYS_LOG_INFO, TASK_HEALTH_CHECK_MODE_NAME, "Operation Mode Health Check Finished!!!"); + sys_log_new_line(); + + vTaskSuspend(NULL); + } +} + +/** \} End of mode_check group */ + diff --git a/firmware/app/tasks/mode_check.h b/firmware/app/tasks/mode_check.h new file mode 100644 index 00000000..5a369f54 --- /dev/null +++ b/firmware/app/tasks/mode_check.h @@ -0,0 +1,61 @@ +/* + * mode_check.h + * + * Copyright The OBDH 2.0 Contributors. + * + * This file is part of OBDH 2.0. + * + * OBDH 2.0 is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * OBDH 2.0 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with OBDH 2.0. If not, see . + * + */ + +/** + * \brief Operation Mode Health Check Tasks definitions + * + * \author Carlos Augusto Porto Freitas + * + * \version 0.10.19 + * + * \date 2024/08/09 + * + * \defgroup mode_check Operation Mode Check + * \ingroup tasks + * \{ + */ + +#ifndef MODE_CHECK_H_ +#define MODE_CHECK_H_ + +#include +#include + +#define TASK_HEALTH_CHECK_MODE_NAME "HealthCheck Mode" /**< Task name. */ +#define TASK_HEALTH_CHECK_MODE_STACK_SIZE 1024U /**< Stack size in bytes. */ +#define TASK_HEALTH_CHECK_MODE_PRIORITY 3U /**< Task priority. */ + +/** + * \brief Health Check Operation Mode Task Handle + */ +extern TaskHandle_t xTaskHealthCheckModeHandle; + +/** + * \brief Health Check Operation Mode Task + * + * \return None. + */ +void vTaskHealthCheckMode(void); + +#endif + +/** \} End of mode_check group */ diff --git a/firmware/app/tasks/op_ctrl.c b/firmware/app/tasks/op_ctrl.c new file mode 100644 index 00000000..d04b0ea6 --- /dev/null +++ b/firmware/app/tasks/op_ctrl.c @@ -0,0 +1,274 @@ +/* + * op_ctrl.c + * + * Copyright The OBDH 2.0 Contributors. + * + * This file is part of OBDH 2.0. + * + * OBDH 2.0 is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * OBDH 2.0 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with OBDH 2.0. If not, see . + * + */ + +/** + * \brief Operation Control Task implementation + * + * \author Carlos Augusto Porto Freitas + * + * \version 0.10.19 + * + * \date 2024/08/04 + * + * \addtogroup op_ctrl + * \{ + */ + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "read_px.h" +#include "read_edc.h" +#include "op_ctrl.h" + +static inline void handle_notification(uint32_t notify_value); + +static int enable_main_edc(void); +static int enable_px(void); +static int disable_curr_payload(void); + +static bool in_brazil = false; +static bool edc_active = false; +static bool in_hibernation = false; + +TaskHandle_t xTaskOpCtrlHandle; + +void vTaskOpCtrl(void) +{ + uint32_t notify_value; + sat_data_buf.state.c_edc = &sat_data_buf.edc_0; + + TickType_t last_cycle = xTaskGetTickCount(); + + while (1) + { + if (xTaskNotifyWait(0UL, UINT32_MAX, ¬ify_value, 0UL) == pdTRUE) + { + handle_notification(notify_value); + } + + /* Hibernation mode check */ + if (sat_data_buf.obdh.data.mode == OBDH_MODE_HIBERNATION) + { + if ((sat_data_buf.obdh.data.ts_last_mode_change + sat_data_buf.obdh.data.mode_duration) <= system_get_time()) + { + if (in_brazil || (sat_data_buf.state.active_payload == PAYLOAD_X)) + { + satellite_change_mode(OBDH_MODE_NORMAL); + } + else + { + satellite_change_mode(OBDH_MODE_STAND_BY); + } + + in_hibernation = false; + } + } + + /* Nominal mode notification */ + if (in_brazil && edc_active) + { + /* Notifies to Read EDC task that the EDC is active. + * Must happen because the task depends on the notification + * to be pending for it to read EDC data. */ + xTaskNotifyGive(xTaskReadEDCHandle); + } + + vTaskDelayUntil(&last_cycle, pdMS_TO_TICKS(TASK_OP_CTRL_PERIOD_MS)); + } +} + +void notify_op_ctrl(uint32_t notification_flag) +{ + xTaskNotify(xTaskOpCtrlHandle, notification_flag, eSetBits); +} + +void satellite_change_mode(uint8_t mode) +{ + /* This ensures the mode change is done atomically */ + taskENTER_CRITICAL(); + sat_data_buf.obdh.data.mode = mode; + sat_data_buf.obdh.data.ts_last_mode_change = system_get_time(); + taskEXIT_CRITICAL(); +} + +static inline void handle_notification(uint32_t notify_value) +{ + uint32_t px_active_time_ms = (uint32_t)PAYLOAD_X_EXPERIMENT_PERIOD_MS; + + if ((notify_value & SAT_NOTIFY_ENTER_HIBERNATION) != 0U) + { + in_hibernation = true; + satellite_change_mode(OBDH_MODE_HIBERNATION); + } + + if ((notify_value & SAT_NOTIFY_LEAVE_HIBERNATION) != 0U) + { + in_hibernation = false; + + if (in_brazil || (sat_data_buf.state.active_payload == PAYLOAD_X)) + { + satellite_change_mode(OBDH_MODE_NORMAL); + } + else + { + satellite_change_mode(OBDH_MODE_STAND_BY); + } + } + + if ((notify_value & SAT_NOTIFY_IN_BRAZIL) != 0U) + { + sys_log_print_event_from_module(SYS_LOG_WARNING, TASK_OP_CTRL_NAME, "Changing Satellite Mode to NOMINAL!"); + sys_log_new_line(); + + if (!in_hibernation) + { + satellite_change_mode(OBDH_MODE_NORMAL); + } + + /* It means the satellite just entered Brazilian territory*/ + if (!in_brazil) + { + in_brazil = true; + + if (enable_main_edc() != 0) + { + sys_log_print_event_from_module(SYS_LOG_ERROR, TASK_OP_CTRL_NAME, "Failed to enable main EDC"); + sys_log_new_line(); + } + else + { + edc_active = true; + } + } + } + + if ((notify_value & SAT_NOTIFY_OUT_OF_BRAZIL) != 0U) + { + edc_active = false; + + /* Stop the Read EDC task */ + xTaskNotify(xTaskReadEDCHandle, 0UL, eSetValueWithOverwrite); + + if (disable_curr_payload() != 0) + { + sys_log_print_event_from_module(SYS_LOG_ERROR, TASK_OP_CTRL_NAME, "Failed to disable active payload"); + sys_log_new_line(); + } + + if (in_brazil) + { + in_brazil = false; + + sys_log_print_event_from_module(SYS_LOG_WARNING, TASK_OP_CTRL_NAME, "Satellite is out of Brazil territory"); + sys_log_new_line(); + + if (enable_px() != 0) + { + sys_log_print_event_from_module(SYS_LOG_ERROR, TASK_OP_CTRL_NAME, "Failed to enable Payload X"); + sys_log_new_line(); + } + else + { + xTaskNotify(xTaskReadPXHandle, px_active_time_ms, eSetValueWithOverwrite); + } + } + } + + if ((notify_value & SAT_NOTIFY_PX_FINISHED) != 0U) + { + sys_log_print_event_from_module(SYS_LOG_WARNING, TASK_OP_CTRL_NAME, "Changing Satellite Mode to STAND BY!"); + sys_log_new_line(); + + if (!in_hibernation) + { + satellite_change_mode(OBDH_MODE_STAND_BY); + } + + if (disable_curr_payload() != 0) + { + sys_log_print_event_from_module(SYS_LOG_ERROR, TASK_OP_CTRL_NAME, "Failed to disable active payload"); + sys_log_new_line(); + } + + sat_data_buf.state.active_payload = PAYLOAD_NONE; + } +} + +static int enable_main_edc(void) +{ + int err = -1; + + sat_data_buf.state.active_payload = sat_data_buf.state.main_edc; + + if (sat_data_buf.state.main_edc == PAYLOAD_EDC_0) + { + payload_enable(PAYLOAD_EDC_0); + sat_data_buf.state.c_edc = &sat_data_buf.edc_0; + err = 0; + } + else + { + payload_enable(PAYLOAD_EDC_1); + sat_data_buf.state.c_edc = &sat_data_buf.edc_1; + err = 0; + } + + return err; +} + +static int enable_px(void) +{ + int err = -1; + + sat_data_buf.state.active_payload = PAYLOAD_X; + + if (payload_enable(PAYLOAD_X) == 0) + { + err = 0; + } + + return err; +} + +static int disable_curr_payload(void) +{ + int err = -1; + + payload_t active_payload = sat_data_buf.state.active_payload; + + if (payload_disable(active_payload) == 0) + { + err = 0; + } + + return err; +} + +/** \} End of op_ctrl group */ diff --git a/firmware/app/tasks/op_ctrl.h b/firmware/app/tasks/op_ctrl.h new file mode 100644 index 00000000..3387bb6d --- /dev/null +++ b/firmware/app/tasks/op_ctrl.h @@ -0,0 +1,97 @@ +/* + * op_ctrl.h + * + * Copyright The OBDH 2.0 Contributors. + * + * This file is part of OBDH 2.0. + * + * OBDH 2.0 is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * OBDH 2.0 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with OBDH 2.0. If not, see . + * + */ + +/** + * \brief Operation Control Task definition + * + * \author Carlos Augusto Porto Freitas + * + * \version 0.10.19 + * + * \date 2024/08/04 + * + * \defgroup op_ctrl Operation Control + * \ingroup tasks + * \{ + */ + +#ifndef OP_CTRL_H_ +#define OP_CTRL_H_ + +#include + +#include +#include + +#include +#include + +#define TASK_OP_CTRL_NAME "Operation Control" /**< Task name. */ +#define TASK_OP_CTRL_STACK_SIZE 256U /**< Stack size in bytes. */ +#define TASK_OP_CTRL_PRIORITY 4U /**< Task priority. */ +#define TASK_OP_CTRL_PERIOD_MS 2000UL /**< Task period in milliseconds. */ +#define TASK_OP_CTRL_INIT_TIMEOUT_MS 2000U /**< Task priority. */ + +#define PAYLOAD_X_EXPERIMENT_PERIOD_MS (600000UL) /**< Payload X default experiment time in milliseconds. */ +#define PAYLOAD_X_CANCEL_EXPERIMENT_FLAG (1UL << 31UL) /**< Flag used as a notification to cancel running experiment */ + +#define SAT_NOTIFY_IN_BRAZIL (1UL << 0UL) /**< In Brazil notification flag */ +#define SAT_NOTIFY_OUT_OF_BRAZIL (1UL << 1UL) /**< Outside Brazil notification flag */ +#define SAT_NOTIFY_PX_FINISHED (1UL << 2UL) /**< Payload X experiment period finished flag */ +#define SAT_NOTIFY_ENTER_HIBERNATION (1UL << 3UL) /**< A request to enter hibernation was made through TC */ +#define SAT_NOTIFY_LEAVE_HIBERNATION (1UL << 4UL) /**< A request to leave hibernation was made through TC */ + +/** + * \brief Changes satellite's operation mode. + * + * \param[in] mode is the satellite mode to enter. + * + * \return None. + */ +void satellite_change_mode(const uint8_t mode); + +/** + * \brief Operation Control Task Handle + */ +extern TaskHandle_t xTaskOpCtrlHandle; + +/** + * \brief Operation Control Task + * + * \return None. + */ +void vTaskOpCtrl(void); + +/** + * \brief Sends a notification to the Operation Control Task. + * + * \param[in] notification_flag is the notification flag to send + * to the Operation Control Task. A example of a flag would be + * SAT_NOTIFY_IN_BRAZIL. + * + * \return None. + */ +void notify_op_ctrl(uint32_t notification_flag); + +#endif + +/** \} End of op_ctrl group */ diff --git a/firmware/app/tasks/pos_det.c b/firmware/app/tasks/pos_det.c index f1f6a345..dd6787b9 100644 --- a/firmware/app/tasks/pos_det.c +++ b/firmware/app/tasks/pos_det.c @@ -24,8 +24,9 @@ * \brief Position determination task implementation. * * \author Gabriel Mariano Marcelino + * \author Carlos Augusto Porto Freitas * - * \version 0.10.7 + * \version 0.10.19 * * \date 2023/07/19 * @@ -41,6 +42,7 @@ #include "pos_det.h" #include "startup.h" +#include "op_ctrl.h" #ifndef M_PI #define M_PI 3.14159265358979323846 @@ -50,6 +52,9 @@ xTaskHandle xTaskPosDetHandle; void vTaskPosDet(void) { + /* Flag used to control notification sending */ + bool sat_is_inside_brazil = false; + /* Wait startup task to finish */ xEventGroupWaitBits(task_startup_status, TASK_STARTUP_DONE, pdFALSE, pdTRUE, pdMS_TO_TICKS(TASK_POS_DET_INIT_TIMEOUT_MS)); @@ -101,6 +106,20 @@ void vTaskPosDet(void) predict_destroy_orbital_elements(satellite); + bool current_position = is_satellite_in_brazil(sat_data_buf.obdh.data.position.latitude, sat_data_buf.obdh.data.position.longitude); + + if (current_position && !sat_is_inside_brazil) + { + sat_is_inside_brazil = true; + notify_op_ctrl(SAT_NOTIFY_IN_BRAZIL); + } + + if (!current_position && sat_is_inside_brazil) + { + sat_is_inside_brazil = false; + notify_op_ctrl(SAT_NOTIFY_OUT_OF_BRAZIL); + } + vTaskDelayUntil(&last_cycle, pdMS_TO_TICKS(TASK_POS_DET_PERIOD_MS)); } } diff --git a/firmware/app/tasks/pos_det.h b/firmware/app/tasks/pos_det.h index 5bc2aadf..ef5e2a25 100644 --- a/firmware/app/tasks/pos_det.h +++ b/firmware/app/tasks/pos_det.h @@ -24,8 +24,9 @@ * \brief Position determination task definition. * * \author Gabriel Mariano Marcelino + * \author Carlos Augusto Porto Freitas * - * \version 0.10.7 + * \version 0.10.19 * * \date 2023/07/19 * @@ -37,8 +38,12 @@ #ifndef POS_DET_H_ #define POS_DET_H_ +#include +#include + #include #include +#include #define TASK_POS_DET_NAME "Position" /**< Task name. */ #define TASK_POS_DET_STACK_SIZE 1024 /**< Stack size in bytes. */ @@ -46,6 +51,25 @@ #define TASK_POS_DET_PERIOD_MS 60000 /**< Task period in milliseconds. */ #define TASK_POS_DET_INIT_TIMEOUT_MS 1000 /**< Wait time to initialize the task in milliseconds. */ +#define POS_BRAZIL_LIM_N (6L) /**< Brazil territory North limit (Rounded up) */ +#define POS_BRAZIL_LIM_S (-34L) /**< Brazil territory South limit (Rounded up) */ +#define POS_BRAZIL_LIM_E (-35L) /**< Brazil territory East limit (Rounded up) */ +#define POS_BRAZIL_LIM_W (-74L) /**< Brazil territory West limit (Rounded up) */ + +/** + * \brief Checks if the satellite is orbiting over Brazil, based on the last available position determined. + * + * \param[in] latitude is the latitude of the satellite as a int16_t. + * + * \param[in] longitude is the longitude of the satellite as a int16_t. + * + * \return True if the satellite is over Brazil, false if it is not. + */ +static inline bool is_satellite_in_brazil(int16_t latitude, int16_t longitude) +{ + return ((latitude >= POS_BRAZIL_LIM_S) && (latitude <= POS_BRAZIL_LIM_N) && (longitude >= POS_BRAZIL_LIM_W) && (longitude <= POS_BRAZIL_LIM_E)); +} + /** * \brief Position determination task handle. */ diff --git a/firmware/app/tasks/process_tc.c b/firmware/app/tasks/process_tc.c index 1fb30dda..55211656 100644 --- a/firmware/app/tasks/process_tc.c +++ b/firmware/app/tasks/process_tc.c @@ -26,7 +26,7 @@ * \author Gabriel Mariano Marcelino * \author Carlos Augusto Porto Freitas * - * \version 0.10.14 + * \version 0.10.19 * * \date 2021/07/06 * @@ -42,8 +42,10 @@ #include #include #include +#include #include #include +#include #include #include @@ -51,6 +53,7 @@ #include #include "process_tc.h" +#include "op_ctrl.h" #include "startup.h" xTaskHandle xTaskProcessTCHandle; @@ -374,15 +377,17 @@ void process_tc_ping_request(uint8_t *pkt, uint16_t pkt_len) /* Source callsign */ fsat_pkt_add_callsign(&pong_pl, CONFIG_SATELLITE_CALLSIGN); - if (memcpy(&pong_pl.payload[0], &pkt[1], 7) == &pong_pl.payload[0]) - { - pong_pl.length = 7U; + (void)memcpy(&pong_pl.payload[0], &pkt[1], 7); + + pong_pl.length = 7U; - uint8_t pong_pl_raw[16] = {0}; - uint16_t pong_pl_raw_len = 0; + uint8_t pong_pl_raw[16] = {0}; + uint16_t pong_pl_raw_len = 0; - fsat_pkt_encode(pong_pl, pong_pl_raw, &pong_pl_raw_len); + fsat_pkt_encode(pong_pl, pong_pl_raw, &pong_pl_raw_len); + if (sat_data_buf.obdh.data.mode != OBDH_MODE_HIBERNATION) + { if (ttc_send(TTC_1, pong_pl_raw, pong_pl_raw_len) != 0) { sys_log_print_event_from_module(SYS_LOG_ERROR, TASK_PROCESS_TC_NAME, "Error transmitting a ping answer!"); @@ -394,7 +399,8 @@ void process_tc_ping_request(uint8_t *pkt, uint16_t pkt_len) void process_tc_data_request(uint8_t *pkt, uint16_t pkt_len) { - if (pkt_len >= (1U + 7U + 1U + 4U + 4U)) + /* If the satellite is in hibernation mode there is no point in processing this telecommand */ + if ((pkt_len >= (1U + 7U + 1U + 4U + 4U)) && (sat_data_buf.obdh.data.mode != OBDH_MODE_HIBERNATION)) { fsat_pkt_pl_t data_req_ans_pkt = {0}; uint8_t data_req_ans_pl[220] = {0}; @@ -431,52 +437,208 @@ void process_tc_data_request(uint8_t *pkt, uint16_t pkt_len) if (media_read(MEDIA_NOR, i * nor_info.page_size, page_buf, sizeof(obdh_telemetry_t)) == 0) { /* Requester callsign */ - if (memcpy(&data_req_ans_pl[0], &pkt[1], 7) == &data_req_ans_pl[0]) - { - /* Data ID */ - data_req_ans_pl[7] = CONFIG_DATA_ID_OBDH; + (void)memcpy(&data_req_ans_pl[0], &pkt[1], 7); - /* Timestamp and Data */ - if (memcpy(&data_req_ans_pl[7 + 1], &page_buf[0], sizeof(obdh_telemetry_t)) == &data_req_ans_pl[7 + 1]) - { - fsat_pkt_add_payload(&data_req_ans_pkt, data_req_ans_pl, 7U + 1U + sizeof(obdh_telemetry_t)); + /* Data ID */ + data_req_ans_pl[7] = CONFIG_DATA_ID_OBDH; + + /* Timestamp and Data */ + (void)memcpy(&data_req_ans_pl[7 + 1], &page_buf[0], sizeof(obdh_telemetry_t)); + + vTaskDelay(pdMS_TO_TICKS(10U)); - fsat_pkt_encode(data_req_ans_pkt, data_req_ans_raw, &data_req_ans_raw_len); + fsat_pkt_add_payload(&data_req_ans_pkt, data_req_ans_pl, 7U + 1U + sizeof(obdh_telemetry_t)); - if (ttc_send(TTC_1, data_req_ans_raw, data_req_ans_raw_len) != 0) - { - sys_log_print_event_from_module(SYS_LOG_ERROR, TASK_PROCESS_TC_NAME, "Error transmitting the OBDH data log of memory page "); - sys_log_print_uint(i); - sys_log_print_msg("!"); - sys_log_new_line(); - } + fsat_pkt_encode(data_req_ans_pkt, data_req_ans_raw, &data_req_ans_raw_len); + + if (sat_data_buf.obdh.data.mode != OBDH_MODE_HIBERNATION) + { + if (ttc_send(TTC_1, data_req_ans_raw, data_req_ans_raw_len) != 0) + { + sys_log_print_event_from_module(SYS_LOG_ERROR, TASK_PROCESS_TC_NAME, "Error transmitting the OBDH data log of memory page "); + sys_log_print_uint(i); + sys_log_print_msg("!"); + sys_log_new_line(); } } } + vTaskDelay(pdMS_TO_TICKS(25U)); } break; } case CONFIG_DATA_ID_EPS: - sys_log_print_event_from_module(SYS_LOG_WARNING, TASK_PROCESS_TC_NAME, "EPS data request not implemented!"); - sys_log_new_line(); + { + uint32_t start_page = sat_data_buf.obdh.data.media.last_page_eps_data - (uint32_t)end_idx; + uint32_t end_page = sat_data_buf.obdh.data.media.last_page_eps_data - (uint32_t)start_idx; + + uint8_t page_buf[256] = {0}; + + uint32_t i = 0; + for(i = start_page; i < end_page; i++) + { + if (media_read(MEDIA_NOR, i * nor_info.page_size, page_buf, sizeof(eps_telemetry_t)) == 0) + { + /* Requester callsign */ + (void)memcpy(&data_req_ans_pl[0], &pkt[1], 7); + + /* Data ID */ + data_req_ans_pl[7] = CONFIG_DATA_ID_EPS; + + /* Timestamp and Data */ + (void)memcpy(&data_req_ans_pl[7 + 1], &page_buf[0], sizeof(eps_telemetry_t)); + + vTaskDelay(pdMS_TO_TICKS(10U)); + + fsat_pkt_add_payload(&data_req_ans_pkt, data_req_ans_pl, 7U + 1U + sizeof(eps_telemetry_t)); + + fsat_pkt_encode(data_req_ans_pkt, data_req_ans_raw, &data_req_ans_raw_len); + + if (sat_data_buf.obdh.data.mode != OBDH_MODE_HIBERNATION) + { + if (ttc_send(TTC_1, data_req_ans_raw, data_req_ans_raw_len) != 0) + { + sys_log_print_event_from_module(SYS_LOG_ERROR, TASK_PROCESS_TC_NAME, "Error transmitting the EPS data log of memory page "); + sys_log_print_uint(i); + sys_log_print_msg("!"); + sys_log_new_line(); + } + } + } + vTaskDelay(pdMS_TO_TICKS(25U)); + } break; + } case CONFIG_DATA_ID_TTC_0: - sys_log_print_event_from_module(SYS_LOG_WARNING, TASK_PROCESS_TC_NAME, "TTC 0 data request not implemented!"); - sys_log_new_line(); + { + uint32_t start_page = sat_data_buf.obdh.data.media.last_page_ttc_0_data - (uint32_t)end_idx; + uint32_t end_page = sat_data_buf.obdh.data.media.last_page_ttc_0_data - (uint32_t)start_idx; + + uint8_t page_buf[256] = {0}; + + uint32_t i = 0; + for(i = start_page; i < end_page; i++) + { + if (media_read(MEDIA_NOR, i * nor_info.page_size, page_buf, sizeof(ttc_telemetry_t)) == 0) + { + /* Requester callsign */ + (void)memcpy(&data_req_ans_pl[0], &pkt[1], 7); + + /* Data ID */ + data_req_ans_pl[7] = CONFIG_DATA_ID_TTC_0; + + /* Timestamp and Data */ + (void)memcpy(&data_req_ans_pl[7 + 1], &page_buf[0], sizeof(ttc_telemetry_t)); + + vTaskDelay(pdMS_TO_TICKS(10U)); + + fsat_pkt_add_payload(&data_req_ans_pkt, data_req_ans_pl, 7U + 1U + sizeof(ttc_telemetry_t)); + + fsat_pkt_encode(data_req_ans_pkt, data_req_ans_raw, &data_req_ans_raw_len); + + if (sat_data_buf.obdh.data.mode != OBDH_MODE_HIBERNATION) + { + if (ttc_send(TTC_1, data_req_ans_raw, data_req_ans_raw_len) != 0) + { + sys_log_print_event_from_module(SYS_LOG_ERROR, TASK_PROCESS_TC_NAME, "Error transmitting the TTC 0 data log of memory page "); + sys_log_print_uint(i); + sys_log_print_msg("!"); + sys_log_new_line(); + } + } + } + vTaskDelay(pdMS_TO_TICKS(25U)); + } break; + } case CONFIG_DATA_ID_TTC_1: - sys_log_print_event_from_module(SYS_LOG_WARNING, TASK_PROCESS_TC_NAME, "TTC 1 data request not implemented!"); - sys_log_new_line(); + { + uint32_t start_page = sat_data_buf.obdh.data.media.last_page_ttc_1_data - (uint32_t)end_idx; + uint32_t end_page = sat_data_buf.obdh.data.media.last_page_ttc_1_data - (uint32_t)start_idx; + + uint8_t page_buf[256] = {0}; + + uint32_t i = 0; + for(i = start_page; i < end_page; i++) + { + if (media_read(MEDIA_NOR, i * nor_info.page_size, page_buf, sizeof(ttc_telemetry_t)) == 0) + { + /* Requester callsign */ + (void)memcpy(&data_req_ans_pl[0], &pkt[1], 7); + + /* Data ID */ + data_req_ans_pl[7] = CONFIG_DATA_ID_TTC_1; + + /* Timestamp and Data */ + (void)memcpy(&data_req_ans_pl[7 + 1], &page_buf[0], sizeof(ttc_telemetry_t)); + + vTaskDelay(pdMS_TO_TICKS(10U)); + + fsat_pkt_add_payload(&data_req_ans_pkt, data_req_ans_pl, 7U + 1U + sizeof(ttc_telemetry_t)); + + fsat_pkt_encode(data_req_ans_pkt, data_req_ans_raw, &data_req_ans_raw_len); + + if (sat_data_buf.obdh.data.mode != OBDH_MODE_HIBERNATION) + { + if (ttc_send(TTC_1, data_req_ans_raw, data_req_ans_raw_len) != 0) + { + sys_log_print_event_from_module(SYS_LOG_ERROR, TASK_PROCESS_TC_NAME, "Error transmitting the TTC 1 data log of memory page "); + sys_log_print_uint(i); + sys_log_print_msg("!"); + sys_log_new_line(); + } + } + } + vTaskDelay(pdMS_TO_TICKS(25U)); + } break; + } case CONFIG_DATA_ID_ANT: - sys_log_print_event_from_module(SYS_LOG_WARNING, TASK_PROCESS_TC_NAME, "Antenna data request not implemented!"); - sys_log_new_line(); + { + uint32_t start_page = sat_data_buf.obdh.data.media.last_page_ant_data - (uint32_t)end_idx; + uint32_t end_page = sat_data_buf.obdh.data.media.last_page_ant_data - (uint32_t)start_idx; + + uint8_t page_buf[256] = {0}; + + uint32_t i = 0; + for(i = start_page; i < end_page; i++) + { + if (media_read(MEDIA_NOR, i * nor_info.page_size, page_buf, sizeof(antenna_telemetry_t)) == 0) + { + /* Requester callsign */ + (void)memcpy(&data_req_ans_pl[0], &pkt[1], 7); + + /* Data ID */ + data_req_ans_pl[7] = CONFIG_DATA_ID_TTC_1; + + /* Timestamp and Data */ + (void)memcpy(&data_req_ans_pl[7 + 1], &page_buf[0], sizeof(antenna_telemetry_t)); + + vTaskDelay(pdMS_TO_TICKS(10U)); + + fsat_pkt_add_payload(&data_req_ans_pkt, data_req_ans_pl, 7U + 1U + sizeof(antenna_telemetry_t)); + + fsat_pkt_encode(data_req_ans_pkt, data_req_ans_raw, &data_req_ans_raw_len); + + if (sat_data_buf.obdh.data.mode != OBDH_MODE_HIBERNATION) + { + if (ttc_send(TTC_1, data_req_ans_raw, data_req_ans_raw_len) != 0) + { + sys_log_print_event_from_module(SYS_LOG_ERROR, TASK_PROCESS_TC_NAME, "Error transmitting the Antenna data log of memory page "); + sys_log_print_uint(i); + sys_log_print_msg("!"); + sys_log_new_line(); + } + } + } + vTaskDelay(pdMS_TO_TICKS(25U)); + } break; + } default: sys_log_print_event_from_module(SYS_LOG_ERROR, TASK_PROCESS_TC_NAME, "Error executing the \"Data Request\" TC! Unknown data ID!"); sys_log_new_line(); @@ -506,15 +668,17 @@ void process_tc_broadcast_message(uint8_t *pkt, uint16_t pkt_len) uint16_t msg_len = pkt_len - 7U - 7U - 1U; - if (memcpy(&broadcast_pl.payload[0], &pkt[1], 14U + msg_len) == &broadcast_pl.payload[0]) - { - broadcast_pl.length = 14U + msg_len; + (void)memcpy(&broadcast_pl.payload[0], &pkt[1], 14U + msg_len); + + broadcast_pl.length = 14U + msg_len; - uint8_t broadcast_pl_raw[55] = {0}; - uint16_t broadcast_pl_raw_len = 0; + uint8_t broadcast_pl_raw[55] = {0}; + uint16_t broadcast_pl_raw_len = 0; - fsat_pkt_encode(broadcast_pl, broadcast_pl_raw, &broadcast_pl_raw_len); + fsat_pkt_encode(broadcast_pl, broadcast_pl_raw, &broadcast_pl_raw_len); + if (sat_data_buf.obdh.data.mode != OBDH_MODE_HIBERNATION) + { if (ttc_send(TTC_1, broadcast_pl_raw, broadcast_pl_raw_len) != 0) { sys_log_print_event_from_module(SYS_LOG_ERROR, TASK_PROCESS_TC_NAME, "Error transmitting a message broadcast!"); @@ -532,9 +696,8 @@ void process_tc_enter_hibernation(uint8_t *pkt, uint16_t pkt_len) if (process_tc_validate_hmac(pkt, 1U + 7U + 2U, &pkt[10], 20U, tc_key, sizeof(CONFIG_TC_KEY_ENTER_HIBERNATION)-1U)) { - sat_data_buf.obdh.data.mode = OBDH_MODE_HIBERNATION; - sat_data_buf.obdh.data.ts_last_mode_change = system_get_time(); sat_data_buf.obdh.data.mode_duration = (((sys_time_t)pkt[8] << 8) | (sys_time_t)pkt[9]) * 60UL * 60UL; + notify_op_ctrl(SAT_NOTIFY_ENTER_HIBERNATION); } else { @@ -552,8 +715,7 @@ void process_tc_leave_hibernation(uint8_t *pkt, uint16_t pkt_len) if (process_tc_validate_hmac(pkt, 1U + 7U, &pkt[8], 20U, tc_key, sizeof(CONFIG_TC_KEY_LEAVE_HIBERNATION)-1U)) { - sat_data_buf.obdh.data.mode = OBDH_MODE_NORMAL; - sat_data_buf.obdh.data.ts_last_mode_change = system_get_time(); + notify_op_ctrl(SAT_NOTIFY_LEAVE_HIBERNATION); } else { @@ -895,18 +1057,9 @@ void process_tc_erase_memory(uint8_t *pkt, uint16_t pkt_len) if (process_tc_validate_hmac(pkt, 1U + 7U, &pkt[8], 20U, tc_key, sizeof(CONFIG_TC_KEY_ERASE_MEMORY)-1U)) { - sat_data_buf.obdh.data.media.last_page_obdh_data = CONFIG_MEM_OBDH_DATA_START_PAGE; - sat_data_buf.obdh.data.media.last_page_eps_data = CONFIG_MEM_EPS_DATA_START_PAGE; - sat_data_buf.obdh.data.media.last_page_ttc_0_data = CONFIG_MEM_TTC_0_DATA_START_PAGE; - sat_data_buf.obdh.data.media.last_page_ttc_1_data = CONFIG_MEM_TTC_1_DATA_END_PAGE; - sat_data_buf.obdh.data.media.last_page_ant_data = CONFIG_MEM_ANT_DATA_START_PAGE; - sat_data_buf.obdh.data.media.last_page_edc_data = CONFIG_MEM_EDC_DATA_START_PAGE; - sat_data_buf.obdh.data.media.last_page_px_data = CONFIG_MEM_PX_DATA_START_PAGE; - sat_data_buf.obdh.data.media.last_page_sbcd_pkts = CONFIG_MEM_SBCD_PKTS_START_PAGE; - - if (media_erase(MEDIA_NOR, MEDIA_ERASE_DIE, 0U) != 0) + if (mem_mng_erase_flash(&sat_data_buf.obdh) < 0) { - sys_log_print_event_from_module(SYS_LOG_ERROR, TASK_PROCESS_TC_NAME, "Error erasing the NOR memory!"); + sys_log_print_event_from_module(SYS_LOG_ERROR, TASK_PROCESS_TC_NAME, "Error erasing flash memory!"); sys_log_new_line(); } } @@ -1026,20 +1179,20 @@ void process_tc_get_parameter(uint8_t *pkt, uint16_t pkt_len) case CONFIG_SUBSYSTEM_ID_OBDH: switch(pkt[9]) { - case OBDH_PARAM_ID_TIME_COUNTER: buf = system_get_time(); break; - case OBDH_PARAM_ID_TEMPERATURE_UC: buf = sat_data_buf.obdh.data.temperature; break; - case OBDH_PARAM_ID_INPUT_CURRENT: buf = sat_data_buf.obdh.data.current; break; - case OBDH_PARAM_ID_INPUT_VOLTAGE: buf = sat_data_buf.obdh.data.voltage; break; - case OBDH_PARAM_ID_LAST_RESET_CAUSE: buf = sat_data_buf.obdh.data.last_reset_cause; break; - case OBDH_PARAM_ID_RESET_COUNTER: buf = sat_data_buf.obdh.data.reset_counter; break; - case OBDH_PARAM_ID_LAST_VALID_TC: buf = sat_data_buf.obdh.data.last_valid_tc; break; - case OBDH_PARAM_ID_TEMPERATURE_ANTENNA: buf = sat_data_buf.antenna.data.temperature; break; - case OBDH_PARAM_ID_ANTENNA_STATUS: buf = sat_data_buf.antenna.data.status.code; break; - case OBDH_PARAM_ID_HARDWARE_VERSION: buf = sat_data_buf.obdh.data.hw_version; break; - case OBDH_PARAM_ID_FIRMWARE_VERSION: buf = sat_data_buf.obdh.data.fw_version; break; - case OBDH_PARAM_ID_MODE: buf = sat_data_buf.obdh.data.mode; break; - case OBDH_PARAM_ID_TIMESTAMP_LAST_MODE: buf = sat_data_buf.obdh.data.ts_last_mode_change; break; - case OBDH_PARAM_ID_MODE_DURATION: buf = sat_data_buf.obdh.data.mode_duration; break; + case OBDH_PARAM_ID_TIME_COUNTER: buf = system_get_time(); break; + case OBDH_PARAM_ID_TEMPERATURE_UC: buf = sat_data_buf.obdh.data.temperature; break; + case OBDH_PARAM_ID_INPUT_CURRENT: buf = sat_data_buf.obdh.data.current; break; + case OBDH_PARAM_ID_INPUT_VOLTAGE: buf = sat_data_buf.obdh.data.voltage; break; + case OBDH_PARAM_ID_LAST_RESET_CAUSE: buf = sat_data_buf.obdh.data.last_reset_cause; break; + case OBDH_PARAM_ID_RESET_COUNTER: buf = sat_data_buf.obdh.data.reset_counter; break; + case OBDH_PARAM_ID_LAST_VALID_TC: buf = sat_data_buf.obdh.data.last_valid_tc; break; + case OBDH_PARAM_ID_TEMPERATURE_ANTENNA: buf = sat_data_buf.antenna.data.temperature; break; + case OBDH_PARAM_ID_ANTENNA_STATUS: buf = sat_data_buf.antenna.data.status.code; break; + case OBDH_PARAM_ID_HARDWARE_VERSION: buf = sat_data_buf.obdh.data.hw_version; break; + case OBDH_PARAM_ID_FIRMWARE_VERSION: buf = sat_data_buf.obdh.data.fw_version; break; + case OBDH_PARAM_ID_MODE: buf = sat_data_buf.obdh.data.mode; break; + case OBDH_PARAM_ID_TIMESTAMP_LAST_MODE: buf = sat_data_buf.obdh.data.ts_last_mode_change; break; + case OBDH_PARAM_ID_MODE_DURATION: buf = system_get_time() - sat_data_buf.obdh.data.ts_last_mode_change; break; default: error = -1; @@ -1099,22 +1252,24 @@ void process_tc_get_parameter(uint8_t *pkt, uint16_t pkt_len) /* Source callsign */ fsat_pkt_add_callsign(¶m_pl, CONFIG_SATELLITE_CALLSIGN); - if (memcpy(¶m_pl.payload[0], &pkt[1], 7) == ¶m_pl.payload[0]) - { - param_pl.payload[8] = pkt[8]; - param_pl.payload[9] = pkt[9]; - param_pl.payload[10] = (uint8_t)((buf >> 24) & 0xFFU); - param_pl.payload[11] = (uint8_t)((buf >> 16) & 0xFFU); - param_pl.payload[12] = (uint8_t)((buf >> 8) & 0xFFU); - param_pl.payload[13] = (uint8_t)(buf & 0xFFU); + (void)memcpy(¶m_pl.payload[0], &pkt[1], 7); + + param_pl.payload[8] = pkt[8]; + param_pl.payload[9] = pkt[9]; + param_pl.payload[10] = (uint8_t)((buf >> 24) & 0xFFU); + param_pl.payload[11] = (uint8_t)((buf >> 16) & 0xFFU); + param_pl.payload[12] = (uint8_t)((buf >> 8) & 0xFFU); + param_pl.payload[13] = (uint8_t)(buf & 0xFFU); - param_pl.length = 6U; + param_pl.length = 6U; - uint8_t param_pl_raw[16] = {0}; - uint16_t param_pl_raw_len = 0; + uint8_t param_pl_raw[16] = {0}; + uint16_t param_pl_raw_len = 0; - fsat_pkt_encode(param_pl, param_pl_raw, ¶m_pl_raw_len); + fsat_pkt_encode(param_pl, param_pl_raw, ¶m_pl_raw_len); + if (sat_data_buf.obdh.data.mode != OBDH_MODE_HIBERNATION) + { if (ttc_send(TTC_1, param_pl_raw, param_pl_raw_len) != 0) { sys_log_print_event_from_module(SYS_LOG_ERROR, TASK_PROCESS_TC_NAME, "Error transmitting a \"get parameter\" answer!"); diff --git a/firmware/app/tasks/read_edc.c b/firmware/app/tasks/read_edc.c index 17aec0bb..2044bb1b 100644 --- a/firmware/app/tasks/read_edc.c +++ b/firmware/app/tasks/read_edc.c @@ -25,8 +25,8 @@ * * \author Gabriel Mariano Marcelino * \author Carlos Augusto Porto Freitas - * - * \version 0.10.18 + * + * \version 0.10.19 * * \date 2020/08/16 * @@ -34,10 +34,14 @@ * \{ */ +#include +#include #include #include #include #include +#include +#include #include @@ -48,9 +52,11 @@ xTaskHandle xTaskReadEDCHandle; pl_edc_hk_raw_t edc_hk_buf = {0}; +static void print_edc_hk(uint8_t *hk); + void vTaskReadEDC(void) { - static payload_t pl_edc_active = PAYLOAD_EDC_0; + payload_telemetry_t **const edc = &sat_data_buf.state.c_edc; /* Wait startup task to finish */ xEventGroupWaitBits(task_startup_status, TASK_STARTUP_DONE, pdFALSE, pdTRUE, pdMS_TO_TICKS(TASK_READ_EDC_INIT_TIMEOUT_MS)); @@ -59,89 +65,138 @@ void vTaskReadEDC(void) while(1) { + uint32_t notification = ulTaskNotifyTake(pdFALSE, pdMS_TO_TICKS(TASK_READ_EDC_MAX_WAIT_TIME_MS)); + TickType_t last_cycle = xTaskGetTickCount(); - /* Read housekeeping data */ - if (payload_get_data(pl_edc_active, PAYLOAD_EDC_RAW_HK, edc_hk_buf.buffer, &edc_hk_buf.length) != 0) + payload_t pl_edc_active = sat_data_buf.state.active_payload; + + if (((pl_edc_active == PAYLOAD_EDC_0) || (pl_edc_active == PAYLOAD_EDC_1)) && (notification > 0UL)) { - sys_log_print_event_from_module(SYS_LOG_ERROR, TASK_READ_EDC_NAME, "Error reading the housekeeping data!"); - sys_log_new_line(); - } + /* Read housekeeping data */ + if (payload_get_data(pl_edc_active, PAYLOAD_EDC_RAW_HK, edc_hk_buf.buffer, &edc_hk_buf.length) != 0) + { + sys_log_print_event_from_module(SYS_LOG_ERROR, TASK_READ_EDC_NAME, "Error reading the housekeeping data!"); + sys_log_new_line(); + } + else + { + (void)memcpy((*edc)->data, edc_hk_buf.buffer, EDC_FRAME_HK_LEN); - vTaskDelay(pdMS_TO_TICKS(500)); /* Wait a while for the next command */ + vTaskDelay(pdMS_TO_TICKS(50U)); - /* Read packets */ - uint8_t state_arr[10] = {0}; - int32_t state_len = 0; + print_edc_hk(edc_hk_buf.buffer); + } - if (payload_get_data(pl_edc_active, PAYLOAD_EDC_STATE, state_arr, &state_len) == 0) - { - if (state_len >= (int32_t)sizeof(edc_state_t)) - { - edc_state_t state = *(edc_state_t*)&state_arr[0]; + vTaskDelay(pdMS_TO_TICKS(500)); /* Wait a while for the next command */ + + /* Read packets */ + uint8_t state_arr[10] = {0}; + int32_t state_len = 0; - if (state.ptt_available > 0) + if (payload_get_data(pl_edc_active, PAYLOAD_EDC_STATE, state_arr, &state_len) == 0) + { + if (state_len >= (int32_t)sizeof(edc_state_t)) { - sys_log_print_event_from_module(SYS_LOG_INFO, TASK_READ_EDC_NAME, ""); - sys_log_print_uint(state.ptt_available); - sys_log_print_msg(" PTT packet(s) available to read!"); - sys_log_new_line(); + (void)memcpy(&(*edc)->data[EDC_FRAME_HK_LEN], state_arr, EDC_FRAME_STATE_LEN); + + (*edc)->timestamp = system_get_time(); + + edc_state_t state = *(edc_state_t*)&state_arr[0]; - uint8_t i = 0; - for(i = 0; i < state.ptt_available; i++) + if (state.ptt_available > 0) { - uint8_t ptt_arr[50] = {0}; - int32_t ptt_len = 0; + sys_log_print_event_from_module(SYS_LOG_INFO, TASK_READ_EDC_NAME, ""); + sys_log_print_uint(state.ptt_available); + sys_log_print_msg(" PTT packet(s) available to read!"); + sys_log_new_line(); - if (payload_get_data(pl_edc_active, PAYLOAD_EDC_PTT, ptt_arr, &ptt_len) == 0) + vTaskDelay(pdMS_TO_TICKS(50U)); + + uint8_t i = 0; + for(i = 0; i < state.ptt_available; i++) { - if (mem_mng_write_data_to_flash_page(ptt_arr, &sat_data_buf.obdh.data.media.last_page_sbcd_pkts, nor_info.page_size, CONFIG_MEM_SBCD_PKTS_START_PAGE, CONFIG_MEM_SBCD_PKTS_END_PAGE) != 0) + uint8_t ptt_arr[50] = {0}; + int32_t ptt_len = 0; + + if (payload_get_data(pl_edc_active, PAYLOAD_EDC_PTT, ptt_arr, &ptt_len) == 0) { - sys_log_print_event_from_module(SYS_LOG_ERROR, TASK_READ_EDC_NAME, "Error writing the PTT packet to the flash memory!"); + if (mem_mng_write_data_to_flash_page(ptt_arr, &sat_data_buf.obdh.data.media.last_page_sbcd_pkts, nor_info.page_size, CONFIG_MEM_SBCD_PKTS_START_PAGE, CONFIG_MEM_SBCD_PKTS_END_PAGE) != 0) + { + sys_log_print_event_from_module(SYS_LOG_ERROR, TASK_READ_EDC_NAME, "Error writing the PTT packet to the flash memory!"); + sys_log_new_line(); + } + + edc_ptt_t ptt = *(edc_ptt_t*)&ptt_arr[0]; + + sys_log_print_event_from_module(SYS_LOG_INFO, TASK_READ_EDC_NAME, "Received PTT packet:"); + sys_log_new_line(); + sys_log_print_event_from_module(SYS_LOG_INFO, TASK_READ_EDC_NAME, "\tTime: "); + sys_log_print_uint(ptt.time_tag); + sys_log_print_msg(" sec"); + sys_log_new_line(); + sys_log_print_event_from_module(SYS_LOG_INFO, TASK_READ_EDC_NAME, "\tError code: "); + sys_log_print_uint(ptt.error_code); + sys_log_new_line(); + sys_log_print_event_from_module(SYS_LOG_INFO, TASK_READ_EDC_NAME, "\tCarrier frequency: "); + sys_log_print_uint(ptt.carrier_freq); + sys_log_print_msg(" Hz"); + sys_log_new_line(); + sys_log_print_event_from_module(SYS_LOG_INFO, TASK_READ_EDC_NAME, "\tCarrier amplitude: "); + sys_log_print_uint(ptt.carrier_abs); + sys_log_new_line(); + sys_log_print_event_from_module(SYS_LOG_INFO, TASK_READ_EDC_NAME, "\tUser message: "); + sys_log_dump_hex(ptt.user_msg, ptt.msg_byte_length); + sys_log_new_line(); + } + else + { + sys_log_print_event_from_module(SYS_LOG_ERROR, TASK_READ_EDC_NAME, "Error reading PTT package!"); sys_log_new_line(); } - edc_ptt_t ptt = *(edc_ptt_t*)&ptt_arr[0]; - - sys_log_print_event_from_module(SYS_LOG_INFO, TASK_READ_EDC_NAME, "Received PTT packet:"); - sys_log_new_line(); - sys_log_print_event_from_module(SYS_LOG_INFO, TASK_READ_EDC_NAME, "\tTime: "); - sys_log_print_uint(ptt.time_tag); - sys_log_print_msg(" sec"); - sys_log_new_line(); - sys_log_print_event_from_module(SYS_LOG_INFO, TASK_READ_EDC_NAME, "\tError code: "); - sys_log_print_uint(ptt.error_code); - sys_log_new_line(); - sys_log_print_event_from_module(SYS_LOG_INFO, TASK_READ_EDC_NAME, "\tCarrier frequency: "); - sys_log_print_uint(ptt.carrier_freq); - sys_log_print_msg(" Hz"); - sys_log_new_line(); - sys_log_print_event_from_module(SYS_LOG_INFO, TASK_READ_EDC_NAME, "\tCarrier amplitude: "); - sys_log_print_uint(ptt.carrier_abs); - sys_log_new_line(); - sys_log_print_event_from_module(SYS_LOG_INFO, TASK_READ_EDC_NAME, "\tUser message: "); - sys_log_dump_hex(ptt.user_msg, ptt.msg_byte_length); - sys_log_new_line(); - } - else - { - sys_log_print_event_from_module(SYS_LOG_ERROR, TASK_READ_EDC_NAME, "Error reading PTT package!"); - sys_log_new_line(); + vTaskDelay(pdMS_TO_TICKS(500)); /* Wait a while for the next command */ } - - vTaskDelay(pdMS_TO_TICKS(500)); /* Wait a while for the next command */ } } } - } - else - { - sys_log_print_event_from_module(SYS_LOG_ERROR, TASK_READ_EDC_NAME, "Error reading the state data!"); - sys_log_new_line(); + else + { + sys_log_print_event_from_module(SYS_LOG_ERROR, TASK_READ_EDC_NAME, "Error reading the state data!"); + sys_log_new_line(); + } } vTaskDelayUntil(&last_cycle, pdMS_TO_TICKS(TASK_READ_EDC_PERIOD_MS)); } } +static void print_edc_hk(uint8_t *hk) +{ + uint16_t curr_dig = (hk[10] << 8U) | hk[9]; + uint16_t curr_rf = (hk[12] << 8U) | hk[11]; + uint16_t volt = (hk[14] << 8U) | hk[13]; + int16_t temp = (int16_t)hk[15] - 40; + + sys_log_print_event_from_module(SYS_LOG_INFO, "EDC Status", "Current(Dig): "); + sys_log_print_uint((uint32_t) curr_dig); + sys_log_print_msg(" mA"); + sys_log_new_line(); + + sys_log_print_event_from_module(SYS_LOG_INFO, "EDC Status", "Current(RF): "); + sys_log_print_uint((uint32_t) curr_rf); + sys_log_print_msg(" mA"); + sys_log_new_line(); + + sys_log_print_event_from_module(SYS_LOG_INFO, "EDC Status", "Sys Voltage: "); + sys_log_print_uint((uint32_t) volt); + sys_log_print_msg(" mV"); + sys_log_new_line(); + + sys_log_print_event_from_module(SYS_LOG_INFO, "EDC Status", "Board Temp: "); + sys_log_print_int((int32_t) temp); + sys_log_print_msg(" oC"); + sys_log_new_line(); +} + /** \} End of read_edc group */ diff --git a/firmware/app/tasks/read_edc.h b/firmware/app/tasks/read_edc.h index 6df713fd..bc199f13 100644 --- a/firmware/app/tasks/read_edc.h +++ b/firmware/app/tasks/read_edc.h @@ -26,7 +26,7 @@ * \author Gabriel Mariano Marcelino * \author Carlos Augusto Porto Freitas * - * \version 0.10.18 + * \version 0.10.19 * * \date 2020/08/16 * @@ -46,6 +46,7 @@ #define TASK_READ_EDC_PRIORITY 3 /**< Task priority. */ #define TASK_READ_EDC_PERIOD_MS (60000) /**< Task period in milliseconds. */ #define TASK_READ_EDC_INIT_TIMEOUT_MS 2000 /**< Wait time to initialize the task in milliseconds. */ +#define TASK_READ_EDC_MAX_WAIT_TIME_MS (60000UL * 60UL) /**< Max time to wait for notifications. (1 hour)*/ /** * \brief EDC housekeeping raw data type. diff --git a/firmware/app/tasks/read_px.c b/firmware/app/tasks/read_px.c index 71ecd0c9..729d1d9e 100644 --- a/firmware/app/tasks/read_px.c +++ b/firmware/app/tasks/read_px.c @@ -26,7 +26,7 @@ * \author Augusto Cezar Boldori Vassoler * \author Carlos Augusto Porto Freitas * - * \version 0.10.18 + * \version 0.10.19 * * \date 2023/08/28 * @@ -35,21 +35,26 @@ */ #include +#include +#include #include +#include #include #include +#include #include "read_px.h" +#include "op_ctrl.h" #include "startup.h" xTaskHandle xTaskReadPXHandle; -pl_px_buf_t px_buf = {0}; - void vTaskReadPX(void) { - static payload_t pl_px_active = PAYLOAD_X; + payload_telemetry_t *const px = &sat_data_buf.payload_x; + + pl_px_buf_t px_buf = {0}; px_buf.length = PX_PONG_BUF_SIZE; /* Wait startup task to finish */ @@ -57,34 +62,65 @@ void vTaskReadPX(void) while(1) { - TickType_t last_cycle = xTaskGetTickCount(); + uint32_t cancel_flag; + uint32_t active_period_ms; - /* Read data */ - if (payload_get_data(pl_px_active, PAYLOAD_X_PONG, px_buf.buffer, &px_buf.length) != 0) - { - sys_log_print_event_from_module(SYS_LOG_ERROR, TASK_READ_PX_NAME, "Error reading the ping-pong data!"); + BaseType_t result = xTaskNotifyWait(0UL, UINT32_MAX, &active_period_ms, pdMS_TO_TICKS(TASK_READ_PX_MAX_WAIT_TIME_MS)); - int32_t i = 0; - for(i = 0; i < px_buf.length; i++){ - sys_log_print_uint(px_buf.buffer[i]); - } + payload_t pl_px_active = sat_data_buf.state.active_payload; - sys_log_new_line(); - } - else + if ((pl_px_active == PAYLOAD_X) && (result == pdTRUE)) { - sys_log_print_event_from_module(SYS_LOG_INFO, TASK_READ_PX_NAME, "Received Payload X packet:"); - sys_log_new_line(); - - /* - uint8_t i = 0; - for(i=0;i 0U) + { + /* Check notifications to break out of the loop if requested */ + if (xTaskNotifyWait(0UL, PAYLOAD_X_CANCEL_EXPERIMENT_FLAG, &cancel_flag, 0U) == pdTRUE) + { + if ((cancel_flag & PAYLOAD_X_CANCEL_EXPERIMENT_FLAG) != 0U) + { + active_period_ms = 0U; + break; + } + } + + /* Read data */ + if (payload_get_data(pl_px_active, PAYLOAD_X_PONG, px_buf.buffer, &px_buf.length) != 0) + { + sys_log_print_event_from_module(SYS_LOG_ERROR, TASK_READ_PX_NAME, "Error reading the ping-pong data!"); + + int32_t i = 0; + for(i = 0; i < px_buf.length; i++){ + sys_log_print_uint(px_buf.buffer[i]); + } + + sys_log_new_line(); + } + else + { + sys_log_print_event_from_module(SYS_LOG_INFO, TASK_READ_PX_NAME, "Received Payload X packet:"); + sys_log_new_line(); + + (void)memcpy(px->data, px_buf.buffer, PX_PONG_BUF_SIZE); + + px->timestamp = system_get_time(); + + /* + uint8_t i = 0; + for(i=0;i * \author Carlos Augusto Porto Freitas * - * \version 0.10.18 + * \version 0.10.19 * * \date 2023/08/28 * @@ -43,10 +43,11 @@ #define TASK_READ_PX_NAME "PX Task" /**< Task name. */ #define TASK_READ_PX_STACK_SIZE 300 /**< Stack size in bytes. */ #define TASK_READ_PX_PRIORITY 3 /**< Task priority. */ -#define TASK_READ_PX_PERIOD_MS (60000) /**< Task period in milliseconds. */ +#define TASK_READ_PX_PERIOD_MS (60000UL) /**< Task period in milliseconds. */ #define TASK_READ_PX_INIT_TIMEOUT_MS 2000 /**< Wait time to initialize the task in milliseconds. */ +#define TASK_READ_PX_MAX_WAIT_TIME_MS (60000UL * 60UL) /**< Max time to wait for notifications. (1 hour)*/ -#define PX_PONG_BUF_SIZE 4; /**< Size of pong response message. */ +#define PX_PONG_BUF_SIZE 4 /**< Size of pong response message. */ /** * \brief PX data type. */ diff --git a/firmware/app/tasks/startup.c b/firmware/app/tasks/startup.c index dd79cac6..1eada7b4 100644 --- a/firmware/app/tasks/startup.c +++ b/firmware/app/tasks/startup.c @@ -26,7 +26,7 @@ * \author Gabriel Mariano Marcelino * \author Carlos Augusto Porto Freitas * - * \version 0.10.18 + * \version 0.10.19 * * \date 2019/12/04 * @@ -222,6 +222,10 @@ void vTaskStartup(void) #if defined(CONFIG_DEV_PAYLOAD_EDC_ENABLED) && (CONFIG_DEV_PAYLOAD_EDC_ENABLED == 1) /* Payload EDC device initialization */ + sat_data_buf.edc_0.id = PAYLOAD_EDC_0_ID; + sat_data_buf.edc_1.id = PAYLOAD_EDC_1_ID; + sat_data_buf.state.main_edc = PAYLOAD_EDC_0; + if (payload_init(PAYLOAD_EDC_1) != 0) { error_counter++; @@ -248,6 +252,7 @@ void vTaskStartup(void) #if defined(CONFIG_DEV_PAYLOAD_X_ENABLED) && (CONFIG_DEV_PAYLOAD_X_ENABLED == 1) /* Payload X device initialization */ + sat_data_buf.payload_x.id = PAYLOAD_X_ID; if (payload_init(PAYLOAD_X) != 0) { error_counter++; diff --git a/firmware/app/tasks/tasks.c b/firmware/app/tasks/tasks.c index 97da4fc1..de48c885 100644 --- a/firmware/app/tasks/tasks.c +++ b/firmware/app/tasks/tasks.c @@ -26,7 +26,7 @@ * \author Gabriel Mariano Marcelino * \author Carlos Augusto Porto Freitas * - * \version 0.10.18 + * \version 0.10.19 * * \date 2019/11/02 * @@ -57,6 +57,8 @@ #include "read_px.h" #include "housekeeping.h" #include "mem_check.h" +#include "op_ctrl.h" +#include "mode_check.h" void create_tasks(void) { @@ -221,10 +223,27 @@ void create_tasks(void) if (xTaskHealthCheckMemHandle == NULL) { - /* Error creating the Housekeeping task */ + /* Error creating the Health Check Memory task */ } -#endif /* CONFIG_TASK_HOUSEKEEPING_ENABLED */ +#endif /* CONFIG_TASK_HEALTH_CHECK_MEM_ENABLED */ + +#if defined(CONFIG_TASK_OP_CTRL_ENABLED) && (CONFIG_TASK_OP_CTRL_ENABLED == 1) + xTaskCreate(vTaskOpCtrl, TASK_OP_CTRL_NAME, TASK_OP_CTRL_STACK_SIZE, NULL, TASK_OP_CTRL_PRIORITY, &xTaskOpCtrlHandle); + if (xTaskOpCtrlHandle == NULL) + { + /* Error creating the Operation Control task */ + } +#endif /* CONFIG_TASK_OP_CTRL_ENABLED */ + +#if defined(CONFIG_TASK_HEALTH_CHECK_MODE_ENABLED) && (CONFIG_TASK_HEALTH_CHECK_MODE_ENABLED == 1) + xTaskCreate(vTaskHealthCheckMode, TASK_HEALTH_CHECK_MODE_NAME, TASK_HEALTH_CHECK_MODE_STACK_SIZE, NULL, TASK_HEALTH_CHECK_MODE_PRIORITY, &xTaskHealthCheckModeHandle); + + if (xTaskHealthCheckModeHandle == NULL) + { + /* Error creating the Health Check Operation Mode task */ + } +#endif /* CONFIG_TASK_HEALTH_CHECK_MODE_ENABLED */ create_event_groups(); } diff --git a/firmware/app/utils/mem_mng.c b/firmware/app/utils/mem_mng.c index 51b4b712..0af3c4f3 100644 --- a/firmware/app/utils/mem_mng.c +++ b/firmware/app/utils/mem_mng.c @@ -26,7 +26,7 @@ * \author Gabriel Mariano Marcelino * \author Carlos Augusto Porto Freitas * - * \version 0.10.18 + * \version 0.10.19 * * \date 2024/02/24 * @@ -42,6 +42,7 @@ #include #include #include +#include #include "mem_mng.h" @@ -176,6 +177,8 @@ int mem_mng_write_data_to_flash_page(uint8_t *data, uint32_t *page, uint32_t pag if (media_write(MEDIA_NOR, (*page) * page_size, data, page_size) == 0) { + portENTER_CRITICAL(); + (*page)++; // cppcheck-suppress misra-c2012-17.8 if (*page > end_page) @@ -183,6 +186,8 @@ int mem_mng_write_data_to_flash_page(uint8_t *data, uint32_t *page, uint32_t pag *page = start_page; } + portEXIT_CRITICAL(); + err = 0; } @@ -230,6 +235,45 @@ int mem_mng_load_obdh_data_bak(obdh_telemetry_t *tel) return err; } +void mem_mng_reset_page_count(media_data_t *media) +{ + portENTER_CRITICAL(); + media->last_page_obdh_data = CONFIG_MEM_OBDH_DATA_START_PAGE; + media->last_page_eps_data = CONFIG_MEM_EPS_DATA_START_PAGE; + media->last_page_ttc_0_data = CONFIG_MEM_TTC_0_DATA_START_PAGE; + media->last_page_ant_data = CONFIG_MEM_ANT_DATA_START_PAGE; + media->last_page_edc_data = CONFIG_MEM_EDC_DATA_START_PAGE; + media->last_page_px_data = CONFIG_MEM_PX_DATA_START_PAGE; + media->last_page_sbcd_pkts = CONFIG_MEM_SBCD_PKTS_START_PAGE; + portEXIT_CRITICAL(); +} + +int mem_mng_erase_flash(obdh_telemetry_t *tel) +{ + int err = 0; + + if (media_erase(MEDIA_NOR, MEDIA_ERASE_DIE, 0U) != 0) + { + sys_log_print_event_from_module(SYS_LOG_ERROR, MEM_MNG_NAME, "Failed to erase flash die 0"); + sys_log_new_line(); + err--; + } + + if (media_erase(MEDIA_NOR, MEDIA_ERASE_DIE, 1U) != 0) + { + sys_log_print_event_from_module(SYS_LOG_ERROR, MEM_MNG_NAME, "Failed to erase flash die 1"); + sys_log_new_line(); + err--; + } + + if (err == 0) + { + mem_mng_reset_page_count(&tel->data.media); + } + + return err; +} + static uint8_t crc8(uint8_t *data, uint8_t len) { uint8_t crc = CRC8_INITIAL_VAL; diff --git a/firmware/app/utils/mem_mng.h b/firmware/app/utils/mem_mng.h index 292a3169..945ec6eb 100644 --- a/firmware/app/utils/mem_mng.h +++ b/firmware/app/utils/mem_mng.h @@ -25,8 +25,8 @@ * * \author Gabriel Mariano Marcelino * \author Carlos Augusto Porto Freitas - * - * \version 0.10.18 + * + * \version 0.10.19 * * \date 2024/02/24 * @@ -129,6 +129,25 @@ int mem_mng_load_obdh_data_bak(obdh_telemetry_t *tel); */ int mem_mng_write_data_to_flash_page(uint8_t *data, uint32_t *page, uint32_t page_size, uint32_t start_page, uint32_t end_page); +/** + * \brief Resets NOR memory page count state. + * + * \param[in] media is the media struct where the page count is stored. + * + * \return None. + */ +void mem_mng_reset_page_count(media_data_t *media); + +/** + * \brief Completely erases NOR memory and, if the erase operation succeeded, + * resets the page count state. + * + * \param[in] tel is the OBDH telemetry data where page count state is stored. + * + * \return The status/error code. + */ +int mem_mng_erase_flash(obdh_telemetry_t *tel); + #endif /* MEM_MNG_H_ */ /** \} End of mem_mng group */ diff --git a/firmware/config/config.h b/firmware/config/config.h index a2b190ad..aeaac35d 100644 --- a/firmware/config/config.h +++ b/firmware/config/config.h @@ -26,7 +26,7 @@ * \author Gabriel Mariano Marcelino * \author Carlos Augusto Porto Freitas * - * \version 0.10.18 + * \version 0.10.19 * * \date 2019/10/26 * @@ -55,7 +55,9 @@ #define CONFIG_TASK_POSITION_DETERMINATION_ENABLED 1 #define CONFIG_TASK_PAYLOAD_X_ENABLED 1 #define CONFIG_TASK_HOUSEKEEPING_ENABLED 1 +#define CONFIG_TASK_OP_CTRL_ENABLED 1 #define CONFIG_TASK_HEALTH_CHECK_MEM_ENABLED 0 +#define CONFIG_TASK_HEALTH_CHECK_MODE_ENABLED 0 /* Devices */ #define CONFIG_DEV_MEDIA_INT_ENABLED 1 @@ -76,6 +78,7 @@ /* Health Check */ #define CONFIG_HEALTH_CHECK_ENABLED 0 +#define CONFIG_HEALTH_CHECK_PAGES_TO_VALIDATE 10 /* Debug and log messages */ #define CONFIG_DRIVERS_DEBUG_ENABLED 0 @@ -173,7 +176,7 @@ #define CONFIG_TASK_READ_SENSORS_ENABLED 0 #define CONFIG_TASK_BEACON_ENABLED 0 #define CONFIG_TASK_TIME_CONTROL_ENABLED 0 -#define CONFIG_TASK_READ_EDC_ENABLED 0 +#define CONFIG_TASK_READ_EDC_ENABLED 1 #define CONFIG_TASK_READ_EPS_ENABLED 0 #define CONFIG_TASK_READ_TTC_ENABLED 0 #define CONFIG_TASK_READ_ANTENNA_ENABLED 0 @@ -181,9 +184,11 @@ #define CONFIG_TASK_PROCESS_TC_ENABLED 0 #define CONFIG_TASK_ANTENNA_DEPLOYMENT_ENABLED 0 #define CONFIG_TASK_POSITION_DETERMINATION_ENABLED 0 -#define CONFIG_TASK_PAYLOAD_X_ENABLED 0 +#define CONFIG_TASK_PAYLOAD_X_ENABLED 1 #define CONFIG_TASK_HOUSEKEEPING_ENABLED 0 +#define CONFIG_TASK_OP_CTRL_ENABLED 1 #define CONFIG_TASK_HEALTH_CHECK_MEM_ENABLED 1 +#define CONFIG_TASK_HEALTH_CHECK_MODE_ENABLED 1 /* Devices */ #define CONFIG_DEV_MEDIA_INT_ENABLED 1 @@ -194,9 +199,9 @@ #define CONFIG_DEV_VOLTAGE_SENSOR_ENABLED 0 #define CONFIG_DEV_TEMP_SENSOR_ENABLED 0 #define CONFIG_DEV_EPS_ENABLED 0 -#define CONFIG_DEV_PAYLOAD_EDC_ENABLED 0 +#define CONFIG_DEV_PAYLOAD_EDC_ENABLED 1 #define CONFIG_DEV_ANTENNA_ENABLED 0 -#define CONFIG_DEV_PAYLOAD_X_ENABLED 0 +#define CONFIG_DEV_PAYLOAD_X_ENABLED 1 /* Drivers */ #define CONFIG_DRV_ISIS_ANTENNA_ENABLED 0 @@ -209,6 +214,11 @@ #error To enable memory Health Check please set the CONFIG_HEALTH_CHECK_ENABLED flag on config.h #endif +#if defined (CONFIG_TASK_HEALTH_CHECK_MODE_ENABLED) && defined (CONFIG_HEALTH_CHECK_ENABLED) && \ + (CONFIG_TASK_HEALTH_CHECK_MODE_ENABLED == 1) && (CONFIG_HEALTH_CHECK_ENABLED == 0) +#error To enable mode Health Check please set the CONFIG_HEALTH_CHECK_ENABLED flag on config.h +#endif + #endif /* CONFIG_H_ */ /** \} End of config group */ diff --git a/firmware/devices/payload/payload.c b/firmware/devices/payload/payload.c index 38cdf1c3..c3ae25b7 100644 --- a/firmware/devices/payload/payload.c +++ b/firmware/devices/payload/payload.c @@ -27,7 +27,7 @@ * \author João Cláudio Elsen Barcellos * \author Carlos Augusto Porto Freitas * - * \version 0.10.18 + * \version 0.10.19 * * \date 2021/08/15 * @@ -47,10 +47,10 @@ #define PAYLOAD_UNIX_TO_J2000_EPOCH(x) ((x) - 946684800) /* Unix to J2000 epoch conversion */ -static edc_config_t edc_0_conf = {0}; -static edc_config_t edc_1_conf = {0}; +static edc_config_t edc_0_conf; +static edc_config_t edc_1_conf; -static px_config_t px_conf = {0}; +static px_config_t px_conf; int payload_init(payload_t pl) { @@ -160,8 +160,9 @@ int payload_init(payload_t pl) { px_conf.port = I2C_PORT_0; px_conf.bitrate = 400000UL; + px_conf.en_pin = GPIO_PIN_37; - if (px_init(px_conf) == 0) + if (px_init(&px_conf) == 0) { err = 0; @@ -217,8 +218,15 @@ int payload_enable(payload_t pl) break; case PAYLOAD_X: - sys_log_print_event_from_module(SYS_LOG_ERROR, PAYLOAD_MODULE_NAME, "Payload-X: enable() routine not implemented yet!"); - sys_log_new_line(); + if (px_enable(&px_conf) == 0) + { + err = 0; + } + else + { + sys_log_print_event_from_module(SYS_LOG_ERROR, PAYLOAD_MODULE_NAME, "Payload X: Error enabling!"); + sys_log_new_line(); + } break; default: @@ -262,8 +270,15 @@ int payload_disable(payload_t pl) break; case PAYLOAD_X: - sys_log_print_event_from_module(SYS_LOG_ERROR, PAYLOAD_MODULE_NAME, "Payload-X: disable() routine not implemented yet!"); - sys_log_new_line(); + if (px_disable(&px_conf) == 0) + { + err = 0; + } + else + { + sys_log_print_event_from_module(SYS_LOG_ERROR, PAYLOAD_MODULE_NAME, "Payload X: Error enabling!"); + sys_log_new_line(); + } break; default: @@ -303,7 +318,7 @@ int payload_write_cmd(payload_t pl, payload_cmd_t cmd) break; case PAYLOAD_X: - if (px_write(px_conf, &cmd, 1U) == 0) + if (px_write(&px_conf, &cmd, 1U) == 0) { sys_log_print_event_from_module(SYS_LOG_INFO, PAYLOAD_MODULE_NAME, "Payload-X: "); sys_log_print_hex(cmd); @@ -439,17 +454,17 @@ int payload_get_data(payload_t pl, payload_data_id_t id, uint8_t *data, int32_t } case PAYLOAD_EDC_RAW_HK: { - int bytes = edc_get_hk_pkg(edc_0_conf, data); + *len = edc_get_hk_pkg(edc_0_conf, data); - if (bytes < 0) + if (*len < 0) { sys_log_print_event_from_module(SYS_LOG_ERROR, PAYLOAD_MODULE_NAME, "EDC 0: Error reading housekeeping data!"); sys_log_new_line(); } - - *len = bytes; - - err = 0; + else + { + err = 0; + } break; } @@ -644,7 +659,7 @@ int payload_get_data(payload_t pl, payload_data_id_t id, uint8_t *data, int32_t break; } case PAYLOAD_X: - if (px_read(px_conf, data, *len) == 0) + if (px_read(&px_conf, data, *len) == 0) { sys_log_print_event_from_module(SYS_LOG_INFO, PAYLOAD_MODULE_NAME, "Payload-X: "); /* diff --git a/firmware/devices/payload/payload.h b/firmware/devices/payload/payload.h index e8effa75..38923032 100644 --- a/firmware/devices/payload/payload.h +++ b/firmware/devices/payload/payload.h @@ -26,7 +26,7 @@ * \author Gabriel Mariano Marcelino * \author Carlos Augusto Porto Freitas * - * \version 0.10.18 + * \version 0.10.19 * * \date 2021/08/15 * @@ -42,6 +42,10 @@ #define PAYLOAD_MODULE_NAME "Payload" +#define PAYLOAD_EDC_0_ID (0x01U) +#define PAYLOAD_EDC_1_ID (0x02U) +#define PAYLOAD_X_ID (0x03U) + /** * \brief Payload type. */ @@ -49,7 +53,8 @@ typedef enum { PAYLOAD_EDC_0=0, /**< Payload EDC 0. */ PAYLOAD_EDC_1, /**< Payload EDC 1. */ - PAYLOAD_X /**< Payload-X. */ + PAYLOAD_X, /**< Payload-X. */ + PAYLOAD_NONE, /**< Means there's no payload active */ } payload_t; /** diff --git a/firmware/drivers/px/px.c b/firmware/drivers/px/px.c index 761929f5..4b4158a1 100644 --- a/firmware/drivers/px/px.c +++ b/firmware/drivers/px/px.c @@ -24,8 +24,9 @@ * \brief Payload X driver implementation. * * \author Gabriel Mariano Marcelino + * \author Carlos Augusto Porto Freitas * - * \version 0.10.8 + * \version 0.10.19 * * \date 2020/03/31 * @@ -33,25 +34,38 @@ * \{ */ +#include + #include "px.h" -int px_init(px_config_t conf) +int px_init(const px_config_t *conf) { - i2c_config_t i2c_conf = {0}; + const gpio_config_t gpio_conf = { .mode = GPIO_MODE_OUTPUT }; + const i2c_config_t i2c_conf = { .speed_hz = conf->bitrate }; + + (void)gpio_init(conf->en_pin, gpio_conf); - i2c_conf.speed_hz = conf.bitrate; + return i2c_init(conf->port, i2c_conf); +} - return i2c_init(conf.port, i2c_conf); +int px_write(const px_config_t *conf, uint8_t *data, uint16_t len) +{ + return i2c_write(conf->port, PX_SLAVE_ADDRESS, data, len); +} + +int px_read(const px_config_t *conf, uint8_t *data, uint16_t len) +{ + return i2c_read(conf->port, PX_SLAVE_ADDRESS, data, len); } -int px_write(px_config_t conf, uint8_t *data, uint16_t len) +int px_enable(const px_config_t *conf) { - return i2c_write(conf.port, PX_SLAVE_ADDRESS, data, len); + return gpio_set_state(conf->en_pin, true); } -int px_read(px_config_t conf, uint8_t *data, uint16_t len) +int px_disable(const px_config_t *conf) { - return i2c_read(conf.port, PX_SLAVE_ADDRESS, data, len); + return gpio_set_state(conf->en_pin, false); } /** \} End of px group */ diff --git a/firmware/drivers/px/px.h b/firmware/drivers/px/px.h index aa6a3975..0a1c4dc5 100644 --- a/firmware/drivers/px/px.h +++ b/firmware/drivers/px/px.h @@ -24,8 +24,9 @@ * \brief Payload X driver definition. * * \author Gabriel Mariano Marcelino + * \author Carlos Augusto Porto Freitas * - * \version 0.10.8 + * \version 0.10.19 * * \date 2020/10/31 * @@ -40,6 +41,7 @@ #include #include +#include #define PX_SLAVE_ADDRESS 0x42 /**< 7-bit slave address. */ @@ -49,22 +51,23 @@ typedef struct { i2c_port_t port; + gpio_pin_t en_pin; uint32_t bitrate; } px_config_t; /** * \brief Device initialization. * - * \param[in] conf is the configuration parameter of a Payload-X device. + * \param[in] conf is a pointer to the configuration parameter of a Payload-X device. * * \return The status/error code. */ -int px_init(px_config_t conf); +int px_init(const px_config_t *conf); /** * \brief Writes data to the Payload X. * - * \param[in] conf is the configuration parameter of a Payload-X device. + * \param[in] conf is a pointer to the configuration parameter of a Payload-X device. * * \param[in] data is an array of bytes to write. * @@ -72,12 +75,12 @@ int px_init(px_config_t conf); * * \return The status/error code. */ -int px_write(px_config_t conf, uint8_t *data, uint16_t len); +int px_write(const px_config_t *conf, uint8_t *data, uint16_t len); /** * \brief Reads data from the Payload X. * - * \param[in] conf is the configuration parameter of a Payload-X device. + * \param[in] conf is a pointer to the configuration parameter of a Payload-X device. * * \param[in,out] data is a pointer to store the read data. * @@ -85,7 +88,25 @@ int px_write(px_config_t conf, uint8_t *data, uint16_t len); * * \return The status/error code. */ -int px_read(px_config_t conf, uint8_t *data, uint16_t len); +int px_read(const px_config_t *conf, uint8_t *data, uint16_t len); + +/** + * \brief Enables the Payload X. + * + * \param[in] conf is a pointer to the configuration parameter of a Payload-X device. + * + * \return The status/error code. + */ +int px_enable(const px_config_t *conf); + +/** + * \brief Disables the Payload X. + * + * \param[in] conf is a pointer to the configuration parameter of a Payload-X device. + * + * \return The status/error code. + */ +int px_disable(const px_config_t *conf); #endif /* PX_H_ */ diff --git a/firmware/drivers/sl_ttc2/sl_ttc2.c b/firmware/drivers/sl_ttc2/sl_ttc2.c index 29c46949..eabdd671 100644 --- a/firmware/drivers/sl_ttc2/sl_ttc2.c +++ b/firmware/drivers/sl_ttc2/sl_ttc2.c @@ -26,7 +26,7 @@ * \author Gabriel Mariano Marcelino * \author Carlos Augusto Porto Freitas * - * \version 0.10.17 + * \version 0.10.19 * * \date 2021/05/12 * @@ -836,7 +836,7 @@ int sl_ttc2_read_packet(sl_ttc2_config_t config, uint8_t *data, uint16_t *len) if (sl_ttc2_read_len_rx_pkt_in_fifo(config, len) == 0) { - if ((*len > 0) && (*len <= 220)) + if ((*len > 0) && (*len <= 300)) { if (sl_ttc2_mutex_take() == 0) { diff --git a/firmware/system/system.c b/firmware/system/system.c index 0868ac0c..a291fefa 100644 --- a/firmware/system/system.c +++ b/firmware/system/system.c @@ -24,8 +24,9 @@ * \brief System management routines implementation. * * \author Gabriel Mariano Marcelino + * \author Carlos Augusto Porto Freitas * - * \version 0.8.7 + * \version 0.10.19 * * \date 2020/01/29 * @@ -35,6 +36,7 @@ #include #include +#include #include "system.h" @@ -59,7 +61,10 @@ void system_set_time(sys_time_t tm) void system_increment_time(void) { + /* This ensures the sys_time increment is done atomically */ + portENTER_CRITICAL(); sys_time++; + portEXIT_CRITICAL(); } sys_time_t system_get_time(void) diff --git a/firmware/tests/devices/Makefile b/firmware/tests/devices/Makefile index 40a34e18..dba40b96 100644 --- a/firmware/tests/devices/Makefile +++ b/firmware/tests/devices/Makefile @@ -35,7 +35,7 @@ ANTENNA_TEST_FLAGS=$(FLAGS),--wrap=isis_antenna_init,--wrap=isis_antenna_arm,--w MEDIA_TEST_FLAGS=$(FLAGS),--wrap=flash_init,--wrap=flash_write,--wrap=flash_write_single,--wrap=flash_read_single,--wrap=flash_write_long,--wrap=flash_read_long,--wrap=flash_erase,--wrap=mt25q_init,--wrap=mt25q_reset,--wrap=mt25q_read_device_id,--wrap=mt25q_read_flash_description,--wrap=mt25q_clear_flag_status_register,--wrap=mt25q_read_status,--wrap=mt25q_enter_deep_power_down,--wrap=mt25q_release_from_deep_power_down,--wrap=mt25q_write_enable,--wrap=mt25q_write_disable,--wrap=mt25q_is_busy,--wrap=mt25q_die_erase,--wrap=mt25q_sector_erase,--wrap=mt25q_sub_sector_erase,--wrap=mt25q_write,--wrap=mt25q_read,--wrap=mt25q_get_max_address,--wrap=mt25q_enter_4_byte_address_mode,--wrap=mt25q_read_flag_status_register,--wrap=mt25q_get_flash_description,--wrap=mt25q_spi_init,--wrap=mt25q_spi_write,--wrap=mt25q_spi_read,--wrap=mt25q_spi_transfer,--wrap=mt25q_spi_select,--wrap=mt25q_spi_unselect,--wrap=mt25q_spi_write_only,--wrap=mt25q_spi_read_only,--wrap=mt25q_spi_transfer_only,--wrap=mt25q_gpio_init,--wrap=mt25q_gpio_set_hold,--wrap=mt25q_gpio_set_reset,--wrap=mt25q_delay_ms,--wrap=cy15x102qn_init,--wrap=cy15x102qn_set_write_enable,--wrap=cy15x102qn_reset_write_enable,--wrap=cy15x102qn_read_status_reg,--wrap=cy15x102qn_write_status_reg,--wrap=cy15x102qn_write,--wrap=cy15x102qn_read,--wrap=cy15x102qn_fast_read,--wrap=cy15x102qn_special_sector_write,--wrap=cy15x102qn_special_sector_read,--wrap=cy15x102qn_read_device_id,--wrap=cy15x102qn_read_unique_id,--wrap=cy15x102qn_write_serial_number,--wrap=cy15x102qn_read_serial_number,--wrap=cy15x102qn_deep_power_down_mode,--wrap=cy15x102qn_hibernate_mode,--wrap=cy15x102qn_spi_init,--wrap=cy15x102qn_spi_write,--wrap=cy15x102qn_spi_read,--wrap=cy15x102qn_spi_transfer,--wrap=cy15x102qn_spi_select,--wrap=cy15x102qn_spi_unselect,--wrap=cy15x102qn_spi_write_only,--wrap=cy15x102qn_spi_read_only,--wrap=cy15x102qn_spi_transfer_only,--wrap=cy15x102qn_gpio_init,--wrap=cy15x102qn_gpio_set_write_protect,--wrap=cy15x102qn_gpio_clear_write_protect -PAYLOAD_TEST_FLAGS=$(FLAGS),--wrap=edc_init,--wrap=edc_enable,--wrap=edc_disable,--wrap=edc_write_cmd,--wrap=edc_read,--wrap=edc_check_device,--wrap=edc_set_rtc_time,--wrap=edc_pop_ptt_pkg,--wrap=edc_pause_ptt_task,--wrap=edc_resume_ptt_task,--wrap=edc_start_adc_task,--wrap=edc_get_state_pkg,--wrap=edc_get_ptt_pkg,--wrap=edc_get_hk_pkg,--wrap=edc_get_adc_seq,--wrap=edc_echo,--wrap=edc_calc_checksum,--wrap=edc_get_state,--wrap=edc_get_ptt,--wrap=edc_get_hk,--wrap=edc_delay_ms,--wrap=phj_init_i2c,--wrap=phj_init_gpio,--wrap=phj_read,--wrap=phj_check_converter,--wrap=phj_check_message,--wrap=px_init,--wrap=px_write,--wrap=px_read +PAYLOAD_TEST_FLAGS=$(FLAGS),--wrap=edc_init,--wrap=edc_enable,--wrap=edc_disable,--wrap=edc_write_cmd,--wrap=edc_read,--wrap=edc_check_device,--wrap=edc_set_rtc_time,--wrap=edc_pop_ptt_pkg,--wrap=edc_pause_ptt_task,--wrap=edc_resume_ptt_task,--wrap=edc_start_adc_task,--wrap=edc_get_state_pkg,--wrap=edc_get_ptt_pkg,--wrap=edc_get_hk_pkg,--wrap=edc_get_adc_seq,--wrap=edc_echo,--wrap=edc_calc_checksum,--wrap=edc_get_state,--wrap=edc_get_ptt,--wrap=edc_get_hk,--wrap=edc_delay_ms,--wrap=phj_init_i2c,--wrap=phj_init_gpio,--wrap=phj_read,--wrap=phj_check_converter,--wrap=phj_check_message,--wrap=px_init,--wrap=px_write,--wrap=px_read,--wrap=px_enable,--wrap=px_disable .PHONY: all all: current_sensor_test voltage_sensor_test temp_sensor_test leds_test watchdog_test ttc_test eps_test antenna_test media_test payload_test diff --git a/firmware/tests/devices/payload_test.c b/firmware/tests/devices/payload_test.c index ea135ca1..6fdfd385 100644 --- a/firmware/tests/devices/payload_test.c +++ b/firmware/tests/devices/payload_test.c @@ -25,8 +25,9 @@ * * \author Gabriel Mariano Marcelino * \author Bruno Benedetti + * \author Carlos Augusto Porto Freitas * - * \version 0.10.11 + * \version 0.10.19 * * \date 2021/08/16 * @@ -147,8 +148,9 @@ static void payload_init_test(void **state) assert_return_code(payload_init(PAYLOAD_EDC_1), 0); /* Payload-X */ - expect_value(__wrap_px_init, conf.port, PX_I2C_PORT); - expect_value(__wrap_px_init, conf.bitrate, PX_I2C_BITRATE); + expect_value(__wrap_px_init, conf->port, PX_I2C_PORT); + expect_value(__wrap_px_init, conf->bitrate, PX_I2C_BITRATE); + expect_value(__wrap_px_init, conf->en_pin, GPIO_PIN_37); will_return(__wrap_px_init, 0); @@ -175,7 +177,11 @@ static void payload_enable_test(void **state) assert_return_code(payload_enable(PAYLOAD_EDC_1), 0); -// assert_return_code(payload_enable(PAYLOAD_X), 0); + expect_value(__wrap_px_enable, conf->en_pin, GPIO_PIN_37); + + will_return(__wrap_px_enable, 0); + + assert_return_code(payload_enable(PAYLOAD_X), 0); // assert_return_code(payload_enable(PAYLOAD_PHJ), 0); } @@ -198,7 +204,12 @@ static void payload_disable_test(void **state) will_return(__wrap_edc_disable, 0); assert_return_code(payload_disable(PAYLOAD_EDC_1), 0); -// assert_return_code(payload_disable(PAYLOAD_X), 0); + + expect_value(__wrap_px_disable, conf->en_pin, GPIO_PIN_37); + + will_return(__wrap_px_disable, 0); + + assert_return_code(payload_disable(PAYLOAD_X), 0); // assert_return_code(payload_disable(PAYLOAD_PHJ), 0); } diff --git a/firmware/tests/mockups/drivers/px_wrap.c b/firmware/tests/mockups/drivers/px_wrap.c index b41235bc..50c95456 100644 --- a/firmware/tests/mockups/drivers/px_wrap.c +++ b/firmware/tests/mockups/drivers/px_wrap.c @@ -24,8 +24,9 @@ * \brief Payload-X driver wrap implementation. * * \author Gabriel Mariano Marcelino + * \author Carlos Augusto Porto Freitas * - * \version 0.10.8 + * \version 0.10.19 * * \date 2023/09/18 * @@ -43,18 +44,19 @@ #include "px_wrap.h" -int __wrap_px_init(px_config_t conf) +int __wrap_px_init(px_config_t *conf) { - check_expected(conf.port); - check_expected(conf.bitrate); + check_expected(conf->port); + check_expected(conf->bitrate); + check_expected(conf->en_pin); return mock_type(int); } -int __wrap_px_write(px_config_t conf, uint8_t *data, uint16_t len) +int __wrap_px_write(px_config_t *conf, uint8_t *data, uint16_t len) { - check_expected(conf.port); - check_expected(conf.bitrate); + check_expected(conf->port); + check_expected(conf->bitrate); check_expected_ptr(data); check_expected(len); @@ -62,10 +64,10 @@ int __wrap_px_write(px_config_t conf, uint8_t *data, uint16_t len) return mock_type(int); } -int __wrap_px_read(px_config_t conf, uint8_t *data, uint16_t len) +int __wrap_px_read(px_config_t *conf, uint8_t *data, uint16_t len) { - check_expected(conf.port); - check_expected(conf.bitrate); + check_expected(conf->port); + check_expected(conf->bitrate); uint16_t i = 0U; for(i = 0U; i < len; i++) @@ -78,4 +80,18 @@ int __wrap_px_read(px_config_t conf, uint8_t *data, uint16_t len) return mock_type(int); } +int __wrap_px_enable(px_config_t *conf) +{ + check_expected(conf->en_pin); + + return mock_type(int); +} + +int __wrap_px_disable(px_config_t *conf) +{ + check_expected(conf->en_pin); + + return mock_type(int); +} + /** \} End of phj_wrap group */ diff --git a/firmware/tests/mockups/drivers/px_wrap.h b/firmware/tests/mockups/drivers/px_wrap.h index fe7dbcf2..504f1611 100644 --- a/firmware/tests/mockups/drivers/px_wrap.h +++ b/firmware/tests/mockups/drivers/px_wrap.h @@ -24,8 +24,9 @@ * \brief Payload-X driver wrap definition. * * \author Gabriel Mariano Marcelino + * \author Carlos Augusto Porto Freitas * - * \version 0.10.8 + * \version 0.10.19 * * \date 2023/09/18 * @@ -41,11 +42,15 @@ #include -int __wrap_px_init(px_config_t conf); +int __wrap_px_init(px_config_t *conf); -int __wrap_px_write(px_config_t conf, uint8_t *data, uint16_t len); +int __wrap_px_write(px_config_t *conf, uint8_t *data, uint16_t len); -int __wrap_px_read(px_config_t conf, uint8_t *data, uint16_t len); +int __wrap_px_read(px_config_t *conf, uint8_t *data, uint16_t len); + +int __wrap_px_enable(px_config_t *conf); + +int __wrap_px_disable(px_config_t *conf); #endif /* PX_WRAP_H_ */ diff --git a/firmware/version.h b/firmware/version.h index 04ede94e..4f581505 100644 --- a/firmware/version.h +++ b/firmware/version.h @@ -25,7 +25,7 @@ * * \author Gabriel Mariano Marcelino * - * \version 0.10.17 + * \version 0.10.19 * * \date 2019/10/25 * @@ -36,7 +36,7 @@ #ifndef VERSION_H_ #define VERSION_H_ -#define FIRMWARE_VERSION "0.10.17" +#define FIRMWARE_VERSION "0.10.19" #define FIRMWARE_STATUS "Development"