Skip to content

Commit

Permalink
[wiring] System.hardwareInfo()
Browse files Browse the repository at this point in the history
minor

add ncp id

minor

minor

minor

minor

minor

minor
  • Loading branch information
avtolstoy committed Aug 29, 2022
1 parent d2e6559 commit af47d3f
Show file tree
Hide file tree
Showing 16 changed files with 274 additions and 18 deletions.
20 changes: 20 additions & 0 deletions hal/inc/deviceid_hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,26 @@ int hal_get_device_hw_version(uint32_t* revision, void* reserved);
*/
int hal_get_device_hw_model(uint32_t* model, uint32_t* variant, void* reserved);

#define HAL_DEVICE_MAX_NCP_IDENTIFIERS (5)

typedef struct hal_device_hw_info {
uint16_t size;
uint16_t version;

uint32_t revision;
uint32_t model;
uint32_t variant;
uint32_t features;
uint16_t ncp[HAL_DEVICE_MAX_NCP_IDENTIFIERS];
} hal_device_hw_info;

/**
* Get the device's hardware information
*/
int hal_get_device_hw_info(hal_device_hw_info* info, void* reserved);

#include "deviceid_hal_impl.h"

#ifdef __cplusplus
}
#endif
Expand Down
1 change: 1 addition & 0 deletions hal/inc/hal_dynalib_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ DYNALIB_FN(38, hal_core, hal_get_device_hw_model, int(uint32_t*, uint32_t*, void
DYNALIB_FN(39, hal_core, hal_get_device_serial_number, int(char*, size_t, void*))
DYNALIB_FN(40, hal_core, hal_get_device_secret, int(char*, size_t, void*))
DYNALIB_FN(41, hal_core, hal_set_device_secret, int(char*, size_t, void*))
DYNALIB_FN(42, hal_core, hal_get_device_hw_info, int(hal_device_hw_info*, void*))

DYNALIB_END(hal_core)

Expand Down
26 changes: 20 additions & 6 deletions hal/shared/platform_ncp.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,24 @@
#include "ota_flash_hal.h"
#include "hal_platform.h"

enum PlatformNCPManufacturer {
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

typedef enum PlatformNCPManufacturer {
PLATFORM_NCP_MANUFACTURER_UNKNOWN,
PLATFORM_NCP_MANUFACTURER_ESPRESSIF = 1,
PLATFORM_NCP_MANUFACTURER_UBLOX = 2,
PLATFORM_NCP_MANUFACTURER_QUECTEL = 3,
PLATFORM_NCP_MANUFACTURER_BROADCOM = 4
};
PLATFORM_NCP_MANUFACTURER_BROADCOM = 4,
PLATFORM_NCP_MANUFACTURER_REALTEK = 5
} PlatformNCPManufacturer;

#define PLATFORM_NCP_IDENTIFIER(mf,t) (t|(mf<<5))
#define PLATFORM_NCP_MANUFACTURER(v) ((v) >> 5)

enum PlatformNCPIdentifier {
PLATFORM_NCP_UNKNOWN = -1,
typedef enum PlatformNCPIdentifier {
PLATFORM_NCP_UNKNOWN = 0xffff,
PLATFORM_NCP_NONE = 0,

// 0x2x
Expand All @@ -60,7 +65,13 @@ enum PlatformNCPIdentifier {
// 0x8x
PLATFORM_NCP_BROADCOM_BCM9WCDUSI09 = PLATFORM_NCP_IDENTIFIER(PLATFORM_NCP_MANUFACTURER_BROADCOM, 1),
PLATFORM_NCP_BROADCOM_BCM9WCDUSI14 = PLATFORM_NCP_IDENTIFIER(PLATFORM_NCP_MANUFACTURER_BROADCOM, 2)
};
PLATFORM_NCP_BROADCOM_BCM9WCDUSI14 = PLATFORM_NCP_IDENTIFIER(PLATFORM_NCP_MANUFACTURER_BROADCOM, 2),
PLATFORM_NCP_REALTEK_RTL872X = PLATFORM_NCP_IDENTIFIER(PLATFORM_NCP_MANUFACTURER_REALTEK, 0)
} PlatformNCPIdentifier;

#if PLATFORM_ID != PLATFORM_GCC
static_assert(sizeof(PlatformNCPIdentifier) == sizeof(uint16_t), "sizeof(Platform_NCPIdentifier) has changed");
#endif

struct PlatformNCPInfo {
PlatformNCPIdentifier identifier;
Expand Down Expand Up @@ -95,3 +106,6 @@ int platform_ncp_fetch_module_info(hal_module_t* module);

#endif

#ifdef __cplusplus
}
#endif // __cplusplus
6 changes: 3 additions & 3 deletions hal/src/b5som/platform_ncp_quectel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ bool isValidNcpId(uint8_t id) {
PlatformNCPIdentifier platform_primary_ncp_identifier() {
// Check the DCT
uint8_t ncpId = 0;
int r = dct_read_app_data_copy(DCT_NCP_ID_OFFSET, &ncpId, 1);
int r = dct_read_app_data_copy(DCT_NCP_ID_OFFSET, &ncpId, sizeof(ncpId));
if (r < 0 || !isValidNcpId(ncpId)) {
// Check the OTP flash
r = hal_exflash_read_special(HAL_EXFLASH_SPECIAL_SECTOR_OTP, NCP_ID_OTP_ADDRESS, &ncpId, 1);
r = hal_exflash_read_special(HAL_EXFLASH_SPECIAL_SECTOR_OTP, NCP_ID_OTP_ADDRESS, &ncpId, sizeof(ncpId));
if (r < 0 || !isValidNcpId(ncpId)) {
ncpId = PlatformNCPIdentifier::PLATFORM_NCP_UNKNOWN;
return PlatformNCPIdentifier::PLATFORM_NCP_UNKNOWN;
}
}
return (PlatformNCPIdentifier)ncpId;
Expand Down
6 changes: 3 additions & 3 deletions hal/src/boron/platform_ncp_boron.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ bool isValidNcpId(uint8_t id) {
PlatformNCPIdentifier platform_primary_ncp_identifier() {
// Check the DCT
uint8_t ncpId = 0;
int r = dct_read_app_data_copy(DCT_NCP_ID_OFFSET, &ncpId, 1);
int r = dct_read_app_data_copy(DCT_NCP_ID_OFFSET, &ncpId, sizeof(ncpId));
if (r < 0 || !isValidNcpId(ncpId)) {
// Check the OTP flash
r = hal_exflash_read_special(HAL_EXFLASH_SPECIAL_SECTOR_OTP, NCP_ID_OTP_ADDRESS, &ncpId, 1);
r = hal_exflash_read_special(HAL_EXFLASH_SPECIAL_SECTOR_OTP, NCP_ID_OTP_ADDRESS, &ncpId, sizeof(ncpId));
if (r < 0 || !isValidNcpId(ncpId)) {
ncpId = PlatformNCPIdentifier::PLATFORM_NCP_UNKNOWN;
return PlatformNCPIdentifier::PLATFORM_NCP_UNKNOWN;
}
}
return (PlatformNCPIdentifier)ncpId;
Expand Down
32 changes: 29 additions & 3 deletions hal/src/gcc/deviceid_hal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@
#include <string.h>
#include <cstdio>
#include <limits>


#include "system_error.h"

using std::string;

Expand All @@ -52,4 +51,31 @@ unsigned HAL_Platform_ID()
int HAL_Get_Device_Identifier(const char** name, char* buf, size_t buflen, unsigned index, void* reserved)
{
return -1;
}
}

void hal_save_device_id(uint32_t offset) {
}

int hal_get_device_serial_number(char* str, size_t size, void* reserved) {
return SYSTEM_ERROR_NOT_SUPPORTED;
}

int hal_get_device_secret(char* data, size_t size, void* reserved) {
return SYSTEM_ERROR_NOT_SUPPORTED;
}

int hal_set_device_secret(char* data, size_t size, void* reserved) {
return SYSTEM_ERROR_NOT_SUPPORTED;
}

int hal_get_device_hw_version(uint32_t* revision, void* reserved) {
return SYSTEM_ERROR_NOT_SUPPORTED;
}

int hal_get_device_hw_model(uint32_t* model, uint32_t* variant, void* reserved) {
return SYSTEM_ERROR_NOT_SUPPORTED;
}

int hal_get_device_hw_info(hal_device_hw_info* info, void* reserved) {
return SYSTEM_ERROR_NOT_SUPPORTED;
}
20 changes: 20 additions & 0 deletions hal/src/gcc/deviceid_hal_impl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright (c) 2022 Particle Industries, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either
* version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

// placeholder
25 changes: 25 additions & 0 deletions hal/src/nRF52840/deviceid_hal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@
#ifndef HAL_DEVICE_ID_NO_DCT
#include "dct.h"
#endif /* HAL_DEVICE_ID_NO_DCT */
#include "check.h"

#include "nrf52840.h"

#include <algorithm>

#include "platform_ncp.h"

namespace {

using namespace particle;
Expand Down Expand Up @@ -111,6 +114,28 @@ int hal_get_device_hw_model(uint32_t* model, uint32_t* variant, void* reserved)
return SYSTEM_ERROR_NONE;
}

int hal_get_device_hw_info(hal_device_hw_info* info, void* reserved) {
CHECK_TRUE(info, SYSTEM_ERROR_INVALID_ARGUMENT);
// HW Data format: | NCP_ID | HW_VERSION | HW Feature Flags |
// | byte 0 | byte 1 | byte 2/3 |
uint8_t hw_data[4] = {};
CHECK(hal_exflash_read_special(HAL_EXFLASH_SPECIAL_SECTOR_OTP, HW_DATA_OTP_ADDRESS, hw_data, sizeof(hw_data)));
CHECK(hal_get_device_hw_model(&info->model, &info->variant, nullptr));
info->revision = hw_data[1];
if (info->revision == 0xff) {
info->revision = 0xffffffff;
}
info->features = ((uint32_t)hw_data[3] << 8) | (uint32_t)hw_data[2];
memset(info->ncp, 0xff, sizeof(info->ncp));
for (int i = 0; i < HAL_PLATFORM_NCP_COUNT; i++) {
PlatformNCPInfo ncpInfo = {};
if (!platform_ncp_get_info(i, &ncpInfo)) {
info->ncp[i] = (uint16_t)ncpInfo.identifier;
}
}
return 0;
}

#ifndef HAL_DEVICE_ID_NO_DCT
int hal_get_device_secret(char* data, size_t size, void* reserved)
{
Expand Down
20 changes: 20 additions & 0 deletions hal/src/newhal/deviceid_hal_impl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright (c) 2022 Particle Industries, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either
* version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

// placeholder
28 changes: 28 additions & 0 deletions hal/src/template/deviceid_hal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include "deviceid_hal.h"
#include <stddef.h>
#include "system_error.h"

unsigned HAL_device_ID(uint8_t* dest, unsigned destLen)
{
Expand All @@ -38,3 +39,30 @@ unsigned HAL_Platform_ID()
{
return PLATFORM_ID;
}

void hal_save_device_id(uint32_t offset) {
}

int hal_get_device_serial_number(char* str, size_t size, void* reserved) {
return SYSTEM_ERROR_NOT_SUPPORTED;
}

int hal_get_device_secret(char* data, size_t size, void* reserved) {
return SYSTEM_ERROR_NOT_SUPPORTED;
}

int hal_set_device_secret(char* data, size_t size, void* reserved) {
return SYSTEM_ERROR_NOT_SUPPORTED;
}

int hal_get_device_hw_version(uint32_t* revision, void* reserved) {
return SYSTEM_ERROR_NOT_SUPPORTED;
}

int hal_get_device_hw_model(uint32_t* model, uint32_t* variant, void* reserved) {
return SYSTEM_ERROR_NOT_SUPPORTED;
}

int hal_get_device_hw_info(hal_device_hw_info* info, void* reserved) {
return SYSTEM_ERROR_NOT_SUPPORTED;
}
7 changes: 7 additions & 0 deletions hal/src/tracker/hal_platform_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,10 @@
#define HAL_PLATFORM_MAX_CLOUD_CONNECT_TIME (9*60*1000)

#define PRODUCT_SERIES "boron"

#define PLATFORM_TRACKER_MODEL_BARE_SOM_DEFAULT (0xffff)
#define PLATFORM_TRACKER_MODEL_BARE_SOM (0x0000)
#define PLATFORM_TRACKER_MODEL_EVAL (0x0001)
#define PLATFORM_TRACKER_MODEL_TRACKERONE (0x0002)
#define PLATFORM_TRACKER_MODEL_MONITORONE (0x0003)
#define PLATFORM_TRACKER_MODEL_MAX (PLATFORM_TRACKER_MODEL_MONITORONE)
6 changes: 3 additions & 3 deletions hal/src/tracker/platform_ncp_quectel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ const auto NCP_IDX_SECONDARY_ESP32 = 1;
PlatformNCPIdentifier platform_primary_ncp_identifier() {
// Check the DCT
uint8_t ncpId = 0;
int r = dct_read_app_data_copy(DCT_NCP_ID_OFFSET, &ncpId, 1);
int r = dct_read_app_data_copy(DCT_NCP_ID_OFFSET, &ncpId, sizeof(ncpId));
if (r < 0 || !isValidNcpId(ncpId)) {
// Check the OTP flash
r = hal_exflash_read_special(HAL_EXFLASH_SPECIAL_SECTOR_OTP, NCP_ID_OTP_ADDRESS, &ncpId, 1);
r = hal_exflash_read_special(HAL_EXFLASH_SPECIAL_SECTOR_OTP, NCP_ID_OTP_ADDRESS, &ncpId, sizeof(ncpId));
if (r < 0 || !isValidNcpId(ncpId)) {
ncpId = PlatformNCPIdentifier::PLATFORM_NCP_UNKNOWN;
return PlatformNCPIdentifier::PLATFORM_NCP_UNKNOWN;
}
}
return (PlatformNCPIdentifier)ncpId;
Expand Down
3 changes: 3 additions & 0 deletions system/inc/system_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ extern "C" {
#define SYSTEM_VERSION_v400ALPHA1 SYSTEM_VERSION_ALPHA(4, 0, 0, 1)
#define SYSTEM_VERSION_v400ALPHA2 SYSTEM_VERSION_ALPHA(4, 0, 0, 2)
#define SYSTEM_VERSION_v400BETA1 SYSTEM_VERSION_BETA(4, 0, 0, 1)
#define SYSTEM_VERSION_v500ALPHA1 SYSTEM_VERSION_ALPHA(5, 0, 0, 1)
#define SYSTEM_VERSION_v500ALPHA2 SYSTEM_VERSION_ALPHA(5, 0, 0, 2)
#define SYSTEM_VERSION_v500 SYSTEM_VERSION_DEFAULT(5, 0, 0)
#define SYSTEM_VERSION SYSTEM_VERSION_v400BETA1

/**
Expand Down
10 changes: 10 additions & 0 deletions user/tests/wiring/api/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,16 @@ test(system_version) {
API_COMPILE(Serial.println(SYSTEM_VERSION));
}

test(hardware_info) {
SystemHardwareInfo info;
API_COMPILE({ info = System.hardwareInfo(); });
API_COMPILE(info.isValid());
API_COMPILE(info.model());
API_COMPILE(info.variant());
API_COMPILE(info.revision());
API_COMPILE((bool)info);
}


test(system_freememory) {
uint32_t f;
Expand Down
13 changes: 13 additions & 0 deletions user/tests/wiring/no_fixture/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,3 +418,16 @@ test(SYSTEM_07_system_event_subscription_funcptr_or_non_capturing_lambda) {
assertFalse(waitFor(checkLastParamCloudConnected, 1000)); // should not fire cloud_status_connected
assertEqual(sLastParam, (int)cloud_status_disconnected);
}

test(SYSTEM_08_hardware_info) {
auto info = System.hardwareInfo();
assertTrue(info.isValid());
// Not testing the actual data, as e.g. DVT devices may have some of the data not populated
#if HAL_PLATFORM_NCP
assertNotEqual(info.ncp().size(), 0);
auto ncpIds = info.ncp();
for (int i = 0; i < HAL_PLATFORM_NCP_COUNT; i++) {
assertNotEqual(ncpIds[i], PLATFORM_NCP_UNKNOWN);
}
#endif // HAL_PLATFORM_NCP
}
Loading

0 comments on commit af47d3f

Please sign in to comment.