board.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * File : board.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2013 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. * 2014-07-18 ArdaFu Port to TM4C129X
  14. */
  15. #include <rthw.h>
  16. #include <rtthread.h>
  17. #include "board.h"
  18. #include "driverlib/interrupt.h"
  19. #include "driverlib/sysctl.h"
  20. #include "driverlib/systick.h"
  21. #include "driverlib/fpu.h"
  22. #include "driverlib/rom_map.h"
  23. #define SYS_CLOCK_DEFAULT 120000000
  24. uint32_t SystemCoreClock;
  25. #define FAULT_NMI 2 // NMI fault
  26. #define FAULT_HARD 3 // Hard fault
  27. #define FAULT_MPU 4 // MPU fault
  28. #define FAULT_BUS 5 // Bus fault
  29. #define FAULT_USAGE 6 // Usage fault
  30. #define FAULT_SVCALL 11 // SVCall
  31. #define FAULT_DEBUG 12 // Debug monitor
  32. #define FAULT_PENDSV 14 // PendSV
  33. #define FAULT_SYSTICK 15 // System Tick
  34. /**
  35. * This is the timer interrupt service routine.
  36. *
  37. */
  38. void SysTick_Handler(void)
  39. {
  40. /* enter interrupt */
  41. rt_interrupt_enter();
  42. rt_tick_increase();
  43. /* leave interrupt */
  44. rt_interrupt_leave();
  45. }
  46. extern void PendSV_Handler(void);
  47. extern void HardFault_Handler(void);
  48. /**
  49. * This function will initial TM4C129X board.
  50. */
  51. void rt_hw_board_init()
  52. {
  53. //init low level drivers. e.g. cpu uart etc.
  54. rt_components_board_init();
  55. //init HEAP.
  56. #ifdef RT_USING_HEAP
  57. rt_system_heap_init(HEAP_BEGIN, HEAP_END);
  58. #endif
  59. //redirect RTT stdio to CONSOLE device
  60. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  61. }
  62. int rt_hw_cpu_init(void)
  63. {
  64. MAP_IntMasterDisable();
  65. IntRegister(FAULT_HARD, HardFault_Handler);
  66. IntRegister(FAULT_PENDSV, PendSV_Handler);
  67. IntRegister(FAULT_SYSTICK, SysTick_Handler);
  68. // Enable lazy stacking for interrupt handlers. This allows floating-point
  69. // instructions to be used within interrupt handlers, but at the expense of
  70. // extra stack usage.
  71. MAP_FPULazyStackingEnable();
  72. // Set the clocking to run directly from the external crystal/oscillator.
  73. // TODO: The SYSCTL_XTAL_ value must be changed to match the value of the
  74. // crystal on your board.
  75. SystemCoreClock = MAP_SysCtlClockFreqSet(
  76. (SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480),
  77. SYS_CLOCK_DEFAULT);
  78. MAP_SysTickDisable();
  79. MAP_SysTickPeriodSet(SystemCoreClock/ RT_TICK_PER_SECOND - 1);
  80. MAP_SysTickIntEnable();
  81. MAP_SysTickEnable();
  82. return 0;
  83. }
  84. // rt_hw_cpu_init should be run before any other INIT_BOARD_EXPORT
  85. // We use INIT_EXPORT here and set the sequence index to "0.xxxx"
  86. INIT_EXPORT(rt_hw_cpu_init, "0.post");