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

📄 2460mon.cpp

📁 三星S3C2460 USB DEVICE /USB HOST 监控代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/**
* 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.cpp
* Description  : S3C2460 USB monitor main code
* Author       : Y.C.Kwon
* Dept         : Mobile solution, AP
* Created Date : 2004.09.16
* Version      : 0.0
* History
*   R0.0 (2004.09.16): Kwon draft
*/

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

#include "type.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 "usbmain.h"
#include "usbout.h"
#include "usblib.h"
#include "2460usb.h"

#include "nand.h"
#include "am29f800.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=0;
volatile unsigned short checkSum=0;
volatile unsigned int err=0;
volatile unsigned int totalDmaCount;

volatile int isUsbdSetConfiguration;

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

void WhichMemory( void)
{
	{
	
      #if (WHICH_PORT==1)
		printf("PORT1 : ");
		if (rP1BANKCFG_DDR&(1<<21)) printf("m");
		if (rP1BANKCFG_DDR&(1<<22)) printf("DDR");
		else printf("SDRAM_D");
	  #endif

		printf("\tPORT2 : ");
		if (rP2BANKCFG_DDR&(1<<21)) printf("m");
		if (rP2BANKCFG_DDR&(1<<22)) printf("DDR\n");
		else printf("SDRAM_D\n");
	}

}

