Imported more library files

Not compiling currently
This commit is contained in:
2025-04-12 23:37:19 +01:00
parent 264a3462e0
commit 9d06f983af
2518 changed files with 1021900 additions and 52 deletions

View File

@@ -0,0 +1,104 @@
/***************************************************************************//**
* @file
* @brief NVM3 API definition (Device Specific).
*******************************************************************************
* # License
* <b>Copyright 2018 Silicon Laboratories Inc. www.silabs.com</b>
*******************************************************************************
*
* SPDX-License-Identifier: Zlib
*
* The licensor of this software is Silicon Laboratories Inc.
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*
******************************************************************************/
#ifndef NVM3_H
#define NVM3_H
#ifndef NVM3_HOST_BUILD
#include "em_device.h"
#endif
#include "nvm3_generic.h"
#ifdef __cplusplus
extern "C" {
#endif
/***************************************************************************//**
* @addtogroup nvm3
* @{
******************************************************************************/
#define NVM3_MIN_FRAGMENT_COUNT (2U) ///< The minimum number of fragments
#if defined(FLASH_PAGE_SIZE)
#define NVM3_MAX_OBJECT_SIZE_X (NVM3_MAX_OBJECT_SIZE + 8) // Adjust for an object header
#define FLASH_PAGE_SIZE_X (FLASH_PAGE_SIZE - 20) // Adjust for a page header
#define NVM3_FRAGMENT_COUNT (((NVM3_MAX_OBJECT_SIZE_X - 1) / FLASH_PAGE_SIZE_X) + NVM3_MIN_FRAGMENT_COUNT)
#endif
typedef struct nvm3_ObjFrag {
uint8_t idx; // Fragment index
bool isFirstFragFound; // The object first fragment found
bool isLastFragFound; // The object last fragment found
#if defined(FLASH_PAGE_SIZE)
nvm3_ObjFragDetail_t detail[NVM3_FRAGMENT_COUNT];
#else
nvm3_ObjFragDetail_t detail[NVM3_MIN_FRAGMENT_COUNT];
#endif
} nvm3_ObjFrag_t;
typedef struct nvm3_Obj {
nvm3_ObjectKey_t key; // The object key
struct nvm3_Obj *objAdr; // The object pointer
struct nvm3_Obj *nextObjAdr; // The next object pointer
const void *srcPtr; // May be used to carry the source address of the data
size_t totalLen; // The object total length
uint8_t objType; // The object type
bool isHdrValid; // The object header is valid
bool isValid; // The object is valid
bool isFragmented; // The object is fragmented
nvm3_ObjFrag_t frag; // The object fragment information
} nvm3_Obj_t;
// Definition of NVM3 variables
/// @brief A variable used by the NVM3 functions.
extern nvm3_Obj_t nvm3_internalObjectHandleA;
/// @brief A variable used by the NVM3 functions.
extern nvm3_Obj_t nvm3_internalObjectHandleB;
/// @brief A variable used by the NVM3 functions.
extern nvm3_Obj_t nvm3_internalObjectHandleC;
/// @brief A variable used by the NVM3 functions.
extern nvm3_Obj_t nvm3_internalObjectHandleD;
#if defined(NVM3_SECURITY)
/// @brief A variable used by the NVM3 functions.
extern nvm3_Obj_t nvm3_internalObjectHandleE;
#endif
/// @brief A variable that must contain the maximum number of object fragments.
extern const uint8_t nvm3_maxFragmentCount;
/// @brief A variable containing the object handle size in bytes.
extern const size_t nvm3_objHandleSize;
#ifdef __cplusplus
}
#endif
/// @} end group nvm3 ****************************************************/
#endif /* NVM3_H */

View File

