Hi, I wanted to make the function that get timestamp like mills(). I made this code bellow. It does'nt move well. Main loop is unintentionally end, nrf52 is reset. What brought this on?
Thanks,
//Code for getting timestamp
#include "y_timer.h"
#include "app_timer.h"
#include "stdint.h"
#define APP_TIMER_PRESCALER 0 /**< Value of the RTC1 PRESCALER register. */
#define APP_TIMER_OP_QUEUE_SIZE 4 /**< Size of timer operation queues. */
#define SENSOR_CONTACT_DETECTED_INTERVAL APP_TIMER_TICKS(1000, APP_TIMER_PRESCALER) /**< Sensor Contact Detected toggle interval (ticks). */
APP_TIMER_DEF(m_sensor_contact_timer_id);
static unsigned long ul_pasttime;
static void timer_timeout_handler(void * p_context)
{
UNUSED_PARAMETER(p_context);
ul_pasttime++;
}
void timers_init(void) //設定
{
uint32_t err_code;
ul_pasttime = 0;
APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, false);
err_code = app_timer_create(&m_sensor_contact_timer_id,
APP_TIMER_MODE_REPEATED,
timer_timeout_handler);
APP_ERROR_CHECK(err_code);
}
void application_timers_start(void)
{
uint32_t err_code;
err_code = app_timer_start(m_sensor_contact_timer_id, SENSOR_CONTACT_DETECTED_INTERVAL, NULL);
APP_ERROR_CHECK(err_code);
}
unsigned long millis(void){
return ul_pasttime;
}
//Main.c
void Sub(){
int i_data = Data_Load();
unsigned long * ul_time = 0;
get_ms(ul_time);
printf("timestamp:%lu",*ul_time);
printf("i_data = %d\r\n",i_data);
}
int main(void) {
device_init(); //Abridgement
timers_init();
application_timers_start();
while(1){
Sub();
delay_ms(100);
}
}