1 /* 2 * Copyright (c) 2006-2020, RT-Thread Development Team 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 * 6 * Change Logs: 7 * Date Author Notes 8 * 2020-04-05 bigmagic Initial version 9 */ 10 11 #include <rtthread.h> 12 #include <rthw.h> 13 14 #include "mips_regs.h" 15 #include "mips_fpu.h" 16 #include "exception.h" 17 #include "drv_uart.h" 18 #include "board.h" 19 #include "ls2k1000.h" 20 21 /** 22 * this function will reset CPU 23 * 24 */ rt_hw_cpu_reset(void)25void rt_hw_cpu_reset(void) 26 { 27 WDT_EN = 0x01; 28 WDT_TIMER = 0x01; 29 WDT_SET = 0x01; 30 rt_kprintf("reboot system...\n"); 31 while (1); 32 } 33 MSH_CMD_EXPORT_ALIAS(rt_hw_cpu_reset, reboot, reset cpu); 34 35 36 /** 37 * this function will shutdown CPU 38 * 39 */ rt_hw_cpu_shutdown(void)40void rt_hw_cpu_shutdown(void) 41 { 42 PM1_STS &= 0xffffffff; 43 PM1_CNT = 0x3c00; 44 rt_kprintf("shutdown...\n"); 45 46 while (1); 47 } 48 MSH_CMD_EXPORT_ALIAS(rt_hw_cpu_shutdown, poweroff, shutdown cpu); 49 50 51 /** 52 * This is the timer interrupt service routine. 53 */ rt_hw_timer_handler(void)54void rt_hw_timer_handler(void) 55 { 56 unsigned int count; 57 58 count = read_c0_compare(); 59 write_c0_compare(count); 60 write_c0_count(0); 61 /* increase a OS tick */ 62 rt_tick_increase(); 63 } 64 65 /** 66 * This function will initial OS timer 67 */ rt_hw_timer_init(void)68void rt_hw_timer_init(void) 69 { 70 write_c0_compare(CPU_HZ / 2 / RT_TICK_PER_SECOND); 71 write_c0_count(0); 72 mips_unmask_cpu_irq(7); 73 } 74 75 /** 76 * Board level initialization 77 */ rt_hw_board_init(void)78void rt_hw_board_init(void) 79 { 80 rt_hw_exception_init(); 81 /* init hardware interrupt */ 82 rt_hw_interrupt_init(); 83 84 #ifdef RT_USING_FPU 85 /* init hardware fpu */ 86 rt_hw_fpu_init(); 87 #endif 88 89 #ifdef RT_USING_SERIAL 90 /* init hardware UART device */ 91 rt_hw_uart_init(); 92 /* set console device */ 93 rt_console_set_device(RT_CONSOLE_DEVICE_NAME); 94 #endif 95 96 #ifdef RT_USING_HEAP 97 rt_system_heap_init((void *)RT_HW_HEAP_BEGIN, (void *)RT_HW_HEAP_END); 98 #endif 99 100 /* init operating system timer */ 101 rt_hw_timer_init(); 102 103 #ifdef RT_USING_COMPONENTS_INIT 104 rt_components_board_init(); 105 #endif 106 107 rt_kprintf("Current SR: 0x%08x\n", read_c0_status()); 108 109 } 110