@@ -0,0 +1,71 @@
/***************************************************************************//**
* @file
* @brief NVM3 object cache
*******************************************************************************
* # License
* <b>Copyright 2018 Silicon Laboratories Inc. www.silabs.com</b>
*******************************************************************************
*
* SPDX-License-Identifier: Zlib
*
* The licensor of this software is Silicon Laboratories Inc.
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*
******************************************************************************/
#ifndef NVM3_CACHE_H
#define NVM3_CACHE_H
#include "nvm3_config.h"
#include "nvm3.h"
#include "nvm3_object.h"
#ifdef __cplusplus
extern "C" {
#endif
/*******************************************************************************
******************************* TYPES *************************************
******************************************************************************/
typedef bool (*nvm3_CacheScanCallback_t)(nvm3_Cache_t *h, nvm3_ObjectKey_t key, nvm3_ObjGroup_t group, nvm3_ObjPtr_t obj, void *user);
/*******************************************************************************
*************************** PROTOTYPES ************************************
******************************************************************************/
void nvm3_cacheOpen(nvm3_Cache_t *h, nvm3_CacheEntry_t *ptr, size_t count);
void nvm3_cacheClear(nvm3_Cache_t *h);
void nvm3_cacheDelete(nvm3_Cache_t *h, nvm3_ObjectKey_t key);
nvm3_ObjPtr_t nvm3_cacheGet(nvm3_Cache_t *h, nvm3_ObjectKey_t key, nvm3_ObjGroup_t *group);
void nvm3_cacheSet(nvm3_Cache_t *h, nvm3_ObjectKey_t key, nvm3_ObjPtr_t obj, nvm3_ObjGroup_t group);
void nvm3_cacheScan(nvm3_Cache_t *h, nvm3_CacheScanCallback_t cacheScanCallback, void *user);
#if defined(NVM3_OPTIMIZATION) && (NVM3_OPTIMIZATION == 1)
sl_status_t nvm3_cacheSort(nvm3_Cache_t *h);
bool nvm3_cacheUpdateEntry(nvm3_Cache_t *h, nvm3_ObjectKey_t key, nvm3_ObjPtr_t obj, nvm3_ObjGroup_t group);
sl_status_t nvm3_cacheAddEntry(nvm3_Cache_t *h, nvm3_ObjectKey_t key, nvm3_ObjPtr_t obj, nvm3_ObjGroup_t group);
sl_status_t nvm3_cacheGetIdx(nvm3_Cache_t *h, nvm3_ObjectKey_t key, size_t low, size_t high, size_t *idx);
void nvm3_cacheOrganize(nvm3_Cache_t *h, size_t idx);
#endif
#ifdef __cplusplus
}
#endif
#endif /* NVM3_CACHE_H */

View File

