board.c 2.8 KB

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