⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pmic_connectivity.cpp

📁 Microsoft WinCE 6.0 BSP FINAL release source code for use with the i.MX27ADS TO2 WCE600_FINAL_MX27_S
💻 CPP
📖 第 1 页 / 共 4 页
字号:
    LeaveCriticalSection(&mutex);
	EXIT_MSG;

    return rc;
}


/*!
 * Get the current callback function and event mask.
 *
 * @param       handle          device handle from open() call
 * @param       func            the current callback function
 * @param       eventMask       the current event selection mask
 *
 * @return      PMIC_SUCCESS    if the callback information was successful
 *                              retrieved
 */
PMIC_STATUS PmicConvityGetCallback(
    const PMIC_CONVITY_HANDLE        handle,
    PMIC_CONVITY_CALLBACK     *const func,
    PMIC_CONVITY_EVENTS       *const eventMask)
{
    PMIC_STATUS rc = PMIC_ERROR;
	
	ENTRY_MSG;
    /* Use a critical section to maintain a consistent state. */
    EnterCriticalSection(&mutex);

    if ((handle == convity.handle)              &&
        (convity.handleState == HANDLE_IN_USE)  &&
        (func != (PMIC_CONVITY_CALLBACK *)NULL) &&
        (eventMask != (PMIC_CONVITY_EVENTS *)NULL))
    {
        *func      = convity.callback;
        *eventMask = convity.eventMask;

        rc = PMIC_SUCCESS;
    }

    /* Exit the critical section. */
    LeaveCriticalSection(&mutex);
	EXIT_MSG;

    return rc;
}


/*!
 * Set the USB transceiver speed. 
 *
 * @param       handle          device handle from open() call
 * @param       speed           the desired USB transceiver speed
 * @param       mode            the USB transceiver mode
 *
 * @return      PMIC_SUCCESS    if the transceiver speed was successfully set
 */
PMIC_STATUS PmicConvityUsbSetSpeed(
    const PMIC_CONVITY_HANDLE    handle,
    const PMIC_CONVITY_USB_SPEED speed,
    const PMIC_CONVITY_USB_MODE  mode)
{
    PMIC_STATUS rc = PMIC_ERROR;

	ENTRY_MSG;
    /* Use a critical section to maintain a consistent state. */
    EnterCriticalSection(&mutex);

    if ((handle == convity.handle) &&
        (convity.handleState == HANDLE_IN_USE))
    {
		param.op = 0;
		param.PARAMS.USB_SPEED.usbSpeed = speed;
		param.PARAMS.USB_SPEED.usbMode = mode;
		DeviceIoControl(hPMI, PMIC_IOCTL_CONVT_USB_SETSPEED, &param, sizeof(param),
			&rc, sizeof(rc), NULL, NULL);
        if (rc == PMIC_SUCCESS)
        {
			convity.usbSpeed = speed;
			convity.usbMode  = mode;
		}
    }
    /* Exit the critical section. */
    LeaveCriticalSection(&mutex);
	EXIT_MSG;

    return rc;
}

/*!
 * Get the USB transceiver speed.
 *
 * @param       handle          device handle from open() call
 * @param       speed           the current USB transceiver speed
 * @param       mode            the current USB transceiver mode
 *
 * @return      PMIC_SUCCESS    if the transceiver speed was successfully
 *                              obtained
 */
PMIC_STATUS PmicConvityUsbGetSpeed(
    const PMIC_CONVITY_HANDLE     handle,
    PMIC_CONVITY_USB_SPEED *const speed,
    PMIC_CONVITY_USB_MODE *const  mode)
{
    PMIC_STATUS rc = PMIC_ERROR;
	
	ENTRY_MSG;
    /* Use a critical section to maintain a consistent state. */
    EnterCriticalSection(&mutex);

    if ((handle == convity.handle)                &&
        (convity.handleState == HANDLE_IN_USE)    &&
        (speed != (PMIC_CONVITY_USB_SPEED *)NULL) &&
        (mode != (PMIC_CONVITY_USB_MODE *)NULL))
    {
        *speed = convity.usbSpeed;
        *mode  = convity.usbMode;

        rc = PMIC_SUCCESS;
    }

    /* Exit the critical section. */
    LeaveCriticalSection(&mutex);
	EXIT_MSG;

    return rc;
}


/*!
 * Set the USB transceiver's power supply configuration.
 *
 * @param       handle          device handle from open() call
 * @param       pwrin           USB transceiver regulator input power source
 * @param       pwrout          USB transceiver regulator output power level
 *
 * @return      PMIC_SUCCESS    if the USB transceiver's power supply
 *                              configuration was successfully set
 */
PMIC_STATUS PmicConvityUsbSetPowerSource(
    const PMIC_CONVITY_HANDLE        handle,
    const PMIC_CONVITY_USB_POWER_IN  pwrin,
    const PMIC_CONVITY_USB_POWER_OUT pwrout)
{
    PMIC_STATUS rc = PMIC_ERROR;
	
	ENTRY_MSG;
    /* Use a critical section to maintain a consistent state. */
    EnterCriticalSection(&mutex);

    if ((handle == convity.handle) &&
        (convity.handleState == HANDLE_IN_USE))
    {
		param.op = 0;
		param.PARAMS.USB_PWR.pwrin = pwrin;
		param.PARAMS.USB_PWR.pwrout = pwrout;
		DeviceIoControl(hPMI, PMIC_IOCTL_CONVT_USB_SETPWR, &param, sizeof(param),
			&rc, sizeof(rc), NULL, NULL);
		if (rc == PMIC_SUCCESS)
		{
			convity.usbPowerIn  = pwrin;
			convity.usbPowerOut = pwrout;
		}
    }

    /* Exit the critical section. */
    LeaveCriticalSection(&mutex);
	EXIT_MSG;

    return rc;
}

/*!
 * Get the USB transceiver's current power supply configuration.
 *
 * @param       handle          device handle from open() call
 * @param       pwrin           USB transceiver regulator input power source
 * @param       pwrout          USB transceiver regulator output power level
 *
 * @return      PMIC_SUCCESS    if the USB transceiver's power supply
 *                              configuration was successfully retrieved
 */
PMIC_STATUS PmicConvityUsbGetPowerSource(
    const PMIC_CONVITY_HANDLE         handle,
    PMIC_CONVITY_USB_POWER_IN  *const pwrin,
    PMIC_CONVITY_USB_POWER_OUT *const pwrout)
{
    PMIC_STATUS rc = PMIC_ERROR;

	ENTRY_MSG;
    /* Use a critical section to maintain a consistent state. */
    EnterCriticalSection(&mutex);

    if ((handle == convity.handle)                   &&
        (convity.handleState == HANDLE_IN_USE)       &&
        (pwrin != (PMIC_CONVITY_USB_POWER_IN *)NULL) &&
        (pwrout != (PMIC_CONVITY_USB_POWER_OUT *)NULL))
    {
        *pwrin  = convity.usbPowerIn;
        *pwrout = convity.usbPowerOut;

        rc = PMIC_SUCCESS;
    }

    /* Exit the critical section. */
    LeaveCriticalSection(&mutex);
	EXIT_MSG;

    return rc;
}

/*!
 * Set the USB transceiver's operating mode.
 *
 * @param       handle          device handle from open() call
 * @param       mode            desired operating mode
 *
 * @return      PMIC_SUCCESS    if the USB transceiver's operating mode
 *                              was successfully configured
 */
PMIC_STATUS PmicConvityUsbSetXcvr(
    const PMIC_CONVITY_HANDLE               handle,
    const PMIC_CONVITY_USB_TRANSCEIVER_MODE mode)
{
    PMIC_STATUS rc = PMIC_ERROR;

	ENTRY_MSG;
    /* Use a critical section to maintain a consistent state. */
    EnterCriticalSection(&mutex);

    if ((handle == convity.handle) &&
        (convity.handleState == HANDLE_IN_USE))
    {
		param.op = 0;
		param.PARAMS.usbXcvrMode = mode;
		DeviceIoControl(hPMI, PMIC_IOCTL_CONVT_USB_SETXCVR, &param, sizeof(param),
			&rc, sizeof(rc), NULL, NULL);
        if (rc == PMIC_SUCCESS)
        {
            convity.usbXcvrMode = mode;
        }
    }

    /* Exit the critical section. */
    LeaveCriticalSection(&mutex);
	EXIT_MSG;

    return rc;
}

/*!
 * Get the USB transceiver's current operating mode.
 *
 * @param       handle          device handle from open() call
 * @param       mode            current operating mode
 *
 * @return      PMIC_SUCCESS    if the USB transceiver's operating mode
 *                              was successfully retrieved
 */