@@ -0,0 +1,71 @@
/***************************************************************************//**
* @file
* @brief NVM3 definition of the default data structures.
*******************************************************************************
* # License
* <b>Copyright 2018 Silicon Laboratories Inc. www.silabs.com</b>
*******************************************************************************
*
* SPDX-License-Identifier: Zlib
*
* The licensor of this software is Silicon Laboratories Inc.
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*
******************************************************************************/
#ifndef NVM3_DEFAULT_H
#define NVM3_DEFAULT_H
#include "nvm3_generic.h"
/***************************************************************************//**
* @addtogroup nvm3
* @{
******************************************************************************/
/***************************************************************************//**
* @addtogroup nvm3default NVM3 Default Instance
* @brief NVM3 default instance functions and handles
* @{
******************************************************************************/
extern nvm3_Handle_t *nvm3_defaultHandle; ///< The default handle.
extern nvm3_Init_t *nvm3_defaultInit; ///< Default initialization data.
/***************************************************************************//**
* @brief
* Initialize the default NVM3 instance.
* Once initialized the instance can be accessed through the NVM3 API using
* nvm3_defaultHandle as the nvm3_Handle_t handle.
*
* @return
* @ref SL_STATUS_OK on success and a NVM3 @ref sl_status_t on failure.
******************************************************************************/
sl_status_t nvm3_initDefault(void);
/***************************************************************************//**
* @brief
* Deinit the default NVM3 instance.
*
* @return
* @ref SL_STATUS_OK on success and a NVM3 @ref sl_status_t on failure.
******************************************************************************/
sl_status_t nvm3_deinitDefault(void);
/** @} (end addtogroup nvm3default) */
/** @} (end addtogroup nvm3) */
#endif /* NVM3_DEFAULT_H */

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,249 @@
/***************************************************************************//**
* @file
* @brief NVM3 driver HAL
*******************************************************************************
* # License
* <b>Copyright 2018 Silicon Laboratories Inc. www.silabs.com</b>
*******************************************************************************
*
* SPDX-License-Identifier: Zlib
*
* The licensor of this software is Silicon Laboratories Inc.
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*
******************************************************************************/
#ifndef NVM3_HAL_H
#define NVM3_HAL_H
#include "sl_status.h"
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
#ifdef NVM3_HOST_BUILD
#include "nvm3_hal_host.h"
#else
#include "sl_assert.h"
#include "sl_common.h"
#endif
#ifdef __cplusplus
extern "C" {
#endif
/***************************************************************************//**
* @addtogroup nvm3
* @{
******************************************************************************/
/***************************************************************************//**
* @addtogroup nvm3hal NVM3 HAL
* @brief NVM3 Hardware Abstraction Layer
* @{
* @details
* This module provides the interface to the NVM. By having all NVM access
* functions in a separate file, it is possible to support different hardware
* by substituting the functions in this module.
*
* @note These functions are used by the NVM3 and should not be used by
* any applications.
******************************************************************************/
/******************************************************************************
****************************** MACROS **********************************
*****************************************************************************/
#define NVM3_HAL_WRITE_SIZE_32 0 ///< Only single writes are allowed
#define NVM3_HAL_WRITE_SIZE_16 1 ///< Two writes are allowed
#define NVM3_HAL_NVM_ACCESS_NONE 0 ///< No access
#define NVM3_HAL_NVM_ACCESS_RD 1 ///< Read access
#define NVM3_HAL_NVM_ACCESS_RDWR 2 ///< Read and write access
#define NVM3_HAL_NVM_ACCESS_NOP 3 ///< Ignore
/// @cond DO_NOT_INCLUDE_WITH_DOXYGEN
#define nvm3_halOpen(hal, a, b) ((hal)->open((a), (b)))
#define nvm3_halClose(hal) ((hal)->close())
#define nvm3_halGetInfo(hal, a) ((hal)->getInfo(a))
#define nvm3_halNvmAccess(hal, a) ((hal)->access(a))
#define nvm3_halReadWords(hal, a, b, c) ((hal)->readWords((a), (b), (c)))
#define nvm3_halWriteWords(hal, a, b, c) ((hal)->writeWords((a), (b), (c)))
#define nvm3_halPageErase(hal, a) ((hal)->pageErase(a))
/// @endcond
/******************************************************************************
****************************** TYPEDEFS **********************************
*****************************************************************************/
/// @brief Pointer to NVM
typedef void *nvm3_HalPtr_t;
/// @brief Device NVM capabilities
typedef struct nvm3_HalInfo {
uint16_t deviceFamilyPartNumber; ///< Device family or part number.
uint8_t writeSize; ///< Write-size: 0=32-bit, 1=16-bit.
uint8_t memoryMapped; ///< Memory-mapped: 0=not memory mapped, 1=memory mapped.
size_t pageSize; ///< The data storage page size.
uint64_t systemUnique; ///< Obsolete. Was used to support external flash.
} nvm3_HalInfo_t;
typedef uint8_t nvm3_HalNvmAccessCode_t; ///< Definition of the access data type.
/*******************************************************************************
***************************** PROTOTYPES **********************************
******************************************************************************/
/***************************************************************************//**
* @brief
* Open the NVM3 HAL for usage.
*
* @details
* This function must be run at initialization, before any other functions
* are called. It is used to call necessary startup routines before the
* hardware can be accessed.
*
* @param[in] nvmAdr
* A pointer to the destination in NVM.
*
* @param[in] nvmSize
* The total size of the NVM.
*
* @return
* The result of the open call.
* @ref SL_STATUS_OK on success or a NVM3 @ref sl_status_t on failure.
******************************************************************************/
typedef sl_status_t (*nvm3_HalOpen_t)(nvm3_HalPtr_t nvmAdr, size_t nvmSize);
/***************************************************************************//**
* @brief
* Close the NVM3 HAL for usage.
*
* @details
* This function should be called at program termination.
* Should be done before any graceful halts.
******************************************************************************/
typedef void(*nvm3_HalClose_t)(void);
/***************************************************************************//**
* @brief
* Retrieve device information.
*
* @details
* This function is used to retrieve information about the device properties,
* such as the device family, write size, whether the NVM is memory mapped or
* not, and finally the NVM page size.
*
* @param[in] info
* A pointer to a structure that will receive the device information.
******************************************************************************/
typedef sl_status_t (*nvm3_HalGetInfo_t)(nvm3_HalInfo_t *info);
/***************************************************************************//**
* @brief
* Control read and write access to the NVM.
*
* @details
* This function is used to control the access to the NVM. It can be either
* read, write, or none.
*
* @param[in] access
* The requested access.
******************************************************************************/
typedef void (*nvm3_HalNvmAccess_t)(nvm3_HalNvmAccessCode_t access);
/***************************************************************************//**
* @brief
* Erase a page in the NVM.
*
* @details
* This function is used to erase an NVM page.
*
* @param[in] nvmAdr
* A memory address pointing to the start of the page to erase.
*
* @return
* The result of the erase operation.
******************************************************************************/
typedef sl_status_t (*nvm3_HalPageErase_t)(nvm3_HalPtr_t nvmAdr);
/***************************************************************************//**
* @brief
* Read data from NVM.
*
* @details
* This function is used to read data from the NVM. It will be a
* blocking call, since the thread asking for data to be read cannot continue
* without the data.
*
* @param[in] nvmAdr
* A memory address in NVM where data will be read.
*
* @param[in] *dst
* A pointer to the destination buffer.
*
* @param[in] wordCnt
* The number of words to read.
******************************************************************************/
typedef sl_status_t (*nvm3_HalReadWords_t)(nvm3_HalPtr_t nvmAdr, void *dst, size_t wordCnt);
/***************************************************************************//**
* @brief
* Write data to the NVM.
*
* @details
* This function is used to write data to the NVM. This is a blocking
* function.
*
* @param[in] nvmAdr
* A memory address in NVM where data will be written.
*
* @param[in] *pSrc
* A pointer to the source data.
*
* @param[in] cnt
* The number of words to write.
*
* @return
* The result of the write operation.
* @ref SL_STATUS_OK on success or a NVM3 @ref sl_status_t on failure.
******************************************************************************/
typedef sl_status_t (*nvm3_HalWriteWords_t)(nvm3_HalPtr_t nvmAdr, void const *pSrc, size_t cnt);
/// @brief The HAL handle definition.
typedef struct {
nvm3_HalOpen_t open; ///< Pointer to the open function
nvm3_HalClose_t close; ///< Pointer to the close function
nvm3_HalGetInfo_t getInfo; ///< Pointer to the get-info function
nvm3_HalNvmAccess_t access; ///< Pointer to the access function
nvm3_HalPageErase_t pageErase; ///< Pointer to the page-erase function
nvm3_HalReadWords_t readWords; ///< Pointer to the read-words function
nvm3_HalWriteWords_t writeWords; ///< Pointer to the write-words function
} nvm3_HalHandle_t;
/** @} (end addtogroup nvm3hal) */
/** @} (end addtogroup nvm3) */
#ifdef __cplusplus
}
#endif
#endif /* NVM3_HAL_H */

