示例#1
0
文件: wdt.c 项目: AndyKorg/esp8266web
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);
	}
}
示例#2
0
文件: user_main.c 项目: pvvx/iramsdk
//=============================================================================
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()
}
示例#3
0
void Timer::stop()
{
	if (!started) return;
	ets_timer_disarm(&timer);
	started = false;
	long_intvl_cntr = 0;
}
示例#4
0
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);
	}
}
示例#5
0
//----------------------------------------------------------------------------------
// Close Humidity Sensor driver
int CloseHMSdrv(void)
//----------------------------------------------------------------------------------
{
	ets_timer_disarm(&test_timer);
	int ret = i2c_deinit();
    hms_errflg = -1; // драйвер не инициализирован
    hms_init_flg = 0;
    return ret;
}
示例#6
0
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;
}
示例#7
0
// Lua: tmr.create()
static int tmr_create( lua_State *L ) {
	timer_t ud = (timer_t)lua_newuserdata(L, sizeof(timer_struct_t));
	if (!ud) return luaL_error(L, "not enough memory");
	luaL_getmetatable(L, "tmr.timer");
	lua_setmetatable(L, -2);
	ud->lua_ref = LUA_NOREF;
	ud->self_ref = LUA_NOREF;
	ud->mode = TIMER_MODE_OFF;
	ets_timer_disarm(&ud->os);
	return 1;
}
示例#8
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;
}
示例#9
0
// Lua: tmr.unregister( id / ref )
static int tmr_unregister(lua_State* L){
	timer_t tmr = tmr_get(L, 1);

	if (tmr->self_ref != LUA_REFNIL) {
		luaL_unref(L, LUA_REGISTRYINDEX, tmr->self_ref);
		tmr->self_ref = LUA_NOREF;
	}

	if(!(tmr->mode & TIMER_IDLE_FLAG) && tmr->mode != TIMER_MODE_OFF)
		ets_timer_disarm(&tmr->os);
	if(tmr->lua_ref != LUA_NOREF)
		luaL_unref(L, LUA_REGISTRYINDEX, tmr->lua_ref);
	tmr->lua_ref = LUA_NOREF;
	tmr->mode = TIMER_MODE_OFF; 
	return 0;
}
示例#10
0
// Lua: tmr.stop( id / ref )
static int tmr_stop(lua_State* L){
	timer_t tmr = tmr_get(L, 1);

	if (tmr->self_ref != LUA_REFNIL) {
		luaL_unref(L, LUA_REGISTRYINDEX, tmr->self_ref);
		tmr->self_ref = LUA_NOREF;
	}

	//we return false if the timer is idle (of not registered)
	if(!(tmr->mode & TIMER_IDLE_FLAG) && tmr->mode != TIMER_MODE_OFF){
		tmr->mode |= TIMER_IDLE_FLAG;
		ets_timer_disarm(&tmr->os);
		lua_pushboolean(L, 1);
	}else{
		lua_pushboolean(L, 0);
	}
	return 1;  
}
示例#11
0
// next iot_data connection
void tc_go_next(void)
{
	#if DEBUGSOO > 4
		os_printf("iot_go_next(%d): %u: %x %x\n", tc_init_flg, system_get_time(), iot_data_first, iot_data_processing);
	#endif
	if(tc_init_flg & TC_RUNNING) { // Process timeout
		close_dns_finding();
		tc_init_flg &= ~TC_RUNNING; // clear
		if(iot_data_processing != NULL) iot_data_processing = iot_data_processing->next;
	}
	// next
	while(iot_data_processing != NULL) {
		if(system_get_time() - iot_data_processing->last_run > iot_data_processing->min_interval) { // если рано - пропускаем
			if(tc_go() == ERR_OK) break;
		}
		iot_data_processing = iot_data_processing->next;
	}
	if(iot_data_processing == NULL) ets_timer_disarm(&error_timer); // stop timer
}
示例#12
0
//-------------------------------------------------------------------------------
// close_dns_found
//-------------------------------------------------------------------------------
void ICACHE_FLASH_ATTR close_dns_finding(void){
	ets_timer_disarm(&error_timer);
	if(tc_init_flg & TC_RUNNING) { // ожидание dns_found_callback() ?
		// убить вызов  tc_dns_found_callback()
		int i;
		for (i = 0; i < DNS_TABLE_SIZE; ++i) {
			if(dns_table[i].state != DNS_STATE_DONE && dns_table[i].found == (dns_found_callback)tc_dns_found_callback) {
				/* flush this entry */
				dns_table[i].found = NULL;
				dns_table[i].state = DNS_STATE_UNUSED;
				#if DEBUGSOO > 4
					os_printf("DNS unused: %s\n", dns_table[i].name);
				#endif
			}
		}
		tc_init_flg &= ~TC_RUNNING;
	}
	tc_close();
}
示例#13
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;
}
示例#14
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;  
}
示例#15
0
static void IRAM_ATTR timer_disarm_wrapper(void *timer)
{
    ets_timer_disarm(timer);
}
示例#16
0
文件: Timer.cpp 项目: MrZANE42/Sming
void Timer::stop()
{
	if (!started) return;
	ets_timer_disarm(&timer);
	started = false;
}
示例#17
0
//-------------------------------------------------------------------------------
// 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 секунд
}
示例#18
0
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;
	}
}