版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
最小bootloader的实现,完整源代码热1已有275次阅读2009-12-3015:18我们整个ARM课程就分为三局部,这是第一局部,实现一个自己的最小bootloader1.ReadMeCode:;s3c2440bootloader;author:xxxx;time:2009.12.22AREAFIRST,CODE,READONLYENTRYCODE32IMPORTuart_testIMPORTsdram_testSTARTWatchDog;CloseWatchDogLDRR0,=0X53000000MOVR1,#0X0STRR1,[R0]Led_on;MakeaLedonLDRR2,=0x20800000MOVR4,#0X1STRBR4,[R2];BLDELAYBeep_off;CloseBeep;ControlGPB0outputLDRR0,=0x56000010MOVR1,#0X1STRR1,[R0]LDRR0,=0X56000014MOVR1,#0X0STRR1,[R0]Interrupt_off;CLoseInterruptLDRR0,=0X4A000008LDRR1,=0XFFFFFFFFSTRR1,[R0]Init_Clock;InitClock;SetModeMRCp15,0,R1,c1,c0,0ORRR1,R1,#0XC0000000MCRp15,0,R1,c1,c0,0;CAMDIVN;WhenConfigtheregisterCLKDIVNNeddThisConfigreLDRR0,=0x4c000018MOVR1,#0x0STRR1,[r0];LOCKTIMEPLLLDRR0,=0x4c000000LDRR1,=0x00ffffffSTRR1,[r0];UPLLCONLDRR0,=0x4c000008LDRR1,=0x00038022STRR1,[R0]NOPNOPNOPNOPNOPNOPNOP;MPLLCONLDRR0,=0x4c000004LDRR1,=0x00044011STRR1,[r0];CLKCON;WitchdiviceneedClockLDRR0,=0x4c00000cLDRR1,=0x00fffff0STRR1,[R0];CLKSLOW;LowClockLDRR0,=0x4c000010LDRR1,=0x00000004STRR1,[R0];CLKDIVN;HCLK=FCLK/3PCLK=HCLK/2LDRR0,=0x4c000014LDRR1,=0x00000007STRR1,[R0];Uart0;Uart;LDRSP,=0x1000;LDRR2,=0x20800000;MOVR4,#0X7;STRBR4,[R2];BLuart_testMemsetup;SDRAMInitldrr1,=MEM_CTL_BASEadrlr2,mem_cfg_valaddr3,r1,#521ldrr4,[r2],#4strr4,[r1],#4cmpr1,r3bne%1nopnopnopnopMEM_CTL_BASEEQU0X48000000mem_cfg_valDCD0x22111110DCD0x00000700DCD0x00000700DCD0x00000700DCD0x00000700DCD0x00000700DCD0x00000700DCD0X00018005DCD0X00018005DCD0X008E0459DCD0X000000B1DCD0X00000030DCD0X00000030Nandflash;NandFlash,BootloaderCopyMyselfldrsp,=0x33ef0000IMPORTcopy_myself;nand_begin=0x0;size=0x20000;sdram_begin=0x33f00000BLcopy_myselfldrr1,=on_the_ramaddpc,r1,#0nopnopnopon_the_ram;SelectmodeIMPORTloadldrsp,=0x33ef0000BLuart_testBLsdram_testBLloadB.ENDCode:/*NANDFlashregisters2440*/#include"DataType.h"#include"stdio.h"#defineNFCONF(*(volatileunsignedint*)0x4e000000)#defineNFCONT(*(volatileunsignedint*)0x4e000004)#defineNFCMD(*(volatileunsignedchar*)0x4e000008)#defineNFADDR(*(volatileunsignedchar*)0x4e00000c)#defineNFDATA(*(volatileunsignedchar*)0x4e000010)#defineNFSTAT(*(volatileunsignedchar*)0x4e000020)#defineNFMECC0(*(volatileunsigned*)0x4E00002C)#defineNAND_CHIP_ENABLE(NFCONT&=~(1<<1))#defineNAND_CHIP_DISABLE(NFCONT|=(1<<1))#defineNAND_CLEAR_RB(NFSTAT|=(1<<2))#defineNAND_DETECT_RB{while(!(NFSTAT&(1<<0)));}/*在第一次实用NANDFlash前,复位一下NANDFlash*/#defineBUSY1#defineInitEcc()(NFCONT|=(1<<4))#defineMEccUnlock()(NFCONT&=~(1<<5))#defineMEccLock()(NFCONT|=(1<<5))#defineSEccUnlock()(NFCONT&=~(1<<6))#defineSEccLock()(NFCONT|=(1<<6))/*for8bitnandflash,onlyuseNFMECC0*/#defineRdNFMEcc()(NFMECC0)#defineNAND_SECTOR_SIZE512#defineNAND_BLOCK_MASK(NAND_SECTOR_SIZE-1)/*inlinevoidwait_idle(void){while(!(NFSTAT&BUSY));NFSTAT|=BUSY;}*/voidreset_nand(void){//inti=0;//NFCONF&=~0x800;//for(;i<10;i++);NFCONF=0x1400;NFCONT=0x73;NAND_CHIP_ENABLE;NFCMD=0xff;//resetcommandwhile(!(NFSTAT&BUSY));NFSTAT|=BUSY;}/*初始化NANDFlash*/voidinit_nand(void){NFCONT=0x73;NAND_CHIP_DISABLE;reset_nand();}/*lowlevelnandreadfunction*/intnand_read_ll(unsignedchar*buf,unsignedlongstart_addr,intsize){inti,j;if((start_addr&NAND_BLOCK_MASK)||(size&NAND_BLOCK_MASK)){return-1;/*invalidalignment*/}NAND_CHIP_ENABLE;for(i=start_addr;i<(start_addr+size);){/*READ0*/NAND_CLEAR_RB;NFCMD=0;/*WriteAddress*/NFADDR=i&0xff;NFADDR=(i>>9)&0xff;NFADDR=(i>>17)&0xff;NFADDR=(i>>25)&0xff;NAND_DETECT_RB;for(j=0;j<NAND_SECTOR_SIZE;j++,i++){*buf=(NFDATA&0xff);buf++;}}NAND_CHIP_DISABLE;return0;}intNandErase(unsignedlongstart_addr){if(start_addr&NAND_BLOCK_MASK){return-1;/*invalidalignment*/}NAND_CHIP_ENABLE;NAND_CLEAR_RB;NFCMD=0x60;NFADDR=(start_addr>>9)&0xff;NFADDR=(start_addr>>17)&0xff;NFADDR=(start_addr>>25)&0xff;NFCMD=0xd0;NAND_DETECT_RB;uart_printf("Erase0x%x\r",start_addr);NAND_CHIP_DISABLE;return0;}intnand_write_ll(unsignedchar*buf,unsignedlongstart_addr,intsize){inti,j,k;if((start_addr&NAND_BLOCK_MASK)||(size&NAND_BLOCK_MASK)){return-1;/*invalidalignment*/}for(k=0;k<=size/(16*1024);k++)NandErase(start_addr+(k*16*1024));NAND_CHIP_ENABLE;for(i=start_addr;i<(start_addr+size);){/*READ0*///if(k%32==0)NandErase(start_addr);NAND_CLEAR_RB;NFCMD=0x80;/*WriteAddress*/NFADDR=i&0xff;NFADDR=(i>>9)&0xff;NFADDR=(i>>17)&0xff;NFADDR=(i>>25)&0xff;for(j=0;j<NAND_SECTOR_SIZE;j++,i++){NFDATA=*buf;buf++;}NFCMD=0x10;NAND_DETECT_RB;}NAND_CHIP_DISABLE;return0;}voidcopy_myself(void){unsignedchar*buf=((unsignedchar*)0x33f00000);unsignedlongstart_addr=0;intsize=0x20000;reset_nand();init_nand();nand_read_ll(buf,start_addr,size);}Code:/**dip.c-dipapi&driver**Board:akae2440*environment:bootloader&ADS*Author:akaedu*Date:2009-5-26*web:***GPIOaddress_MAP**CPLD_MAP_BASEphysicaladdressis0x20800000*CPLD_LEDphysicaladdressis0x20800000*CPLD_SEGphysicaladdressis0x20800080*CPLD_DIPphysicaladdressis0x208000a0**GPIOport_MAP**GPA_PORT~GPB_PORT(130multi-functionalinputportpins)*GPIO_BASE:GPACON:0x56000000**NAMEGPIOCPLD_INCPLD_OUTGPIO_CONMODE_bit_CONGPIO_DATMODE_bit_DAT*BEEPGPB0TOUT0BEEP0x56000010[1:0]0x56000014[0]**GPIOkey_scn_MAP**NAMEPORT_OUTPORT_IN*KEY(sw1)KBOUT1:GPB8KBIN1:ENT0:GPF0*KEY(sw2)KBOUT0:GPB9KBIN1:ENT0:GPF0*KEY(sw3)KBOUT1:GPB8KBIN0:ENT2:GPF2*KEY(sw4)KBOUT1:GPB8KBIN1:ENT2:GPF2**GPIO_CONGPIO_DATGPIOMODE_bit_CONMODE_bit_DAT*GPBCON:0x56000010GPBDAT:0x56000014GPB8[17:16][8]*GPBCON:0x56000010GPBDAT:0x56000014GPB9[19:18][9]*GPFCON:0x56000050GPBDAT:0x56000054GPF0[1:0][0]*GPFCON:0x56000050GPBDAT:0x56000054GPF2[5:4][2]**/#include"dip.h"#include"seg7.h"#defineCPLD_DIP*((volatileunsignedchar*)0x208000a0)intdip_init(void){return0;}intdip_num(void){returnCPLD_DIP;}intdip_test(void){intdip_input;inti=5000000;seg7_init();dip_init();while(i--){dip_input=dip_num();seg7_display_num(dip_input);}return0;}Code:#include"uart.h"#include"shell.h"#include"stdlib.h"#include"stdio.h"#include"nand.h"#defineSEC3#defineLOAD_OS0#defineLOAD_SHELL1#defineOS_MEM_ADDR0x31000000#defineOS_ADDR(100*32*512)/*OSaddress*/#defineOS_SIZE0x20000/*MoveOStoSdramFromNandFlash*/voidos_test(void){unsignedchar*buf=(unsignedchar*)OS_MEM_ADDR;unsignedlongstart=OS_ADDR;intsize=OS_SIZE;uart_printf("\rcopyoprationsystemtothesdrmfromnanflash...\r");reset_nand();init_nand();nand_read_ll(buf,start,size);}/*WaitforUserEnterAnyKeytoLoginintheShellofBootloader*/intdelay_p(intsec){intosec=500000,i,j;uart_printf("Enteranykeytoloadintheshellofbootloader:%d",sec);for(i=0;i<sec;i++){for(j=0;j<osec;j++){if(UTRSTAT0&UTRSTAT_R_READY){uart_getchar();returnLOAD_SHELL;}}uart_printf("\b%d",sec-i);}//uart_printf("return");returnLOAD_OS;}/*ShellorOS*/voidload(void){intload_stat;if((load_stat=delay_p(SEC))==LOAD_OS){os_test();uart_printf("\rrunintheopritionsystem...\r");go((void*)OS_MEM_ADDR);}else{shell();}}Code:/**seg7.c-seg7api&driver**Board:akae2440*environment:bootloader&ADS*Author:akaedu*Date:2009-5-26*web:***GPIOaddress_MAP**CPLD_MAP_BASEphysicaladdressis0x20800000*CPLD_LEDphysicaladdressis0x20800000*CPLD_SEG7physicaladdressis0x20800080*CPLD_DIPphysicaladdressis0x208000a0**GPIOport_MAP**GPA_PORT~GPB_PORT(130multi-functionalinputportpins)*GPIO_BASE:GPACON:0x56000000**NAMEGPIOCPLD_INCPLD_OUTGPIO_CONMODE_bit_CONGPIO_DATMODE_bit_DAT*BEEPGPB0TOUT0BEEP0x56000010[1:0]0x56000014[0]**GPIOkey_scn_MAP**NAMEPORT_OUTPORT_IN*KEY(sw1)KBOUT1:GPB8KBIN1:ENT0:GPF0*KEY(sw2)KBOUT0:GPB9KBIN1:ENT0:GPF0*KEY(sw3)KBOUT1:GPB8KBIN0:ENT2:GPF2*KEY(sw4)KBOUT1:GPB8KBIN1:ENT2:GPF2**GPIO_CONGPIO_DATGPIOMODE_bit_CONMODE_bit_DAT*GPBCON:0x56000010GPBDAT:0x56000014GPB8[17:16][8]*GPBCON:0x56000010GPBDAT:0x56000014GPB9[19:18][9]*GPFCON:0x56000050GPBDAT:0x56000054GPF0[1:0][0]*GPFCON:0x56000050GPBDAT:0x56000054GPF2[5:4][2]**/#include"seg7.h"#include"shell.h"#defineCPLD_SEG7*((volatileunsignedchar*)0x20800080)/*delayforaboutonesecond*//*staticvoiddelay(inttime){inti,j;for(i=0;i<time;i++)for(j=0;j<500000;j++);}*/intseg7_init(void){CPLD_SEG7=0x0;return0;}/*displaynumberonseg7*/intseg7_display_num(intnum){CPLD_SEG7=1<<num;return0;}intseg7_test(void){inti;seg7_init();for(i=0;i<8;i++){seg7_display_num(i);delay(1);}return0;}Code:#include"shell.h"#include"uart.h"#include"stdlib.h"#include"stdio.h"#include"xmodem.h"#include"dip.h"#include"seg7.h"#include"nand.h"#defineSTART_ADDR0x30000000#defineEND_ADDR0x34000000#defineMAX_LINE256#defineCMD_NUM11#defineLED_NUM8#defineSTART_FLASH0x0#defineEND_FLASH0x40000000#defineSTART_MEM0x30000000#defineEND_MEM0x34000000#defineMAX_SIZE(END_MEM-START_MEM-0x20000)#defineLED_ADDR*((volatileunsignedint*)0x20800000)#defineGPB0*((volatileunsignedint*)0x56000010)#defineBEEP*((volatileunsignedint*)0x56000014)/*delay*/voiddelay(intsec){inti,j;for(i=0;i<sec;i++){for(j=0;j<500000;j++);}}structCMD{char*cmd_line;void(*fun)(void*);}cmd[CMD_NUM]={{"help",help},{"loadx",loadx},{"go",go},{"led_on",led_on},{"led_off",led_off},{"beep_test",beep_test},{"led_test",led_test},{"seg7_test",seg7_on},{"dip4_test",dip4_on},{"flash_load",flash_load},{"flash_write",flash_write},//{"flash_write",flash_write},};voidflash_load(void*arg){char*argv[4],*end;intflash_start,mem_start,size;argv[1]=arg;uart_printf("theargis%s\r",arg);if((end=found_ch(arg,''))==NULL){uart_printf("Uaseage1:<flash_load><flashaddress><sdramaddress><size>\r");return;}else{*end='\0';end++;}argv[2]=end;if((end=found_ch(end,''))==NULL){uart_printf("Uaseage2:<flash_load><flashaddress><sdramaddress><size>\r");return;}else{*end='\0';end++;}argv[3]=end;if((flash_start=my_atox(argv[1]))<START_FLASH||(mem_start=my_atox(argv[2]))<START_MEM||(size=my_atox(argv[3]))>MAX_SIZE||(mem_start+size)>END_MEM){uart_printf("AccessViolation:Pleasecheckyouraddress\r");uart_printf("flash_start=%x\rmem_start=%x\rsize=%x\r",flash_start,mem_start,size);}else{uart_printf("flash_start=%x\rmem_start=%x\rsize=%x\r",flash_start,mem_start,size);nand_read_ll((unsignedchar*)mem_start,flash_start,size);}}#if1voidflash_write(void*arg){char*argv[4],*end;intflash_start,mem_start,size;argv[1]=arg;uart_printf("theargis%s\r",arg);if((end=found_ch(arg,''))==NULL){uart_printf("Uaseage1:<flash_load><sdramaddress><flashaddress><size>\r");return;}else{*end='\0';end++;}argv[2]=end;if((end=found_ch(end,''))==NULL){uart_printf("Uaseage2:<flash_load><sdramaddress><flashaddress><size>\r");return;}else{*end='\0';end++;}argv[3]=end;if((flash_start=my_atox(argv[2]))<START_FLASH||(mem_start=my_atox(argv[1]))<START_MEM||(size=my_atox(argv[3]))>MAX_SIZE||(mem_start+size)>END_MEM){uart_printf("AccessViolation:Pleasecheckyouraddress\r");//reset_nand();//init_nand();uart_printf("flash_start=%x\rmem_start=%x\rsize=%x\r",flash_start,mem_start,size);}else{uart_printf("flash_start=%x\rmem_start=%x\rsize=%x\r",flash_start,mem_start,size);//reset_nand();//init_nand();nand_write_ll((unsignedchar*)mem_start,flash_start,size);}}#endifvoidloadx(void*argv){intargc;uart_printf("argvis%s\r",(char*)argv);if(argv!=NULL)argc=2;elseargc=1;if(found_ch(argv,'')!=NULL){uart_printf("Error:Usage<loadx><address>\r");}else{xmodem_receive(argc,argv);uart_printf("Success!");}return;}voidled_on(void*argv){/*test第3字节有效*///uart_printf("%dndledison\r",(int)argv+1);//LED_ADDR=0xff0000;LED_ADDR|=(1<<((int)argv+16));}voidled_off(void*argv){//uart_printf("%dndledisoff\r",(int)argv+1);LED_ADDR&=~(1<<((int)argv+16));}voidled_test(void*argv){inti,j;for(i=0;i<3;i++){for(j=0;j<LED_NUM;j++){led_on((void*)j);}delay(1);for(j=0;j<LED_NUM;j++){led_off((void*)j);}delay(1);}}voidbeep_test(void*argv){inti;GPB0|=0x1;for(i=0;i<3;i++){BEEP=0x1;delay(1);BEEP=0x0;delay(1);}}voidseg7_on(void*argv){seg7_test();}voiddip4_on(void*argv){dip_test();}voidhelp(void*argv){uart_printf("loadx-[address],downloadafiletotheborad\r");uart_printf("go-<address>,gototheaddrress\r");uart_printf("flash_load-<flashaddress><sdramaddress><size>,Movethecodetosdramfromnandflash\r");uart_printf("flash_write-<sdramaddress><flashaddress><size>,MovethecodetoNandflashfromsdram\r");uart_printf("led_on-<lednumber>,testled\r");uart_printf("led_off-<led_number>,test_led\r");uart_printf("led_test-testallled\r");uart_printf("beep_test-testbeep\r");uart_printf("seg7_test-testseg\r");uart_printf("dip4_test-testdip4,youhavetensecondtotestit\r\r");}voidgo(void*argv){intaddr=(int)argv;if(addr==0)addr=0x32000000;//void(*gt)(void)=(void(*)(void))addr;if(addr<START_ADDR||addr>END_ADDR){//return-1;}else{uart_printf("ingo\r");(*(void(*)(void))addr)();}}voidshellcmd(charbuf[]){char*start,*end,*argv=NULL;inti,i_argv;start=buf;if((end=found_ch(buf,''))!=NULL){*end='\0';argv=end+1;}//uart_printf("bufisbeforeis%s\r",buf);//uart_printf("thecommandis%s",start);//uart_printf("thecommandis%s",cmd[0]d_line);for(i=0;i<CMD_NUM;i++){if(my_strcmp(start,cmd[i]d_line)==0){if(i==3||i==4){i_argv=my_atoi(argv);//uart_printf("i_argvis%d\r",i_argv);(*cmd[i].fun)((void*)i_argv);}elseif(i==2){i_argv=my_atox(argv);//uart_printf("i_argvis%x\r",i_argv);(*cmd[i].fun)((void*)i_argv);}else{(*cmd[i].fun)((void*)argv);}break;}}if(i==CMD_NUM){uart_printf("Commandnotfound\r");}}voidshell(void){charbuf[MAX_LINE];while(1){uart_puts("\rT-BOOT#");uart_gets(buf);//uart_printf("\rgetthecommand\r");//uart_puts(buf);shellcmd(buf);}}Code:#include<stdarg.h>#include"stdlib.h"#include"uart.h"#include"stdio.h"voiduart_puts(char*str){while(*str!='\0'){uart_putchar(*str);str++;}}char*uart_gets(char*str){inti;if(str==NULL)returnstr;for(i=0;;i++){str[i]=uart_getchar();/*doshomthingwhen'\bisinput'*/if(str[i]=='\b'){if(i>0){uart_putchar('\b');i-=2;}else{i=-1;}}else{uart_putchar(str[i]);}if(str[i]=='\r'||str[i]=='\n'){str[i]='\0';break;}}returnstr;}voiduart_put_num(intnum,intpow){if(num!=0){uart_put_num(num/pow,pow);if(num%pow>9)uart_putchar((char)(num%pow-10)+'A');elseuart_putchar((char)(num%pow+'0'));}}voiduart_printf(constchar*str,...){va_listap;charc,ch;char*s;intnum;va_start(ap,str);while(c=*str++){if(c!='%'){uart_putchar(c);}else{c=*str++;switch(c){case'c':ch=va_arg(ap,int);uart_putchar((char)ch);break;case's':s=va_arg(ap,char*);uart_puts(s);break;case'd':num=va_arg(ap,int);uart_put_num(num,10);break;case'x':num=va_arg(ap,int);uart_put_num(num,16);break;default:uart_putchar(c);}}}va_end(ap);}Code:#include"stdlib.h"#include"stdio.h"intmy_strcmp(char*src,char*dst){if(src==NULL||dst==NULL)gotoexit;while(*src==*dst&&*src!='\0'&&*dst!='\0'){src++;dst++;}exit:return(*src-*dst);}char*found_ch(char*str,charch){if(str==NULL)gotoexit;while(*str!=ch&&*str!='\0'){str++;}exit:if(*str==ch)returnstr;elsereturnNULL;}intmy_strlen(char*str){char*p=str;if(str==NULL)gotoexit;while(*str!='\0'){str++;}exit:return(str-p);}intis_number(charch){if('0'<=ch&&ch<='9')return1;elsereturn0;}intpow(intnum,intpower){/*donotcareaboutoverflow*/intcount=1;while(power--){count*=num;}returncount;}intmy_atoi(char*str){intlen=my_strlen(str),i,count=0;//uart_printf("thestris%s\r",str);//uart_printf("len=%d\r",len);if(str==NULL)gotoexit;//if(*str=='0'&&(*(str+1)=='x'||*(str+1)=='X'))//str+=2;for(i=0;i<len;i++){if(!is_number(str[i]))gotoexit;count+=((str[i]-'0')*pow(10,len-i-1));}exit:returncount;}intmy_atox(char*str){intlen=my_strlen(str),i,count=0;//uart_printf("thestris%s\r",str);//uart_printf("len=%d\r",len);if(str==NULL)gotoexit;if(*str=='0'&&(*(str+1)=='x'||*(str+1)=='X')){str+=2;len-=2;}for(i=0;i<len;i++){if(!is_number(str[i]))gotoexit;count+=((str[i]-'0')*pow(16,len-i-1));//uart_printf("thecountis%x\r",count);}exit:returncount;}Code:/*UartDriveronS3C2440*//*Athor:tongxiaohua*//*Time:2009.12.27*/#include"uart.h"#include"stdlib.h"#include"stdio.h"#include"shell.h"/*InitUart0*/voiduart_init(void){ULCON0|=3;/*8N1*/UCON0=5;/*WorkFrequencySelectPCLK,themodeofrecive/sendselectpoll*/UTRSTAT0&=6;/*SetNullofrecive/sendBuffer*/UBRDIV0=26;/*(int)50000000/(115200*16)-1*/GPHCON=0xa0;/*SetF2,F3Function*/UFCON0=0;UMCON0=0;}/*PutabytetotheUart0*/voiduart_putchar(charch){while(!(UTRSTAT0&UTRSTAT_T_EMPTY));UTX0=ch;/*BackSpace*/if(ch=='\b'){while(!(UTRSTAT0&UTRSTAT_T_EMPTY));UTX0='';while(!(UTRSTAT0&UTRSTAT_T_EMPTY));UTX0='\b';}/*Enter*/if(ch=='\r'){while(!(UTRSTAT0&UTRSTAT_T_EMPTY));UTX0='\n';}}/*GetabytefromUart*/charuart_getchar(void){while(!(UTRSTAT0&UTRSTAT_R_READY));returnURX0;}/*TesttheUartisornotWorking*/voiduart_test(void){uart_init();uart_printf("\r\rWelecomtousemybootloader\rAuthor:tongxiaohua\rBoard:s3c2440\r");uart_printf("Time:2009.12.27\rCPU:Arm920T\rSRAM:4k\rSDRAM:32M\rNANDFLASH:64M\r");uart_printf("Uart0isworking...\r");}/*TesttheSdramisorNotWorking*/voidsdram_test(void){inttestnum=0x12345678;*((volatileunsignedint*)0x32000000)=testnum;testnum=*((volatileunsignedint*)0x32000000);if(testnum==0x12345678){//uart_printf("%x\r",testnum);uart_printf("sdramisworking...\r");//uart_printf("test...\r");}else{//uart_printf("testfaild\r");uart_printf("sdramworkingerror...\r",testnum);//uart_printf("test...\r");}}Code:#include"xmodem.h"/*这两个头文件是你已经实现的功能函数,下面*代码中用到的函数如不是xmodem.c中定义的,*需移植你已写好的函数接口到本程序中,如*uart0_getchar()、uart0_putchar()、*myprintf()等*/#include"stdio.h"#include"uart.h"#include"stdlib.h"/*globalerrorvariable*/char*xmodem_errtxt=NULL;intget_byte_err=0;U8volatilereceive_buffer[BLOCK_SIZE];//unsigneddownload_addr=0x8000;/*prototypesofhelperfunctions*/intget_record(void);enum{SAC_SEND_NAK=0,SAC_SENT_NAK=1,SAC_PAST_START_NAK=2};staticvolatileintseen_a_char=SAC_SEND_NAK;//staticintone_nak=0;//staticunsignedlongxmodem_timeout=GET_BYTE_TIMEOUT;chardebugbuf[4096];intdb_idx=0;staticvoiddelay(void){intj;for(j=0;j<2000090;j++);}intxmodem_receive(intargc,char*argv){charochr;intr=0,rx_block_num=0,error_count=0;intfoffset=0;inti;unsignedintdownload_addr;charnak=NAK;xmodem_errtxt=NULL;seen_a_char=0;uart_printf("inxmodemargc=%d,argv=%s\r",argc,argv);//if(argc>1)download_addr=atox(argv[1]);if(argc>1)download_addr=my_atox(argv);elsedownload_addr=0x32000000;uart_printf("download_addris%x,",download_addr);UART0_putchar('9');delay();UART0_putchar('8');delay();UART0_putchar('7');delay();UART0_putchar('6');delay();UART0_putchar('5');delay();UART0_putchar('4');delay();UART0_putchar('3');delay();UART0_putchar('2');delay();UART0_putchar('1');delay();UART0_putchar('0');//uart_putchar(UART0_BASE,nak);UART0_putchar(nak);rx_block_num=1;/*timestoretry*/error_count=RETRIES;do{/*whenlocalblocknumberequalstotheblocknumberinthepacket,storethedataintothememorywhichdownload_addrpoints*/if((r=get_record())==(rx_block_num&255)){error_count=RETRIES;for(i=0;i<BLOCK_SIZE;i++)*(U8*)(download_addr+foffset+i)=receive_buffer[i];
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 信阳师范大学《物理学史》2021-2022学年第一学期期末试卷
- 信阳师范大学《数据结构实验》2022-2023学年第一学期期末试卷
- 信阳师范大学《嵌入式系统原理与应用实验》2023-2024学年第一学期期末试卷
- 信阳师范大学《包装设计》2021-2022学年第一学期期末试卷
- 信阳师范大学《Python语言程序设计实验》2021-2022学年第一学期期末试卷
- 跨部门协作的工作安排计划
- 西南医科大学《卫生事业管理学》2023-2024学年第一学期期末试卷
- 长租公寓项目培训
- 西南交通大学《计算机辅助设计》2023-2024学年第一学期期末试卷
- 西华大学《设计基础》2022-2023学年第一学期期末试卷
- 输血不良反应报告表
- 高三英语写作专项道歉信 感谢信 投诉信课件
- 高中数学高级教师职称评审答辩题目
- 高净值个人财富管理税务风险与应对课件讲义
- 护工培训教学课件
- 医院个人岗位廉政风险排查登记表(空表)
- (精选)大学无机化学期末试卷及答案
- 糖尿病中医治疗及护理课件整理
- 初中数学北师大七年级上册第五章一元一次方程一元一次方程复习PPT
- 关于进一步加强建设工程施工合同管理的通知
- 《农产品质量安全》系列讲座课件
评论
0/150
提交评论