From 51d594242d57a6207ff7d43bef250d3ca171da9f Mon Sep 17 00:00:00 2001 From: AugustoVassoler Date: Mon, 28 Aug 2023 15:53:06 -0300 Subject: [PATCH] Firmware: app: task: payload: Adding Payload X initialization and read tasks #337 --- firmware/app/tasks/read_px.c | 83 ++++++++++++++++++++++++++++++ firmware/app/tasks/read_px.h | 75 +++++++++++++++++++++++++++ firmware/app/tasks/startup.c | 8 +++ firmware/config/config.h | 1 + firmware/devices/payload/payload.h | 3 +- 5 files changed, 169 insertions(+), 1 deletion(-) create mode 100644 firmware/app/tasks/read_px.c create mode 100644 firmware/app/tasks/read_px.h diff --git a/firmware/app/tasks/read_px.c b/firmware/app/tasks/read_px.c new file mode 100644 index 00000000..31e6be93 --- /dev/null +++ b/firmware/app/tasks/read_px.c @@ -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 . + * + */ + +/** + * \brief Read PX task implementation. + * + * \author Augusto Cezar Boldori Vassoler + * + * \version 0.0.1 + * + * \date 2023/08/28 + * + * \addtogroup read_px + * \{ + */ + +#include +#include +#include + +#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. + * + */ + +/** + * \brief Read PX task implementation. + * + * \author Augusto Cezar Boldori Vassoler + * + * \version 0.0.1 + * + * \date 2023/08/28 + * + * \addtogroup read_px + * \{ + */ + +#ifndef READ_PX_H_ +#define READ_PX_H_ + +#include +#include + +#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_ */ diff --git a/firmware/app/tasks/startup.c b/firmware/app/tasks/startup.c index 958bd9b6..191b6baf 100644 --- a/firmware/app/tasks/startup.c +++ b/firmware/app/tasks/startup.c @@ -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 "); diff --git a/firmware/config/config.h b/firmware/config/config.h index ff6c36c5..5cffde13 100644 --- a/firmware/config/config.h +++ b/firmware/config/config.h @@ -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 diff --git a/firmware/devices/payload/payload.h b/firmware/devices/payload/payload.h index 8d403905..47d69dc7 100644 --- a/firmware/devices/payload/payload.h +++ b/firmware/devices/payload/payload.h @@ -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; /**