Microchip® Advanced Software Framework

nvm.h File Reference

SAM Non-Volatile Memory driver.

Copyright (c) 2012-2020 Microchip Technology Inc. and its subsidiaries.

#include <compiler.h>
#include <status_codes.h>
#include <stdbool.h>

Data Structures

struct  nvm_config
 NVM controller configuration structure. More...
 
struct  nvm_fusebits
 NVM user row fuse setting structure. More...
 
struct  nvm_parameters
 NVM memory parameter structure. More...
 

Macros

Driver Feature Definition

Define NVM features set according to the different device families.

#define FEATURE_NVM_RWWEE
 Read while write EEPROM emulation feature. More...
 
#define FEATURE_BOD12
 Brown-out detector internal to the voltage regulator for VDDCORE. More...
 

Enumerations

enum  nvm_bod12_action {
  NVM_BOD12_ACTION_NONE,
  NVM_BOD12_ACTION_RESET,
  NVM_BOD12_ACTION_INTERRUPT
}
 BOD12 Action. More...
 
enum  nvm_bod33_action {
  NVM_BOD33_ACTION_NONE,
  NVM_BOD33_ACTION_RESET,
  NVM_BOD33_ACTION_INTERRUPT
}
 BOD33 Action. More...
 
enum  nvm_bootloader_size {
  NVM_BOOTLOADER_SIZE_128,
  NVM_BOOTLOADER_SIZE_64,
  NVM_BOOTLOADER_SIZE_32,
  NVM_BOOTLOADER_SIZE_16,
  NVM_BOOTLOADER_SIZE_8,
  NVM_BOOTLOADER_SIZE_4,
  NVM_BOOTLOADER_SIZE_2,
  NVM_BOOTLOADER_SIZE_0
}
 Bootloader size. More...
 
enum  nvm_cache_readmode {
  NVM_CACHE_READMODE_NO_MISS_PENALTY,
  NVM_CACHE_READMODE_LOW_POWER,
  NVM_CACHE_READMODE_DETERMINISTIC
}
 NVM controller cache readmode configuration. More...
 
enum  nvm_command {
  NVM_COMMAND_ERASE_ROW = NVMCTRL_CTRLA_CMD_ER,
  NVM_COMMAND_WRITE_PAGE = NVMCTRL_CTRLA_CMD_WP,
  NVM_COMMAND_ERASE_AUX_ROW = NVMCTRL_CTRLA_CMD_EAR,
  NVM_COMMAND_WRITE_AUX_ROW = NVMCTRL_CTRLA_CMD_WAP,
  NVM_COMMAND_LOCK_REGION = NVMCTRL_CTRLA_CMD_LR,
  NVM_COMMAND_UNLOCK_REGION = NVMCTRL_CTRLA_CMD_UR,
  NVM_COMMAND_PAGE_BUFFER_CLEAR = NVMCTRL_CTRLA_CMD_PBC,
  NVM_COMMAND_SET_SECURITY_BIT = NVMCTRL_CTRLA_CMD_SSB,
  NVM_COMMAND_ENTER_LOW_POWER_MODE = NVMCTRL_CTRLA_CMD_SPRM,
  NVM_COMMAND_EXIT_LOW_POWER_MODE = NVMCTRL_CTRLA_CMD_CPRM,
  NVM_COMMAND_RWWEE_ERASE_ROW = NVMCTRL_CTRLA_CMD_RWWEEER,
  NVM_COMMAND_RWWEE_WRITE_PAGE = NVMCTRL_CTRLA_CMD_RWWEEWP
}
 NVM controller commands. More...
 
enum  nvm_eeprom_emulator_size {
  NVM_EEPROM_EMULATOR_SIZE_16384,
  NVM_EEPROM_EMULATOR_SIZE_8192,
  NVM_EEPROM_EMULATOR_SIZE_4096,
  NVM_EEPROM_EMULATOR_SIZE_2048,
  NVM_EEPROM_EMULATOR_SIZE_1024,
  NVM_EEPROM_EMULATOR_SIZE_512,
  NVM_EEPROM_EMULATOR_SIZE_256,
  NVM_EEPROM_EMULATOR_SIZE_0
}
 EEPROM emulator size. More...
 
enum  nvm_error {
  NVM_ERROR_NONE = 0,
  NVM_ERROR_LOCK = NVMCTRL_STATUS_NVME | NVMCTRL_STATUS_LOCKE,
  NVM_ERROR_PROG = NVMCTRL_STATUS_NVME | NVMCTRL_STATUS_PROGE
}
 NVM error flags. More...
 
