Skip to content

Commit

Permalink
Adding a routine to reset the non-volatile memory during the boot #122
Browse files Browse the repository at this point in the history
  • Loading branch information
mgm8 committed Jul 4, 2019
1 parent 9e287a4 commit 5d65309
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 79 deletions.
38 changes: 38 additions & 0 deletions firmware/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* config.h
*
* Copyright (C) 2019, Universidade Federal de Santa Catarina.
*
* This file is part of FloripaSat-OBDH.
*
* FloripaSat-OBDH 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.
*
* FloripaSat-OBDH 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 FloripaSat-OBDH. If not, see <http://www.gnu.org/licenses/>.
*
*/

/**
* \brief General configuration definitions.
*
* \author Gabriel Mariano Marcelino <[email protected]>
*
* \date 03/07/2019
*/

#ifndef CONFIG_H_
#define CONFIG_H_

#define OBDH_RESET_MEMORY_ON_BOOT 0

#endif // CONFIG_H_

//! \} End of config group
13 changes: 9 additions & 4 deletions firmware/include/obdh.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* obdh.c
*
* Copyright (C) 2017, Universidade Federal de Santa Catarina
* Copyright (C) 2017-2019, Universidade Federal de Santa Catarina.
*
* This file is part of FloripaSat-OBDH.
*
Expand All @@ -21,13 +21,11 @@
*/

/**
* \file obdh.c
*
* \brief Main functions of the OBDH module
*
* \author Elder Tramontin
*
*/

#include "obdh.h"

void create_tasks( void ) {
Expand Down Expand Up @@ -179,6 +177,13 @@ void hibernate(void) {
stop_timer_b(); /**< stop counting time over the timer B */
}

void reset_memory(void) {
flash_erase(SEGD_ADDR);
flash_erase(SEGC_ADDR);
flash_erase(SEGB_ADDR);
flash_erase(SEGA_ADDR);
}

void vApplicationTickHook( void ) {
/*
* Tick hook functions execute within the context of the tick interrupt so must be kept very short,
Expand Down
26 changes: 13 additions & 13 deletions firmware/include/obdh.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* obdh.h
*
* Copyright (C) 2017, Universidade Federal de Santa Catarina
* Copyright (C) 2017-2019, Universidade Federal de Santa Catarina.
*
* This file is part of FloripaSat-OBDH.
*
Expand All @@ -21,12 +21,9 @@
*/

/**
* \file obdh.h
*
* \brief Main functions of the OBDH module
*
* \author Elder Tramontin
*
*/

#ifndef INCLUDE_OBDH_H_
Expand Down Expand Up @@ -62,28 +59,31 @@
#include "../rf4463/rf4463.h"

/**
* \fn create_tasks
*
* \brief Instantiation of the OS tasks
*
* \return None
*/
void create_tasks( void );
void create_tasks(void);

/**
* \fn setup_hardware
*
* \brief Initialization of peripheral modules: internal WDT, external WDT, Clocks, I2C, SPI, UART, ADC.
*
* \return None
*/
void setup_hardware( void );
void setup_hardware(void);

/**
* \fn hibernate
*
* \brief Put the MCU in a low power state during 45 minutes. Wake-up each seconds and count the elapsed time.
*
* \return None
*/
void hibernate(void);

#endif
/**
* \brief Reset the non-volatile memory.
*
* \return None.
*/
void reset_memory(void);

#endif // INCLUDE_OBDH_H_
15 changes: 9 additions & 6 deletions firmware/main.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* main.c
*
* Copyright (C) 2017, Universidade Federal de Santa Catarina
* Copyright (C) 2017-2019, Universidade Federal de Santa Catarina.
*
* This file is part of FloripaSat-OBDH.
*
Expand All @@ -21,19 +21,24 @@
*/

/**
* \file main.c
*
* \brief Main file
*
* \author Elder Tramontin
*
*/

#include "obdh.h"
#include "config.h"

int main(void) {

setup_hardware(); /**< setup the watchdog timers, I/O pins, communications and other peripherals */

#if OBDH_RESET_MEMORY_ON_BOOT == 1
reset_memory();

return 0;
#endif // OBDH_RESET_MEMORY_ON_BOOT

if(verify_deployment_status() == ANTENNAS_NOT_DEPLOYED){ /**< **** TODO: Verify the byte order in I2C (MSB or LSB first). */
hibernate(); /**< sleep for 45 minutes */
antennas_deployment_routine(); /**< open the antennas */
Expand All @@ -47,5 +52,3 @@ int main(void) {

return 0; /**< will never reach here */
}


56 changes: 0 additions & 56 deletions firmware/src/communications_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -543,62 +543,6 @@ void send_reset_charge_command(telecommand_t telecommand) {
xQueueOverwrite(eps_charge_queue, &eps_command); /**< send reset charge command to eps, via eps task */
}

void answer_rush_enable_telecommand(telecommand_t telecommand) {
NGHam_TX_Packet ngham_packet;
uint8_t ngham_pkt_str[220];
uint16_t ngham_pkt_str_len;
uint8_t answer_msg[50] = RUSH_DISABLED_MSG;
uint8_t cmd;

cmd = telecommand.arguments[0];

if (read_current_energy_level() == ENERGY_L1_MODE)
{
if (cmd == 0)
{
xQueueReset(command_to_payload_rush_queue);
xQueueSendToFront(command_to_payload_rush_queue,&cmd,0);
//answer = RUSH_DISABLED_MSG
}
else if(cmd > 30)
{
cmd = 10;
if(xQueueSendToBack(command_to_payload_rush_queue,&cmd,0) == pdTRUE)
{
//answer = RUSH_EN_OUT_OF_RANGE_MSG;
}
else
{
//answer = RUSH_QUEUE_FULL_MSG;
}
}
else
{
if(xQueueSendToBack(command_to_payload_rush_queue,&cmd,0) == pdTRUE)
{
//answer = RUSH_EN_OK_MSG;
//answer[end + 1] = cmd/10 + 0x30;
//answer[end + 2] = cmd%10 + 0x30;
}
else
{
//answer = RUSH_QUEUE_FULL_MSG;
}
}

}
else
{
//answer = RUSH_OUT_OF_BAT_MSG;
}

ngham_TxPktGen(&ngham_packet, answer_msg, sizeof(answer_msg));
ngham_Encode(&ngham_packet, ngham_pkt_str, &ngham_pkt_str_len);

rf4463_tx_long_packet(ngham_pkt_str + (NGH_SYNC_SIZE + NGH_PREAMBLE_SIZE), ngham_pkt_str_len - (NGH_SYNC_SIZE + NGH_PREAMBLE_SIZE));
rf4463_rx_init();
}

void request_antenna_mutex(void) {
uint8_t ttc_command;
uint8_t ttc_response;
Expand Down

0 comments on commit 5d65309

Please sign in to comment.