Skip to content
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
11 changes: 11 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@
"preLaunchTask": "build unit tests",
"stopAtEntry": false,
"externalConsole": false
},
{
"name": "Debug RP2350 via OpenOCD :3333",
"type": "cortex-debug",
"request": "launch",
"cwd": "${workspaceFolder}",
"servertype": "external",
"gdbTarget": "localhost:3333",
"executable": "${workspaceFolder}/build-artifacts/zephyr.elf",
"device": "RP2350",
"runToEntryPoint": "main"
}
]
}
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ endif()

project(fprime-zephyr-reference C CXX)

# Enable Zephyr Pico hardware_adc library
zephyr_include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/lib/zephyr-workspace/modules/hal/rpi_pico/src/rp2_common/hardware_adc/include
)
Comment thread
nateinaction marked this conversation as resolved.

# Disable F´ framework/autocoder/app unit tests; we use our own GoogleTests in tests/
set(FPRIME_ENABLE_FRAMEWORK_UTS OFF CACHE BOOL "" FORCE)
set(FPRIME_ENABLE_AUTOCODER_UTS OFF CACHE BOOL "" FORCE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/RtcManager")
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Tmp112Manager/")
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Types/")
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Veml6031Manager/")
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/PicoTempManager/")
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
####
# F Prime CMakeLists.txt:
#
# SOURCES: list of source files (to be compiled)
# AUTOCODER_INPUTS: list of files to be passed to the autocoders
# DEPENDS: list of libraries that this module depends on
#
# More information in the F´ CMake API documentation:
# https://fprime.jpl.nasa.gov/latest/docs/reference/api/cmake/API/
#
####

# Module names are derived from the path from the nearest project/library/framework
# root when not specifically overridden by the developer, i.e. the module defined by
# `MyProj/Some/Path/CMakeLists.txt` will be named `MyProj_Some_Path`.

register_fprime_library(
AUTOCODER_INPUTS
"${CMAKE_CURRENT_LIST_DIR}/PicoTempManager.fpp"
SOURCES
"${CMAKE_CURRENT_LIST_DIR}/PicoTempManager.cpp"
# DEPENDS
# MyPackage_MyOtherModule
)

### Unit Tests ###
# register_fprime_ut(
# AUTOCODER_INPUTS
# "${CMAKE_CURRENT_LIST_DIR}/PicoTempManager.fpp"
# SOURCES
# "${CMAKE_CURRENT_LIST_DIR}/test/ut/PicoTempManagerTestMain.cpp"
# "${CMAKE_CURRENT_LIST_DIR}/test/ut/PicoTempManagerTester.cpp"
# DEPENDS
# STest # For rules-based testing
# UT_AUTO_HELPERS
# )
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// ======================================================================
// \title PicoTempManager.cpp
// \brief cpp file for PicoTempManager component implementation class
// ======================================================================

#include "PROVESFlightControllerReference/Components/Drv/PicoTempManager/PicoTempManager.hpp"

namespace Drv {

// ----------------------------------------------------------------------
// Component construction and destruction
// ----------------------------------------------------------------------

PicoTempManager ::PicoTempManager(const char* const compName) : PicoTempManagerComponentBase(compName) {}

PicoTempManager ::~PicoTempManager() {}

// ----------------------------------------------------------------------
// Public helper methods
// ----------------------------------------------------------------------
void PicoTempManager::configure(const struct device* dev) {
this->m_dev = dev;
}

// ----------------------------------------------------------------------
// Handler implementations for typed input ports
// ----------------------------------------------------------------------

F64 PicoTempManager ::picoTemperatureGet_handler(FwIndexType portNum, Fw::Success& condition) {
condition = Fw::Success::FAILURE;
F64 temperature = this->getPicoTemperature(condition);
if (condition != Fw::Success::SUCCESS) {
return 0;
}
this->tlmWrite_PicoTemperature(temperature);
return temperature;
}

// ----------------------------------------------------------------------
// Handler implementations for commands
// ----------------------------------------------------------------------

void PicoTempManager ::GetPicoTemperature_cmdHandler(FwOpcodeType opCode, U32 cmdSeq) {
Fw::Success condition = Fw::Success::FAILURE;
F64 temperature = this->getPicoTemperature(condition);
if (condition != Fw::Success::SUCCESS) {
this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::EXECUTION_ERROR);
return;
}
Comment thread
nateinaction marked this conversation as resolved.
this->log_ACTIVITY_HI_PicoTemperature(temperature);
this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK);
}

// ----------------------------------------------------------------------
// Private helper methods
// ----------------------------------------------------------------------