View File

@@ -0,0 +1,68 @@
/***************************************************************************//**
* @file
* @brief NVM3 driver HAL for memory mapped FLASH
*******************************************************************************
* # License
* <b>Copyright 2018 Silicon Laboratories Inc. www.silabs.com</b>
*******************************************************************************
*
* SPDX-License-Identifier: Zlib
*
* The licensor of this software is Silicon Laboratories Inc.
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*
******************************************************************************/
#ifndef NVM3_HAL_FLASH_H
#define NVM3_HAL_FLASH_H
#include "nvm3_hal.h"
#ifdef __cplusplus
extern "C" {
#endif
/***************************************************************************//**
* @addtogroup nvm3
* @{
******************************************************************************/
/***************************************************************************//**
* @addtogroup nvm3hal
* @{
* @details
* This module provides the NVM3 interface to the EFM and EFR Flash NVM.
*
* @note The features available through the handle are used by the NVM3 and
* should not be used directly by any applications.
******************************************************************************/
/*******************************************************************************
*************************** GLOBAL VARIABLES ******************************
******************************************************************************/
extern const nvm3_HalHandle_t nvm3_halFlashHandle; ///< The HAL flash handle.
/** @} (end addtogroup nvm3hal) */
/** @} (end addtogroup nvm3) */
#ifdef __cplusplus
}
#endif
#endif /* NVM3_HAL_FLASH_H */

