MCUXpresso SDK API Reference Manual  Rev. 0
NXP Semiconductors
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
SNVS_LP: Secure Non-Volatile Storage

Overview

The MCUXpresso SDK provides a peripheral driver for the Secure Non-Volatile Storage (SNVS) module.

The SNVS module is designed to safely hold security-related data such as cryptographic key, time counter, monotonic counter, and general purpose security information. The The SNVS includes a low power section, namely SNVS_LP, that is battery backed by the SVNS (or VBAT) power domain. This enables it to keep this data valid and continue to increment the time counter when the power goes down in the rest of the SoC. The always-powered-up part of the module is isolated from the rest of the logic to ensure that it does not get corrupted when the SoC is powered down. The SNVS is designed to comply with Digital Rights Management (DRM) and other security application rules and requirements. This trusted hardware provides features that allow the system software designer to ensure that the data kept by the device is certifiable. Specially, it incorporates a security monitor that checks for various security conditions. If a security violation is indicated then it invalidates access to its sensitive data, and the secret data, e.g. Zeroizable Secret Key, is zeroized. the SNVS can be also configured to bypass its security features and protection mechanism. In this case it can be used by systems that do not require security.

SNVS_LP Driver Initialization and Configuration

The function SNVS_LP_RTC_Init() initializes the SNVS with specified configurations. The function SNVS_LP_RTC_GetDefaultConfig() gets the default configurations.

The function SNVS_LP_RTC_Deinit() disables the SNVS SRTC timer and disables the module clock.

Set & Get Datetime

The function SNVS_LP_RTC_SetDatetime() sets the SNVS SRTC date and time according to the given time structure described below.

