char accelerometer_init(void) { char read_data = 0; char init_sucess_F = 0; f.g_motion_sensed_F = 0; // Set up interrupt eat_debug("Init accelerometer\n"); eat_sleep(10); eat_int_setup(ACC_INT, EAT_INT_TRIGGER_RISING_EDGE, 0, (eat_gpio_int_callback_func)acc_isp); eat_int_set_trigger(ACC_INT, EAT_INT_TRIGGER_RISING_EDGE); eat_sleep(10); write(0,ADDRESS,0x20,0x77); //400 int per sec and axis x,y,z enable write(0,ADDRESS,0x21,0x09); //09 for motion only,0d write(0,ADDRESS,0x22,0x40); //40 for only motion write(0,ADDRESS,0x23,0x00); write(0,ADDRESS,0x24,0x00); // 08 for latching write(0,ADDRESS,0x32,0x10); write(0,ADDRESS,0x33,0x00); read(0,ADDRESS,0x26); write(0,ADDRESS,0x30,0x2a);//2a for only motion ,aa read(0,ADDRESS,0x31); if(read(0,ADDRESS,0x20) == 0x77) if(read(0,ADDRESS,0x21) == 0x09) return 1; return 0; }
void gpt_timer_callback() { static char gps_rx_count = 0; g_sending_time_cnt += 1;g_watchdog_cnt += 1;g_sleep_on_duration += 1;g_device_idle_duration += 1;gps_rx_count += 1;g_other_task_cnt+=1; if(f.g_device_in_sleep_F == 0) sending_interval = g_gprs_sending_time; else sending_interval = g_sleep_tracking_interval_in_secs; if(g_sending_time_cnt >= sending_interval) { g_sending_time_cnt = 0; f.g_make_data_F = 1; } if(g_sleep_on_duration >= 60) // If motion is not sensed from last 180 seconds then put the device in sleep. { g_sleep_on_duration = 0; f.g_enter_in_sleep_F = 1; } if(g_watchdog_cnt > 310) // Watchdog is running at 300 secs, if count goes more than 310 then restart the module. { eat_debug("WatchDog Reset\n"); eat_sleep(1000); eat_reset_module(); } if(g_device_idle_duration > 60) //If motion is not sensed from last 60 secs then put the device in idle mode. { g_device_idle_duration = 0; f.g_device_idle_F = 1; f.g_motion_sensed_F = 0; } if(gps_rx_count >= 2) { gps_rx_count = 0; if(f.g_gps_rx_F == 0 && f.g_device_in_sleep_F == 0) f.g_gps_rx_F = 1; } if(g_other_task_cnt > 30) { g_other_task_cnt = 0; f.g_other_routine_F = 1; } led_functionality(); }
void var_delay_ms(unsigned int cnt) { u8 number_of_events = 0; unsigned int time=1; cnt /=100; while(time<=cnt) { if(f.g_ota_in_progress_F == 0) { sense_io(1); save_live_data_in_memory(); if(f.g_gps_rx_F == 1) { //f.g_gps_rx_F = 0; gps_rx(0); } } eat_sleep(100); time++; } }
static void app_main(void *data) { EatUartConfig_st uart_config; EatEvent_st event; int event_num = 0; APP_InitRegions(); //APP RAM initialize APP_init_clib(); //C library initialize if(eat_uart_open(eat_uart_app ) == EAT_FALSE) { eat_trace("[%s] uart(%d) open fail!", __FUNCTION__, eat_uart_app); } uart_config.baud = EAT_UART_BAUD_115200; uart_config.dataBits = EAT_UART_DATA_BITS_8; uart_config.parity = EAT_UART_PARITY_NONE; uart_config.stopBits = EAT_UART_STOP_BITS_1; if(EAT_FALSE == eat_uart_set_config(eat_uart_app, &uart_config)) { eat_trace("[%s] uart(%d) set config fail!", __FUNCTION__, eat_uart_app); } //eat_uart_set_send_complete_event(eat_uart_app, EAT_TRUE); eat_timer_start(EAT_TIMER_1, 10000); while(1) { event_num = eat_get_event_num(); get_event: if(event_num>0) { eat_get_event(&event); eat_trace("[%s] event_id=%d", __FUNCTION__, event.event); if (event.event == EAT_EVENT_NULL || event.event >= EAT_EVENT_NUM) { eat_trace("[%s] invalid event type", __FUNCTION__, event.event); continue; } switch (event.event) { case EAT_EVENT_TIMER : { //Restart timer if(event.data.timer.timer_id == EAT_TIMER_2) { eat_timer_start(EAT_TIMER_2, 50); }else { if(eat_timer_process()) eat_timer_start(event.data.timer.timer_id, 6000); else eat_timer_start(EAT_TIMER_2, 50); } // eat_trace("Timer test 1, timer ID:%d", event.data.timer.timer_id); } break; case EAT_EVENT_MDM_READY_RD: mdm_rx_proc(&event); break; case EAT_EVENT_MDM_READY_WR: eat_trace("[%s] uart(%d) event :%s", __FUNCTION__, event.data.uart, "EAT_EVENT_MDM_READY_WR"); break; case EAT_EVENT_UART_READY_RD: uart_rx_proc(&event); break; case EAT_EVENT_UART_READY_WR: eat_trace("[%s] uart(%d) event :%s", __FUNCTION__, event.data.uart, "EAT_EVENT_UART_READY_WR"); uart_ready_wr_proc(); break; case EAT_EVENT_UART_SEND_COMPLETE: uart_send_complete_proc(&event); break; default: break; } event_num = eat_get_event_num(); if(event_num>0) goto get_event; else eat_sleep(50); }else { eat_sleep(50); } } }