View File

@@ -0,0 +1,93 @@
/***************************************************************************//**
* @file
* @brief NVM3 data access lock API definition
*******************************************************************************
* # License
* <b>Copyright 2018 Silicon Laboratories Inc. www.silabs.com</b>
*******************************************************************************
*
* SPDX-License-Identifier: Zlib
*
* The licensor of this software is Silicon Laboratories Inc.
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*
******************************************************************************/
#ifndef NVM3_LOCK_H
#define NVM3_LOCK_H
#include <stdint.h>
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
/***************************************************************************//**
* @addtogroup nvm3
* @{
******************************************************************************/
/***************************************************************************//**
* @addtogroup nvm3lock NVM3 Lock
* @brief NVM3 lock functions
* @{
* @details
* This module provides data protection tools for NVM3.
*
* The functions in this module are the default protection tools for NVM3.
* The application can substitute the nvm3_lockBegin and nvm3_lockEnd
* functions as long as the NVM3 functions are protected from
* being called re-entrant.
*
* @note These functions are used by the NVM3 and should not be used by
* any applications.
******************************************************************************/
/***************************************************************************//**
* @brief
* Create a mutex to lock and unlock section.
******************************************************************************/
void nvm3_lockCreateMutex(void);
/***************************************************************************//**
* @brief
* Begin a lock section.
******************************************************************************/
void nvm3_lockBegin(void);
/***************************************************************************//**
* @brief
* End a lock section.
******************************************************************************/
void nvm3_lockEnd(void);
/***************************************************************************//**
* @brief
* Disable execution from data area.
******************************************************************************/
void nvm3_lockDisableExecute(void* address, size_t size);
/** @} (end addtogroup nvm3lock) */
/** @} (end addtogroup nvm3) */
#ifdef __cplusplus
}
#endif
#endif //NVM3_LOCK_H

View File

