board.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * File : board.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2009 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://www.rt-thread.org/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2009-01-05 Bernard first implementation
  13. * 2010-02-04 Magicoe ported to LPC17xx
  14. * 2010-05-02 Aozima update CMSIS to 130
  15. */
  16. #include <rthw.h>
  17. #include <rtthread.h>
  18. #include "board.h"
  19. #include "drv_uart.h"
  20. #ifdef RT_USING_COMPONENTS_INIT
  21. #include <components.h>
  22. #endif
  23. /**
  24. * This is the timer interrupt service routine.
  25. *
  26. */
  27. void SysTick_Handler(void)
  28. {
  29. /* enter interrupt */
  30. rt_interrupt_enter();
  31. rt_tick_increase();
  32. /* leave interrupt */
  33. rt_interrupt_leave();
  34. }
  35. /**
  36. * This function will initial LPC54xx board.
  37. */
  38. void rt_hw_board_init()
  39. {
  40. /* NVIC Configuration */
  41. #define NVIC_VTOR_MASK 0x3FFFFF80
  42. #ifdef VECT_TAB_RAM
  43. /* Set the Vector Table base location at 0x10000000 */
  44. SCB->VTOR = (0x10000000 & NVIC_VTOR_MASK);
  45. #else /* VECT_TAB_FLASH */
  46. /* Set the Vector Table base location at 0x00000000 */
  47. SCB->VTOR = (0x00000000 & NVIC_VTOR_MASK);
  48. #endif
  49. SystemCoreClockUpdate();
  50. /* init systick 1 systick = 1/(100M / 100) 100¸ösystick = 1s*/
  51. SysTick_Config(SystemCoreClock / RT_TICK_PER_SECOND);
  52. /* set pend exception priority */
  53. NVIC_SetPriority(PendSV_IRQn, (1 << __NVIC_PRIO_BITS) - 1);
  54. /*init uart device*/
  55. rt_hw_uart_init();
  56. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  57. #if LPC_EXT_SDRAM == 1
  58. lpc_sdram_hw_init();
  59. mpu_init();
  60. #endif
  61. #ifdef RT_USING_COMPONENTS_INIT
  62. /* initialization board with RT-Thread Components */
  63. rt_components_board_init();
  64. #endif
  65. }
  66. /* initialization for system heap */
  67. int rt_hw_board_heap_init(void)
  68. {
  69. #ifdef RT_USING_HEAP
  70. #if LPC_EXT_SDRAM
  71. #include "drv_sram.h"
  72. rt_system_heap_init((void *)LPC_EXT_SDRAM_BEGIN, (void *)LPC_EXT_SDRAM_END);
  73. sram_init();
  74. #else
  75. rt_system_heap_init((void *)HEAP_BEGIN, (void *)HEAP_END);
  76. #endif
  77. #endif
  78. return 0;
  79. }
  80. void MemManage_Handler(void)
  81. {
  82. extern void HardFault_Handler(void);
  83. rt_kprintf("Memory Fault!\n");
  84. HardFault_Handler();
  85. }