PMIC_STATUS PmicConvityUsbGetXcvr(
    const PMIC_CONVITY_HANDLE                handle,
    PMIC_CONVITY_USB_TRANSCEIVER_MODE *const mode)
{
    PMIC_STATUS rc = PMIC_ERROR;
	
	ENTRY_MSG;
    /* Use a critical section to maintain a consistent state. */
    EnterCriticalSection(&mutex);

    if ((handle == convity.handle)             &&
        (convity.handleState == HANDLE_IN_USE) &&
        (mode != (PMIC_CONVITY_USB_TRANSCEIVER_MODE *)NULL))
    {
        *mode = convity.usbXcvrMode;

        rc = PMIC_SUCCESS;
    }

    /* Exit the critical section. */
    LeaveCriticalSection(&mutex);
	EXIT_MSG;

    return rc;
}

/*!
 * Set the Data Line Pulse duration (in milliseconds) for the USB OTG
 * Session Request Protocol.
 *
 * For MC13783, the get/set DLP duration APIs are not supported.
 *
 * @param       handle          device handle from open() call
 * @param       duration        the data line pulse duration (ms)
 *
 * @return      PMIC_SUCCESS    if the pulse duration was successfully set
 */
PMIC_STATUS PmicConvityUsbOtgSetDlpDuration(
    const PMIC_CONVITY_HANDLE handle,
    const unsigned int        duration)
{
    PMIC_STATUS rc = PMIC_NOT_SUPPORTED;
	ENTRY_MSG;

    /* The DLP duration is not supported by the MC13783 PMIC hardware. */

    /* No critical section is required. */

    if ((handle != convity.handle) || (convity.handleState != HANDLE_IN_USE))
    {
        /* Must return error indication for invalid handle parameter to be
         * consistent with other APIs.
         */
        rc = PMIC_ERROR;
    }
	EXIT_MSG;

    return rc;
}


/*!
 * Get the current Data Line Pulse duration (in milliseconds) for the USB
 * OTG Session Request Protocol.
 *
 * @param       handle          device handle from open() call
 * @param       duration        the data line pulse duration (ms)
 *
 * @return      PMIC_SUCCESS    if the pulse duration was successfully obtained
 */
PMIC_STATUS PmicConvityUsbOtgGetDlpDuration(
    const PMIC_CONVITY_HANDLE handle,
    unsigned int *const       duration)
{
    PMIC_STATUS rc = PMIC_NOT_SUPPORTED;
	
	ENTRY_MSG;
    /* The DLP duration is not supported by the MC13783 PMIC hardware. */

    /* No critical section is required. */

    if ((handle != convity.handle) || (convity.handleState != HANDLE_IN_USE))
    {
        /* Must return error indication for invalid handle parameter to be
         * consistent with other APIs.
         */
        rc = PMIC_ERROR;
    }
	EXIT_MSG;

    return rc;
}


/*!
 * Explicitly start the USB OTG Host Negotiation Protocol (HNP) process.
 * This simply involves pulling the D+ line high for the "A" device
 * and disconnecting all pull-up and pull-down resistors for the "B"
 * device.
 *
 * Note that the pmic_convity_usb_otg_end_hnp() function must be called
 * after a suitable time has elapsed to complete the HNP process.
 *
 * @param       handle          device handle from open() call
 * @param       deviceType      the USB device type (either A or B)
 *
 * @return      PMIC_SUCCESS    if the HNP was successfully started
 */
PMIC_STATUS PmicConvityUsbOtgBeginHnp(
    const PMIC_CONVITY_HANDLE          handle,
    const PMIC_CONVITY_USB_DEVICE_TYPE deviceType)
{
    PMIC_STATUS rc = PMIC_ERROR;
	
	ENTRY_MSG;
    /* Use a critical section to maintain a consistent state. */
    EnterCriticalSection(&mutex);

    if ((handle == convity.handle) &&
        (convity.handleState == HANDLE_IN_USE))
    {
		param.op = 0;
		param.PARAMS.usbOtgType = deviceType;
 		DeviceIoControl(hPMI, PMIC_IOCTL_CONVT_USB_BGNHNP, &param, sizeof(param),
			&rc, sizeof(rc), NULL, NULL);
    }

    /* Exit the critical section. */
    LeaveCriticalSection(&mutex);
	EXIT_MSG;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -