?? usb_test.c
字號:
/*********************************************************************************************
* File: u241mon.c
* Author: Embest
* Desc: u241mon entry point,menu,download
* History:
* Y.J.Guo, April 28, 2005
* Modifying and reusing of S3C2410X u24xmon
*********************************************************************************************/
/*------------------------------------------------------------------------------------------*/
/* include files */
/*------------------------------------------------------------------------------------------*/
#include <stdlib.h>
#include <string.h>
#include "def.h"
#include "2410lib.h"
#include "2410slib.h"
#include "mmu.h"
#include "profile.h"
#include "usbmain.h"
#include "usbout.h"
#include "usblib.h"
#include "2410usb.h"
/*------------------------------------------------------------------------------------------*/
/* functions declare */
/*------------------------------------------------------------------------------------------*/
void Isr_Init(void);
extern void debug_undef(void);
extern void debug_abort_d(void);
extern void debug_abort_d(void);
void Lcd_Off(void);
void WaitDownload(void);
void Menu(void);
//void (*restart)(void)=(void (*)(void))0x0;
void (*run)(void);
/*------------------------------------------------------------------------------------------*/
/* global variablese */
/*------------------------------------------------------------------------------------------*/
//#define DOWNLOAD_ADDRESS _RAM_STARTADDRESS
volatile UINT32T downloadAddress;
volatile unsigned char *downPt;
volatile UINT32T downloadFileSize;
volatile UINT16T checkSum;
volatile unsigned int err=0;
volatile UINT32T totalDmaCount;
volatile int isUsbdSetConfiguration;
int download_run=0;
UINT32T tempDownloadAddress;
UINT32T test_ram_start;
UINT32T test_ram_end;
int menuUsed=0;
extern char Image_RW_Limit[];
UINT32T *pMagicNum=(UINT32T *)Image_RW_Limit;
int consoleNum;
/*********************************************************************************************
* name: MemoryTest
* func: Test Ram
* para: none
* ret: none
* modify:
* comment: comparing the data writen to RAM and the data read from RAM
*********************************************************************************************/
void MemoryTest(void)
{
int i;
UINT32T data;
int memError=0;
UINT32T *pt;
// memory test
uart_printf("\nEnter a start address of ram to test(0x3...):");
test_ram_start = uart_getintnum();
uart_printf("\nEnter a end address of ram to test(0x3...):");
test_ram_end = uart_getintnum();
uart_printf("Memory Test(%xh-%xh):WR",test_ram_start,test_ram_end);
pt=(UINT32T *)(test_ram_start);
while((UINT32T)pt<(test_ram_end))
{
*pt=(UINT32T)pt;
pt++;
}
uart_printf("\b\bRD");
pt=(UINT32T *)(test_ram_start);
while((UINT32T)pt<(test_ram_end))
{
data=*pt;
if(data!=(UINT32T)pt)
{
memError=1;
uart_printf("\b\bFAIL:0x%x=0x%x\n",i,data);
break;
}
pt++;
}
if(memError==0)uart_printf("\b\bO.K.\n");
}
/*********************************************************************************************
* name: usb_test
* func: usb monitor entry
* para: none
* ret: none
* modify:
* comment:
*********************************************************************************************/
void usb_test(void)
{
char *mode;
int i;
UINT8T key;
rGPHCON = rGPHCON&~(0xf<<18)|(0x5<<18);
//To enhance the USB signal quality.
//CLKOUT 0,1=OUTPUT to reduce the power consumption.
Isr_Init();
if(*pMagicNum!=0x12345678)
consoleNum=0;
else
consoleNum=1;
uart_init(0,115200,UART0);
uart_select(consoleNum);
rMISCCR=rMISCCR&~(1<<3); // USBD is selected instead of USBH1
rMISCCR=rMISCCR&~(1<<13); // USB port 1 is enabled.
//
// USBD should be initialized first of all.
//
isUsbdSetConfiguration=0;
UsbdMain();
delay(0); //calibrate delay()
pISR_SWI=(_ISR_STARTADDRESS+0xf0); //for pSOS
#if USBDMA
mode="DMA";
#else
mode="Int";
#endif
uart_printf("\n");
uart_printf("+---------------------------------------------+\n");
uart_printf("| S3C2410X USB Downloader ver R1.11 APR/29/05 |\n");
uart_printf("+---------------------------------------------+\n");
uart_printf("FCLK=%dMHz,%s mode\n",FCLK/1000000,mode);
uart_printf("USB: IN_ENDPOINT:1 OUT_ENDPOINT:3\n");
uart_printf("FORMAT: <ADDR(DATA):4>+<SIZE(n+10):4>+<DATA:n>+<CS:2>\n");
uart_printf("NOTE: 1. Power off/on or press the reset button for 1 sec\n");
uart_printf(" in order to get a valid USB device address.\n");
uart_printf(" 2. For additional menu, Press any key. \n");
uart_printf("\n");
download_run=0; //The default menu is the Download mode.
while(1)
{
if(menuUsed==1) Menu();
WaitDownload();
#ifdef BOARDTEST
break;
#endif
}
uart_printf(" end.\n");
}
/*********************************************************************************************
* name: Menu
* func: usb monitor Menu
* para: none
* ret: none
* modify:
* comment:
*********************************************************************************************/
void Menu(void)
{
int i;
UINT8T key;
menuUsed=1;
g_nKeyPress = 1;
while(g_nKeyPress==1) // only for board test to exit
{
uart_printf("\n###### Select Menu ######\n");
//uart_printf(" [0] Download & Run\n");
uart_printf(" [1] Download Only\n");
uart_printf(" [2] Test SDRAM \n");
uart_printf(" [3] Change The Console UART Ch.\n");
while(g_nKeyPress==1)
{
if(key = uart_getkey()) break;
}
switch(key)
{
//case '0':
// uart_printf("\nDownload&Run is selected.\n\n");
// download_run=1;
// return;
case '1':
uart_printf("\nDownload Only is selected.\n");
uart_printf("\nEnter a new temporary download address(0x3...):");
tempDownloadAddress=uart_getintnum();
download_run=0;
uart_printf("\nThe temporary download address is 0x%x.\n\n",tempDownloadAddress);
return;
case '2':
uart_printf("\nMemory Test is selected. please wait a little long time.\n");
MemoryTest();
Menu();
return;
break;
case '3':
uart_printf("\nWhich UART channel do you want to use for the console?[0/1]\n");
if(uart_getch()!='1')
{
*pMagicNum=0x0;
uart_printf("UART ch.0 will be used for console at next boot.\n");
}
else
{
*pMagicNum=0x12345678;
uart_printf("UART ch.1 will be used for console at next boot.\n");
uart_printf("UART ch.0 will be used after long power-off.\n");
}
uart_printf("System is waiting for a reset. Please, Reboot!!!\n");
while(1);
break;
default:
break;
}
}
}
/*********************************************************************************************
* name: WaitDownload
* func: usb downloader
* para: none
* ret: none
* modify:
* comment:
*********************************************************************************************/
void WaitDownload(void)
{
UINT32T i;
UINT32T j;
UINT16T cs;
UINT32T temp;
UINT16T dnCS;
int first=1;
float time;
UINT8T tempMem[16];
UINT8T key;
checkSum=0;
downloadAddress=(UINT32T)tempMem; //_RAM_STARTADDRESS;
downPt=(unsigned char *)downloadAddress;
//This address is used for receiving first 8 byte.
downloadFileSize=0;
#if 1
MMU_DisableICache();
//For multi-ICE.
//If ICache is not turned-off, debugging is started with ICache-on.
#endif
/*******************************/
/* Test program download */
/*******************************/
if(isUsbdSetConfiguration==0)
{
uart_printf("USB host is not connected yet.\n");
}
while(downloadFileSize==0)
{
if(first==1 && isUsbdSetConfiguration!=0)
{
uart_printf("USB host is connected. Waiting a download.\n");
first=0;
}
key=uart_getkey();
if(key!=0)
{
Menu();
first=1; //To display the message,"USB host ...."
}
}
timer_initex();
timer_startex();
#if USBDMA
rINTMSK &= ~(BIT_DMA2);
ClearEp3OutPktReady();
// indicate the first packit is processed.
// has been delayed for DMA2 cofiguration.
if(downloadFileSize>EP3_PKT_SIZE)
{
if(downloadFileSize<=(0x80000))
{
ConfigEp3DmaMode(downloadAddress+EP3_PKT_SIZE-8,downloadFileSize-EP3_PKT_SIZE);
//wait until DMA reload occurs.
while((rDSTAT2&0xfffff)==0);
//will not be used.
rDIDST2=(downloadAddress+downloadFileSize-EP3_PKT_SIZE);
rDIDSTC2=(0<<1)|(0<<0);
rDCON2=rDCON2&~(0xfffff)|(0);
}
else
{
ConfigEp3DmaMode(downloadAddress+EP3_PKT_SIZE-8,0x80000-EP3_PKT_SIZE);
//wait until DMA reload occurs.
while((rDSTAT2&0xfffff)==0);
if(downloadFileSize>(0x80000*2))//for 1st autoreload
{
rDIDST2=(downloadAddress+0x80000-8); //for 1st autoreload.
rDIDSTC2=(0<<1)|(0<<0);
rDCON2=rDCON2&~(0xfffff)|(0x80000);
while(rEP3_DMA_TTC<0xfffff)
{
rEP3_DMA_TTC_L=0xff;
rEP3_DMA_TTC_M=0xff;
rEP3_DMA_TTC_H=0xf;
}
}
else
{
rDIDST2=(downloadAddress+0x80000-8); //for 1st autoreload.
rDIDSTC2=(0<<1)|(0<<0);
rDCON2=rDCON2&~(0xfffff)|(downloadFileSize-0x80000);
while(rEP3_DMA_TTC<0xfffff)
{
rEP3_DMA_TTC_L=0xff;
rEP3_DMA_TTC_M=0xff;
rEP3_DMA_TTC_H=0xf;
}
}
}
totalDmaCount=0;
}
else
{
totalDmaCount=downloadFileSize;
}
#endif
uart_printf("\nNow, Downloading [ADDRESS:%xh,TOTAL:%d]\n",
downloadAddress,downloadFileSize);
uart_printf("RECEIVED FILE SIZE:%8d",0);
#if USBDMA
j=0x10000;
while(1)
{
if( (rDCDST2-(UINT32T)downloadAddress+8)>=j)
{
uart_printf("\b\b\b\b\b\b\b\b%8d",j);
j+=0x10000;
}
if(totalDmaCount>=downloadFileSize)break;
}
#else
j=0x10000;
while(((UINT32T)downPt-downloadAddress)<(downloadFileSize-8))
{
if( ((UINT32T)downPt-downloadAddress)>=j)
{
uart_printf("\b\b\b\b\b\b\b\b%8d",j);
j+=0x10000;
}
}
#endif
time=timer_stopex();
uart_printf("\b\b\b\b\b\b\b\b%8d",downloadFileSize);
uart_printf("(%5.1fKB/S,%3.1fS)\n",(float)(downloadFileSize/time/1000.),time);
#if USBDMA
/*******************************/
/* Verify check sum */
/*******************************/
uart_printf("Now, Checksum calculation\n");
cs=0;
i=(downloadAddress);
j=(downloadAddress+downloadFileSize-10)&0xfffffffc;
while(i<j)
{
temp=*((UINT32T *)i);
i+=4;
cs+=(UINT16T)(temp&0xff);
cs+=(UINT16T)((temp&0xff00)>>8);
cs+=(UINT16T)((temp&0xff0000)>>16);
cs+=(UINT16T)((temp&0xff000000)>>24);
}
i=(downloadAddress+downloadFileSize-10)&0xfffffffc;
j=(downloadAddress+downloadFileSize-10);
while(i<j)
{
cs+=*((UINT8T *)i++);
}
checkSum=cs;
#else
//checkSum was calculated including dnCS. So, dnCS should be subtracted.
checkSum=checkSum - *((unsigned char *)(downloadAddress+downloadFileSize-8-2))
- *( (unsigned char *)(downloadAddress+downloadFileSize-8-1) );
#endif
dnCS=*((unsigned char *)(downloadAddress+downloadFileSize-8-2))+
(*( (unsigned char *)(downloadAddress+downloadFileSize-8-1) )<<8);
if(downloadFileSize<1024*4)
for (i=0;i<downloadFileSize;i++)
uart_printf("%c",*(unsigned char *)(downloadAddress+i));
if(checkSum!=dnCS)
{
uart_printf(" Checksum Error!!! MEM:%x DN:%x\n",checkSum,dnCS);
return;
}
uart_printf("\n Download O.K.\n\n");
uart_txempty(consoleNum);
if(download_run==1)
{
rINTMSK = BIT_ALLMSK;
run=(void (*)(void))downloadAddress;
run();
}
}
/*********************************************************************************************
* name: Isr_Init
* func: Initialization of Isr
* para: none
* ret: none
* modify:
* comment:
*********************************************************************************************/
void Isr_Init(void)
{
pISR_UNDEF=(unsigned)debug_undef;
pISR_SWI =(unsigned)debug_swi;
pISR_PABORT=(unsigned)debug_abort_d;
pISR_DABORT=(unsigned)debug_abort_d;
rINTMOD=0x0; // All=IRQ mode
rSRCPND = rSRCPND; // clear all interrupt
rINTPND = rINTPND; // clear all interrupt
rINTMSK = BIT_ALLMSK; // All interrupt is masked.
rINTSUBMSK = BIT_SUB_ALLMSK; // All sub-interrupt is masked.
//pISR_URXD0=(unsigned)Uart0_RxInt;
//rINTMSK=~(BIT_URXD0); //enable UART0 RX Default value=0xffffffff
#if 1
pISR_USBD =(unsigned)IsrUsbd;
pISR_DMA2 =(unsigned)IsrDma2;
#else
pISR_IRQ =(unsigned)IsrUsbd;
//Why doesn't it receive the big file if use this. (???)
//It always stops when 327680 bytes are received.
#endif
ClearPending(BIT_DMA2);
ClearPending(BIT_USBD);
//rINTMSK&=~(BIT_USBD);
//pISR_FIQ,pISR_IRQ must be initialized
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -