diff --git a/.codespell-ignore-words.txt b/.codespell-ignore-words.txt index f5f10d4..c72c89e 100644 --- a/.codespell-ignore-words.txt +++ b/.codespell-ignore-words.txt @@ -1 +1,2 @@ comIn +Ines diff --git a/CMakeLists.txt b/CMakeLists.txt index 488e62f..b6a82d4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,7 @@ #### cmake_minimum_required(VERSION 3.24.2) +add_compile_definitions(_POSIX_C_SOURCE=200809L) # Set BOARD_ROOT to find custom boards # The structure is BOARD_ROOT/boards/vendor/board @@ -33,6 +34,11 @@ fprime_setup_included_code() # This includes project-wide objects add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/FprimeZephyrReference") - +if (FPRIME_USE_POSIX) + set_target_properties(Drv_Ip PROPERTIES EXCLUDE_FROM_ALL TRUE) + set_target_properties(Drv_TcpServer PROPERTIES EXCLUDE_FROM_ALL TRUE) + set_target_properties(Drv_TcpClient PROPERTIES EXCLUDE_FROM_ALL TRUE) + set_target_properties(Drv_Udp PROPERTIES EXCLUDE_FROM_ALL TRUE) +endif() set_target_properties(Svc_FatalHandler PROPERTIES EXCLUDE_FROM_ALL TRUE) set_target_properties(fprime-zephyr_Drv_ZephyrSpiDriver PROPERTIES EXCLUDE_FROM_ALL TRUE) diff --git a/FprimeZephyrReference/Components/CMakeLists.txt b/FprimeZephyrReference/Components/CMakeLists.txt index 5245d97..26405d0 100644 --- a/FprimeZephyrReference/Components/CMakeLists.txt +++ b/FprimeZephyrReference/Components/CMakeLists.txt @@ -9,3 +9,4 @@ add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Watchdog") add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Burnwire/") add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/BootloaderTrigger/") add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/AntennaDeployer/") +add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/FsSpace/") diff --git a/FprimeZephyrReference/Components/FsSpace/CMakeLists.txt b/FprimeZephyrReference/Components/FsSpace/CMakeLists.txt new file mode 100644 index 0000000..dabc113 --- /dev/null +++ b/FprimeZephyrReference/Components/FsSpace/CMakeLists.txt @@ -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 +# `Ref/SignalGen/CMakeLists.txt` will be named `Ref_SignalGen`. + +register_fprime_library( + AUTOCODER_INPUTS + "${CMAKE_CURRENT_LIST_DIR}/FsSpace.fpp" + SOURCES + "${CMAKE_CURRENT_LIST_DIR}/FsSpace.cpp" +# DEPENDS +# MyPackage_MyOtherModule +) + +### Unit Tests ### +# register_fprime_ut( +# AUTOCODER_INPUTS +# "${CMAKE_CURRENT_LIST_DIR}/FsSpace.fpp" +# SOURCES +# "${CMAKE_CURRENT_LIST_DIR}/test/ut/FsSpaceTestMain.cpp" +# "${CMAKE_CURRENT_LIST_DIR}/test/ut/FsSpaceTester.cpp" +# DEPENDS +# STest # For rules-based testing +# UT_AUTO_HELPERS +# ) diff --git a/FprimeZephyrReference/Components/FsSpace/FsSpace.cpp b/FprimeZephyrReference/Components/FsSpace/FsSpace.cpp new file mode 100644 index 0000000..4c5e44f --- /dev/null +++ b/FprimeZephyrReference/Components/FsSpace/FsSpace.cpp @@ -0,0 +1,36 @@ +// ====================================================================== +// \title FsSpace.cpp +// \author starchmd +// \brief cpp file for FsSpace component implementation class +// ====================================================================== + +#include "FprimeZephyrReference/Components/FsSpace/FsSpace.hpp" +#include +#include +#include "Os/FileSystem.hpp" + +namespace Components { + +// ---------------------------------------------------------------------- +// Component construction and destruction +// ---------------------------------------------------------------------- + +FsSpace ::FsSpace(const char* const compName) : FsSpaceComponentBase(compName) {} + +FsSpace ::~FsSpace() {} + +// ---------------------------------------------------------------------- +// Handler implementations for typed input ports +// ---------------------------------------------------------------------- + +void FsSpace ::run_handler(FwIndexType portNum, U32 context) { + FwSizeType freeBytes = 0; + FwSizeType totalBytes = 0; + Os::FileSystem::Status status = Os::FileSystem::getFreeSpace("/prmDb.dat", totalBytes, freeBytes); + if (status == Os::FileSystem::OP_OK) { + this->tlmWrite_FreeSpace(freeBytes); + this->tlmWrite_TotalSpace(totalBytes); + } +} + +} // namespace Components diff --git a/FprimeZephyrReference/Components/FsSpace/FsSpace.fpp b/FprimeZephyrReference/Components/FsSpace/FsSpace.fpp new file mode 100644 index 0000000..5ffa4a9 --- /dev/null +++ b/FprimeZephyrReference/Components/FsSpace/FsSpace.fpp @@ -0,0 +1,27 @@ +module Components { + @ Read free space + passive component FsSpace { + + ############################################################################## + #### Uncomment the following examples to start customizing your component #### + ############################################################################## + + @ Free disk space telemetry channel + telemetry FreeSpace: FwSizeType + + @ Total disk space telemetry channel + telemetry TotalSpace: FwSizeType + + sync input port run: Svc.Sched + + ############################################################################### + # Standard AC Ports: Required for Channels, Events, Commands, and Parameters # + ############################################################################### + @ Port for requesting the current time + time get port timeCaller + + @ Port for sending telemetry channels to downlink + telemetry port tlmOut + + } +} diff --git a/FprimeZephyrReference/Components/FsSpace/FsSpace.hpp b/FprimeZephyrReference/Components/FsSpace/FsSpace.hpp new file mode 100644 index 0000000..d242dc3 --- /dev/null +++ b/FprimeZephyrReference/Components/FsSpace/FsSpace.hpp @@ -0,0 +1,40 @@ +// ====================================================================== +// \title FsSpace.hpp +// \author starchmd +// \brief hpp file for FsSpace component implementation class +// ====================================================================== + +#ifndef Components_FsSpace_HPP +#define Components_FsSpace_HPP + +#include "FprimeZephyrReference/Components/FsSpace/FsSpaceComponentAc.hpp" + +namespace Components { + +class FsSpace final : public FsSpaceComponentBase { + public: + // ---------------------------------------------------------------------- + // Component construction and destruction + // ---------------------------------------------------------------------- + + //! Construct FsSpace object + FsSpace(const char* const compName //!< The component name + ); + + //! Destroy FsSpace object + ~FsSpace(); + + private: + // ---------------------------------------------------------------------- + // Handler implementations for typed input ports + // ---------------------------------------------------------------------- + + //! Handler implementation for run + void run_handler(FwIndexType portNum, //!< The port number + U32 context //!< The call order + ) override; +}; + +} // namespace Components + +#endif diff --git a/FprimeZephyrReference/Components/FsSpace/docs/sdd.md b/FprimeZephyrReference/Components/FsSpace/docs/sdd.md new file mode 100644 index 0000000..46f4172 --- /dev/null +++ b/FprimeZephyrReference/Components/FsSpace/docs/sdd.md @@ -0,0 +1,15 @@ +# Components::FsSpace + +Read free space from the filesystem (specifically the filesystem containing /prmDb.dat)/ + +## Telemetry +| Name | Description | +|---|---| +| FreeSpace | Free space in bytes | +| TotalSpace | Total space in bytes | + + +## Change Log +| Date | Description | +|---|---| +|---| Initial Draft | diff --git a/FprimeZephyrReference/ReferenceDeployment/CMakeLists.txt b/FprimeZephyrReference/ReferenceDeployment/CMakeLists.txt index 2643839..19c7aa7 100644 --- a/FprimeZephyrReference/ReferenceDeployment/CMakeLists.txt +++ b/FprimeZephyrReference/ReferenceDeployment/CMakeLists.txt @@ -20,5 +20,8 @@ if (FPRIME_PLATFORM STREQUAL "Zephyr") "${CMAKE_CURRENT_LIST_DIR}/Main.cpp" DEPENDS ${FPRIME_CURRENT_MODULE}_Top + CHOOSES_IMPLEMENTATIONS + # Can remain stubs for now + Os_File_Posix ) endif() diff --git a/FprimeZephyrReference/ReferenceDeployment/Main.cpp b/FprimeZephyrReference/ReferenceDeployment/Main.cpp index 1747956..705a7f2 100644 --- a/FprimeZephyrReference/ReferenceDeployment/Main.cpp +++ b/FprimeZephyrReference/ReferenceDeployment/Main.cpp @@ -19,7 +19,6 @@ int main(int argc, char* argv[]) { // This sleep is necessary to allow the USB CDC ACM interface to initialize before // the application starts writing to it. k_sleep(K_MSEC(3000)); - Os::init(); // Object for communicating state to the topology ReferenceDeployment::TopologyState inputs; diff --git a/FprimeZephyrReference/ReferenceDeployment/Top/ReferenceDeploymentPackets.fppi b/FprimeZephyrReference/ReferenceDeployment/Top/ReferenceDeploymentPackets.fppi index c836a04..43f0bbf 100644 --- a/FprimeZephyrReference/ReferenceDeployment/Top/ReferenceDeploymentPackets.fppi +++ b/FprimeZephyrReference/ReferenceDeployment/Top/ReferenceDeploymentPackets.fppi @@ -36,6 +36,8 @@ telemetry packets ReferenceDeploymentPackets { CdhCore.version.FrameworkVersion CdhCore.version.ProjectVersion CdhCore.version.LibraryVersion01 + fsSpace.FreeSpace + fsSpace.TotalSpace } packet Led id 5 group 4 { diff --git a/FprimeZephyrReference/ReferenceDeployment/Top/ReferenceDeploymentTopology.cpp b/FprimeZephyrReference/ReferenceDeployment/Top/ReferenceDeploymentTopology.cpp index 2130696..ccef907 100644 --- a/FprimeZephyrReference/ReferenceDeployment/Top/ReferenceDeploymentTopology.cpp +++ b/FprimeZephyrReference/ReferenceDeployment/Top/ReferenceDeploymentTopology.cpp @@ -50,6 +50,7 @@ U32 rateGroup1HzContext[Svc::ActiveRateGroup::CONNECTION_COUNT_MAX] = {getRateGr * desired, but is extracted here for clarity. */ void configureTopology() { + prmDb.configure("/prmDb.dat"); // Rate group driver needs a divisor list rateGroupDriver.configure(rateGroupDivisorsSet); // Rate groups require context arrays. @@ -77,6 +78,7 @@ void setupTopology(const TopologyState& state) { // Project-specific component configuration. Function provided above. May be inlined, if desired. configureTopology(); // Autocoded parameter loading. Function provided by autocoder. + prmDb.readParamFile(); loadParameters(); // Autocoded task kick-off (active components). Function provided by autocoder. startTasks(state); diff --git a/FprimeZephyrReference/ReferenceDeployment/Top/instances.fpp b/FprimeZephyrReference/ReferenceDeployment/Top/instances.fpp index e18b143..26eebbf 100644 --- a/FprimeZephyrReference/ReferenceDeployment/Top/instances.fpp +++ b/FprimeZephyrReference/ReferenceDeployment/Top/instances.fpp @@ -37,6 +37,11 @@ module ReferenceDeployment { stack size Default.STACK_SIZE \ priority 4 + instance prmDb: Svc.PrmDb base id 0x10003000 \ + queue size Default.QUEUE_SIZE \ + stack size Default.STACK_SIZE \ + priority 5 + # ---------------------------------------------------------------------- # Queued component instances # ---------------------------------------------------------------------- @@ -73,8 +78,6 @@ module ReferenceDeployment { instance gpioBurnwire1: Zephyr.ZephyrGpioDriver base id 0x10023000 - instance prmDb: Components.NullPrmDb base id 0x10024000 - instance comDelay: Components.ComDelay base id 0x10025000 instance lora: Zephyr.LoRa base id 0x10026000 @@ -84,4 +87,6 @@ module ReferenceDeployment { instance comSplitterTelemetry: Svc.ComSplitter base id 0x10028000 instance antennaDeployer: Components.AntennaDeployer base id 0x10029000 + + instance fsSpace: Components.FsSpace base id 0x10030000 } diff --git a/FprimeZephyrReference/ReferenceDeployment/Top/topology.fpp b/FprimeZephyrReference/ReferenceDeployment/Top/topology.fpp index 6a9d248..ec3bcfb 100644 --- a/FprimeZephyrReference/ReferenceDeployment/Top/topology.fpp +++ b/FprimeZephyrReference/ReferenceDeployment/Top/topology.fpp @@ -43,6 +43,8 @@ module ReferenceDeployment { instance comSplitterTelemetry # For UART sideband communication instance comDriver + instance fsSpace + # ---------------------------------------------------------------------- # Pattern graph specifiers @@ -134,6 +136,7 @@ module ReferenceDeployment { rateGroup1Hz.RateGroupMemberOut[6] -> comDelay.run rateGroup1Hz.RateGroupMemberOut[7] -> burnwire.schedIn rateGroup1Hz.RateGroupMemberOut[8] -> antennaDeployer.schedIn + rateGroup1Hz.RateGroupMemberOut[9] -> fsSpace.run } diff --git a/boards/bronco_space/proves_flight_control_board_v5/proves_flight_control_board_v5-pinctrl.dtsi b/boards/bronco_space/proves_flight_control_board_v5/proves_flight_control_board_v5-pinctrl.dtsi index 0ae79cf..34fd8f3 100644 --- a/boards/bronco_space/proves_flight_control_board_v5/proves_flight_control_board_v5-pinctrl.dtsi +++ b/boards/bronco_space/proves_flight_control_board_v5/proves_flight_control_board_v5-pinctrl.dtsi @@ -1,6 +1,16 @@ #include &pinctrl { + spi0_default: spi0_default { + group1 { + pinmux = , ; + }; + + group2 { + pinmux = ; + input-enable; + }; + }; spi1_default: spi1_default { group1 { pinmux = , ; diff --git a/boards/bronco_space/proves_flight_control_board_v5/proves_flight_control_board_v5.dtsi b/boards/bronco_space/proves_flight_control_board_v5/proves_flight_control_board_v5.dtsi index 397708c..11db77d 100644 --- a/boards/bronco_space/proves_flight_control_board_v5/proves_flight_control_board_v5.dtsi +++ b/boards/bronco_space/proves_flight_control_board_v5/proves_flight_control_board_v5.dtsi @@ -14,6 +14,17 @@ zephyr,code-partition = &code_partition; }; + fstab { + compatible = "zephyr,fstab"; + ffs1: ffs1 { + compatible = "zephyr,fstab,fatfs"; + automount; + disk-access; + mount-point = "/"; + }; + }; + + aliases { watchdog0 = &wdt0; }; @@ -89,6 +100,24 @@ zephyr_udc0: &usbd { status = "okay"; }; +&spi0 { + status = "okay"; + cs-gpios = <&gpio0 15 GPIO_ACTIVE_LOW>; + pinctrl-0 = <&spi0_default>; + pinctrl-names = "default"; + sdhc0: sdhc@0 { + compatible = "zephyr,sdhc-spi-slot"; + reg = <0>; + status = "okay"; + mmc { + compatible = "zephyr,sdmmc-disk"; + disk-name = "SD"; + status = "okay"; + }; + spi-max-frequency = <24000000>; + }; +}; + &spi1 { status = "okay"; cs-gpios = <&gpio0 9 GPIO_ACTIVE_LOW>; diff --git a/lib/fprime b/lib/fprime index 626473f..064b645 160000 --- a/lib/fprime +++ b/lib/fprime @@ -1 +1 @@ -Subproject commit 626473fc4e89e491d43ad95bb0d1b7727014c80d +Subproject commit 064b64553f1c0dce5afd43453bbf58993004e1e2 diff --git a/lib/fprime-zephyr b/lib/fprime-zephyr index dc83bef..11c2a10 160000 --- a/lib/fprime-zephyr +++ b/lib/fprime-zephyr @@ -1 +1 @@ -Subproject commit dc83bef61c25c65d3854cf65b045daf42a6a58f9 +Subproject commit 11c2a109c0225745237c46a0f45902ffc598500b diff --git a/lib/makelib/zephyr.mk b/lib/makelib/zephyr.mk index 5c3a9e0..6296d38 100644 --- a/lib/makelib/zephyr.mk +++ b/lib/makelib/zephyr.mk @@ -24,11 +24,8 @@ clean-zephyr-config: ## Remove west configuration .PHONY: zephyr-workspace zephyr-workspace: fprime-venv ## Setup Zephyr bootloader, modules, and tools directories - @test -d ../lib/zephyr-workspace/bootloader || \ - test -d ../lib/zephyr-workspace/modules || \ - test -d ../lib/zephyr-workspace/tools || { \ - $(WESTX) update; \ - } + $(WESTX) update; \ + .PHONY: clean-zephyr-workspace clean-zephyr-workspace: ## Remove Zephyr bootloader, modules, and tools directories diff --git a/prj.conf b/prj.conf index 72c56e2..b1e3567 100644 --- a/prj.conf +++ b/prj.conf @@ -54,3 +54,14 @@ CONFIG_LOG=n CONFIG_LOG_DEFAULT_LEVEL=3 CONFIG_CBPRINTF_FP_SUPPORT=y + + +CONFIG_POSIX_AEP_CHOICE_PSE52=y +CONFIG_POSIX_FILE_SYSTEM=y +CONFIG_FILE_SYSTEM=y +CONFIG_SDHC=y +CONFIG_DISK_ACCESS=y +CONFIG_FAT_FILESYSTEM_ELM=y +CONFIG_FS_FATFS_EXFAT=y +CONFIG_FS_FATFS_MOUNT_MKFS=y +CONFIG_FS_FATFS_FSTAB_AUTOMOUNT=y diff --git a/settings.ini b/settings.ini index dde51b9..cf24077 100644 --- a/settings.ini +++ b/settings.ini @@ -8,3 +8,6 @@ default_cmake_options: FPRIME_ENABLE_FRAMEWORK_UTS=OFF FPRIME_ENABLE_AUTOCODER_UTS=OFF BOARD_ROOT=. BOARD=proves_flight_control_board_v5d/rp2350a/m33 + FPRIME_USE_POSIX=ON + FPRIME_CMAKE_QUIET=ON + FPRIME_INSTALL_STATIC_LIBRARIES=OFF diff --git a/west.yml b/west.yml index 5e9079d..c1a61d8 100644 --- a/west.yml +++ b/west.yml @@ -84,6 +84,13 @@ manifest: groups: - bootloader + # FAT Filesystem support + - name: fatfs + revision: 16245c7c41d2b79e74984f49b5202551786b8a9b + path: lib/zephyr-workspace/modules/fs/fatfs + groups: + - fs + self: path: . west-commands: west-commands.yml