F64 PicoTempManager ::getPicoTemperature(Fw::Success& condition) {
if (!device_is_ready(this->m_dev)) {
this->log_WARNING_LO_DeviceNotReady();
return 0;
}
this->log_WARNING_LO_DeviceNotReady_ThrottleClear();
Comment thread
nateinaction marked this conversation as resolved.

int rc = sensor_sample_fetch(this->m_dev);
if (rc != 0) {
this->log_WARNING_LO_SensorSampleFetchFailed(rc);
return 0;
}
this->log_WARNING_LO_SensorSampleFetchFailed_ThrottleClear();

struct sensor_value temp_val;
rc = sensor_channel_get(this->m_dev, SENSOR_CHAN_DIE_TEMP, &temp_val);
if (rc != 0) {
this->log_WARNING_LO_SensorChannelGetFailed(rc);
return 0.0;
}
this->log_WARNING_LO_SensorChannelGetFailed_ThrottleClear();
F64 temp = sensor_value_to_double(&temp_val);
condition = Fw::Success::SUCCESS;
return temp;
}

} // namespace Drv
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
module Drv {
port picoTemperatureGet(ref condition: Fw.Success) -> F64
}

module Drv {
@ Manager for the RP2350's built in temperature sensor
passive component PicoTempManager {

#### Ports ####
@ Port to read the die temperature in degrees Celsius
sync input port picoTemperatureGet: picoTemperatureGet

#### Commands ####
@ Command to get the temperature in degrees Celsius
sync command GetPicoTemperature()

#### Telemetry ####
@ Telemetry channel for temperature in degrees Celsius
telemetry PicoTemperature: F64

@ Event for reporting not ready error
event DeviceNotReady() severity warning low format "Device not ready" throttle 5

@ Event for reporting sensor fetch failure
event SensorSampleFetchFailed(ret: I32) severity warning low format "Sensor fetch failed with return code: {}" throttle 5

@ Event for reporting sensor channel get failure
event SensorChannelGetFailed(ret: I32) severity warning low format "Sensor channel get failed with return code: {}" throttle 5

@ Event for reporting temperature
event PicoTemperature(temperature: F64) severity activity high format "Pico Temperature: {}°C"

###############################################################################
# Standard AC Ports: Required for Channels, Events, Commands, and Parameters #
###############################################################################
@ Port for requesting the current time
time get port timeCaller

@ Port for sending command registrations
command reg port cmdRegOut

@ Port for receiving commands
command recv port cmdIn

@ Port for sending command responses
command resp port cmdResponseOut

@ Port for sending textual representation of events
text event port logTextOut

@ Port for sending events to downlink
event port logOut

@ Port for sending telemetry channels to downlink
telemetry port tlmOut


}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// ======================================================================
// \title PicoTempManager.hpp
// \brief hpp file for PicoTempManager component implementation class
// ======================================================================

#ifndef Drv_PicoTempManager_HPP
#define Drv_PicoTempManager_HPP

#include "Fw/Types/SuccessEnumAc.hpp"
#include "PROVESFlightControllerReference/Components/Drv/PicoTempManager/PicoTempManagerComponentAc.hpp"
#include <zephyr/device.h>
#include <zephyr/drivers/sensor.h>
#include <zephyr/kernel.h>

namespace Drv {

class PicoTempManager final : public PicoTempManagerComponentBase {
public:
// ----------------------------------------------------------------------
// Component construction and destruction
// ----------------------------------------------------------------------

//! Construct PicoTempManager object
PicoTempManager(const char* const compName //!< The component name
);

//! Destroy PicoTempManager object
~PicoTempManager();

public:
// ----------------------------------------------------------------------
// Public helper methods
// ----------------------------------------------------------------------

//! Configure the die_temp device
void configure(const struct device* dev);

private:
// ----------------------------------------------------------------------
// Handler implementations for typed input ports
// ----------------------------------------------------------------------

//! Port handler for getting the die temperature in degrees Celsius
F64 picoTemperatureGet_handler(FwIndexType portNum, //!< The port number
Fw::Success& condition //!< The call order
) override;

private:
// ----------------------------------------------------------------------
// Handler implementations for commands
// ----------------------------------------------------------------------

//! Handler implementation for command GetTemperature
//!
//! Command to get the temperature in degrees Celsius
void GetPicoTemperature_cmdHandler(FwOpcodeType opCode, //!< The opcode
U32 cmdSeq //!< The command sequence number
) override;

private:
// ----------------------------------------------------------------------
// Private helper methods
// ----------------------------------------------------------------------

//! Get the temperature in degrees Celsius from the die_temp device
F64 getPicoTemperature(Fw::Success& condition);

private:
// ----------------------------------------------------------------------
// Private member variables
// ----------------------------------------------------------------------

//! Zephyr device stores the initialized die_temp sensor
const struct device* m_dev;
};

} // namespace Drv

#endif
Loading
Loading