研讀"如何自己用SOPC Builder建立一個能在DE2-70上跑μC/OS-II的Nios II系統?"裡面的C
时间:2011-02-03 来源:布魯斯
1 #include <stdio.h>這是透過IORD函數讀去DE2-70板子上的SW狀態到i這個定義裡面( i = IORD(PIO_SW_BASE, 0);)其中PIO_SW_BASE的定義是在system.h裡面有定義,再透過IOWR把i寫入RED LED裡面
2 #include "includes.h"
3 #include "system.h"
4 #include <io.h>
5
6 /* Definition of Task Stacks */
7 #define TASK_STACKSIZE 2048
8 OS_STK task1_stk[TASK_STACKSIZE];
9 OS_STK task2_stk[TASK_STACKSIZE];
10
11 /* Definition of Task Priorities */
12
13 #define TASK1_PRIORITY 1
14 #define TASK2_PRIORITY 2
15
16 /* Prints "Hello World" and sleeps for three seconds */
17 void task1(void* pdata)
18 {
19 while (1)
20 {
21 printf("Hello uCOS-II\n");
22 OSTimeDlyHMSM(0, 0, 3, 0);
23 }
24 }
25 /* Prints "Hello World" and sleeps for three seconds */
26 void task2(void* pdata)
27 {
28 unsigned int i;
29 while (1)
30 {
31 // read switch
32 i = IORD(PIO_SW_BASE, 0);
33 // write ledr
34 IOWR(PIO_LEDR_BASE, 0, i);
35 }
36 }
37 /* The main function creates two task and starts multi-tasking */
38 int main(void)
39 {
40 OSTaskCreateExt(task1,
41 NULL,
42 (void *)&task1_stk[TASK_STACKSIZE-1],
43 TASK1_PRIORITY,
44 TASK1_PRIORITY,
45 task1_stk,
46 TASK_STACKSIZE,
47 NULL,
48 0);
49 OSTaskCreateExt(task2,
50 NULL,
51 (void *)&task2_stk[TASK_STACKSIZE-1],
52 TASK2_PRIORITY,
53 TASK2_PRIORITY,
54 task2_stk,
55 TASK_STACKSIZE,
56 NULL,
57 0);
58 OSStart();
59 return 0;
60 }
1. OSTimeDlyHMSM函數
函數說明:INT8U OSTimeDlyHMSM(INT8U hours, INT8U minutes, INT8U seconds, INT16U milli)
2.IORD與IOWR(定義在io.h)
函數說明I. IORD(BASE, REGNUM) II. IOWR(BASE, REGNUM, DATA)26 void task2(void* pdata)
27 {
28 unsigned int i;
29 while (1)
30 {
31 // read switch
32 i = IORD(PIO_SW_BASE, 0);
33 // write ledr
34 IOWR(PIO_LEDR_BASE, 0, i);
35 }
36 }
PIO_LEDR_BASE一樣定義在system.h裡面
其他部分還在研究~~~
相关阅读 更多 +