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 * 2011-03-04 aozima add led.
10 */
11
12 #include <rtthread.h>
13 #include "board.h"
14
15 /**
16 * @addtogroup NIOS_II
17 */
18
19 /*@{*/
20
21 #include "system.h"
22 #include "altera_avalon_pio_regs.h"
23
24 // trun on led n
25 #define rt_hw_led_on(n) IOWR_ALTERA_AVALON_PIO_DATA(\
26 LED_BASE,\
27 IORD_ALTERA_AVALON_PIO_DATA(LED_BASE) | 1<<n)
28 // trun off led n
29 #define rt_hw_led_off(n) IOWR_ALTERA_AVALON_PIO_DATA(\
30 LED_BASE,\
31 IORD_ALTERA_AVALON_PIO_DATA(LED_BASE) & ~(1<<n) )
32
33 rt_align(RT_ALIGN_SIZE)
34 static char thread_led1_stack[1024];
35 struct rt_thread thread_led1;
rt_thread_entry_led1(void * parameter)36 static void rt_thread_entry_led1(void* parameter)
37 {
38 unsigned int count=0;
39 while (1)
40 {
41 /* led1 on */
42 #ifndef RT_USING_FINSH
43 rt_kprintf("led1 on,count : %d\r\n",count);
44 #endif
45 count++;
46 rt_hw_led_on(1);
47 /* sleep 0.5 second and switch to other thread */
48 rt_thread_delay(RT_TICK_PER_SECOND/2);
49
50 /* led1 off */
51 #ifndef RT_USING_FINSH
52 rt_kprintf("led1 off\r\n");
53 #endif
54 rt_hw_led_off(1);
55 rt_thread_delay(RT_TICK_PER_SECOND/2);
56 }
57 }
58
59 rt_align(RT_ALIGN_SIZE)
60 static char thread_led2_stack[1024];
61 struct rt_thread thread_led2;
rt_thread_entry_led2(void * parameter)62 void rt_thread_entry_led2(void* parameter)
63 {
64 unsigned int count=0;
65 while (1)
66 {
67 /* led2 on */
68 #ifndef RT_USING_FINSH
69 rt_kprintf("led2 on,count : %d\r\n",count);
70 #endif
71 count++;
72 rt_hw_led_on(2);
73 rt_thread_delay(RT_TICK_PER_SECOND);
74
75 /* led2 off */
76 #ifndef RT_USING_FINSH
77 rt_kprintf("led2 off\r\n");
78 #endif
79 rt_hw_led_off(2);
80 rt_thread_delay(RT_TICK_PER_SECOND);
81 }
82 }
83
rt_application_init()84 int rt_application_init()
85 {
86 // led_init();
87
88 //------- init led1 thread
89 rt_thread_init(&thread_led1,
90 "led1",
91 rt_thread_entry_led1,
92 RT_NULL,
93 &thread_led1_stack[0],
94 sizeof(thread_led1_stack),11,5);
95 rt_thread_startup(&thread_led1);
96
97 //------- init led2 thread
98 rt_thread_init(&thread_led2,
99 "led2",
100 rt_thread_entry_led2,
101 RT_NULL,
102 &thread_led2_stack[0],
103 sizeof(thread_led2_stack),12,5);
104 rt_thread_startup(&thread_led2);
105
106 return 0;
107 }
108
109 /*@}*/
110
111