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 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; }
void pp_soft_wdt_feed() { struct rst_info rst_info; rst_info.exccause = RSR(EXCCAUSE); rst_info.epc1 = RSR(EPC1); rst_info.epc2 = RSR(EPC2); rst_info.epc3 = RSR(EPC3); rst_info.excvaddr = RSR(EXCVADDR); rst_info.depc = RSR(DEPC); rst_info.reason = WDT_RST_FLAG; system_rtc_mem_write(0, &rst_info, sizeof(rst_info)); if(wdt_flg == true) { Cache_Read_Disable(); Cache_Read_Enable_New(); system_restart_local(); } else { #if SDK_VERSION >= 1119 wDev_MacTim1Arm(soft_wdt_interval); #else ets_timer_disarm(SoftWdtTimer); ets_timer_arm_new(SoftWdtTimer, soft_wdt_interval, 0, 1); #endif wdt_flg = true; pp_post(12); } }
void pp_soft_wdt_feed_local() { struct rst_info rst_info; rst_info.exccause = RSR(EXCCAUSE); rst_info.epc1 = RSR(EPC1); rst_info.epc2 = RSR(EPC2); rst_info.epc3 = RSR(EPC3); rst_info.excvaddr = RSR(EXCVADDR); rst_info.depc = RSR(DEPC); if(wdt_flg == true) { rst_info.reason = REASON_SOFT_WDT_RST; // =3 system_rtc_mem_write(0, &rst_info, sizeof(rst_info)); ets_intr_lock(); Wait_SPI_Idle(flashchip); Cache_Read_Enable_New(); system_restart_local(); } else { rst_info.reason = REASON_WDT_RST; // =1 system_rtc_mem_write(0, &rst_info, sizeof(rst_info)); #if DEF_SDK_VERSION >= 1119 wDev_MacTim1Arm(soft_wdt_interval); #else ets_timer_disarm(SoftWdtTimer); ets_timer_arm_new(SoftWdtTimer, soft_wdt_interval, 0, 1); #endif wdt_flg = true; pp_post(12); } }
/** * SNTP processing of received timestamp */ static void sntp_process(u32_t *receive_timestamp) { /* convert SNTP time (1900-based) to unix GMT time (1970-based) * @todo: if MSB is 1, SNTP time is 2036-based! */ time_t t = (ntohl(receive_timestamp[0]) - DIFF_SEC_1900_1970); sntp_time = t; #if SNTP_CALC_TIME_US u32_t us = ntohl(receive_timestamp[1]) / 4295; SNTP_SET_SYSTEM_TIME_US(t, us); /* display local time from GMT time */ //LWIP_DEBUGF(SNTP_DEBUG_TRACE, ("sntp_process: %s, %"U32_F" us", ctime(&t), us)); LWIP_DEBUGF(SNTP_DEBUG_TRACE, "sntp_process: %lu, us", t); /* os_sprintf(deb,"sntp_process: %lu" , t); uart0_sendStr(deb);*/ #else /* SNTP_CALC_TIME_US */ /* change system time and/or the update the RTC clock */ SNTP_SET_SYSTEM_TIME(t); /* display local time from GMT time */ //LWIP_DEBUGF(SNTP_DEBUG_TRACE, ("sntp_process: %s", ctime(&t))); LWIP_DEBUGF(SNTP_DEBUG_TRACE, "sntp_process: %lu, us", t); /* os_sprintf(deb, "sntp_process: %lu", t); uart0_sendStr(deb);*/ #endif /* SNTP_CALC_TIME_US */ os_timer_disarm(&ntp_timer); ets_timer_arm_new(&ntp_timer,1000,1); //uart0_sendStr("Arming timer...\n"); }
//============================================================================= 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 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 DriverPWM::initialize() { if (!initialized) { initialized = true; os_timer_disarm(&main); os_timer_setfn(&main, (os_timer_func_t *)processingStatic, this); ets_timer_arm_new(&main, period, 1, 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 ChannelPWM::high() { if (time == 0) return; // Full OFF mode digitalWrite(pin, HIGH); if (time != ULONG_MAX) // Full ON mode { os_timer_disarm(&item); item.timer_arg = this; ets_timer_arm_new(&item, time, 0, 0); } }
// Lua: tmr.interval( id / ref, interval ) static int tmr_interval(lua_State* L){ timer_t tmr = tmr_get(L, 1); uint32_t interval = luaL_checkinteger(L, 2); luaL_argcheck(L, (interval > 0 && interval <= MAX_TIMEOUT), 2, MAX_TIMEOUT_ERR_STR); if(tmr->mode != TIMER_MODE_OFF){ tmr->interval = interval; if(!(tmr->mode&TIMER_IDLE_FLAG)){ ets_timer_disarm(&tmr->os); ets_timer_arm_new(&tmr->os, tmr->interval, tmr->mode==TIMER_MODE_AUTO, 1); } } return 0; }
// Lua: tmr.start( id / ref ) static int tmr_start(lua_State* L){ timer_t tmr = tmr_get(L, 1); if (tmr->self_ref == LUA_NOREF) { lua_pushvalue(L, 1); tmr->self_ref = luaL_ref(L, LUA_REGISTRYINDEX); } //we return false if the timer is not idle if(!(tmr->mode&TIMER_IDLE_FLAG)){ lua_pushboolean(L, 0); }else{ tmr->mode &= ~TIMER_IDLE_FLAG; ets_timer_arm_new(&tmr->os, tmr->interval, tmr->mode==TIMER_MODE_AUTO, 1); lua_pushboolean(L, 1); } return 1; }
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; }
//---------------------------------------------------------------------------------- // 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; }
int func1(int val) { if (!pm_is_open()) return 0; if (((uint8 *)default_interface)[0] == 0) { __func2(promiscuous_cb, 0x4024081c, 0); ((uint8 *)default_interface)[0] = 1; } if (!pm_is_waked() || (((uint8 *)user_init_flag)[60] == 1)) { if (((uint8 *)user_init_flag)[60] == 0) { pm_post(1); __func3(((uint8 *)user_init_flag)[24]); ets_timer_arm_new(((uint8 *)user_init_flag)[24], 10, 0, 1); ((uint8 *)user_init_flag)[60] = 1; } ((uint8 *)user_init_flag)[61] = (((uint8 *)user_init_flag)[61] + 1) & 0xff; if (((uint8 *)user_init_flag)[61] > 10) { os_printf_plus("DEFERRED FUNC NUMBER IS BIGGER THAN 10\n"); ((uint8 *)user_init_flag)[61] = 10; } ((uint8 *)user_init_flag)[62] += 9; if (((uint8 *)user_init_flag)[62] >= 10) { *(((uint8 *)user_init_flag)[62] + ((uint8 *)user_init_flag)[175] + 122) = val; return -1; } *(((uint8 *)user_init_flag)[62] + ((uint8 *)user_init_flag)[175] + 132) = val; return -1; } return 0; }
//=============================================================================== // Timer: UART->TCP (UART->bufo->TCP) // loading_rx_buf() чтение fifo UART rx в буфер передачи TCP // Сигнал CTS/RTS пока не огранизован в связи с неясностью, // на какую ногу модуля его делать //------------------------------------------------------------------------------- void ICACHE_FLASH_ATTR loading_rx_buf(void) { TCP_SERV_CONN *conn = tcp2uart_conn; if(conn == NULL || conn->pbufo == NULL || conn->flag.user_flg1) return; // нет буфера + тест на повторное вхождение conn->flag.user_flg1 = 1; ets_intr_lock(); // ETS_UART_INTR_DISABLE(); MEMW(); UART0_INT_ENA &= ~ UART_RXFIFO_FULL_INT_ENA; // запретить прерывание по приему символа ets_intr_unlock(); // ETS_UART_INTR_ENABLE(); os_timer_disarm(&uart0_rx_buf_timer); if(conn->flag.busy_bufo) { // в данный момент bufo обрабатывается (передается LwIP-у)? // попробовать повторить через время ets_timer_arm_new(&uart0_rx_buf_timer, 10, 0, 0); // 10us conn->flag.user_flg1 = 0; return; } uint8 *pend = conn->pbufo + conn->sizeo; // дополнить буфер передачи символами из rx fifo while((conn->ptrtx + conn->cntro) < pend) { MEMW(); if((UART0_STATUS >> UART_RXFIFO_CNT_S) & UART_RXFIFO_CNT) conn->ptrtx[conn->cntro++] = UART0_FIFO; else break; }
//------------------------------------------------------------------------------- // 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 секунд }
void ICACHE_RAM_ATTR onSdaChange(void) { static uint8_t sda; static uint8_t scl; sda = SDA_READ(); scl = SCL_READ(); switch (twip_state) { case TWIP_IDLE: if (!scl) { // DATA - ignore } else if (sda) { // STOP - ignore } else { // START bitCount = 8; twip_state = TWIP_START; ets_timer_arm_new(&timer, twi_timeout_ms, false, true); // Once, ms } break; case TWIP_START: case TWIP_REP_START: case TWIP_SEND_ACK: case TWIP_WAIT_ACK: case TWIP_SLA_R: case TWIP_REC_ACK: case TWIP_READ_ACK: case TWIP_RWAIT_ACK: case TWIP_WRITE: if (!scl) { // DATA - ignore } else { // START or STOP SDA_HIGH(); // Should not be necessary twip_status = TW_BUS_ERROR; twi_onTwipEvent(twip_status); twip_mode = TWIPM_WAIT; twip_state = TWIP_BUS_ERR; } break; case TWIP_WAIT_STOP: case TWIP_BUS_ERR: if (!scl) { // DATA - ignore } else { if (sda) { // STOP SCL_LOW(); // clock stretching ets_timer_disarm(&timer); twip_state = TWIP_IDLE; twip_mode = TWIPM_IDLE; SCL_HIGH(); } else { // START if (twip_state == TWIP_BUS_ERR) { // ignore } else { bitCount = 8; twip_state = TWIP_REP_START; ets_timer_arm_new(&timer, twi_timeout_ms, false, true); // Once, ms } } } break; case TWIP_SLA_W: case TWIP_READ: if (!scl) { // DATA - ignore } else { // START or STOP if (bitCount != 7) { // inside byte transfer - error twip_status = TW_BUS_ERROR; twi_onTwipEvent(twip_status); twip_mode = TWIPM_WAIT; twip_state = TWIP_BUS_ERR; } else { // during first bit in byte transfer - ok SCL_LOW(); // clock stretching twip_status = TW_SR_STOP; twi_onTwipEvent(twip_status); if (sda) { // STOP ets_timer_disarm(&timer); twip_state = TWIP_IDLE; twip_mode = TWIPM_IDLE; } else { // START bitCount = 8; ets_timer_arm_new(&timer, twi_timeout_ms, false, true); // Once, ms twip_state = TWIP_REP_START; twip_mode = TWIPM_IDLE; } } } break; default: break; } }