@@ -0,0 +1,111 @@
/***************************************************************************//**
* @file
* @brief NVM3 object definition
*******************************************************************************
* # License
* <b>Copyright 2018 Silicon Laboratories Inc. www.silabs.com</b>
*******************************************************************************
*
* SPDX-License-Identifier: Zlib
*
* The licensor of this software is Silicon Laboratories Inc.
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*
******************************************************************************/
#ifndef NVM3_OBJECT_H
#define NVM3_OBJECT_H
#include "nvm3_hal.h"
#include "nvm3_config.h"
#include "nvm3.h"
#ifdef __cplusplus
extern "C" {
#endif
/// @cond DO_NOT_INCLUDE_WITH_DOXYGEN
#define NVM3_OBJ_SMALL_MAX_SIZE 120U // Small object is limited to 120 bytes
#define NVM3_OBJ_PTR_INVALID ((nvm3_ObjPtr_t)(-1L))
#define NVM3_OBJ_HDR_PTR_INVALID ((nvm3_ObjHdrPtr_t)(-1L))
#define NVM3_OBJ_HEADER_SIZE_LARGE (sizeof(nvm3_ObjHdrLarge_t))
#define NVM3_OBJ_HEADER_SIZE_WLARGE (sizeof(nvm3_ObjHdrLarge_t) / sizeof(uint32_t))
#define NVM3_OBJ_HEADER_SIZE_SMALL (sizeof(nvm3_ObjHdrSmall_t))
#define NVM3_OBJ_HEADER_SIZE_WSMALL (sizeof(nvm3_ObjHdrSmall_t) / sizeof(uint32_t))
#define NVM3_OBJ_HEADER_SIZE_COUNTER (NVM3_OBJ_HEADER_SIZE_LARGE)
typedef struct nvm3_ObjHeaderSmall {
uint32_t oh1;
} nvm3_ObjHdrSmall_t;
typedef struct nvm3_ObjHeaderLarge {
uint32_t oh1;
uint32_t oh2;
} nvm3_ObjHdrLarge_t;
typedef nvm3_ObjHdrSmall_t *nvm3_ObjHdrSmallPtr_t;
typedef nvm3_ObjHdrLarge_t *nvm3_ObjHdrLargePtr_t;
typedef enum {
objTypeDataLarge = 0,
objTypeCounterLarge = 1,
objTypeCounterSmall = 2,
objTypeDeleted = 3,
objTypeRes_1 = 4,
objTypeRes_2 = 5,
objTypeRes_3 = 6,
objTypeDataSmall = 7,
} nvm3_ObjType_t;
typedef enum {
objGroupUnknown,
objGroupData,
objGroupCounter,
objGroupDeleted,
} nvm3_ObjGroup_t;
typedef enum {
fragTypeNone = 0,
fragTypeFirst = 1,
fragTypeNext = 2,
fragTypeLast = 3,
} nvm3_ObjFragType_t;
typedef nvm3_Obj_t *nvm3_ObjPtr_t;
void nvm3_objInit(nvm3_ObjPtr_t obj, nvm3_ObjPtr_t objAdr);
size_t nvm3_objHdrInit(nvm3_ObjHdrLargePtr_t oh, nvm3_ObjectKey_t key, nvm3_ObjType_t objType, size_t len, bool isLarge, nvm3_ObjFragType_t fragTyp);
size_t nvm3_objHdrLen(bool isLarge);
bool nvm3_objHdrValidateSmall(nvm3_ObjHdrSmallPtr_t objHdrSmall);
bool nvm3_objHdrValidateLarge(nvm3_ObjHdrLargePtr_t objHdrLarge);
bool nvm3_objHdrGetErased(nvm3_ObjHdrSmallPtr_t objHdrSmall);
nvm3_ObjFragType_t nvm3_objHdrGetFragTyp(nvm3_ObjHdrSmallPtr_t objHdrSmall);
nvm3_ObjectKey_t nvm3_objHdrGetKey(nvm3_ObjHdrSmallPtr_t objHdrSmall);
bool nvm3_objHdrGetHdrIsLarge(nvm3_ObjHdrSmallPtr_t objHdrSmall);
size_t nvm3_objHdrGetHdrLen(nvm3_ObjHdrSmallPtr_t objHdrSmall);
size_t nvm3_objHdrGetDatLen(nvm3_ObjHdrLargePtr_t objHdrLarge);
nvm3_ObjType_t nvm3_objHdrGetType(nvm3_ObjHdrSmallPtr_t objHdrSmall);
nvm3_ObjType_t nvm3_objGroupToType(nvm3_ObjGroup_t objGroup, bool hdrIsLarge);
nvm3_ObjGroup_t nvm3_objTypeToGroup(nvm3_ObjType_t objType);
/// @endcond
#ifdef __cplusplus
}
#endif
#endif /* NVM3_OBJECT_H */

View File

