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

📄 hwinit.c

📁 Freescale ARM11系列CPU MX31的WINCE 5.0下的BSP
💻 C
📖 第 1 页 / 共 4 页
字号:
//  Function: InitializeTransceiver
//
//  This function is to configure the USB Transceiver, register the interrupt
//
//  Parameters:
//     NULL
//     
//  Returns:
//     TRUE - success, FALSE - failure
//
//-----------------------------------------------------------------------------
BOOL InitializeTransceiver(PCSP_USB_REGS* regs, DWORD * phyregs, 
                           DWORD * sysintr, DWORD dwOTGSupport, TCHAR *pOTGGroup)
{
    DWORD dwRet=TRUE, speed, temp;
    int off, irq;
    WORD sel = 0;

     
    lstrcpy(gszOTGGroup, pOTGGroup);
    gdwOTGSupport = dwOTGSupport;

    dwRet =InitializeCPLD(&sel);
    speed=dwRet;
    gSel = sel;
    off=InitializeMux(dwRet, sel);  
    USBClockInit();
    
    if (speed==FULL_SPEED && sel==1) {
        ConfigH1(*regs);
        irq=IRQ_USB_HOST1;
    }
    else if (sel<2) {
        ConfigH2(*regs);
        irq = IRQ_USB_HOST2;
    }
    else {
        ConfigOTG(*regs, speed);
        irq = IRQ_USB_OTG;      
    }


     if (irq == IRQ_USB_OTG)
        *sysintr = SYSINTR_USBOTG;
    else
        KernelIoControl(IOCTL_HAL_REQUEST_SYSINTR, &irq, sizeof(DWORD), sysintr, sizeof(DWORD), NULL);      
    DEBUGMSG(1, (TEXT("InitializeTransceiver: IRQ=%d, sysIntr=%d\r\n"), irq, *sysintr));
        
    {    
        USB_CTRL_T ctrl;
        DWORD * temp=(DWORD *)&ctrl;
        
        *temp=0;
        ctrl.BPE=1;     //  Bypass Enable bit, clear it
        CLRREG32(&(*regs)->USB_CTRL, *temp);
    }
       
    {
        USB_USBMODE_T mode;
        DWORD * temp=(DWORD *)&mode;
        
        // Set USB Mode 
        *temp=0;
        mode.CM=3;      // Host 

 
        if (sel == 1)
            OUTREG32(&(*regs)->H1.USBMODE, *temp);
        else if (sel == 0)
            OUTREG32(&(*regs)->H2.USBMODE, *temp);
        else
            OUTREG32(&(*regs)->OTG.USBMODE, *temp);

	}


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

            if (hcs.PPC) 
            {
                USB_PORTSC_T portsc;
                DWORD * temp2= (DWORD *)&portsc;

                *temp2 = INREG32(&(*regs)->H2.PORTSC);
                portsc.PP = 1;
                SETREG32(&(*regs)->H2.PORTSC, *temp2);
            }   
        }
        else if (sel == 2)
        {
            DWORD *temp;
            USB_HCSPARAMS_T hcs;
            temp=(DWORD *)&hcs;
            *temp=INREG32(&(*regs)->OTG.HCSPARAMS);

            if (hcs.PPC) 
            {
                USB_PORTSC_T portsc;
                DWORD * temp2= (DWORD *)&portsc;

                *temp2 = INREG32(&(*regs)->OTG.PORTSC);
                portsc.PP = 1;
                SETREG32(&(*regs)->OTG.PORTSC, *temp2);
            }   
        }
        else if (speed==FULL_SPEED && sel==1)
        {
            DWORD *temp;
            USB_HCSPARAMS_T hcs;
            temp=(DWORD *)&hcs;
            *temp=INREG32(&(*regs)->H1.HCSPARAMS);

            if (hcs.PPC) 
            {
                USB_PORTSC_T portsc;
                DWORD * temp2= (DWORD *)&portsc;

                *temp2 = INREG32(&(*regs)->H1.PORTSC);
                portsc.PP = 1;
                SETREG32(&(*regs)->H1.PORTSC, *temp2);
            }   
        }

    }
    
    gRegs = (PCSP_USB_REGS)(*regs);
    gSel = sel;
        
    if (sel==2 && speed==FULL_SPEED)
    {
        DEBUGMSG (1, (TEXT("Initialize1301\r\n")));
        dwRet=Initialize1301(*regs);
    }
    else
    {
    if (speed==FULL_SPEED)
        {
            DEBUGMSG(1, (TEXT("Initialize1105 FullSpeed\r\n")));
            dwRet=Initialize1105();
        }
        else if (sel == 0)
        {
            DEBUGMSG(1, (TEXT("Initialize1504 H2 HighSpeed\r\n")));
            dwRet=Initialize1504(*regs, sel);
        }
    else
        {
            DEBUGMSG(1, (TEXT("Initialize1504 OTG HighSpeed\r\n")));
            dwRet=Initialize1504(*regs,sel);
        }
    }

    temp=*(DWORD*)regs;
    temp+=off;
    *(DWORD*)regs=temp;
    *phyregs+=off;
    return dwRet;
}

