struct timespec ts;
ts = current_kernel_time();
printk(KERN_ALERT "i=%d, channel=%d, %ld %ld\n", i, channel, ts.tv_sec, ts.tv_nsec);
struct timeval tv;
/*获取时间*/
do_gettimeofday(&tv);
printk(KERN_ALERT "now: %ld %ld\n", tv.tv_sec, tv.tv_usec);
/*设置时间, 时钟调后5小时*/
ts.tv_sec = tv.tv_sec + 3600*5;
do_settimeofday(&ts);
报文调试:
i=0, channel=0, 1523614738 199999523
now: 1523614738 207424
i=0, channel=1, 1523614738 199999523
now: 1523614738 223716
i=0, channel=2, 1523614738 219999522
now: 1523614738 273299
i=0, channel=3, 1523614738 269999520
now: 1523614738 280457
i=0, channel=4, 1523614738 289999519
now: 1523614738 299316
i=0, channel=5, 1523614738 289999519
now: 1523614738 313382
i=0, channel=6, 1523614738 309999519
now: 1523614738 319441
i=0, channel=7, 1523614738 309999519
now: 1523614738 343332
i=1, channel=0, 1523614738 359999517
now: 1523614738 366732
i=1, channel=1, 1523614738 359999517
now: 1523614738 374799
i=1, channel=2, 1523614738 369999516
now: 1523614738 380832
i=1, channel=3, 1523614738 379999516
now: 1523614738 387841
i=1, channel=4, 1523614738 379999516
now: 1523614738 423382
i=1, channel=5, 1523614738 419999514
now: 1523614738 429524
i=1, channel=6, 1523614738 419999514
now: 1523614738 473382
i=1, channel=7, 1523614738 469999512
now: 1523614738 479674
i=2, channel=0, 1523614738 469999512
now: 1523614738 503307
i=2, channel=1, 1523614738 499999511
now: 1523614738 509524
i=2, channel=2, 1523614738 499999511
now: 1523614738 533374
i=2, channel=3, 1523614738 529999510
now: 1523614738 539407
i=2, channel=4, 1523614738 539999510
now: 1523614738 548157
i=2, channel=5, 1523614738 539999510
now: 1523614738 555924
i=2, channel=6, 1523614738 549999509
now: 1523614738 562524
i=2, channel=7, 1523614738 589999508
now: 1523614738 597291
i=3, channel=0, 1523614738 589999508
now: 1523614738 605132
ADC5通道每次会采样10次,耗时800ms,平均一次是80ms,由于电源监控芯片CAT809TBL在检测到低电平时会存在最小140ms的延时,所以ADC采样10次,去掉最大、最小值,然后取平均值,可以规避这个问题。