Ejemplo n.º 1
0
/* rtc init check */
int rtc_init(u8 recover)
{
	int ret;

	rtc_info("recovery: %d\n", recover);

	/* write powerkeys to enable rtc functions */
	if (!rtc_powerkey_init()) {
		ret = -RTC_STATUS_POWERKEY_INIT_FAIL;
		goto err;
	}

	/* write interface unlock need to be set after powerkey match */
	if (!rtc_writeif_unlock()) {
		ret = -RTC_STATUS_WRITEIF_UNLOCK_FAIL;
		goto err;
	}

	/* using dcxo 32K clock */
	if (!rtc_enable_dcxo()) {
		ret = -RTC_STATUS_OSC_SETTING_FAIL;
		goto err;
	}

	if (recover)
		mdelay(20);

	if (!rtc_gpio_init()) {
		ret = -RTC_STATUS_GPIO_INIT_FAIL;
		goto err;
	}

	if (!rtc_hw_init()) {
		ret = -RTC_STATUS_HW_INIT_FAIL;
		goto err;
	}

	if (!rtc_reg_init()) {
		ret = -RTC_STATUS_REG_INIT_FAIL;
		goto err;
	}

	if (!rtc_lpd_init()) {
		ret = -RTC_STATUS_LPD_INIT_FAIL;
		goto err;
	}

	/* After lpd init, powerkeys need to be written again to enable
	 * low power detect function.
	 */
	if (!rtc_powerkey_init()) {
		ret = -RTC_STATUS_POWERKEY_INIT_FAIL;
		goto err;
	}

	return RTC_STATUS_OK;
err:
	rtc_info("init fail: ret=%d\n", ret);
	return ret;
}
Ejemplo n.º 2
0
relay_handle_t iot_relay_create(relay_io_t relay_io, relay_close_level_t close_level, relay_ctl_mode_t ctl_mode, relay_io_mode_t io_mode)
{   
    relay_dev_t* relay_p = (relay_dev_t*) calloc(1, sizeof(relay_dev_t));
    relay_p->close_level = close_level;
    relay_p->relay_io = relay_io;
    relay_p->state = RELAY_STATUS_OPEN;
    relay_p->ctl_mode = ctl_mode;
    relay_p->io_mode = io_mode;
    if (io_mode == RELAY_IO_NORMAL) {
        uint64_t bit_mask;
        if (ctl_mode == RELAY_DFLIP_CONTROL) {
            bit_mask = BIT(relay_io.flip_io.d_io_num) | BIT(relay_io.flip_io.cp_io_num);
        }
        else {
            bit_mask = BIT(relay_io.single_io.ctl_io_num);
        }
        gpio_config_t io_conf;
        io_conf.intr_type = GPIO_PIN_INTR_DISABLE;
        io_conf.mode = GPIO_MODE_OUTPUT;
        io_conf.pin_bit_mask = bit_mask;
        io_conf.pull_down_en = 0;
        io_conf.pull_up_en = 0;
        IOT_CHECK(TAG, gpio_config(&io_conf) == ESP_OK, NULL);
    }
    else {
        if (ctl_mode == RELAY_DFLIP_CONTROL) {
            IOT_CHECK(TAG, rtc_gpio_init(relay_io.flip_io.d_io_num) == ESP_OK, NULL);
            IOT_CHECK(TAG, rtc_gpio_init(relay_io.flip_io.cp_io_num) == ESP_OK, NULL);
            rtc_gpio_set_direction(relay_io.flip_io.d_io_num, RTC_GPIO_MODE_OUTPUT_ONLY);
            rtc_gpio_set_direction(relay_io.flip_io.cp_io_num, RTC_GPIO_MODE_OUTPUT_ONLY);
        }
        else {
            IOT_CHECK(TAG, rtc_gpio_init(relay_io.single_io.ctl_io_num) == ESP_OK, NULL);
            rtc_gpio_set_direction(relay_io.single_io.ctl_io_num, RTC_GPIO_MODE_OUTPUT_ONLY);
        }
    }
    return (relay_handle_t) relay_p;
}
Ejemplo n.º 3
0
/* set xosc mode */
void rtc_osc_init(void)
{
	/* enable 32K export */
	rtc_gpio_init();
}