board.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 LPC40xx 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. //redirect RTT stdio to CONSOLE device
  56. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  57. }
  58. int rt_hw_cpu_init(void)
  59. {
  60. MAP_IntMasterDisable();
  61. IntRegister(FAULT_HARD, HardFault_Handler);
  62. IntRegister(FAULT_PENDSV, PendSV_Handler);
  63. IntRegister(FAULT_SYSTICK, SysTick_Handler);
  64. // Enable lazy stacking for interrupt handlers. This allows floating-point
  65. // instructions to be used within interrupt handlers, but at the expense of
  66. // extra stack usage.
  67. MAP_FPULazyStackingEnable();
  68. // Set the clocking to run directly from the external crystal/oscillator.
  69. // TODO: The SYSCTL_XTAL_ value must be changed to match the value of the
  70. // crystal on your board.
  71. SystemCoreClock = MAP_SysCtlClockFreqSet(
  72. (SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480),
  73. SYS_CLOCK_DEFAULT);
  74. MAP_SysTickDisable();
  75. MAP_SysTickPeriodSet(SystemCoreClock/ RT_TICK_PER_SECOND - 1);
  76. MAP_SysTickIntEnable();
  77. MAP_SysTickEnable();
  78. return 0;
  79. }
  80. // rt_hw_cpu_init should be run before any other INIT_BOARD_EXPORT
  81. // We use INIT_EXPORT here and set the sequence index to "0.xxxx"
  82. INIT_EXPORT(rt_hw_cpu_init, "0.post");