4475
- 收藏
- 点赞
- 分享
- 举报
hi3520d的RTC和系统是时间设置,修改自sdk中的rtc_test.c
加载hi_rtc.ko,然后通过rtc_test.c来修改读取rtc时间,这个很多人都会了。
但是rtc时间怎么同步到系统时间,系统时间怎么同步到rtc上,就不那么方便了。
因此我参考网友的代码,在rtc_test.c上增加了2个参数。
建个启动文件/etc/init.d/S1000rtc,这样开机就能自动把rtc时间同步到系统上了
[code]#!/bin/sh
cd /mpp/ko //根据自己ko文件路径修改
./load3520D -i
rtctool -rtc2sys[/code]
Usage: ./test [options] [parameter1] ...
Options:
-s(set) Set time/alarm, e.g '-s time 2012/7/15/13/37/59'
-g(get) Get time/alarm, e.g '-g alarm'
-w(write) Write RTC register, e.g '-w '
-sys2rtc Read the system time and write it to the RTC
-rtc2sys Read the RTC and write it to the system time
-r(ead) Read RTC register, e.g '-r'
-a(alarm) Alarm ON/OFF', e.g '-a ON'
-reset RTC reset
-c(ompensation) temperature compensation ON/OFF, eg '-c ON'
-f(requency) frequency precise adjustment, eg '-f'
-m(mode) Mode of temperature gather, e.g '-m , mode[
[code]/*
* RTC sample&test code.
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include "hi_rtc.h"
void usage(void)
{
printf(
"\n"
"Usage: ./test [options] [parameter1] ...\n"
"Options: \n"
" -s(set) Set time/alarm, e.g '-s time 2012/7/15/13/37/59'\n"
" -g(get) Get time/alarm, e.g '-g alarm'\n"
" -w(write) Write RTC register, e.g '-w '\n"
" -sys2rtc Read the system time and write it to the RTC\n"
" -rtc2sys Read the RTC and write it to the system time\n"
" -r(ead) Read RTC register, e.g '-r'\n"
" -a(alarm) Alarm ON/OFF', e.g '-a ON'\n"
" -reset RTC reset\n"
" -c(ompensation) temperature compensation ON/OFF, eg '-c ON'\n"
" -f(requency) frequency precise adjustment, eg '-f'\n"
" -m(mode) Mode of temperature gather, e.g '-m , mode[0-2]'\n"
"\n");
exit(1);
}
static int _atoul(const char *str, unsigned char *pvalue)
{
unsigned int result=0;
while (*str)
{
if (isdigit((int)*str))
{
if ((result<429496729) || ((result==429496729) && (*str<'6')))
{
result = result*10 + (*str)-48;
}
else
{
*pvalue = result;
return -1;
}
}
else
{
*pvalue=result;
return -1;
}
str++;
}
*pvalue=result;
return 0;
}
#define ASC2NUM(ch) (ch - '0')
#define HEXASC2NUM(ch) (ch - 'A' + 10)
static int _atoulx(const char *str, unsigned char *pvalue)
{
unsigned int result=0;
unsigned char ch;
while (*str)
{
ch=toupper(*str);
if (isdigit(ch) || ((ch >= 'A') && (ch <= 'F' )))
{
if (result < 0x10000000)
{
result = (result << 4) + ((ch<='9')?(ASC2NUM(ch)):(HEXASC2NUM(ch)));
}
else
{
*pvalue=result;
return -1;
}
}
else
{
*pvalue=result;
return -1;
}
str++;
}
*pvalue=result;
return 0;
}
/*used for convert hex value from string to int*/
static int str_to_num(const char *str, unsigned char *pvalue)
{
if ( *str == '0' && (*(str+1) == 'x' || *(str+1) == 'X') ){
if (*(str+2) == '\0'){
return -1;
}
else{
return _atoulx(str+2, pvalue);
}
}
else {
return _atoul(str,pvalue);
}
}
/*used for convert time frome string to struct rtc_time_t*/
static int parse_string(char *string, rtc_time_t *p_tm)
{
char *comma, *head;
int value[10];
int i;
if (!string || !p_tm)
return -1;
if (!strchr(string, '/'))
return -1;
head = string;
i = 0;
comma = NULL;
for(;;) {
comma = strchr(head, '/');
if (!comma){
value[i++] = atoi(head);
break;
}
*comma = '\0';
value[i++] = atoi(head);
head = comma+1;
}
if (i < 5)
return -1;
p_tm->year = value[0];
p_tm->month = value[1];
p_tm->date = value[2];
p_tm->hour = value[3];
p_tm->minute = value[4];
p_tm->second = value[5];
p_tm->weekday = 0;
return 0;
}
int main(int argc, const char *argv[])
{
rtc_time_t tm;
reg_data_t regv;
reg_temp_mode_t mode;
int ret = -1;
int fd = -1;
const char *dev_name = "/dev/hi_rtc";
char string[50];
if (argc < 2){
usage();
return 0;
}
fd = open(dev_name, O_RDWR);
if (!fd) {
printf("open %s failed\n", dev_name);
return -1;
}
if (!strcmp(argv[1],"-s")) {
if (argc < 3) {
usage();
goto err1;
}
if (!strcmp(argv[2], "time")) {
strcpy(string, argv[3]);
ret = parse_string(string, &tm);
if (ret < 0)
{
printf("parse time param failed\n");
goto err1;
}
printf("set time\n");
#if 1
/* code */
printf("year:%d\n", tm.year);
printf("month:%d\n",tm.month);
printf("date:%d\n", tm.date);
printf("hour:%d\n", tm.hour);
printf("minute:%d\n", tm.minute);
printf("second:%d\n", tm.second);
#endif
ret = ioctl(fd, HI_RTC_SET_TIME, &tm);
if (ret < 0) {
printf("ioctl: HI_RTC_SET_TIME failed\n");
goto err1;
}
} else if (!strcmp(argv[2], "alarm")) {
strcpy(string, argv[3]);
ret = parse_string(string, &tm);
if (ret < 0) {
printf("parse alarm param failed\n");
goto err1;
}
printf("set alarm\n");
#if 1
printf("year:%d\n", tm.year);
printf("month:%d\n",tm.month);
printf("date:%d\n", tm.date);
printf("hour:%d\n", tm.hour);
printf("minute:%d\n", tm.minute);
printf("second:%d\n", tm.second);
#endif
ret = ioctl(fd, HI_RTC_ALM_SET, &tm);
if (ret < 0) {
printf("ioctl: HI_RTC_ALM_SET failed\n");
goto err1;
}
} else {
printf("unknown options %s\n", argv[2]);
goto err1;
}
} else if (!strcmp(argv[1],"-g")) {
if (argc < 3) {
usage();
goto err1;
}
if (!strcmp(argv[2], "time")) {
printf("[RTC_RD_TIME]\n");
ret = ioctl(fd, HI_RTC_RD_TIME, &tm);
if (ret < 0) {
printf("ioctl: HI_RTC_RD_TIME failed\n");
goto err1;
}
printf("Current time value: \n");
} else if (!strcmp(argv[2], "alarm")) {
printf("[RTC_RD_ALM]\n");
ret = ioctl(fd, HI_RTC_ALM_READ, &tm);
if (ret < 0) {
printf("ioctl: HI_RTC_ALM_READ failed\n");
goto err1;
}
printf("Current alarm value: \n");
} else {
printf("unknow options %s\n", argv[2]);
goto err1;
}
printf("year %d\n", tm.year);
printf("month %d\n", tm.month);
printf("date %d\n", tm.date);
printf("hour %d\n", tm.hour);
printf("minute %d\n", tm.minute);
printf("second %d\n", tm.second);
printf("weekday %d\n", tm.weekday);
} else if (!strcmp(argv[1],"-w")) {
if (argc < 4) {
usage();
goto err1;
}
ret = str_to_num(argv[2], &(regv.reg));
if (ret != 0) {
printf("reg 0x%08x invalid\n", regv.reg);
goto err1;
}
ret = str_to_num(argv[3], &(regv.val));
if (ret != 0) {
printf("val 0x%08x invalid\n", regv.val);
goto err1;
}
printf("\n");
printf("[RTC_REG_SET] reg:%02x, val:%02x\n", regv.reg, regv.val);
printf("\n");
ret = ioctl(fd, HI_RTC_REG_SET, ®v);
if (ret < 0) {
printf("ioctl: HI_RTC_REG_SET failed\n");
goto err1;
}
} else if (!strcmp(argv[1],"-r")) {
if (argc < 3) {
usage();
goto err1;
}
ret = str_to_num(argv[2], &(regv.reg));
if (ret != 0) {
printf("reg 0x%08x invalid\n", regv.reg);
goto err1;
}
regv.val = 0;
ret = ioctl(fd, HI_RTC_REG_READ, ®v);
if (ret < 0) {
printf("ioctl: HI_RTC_REG_READ failed\n");
goto err1;
}
printf("\n");
printf("[RTC_REG_GET] reg:0x%02x, val:0x%02x\n", regv.reg, regv.val);
printf("\n");
} else if (!strcmp(argv[1],"-a")) {
if (argc < 3) {
usage();
goto err1;
}
if (!strcmp(argv[2], "ON")) {
ret = ioctl(fd, HI_RTC_AIE_ON);
} else if (!strcmp(argv[2], "OFF")) {
ret = ioctl(fd, HI_RTC_AIE_OFF);
}
if (ret < 0) {
printf("ioctl: HI_RTC_AIE_ON/OFF failed\n");
goto err1;
}
} else if (!strcmp(argv[1],"-reset")) {
printf("[RTC_RESET]\n");
ret = ioctl(fd, HI_RTC_RESET);
if(ret){
printf("reset err\n");
goto err1;
}
} else if (!strcmp(argv[1],"-sys2rtc")) {// add by xiaojianbin @2016/8/12
printf("[Read the system time and write it to the RTC]\n");
time_t sys_time;
struct tm *p_time;
rtc_time_t rtc_time;
time(&sys_time);
p_time = gmtime(&sys_time);
printf("time year:%d\n"
"month :%d\n"
"day : %d\n"
"h :%d\n"
"min :%d\n"
"second %d\n",
p_time->tm_year+1900,
p_time->tm_mon+1,
p_time->tm_mday,
p_time->tm_hour + 8,
p_time->tm_min,
p_time->tm_sec);
printf("system date :\r\n");
system("date");
rtc_time.year = p_time->tm_year + 1900;
rtc_time.month = p_time->tm_mon + 1;
rtc_time.date = p_time->tm_mday;
rtc_time.hour = p_time->tm_hour;
rtc_time.minute = p_time->tm_min;
rtc_time.second = p_time->tm_sec;
ret = ioctl(fd, HI_RTC_SET_TIME, &rtc_time);
if(ret < 0){
printf("set rtc of localtime error!\r\n");
goto err1;
}
} else if (!strcmp(argv[1],"-rtc2sys")) {// add by xiaojianbin @2016/8/12
printf("[Read the RTC and write it to the system time]\n");
rtc_time_t rtc_time;
struct timeval val_time;
struct tm tm_time;
// 1 get the time from rtc
// ioctl HI_RTC_RD_TIME
ret = ioctl(fd, HI_RTC_RD_TIME, &rtc_time);
if (ret < 0) {
printf("ioctl: HI_RTC_RD_TIME failed\n");
goto err1;
}
tm_time.tm_year = rtc_time.year - 1900;
tm_time.tm_mon = rtc_time.month -1;
tm_time.tm_mday = rtc_time.date;
tm_time.tm_hour = rtc_time.hour;
tm_time.tm_min = rtc_time.minute;
tm_time.tm_sec = rtc_time.second;
tm_time.tm_wday = rtc_time.weekday;
val_time.tv_sec = mktime(&tm_time);
val_time.tv_usec = 0;
settimeofday(&val_time,NULL);
printf("the value will write to the system time is:"
"year:%d\n"
"month%d\n"
"day:%d\n"
"hour:%d\n"
"min:%d\n"
"sec:%d\n",
tm_time.tm_yday,
tm_time.tm_mon,
tm_time.tm_mday,
tm_time.tm_hour,
tm_time.tm_min,
tm_time.tm_sec);
} else if (!strcmp(argv[1], "-c")) {
if (argc < 3) {
usage();
goto err1;
}
if (!strcmp(argv[2], "ON")) {
//printf("RTC temperature compensation on!\n");
ret = ioctl(fd, HI_RTC_COMP_ON);
} else if (!strcmp(argv[2], "OFF")) {
//printf("RTC temperature compensation off!\n");
ret = ioctl(fd, HI_RTC_COMP_OFF);
}
if (ret < 0) {
printf("ioctl: HI_RTC_COMP_ON/OFF failed\n");
goto err1;
}
} else if (!strcmp(argv[1], "-f")) {
unsigned int freq;
rtc_freq_t value;
// print current frequency value
if (argc < 3)
{
ret = ioctl(fd, HI_RTC_GET_FREQ, &value);
if (ret < 0)
{
printf("get current frequency failed\n");
goto err1;
}
freq = value.freq_l;
#if 0
if (freq > 3277000 || freq < 3276000)
{
printf("get invalid freq %d\n", freq);
goto err1;
}
#endif
printf("current frequency : %d\n", freq);
}
// set frequency
else if (argc == 3)
{
freq = atoi(argv[2]);
if (freq > 3277000 || freq < 3276000)
{
printf("invalid freq %d\n", freq);
goto err1;
}
value.freq_l = freq;
ret = ioctl(fd, HI_RTC_SET_FREQ, &value);
if (ret < 0)
{
printf("get current frequency failed\n");
goto err1;
}
}
} else if (!strcmp(argv[1], "-m")) {
int mod, value;
if (argc < 3) {
usage();
goto err1;
}
mod = atoi(argv[2]);
if (mod > 2 || mod < 0) {
printf("invalid mode %d\n", mod);
goto err1;
}
if (mod == 0) {
if (argc < 4) {
usage();
goto err1;
}
value = atoi(argv[3]);
}
else {
value = 0;
}
printf("[RTC_SET_TEMP_MODE] %d\n", mod);
mode.mode = (enum temp_sel_mode)mod;
mode.value = value;
ret = ioctl(fd, HI_RTC_SET_TEMP_MODE, &mode);
if(ret) {
printf("ioctl: HI_RTC_SET_TEMP_MODE failed\n");
goto err1;
}
} else {
printf("unknown download mode.\n");
goto err1;
}
err1:
close(fd);
return 0;
}
[/code]
但是rtc时间怎么同步到系统时间,系统时间怎么同步到rtc上,就不那么方便了。
因此我参考网友的代码,在rtc_test.c上增加了2个参数。
建个启动文件/etc/init.d/S1000rtc,这样开机就能自动把rtc时间同步到系统上了
[code]#!/bin/sh
cd /mpp/ko //根据自己ko文件路径修改
./load3520D -i
rtctool -rtc2sys[/code]
Usage: ./test [options] [parameter1] ...
Options:
-s(set) Set time/alarm, e.g '-s time 2012/7/15/13/37/59'
-g(get) Get time/alarm, e.g '-g alarm'
-w(write) Write RTC register, e.g '-w
-sys2rtc Read the system time and write it to the RTC
-rtc2sys Read the RTC and write it to the system time
-r(ead) Read RTC register, e.g '-r
-a(alarm) Alarm ON/OFF', e.g '-a ON'
-reset RTC reset
-c(ompensation) temperature compensation ON/OFF, eg '-c ON'
-f(requency) frequency precise adjustment, eg '-f
-m(mode) Mode of temperature gather, e.g '-m
[code]/*
* RTC sample&test code.
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include "hi_rtc.h"
void usage(void)
{
printf(
"\n"
"Usage: ./test [options] [parameter1] ...\n"
"Options: \n"
" -s(set) Set time/alarm, e.g '-s time 2012/7/15/13/37/59'\n"
" -g(get) Get time/alarm, e.g '-g alarm'\n"
" -w(write) Write RTC register, e.g '-w
" -sys2rtc Read the system time and write it to the RTC\n"
" -rtc2sys Read the RTC and write it to the system time\n"
" -r(ead) Read RTC register, e.g '-r
" -a(alarm) Alarm ON/OFF', e.g '-a ON'\n"
" -reset RTC reset\n"
" -c(ompensation) temperature compensation ON/OFF, eg '-c ON'\n"
" -f(requency) frequency precise adjustment, eg '-f
" -m(mode) Mode of temperature gather, e.g '-m
"\n");
exit(1);
}
static int _atoul(const char *str, unsigned char *pvalue)
{
unsigned int result=0;
while (*str)
{
if (isdigit((int)*str))
{
if ((result<429496729) || ((result==429496729) && (*str<'6')))
{
result = result*10 + (*str)-48;
}
else
{
*pvalue = result;
return -1;
}
}
else
{
*pvalue=result;
return -1;
}
str++;
}
*pvalue=result;
return 0;
}
#define ASC2NUM(ch) (ch - '0')
#define HEXASC2NUM(ch) (ch - 'A' + 10)
static int _atoulx(const char *str, unsigned char *pvalue)
{
unsigned int result=0;
unsigned char ch;
while (*str)
{
ch=toupper(*str);
if (isdigit(ch) || ((ch >= 'A') && (ch <= 'F' )))
{
if (result < 0x10000000)
{
result = (result << 4) + ((ch<='9')?(ASC2NUM(ch)):(HEXASC2NUM(ch)));
}
else
{
*pvalue=result;
return -1;
}
}
else
{
*pvalue=result;
return -1;
}
str++;
}
*pvalue=result;
return 0;
}
/*used for convert hex value from string to int*/
static int str_to_num(const char *str, unsigned char *pvalue)
{
if ( *str == '0' && (*(str+1) == 'x' || *(str+1) == 'X') ){
if (*(str+2) == '\0'){
return -1;
}
else{
return _atoulx(str+2, pvalue);
}
}
else {
return _atoul(str,pvalue);
}
}
/*used for convert time frome string to struct rtc_time_t*/
static int parse_string(char *string, rtc_time_t *p_tm)
{
char *comma, *head;
int value[10];
int i;
if (!string || !p_tm)
return -1;
if (!strchr(string, '/'))
return -1;
head = string;
i = 0;
comma = NULL;
for(;;) {
comma = strchr(head, '/');
if (!comma){
value[i++] = atoi(head);
break;
}
*comma = '\0';
value[i++] = atoi(head);
head = comma+1;
}
if (i < 5)
return -1;
p_tm->year = value[0];
p_tm->month = value[1];
p_tm->date = value[2];
p_tm->hour = value[3];
p_tm->minute = value[4];
p_tm->second = value[5];
p_tm->weekday = 0;
return 0;
}
int main(int argc, const char *argv[])
{
rtc_time_t tm;
reg_data_t regv;
reg_temp_mode_t mode;
int ret = -1;
int fd = -1;
const char *dev_name = "/dev/hi_rtc";
char string[50];
if (argc < 2){
usage();
return 0;
}
fd = open(dev_name, O_RDWR);
if (!fd) {
printf("open %s failed\n", dev_name);
return -1;
}
if (!strcmp(argv[1],"-s")) {
if (argc < 3) {
usage();
goto err1;
}
if (!strcmp(argv[2], "time")) {
strcpy(string, argv[3]);
ret = parse_string(string, &tm);
if (ret < 0)
{
printf("parse time param failed\n");
goto err1;
}
printf("set time\n");
#if 1
/* code */
printf("year:%d\n", tm.year);
printf("month:%d\n",tm.month);
printf("date:%d\n", tm.date);
printf("hour:%d\n", tm.hour);
printf("minute:%d\n", tm.minute);
printf("second:%d\n", tm.second);
#endif
ret = ioctl(fd, HI_RTC_SET_TIME, &tm);
if (ret < 0) {
printf("ioctl: HI_RTC_SET_TIME failed\n");
goto err1;
}
} else if (!strcmp(argv[2], "alarm")) {
strcpy(string, argv[3]);
ret = parse_string(string, &tm);
if (ret < 0) {
printf("parse alarm param failed\n");
goto err1;
}
printf("set alarm\n");
#if 1
printf("year:%d\n", tm.year);
printf("month:%d\n",tm.month);
printf("date:%d\n", tm.date);
printf("hour:%d\n", tm.hour);
printf("minute:%d\n", tm.minute);
printf("second:%d\n", tm.second);
#endif
ret = ioctl(fd, HI_RTC_ALM_SET, &tm);
if (ret < 0) {
printf("ioctl: HI_RTC_ALM_SET failed\n");
goto err1;
}
} else {
printf("unknown options %s\n", argv[2]);
goto err1;
}
} else if (!strcmp(argv[1],"-g")) {
if (argc < 3) {
usage();
goto err1;
}
if (!strcmp(argv[2], "time")) {
printf("[RTC_RD_TIME]\n");
ret = ioctl(fd, HI_RTC_RD_TIME, &tm);
if (ret < 0) {
printf("ioctl: HI_RTC_RD_TIME failed\n");
goto err1;
}
printf("Current time value: \n");
} else if (!strcmp(argv[2], "alarm")) {
printf("[RTC_RD_ALM]\n");
ret = ioctl(fd, HI_RTC_ALM_READ, &tm);
if (ret < 0) {
printf("ioctl: HI_RTC_ALM_READ failed\n");
goto err1;
}
printf("Current alarm value: \n");
} else {
printf("unknow options %s\n", argv[2]);
goto err1;
}
printf("year %d\n", tm.year);
printf("month %d\n", tm.month);
printf("date %d\n", tm.date);
printf("hour %d\n", tm.hour);
printf("minute %d\n", tm.minute);
printf("second %d\n", tm.second);
printf("weekday %d\n", tm.weekday);
} else if (!strcmp(argv[1],"-w")) {
if (argc < 4) {
usage();
goto err1;
}
ret = str_to_num(argv[2], &(regv.reg));
if (ret != 0) {
printf("reg 0x%08x invalid\n", regv.reg);
goto err1;
}
ret = str_to_num(argv[3], &(regv.val));
if (ret != 0) {
printf("val 0x%08x invalid\n", regv.val);
goto err1;
}
printf("\n");
printf("[RTC_REG_SET] reg:%02x, val:%02x\n", regv.reg, regv.val);
printf("\n");
ret = ioctl(fd, HI_RTC_REG_SET, ®v);
if (ret < 0) {
printf("ioctl: HI_RTC_REG_SET failed\n");
goto err1;
}
} else if (!strcmp(argv[1],"-r")) {
if (argc < 3) {
usage();
goto err1;
}
ret = str_to_num(argv[2], &(regv.reg));
if (ret != 0) {
printf("reg 0x%08x invalid\n", regv.reg);
goto err1;
}
regv.val = 0;
ret = ioctl(fd, HI_RTC_REG_READ, ®v);
if (ret < 0) {
printf("ioctl: HI_RTC_REG_READ failed\n");
goto err1;
}
printf("\n");
printf("[RTC_REG_GET] reg:0x%02x, val:0x%02x\n", regv.reg, regv.val);
printf("\n");
} else if (!strcmp(argv[1],"-a")) {
if (argc < 3) {
usage();
goto err1;
}
if (!strcmp(argv[2], "ON")) {
ret = ioctl(fd, HI_RTC_AIE_ON);
} else if (!strcmp(argv[2], "OFF")) {
ret = ioctl(fd, HI_RTC_AIE_OFF);
}
if (ret < 0) {
printf("ioctl: HI_RTC_AIE_ON/OFF failed\n");
goto err1;
}
} else if (!strcmp(argv[1],"-reset")) {
printf("[RTC_RESET]\n");
ret = ioctl(fd, HI_RTC_RESET);
if(ret){
printf("reset err\n");
goto err1;
}
} else if (!strcmp(argv[1],"-sys2rtc")) {// add by xiaojianbin @2016/8/12
printf("[Read the system time and write it to the RTC]\n");
time_t sys_time;
struct tm *p_time;
rtc_time_t rtc_time;
time(&sys_time);
p_time = gmtime(&sys_time);
printf("time year:%d\n"
"month :%d\n"
"day : %d\n"
"h :%d\n"
"min :%d\n"
"second %d\n",
p_time->tm_year+1900,
p_time->tm_mon+1,
p_time->tm_mday,
p_time->tm_hour + 8,
p_time->tm_min,
p_time->tm_sec);
printf("system date :\r\n");
system("date");
rtc_time.year = p_time->tm_year + 1900;
rtc_time.month = p_time->tm_mon + 1;
rtc_time.date = p_time->tm_mday;
rtc_time.hour = p_time->tm_hour;
rtc_time.minute = p_time->tm_min;
rtc_time.second = p_time->tm_sec;
ret = ioctl(fd, HI_RTC_SET_TIME, &rtc_time);
if(ret < 0){
printf("set rtc of localtime error!\r\n");
goto err1;
}
} else if (!strcmp(argv[1],"-rtc2sys")) {// add by xiaojianbin @2016/8/12
printf("[Read the RTC and write it to the system time]\n");
rtc_time_t rtc_time;
struct timeval val_time;
struct tm tm_time;
// 1 get the time from rtc
// ioctl HI_RTC_RD_TIME
ret = ioctl(fd, HI_RTC_RD_TIME, &rtc_time);
if (ret < 0) {
printf("ioctl: HI_RTC_RD_TIME failed\n");
goto err1;
}
tm_time.tm_year = rtc_time.year - 1900;
tm_time.tm_mon = rtc_time.month -1;
tm_time.tm_mday = rtc_time.date;
tm_time.tm_hour = rtc_time.hour;
tm_time.tm_min = rtc_time.minute;
tm_time.tm_sec = rtc_time.second;
tm_time.tm_wday = rtc_time.weekday;
val_time.tv_sec = mktime(&tm_time);
val_time.tv_usec = 0;
settimeofday(&val_time,NULL);
printf("the value will write to the system time is:"
"year:%d\n"
"month%d\n"
"day:%d\n"
"hour:%d\n"
"min:%d\n"
"sec:%d\n",
tm_time.tm_yday,
tm_time.tm_mon,
tm_time.tm_mday,
tm_time.tm_hour,
tm_time.tm_min,
tm_time.tm_sec);
} else if (!strcmp(argv[1], "-c")) {
if (argc < 3) {
usage();
goto err1;
}
if (!strcmp(argv[2], "ON")) {
//printf("RTC temperature compensation on!\n");
ret = ioctl(fd, HI_RTC_COMP_ON);
} else if (!strcmp(argv[2], "OFF")) {
//printf("RTC temperature compensation off!\n");
ret = ioctl(fd, HI_RTC_COMP_OFF);
}
if (ret < 0) {
printf("ioctl: HI_RTC_COMP_ON/OFF failed\n");
goto err1;
}
} else if (!strcmp(argv[1], "-f")) {
unsigned int freq;
rtc_freq_t value;
// print current frequency value
if (argc < 3)
{
ret = ioctl(fd, HI_RTC_GET_FREQ, &value);
if (ret < 0)
{
printf("get current frequency failed\n");
goto err1;
}
freq = value.freq_l;
#if 0
if (freq > 3277000 || freq < 3276000)
{
printf("get invalid freq %d\n", freq);
goto err1;
}
#endif
printf("current frequency : %d\n", freq);
}
// set frequency
else if (argc == 3)
{
freq = atoi(argv[2]);
if (freq > 3277000 || freq < 3276000)
{
printf("invalid freq %d\n", freq);
goto err1;
}
value.freq_l = freq;
ret = ioctl(fd, HI_RTC_SET_FREQ, &value);
if (ret < 0)
{
printf("get current frequency failed\n");
goto err1;
}
}
} else if (!strcmp(argv[1], "-m")) {
int mod, value;
if (argc < 3) {
usage();
goto err1;
}
mod = atoi(argv[2]);
if (mod > 2 || mod < 0) {
printf("invalid mode %d\n", mod);
goto err1;
}
if (mod == 0) {
if (argc < 4) {
usage();
goto err1;
}
value = atoi(argv[3]);
}
else {
value = 0;
}
printf("[RTC_SET_TEMP_MODE] %d\n", mod);
mode.mode = (enum temp_sel_mode)mod;
mode.value = value;
ret = ioctl(fd, HI_RTC_SET_TEMP_MODE, &mode);
if(ret) {
printf("ioctl: HI_RTC_SET_TEMP_MODE failed\n");
goto err1;
}
} else {
printf("unknown download mode.\n");
goto err1;
}
err1:
close(fd);
return 0;
}
[/code]
我来回答
回答3个
时间排序
认可量排序
认可0
认可0
认可0
或将文件直接拖到这里
悬赏:
E币
网盘
* 网盘链接:
* 提取码:
悬赏:
E币
Markdown 语法
- 加粗**内容**
- 斜体*内容*
- 删除线~~内容~~
- 引用> 引用内容
- 代码`代码`
- 代码块```编程语言↵代码```
- 链接[链接标题](url)
- 无序列表- 内容
- 有序列表1. 内容
- 缩进内容
- 图片![alt](url)
相关问答
-
1302015-08-20 20:38:18
-
2018-02-06 17:07:15
-
2019-07-09 11:12:50
-
2020-04-07 14:09:13
-
12016-09-14 15:46:07
-
2017-10-17 12:14:19
-
2016-11-08 18:00:35
-
2020-10-23 18:22:26
-
2016-01-16 14:23:17
-
2019-12-18 10:16:51
-
2018-12-11 10:10:32
-
2020-04-23 18:27:38
-
2019-12-18 10:37:52
-
2019-01-09 11:10:38
-
2015-03-25 13:45:37
-
32017-10-12 17:09:51
-
22017-10-14 16:45:38
-
2015-11-23 14:22:42
-
2017-06-23 15:06:42
无更多相似问答 去提问
点击登录
-- 积分
-- E币
提问
—
收益
—
被采纳
—
我要提问
切换马甲
上一页
下一页
悬赏问答
-
5Hi3516CV610 如何使用SD卡升级固件
-
5cat /dev/logmpp 报错 <3>[ vi] [func]:vi_send_frame_node [line]:99 [info]:vi pic queue is full!
-
50如何获取vpss chn的图像修改后发送至vo
-
5FPGA通过Bt1120传YUV422数据过来,vi接收不到数据——3516dv500
-
50SS928 运行PQtools 拼接 推到设备里有一半画面会异常
-
53536AV100的sample_vdec输出到CVBS显示
-
10海思板子mpp怎么在vi阶段改变视频数据尺寸
-
10HI3559AV100 多摄像头同步模式
-
9海思ss928单路摄像头vio中加入opencv处理并显示
-
10EB-RV1126-BC-191板子运行自己编码的程序
举报反馈
举报类型
- 内容涉黄/赌/毒
- 内容侵权/抄袭
- 政治相关
- 涉嫌广告
- 侮辱谩骂
- 其他
详细说明
提醒
你的问题还没有最佳答案,是否结题,结题后将扣除20%的悬赏金
取消
确认
提醒
你的问题还没有最佳答案,是否结题,结题后将根据回答情况扣除相应悬赏金(1回答=1E币)
取消
确认