ClockPeriod ยป clock_period.cpp
| 1 |
//============================================================================
|
|---|---|
| 2 |
// Name : clock_period.cpp
|
| 3 |
// Author :
|
| 4 |
// Version :
|
| 5 |
// Copyright : Your copyright notice
|
| 6 |
// Description : Hello World in C++, Ansi-style
|
| 7 |
//============================================================================
|
| 8 |
|
| 9 |
#include <iostream>
|
| 10 |
#include <stdlib.h>
|
| 11 |
#include <sys/neutrino.h>
|
| 12 |
|
| 13 |
using namespace std; |
| 14 |
|
| 15 |
int main(int argc, char *argv[]) |
| 16 |
{
|
| 17 |
struct _clockperiod clkper; |
| 18 |
|
| 19 |
if (argc != 1 && argc != 2) |
| 20 |
{
|
| 21 |
cout << "Usage: clock_period <nsec>" << endl; |
| 22 |
exit (0); |
| 23 |
}
|
| 24 |
|
| 25 |
if (argc == 1) |
| 26 |
{
|
| 27 |
/* display the current clock period */
|
| 28 |
ClockPeriod(CLOCK_REALTIME, NULL, &clkper, 0); |
| 29 |
cout << "ClockPeriod: " << clkper.nsec << " nsecs" << endl; |
| 30 |
}
|
| 31 |
else
|
| 32 |
{
|
| 33 |
/* set new clock period */
|
| 34 |
clkper.nsec = atoi(argv[1]); |
| 35 |
clkper.fract = 0; |
| 36 |
ClockPeriod ( CLOCK_REALTIME, &clkper, NULL, 0 ); |
| 37 |
}
|
| 38 |
|
| 39 |
return 0; |
| 40 |
}
|