cache.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. // Copyright 2015-2016 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. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #ifndef _ROM_CACHE_H_
  14. #define _ROM_CACHE_H_
  15. #include "soc/dport_access.h"
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. /** \defgroup uart_apis, uart configuration and communication related apis
  20. * @brief uart apis
  21. */
  22. /** @addtogroup uart_apis
  23. * @{
  24. */
  25. /**
  26. * @brief Initialise cache mmu, mark all entries as invalid.
  27. * Please do not call this function in your SDK application.
  28. *
  29. * @param int cpu_no : 0 for PRO cpu, 1 for APP cpu.
  30. *
  31. * @return None
  32. */
  33. void mmu_init(int cpu_no);
  34. /**
  35. * @brief Set Flash-Cache mmu mapping.
  36. * Please do not call this function in your SDK application.
  37. *
  38. * @param int cpu_no : CPU number, 0 for PRO cpu, 1 for APP cpu.
  39. *
  40. * @param int pod : process identifier. Range 0~7.
  41. *
  42. * @param unsigned int vaddr : virtual address in CPU address space.
  43. * Can be IRam0, IRam1, IRom0 and DRom0 memory address.
  44. * Should be aligned by psize.
  45. *
  46. * @param unsigned int paddr : physical address in Flash.
  47. * Should be aligned by psize.
  48. *
  49. * @param int psize : page size of flash, in kilobytes. Should be 64 here.
  50. *
  51. * @param int num : pages to be set.
  52. *
  53. * @return unsigned int: error status
  54. * 0 : mmu set success
  55. * 1 : vaddr or paddr is not aligned
  56. * 2 : pid error
  57. * 3 : psize error
  58. * 4 : mmu table to be written is out of range
  59. * 5 : vaddr is out of range
  60. */
  61. static inline unsigned int IRAM_ATTR cache_flash_mmu_set(int cpu_no, int pid, unsigned int vaddr, unsigned int paddr, int psize, int num)
  62. {
  63. extern unsigned int cache_flash_mmu_set_rom(int cpu_no, int pid, unsigned int vaddr, unsigned int paddr, int psize, int num);
  64. unsigned int ret;
  65. DPORT_STALL_OTHER_CPU_START();
  66. ret = cache_flash_mmu_set_rom(cpu_no, pid, vaddr, paddr, psize, num);
  67. DPORT_STALL_OTHER_CPU_END();
  68. return ret;
  69. }
  70. /**
  71. * @brief Set Ext-SRAM-Cache mmu mapping.
  72. * Please do not call this function in your SDK application.
  73. *
  74. * Note that this code lives in IRAM and has a bugfix in respect to the ROM version
  75. * of this function (which erroneously refused a vaddr > 2MiB
  76. *
  77. * @param int cpu_no : CPU number, 0 for PRO cpu, 1 for APP cpu.
  78. *
  79. * @param int pod : process identifier. Range 0~7.
  80. *
  81. * @param unsigned int vaddr : virtual address in CPU address space.
  82. * Can be IRam0, IRam1, IRom0 and DRom0 memory address.
  83. * Should be aligned by psize.
  84. *
  85. * @param unsigned int paddr : physical address in Ext-SRAM.
  86. * Should be aligned by psize.
  87. *
  88. * @param int psize : page size of flash, in kilobytes. Should be 32 here.
  89. *
  90. * @param int num : pages to be set.
  91. *
  92. * @return unsigned int: error status
  93. * 0 : mmu set success
  94. * 1 : vaddr or paddr is not aligned
  95. * 2 : pid error
  96. * 3 : psize error
  97. * 4 : mmu table to be written is out of range
  98. * 5 : vaddr is out of range
  99. */
  100. unsigned int IRAM_ATTR cache_sram_mmu_set(int cpu_no, int pid, unsigned int vaddr, unsigned int paddr, int psize, int num);
  101. /**
  102. * @brief Initialise cache access for the cpu.
  103. * Please do not call this function in your SDK application.
  104. *
  105. * @param int cpu_no : 0 for PRO cpu, 1 for APP cpu.
  106. *
  107. * @return None
  108. */
  109. static inline void IRAM_ATTR Cache_Read_Init(int cpu_no)
  110. {
  111. extern void Cache_Read_Init_rom(int cpu_no);
  112. DPORT_STALL_OTHER_CPU_START();
  113. Cache_Read_Init_rom(cpu_no);
  114. DPORT_STALL_OTHER_CPU_END();
  115. }
  116. /**
  117. * @brief Flush the cache value for the cpu.
  118. * Please do not call this function in your SDK application.
  119. *
  120. * @param int cpu_no : 0 for PRO cpu, 1 for APP cpu.
  121. *
  122. * @return None
  123. */
  124. static inline void IRAM_ATTR Cache_Flush(int cpu_no)
  125. {
  126. extern void Cache_Flush_rom(int cpu_no);
  127. DPORT_STALL_OTHER_CPU_START();
  128. Cache_Flush_rom(cpu_no);
  129. DPORT_STALL_OTHER_CPU_END();
  130. }
  131. /**
  132. * @brief Disable Cache access for the cpu.
  133. * Please do not call this function in your SDK application.
  134. *
  135. * @param int cpu_no : 0 for PRO cpu, 1 for APP cpu.
  136. *
  137. * @return None
  138. */
  139. static inline void IRAM_ATTR Cache_Read_Disable(int cpu_no)
  140. {
  141. extern void Cache_Read_Disable_rom(int cpu_no);
  142. DPORT_STALL_OTHER_CPU_START();
  143. Cache_Read_Disable_rom(cpu_no);
  144. DPORT_STALL_OTHER_CPU_END();
  145. }
  146. /**
  147. * @brief Enable Cache access for the cpu.
  148. * Please do not call this function in your SDK application.
  149. *
  150. * @param int cpu_no : 0 for PRO cpu, 1 for APP cpu.
  151. *
  152. * @return None
  153. */
  154. static inline void IRAM_ATTR Cache_Read_Enable(int cpu_no)
  155. {
  156. extern void Cache_Read_Enable_rom(int cpu_no);
  157. DPORT_STALL_OTHER_CPU_START();
  158. Cache_Read_Enable_rom(cpu_no);
  159. DPORT_STALL_OTHER_CPU_END();
  160. }
  161. /**
  162. * @}
  163. */
  164. #ifdef __cplusplus
  165. }
  166. #endif
  167. #endif /* _ROM_CACHE_H_ */