rt_low_level_init.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * File : rt_low_level_init.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006 - 2015, RT-Thread Development Team
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * Change Logs:
  21. * Date Author Notes
  22. * 2015-04-14 ArdaFu first version
  23. */
  24. /* write register a=address, v=value */
  25. #define write_reg(a,v) (*(volatile unsigned int *)(a) = (v))
  26. /* Processor Reset */
  27. #define AT91_RSTC_PROCRST (1 << 0)
  28. #define AT91_RSTC_PERRST (1 << 2)
  29. #define AT91_RSTC_KEY (0xa5 << 24)
  30. #define AT91_MATRIX_BASE (0XFFFFEE00)
  31. /* Master Remap Control Register */
  32. #define AT91_MATRIX_MRCR (AT91_MATRIX_BASE + 0x100)
  33. /* Remap Command for AHB Master 0 (ARM926EJ-S InSTRuction Master) */
  34. #define AT91_MATRIX_RCB0 (1 << 0)
  35. /* Remap Command for AHB Master 1 (ARM926EJ-S Data Master) */
  36. #define AT91_MATRIX_RCB1 (1 << 1)
  37. #define AT91_AIC_BASE (0XFFFFF000)
  38. /* Interrupt DisaBLe Command Register */
  39. #define AT91_AIC_IDCR (AT91_AIC_BASE + 0x124)
  40. /* Interrupt Clear Command Register */
  41. #define AT91_AIC_ICCR (AT91_AIC_BASE + 0x128)
  42. #define AT91_WDT_BASE (0XFFFFFD40)
  43. #define AT91_WDT_CR (AT91_WDT_BASE + 0x00)
  44. #define AT91_WDT_CR_KEY (0xA5000000)
  45. #define AT91_WDT_CR_WDRSTT (0x00000001)
  46. #define AT91_WDT_MR (AT91_WDT_BASE + 0x04)
  47. #define AT91_WDT_MR_WDDIS (0x00008000)
  48. void rt_low_level_init(void)
  49. {
  50. // Mask all IRQs by clearing all bits in the INTMRS
  51. write_reg(AT91_AIC_IDCR, 0xFFFFFFFF);
  52. write_reg(AT91_AIC_ICCR, 0xFFFFFFFF);
  53. // Remap internal ram to 0x00000000 Address
  54. write_reg(AT91_MATRIX_MRCR, AT91_MATRIX_RCB0 | AT91_MATRIX_RCB1);
  55. // Disable the watchdog
  56. write_reg(AT91_WDT_CR, AT91_WDT_CR_KEY|AT91_WDT_CR_WDRSTT);
  57. write_reg(AT91_WDT_MR, AT91_WDT_MR_WDDIS);
  58. }