//-----------------------------------------------------------------------------
//
//  Function:  BSPUsbCheckConfigPower
//
//  Check power required by specific device configuration and return whether it
//  can be supported on this platform.  For CEPC, this is trivial, just limit
//  to the 500mA requirement of USB.  For battery powered devices, this could
//  be more sophisticated, taking into account current battery status or other 
//  info.
//
// Parameters:
//      bPort
//          [in] Port number
//
//      dwCfgPower
//          [in] Power required by configuration in mA.
//
//      dwTotalPower
//          [in] Total power currently in use on port in mA.
//
// Returns:
//      Return TRUE if configuration can be supported, FALSE if not.
//
//-----------------------------------------------------------------------------
BOOL BSPUsbhCheckConfigPower(UCHAR bPort, DWORD dwCfgPower, DWORD dwTotalPower)
{
    return ((dwCfgPower + dwTotalPower) > 100) ? FALSE : TRUE;
}

#ifdef DISABLE_DETACH_WAKEUP
#undef DISABLE_DETACH_WAKEUP
#endif
 //-----------------------------------------------------------------------------
//
//  Function: BSPUsbSetWakeUp
//
//  This function is to enable/disable the wakeup interrupt bit in USBCONTROL
//
//  Parameters:
//     bEnable - TRUE : Enable, FALSE : Disable
//     
//  Returns:
//     NULL
//
//-----------------------------------------------------------------------------
void BSPUsbSetWakeUp(BOOL bEnable)
{
    // Access the USB Control Register
    volatile DWORD  *temp;
    USB_CTRL_T ctrl;
    USB_PORTSC_T portsc;
    CSP_USB_REG *pReg; 

    // still need to check it first before proceed
    BSPUsbCheckWakeUp();
        
    switch (gSel) 
	{
    case 0:
        pReg = (PCSP_USB_REG)(&(gRegs->H2));
        break;
    case 1:
        pReg = (PCSP_USB_REG)(&(gRegs->H1));
        break;
    
    default:
        pReg = (PCSP_USB_REG)(&(gRegs->OTG));
        break;
    }
    temp = (DWORD *)&portsc;
    *temp = INREG32(&pReg->PORTSC[0]);
    // If Current Connect Status = 1, we should not set WKCN or it would 
    // wake up right away.  With this we can enable wake up on attach
    if ((bEnable) && (portsc.CCS == 0))
    {
        portsc.WKCN = 1;
        portsc.WKOC = 1;
        portsc.WKDC = 0;        
    }
    else
    {
        portsc.WKOC = 0;
        portsc.WKDC = 0;
        portsc.WKCN = 0;
    }
    OUTREG32(&pReg->PORTSC[0], *temp);
    
    temp = (DWORD *)&ctrl;
#ifdef DISABLE_DETACH_WAKEUP
    if (bEnable)
#else
    if ((bEnable) && (portsc.CCS == 0))
#endif
        *temp = INREG32(&gRegs->USB_CTRL);
    else
        *temp = 0;

    switch (gSel)
	{
    case 0:     
        ctrl.H2WIE = 1;
        ctrl.H2UIE = 1;
        break;
    case 1:
        ctrl.H1WIE = 1;     
        break;
    case 2:
        ctrl.OWIE = 1;
        ctrl.OUIE = 1;
        break;
    default:
        break;
    }

#ifdef DISABLE_DETACH_WAKEUP
    if (bEnable)
#else
    if ((bEnable) && (portsc.CCS == 0))
#endif
        SETREG32(&gRegs->USB_CTRL, *temp);
    else
        CLRREG32(&gRegs->USB_CTRL, *temp);

     return;
}

//-----------------------------------------------------------------------------
//
//  Function: BSPUsbCheckWakeUp
//
//  This function is called by CSP to clear the wakeup interrupt bit in USBCONTROL. According to
//  MX31 specification, disable the wake-up enable bit also clear the interrupt request bit.
//  This wake-up interrupt enable should be disable after receiving a wakeup request.
//
//  Parameters:
//     NULL
//     
//  Returns:
//     TRUE - there is a wakeup.  FALSE - no wakeup is set.
//
//-----------------------------------------------------------------------------

BOOL BSPUsbCheckWakeUp(void)
{
    // Access the USB Control Register
    volatile DWORD  *temp;
    USB_CTRL_T ctrl;
    BOOL fWakeUp = FALSE;

    temp = (DWORD *)&ctrl;
    *temp = INREG32(&gRegs->USB_CTRL);

 
    switch (gSel) {
    case 0:
        if (ctrl.H2WIR == 1)
        {
            *temp = 0;
            fWakeUp = TRUE;
            ctrl.H2WIE = 1;
        }
        break;
    case 1:
        if (ctrl.H1WIR == 1)
        {
            *temp = 0;
            fWakeUp = TRUE;
            ctrl.H1WIE = 1;
        }
        break;
    case 2:
        if (ctrl.OWIR == 1)
        {
            *temp = 0;
            fWakeUp = TRUE;
            ctrl.OWIE = 1;
        }
        break;
    default:
        break;
    }

    if (fWakeUp)
        CLRREG32(&gRegs->USB_CTRL, *temp);  

     return fWakeUp;
}


⌨️ 快捷键说明

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