Skip to content

Commit

Permalink
Merge pull request #354 from spacelab-ufsc/feature_op_modes
Browse files Browse the repository at this point in the history
Feature op modes
  • Loading branch information
c-porto authored Aug 19, 2024
2 parents f60610d + 8f385bc commit c15ace9
Show file tree
Hide file tree
Showing 35 changed files with 1,384 additions and 298 deletions.
3 changes: 2 additions & 1 deletion firmware/app/structs/obdh_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* \author Gabriel Mariano Marcelino <[email protected]>
* \author Carlos Augusto Porto Freitas <[email protected]>
*
* \version 0.10.18
* \version 0.10.19
*
* \date 2020/07/16
*
Expand Down Expand Up @@ -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.
Expand Down
17 changes: 15 additions & 2 deletions firmware/app/structs/satellite.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
* \brief Satellite data structure definition.
*
* \author Gabriel Mariano Marcelino <[email protected]>
* \author Carlos Augusto Porto Freitas <[email protected]>
*
* \version 0.10.9
* \version 0.10.19
*
* \date 2020/07/16
*
Expand All @@ -45,6 +46,7 @@
#include <devices/eps/eps_data.h>
#include <devices/ttc/ttc_data.h>
#include <devices/antenna/antenna_data.h>
#include <devices/payload/payload.h>

#include "obdh_data.h"

Expand Down Expand Up @@ -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.
*/
Expand All @@ -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;

/**
Expand Down
5 changes: 3 additions & 2 deletions firmware/app/tasks/antenna_deployment.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
* \brief Antenna deployment task implementation.
*
* \author Gabriel Mariano Marcelino <[email protected]>
* \author Carlos Augusto Porto Freitas <[email protected]>
*
* \version 0.10.7
* \version 0.10.19
*
* \date 2021/11/17
*
Expand Down Expand Up @@ -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));

Expand Down
24 changes: 4 additions & 20 deletions firmware/app/tasks/beacon.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
* \brief Beacon task implementation.
*
* \author Gabriel Mariano Marcelino <[email protected]>
* \author Carlos Augusto Porto Freitas <[email protected]>
*
* \version 0.10.9
* \version 0.10.19
*
* \date 2019/10/27
*
Expand Down Expand Up @@ -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;

Expand Down
6 changes: 3 additions & 3 deletions firmware/app/tasks/data_log.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
*
* \author Gabriel Mariano Marcelino <[email protected]>
* \author Carlos Augusto Porto Freitas <[email protected]>
*
* \version 0.10.18
*
* \version 0.10.19
*
* \date 2021/05/24
*
Expand Down Expand Up @@ -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!");
Expand Down
30 changes: 9 additions & 21 deletions firmware/app/tasks/housekeeping.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* \author Gabriel Mariano Marcelino <[email protected]>
* \author Carlos Augusto Porto Freitas <[email protected]>
*
* \version 0.10.18
* \version 0.10.19
*
* \date 2021/04/27
*
Expand All @@ -39,6 +39,7 @@
#include <devices/current_sensor/current_sensor.h>
#include <devices/voltage_sensor/voltage_sensor.h>
#include <devices/temp_sensor/temp_sensor.h>
#include <utils/mem_mng.h>

#include <structs/satellite.h>

Expand All @@ -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));
Expand Down
5 changes: 3 additions & 2 deletions firmware/app/tasks/housekeeping.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
* \brief Housekeeping task definition.
*
* \author Gabriel Mariano Marcelino <[email protected]>
* \author Carlos Augusto Porto Freitas <[email protected]>
*
* \version 0.10.17
* \version 0.10.19
*
* \date 2021/04/27
*
Expand All @@ -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. */

/**
Expand Down
8 changes: 6 additions & 2 deletions firmware/app/tasks/mem_check.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*
* \author Carlos Augusto Porto Freitas <[email protected]>
*
* \version 0.10.18
* \version 0.10.19
*
* \date 2024/07/24
*
Expand All @@ -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)

Expand Down Expand Up @@ -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);
}
}
Expand Down
Loading

0 comments on commit c15ace9

Please sign in to comment.