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

📄 usbinit.c

📁 u-boot-1.1.6 for mini2440开发板。 支持网络下载
💻 C
📖 第 1 页 / 共 2 页
字号:
	//for(i=0; i<7; i++);
	//ChangeClockDivider(13,12);
	//ChangeMPllValue(97,1,2);		//296Mhz

	Isr_Init();


	gpioregs->MISCCR=gpioregs->MISCCR&~(1<<3); // USBD is selected instead of USBH1 
	gpioregs->MISCCR=gpioregs->MISCCR&~(1<<13); // USB port 1 is enabled.

//
//  USBD should be initialized first of all.
//
	isUsbdSetConfiguration=0;

#if 0
	UsbdMain(); 
	MMU_Init(); //MMU should be reconfigured or turned off for the debugger, 
	//After downloading, MMU should be turned off for the MMU based program,such as WinCE.	
#else
//mike.arm9    MMU_EnableICache();  
	UsbdMain(); 
    udelay(100000);
    gpioregs->GPGDAT |= (1<<12);  /* enable USB Device, mike.arm9 */
    gpioregs->GPBDAT |= (1<<9);   /* enable USB Device, mike.arm9 */
    gpioregs->GPCDAT |= (1<<5);   /* enable USB Device, mike.arm9 */
#endif

#if USBDMA
	mode="DMA";
#else
	mode="Int";
#endif

	// CLKOUT0/1 select.
	//printf("CLKOUT0:MPLL in, CLKOUT1:RTC clock.\n");
	//Clk0_Enable(0);	// 0:MPLLin, 1:UPLL, 2:FCLK, 3:HCLK, 4:PCLK, 5:DCLK0
	//Clk1_Enable(2);	// 0:MPLLout, 1:UPLL, 2:RTC, 3:HCLK, 4:PCLK, 5:DCLK1	
//	Clk0_Disable();
//	Clk1_Disable();
	
	mpll_val = clk_powerregs->MPLLCON;
	upll_val = clk_powerregs->UPLLCON; 


    if (1) //(!bBootFrmNORFlash())
    {
    	printf("UPLLVal [M:%xh,P:%xh,S:%xh]\n", (upll_val&(0xff<<12))>>12,(upll_val&(0x3f<<4))>>4,(upll_val&0x3));
    	printf("MPLLVal [M:%xh,P:%xh,S:%xh]\n", (mpll_val&(0xff<<12))>>12,(mpll_val&(0x3f<<4))>>4,(mpll_val&0x3));
    	printf("CLKDIVN:%xh\n", clk_powerregs->CLKDIVN);

    	printf("\n\n");
    	printf("+---------------------------------------------+\n");
    	printf("| S3C2440A USB Downloader ver R0.03 2004 Jan  |\n");
    	printf("+---------------------------------------------+\n");
    //	printf("FCLK=%4.1fMHz,%s mode\n",FCLK/1000000.,mode); 
    	printf("USB: IN_ENDPOINT:1 OUT_ENDPOINT:3\n"); 
    	printf("FORMAT: <ADDR(DATA):4>+<SIZE(n+10):4>+<DATA:n>+<CS:2>\n");
    	printf("NOTE: Power off/on or press the reset button for 1 sec\n");
    	printf("      in order to get a valid USB device address.\n");
    	printf("\n");
    }
	download_run=0; //The default menu is the Download & Run mode.

//	WaitDownload();    

}


