Skip to content

Commit

Permalink
firmware: app: tasks: op_ctrl: Add override operation mode logic #355
Browse files Browse the repository at this point in the history
  • Loading branch information
c-porto committed Aug 22, 2024
1 parent de02c79 commit f0429fb
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 2 deletions.
58 changes: 56 additions & 2 deletions firmware/app/tasks/op_ctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void vTaskOpCtrl(void)
}

/* Nominal mode notification */
if (in_brazil && edc_active)
if ((sat_data_buf.obdh.data.mode == OBDH_MODE_NORMAL) && edc_active)
{
/* Notifies to Read EDC task that the EDC is active.
* Must happen because the task depends on the notification
Expand All @@ -112,7 +112,7 @@ void notify_op_ctrl(uint32_t notification_flag)
xTaskNotify(xTaskOpCtrlHandle, notification_flag, eSetBits);
}

void satellite_change_mode(uint8_t mode)
void satellite_change_mode(const uint8_t mode)
{
/* This ensures the mode change is done atomically */
taskENTER_CRITICAL();
Expand All @@ -121,6 +121,59 @@ void satellite_change_mode(uint8_t mode)
taskEXIT_CRITICAL();
}

int8_t override_op_mode(const uint8_t mode)
{
int8_t err = 0;

switch (mode)
{
case OBDH_MODE_NORMAL:
{
edc_active = true;
satellite_change_mode(mode);

if (enable_main_edc() != 0)
{
err = -1;
}

break;
}
case OBDH_MODE_HIBERNATION:
{
in_hibernation = true;
satellite_change_mode(mode);

if (disable_ttc_tx() != 0)
{
sys_log_print_event_from_module(SYS_LOG_ERROR, TASK_OP_CTRL_NAME, "Failed to disable TTC TX!!");
sys_log_new_line();
}

break;
}
case OBDH_MODE_STAND_BY:
{
edc_active = false;
satellite_change_mode(mode);

if (disable_curr_payload() != 0)
{
err = -1;
}

break;
}
default:
sys_log_print_event_from_module(SYS_LOG_ERROR, TASK_OP_CTRL_NAME, "Invalid Mode was given!");
sys_log_new_line();
err = -1;
break;
}

return err;
}

static inline void handle_notification(uint32_t notify_value)
{
uint32_t px_active_time_ms = (uint32_t)PAYLOAD_X_EXPERIMENT_PERIOD_MS;
Expand Down Expand Up @@ -315,6 +368,7 @@ static int disable_curr_payload(void)

if (payload_disable(active_payload) == 0)
{
sat_data_buf.state.active_payload = PAYLOAD_NONE;
err = 0;
}

Expand Down
9 changes: 9 additions & 0 deletions firmware/app/tasks/op_ctrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,15 @@ void vTaskOpCtrl(void);
*/
void notify_op_ctrl(uint32_t notification_flag);

/**
* \brief Overrides current operation mode.
*
* \param[in] mode is the operation mode to enter.
*
* \return The status/error code.
*/
int8_t override_op_mode(const uint8_t mode);

#endif

/** \} End of op_ctrl group */

0 comments on commit f0429fb

Please sign in to comment.