cpuport.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. * 2010-07-09 Bernard first version
  9. * 2010-09-11 Bernard add CPU reset implementation
  10. * 2015-07-06 chinesebear modified for loongson 1c
  11. */
  12. #include <rtthread.h>
  13. #include "gs232.h"
  14. /**
  15. * @addtogroup Loongson GS232
  16. */
  17. /*@{*/
  18. /**
  19. * this function will reset CPU
  20. *
  21. */
  22. RT_WEAK void rt_hw_cpu_reset(void)
  23. {
  24. /* open the watch-dog */
  25. WDT_EN = 0x01; /* watch dog enable */
  26. WDT_TIMER = 0x01; /* watch dog will be timeout after 1 tick */
  27. WDT_SET = 0x01; /* watch dog start */
  28. rt_kprintf("reboot system...\n");
  29. while (1);
  30. }
  31. /**
  32. * this function will shutdown CPU
  33. *
  34. */
  35. RT_WEAK void rt_hw_cpu_shutdown(void)
  36. {
  37. rt_kprintf("shutdown...\n");
  38. while (1);
  39. }
  40. #define Hit_Invalidate_I 0x10
  41. #define Hit_Invalidate_D 0x11
  42. #define CONFIG_SYS_CACHELINE_SIZE 32
  43. #define Hit_Writeback_Inv_D 0x15
  44. void flush_cache(unsigned long start_addr, unsigned long size)
  45. {
  46. unsigned long lsize = CONFIG_SYS_CACHELINE_SIZE;
  47. unsigned long addr = start_addr & ~(lsize - 1);
  48. unsigned long aend = (start_addr + size - 1) & ~(lsize - 1);
  49. while (1) {
  50. cache_op(Hit_Writeback_Inv_D, addr);
  51. cache_op(Hit_Invalidate_I, addr);
  52. if (addr == aend)
  53. break;
  54. addr += lsize;
  55. }
  56. }
  57. /*@}*/