130 likes | 287 Views
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
E N D
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 • Cygwin on Windows XP • GNU GCC
Lab. Procedures • Create Timer. • Append mutex to your program.
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;
Reference functions • Definition: examine and change signal action • #include <signal.h> • int sigaction( int sig, const struct sigaction *act, struct sigaction *oact);
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:
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*/ };
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);
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);
Reference functions • Definition: wait for a signal • #include <signal.h> • int sigsuspend(constsigset_t *sigmask);
Download files You can download the aLAB5.tar (include reference code) from http://newslab.csie.ntu.edu.tw/course/NetworkedSoCSystems/files/aLAB5.tar
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.