90 lines
2.4 KiB
C
Raw Normal View History

2025-05-14 11:26:23 +08:00
#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;
}