Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add health check runtime test for memories, fix fram driver and fix internal flash device driver #353

Merged
merged 32 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
4f29ca5
firmware: Add Memory Health Check utility
c-porto Jul 24, 2024
89d7007
firmware: system: sys_log: Add a log function for tests
c-porto Jul 26, 2024
edab4b5
firmware: config: Fix HealthCheck flags
c-porto Jul 26, 2024
c242800
firmware: app: tasks: mem_check: Add tests for param loading from fram
c-porto Jul 26, 2024
aeafdb2
firmware: system: sys_log: Fix print_test_result function
c-porto Jul 27, 2024
0fd5515
firmware: Add initial backup for media info using internal flash
c-porto Jul 27, 2024
f2405c4
firmware: app: Fix obdh data saving to fram
c-porto Jul 28, 2024
1eb642c
firmware: system: sys_log: Add SYS_LOG_INFO color
c-porto Jul 28, 2024
7d37afb
firmware: app: tasks: time_control: Add log message when saving syste…
c-porto Jul 28, 2024
465a728
firmware: app: Refactor data log task
c-porto Jul 28, 2024
41e1385
firmware: Fix integer type bug in payload lenght assignment
c-porto Jul 28, 2024
3a01c36
firmware: Fix MEDIA_INT_FLASH device functions
c-porto Jul 29, 2024
537be79
firmware: app: tasks: read_edc: Update flash writing of PTT packets
c-porto Jul 30, 2024
6eaf9ec
firmware: app: utils: mem_mng: Format functions
c-porto Jul 30, 2024
18cfe49
firmware: app: tasks: mem_check: Add internal flash tests and cleanup
c-porto Jul 30, 2024
2504e8b
firmware: app: Update obdh data backup strategy
c-porto Jul 30, 2024
0a09314
firmware: app: tasks: mem_check: Include tests for new backup strategy
c-porto Jul 30, 2024
c9f2901
firmware: app: utils: mem_mng: Add another check to ensure data integ…
c-porto Jul 30, 2024
871e1db
firmware: system: sys_log: Increase max wait time for sys_log mutex
c-porto Jul 30, 2024
9471994
firmware: drivers: flash: Fix flash_erase function
c-porto Jul 30, 2024
ce72e52
firmware: app: utils: Remove assert
c-porto Jul 30, 2024
ccabdde
firmware: drivers: cy15x102qn: Add write enable command for writes
c-porto Jul 31, 2024
79dec56
firmware: devices: media: Add fram status register config on initiali…
c-porto Jul 31, 2024
72fa950
firmware: app: tasks: mem_check: Update mem_full_clean function
c-porto Jul 31, 2024
6ca4bb9
firmware: app: tasks: data_log: Add notification log message
c-porto Jul 31, 2024
8ed968e
firmware: app: tasks: startup: Update media init structure
c-porto Jul 31, 2024
bb76fb6
firmware: Update versions of modified files
c-porto Aug 2, 2024
e454c38
Merge branch 'dev_firmware' into feature_mem_debug
c-porto Aug 2, 2024
79a09fb
firmware: Update version for modified files
c-porto Aug 2, 2024
2c1a37a
firmware: app: tasks: startup: Fix MISRA-C 2012 violations
c-porto Aug 2, 2024
32c4680
firmware: tests: drivers: Update cy15x102qn test to expect WREN ops
c-porto Aug 2, 2024
cf09a64
firmware: tests: devices: Update media test to expect fram configurat…
c-porto Aug 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions firmware/app/structs/obdh_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
* \brief OBDH data structure definition.
*
* \author Gabriel Mariano Marcelino <[email protected]>
* \author Carlos Augusto Porto Freitas <[email protected]>
*
* \version 0.10.17
* \version 0.10.18
*
* \date 2020/07/16
*
Expand Down Expand Up @@ -151,20 +152,20 @@ typedef struct
uint16_t temperature; /**< Temperature of the uC in Kelvin. */
uint16_t current; /**< Input current in mA. */
uint16_t voltage; /**< Input voltage in mV. */
uint8_t last_reset_cause; /**< Last reset cause code. */
uint16_t reset_counter; /**< Reset counter. */
uint8_t last_reset_cause; /**< Last reset cause code. */
uint8_t last_valid_tc; /**< Last valid telecommand ID. */
uint8_t mode; /**< Satellite mode. */
uint8_t ant_deployment_counter; /**< Antenna deployment counter. */
uint8_t initial_hib_time_count; /**< Initial hibernation time counter in minutes. */
uint8_t hw_version; /**< Hardware version. */
uint32_t fw_version; /**< Firmware version (ex.: "v1.2.3" = 0x00010203). */
uint8_t mode; /**< Satellite mode. */
sys_time_t ts_last_mode_change; /**< Timestamp of the last change in the operation mode. */
sys_time_t mode_duration; /**< Mode duration (valid only in hibernation mode). */
bool initial_hib_executed; /**< Initial hibernation executed flag. */
uint8_t initial_hib_time_count; /**< Initial hibernation time counter in minutes. */
bool ant_deployment_executed; /**< Antenna deployment executed flag. */
uint8_t ant_deployment_counter; /**< Antenna deployment counter. */
position_data_t position; /**< Current position of the satellite. */
media_data_t media; /**< Memories data. */
position_data_t position; /**< Current position of the satellite. */
} obdh_data_t;

