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

📄 main.c

📁 基于AT91SAM9260的bootloader
💻 C
📖 第 1 页 / 共 2 页
字号:
/*---------------------------------------------------------------------------- *         ATMEL Microcontroller Software Support  -  ROUSSET  - *---------------------------------------------------------------------------- * The software is delivered "AS IS" without warranty or condition of any * kind, either express, implied or statutory. This includes without * limitation any warranty or condition with respect to merchantability or * fitness for any particular purpose, or against the infringements of * intellectual property rights of others. *---------------------------------------------------------------------------- * File Name           : main.c * Object              :  * Creation            : HIi   19/05/2005 *---------------------------------------------------------------------------- */#include "main.h"#include "dataflash.h"#include "com.h"#include "stdio.h"#define AT91C_BOOT_ADDR 			0x23F00000#define AT91C_BOOT_SIZE 			128*1024#define AT91C_BOOT_DATAFLASH_ADDR 	0xC0008000#define AT91C_DELAY_TO_BOOT 		2 // number of seconds#define DISP_LINE_LEN 				16/* prototypes */extern void Jump(unsigned int addr);extern void AT91F_RTT_ASM_HANDLER(void);static const char menu_separ[] = {	"*--------------------------------------*\n\r"};static const char *menu_dataflash[] = {	"1: Read Dataflash [addr]\r",	"2: Start UBOOT [C0008000 => 20000000]\r",	"3: Test DataFlash\r"};char message[40];int boot=0;char command = 0;//*--------------------------------------------------------------------------------------//* Function Name       : GetTickCount()//* Object              : Return the number of systimer tick //* Input Parameters    ://* Output Parameters   ://*--------------------------------------------------------------------------------------*/unsigned int GetTickCount(void){	return AT91C_BASE_RTTC -> RTTC_RTVR;}//*-----------------------------------------------------------------------------//* Function Name       : AT91F_DisplayMenu()//* Object              : //* Input Parameters    : //* Return value		: //*-----------------------------------------------------------------------------*/void AT91F_DisplayMenu(void){	AT91F_ClrScr();	printf("\n\rATMEL DataFlash LOADER %s %s %s\n\r",AT91C_VERSION,__DATE__,__TIME__);	puts(menu_separ);		AT91F_DataflashPrintInfo();	puts(menu_separ);	puts(menu_dataflash[0]);	puts(menu_dataflash[1]);	puts(menu_dataflash[2]);	puts(menu_separ);	}	//*-----------------------------------------------------------------------------//* Function Name       : AsciiToHex()//* Object              : ascii to hexa conversion//* Input Parameters    : //* Return value		: //*-----------------------------------------------------------------------------*/static unsigned int AsciiToHex(char *s, unsigned int *val){	int n;	*val=0;		if(s[0] == '0' && ((s[1] == 'x') || (s[1] == 'X')))		s+=2;	n = 0;		while((n < 8) && (s[n] !=0))	{		*val <<= 4;		if ( (s[n] >= '0') && (s[n] <='9'))			*val += (s[n] - '0');		else				if ((s[n] >= 'a') && (s[n] <='f'))				*val += (s[n] - 0x57);			else				if ((s[n] >= 'A') && (s[n] <='F'))					*val += (s[n] - 0x37);			else				return 0;		n++;	}	return 1;				}//*-----------------------------------------------------------------------------//* Function Name       : AT91F_MemoryDisplay()//* Object              : Display the content of the dataflash//* Input Parameters    : //* Return value		: //*-----------------------------------------------------------------------------*/static int AT91F_MemoryDisplay(unsigned int addr, unsigned int size,                               unsigned int length){	unsigned long	i, nbytes, linebytes;	char	*cp;	unsigned int 	*uip;	unsigned short 	*usp;	unsigned char 	*ucp;	char linebuf[DISP_LINE_LEN];	nbytes = length * size;   	do   	{   		uip = (unsigned int *)linebuf;   		usp = (unsigned short *)linebuf;		ucp = (unsigned char *)linebuf;				printf("%08x:", addr);		linebytes = (nbytes > DISP_LINE_LEN)?DISP_LINE_LEN:nbytes;                 		read_dataflash(addr, (linebytes/size)*size, linebuf);		for (i=0; i<linebytes; i+= size)		{			if (size == 4) 				printf(" %08x", *uip++);			else if (size == 2)				printf(" %04x", *usp++);			else				printf(" %02x", *ucp++);			addr += size;		}		printf("    ");		cp = linebuf;		for (i=0; i<linebytes; i++) {			if ((*cp < 0x20) || (*cp > 0x7e))				printf(".");			else				printf("%c", *cp);			cp++;		}		printf("\n\r");		nbytes -= linebytes;	} while (nbytes > 0);	return 0;}//*--------------------------------------------------------------------------------------//* Function Name       : AT91F_ResetRegisters//* Object              : Restore the initial state to registers//* Input Parameters    ://* Output Parameters   ://*--------------------------------------------------------------------------------------*/#if 0static unsigned int AT91F_ResetRegisters(void){	volatile int i = 0;	/* set the PIOs in input*/	*AT91C_PIOA_ODR = 0xFFFFFFFF;	/* Disables all the output pins */	*AT91C_PIOA_PER = 0xFFFFFFFF;	/* Enables the PIO to control all the pins *///	AT91F_AIC_DisableIt (AT91C_BASE_AIC, AT91C_ID_SYS);	/* close all peripheral clocks */	AT91C_BASE_PMC->PMC_PCDR = 0xFFFFFFFC;	/* Disable core interrupts and set supervisor mode */    {__asm("MSR CPSR_c, #0xDF");	/* ARM_MODE_SYS(0x1F) | I_BIT(0x80) | F_BIT(0x40) */    }	/* Clear all the interrupts */	*AT91C_AIC_ICCR = 0xffffffff;	/* read the AIC_IVR and AIC_FVR */	i = *AT91C_AIC_IVR;	i = *AT91C_AIC_FVR;	/* write the end of interrupt control register */	*AT91C_AIC_EOICR	= 0;	return 1;}#endifstatic void AT91F_StartBoot(unsigned int dummy, void *pvoid){	volatile unsigned int SizeToDownload = 0x30000;	volatile unsigned int AddressToDownload = AT91C_BOOT_ADDR;	printf("\n\rLoad UBOOT from dataflash[%x] to SDRAM[%x]\n\r",	       AT91C_BOOT_DATAFLASH_ADDR, AT91C_BOOT_ADDR);	if (read_dataflash(AT91C_BOOT_DATAFLASH_ADDR, SizeToDownload + 8,	                   (char *)AddressToDownload) != AT91C_DATAFLASH_OK)	{		printf("Read Dataflash failed\n\r");		return;	}	printf("PLLA[200MHz], MCK[100Mhz] ==> Start UBOOT\n\r");	Jump(AT91C_BOOT_ADDR);}//*--------------------------------------------------------------------------------------//* Function Name       : RTT_Handler//* Object              : Set an alarm//* Input Parameters    : N_seconde //* Output Parameters   : none//*--------------------------------------------------------------------------------------void AT91F_RTT_HANDLER(void){	unsigned int sr = AT91C_BASE_RTTC -> RTTC_RTSR;	sr = sr;	AT91C_BASE_RTTC -> RTTC_RTMR &= ~AT91C_RTTC_ALMIEN; //disable Alarm Interrupt	AT91C_BASE_RTTC -> RTTC_RTAR = 0xffffffff;			//max alarm value	AT91F_AIC_DisableIt(AT91C_BASE_AIC, AT91C_ID_SYS);	//disable SYS Interrupt	AT91F_StartBoot(0, NULL);	//command = 2; //AT91F_StartBoot}//*--------------------------------------------------------------------------------------//* Function Name       : Program_RTT_Alarm//* Object              : Set an alarm//*--------------------------------------------------------------------------------------void Program_RTT_Alarm (int N_seconde){	volatile int Read_Reg_u32;	while (((Read_Reg_u32 = AT91C_BASE_RTTC -> RTTC_RTSR) & AT91C_RTTC_ALMS) != 0); // To clear any alarm	Read_Reg_u32 = AT91C_BASE_RTTC -> RTTC_RTVR; // Rd current time	  	AT91C_BASE_RTTC -> RTTC_RTAR = (Read_Reg_u32 + N_seconde - 1); // Set alarm to N second	  

⌨️ 快捷键说明

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