estsdrivershwinfoapisrcmain.c
hwinfo: add driver support for NXP i.mx RT device ID
Add driver support for NXP i.mx RT ID device.
This device has an ID of 8 bytes. #include //函数接口定义
#include
#include
#include
/*
* @addtogroup t_hwinfo_get_device_id_api
* @{
* @defgroup t_hwinfo_get_device_id test_hwinfo_get_device_id
* @brief TestPurpose: verify device id get works
* @details
* - Test Steps
* -# Read the ID
* -# Check if to many bytes are written to the buffer
* -# Check if UID is plausible
* - Expected Results
* -# Device uid with correct length should be written to the buffer.
* @}
*/
#define BUFFER_LENGTH 17
#define BUFFER_CANARY 0xFF
/*
* Function invokes the get_entropy callback in driver
* to get the random data and fill to passed buffer
*/
static void test_device_id_get(void)
{
u8_t buffer_1[BUFFER_LENGTH];
u8_t buffer_2[BUFFER_LENGTH];
ssize_t length_read_1, length_read_2;
int i;
length_read_1 = hwinfo_get_device_id(buffer_1, 1); //第1次测试
zassert_not_equal(length_read_1, -ENOTSUP, "Not supported by hardware");
zassert_false((length_read_1 < 0), "Error returned: %d", length_read_1);
zassert_not_equal(length_read_1, 0, "Zero bytes read");
zassert_equal(length_read_1, 1, "Length not adhered");
memset(buffer_1, BUFFER_CANARY, sizeof(buffer_1));
length_read_1 = hwinfo_get_device_id(buffer_1, BUFFER_LENGTH - 1);
zassert_equal(buffer_1[length_read_1], BUFFER_CANARY,
"Too many bytes are written");
memcpy(buffer_2, buffer_1, length_read_1);
for (i = 0; i < BUFFER_LENGTH; i++) {
buffer_1[i] ^= 0xA5;
}
length_read_2 = hwinfo_get_device_id(buffer_1, BUFFER_LENGTH - 1); //第2次函数
zassert_equal(length_read_1, length_read_2, "Length varied"); //比较多次读是否出错
zassert_equal(buffer_1[length_read_1], (BUFFER_CANARY ^ 0xA5),
"Too many bytes are written");
//比较2次Buffer 读取是否出错
for (i = 0; i < length_read_1; i++) {
zassert_equal(buffer_1[i], buffer_2[i],
"Two consecutively readings don't match");
}
}
1.1 头文件
/**
* @brief Copy the device id to a buffer
*
* This routine copies "length" number of bytes of the device ID to the buffer.
* If the device ID is smaller then length, the rest of the buffer is left unchanged.
* The ID depends on the hardware and is not guaranteed unique.
*
* @param buffer Buffer to write the ID to.
* @param length Max length of the buffer.
*
* @retval size of the device ID copied or negative on error.
*/
__syscall ssize_t hwinfo_get_device_id(u8_t *buffer, size_t length);
ssize_t z_impl_hwinfo_get_device_id(u8_t *buffer, size_t length); //内涵函数定义
menuconfig HWINFO
bool "Hardware Information driver"
help
Enable hwinfo driver.
if HWINFO
config HWINFO_SHELL
bool "Enable HWINFO Shell"
depends on SHELL
help
Enable hwinfo Shell for testing.
config HWINFO_STM32
bool "STM32 hwinfo"
default y
depends on SOC_FAMILY_STM32
select USE_STM32_LL_UTILS
help
Enable STM32 hwinfo driver.
config HWINFO_IMXRT
bool "NXP i.mx RT device ID"
default y
depends on SOC_SERIES_IMX_RT
help
Enable NXP i.mx RT hwinfo driver.
config HWINFO_SAM
bool "Atmel SAM device ID"
default y
depends on SOC_FAMILY_SAM
help
Enable Atmel SAM hwinfo driver.
endif