cpu.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2008-12-11 XuXinming first version
  9. * 2013-05-24 Grissiom port to RM48x50
  10. */
  11. #include <rtthread.h>
  12. /**
  13. * @addtogroup RM48x50
  14. */
  15. /*@{*/
  16. /**
  17. * this function will reset CPU
  18. *
  19. */
  20. RT_WEAK void rt_hw_cpu_reset()
  21. {
  22. }
  23. /**
  24. * this function will shutdown CPU
  25. *
  26. */
  27. RT_WEAK void rt_hw_cpu_shutdown()
  28. {
  29. rt_kprintf("shutdown...\n");
  30. while (1);
  31. }
  32. #ifdef __TI_COMPILER_VERSION__
  33. #ifdef RT_USING_CPU_FFS
  34. int __rt_ffs(int value)
  35. {
  36. if (value == 0)
  37. return value;
  38. __asm(" rsb r1, r0, #0");
  39. __asm(" and r1, r1, r0");
  40. __asm(" clz r1, r1");
  41. __asm(" rsb r0, r1, #32");
  42. }
  43. #endif
  44. void rt_hw_cpu_icache_enable()
  45. {
  46. __asm(" MRC p15, #0, r1, c1, c0, #0 ; Read SCTLR configuration data");
  47. __asm(" ORR r1, r1, #0x1 <<12 ; instruction cache enable");
  48. __asm(" MCR p15, #0, r0, c7, c5, #0 ; Invalidate entire instruction cache, r0 is ignored");
  49. __asm(" MCR p15, #0, r1, c1, c0, #0 ; enabled instruction cache");
  50. __asm(" ISB");
  51. }
  52. void rt_hw_cpu_icache_disable()
  53. {
  54. __asm(" MRC p15, #0, r1, c1, c0, #0 ; Read SCTLR configuration data");
  55. __asm(" BIC r1, r1, #0x1 <<12 ; instruction cache enable");
  56. __asm(" MCR p15, #0, r1, c1, c0, #0 ; disabled instruction cache");
  57. __asm(" ISB");
  58. }
  59. void rt_hw_cpu_dcache_enable()
  60. {
  61. __asm(" MRC p15, #0, R1, c1, c0, #0 ; Read SCTLR configuration data");
  62. __asm(" ORR R1, R1, #0x1 <<2");
  63. __asm(" DSB");
  64. __asm(" MCR p15, #0, r0, c15, c5, #0 ; Invalidate entire data cache");
  65. __asm(" MCR p15, #0, R1, c1, c0, #0 ; enabled data cache");
  66. }
  67. void rt_hw_cpu_dcache_disable()
  68. {
  69. /* FIXME: Clean entire data cache. This routine depends on the data cache
  70. * size. It can be omitted if it is known that the data cache has no dirty
  71. * data. */
  72. __asm(" MRC p15, #0, r1, c1, c0, #0 ; Read SCTLR configuration data");
  73. __asm(" BIC r1, r1, #0x1 <<2");
  74. __asm(" DSB");
  75. __asm(" MCR p15, #0, r1, c1, c0, #0 ; disabled data cache");
  76. }
  77. #elif __GNUC__
  78. int __rt_ffs(int value)
  79. {
  80. return __builtin_ffs(value);
  81. }
  82. #endif
  83. /*@}*/