esp_flash_internal.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 "esp_private/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. esp_err_t esp_flash_init_default_chip(void);
  22. /**
  23. * Enable OS-level SPI flash protections in IDF
  24. *
  25. * Called by OS startup code. You do not need to call this in your own applications.
  26. *
  27. * @return ESP_OK if success, otherwise failed. See return value of ``esp_flash_init_os_functions``.
  28. */
  29. esp_err_t esp_flash_app_init(void);
  30. /**
  31. * Disable (or enable) OS-level SPI flash protections in IDF
  32. *
  33. * Called by the IDF internal code (e.g. coredump). You do not need to call this in your own applications.
  34. *
  35. * @return always ESP_OK.
  36. */
  37. esp_err_t esp_flash_app_disable_protect(bool disable);
  38. /**
  39. * Initialize OS-level functions for a specific chip.
  40. *
  41. * @param chip The chip to init os functions.
  42. * @param host_id Which SPI host to use, 1 for SPI1, 2 for SPI2 (HSPI), 3 for SPI3 (VSPI)
  43. * @param dev_handle SPI bus lock device handle to acquire during flash operations
  44. *
  45. * @return
  46. * - ESP_OK if success
  47. * - ESP_ERR_INVALID_ARG if host_id is invalid
  48. */
  49. esp_err_t esp_flash_init_os_functions(esp_flash_t *chip, int host_id, spi_bus_lock_dev_handle_t dev_handle);
  50. /**
  51. * @brief Deinitialize OS-level functions
  52. *
  53. * @param chip The chip to deinit os functions
  54. * @param out_dev_handle The SPI bus lock passed from `esp_flash_init_os_functions`. The caller should deinitialize
  55. * the lock.
  56. * @return always ESP_OK.
  57. */
  58. esp_err_t esp_flash_deinit_os_functions(esp_flash_t* chip, spi_bus_lock_dev_handle_t* out_dev_handle);
  59. /**
  60. * @brief Initialize the bus lock on the SPI1 bus. Should be called if drivers (including esp_flash)
  61. * wants to use SPI1 bus.
  62. *
  63. * @note When using legacy spi flash API, the bus lock will not be available on SPI1 bus.
  64. *
  65. * @return esp_err_t always ESP_OK.
  66. */
  67. esp_err_t esp_flash_init_main_bus_lock(void);
  68. /**
  69. * Initialize OS-level functions for the main flash chip.
  70. *
  71. * @param chip The chip to init os functions. Only pointer to the default chip is supported now.
  72. *
  73. * @return always ESP_OK
  74. */
  75. esp_err_t esp_flash_app_enable_os_functions(esp_flash_t* chip);
  76. /**
  77. * Disable OS-level functions for the main flash chip during special phases (e.g. coredump)
  78. *
  79. * @param chip The chip to init os functions. Only "esp_flash_default_chip" is supported now.
  80. *
  81. * @return always ESP_OK
  82. */
  83. esp_err_t esp_flash_app_disable_os_functions(esp_flash_t* chip);
  84. #ifdef __cplusplus
  85. }
  86. #endif