0 Replies Latest reply on Nov 20, 2014 7:25 PM by userc_4697

    WICED Smart BCM92073X NVRAM Access

    userc_4697

      Overview

      The NVRAM is used to store the data which may be modified frequently, such as pairing information and application private data, etc.

      The storage space of NVRAM is the Volatile Section (VS) mentioned in document “WICED Smart BCM92073X EEPROM and SFLASH Layout”.

       

      NVRAM Size and Record

      The total size of NVRAM space is the length of VS. User can configure the VS’s location and size in the configuration file mentioned in document “WICED Smart BCM92073X EEPROM and SFLASH Layout”. The parameters are as follow:

      • DLConfigVSLocation

      VS start address in EEPROM or SFLASH.

      • DLConfigVSLength

      VS length.

       

      Note: In WICES Smart SDK 2.1.0, the default VS length is 1024; In WICED Smart SDK 1.1.0, the length is 512.

       

      The NVRAM is divided into many pages. The size of page is 32 bytes.

      The BLE firmware occupy 4 pages, so the number of the pages left to store record item is

      [Total Pages of Record Item] = ([VS Length] / 32) - 4

       

      For example, when VS length is 1024, it has 32 pages, and 28 pages are used to save NVRAM record item.

       

      A NVRAM record item has a 3 bytes header.

       

      Page is the minimum allocation unit of NVRAM. It means that even if the record item’s size (included the header) is less than 32 bytes, it still needs to allocate one page for it. In other word, one record item occupies one page at least. Therefore, the maximum number of record items we can use is equal to total pages of record item as mentioned above.

       

      The formula of allocated page number of a record item is as below:

                                 [Allocated Page Number] = ([Record Item Data Size] + [Header Size] + 31) / 32

      And the size of NVRAM occupied by a record item is as below:

                                 [Record Item NVRAM Size] = [Allocated Page Number] * 32

       

      The maximum length of record item data is 255.

       

      NVRAM IDs

      NVRAM record item is identified by ID. The valid rang for user is 0 – 0x6F. And in WICED Smart SDK, some IDs are used by stack and pre-defined applications as shown in Figure 1. We shouldn’t use these IDs.

      File: Stacknvram.h (WICED-Smart-SDK\wiced-smart\bleapp\lestack\blecm)

      #define   STACKNVRAM_FIRST_USABLE_ITEM_NUMBER    0x00

       

      // This item has the local root keys.

      #define   STACKNVRAM_LOCAL_KEYS (STACKNVRAM_FIRST_USABLE_ITEM_NUMBER+1)

      // This item has the index table associated with the bonded devices.

      #define   STACKNVRAM_BOND_INDEX (STACKNVRAM_LOCAL_KEYS + 1)

       

       

      // Note: This one should be the last one so that the idx can grow

      // to the end. We reserve 5 bonded device, defined in lesmpkeys.h

      #define   STACKNVRAM_FIRST_BONDED_IDX (STACKNVRAM_BOND_INDEX + 1)

       

      #define   VS_BLE_HOST_LIST 0x70 //0x70 is working // (STACKNVRAM_FIRST_BONDED_IDX + 1)

      #define   VS_BLE_BPM_DATA (VS_BLE_HOST_LIST + 1)

      #define   VS_BLE_HRM_DATA (VS_BLE_HOST_LIST + 1)

      #define   VS_BLE_THER_DATA (VS_BLE_HOST_LIST + 1)

      #define   VS_BLE_GEN_DATA (VS_BLE_HOST_LIST + 1)

       

      #define   VS_BLE_WS_DATA (VS_BLE_HOST_LIST + 1)

      #define   VS_BLE_GM_DATA (VS_BLE_HOST_LIST + 1)

       

      #define   VS_BLE_BAT_DATA (VS_BLE_HOST_LIST - 1)

       

      #define   VS_BLE_BAT_DATA1_1 (VS_BLE_HOST_LIST - 2)

      Figure 1: Pre-defined NVRAM IDs

       

      NVARM API

      bleprofile_ReadNVRAM

      • Description

      Read a record item from NVRAM.

      • Prototype

      UINT8 bleprofile_ReadNVRAM(UINT8 vsID, UINT8 itemLength, UINT8* payload);

      • Parameter
        • vsID

      The NVRAM ID of the record item.

        • itemLength

      The length of record item.

        • payload

      The buffer to be copied record item to.

      • Return
        • If success, return the number of bytes read from NVRAM, else return 0.

       

      bleprofile_WriteNVRAM

      • Description

      Write a record item into NVARM.

      • Prototype

      UINT8 bleprofile_WriteNVRAM(UINT8 vsID, UINT8 itemLength, UINT8 *payload);

      • Parameter
        • vsID

      The NVRAM ID of the record item.

        • itemLength

      The data length of record item.

        • payload

      The buffer of record item to be written into NVRAM.

      • Return
        • If success, return the number of bytes written into NVRAM, else return 0.

       

      bleprofile_DeleteNVRAM

      • Description

      Delete a record item in NVRAM.

      • Prototype

      BOOL32 bleprofile_DeleteNVRAM(UINT8 vsID);

      • Parameter
        • vsID

      The NVRAM ID of the record item.

        • itemLength

      The data length of record item.

        • § payload

      The buffer of record item to be written into NVRAM.

      • Return
        • If success, return 1, else return 0.