cpu.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * File : cpu.c
  3. * COPYRIGHT (C) 2008 - 2016, RT-Thread Development Team
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program; if not, write to the Free Software Foundation, Inc.,
  17. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  18. *
  19. * Change Logs:
  20. * Date Author Notes
  21. * 2010-07-09 Bernard first version
  22. * 2010-09-11 Bernard add CPU reset implementation
  23. */
  24. #include <rtthread.h>
  25. #include <board.h>
  26. /**
  27. * @addtogroup Ingenic
  28. */
  29. /*@{*/
  30. /**
  31. * this function will reset CPU
  32. *
  33. */
  34. void rt_hw_cpu_reset()
  35. {
  36. /* open the watch-dog */
  37. REG_WDT_TCSR = WDT_TCSR_EXT_EN;
  38. REG_WDT_TCSR |= WDT_TCSR_PRESCALE_1024;
  39. REG_WDT_TDR = 0x03;
  40. REG_WDT_TCNT = 0x00;
  41. REG_WDT_TCER |= WDT_TCER_TCEN;
  42. rt_kprintf("reboot system...\n");
  43. while (1);
  44. }
  45. /**
  46. * this function will shutdown CPU
  47. *
  48. */
  49. void rt_hw_cpu_shutdown()
  50. {
  51. rt_kprintf("shutdown...\n");
  52. while (1);
  53. }
  54. /**
  55. * This function finds the first bit set (beginning with the least significant bit)
  56. * in value and return the index of that bit.
  57. *
  58. * Bits are numbered starting at 1 (the least significant bit). A return value of
  59. * zero from any of these functions means that the argument was zero.
  60. *
  61. * @return return the index of the first bit set. If value is 0, then this function
  62. * shall return 0.
  63. */
  64. int __rt_ffs(int value)
  65. {
  66. return __builtin_ffs(value);
  67. }
  68. /*@}*/