how to use lld_evt_time_get function as a RTC

⚠️
Hi there.. thanks for coming to the forums. Exciting news! we’re now in the process of moving to our new forum platform that will offer better functionality and is contained within the main Dialog website. All posts and accounts have been migrated. We’re now accepting traffic on the new forum only - please POST any new threads at//www.xmece.com/support. We’ll be fixing bugs / optimising the searching and tagging over the coming days.
2 posts / 0 new
Last post
ustbzhangm
Offline
Last seen:5 months 2 weeks ago
加入:2015-08-24 07:50
how to use lld_evt_time_get function as a RTC

Hi, I want to calculate a time in my application. I set the iBeacon to connectable at 2:00 ~ 3:00 in every day. So, I will use a timer to count the current time.
I add some code in schedule_while_ble_on which located in arch_main.c
static inline void schedule_while_ble_on(void)
{
// BLE clock is enabled
while (ble_is_powered())
{
// BLE event end is set. conditional RF calibration can run.
uint8_t ble_evt_end_set = ke_event_get(KE_EVENT_BLE_EVT_END);

uint32_t current_time = lld_evt_time_get ();
if ((current_time - last_time) > 1599){
//timer_second++;
last_time = current_time;
if (GPIO_GetPinStatus(GPIO_PORT_2, GPIO_PIN_0))
GPIO_SetInactive(GPIO_PORT_2, GPIO_PIN_0);
else
GPIO_SetActive(GPIO_PORT_2, GPIO_PIN_0);
}
if (current_time < last_time)
last_time = 0;

/ /执行消息和事件
rwip_schedule();
.......
}
1600*0.625ms = 1000ms.
I measure the period use a GPIO. But the result is that, the GPIO`s high level and low level is not equal 1s. Only when startup period, the GPIO output square wave is a exactly 1 second.
I need help, thanks.

Device:
PM_Dialog
Offline
Last seen:11 hours 20 min ago
Staff
加入:2018-02-08 11:03
嗨ustbzhangm,

嗨ustbzhangm,

It is strongly recommended to use the .app_on_ble_powered callback function and not trying to modify the SKD files.The lld_evt_time_get() function will return the value of the BLE timer.If you are asleep for more than 1 second, this code that you have attached, will never run because will never enter the if ((current_time - last_time) > 1599). Then the device will schedule a BLE event and will wake up at that time, so when the device wakes up, it will go through the code that you have attached, and then perform the actions that you have coded like toggling the GPIO's. When the device is in sleep mode the code that you have attached will never run, because the BLE timer will never restored and the timer period that you are counting will be always more than 1 sec. The reason that you get toggles near to 1 sec when starting up is because the device doesn't go sleep for 2 seconds, so the code that you have attached keeps on running and comparing.

Thanks, PM_Dialog