enum  nvm_sleep_power_mode {
  NVM_SLEEP_POWER_MODE_WAKEONACCESS = NVMCTRL_CTRLB_SLEEPPRM_WAKEONACCESS_Val,
  NVM_SLEEP_POWER_MODE_WAKEUPINSTANT = NVMCTRL_CTRLB_SLEEPPRM_WAKEUPINSTANT_Val,
  NVM_SLEEP_POWER_MODE_ALWAYS_AWAKE = NVMCTRL_CTRLB_SLEEPPRM_DISABLED_Val
}
 NVM controller power reduction mode configurations. More...
 
enum  nvm_wdt_early_warning_offset {
  NVM_WDT_EARLY_WARNING_OFFSET_8,
  NVM_WDT_EARLY_WARNING_OFFSET_16,
  NVM_WDT_EARLY_WARNING_OFFSET_32,
  NVM_WDT_EARLY_WARNING_OFFSET_64,
  NVM_WDT_EARLY_WARNING_OFFSET_128,
  NVM_WDT_EARLY_WARNING_OFFSET_256,
  NVM_WDT_EARLY_WARNING_OFFSET_512,
  NVM_WDT_EARLY_WARNING_OFFSET_1024,
  NVM_WDT_EARLY_WARNING_OFFSET_2048,
  NVM_WDT_EARLY_WARNING_OFFSET_4096,
  NVM_WDT_EARLY_WARNING_OFFSET_8192,
  NVM_WDT_EARLY_WARNING_OFFSET_16384
}
 WDT Early warning offset. More...
 
enum  nvm_wdt_window_timeout {
  NVM_WDT_WINDOW_TIMEOUT_PERIOD_8,
  NVM_WDT_WINDOW_TIMEOUT_PERIOD_16,
  NVM_WDT_WINDOW_TIMEOUT_PERIOD_32,
  NVM_WDT_WINDOW_TIMEOUT_PERIOD_64,
  NVM_WDT_WINDOW_TIMEOUT_PERIOD_128,
  NVM_WDT_WINDOW_TIMEOUT_PERIOD_256,
  NVM_WDT_WINDOW_TIMEOUT_PERIOD_512,
  NVM_WDT_WINDOW_TIMEOUT_PERIOD_1024,
  NVM_WDT_WINDOW_TIMEOUT_PERIOD_2048,
  NVM_WDT_WINDOW_TIMEOUT_PERIOD_4096,
  NVM_WDT_WINDOW_TIMEOUT_PERIOD_8192,
  NVM_WDT_WINDOW_TIMEOUT_PERIOD_16384
}
 WDT Window time-out period. More...
 

Functions

Configuration and Initialization
static void nvm_get_config_defaults (struct nvm_config *const config)
 Initializes an NVM controller configuration structure to defaults. More...
 
enum status_code nvm_set_config (const struct nvm_config *const config)
 Sets the up the NVM hardware module based on the configuration. More...
 
static bool nvm_is_ready (void)
 Checks if the NVM controller is ready to accept a new command. More...
 
NVM Access Management
void nvm_get_parameters (struct nvm_parameters *const parameters)
 Reads the parameters of the NVM controller. More...
 
enum status_code nvm_write_buffer (const uint32_t destination_address, const uint8_t *buffer, uint16_t length)
 Writes a number of bytes to a page in the NVM memory region. More...
 
enum status_code nvm_read_buffer (const uint32_t source_address, uint8_t *const buffer, uint16_t length)
 Reads a number of bytes from a page in the NVM memory region. More...
 
enum status_code nvm_update_buffer (const uint32_t destination_address, uint8_t *const buffer, uint16_t offset, uint16_t length)
 Updates an arbitrary section of a page with new data. More...
 
enum status_code nvm_erase_row (const uint32_t row_address)
 Erases a row in the NVM memory space. More...
 
enum status_code nvm_execute_command (const enum nvm_command command, const uint32_t address, const uint32_t parameter)
 Executes a command on the NVM controller. More...
 
enum status_code nvm_get_fuses (struct nvm_fusebits *fusebits)
 Get fuses from user row. More...
 
enum status_code nvm_set_fuses (struct nvm_fusebits *fb)
 Set fuses from user row. More...
 
bool nvm_is_page_locked (uint16_t page_number)
 Checks whether the page region is locked. More...
 
static enum nvm_error nvm_get_error (void)
 Retrieves the error code of the last issued NVM operation. More...