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

📄 board.c

📁 针对freescale的coldfire系列mcu的开源bootloader源码colilo的优化代码
💻 C
字号:
/* *  vendors/Motorola/M5249C3-1MB/board.c *  CoLiLo MCF5249 Development board port  * *  (C) Copyright April 2003, Jeremy Andrus <jeremy@jeremya.com> * */#include "arch.h"#include "mcfuart.h"#include "ledstate.h"char	ident[] = "Motorola MCF5249 C3 & EDA SAC BOARD";char	copyright[] = "(C) 2003, Jeremy Andrus <jeremy@jeremya.com>;2004 SAC BOARD support added ,also add support for flash programing, leeky <leeky_2000@hotmail.com>";extern unsigned int downloadPort;extern unsigned int image_size;extern unsigned char *xfer_addr;extern unsigned char *down_addr;extern unsigned char *dest_addr;extern unsigned char *source_addr;extern unsigned long consoleBase;void configureConsole();void configureAuxSerial();void setLED(int state);void setImageParams();void setupBoard();static int delay(int size);void setupDRAM();//void LEDboot();//#define	IMAGE_ADDR  0xff010000  /* colilo shouldn't be more than 32k */#define IMAGE_SIZE 0x001f0000   /* You really can't get any bigger than 1MB - 32 k :-) */#define XFER_ADDR 0x20000//#define DEFAULT_PORT 0#define DEFAULT_PORT 1void configureConsole(){	/** Note: The UART timer in the 5249 uses the bus clock (PSTCLK / 2) to generate the baud ***/	consoleBase = MCFUART_BASE1;	configureSerial(MCFUART_BASE1, 19200, MCF_BUSCLK); /* dBUG compliance: 19200 it is. */}void configureAuxSerial(){	configureSerial(MCFUART_BASE2, 115200, MCF_BUSCLK); /* This can be used for image transfers */}/*  *  State to LED mapping: *  The gpio pins 53,52,51,34,19,18,12,11,9 will serve as a nice boot-up state indicator  * */void setLED(int state){	/*  Note: LEDs asserted low  */	/*  M5249C3 Diode Layout	 *	 *  gpio | led | diode 	 *   19  |  0  |  13  	 *   18  |  1  |  14  	 *   34  |  2  |  15  	 *   11  |  3  |  16  	 *  ------------------	 *   12  |  4  |  17  	 *    9  |  5  |  18  	 *   53  |  6  |  19  	 *  ------------------	 *   52  |  7  |  20  	 *   51  |  8  |  21  	 *  ------------------	 *	 */	/* bits = gpio[31..0], bits1 = gpio[63..32] */	unsigned long bits, bits1;	/* boot (led[3..0]) indicates the major boot step */	switch(state) {	  case LED_STATUS_INIT:	    bits = 0xffffffff;	    bits1 = 0xffffffff;	    break;	  case LED_STATUS_MEM:	    bits = 0xfff7ffff;	    bits1 = 0xffffffff;	    break;	  case LED_STATUS_RUNTIME:	    bits = 0xfffbffff;	    bits1 = 0xffffffff;	    break;	  case LED_STATUS_UART:	    bits = 0xfff3ffff;	    bits1 = 0xffffffff;	    break;	  case LED_STATUS_UI:	    bits = 0xffffffff;	    bits1 = 0xfffffffb;	    break;	  case LED_STATUS_DLOAD:	    bits = 0xfff7ffff;	    bits1 = 0xfffffffb;	    break;	  case LED_STATUS_DDECOMPGO:	  case LED_STATUS_DDECOMPRESS:	    bits = 0xfffbffff;	    bits1 = 0xfffffffb;	    break;	  case LED_STATUS_RUNIMAGE:	    bits = 0xfff3ffff;	    bits1 = 0xfffffffb;	    break;	  /*	   *  This is a binary counter, so if we ever need more states	   *  they're right here :-)  ~Jeremy	   */	  /**********************	  case 8:	    bits = 0xfffff7ff;	    bits1 = 0xffffffff;	    break;	  case 9:	    bits = 0xfff7f7ff;	    bits1 = 0xffffffff;	    break;	  case 10:	    bits = 0xfffbf7ff;	    bits1 = 0xffffffff;	    break;	  case 11:	    bits = 0xfff3f7ff;	    bits1 = 0xffffffff;	    break;	  case 12:	    bits = 0xfffff7ff;	    bits1 = 0xfffffffb;	    break;	  case 13:	    bits = 0xfff7f7ff;	    bits1 = 0xfffffffb;	    break;	  case 14:	    bits = 0xfffbf7ff;	    bits1 = 0xfffffffb;	    break;	  ***********************/	  case LED_STATUS_ERROR:	    bits = 0xfff3f7ff;	    bits1 = 0xfffffffb;	    break;	  default:	    bits = 0xffffffff;	    bits1 = 0xffffffff;	    break;	}	switch (state) {	  case LED_STATUS_MEMPRECHARGE:	  case LED_STATUS_CS6:	  case LED_STATUS_COPYDATA:	    bits ^= 0x00001000;	    bits1 ^= 0x00000000;	    break;	  case LED_STATUS_MEMREFRESH:	  case LED_STATUS_CS5:	  case LED_STATUS_ZEROBSS:	    bits ^= 0x00000200;	    bits1 ^= 0x00000000;	    break;	  case LED_STATUS_MEMMRI:	  case LED_STATUS_CS4:	  case LED_STATUS_INITVEC:	    bits ^= 0x00001200;	    bits1 ^= 0x00000000;	    break;	  case LED_STATUS_CS3:	  case LED_STATUS_DECOMP1:	    bits ^= 0x00000000;	    bits1 ^= 0x00200000;	    break;	  case LED_STATUS_CS2:	  case LED_STATUS_DECOMP2:	    bits ^= 0x00001000;	    bits1 ^= 0x00200000;	    break;	  case LED_STATUS_CS1:	  case LED_STATUS_LOAD1:	    bits ^= 0x00000200;	    bits1 ^= 0x00200000;	    break;	  case LED_STATUS_CS0:	  case LED_STATUS_LOAD2:	    bits ^= 0x00001200;	    bits1 ^= 0x00200000;	    break;	  default:	    bits ^= 0x00000000;	    bits1 ^= 0x00000000;	    break;	}	switch (state) {  	  case LED_STATUS_ENSWT:	    bits1 ^= 0x00100000;	    break;	  case LED_STATUS_STARTIMG:	    bits1 ^= 0x00080000;	    break;	/** Kept this here to keep the binary counter 	  case 3:	    bits1 ^= 0x00180000;	    break;	**/	  default:	    bits1 ^= 0x00000000;	    break;	}	mbar2_writeLong(MCFSIM_GPIO_OUT, bits);    // Write the new LED config to the gpio pins	mbar2_writeLong(MCFSIM_GPIO1_OUT, bits1);}void setImageParams(){	downloadPort = DEFAULT_PORT;	image_size  = IMAGE_SIZE;	source_addr = (unsigned char *)IMAGE_ADDR;	//down_addr   = (unsigned char *)IMAGE_ADDR;	down_addr   = (unsigned char *)XFER_ADDR;	xfer_addr   = (unsigned char *)XFER_ADDR;	dest_addr   = (unsigned char *)XFER_ADDR;}void setupBoard(){	/* 	 *  Setup the PLL to run at the specified speed 	 *  	 */	volatile unsigned long cpll = mbar2_readLong(MCFSIM_PLLCR);  // Current PLL value	unsigned long pllcr;#ifdef __MCF_FAST_CLK__  	//pllcr = 0x125b8100;  // 140MHz clock (PLL bypass = 0)  	pllcr = 0x125fc160;	//120 #else 	pllcr = 0x135a4140;  // 70MHz clock (PLL bypass = 0)#endif	cpll = cpll & 0xfffffffe; 		  // Set PLL bypass mode = 0 (PSTCLK = crystal)	mbar2_writeLong(MCFSIM_PLLCR, cpll); 	  // Set the PLL to bypass mode (PSTCLK = crystal)	mbar2_writeLong(MCFSIM_PLLCR, pllcr);  	  // set the clock speed 	pllcr ^= 0x00000001; 		      	  // Set pll bypass to 1 	mbar2_writeLong(MCFSIM_PLLCR, pllcr);  	  // Start locking (pll bypass = 1)			/*	 *  Turn off the two LEDs that are on by default: D18, D19	 *  We will start flashing LEDs in just a minute ;-)	  	 *    These are on GPIO pins on the 5349C3 board	 *  	 *  NOTE: by setting the GPIO_FUNCTION registers, we ensure that the UART pins	 *        (UART0: gpio 30,27, UART1: gpio 31, 28) will be used as UART pins 	 *        which is their primary function.	 *        ~Jeremy	 */	mbar2_writeLong(MCFSIM_GPIO_FUNC, 0x000C1A80);   // Enable gpio pins: 19,18,112,11,9 (LEDs) and 7?	mbar2_writeLong(MCFSIM_GPIO1_FUNC, 0x00380004);  // Enable gpio pins: 53,52,51,34 (LEDs)	mbar2_writeLong(MCFSIM_GPIO_EN, 0x000C1A00);     // Map the pins to the corresponding gpio	mbar2_writeLong(MCFSIM_GPIO1_EN, 0x00380004);    	setLED(LED_STATUS_INIT); // Actualy clear the LEDs: Starting up . . . 	/* 	 *  dBug Compliance:	 *    You can verify these values by using dBug's 'ird' 	 *    (Internal Register Display) command	 *    ~Jeremy	 * 	 */	mbar_writeByte(MCFSIM_MPARK, 0x30);    // 5249 Internal Core takes priority over DMA 	mbar_writeByte(MCFSIM_SYPCR, 0x00);	mbar_writeByte(MCFSIM_SWIVR, 0xF0);	mbar_writeByte(MCFSIM_SWSR, 0x00);	mbar_writeLong(MCFSIM_IMR, 0xFFFFFBFF);	mbar_writeByte(MCFSIM_SWDICR, 0x00);	mbar_writeByte(MCFSIM_TIMER1ICR, 0x00);	mbar_writeByte(MCFSIM_TIMER2ICR, 0x88);	mbar_writeByte(MCFSIM_I2CICR, 0x00);	mbar_writeByte(MCFSIM_UART1ICR, 0x00);	mbar_writeByte(MCFSIM_UART2ICR, 0x00);	mbar_writeByte(MCFSIM_ICR6, 0x00);	mbar_writeByte(MCFSIM_ICR7, 0x00);	mbar_writeByte(MCFSIM_ICR8, 0x00);	mbar_writeByte(MCFSIM_ICR9, 0x00);	mbar_writeByte(MCFSIM_QSPIICR, 0x00);	mbar2_writeByte(MCFSIM_INTBASE, 0x40);  // Base interrupts at 0x40 		/*	 *  Setup chip selects...	 */	/* XXX - Setup the IDE (CS2 and CS3) interface */	setLED(LED_STATUS_CS1);	/* CS1 - SMSC LAN91C111 ethernet, address 0xe0000000 */	mbar_writeLong(MCFSIM_CSAR1,0xe0000000);	mbar_writeLong(MCFSIM_CSCR1, 0x00001180);  // WS=0100 (4 wait states), AA=1, PS=10 (16bit port)	mbar_writeLong(MCFSIM_CSMR1, 0x00000021);  // , WP=0, C/I=1, V=1	setLED(LED_STATUS_CS0);	/* CS0 - AMD Flash */	mbar_writeLong(MCFSIM_CSAR0,0xff000000);	mbar_writeLong(MCFSIM_CSCR0, 0x00001180);  // WS=0100 (4 wait states), AA=1, PS=10 (16bit port)		/** Note: There is a CSMR0/DRAM vector problem, need to disable C/I ***/	mbar_writeLong(MCFSIM_CSMR0, 0x001f0021);  // 1MB of flash (the bottom half), WP=0, C/I=1, V=1                }static int delay(int size){	int i;	for (i = 0; (i < size); i++)	  nop();}/* *  SDRAM is pretty confusing.  *  Please read _all_ the docs before meddling with this code :-) *	~Jeremy */void setupDRAM(){	volatile unsigned char *mbar = (unsigned char *)MCF_MBAR;	unsigned long	junk = 0xbeaddeed;	/* 	 *  Note: 	 *	RC = ([(RefreshTime/#rows) / (1/BusClk)] / 16) - 1	 */#ifdef __MCF_FAST_CLK__	// Busclk=70MHz, RefreshTime=64ms, #rows=4096 (4K)	// SO=1, NAM=0, COC=0, RTIM=01 (6clk refresh), RC=43 (1093 bus clock cycles)	mbar_writeShort(MCFSIM_DCR, 0x8243);  #else	// Busclk=32MHz, RefreshTime=64ms, #rows=4096 (4K)	// SO=1, NAM=0, COC=0, RTIM=01 (6clk refresh), RC=1e (500 bus clock cycles)	mbar_writeShort(MCFSIM_DCR, 0x821e);  #endif	// SDRAM starts at 0x0000_0000, CASL=10, CBM=010, PS=10 (16bit port), PM=1 (continuous page mode)	// RE=0 (keep auto-refresh disabled while setting up registers)	mbar_writeLong(MCFSIM_DACR0, 0x00002224);  	// BAM=007c (bits 22,21 are bank selects; 256kB blocks)	mbar_writeLong(MCFSIM_DMR0, 0x00fc0001);	setLED(LED_STATUS_MEMPRECHARGE);	/** Precharge sequence - set DACR0[IP] (aka bit 3)   Note: init. precharge twice ~Jeremy **/	mbar_writeLong(MCFSIM_DACR0, 0x0000222c);	*((volatile unsigned long *) 0x200) = junk; // write to a memory location to init. precharge	delay(0x01);	mbar_writeLong(MCFSIM_DACR0, 0x0000222c);	*((volatile unsigned long *) 0x200) = junk;	delay(0x01);	setLED(LED_STATUS_MEMREFRESH);	/** Refresh Sequence **/	// Enable the refresh bit, DACR0[RE} (bit 15)	mbar_writeLong(MCFSIM_DACR0, 0x0000b224);	delay(0x10);	setLED(LED_STATUS_MEMMRI);	/** Mode Register initialization **/	mbar_writeLong(MCFSIM_DMR0, 0x00080001);  // Mask bit 19 of the address	mbar_writeLong(MCFSIM_DACR0, 0x0000b264);  // Enable DACR0[IMRS] (bit 6); RE remains enabled	*((volatile unsigned long *) 0x800) = 0x00000000; // Access RAM to initialize the mode register	delay(0x10);	mbar_writeLong(MCFSIM_DACR0, 0x0000b224);  // Reset DACR0	delay(0x10);	mbar_writeLong(MCFSIM_DMR0, 0x00fc0001);  // Reset DMR0	delay(0x10);}// LED boot indication void LEDboot(int signal){	switch(signal){	case 1:		{setLED(LED_STATUS_MEM);}//delay(0xF0000);}		break;			case 2:		{setLED(LED_STATUS_RUNTIME);}//delay(0xF0000);}		break;	case 3:		{setLED(LED_STATUS_UI);}//delay(0xF0000);}		break;				default:		break;		}}

⌨️ 快捷键说明

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