diff --git a/Libraries/PeriphDrivers/Include/MAX32520/mxc_sys.h b/Libraries/PeriphDrivers/Include/MAX32520/mxc_sys.h index 14a2d860593..1f78fe28c13 100644 --- a/Libraries/PeriphDrivers/Include/MAX32520/mxc_sys.h +++ b/Libraries/PeriphDrivers/Include/MAX32520/mxc_sys.h @@ -28,6 +28,7 @@ #include "mxc_device.h" #include "gcr_regs.h" +#include "mxc_sys_common.h" #ifdef __cplusplus extern "C" { diff --git a/Libraries/PeriphDrivers/Include/MAX32570/mxc_sys.h b/Libraries/PeriphDrivers/Include/MAX32570/mxc_sys.h index 44321547828..ec6071faf99 100644 --- a/Libraries/PeriphDrivers/Include/MAX32570/mxc_sys.h +++ b/Libraries/PeriphDrivers/Include/MAX32570/mxc_sys.h @@ -28,6 +28,7 @@ #include "mxc_device.h" #include "gcr_regs.h" +#include "mxc_sys_common.h" #ifdef __cplusplus extern "C" { diff --git a/Libraries/PeriphDrivers/Include/MAX32650/mxc_sys.h b/Libraries/PeriphDrivers/Include/MAX32650/mxc_sys.h index 35ae798f413..7a9019676b2 100644 --- a/Libraries/PeriphDrivers/Include/MAX32650/mxc_sys.h +++ b/Libraries/PeriphDrivers/Include/MAX32650/mxc_sys.h @@ -42,6 +42,7 @@ #include "spi_regs.h" #include "wdt_regs.h" #include "dma.h" +#include "mxc_sys_common.h" #ifdef __cplusplus extern "C" { diff --git a/Libraries/PeriphDrivers/Include/MAX32655/mxc_sys.h b/Libraries/PeriphDrivers/Include/MAX32655/mxc_sys.h index c6227c9fe7f..b11adeabb99 100644 --- a/Libraries/PeriphDrivers/Include/MAX32655/mxc_sys.h +++ b/Libraries/PeriphDrivers/Include/MAX32655/mxc_sys.h @@ -29,6 +29,7 @@ #include "mxc_device.h" #include "gcr_regs.h" #include "lpgcr_regs.h" +#include "mxc_sys_common.h" #ifdef __cplusplus extern "C" { diff --git a/Libraries/PeriphDrivers/Include/MAX32657/mxc_sys.h b/Libraries/PeriphDrivers/Include/MAX32657/mxc_sys.h index a763886da73..6bd24777f43 100644 --- a/Libraries/PeriphDrivers/Include/MAX32657/mxc_sys.h +++ b/Libraries/PeriphDrivers/Include/MAX32657/mxc_sys.h @@ -26,6 +26,7 @@ #include "mxc_device.h" #include "gcr_regs.h" +#include "mxc_sys_common.h" #ifdef __cplusplus extern "C" { diff --git a/Libraries/PeriphDrivers/Include/MAX32660/mxc_sys.h b/Libraries/PeriphDrivers/Include/MAX32660/mxc_sys.h index ed3e2062bd6..7441f78616e 100644 --- a/Libraries/PeriphDrivers/Include/MAX32660/mxc_sys.h +++ b/Libraries/PeriphDrivers/Include/MAX32660/mxc_sys.h @@ -28,6 +28,7 @@ #include "mxc_device.h" #include "gcr_regs.h" +#include "mxc_sys_common.h" #ifdef __cplusplus extern "C" { diff --git a/Libraries/PeriphDrivers/Include/MAX32662/mxc_sys.h b/Libraries/PeriphDrivers/Include/MAX32662/mxc_sys.h index a483bd94dea..6f3c5eb3961 100644 --- a/Libraries/PeriphDrivers/Include/MAX32662/mxc_sys.h +++ b/Libraries/PeriphDrivers/Include/MAX32662/mxc_sys.h @@ -29,6 +29,7 @@ #include "mxc_device.h" #include "gcr_regs.h" #include "mcr_regs.h" +#include "mxc_sys_common.h" #ifdef __cplusplus extern "C" { diff --git a/Libraries/PeriphDrivers/Include/MAX32665/mxc_sys.h b/Libraries/PeriphDrivers/Include/MAX32665/mxc_sys.h index 274fc132eed..c293087a1dc 100644 --- a/Libraries/PeriphDrivers/Include/MAX32665/mxc_sys.h +++ b/Libraries/PeriphDrivers/Include/MAX32665/mxc_sys.h @@ -28,6 +28,7 @@ #include "mxc_device.h" #include "gcr_regs.h" +#include "mxc_sys_common.h" #ifdef __cplusplus extern "C" { diff --git a/Libraries/PeriphDrivers/Include/MAX32670/mxc_sys.h b/Libraries/PeriphDrivers/Include/MAX32670/mxc_sys.h index 9c897e5fd78..18bfc2e308b 100644 --- a/Libraries/PeriphDrivers/Include/MAX32670/mxc_sys.h +++ b/Libraries/PeriphDrivers/Include/MAX32670/mxc_sys.h @@ -29,6 +29,7 @@ #include "mxc_device.h" #include "gcr_regs.h" #include "mcr_regs.h" +#include "mxc_sys_common.h" #ifdef __cplusplus extern "C" { diff --git a/Libraries/PeriphDrivers/Include/MAX32672/mxc_sys.h b/Libraries/PeriphDrivers/Include/MAX32672/mxc_sys.h index 7b4dd76f618..3975ba28a9b 100644 --- a/Libraries/PeriphDrivers/Include/MAX32672/mxc_sys.h +++ b/Libraries/PeriphDrivers/Include/MAX32672/mxc_sys.h @@ -29,6 +29,7 @@ #include "mxc_device.h" #include "gcr_regs.h" #include "mcr_regs.h" +#include "mxc_sys_common.h" #ifdef __cplusplus extern "C" { diff --git a/Libraries/PeriphDrivers/Include/MAX32675/mxc_sys.h b/Libraries/PeriphDrivers/Include/MAX32675/mxc_sys.h index db5eb7380f3..bbe6a295ee7 100644 --- a/Libraries/PeriphDrivers/Include/MAX32675/mxc_sys.h +++ b/Libraries/PeriphDrivers/Include/MAX32675/mxc_sys.h @@ -29,6 +29,7 @@ #include "mxc_device.h" #include "gcr_regs.h" #include "mcr_regs.h" +#include "mxc_sys_common.h" #ifdef __cplusplus extern "C" { diff --git a/Libraries/PeriphDrivers/Include/MAX32680/mxc_sys.h b/Libraries/PeriphDrivers/Include/MAX32680/mxc_sys.h index 93c407dcea3..734a1ed617b 100644 --- a/Libraries/PeriphDrivers/Include/MAX32680/mxc_sys.h +++ b/Libraries/PeriphDrivers/Include/MAX32680/mxc_sys.h @@ -29,6 +29,7 @@ #include "mxc_device.h" #include "gcr_regs.h" #include "lpgcr_regs.h" +#include "mxc_sys_common.h" #ifdef __cplusplus extern "C" { diff --git a/Libraries/PeriphDrivers/Include/MAX32690/mxc_sys.h b/Libraries/PeriphDrivers/Include/MAX32690/mxc_sys.h index c239d0858a4..8a6105be66e 100644 --- a/Libraries/PeriphDrivers/Include/MAX32690/mxc_sys.h +++ b/Libraries/PeriphDrivers/Include/MAX32690/mxc_sys.h @@ -30,6 +30,7 @@ #include "mxc_device.h" #include "lpgcr_regs.h" #include "gcr_regs.h" +#include "mxc_sys_common.h" #ifdef __cplusplus extern "C" { diff --git a/Libraries/PeriphDrivers/Include/MAX78000/mxc_sys.h b/Libraries/PeriphDrivers/Include/MAX78000/mxc_sys.h index e0055a05819..c961c459f6d 100644 --- a/Libraries/PeriphDrivers/Include/MAX78000/mxc_sys.h +++ b/Libraries/PeriphDrivers/Include/MAX78000/mxc_sys.h @@ -29,6 +29,7 @@ #include "mxc_device.h" #include "lpgcr_regs.h" #include "gcr_regs.h" +#include "mxc_sys_common.h" #ifdef __cplusplus extern "C" { diff --git a/Libraries/PeriphDrivers/Include/MAX78002/mxc_sys.h b/Libraries/PeriphDrivers/Include/MAX78002/mxc_sys.h index 0f2ca395f33..bef52edbf67 100644 --- a/Libraries/PeriphDrivers/Include/MAX78002/mxc_sys.h +++ b/Libraries/PeriphDrivers/Include/MAX78002/mxc_sys.h @@ -30,6 +30,7 @@ #include "mxc_device.h" #include "lpgcr_regs.h" #include "gcr_regs.h" +#include "mxc_sys_common.h" #ifdef __cplusplus extern "C" { diff --git a/Libraries/PeriphDrivers/Source/SYS/mxc_sys_common.c b/Libraries/PeriphDrivers/Source/SYS/mxc_sys_common.c new file mode 100644 index 00000000000..c6c2a077c74 --- /dev/null +++ b/Libraries/PeriphDrivers/Source/SYS/mxc_sys_common.c @@ -0,0 +1,113 @@ +/****************************************************************************** + * + * Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by + * Analog Devices, Inc.), + * Copyright (C) 2023-2024 Analog Devices, Inc. + * + * Licensed 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. + * + ******************************************************************************/ + +/** + * @file mxc_sys.c + * @brief System layer driver. + * @details This driver is used to control the system layer of the device. + */ + +/* **** Includes **** */ +#include +#include +#include "mxc_device.h" +#include "mxc_assert.h" +#include "mxc_sys_common.h" +#include "mxc_sys.h" +#include "flc.h" + +/** + * @ingroup mxc_sys + * @{ + */ + +/* **** Definitions **** */ +#define DAY_CODE_OFFSET 0x14 +#define MONTH_CODE_OFFSET 0x15 +#define YEAR_CODE_OFFSET 0x16 +#define PKG_CODE_OFFSET 0x17 + +#define REG8_VAL(addr) (*(volatile uint8_t *)(MXC_INFO_MEM_BASE + addr)) + +/* **** Globals **** */ +static mxc_sys_package_type_t pkg_type = MXC_SYS_PKG_UNSET; +/* **** Functions **** */ + +/* ************************************************************************** */ +mxc_sys_package_type_t MXC_SYS_GetPackageType(void) +{ + if (pkg_type != MXC_SYS_PKG_UNSET) { + return pkg_type; + } + + mxc_sys_date_t date; + + // Package codes were only introduced when test date was + if (MXC_SYS_GetTestDate(&date) != E_NO_ERROR) { + return MXC_SYS_PKG_UNSET; + } + + MXC_FLC_UnlockInfoBlock(MXC_INFO_MEM_BASE); + + const uint8_t maybe_pkg_type = REG8_VAL(PKG_CODE_OFFSET); + const int err = MXC_SYS_SetPackageType(maybe_pkg_type); + + MXC_FLC_LockInfoBlock(MXC_INFO_MEM_BASE); + + MXC_ASSERT(err == E_NO_ERROR); + + return pkg_type; +} +int MXC_SYS_SetPackageType(mxc_sys_package_type_t new_pkg_type) +{ + switch (new_pkg_type) { + case MXC_SYS_PKG_TQFN: + case MXC_SYS_PKG_BGA: + case MXC_SYS_PKG_WLP: + case MXC_SYS_PKG_UNSET: + pkg_type = new_pkg_type; + return E_NO_ERROR; + default: + return E_BAD_PARAM; + } +} + +int MXC_SYS_GetTestDate(mxc_sys_date_t *date_info) +{ + MXC_ASSERT(date_info); + + MXC_FLC_UnlockInfoBlock(MXC_INFO_MEM_BASE); + + date_info->day = REG8_VAL(DAY_CODE_OFFSET); + date_info->month = REG8_VAL(MONTH_CODE_OFFSET); + date_info->year = REG8_VAL(YEAR_CODE_OFFSET); + + MXC_FLC_LockInfoBlock(MXC_INFO_MEM_BASE); + + // Flash is cleared if not valid + // Year 2255 is valid + if (date_info->month > 12 || date_info->day > 31) { + return E_INVALID; + } + + return E_NO_ERROR; +} + +/**@} end of mxc_sys */ diff --git a/Libraries/PeriphDrivers/Source/SYS/mxc_sys_common.h b/Libraries/PeriphDrivers/Source/SYS/mxc_sys_common.h new file mode 100644 index 00000000000..e8f659fa27a --- /dev/null +++ b/Libraries/PeriphDrivers/Source/SYS/mxc_sys_common.h @@ -0,0 +1,77 @@ +/** + * @file mxc_sys.h + * @brief System level header file. + */ + +/****************************************************************************** + * + * Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by + * Analog Devices, Inc.), + * Copyright (C) 2023-2024 Analog Devices, Inc. + * + * Licensed 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 LIBRARIES_PERIPHDRIVERS_SOURCE_SYS_MXC_SYS_COMMON_H_ +#define LIBRARIES_PERIPHDRIVERS_SOURCE_SYS_MXC_SYS_COMMON_H_ + +#include "mxc_device.h" +#include "gcr_regs.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @defgroup mxc_sys_common System Configuration (MXC_SYS) + * @ingroup syscfg + * @details API for system configuration common to all parts including getting package type. + * @{ + */ + +/** @brief Enumeration to select Package Type*/ +typedef enum { + MXC_SYS_PKG_TQFN = 1, + MXC_SYS_PKG_BGA = 2, + MXC_SYS_PKG_WLP = 3, + MXC_SYS_PKG_UNSET = 0xff +} mxc_sys_package_type_t; + +typedef struct { + uint8_t day, month, year; +} mxc_sys_date_t; + +/** + * @brief Reads the device package type. + * @returns Device Package Type (See mxc_sys_package_t for available options) + */ +mxc_sys_package_type_t MXC_SYS_GetPackageType(void); +/** + * @brief Set the package type. (Acts as an override to what is in Info Block) + * @param new_pkg_type Device Package Type (See mxc_sys_package_t for available options) + * @returns E_NO_ERROR if package exists. + */ +int MXC_SYS_SetPackageType(mxc_sys_package_type_t new_pkg_type); +/** + * @brief Get date of production test + * @param date_info Pointer to date information struct + * @returns E_NO_ERROR if date is valid. E_INVALID otherwise + */ +int MXC_SYS_GetTestDate(mxc_sys_date_t *date_info); + +#ifdef __cplusplus +} +#endif + +#endif // LIBRARIES_PERIPHDRIVERS_SOURCE_SYS_MXC_SYS_COMMON_H_ diff --git a/Libraries/PeriphDrivers/libPeriphDriver.mk b/Libraries/PeriphDrivers/libPeriphDriver.mk index 4bed4f12325..d4993fa3d64 100644 --- a/Libraries/PeriphDrivers/libPeriphDriver.mk +++ b/Libraries/PeriphDrivers/libPeriphDriver.mk @@ -60,6 +60,11 @@ CMSIS_ROOT=../CMSIS endif include ${CMSIS_ROOT}/../PeriphDrivers/$(TARGET_LC)_files.mk +PERIPH_DRIVER_C_FILES += $(PERIPH_DIR)/Source/SYS/mxc_assert.c +PERIPH_DRIVER_C_FILES += $(PERIPH_DIR)/Source/SYS/mxc_delay.c +PERIPH_DRIVER_C_FILES += $(PERIPH_DIR)/Source/SYS/mxc_lock.c +PERIPH_DRIVER_C_FILES += $(PERIPH_DIR)/Source/SYS/nvic_table.c +PERIPH_DRIVER_C_FILES += $(PERIPH_DIR)/Source/SYS/mxc_sys_common.c PERIPH_DRIVER_C_FILES += $(SOURCE_DIR)/SYS/mxc_assert.c PERIPH_DRIVER_C_FILES += $(SOURCE_DIR)/SYS/mxc_delay.c diff --git a/Libraries/PeriphDrivers/max32655_files.mk b/Libraries/PeriphDrivers/max32655_files.mk index 19707aa9b77..55a581c0272 100644 --- a/Libraries/PeriphDrivers/max32655_files.mk +++ b/Libraries/PeriphDrivers/max32655_files.mk @@ -52,6 +52,7 @@ PINS_FILE ?= $(SOURCE_DIR)/SYS/pins_me17.c PERIPH_DRIVER_C_FILES += $(PINS_FILE) PERIPH_DRIVER_C_FILES += $(SOURCE_DIR)/SYS/sys_me17.c + PERIPH_DRIVER_INCLUDE_DIR += $(SOURCE_DIR)/ADC PERIPH_DRIVER_C_FILES += $(SOURCE_DIR)/ADC/adc_me17.c PERIPH_DRIVER_C_FILES += $(SOURCE_DIR)/ADC/adc_reva.c diff --git a/Libraries/PeriphDrivers/periphdriver.mk b/Libraries/PeriphDrivers/periphdriver.mk index a1ed9bff8a4..72220937ff1 100644 --- a/Libraries/PeriphDrivers/periphdriver.mk +++ b/Libraries/PeriphDrivers/periphdriver.mk @@ -84,7 +84,8 @@ export COMPILER # export MFLOAT_ABI include ${PERIPH_DRIVER_DIR}/$(TARGET_LC)_files.mk -IPATH += ${PERIPH_DRIVER_INCLUDE_DIR} +IPATH += ${PERIPH_DRIVER_INCLUDE_DIR} ${PERIPH_DRIVER_DIR}/Source/SYS + ifeq "$(PD_LIBRARY_VARIANT)" "" PERIPH_DRIVER_LIB_FILENAME := libPeriphDriver else @@ -105,4 +106,4 @@ clean.periph: @$(MAKE) -f ${PERIPH_DRIVER_DIR}/libPeriphDriver.mk BUILD_DIR=${PERIPH_DRIVER_BUILD_DIR} PERIPH_DRIVER_LIB_FILENAME=$(PERIPH_DRIVER_LIB_FILENAME) clean query.periphdrivers: - @$(MAKE) -f ${PERIPH_DRIVER_DIR}/libPeriphDriver.mk query QUERY_VAR="${QUERY_VAR}" \ No newline at end of file + @$(MAKE) -f ${PERIPH_DRIVER_DIR}/libPeriphDriver.mk query QUERY_VAR="${QUERY_VAR}"