From 3aed0aa641ad2f37e5e528dac896174ede082d1e Mon Sep 17 00:00:00 2001 From: Jari van Ewijk Date: Thu, 13 Jan 2022 15:28:05 +0100 Subject: [PATCH] S32K1XX: implement uniqueid --- arch/arm/src/s32k1xx/Make.defs | 2 +- arch/arm/src/s32k1xx/s32k1xx_uid.c | 79 +++++++++++++++++++ arch/arm/src/s32k1xx/s32k1xx_uid.h | 42 ++++++++++ boards/arm/s32k1xx/s32k144evb/src/Makefile | 4 + .../arm/s32k1xx/s32k144evb/src/s32k1xx_uid.c | 57 +++++++++++++ 5 files changed, 183 insertions(+), 1 deletion(-) create mode 100644 arch/arm/src/s32k1xx/s32k1xx_uid.c create mode 100644 arch/arm/src/s32k1xx/s32k1xx_uid.h create mode 100644 boards/arm/s32k1xx/s32k144evb/src/s32k1xx_uid.c diff --git a/arch/arm/src/s32k1xx/Make.defs b/arch/arm/src/s32k1xx/Make.defs index b63f0fdd9c..06e3fa112e 100644 --- a/arch/arm/src/s32k1xx/Make.defs +++ b/arch/arm/src/s32k1xx/Make.defs @@ -38,7 +38,7 @@ endif CHIP_CSRCS = s32k1xx_start.c s32k1xx_lowputc.c s32k1xx_clockconfig.c CHIP_CSRCS += s32k1xx_periphclocks.c s32k1xx_pin.c s32k1xx_pingpio.c -CHIP_CSRCS += s32k1xx_idle.c +CHIP_CSRCS += s32k1xx_idle.c s32k1xx_uid.c ifeq ($(CONFIG_BOOT_RUNFROMFLASH),y) CHIP_CSRCS += s32k1xx_flashcfg.c diff --git a/arch/arm/src/s32k1xx/s32k1xx_uid.c b/arch/arm/src/s32k1xx/s32k1xx_uid.c new file mode 100644 index 0000000000..1aebed0e93 --- /dev/null +++ b/arch/arm/src/s32k1xx/s32k1xx_uid.c @@ -0,0 +1,79 @@ +/**************************************************************************** + * arch/arm/src/s32k1xx/s32k1xx_uid.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include + +#include "arm_arch.h" + +#include "hardware/s32k1xx_sim.h" +#include "s32k1xx_uid.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: s32k1xx_get_uniqueid + ****************************************************************************/ + +void s32k1xx_get_uniqueid(uint8_t *uniqueid) +{ + uint32_t regval; + + DEBUGASSERT(uniqueid != NULL); + + /* Retrieve all 16 bytes (128 bits) of the unique identifier and store the + * individual bytes in order from lowest byte first to highest byte last. + */ + + regval = getreg32(S32K1XX_SIM_UIDL); + + uniqueid[0] = (uint8_t)((regval & 0x000000ff) >> 0); + uniqueid[1] = (uint8_t)((regval & 0x0000ff00) >> 8); + uniqueid[2] = (uint8_t)((regval & 0x00ff0000) >> 16); + uniqueid[3] = (uint8_t)((regval & 0xff000000) >> 24); + + regval = getreg32(S32K1XX_SIM_UIDML); + + uniqueid[4] = (uint8_t)((regval & 0x000000ff) >> 0); + uniqueid[5] = (uint8_t)((regval & 0x0000ff00) >> 8); + uniqueid[6] = (uint8_t)((regval & 0x00ff0000) >> 16); + uniqueid[7] = (uint8_t)((regval & 0xff000000) >> 24); + + regval = getreg32(S32K1XX_SIM_UIDMH); + + uniqueid[8] = (uint8_t)((regval & 0x000000ff) >> 0); + uniqueid[9] = (uint8_t)((regval & 0x0000ff00) >> 8); + uniqueid[10] = (uint8_t)((regval & 0x00ff0000) >> 16); + uniqueid[11] = (uint8_t)((regval & 0xff000000) >> 24); + + regval = getreg32(S32K1XX_SIM_UIDH); + + uniqueid[12] = (uint8_t)((regval & 0x000000ff) >> 0); + uniqueid[13] = (uint8_t)((regval & 0x0000ff00) >> 8); + uniqueid[14] = (uint8_t)((regval & 0x00ff0000) >> 16); + uniqueid[15] = (uint8_t)((regval & 0xff000000) >> 24); +} diff --git a/arch/arm/src/s32k1xx/s32k1xx_uid.h b/arch/arm/src/s32k1xx/s32k1xx_uid.h new file mode 100644 index 0000000000..53573d9040 --- /dev/null +++ b/arch/arm/src/s32k1xx/s32k1xx_uid.h @@ -0,0 +1,42 @@ +/**************************************************************************** + * arch/arm/src/s32k1xx/s32k1xx_uid.h + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __ARCH_ARM_SRC_S32K1XX_S32K1XX_UID_H +#define __ARCH_ARM_SRC_S32K1XX_S32K1XX_UID_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define S32K1XX_UID_SIZE 16 + +/**************************************************************************** + * Public Functions Prototypes + ****************************************************************************/ + +void s32k1xx_get_uniqueid(uint8_t *uniqueid); + +#endif /* __ARCH_ARM_SRC_S32K1XX_S32K1XX_UID_H */ diff --git a/boards/arm/s32k1xx/s32k144evb/src/Makefile b/boards/arm/s32k1xx/s32k144evb/src/Makefile index 8239f43b85..c476e5773a 100644 --- a/boards/arm/s32k1xx/s32k144evb/src/Makefile +++ b/boards/arm/s32k1xx/s32k144evb/src/Makefile @@ -37,6 +37,10 @@ ifeq ($(CONFIG_BOARDCTL),y) CSRCS += s32k1xx_appinit.c endif +ifeq ($(CONFIG_BOARDCTL_UNIQUEID),y) +CSRCS += s32k1xx_uid.c +endif + ifeq ($(CONFIG_S32K1XX_LPI2C),y) CSRCS += s32k1xx_i2c.c endif diff --git a/boards/arm/s32k1xx/s32k144evb/src/s32k1xx_uid.c b/boards/arm/s32k1xx/s32k144evb/src/s32k1xx_uid.c new file mode 100644 index 0000000000..4f3c2fa78d --- /dev/null +++ b/boards/arm/s32k1xx/s32k144evb/src/s32k1xx_uid.c @@ -0,0 +1,57 @@ +/**************************************************************************** + * boards/arm/s32k1xx/s32k144evb/src/s32k1xx_uid.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include +#include + +#include "s32k1xx_uid.h" + +#ifdef CONFIG_BOARDCTL_UNIQUEID + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: board_uniqueid + ****************************************************************************/ + +int board_uniqueid(FAR uint8_t *uniqueid) +{ + if (uniqueid == NULL) + { + return -EINVAL; + } + + s32k1xx_get_uniqueid(uniqueid); + + return OK; +} + +#endif /* CONFIG_BOARDCTL_UNIQUEID */