cache.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. * @param int cpu_no : CPU number, 0 for PRO cpu, 1 for APP cpu.
  75. *
  76. * @param int pod : process identifier. Range 0~7.
  77. *
  78. * @param unsigned int vaddr : virtual address in CPU address space.
  79. * Can be IRam0, IRam1, IRom0 and DRom0 memory address.
  80. * Should be aligned by psize.
  81. *
  82. * @param unsigned int paddr : physical address in Ext-SRAM.
  83. * Should be aligned by psize.
  84. *
  85. * @param int psize : page size of flash, in kilobytes. Should be 32 here.
  86. *
  87. * @param int num : pages to be set.
  88. *
  89. * @return unsigned int: error status
  90. * 0 : mmu set success
  91. * 1 : vaddr or paddr is not aligned
  92. * 2 : pid error
  93. * 3 : psize error
  94. * 4 : mmu table to be written is out of range
  95. * 5 : vaddr is out of range
  96. */
  97. static inline unsigned int IRAM_ATTR cache_sram_mmu_set(int cpu_no, int pid, unsigned int vaddr, unsigned int paddr, int psize, int num)
  98. {
  99. extern unsigned int cache_sram_mmu_set_rom(int cpu_no, int pid, unsigned int vaddr, unsigned int paddr, int psize, int num);
  100. unsigned int ret;
  101. DPORT_STALL_OTHER_CPU_START();
  102. ret = cache_sram_mmu_set_rom(cpu_no, pid, vaddr, paddr, psize, num);
  103. DPORT_STALL_OTHER_CPU_END();
  104. return ret;
  105. }
  106. /**
  107. * @brief Initialise cache access for the cpu.
  108. * Please do not call this function in your SDK application.
  109. *
  110. * @param int cpu_no : 0 for PRO cpu, 1 for APP cpu.
  111. *
  112. * @return None
  113. */
  114. static inline void IRAM_ATTR Cache_Read_Init(int cpu_no)
  115. {
  116. extern void Cache_Read_Init_rom(int cpu_no);
  117. DPORT_STALL_OTHER_CPU_START();
  118. Cache_Read_Init_rom(cpu_no);
  119. DPORT_STALL_OTHER_CPU_END();
  120. }
  121. /**
  122. * @brief Flush the cache value for the cpu.
  123. * Please do not call this function in your SDK application.
  124. *
  125. * @param int cpu_no : 0 for PRO cpu, 1 for APP cpu.
  126. *
  127. * @return None
  128. */
  129. static inline void IRAM_ATTR Cache_Flush(int cpu_no)
  130. {
  131. extern void Cache_Flush_rom(int cpu_no);
  132. DPORT_STALL_OTHER_CPU_START();
  133. Cache_Flush_rom(cpu_no);
  134. DPORT_STALL_OTHER_CPU_END();
  135. }
  136. /**
  137. * @brief Disable Cache access for the cpu.
  138. * Please do not call this function in your SDK application.
  139. *
  140. * @param int cpu_no : 0 for PRO cpu, 1 for APP cpu.
  141. *
  142. * @return None
  143. */
  144. static inline void IRAM_ATTR Cache_Read_Disable(int cpu_no)
  145. {
  146. extern void Cache_Read_Disable_rom(int cpu_no);
  147. DPORT_STALL_OTHER_CPU_START();
  148. Cache_Read_Disable_rom(cpu_no);
  149. DPORT_STALL_OTHER_CPU_END();
  150. }
  151. /**
  152. * @brief Enable Cache access for the cpu.
  153. * Please do not call this function in your SDK application.
  154. *
  155. * @param int cpu_no : 0 for PRO cpu, 1 for APP cpu.
  156. *
  157. * @return None
  158. */
  159. static inline void IRAM_ATTR Cache_Read_Enable(int cpu_no)
  160. {
  161. extern void Cache_Read_Enable_rom(int cpu_no);
  162. DPORT_STALL_OTHER_CPU_START();
  163. Cache_Read_Enable_rom(cpu_no);
  164. DPORT_STALL_OTHER_CPU_END();
  165. }
  166. /**
  167. * @}
  168. */
  169. #ifdef __cplusplus
  170. }
  171. #endif
  172. #endif /* _ROM_CACHE_H_ */