@@ -0,0 +1,97 @@
/***************************************************************************//**
* @file
* @brief NVM3 page handling functions
*******************************************************************************
* # License
* <b>Copyright 2018 Silicon Laboratories Inc. www.silabs.com</b>
*******************************************************************************
*
* SPDX-License-Identifier: Zlib
*
* The licensor of this software is Silicon Laboratories Inc.
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*
******************************************************************************/
#ifndef NVM3_PAGE_H
#define NVM3_PAGE_H
#include "nvm3_hal.h"
#include "nvm3_object.h"
#ifdef __cplusplus
extern "C" {
#endif
/// @cond DO_NOT_INCLUDE_WITH_DOXYGEN
#define NVM3_PAGE_COUNTER_SIZE 27U // 27 bits
#define NVM3_PAGE_COUNTER_MASK ((1U << NVM3_PAGE_COUNTER_SIZE) - 1U)
#define NVM3_PAGE_BCCB_SIZE 5U // 5 bits
#define NVM3_PAGE_BCCB_MASK ((1U << NVM3_PAGE_BCCB_SIZE) - 1U)
#define NVM3_PAGE_HEADER_WORDS 5 // The number of words in the page header
#define NVM3_PAGE_HEADER_SIZE (sizeof(nvm3_PageHdr_t))
#define NVM3_PAGE_HEADER_WSIZE (sizeof(nvm3_PageHdr_t) / sizeof(uint32_t))
#define NVM3_PAGE_H1_OFFSET (0 * sizeof(uint32_t))
#define NVM3_PAGE_H2_OFFSET (1 * sizeof(uint32_t))
#define NVM3_PAGE_H3_OFFSET (2 * sizeof(uint32_t))
#define NVM3_PAGE_H4_OFFSET (3 * sizeof(uint32_t))
#define NVM3_PAGE_H5_OFFSET (4 * sizeof(uint32_t))
#define NVM3_ERASE_COUNT_INVALID 0xFFFFFFFFU
#define NVM3_PAGE_INDEX_INVALID 0xFFFFU
typedef struct nvm3_PageHdr {
uint32_t data[NVM3_PAGE_HEADER_WORDS];
} nvm3_PageHdr_t;
/// @endcond
typedef enum {
nvm3_PageStateGood,
nvm3_PageStateGoodEip,
nvm3_PageStateBad,
nvm3_PageStateInvalidErased,
nvm3_PageStateInvalidUnknown,
} nvm3_PageState_t;
#if defined(NVM3_SECURITY)
sl_status_t nvm3_pageHeaderWrite(const nvm3_HalHandle_t *hal, nvm3_HalPtr_t pageAdr, uint32_t eraseCnt, nvm3_HalInfo_t *halInfo, nvm3_SecurityType_t secType);
#else
sl_status_t nvm3_pageHeaderWrite(const nvm3_HalHandle_t *hal, nvm3_HalPtr_t pageAdr, uint32_t eraseCnt, nvm3_HalInfo_t *halInfo);
#endif
void nvm3_pageSetBad(const nvm3_HalHandle_t *hal, nvm3_HalPtr_t pageAdr);
sl_status_t nvm3_pageSetEip(const nvm3_HalHandle_t *hal, nvm3_HalPtr_t pageAdr);
uint32_t nvm3_pageGetEraseCnt(nvm3_PageHdr_t *pageHdr);
nvm3_PageState_t nvm3_pageGetState(nvm3_PageHdr_t *pageHdr);
bool nvm3_pageStateIsGood(nvm3_PageState_t pageState);
bool nvm3_pageStateIsInvalid(nvm3_PageState_t pageState);
nvm3_ObjPtr_t nvm3_pageGetFirstObj(nvm3_HalPtr_t pageAdr);
#if defined(NVM3_SECURITY)
nvm3_SecurityType_t nvm3_pageGetSecType(nvm3_PageHdr_t *pageHdr);
sl_status_t nvm3_pageErase(const nvm3_HalHandle_t *hal, nvm3_HalPtr_t pageAdr, uint32_t eraseCnt, nvm3_HalInfo_t *halInfo, nvm3_SecurityType_t secType);
#else
sl_status_t nvm3_pageErase(const nvm3_HalHandle_t *hal, nvm3_HalPtr_t pageAdr, uint32_t eraseCnt, nvm3_HalInfo_t *halInfo);
#endif
#ifdef __cplusplus
}
#endif
#endif /* NVM3_PAGE_H */

