1 /* 2 * Copyright (c) 2023 HPMicro 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 * 6 */ 7 #ifndef _HPM_NOR_FLASH_H 8 #define _HPM_NOR_FLASH_H 9 10 #include <stdint.h> 11 #include "hpm_common.h" 12 #include "hpm_romapi.h" 13 14 #ifdef __cplusplus 15 extern "C" { 16 #endif /* __cplusplus */ 17 18 typedef struct { 19 XPI_Type *xpi_base; 20 uint32_t base_addr; 21 uint32_t sector_size; 22 uint32_t opt_header; 23 uint32_t opt0; 24 uint32_t opt1; 25 xpi_nor_config_t nor_config; 26 } nor_flash_config_t; 27 28 /** 29 * @brief hpm nor-flash initialization 30 * 31 * @param[in] cfg config_context 32 * @return hpm_stat_t 33 */ 34 hpm_stat_t nor_flash_init(nor_flash_config_t *cfg); 35 36 /** 37 * @brief hpm nor-flash read function 38 * 39 * @param[in] cfg config_context 40 * @param[out] buf store read data 41 * @param[in] addr read physical start addr 42 * @param[in] size read bytes size 43 * @return hpm_stat_t 44 */ 45 hpm_stat_t nor_flash_read(nor_flash_config_t *cfg, uint8_t *buf, uint32_t addr, uint32_t size); 46 47 /** 48 * @brief hpm nor-flash write function 49 * 50 * @param[in] cfg config_context 51 * @param[in] buf data to be written 52 * @param[in] addr write physical start addr 53 * @param[in] size write bytes size 54 * @return hpm_stat_t 55 */ 56 hpm_stat_t nor_flash_write(nor_flash_config_t *cfg, uint8_t *buf, uint32_t addr, uint32_t size); 57 58 /** 59 * @brief hpm nor-flash erase function 60 * 61 * @param[in] cfg config_context 62 * @param[in] start_addr erase physical start addr 63 * @param[in] size erase bytes size 64 */ 65 void nor_flash_erase(nor_flash_config_t *cfg, uint32_t start_addr, uint32_t size); 66 67 #ifdef __cplusplus 68 } 69 #endif /* __cplusplus */ 70 #endif