2015-09-23 12:52:07 -03:00
|
|
|
#include <AP_HAL/AP_HAL.h>
|
|
|
|
|
2015-11-01 07:25:51 -04:00
|
|
|
#if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIO || CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_RASPILOT || CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_ERLEBRAIN2
|
2015-09-23 12:52:07 -03:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
2015-09-23 22:53:42 -03:00
|
|
|
#include "Util_RPI.h"
|
2015-09-23 12:52:07 -03:00
|
|
|
|
|
|
|
extern const AP_HAL::HAL& hal;
|
|
|
|
|
|
|
|
using namespace Linux;
|
|
|
|
|
2015-10-20 18:13:25 -03:00
|
|
|
UtilRPI::UtilRPI()
|
2015-09-23 12:52:07 -03:00
|
|
|
{
|
|
|
|
_check_rpi_version();
|
|
|
|
}
|
|
|
|
|
|
|
|
#define MAX_SIZE_LINE 50
|
2015-10-20 18:13:25 -03:00
|
|
|
int UtilRPI::_check_rpi_version()
|
2015-09-23 12:52:07 -03:00
|
|
|
{
|
|
|
|
char buffer[MAX_SIZE_LINE];
|
|
|
|
const char* hardware_description_entry = "Hardware";
|
|
|
|
const char* v1 = "BCM2708";
|
|
|
|
const char* v2 = "BCM2709";
|
|
|
|
char* flag;
|
|
|
|
FILE* fd;
|
|
|
|
|
|
|
|
fd = fopen("/proc/cpuinfo", "r");
|
|
|
|
|
|
|
|
while (fgets(buffer, MAX_SIZE_LINE, fd) != NULL) {
|
|
|
|
flag = strstr(buffer, hardware_description_entry);
|
|
|
|
if (flag != NULL) {
|
|
|
|
if (strstr(buffer, v2) != NULL) {
|
|
|
|
printf("Raspberry Pi 2 with BCM2709!\n");
|
|
|
|
fclose(fd);
|
|
|
|
|
|
|
|
_rpi_version = 2;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-10-20 18:13:25 -03:00
|
|
|
int UtilRPI::get_rpi_version() const
|
2015-09-23 12:52:07 -03:00
|
|
|
{
|
|
|
|
return _rpi_version;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|