esp_flash_internal.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #pragma once
  15. #include "esp_err.h"
  16. #include <stdint.h>
  17. #include <stdbool.h>
  18. #include <driver/spi_common_internal.h>
  19. #include "sdkconfig.h"
  20. #include "esp_flash.h"
  21. /** Internal API, don't use in the applications */
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. /** @brief Initialise the default SPI flash chip
  26. *
  27. * Called by OS startup code. You do not need to call this in your own applications.
  28. */
  29. #ifdef CONFIG_SPI_FLASH_USE_LEGACY_IMPL
  30. #define esp_flash_init_default_chip(...) ({ESP_OK;})
  31. #else
  32. esp_err_t esp_flash_init_default_chip(void);
  33. #endif
  34. /**
  35. * Enable OS-level SPI flash protections in IDF
  36. *
  37. * Called by OS startup code. You do not need to call this in your own applications.
  38. *
  39. * @return ESP_OK if success, otherwise failed. See return value of ``esp_flash_init_os_functions``.
  40. */
  41. #ifdef CONFIG_SPI_FLASH_USE_LEGACY_IMPL
  42. #define esp_flash_app_init(...) ({ESP_OK;})
  43. #else
  44. esp_err_t esp_flash_app_init(void);
  45. #endif
  46. /**
  47. * Disable OS-level SPI flash protections in IDF
  48. *
  49. * Called by the IDF internal code (e.g. coredump). You do not need to call this in your own applications.
  50. *
  51. * @return always ESP_OK.
  52. */
  53. #ifdef CONFIG_SPI_FLASH_USE_LEGACY_IMPL
  54. #define esp_flash_app_disable_protect(...) ({ESP_OK;})
  55. #else
  56. esp_err_t esp_flash_app_disable_protect(bool disable);
  57. #endif
  58. /**
  59. * Initialize OS-level functions for a specific chip.
  60. *
  61. * @param chip The chip to init os functions.
  62. * @param host_id Which SPI host to use, 1 for SPI1, 2 for SPI2 (HSPI), 3 for SPI3 (VSPI)
  63. * @param out_dev_id Output of occupied device slot
  64. *
  65. * @return
  66. * - ESP_OK if success
  67. * - ESP_ERR_INVALID_ARG if host_id is invalid
  68. */
  69. esp_err_t esp_flash_init_os_functions(esp_flash_t *chip, int host_id, int *out_dev_id);
  70. /**
  71. * @brief Deinitialize OS-level functions
  72. *
  73. * @param chip The chip to deinit os functions
  74. * @return always ESP_OK.
  75. */
  76. esp_err_t esp_flash_deinit_os_functions(esp_flash_t* chip);
  77. /**
  78. * Initialize OS-level functions for the main flash chip.
  79. *
  80. * @param chip The chip to init os functions. Only pointer to the default chip is supported now.
  81. *
  82. * @return always ESP_OK
  83. */
  84. esp_err_t esp_flash_app_init_os_functions(esp_flash_t* chip);
  85. /**
  86. * Disable OS-level functions for the main flash chip during special phases (e.g. coredump)
  87. *
  88. * @param chip The chip to init os functions. Only "esp_flash_default_chip" is supported now.
  89. *
  90. * @return always ESP_OK
  91. */
  92. esp_err_t esp_flash_app_disable_os_functions(esp_flash_t* chip);
  93. #ifdef __cplusplus
  94. }
  95. #endif