6e107db73795b20d0a3fb5401e29462b156d2de0
7 #include <native/task.h>
8 #include <native/timer.h>
9 #include <native/intr.h>
18 RT_TASK intrtask
, drawtask
;
22 void add_tick(RTIME
*t
, RTIME tnew
)
26 for(i
=TICKS
-1; i
>0; i
--){
31 t
[TICKS
] = t
[TICKS
]/TICKS
;
36 RTIME time
= *(RTIME
*)arg
;
37 rt_printf("Time to draw=%.2fms\n", time
/1000/1000.0);
38 RTIME step
= time
/MAXX
;
39 rt_printf("Every x has %.2fms\n", step
/1000/1000.0);
44 //Register as interrupt handler
46 rt_intr_create(&intr
, NULL
, LPT1IRQ
, 0);
47 rt_printf("Interrupt created\n");
49 //Initialize and declare the timer variables
50 RTIME tick
= rt_timer_read();
54 //Wait for tick (long stretch)
55 rt_intr_wait(&intr
, TM_INFINITE
);
56 tock
= rt_timer_read();
57 add_tick(ticks
, rt_timer_read()-tick
);
59 // Tocks are the short stretches
60 if(tocks
[TICKS
] < ticks
[TICKS
]){
61 // sleep until the arm is most left
62 rt_task_sleep(tocks
[TICKS
]/2);
63 rt_task_create(&drawtask
, NULL
, 0, 50, 0);
64 period
= ticks
[TICKS
]/2+tocks
[TICKS
]/2;
65 rt_task_start(&drawtask
, &taskd
, &period
);
66 rt_printf("tocks is the short stretch\n");
69 //Wait for tock (shorter stretch)
70 rt_intr_wait(&intr
, TM_INFINITE
);
71 tick
= rt_timer_read();
72 add_tick(tocks
, rt_timer_read()-tock
);
75 if(ticks
[TICKS
] < tocks
[TICKS
]){
76 // sleep until the arm is most left
77 rt_task_sleep(ticks
[TICKS
]/2);
78 rt_task_create(&drawtask
, NULL
, 0, 50, 0);
79 period
= tocks
[TICKS
]/2+ticks
[TICKS
]/2;
80 rt_task_start(&drawtask
, &taskd
, &period
);
81 rt_printf("ticks is the short stretch\n");
85 //rt_printf("avgtick: %lluns, avgtock: %lluns, avgticktock: %lluns\n",
86 // ticks[TICKS], tocks[TICKS], (ticks[TICKS]+tocks[TICKS])/2);
90 int main(int argc
, char* argv
[])
92 rt_print_auto_init(1);
93 mlockall(MCL_CURRENT
| MCL_FUTURE
);
95 // Get permission to write to parallel port
98 outb(inb(0x37A) | 0x10, 0x37A);
100 rt_task_create(&intrtask
, NULL
, 0, 50, 0);
101 rt_task_start(&intrtask
, &taski
, 0);