File ns_nvm.h
File List > includes-api > ns_nvm.h
Go to the documentation of this file
#ifndef NS_NVM_H
#define NS_NVM_H
#ifdef __cplusplus
extern "C" {
#endif
#include "ns_core.h"
#include "am_mcu_apollo.h" // For am_hal_mspi_* enums
#include <stdbool.h>
#include <stdint.h>
/* ===== Versioning (ns_core-style) ===== */
#define NS_NVM_V0_0_1 { .major = 0, .minor = 0, .revision = 1 }
#define NS_NVM_V1_0_0 { .major = 1, .minor = 0, .revision = 0 }
#define NS_NVM_OLDEST_SUPPORTED_VERSION NS_NVM_V0_0_1
#define NS_NVM_CURRENT_VERSION NS_NVM_V1_0_0
#define NS_NVM_API_ID 0xCA000B
extern const ns_core_api_t ns_nvm_V0_0_1;
extern const ns_core_api_t ns_nvm_oldest_supported_version;
extern const ns_core_api_t ns_nvm_current_version;
/* ===== Public types ===== */
typedef enum {
NS_NVM_IF_OCTAL_DDR = 0,
NS_NVM_IF_OCTAL_1_8_8 = 1
} ns_nvm_interface_e;
typedef struct {
/* ns_core api prefix */
ns_core_api_t const *api;
/* Features */
bool enable;
bool enable_xip;
/* MSPI/Device selection */
uint8_t mspi_module;
uint8_t chip_select;
ns_nvm_interface_e iface;
am_hal_mspi_clock_e clock_freq;
/* Optional non-blocking TCB buffer (if NULL, an internal one is used) */
uint32_t *nbtxn_buf;
uint32_t nbtxn_buf_len;
/* Optional MSPI scrambling window (0 disables) */
uint32_t scrambling_start;
uint32_t scrambling_end;
/* Out params filled on init */
uint32_t xip_base_address;
uint32_t size_bytes;
} ns_nvm_config_t;
/* ===== Public API ===== */
uint32_t ns_nvm_init(ns_nvm_config_t *cfg);
uint32_t ns_nvm_read(uint32_t addr, uint8_t *buf, uint32_t len, bool wait);
uint32_t ns_nvm_write(uint32_t addr, const uint8_t *buf, uint32_t len, bool wait);
uint32_t ns_nvm_sector_erase(uint32_t sector_addr);
uint32_t ns_nvm_mass_erase(void);
uint32_t ns_nvm_enable_xip(void);
uint32_t ns_nvm_disable_xip(void);
#ifdef __cplusplus
}
#endif
#endif /* NS_NVM_H */