diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 97794743091858d83004e57c0f9ef67a1ebdde7c..1ada274691a4637589ee76449b7d4aed76b64196 100755 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -331,6 +331,29 @@ "${workspaceFolder}/skyward-boardcore/libs/miosix-kernel/miosix/default/" ] }, + { + "name": "stm32f767zi_lyra_gs", + "cStandard": "c11", + "cppStandard": "c++14", + "compilerPath": "/opt/arm-miosix-eabi/bin/arm-miosix-eabi-g++", + "defines": [ + "${defaultDefines}", + "_MIOSIX_BOARDNAME=stm32f767zi_lyra_gs", + "_BOARD_STM32F767ZI_LYRA_GS", + "_ARCH_CORTEXM7_STM32F7", + "STM32F767xx", + "HSE_VALUE=25000000", + "SYSCLK_FREQ_216MHz=216000000", + "__ENABLE_XRAM", + "V_DDA_VOLTAGE=3.3f" + ], + "includePath": [ + "${defaultIncludePaths}", + "${workspaceFolder}/libs/miosix-kernel/miosix/arch/cortexM7_stm32f7/common", + "${workspaceFolder}/src/bsps/stm32f767zi_lyra_gs/config", + "${workspaceFolder}/src/bsps/stm32f767zi_lyra_gs" + ] + }, { "name": "stm32f767zi_gemini_gs", "cStandard": "c11", diff --git a/src/entrypoints/Groundstation/lyra-gs-entry.cpp b/src/entrypoints/Groundstation/lyra-gs-entry.cpp index 200e16bcf23745c31f76a31d896e6fd9a3058153..8c07b784bfc1aff2d8feaf3ac3b92198c012dc22 100644 --- a/src/entrypoints/Groundstation/lyra-gs-entry.cpp +++ b/src/entrypoints/Groundstation/lyra-gs-entry.cpp @@ -20,6 +20,15 @@ * THE SOFTWARE. */ +#include <Groundstation/Automated/Actuators/Actuators.h> +#include <Groundstation/Automated/BoardStatus.h> +#include <Groundstation/Automated/Buses.h> +#include <Groundstation/Automated/Hub.h> +#include <Groundstation/Automated/Leds/Leds.h> +#include <Groundstation/Automated/Ports/Ethernet.h> +#include <Groundstation/Automated/Radio/Radio.h> +#include <Groundstation/Automated/SMA/SMA.h> +#include <Groundstation/Automated/Sensors/Sensors.h> #include <Groundstation/Base/BoardStatus.h> #include <Groundstation/Base/Buses.h> #include <Groundstation/Base/Hub.h> @@ -27,10 +36,19 @@ #include <Groundstation/Base/Radio/Radio.h> #include <Groundstation/Common/Ports/Serial.h> #include <Groundstation/DipReader.h> +#include <common/Events.h> +#include <diagnostic/PrintLogger.h> +#include <events/EventBroker.h> #include <miosix.h> +#include <scheduler/TaskScheduler.h> +#include <utils/ButtonHandler/ButtonHandler.h> + +#include <thread> +#include <utils/ModuleManager/ModuleManager.hpp> using namespace Boardcore; using namespace miosix; +using namespace Groundstation; void idleLoop() { @@ -40,21 +58,254 @@ void idleLoop() } } +/** + * @brief Blinking RED led at 5Hz + */ void errorLoop() { while (1) { - led1On(); + led3On(); //< Turn on RED led (CU) Thread::sleep(100); - led1Off(); + led3Off(); Thread::sleep(100); } } +/** + * @brief Lyra GS entrypoint. + * This entrypoint performs the following operations: + * - Reads the dip switch + * + * In case ARP (switch A on) select ARP initialization + * - Initializes software modules + * -> Green LED is turned on when done + * - Waits for the rocket to be powered on and acquire a GPS fix + * -> Yellow LED is turned on when done + * - Waits for the antenna to acquire a GPS fix + * -> Orange LED is turned on when done + * - Initializes the follower + * - Starts the follower task + * + * Otherwise initialize the GroundstationBase + * - Initializes software modules + * -> Green LED is turned on when main radio on + * -> Yellow LED is turned on when backup radio on + * -> Orange LED is turned on when ethernet radio on + * + * - When done the red LED is fixed. Blinks if error in modules init. + */ int main() { ledOff(); // Read dip switch configuration DipStatus dipRead = DipReader::readDip(); + + // TODO: Pass to DependencyManager when rebased + ModuleManager &modules = ModuleManager::getInstance(); + PrintLogger logger = Logging::getLogger("lyra_gs"); + + // ARP entry + if (dipRead.isARP) + { + TaskScheduler *scheduler_low = new TaskScheduler(0); + TaskScheduler *scheduler_high = new TaskScheduler(); + Antennas::Leds *leds = new Antennas::Leds(scheduler_low); + Antennas::Hub *hub = new Antennas::Hub(); + Antennas::Buses *buses = new Antennas::Buses(); + Serial *serial = new Serial(); + Antennas::RadioMain *radio_main = new Antennas::RadioMain(); + Antennas::BoardStatus *board_status = new Antennas::BoardStatus(); + Antennas::Actuators *actuators = new Antennas::Actuators(); + Antennas::Sensors *sensors = new Antennas::Sensors(); + Antennas::SMA *sma = new Antennas::SMA(scheduler_high); + Antennas::Ethernet *ethernet = new Antennas::Ethernet(); + + bool ok = true; + + // Inserting Modules + ok &= modules.insert(sma); + ok &= modules.insert<HubBase>(hub); + ok &= modules.insert(buses); + ok &= modules.insert(serial); + ok &= modules.insert(radio_main); + ok &= modules.insert(board_status); + ok &= modules.insert(actuators); + ok &= modules.insert(sensors); + ok &= modules.insert(ethernet); + ok &= modules.insert(leds); + + // If insertion failed, stop right here + if (!ok) + { + LOG_ERR(logger, "[error] Failed to insert all modules!\n"); + errorLoop(); + } + + // Start the modules + + ok &= scheduler_low->start(); + if (!ok) + { + LOG_ERR(logger, "[error] Failed to start scheduler_low!\n"); + } + + ok &= scheduler_high->start(); + if (!ok) + { + LOG_ERR(logger, "[error] Failed to start scheduler_high!\n"); + } + + ok &= serial->start(); + if (!ok) + { + LOG_ERR(logger, "[error] Failed to start serial!\n"); + } + + ok &= radio_main->start(); + if (!ok) + { + LOG_ERR(logger, "[error] Failed to start radio_main!\n"); + } + + ok &= ethernet->start(); + if (!ok) + { + LOG_ERR(logger, "[error] Failed to start ethernet!\n"); + } + + ok &= board_status->start(); + if (!ok) + { + LOG_ERR(logger, "[error] Failed to start board_status!\n"); + } + + ok &= leds->start(); + if (!ok) + { + LOG_ERR(logger, "[error] Failed to start leds!\n"); + } + + ok &= sensors->start(); + if (!ok) + { + LOG_ERR(logger, "[error] Failed to start sensors!\n"); + } + + ok &= sma->start(); + if (!ok) + { + LOG_ERR(logger, "[error] Failed to start sma!\n"); + } + + // Start ARP by posting INIT event + led3On(); //< RED led (CU) + led1On(); //< GREEN led (CU) + LOG_INFO(logger, "Starting ARP"); + EventBroker::getInstance().post(Common::Events::ARP_INIT_OK, + Common::Topics::TOPIC_ARP); + idleLoop(); + return 0; + } + + // Groundstation entry + else + { + GroundstationBase::Hub *hub = new GroundstationBase::Hub(); + GroundstationBase::Buses *buses = new GroundstationBase::Buses(); + Serial *serial = new Serial(); + GroundstationBase::Ethernet *ethernet = + new GroundstationBase::Ethernet(); + GroundstationBase::RadioMain *radio_main = + new GroundstationBase::RadioMain(); + GroundstationBase::RadioPayload *radio_payload = + new GroundstationBase::RadioPayload(); + GroundstationBase::BoardStatus *board_status = + new GroundstationBase::BoardStatus(); + + bool ok = true; + + // Inserting modules + + ok &= modules.insert<HubBase>(hub); + ok &= modules.insert(buses); + ok &= modules.insert(serial); + ok &= modules.insert(ethernet); + ok &= modules.insert(radio_main); + ok &= modules.insert(radio_payload); + ok &= modules.insert(board_status); + + // If insertion failed, stop right here + if (!ok) + { + LOG_ERR(logger, "[error] Failed to insert all modules!\n"); + errorLoop(); + } + + LOG_DEBUG(logger, "All modules inserted successfully!\n"); + + // Ok now start them + + ok &= serial->start(); + if (!ok) + { + LOG_ERR(logger, "[error] Failed to start serial!\n"); + } + + ok &= ethernet->start(); + if (!ok) + { + LOG_ERR(logger, "[error] Failed to start ethernet!\n"); + } + + ok &= radio_main->start(); + if (!ok) + { + LOG_ERR(logger, "[error] Failed to start main radio!\n"); + } + + ok &= radio_payload->start(); + if (!ok) + { + LOG_ERR(logger, "[error] Failed to start payload radio!\n"); + } + + ok &= board_status->start(); + if (!ok) + { + LOG_ERR(logger, "[error] Failed to start board status!\n"); + } + + LOG_DEBUG(logger, "All modules started successfully!\n"); + + if (board_status->isMainRadioPresent()) + { + LOG_ERR(logger, "Main radio detected!\n"); + led1On(); //< GREEN led on (CU) + } + + if (board_status->isPayloadRadioPresent()) + { + LOG_ERR(logger, "Payload radio detected!\n"); + led2On(); //< YELLOW led on (CU) + } + + if (board_status->isEthernetPresent()) + { + LOG_ERR(logger, "Ethernet detected!\n"); + led4On(); //< ORANGE led on (CU) + } + + LOG_DEBUG(logger, "All boards detected!\n"); + + if (!ok) + { + errorLoop(); + } + + led3On(); //< fix RED led (CU) + idleLoop(); + return 0; + } } \ No newline at end of file