12.07.2015 Views

Použití OS Linux pro měřicí aplikace

Použití OS Linux pro měřicí aplikace

Použití OS Linux pro měřicí aplikace

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

PŘÍLOHA B. ZDROJOVÝ KÓD - SEKUNDOVÝ GENERÁTOR S HPET ČASOVAČEM}i n t main ( ) {s t r u c t t i m e s p e c t t s , t t s _ a f t e r , t t s _ d e l t a ;const s t r u c t t i m e s p e c i n t e r v a l _ u p = {0 ,100000000};s t r u c t t i m e s p e c interval_down = {0 ,900000000 −CORRECT_SYST} ;s t r u c t sched_param s c h e d u l i n g _ p a r a m e t e r s ;i n t count = 0 ;comedi_t ∗ i t ;i n t subdev = 2 ;i n t chan = 0 ;/∗ Lock pages i n r e a l memmory ∗/m l o c k a l l (MCL_CURRENT|MCL_FUTURE) ;/∗ Setup p r i o r i t y o f p r o c e s s ∗/s c h e d u l i n g _ p a r a m e t e r s . s c h e d _ p r i o r i t y = sched_get_priority_max (SCHED_FIFO) − 4 ;/∗ Setup s c h e d u l i n g s t r a t e g y ∗/i f (0 != pthread_setschedparam ( p t h r e a d _ s e l f ( ) , SCHED_FIFO , &s c h e d u l i n g _ p a r a m e t e r s ) ){p e r r o r ( " pthread_setschedparam ␣ e r r o r " ) ;}/∗ Open Comedi d e v i c e ∗/i t = comedi_open ( "/ dev / comedi0 " ) ;/∗ C o n f i g u r e l i n e s to DO ∗/comedi_dio_config ( i t , subdev , chan ,COMEDI_OUTPUT) ;}/∗ Get time to measure r u n n i n g time ∗/c l ock_gettime (CLOCK_REALTIME,& t t s ) ;f o r ( count = 0 ; count < CNT; count++) {comedi_dio_write ( i t , subdev , chan , 1 ) ;n a n o s l e e p (& i n t e r v a l _ u p , NULL) ;comedi_dio_write ( i t , subdev , chan , 0 ) ;n a n o s l e e p (& interval_down , NULL) ;}/∗ Get time to measure r u n n i n g time ∗/c l ock_gettime (CLOCK_REALTIME,& t t s _ a f t e r ) ;d e l t a _ t (& t t s _ d e l t a , &t t s , &t t s _ a f t e r ) ;p r i n t f ( " Total ␣ w a i t : ␣%l u ␣ s e c ␣%l u ␣ nsec \n" , t t s _ d e l t a . tv_sec , t t s _ d e l t a .tv_nsec ) ;comedi_close ( i t ) ;return 0 ;30

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!