Non-Volatile Parameters

Reads and writes parameters in non-volatile memory (FRAM).

The cuplTag (and cuplcodec) is configured with a small set of parameters. These control the tag serial string, the sampling interval or the URL of the web application that decodes the tag contents.

A parameter has a single-byte identifier e.g. ‘w’ and a value. The length of the value field depends on the parameter. For example, the serial string consists of eight bytes (e.g. ‘AB43xkp4’).

A variable is used to monitor how many parameters have been written since the last power cycle. A full set of parameters is needed for the program to proceed.

Defines

NVPARAM_SERIAL_ID

Serial ID

NVPARAM_SECKEY_ID

Secret key ID

NVPARAM_BASEURL_ID

Base URL of the cupl web application ID

NVPARAM_FMT_ID

Sample format ID

NVPARAM_SMPLINT_ID

Sample interval ID

NVPARAM_MINVOLT_ID

Minimum operating voltage (in mV) ID

NVPARAM_HTTPSDIS_ID

Disable HTTPS ID

NVPARAM_USEHMAC_ID

Use HMAC ID

SERIAL_PARAM_WRITTEN
SECKEY_PARAM_WRITTEN
FMT_PARAM_WRITTEN
SMPLINT_PARAM_WRITTEN
MINVOLT_PARAM_WRITTEN
BASEURL_PARAM_WRITTEN
HTTPSDIS_PARAM_WRITTEN
USEHMAC_PARAM_WRITTEN
ALL_PARAMS_WRITTEN

0xFF in the ‘paramswritten’ RAM variable indicates that all parameters have been written.

NVM_ALL_PARAMS_WRITTEN

Zero in NVM indicates that all parameters have been written. Why zero? After programming, the initial value for this NVM section is 0xFF.

MINUTES_PER_DAY
INTEGERFIELD_LENBYTES

Value up to 65535 (5 ASCII digits)

DISABLE_FRAM_DATA_WRITEPROTECT

Clear the Data FRAM Write Protect bit.

ENABLE_FRAM_DATA_WRITEPROTECT

Set the Data FRAM Write Protect bit.

Functions

char *nvparams_getserial()

Get the 8-character alphanumeric serial string.

This is used to identify a cuplTag to the server. It is included in the URL.

Returns

A pointer to the serial string.

char *nvparams_getsecretkey()

Get the secret key used by cuplcodec to calculate an HMAC-MD5.

The secret key is unique per tag. It is known only to the web server and the tag. It is used to generate a Hash based Message Authenticity Code, which prevents an ‘imposter tag’ from writing sample data to the web server.

Returns

A pointer to the secret key, which is SECKEY_LENBYTES long.

unsigned int nvparams_getminvoltagemv(void)

Get the minimum operating voltage parameter.

If the battery voltage is allowed to drop to the brown-out voltage, then the NFC EEPROM will be left with stale data. There will be insufficient power to overwrite this with a ‘low power’ message, because the MSP430 will be stuck in a reset loop.

This parameter should be slightly higher than the brown-out voltage e.g. 2200mV. When it is reached, the sampling loop will stop, sample data removed and the user will be notified.

Returns

Minimum operating voltage in millivolts.

unsigned int nvparams_getsmplintmins()

Get the sample interval in minutes.

Temperature/humidity sensor samples are written to the circular buffer at this interval.

Returns

The sample interval in minutes as a 16-bit unsigned integer.

long nvparams_getsleepintmins()

Get the sleep interval in minutes (deprecated).

This NVM parameter is not used.

Returns

The tag sleep interval in minutes.

bool nvparams_allwritten()

Check that the cuplTag is fully configured.

Returns

‘true’ if all NVM parameters have been written.

int nvparams_getresetsperloop()

Get resets per loop.

Returns

The number of resets that have occurred during the present ‘loop’ of the circular buffer.

int nvparams_getresetsalltime()
Returns

The number of resets that have occurred from the factory.

void nvparams_cresetsperloop()

Clear resets per loop.

Clear the number of resets that has occurred during the present ‘loop’ of the circular buffer. This should be done each time data wraps from the end of the circular buffer back to the start.

void nvparams_incrcounters()

Increment both reset counters in NVM.

bool nvparams_write(char id, char *valptr, unsigned int vlen)

Write a parameter to non-volatile memory.

A parameter consists of an ID (one byte) and a value (one or more bytes).

Parameters
  • id[in] parameter ID.

  • valptr[in] pointer to an array that contains the parameter value.

  • vlen[in] length of the value in bytes.

Returns

true if the parameter ID is recognised and its value has the correct length in bytes. Otherwise false.

Variables

nv_t nv
unsigned int paramswritten = 0

Bits are set in this integer that correspond to parameters written since the last power cycle.