int main(void)
{
	register int i;
    char *mode;

	for(i=0;i<10000;i++);	//	Wait for PLL lock down.

	GlobalCLK();

	Init_LogicalConsole();
	Init_LED();

   	Isr_Init();

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

   	Usb_Off(); //USB D+ signal is 'Low'

    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
   	MMU_EnableICache();  
   	UsbdMain(); 
#endif

    Delay(0);  //calibrate Delay()

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

    Led_Display(0x6);
   
#if USBDMA
   	mode="DMA";
#else
   	mode="Int";
#endif

    //printf("\nrP1BANKCFG_DDR=0x%08x,rP2BANKCFG_DDR=0x%08x\n",rP1BANKCFG_DDR,rP2BANKCFG_DDR);
    //printf("rP1BANKCON_DDR=0x%08x,rP2BANKCON_DDR=0x%08x\n",rP1BANKCON_DDR,rP2BANKCON_DDR);
    //printf("rP1REFRESH_DDR=0x%08x,rP2REFRESH_DDR=0x%08x\n",rP1REFRESH_DDR,rP2REFRESH_DDR);

   	printf("\n\n");
   	printf("+-----------------------------------------------+\n");
   	printf("| S3C2460A USB Downloader ver R0.2              +\n");
   	printf("+-----------------------------------------------+\n");
   	WhichMemory();
   	printf("MPLL=%.2fMHz, ARMCLK=%.2fMHz (%d:%d:%d), HCLK=%.2fMHz, PCLK=%.2fMHz\n\n",
   		(float)MPLL/1000000,(float)ARMCLK/1000000,ARMCLKdiv+1,(ARMCLKdiv+1)*(HCLKdiv+1),(ARMCLKdiv+1)*(HCLKdiv+1)*(PCLKdiv+1),(float)HCLK/1000000,(float)PCLK/1000000);
   	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("\n");
   		
	Usb_On(); //USB D+ signal is 'High'
    
   /*******************************/
   /*		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();    
    }

}

unsigned char not_suspend = TRUE;
unsigned char not_resume = TRUE;
unsigned char sus_res_print = FALSE;
uint32 bank_of_nor=0;
void Menu(void)
{
    int i;
	int key;
    menuUsed=1;
    volatile uint32 saved_SROM_BW;
    uint32 jumpAddress;
    
    while(1)
    {
        printf("\n###### Select Menu ######\n");
        printf(" [0] Download & Run\n");
        printf(" [1] Download Only\n");
		printf(" [2] Test SDRAM \n");
        printf(" [3] Program NAND Flash Memory(K9S1208)\n");
        printf(" [4] Run DSP\n");
        printf(" [5] Clear SDRAM.\n");
		printf(" [6] Jump to Specific Address.\n");
		printf("\t(Note! Effective only when pressing a reset button without power-off.\n");
		printf(" [7] USB Suspend/Resume Test\n");
	  #if (WHICH_PORT==1)	//only 496pkg supports this
        printf(" [8] Program AMD NOR Flash Memory\n");
	  #endif

	 	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(0x...):");
            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("\nProgram NAND Flash 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':
			printf("\nEnter the branch address(Default:0x%08x):",(_RAM_STARTADDRESS+0x00200000));
            jumpAddress=(uint32)GetIntNum();
            if (jumpAddress==0xffffffff)
            	jumpAddress = (_RAM_STARTADDRESS+0x00200000);
            run = (void (*)(void))jumpAddress;
            run();
			break;
		
		case '7':
			printf("\n USB Suspend/Resume test is selected.\n");
			printf("\nIf you don't want to wait suspend interrupt any more, press any key\n");	
			rEP_INT_EN_REG = 0;
			sus_res_print = TRUE;	
			rPWR_REG = 0x01;	//enable suspend mode
    		rUSB_INT_EN_REG |= SUSPEND_INT;
			while(((rPWR_REG & 0x02) != 0x02) && (not_suspend==TRUE))
			{
				if(Uart_GetKey())
					break;
			}
			//printf("Curent PWR_Reg Value is 0x%01x\n", (rPWR_REG&0xf));
			//printf("Curent USB_INT_Reg Value is 0x%01x\n", (rUSB_INT_REG&0xf));
			//printf("Curent USB_INT_EN_Reg Value is 0x%01x\n", (rUSB_INT_EN_REG&0xf));
			
			if(rPWR_REG & 0x02)
			{	
				printf("\nEntered Suspend Mode\n");
			}
			printf("\nIf you want to end this test, press 'y' key\n");
			while(not_resume==TRUE)
			{
				if(Uart_GetKey()=='y')
					break;
			}
			//printf("Curent PWR_Reg Value is 0x%01x\n", (rPWR_REG&0xf));
			//printf("Curent USB_INT_Reg Value is 0x%01x\n", (rUSB_INT_REG&0xf));
			//printf("Curent USB_INT_EN_Reg Value is 0x%01x\n", (rUSB_INT_EN_REG&0xf));
			
			not_suspend = TRUE;
			not_resume = TRUE;   
			
			sus_res_print = FALSE;	
		
			rPWR_REG &= ~0x01;	//disable suspend mode			
    		rEP_INT_EN_REG=EP0_INT|EP1_INT|EP3_INT; 	// determines which interrupt is enabled
    		
			break;
			
	  #if (WHICH_PORT==1)	//only 496pkg supports this
        case '8':
            downloadAddress=_NONCACHE_STARTADDRESS;
            bank_of_nor = 0x0;	//bank0
            saved_SROM_BW = rSROM_BW;
            rSROM_BW = rSROM_BW & ~(0x7<<0) | (0x1<<0);
            
		    printf("\n[Check AM29LVxxx]\n");
		    switch(AM29F800_CheckId())  //04.01.12 junon
		    {
				case 1 :
				    printf("This device is AM29LV200B!\n");	
				    break;
				case 2 :
				    printf("This device is AM29LV400B!\n");	
				    break;
				case 3 :
				    printf("This device is AM29LV800B!\n");	
				    break;
				case 4 :
				    printf("This device is AM29LV160B!\n");	
				    break;
		    	default:
		    		rSROM_BW = saved_SROM_BW;
		    		bank_of_nor = 0x05000000;	//bank2
            		rSROM_BW = rSROM_BW & ~(0x7<<3) | (0x1<<3);
            		switch(AM29F800_CheckId())
            		{
						case 1 :
						    printf("This device is AM29LV200B!\n");	
						    break;
						case 2 :
						    printf("This device is AM29LV400B!\n");	
						    break;
						case 3 :
						    printf("This device is AM29LV800B!\n");	
						    break;
						case 4 :
						    printf("This device is AM29LV160B!\n");	
						    break;
				    	default:  
				    		printf("ID Check Error!!!\n");
				    		return;          		
            		}
            		break;
		    }            
            
            ProgramAM29F800();
            printf("\nProgram AMD NOR Flash Ends.\n");
		    rINTMSK&=~(BIT_USB);  
   			rINTSUBMSK&=~(BIT_SUB_USBD);
            break;
	  #endif            
            
		default:
			break;
		}	

⌨️ 快捷键说明

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