Skip to content

Commit

Permalink
Merge pull request #157 from spacelab-ufsc/reset_param_feature
Browse files Browse the repository at this point in the history
Merge pull request from reset_param_feature
  • Loading branch information
miguelboing authored Sep 8, 2024
2 parents 58945e6 + ef5ace7 commit 8fa7297
Show file tree
Hide file tree
Showing 20 changed files with 473 additions and 77 deletions.
34 changes: 27 additions & 7 deletions firmware/app/tasks/obdh_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*
* \author Miguel Boing <miguelboing13@gmail.com>
*
* \version 0.5.1
* \version 0.5.2
*
* \date 2024/04/22
*
Expand Down Expand Up @@ -86,10 +86,13 @@ void vTaskObdhServer(void)
case CMDPR_CMD_WRITE_PARAM:
obdh_write_read_bytes(7);

sys_log_print_event_from_module(SYS_LOG_INFO, TASK_OBDH_SERVER_NAME, "TX is now ");

switch(obdh_request.data.param_8)
switch(obdh_request.parameter)
{
case CMDPR_PARAM_TX_ENABLE:
sys_log_print_event_from_module(SYS_LOG_INFO, TASK_OBDH_SERVER_NAME, "TX is now ");

switch(obdh_request.data.param_8)
{
case 0x00:
sys_log_print_msg("Turned off.");
ttc_data_buf.radio.tx_enable = obdh_request.data.param_8;
Expand All @@ -101,20 +104,37 @@ void vTaskObdhServer(void)

break;
default:

sys_log_print_msg("Invalid mode: ");
sys_log_print_uint(obdh_request.data.param_8);

break;
}
sys_log_new_line();
}

sys_log_new_line();

break;
case CMDPR_PARAM_RESET_DEVICE:

if (obdh_request.data.param_8 == 0x01)
{
sys_log_print_event_from_module(SYS_LOG_INFO, TASK_OBDH_SERVER_NAME, "Received command to reset system...");
system_reset();
}
break;

default:
sys_log_print_event_from_module(SYS_LOG_ERROR, TASK_OBDH_SERVER_NAME, "Invalid write parameter.");

break;
}
break;
case CMDPR_CMD_TRANSMIT_PACKET:
obdh_write_read_bytes(7);

downlink_add_packet(obdh_request.data.data_packet.packet, obdh_request.data.data_packet.len);

break;
break;
case CMDPR_CMD_READ_FIRST_PACKET:
obdh_response.command = obdh_request.command;

Expand Down
31 changes: 27 additions & 4 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 <gabriel.mm8@gmail.com>
*
* \version 0.4.5
* \version 0.5.2
*
* \date 2019/12/04
*
Expand Down Expand Up @@ -64,6 +64,11 @@ void vTaskStartup(void)
/* Logger device initialization */
sys_log_init();

/* Print the TTC radio module */
sys_log_print_event_from_module(SYS_LOG_INFO, TASK_STARTUP_NAME, "Booting TTC Module ");
sys_log_print_uint((uint32_t)RADIO_MODULE);
sys_log_new_line();

/* Print the FreeRTOS version */
sys_log_print_event_from_module(SYS_LOG_INFO, TASK_STARTUP_NAME, "FreeRTOS ");
sys_log_print_msg(tskKERNEL_VERSION_NUMBER);
Expand Down Expand Up @@ -163,18 +168,36 @@ void vTaskStartup(void)
}
#endif /* CONFIG_DEV_OBDH_ENABLED */

/* Checking and updating the reset counter parameter */
if (system_reset_count() == 0)
{
sys_log_print_event_from_module(SYS_LOG_INFO, TASK_STARTUP_NAME, "Reset counter: ");
sys_log_print_uint((uint32_t)(ttc_data_buf.reset_counter));
sys_log_new_line();
}
else
{
sys_log_print_event_from_module(SYS_LOG_ERROR, TASK_STARTUP_NAME, "Failed to access last reset counter");
sys_log_new_line();
}


if (error_counter > 0U)
{
sys_log_print_event_from_module(SYS_LOG_ERROR, TASK_STARTUP_NAME, "Boot completed with ");
sys_log_print_uint(error_counter);
sys_log_print_event_from_module(SYS_LOG_ERROR, TASK_STARTUP_NAME, "TTC Radio Module ");
sys_log_print_uint((uint32_t)RADIO_MODULE);
sys_log_print_msg(" booted with ");
sys_log_print_uint((uint32_t)error_counter);
sys_log_print_msg(" ERROR(S)!");
sys_log_new_line();

led_set(LED_FAULT);
}
else
{
sys_log_print_event_from_module(SYS_LOG_INFO, TASK_STARTUP_NAME, "Boot completed with SUCCESS!");
sys_log_print_event_from_module(SYS_LOG_INFO, TASK_STARTUP_NAME, "Successfully booted TTC Radio Module ");
sys_log_print_uint((uint32_t)RADIO_MODULE);
sys_log_print_msg("!");
sys_log_new_line();

led_clear(LED_FAULT);
Expand Down
8 changes: 4 additions & 4 deletions firmware/app/tasks/time_control.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* time_control.h
*
* Copyright (C) 2021, SpaceLab.
* Copyright The TTC 2.0 Contributors.
*
* This file is part of TTC 2.0.
*
Expand All @@ -25,7 +25,7 @@
*
* \author Gabriel Mariano Marcelino <gabriel.mm8@gmail.com>
*
* \version 0.1.10
* \version 0.5.2
*
* \date 2020/08/09
*
Expand Down Expand Up @@ -139,7 +139,7 @@ static int time_control_load_sys_time(sys_time_t *tm)

uint8_t buf[6] = {0};

if (media_read(TIME_CONTROL_MEDIA, CONFIG_MEM_ADR_SYS_TIME, buf, 6U) == 0)
if (media_read(TIME_CONTROL_MEDIA, CONFIG_MEM_ADR_SYS_TIME, FLASH_SEG_A_ADR, buf, 6U) == 0)
{
if ((buf[0] == TIME_CONTROL_MEM_ID) && (time_control_crc8(buf, 5U) == buf[5]))
{
Expand Down Expand Up @@ -180,7 +180,7 @@ static int time_control_save_sys_time(sys_time_t tm)

if (media_erase(TIME_CONTROL_MEDIA, FLASH_SEG_A_ADR) == 0)
{
if (media_write(TIME_CONTROL_MEDIA, CONFIG_MEM_ADR_SYS_TIME, buf, 6U) != 0)
if (media_write(TIME_CONTROL_MEDIA, CONFIG_MEM_ADR_SYS_TIME, FLASH_SEG_A_ADR, buf, 6U) != 0)
{
sys_log_print_event_from_module(SYS_LOG_ERROR, TASK_TIME_CONTROL_NAME, "Error writing the system time to the non-volatile memory!");
sys_log_new_line();
Expand Down
12 changes: 11 additions & 1 deletion firmware/devices/leds/leds.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,32 @@
*
* \author Gabriel Mariano Marcelino <gabriel.mm8@gmail.com>
*
* \version 0.2.11
* \version 0.5.2
*
* \date 2020/01/20
*
* \addtogroup leds
* \{
*/

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

#include "leds.h"

/* GPIO configuration */
/* TTC 2.0 Radio Module 0 has inverted silk screen labels, this is a manual firmware fix. */
#if defined(RADIO_MODULE) && (RADIO_MODULE == 1)
#define LED_SYSTEM_PIN GPIO_PIN_28
#define LED_FAULT_PIN GPIO_PIN_27

#else
#define LED_SYSTEM_PIN GPIO_PIN_27
#define LED_FAULT_PIN GPIO_PIN_28

#endif

#define LED_DOWNLINK_PIN GPIO_PIN_30
#define LED_UPLINK_PIN GPIO_PIN_29

Expand Down
78 changes: 50 additions & 28 deletions firmware/devices/media/media.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*
* \author Gabriel Mariano Marcelino <gabriel.mm8@gmail.com>
*
* \version 0.1.19
* \version 0.5.2
*
* \date 2020/07/21
*
Expand Down Expand Up @@ -60,61 +60,75 @@ int media_init(media_t med)
return err;
}

int media_write(media_t med, uint32_t adr, uint8_t *data, uint16_t len)
int media_write(media_t med, uint32_t adr, uint32_t sector, uint8_t *data, uint16_t len)
{
int err = -1;
uint16_t i = 0U;

switch(med)
{
case MEDIA_INT_FLASH:
{
/* Address index */
uintptr_t adr_idx = adr + FLASH_SEG_A_ADR;

uint16_t i = 0;
for(i=0; i<len; ++i)
if (flash_mutex_take() == 0)
{
uintptr_t adr_counter = adr_idx + i;
/* Address index */
uintptr_t adr_idx = adr + sector;

flash_write_single(data[i], adr_counter);
}
for(i=0; i<len; ++i)
{
uintptr_t adr_counter = adr_idx + i;

err = 0;
flash_write_single(data[i], adr_counter);
}

err = flash_mutex_give();
}
else
{
sys_log_print_event_from_module(SYS_LOG_ERROR, MEDIA_MODULE_NAME, "Couldn't get mutex control.");
sys_log_new_line();
}

break;
}
default:
sys_log_print_event_from_module(SYS_LOG_ERROR, MEDIA_MODULE_NAME, "Invalid storage media to write!");
sys_log_new_line();

break;
}
}

return err;
}

int media_read(media_t med, uint32_t adr, uint8_t *data, uint16_t len)
int media_read(media_t med, uint32_t adr, uint32_t sector, uint8_t *data, uint16_t len)
{
int err = -1;

uint16_t i = 0;

switch(med)
{
case MEDIA_INT_FLASH:
{
/* Address index */
uintptr_t adr_idx = adr + FLASH_SEG_A_ADR;

for(i=0; i<len; ++i)
if (flash_mutex_take() == 0)
{
uintptr_t adr_counter = adr_idx + i;
/* Address index */
uintptr_t adr_idx = adr + sector;

data[i] = flash_read_single(adr_counter);
}
for(i=0; i<len; ++i)
{
uintptr_t adr_counter = adr_idx + i;

err = 0;
data[i] = flash_read_single(adr_counter);
}

err = flash_mutex_give();
}
else
{
sys_log_print_event_from_module(SYS_LOG_ERROR, MEDIA_MODULE_NAME, "Couldn't get mutex control.");
sys_log_new_line();
}
break;
}
default:
Expand All @@ -134,19 +148,27 @@ int media_erase(media_t med, uint32_t sector)
switch(med)
{
case MEDIA_INT_FLASH:
{
if ((sector == FLASH_SEG_A_ADR) || (sector == FLASH_SEG_B_ADR))
if (flash_mutex_take() == 0)
{
flash_erase((uintptr_t)sector);
err = 0;
if ((sector == FLASH_SEG_A_ADR) || (sector == FLASH_SEG_B_ADR))
{
flash_erase((uintptr_t)sector);
err = flash_mutex_give();
}
else
{
sys_log_print_event_from_module(SYS_LOG_ERROR, MEDIA_MODULE_NAME, "Erasing invalid sector!");
sys_log_new_line();
}

}
else
{
sys_log_print_event_from_module(SYS_LOG_ERROR, MEDIA_MODULE_NAME, "Erasing invalid sector!");
sys_log_print_event_from_module(SYS_LOG_ERROR, MEDIA_MODULE_NAME, "Couldn't get mutex control.");
sys_log_new_line();
}

break;
}
default:
sys_log_print_event_from_module(SYS_LOG_ERROR, MEDIA_MODULE_NAME, "Invalid storage media to erase!");
sys_log_new_line();
Expand Down
10 changes: 7 additions & 3 deletions firmware/devices/media/media.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*
* \author Gabriel Mariano Marcelino <gabriel.mm8@gmail.com>
*
* \version 0.1.19
* \version 0.5.2
*
* \date 2020/04/21
*
Expand Down Expand Up @@ -85,13 +85,15 @@ int media_init(media_t med);
*
* \param[in] adr is the address to write data.
*
* \param[in] sector is the sector number to write.
*
* \param[in] data is an array of bytes to write.
*
* \param[in] len is the number of bytes to write.
*
* \return The status/error code.
*/
int media_write(media_t med, uint32_t adr, uint8_t *data, uint16_t len);
int media_write(media_t med, uint32_t adr, uint32_t sector, uint8_t *data, uint16_t len);

/**
* \brief Reads data from a given address of a media device.
Expand All @@ -104,13 +106,15 @@ int media_write(media_t med, uint32_t adr, uint8_t *data, uint16_t len);
*
* \param[in] adr is the address to read.
*
* \param[in] sector is the sector number to read.
*
* \param[in,out] data is a pointer to store the read data.
*
* \param[in] len is the number of bytes to read starting at addr.
*
* \return The status/error code.
*/
int media_read(media_t med, uint32_t adr, uint8_t *data, uint16_t len);
int media_read(media_t med, uint32_t adr, uint32_t sector, uint8_t *data, uint16_t len);

/**
* \brief Erases a memory region from a media device.
Expand Down
Loading

0 comments on commit 8fa7297

Please sign in to comment.