Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add code for RF temperature sensor #334

Merged
merged 6 commits into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Sts1CobcSw/Hal/IoNames.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ inline constexpr auto rfGpio0Pin = pc6;
inline constexpr auto rfGpio1Pin = pc8;
inline constexpr auto rfPaEnablePin = pc9;
#if HW_VERSION >= 27
inline constexpr auto rfTmpPin = pc0;
#if HW_VERSION >= 30
inline constexpr auto rfLatchupDisablePin1 = pa0;
inline constexpr auto rfLatchupDisablePin2 = pa1;
Expand Down
5 changes: 4 additions & 1 deletion Sts1CobcSw/Periphery/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ target_link_libraries(
)

if(CMAKE_SYSTEM_NAME STREQUAL Generic)
target_sources(Sts1CobcSw_Periphery PRIVATE Eps.cpp Flash.cpp Fram.cpp Rf.cpp Spis.cpp)
target_sources(
Sts1CobcSw_Periphery PRIVATE Eps.cpp Flash.cpp Fram.cpp Rf.cpp Spis.cpp
TemperatureSensor.cpp
)
else()
target_sources(Sts1CobcSw_Periphery PRIVATE FlashMock.cpp FramMock.cpp SpiMocks.cpp)
endif()
36 changes: 36 additions & 0 deletions Sts1CobcSw/Periphery/TemperatureSensor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//! @file
//! @brief "Driver" for the temperature sensor TMP36xS


#include <Sts1CobcSw/Periphery/TemperatureSensor.hpp>

#include <rodos_no_using_namespace.h>


namespace sts1cobcsw::rftemperaturesensor
{
// RF_TMP is read on pin PC0 on internal ADC1
auto adc = RODOS::HAL_ADC(RODOS::ADC_IDX1);
constexpr auto channel = RODOS::ADC_CH_010;


auto Initialize() -> void
{
adc.init(channel);
const int32_t bitResolution = 12; // 3.3 V / 2^12 bits / (10 mV/°C) = 0.0806 °C/bit
adc.config(RODOS::ADC_PARAMETER_RESOLUTION, bitResolution);
}


auto Read() -> std::uint16_t
{
auto rfTemperature = adc.read(channel);
if(rfTemperature == static_cast<std::uint16_t>(RODOS::ADC_ERR_CONV_FAIL))
{
adc.reset();
Initialize();
rfTemperature = adc.read(channel);
}
return rfTemperature;
}
}
11 changes: 11 additions & 0 deletions Sts1CobcSw/Periphery/TemperatureSensor.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once


#include <cstdint>


namespace sts1cobcsw::rftemperaturesensor
{
auto Initialize() -> void;
auto Read() -> std::uint16_t;
}
7 changes: 7 additions & 0 deletions Tests/HardwareTests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ target_link_libraries(
)
add_watchdog_version_of(SpiSupervisor)

add_program(TemperatureSensor TemperatureSensor.test.cpp)
target_link_libraries(
Sts1CobcSwTests_TemperatureSensor PRIVATE rodos::rodos Sts1CobcSw_Periphery
Sts1CobcSwTests_RfLatchupDisablePin
)
add_watchdog_version_of(TemperatureSensor)

add_program(Gpio Gpio.test.cpp)
target_link_libraries(
Sts1CobcSwTests_Gpio PRIVATE rodos::rodos Sts1CobcSw_Hal Sts1CobcSwTests_RfLatchupDisablePin
Expand Down
44 changes: 44 additions & 0 deletions Tests/HardwareTests/TemperatureSensor.test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include <Tests/HardwareTests/RfLatchupDisablePin.hpp>

#include <Sts1CobcSw/Periphery/TemperatureSensor.hpp>

#include <rodos_no_using_namespace.h>


namespace sts1cobcsw
{
class TermperatureSensorTest : public RODOS::StaticThread<>
{
public:
TermperatureSensorTest() : StaticThread("TermperatureSensorTest")
{
}


private:
void init() override
{
InitializeRfLatchupDisablePins();
rftemperaturesensor::Initialize();
}


void run() override
{
using RODOS::PRINTF;

EnableRfLatchupProtection();

PRINTF("\nRF temperature sensor test\n\n");

auto const conversionFactor = 0.0806; // °C/bit
auto const offset = -50; // °C at 0 V
TIME_LOOP(0, 1000 * RODOS::MILLISECONDS)
{
auto temperature = rftemperaturesensor::Read();
PRINTF("raw value = %5d\n", temperature);
PRINTF("temperature = %5.1f deg C\n", temperature * conversionFactor + offset);
}
}
} termperatureSensorTest;
}
Loading