Skip to content
Open
2 changes: 1 addition & 1 deletion PROVESFlightControllerReference/Components/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/NullPrmDb/")
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/PayloadCom/")
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/PowerMonitor/")
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/ResetManager/")
#add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/SBand/")
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/SBand/")
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/StackMonitor/")
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/StartupManager/")
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/ThermalManager/")
Expand Down
15 changes: 15 additions & 0 deletions PROVESFlightControllerReference/Components/SBand/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ register_fprime_library(
SOURCES
"${CMAKE_CURRENT_LIST_DIR}/SBand.cpp"
"${CMAKE_CURRENT_LIST_DIR}/FprimeHal.cpp"
"${CMAKE_CURRENT_LIST_DIR}/SBandFaultPolicy.cpp"
"${CMAKE_CURRENT_LIST_DIR}/RadioLibSBandRadio.cpp"
DEPENDS
RadioLib
)
Expand All @@ -29,7 +31,20 @@ add_subdirectory("${FPRIME_PROJECT_ROOT}/lib/RadioLib" "${CMAKE_BINARY_DIR}/Radi
# Disable compile warnings for RadioLib as they pollute the log and we can't do anything about them.
target_compile_options(RadioLib PRIVATE -w)

# RadioLib defaults to dynamic (heap) allocation; flight code must not
# heap-allocate after boot (S-BAND-REINTEGRATION-PLAN.md root cause #3).
# PUBLIC so it also applies to any TU that includes RadioLib headers
# (SBand.cpp, FprimeHal.cpp, RadioLibSBandRadio.cpp) via the RadioLib
# target dependency above, not just RadioLib's own compilation units.
target_compile_definitions(RadioLib PUBLIC RADIOLIB_STATIC_ONLY=1)

### Unit Tests ###
# F Prime component-level UTs are intentionally not used in this repo: host
# unit tests live under test/unit-tests/ (see test_SBand_FaultPolicy.cpp),
# driving the pure-logic SBandFaultPolicy class directly with no Zephyr/F'
# autocode dependency. The SBand component itself is a thin adapter over
# SBandRadioIf/SBandFaultPolicy, verified by this firmware build and by
# HWIL in PR 3.
# register_fprime_ut(
# AUTOCODER_INPUTS
# "${CMAKE_CURRENT_LIST_DIR}/SBand.fpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ uint32_t FprimeHal::digitalRead(uint32_t pin) {
else
return FPRIME_HAL_GPIO_LEVEL_LOW;
}
if (pin == SBAND_PIN_BUSY) {
Fw::Logic busyState;
Drv::GpioStatus state = this->m_component->getBusyLine_out(0, busyState);
FW_ASSERT(state == Drv::GpioStatus::OP_OK);
if (busyState == Fw::Logic::HIGH)
return FPRIME_HAL_GPIO_LEVEL_HIGH;
else
return FPRIME_HAL_GPIO_LEVEL_LOW;
}
return FPRIME_HAL_GPIO_LEVEL_LOW;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#define SBAND_PIN_CS 0
#define SBAND_PIN_IRQ 5
#define SBAND_PIN_RST 6
#define SBAND_PIN_BUSY 7