typedef struct _snvs_lp_srtc_datetime
{
uint16_t year;
uint8_t month;
uint8_t day;
uint8_t hour;
uint8_t minute;
uint8_t second;

The function SNVS_LP_RTC_GetDatetime() reads the current timer value in seconds, converts it to date & time format and stores it into a datetime structure passed in by the user.

Set & Get Alarm

The function SNVS_LP_RTC_SetAlarm() sets the alarm time period in seconds. Users pass in the details in date & time format by using the datetime data structure.

The function SNVS_LP_RTC_GetAlarm() reads the alarm time in seconds, converts it to date & time format and stores it into a datetime structure passed in by the user.

Start & Stop timer

The function SNVS_LP_RTC_StartTimer() starts the SNVS_LP SRTC time counter.

The function SNVS_LP_RTC_StopTimer() stops the SNVS_LP SRTC time counter.

Status

Provides functions to get and clear the SNVS_LP status.

Interrupt

Provides functions to enable/disable SNVS_LP interrupts and get current enabled interrupts.

Typical use case

SNVS_LP SRTC example

Example to set the SNVS_LP SRTC current time, synchronize RTC time and date with SRTC and start RTC and trigger an alarm.

int main(void)
{
uint32_t sec;
snvs_hp_rtc_config_t snvsRtcConfig;
snvs_lp_srtc_config_t snvsSrtcConfig;
/* Board pin, clock, debug console init */
BOARD_InitHardware();
/* Init SNVS_HP */
/*
* config->rtcCalEnable = false;
* config->rtcCalValue = 0U;
* config->periodicInterruptFreq = 0U;
*/
SNVS_HP_RTC_Init(SNVS, &snvsRtcConfig);
/* Init SNVS_LP */
/*
* config->srtcCalEnable = false;
* config->srtcCalValue = 0U;
*/
SNVS_LP_SRTC_Init(SNVS, &snvsSrtcConfig);
PRINTF("SNVS LP SRTC example:\r\n");
/* Set a start date time and start RT */
srtcDate.year = 2014U;
srtcDate.month = 12U;
srtcDate.day = 25U;
srtcDate.hour = 19U;
srtcDate.minute = 0;
srtcDate.second = 0;
/* Set SRTC time to default time and date and start the SRTC */
SNVS_LP_SRTC_SetDatetime(SNVS, &srtcDate);
/* Synchronize RTC time and date with SRTC and start RTC */
PRINTF("RTC date and time has been synchronized with SRTC\r\n");
/* Enable SNVS alarm interrupt */
/* Enable at the NVIC */
EnableIRQ(EXAMPLE_SNVS_IRQn);
PRINTF("Set up time to wake up an alarm.\r\n");
/* This loop will set the SNVS alarm */
while (1)
{
busyWait = true;
/* Get date time */
SNVS_HP_RTC_GetDatetime(SNVS, &rtcDate);
/* print default time */
PRINTF("Current datetime: %04hd-%02hd-%02hd %02hd:%02hd:%02hd\r\n", rtcDate.year, rtcDate.month, rtcDate.day,
rtcDate.hour, rtcDate.minute, rtcDate.second);
/* Get alarm time from user */
sec = 0;
PRINTF("Please input the number of second to wait for alarm and press enter \r\n");
PRINTF("The second must be positive value\r\n");
while (sec < 1)
{
SCANF("%d", &sec);
}
SNVS_HP_RTC_GetDatetime(SNVS, &rtcDate);
if ((rtcDate.second + sec) < 60)
{
rtcDate.second += sec;
}
else
{
rtcDate.minute += (rtcDate.second + sec) / 60U;
rtcDate.second = (rtcDate.second + sec) % 60U;
}
SNVS_HP_RTC_SetAlarm(SNVS, &rtcDate);
/* Get alarm time */
SNVS_HP_RTC_GetAlarm(SNVS, &rtcDate);
/* Print alarm time */
PRINTF("Alarm will occur at: %04hd-%02hd-%02hd %02hd:%02hd:%02hd\r\n", rtcDate.year, rtcDate.month, rtcDate.day,
rtcDate.hour, rtcDate.minute, rtcDate.second);
/* Wait until alarm occurs */
while (busyWait)
{
}
PRINTF("\r\n Alarm occurs !!!! ");
}
}

Data Structures

struct  snvs_lp_srtc_datetime_t
 Structure is used to hold the date and time. More...
 
struct  snvs_lp_srtc_config_t
 SNVS_LP config structure. More...
 

Enumerations

enum  snvs_lp_srtc_interrupt_enable_t { kSNVS_SRTC_AlarmInterruptEnable = 4U }
 List of SNVS_LP interrupts. More...
 
enum  snvs_lp_srtc_status_flags_t { kSNVS_SRTC_AlarmInterruptFlag = 4U }
 List of SNVS_LP flags. More...
 
enum  snvs_lp_external_tamper_t
 List of SNVS_LP external tampers.
 
enum  snvs_lp_external_tamper_status_t
 List of SNVS_LP external tampers status.
 
enum  snvs_lp_external_tamper_polarity_t
 SNVS_LP external tamper polarity.
 

Variables

uint16_t snvs_lp_srtc_datetime_t::year
 Range from 1970 to 2099. More...
 
uint8_t snvs_lp_srtc_datetime_t::month
 Range from 1 to 12. More...
 
uint8_t snvs_lp_srtc_datetime_t::day
 Range from 1 to 31 (depending on month). More...
 
uint8_t snvs_lp_srtc_datetime_t::hour
 Range from 0 to 23. More...
 
uint8_t snvs_lp_srtc_datetime_t::minute
 Range from 0 to 59. More...
 
uint8_t snvs_lp_srtc_datetime_t::second
 Range from 0 to 59. More...
 
bool snvs_lp_srtc_config_t::srtcCalEnable
 true: SRTC calibration mechanism is enabled; false: No calibration is used
 
uint32_t snvs_lp_srtc_config_t::srtcCalValue
 Defines signed calibration value for SRTC; This is a 5-bit 2's complement value, range from -16 to +15.
 

Driver version

#define FSL_SNVS_LP_DRIVER_VERSION   (MAKE_VERSION(2, 0, 0))
 Version 2.0.0.
 

Initialization and deinitialization

void SNVS_LP_SRTC_Init (SNVS_Type *base, const snvs_lp_srtc_config_t *config)
 Ungates the SNVS clock and configures the peripheral for basic operation. More...
 
void SNVS_LP_SRTC_Deinit (SNVS_Type *base)
 Stops the SRTC timer. More...
 
void SNVS_LP_SRTC_GetDefaultConfig (snvs_lp_srtc_config_t *config)
 Fills in the SNVS_LP config struct with the default settings. More...
 

Secure RTC (SRTC) current Time & Alarm

status_t SNVS_LP_SRTC_SetDatetime (SNVS_Type *base, const snvs_lp_srtc_datetime_t *datetime)
 Sets the SNVS SRTC date and time according to the given time structure. More...
 
void SNVS_LP_SRTC_GetDatetime (SNVS_Type *base, snvs_lp_srtc_datetime_t *datetime)
 Gets the SNVS SRTC time and stores it in the given time structure. More...
 
status_t SNVS_LP_SRTC_SetAlarm (SNVS_Type *base, const snvs_lp_srtc_datetime_t *alarmTime)
 Sets the SNVS SRTC alarm time. More...
 
void SNVS_LP_SRTC_GetAlarm (SNVS_Type *base, snvs_lp_srtc_datetime_t *datetime)
 Returns the SNVS SRTC alarm time. More...
 

Interrupt Interface

void SNVS_LP_SRTC_EnableInterrupts (SNVS_Type *base, uint32_t mask)
 Enables the selected SNVS interrupts. More...
 
void SNVS_LP_SRTC_DisableInterrupts (SNVS_Type *base, uint32_t mask)
 Disables the selected SNVS interrupts. More...
 
uint32_t SNVS_LP_SRTC_GetEnabledInterrupts (SNVS_Type *base)
 Gets the enabled SNVS interrupts. More...
 

Status Interface

uint32_t SNVS_LP_SRTC_GetStatusFlags (SNVS_Type *base)
 Gets the SNVS status flags. More...
 
void SNVS_LP_SRTC_ClearStatusFlags (SNVS_Type *base, uint32_t mask)
 Clears the SNVS status flags. More...
 

Timer Start and Stop

static void SNVS_LP_SRTC_StartTimer (SNVS_Type *base)
 Starts the SNVS SRTC time counter. More...
 
static void SNVS_LP_SRTC_StopTimer (SNVS_Type *base)
 Stops the SNVS SRTC time counter. More...
 

External tampering

void SNVS_LP_EnableExternalTamper (SNVS_Type *base, snvs_lp_external_tamper_t pin, snvs_lp_external_tamper_polarity_t polarity)
 Enables the specified SNVS external tamper. More...
 
void SNVS_LP_DisableExternalTamper (SNVS_Type *base, snvs_lp_external_tamper_t pin)
 Disables the specified SNVS external tamper. More...
 
snvs_lp_external_tamper_status_t SNVS_LP_GetExternalTamperStatus (SNVS_Type *base, snvs_lp_external_tamper_t pin)
 Returns status of the specified external tamper. More...
 
void SNVS_LP_ClearExternalTamperStatus (SNVS_Type *base, snvs_lp_external_tamper_t pin)
 Clears status of the specified external tamper. More...
 

Data Structure Documentation

struct snvs_lp_srtc_datetime_t

Data Fields

uint16_t year
 Range from 1970 to 2099. More...
 
uint8_t month
 Range from 1 to 12. More...
 
uint8_t day
 Range from 1 to 31 (depending on month). More...
 
uint8_t hour
 Range from 0 to 23. More...
 
uint8_t minute
 Range from 0 to 59. More...
 
uint8_t second
 Range from 0 to 59. More...
 
struct snvs_lp_srtc_config_t

This structure holds the configuration settings for the SNVS_LP peripheral. To initialize this structure to reasonable defaults, call the SNVS_LP_GetDefaultConfig() function and pass a pointer to your config structure instance.

The config struct can be made const so it resides in flash

Data Fields

bool srtcCalEnable
 true: SRTC calibration mechanism is enabled; false: No calibration is used
 
uint32_t srtcCalValue
 Defines signed calibration value for SRTC; This is a 5-bit 2's complement value, range from -16 to +15.
 

Enumeration Type Documentation

Enumerator
kSNVS_SRTC_AlarmInterruptEnable 

SRTC time alarm.

Enumerator
kSNVS_SRTC_AlarmInterruptFlag 

SRTC time alarm flag.

Function Documentation

void SNVS_LP_SRTC_Init ( SNVS_Type *  base,
const snvs_lp_srtc_config_t config 
)
Note
This API should be called at the beginning of the application using the SNVS driver.
Parameters
baseSNVS peripheral base address
configPointer to the user's SNVS configuration structure.
void SNVS_LP_SRTC_Deinit ( SNVS_Type *  base)
Parameters
baseSNVS peripheral base address
void SNVS_LP_SRTC_GetDefaultConfig ( snvs_lp_srtc_config_t config)

The default values are as follows.

* config->srtccalenable = false;
* config->srtccalvalue = 0U;
*
Parameters
configPointer to the user's SNVS configuration structure.
status_t SNVS_LP_SRTC_SetDatetime ( SNVS_Type *  base,
const snvs_lp_srtc_datetime_t datetime 
)
Parameters
baseSNVS peripheral base address
datetimePointer to the structure where the date and time details are stored.
Returns
kStatus_Success: Success in setting the time and starting the SNVS SRTC kStatus_InvalidArgument: Error because the datetime format is incorrect
void SNVS_LP_SRTC_GetDatetime ( SNVS_Type *  base,
snvs_lp_srtc_datetime_t datetime 
)
Parameters
baseSNVS peripheral base address
datetimePointer to the structure where the date and time details are stored.
status_t SNVS_LP_SRTC_SetAlarm ( SNVS_Type *  base,
const snvs_lp_srtc_datetime_t alarmTime 
)

The function sets the SRTC alarm. It also checks whether the specified alarm time is greater than the present time. If not, the function does not set the alarm and returns an error. Please note, that SRTC alarm has limited resolution because only 32 most significant bits of SRTC counter are compared to SRTC Alarm register. If the alarm time is beyond SRTC resolution, the function does not set the alarm and returns an error.

Parameters
baseSNVS peripheral base address
alarmTimePointer to the structure where the alarm time is stored.
Returns
kStatus_Success: success in setting the SNVS SRTC alarm kStatus_InvalidArgument: Error because the alarm datetime format is incorrect kStatus_Fail: Error because the alarm time has already passed or is beyond resolution
void SNVS_LP_SRTC_GetAlarm ( SNVS_Type *  base,
snvs_lp_srtc_datetime_t datetime 
)
Parameters
baseSNVS peripheral base address
datetimePointer to the structure where the alarm date and time details are stored.
void SNVS_LP_SRTC_EnableInterrupts ( SNVS_Type *  base,
uint32_t  mask 
)
Parameters
baseSNVS peripheral base address
maskThe interrupts to enable. This is a logical OR of members of the enumeration ::snvs_interrupt_enable_t
void SNVS_LP_SRTC_DisableInterrupts ( SNVS_Type *  base,
uint32_t  mask 
)
Parameters
baseSNVS peripheral base address
maskThe interrupts to enable. This is a logical OR of members of the enumeration ::snvs_interrupt_enable_t
uint32_t SNVS_LP_SRTC_GetEnabledInterrupts ( SNVS_Type *  base)
Parameters
baseSNVS peripheral base address
Returns
The enabled interrupts. This is the logical OR of members of the enumeration ::snvs_interrupt_enable_t
uint32_t SNVS_LP_SRTC_GetStatusFlags ( SNVS_Type *  base)
Parameters
baseSNVS peripheral base address
Returns
The status flags. This is the logical OR of members of the enumeration ::snvs_status_flags_t
void SNVS_LP_SRTC_ClearStatusFlags ( SNVS_Type *  base,
uint32_t  mask 
)
Parameters
baseSNVS peripheral base address
maskThe status flags to clear. This is a logical OR of members of the enumeration ::snvs_status_flags_t
static void SNVS_LP_SRTC_StartTimer ( SNVS_Type *  base)
inlinestatic
Parameters
baseSNVS peripheral base address
static void SNVS_LP_SRTC_StopTimer ( SNVS_Type *  base)
inlinestatic
Parameters
baseSNVS peripheral base address
void SNVS_LP_EnableExternalTamper ( SNVS_Type *  base,
snvs_lp_external_tamper_t  pin,
snvs_lp_external_tamper_polarity_t  polarity 
)
Parameters
baseSNVS peripheral base address
pinSNVS external tamper pin
polarityPolarity of external tamper
void SNVS_LP_DisableExternalTamper ( SNVS_Type *  base,
snvs_lp_external_tamper_t  pin 
)
Parameters
baseSNVS peripheral base address
pinSNVS external tamper pin
snvs_lp_external_tamper_status_t SNVS_LP_GetExternalTamperStatus ( SNVS_Type *  base,
snvs_lp_external_tamper_t  pin 
)
Parameters
baseSNVS peripheral base address
pinSNVS external tamper pin
Returns
The status flag. This is the enumeration ::snvs_external_tamper_status_t
void SNVS_LP_ClearExternalTamperStatus ( SNVS_Type *  base,
snvs_lp_external_tamper_t  pin 
)
Parameters
baseSNVS peripheral base address
pinSNVS external tamper pin

Variable Documentation

uint16_t snvs_lp_srtc_datetime_t::year
uint8_t snvs_lp_srtc_datetime_t::month
uint8_t snvs_lp_srtc_datetime_t::day
uint8_t snvs_lp_srtc_datetime_t::hour
uint8_t snvs_lp_srtc_datetime_t::minute
uint8_t snvs_lp_srtc_datetime_t::second