90 lines
2.4 KiB
C
90 lines
2.4 KiB
C
![]() |
|
|||
|
#include <common/bk_include.h>
|
|||
|
#include "bk_arm_arch.h"
|
|||
|
#include <stdio.h>
|
|||
|
#include <stdlib.h>
|
|||
|
#include <string.h>
|
|||
|
//#include <netdb.h>
|
|||
|
#include "net_client.h"
|
|||
|
#include "time.h"
|
|||
|
#include "app_time.h"
|
|||
|
//#include "sys_time.h"
|
|||
|
#include <driver/timer.h>
|
|||
|
|
|||
|
#include <components/app_time_intf.h>
|
|||
|
#include "time/time.h"
|
|||
|
#include <time/ntp.h>
|
|||
|
|
|||
|
#define TAG "APP_TIME"
|
|||
|
|
|||
|
#define LOGI(...) BK_LOGI(TAG, ##__VA_ARGS__)
|
|||
|
#define LOGW(...) BK_LOGW(TAG, ##__VA_ARGS__)
|
|||
|
#define LOGE(...) BK_LOGE(TAG, ##__VA_ARGS__)
|
|||
|
#define LOGD(...) BK_LOGD(TAG, ##__VA_ARGS__)
|
|||
|
|
|||
|
|
|||
|
static beken_timer_t timer_handle;
|
|||
|
static long long timestamp_s = 0;
|
|||
|
/*
|
|||
|
static int channel1 = 0;
|
|||
|
|
|||
|
static void callback_timer_isr(timer_id_t chan)
|
|||
|
{
|
|||
|
//软件定时器 时间戳每秒加1 作为时钟
|
|||
|
timestamp_s++;
|
|||
|
BK_LOGE(TAG,"[TIMER][ISR] chan:%d %lld\r\n", chan,(long long)timestamp_s);
|
|||
|
}
|
|||
|
*/
|
|||
|
void timer_handle_alarm( void *arg )
|
|||
|
{
|
|||
|
//bk_err_t err = kNoErr;
|
|||
|
//rtos_stop_timer(&station_ps_timer_handle);
|
|||
|
|
|||
|
//rtos_start_timer(&station_ps_stop_timer_handle);
|
|||
|
//软件定时器 时间戳每秒加1 作为时钟
|
|||
|
timestamp_s++;
|
|||
|
//BK_LOGE(TAG,"timer_handle_alarm\r\n");
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
void app_time_init(void){
|
|||
|
//timer
|
|||
|
//bk_timer_driver_init();
|
|||
|
//bk_timer_start(channel1, 1000, callback_timer_isr);
|
|||
|
|
|||
|
rtos_init_timer(&timer_handle, 1000, timer_handle_alarm, 0);
|
|||
|
|
|||
|
rtos_start_timer(&timer_handle);
|
|||
|
|
|||
|
time_t time = 0;
|
|||
|
while (time==0)
|
|||
|
{
|
|||
|
|
|||
|
uint32_t frac_val = 0;
|
|||
|
time = ntp_get_local_time(&frac_val);
|
|||
|
//time = ntp_get_local_time();
|
|||
|
BK_LOGE(TAG,"\r\nGet local time from NTP server: %s", ctime(&time));
|
|||
|
}
|
|||
|
timestamp_s = time;
|
|||
|
//timestamp_s =1723771660;
|
|||
|
BK_LOGE(TAG,"timestamp :%ld\n",timestamp_s);
|
|||
|
//return timestamp_s;
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
long app_time_timestamp_s(void){
|
|||
|
return timestamp_s;
|
|||
|
}
|
|||
|
|
|||
|
long long app_time_timestamp_ms(void){
|
|||
|
long long ltimestamp = (long long)timestamp_s*1000L;//s-->ms
|
|||
|
/*
|
|||
|
因为溢出了 111111*111111=12345654321 超出了int能表示的范围
|
|||
|
可能你要问 不是已经%lld了吗 没错 %lld是用于long long类型的,但只代表输出的时候按照long long的类型输出,并不能影响后面参数的实际类型
|
|||
|
对于整型常数,C语言默认都是int型 除非有特殊标明
|
|||
|
*/
|
|||
|
//BK_LOGE(TAG,"timestamp l:%lld\n",(long long )ltimestamp);
|
|||
|
return ltimestamp;
|
|||
|
}
|