PicoWAN SDK Documentation
Macros | Enumerations | Functions
flash.h File Reference

Eeprom/Flash access routines. More...

#include <stdint.h>

Go to the source code of this file.

Macros

#define NV_COMMON_MAGIC   0x442A6B6E
 
#define NV_COMMON_MAGIC_OFFSET   0
 
#define NV_COMMON_MAGIC_SIZE   1 /* in blocks */
 
#define NV_COMMON_SECTION_LENGTH_OFFSET   (NV_COMMON_MAGIC_OFFSET + NV_COMMON_MAGIC_SIZE * sizeof(uint32_t))
 
#define NV_COMMON_SECTION_LENGTH_SIZE   1 /* in blocks */
 
#define NV_COMMON_FIRST_FIELD_OFFSET   (NV_COMMON_SECTION_LENGTH_OFFSET + NV_COMMON_SECTION_LENGTH_SIZE * sizeof(uint32_t))
 
#define NV_COMMON_PICOWAN_DEVICE_ADDRESS_OFFSET   NV_COMMON_FIRST_FIELD_OFFSET
 
#define NV_COMMON_PICOWAN_DEVICE_ADDRESS_SIZE   1 /* in blocks */
 
#define NV_COMMON_PICOWAN_NETWORK_SESSION_KEY_OFFSET   (NV_COMMON_PICOWAN_DEVICE_ADDRESS_OFFSET + NV_COMMON_PICOWAN_DEVICE_ADDRESS_SIZE * sizeof(uint32_t))
 
#define NV_COMMON_PICOWAN_NETWORK_SESSION_KEY_SIZE   4 /* in blocks */
 
#define NV_COMMON_PICOWAN_APPLICATION_SESSION_KEY_OFFSET   (NV_COMMON_PICOWAN_NETWORK_SESSION_KEY_OFFSET + NV_COMMON_PICOWAN_NETWORK_SESSION_KEY_SIZE * sizeof(uint32_t))
 
#define NV_COMMON_PICOWAN_APPLICATION_SESSION_KEY_SIZE   4 /* in blocks */
 
#define NV_COMMON_DEVICE_EUI_OFFSET   (NV_COMMON_PICOWAN_APPLICATION_SESSION_KEY_OFFSET + NV_COMMON_PICOWAN_APPLICATION_SESSION_KEY_SIZE * sizeof(uint32_t))
 
#define NV_COMMON_DEVICE_EUI_SIZE   2 /* in blocks */
 
#define NV_COMMON_APPLICATION_EUI_OFFSET   (NV_COMMON_DEVICE_EUI_OFFSET + NV_COMMON_DEVICE_EUI_SIZE * sizeof(uint32_t))
 
#define NV_COMMON_APPLICATION_EUI_SIZE   2 /* in blocks */
 
#define NV_COMMON_APPLICATION_KEY_OFFSET   (NV_COMMON_APPLICATION_EUI_OFFSET + NV_COMMON_APPLICATION_EUI_SIZE * sizeof(uint32_t))
 
#define NV_COMMON_APPLICATION_KEY_SIZE   4 /* in blocks */
 
#define NV_COMMON_LORA_DEVICE_ADDRESS_OFFSET   (NV_COMMON_APPLICATION_KEY_OFFSET + NV_COMMON_APPLICATION_KEY_SIZE * sizeof(uint32_t))
 
#define NV_COMMON_LORA_DEVICE_ADDRESS_SIZE   1 /* in blocks */
 
#define NV_COMMON_LORA_NETWORK_SESSION_KEY_OFFSET   (NV_COMMON_LORA_DEVICE_ADDRESS_OFFSET + NV_COMMON_LORA_DEVICE_ADDRESS_SIZE * sizeof(uint32_t))
 
#define NV_COMMON_LORA_NETWORK_SESSION_KEY_SIZE   4 /* in blocks */
 
#define NV_COMMON_LORA_APPLICATION_SESSION_KEY_OFFSET   (NV_COMMON_LORA_NETWORK_SESSION_KEY_OFFSET + NV_COMMON_LORA_NETWORK_SESSION_KEY_SIZE * sizeof(uint32_t))
 
#define NV_COMMON_LORA_APPLICATION_SESSION_KEY_SIZE   4 /* in blocks */
 
#define NV_COMMON_LORA_UPLINK_COUNTER_OFFSET   (NV_COMMON_LORA_APPLICATION_SESSION_KEY_OFFSET + NV_COMMON_LORA_APPLICATION_SESSION_KEY_SIZE * sizeof(uint32_t))
 
#define NV_COMMON_LORA_UPLINK_COUNTER_SIZE   1 /* in blocks */
 
#define NV_COMMON_LORA_DOWNLINK_COUNTER_OFFSET   (NV_COMMON_LORA_UPLINK_COUNTER_OFFSET + NV_COMMON_LORA_UPLINK_COUNTER_SIZE * sizeof(uint32_t))
 
#define NV_COMMON_LORA_DOWNLINK_COUNTER_SIZE   1 /* in blocks */
 
