#include <rtdk.h>
#define LPT1IRQ 7
-#define TESTSAMPLES 20
+#define TICKS 5
+#define MAXX 10
+#define MAXY 7
-RT_TASK task;
-RTIME times[SAMPLES];
+RT_TASK intrtask, drawtask;
+RTIME ticks[TICKS+1];
+RTIME tocks[TICKS+1];
-void taskf(void *arg)
+void add_tick(RTIME *t, RTIME tnew)
+{
+ unsigned int i = 0;
+ t[TICKS] = 0;
+ for(i=TICKS-1; i>0; i--){
+ t[i] = t[i-1];
+ t[TICKS] += t[i];
+ }
+ t[0] = tnew;
+ t[TICKS] = t[TICKS]/TICKS;
+}
+
+void taskd(void *arg)
+{
+ RTIME time = *(RTIME *)arg;
+ rt_printf("Time to draw=%.2fms\n", time/1000/1000.0);
+ RTIME step = time/MAXX;
+ rt_printf("Every x has %.2fms\n", step/1000/1000.0);
+}
+
+void taski(void *arg)
{
//Register as interrupt handler
RT_INTR intr;
rt_intr_create(&intr, NULL, LPT1IRQ, 0);
+ rt_printf("Interrupt created\n");
- //Measure average time of the clock
- RTIME dur = rt_timer_read();
- unsigned int i;
- for(i = 0; i<TESTSAMPLES; i++){
+ //Initialize and declare the timer variables
+ RTIME tick = rt_timer_read();
+ RTIME tock;
+ RTIME period;
+ while(1){
+ //Wait for tick (long stretch)
rt_intr_wait(&intr, TM_INFINITE);
- }
- dur = rt_timer_read() / TESTSAMPLES;
- rt_printf("%d interrupts: average time: %.2f\n", TESTSAMPLES, dur);
+ tock = rt_timer_read();
+ add_tick(ticks, rt_timer_read()-tick);
- //Do the magic
- while(1){
+ // Tocks are the short stretches
+ if(tocks[TICKS] < ticks[TICKS]){
+ // sleep until the arm is most left
+ rt_task_sleep(tocks[TICKS]/2);
+ rt_task_create(&drawtask, NULL, 0, 50, 0);
+ period = ticks[TICKS]/2+tocks[TICKS]/2;
+ rt_task_start(&drawtask, &taskd, &period);
+ rt_printf("tocks is the short stretch\n");
+ }
+
+ //Wait for tock (shorter stretch)
rt_intr_wait(&intr, TM_INFINITE);
+ tick = rt_timer_read();
+ add_tick(tocks, rt_timer_read()-tock);
+
+ //Long stretch
+ if(ticks[TICKS] < tocks[TICKS]){
+ // sleep until the arm is most left
+ rt_task_sleep(ticks[TICKS]/2);
+ rt_task_create(&drawtask, NULL, 0, 50, 0);
+ period = tocks[TICKS]/2+ticks[TICKS]/2;
+ rt_task_start(&drawtask, &taskd, &period);
+ rt_printf("ticks is the short stretch\n");
+ }
+
+ //Print average
+ //rt_printf("avgtick: %lluns, avgtock: %lluns, avgticktock: %lluns\n",
+ // ticks[TICKS], tocks[TICKS], (ticks[TICKS]+tocks[TICKS])/2);
}
}
ioperm(0x378, 1, 1);
outb(inb(0x37A) | 0x10, 0x37A);
- rt_task_create(&task, NULL, 0, 50, 0);
- rt_task_start(&task, &taskf, 0);
+ rt_task_create(&intrtask, NULL, 0, 50, 0);
+ rt_task_start(&intrtask, &taski, 0);
pause();
}