-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(spi_nand_flash): expose lower-level API and make it usable witho…
…ut Dhara
- Loading branch information
1 parent
d402e9c
commit b66eda8
Showing
17 changed files
with
961 additions
and
549 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2022 mikkeldamsgaard project | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* SPDX-FileContributor: 2015-2024 Espressif Systems (Shanghai) CO LTD | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <stdint.h> | ||
#include "spi_nand_flash.h" | ||
#include "freertos/semphr.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#define INVALID_PAGE 0xFFFF | ||
|
||
typedef enum { | ||
STAT_ECC_OK = 0, | ||
STAT_ECC_1_TO_3_BITS_CORRECTED = 1, | ||
STAT_ECC_BITS_CORRECTED = STAT_ECC_1_TO_3_BITS_CORRECTED, | ||
STAT_ECC_NOT_CORRECTED = 2, | ||
STAT_ECC_4_TO_6_BITS_CORRECTED = 3, | ||
STAT_ECC_MAX_BITS_CORRECTED = STAT_ECC_4_TO_6_BITS_CORRECTED, | ||
STAT_ECC_7_8_BITS_CORRECTED = 5, | ||
STAT_ECC_MAX | ||
} ecc_status_t; | ||
|
||
typedef struct { | ||
uint8_t ecc_status_reg_len_in_bits; | ||
uint8_t ecc_data_refresh_threshold; | ||
ecc_status_t ecc_corrected_bits_status; | ||
} ecc_data_t; | ||
|
||
typedef struct { | ||
uint8_t log2_page_size; //is power of 2, log2_page_size shift (1<<log2_page_size) is stored to page_size | ||
uint8_t log2_ppb; //is power of 2, log2_ppb shift ((1<<log2_ppb) * page_size) will be stored in block size | ||
uint32_t block_size; | ||
uint32_t page_size; | ||
uint32_t num_blocks; | ||
uint32_t read_page_delay_us; | ||
uint32_t erase_block_delay_us; | ||
uint32_t program_page_delay_us; | ||
ecc_data_t ecc_data; | ||
} spi_nand_chip_t; | ||
|
||
typedef struct { | ||
esp_err_t (*init)(spi_nand_flash_device_t *handle); | ||
esp_err_t (*deinit)(spi_nand_flash_device_t *handle); | ||
esp_err_t (*read)(spi_nand_flash_device_t *handle, uint8_t *buffer, sector_t sector_id); | ||
esp_err_t (*write)(spi_nand_flash_device_t *handle, const uint8_t *buffer, sector_t sector_id); | ||
esp_err_t (*trim)(spi_nand_flash_device_t *handle, sector_t sector_id); | ||
esp_err_t (*sync)(spi_nand_flash_device_t *handle); | ||
esp_err_t (*copy_sector)(spi_nand_flash_device_t *handle, sector_t src_sec, sector_t dst_sec); | ||
esp_err_t (*get_capacity)(spi_nand_flash_device_t *handle, sector_t *number_of_sectors); | ||
} spi_nand_ops; | ||
|
||
struct spi_nand_flash_device_t { | ||
uint8_t dev_index; | ||
spi_nand_flash_config_t config; | ||
spi_nand_chip_t chip; | ||
const spi_nand_ops *ops; | ||
uint8_t *work_buffer; | ||
uint8_t *read_buffer; | ||
SemaphoreHandle_t mutex; | ||
}; | ||
|
||
esp_err_t register_nand_dev(spi_nand_flash_device_t *handle); | ||
esp_err_t unregister_nand_dev(spi_nand_flash_device_t *handle); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2022 mikkeldamsgaard project | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* SPDX-FileContributor: 2015-2023 Espressif Systems (Shanghai) CO LTD | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <stdint.h> | ||
#include "esp_err.h" | ||
#include "nand.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
esp_err_t nand_is_bad(spi_nand_flash_device_t *handle, block_t b, bool *is_bad_status); | ||
esp_err_t nand_mark_bad(spi_nand_flash_device_t *handle, block_t b); | ||
esp_err_t nand_erase_chip(spi_nand_flash_device_t *handle); | ||
esp_err_t nand_erase_block(spi_nand_flash_device_t *handle, block_t b); | ||
esp_err_t nand_prog(spi_nand_flash_device_t *handle, page_t p, const uint8_t *data); | ||
esp_err_t nand_is_free(spi_nand_flash_device_t *handle, page_t p, bool *is_free_status); | ||
esp_err_t nand_read(spi_nand_flash_device_t *handle, page_t p, size_t offset, size_t length, uint8_t *data); | ||
esp_err_t nand_copy(spi_nand_flash_device_t *handle, page_t src, page_t dst); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |
File renamed without changes.
Oops, something went wrong.