#endif /* OBDH_DATA_H_ */
Expand Down
132 changes: 43 additions & 89 deletions firmware/app/tasks/data_log.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
* \brief Data log task implementation.
*
* \author Gabriel Mariano Marcelino <[email protected]>
*
* \version 0.10.17
* \author Carlos Augusto Porto Freitas <[email protected]>
*
* \version 0.10.18
*
* \date 2021/05/24
*
Expand All @@ -34,153 +35,106 @@
*/

#include <stdint.h>
#include <string.h>

#include <system/sys_log/sys_log.h>
#include <devices/media/media.h>
#include <structs/satellite.h>
#include <utils/mem_mng.h>

#include "data_log.h"
#include "startup.h"

xTaskHandle xTaskDataLogHandle;

/**
* \brief Writes data to a given flash memory page.
*
* \param[in] is the array of bytes to write.
*
* \param[in,out] page is a pointer to the current page to write.
*
* \param[in] page_size is the page size, in bytes, of the flash memory.
*
* \param[in] start_page is the possible start page to write.
*
* \param[in] end_page is the possible end page to write.
*
* \return The status/error code.
*/
int write_data_to_flash_page(uint8_t *data, uint32_t *page, uint32_t page_size, uint32_t start_page, uint32_t end_page);

void vTaskDataLog(void)
{
/* Wait startup task to finish */
xEventGroupWaitBits(task_startup_status, TASK_STARTUP_DONE, pdFALSE, pdTRUE, pdMS_TO_TICKS(TASK_DATA_LOG_INIT_TIMEOUT_MS));

media_info_t nor_info = media_get_info(MEDIA_NOR);

uint32_t mem_page = 0U;
uint8_t page_buf[256] = {0};
void *null_ptr;

while(1)
{
TickType_t last_cycle = xTaskGetTickCount();

sys_log_print_event_from_module(SYS_LOG_INFO, TASK_DATA_LOG_NAME, "Saving data to flash memory...");
sys_log_new_line();

/* OBDH data */
if (memcpy(&page_buf[0], &sat_data_buf.obdh, sizeof(obdh_telemetry_t)) == &page_buf[0])
(void)memcpy(&page_buf[0], &sat_data_buf.obdh, sizeof(obdh_telemetry_t));
if (mem_mng_write_data_to_flash_page(page_buf, &sat_data_buf.obdh.data.media.last_page_obdh_data, nor_info.page_size, CONFIG_MEM_OBDH_DATA_START_PAGE, CONFIG_MEM_OBDH_DATA_END_PAGE) != 0)
{
if (write_data_to_flash_page(page_buf, &sat_data_buf.obdh.data.media.last_page_obdh_data, nor_info.page_size, CONFIG_MEM_OBDH_DATA_START_PAGE, CONFIG_MEM_OBDH_DATA_END_PAGE) != 0)
{
sys_log_print_event_from_module(SYS_LOG_ERROR, TASK_DATA_LOG_NAME, "Error writing the OBDH data to the flash memory!");
sys_log_new_line();
}
sys_log_print_event_from_module(SYS_LOG_ERROR, TASK_DATA_LOG_NAME, "Error writing the OBDH data to the flash memory!");
sys_log_new_line();
}

null_ptr = memset(&page_buf[0], 0, 256);
(void)memset(&page_buf[0], 0, 256);

/* EPS data */
if (memcpy(&page_buf[0], &sat_data_buf.eps, sizeof(eps_telemetry_t)) == &page_buf[0])
(void)memcpy(&page_buf[0], &sat_data_buf.eps, sizeof(eps_telemetry_t));
if (mem_mng_write_data_to_flash_page(page_buf, &sat_data_buf.obdh.data.media.last_page_eps_data, nor_info.page_size, CONFIG_MEM_EPS_DATA_START_PAGE, CONFIG_MEM_EPS_DATA_END_PAGE) != 0)
{
if (write_data_to_flash_page(page_buf, &sat_data_buf.obdh.data.media.last_page_eps_data, nor_info.page_size, CONFIG_MEM_EPS_DATA_START_PAGE, CONFIG_MEM_EPS_DATA_END_PAGE) != 0)
{
sys_log_print_event_from_module(SYS_LOG_ERROR, TASK_DATA_LOG_NAME, "Error writing the EPS data to the flash memory!");
sys_log_new_line();
}
sys_log_print_event_from_module(SYS_LOG_ERROR, TASK_DATA_LOG_NAME, "Error writing the EPS data to the flash memory!");
sys_log_new_line();
}

null_ptr = memset(&page_buf[0], 0, 256);
(void)memset(&page_buf[0], 0, 256);

/* TTC 0 data */
if (memcpy(&page_buf[0], &sat_data_buf.ttc_0, sizeof(ttc_telemetry_t)) == &page_buf[0])
(void)memcpy(&page_buf[0], &sat_data_buf.ttc_0, sizeof(ttc_telemetry_t));
if (mem_mng_write_data_to_flash_page(page_buf, &sat_data_buf.obdh.data.media.last_page_ttc_0_data, nor_info.page_size, CONFIG_MEM_TTC_0_DATA_START_PAGE, CONFIG_MEM_TTC_0_DATA_END_PAGE) != 0)
{
if (write_data_to_flash_page(page_buf, &sat_data_buf.obdh.data.media.last_page_ttc_0_data, nor_info.page_size, CONFIG_MEM_TTC_0_DATA_START_PAGE, CONFIG_MEM_TTC_0_DATA_END_PAGE) != 0)
{
sys_log_print_event_from_module(SYS_LOG_ERROR, TASK_DATA_LOG_NAME, "Error writing the TTC 0 data to the flash memory!");
sys_log_new_line();
}
sys_log_print_event_from_module(SYS_LOG_ERROR, TASK_DATA_LOG_NAME, "Error writing the TTC 0 data to the flash memory!");
sys_log_new_line();
}

null_ptr = memset(&page_buf[0], 0, 256);
(void)memset(&page_buf[0], 0, 256);

/* TTC 1 data */
if (memcpy(&page_buf[0], &sat_data_buf.ttc_1, sizeof(ttc_telemetry_t)) == &page_buf[0])
(void)memcpy(&page_buf[0], &sat_data_buf.ttc_1, sizeof(ttc_telemetry_t));
if (mem_mng_write_data_to_flash_page(page_buf, &sat_data_buf.obdh.data.media.last_page_ttc_1_data, nor_info.page_size, CONFIG_MEM_TTC_1_DATA_START_PAGE, CONFIG_MEM_TTC_1_DATA_END_PAGE) != 0)
{
if (write_data_to_flash_page(page_buf, &sat_data_buf.obdh.data.media.last_page_ttc_1_data, nor_info.page_size, CONFIG_MEM_TTC_1_DATA_START_PAGE, CONFIG_MEM_TTC_1_DATA_END_PAGE) != 0)
{
sys_log_print_event_from_module(SYS_LOG_ERROR, TASK_DATA_LOG_NAME, "Error writing the TTC 1 data to the flash emory!");
sys_log_new_line();
}
sys_log_print_event_from_module(SYS_LOG_ERROR, TASK_DATA_LOG_NAME, "Error writing the TTC 1 data to the flash emory!");
sys_log_new_line();
}

null_ptr = memset(&page_buf[0], 0, 256);
(void)memset(&page_buf[0], 0, 256);

/* Antenna data */
if (memcpy(&page_buf[0], &sat_data_buf.antenna, sizeof(antenna_telemetry_t)) == &page_buf[0])
(void)memcpy(&page_buf[0], &sat_data_buf.antenna, sizeof(antenna_telemetry_t));
if (mem_mng_write_data_to_flash_page(page_buf, &sat_data_buf.obdh.data.media.last_page_ant_data, nor_info.page_size, CONFIG_MEM_ANT_DATA_START_PAGE, CONFIG_MEM_ANT_DATA_END_PAGE) != 0)
{
if (write_data_to_flash_page(page_buf, &sat_data_buf.obdh.data.media.last_page_ant_data, nor_info.page_size, CONFIG_MEM_ANT_DATA_START_PAGE, CONFIG_MEM_ANT_DATA_END_PAGE) != 0)
{
sys_log_print_event_from_module(SYS_LOG_ERROR, TASK_DATA_LOG_NAME, "Error writing the antenna data to the flash memory!");
sys_log_new_line();
}
sys_log_print_event_from_module(SYS_LOG_ERROR, TASK_DATA_LOG_NAME, "Error writing the antenna data to the flash memory!");
sys_log_new_line();
}

null_ptr = memset(&page_buf[0], 0, 256);
(void)memset(&page_buf[0], 0, 256);

/* EDC data */
if (memcpy(&page_buf[0], &sat_data_buf.edc_0, sizeof(payload_telemetry_t)) == &page_buf[0])
(void)memcpy(&page_buf[0], &sat_data_buf.edc_0, 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)
{
if (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!");
sys_log_new_line();
}
sys_log_print_event_from_module(SYS_LOG_ERROR, TASK_DATA_LOG_NAME, "Error writing the EDC data to the flash memory!");
sys_log_new_line();
}

null_ptr = memset(&page_buf[0], 0, 256);
(void)memset(&page_buf[0], 0, 256);

/* Payload-X data */
if (memcpy(&page_buf[0], &sat_data_buf.payload_x, sizeof(payload_telemetry_t)) == &page_buf[0])
(void)memcpy(&page_buf[0], &sat_data_buf.payload_x, sizeof(payload_telemetry_t));
if (mem_mng_write_data_to_flash_page(page_buf, &sat_data_buf.obdh.data.media.last_page_px_data, nor_info.page_size, CONFIG_MEM_PX_DATA_START_PAGE, CONFIG_MEM_PX_DATA_END_PAGE) != 0)
{
if (write_data_to_flash_page(page_buf, &sat_data_buf.obdh.data.media.last_page_px_data, nor_info.page_size, CONFIG_MEM_PX_DATA_START_PAGE, CONFIG_MEM_PX_DATA_END_PAGE) != 0)
{
sys_log_print_event_from_module(SYS_LOG_ERROR, TASK_DATA_LOG_NAME, "Error writing the Payload-X data to the flash memory!");
sys_log_new_line();
}
sys_log_print_event_from_module(SYS_LOG_ERROR, TASK_DATA_LOG_NAME, "Error writing the Payload-X data to the flash memory!");
sys_log_new_line();
}

null_ptr = memset(&page_buf[0], 0, 256);
(void)memset(&page_buf[0], 0, 256);

vTaskDelayUntil(&last_cycle, pdMS_TO_TICKS(TASK_DATA_LOG_PERIOD_MS));
}
}

