?? library.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 : library.c
*
* File Description : This file implements library functions.
*
* Author : Haksoo,Kim
* Dept. : AP Development Team
* Created Date : 2006/11/08
* Version : 0.1
*
* History
* - Created(Haksoo,Kim 2006/11/08)
* - Added DownloadImageThruUsbOtg function (Haksoo,Kim 2007/01/24)
*
**************************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <ctype.h>
#include "option.h"
#include "library.h"
#include "sfr6400.h"
#include "system.h"
#include "uart.h"
#include "gpio.h"
#include "otg_dev.h"
#include "intc.h"
#include "register_addr.h"
#define IMAGE_MAXSIZE 1600
//////////
// Function Name : InitUartPort
// Function Description : This function initializes gpio for debugging uart ch.
// Input : ch, uart ch number
// flowControl, whether flow control or not
// Output : NONE
// Version :
void InitUartPort(u8 ch, bool flowControl)
{
switch (ch)
{
default:
case 0:
if(flowControl == TRUE)
{
GPIO_SetFunctionEach(eGPIO_A, eGPIO_0, 2);
GPIO_SetFunctionEach(eGPIO_A, eGPIO_1, 2);
GPIO_SetFunctionEach(eGPIO_A, eGPIO_2, 2);
GPIO_SetFunctionEach(eGPIO_A, eGPIO_3, 2);
}
else
{
GPIO_SetFunctionEach(eGPIO_A, eGPIO_0, 2);
GPIO_SetFunctionEach(eGPIO_A, eGPIO_1, 2);
}
break;
case 1:
if(flowControl == TRUE)
{
GPIO_SetFunctionEach(eGPIO_A, eGPIO_4, 2);
GPIO_SetFunctionEach(eGPIO_A, eGPIO_5, 2);
GPIO_SetFunctionEach(eGPIO_A, eGPIO_6, 2);
GPIO_SetFunctionEach(eGPIO_A, eGPIO_7, 2);
}
else
{
GPIO_SetFunctionEach(eGPIO_A, eGPIO_4, 2);
GPIO_SetFunctionEach(eGPIO_A, eGPIO_5, 2);
}
break;
case 2:
GPIO_SetFunctionEach(eGPIO_B, eGPIO_0, 2);
GPIO_SetFunctionEach(eGPIO_B, eGPIO_1, 2);
break;
case 3:
GPIO_SetFunctionEach(eGPIO_B, eGPIO_2, 2);
GPIO_SetFunctionEach(eGPIO_B, eGPIO_3, 2);
break;
}
return;
}
//////////
// Function Name : InitLED
// Function Desctiption : This function initializes gpio for debugging LED
// Input : NONE
// Output : NONE
// Version :
void InitLED(void)
{
GPIO_SetFunctionEach(eGPIO_N, eGPIO_12, 1);
GPIO_SetFunctionEach(eGPIO_N, eGPIO_13, 1);
GPIO_SetFunctionEach(eGPIO_N, eGPIO_14, 1);
GPIO_SetFunctionEach(eGPIO_N, eGPIO_15, 1);
return;
}
//////////
// Function Name : DisplayLED
// Function Desctiption : This function controls debugging LED
// Input : data, LED value
// Output : NONE
// Version :
void DisplayLED(u8 data)
{
u32 temp;
temp = GPIO_GetDataAll(eGPIO_N);
temp = (temp & ~(0xf000))|((data&0xf)<<12);
GPIO_SetDataAll(eGPIO_N, temp);
return;
}
//////////
// Function Name : OpenConsole
// Function Description : This function opens uart and LED for debugging
// Input : NONE
// Output : NONE
// Version :
void OpenConsole( void)
{
u8 ch=0; //uart channel for debugging
InitUartPort(ch, FALSE);
UART_InitDebugCh(ch, 115200);
InitLED();
return;
}
//////////
// Function Name : GetIntNum
// Function Description : This function gets the number which a user enters
// Input : NONE
// Output : number, number which a user enters
// Version :
s32 GetIntNum( void)
{
char str[30];
char *string = str;
int base = 10;
int minus = 0;
int result = 0;
int lastIndex;
int i,j;
gets(string);
i=0; j=0;
do {
if (string[j]==0x8) {
if (i>0) i--;
} else
string[i++]=string[j];
} while(string[j++]!=0);
if(string[0]=='-') {
minus = 1;
string++;
}
if(string[0]=='0' && (string[1]=='x' || string[1]=='X')) {
base = 16;
string += 2;
}
lastIndex = strlen(string) - 1;
if(lastIndex<0)
return -1;
if(string[lastIndex]=='h' || string[lastIndex]=='H' ) {
base = 16;
string[lastIndex] = 0;
lastIndex--;
}
if(base==10) {
result = atoi(string);
result = minus ? (-1*result):result;
}
else {
for(i=0;i<=lastIndex;i++) {
if(isalpha(string[i])) {
if(isupper(string[i]))
result = (result<<4) + string[i] - 'A' + 10;
else
result = (result<<4) + string[i] - 'a' + 10;
}
else
result = (result<<4) + string[i] - '0';
}
result = minus ? (-1*result):result;
}
return result;
}
//////////
// Function Name : DownloadImageThruUart
// Function Description : This function downloads a certain image through uart
// Input : DownloadAddress, address to download the image
// Output : FileSize, size of downloaded image
// Version :
u32 DownloadImageThruUart(u8 *DownloadAddress)
{
char buf[4];
int i;
u32 FileSize;
u16 CheckSum=0,dnCS;
printf("\nDownloadAddress : 0x%08x\n",DownloadAddress);
printf("STATUS : ");
// To get the file size.
for(i=0;i<4;i++)
buf[i]=UART_Getc();
FileSize=(buf[0])+(buf[1]<<8)+(buf[2]<<16)+(buf[3]<<24);
FileSize-=4;
for(i=0;i<FileSize;i++) {
*(DownloadAddress+i)=UART_Getc();
if((i&0x3ff)==0)
putchar('#');
}
for(i=0;i<(FileSize-2);i++)
CheckSum+=*((u8 *)(DownloadAddress+i));
dnCS=*((u8 *)(DownloadAddress+FileSize-2))+
(*( (u8 *)(DownloadAddress+FileSize-1) )<<8);
if(CheckSum!=dnCS) {
printf("\nChecksum Error!!! MEM : %x DN : %x\n",CheckSum,dnCS);
FileSize=0;
} else {
FileSize-=2;
printf("\n%d bytes downloaded OK.\n",FileSize);
}
return FileSize;
}
//////////
// Function Name : DownloadImageThruUsbOtg
// Function Description : This function downloads a certain image through usb otg
// Input : DownloadAddress, address to download the image
// Output : FileSize, size of downloaded image
// Version :
extern USB_OPMODE eOpMode;
extern USB_SPEED eSpeed;
extern bool download_run;
extern u32 tempDownloadAddress;
extern void __irq Isr_UsbOtg(void);
u32 DownloadImageThruUsbOtg(u8 *DownloadAddress)
{
bool first = true;
u32 uDownAddr, uDownFileSize, pDownPt, i;
USB_SPEED eUsbSpeed;
INTC_SetVectAddr(NUM_OTG, Isr_UsbOtg);
INTC_Enable(NUM_OTG);
while(1)
{
if(OTGDEV_IsUsbOtgSetConfiguration()==true)
{
OTGDEV_CheckEnumeratedSpeed(&eUsbSpeed);
if(eUsbSpeed == USB_HIGH)
{
Disp("\n!!! USB host is connected (Speed : High) !!!\n\n");
DisplayLED(0xf);
}
else if(eUsbSpeed == USB_FULL)
{
Disp("\n!!! USB host is connected (Speed : Full) !!!\n\n");
DisplayLED(0x6);
}
break;
}
else if(first == true)
{
OTGDEV_InitOtg(eSpeed);
first = false;
}
}
OTGDEV_ClearDownFileInfo();
OTGDEV_SetOpMode(eOpMode);
if(DownloadAddress!=0)
{
tempDownloadAddress = (u32)DownloadAddress;
}
else
{
Disp("Enter a new temporary download address(0x...):");
tempDownloadAddress=(u32)GetIntNum();
if(tempDownloadAddress==0xffffffff)
{
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -