コード例 #1
0
void d_flip_flop_set(uint8_t value) {
	uint8_t tmp = !!value; /* be sure to have 0 or 1 */
	/* 74LVC79-type flip-flop accept 160MHz clk and 2.5ns setup time.
	 * At 32MHz processor, no need to add any delay.*/
	soc_gpio_write(d_flip_flop.gpio_port, d_flip_flop.d, tmp);
	soc_gpio_write(d_flip_flop.gpio_port, d_flip_flop.ck, 1);
	soc_gpio_write(d_flip_flop.gpio_port, d_flip_flop.ck, 0);
	soc_gpio_write(d_flip_flop.gpio_port, d_flip_flop.d, 0);
}
コード例 #2
0
void usb_disconnect()
{
	struct usb_event evt;
	evt.event = USB_EVENT_DISCONNECT;
	if (static_data->usb_event_cb) {
		static_data->usb_event_cb(&evt);
	}
	if (dwc_otg_device->core_if->pcd_cb) {
		DWC_FREE(dwc_otg_device->core_if->pcd_cb);
		dwc_otg_device->core_if->pcd_cb = NULL;
	}
	if (dwc_otg_device->pcd) {
		dwc_otg_pcd_remove(dwc_otg_device->pcd);
		dwc_otg_device->pcd = NULL;
	}
	if (dwc_otg_device->core_if) {
		dwc_otg_cil_remove(dwc_otg_device->core_if);
		dwc_otg_device->core_if = NULL;
	}

	/* Disable clock */
	MMIO_REG_VAL(AHB_CTRL_REG) &= ~CCU_USB_CLK_EN;

	/* Stopping USB PLL */
	MMIO_REG_VAL(USB_PLL_CFG0) &= ~USB_PLL_PDLD;

	/* Disable regulator */
	soc_gpio_write(SOC_GPIO_32, VENABLE_USB_REGULATOR, 0);
}
コード例 #3
0
ファイル: crb.c プロジェクト: pafcndg/ndgIqSoftwareKit
static void battery_latch_en(void)
{
	gpio_cfg_data_t config;
	/* Enable Battery Latch */
	config.gpio_type = GPIO_OUTPUT;
	soc_gpio_set_config(SOC_GPIO_32, POWER_LATCH_GPIO, &config);
	soc_gpio_write(SOC_GPIO_32, POWER_LATCH_GPIO, 1);
}
コード例 #4
0
ファイル: usb_pm.c プロジェクト: pafcndg/ndgIqSoftwareKit
void enable_vusb_regulator(struct usb_pm_info *usb_pm, bool enable){
	gpio_cfg_data_t config;
	struct device * gpiodev = usb_pm->vusb_enable_dev;
	if (gpiodev){
		config.gpio_type = GPIO_OUTPUT;
		soc_gpio_set_config(gpiodev, usb_pm->vusb_enable_pin, &config);
		soc_gpio_write(gpiodev, usb_pm->vusb_enable_pin, enable);

		/* We need to wait some time here for USB voltage regulator to stabilize */
		delay_us(90);
	} else {
		pr_warning(LOG_MODULE_USB, "USB Voltage regulator enable not supported");
	}
}
コード例 #5
0
void usb_connect()
{
	gpio_cfg_data_t config;

	/* Setup and turn on USB PLL */
	MMIO_REG_VAL(USB_PLL_CFG0) = USB_PLL_CFG0_DEFAULT | USB_PLL_PDLD;

	/*Wait for the PLL lock */
	int count = 500;
	while(count-- && (0 == (MMIO_REG_VAL(USB_PLL_CFG0) & USB_PLL_LOCK))){}

	/* Turn on the clock gate */
	MMIO_REG_VAL(AHB_CTRL_REG) |= CCU_USB_CLK_EN;

	/* GPIO already configured by BOOTLOADER on OUTPUT MODE */
	/* Enable internal regulator */
	soc_gpio_write(SOC_GPIO_32, VENABLE_USB_REGULATOR, 1);
}
コード例 #6
0
ファイル: crb.c プロジェクト: pafcndg/ndgIqSoftwareKit
void shutdown(enum shutdown_types type)
{
	soc_gpio_write(SOC_GPIO_32, POWER_LATCH_GPIO, 0);
}
コード例 #7
0
ファイル: gpio_tst.c プロジェクト: pafcndg/ndgIqSoftwareKit
static DRIVER_API_RC soc_gpio_test_pin(struct device *dev, unsigned int input_pin, unsigned int output_pin)
{
    DRIVER_API_RC ret;
    bool value;

    gpio_cfg_data_t in_pin_cfg;
    gpio_cfg_data_t out_pin_cfg;

    in_pin_cfg.gpio_type = GPIO_INPUT;
    in_pin_cfg.int_type = LEVEL;
    in_pin_cfg.int_polarity = ACTIVE_LOW;
    in_pin_cfg.int_debounce = DEBOUNCE_OFF;
    in_pin_cfg.int_ls_sync = LS_SYNC_OFF;
    in_pin_cfg.gpio_cb = NULL;

    out_pin_cfg.gpio_type = GPIO_OUTPUT;
    out_pin_cfg.int_type = LEVEL;
    out_pin_cfg.int_polarity = ACTIVE_LOW;
    out_pin_cfg.int_debounce = DEBOUNCE_OFF;
    out_pin_cfg.int_ls_sync = LS_SYNC_OFF;
    out_pin_cfg.gpio_cb = NULL;

    if((ret =  soc_gpio_set_config(dev, input_pin, &in_pin_cfg)) != DRV_RC_OK) {
        cu_print("Error pin %d config (%d)\n", input_pin, ret);
        return ret;
    }
    if((ret =  soc_gpio_set_config(dev, output_pin, &out_pin_cfg)) != DRV_RC_OK) {
        cu_print("Error pin %d config (%d)\n", output_pin, ret);
        soc_gpio_deconfig(dev, input_pin);
        return ret;
    }

    // Test LOW
    if((ret =  soc_gpio_write(dev, output_pin, 0)) != DRV_RC_OK) {
        cu_print("Error pin %d write 1 (%d)\n", output_pin, ret);
        soc_gpio_deconfig(dev, output_pin);
        soc_gpio_deconfig(dev, input_pin);
        return ret;
    }
    trans_delay(); // Delay a little bit
    if((ret =  soc_gpio_read(dev, input_pin, &value)) != DRV_RC_OK) {
        cu_print("Error pin %d read 1 (%d)\n", input_pin, ret);
        soc_gpio_deconfig(dev, output_pin);
        soc_gpio_deconfig(dev, input_pin);
        return ret;
    }
    if(value) {
        cu_print("Error pin %d is at 1, 0 expected\n", input_pin);
        soc_gpio_deconfig(dev, output_pin);
        soc_gpio_deconfig(dev, input_pin);
        return DRV_RC_FAIL;
    }

    // Test HIGH
    if((ret =  soc_gpio_write(dev, output_pin, 1)) != DRV_RC_OK) {
        cu_print("Error pin %d write 2 (%d)\n", output_pin, ret);
        soc_gpio_deconfig(dev, output_pin);
        soc_gpio_deconfig(dev, input_pin);
        return ret;
    }
    trans_delay(); // Delay a little bit
    if((ret =  soc_gpio_read(dev, input_pin, &value)) != DRV_RC_OK) {
        cu_print("Error pin %d read 2 (%d)\n", input_pin, ret);
        soc_gpio_deconfig(dev, output_pin);
        soc_gpio_deconfig(dev, input_pin);
        return ret;
    }
    if(!value) {
        cu_print("Error pin %d is at 0, 1 expected\n", input_pin);
        soc_gpio_deconfig(dev, output_pin);
        soc_gpio_deconfig(dev, input_pin);
        return DRV_RC_FAIL;
    }

    soc_gpio_deconfig(dev, output_pin);
    soc_gpio_deconfig(dev, input_pin);

    return DRV_RC_OK;
}
コード例 #8
0
ファイル: gpio_tst.c プロジェクト: pafcndg/ndgIqSoftwareKit
static DRIVER_API_RC soc_gpio_test_pin_int(struct device *dev, unsigned int input_pin, unsigned int output_pin)
{
    uint32_t priv = PRIV_KEY;
    gpio_cfg_data_t in_pin_cfg;
    gpio_cfg_data_t out_pin_cfg;

    out_pin_cfg.gpio_type = GPIO_OUTPUT;
    out_pin_cfg.int_type = LEVEL;
    out_pin_cfg.int_polarity = ACTIVE_LOW;
    out_pin_cfg.int_debounce = DEBOUNCE_OFF;
    out_pin_cfg.gpio_cb = NULL;

    // TODO: test return value. It should be ok if previous tests worked
    soc_gpio_set_config(dev, output_pin, &out_pin_cfg);

    // -----------------------------
    // Test ACTIVE_LOW interrupt
    // -----------------------------
    in_pin_cfg.gpio_type = GPIO_INTERRUPT;
    in_pin_cfg.int_type = EDGE;
    in_pin_cfg.int_polarity = ACTIVE_LOW;
    in_pin_cfg.int_debounce = DEBOUNCE_OFF;
    in_pin_cfg.gpio_cb = my_callback;
    in_pin_cfg.gpio_cb_arg = &priv;

    soc_gpio_write(dev, output_pin, 0);
    trans_delay(); // Delay a little bit
    my_callback_counter = 0;
    soc_gpio_set_config(dev, input_pin, &in_pin_cfg);
    trans_delay(); // Delay a little bit
    soc_gpio_write(dev, output_pin, 1);
    trans_delay(); // Delay a little bit

    // Check that interrupt is not triggered
    if(my_callback_counter != 0) {
        cu_print("Error: interrupt occured %d\n", my_callback_counter);
        goto fail;
    }

    // Trigger interrupt (active low)
    soc_gpio_write(dev, output_pin, 0);
    trans_delay(); // Delay a little bit
    // Check that interrupt is triggered
    if(my_callback_counter != 1) {
        cu_print("Error: interrupt test for ACTIVE_LOW returned %d\n", my_callback_counter);
        goto fail;
    }
    // Check that pin state returned in IRQ callback is valid
    if(my_callback_state != false) {
        cu_print("Error: pin state not valid\n");
        goto fail;
    }

    // deconfigure input pin for next test (active high)
    soc_gpio_deconfig(dev, input_pin);

    // -----------------------------
    // Test ACTIVE_HIGH interrupt
    // -----------------------------
    in_pin_cfg.gpio_type = GPIO_INTERRUPT;
    in_pin_cfg.int_type = EDGE;
    in_pin_cfg.int_polarity = ACTIVE_HIGH;
    in_pin_cfg.int_debounce = DEBOUNCE_OFF;
    in_pin_cfg.gpio_cb = my_callback;

    // Test LOW
    soc_gpio_write(dev, output_pin, 1);
    trans_delay(); // Delay a little bit
    my_callback_counter = 0;
    soc_gpio_set_config(dev, input_pin, &in_pin_cfg);
    soc_gpio_write(dev, output_pin, 0);
    trans_delay(); // Delay a little bit
    // Check that interrupt is not triggered
    if(my_callback_counter != 0) {
        cu_print("Error: interrupt test for ACTIVE_HIGH returned %d (should be 0)\n", my_callback_counter);
        goto fail;
    }
    // Check that interrupt is triggered (active high)
    soc_gpio_write(dev, output_pin, 1);
    trans_delay(); // Delay a little bit
    if(my_callback_counter != 1) {
        cu_print("Error: interrupt test for ACTIVE_HIGH returned %d (should be 1)\n", my_callback_counter);
        goto fail;
    }
    // Check that pin state returned in IRQ callback is valid
    if(my_callback_state != true) {
        cu_print("Error: pin state not valid\n");
        goto fail;
    }

    // deconfigure input pin for next test (double edge)
    soc_gpio_deconfig(dev, input_pin);

    // -----------------------------
    // Test BOTH_EDGE interrupt
    // -----------------------------
    in_pin_cfg.gpio_type = GPIO_INTERRUPT;
    in_pin_cfg.int_type = DOUBLE_EDGE;
    in_pin_cfg.int_polarity = ACTIVE_HIGH;
    in_pin_cfg.int_debounce = DEBOUNCE_OFF;
    in_pin_cfg.gpio_cb = my_callback;

    // Test LOW
    soc_gpio_write(dev, output_pin, 0);
    trans_delay(); // Delay a little bit
    soc_gpio_set_config(dev, input_pin, &in_pin_cfg);
    my_callback_counter = 0;
    soc_gpio_write(dev, output_pin, 1);
    trans_delay(); // Delay a little bit
    // Check that interrupt is triggered
    if(my_callback_counter != 1) {
        cu_print("Error: interrupt test for DOUBLE_EDGE returned %d (should be 1)\n", my_callback_counter);
        goto fail;
    }
    // Check that pin state returned in IRQ callback is valid
    if(my_callback_state != true) {
        cu_print("Error: pin state not valid\n");
        goto fail;
    }
    // Check that interrupt is triggered (double edge)
    soc_gpio_write(dev, output_pin, 0);
    trans_delay(); // Delay a little bit
    // Check that interrupt is not triggered
    if(my_callback_counter != 2) {
        cu_print("Error: interrupt test for DOUBLE_EDGE returned %d (should be 2)\n", my_callback_counter);
        goto fail;
    }
    // Check that pin state returned in IRQ callback is valid
    if(my_callback_state != false) {
        cu_print("Error: pin state not valid\n");
        goto fail;
    }

    soc_gpio_deconfig(dev, output_pin);
    soc_gpio_deconfig(dev, input_pin);
    return DRV_RC_OK;

fail:
    soc_gpio_deconfig(dev, output_pin);
    soc_gpio_deconfig(dev, input_pin);
    return DRV_RC_FAIL;
}