cpu.c 2.3 KB

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