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

📄 bootloader.c

📁 Hardware and firmware for a DSP based digital audio MP3 player with USB pen drive funtionality, usin
💻 C
字号:
/*
 * DSPdap-bootloader - DSP based Digital Audio Player, Bootloader
 * Copyright (C) 2004-2007 Roger Quadros <rogerquads @ yahoo . com>
 * http://dspdap.sourceforge.net
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * $Id: bootloader.c,v 1.2 2007/06/03 08:54:03 Roger Exp $
 */

#include <csl.h>
#include <csl_mcbsp.h>
#include <csl_dma.h>
#include <csl_pll.h>
#include <csl_usb.h>

#include "IO.h"
#include "FAT32.h"
#include "file.h"

void bootload();

void main(int argc, char *argv[])
{
	PLL_Config	pllConfig = {
					0,	/*iai*/
					0,	/*iob*/
					14,	/*PLLMULT*/	//168MHz
					0,	/*DIV*/
				};
	CSL_init();
	LED_off();
//----------configure CompactFlash interface------
	config_EMIF();
	CF_HardReset();
	
//-----------configure PLLs------------------------
	//Configure PLL
	PLL_config(&pllConfig);
	//set CLKOUT pin to 12MHz for AIC
	
	//write a value that is half of PLLMULT into SYSREG:CLKDIV so that
	//the frequency on CLKOUT pin remains equal to CLKIN i.e. 12MHz.
	//e.g. if PLLMULT is 14 then write 7.
	//only a value between 0 and 7 can be written to SYSREG:CLKDIV
	asm("	MOV #7h, port(#07FDh)");		
//---------------------------------------------------

	bootload();
	//if bootload returns then there was an error
	//so halt
	while(1);
}

//returns a big-endian 32-bit word from a byte offset in a given buffer
UI32 GetBE32BitWord(UI* buffer, int byteOffset)
{
	UI32 lword;
	
	lword = Get8BitWord(buffer, 1)<<8;
	lword |= Get8BitWord(buffer, 0);
	lword <<= 8;
	lword |= Get8BitWord(buffer,3);
	lword <<= 8;
	lword |= Get8BitWord(buffer, 2);
	return lword;
}


//globals

Uns buffer[5];
FILE *fp;
UI32 gEntryPointAddr;

/* Filename of the firmware file to be booted */
char filePath[] = "firmwar.bin";


void jump(UI32 addr)
{
	//addr is in AC0
	asm("	B AC0");	//jump to address in AC0
}


void bootload()
{
	UI32 sectionSize;
	UI32 sectionStartAddr;
	UI32 regConfigCount;
	UI16 *sectionPtr;

	
	if(FAT32_GetFAT32Details())
	{
		while(1);
	}

	fp = fopen(filePath);

	if(fp == 0)
	{
		while(1);
	}

	//read entry point
	fread(fp, buffer, 2);
	gEntryPointAddr = GetBE32BitWord(buffer, 0);

	//read register configuration count
	fread(fp, buffer, 2);
	regConfigCount = GetBE32BitWord(buffer, 3);
	//register config .currently not supported so we skip those values
	fread(fp, buffer, regConfigCount*2);

	while(1)
	{
		//read section size in bytes
		if(fread(fp, buffer, 2) != 2)
		{
			break;
		}
		sectionSize = GetBE32BitWord(buffer, 3);


		if(sectionSize == 0)
		{
			asm("	BSET INTM");	//disable interrupts
			LED_on();				//indicate bootload complete
			jump(gEntryPointAddr);
			break;
		}

		//read section start addr
		if(fread(fp, buffer, 2) != 2)
		{
			break;
		}
		sectionStartAddr = GetBE32BitWord(buffer, 3);

		//get section size into number of words
		sectionSize /= 2;
		//get section start address to word address
		sectionStartAddr /= 2;

		sectionPtr = (UI16*)sectionStartAddr;
		if(fread(fp, sectionPtr, sectionSize) != sectionSize)
		{
			break;
		}
	}

}

⌨️ 快捷键说明

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