#define NV_COMMON_SECTION_LENGTH
 
#define NV_PRIVATE_MAGIC_OFFSET   0
 
#define NV_PRIVATE_MAGIC_SIZE   1 /* in blocks */
 
#define NV_PRIVATE_SECTION_LENGTH_OFFSET   (NV_PRIVATE_MAGIC_OFFSET + NV_PRIVATE_MAGIC_SIZE * sizeof(uint32_t))
 
#define NV_PRIVATE_SECTION_LENGTH_SIZE   1 /* in blocks */
 
#define NV_PRIVATE_FIRST_FIELD_OFFSET   (NV_PRIVATE_SECTION_LENGTH_OFFSET + NV_PRIVATE_SECTION_LENGTH_SIZE * sizeof(uint32_t))
 

Enumerations

enum  nv_section { NV_SECTION_PRIVATE, NV_SECTION_COMMON }
 

Functions

int8_t flash_data_nvread (enum nv_section section, uint32_t offset, uint32_t *data, uint32_t length)
 Reads 32-bit long blocks from the Eeprom using PicoWAN-SDK's Eeprom layout. More...
 
int8_t flash_data_nvwrite (enum nv_section section, uint32_t offset, uint32_t *data, uint32_t length)
 Writes 32-bit long blocks to the Eeprom using PicoWAN-SDK's Eeprom layout. More...
 
void flash_data_nvcheck (uint32_t private_magic, uint32_t private_size)
 Initializes and checks the Eeprom format. More...
 

Detailed Description

Eeprom/Flash access routines.

NOTE: The eeprom is divided in 2 sections:

Copyright (c) 2018, Archos S.A. All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND AND EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ARCHOS S.A. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Macro Definition Documentation

#define NV_COMMON_SECTION_LENGTH
Value:
NV_COMMON_PICOWAN_DEVICE_ADDRESS_SIZE + \
NV_COMMON_PICOWAN_NETWORK_SESSION_KEY_SIZE + \
NV_COMMON_PICOWAN_APPLICATION_SESSION_KEY_SIZE + \
NV_COMMON_DEVICE_EUI_SIZE + \
NV_COMMON_APPLICATION_EUI_SIZE + \
NV_COMMON_APPLICATION_KEY_SIZE + \
NV_COMMON_LORA_DEVICE_ADDRESS_SIZE + \
NV_COMMON_LORA_NETWORK_SESSION_KEY_SIZE + \
NV_COMMON_LORA_APPLICATION_SESSION_KEY_SIZE + \
NV_COMMON_LORA_UPLINK_COUNTER_SIZE + \
NV_COMMON_LORA_DOWNLINK_COUNTER_SIZE

Function Documentation

void flash_data_nvcheck ( uint32_t  private_magic,
uint32_t  private_size 
)

Initializes and checks the Eeprom format.

This functions performs a sanity check on the Eeprom sections, initializing or migrating them if necessary. Keep in mind that different applications must have different private magics to be sure that flashing a new application will re-initialize the private section.

Parameters
private_magicThe magic of the private section (must be unique per application)
private_sizeThe total size in 32-bit long blocks of the private section. This size can be increases in case new fields are added to the private section, however decreasing it is not allowed.
int8_t flash_data_nvread ( enum nv_section  section,
uint32_t  offset,
uint32_t *  data,
uint32_t  length 
)

Reads 32-bit long blocks from the Eeprom using PicoWAN-SDK's Eeprom layout.

Note
Data from NV_SECTION_COMMON are kept when different applications are flashed into the board, while data from NV_SECTION_PRIVATE are lost everytime a new application is flashed.
Parameters
sectionThe section to read from. This can be NV_SECTION_COMMON for general data related to MACs, or NV_SECTION_PRIVATE for data related to the main application.
offsetThe offset of the field to read. This must come from the list of available fields for the section, ex NV_COMMON_APPLICATION_EUI_OFFSET.
dataA pointer to the buffer that will hold the data.
lengthThe length of the data to read in 32-bit long blocks, ex NV_COMMON_APPLICATION_EUI_SIZE.
Return values
int8_t-1 if it failed, 0 otherwise.
int8_t flash_data_nvwrite ( enum nv_section  section,
uint32_t  offset,
uint32_t *  data,
uint32_t  length 
)

Writes 32-bit long blocks to the Eeprom using PicoWAN-SDK's Eeprom layout.

Note
Data from NV_SECTION_COMMON are kept when different applications are flashed into the board, while data from NV_SECTION_PRIVATE are lost everytime a new application is flashed.
Parameters
sectionThe section to write to. This can be NV_SECTION_COMMON for general data related to MACs, or NV_SECTION_PRIVATE for data related to the main application.
offsetThe offset of the field to write. This must come from the list of available fields for the section, ex NV_COMMON_APPLICATION_EUI_OFFSET.
dataA pointer to the buffer that holds the data to write.
lengthThe length of the data to write in 32-bit long blocks, ex NV_COMMON_APPLICATION_EUI_SIZE.
Return values
int8_t-1 if it failed, 0 otherwise.