#include #include #include #include // ----- forward declaration ----- // void setLED( unsigned int status ); pthread_t thread01; pthread_t thread02; unsigned int curLED; //=================================================================================== void* task_fcn_num(void* arg) { long sec1 = 1000000000L; int n =0; int isOn = 0; //0: LED currently off, 1: currently on unsigned int tmp; //temp variable to compute LED pattern pthread_make_periodic_np( pthread_self(), gethrtime(), sec1 ); while (n<100) { pthread_wait_np(); //rtl_printf("n=%d\n", n); //debug only ++n; tmp = curLED; if (!isOn) { isOn =1; tmp |= 2; //Num-lock } else { isOn=0; tmp &= (0xFFFF ^ 0x2); } curLED = tmp; setLED( tmp ); }//end while return 0; } //=================================================================================== void* task_fcn_cap(void* arg) { long sec1 = 1000000000L; int n =0; int isOn = 0; //0: LED currently off, 1: currently on unsigned int tmp; //temp variable to compute LED pattern int rnd; //adjusting number while (n<100) { rnd = n % 3; pthread_make_periodic_np( pthread_self(), gethrtime(), sec1*rnd/3 + 200000000 ); pthread_wait_np(); rtl_printf("n=%d\n", n); //debug only ++n; tmp = curLED; if (!isOn) { isOn =1; tmp |= 4; //Cap-lock } else { isOn=0; tmp &= (0xFFFF ^ 0x4); } curLED = tmp; setLED( tmp ); }//end while return 0; } //=================================================================================== //=================================================================================== //BOITE NOIRE void setLED( unsigned int status ) { long cnt; //loop counter unsigned int stat; //keyboard status for (cnt=0; cnt<500000; ++cnt) { stat = rtl_inb(0x64); if ( (stat &0x02) == 0 ) break; }//end for rtl_outb(0xED, 0x60); //set LED for (cnt=0; cnt<500000; ++cnt){ stat = rtl_inb(0x64); if ( (stat & 0x02) == 0 ) break; }// end for rtl_outb(status, 0x60); //set LED } //end setLED(.) //=================================================================================== int init_module(void) { rtl_printf("init_module()...\n"); curLED = 0; pthread_create( &thread01, NULL, task_fcn_num, 0 ); pthread_create( &thread02, NULL, task_fcn_cap, 0 ); return 0; } void cleanup_module(void) { rtl_printf("cleanup_module().\n"); pthread_delete_np (thread01); pthread_delete_np (thread02); }