diff --git a/Sts1CobcSw/Hal/IoNames.hpp b/Sts1CobcSw/Hal/IoNames.hpp index 62829f5c..9e9e3800 100644 --- a/Sts1CobcSw/Hal/IoNames.hpp +++ b/Sts1CobcSw/Hal/IoNames.hpp @@ -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; diff --git a/Sts1CobcSw/Periphery/CMakeLists.txt b/Sts1CobcSw/Periphery/CMakeLists.txt index 310b17f8..7b4a7ce2 100644 --- a/Sts1CobcSw/Periphery/CMakeLists.txt +++ b/Sts1CobcSw/Periphery/CMakeLists.txt @@ -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() diff --git a/Sts1CobcSw/Periphery/TemperatureSensor.cpp b/Sts1CobcSw/Periphery/TemperatureSensor.cpp new file mode 100644 index 00000000..f13438d3 --- /dev/null +++ b/Sts1CobcSw/Periphery/TemperatureSensor.cpp @@ -0,0 +1,36 @@ +//! @file +//! @brief "Driver" for the temperature sensor TMP36xS + + +#include + +#include + + +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(RODOS::ADC_ERR_CONV_FAIL)) + { + adc.reset(); + Initialize(); + rfTemperature = adc.read(channel); + } + return rfTemperature; +} +} diff --git a/Sts1CobcSw/Periphery/TemperatureSensor.hpp b/Sts1CobcSw/Periphery/TemperatureSensor.hpp new file mode 100644 index 00000000..4a893c4a --- /dev/null +++ b/Sts1CobcSw/Periphery/TemperatureSensor.hpp @@ -0,0 +1,11 @@ +#pragma once + + +#include + + +namespace sts1cobcsw::rftemperaturesensor +{ +auto Initialize() -> void; +auto Read() -> std::uint16_t; +} diff --git a/Tests/HardwareTests/CMakeLists.txt b/Tests/HardwareTests/CMakeLists.txt index 38229786..758d6aa2 100644 --- a/Tests/HardwareTests/CMakeLists.txt +++ b/Tests/HardwareTests/CMakeLists.txt @@ -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 diff --git a/Tests/HardwareTests/TemperatureSensor.test.cpp b/Tests/HardwareTests/TemperatureSensor.test.cpp new file mode 100644 index 00000000..6ed961c5 --- /dev/null +++ b/Tests/HardwareTests/TemperatureSensor.test.cpp @@ -0,0 +1,44 @@ +#include + +#include + +#include + + +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; +}