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 || \
|
2023-10-22 14:50:57 -03:00
|
|
|
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_OBAL_V1 || \
|
|
|
|
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_CANZERO
|
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
|
|
|
{
|
2023-06-01 09:38:09 -03:00
|
|
|
_get_board_type_using_peripheral_base ();
|
2015-09-23 12:52:07 -03:00
|
|
|
}
|
|
|
|
|
2017-12-06 08:04:06 -04:00
|
|
|
|
2023-06-01 09:38:09 -03:00
|
|
|
//
|
|
|
|
// previous appraoch was using /proc/device-tree/system/linux,revision
|
|
|
|
// now we use /proc/device-tree/soc/ranges see: https://forums.raspberrypi.com//viewtopic.php?t=244031
|
|
|
|
void UtilRPI::_get_board_type_using_peripheral_base()
|
|
|
|
{
|
|
|
|
FILE *fp;
|
|
|
|
uint32_t base=0x00;
|
|
|
|
unsigned char buf[32];
|
|
|
|
_linux_board_version = LINUX_BOARD_TYPE::UNKNOWN_BOARD;
|
|
|
|
fp = fopen("/proc/device-tree/soc/ranges" , "rb");
|
|
|
|
if (fp) {
|
|
|
|
const uint16_t len = fread(buf, 1, sizeof(buf), fp);
|
|
|
|
if (len >= 8) {
|
|
|
|
base = buf[4]<<24 | buf[5]<<16 | buf[6]<<8 | buf[7];
|
|
|
|
if (!base)
|
|
|
|
base = buf[8]<<24 | buf[9]<<16 | buf[10]<<8 | buf[11];
|
|
|
|
if (!base)
|
|
|
|
base = buf[8]<<24 | buf[9]<<16 | buf[10]<<8 | buf[11];
|
|
|
|
if (!base && (len>15))
|
|
|
|
base = buf[12]<<24 | buf[13]<<16 | buf[14]<<8 | buf[15];
|
2022-01-17 10:17:03 -04:00
|
|
|
|
2018-02-12 12:46:36 -04:00
|
|
|
}
|
2023-06-01 09:38:09 -03:00
|
|
|
fclose(fp);
|
2018-02-12 12:46:36 -04:00
|
|
|
}
|
2017-12-06 08:04:06 -04:00
|
|
|
|
2023-06-01 09:38:09 -03:00
|
|
|
switch (base) {
|
|
|
|
case 0x0:
|
|
|
|
_linux_board_version = LINUX_BOARD_TYPE::UNKNOWN_BOARD;
|
|
|
|
printf("Cannot detect board-type \r\n");
|
|
|
|
break;
|
|
|
|
case 0x20000000:
|
|
|
|
_linux_board_version = LINUX_BOARD_TYPE::RPI_ZERO_1;
|
|
|
|
printf("RPI Zero / 1 \r\n");
|
|
|
|
printf("Peripheral base address is %x\n", base);
|
|
|
|
break;
|
|
|
|
case 0x3f000000:
|
|
|
|
_linux_board_version = LINUX_BOARD_TYPE::RPI_2_3_ZERO2;
|
|
|
|
printf("RPI 2, 3 or Zero-2 \r\n");
|
|
|
|
printf("Peripheral base address is %x\n", base);
|
|
|
|
break;
|
|
|
|
case 0xfe000000:
|
|
|
|
_linux_board_version = LINUX_BOARD_TYPE::RPI_4;
|
|
|
|
printf("RPI 4 \r\n");
|
|
|
|
printf("Peripheral base address is %x\n", base);
|
|
|
|
break;
|
|
|
|
case 0x40000000:
|
|
|
|
_linux_board_version = LINUX_BOARD_TYPE::ALLWINNWER_H616;
|
|
|
|
printf("AllWinner-H616 \r\n");
|
|
|
|
break;
|
|
|
|
}
|
2015-09-23 12:52:07 -03:00
|
|
|
|
2023-06-01 09:38:09 -03:00
|
|
|
return ;
|
|
|
|
}
|
2022-01-17 10:17:03 -04:00
|
|
|
|
2023-06-01 09:38:09 -03:00
|
|
|
LINUX_BOARD_TYPE UtilRPI::detect_linux_board_type() const
|
2015-09-23 12:52:07 -03:00
|
|
|
{
|
2023-06-01 09:38:09 -03:00
|
|
|
return _linux_board_version;
|
2015-09-23 12:52:07 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|