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

📄 fbtc55.c

📁 5509A烧写flash的bootloader启动程序
💻 C
字号:
 /*********************************************************************
 *          (C) COPYRIGHT TEXAS INSTRUMENTS, INC. 2000, 2001
 * FBTC55.c -- Main Loop and global utility funcs for
 *             55x FlashBurn FBTC
 ********************************************************************/

/* Change Log:
 */
/*
 * $Log: FBTC55.c,v $
 * Revision 1.5  2001/06/27 17:55:14  heeschen
 * v00.32 Beta Prep
 * Capturing all files to prepare for Beta Release
 *
 * Revision 1.4  2001/04/19 18:56:50  heeschen
 * v00.30 Alpha - Updated comments
 *
 *
 */

#include <stdio.h>
#include "fbtc55.h"
#include "fbcmd.h"
#include "flash.h"


// add by mark
#include <csl.h>
#include <csl_pll.h>
#include <csl_emif.h>
#include <csl_chip.h>


/* Local Prototypes
 */


/* -------------
 * Globals
 * -------------
 */
/* The message must be global; Host will use
 * its address for sending and receiving
 * messages.
 * This program reads what's in the message block
 * and processes it. When done processing,
 * this program will store any response data back
 * into the same block.
 */
u16 theMessage[1+ARGSIZEWORDS+MAXDATAWORDS] = {0}; // the latest message from Host

/* This function must be global; Host will
 * set a breakpoint on it.
 * When this program hits the breakpoint,
 * host will detect the halt and process
 * any response info that may be in the message
 * block. When Host wants to send a message
 * to this FBTC, it will store
 * the message into the global message block
 * and start this FBTC running.
 */
void doMessageProc();  // Message Exchange routine

/* -------------
 * Local Variables & funcs
 * -------------
 */

/* This is the Status Word described
 * in the Comm. Protocol Spec.
 */	
static u16 m_ProtocolStatusWord = 0;



// add by mark
PLL_Config  myConfig      = {
  0,    //IAI: the PLL locks using the same process that was underway 
                //before the idle mode was entered
  1,    //IOB: If the PLL indicates a break in the phase lock, 
                //it switches to its bypass mode and restarts the PLL phase-locking 
                //sequence
  24,    //PLL multiply value; multiply 24 times
  1             //Divide by 2 PLL divide value; it can be either PLL divide value 
                //(when PLL is enabled), or Bypass-mode divide value
                //(PLL in bypass mode, if PLL multiply value is set to 1)
};

// add by mark
EMIF_Config emiffig = {
  0x231, 	//EGCR  : the MEMFREQ = 00,the clock for the memory is equal to cpu frequence
  			//		  the WPE = 0 ,forbiden the writing posting when we debug the EMIF
  			//        the MEMCEN = 1,the memory clock is reflected on the CLKMEM pin
  			//        the NOHOLD = 1,HOLD requests are not recognized by the EMIF 
  			
  			//错了吧 MEMFREQ = 001 , 是二分频
  			//错了吧,EGCR里没有HOLD信号
  			//bit-4:为1代表不采样ardy off
  			
  0xFFFF,	//EMI_RST: any write to this register resets the EMIF state machine
  0x1FFF,	//CE0_1:  CE0 space control register 1
  			////        MTYPE = 001,16-bit data bus width async memory, FIFO
  0xFFFF,   //CE0_2:  CE0 space control register 2
  0x00FF,   //CE0_3:  CE0 space control register 3
  			//        TIMEOUT = 0xFF;  
  
  0x1FFF,	//CE1_1:  CE1 space control register 1
            ////        MTYPE = 001,16-bit data bus width async memory, flash
  0xFFFF,	//CE1_2:  CE1 space control register 2
  0x00FF,	//CE1_3:  CE1 space control register 3
  			
  			//为何CE1中不设置SDRAM???
  
  0x3FFF,	//CE2_1:  CE2 space control register 1
            //        MTYPE = 011,Synchronous DRAM(SDRAM),16-bit data bus width
  0xFFFF,	//CE2_2:  CE2 space control register 2
  0x00FF,	//CE2_3:  CE2 space control register 3
  
  0x3FFF,	//CE3_1:  CE3 space control register 1
  0xFFFF,	//CE3_2:  CE3 space control register 2
  0x00FF,	//CE3_3:  CE3 space control register 3
  
  0x2911,   //SDC1:   SDRAM control register 1
  			//		  TRC = 8 
  			//        SDSIZE = 0;SDWID = 0
  			//        RFEN = 1
  			//        TRCD = 2
  			//        TRP  = 2
  			
  			//这三个时间应该算一下
  			//tRC = 66ns, tRCD = 20ns, tRP = 20ns.(都是最小值)
  			//CLKMEM = 1000/72=13.?ns,  但这里好像是算成CLKMEM = 1000/144= 6.94ns
  			//TRC = 66 / 6.94 - 1 = 8.5
  			//这样比用72Mhz算,更保险
  			
  0x0410,	//SDPER : SDRAM period register
  			//		  7ns *4096
  			
  			//?  可410h = 1040呀
  			
  0x07FF,    //SDINIT: SDRAM initialization register
  			//        any write to this register to init the all CE spaces,
  			//        do it after hardware reset or power up the C55x device
  0x0131	//SDC2:	  SDRAM control register 2
  			//        SDACC = 0;
  			//        TMRD = 01;
  			//        TRAS = 0101;
  			//        TACTV2ACTV = 0001;
  			//需要计算一下
  			//tMRD = 15/20ns, tRAS = 44~120000ns,tRRD = 15ns.
  			//例如 TMRD = 44 / 6.94 - 1 = 5.3
  																			
  };
  
  
  
unsigned long i = 0 ;                     // add by mark
//unsigned long nFileLength = 1222 ;           // add by mark
unsigned long nFileLength =  707-2;//24257-2;//21981-2;           // add by mark
unsigned short nDataWrite [2] = {0,0} ;    // add by mark

void dataIo()
{
    nDataWrite[1] = nDataWrite[0] ;

}

void main()    // add by mark
{
    /*初始化CSL库*/	
    CSL_init();
    
    /*EMIF为全EMIF接口*/
    CHIP_RSET(XBSR,0x0a01);
    
    /*设置系统的运行速度为144MHz*/
    PLL_config(&myConfig);
    
    /*初始化DSP的外部空间*/
    // EMIF准备
    // CE1--运气不错,与FlashBurn默认的相同 
    EMIF_config(&emiffig);    
       
    printf("Target FBTC Running\n");
    // FLASH soft reset
    printf("flash_reset()\n");
    flash_reset();
    
    // Flash Erase
    printf("EraseFlash()\n");
    EraseFlash() ; 
    printf("end EraseFlash() len = %d\n",nFileLength); 
    
    //21981-2  
    
    // Flash Program, nFileLength for 实际文件长度
    for ( i=0; i< nFileLength; i ++ )
    {
        // 文件探针
        dataIo() ;
        
        // 写入一个word   
        BurnFlash( i * 2 , nDataWrite , 2 ) ;     
        
        // 每写入1000个word,打印输出一个字符
        if ( i % 1000 == 0 )
        {
            puts("thousand");
            if ( i % 10000 == 0 )
                puts("ten thousand");
        }
    }    
}

/*
void main()
{

	flash_reset();
	
    // User comfort message. Runs much
    // faster and leaner if no printf is
    // used anywhere.
     
//	printf("Target FBTC Running\n");

	InitFlash();
		
	// Runs forever: I expect Host component
	// to halt me by closing CCS.
	 
	for(;;)
	{
		doMessageProc();   // when this returns, I have a message.
		
    	doCommand(theMessage); // Process the new message
	}

}
*/

/* Global Utility Functions
 */


/* This do-nothing function is here to
 * define a global symbol. The Host app.
 * will set a breakpoint at this loc.
 * When this program steps off the
 * breakpoint (returns from this func),
 * that means that the Host has filled
 * the global message block (at theMessage)
 * with a command and data to process.
 * This prog. will process the message,
 * write any response data back into
 * the message block, and then come back
 * here and hit the breakpoint.
 */
void doMessageProc()
{
	/* Optimizer will want to delete
	 * this function, since it doesn't
	 * appear to do anything useful.
	 * Assigning a value to a volatile
	 * forces optimizer to keep this code. 
	 */ 
	volatile int FoolTheOptimizer = 0;
}


u16 GetProtocolVersionID(void)
{
	return (u16)COMMPROTOCOLVERSION;
}

u16 GetProtocolStatusWord(void)
{
	return m_ProtocolStatusWord;
}


void SendI4ToHost(u16 cmd, long val)
{
	StoreCmd(cmd);
	StoreArg(0, (u16)(val >> 16));
	StoreArg(1, (u16)(val & 0x0000ffff));

}


void SendI2ToHost(u16 cmd, u16 val)
{
	StoreCmd(cmd);
	StoreArg(0, val);
}


/* Utility Status Word funcs
 */

	/* Set the 4 status bits
	 */
void SetErrorBits(u16 x)
{
    m_ProtocolStatusWord &= ~(0x000f);
    m_ProtocolStatusWord |= ((x) & 0x000f);
}



/* Stores val into the message command bytes
 */
void StoreCmd(u16 val)
{
	theMessage[CMDINDEX] = val;
}

u16 GetCmd(void)
{
	return theMessage[CMDINDEX];
}

/* Stores val into the message argument bytes
 * at argindex.
 * Argindex is 0-15.
 */
void StoreArg(int argindex, u16 val)
{
	int myindex = ARGINDEX + argindex;
	theMessage[myindex] = val;
}

/* Returns an arg value from arg index 0-15
 */
u16  GetArgVal(int index)
{
	return theMessage[ARGINDEX + index];
}

u16 *GetMessage(void)
{
	return &theMessage[0];
}

u16 *GetData(void)
{
	return &theMessage[DATAINDEX];
}

⌨️ 快捷键说明

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