Skip to content

Commit

Permalink
Remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
uweseimet committed Nov 25, 2023
1 parent 4565652 commit 9484565
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 66 deletions.
60 changes: 3 additions & 57 deletions cpp/hal/sbc_version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include <iostream>
#include <sstream>

// 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";
Expand All @@ -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<string, SBC_Version::sbc_version_type, less<>> 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},
Expand All @@ -38,7 +36,6 @@ const map<string, SBC_Version::sbc_version_type, less<>> 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) {
Expand All @@ -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;
Expand All @@ -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<uint8_t, 4> 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
9 changes: 0 additions & 9 deletions cpp/hal/sbc_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@

using namespace std;

//===========================================================================
//
// Single Board Computer Versions
//
//===========================================================================
class SBC_Version
{

Expand All @@ -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;;
Expand All @@ -56,6 +49,4 @@ class SBC_Version
static const map<std::string, sbc_version_type, less<>> 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);
};

0 comments on commit 9484565

Please sign in to comment.