RTIME tocks[TICKS+1];
unsigned char data[MAXX] = {
- 1, 2, 4, 8, 16, 32, 64, 128, 256,
- 1, 2, 4, 8, 16, 32, 64, 128, 256
+ 1, 2, 4, 8, 16, 32, 64, 128, 256,
+ 1, 2, 4, 8, 16, 32, 64, 128, 256
};
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;
+ 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;
- RTIME step = time/(2*MAXX+2);
- unsigned int i;
+ RTIME time = *(RTIME *)arg;
+ RTIME step = time/(2*MAXX+2);
+ unsigned int i;
- //To the right
+ //To the right
outb(0x00, 0x378);
- rt_task_sleep(step*2);
- for(i=0; i<MAXX; i++){
- outb(data[i], 0x378);
- rt_task_sleep(step/2);
- outb(0x00, 0x378);
- rt_task_sleep(step/2);
- }
- rt_task_sleep(step);
+ rt_task_sleep(step*2);
+ for(i=0; i<MAXX; i++){
+ outb(data[i], 0x378);
+ rt_task_sleep(step/2);
+ outb(0x00, 0x378);
+ rt_task_sleep(step/2);
+ }
+ rt_task_sleep(step);
outb(0x00, 0x378);
- //rt_printf("Every x has %.2fms\n", step/1000/1000.0);
+ //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");
+ rt_printf("Interrupt created\n");
- //Initialize and declare the timer variables
+ //Initialize and declare the timer variables
RTIME tick = rt_timer_read();
- RTIME tock;
- RTIME period;
+ RTIME tock;
+ RTIME period;
while(1){
- tock = rt_timer_read();
- add_tick(ticks, tock-tick);
-
- // Tocks waiting period
- 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]+tocks[TICKS];
- rt_task_start(&drawtask, &taskd, &period);
- rt_printf("tocks is the short stretch\n");
- }
+ tock = rt_timer_read();
+ add_tick(ticks, tock-tick);
+
+ // Tocks waiting period
+ 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]+tocks[TICKS];
+ rt_task_start(&drawtask, &taskd, &period);
+ rt_printf("tocks is the short stretch\n");
+ }
rt_intr_wait(&intr, TM_INFINITE);
- //Tick waiting period
- tick = rt_timer_read();
- add_tick(tocks, tick-tock);
-
- 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 = ticks[TICKS]+tocks[TICKS];
- rt_task_start(&drawtask, &taskd, &period);
- rt_printf("ticks is the short stretch\n");
- }
+ //Tick waiting period
+ tick = rt_timer_read();
+ add_tick(tocks, tick-tock);
+
+ 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 = ticks[TICKS]+tocks[TICKS];
+ rt_task_start(&drawtask, &taskd, &period);
+ rt_printf("ticks is the short stretch\n");
+ }
rt_intr_wait(&intr, TM_INFINITE);
- //Print average
- //rt_printf("avgtick: %lluns, avgtock: %lluns, avgticktock: %lluns\n",
- // ticks[TICKS], tocks[TICKS], (ticks[TICKS]+tocks[TICKS])/2);
+ //Print average
+ //rt_printf("avgtick: %lluns, avgtock: %lluns, avgticktock: %lluns\n",
+ // ticks[TICKS], tocks[TICKS], (ticks[TICKS]+tocks[TICKS])/2);
}
}