0dbd214e254d309a8c7d15eb5def3d1f450a9d78
7 #include <native/task.h>
8 #include <native/timer.h>
9 #include <native/intr.h>
17 RT_TASK intrtask
, drawtask
;
21 unsigned char data
[MAXX
] = {
22 1, 2, 4, 8, 16, 32, 64, 128, 256,
23 1, 2, 4, 8, 16, 32, 64, 128, 256
26 void add_tick(RTIME
*t
, RTIME tnew
)
30 for(i
=TICKS
-1; i
>0; i
--){
35 t
[TICKS
] = t
[TICKS
]/TICKS
;
40 RTIME time
= *(RTIME
*)arg
;
41 RTIME step
= time
/(2*MAXX
+2);
46 rt_task_sleep(step
*2);
47 for(i
=0; i
<MAXX
; i
++){
49 rt_task_sleep(step
/2);
51 rt_task_sleep(step
/2);
56 //rt_printf("Every x has %.2fms\n", step/1000/1000.0);
61 //Register as interrupt handler
63 rt_intr_create(&intr
, NULL
, LPT1IRQ
, 0);
64 rt_printf("Interrupt created\n");
66 //Initialize and declare the timer variables
67 RTIME tick
= rt_timer_read();
71 tock
= rt_timer_read();
72 add_tick(ticks
, tock
-tick
);
74 // Tocks waiting period
75 if(tocks
[TICKS
] < ticks
[TICKS
]){
76 // sleep until the arm is most left
77 rt_task_sleep(tocks
[TICKS
]/2);
78 rt_task_create(&drawtask
, NULL
, 0, 50, 0);
79 period
= ticks
[TICKS
]+tocks
[TICKS
];
80 rt_task_start(&drawtask
, &taskd
, &period
);
81 rt_printf("tocks is the short stretch\n");
83 rt_intr_wait(&intr
, TM_INFINITE
);
86 tick
= rt_timer_read();
87 add_tick(tocks
, tick
-tock
);
89 if(ticks
[TICKS
] < tocks
[TICKS
]){
90 // sleep until the arm is most left
91 rt_task_sleep(ticks
[TICKS
]/2);
92 rt_task_create(&drawtask
, NULL
, 0, 50, 0);
93 period
= ticks
[TICKS
]+tocks
[TICKS
];
94 rt_task_start(&drawtask
, &taskd
, &period
);
95 rt_printf("ticks is the short stretch\n");
97 rt_intr_wait(&intr
, TM_INFINITE
);
99 //rt_printf("avgtick: %lluns, avgtock: %lluns, avgticktock: %lluns\n",
100 // ticks[TICKS], tocks[TICKS], (ticks[TICKS]+tocks[TICKS])/2);
104 int main(int argc
, char* argv
[])
106 rt_print_auto_init(1);
107 mlockall(MCL_CURRENT
| MCL_FUTURE
);
109 // Get permission to write to parallel port
112 outb(inb(0x37A) | 0x10, 0x37A);
114 rt_task_create(&intrtask
, NULL
, 0, 50, 0);
115 rt_task_start(&intrtask
, &taski
, 0);