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

📄 2460mon.nor.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 "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"


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;
volatile unsigned int totalDmaCount;

volatile int isUsbdSetConfiguration;

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

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


void WhichMemory( void)
{
	if (rPRIORITY1&(1<<4))	{
		if (rP1BANKCFG_L2RAM&(1<<1)) printf("PORT1 : L2RAM");
		else printf("PORT1 : SDRAM_L");
		if (rP2BANKCFG_L2RAM&(1<<1)) printf("\tPORT2 : L2RAM\n");
		else printf("\tPORT2 : SDRAM_L\n");
	} else {
		printf("PORT1 : ");
		if (rP1BANKCFG_DDR&(1<<21)) printf("m");
		if (rP1BANKCFG_DDR&(1<<22)) printf("DDR");
		else printf("SDRAM_D");

		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("\n\n");
   	printf("+-----------------------------------------------+\n");
   	printf("| S3C2460A USB Downloader ver R0.1              +\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;
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] Run test program again.\n");
		printf("\t(Note! Effective only when pressing a reset button without power-off.\n");
		printf(" [6] USB Suspend/Resume Test\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':
            printf("\nWhich UART channel do you want to use for the console?[0/1]\n");
            if(getchar()!='1')
            {
	    	*pMagicNum=0x0;
			printf("UART ch.0 will be used for console at next boot.\n");
		    }
		    else
		    {
		        *pMagicNum=0x12345678;
		 		printf("UART ch.1 will be used for console at next boot.\n");        
	            printf("UART ch.0 will be used after long power-off.\n");
		    }
            printf("System is waiting for a reset. Please, Reboot!!!\n");
            while(1);
            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':
			run=(void (*)(void))0x10200000;
			run();
			break;
		
		case '6':
			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");	
			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
			break;
			
		default:
			break;
		}	
	}	    

}

void WaitDownload(void)
{
    unsigned int i;
    unsigned int j;
    unsigned short cs;
    unsigned int temp;
    unsigned short dnCS;
    int first=1;
    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;

	if(isUsbdSetConfiguration==0)

⌨️ 快捷键说明

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