2015-09-23 12:52:07 -03:00
|
|
|
#include <AP_HAL/AP_HAL.h>
|
|
|
|
|
2015-11-28 05:38:56 -04:00
|
|
|
#if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIO || \
|
2016-01-20 09:27:43 -04:00
|
|
|
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIO2 || \
|
2016-06-29 05:16:03 -03:00
|
|
|
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_EDGE || \
|
2015-11-28 05:38:56 -04:00
|
|
|
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_ERLEBRAIN2 || \
|
2016-01-05 06:36:02 -04:00
|
|
|
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BH || \
|
2016-10-17 15:02:48 -03:00
|
|
|
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_DARK || \
|
2020-01-10 15:25:03 -04:00
|
|
|
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_PXFMINI || \
|
2021-09-07 02:17:32 -03:00
|
|
|
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIGATOR || \
|
|
|
|
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_OBAL_V1
|
2015-09-23 12:52:07 -03:00
|
|
|
|
2018-02-12 13:05:21 -04:00
|
|
|
#include <errno.h>
|
2015-09-23 12:52:07 -03:00
|
|
|
#include <stdarg.h>
|
2018-02-12 13:05:21 -04:00
|
|
|
#include <stdio.h>
|
2015-09-23 12:52:07 -03:00
|
|
|
#include <stdlib.h>
|
2018-02-12 13:05:21 -04:00
|
|
|
#include <sys/stat.h>
|
2015-09-23 12:52:07 -03:00
|
|
|
#include <time.h>
|
2018-02-12 13:05:21 -04:00
|
|
|
#include <unistd.h>
|
2015-09-23 12:52:07 -03:00
|
|
|
|
2015-12-22 09:49:12 -04:00
|
|
|
#include "Util.h"
|
2018-02-12 13:05:21 -04:00
|
|
|
#include "Util_RPI.h"
|
2015-09-23 12:52:07 -03:00
|
|
|
|
2018-02-12 13:05:21 -04:00
|
|
|
extern const AP_HAL::HAL &hal;
|
2015-09-23 12:52:07 -03:00
|
|
|
|
|
|
|
using namespace Linux;
|
|
|
|
|
2015-10-20 18:13:25 -03:00
|
|
|
UtilRPI::UtilRPI()
|
2015-09-23 12:52:07 -03:00
|
|
|
{
|
2022-01-17 10:17:03 -04:00
|
|
|
_check_rpi_version_by_rev();
|
2015-09-23 12:52:07 -03:00
|
|
|
}
|
|
|
|
|
2022-01-17 10:17:03 -04:00
|
|
|
int UtilRPI::_check_rpi_version_by_rev()
|
2015-09-23 12:52:07 -03:00
|
|
|
{
|
2022-01-17 10:17:03 -04:00
|
|
|
// assume 2 if unknown
|
|
|
|
_rpi_version = 2;
|
|
|
|
const char *SOC[]= {"Broadcom BCM2835","Broadcom BCM2836","Broadcom BCM2837","Broadcom BCM2711"};
|
|
|
|
const char *revision_file_ = "/proc/device-tree/system/linux,revision";
|
|
|
|
uint8_t revision[4] = { 0 };
|
|
|
|
uint32_t cpu = 0;
|
|
|
|
FILE *fd;
|
2017-12-06 08:04:06 -04:00
|
|
|
|
2022-01-17 10:17:03 -04:00
|
|
|
if ((fd = fopen(revision_file_, "rb")) == NULL) {
|
|
|
|
printf("Can't open '%s'\n", revision_file_);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (fread(revision, 1, sizeof(revision), fd) == 4) {
|
|
|
|
cpu = (revision[2] >> 4) & 0xf;
|
|
|
|
|
|
|
|
_rpi_version = cpu;
|
|
|
|
|
|
|
|
if (_rpi_version==0) {
|
|
|
|
_rpi_version=1; //RPI-Zero
|
2018-02-12 12:46:36 -04:00
|
|
|
}
|
2017-12-06 08:04:06 -04:00
|
|
|
|
2022-01-17 10:17:03 -04:00
|
|
|
printf("SOC: %s use intern: %d \r\n",SOC[cpu], _rpi_version);
|
2018-02-12 12:46:36 -04:00
|
|
|
}
|
2022-01-17 10:17:03 -04:00
|
|
|
else {
|
|
|
|
printf("Revision data too short\n");
|
|
|
|
}
|
|
|
|
fclose(fd);
|
2018-02-12 12:46:36 -04:00
|
|
|
}
|
2017-12-06 08:04:06 -04:00
|
|
|
|
2015-09-23 12:52:07 -03:00
|
|
|
return _rpi_version;
|
|
|
|
}
|
|
|
|
|
2022-01-17 10:17:03 -04:00
|
|
|
|
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
|