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