mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-02-05 23:43:58 -04:00
AP_HAL_Linux: Make RPI get_hw method public
Valid also on Bebop
This commit is contained in:
parent
cadef09542
commit
b6f51233db
@ -160,4 +160,45 @@ int Util::read_file(const char *path, const char *fmt, ...)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *Linux::Util::_hw_names[UTIL_NUM_HARDWARES] = {
|
||||||
|
[UTIL_HARDWARE_RPI1] = "BCM2708",
|
||||||
|
[UTIL_HARDWARE_RPI2] = "BCM2709",
|
||||||
|
[UTIL_HARDWARE_BEBOP] = "Mykonos3 board",
|
||||||
|
[UTIL_HARDWARE_BEBOP2] = "Milos board",
|
||||||
|
};
|
||||||
|
|
||||||
|
#define MAX_SIZE_LINE 50
|
||||||
|
int Util::get_hw_arm32()
|
||||||
|
{
|
||||||
|
int ret = -ENOENT;
|
||||||
|
char buffer[MAX_SIZE_LINE];
|
||||||
|
const char* hardware_description_entry = "Hardware";
|
||||||
|
char* flag;
|
||||||
|
FILE* f;
|
||||||
|
|
||||||
|
f = fopen("/proc/cpuinfo", "r");
|
||||||
|
|
||||||
|
if (f == NULL) {
|
||||||
|
ret = -errno;
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (fgets(buffer, MAX_SIZE_LINE, f) != NULL) {
|
||||||
|
flag = strstr(buffer, hardware_description_entry);
|
||||||
|
if (flag != NULL) {
|
||||||
|
for (uint8_t i = 0; i < UTIL_NUM_HARDWARES; i++) {
|
||||||
|
if (strstr(buffer, _hw_names[i]) != 0) {
|
||||||
|
ret = i;
|
||||||
|
goto close_end;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
close_end:
|
||||||
|
fclose(f);
|
||||||
|
end:
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
#endif // CONFIG_HAL_BOARD == HAL_BOARD_LINUX
|
#endif // CONFIG_HAL_BOARD == HAL_BOARD_LINUX
|
||||||
|
@ -9,6 +9,14 @@
|
|||||||
#include "ToneAlarmDriver.h"
|
#include "ToneAlarmDriver.h"
|
||||||
#include "Semaphores.h"
|
#include "Semaphores.h"
|
||||||
|
|
||||||
|
enum hw_type {
|
||||||
|
UTIL_HARDWARE_RPI1 = 0,
|
||||||
|
UTIL_HARDWARE_RPI2,
|
||||||
|
UTIL_HARDWARE_BEBOP,
|
||||||
|
UTIL_HARDWARE_BEBOP2,
|
||||||
|
UTIL_NUM_HARDWARES,
|
||||||
|
};
|
||||||
|
|
||||||
class Linux::Util : public AP_HAL::Util {
|
class Linux::Util : public AP_HAL::Util {
|
||||||
public:
|
public:
|
||||||
static Util *from(AP_HAL::Util *util) {
|
static Util *from(AP_HAL::Util *util) {
|
||||||
@ -25,7 +33,7 @@ public:
|
|||||||
|
|
||||||
bool toneAlarm_init();
|
bool toneAlarm_init();
|
||||||
void toneAlarm_set_tune(uint8_t tune);
|
void toneAlarm_set_tune(uint8_t tune);
|
||||||
|
|
||||||
void _toneAlarm_timer_tick();
|
void _toneAlarm_timer_tick();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -64,14 +72,17 @@ public:
|
|||||||
|
|
||||||
// create a new semaphore
|
// create a new semaphore
|
||||||
AP_HAL::Semaphore *new_semaphore(void) override { return new Linux::Semaphore; }
|
AP_HAL::Semaphore *new_semaphore(void) override { return new Linux::Semaphore; }
|
||||||
|
|
||||||
|
int get_hw_arm32();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static Linux::ToneAlarm _toneAlarm;
|
static Linux::ToneAlarm _toneAlarm;
|
||||||
Linux::Heat *_heat;
|
Linux::Heat *_heat;
|
||||||
int saved_argc;
|
int saved_argc;
|
||||||
char* const *saved_argv;
|
char* const *saved_argv;
|
||||||
const char* custom_log_directory = NULL;
|
const char* custom_log_directory = NULL;
|
||||||
const char* custom_terrain_directory = NULL;
|
const char* custom_terrain_directory = NULL;
|
||||||
|
static const char *_hw_names[UTIL_NUM_HARDWARES];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
#include "Util_RPI.h"
|
#include "Util_RPI.h"
|
||||||
|
#include "Util.h"
|
||||||
|
|
||||||
extern const AP_HAL::HAL& hal;
|
extern const AP_HAL::HAL& hal;
|
||||||
|
|
||||||
@ -24,43 +25,22 @@ UtilRPI::UtilRPI()
|
|||||||
_check_rpi_version();
|
_check_rpi_version();
|
||||||
}
|
}
|
||||||
|
|
||||||
#define MAX_SIZE_LINE 50
|
|
||||||
int UtilRPI::_check_rpi_version()
|
int UtilRPI::_check_rpi_version()
|
||||||
{
|
{
|
||||||
char buffer[MAX_SIZE_LINE];
|
int hw;
|
||||||
const char* hardware_description_entry = "Hardware";
|
hw = Util::from(hal.util)->get_hw_arm32();
|
||||||
const char* v1 = "BCM2708";
|
|
||||||
const char* v2 = "BCM2709";
|
|
||||||
char* flag;
|
|
||||||
FILE* fd;
|
|
||||||
|
|
||||||
fd = fopen("/proc/cpuinfo", "r");
|
if (hw == UTIL_HARDWARE_RPI2) {
|
||||||
|
printf("Raspberry Pi 2 with BCM2709!\n");
|
||||||
while (fgets(buffer, MAX_SIZE_LINE, fd) != NULL) {
|
_rpi_version = 2;
|
||||||
flag = strstr(buffer, hardware_description_entry);
|
} else if (hw == UTIL_HARDWARE_RPI1) {
|
||||||
if (flag != NULL) {
|
printf("Raspberry Pi 1 with BCM2708!\n");
|
||||||
if (strstr(buffer, v2) != NULL) {
|
_rpi_version = 1;
|
||||||
printf("Raspberry Pi 2 with BCM2709!\n");
|
} else {
|
||||||
fclose(fd);
|
/* defaults to 1 */
|
||||||
|
fprintf(stderr, "Could not detect RPi version, defaulting to 1\n");
|
||||||
_rpi_version = 2;
|
_rpi_version = 1;
|
||||||
return _rpi_version;
|
|
||||||
}
|
|
||||||
else if (strstr(buffer, v1) != NULL) {
|
|
||||||
printf("Raspberry Pi 1 with BCM2708!\n");
|
|
||||||
fclose(fd);
|
|
||||||
|
|
||||||
_rpi_version = 1;
|
|
||||||
return _rpi_version;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* defaults to 1 */
|
|
||||||
fprintf(stderr, "Could not detect RPi version, defaulting to 1\n");
|
|
||||||
fclose(fd);
|
|
||||||
|
|
||||||
_rpi_version = 1;
|
|
||||||
return _rpi_version;
|
return _rpi_version;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user