This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC2630: Writing/Reading NV from application

Part Number: CC2630
Other Parts Discussed in Thread: Z-STACK

Hi,


i want to write and read information to/from the NV and read chapter 10 in the OSAP API.pdf. However, the function prototypes in the document only mention a NVid and an offset (as well as length) while the function prototypes in, for example, the sampleswitch project require an id, a subid and an index. I suppose offset = index, but what values should i put in id and subid?

The document also specifies an Application value range from 0x0401-0x0FFF.

Has anyone used those functions yet and can please give me a hint?

Thanks you!

regards, stephanie

  • Hi Stephanie,

    There are two prototypes:
    - uint8 osal_nv_write_ex( uint16 id, uint16 subId, uint16 ndx, uint16 len, void *buf )
    - uint8 osal_nv_write( uint16 id, uint16 ndx, uint16 len, void *buf )

    So it depends on how the item that you want to write was initialized:
    - uint8 osal_nv_item_init_ex( uint16 id, uint16 subId, uint16 len, void *buf )
    - uint8 osal_nv_item_init( uint16 id, uint16 len, void *buf )

    Look at the ZComDef.h for the NV items that you want to use and look how they were initialized. The extended version of the functions use two IDs to reach the NV memory item while the older one just use one ID.

    If you need some new items for your application, just add them to the ZComDef.h in the range of 0x0401-0x0FFF and initialize them with the osal Nv init functions.

    I hipe this helps.

    Regards.
  • As I remember, NV ID 0x0401-0x0FFF doesn't work in Z-Stack for CC26xx.
  • Hi Stephanie,

    I made a mistake with my last answer because the OSAL functions are not exposed to the application, instead you need to use the functions defined in the zcl_port.h file, look at the zclGeneral_AddScene() function defined in zcl_port.c and use it as example. Again the "Id" and "subId" are used in order to init, read and write the NV items.

    The next NV itmes are already reserved:

    // OSAL NV Item IDs

    #define ZCD_NV_EX_LEGACY                  0x0000

    #define ZCD_NV_EX_ADDRMGR                 0x0001

    #define ZCD_NV_EX_BINDING_TABLE           0x0002

    #define ZCD_NV_EX_DEVICE_LIST             0x0003

     

    I hope this helps.

     

    Regards,

  • Hi Jose,


    thank you, yes it does. Do you also know how items are placed in NV?

    The SceneNVID is defined as "ZCL_PORT_SCENE_TABLE_NV_ID 0x0001". Does this mean it is safe to use 0x0002 for my own NV items? And should all the NV items i want to place under 0x0002 have the same length/data type or can they be different data types?

    i.e. would this be valid?

    uint32_t capabilities;
    bool     pairedFlag;
    uint8_t  identifier;
    
    zclport_writeNV(0x0004, 0x0001, 0, sizeof(capabilities), (void*)&capabilities);
    zclport_writeNV(0x0004, 0x0002, 0, sizeof(pairedFlag),   (void*)&pairedFlag);
    zclport_writeNV(0x0004, 0x0003, 0, sizeof(identifier),   (void*)&identifier);

    thanks!

  • After checking, I had get suggestion fro TI to use NV ID after 0x0100.
  • Hi Stephnie,

    As YK says, it would be better to use the NV Id from 0x0100 and just keep track of future zstack changes to look if your NV id is reserved for other propose or not and just change it if necessary.

    The example that you provide looks good just keep track of the size of each item, is easy to make mistakes on this.

    Regards,

  • Okay, i have changed the NV id accordingly.

    What do you mean by "keep track of the size"?

  • Jose means to keep track of future zstack changes to look if your NV id is reserved for other propose or not and just change it if necessary.
  • Hi,

    As YK says, maybe a new release of the stack can have more NV IDs reserved because are used for any kind of stuff so, look if your IDs still available and if not just change them from 0x0100 to 0x0200 (any free ID).

    Regarding to keep track of the size of items:

    zclport_writeNV(0x0004, 0x0001, 0, sizeof(capabilities), (void*)&capabilities);
    zclport_writeNV(0x0004, 0x0002, 0, sizeof(pairedFlag),   (void*)&pairedFlag);
    zclport_writeNV(0x0004, 0x0003, 0, sizeof(identifier),   (void*)&identifier);
    Take care of the size during memory inizialization, read and write. In your example is clear that you are aware of that. But again is easy to make mistakes and create a mess.
     
    Regards,
     
  • Ohhh, okay. I thought, when you mentioned size there was something i missed.

    Thanks a lot! You two have been a great help.