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 Mutex to SPI bus and general bug fixes, closes #346, fixes #351. #352

Merged
merged 33 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
2c45941
firmware: drivers: spi: Adding a mutex to protect the spi bus from co…
c-porto Feb 28, 2024
7241fc8
firmware: drivers: spi: Updating mutex initialization.
c-porto Mar 13, 2024
1f9df5b
Merge branch 'dev_firmware' into spi_mutex_feature
c-porto May 15, 2024
78c230f
firmware: drivers: spi: Fix MISRA-C rule #346
c-porto May 15, 2024
56b50dc
firmware: drivers: spi: Change spi mutex to be recursive #346
c-porto May 15, 2024
c197973
firmware: tests: freertos_sim: Add recursive mutex simulation functio…
c-porto May 15, 2024
0ed378a
firmware: drivers: sl_ttc2: Update driver to use spi port mutex #346
c-porto May 15, 2024
07fbde5
firmware: tests: mockups: drivers: Add spi mutex mockup functions #346
c-porto May 15, 2024
3f2234f
firmware: tests: mockups: drivers: Remove unnecessary mockup function
c-porto May 15, 2024
92050c3
firmware: tests: drivers: Update sl_ttc2 driver test #346
c-porto May 15, 2024
e877c82
firmware: drivers: mt25q: Fix write enable/disable function #346
c-porto May 15, 2024
8cd4a77
firmware: drivers: sl_ttc2: Update sl_ttc2 mutex related definitions
c-porto May 16, 2024
1acb265
firmware: drivers: mt25q: Add mt25q mutex functions #346
c-porto May 16, 2024
93c842f
firmware: drivers: mt25q: Update mt25q driver to use the spi port mut…
c-porto May 16, 2024
d1917aa
firmware: drivers: cy15x102qn: Add cy15x102qn mutex functions #346
c-porto May 16, 2024
0f29581
firmware: drivers: cy15x102qn: Update cy15x102qn driver to use the sp…
c-porto May 27, 2024
c5e3989
firmware: Enable Housekeeping Task and increase its stack size
c-porto May 28, 2024
6ced576
firmware: app: structs: Fix define for TTC1 data default value
c-porto May 29, 2024
59128b2
firmware: app: tasks: housekeeping: Fix OBDH data saving time period
c-porto Jun 4, 2024
6f6179e
firmware: app: tasks: data_log: Fix memory page update after a write
c-porto Jun 4, 2024
04e4120
firmware: Fix FRAM initialization
c-porto Jun 6, 2024
6373be5
Merge branch 'dev_firmware' into spi_mutex_feature
c-porto Jun 6, 2024
df675c8
firmware: app: tasks: Update initial delay for TTC tasks #351
c-porto Jun 7, 2024
363315d
firmware: devices: temp_sensor: Fix raw data to Kelvin conversion
c-porto Jun 21, 2024
067f377
firmware: app: tasks: read_sensors: Fix temperature param unit
c-porto Jun 21, 2024
0472aef
firmware: devices: current_sensor: Fix RL resistor value
c-porto Jun 21, 2024
62092e9
firmware: app: Add logs to FRAM initialization
c-porto Jul 3, 2024
cba923e
firmware: devices: voltage_sensor: Add a filter to voltage sensor mea…
c-porto Jul 11, 2024
1a5fdb7
firmware: app: tasks: read_sensors: Add log messages for sensor readings
c-porto Jul 11, 2024
b337df3
firmware: tests: drivers: Update tests for memory drivers
c-porto Jul 11, 2024
2ec68cb
firmware: Update versions of modified files
c-porto Jul 11, 2024
0dbd377
firmware: Update the firmware version
c-porto Jul 11, 2024
4f1ad7b
firmware: devices: voltage_sensor: Change filter first sample
c-porto Jul 15, 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
4 changes: 2 additions & 2 deletions firmware/app/structs/obdh_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*
* \author Gabriel Mariano Marcelino <[email protected]>
*
* \version 0.10.9
* \version 0.10.17
*
* \date 2020/07/16
*
Expand Down Expand Up @@ -105,7 +105,7 @@
#define OBDH_PARAM_MEDIA_LAST_OBDH_DATA_DEFAULT_VAL CONFIG_MEM_OBDH_DATA_START_PAGE
#define OBDH_PARAM_MEDIA_LAST_EPS_DATA_DEFAULT_VAL CONFIG_MEM_EPS_DATA_START_PAGE
#define OBDH_PARAM_MEDIA_LAST_TTC_0_DATA_DEFAULT_VAL CONFIG_MEM_TTC_0_DATA_START_PAGE
#define OBDH_PARAM_MEDIA_LAST_TTC_1_DATA_DEFAULT_VAL CONFIG_MEM_TTC_1_DATA_END_PAGE
#define OBDH_PARAM_MEDIA_LAST_TTC_1_DATA_DEFAULT_VAL CONFIG_MEM_TTC_1_DATA_START_PAGE
#define OBDH_PARAM_MEDIA_LAST_ANT_DATA_DEFAULT_VAL CONFIG_MEM_ANT_DATA_START_PAGE
#define OBDH_PARAM_MEDIA_LAST_EDC_DATA_DEFAULT_VAL CONFIG_MEM_EDC_DATA_START_PAGE
#define OBDH_PARAM_MEDIA_LAST_PX_DATA_DEFAULT_VAL CONFIG_MEM_PX_DATA_START_PAGE
Expand Down
4 changes: 2 additions & 2 deletions firmware/app/tasks/data_log.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*
* \author Gabriel Mariano Marcelino <[email protected]>
*
* \version 0.10.9
* \version 0.10.17
*
* \date 2021/05/24
*
Expand Down Expand Up @@ -170,7 +170,7 @@ int write_data_to_flash_page(uint8_t *data, uint32_t *page, uint32_t page_size,

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

if (*page > end_page)
{
Expand Down
4 changes: 2 additions & 2 deletions firmware/app/tasks/housekeeping.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*
* \author Gabriel Mariano Marcelino <[email protected]>
*
* \version 0.10.9
* \version 0.10.17
*
* \date 2021/04/27
*
Expand Down Expand Up @@ -66,7 +66,7 @@ void vTaskHousekeeping(void)
}

/* Save the last available OBDH data at every minute */
if ((system_get_time() % (60U*1000U)) == 0U)
if ((system_get_time() % 60U) == 0U)
{
if (mem_mng_save_obdh_data_to_fram(sat_data_buf.obdh) != 0)
{
Expand Down
4 changes: 2 additions & 2 deletions firmware/app/tasks/housekeeping.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*
* \author Gabriel Mariano Marcelino <[email protected]>
*
* \version 0.8.33
* \version 0.10.17
*
* \date 2021/04/27
*
Expand All @@ -41,7 +41,7 @@
#include <task.h>

#define TASK_HOUSEKEEPING_NAME "Housekeeping" /**< Task name. */
#define TASK_HOUSEKEEPING_STACK_SIZE 160 /**< Stack size in bytes. */
#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_INIT_TIMEOUT_MS 2000 /**< Wait time to initialize the task in milliseconds. */
Expand Down
4 changes: 2 additions & 2 deletions firmware/app/tasks/process_tc.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.14
* \version 0.10.17
*
* \date 2021/07/06
*
Expand All @@ -45,7 +45,7 @@
#define TASK_PROCESS_TC_STACK_SIZE 500 /**< Stack size in bytes. */
#define TASK_PROCESS_TC_PRIORITY 4 /**< Task priority. */
#define TASK_PROCESS_TC_PERIOD_MS 1000 /**< Task period in milliseconds. */
#define TASK_PROCESS_TC_INITIAL_DELAY_MS 2000 /**< Delay, in milliseconds, before the first execution. */
#define TASK_PROCESS_TC_INITIAL_DELAY_MS 6500 /**< Delay, in milliseconds, before the first execution. */
#define TASK_PROCESS_TC_INIT_TIMEOUT_MS (10*1000) /**< Wait time to initialize the task in milliseconds. */

/**
Expand Down
20 changes: 18 additions & 2 deletions firmware/app/tasks/read_sensors.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*
* \author Gabriel Mariano Marcelino <[email protected]>
*
* \version 0.8.5
* \version 0.10.17
*
* \date 2020/07/12
*
Expand All @@ -38,6 +38,7 @@
#include <devices/temp_sensor/temp_sensor.h>

#include <structs/satellite.h>
#include <system/sys_log/sys_log.h>

#include "read_sensors.h"
#include "startup.h"
Expand All @@ -59,18 +60,33 @@ void vTaskReadSensors(void)
if (current_sensor_read_ma(&buf) == 0)
{
sat_data_buf.obdh.data.current = buf;

sys_log_print_event_from_module(SYS_LOG_INFO, TASK_READ_SENSORS_NAME, "Current input current: ");
sys_log_print_uint((uint32_t)buf);
sys_log_print_msg(" mA");
sys_log_new_line();
}

/* OBDH voltage */
if (voltage_sensor_read_mv(&buf) == 0)
{
sat_data_buf.obdh.data.voltage = buf;

sys_log_print_event_from_module(SYS_LOG_INFO, TASK_READ_SENSORS_NAME, "Current input voltage: ");
sys_log_print_uint((uint32_t)buf);
sys_log_print_msg(" mV");
sys_log_new_line();
}

/* OBDH temperature */
if (temp_sensor_read_raw(&buf) == 0)
if (temp_sensor_read_k(&buf) == 0)
{
sat_data_buf.obdh.data.temperature = buf;

sys_log_print_event_from_module(SYS_LOG_INFO, TASK_READ_SENSORS_NAME, "Current uC temperature: ");
sys_log_print_uint((uint32_t)buf);
sys_log_print_msg(" K");
sys_log_new_line();
}

/* Data timestamp */
Expand Down
4 changes: 2 additions & 2 deletions firmware/app/tasks/read_ttc.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.14
* \version 0.10.17
*
* \date 2021/05/14
*
Expand All @@ -45,7 +45,7 @@
#define TASK_READ_TTC_STACK_SIZE 384 /**< Stack size in bytes. */
#define TASK_READ_TTC_PRIORITY 3 /**< Task priority. */
#define TASK_READ_TTC_PERIOD_MS (60000) /**< Task period in milliseconds. */
#define TASK_READ_TTC_INITIAL_DELAY_MS 1000 /**< Delay, in milliseconds, before the first execution. */
#define TASK_READ_TTC_INITIAL_DELAY_MS 5500 /**< Delay, in milliseconds, before the first execution. */
#define TASK_READ_TTC_INIT_TIMEOUT_MS 2000 /**< Wait time to initialize the task in milliseconds. */

/**
Expand Down
10 changes: 8 additions & 2 deletions firmware/app/tasks/startup.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*
* \author Gabriel Mariano Marcelino <[email protected]>
*
* \version 0.10.9
* \version 0.10.17
*
* \date 2019/12/04
*
Expand Down Expand Up @@ -114,14 +114,20 @@ void vTaskStartup(void)
}
else
{
sys_log_print_event_from_module(SYS_LOG_WARNING, TASK_STARTUP_NAME, "FRAM was not initialized in previous cycles");
sys_log_new_line();

/* Initialize FRAM */
if (mem_mng_init_fram() == 0)
{
/* Load default values to the OBDH data buffer */
mem_mng_load_obdh_data_from_default_values(&sat_data_buf.obdh);

sys_log_print_event_from_module(SYS_LOG_WARNING, TASK_STARTUP_NAME, "Loading default values to FRAM...");
sys_log_new_line();

/* Write the OBDH data to the FRAM memory */
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)
{
error_counter++;
}
Expand Down
12 changes: 11 additions & 1 deletion firmware/app/tasks/tasks.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*
* \author Gabriel Mariano Marcelino <[email protected]>
*
* \version 0.10.7
* \version 0.10.17
*
* \date 2019/11/02
*
Expand Down Expand Up @@ -54,6 +54,7 @@
#include "process_tc.h"
#include "pos_det.h"
#include "read_px.h"
#include "housekeeping.h"

void create_tasks(void)
{
Expand Down Expand Up @@ -204,6 +205,15 @@ void create_tasks(void)
}
#endif /* CONFIG_TASK_PAYLOAD_X_ENABLED */

#if defined(CONFIG_TASK_HOUSEKEEPING_ENABLED) && (CONFIG_TASK_HOUSEKEEPING_ENABLED == 1)
xTaskCreate(vTaskHousekeeping, TASK_HOUSEKEEPING_NAME, TASK_HOUSEKEEPING_STACK_SIZE, NULL, TASK_HOUSEKEEPING_PRIORITY, &xTaskHousekeepingHandle);

if (xTaskHousekeepingHandle == NULL)
{
/* Error creating the Housekeeping task */
}
#endif /* CONFIG_TASK_HOUSEKEEPING_ENABLED */

create_event_groups();
}

Expand Down
34 changes: 17 additions & 17 deletions firmware/app/utils/mem_mng.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*
* \author Gabriel Mariano Marcelino <[email protected]>
*
* \version 0.10.9
* \version 0.10.17
*
* \date 2024/02/24
*
Expand All @@ -37,6 +37,7 @@
#include <string.h>

#include <config/config.h>
#include <system/sys_log/sys_log.h>

#include "mem_mng.h"

Expand All @@ -45,12 +46,15 @@ int mem_mng_check_fram(void)
int err = -1;

uint8_t mem_word_ref[8] = CONFIG_MEM_INIT_WORD;
uint8_t mem_word[8] = {0};
uint8_t mem_word[8];

if (media_read(MEDIA_FRAM, CONFIG_MEM_ADR_INIT_WORD, mem_word, 8U) == 0)
{
if (memcmp(&mem_word_ref[0], &mem_word[0], 8U) == 0)
{
sys_log_print_event_from_module(SYS_LOG_INFO, MEM_MNG_NAME, "FRAM was already initalized");
sys_log_new_line();

err = 0;
}
}
Expand Down Expand Up @@ -109,9 +113,8 @@ void mem_mng_load_obdh_data_from_default_values(obdh_telemetry_t *tel)
uint8_t tle_line1[70] = OBDH_PARAM_POSITION_TLE_LINE1_DEFAULT_VAL;
uint8_t tle_line2[70] = OBDH_PARAM_POSITION_TLE_LINE2_DEFAULT_VAL;

void *null_ptr;
null_ptr = memcpy(&tel->data.position.tle_line1, &tle_line1[0], 70U);
null_ptr = memcpy(&tel->data.position.tle_line2, &tle_line2[0], 70U);
(void)memcpy(&tel->data.position.tle_line1, &tle_line1[0], 70U);
(void)memcpy(&tel->data.position.tle_line2, &tle_line2[0], 70U);

tel->data.position.latitude = OBDH_PARAM_POSITION_LATITUDE_DEFAULT_VAL;
tel->data.position.longitude = OBDH_PARAM_POSITION_LONGITUDE_DEFAULT_VAL;
Expand All @@ -126,18 +129,17 @@ void mem_mng_load_obdh_data_from_default_values(obdh_telemetry_t *tel)
tel->data.media.last_page_sbcd_pkts = OBDH_PARAM_MEDIA_LAST_SBCD_PKTS_DEFAULT_VAL;
}

int mem_mng_save_obdh_data_to_fram(obdh_telemetry_t tel)
int mem_mng_save_obdh_data_to_fram(obdh_telemetry_t* tel)
{
int err = -1;

uint8_t buf[256] = {0};
uint8_t buf[256];

(void)memcpy(buf, tel, sizeof(obdh_telemetry_t));

if (memcpy(&buf[0], &tel, sizeof(obdh_telemetry_t)) == &buf[0])
if (media_write(MEDIA_FRAM, CONFIG_MEM_ADR_SYS_PARAM, buf, 256U) == 0)
{
if (media_write(MEDIA_FRAM, CONFIG_MEM_ADR_SYS_PARAM, buf, 256U) == 0)
{
err = 0;
}
err = 0;
}

return err;
Expand All @@ -147,14 +149,12 @@ int mem_mng_load_obdh_data_from_fram(obdh_telemetry_t *tel)
{
int err = -1;

uint8_t sys_par[256] = {0};
uint8_t sys_par[256];

if (media_read(MEDIA_FRAM, CONFIG_MEM_ADR_SYS_PARAM, sys_par, sizeof(obdh_telemetry_t)) == 0)
{
if (memcpy(&tel, &sys_par[0], sizeof(obdh_telemetry_t)) == &tel)
{
err = 0;
}
(void)memcpy(tel, sys_par, sizeof(obdh_telemetry_t));
err = 0;
}

return err;
Expand Down
6 changes: 4 additions & 2 deletions firmware/app/utils/mem_mng.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*
* \author Gabriel Mariano Marcelino <[email protected]>
*
* \version 0.10.9
* \version 0.10.17
*
* \date 2024/02/24
*
Expand All @@ -41,6 +41,8 @@

#include <app/structs/satellite.h>

#define MEM_MNG_NAME "Memory Management"

/**
* \brief Checks if the FRAM memory is initialized or not.
*
Expand Down Expand Up @@ -78,7 +80,7 @@ void mem_mng_load_obdh_data_from_default_values(obdh_telemetry_t *tel);
*
* \return The status/error code.
*/
int mem_mng_save_obdh_data_to_fram(obdh_telemetry_t tel);
int mem_mng_save_obdh_data_to_fram(obdh_telemetry_t *tel);

/**
* \brief Loads the last saved OBDH data from the FRAM memory.
Expand Down
3 changes: 2 additions & 1 deletion firmware/config/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*
* \author Gabriel Mariano Marcelino <[email protected]>
*
* \version 0.10.15
* \version 0.10.17
*
* \date 2019/10/26
*
Expand Down Expand Up @@ -53,6 +53,7 @@
#define CONFIG_TASK_ANTENNA_DEPLOYMENT_ENABLED 0
#define CONFIG_TASK_POSITION_DETERMINATION_ENABLED 1
#define CONFIG_TASK_PAYLOAD_X_ENABLED 1
#define CONFIG_TASK_HOUSEKEEPING_ENABLED 1

/* Devices */
#define CONFIG_DEV_MEDIA_INT_ENABLED 1
Expand Down
6 changes: 3 additions & 3 deletions firmware/devices/current_sensor/current_sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*
* \author Gabriel Mariano Marcelino <[email protected]>
*
* \version 0.6.2
* \version 0.10.17
*
* \date 2020/07/11
*
Expand All @@ -50,8 +50,8 @@
#define CURRENT_SENSOR_RSENSE_VALUE_MOHM 50 /**< Rsense resistor value in mOhm. */

/* Rload value */
#define CURRENT_SENSOR_RL_VALUE_OHM 1650 /**< RL resistor value in Ohms. */
#define CURRENT_SENSOR_RL_VALUE_KOHM 1.65 /**< RL resistor value in kOhms. */
#define CURRENT_SENSOR_RL_VALUE_OHM 12000 /**< RL resistor value in Ohms. */
#define CURRENT_SENSOR_RL_VALUE_KOHM 12 /**< RL resistor value in kOhms. */

/* Gain value */
#define CURRENT_SENSOR_GAIN_A_V 0.025 /**< Current gain of max9934 in A/V. */
Expand Down
6 changes: 3 additions & 3 deletions firmware/devices/temp_sensor/temp_sensor.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*
* \author Gabriel Mariano Marcelino <[email protected]>
*
* \version 0.7.28
* \version 0.10.17
*
* \date 2020/03/17
*
Expand Down Expand Up @@ -95,9 +95,9 @@ uint16_t temp_sensor_raw_to_k(uint16_t raw)
{
int16_t temp_c = temp_sensor_raw_to_c(raw);

if (temp_c < 273)
if (temp_c < -273)
{
temp_c = 273;
temp_c = -273;
}

uint16_t res = temp_c + 273;
Expand Down
Loading
Loading