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

📄 6400_otgmon.c

📁 Samsugn 6400 NAND boot code
💻 C
字号:
/**************************************************************************************
* 
*	Project Name : S3C6400 Validation
*
*	Copyright 2006 by Samsung Electronics, Inc.
*	All rights reserved.
*
*	Project Description :
*		This software is only for validating functions of the S3C6400.
*		Anybody can use this software without our permission.
*  
*--------------------------------------------------------------------------------------
* 
*	File Name : 6400_main.c
*  
*	File Description : This file implements the monitor program using USB OTG.
*
*	Author : Haksoo,Kim
*	Dept. : AP Development Team
*	Created Date : 2007/01/23
*	Version : 0.1 
* 
*	History
*	- Created(Haksoo,Kim 2007/01/23)
*  
**************************************************************************************/


#include <stdio.h>

#include "option.h"
#include "library.h"
#include "sfr6400.h"
#include "system.h"
#include "sysc.h"
#include "intc.h"
#include "otg_dev.h"


USB_OPMODE eOpMode = USB_DMA;
void (*run)(void);

//////////
// Function Name : Isr_UsbOtg
// Function Description : USB OTG ISR
// Input : NONE
// Output : NONE
// Version : 
static void __irq Isr_UsbOtg(void)
{
	INTC_Disable(NUM_OTG);
	
	OTGDEV_HandleEvent();
	
	INTC_Enable(NUM_OTG);
	
	INTC_ClearVectAddr();
}

//////////
// Function Name : Download_Only
// Function Description : This function downloads a image file thru DNW.
//						You can configure the address to downlad in DNW "Configuration-Options" menu.
// Input : NONE
// Output : NONE
// Version : 
static void Download_Only(void)
{
	u32 uDownAddr, uDownFileSize, pDownPt, i;

	OTGDEV_ClearDownFileInfo();

	OTGDEV_SetOpMode(eOpMode); 

	Disp("Select a file to download in DNW\n");
	Disp("If you want to quit, press 'x' key\n");

	i = 0;

	do
	{
		OTGDEV_GetDownFileInfo(&uDownAddr, &uDownFileSize, &pDownPt);
		
		if(GetKey() == 'x')
		{
			return;
		}      
       
		if(i%0x40000==0)
			DisplayLED(0x6);
		if(i%0x40000==0x20000)
			DisplayLED(0x9);
		i++;		
	}while((uDownAddr == 0) ||(uDownFileSize == 0));
	
	Disp("\n[ADDRESS:%xh,TOTAL:%d(0x%x)]\n", uDownAddr, uDownFileSize, (uDownFileSize-10));

	do
	{
		OTGDEV_GetDownFileInfo(&uDownAddr, &uDownFileSize, &pDownPt);

		if(GetKey() == 'x')
		{
			return;
		} 
	}while((pDownPt - uDownAddr)<(uDownFileSize - 8));

	OTGDEV_VerifyChecksum();
	
}

//////////
// Function Name : Download_Run
// Function Description : This function downloads a image file thru DNW 
//						and then jumps to the start address of the downloaded image
// Input : NONE
// Output : NONE
// Version : 
void Download_Run(void)
{
	u32 uDownAddr, uDownFileSize, pDownPt, i;

	Download_Only();
	
	OTGDEV_GetDownFileInfo(&uDownAddr, &uDownFileSize, &pDownPt);

	run=(void (*)(void))uDownAddr;

	for(i=0;i<INT_LIMIT;i++)
	{
		INTC_Disable(i);
	}

	run();	
		
}

//////////
// Function Name : Upload_Only
// Function Description : This function uploads a image file thru DNW
//						You can configure the address and the size to upload in DNW "Configuration-Options" menu.
// Input : NONE
// Output : NONE
// Version : 
void Upload_Only()
{
	u32 uUpAddr, uUpFileSize, pUpPt, i;

	OTGDEV_ClearUpFileInfo();

	OTGDEV_SetOpMode(eOpMode); 

	Disp("\nConfigure the address and the size of the file to upload in DNW\n");
	Disp("If you want to quit, press 'x' key\n");

	i = 0;

	do
	{
		OTGDEV_GetUpFileInfo(&uUpAddr, &uUpFileSize, &pUpPt);
	
		if(GetKey() == 'x')
		{
			return;
		}      
       
		if(i%0x40000==0)
			DisplayLED(0x6);
		if(i%0x40000==0x20000)
			DisplayLED(0x9);
		i++;		
	}while((uUpAddr == 0) || (uUpFileSize == 0));
	
	Disp("\n[ADDRESS:%xh,TOTAL:%d]\n", uUpAddr, uUpFileSize);

	do
	{
		OTGDEV_GetUpFileInfo(&uUpAddr, &uUpFileSize, &pUpPt);

		if(GetKey() == 'x')
		{
			return;
		} 
	}while((pUpPt - uUpAddr)<uUpFileSize);
	
}

//////////
// Function Name : Select_OpMode
// Function Description : This function selects an operation mode of USB OTG of CPU or DMA mode.
// Input : NONE
// Output : NONE
// Version : 
void Select_OpMode(void)
{
	int iSel;
	
	Disp(" Current Op Mode : ");
	if(eOpMode == USB_CPU)
	{
		Disp("CPU mode\n");
	}
	else if(eOpMode== USB_DMA)
	{
		Disp("DMA mode\n");
	}

	Disp(" Enter the op. mode (0: CPU_MODE, 1: DMA_MODE) : ");
	iSel = GetIntNum();

	if (iSel != -1) 
	{
		if (iSel == 0)
			eOpMode = USB_CPU;
		else if (iSel == 1)
			eOpMode = USB_DMA;
		else
			Disp("Invalid selection\n");
	}
}

//////////
// Function Name : DisplayMenu
// Function Description : This function displays the menus of the monitor pgm
//						and then executes the selected item.
// Input : NONE
// Output : NONE
// Version : 
void DisplayMenu(void)
{
	int iSel, i;
	
	const testFuncMenu menu[]=
	{
		Download_Run,	        "Download & Run",
		Download_Only,			"Donwload Only",
		Upload_Only,			"Upload Only",
		Select_OpMode,			"Select Op Mode",
		0,                      0
	};

	Disp("\n");
	for (i=0; (int)(menu[i].desc)!=0; i++)
		Disp("%2d: %s\n", i, menu[i].desc);

	Disp("\nSelect the function to test : ");
	iSel = GetIntNum();
	Disp("\n");

	if ((iSel>=0) && (iSel<sizeof(menu)/8-1))
		(menu[iSel].func)();	
	
	
}

//////////
// Function Name : main
// Function Desctiption : main function of the monitor pgm.
// Input : NONE
// Output : NONE
// Version :
int main(void)
{
	USB_SPEED eUsbSpeed;
	
	SYSTEM_InitException();
	SYSTEM_EnableICache();
	
	SYSC_ReadSystemID();
	SYSC_GetClkInform();

	OpenConsole();
	
	CalibrateDelay();

   	Disp("\n\n");
   	Disp("+-----------------------------------------------+\n");
   	Disp("| S3C6400 USB OTG Downloader v0.1               +\n");
	Disp("| System ID : Revision [%2d], Pass [%2d]        +\n", g_System_Revision, g_System_Pass);
	Disp("+-----------------------------------------------+\n");
	Disp("ARMCLK: %.2fMHz  HCLKx2: %.2fMHz  HCLK: %.2fMHz  PCLK: %.2fMHz\n\n",(float)g_ARMCLK/1.0e6, (float)g_HCLKx2/1.0e6, (float)g_HCLK/1.0e6, (float)g_PCLK/1.0e6);
	
	Disp("USB host is not connected yet.\n");
	Disp("Waiting for USB host connection.\n");
	
	
	INTC_SetVectAddr(NUM_OTG, Isr_UsbOtg);
	INTC_Enable(NUM_OTG);
	
	OTGDEV_InitOtg(USB_HIGH);	
	
	while(1)
	{
		if(OTGDEV_IsUsbOtgSetConfiguration()==true)
		{
			Disp("\n!!! USB host is connected !!!\n");
			Disp(" - Bulk In EP : %d\n",BULK_IN_EP);
			Disp(" - Bulk Out EP : %d\n",BULK_OUT_EP);
			
			OTGDEV_CheckEnumeratedSpeed(&eUsbSpeed);
			Disp(" - Speed : ");
			if(eUsbSpeed == USB_HIGH)
			{
				Disp("High\n");
			}
			else if(eUsbSpeed == USB_FULL)
			{
				Disp("Full\n");
			}

			Disp(" - Op Mode : ");
			if(eOpMode== USB_DMA)
			{
				Disp("DMA mode\n");
			}
			else if(eOpMode == USB_CPU)
			{
				Disp("CPU mode\n");
			}
			break;
		}
	}

	while(1)
	{
		DisplayMenu();
	}
}

⌨️ 快捷键说明

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