//void WaitDownload(void)
__u32 usb_receive(char *buf, size_t len, U32 wait)
{
    int first=1;
    U8 tempMem[16];
    U32 j;
    unsigned int dwRecvTimeSec = 0;
	char c;

    dwUSBBufReadPtr = dwUSBBufBase; // USB_BUF_BASE; mike.arm9, 2006.06.21
    dwUSBBufWritePtr = dwUSBBufBase; // USB_BUF_BASE; mike.arm9, 2006.06.21
    bDMAPending = 0;

    /* add by mike.arm9 */
    tempDownloadAddress = dwUSBBufBase; // USB_BUF_BASE; mike.arm9, 2006.06.21 // RAM_BASE, changed by mike.arm9 for wince, 2006.06.18

    downloadAddress=(U32)tempMem; //_RAM_STARTADDRESS; 
    downPt=(unsigned char *)downloadAddress;
	//This address is used for receiving first 8 byte.
    downloadFileSize=0;
    

    /*******************************/
    /*    File download    */
    /*******************************/
    if(isUsbdSetConfiguration==0)
    {
	    printf("USB host is not connected yet.\n");
    }

    while(downloadFileSize==0) /* wait until send a file */
    {
        if(first==1 && isUsbdSetConfiguration!=0)
        {
            printf("USB host is connected. Waiting a download.\n");
            first=0;
        }
		c = awaitkey(1, 0);
		if ((c & 0x7f) == INTR)
		{
			printf("Cancelled by user\n");
			return 0;
		}
    }

    /* add by mike.arm9 */
    if (downloadFileSize - 10 > len)
    {
        printf("Length of file is too big : %d > %d\n", downloadFileSize - 10, len);
        return 0;
    }
    
    Timer_InitEx();
    Timer_StartEx();
        
#if USBDMA    

    intregs->INTMSK&=~(BIT_DMA2);  

    ClearEp3OutPktReady(); 
    	// indicate the first packit is processed.
    	// has been delayed for DMA2 cofiguration.

    if(downloadFileSize>EP3_PKT_SIZE)
    {
        if(downloadFileSize - EP3_PKT_SIZE<=(0x80000))
        {
            /* set the source and length */
            dwUSBBufWritePtr = downloadAddress + EP3_PKT_SIZE-8;
            dwWillDMACnt = downloadFileSize - EP3_PKT_SIZE;
	    }
      	else
      	{
            dwUSBBufWritePtr = downloadAddress + EP3_PKT_SIZE - 8;
            // dwWillDMACnt = 0x80000 - EP3_PKT_SIZE;
            
            /* Changed by mike.arm9, 2006.06.22
             * We want When the first DMA interrupt happened, 
             * it has received (0x80000 + 8) bytes data from PC
             * The format of data PC send out is: <ADDR(DATA):4>+<SIZE(n+10):4>+<DATA:n>+<CS:2>
             * So, the first 8 bytes isn't the real data we want
             * We want the dwUSBBufWritePtr is always 0x80000 aligin
             */
            dwWillDMACnt = 0x80000 + 8 - EP3_PKT_SIZE;
    	}
     	totalDmaCount = 0;
  	    ConfigEp3DmaMode(dwUSBBufWritePtr, dwWillDMACnt);
    }
    else
    {
        dwUSBBufWritePtr = downloadAddress + downloadFileSize - 8;
	    totalDmaCount = downloadFileSize;
    }
#endif

    printf("\nNow, Downloading [ADDRESS:%xh,TOTAL:%d]\n",
    		downloadAddress,downloadFileSize);

    if (wait)
    {
        printf("RECEIVED FILE SIZE:%8d",0);

        j = totalDmaCount + 0x10000;
        while (totalDmaCount != downloadFileSize)
        {
            if (totalDmaCount > j)
            {
        	    printf("\b\b\b\b\b\b\b\b%8d", j);
                j = totalDmaCount + 0x10000;
            }
        }
	    printf("\b\b\b\b\b\b\b\b%8d ", totalDmaCount);
        dwRecvTimeSec = Timer_StopEx();
        if (dwRecvTimeSec == 0)
        {
            dwRecvTimeSec = 1;
        }
        printf("(%dKB/S, %dS)\n", (downloadFileSize/dwRecvTimeSec/1024), dwRecvTimeSec);
    }

    return downloadFileSize - 10;

}


void HaltUndef(void)
{
	printf("Undefined instruction exception!!!\n");
	while(1);
}

void HaltSwi(void)
{
	printf("SWI exception!!!\n");
	while(1);
}

void HaltPabort(void)
{
	printf("Pabort exception!!!\n");
	while(1);
}

void HaltDabort(void)
{
	printf("Dabort exception!!!\n");
	while(1);
}

void Clk0_Enable(int clock_sel)	
{	// 0:MPLLin, 1:UPLL, 2:FCLK, 3:HCLK, 4:PCLK, 5:DCLK0
	gpioregs->MISCCR = gpioregs->MISCCR&~(7<<4) | (clock_sel<<4);
	gpioregs->GPHCON = gpioregs->GPHCON&~(3<<18) | (2<<18);
}
void Clk1_Enable(int clock_sel)
{	// 0:MPLLout, 1:UPLL, 2:RTC, 3:HCLK, 4:PCLK, 5:DCLK1	
	gpioregs->MISCCR = gpioregs->MISCCR&~(7<<8) | (clock_sel<<8);
	gpioregs->GPHCON = gpioregs->GPHCON&~(3<<20) | (2<<20);
}
void Clk0_Disable(void)
{
	gpioregs->GPHCON = gpioregs->GPHCON&~(3<<18);	// GPH9 Input
}
void Clk1_Disable(void)
{
	gpioregs->GPHCON = gpioregs->GPHCON&~(3<<20);	// GPH10 Input
}

⌨️ 快捷键说明

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