Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(PeriphDrivers): API to get the package type of part and test date. #1243

Open
wants to merge 32 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
ed44792
added basic api for get package and date code
EricB-ADI Oct 23, 2024
dd1330d
added common c files to libPeriphDriver.mk
EricB-ADI Oct 24, 2024
8dc43d3
added common package info functons and structs to all parts
EricB-ADI Oct 25, 2024
4266b04
updated get test date to unlock lock info block
EricB-ADI Oct 25, 2024
183116d
clang-format bot reformatting.
EricB-ADI Oct 25, 2024
2945345
fixed redef error
EricB-ADI Oct 25, 2024
d20c505
fixed copy from rebase
EricB-ADI Oct 25, 2024
e0da363
format
EricB-ADI Oct 25, 2024
a773217
format h
EricB-ADI Oct 25, 2024
1665ad7
add sys common to all mxc_sys.h
EricB-ADI Oct 25, 2024
f8d3088
remove redef from 655 mxc_sys.h
EricB-ADI Oct 25, 2024
698bc6e
added mxc_sys_common.h to periphdriver.mk
EricB-ADI Oct 25, 2024
b3d0cfb
clang-format bot reformatting.
EricB-ADI Oct 25, 2024
6f90746
added sys_common to me17
EricB-ADI Oct 25, 2024
092ae59
add sys common to 655
EricB-ADI Oct 25, 2024
1f0f538
copy sys common to part files
EricB-ADI Oct 25, 2024
654b708
removed uneeded headers
EricB-ADI Oct 28, 2024
8eea9e4
removed unused variable
EricB-ADI Oct 28, 2024
5d691ce
Merge branch 'main' into feat/usn-pkg-type
EricB-ADI Oct 28, 2024
e805469
format
EricB-ADI Oct 28, 2024
8e47472
update header guard comment
EricB-ADI Oct 28, 2024
1c60a1c
rename sys common to mxc_sys_common
EricB-ADI Oct 28, 2024
b03675b
fix linter issues
EricB-ADI Nov 4, 2024
806dacb
fixed header guard common
EricB-ADI Nov 4, 2024
8b43164
Merge branch 'main' into feat/usn-pkg-type
EricB-ADI Nov 8, 2024
5873ce4
added sys common to IPATH
EricB-ADI Nov 8, 2024
c4a4abd
remove sys common from individual parts
EricB-ADI Nov 8, 2024
6efb15c
lint
EricB-ADI Nov 8, 2024
598311a
Merge branch 'main' into feat/usn-pkg-type
EricB-ADI Nov 8, 2024
25e7711
include .h in .c
EricB-ADI Nov 8, 2024
4a4cfef
include mxc-sys.h
EricB-ADI Nov 8, 2024
63dc004
Merge branch 'main' into feat/usn-pkg-type
EricB-ADI Nov 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Libraries/PeriphDrivers/Include/MAX32520/mxc_sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

#include "mxc_device.h"
#include "gcr_regs.h"
#include "mxc_sys_common.h"