View File

@@ -0,0 +1,74 @@
/***************************************************************************//**
* @file
* @brief NVM3 trace macros
*******************************************************************************
* # License
* <b>Copyright 2018 Silicon Laboratories Inc. www.silabs.com</b>
*******************************************************************************
*
* SPDX-License-Identifier: Zlib
*
* The licensor of this software is Silicon Laboratories Inc.
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*
******************************************************************************/
#ifndef NVM3_TRACE_H
#define NVM3_TRACE_H
#include "nvm3_config.h"
#include <stdint.h>
#if (NVM3_TRACE_PORT == NVM3_TRACE_PORT_PRINTF)
#include <stdio.h>
#endif
#if NVM3_TRACE_PORT == NVM3_TRACE_PORT_UNITYPRINTF
#include "unity.h"
#endif
/***************************************************************************//**
* @addtogroup nvm3trace NVM3 Trace
* @brief NVM3 Trace functions
* @{
******************************************************************************/
/*** */
/// @cond DO_NOT_INCLUDE_WITH_DOXYGEN
// Temporary solution, shoud use NVM3_TRACE_LEVEL as well
#define NVM3_TRACE_ENABLED (NVM3_TRACE_PORT != NVM3_TRACE_PORT_NONE)
#ifdef NVM3_HOST_BUILD
#define UnityPrintf(...) nvm3_tracePrint(NVM3_TRACE_LEVEL, __VA_ARGS__)
#define UNITY_PRINT_EOL() nvm3_tracePrint(NVM3_TRACE_LEVEL, "\n")
#define TEST_PRINTF UnityPrintf
#define TEST_MESSAGE UnityPrintf
#define UNITY_OUTPUT_CHAR UnityPrintf
#endif
#if (NVM3_TRACE_PORT == NVM3_TRACE_PORT_PRINTF)
#define nvm3_tracePrint(lev, ...) do { if (lev <= NVM3_TRACE_LEVEL) { printf(__VA_ARGS__); } } while (0)
#elif (NVM3_TRACE_PORT == NVM3_TRACE_PORT_UNITYPRINTF)
#define nvm3_tracePrint(lev, ...) do { if (lev <= NVM3_TRACE_LEVEL) { UnityPrintf(__VA_ARGS__); } } while (0)
#else
#define nvm3_tracePrint(lev, ...)
#endif
/// @endcond
/** @} (end addtogroup nvm3trace) */
#endif /* NVM3_TRACE_H */

View File

@@ -0,0 +1,68 @@
/***************************************************************************//**
* @file
* @brief NVM3 utility functions
*******************************************************************************
* # License
* <b>Copyright 2018 Silicon Laboratories Inc. www.silabs.com</b>
*******************************************************************************
*
* SPDX-License-Identifier: Zlib
*
* The licensor of this software is Silicon Laboratories Inc.
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*
******************************************************************************/
#ifndef NVM3_UTILS_H
#define NVM3_UTILS_H
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/// @cond DO_NOT_INCLUDE_WITH_DOXYGEN
/***************************************************************************//**
* @brief
* This function calculates the Berger Code of the supplied input variable.
* The Berger Code is calculated by looking at the binary value of the variable
* and counting the number of binary zeros.
*
* @param[in, out] pResult
* A pointer to a variable that will accumulate the berger code for
* the input variable specified in the next two variables.
*
* @param[in] pInput
* A pointer to the variable that contains data that is used.
*
* @param[in] numberOfBits
* The number of bits in the input variable used in the calculation.
* The calculation is starting from the least significant bit in the input
* variable.
******************************************************************************/
void nvm3_utilsComputeBergerCode(uint8_t *pResult, void *pInput, uint8_t numberOfBits);
/// @endcond
#ifdef __cplusplus
}
#endif
#endif /* NVM3_UTILS_H */