|
| 1 | +/* |
| 2 | + * Copyright (c) 2006-2019, RT-Thread Development Team |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + * |
| 6 | + * Change Logs: |
| 7 | + * Date Author Notes |
| 8 | + * 2019-12-04 Jiaxun Yang Initial version |
| 9 | + */ |
| 10 | + |
| 11 | +/** |
| 12 | + * @addtogroup mipssim |
| 13 | + */ |
| 14 | + |
| 15 | +/*@{*/ |
| 16 | + |
| 17 | +#include <rtthread.h> |
| 18 | +#include <rthw.h> |
| 19 | + |
| 20 | +#include "mips_regs.h" |
| 21 | +#include "exception.h" |
| 22 | +#include "drv_uart.h" |
| 23 | + |
| 24 | +#define CPU_HZ (100 * 1000 * 1000) |
| 25 | +#define RT_HW_HEAP_END (0x80000000 + 64 * 1024 * 1024) |
| 26 | + |
| 27 | +extern unsigned char __bss_end; |
| 28 | + |
| 29 | +/** |
| 30 | + * this function will reset CPU |
| 31 | + * |
| 32 | + */ |
| 33 | +void rt_hw_cpu_reset(void) |
| 34 | +{ |
| 35 | + rt_kprintf("reboot system...\n"); |
| 36 | + while (1); |
| 37 | +} |
| 38 | + |
| 39 | +/** |
| 40 | + * this function will shutdown CPU |
| 41 | + * |
| 42 | + */ |
| 43 | +void rt_hw_cpu_shutdown(void) |
| 44 | +{ |
| 45 | + rt_kprintf("shutdown...\n"); |
| 46 | + |
| 47 | + while (1); |
| 48 | +} |
| 49 | + |
| 50 | + |
| 51 | +/** |
| 52 | + * This is the timer interrupt service routine. |
| 53 | + */ |
| 54 | +void 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 | + */ |
| 68 | +void 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 | + */ |
| 78 | +void rt_hw_board_init(void) |
| 79 | +{ |
| 80 | + rt_hw_exception_init(); |
| 81 | + |
| 82 | + /* init hardware interrupt */ |
| 83 | + rt_hw_interrupt_init(); |
| 84 | + |
| 85 | + #ifdef RT_USING_FPU |
| 86 | + /* init hardware fpu */ |
| 87 | + rt_hw_fpu_init(); |
| 88 | + #endif |
| 89 | + |
| 90 | +#ifdef RT_USING_SERIAL |
| 91 | + /* init hardware UART device */ |
| 92 | + rt_hw_uart_init(); |
| 93 | + /* set console device */ |
| 94 | + rt_console_set_device("uart"); |
| 95 | +#endif |
| 96 | + |
| 97 | +#ifdef RT_USING_HEAP |
| 98 | + rt_system_heap_init((void*)&__bss_end, (void*)RT_HW_HEAP_END); |
| 99 | +#endif |
| 100 | + |
| 101 | + /* init operating system timer */ |
| 102 | + rt_hw_timer_init(); |
| 103 | + |
| 104 | + |
| 105 | +#ifdef RT_USING_COMPONENTS_INIT |
| 106 | + rt_components_board_init(); |
| 107 | +#endif |
| 108 | + |
| 109 | + rt_kprintf("Current SR: 0x%08x\n", read_c0_status()); |
| 110 | + |
| 111 | +} |
| 112 | + |
| 113 | +/*@}*/ |
0 commit comments