diff --git a/cpp/hal/sbc_version.cpp b/cpp/hal/sbc_version.cpp index 09cf2fc0..6d547d98 100644 --- a/cpp/hal/sbc_version.cpp +++ b/cpp/hal/sbc_version.cpp @@ -14,7 +14,6 @@ #include #include -// TODO: THESE NEED TO BE VALIDATED!!!! const string SBC_Version::str_raspberry_pi_1 = "Raspberry Pi 1"; const string SBC_Version::str_raspberry_pi_2_3 = "Raspberry Pi 2/3"; const string SBC_Version::str_raspberry_pi_4 = "Raspberry Pi 4"; @@ -28,7 +27,6 @@ const string SBC_Version::str_unknown_sbc = "Unknown platform"; // "Raspberry Pi 4 Model B" will match with both of the following: // - Raspberry Pi 4 Model B Rev 1.4 // - Raspberry Pi 4 Model B Rev 1.3 -// TODO Is there a better way to detect the Pi type than relying on strings? const map> SBC_Version::proc_device_tree_mapping = { {"Raspberry Pi 1 Model ", sbc_version_type::sbc_raspberry_pi_1}, {"Raspberry Pi 2 Model ", sbc_version_type::sbc_raspberry_pi_2_3}, @@ -38,7 +36,6 @@ const map> SBC_Version::proc_devic {"Raspberry Pi Zero", sbc_version_type::sbc_raspberry_pi_1} }; -// Convert the SBC Version to a printable string string SBC_Version::GetAsString() { switch (sbc_version) { @@ -53,14 +50,12 @@ string SBC_Version::GetAsString() } } -// Determine which version of single board computer (Pi) is being used -// based upon the device tree model string. void SBC_Version::Init() { ifstream input_stream(SBC_Version::DEVICE_TREE_MODEL_PATH); if (input_stream.fail()) { - spdlog::trace("Failed to open " + DEVICE_TREE_MODEL_PATH + ": This may not be a Raspberry Pi"); + spdlog::trace("Failed to open " + DEVICE_TREE_MODEL_PATH + ": This may not be a Raspberry Pi."); sbc_version = sbc_version_type::sbc_unknown; spdlog::info("Detected " + GetAsString()); return; @@ -79,60 +74,11 @@ void SBC_Version::Init() } sbc_version = sbc_version_type::sbc_raspberry_pi_4; - spdlog::error("Unable to determine Raspberry Pi model. Defaulting to Raspberry Pi 4"); + + spdlog::error("Unable to determine Raspberry Pi model. Defaulting to Raspberry Pi 4."); } bool SBC_Version::IsRaspberryPi() { return sbc_version != sbc_version_type::sbc_unknown; } - -// The following functions are only used on the Raspberry Pi -// (imported from bcm_host.c) -uint32_t SBC_Version::GetDeviceTreeRanges(const char *filename, uint32_t offset) -{ - uint32_t address = ~0; - if (FILE *fp = fopen(filename, "rb"); fp) { - fseek(fp, offset, SEEK_SET); - if (array buf; fread(buf.data(), 1, buf.size(), fp) == buf.size()) { - address = (int)buf[0] << 24 | (int)buf[1] << 16 | (int)buf[2] << 8 | (int)buf[3] << 0; - } - fclose(fp); - } - return address; -} - -#if defined __linux__ -uint32_t SBC_Version::GetPeripheralAddress(void) -{ - uint32_t address = GetDeviceTreeRanges("/proc/device-tree/soc/ranges", 4); - if (address == 0) { - address = GetDeviceTreeRanges("/proc/device-tree/soc/ranges", 8); - } - address = (address == (uint32_t)~0) ? 0x20000000 : address; - - return address; -} -#elif defined __NetBSD__ && (!defined(__x86_64__) || defined(__X86__)) -uint32_t SBC_Version::GetPeripheralAddress(void) -{ - char buf[1024]; - size_t len = sizeof(buf); - uint32_t address; - - if (sysctlbyname("hw.model", buf, &len, NULL, 0) || strstr(buf, "ARM1176JZ-S") != buf) { - // Failed to get CPU model || Not BCM2835 - // use the address of BCM283[67] - address = 0x3f000000; - } else { - // Use BCM2835 address - address = 0x20000000; - } - return address; -} -#else -uint32_t SBC_Version::GetPeripheralAddress(void) -{ - return 0; -} -#endif diff --git a/cpp/hal/sbc_version.h b/cpp/hal/sbc_version.h index f715a0e7..224b19f9 100644 --- a/cpp/hal/sbc_version.h +++ b/cpp/hal/sbc_version.h @@ -16,11 +16,6 @@ using namespace std; -//=========================================================================== -// -// Single Board Computer Versions -// -//=========================================================================== class SBC_Version { @@ -42,8 +37,6 @@ class SBC_Version static string GetAsString(); - static uint32_t GetPeripheralAddress(); - private: inline static sbc_version_type sbc_version = sbc_version_type::sbc_unknown;; @@ -56,6 +49,4 @@ class SBC_Version static const map> proc_device_tree_mapping; inline static const string DEVICE_TREE_MODEL_PATH = "/proc/device-tree/model"; - - static uint32_t GetDeviceTreeRanges(const char *filename, uint32_t offset); };