esp_flash_internal.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #pragma once
  7. #include "esp_err.h"
  8. #include <stdint.h>
  9. #include <stdbool.h>
  10. #include <driver/spi_common_internal.h>
  11. #include "sdkconfig.h"
  12. #include "esp_flash.h"
  13. /** Internal API, don't use in the applications */
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17. /** @brief Initialise the default SPI flash chip
  18. *
  19. * Called by OS startup code. You do not need to call this in your own applications.
  20. */
  21. #ifdef CONFIG_SPI_FLASH_USE_LEGACY_IMPL
  22. #define esp_flash_init_default_chip(...) ({ESP_OK;})
  23. #else
  24. esp_err_t esp_flash_init_default_chip(void);
  25. #endif
  26. /**
  27. * Enable OS-level SPI flash protections in IDF
  28. *
  29. * Called by OS startup code. You do not need to call this in your own applications.
  30. *
  31. * @return ESP_OK if success, otherwise failed. See return value of ``esp_flash_init_os_functions``.
  32. */
  33. #ifdef CONFIG_SPI_FLASH_USE_LEGACY_IMPL
  34. #define esp_flash_app_init(...) ({ESP_OK;})
  35. #else
  36. esp_err_t esp_flash_app_init(void);
  37. #endif
  38. /**
  39. * Disable (or enable) OS-level SPI flash protections in IDF
  40. *
  41. * Called by the IDF internal code (e.g. coredump). You do not need to call this in your own applications.
  42. *
  43. * @return always ESP_OK.
  44. */
  45. #ifdef CONFIG_SPI_FLASH_USE_LEGACY_IMPL
  46. #define esp_flash_app_disable_protect(...) ({ESP_OK;})
  47. #else
  48. esp_err_t esp_flash_app_disable_protect(bool disable);
  49. #endif
  50. /**
  51. * Initialize OS-level functions for a specific chip.
  52. *
  53. * @param chip The chip to init os functions.
  54. * @param host_id Which SPI host to use, 1 for SPI1, 2 for SPI2 (HSPI), 3 for SPI3 (VSPI)
  55. * @param dev_handle SPI bus lock device handle to acquire during flash operations
  56. *
  57. * @return
  58. * - ESP_OK if success
  59. * - ESP_ERR_INVALID_ARG if host_id is invalid
  60. */
  61. esp_err_t esp_flash_init_os_functions(esp_flash_t *chip, int host_id, spi_bus_lock_dev_handle_t dev_handle);
  62. /**
  63. * @brief Deinitialize OS-level functions
  64. *
  65. * @param chip The chip to deinit os functions
  66. * @param out_dev_handle The SPI bus lock passed from `esp_flash_init_os_functions`. The caller should deinitialize
  67. * the lock.
  68. * @return always ESP_OK.
  69. */
  70. esp_err_t esp_flash_deinit_os_functions(esp_flash_t* chip, spi_bus_lock_dev_handle_t* out_dev_handle);
  71. /**
  72. * @brief Initialize the bus lock on the SPI1 bus. Should be called if drivers (including esp_flash)
  73. * wants to use SPI1 bus.
  74. *
  75. * @note When using legacy spi flash API, the bus lock will not be available on SPI1 bus.
  76. *
  77. * @return esp_err_t always ESP_OK.
  78. */
  79. esp_err_t esp_flash_init_main_bus_lock(void);
  80. /**
  81. * Initialize OS-level functions for the main flash chip.
  82. *
  83. * @param chip The chip to init os functions. Only pointer to the default chip is supported now.
  84. *
  85. * @return always ESP_OK
  86. */
  87. esp_err_t esp_flash_app_enable_os_functions(esp_flash_t* chip);
  88. /**
  89. * Disable OS-level functions for the main flash chip during special phases (e.g. coredump)
  90. *
  91. * @param chip The chip to init os functions. Only "esp_flash_default_chip" is supported now.
  92. *
  93. * @return always ESP_OK
  94. */
  95. esp_err_t esp_flash_app_disable_os_functions(esp_flash_t* chip);
  96. #ifdef __cplusplus
  97. }
  98. #endif