void *ClockChrono_Read(void *args) { RT_TASK *mytask; char ch; int run = 0; mqd_t Keyboard; struct mq_attr kb_attrs = { MAX_MSGS, 1, 0, 0 }; if (!(mytask = rt_thread_init(nam2num("READ"), 1, 0, SCHED_FIFO, 0xF))) { printf("CANNOT INIT TASK ClockChronoRead\n"); exit(1); } Keyboard = mq_open("KEYBRD", O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP, &kb_attrs); printf("INIT TASK ClockChronoRead %p.\n", mytask); mlockall(MCL_CURRENT | MCL_FUTURE); while(1) { mq_receive(Keyboard, &ch, 1, NULL); ch = toupper(ch); switch(ch) { case 'T': case 'R': case 'H': case 'M': case 'S': CommandClock_Put(ch); break; case 'C': case 'I': case 'E': CommandChrono_Put(ch); break; case 'N': hide = ~hide; break; case 'P': Pause = TRUE; rt_fractionated_sleep(nano2count(FIVE_SECONDS)); Pause = FALSE; break; case 'K': case 'D': run |= ch; if (run == ('K' | 'D')) { sem_post(&sync_sem); sem_post(&sync_sem); } break; case 'F': CommandClock_Put('F'); CommandChrono_Put('F'); goto end; } } end: mq_close(Keyboard); rt_task_delete(mytask); printf("END TASK ClockChronoRead %p.\n", mytask); return 0; }
static void ClockChrono_Read(long t) { char ch; unsigned int run = 0; while(1) { cpu_used[hard_cpu_id()]++; rt_sem_wait(&keybrd_sem); rtf_get(Keyboard, &ch, 1); ch = toupper(ch); switch(ch) { case 'T': case 'R': case 'H': case 'M': case 'S': CommandClock_Put(ch); break; case 'C': case 'I': case 'E': CommandChrono_Put(ch); break; case 'N': hide = ~hide; break; case 'P': pause = TRUE; rt_fractionated_sleep(nano2count(FIVE_SECONDS)); pause = FALSE; break; case 'K': case 'D': run += ch; if (run == ('K' + 'D')) { rt_send(&clock, run); rt_send(&chrono, run); } break; } } }