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

📄 2460mon_otg.cpp.bak

📁 三星 S3C2460 USB OTG监控代码
💻 BAK
字号:
/**
* Project Name : S3C2460 verification project
*
* Copyright 2004 by Samsung Electronics, Inc.
* All rights reserved.
*
* Project Description :
* This software is only for verifying functions of the S3C2460. 
* Anybody can use this code without our permission.
*/

/**
* File Name    : 2460mon_otg.cpp
* Description  : S3C2460 USB OTG monitor main code
* Author       : Haksoo Kim
* Dept         : Mobile solution, AP
* Created Date : 2005.06.02
* Version      : 1.0
* History
*   R1.0 (2005.06.02): First Release
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "Option.h"
#include "Console.h"

#include "2460addr.h"
#include "2460lib.h"
#include "2460slib.h"
#include "mmu.h"
#include "profile.h"
#include "memtest.h"

#include "PLL.h"

#include "nand.h"

#include "usb_otg_dev_main.h"
#include "usb_otg_dev_out.h"
#include "usb_otg_dev_lib.h"
#include "2460usb_otg_dev.h"
#include "usb_otg.h"
#include "otg_xvr_isp1301.h"

void Isr_Init(void);
void Check_SleepKey(void);
void Clear_SleepKey(void);


void Lcd_Off(void);
void Usb_On(void);
void Usb_Off(void);
void WaitDownload(void);
void Menu(void);

#define	OS_START_ADDR_OFFSET (0x00200000)
#define DOWNLOAD_ADDRESS (_RAM_STARTADDRESS+OS_START_ADDR_OFFSET)

volatile unsigned int downloadAddress;

void (*restart)(void)=(void (*)(void))0x0;
void (*run)(void);


volatile unsigned char *downPt;
volatile unsigned int downloadFileSize;
volatile unsigned short checkSum;
volatile unsigned int err=0;
#if USBOTG_DMA
volatile unsigned int totalRxCountInDMA=0;
#endif

volatile int isUsbOtgSetConfiguration;

int download_run=0;
unsigned int tempDownloadAddress;
int menuUsed=0;
int first=1;

extern char Image$$RW$$Limit[];
unsigned int *pMagicNum=(unsigned int *)Image$$RW$$Limit;


int main(void)
{
    float	mpll,armclk,hclk,pclk;
    char	armdiv,hdiv,pdiv;
    uint32	i;
    
	GlobalCLK();

	Init_LogicalConsole();
	Init_LED();

   	Isr_Init();

	rCLKSRCCON	|=	(1<<5);
	rCLKDIVCON	=	rCLKDIVCON | (1<<12);	// USB 48 Div on
	SetUPLL( 72, 3, 1);

	//* initialize ISP1301
	//ISP1301_Init_DeviceMode();
	
	USBOTG_Port_Init();
	
	/* emulate disconnection */
	ISP1301_IIC_Write(OTG_XVR_ISP1301_ADDR,ISP1301_OTG_CTRL_CLR,0x03);	//DP,DM pull-up resistor disable
	for(i=0;i<0x1000;)i++;
	
	isUsbOtgSetConfiguration=0;
	
	#if 0
	{
		uint32 *otg_addr=(uint32 *)0x41944200;
		
		printf("\n==============================================\n");
		for(;otg_addr<(uint32 *)0x41944308;otg_addr++)
			printf("=    ADDR=0x%08x : VALUE = 0x%08x    =\n",otg_addr,*otg_addr);
		printf("==============================================\n");
	}
	#endif
	
	//* initialize ISP1301
	ISP1301_Init_DeviceMode();
   	
  #if (ONLY_ICACHE_ENABLED == TRUE)
   	MMU_EnableICache();
  #else
  	MMU_Init();
  #endif
	
	UsbOtgDevMain();
	 
   #if USBOTG_DMA
   	
   	if(rDSTAT2 & (1<<20))
		rDMASKTRIG2 |= (1<<2);
	
	for(i=0;i<0x1000;)
		i++;
    
   #endif
	
	ConfigEp3IntMode();
	

    Delay(0);  //calibrate Delay()

    pISR_SWI=(_ISR_STARTADDRESS+0xf0);    //for pSOS

    Led_Display(0x6);
   
	mpll = (float)MPLL/1000000;
	armclk = (float)ARMCLK/1000000;
	hclk = (float)HCLK/1000000;
	pclk = (float)PCLK/1000000;
	armdiv = ARMCLKdiv+1;
	hdiv = armdiv*(HCLKdiv+1);
	pdiv = hdiv*(PCLKdiv+1);	
	
   	printf("\n\n");
   	#if USBOTG_DMA
   	printf("+-------------------------------------------------+\n");
   	printf("| S3C2460A USB OTG Downloader ver R1.0 (DMA Mode) |\n");
   	printf("+-------------------------------------------------+\n");
   	#else
   	printf("+-------------------------------------------------------+\n");
   	printf("| S3C2460A USB OTG Downloader ver R1.0 (Interrupt Mode) |\n"); 
   	printf("+-------------------------------------------------------+\n");  	
   	#endif
   	printf("MPLL=%.2fMHz, ARMCLK=%.2fMHz (%d:%d:%d), HCLK=%.2fMHz, PCLK=%.2fMHz\n\n",mpll,armclk,armdiv,hdiv,pdiv,hclk,pclk);
   	
   	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: 1. Power off/on or press the reset button for 1 sec\n");
   	printf("         in order to get a valid USB device address.\n");
   	printf("      2. For additional menu, Press any key. \n");
    
    printf("(Bulk Max Packet Size is %3dbytes)\n",OTG_BULK_PKT_SIZE);
   	printf("\n");
    
		
	/*******************************/
	/*		Cause of Boot-up	   */
	/*******************************/
//    Check_SleepKey(); // Check the cause of Boot-up(Watchdog /Soft Reset / Power on reset / Sleep wakeup.....) 
   
    download_run=1; //The default menu is the Download & Run mode.

    while(1)
    {
    	if(menuUsed==1)Menu();
    	WaitDownload();    
    }

}

void Menu(void)
{
    int i;
	int key;
    menuUsed=1;
    while(1)
    {
		printf("\n###### Select Menu ######\n");
		printf(" [0] Download & Run\n");
		printf(" [1] Download Only\n");
		printf(" [2] Test SDRAM \n");
		printf(" [3] Change The Console UART Ch.\n");
		printf(" [4] Run DSP\n");
        printf(" [5] Clear SDRAM.\n");
		printf(" [6] Run test program again.\n");
		printf("\t(Note! Effective only when pressing a reset button without power-off.\n");
		//* temporary code for otg xvr test
		printf(" [7] Read all registers of ISP1301.\n");

		key=getchar();

		switch(key)
		{
	        case '0':
	            printf("\nDownload&Run is selected.\n\n");
	            download_run=1;
	            return;
	        case '1':
	            printf("\nDownload Only is selected.\n");
	            printf("Enter a new temporary download address(0x1...):");
	            tempDownloadAddress=GetIntNum();
	            download_run=0;
	            printf("The temporary download address is 0x%x.\n\n",tempDownloadAddress);
	            return;
			case '2':
	            printf("\nMemory Test is selected.\n");        
		    	MemoryTest();
		    	Menu();
			    return;
	            break;
	        case '3':
	            Test_K9S1208();
	            printf("\nFlash Write Ends.\n");
			    rINTMSK&=~(BIT_USB);  
	   			rINTSUBMSK&=~(BIT_SUB_USBD);
	            break;

			case '4':
				rARM2DSP_CTRL	&=	~(0x8);
				i=HCLK;
				printf("\nSelect the frequency of DSPCLK\n");
				printf("[0] HCLK (%dMHz)      [1] HCLK/2 (%dMHz)\n",i/1000000,i/2000000);
				
				if (getchar()=='1') {
					rCLKDIVCON	|=	0x8;
					i/=2;
				} else {
					rCLKDIVCON	&=	~(0x8);
				}
				printf("\nNow run the TeakDSP @%dMHz !!!\n",i);
				
				rARM2DSP_CTRL	|=	0x8;
				break;
			
			case '5':
				printf("\nMemory Clear is selected.\n");
				ClearMemory();
				break;
				
			case '6':
			  #if (WHICH_PORT==1)
				run=(void (*)(void))0x10200000;
			  #else
				run=(void (*)(void))0x20200000;
			  #endif
				run();
				break;
			
			case '7':
				ISP1301_IIC_FullRead();
				break;
				
			default:
				break;
		}	
  	}	  
}

void WaitDownload(void)
{
	unsigned int i;
	unsigned int j;
	unsigned short cs;
	unsigned int temp;
	unsigned short dnCS;
	float time;
	unsigned char tempMem[16];
	unsigned char key;

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

#if 0
	MMU_DisableICache(); 
	    //For multi-ICE. 
	    //If ICache is not turned-off, debugging is started with ICache-on.
#endif

	/*******************************/
	/*    Test program download    */
	/*******************************/
	j=0;

	UsbOtgDevMain(); 
	ConfigEp3IntMode();
  #if USBOTG_DMA
	totalRxCountInDMA = 0;
  #endif

	if(isUsbOtgSetConfiguration==0)
	{
		printf("USB OTG is not connected yet with DNW.\n");	
		
	}
    
    while(downloadFileSize==0)
    {
		if(first==1 && isUsbOtgSetConfiguration!=0)
        {
            printf("USB OTG is connected with DNW. Waiting a download.\n");
			
		    //->
		    //khs.050117
		    //	added for debug
		   #ifdef KHS_USBD_DEBUG
		   	if(first == 1)
		   	{
			    printf("\nIf you want to check USB OTG enumeration sequence, press 'y/Y' key\n");
			    printf(" Otherwise, press any key except 'y/Y'\n");
			    while(!(temp = Uart_GetKey()));
			    if((temp=='y') || (temp=='Y'))
			    {
			    	extern Usbd_Ep0_Data_s Usbd_Ep0_Data[100];
					extern unsigned char count_Ep0_Data; 
					int i;
					if(count_Ep0_Data != 0)
					{
						for(i=0;i<count_Ep0_Data;i++)
						{
							if(Usbd_Ep0_Data[i].direction==0)
							{
								printf("\n\n[RX at state:%2d : ",Usbd_Ep0_Data[i].state);
							}else
							{
								printf("\n [TX at state:%2d : ",Usbd_Ep0_Data[i].state);
							}
							for(j=0;j<Usbd_Ep0_Data[i].cnt;j++)
								printf("0x%02x ",Usbd_Ep0_Data[i].data[j]);
						}
						count_Ep0_Data=0;
					}
			    	printf("\n\n");
			    }
	   			printf("\nAnd then, If you want to see menu, Press any key. \n");
	   		}
		   #endif
		    //<-  	
		    
	     	first=0;
        }
       
		if(j%0x100000==0)Led_Display(0x6);
		if(j%0x100000==0x80000)Led_Display(0x9);
		j++;

		key=Uart_GetKey();

		if(key!=0)
		{			
	    	Menu();
			//first=1; //To display the message,"USB host ...."
		}
    }

    Timer_InitEx();      
    Timer_StartEx();   

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

#if USBOTG_DMA    
    j=0x10000;

    while(1)
    {
    	if(totalRxCountInDMA>=j)
		{
	    	printf("\b\b\b\b\b\b\b\b%8d",j);
   	    	j+=0x10000;
		}
		if(totalRxCountInDMA>=downloadFileSize)
		{
			break;
		}
    }

#else

    j=0x10000;


    while(((unsigned int)downPt-downloadAddress)<(downloadFileSize-8))
    {
		if( ((unsigned int)downPt-downloadAddress)>=j)
		{
		    printf("\b\b\b\b\b\b\b\b%8d",j);
	   	    j+=0x10000;
		}
    }
#endif    

    time=Timer_StopEx();
    
    printf("\b\b\b\b\b\b\b\b%8d",downloadFileSize);	
    printf("(%5.1fKB/S,%3.1fS)\n",(float)(downloadFileSize/time/1024.),time);
    
    /*******************************/
    /*     Verify check sum        */
    /*******************************/

    printf("Now, Checksum calculation\n");

    cs=0;    
    i=(downloadAddress);
    j=(downloadAddress+downloadFileSize-10)&0xfffffffc;
    
    while(i<j)
    {    		
    	temp=*((unsigned int *)i);
    	i+=4;
    	cs+=(unsigned short)(temp&0xff);
    	cs+=(unsigned short)((temp&0xff00)>>8);
    	cs+=(unsigned short)((temp&0xff0000)>>16);
    	cs+=(unsigned short)((temp&0xff000000)>>24);
    }

    i=(downloadAddress+downloadFileSize-10)&0xfffffffc;
    j=(downloadAddress+downloadFileSize-10);
    while(i<j)
    {
  		cs+=*((unsigned char *)i++);
    }
    
    checkSum=cs;

    dnCS=*((unsigned char *)(downloadAddress+downloadFileSize-8-2))+
	(*( (unsigned char *)(downloadAddress+downloadFileSize-8-1) )<<8);

	printf("\nChecksum Value => MEM:%x DN:%x\n\n",checkSum,dnCS);
    
    if(checkSum!=dnCS)
    {
		printf("Checksum Error!!!");
		//return;
    }
    else
    {
	    printf("Download O.K.\n\n");
	}


    if(download_run==1)
    {
        rINTMSK=BIT_ALLMSK;
    	run=(void (*)(void))downloadAddress;
   
	  #if (ONLY_ICACHE_ENABLED == TRUE)
    	MMU_DisableICache();
      
      #else    
	    MMU_DisableDCache();
	    MMU_DisableICache();
	    for(i=0;i<4;i++)
	    	for(j=0;j<128;j++)
	    	    MMU_CleanInvalidateDCacheSET((i<<30)|(j<<5));
	    MMU_InvalidateICache();
	    
	    MMU_DisableMMU();
	    MMU_InvalidateTLB();
	  #endif
	  
		Delay(0);
		run();
    }
}


void Isr_Init(void)
{
    pISR_UNDEF=(unsigned)HaltUndef;
    pISR_SWI  =(unsigned)HaltSwi;
    pISR_PABORT=(unsigned)HaltPabort;
    pISR_DABORT=(unsigned)HaltDabort;
	pISR_IRQ	=	(unsigned)IsrIRQ;

    rINTMOD=0x0;	  // All=IRQ mode
    rINTMSK=BIT_ALLMSK;	  // All interrupt is masked.
    rINTSUBMSK=BIT_ALLMSK;
    rINTSUBMSK2=BIT_ALLMSK;

    //pISR_URXD0=(unsigned)Uart0_RxInt;	
    //rINTMSK=~(BIT_URXD0);   //enable UART0 RX Default value=0xffffffff

#if 1
    pISR_USB =(unsigned)IsrUsbOtgDev;
   #if USBOTG_DMA
    pISR_DMA_SBUS =(unsigned)IsrOtgDma2;
   #endif
#else
    pISR_IRQ =(unsigned)IsrUsbOtgDev;
    	//Why doesn't it receive the big file if use this. (???)
    	//It always stops when 327680 bytes are received.
#endif    
    ClearPending(BIT_DMA_SBUS);
    ClearPending(BIT_USB);
    rSUBSRCPND=BIT_SUB_USBD;
    rSUBSRCPND=BIT_SUB_OTG;
    rSUBSRCPND=BIT_SUB_DMA2;

	//External interrupt will be falling edge triggered.
	rEINTCON0	= 0x22222222;			//EINT2~0
	rEINTCON1 	= 0x22222222;		//EINT10~3

    CLR_IF();
    
    //pISR_FIQ,pISR_IRQ must be initialized
}




⌨️ 快捷键说明

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