#ifdef __cplusplus
extern "C" {
Expand Down
1 change: 1 addition & 0 deletions Libraries/PeriphDrivers/Include/MAX32570/mxc_sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

#include "mxc_device.h"
#include "gcr_regs.h"
#include "mxc_sys_common.h"

#ifdef __cplusplus
extern "C" {
Expand Down
1 change: 1 addition & 0 deletions Libraries/PeriphDrivers/Include/MAX32650/mxc_sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "spi_regs.h"
#include "wdt_regs.h"
#include "dma.h"
#include "mxc_sys_common.h"

#ifdef __cplusplus
extern "C" {
Expand Down
1 change: 1 addition & 0 deletions Libraries/PeriphDrivers/Include/MAX32657/mxc_sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include "mxc_device.h"
#include "gcr_regs.h"
#include "mxc_sys_common.h"

#ifdef __cplusplus
extern "C" {
Expand Down
1 change: 1 addition & 0 deletions Libraries/PeriphDrivers/Include/MAX32660/mxc_sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

#include "mxc_device.h"
#include "gcr_regs.h"
#include "mxc_sys_common.h"

#ifdef __cplusplus
extern "C" {
Expand Down
1 change: 1 addition & 0 deletions Libraries/PeriphDrivers/Include/MAX32662/mxc_sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
1 change: 1 addition & 0 deletions Libraries/PeriphDrivers/Include/MAX32665/mxc_sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

#include "mxc_device.h"
#include "gcr_regs.h"
#include "mxc_sys_common.h"

#ifdef __cplusplus
extern "C" {
Expand Down
1 change: 1 addition & 0 deletions Libraries/PeriphDrivers/Include/MAX32670/mxc_sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
1 change: 1 addition & 0 deletions Libraries/PeriphDrivers/Include/MAX32672/mxc_sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
1 change: 1 addition & 0 deletions Libraries/PeriphDrivers/Include/MAX32675/mxc_sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
1 change: 1 addition & 0 deletions Libraries/PeriphDrivers/Include/MAX32680/mxc_sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
1 change: 1 addition & 0 deletions Libraries/PeriphDrivers/Include/MAX32690/mxc_sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
1 change: 1 addition & 0 deletions Libraries/PeriphDrivers/Include/MAX78000/mxc_sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
1 change: 1 addition & 0 deletions Libraries/PeriphDrivers/Include/MAX78002/mxc_sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
77 changes: 77 additions & 0 deletions Libraries/PeriphDrivers/Source/SYS/mxc_sys_common.h
Original file line number Diff line number Diff line change
@@ -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_INCLUDE_MXC_SYS_COMMON_H_
#define LIBRARIES_PERIPHDRIVERS_INCLUDE_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_INCLUDE_MAX32520_MXC_SYS_H_
117 changes: 117 additions & 0 deletions Libraries/PeriphDrivers/Source/SYS/sys_common.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/******************************************************************************
*
* 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 <stddef.h>
#include "mxc_device.h"
#include "mxc_assert.h"
#include "mxc_sys.h"
#include "flc.h"
#include "mxc_delay.h"
#include "gcr_regs.h"
#include "fcr_regs.h"
#include "mcr_regs.h"
#include <stdbool.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;
bool info_block_unlocked = false;
/* **** 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 */
5 changes: 5 additions & 0 deletions Libraries/PeriphDrivers/libPeriphDriver.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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/sys_common.c

# # Where to find header files for this project
IPATH += $(PERIPH_DRIVER_INCLUDE_DIR)
Expand Down
6 changes: 1 addition & 5 deletions Libraries/PeriphDrivers/max32655_files.mk
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,10 @@ PERIPH_DRIVER_INCLUDE_DIR += $(INCLUDE_DIR)/$(TARGET_UC)/
PINS_FILE ?= $(SOURCE_DIR)/SYS/pins_me17.c

# Source files
PERIPH_DRIVER_C_FILES += $(SOURCE_DIR)/SYS/mxc_assert.c
PERIPH_DRIVER_C_FILES += $(SOURCE_DIR)/SYS/mxc_delay.c
PERIPH_DRIVER_C_FILES += $(SOURCE_DIR)/SYS/mxc_lock.c
PERIPH_DRIVER_C_FILES += $(SOURCE_DIR)/SYS/nvic_table.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
Expand Down Expand Up @@ -147,4 +144,3 @@ PERIPH_DRIVER_C_FILES += $(SOURCE_DIR)/WDT/wdt_revb.c
PERIPH_DRIVER_INCLUDE_DIR += $(SOURCE_DIR)/WUT
PERIPH_DRIVER_C_FILES += $(SOURCE_DIR)/WUT/wut_me17.c
PERIPH_DRIVER_C_FILES += $(SOURCE_DIR)/WUT/wut_reva.c

4 changes: 3 additions & 1 deletion Libraries/PeriphDrivers/periphdriver.mk
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ export COMPILER

include ${PERIPH_DRIVER_DIR}/$(TARGET_LC)_files.mk
IPATH += ${PERIPH_DRIVER_INCLUDE_DIR}
IPATH += ${PERIPH_DRIVER_DIR}/SYS/Source

ifeq "$(PD_LIBRARY_VARIANT)" ""
PERIPH_DRIVER_LIB_FILENAME := libPeriphDriver
else
Expand All @@ -105,4 +107,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}"
@$(MAKE) -f ${PERIPH_DRIVER_DIR}/libPeriphDriver.mk query QUERY_VAR="${QUERY_VAR}"