1 / 13

Lab: Timer and Timer Signals

Lab: Timer and Timer Signals. Lab. Goal. The goal of this lab is (1) to under the defects of software timers, (2) to write a periodic program without timers, (3) to write a periodic program using timer. Experimental Environment. Hardware Host computer PC Software

pavel
Télécharger la présentation

Lab: Timer and Timer Signals

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lab: Timer and Timer Signals

  2. Lab. Goal The goal of this lab is (1) to under the defects of software timers, (2) to write a periodic program without timers, (3) to write a periodic program using timer.

  3. Experimental Environment • Hardware • Host computer PC • Software • Cygwin on Windows XP • GNU GCC

  4. Lab. Procedures • Create Timer. • Append mutex to your program.

  5. Reference functions • Definition: control device • #include < sys/ioctl.h > int ioctl(int d, int request, ...) • request will be TIOCMGET and TIOCMSET • e.g. Get the status of rs232 registers, and set the RTS register to high ioctl(a, TIOCMGET, &status ); status |= TIOCM_RTS;

  6. Reference functions • Definition: examine and change signal action • #include <signal.h> • int sigaction( int sig, const struct sigaction *act, struct sigaction *oact);

  7. Reference functions • The structure sigaction, used to describe an action to be taken, is defined in the header <signal.h> to include at least the following members:

  8. Reference functions Definition: Structure for timer_ functions itimerspec Public Attributes Timespec it_value // current value Timespec it_interval // reset value struct timespec { time_t tv_sec; /**< seconds*/ long tv_nsec; /**< nanoseconds*/ };

  9. Reference functions • Definition: create a per-process timer (REALTIME) • #include <time.h> • #include <signal.h> • include library -lrt • int timer_create( clockid_t clockid, struct sigevent *evp, timer_t *timerid);

  10. Reference functions • Definition: set timer time (REALTIME) • #include <time.h> • include library #-lrt • int timer_settime( timer_t timerid, int flags, const struct itimerspec *value, struct itimerspec *ovalue);

  11. Reference functions • Definition: wait for a signal • #include <signal.h> • int sigsuspend(constsigset_t *sigmask);

  12. Download files You can download the aLAB5.tar (include reference code) from http://newslab.csie.ntu.edu.tw/course/NetworkedSoCSystems/files/aLAB5.tar

  13. Sampling Periods • Task T1: period =200 ms • Task T2: period =100 ms • I/O: get and print out current time to a file. • Computation: double x; for(i=1;i<1+(int) (1000.0*rand()/(RAND_MAX+1.0)); i++){ x = sin(x * 1000);} • I/O: get and print out current time to a file.

More Related