Skip to content

Commit

Permalink
Firmware: app: task: payload: Adding Payload X initialization and rea…
Browse files Browse the repository at this point in the history
…d tasks #337
  • Loading branch information
AugustoVassoler committed Aug 28, 2023
1 parent bf96476 commit 51d5942
Show file tree
Hide file tree
Showing 5 changed files with 169 additions and 1 deletion.
83 changes: 83 additions & 0 deletions firmware/app/tasks/read_px.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* read_px.c
*
* Copyright The OBDH 2.0 Contributors.
*
* This file is part of OBDH 2.0.
*
* OBDH 2.0 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.
*
* OBDH 2.0 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 OBDH 2.0. If not, see <http:/\/www.gnu.org/licenses/>.
*
*/

/**
* \brief Read PX task implementation.
*
* \author Augusto Cezar Boldori Vassoler <[email protected]>
*
* \version 0.0.1
*
* \date 2023/08/28
*
* \addtogroup read_px
* \{
*/

#include <system/sys_log/sys_log.h>
#include <devices/payload/payload.h>
#include <drivers/px/px.h>

#include "read_px.h"
#include "startup.h"

xTaskHandle xTaskReadPXHandle;

pl_px_buf_t px_buf = {0};

void vTaskReadPX(void)
{
static payload_t pl_px_active = PAYLOAD_X;
px_buf.lenth = PX_PONG_BUF_SIZE;

/* Wait startup task to finish */
xEventGroupWaitBits(task_startup_status, TASK_STARTUP_DONE, pdFALSE, pdTRUE, pdMS_TO_TICKS(TASK_READ_PX_INIT_TIMEOUT_MS));

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

/* Read data */
if (payload_get_data(pl_px_active, PAYLOAD_X_PONG, px_buf.buffer, &px_buf.length) != 0)
{
sys_log_print_event_from_module(SYS_LOG_ERROR, TASK_READ_PX_NAME, "Error reading the ping-pong data!");
sys_log_new_line();
}
else
{
sys_log_print_event_from_module(SYS_LOG_INFO, TASK_READ_PX_NAME, "Received Payload X packet:");
sys_log_new_line();

uint8_t i = 0;
for(i=0;i<px_buf.length;i++){
sys_log_print_uint(px_buf.buffer[i]);
}

}

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

/** \} End of read_px group */


75 changes: 75 additions & 0 deletions firmware/app/tasks/read_px.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* read_px.h
*
* Copyright The OBDH 2.0 Contributors.
*
* This file is part of OBDH 2.0.
*
* OBDH 2.0 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.
*
* OBDH 2.0 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 OBDH 2.0. If not, see <http:/\/www.gnu.org/licenses/>.
*
*/

/**
* \brief Read PX task implementation.
*
* \author Augusto Cezar Boldori Vassoler <[email protected]>
*
* \version 0.0.1
*
* \date 2023/08/28
*
* \addtogroup read_px
* \{
*/

#ifndef READ_PX_H_
#define READ_PX_H_

#include <FreeRTOS.h>
#include <task.h>

#define TASK_READ_PX_NAME "PX Task" /**< Task name. */
#define TASK_READ_PX_STACK_SIZE 300 /**< Stack size in bytes. */
#define TASK_READ_PX_PRIORITY 3 /**< Task priority. */
#define TASK_READ_PX_PERIOD_MS (60000) /**< Task period in milliseconds. */
#define TASK_READ_PX_INIT_TIMEOUT_MS 2000 /**< Wait time to initialize the task in milliseconds. */

#define PX_PONG_BUF_SIZE 4; /**< Size of pong response message. */
/**
* \brief PX data type.
*/
typedef struct
{
uint8_t buffer[30];
uint32_t length;
} pl_px_buf_t;

/**
* \brief PX read data buffer.
*/
extern pl_px_buf_t px_buf;

/**
* \brief Read PX handle.
*/
extern xTaskHandle xTaskReadPXHandle;

/**
* \brief Read PX task.
*
* \return None.
*/
void vTaskReadPX(void);

#endif /* READ_PX_H_ */
8 changes: 8 additions & 0 deletions firmware/app/tasks/startup.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,14 @@ void vTaskStartup(void)
}
#endif /* CONFIG_DEV_ANTENNA_ENABLED */

#if defined(CONFIG_DEV_PAYLOAD_X_ENABLED) && (CONFIG_DEV_PAYLOAD_X_ENABLED == 1)
/* Payload X device initialization */
if (payload_init(PAYLOAD_X) != 0)
{
error_counter++;
}
#endif /* CONFIG_DEV_PAYLOAD_X_ENABLED */

if (error_counter > 0U)
{
sys_log_print_event_from_module(SYS_LOG_ERROR, TASK_STARTUP_NAME, "Boot completed with ");
Expand Down
1 change: 1 addition & 0 deletions firmware/config/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
#define CONFIG_DEV_EPS_ENABLED 1
#define CONFIG_DEV_PAYLOAD_EDC_ENABLED 1
#define CONFIG_DEV_ANTENNA_ENABLED 1
#define CONFIG_DEV_PAYLOAD_X_ENABLED 1

/* Drivers */
#define CONFIG_DRV_ISIS_ANTENNA_ENABLED 1
Expand Down
3 changes: 2 additions & 1 deletion firmware/devices/payload/payload.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ typedef enum
PAYLOAD_EDC_RAW_PTT, /**< EDC raw PTT packet. */
PAYLOAD_EDC_PTT, /**< EDC PTT packet. */
PAYLOAD_EDC_RAW_HK, /**< EDC raw housekeeping. */
PAYLOAD_EDC_HK /**< EDC housekeeping. */
PAYLOAD_EDC_HK, /**< EDC housekeeping. */
PAYLOAD_X_PONG /**< PX ping pong. */
} payload_data_id_t;

/**
Expand Down

0 comments on commit 51d5942

Please sign in to comment.