int write_data_to_flash_page(uint8_t *data, uint32_t *page, uint32_t page_size, uint32_t start_page, uint32_t end_page)
{
int err = -1;

if (media_write(MEDIA_NOR, (*page) * page_size, data, page_size) == 0)
{
(*page)++; // cppcheck-suppress misra-c2012-17.8

if (*page > end_page)
{
*page = start_page;
}

err = 0;
}

return err;
}

/** \} End of file_system group */
10 changes: 8 additions & 2 deletions firmware/app/tasks/housekeeping.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
* \brief Housekeeping task implementation.
*
* \author Gabriel Mariano Marcelino <[email protected]>
* \author Carlos Augusto Porto Freitas <[email protected]>
*
* \version 0.10.17
* \version 0.10.18
*
* \date 2021/04/27
*
Expand Down Expand Up @@ -68,11 +69,16 @@ void vTaskHousekeeping(void)
/* Save the last available OBDH data at every minute */
if ((system_get_time() % 60U) == 0U)
{
if (mem_mng_save_obdh_data_to_fram(sat_data_buf.obdh) != 0)
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();
}
}

vTaskDelayUntil(&last_cycle, pdMS_TO_TICKS(TASK_HOUSEKEEPING_PERIOD_MS));
Expand Down
Loading
Loading