?? 2443mon_u.cpp
字號:
/**
* Project Name : S3C2443 verification project
*
* Copyright 2006 by Samsung Electronics, Inc.
* All rights reserved.
*
* Project Description :
* This software is only for verifying functions of the S3C2443.
* Anybody can use this code without our permission.
*/
/**
* File Name : 2443mon.cpp
* Description : S3C2443 USB monitor main code
* Author : Cha gyu hwan
* Dept : Mobile solution, AP
* Created Date : 2006.09.16
* Version : 0.0
* History
* R0.0 (2006.06.): Cha gyu hwan draft
*/
#include <stdio.h>
#include <stdlib.h>
#include "Option.h"
#include "System.h"
#include "Console.h"
#include "MMUCache.h"
#include "Exception.h"
#include "2443addr.h"
#include "memtest.h"
#include "pll.h"
#include "profile.h"
#include "usbdev.h"
#include "uartdown.h" // add 060626
void Lcd_Off(void);
void WaitDownload(void);
void Menu(void);
void ClearMemory(void);
void UsbMon(void);
void Clk0_Enable(int clock_sel);
void Clk1_Enable(int clock_sel);
void Clk0_Disable(void);
void Clk1_Disable(void);
void TestDownLoading(void);
static USBDEV oUdev;
volatile U32 downloadAddress; //=DOWNLOAD_ADDRESS;
void (*restart)(void)=(void (*)(void))0x0;
void (*run)(void);
volatile U8 dma_done=0;
int download_run=0;
volatile U32 tempDownloadAddress;
int menuUsed=0;
extern char Image$$RW$$Limit[];
U32 *pMagicNum=(U32 *)Image$$RW$$Limit;
int consoleNum;
//static USB_OP eOpMode = USB_CPU;
static USB_OP eOpMode = USB_DMA;
static void __irq Isr_Usb(void)
{
// rINTMSK|=BIT_USBD;
oUdev.HandleEvent();
ClearPending(BIT_USBD);
// rINTMSK&=~(BIT_USBD);
}
void WhichMemory(void)
{
if(rBANKCFG & 0x4)
{
printf("mSDR\n");
}else{
printf("mDDR\n");
}
}
void Reset_Status_Check(void)
{
printf("reset status register = %08x\n", rRSTSTAT);
if( rRSTSTAT & (1<<0) )
{
printf("Power-on Reset\n");
}
else if( rRSTSTAT & (1<<2) )
{
printf("\nWatch-dog Reset\n\n");
run=(void (*)(void))0x30000000;
run();
}
else if( rRSTSTAT & (1<<3) )//Sleep mode wake-up
{
printf("\nSLEEP mode Wake-up\n\n");
run=(void (*)(void))0x30000000;
run();
}
else if( rRSTSTAT & (1<<4) )
{
printf("\nEsleep mode Wake-up\n\n");
run=(void (*)(void))0x30000000;
run();
}
else if( rRSTSTAT & (1<<5) )
{
printf("\nSoft Reset\n\n");
run=(void (*)(void))0x30000000;
run();
}
}
int main(void)
{
SystemCLK(0);
Console();
Isr_Init();
UsbMon();
}
void UsbMon(void)
{
if (rRSTSTAT&0x8) rRSTCON|=(1<<16); //if reset by sleep wakeup, control the retention I/O cell
//USB Port is Normal mode
rMISCCR=rMISCCR&~(1<<12); // USBD is 0 ,normal mode ,1 is suspend mode /
rPWRCFG |= (0x1<<4); // phy power enable
//USB device 2.0 must reset like bellow , 1st phy reset and after at least 10us, func_reset & host reset
//phy reset can reset bellow registers.
rUSB_RSTCON = (0x0<<2)|(0x0<<1)|(0x1<<0);//Function 2.0 S/W reset, Host 1.1 S/W reset,PHY 2.0 S/W reset
Delay(1); // phy reset must be asserted for at 10us
rUSB_RSTCON = (0x1<<2)|(0x1<<1)|(0x0<<0);//Function 2.0 S/W reset, Host 1.1 S/W reset,PHY 2.0 S/W reset
rUSB_RSTCON = (0x0<<2)|(0x0<<1)|(0x0<<0);//Function 2.0 S/W reset, Host 1.1 S/W reset,PHY 2.0 S/W reset
//rUSB_PHYCTRL =(0x2<<3)|(0x0<<2)|(0x1<<1)|(0x0<<0); //12Mhz,X-tal,External X-tal,device
rUSB_PHYCTRL =(0x0<<3)|(0x0<<2)|(0x1<<1)|(0x0<<0); //48Mhz,x-tal,External X-tal,device
rUSB_PHYPWR = (0x0<<31)|(0x3<<4)|(0x0<<3)|(0x0<<2)|(0x0<<1)|(0x0<<0);
//48Mhz clock on ,PHY2.0 analog block power on,XO block power on,XO block power in suspend mode,PHY 2.0 Pll power on ,suspend signal for save mode disable
//rUSB_PHYPWR = (0x1<<31)|(0x3<<4)|(0x0<<3)|(0x1<<2)|(0x1<<1)|(0x0<<0);
//48Mhz clock on ,PHY2.0 analog block power on,XO block power on,XO block power in suspend mode,PHY 2.0 Pll power on ,suspend signal for save mode disable
rUSB_TESTTI =(0x0<<31)|(0x0<<30)|(0x0<<12)|(0xf<<8)|(0xff<<0); // vbus detect enable...
rUSB_CLKCON = (0x0<<31)|(0x1<<2)|(0x0<<1)|(0x0<<0); // vbus detect enable...
//D+ pull up , USB2.0 Function clock Enable, USB1.1 HOST disable,USB2.0 PHY test enable
rCLKDIV1|=0x1<<4; // for test clk enable
pISR_USBD =(unsigned)Isr_Usb;
MMU_EnableICache();
ClearPending(BIT_USBD);
rINTMSK&=~(BIT_USBD); // usb interrupt enable
Delay(0); //calibrate Delay()
Led_Display(0x6);
rUSB_CLKCON = (0x1<<31)|(0x1<<2)|(0x0<<1)|(0x1<<0); // vbus detect enable...
//D+ pull up , USB2.0 Function clock Enable, USB1.1 HOST disable,USB2.0 PHY test enable
// CLKOUT0/1 select.
printf("CLKOUT0:MPLL in, CLKOUT1:RTC clock.\n");
printf("\n\n");
printf("+-----------------------------------------------+\n");
printf("| S3C2443X 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");
download_run=1; //The default menu is the Download & Run mode.
Reset_Status_Check();
rUSB_TESTTI = 0x0400; //
while(1)
{
eOpMode =USB_DMA;
UsbdMain();
if(menuUsed==1)Menu();
WaitDownload();
}
}
void UsbdMain(void)
{
oUdev.SetOpMode(eOpMode);
oUdev.Init();
}
void Menu(void)
{
U8 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] Clear SDRAM \n");
printf(" [4] Change The Console UART Ch.\n");
printf(" [5] Download with UART\n");
printf(" [6] Upload with USB 2.0 device \n");
printf(" [7] suspend mode 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(0x3...):");
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;
case '3':
printf("\nMemory Clear is selected.\n");
ClearMemory();
Menu();
return;
case '4':
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);
case '5': // add 060626
printf("\nDownload with UART\n");
UartMON();
return;
case '6': // add 060626
printf("\nUpload file !!\n");
oUdev.SetOpMode(eOpMode);
getchar();
return;
case '7': // add 060626
//rMISCCR|=(1<<12);
rUSB_PHYPWR = (0x0<<31)|(0x3<<4)|(0x0<<3)|(0x0<<2)|(0x1<<1)|(0x0<<0);
getchar();
return;
default:
break;
}
}
}
extern U32 checkTest;
void WaitDownload(void)
{
U32 i;
U32 j;
U16 cs;
U32 temp;
U16 dnCS;
int first=1;
float time;
U8 tempMem[16];
U8 key;
U32 uDownAddr, uDownFileSize;
oUdev.m_uDownloadAddress=(U32)tempMem; //_RAM_STARTADDRESS;
oUdev.m_uDownloadFileSize=0;
/*******************************/
/* Test program download */
/*******************************/
j=0;
if(oUdev.IsEnumerationDone()==false)
{
printf("USB host is not connected yet.\n");
}
while(oUdev.m_uDownloadFileSize==0)
{
if(first==1 && oUdev.IsEnumerationDone()==true)
{
printf("USB host is connected. Waiting a download.\n");
first=0;
}
if(j%0x50000==0)Led_Display(0x6);
if(j%0x50000==0x28000)Led_Display(0x9);
j++;
key=Uart_GetKey();
if(key!=0)
{
Menu();
first=1; //To display the message,"USB host ...."
}
}
StartStopwatch();
printf("\nNow, Downloading [ADDRESS:%xh,TOTAL:%d]\n",
oUdev.m_uDownloadAddress,oUdev.m_uDownloadFileSize);
printf("RECEIVED FILE SIZE:%12d",0);
/* if(oUdev.m_eOpMode!= USB_CPU)
{
j=0x10000;
// getchar();
while(1)
{
printf("\b\b\b\b\b\b\b\b\b\b%10d",j);
j+=0x10000;
if(dma_done ==1)break;
}
}
else
{
// printf("*");
*/
// getchar();
// printf("\nsize=%d oUdev.m_uDownloadFileSize-8 = %d\n",((U32)oUdev.m_pDownPt-oUdev.m_uDownloadAddress),(oUdev.m_uDownloadFileSize-8));
// printf("ep3csr = %x \n\n",rESR);
// printf("oUdev.m_cpucnt= %d\n",oUdev.m_cpucnt);
j=0x10000;
while(((U32)oUdev.m_pDownPt-oUdev.m_uDownloadAddress)<(oUdev.m_uDownloadFileSize-8))
{
U8 key=0;
//printf("*");
if( ((U32)oUdev.m_pDownPt-oUdev.m_uDownloadAddress)>=j)
{
// printf("\b\b\b\b\b\b\b\b%8d",j);
j+=0x10000;
}
key=Uart_GetKey();
if(key=='x')
{
printf("\nsize=%d oUdev.m_uDownloadFileSize-8 = %d\n",((U32)oUdev.m_pDownPt-oUdev.m_uDownloadAddress),(oUdev.m_uDownloadFileSize-8));
printf("ep3csr = %x \n\n",rESR);
printf("oUdev.m_cpucnt= %d\n",oUdev.m_cpucnt);
printf("\nCheckTest : %d", checkTest);
}
}
//printf("\b\b\b\b\b\b\b\b%8d",j);
// }
// dma_done=0;
time=EndStopwatch();
printf("\b\b\b\b\b\b\b\b%8d",oUdev.m_uDownloadFileSize);
printf("\n(%5.1fKB/S,%3.1fS)\n",(float)(oUdev.m_uDownloadFileSize/time*1000.),time/1000000);
printf("RECEIVE FILE DONE !! \n");
if (oUdev.VerifyChecksum())
printf("\nChecksum O.K.\n\n");
else
printf("\nChecksum failed.\n\n");
if(download_run==1)
{
rINTMSK=BIT_ALLMSK;
run=(void (*)(void))oUdev.m_uDownloadAddress;
run();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -