Skip to content

Commit

Permalink
Merge pull request #347 from spacelab-ufsc/sl_antenna_driver
Browse files Browse the repository at this point in the history
Adding sl_antenna driver.
  • Loading branch information
c-porto authored May 15, 2024
2 parents 689b11c + 1926b46 commit c180b69
Show file tree
Hide file tree
Showing 5 changed files with 280 additions and 2 deletions.
3 changes: 2 additions & 1 deletion firmware/config/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*
* \author Gabriel Mariano Marcelino <[email protected]>
*
* \version 0.10.14
* \version 0.10.15
*
* \date 2019/10/26
*
Expand Down Expand Up @@ -69,6 +69,7 @@

/* Drivers */
#define CONFIG_DRV_ISIS_ANTENNA_ENABLED 1
#define CONFIG_DRV_SL_ANTENNA_ENABLED 0

/* Debug and log messages */
#define CONFIG_DRIVERS_DEBUG_ENABLED 0
Expand Down
27 changes: 26 additions & 1 deletion firmware/devices/antenna/antenna.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
* \brief Antenna device implementation.
*
* \author Gabriel Mariano Marcelino <[email protected]>
* \author Carlos Augusto Porto Freitas <[email protected]>
*
* \version 0.10.7
* \version 0.10.14
*
* \date 2019/11/01
*
Expand All @@ -39,6 +40,7 @@
#include <system/sys_log/sys_log.h>

#include <drivers/isis_antenna/isis_antenna.h>
#include <drivers/sl_antenna/sl_antenna.h>

#include "antenna.h"

Expand Down Expand Up @@ -108,6 +110,19 @@ int antenna_init(void)
sys_log_print_event_from_module(SYS_LOG_ERROR, ANTENNA_MODULE_NAME, "Error during the initialization!");
sys_log_new_line();
}
#elif defined(CONFIG_DRV_SL_ANTENNA_ENABLED) && (CONFIG_DRV_SL_ANTENNA_ENABLED == 1)
sys_log_print_event_from_module(SYS_LOG_INFO, ANTENNA_MODULE_NAME, "Initializing the antenna...");
sys_log_new_line();

if (sl_antenna_init() == 0)
{
err = 0;
}
else
{
sys_log_print_event_from_module(SYS_LOG_ERROR, ANTENNA_MODULE_NAME, "Error during the initialization!");
sys_log_new_line();
}
#else
antenna_is_open = true;

Expand Down Expand Up @@ -239,7 +254,17 @@ int antenna_deploy(uint32_t timeout_ms)

err++;
}
#elif defined(CONFIG_DRV_SL_ANTENNA_ENABLED) && (CONFIG_DRV_SL_ANTENNA_ENABLED == 1)
sys_log_print_event_from_module(SYS_LOG_INFO, ANTENNA_MODULE_NAME, "Trying a sequential deploy...");
sys_log_new_line();

