//============================================================================= void user_init(void) { ets_timer_disarm(&test_timer); ets_timer_setfn(&test_timer, (os_timer_func_t *)test_timer_isr, NULL); ets_timer_arm_new(&test_timer, 1000000, 1, 0); // 1 раз в сек ets_set_idle_cb(tests, NULL); // после инициалаизации запустить tests() }
void Timer::start(bool repeating/*=true*/) { stop(); ets_timer_setfn(&timer, (os_timer_func_t *)processing, this); started = true; if (interval > 1000) ets_timer_arm_new(&timer, interval / 1000, repeating, 1); // msec else ets_timer_arm_new(&timer, interval, repeating, 0); // usec }
void ICACHE_FLASH_ATTR pp_soft_wdt_init(void) { #if DEF_SDK_VERSION < 1109 // (SDK 1.1.0 no patch) ets_timer_setfn(SoftWdtTimer, (ETSTimerFunc *)pp_soft_wdt_feed, NULL); ets_timer_arm_new(SoftWdtTimer, soft_wdt_interval, 0, 1); #elif DEF_SDK_VERSION >= 1119 wDev_MacTim1SetFunc(pp_soft_wdt_feed_local); wDev_MacTim1Arm(soft_wdt_interval); #endif }
void Timer::start(bool repeating/* = true*/) { stop(); if(interval == 0 || (!callback && !delegate_func)) return; ets_timer_setfn(&timer, (os_timer_func_t *)processing, this); if (interval > 1000) ets_timer_arm_new(&timer, interval / 1000, repeating, 1); // msec else ets_timer_arm_new(&timer, interval, repeating, 0); // usec started = true; }
int luaopen_tmr( lua_State *L ){ int i; luaL_rometatable(L, "tmr.timer", (void *)tmr_dyn_map); for(i=0; i<NUM_TMR; i++){ alarm_timers[i].lua_ref = LUA_NOREF; alarm_timers[i].self_ref = LUA_REFNIL; alarm_timers[i].mode = TIMER_MODE_OFF; ets_timer_disarm(&alarm_timers[i].os); } last_rtc_time=system_get_rtc_time(); // Right now is time 0 last_rtc_time_us=0; ets_timer_disarm(&rtc_timer); ets_timer_setfn(&rtc_timer, rtc_callback, NULL); ets_timer_arm_new(&rtc_timer, 1000, 1, 1); return 0; }
void Timer::start(bool repeating/* = true*/) { this->repeating = repeating; stop(); if(interval == 0 || (!callback && !delegate_func)) return; ets_timer_setfn(&timer, (os_timer_func_t *)processing, this); if (interval > 10000) { ets_timer_arm_new(&timer, (uint32_t)(interval / 1000), (long_intvl_cntr_lim > 0 ? true : repeating), 1); // msec } else { ets_timer_arm_new(&timer, (uint32_t)interval, repeating, 0); // usec } started = true; }
void twi_init(unsigned char sda, unsigned char scl) { // set timer function ets_timer_setfn(&timer, onTimer, NULL); // create event task ets_task(eventTask, EVENTTASK_QUEUE_PRIO, eventTaskQueue, EVENTTASK_QUEUE_SIZE); twi_sda = sda; twi_scl = scl; pinMode(twi_sda, INPUT_PULLUP); pinMode(twi_scl, INPUT_PULLUP); twi_setClock(preferred_si2c_clock); twi_setClockStretchLimit(230); // default value is 230 uS if (twi_addr != 0) { attachInterrupt(scl, onSclChange, CHANGE); attachInterrupt(sda, onSdaChange, CHANGE); } }
//---------------------------------------------------------------------------------- // Initialize Humidity Sensor driver int OpenHMSdrv(void) //---------------------------------------------------------------------------------- { if(hms_pin_scl > 15 || hms_pin_sda > 15 || hms_pin_scl == hms_pin_sda) { // return 1; hms_pin_scl = 4; hms_pin_sda = 5; } if(i2c_init(hms_pin_scl, hms_pin_sda, 54)) { // 4,5,54); // 354 hms_errflg = -3; // драйвер не инициализирован - ошибки параметров инициализации return 1; } hmerrcnt = 0; hmioerr = 0; hmfuncs = 0; hms_errflg = 1; // драйвер запущен SetTimeOut(50); // зададим таймаут в 50 ms ets_timer_disarm(&test_timer); ets_timer_setfn(&test_timer, (os_timer_func_t *)ReadHMS, NULL); ets_timer_arm_new(&test_timer, 10, 1, 1); // 100 раз в сек hms_init_flg = 1; return 0; }
// Lua: tmr.register( id / ref, interval, mode, function ) static int tmr_register(lua_State* L){ timer_t tmr = tmr_get(L, 1); uint32_t interval = luaL_checkinteger(L, 2); uint8_t mode = luaL_checkinteger(L, 3); luaL_argcheck(L, (interval > 0 && interval <= MAX_TIMEOUT), 2, MAX_TIMEOUT_ERR_STR); luaL_argcheck(L, (mode == TIMER_MODE_SINGLE || mode == TIMER_MODE_SEMI || mode == TIMER_MODE_AUTO), 3, "Invalid mode"); luaL_argcheck(L, (lua_type(L, 4) == LUA_TFUNCTION || lua_type(L, 4) == LUA_TLIGHTFUNCTION), 4, "Must be function"); //get the lua function reference lua_pushvalue(L, 4); sint32_t ref = luaL_ref(L, LUA_REGISTRYINDEX); if(!(tmr->mode & TIMER_IDLE_FLAG) && tmr->mode != TIMER_MODE_OFF) ets_timer_disarm(&tmr->os); //there was a bug in this part, the second part of the following condition was missing if(tmr->lua_ref != LUA_NOREF && tmr->lua_ref != ref) luaL_unref(L, LUA_REGISTRYINDEX, tmr->lua_ref); tmr->lua_ref = ref; tmr->mode = mode|TIMER_IDLE_FLAG; tmr->interval = interval; ets_timer_setfn(&tmr->os, alarm_timer_common, tmr); return 0; }
static void IRAM_ATTR timer_setfn_wrapper(void *ptimer, void *pfunction, void *parg) { ets_timer_setfn(ptimer, pfunction, parg); }
//------------------------------------------------------------------------------- // run_error_timer //------------------------------------------------------------------------------- void ICACHE_FLASH_ATTR run_error_timer(uint32 tsec) { ets_timer_disarm(&error_timer); ets_timer_setfn(&error_timer, (os_timer_func_t *)tc_go_next, NULL); ets_timer_arm_new(&error_timer, tsec*1000, 0, 1); // таймер на x секунд }