board.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 "drv_uart.h"
  19. #include "driverlib/interrupt.h"
  20. #include "driverlib/sysctl.h"
  21. #include "driverlib/systick.h"
  22. #include "driverlib/fpu.h"
  23. #include "driverlib/rom_map.h"
  24. #define SYS_CLOCK_DEFAULT 120000000
  25. uint32_t SysClock;
  26. #define FAULT_NMI 2 // NMI fault
  27. #define FAULT_HARD 3 // Hard fault
  28. #define FAULT_MPU 4 // MPU fault
  29. #define FAULT_BUS 5 // Bus fault
  30. #define FAULT_USAGE 6 // Usage fault
  31. #define FAULT_SVCALL 11 // SVCall
  32. #define FAULT_DEBUG 12 // Debug monitor
  33. #define FAULT_PENDSV 14 // PendSV
  34. #define FAULT_SYSTICK 15 // System Tick
  35. /**
  36. * This is the timer interrupt service routine.
  37. *
  38. */
  39. void SysTick_Handler(void)
  40. {
  41. /* enter interrupt */
  42. rt_interrupt_enter();
  43. rt_tick_increase();
  44. /* leave interrupt */
  45. rt_interrupt_leave();
  46. }
  47. extern void PendSV_Handler(void);
  48. extern void HardFault_Handler(void);
  49. /**
  50. * This function will initial LPC40xx board.
  51. */
  52. void rt_hw_board_init()
  53. {
  54. MAP_IntMasterDisable();
  55. IntRegister(FAULT_HARD, HardFault_Handler);
  56. IntRegister(FAULT_PENDSV, PendSV_Handler);
  57. IntRegister(FAULT_SYSTICK, SysTick_Handler);
  58. //
  59. // Enable lazy stacking for interrupt handlers. This allows floating-point
  60. // instructions to be used within interrupt handlers, but at the expense of
  61. // extra stack usage.
  62. //
  63. MAP_FPULazyStackingEnable();
  64. //
  65. // Set the clocking to run directly from the external crystal/oscillator.
  66. // TODO: The SYSCTL_XTAL_ value must be changed to match the value of the
  67. // crystal on your board.
  68. //
  69. SysClock = MAP_SysCtlClockFreqSet(
  70. (SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480),
  71. SYS_CLOCK_DEFAULT);
  72. MAP_SysTickDisable();
  73. MAP_SysTickPeriodSet(SysClock/ RT_TICK_PER_SECOND - 1);
  74. MAP_SysTickIntEnable();
  75. MAP_SysTickEnable();
  76. /* set pend exception priority */
  77. //IntPrioritySet(FAULT_PENDSV, (1 << 5) - 1);
  78. /*init uart device*/
  79. rt_hw_uart_init();
  80. //redirect RTT stdio to CONSOLE device
  81. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  82. //
  83. // Enable interrupts to the processor.
  84. //
  85. MAP_IntMasterEnable();
  86. }