From e6779e91e6951c7494529d05d7dfc86d0ca39ed7 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Sat, 16 Oct 2021 17:10:58 +1100 Subject: [PATCH] SITL: allow JEDEC/RAMTRON to be compiled out SITL: add and use AP_SIM_RAMTRON_ENABLED SITL: add an use AP_SIM_JEDEC_ENABLED --- libraries/SITL/SIM_JEDEC.cpp | 8 ++++++-- libraries/SITL/SIM_JEDEC.h | 10 ++++++++++ libraries/SITL/SIM_JEDEC_MX25L3206E.cpp | 4 ++++ libraries/SITL/SIM_JEDEC_MX25L3206E.h | 8 ++++++++ libraries/SITL/SIM_RAMTRON.cpp | 8 ++++++-- libraries/SITL/SIM_RAMTRON.h | 10 ++++++++++ libraries/SITL/SIM_RAMTRON_FM25V02.cpp | 4 ++++ libraries/SITL/SIM_RAMTRON_FM25V02.h | 8 ++++++++ libraries/SITL/SIM_SPI.cpp | 10 ++++++++++ 9 files changed, 66 insertions(+), 4 deletions(-) diff --git a/libraries/SITL/SIM_JEDEC.cpp b/libraries/SITL/SIM_JEDEC.cpp index 8042d613c1..9b4255f781 100644 --- a/libraries/SITL/SIM_JEDEC.cpp +++ b/libraries/SITL/SIM_JEDEC.cpp @@ -1,5 +1,7 @@ #include "SIM_JEDEC.h" +#if AP_SIM_JEDEC_ENABLED + #include #include @@ -7,7 +9,7 @@ using namespace SITL; -extern HAL_SITL& hal; +extern const HAL_SITL& hal_sitl; void JEDEC::open_storage_fd() { @@ -15,7 +17,7 @@ void JEDEC::open_storage_fd() AP_HAL::panic("Should not have been called"); } const char *filepath = filename(); - if (hal.get_wipe_storage()) { + if (hal_sitl.get_wipe_storage()) { unlink(filepath); } storage_fd = open(filepath, O_RDWR|O_CREAT, 0644); @@ -190,3 +192,5 @@ int JEDEC::rdwr(uint8_t count, SPI::spi_ioc_transfer *&tfrs) } return 0; } + +#endif // AP_SIM_JEDEC_ENABLED diff --git a/libraries/SITL/SIM_JEDEC.h b/libraries/SITL/SIM_JEDEC.h index 840ba77614..24f568e328 100644 --- a/libraries/SITL/SIM_JEDEC.h +++ b/libraries/SITL/SIM_JEDEC.h @@ -1,5 +1,13 @@ #pragma once +#include + +#ifndef AP_SIM_JEDEC_ENABLED +#define AP_SIM_JEDEC_ENABLED (CONFIG_HAL_BOARD == HAL_BOARD_SITL) +#endif + +#if AP_SIM_JEDEC_ENABLED + #include "SIM_SPIDevice.h" namespace SITL { @@ -46,3 +54,5 @@ private: }; } + +#endif // AP_SIM_JEDEC_ENABLED diff --git a/libraries/SITL/SIM_JEDEC_MX25L3206E.cpp b/libraries/SITL/SIM_JEDEC_MX25L3206E.cpp index f5eae615f2..8570d97c05 100644 --- a/libraries/SITL/SIM_JEDEC_MX25L3206E.cpp +++ b/libraries/SITL/SIM_JEDEC_MX25L3206E.cpp @@ -1,5 +1,7 @@ #include "SIM_JEDEC_MX25L3206E.h" +#if AP_SIM_JEDEC_MX25L3206E_ENABLED + using namespace SITL; void JEDEC_MX25L3206E::fill_rdid(uint8_t *buffer, uint8_t len) @@ -15,3 +17,5 @@ void JEDEC_MX25L3206E::fill_rdsr(uint8_t *buffer, uint8_t len) // hence we can never be busy while reading the status register buffer[0] = 0x00; } + +#endif // AP_SIM_JEDEC_MX25L3206E_ENABLED diff --git a/libraries/SITL/SIM_JEDEC_MX25L3206E.h b/libraries/SITL/SIM_JEDEC_MX25L3206E.h index 72bb5e36be..3e8dadb7d0 100644 --- a/libraries/SITL/SIM_JEDEC_MX25L3206E.h +++ b/libraries/SITL/SIM_JEDEC_MX25L3206E.h @@ -2,6 +2,12 @@ #include "SIM_JEDEC.h" +#ifndef AP_SIM_JEDEC_MX25L3206E_ENABLED +#define AP_SIM_JEDEC_MX25L3206E_ENABLED AP_SIM_JEDEC_ENABLED +#endif + +#if AP_SIM_JEDEC_MX25L3206E_ENABLED + namespace SITL { class JEDEC_MX25L3206E : public JEDEC @@ -24,3 +30,5 @@ private: }; } + +#endif // AP_SIM_JEDEC_MX25L3206E_ENABLED diff --git a/libraries/SITL/SIM_RAMTRON.cpp b/libraries/SITL/SIM_RAMTRON.cpp index 9a0fe368ac..dee0fca6b7 100644 --- a/libraries/SITL/SIM_RAMTRON.cpp +++ b/libraries/SITL/SIM_RAMTRON.cpp @@ -1,5 +1,7 @@ #include "SIM_RAMTRON.h" +#if AP_SIM_RAMTRON_ENABLED + #include #include @@ -7,7 +9,7 @@ using namespace SITL; -extern HAL_SITL& hal; +extern const HAL_SITL& hal_sitl; void RAMTRON::open_storage_fd() { @@ -16,7 +18,7 @@ void RAMTRON::open_storage_fd() } const char *filepath = filename(); uint32_t flags = O_RDWR|O_CREAT; - if (hal.get_wipe_storage()) { + if (hal_sitl.get_wipe_storage()) { flags |= O_TRUNC; } storage_fd = open(filepath, flags, 0644); @@ -109,3 +111,5 @@ int RAMTRON::rdwr(uint8_t count, SPI::spi_ioc_transfer *&tfrs) } return 0; } + +#endif // AP_SIM_RAMTRON_ENABLED diff --git a/libraries/SITL/SIM_RAMTRON.h b/libraries/SITL/SIM_RAMTRON.h index c9215b9d68..dd701f604b 100644 --- a/libraries/SITL/SIM_RAMTRON.h +++ b/libraries/SITL/SIM_RAMTRON.h @@ -1,5 +1,13 @@ #pragma once +#include + +#ifndef AP_SIM_RAMTRON_ENABLED +#define AP_SIM_RAMTRON_ENABLED (CONFIG_HAL_BOARD == HAL_BOARD_SITL) +#endif + +#if AP_SIM_RAMTRON_ENABLED + #include "SIM_SPIDevice.h" namespace SITL { @@ -33,3 +41,5 @@ private: }; } + +#endif // AP_SIM_RAMTRON_ENABLED diff --git a/libraries/SITL/SIM_RAMTRON_FM25V02.cpp b/libraries/SITL/SIM_RAMTRON_FM25V02.cpp index c4b8c29af9..91db542ebe 100644 --- a/libraries/SITL/SIM_RAMTRON_FM25V02.cpp +++ b/libraries/SITL/SIM_RAMTRON_FM25V02.cpp @@ -1,5 +1,7 @@ #include "SIM_RAMTRON_FM25V02.h" +#if AP_SIM_RAMTRON_FM25V02_ENABLED + using namespace SITL; void RAMTRON_FM25V02::fill_rdid(uint8_t *buffer, uint8_t len) @@ -8,3 +10,5 @@ void RAMTRON_FM25V02::fill_rdid(uint8_t *buffer, uint8_t len) buffer[7] = id1(); buffer[8] = id2(); } + +#endif // AP_SIM_RAMTRON_FM25V02_ENABLED diff --git a/libraries/SITL/SIM_RAMTRON_FM25V02.h b/libraries/SITL/SIM_RAMTRON_FM25V02.h index 73502f5902..b143d95373 100644 --- a/libraries/SITL/SIM_RAMTRON_FM25V02.h +++ b/libraries/SITL/SIM_RAMTRON_FM25V02.h @@ -2,6 +2,12 @@ #include "SIM_RAMTRON.h" +#ifndef AP_SIM_RAMTRON_FM25V02_ENABLED +#define AP_SIM_RAMTRON_FM25V02_ENABLED AP_SIM_RAMTRON_ENABLED +#endif + +#if AP_SIM_RAMTRON_FM25V02_ENABLED + namespace SITL { class RAMTRON_FM25V02 : public RAMTRON @@ -31,3 +37,5 @@ private: }; } + +#endif // AP_SIM_RAMTRON_FM25V02_ENABLED diff --git a/libraries/SITL/SIM_SPI.cpp b/libraries/SITL/SIM_SPI.cpp index 7c234c020c..36380f0a90 100644 --- a/libraries/SITL/SIM_SPI.cpp +++ b/libraries/SITL/SIM_SPI.cpp @@ -21,6 +21,8 @@ #include #include "SIM_SPI.h" +#include "SIM_SPIDevice.h" + #include "SIM_RAMTRON_FM25V02.h" #include "SIM_JEDEC_MX25L3206E.h" @@ -28,16 +30,24 @@ using namespace SITL; +#if AP_SIM_RAMTRON_FM25V02_ENABLED static RAMTRON_FM25V02 ramtron_FM25V02; // 32kB 2-byte-addressing +#endif +#if AP_SIM_JEDEC_MX25L3206E_ENABLED static JEDEC_MX25L3206E jedec_MX25L3206E; +#endif struct spi_device_at_cs_pin { uint8_t bus; uint8_t cs_pin; SPIDevice &device; } spi_devices[] { +#if AP_SIM_RAMTRON_FM25V02_ENABLED { 0, 0, ramtron_FM25V02 }, +#endif +#if AP_SIM_JEDEC_MX25L3206E_ENABLED { 1, 0, jedec_MX25L3206E }, +#endif }; void SPI::init()