if (sl_antenna_start_sequential_deploy() != 0)
{
sys_log_print_event_from_module(SYS_LOG_ERROR, ANTENNA_MODULE_NAME, "Error during the sequential deployment!");
sys_log_new_line();

err = -1;
}
#else
sys_log_print_event_from_module(SYS_LOG_ERROR, ANTENNA_MODULE_NAME, "No driver to read the status!");
sys_log_new_line();
Expand Down
95 changes: 95 additions & 0 deletions firmware/drivers/sl_antenna/sl_antenna.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* sl_antenna.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 SpaceLab Antenna Driver implementation.
*
* \author Carlos Augusto Porto Freitas <[email protected]>
*
* \version 0.10.15
*
* \date 2024/03/06
*
* \addtogroup sl_antenna
* \{
*/

#include <drivers/gpio/gpio.h>

#include "sl_antenna.h"

/* Antenna gpio pin */
#define SL_ANTENNA_DEPLOY_PIN GPIO_PIN_61

int sl_antenna_init(void)
{
sl_antenna_config_t ant_config = {0};
int err = -1;

ant_config.mode = GPIO_MODE_OUTPUT;

if (gpio_init(SL_ANTENNA_DEPLOY_PIN, ant_config) == 0)
{
if (gpio_set_state(SL_ANTENNA_DEPLOY_PIN, GPIO_STATE_LOW) == 0)
{
err = 0;
}
}

return err;
}

int sl_antenna_start_sequential_deploy(void)
{
int err = -1;

if (gpio_set_state(SL_ANTENNA_DEPLOY_PIN, SL_ANTENNA_FIRST_STAGE_STATE) == 0)
{
sl_antenna_delay_s(SL_ANTENNA_STAGE_DURATION_SEC);

sl_antenna_delay_s(SL_ANTENNA_HALF_TRANSITION_DURATION_SEC);

if (gpio_set_state(SL_ANTENNA_DEPLOY_PIN, SL_ANTENNA_SECOND_STAGE_STATE) == 0)
{
sl_antenna_delay_s(SL_ANTENNA_HALF_TRANSITION_DURATION_SEC);

sl_antenna_delay_s(SL_ANTENNA_STAGE_DURATION_SEC);

sl_antenna_delay_s(SL_ANTENNA_HALF_TRANSITION_DURATION_SEC);

if (gpio_set_state(SL_ANTENNA_DEPLOY_PIN, SL_ANTENNA_THIRD_STAGE_STATE) == 0)
{
sl_antenna_delay_s(SL_ANTENNA_HALF_TRANSITION_DURATION_SEC);

sl_antenna_delay_s(SL_ANTENNA_STAGE_DURATION_SEC);

err = 0;
}
}
}

(void)gpio_set_state(SL_ANTENNA_DEPLOY_PIN, GPIO_STATE_LOW);

return err;
}

/** \} End of sl_antenna group */
106 changes: 106 additions & 0 deletions firmware/drivers/sl_antenna/sl_antenna.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
* sl_antenna.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 SpaceLab Antenna Driver definition.
*
* \author Carlos Augusto Porto Freitas <[email protected]>
*
* \version 0.10.15
*
* \date 2024/03/06
*
* \defgroup sl_antenna SpaceLab Antenna
* \ingroup drivers
* \{
*/

#ifndef SL_ANTENNA_H_
#define SL_ANTENNA_H_

#include <stdint.h>

#include <drivers/gpio/gpio.h>

/**
* \brief Deployment stage duration time in seconds.
*
* The deployment has three stages in which the gpio state must match
* the expected state required by the antenna during the entire stage
* duration.
*/
#define SL_ANTENNA_STAGE_DURATION_SEC 20U

/**
* \brief Deployment transition duration time in seconds.
*
* Between each stage there is a transition time for switching the
* gpio state to the required one.
*/
#define SL_ANTENNA_TRANSITION_DURATION_SEC 10U
#define SL_ANTENNA_HALF_TRANSITION_DURATION_SEC (SL_ANTENNA_TRANSITION_DURATION_SEC >> 1U)

/* Expected gpio states for each stage */
#define SL_ANTENNA_FIRST_STAGE_STATE GPIO_STATE_HIGH
#define SL_ANTENNA_SECOND_STAGE_STATE GPIO_STATE_LOW
#define SL_ANTENNA_THIRD_STAGE_STATE GPIO_STATE_HIGH

/**
* \brief Antenna config.
*/
typedef gpio_config_t sl_antenna_config_t;

/**
* \brief Driver initialization.
*
* \return The status/error code.
*/
int sl_antenna_init(void);

/**
* \brief Executes sequential deployment.
*
* \return The status/error code.
*/
int sl_antenna_start_sequential_deploy(void);

/**
* \brief Seconds delay.
*
* \param[in] s is the delay in seconds.
*
* \return None.
*/
void sl_antenna_delay_s(uint8_t s);

/**
* \brief Milliseconds delay.
*
* \param[in] ms is the delay in milliseconds.
*
* \return None.
*/
void sl_antenna_delay_ms(uint16_t ms);

#endif /* DRIVERS_SL_ANTENNA_SL_ANTENNA_H_ */

/** \} End of sl_antenna group */
51 changes: 51 additions & 0 deletions firmware/drivers/sl_antenna/sl_antenna_delay.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* sl_antenna_delay.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 SpaceLab Antenna Driver delay implementation.
*
* \author Carlos Augusto Porto Freitas <[email protected]>
*
* \version 0.10.15
*
* \date 2024/03/06
*
* \addtogroup sl_antenna
* \{
*/

#include "FreeRTOS.h"
#include "task.h"

#include "sl_antenna.h"

void sl_antenna_delay_s(uint8_t s)
{
vTaskDelay(pdMS_TO_TICKS(1000U*s));
}

void sl_antenna_delay_ms(uint16_t ms)
{
vTaskDelay(pdMS_TO_TICKS(ms));
}

/** \} End of sl_antenna group */

0 comments on commit c180b69

Please sign in to comment.