1 /*
2 * Copyright (c) 2006-2021, RT-Thread Development Team
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Change Logs:
7 * Date Author Notes
8 * 2011-02-14 aozima first implementation for Nios II.
9 */
10
11
12 #include <rthw.h>
13 #include <rtthread.h>
14
15 #include <stdio.h>
16 #include "system.h"
17 #include "sys/alt_irq.h"
18 #include "altera_avalon_timer_regs.h"
19
20 #include "uart.h"
21
22 extern int alt_irq_register (alt_u32 id,
23 void* context,
24 void (*alt_isr_func)(void* isr_context, alt_u32 id) );
25
26 /**
27 * @addtogroup NIOS_II
28 */
29
30 /*@{*/
31
32 /**
33 * This is the timer interrupt service routine.
34 *
35 */
rt_hw_timer_handler(void * context,unsigned long id)36 void rt_hw_timer_handler(void * context,unsigned long id)
37 {
38 void* base = (void*)TIMER_BASE;
39
40 /* clear the interrupt */
41 IOWR_ALTERA_AVALON_TIMER_STATUS (base, 0);
42
43 /* enter interrupt */
44 rt_interrupt_enter();
45
46 rt_tick_increase();
47
48 /* leave interrupt */
49 rt_interrupt_leave();
50 }
51
sysTick_config(void)52 void sysTick_config(void)
53 {
54 void* base = (void*)TIMER_BASE;
55
56 IOWR_ALTERA_AVALON_TIMER_CONTROL (base,
57 ALTERA_AVALON_TIMER_CONTROL_ITO_MSK |
58 ALTERA_AVALON_TIMER_CONTROL_CONT_MSK |
59 ALTERA_AVALON_TIMER_CONTROL_START_MSK);
60
61 alt_irq_register (TIMER_IRQ, NULL, rt_hw_timer_handler);
62 }
63
rt_hw_show_info(void)64 static void rt_hw_show_info(void)
65 {
66 rt_kprintf("\r\n\r\n---------- board info ----------\r\n");
67 rt_kprintf("ALT_DEVICE_FAMILY: %s\r\n",ALT_DEVICE_FAMILY);
68 rt_kprintf("ALT_CPU_ARCHITECTURE: %s\r\n",ALT_CPU_ARCHITECTURE);
69 rt_kprintf("ALT_CPU_CPU_FREQ: %uMHz\r\n",ALT_CPU_CPU_FREQ/1000000UL);
70 rt_kprintf("memory size: at 0x%08X 0x%08X byte\r\n",SDRAM_BASE,SDRAM_SPAN);
71 }
72
rt_hw_board_init(void)73 void rt_hw_board_init(void)
74 {
75 rt_hw_uart_init();
76 rt_console_set_device("uart");
77 rt_hw_show_info();
78
79 sysTick_config();
80 }
81
82 /*@}*/
83
84