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

📄 isp1504.c

📁 Freescale ARM11系列CPU MX31的WINCE 5.0下的BSP
💻 C
字号:
/*---------------------------------------------------------------------------
* Copyright (C) 2005-2006, Freescale Semiconductor, Inc. All Rights Reserved.
* THIS SOURCE CODE, AND ITS USE AND DISTRIBUTION, IS SUBJECT TO THE TERMS
* AND CONDITIONS OF THE APPLICABLE LICENSE AGREEMENT 
*--------------------------------------------------------------------------*/

 
/*
 *  File:     Isp1504.c
 *  Purpose:  Platform-specific host transceiver configuration
 *            Interrupt, USB signal pull-up, and Vbus driving configuration
 *
 *  Functions:  
 *              Initialize1504 - initial set up for host mode
 *              SetULPIHostMode - change those parts for swapping to host 
 *                                from client mode
 */              

#include <windows.h>
#include <Winbase.h>
#include <ceddk.h>
#include "bsp.h"
#include "mx31_usbcommon.h"

//-----------------------------------------------------------------------------
//
//  Function: Initialize1504
//
//  This function is to configure the ISP1504 transceiver and corresponding 
//  USB OTG Core. This function is called by InitializeTransceiver in hwinit.c
//
//  Parameters:
//     regs - Pointer to the 3 USB Core registers.
//     
//  Returns:
//     TRUE - success, FALSE - failure
//
//-----------------------------------------------------------------------------

BOOL Initialize1504(CSP_USB_REGS * regs, WORD sel)
{
//          
        DWORD * temp;
        volatile DWORD * view_port;

        if (sel == 0)
        {
            USB_HCSPARAMS_T hcs;
            temp=(DWORD *)&hcs;
            *temp=INREG32(&regs->H2.HCSPARAMS);

            if (hcs.PPC) {
                USB_PORTSC_T portsc;
                temp=(DWORD *)&portsc;
                *temp=0;
                portsc.CSC=1; portsc.PEC=1; portsc.OCC=1;
                *temp=(~*(temp))&INREG32(&regs->H2.PORTSC);

                
                SETREG32(&regs->H2.PORTSC, *temp);
            }

            //DumpRegs((CSP_USB_REG *)&regs->H2);
            view_port = &regs->H2.ULPI_VIEWPORT;

        }                   
        else if (sel == 2)
        {
            USB_HCSPARAMS_T hcs;
            temp=(DWORD *)&hcs;
            *temp=INREG32(&regs->OTG.HCSPARAMS);

            if (hcs.PPC) {
            USB_PORTSC_T portsc;
            temp=(DWORD *)&portsc;
            *temp=0;
                portsc.CSC=1; portsc.PEC=1; portsc.OCC=1;portsc.WKOC=1; portsc.WKDC=1; portsc.WKCN=1;
                *temp=(~*(temp))&INREG32(&regs->OTG.PORTSC);
                
                
                SETREG32(&regs->OTG.PORTSC, *temp);
            }

            //DumpRegs((CSP_USB_REG *)&regs->OTG);
            view_port = &regs->OTG.ULPI_VIEWPORT;
        }   

        DEBUGMSG(1, (TEXT("Access PHY set to host mode - USBHOST\r\n")));
        // Execute reset
        ISP1504_WriteReg(view_port, ISP1504_FUNCTION_CTRL_S, 0x20);

        ISP1504_WriteReg(view_port, ISP1504_OTG_CTRL_S, 0x1); // ID_PULLUP      
        // enable external vbus supply
        // onboard power supply MC13783 feeds through MAX4787 current limit switch
        ISP1504_WriteReg(view_port, ISP1504_OTG_CTRL_S, 0x40); // DRV_VBUS_EXT

        // disable vbus (internal)
        // use external VBus power supply from MC17383 DC-DC converter
        ISP1504_WriteReg(view_port, ISP1504_OTG_CTRL_S, 0x20); // DRV_VBUS

        // enable external vbus (fault) indicator
        // use MAX4787 fault flag to indicate over current condition
        ISP1504_WriteReg(view_port, ISP1504_OTG_CTRL_S, 0x80); // USE_EXT_VBUS_IND

        ISP1504_WriteReg(view_port, ISP1504_OTG_CTRL_S, 0x10); // VBus Charge


    return TRUE;
}

//-----------------------------------------------------------------------------
//
//  Function: SetULPIToHostMode
//
//  This function is called by CSP public module to configure the ULPI to host
//  mode before putting the ULPI to suspend mode or after resume.
//
//  Parameters:
//     pRegs - Pointer to the 3 USB Core registers.
//     pSel - USB Core to be configured. 
//     fSuspend - Suspend or resume
//     
//  Returns:
//     NONE
//
//-----------------------------------------------------------------------------

void SetULPIHostMode(PCSP_USB_REGS pRegs, WORD pSel, BOOL fSuspend)
{
    volatile DWORD * view_port;
    DEBUGMSG (1, (TEXT("SetULPIHostMode sel = %d\r\n"),pSel));
    if (pSel == 0)
        view_port = &pRegs->H2.ULPI_VIEWPORT;
    else if (pSel == 2)
        view_port = &pRegs->OTG.ULPI_VIEWPORT;
    else
        return;

    DEBUGMSG (1, (TEXT("Dump USBCTRL = 0x%x\r\n"), INREG32(&pRegs->USB_CTRL)));
    if (fSuspend)
    {
        ISP1504_WriteReg(view_port, ISP1504_FUNCTION_CTRL_C, 0x3); // Clear the XCVRSELECT
        ISP1504_WriteReg(view_port, ISP1504_FUNCTION_CTRL_S, 0x1); // Set the XCVRSELECT

        ISP1504_WriteReg(view_port, ISP1504_FUNCTION_CTRL_S, 0x4); // Set the TERM SELECT

        ISP1504_WriteReg(view_port, ISP1504_FUNCTION_CTRL_C, 0x18); // Set the OPMODE = 00

        ISP1504_WriteReg(view_port, ISP1504_OTG_CTRL_S, 0x2); // DP_PULL_DOWN

        ISP1504_WriteReg(view_port, ISP1504_OTG_CTRL_S, 0x4); // DM_PULL_DOWN

    }
    else
    {
        ISP1504_WriteReg(view_port, ISP1504_FUNCTION_CTRL_S, 0x20);

        ISP1504_WriteReg(view_port, ISP1504_OTG_CTRL_S, 0x1); // ID_PULLUP      
        // enable external vbus supply
        // onboard power supply MC13783 feeds through MAX4787 current limit switch
        ISP1504_WriteReg(view_port, ISP1504_OTG_CTRL_S, 0x40); // DRV_VBUS_EXT

        // disable vbus (internal)
        // use external VBus power supply from MC17383 DC-DC converter
        ISP1504_WriteReg(view_port, ISP1504_OTG_CTRL_S, 0x20); // DRV_VBUS

        // enable external vbus (fault) indicator
        // use MAX4787 fault flag to indicate over current condition
        ISP1504_WriteReg(view_port, ISP1504_OTG_CTRL_S, 0x80); // USE_EXT_VBUS_IND

        ISP1504_WriteReg(view_port, ISP1504_OTG_CTRL_S, 0x10); // VBus Charge
    }
}



⌨️ 快捷键说明

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