📄 main_org.c
字号:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "common.h"
#include "tht_memory_map_defines.h"
// Add the following Function
void UsbEPConfig(U32 ep, U32 dir, U32 stall, U32 setup, U32 MPS, U32 format, U32 xbsa, U32 ybsa, U32 Bufsize, U32 Tbyte)
{
U32 DWORD0 = 0;
U32 DWORD1 = 0;
U32 DWORD2 = 0;
U32 DWORD3 = 0;
U32 localEp = ep;
U32 DWORD0_addr,DWORD1_addr,DWORD2_addr,DWORD3_addr ;
DWORD0_addr = OTG_EP_BASE + (16*((localEp*2) + dir));
DWORD1_addr = DWORD0_addr + 4;
DWORD2_addr = DWORD1_addr + 4;
DWORD3_addr = DWORD2_addr + 4;
/*Configuring DWORD0*/
DWORD0 = (stall << 31)| (setup << 30) | (0 << 26) | (MPS<< 16) | (format << 14) | 0;
*(VP_U32)DWORD0_addr = DWORD0;
/*Configuring DWORD1*/
DWORD1 = (ybsa << 16) | (xbsa << 2) |0 ;
*(VP_U32)DWORD1_addr = DWORD1;
/*Configuring DWORD2*/
/* reserved */
/*Configuring DWORD3*/
//Bufsize = buffersize - 1
DWORD3 = (Bufsize << 21) | Tbyte;
*(VP_U32)DWORD3_addr = DWORD3;
/*Configure EP Table Entry*/
}
void CheckFlashComplete(U32 StatusCode)
{
U32 temp = 0;
U32 USBTimeOut = 0x100000;
U32 EpStartAddress = 0;
/*
// Status Code
U32 FlashComplete = 0x67676767;
U32 FlashTimeOut = 0x57575757;
U32 FlashError = 0x47474747;
*/
//**************************************************************
// Send through UART
*(VP_U32)UART1_UTXD_1 = (U8)StatusCode & 0xFF; // Lewis, UART1_TXDATA > UART1_UTXD_1
*(VP_U32)UART1_UTXD_1 = (U8)((StatusCode & 0xFF00)>>8);
*(VP_U32)UART1_UTXD_1 = (U8)((StatusCode & 0xFF0000)>>16);
*(VP_U32)UART1_UTXD_1 = (U8)((StatusCode & 0xFF000000)>>24);
while (!(*(VP_U32)UART1_USR2_1 & 0x4000)); // Lewis, UART1_SR2 > UART1_USR2_1
//**************************************************************
// Send through USB
UsbEPConfig(0x2, 0x1, 0, 0, 32, 0x2, (0*16), 0x200, (0x200-1), 4);
//read the Start Address (xbsa, ybsa)
EpStartAddress = ((*(VP_U32)(OTG_EP_BASE+(16*5)+4))&0x0000FFFF);
*(VP_U32)(OTG_DATA_BASE + EpStartAddress + (0*0x4)) = StatusCode;
//Set/Clear Fill Status
*(VP_U32)(OTG_FUNC_XFILL_STAT) = 0x20; //write to toggle the correct EP's X buffer status
//clear XY interrupt
temp = *(VP_U32)OTG_FUNC_XINT_STAT;
*(VP_U32)OTG_FUNC_XINT_STAT = temp;
temp = *(VP_U32)OTG_FUNC_YINT_STAT;
*(VP_U32)OTG_FUNC_YINT_STAT = temp;
//ready EP2
*(VP_U32)(OTG_FUNC_EP_RDY) = 0x20;
//check for EP2 IN transfer done
while (1)
{
if (*(VP_U32)OTG_FUNC_EP_DSTAT & 0x20)
break;
else
USBTimeOut -- ;
if (!USBTimeOut)
break;
}
//clear EP0 IN transfer done
*(VP_U32)OTG_FUNC_EP_DSTAT = 0x20;
//clear XY interrupt
temp = *(VP_U32)OTG_FUNC_XINT_STAT;
*(VP_U32)OTG_FUNC_XINT_STAT = temp;
temp = *(VP_U32)OTG_FUNC_YINT_STAT;
*(VP_U32)OTG_FUNC_YINT_STAT = temp;
//**************************************************************
}
int main(void)
{
U32 SourceAddress = *(volatile U32*)(0xC000FFF0);
U32 TargetAddress = *(volatile U32*)(0xC000FFF4);
U32 Word = *(volatile U32*)(0xC000FFF8);
//U32 SourceAddress = 0xC2000000;
//U32 TargetAddress = 0xC8000000;
//U32 Word = 8*1024*1024;
// 0xC000_0060: Flash Image temporary at SDRAM, e.g. 0xC001_0000
// 0xC000_0064: Flash Image to be store on Flash, e.g. 0xC800_0000 - CS0
// 0xC000_0068: Size of Flash Image
// 0xC000_4000: Entry of this Flash Download Application
// 0xC000_8000: End of Flash Download Application
// ************************
// LED RAM application
// Load Flash_img.bin into 0xC3000000, will burn onto 0xC8000000, size as 1M = 1 * 1024*1024/4;
// ************************
// Linux OS
// * Bootloader
// Load HAB-vec.bin into 0xC3000000
// Load boot0.2.0.bin into 0xC3004000
// With size 1M = 1 * 1024*1024/4, program onto 0xC8000000;
// * Kernel
// Load kernel4.bin into 0xC3100000
// With size 2M = 2 * 1024*1024/4, program onto 0xC8100000;
// * RootDisk
// Load rootdisk4.bin into 0xC3300000
// With size 12M = 12 * 1024*1024/4, program onto 0xC8300000;
/*
SourceAddress = 0xC3000000;
TargetAddress = 0xC8000000;
Word = 16* 1024*1024/4;
FlashLoader(TargetAddress, SourceAddress, Word);
*/
FlashLoader(TargetAddress, SourceAddress, Word);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -