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

📄 sci_boot.c

📁 一个很全面的TMS320F2812的最小系统的工程
💻 C
字号:
//###########################################################################
//
// FILE: SCI_Boot.c
//
// TITLE: F2810/12 SCI Boot mode routines
//
// Functions:
//
// ui32 SCI_Boot(void)
// inline void SCIA_GPIOSelect(void)
// inline void SCIA_SysClockEnable(void)
// inline void SCIA_Init(void)
// inline void SCIA_AutobaudLock(void)
// inline ui16 SCIA_CheckKeyVal(void)
// inline void SCIA_ReservedFn(void)
// ui32 SCIA_GetLongData(void)
// ui32 SCIA_GetWordData(void)
// void SCIA_CopyData(void)
//
// Notes:
//
//###########################################################################
//
// Ver | dd mmm yyyy | Who | Description of changes
// =====|=============|==============|=======================================
// 1.0 | 12 Mar 2002 | LH | PG Release.
// | | |
//###########################################################################
#include "cpu\registers.h"
#include "f2812_boot.h"
// Private functions
inline void SCIA_GPIOSelect(void);
inline void SCIA_Init(void);
inline void SCIA_AutobaudLock(void);
inline ui16 SCIA_CheckKeyVal(void);
inline void SCIA_ReservedFn(void);
inline void SCIA_SysClockEnable(void);
ui32 SCIA_GetLongData(void);
ui16 SCIA_GetWordData(void);
void SCIA_CopyData(void);
// Data section where SCIA control registers
// reside
//#pragma DATA_SECTION(SciaRegs,".SciaRegs");
//volatile struct SCI_REGS SciaRegs;
//#pragma DATA_SECTION(GPIOMuxRegs,"GpioMuxRegsFile");
//volatile struct GPIO_MUX_REGS GPIOMuxRegs;
//#pragma DATA_SECTION(SciaRegs,"SciaRegsFile");
//volatile struct SCI_REGS SciaRegs;

//kickdog
void sKickDog(void)
{
    EALLOW;
    SysCtrlRegs.WDKEY = 0x0055;
    SysCtrlRegs.WDKEY = 0x00AA;
    EDIS;
}
//#################################################
// ui32 SCI_Boot(void)
//––––––––––––––––––––––––––––––––––––––––––––
// This module is the main SCI boot routine.
// It will load code via the SCI-A port.
//
// It will return a entry point address back
// to the InitBoot routine which in turn calls
// the ExitBoot routine.
//––––––––––––––––––––––––––––––––––––––––––––
ui32 SCI_Boot()
{
	ui32 EntryAddr;
	ui16 ErrorFlag;
	
	//sKickDog();	//lg/040616
	//SCIA_SysClockEnable();
	//SCIA_GPIOSelect();
	SCIA_Init();
	SCIA_AutobaudLock();
	// If the KeyValue was invalid, abort the load
	// and return the flash entry point.
	ErrorFlag = SCIA_CheckKeyVal();
	if (ErrorFlag == ERROR) return FLASH_ENTRY_POINT; //to be modified
	SCIA_ReservedFn();
	EntryAddr = SCIA_GetLongData();
	SCIA_CopyData();
	return EntryAddr;
}
//#################################################
// void SCIA_GPIOSelect(void)
//––––––––––––––––––––––––––––––––––––––––––
// Enable pins for the SCI-A module for SCI
// peripheral functionality.
//––––––––––––––––––––––––––––––––––––––––––
inline void SCIA_GPIOSelect()
{
	EALLOW;
	GpioMuxRegs.GPFMUX.all = 0x0030;
	EDIS;
}
//#################################################
// void SCIA_Init(void)
//––––––––––––––––––––––––––––––––––––––––––––––
// Initialize the SCI-A port for communications
// with the host.
//––––––––––––––––––––––––––––––––––––––––––––––
inline void SCIA_Init()
{
	// Enable FIFO reset bit only
	SciaRegs.SCIFFTX.all=0x8000;
	// 1 stop bit, No parity, 8-bit character
	// No loopback
	SciaRegs.SCICCR.all = 0x0007;
	// Enable TX, RX, Use internal SCICLK
	SciaRegs.SCICTL1.all = 0x0003;
	// Disable RxErr, Sleep, TX Wake,
	// Diable Rx Interrupt, Tx Interrupt
	SciaRegs.SCICTL2.all = 0x0000;
	// Relinquish SCI-A from reset
	SciaRegs.SCICTL1.all = 0x0023;
	return;
}
//#################################################
// void SCIA_AutobaudLock(void)
//––––––––––––––––––––––––––––––––––––––––––––––––
// Perform autobaud lock with the host.
// Note that if autobaud never occurs
// the program will hang in this routine as there
// is no timeout mechanism included.
//––––––––––––––––––––––––––––––––––––––––––––––––
inline void SCIA_AutobaudLock()
{
	ui16 byteData;
	// Must prime baud register with >= 1
	SciaRegs.SCILBAUD = 1;
	SciaRegs.SCIHBAUD = 0;	//lg/040616
	// Prepare for autobaud detection
	// Set the CDC bit to enable autobaud detection
	// and clear the ABD bit
	SciaRegs.SCIFFCT.all = 0x6000;// the original 0x2000 is wrong;
	// Wait until we correctly read an
	// ’A’ or ’a’ and lock
	while(SciaRegs.SCIFFCT.bit.ABD != 1) {}
	// After autobaud lock, clear the CDC bit
	SciaRegs.SCIFFCT.bit.CDC = 0;
	while(SciaRegs.SCIRXST.bit.RXRDY != 1) { }
	byteData = SciaRegs.SCIRXBUF.bit.RXDT;
	SciaRegs.SCITXBUF = byteData;
	return;
}
//#################################################
// ui16 SCIA_CheckKeyVal(void)
//–––––––––––––––––––––––––––––––––––––––––––––––––
// The header of the datafile should have a proper
// key value of 0x08 0xAA. If it does not, then
// we either have a bad data file or we are not
// booting properly. If this is the case, return
// an error to the main routine.
//–––––––––––––––––––––––––––––––––––––––––––––––––
inline ui16 SCIA_CheckKeyVal()
{
	ui16 wordData;
	wordData = SCIA_GetWordData();
	if(wordData != EIGHT_BIT_HEADER) return ERROR;
	// No error found
	return NO_ERROR;
}
//#################################################
// void SCIA_ReservedFn(void)
//–––––––––––––––––––––––––––––––––––––––––––––––––
// This function reads 8 reserved words in the header.
// None of these reserved words are used by the
// SCI boot loader at this time, they may be used in
// future devices for enhancments.
//–––––––––––––––––––––––––––––––––––––––––––––––––
inline void SCIA_ReservedFn()
{
	ui16 i;
	// Read and discard the 8 reserved words.
	for(i = 1; i <= 8; i++)
	{
		SCIA_GetWordData();
	}
	return;
}
//#################################################
// ui32 SCIA_GetLongData(void)
//–––––––––––––––––––––––––––––––––––––––––––––––
// This routine fetches two words from the SCI-A
// port and puts them together to form a single
// 32-bit value. It is assumed that the host is
// sending the data in the form MSW:LSW.
//–––––––––––––––––––––––––––––––––––––––––––––––
ui32 SCIA_GetLongData()
{
	ui32 longData = (ui32)0x00000000;
	// Fetch the upper 1/2 of the 32-bit value
	longData = ( (ui32)SCIA_GetWordData() << 16);
	// Fetch the lower 1/2 of the 32-bit value
	longData |= (ui32)SCIA_GetWordData();
	return longData;
}
//#################################################
// ui16 SCIA_GetWordData(void)
//–––––––––––––––––––––––––––––––––––––––––––––––
// This routine fetches two bytes from the SCI-A
// port and puts them together to form a single
// 16-bit value. It is assumed that the host is
// sending the data in the order LSB followed by MSB.
//–––––––––––––––––––––––––––––––––––––––––––––––
ui16 SCIA_GetWordData()
{
	ui16 wordData;
	ui16 byteData;
	wordData = 0x0000;
	byteData = 0x0000;
	// Fetch the LSB and verify back to the host
	while(SciaRegs.SCIRXST.bit.RXRDY != 1) { }
	wordData = (ui16)SciaRegs.SCIRXBUF.bit.RXDT;
	SciaRegs.SCITXBUF = wordData;
	// Fetch the MSB and verify back to the host
	while(SciaRegs.SCIRXST.bit.RXRDY != 1) { }
	byteData = (ui16)SciaRegs.SCIRXBUF.bit.RXDT;
	SciaRegs.SCITXBUF = byteData;
	// form the wordData from the MSB:LSB
	wordData |= (byteData << 8);
	return wordData;
}
//#################################################
// void SCIA_CopyData(void)
//–––––––––––––––––––––––––––––––––––––––––––––––––––––
// This routine copies multiple blocks of data from the host
// to the specified RAM locations. There is no error
// checking on any of the destination addresses.
// That is it is assumed all addresses and block size
// values are correct.
//
// Multiple blocks of data are copied until a block
// size of 00 00 is encountered.
//
//–––––––––––––––––––––––––––––––––––––––––––––––––––––
void SCIA_CopyData()
{
	struct HEADER {
		ui16 BlockSize;
		ui32 DestAddr;
	} BlockHeader;
	ui16 wordData;
	ui16 i;
	// Get the size in words of the first block
	BlockHeader.BlockSize = SCIA_GetWordData();
	// While the block size is > 0 copy the data
	// to the DestAddr. There is no error checking
	// as it is assumed the DestAddr is a valid
	// memory location
	while(BlockHeader.BlockSize != (ui16)0x0000)
	{
		BlockHeader.DestAddr = SCIA_GetLongData();
		for(i = 1; i <= BlockHeader.BlockSize; i++)
		{
			wordData = SCIA_GetWordData();
			*(ui16 *)BlockHeader.DestAddr++ = wordData;
		}
		// Get the size of the next block
		BlockHeader.BlockSize = SCIA_GetWordData();
	}
	return;
}
//#################################################
// inline void SCIA_SysClockEnable(void)
//–––––––––––––––––––––––––––––––––––––––––––––––––––––
// This routine enables the clocks to the SCIA Port.
//–––––––––––––––––––––––––––––––––––––––––––––––––––––
inline void SCIA_SysClockEnable()
{
	EALLOW;
	SysCtrlRegs.PCLKCR.bit.SCIENCLKA=1;
	SysCtrlRegs.LOSPCP.all = 0x0002;
	EDIS;
}

⌨️ 快捷键说明

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