namespace Components {
class SBand;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// ======================================================================
// \title RadioLibSBandRadio.cpp
// \brief Production SBandRadioIf implementation backed by RadioLib
// ======================================================================

#define RADIOLIB_LOW_LEVEL 1

#include "PROVESFlightControllerReference/Components/SBand/RadioLibSBandRadio.hpp"

namespace Components {

RadioLibSBandRadio::RadioLibSBandRadio(SBand* component)
: m_hal(component),
m_module(&m_hal, SBAND_PIN_CS, SBAND_PIN_IRQ, SBAND_PIN_RST, SBAND_PIN_BUSY),
m_radio(&m_module) {}

int16_t RadioLibSBandRadio::begin(float freqMHz,
float bandwidthKHz,
uint8_t spreadingFactor,
uint8_t codingRate,
uint8_t syncWord,
int8_t outputPowerDbm,
uint16_t preambleLength) {
return m_radio.begin(freqMHz, bandwidthKHz, spreadingFactor, codingRate, syncWord, outputPowerDbm, preambleLength);
}

int16_t RadioLibSBandRadio::setPacketParamsLoRa(uint8_t preambleLen,
uint8_t hdrType,
uint8_t payLen,
uint8_t crc,
uint8_t invIQ) {
return m_radio.setPacketParamsLoRa(preambleLen, hdrType, payLen, crc, invIQ);
}

int16_t RadioLibSBandRadio::transmit(const uint8_t* data, size_t len) {
return m_radio.transmit(data, len);
}

int16_t RadioLibSBandRadio::readData(uint8_t* data, size_t len) {
return m_radio.readData(data, len);
}

size_t RadioLibSBandRadio::getPacketLength() {
return m_radio.getPacketLength();
}

uint16_t RadioLibSBandRadio::getIrqStatus() {
return m_radio.getIrqStatus();
}

int16_t RadioLibSBandRadio::startReceive() {
return m_radio.startReceive();
}

int16_t RadioLibSBandRadio::standby() {
return m_radio.standby();
}

int16_t RadioLibSBandRadio::setSpreadingFactor(uint8_t sf) {
return m_radio.setSpreadingFactor(sf);
}

int16_t RadioLibSBandRadio::setCodingRate(uint8_t cr) {
return m_radio.setCodingRate(cr);
}

int16_t RadioLibSBandRadio::setBandwidth(float bwKHz) {
return m_radio.setBandwidth(bwKHz);
}

float RadioLibSBandRadio::getRSSI() {
return m_radio.getRSSI();
}

float RadioLibSBandRadio::getSNR() {
return m_radio.getSNR();
}

} // namespace Components
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// ======================================================================
// \title RadioLibSBandRadio.hpp
// \brief Production SBandRadioIf implementation backed by RadioLib
// ======================================================================

#ifndef Components_RadioLibSBandRadio_HPP
#define Components_RadioLibSBandRadio_HPP

#include <RadioLib.h>

#include "PROVESFlightControllerReference/Components/SBand/FprimeHal.hpp"
#include "PROVESFlightControllerReference/Components/SBand/SBandRadioIf.hpp"

namespace Components {

class SBand;

//! Production implementation of SBandRadioIf: owns the RadioLib HAL/Module/
//! SX1280 stack and forwards every call 1:1 (S-BAND-REINTEGRATION-PLAN.md
//! decision D4). The SBand component holds this by value and points its
//! SBandRadioIf* at it in production; tests point the same pointer at a
//! fake instead.
class RadioLibSBandRadio final : public SBandRadioIf {
public:
//! \param component back-pointer used by the owned FprimeHal to reach
//! the component's GPIO/SPI output ports.
explicit RadioLibSBandRadio(SBand* component);

int16_t begin(float freqMHz,
float bandwidthKHz,
uint8_t spreadingFactor,
uint8_t codingRate,
uint8_t syncWord,
int8_t outputPowerDbm,
uint16_t preambleLength) override;

int16_t setPacketParamsLoRa(uint8_t preambleLen,
uint8_t hdrType,
uint8_t payLen,
uint8_t crc,
uint8_t invIQ) override;

int16_t transmit(const uint8_t* data, size_t len) override;
int16_t readData(uint8_t* data, size_t len) override;
size_t getPacketLength() override;
uint16_t getIrqStatus() override;
int16_t startReceive() override;
int16_t standby() override;
int16_t setSpreadingFactor(uint8_t sf) override;
int16_t setCodingRate(uint8_t cr) override;
int16_t setBandwidth(float bwKHz) override;
float getRSSI() override;
float getSNR() override;

private:
FprimeHal m_hal; //!< RadioLib HAL instance
Module m_module; //!< RadioLib Module instance
SX1280 m_radio; //!< RadioLib SX1280 radio instance
};

} // namespace Components

#endif
Loading
Loading