|
|
|
@ -141,6 +141,9 @@ static void ds1307_read_time(void) |
|
|
|
} |
|
|
|
|
|
|
|
/* Software thread to maintain local time estimation */ |
|
|
|
time_t now; |
|
|
|
struct tm *p_tm; |
|
|
|
extern unsigned char sys_time[6]; |
|
|
|
static void auto_update_current_datatime(void *parameter) |
|
|
|
{ |
|
|
|
uint32_t count = 0; |
|
|
|
@ -154,6 +157,14 @@ static void auto_update_current_datatime(void *parameter) |
|
|
|
ds1307_read_time(); |
|
|
|
count = 0; |
|
|
|
} |
|
|
|
time(&now); // 获取当前日历时间(秒,自 1970-01-01 00:00:00 UTC)
|
|
|
|
p_tm = localtime(&now); // 转换为本地时间结构
|
|
|
|
sys_time[5]= p_tm->tm_year - 100; |
|
|
|
sys_time[4]= p_tm->tm_mon + 1; |
|
|
|
sys_time[3]= p_tm->tm_mday; |
|
|
|
sys_time[2]= p_tm->tm_hour; |
|
|
|
sys_time[1]= p_tm->tm_min; |
|
|
|
sys_time[0]= p_tm->tm_sec;; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -210,7 +221,7 @@ static int rt_hw_ds1307_rtc_init(void) |
|
|
|
|
|
|
|
ds1307_read_time(); |
|
|
|
|
|
|
|
ds1307.thd_soft_update_sec = rt_thread_create("ds1307",auto_update_current_datatime,RT_NULL,256, 20, 5); |
|
|
|
ds1307.thd_soft_update_sec = rt_thread_create("ds1307",auto_update_current_datatime,RT_NULL,512, 20, 5); |
|
|
|
if (ds1307.thd_soft_update_sec) |
|
|
|
{ |
|
|
|
rt_thread_startup(ds1307.thd_soft_update_sec); |
|
|
|
|