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

📄 coffloader.cpp

📁 TMS320F2808的完整驱动测试程序源码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
	InitEvent();

    // Always test for connection to prevent user calling in disconnected
    // state or with NULL handles.
    if( CheckConnection() == FALSE ) {
        return( FALSE );
    }

	do
	{
		isEvt = CheckEvents();
		if( isEvt )
		{
			if( m_Evt.System )
				break;

			if( m_Evt.Type != EVT_NONE )
				break;
			isEvt = FALSE;
		}
        else {
			Sleep(10);
        }

        TimeOutInMs -= 10;

	}while( TimeOutInMs > 0 );

	return( isEvt );
}
/*F***************************************************************************
* NAME: RunTarget( void )   
*
* DESCRIPTION:  Start the target running from it's current program counter.
*               If processor had stopped on a breakpoint then it will be
*               stepped over by low level code.
*
*
*F***************************************************************************/
BOOL CoffLoader::RunTarget( void )
{
    // Always test for connection to prevent user calling in disconnected
    // state or with NULL handles.
    if( CheckConnection() == FALSE ) {
        return( FALSE );
    }
	return( m_pSdti_Intf->pExe->Continue( m_Sdti_Hndl ));
}

/*F***************************************************************************
* NAME: StepTarget( void )   
*
* DESCRIPTION:  Step the target
*
*F***************************************************************************/
BOOL CoffLoader::StepTarget( DWORD Count )
{
    BOOL Success;
    BOOL isEvt;
    // Always test for connection to prevent user calling in disconnected
    // state or with NULL handles.
    if( CheckConnection() == FALSE ) {
        return( FALSE );
    }
	Success = m_pSdti_Intf->pExe->Step( m_Sdti_Hndl, (unsigned long)Count );
    if( Success == FALSE )
        return( FALSE );

	isEvt = WaitForHaltEvent();

	// Timed out or some oher event but may not be halted
	if( isEvt == FALSE )
		return( FALSE );

	// Target has not halted return error
	if( m_pSdti_Intf->pExe->IsRunning( m_Sdti_Hndl ) == TRUE )
		return( FALSE );
	
	return( TRUE );}

/*F***************************************************************************
* NAME:  RunTargetTillDone( )  
*
* DESCRIPTION:  Run processor and wait for a "halting" event.  Then verify
*               the processor has stopped.
*
*
*F***************************************************************************/
BOOL CoffLoader::RunTargetTillDone( )
{
	BOOL isEvt;

    // Always test for connection to prevent user calling in disconnected
    // state or with NULL handles.
    if( CheckConnection() == FALSE ) {
        return( FALSE );
    }

	if( RunTarget() == FALSE )
		return( FALSE );

	isEvt = WaitForHaltEvent();

	// Timed out or some other event but may not be halted
	if( isEvt == FALSE )
		return( FALSE );

	if( m_pSdti_Intf->pExe->IsRunning( m_Sdti_Hndl ) == TRUE )
		return( FALSE );
	
	return( TRUE );
}

/*F***************************************************************************
* NAME:  GoMain( void ) 
*
* DESCRIPTION: Sets breakpoint at main and runs to it then deletes the
*              breakpoint.
*
*
*F***************************************************************************/
BOOL CoffLoader::GoMain( void )
{

    BOOL  BpSuccess, RunSuccess;
    
    // Always test for connection to prevent user calling in disconnected
    // state or with NULL handles.
    if( CheckConnection() == FALSE ) {
        return( FALSE );
    }

    BpSuccess = AddSwbp( "_main" );
    if( BpSuccess == FALSE )
        return( FALSE );
    
    RunSuccess = RunTargetTillDone();
    if( RunSuccess == FALSE ) {
        ErrMsg("Target did not hit breakpoint" );
    }

    // DeleteSwbp will check for valid run condition before deleting
    BpSuccess = DeleteSwbp("_main");

    return( RunSuccess & BpSuccess );
}

/*F***************************************************************************
* NAME: HaltTarget( void )   
*
* DESCRIPTION:  Halt/Suspend target execution and verify the halt condition.
*
*
*F***************************************************************************/
BOOL CoffLoader::HaltTarget( void )
{
	BOOL isEvt;

    // Always test for connection to prevent user calling in disconnected
    // state or with NULL handles.
    if( CheckConnection() == FALSE ) {
        return( FALSE );
    }

	// Ignore the the return value
	m_pSdti_Intf->pExe->Suspend( m_Sdti_Hndl );
    
	isEvt = WaitForHaltEvent();

	// Timed out or some oher event but may not be halted
	if( isEvt == FALSE )
		return( FALSE );

	// Target has not halted
	if( m_pSdti_Intf->pExe->IsRunning( m_Sdti_Hndl ) == TRUE )
		return( FALSE );
	
	return( TRUE );

}
/*F***************************************************************************
* NAME: DoReset( void )
*
* DESCRIPTION:  Reset the target. Beware, this is a soft reset not a hardware
*               reset.  So may want to add in some extra post-reset operations.
*
*
*F***************************************************************************/
BOOL CoffLoader::DoReset( void )
{
	BOOL isReset = FALSE;

    // Always test for connection to prevent user calling in disconnected
    // state or with NULL handles.
    if( CheckConnection() == FALSE ) {
        return( FALSE );
    }

	// Reset the processor and check/clear events
	while( CheckEvents() ){}

    isReset = m_pSdti_Intf->pExe->Reset( m_Sdti_Hndl );
    if( isReset == TRUE )
	{
		// Clear events and make sure we are not running
		while( CheckEvents() ){}

		if( m_pSdti_Intf->pExe->IsRunning( m_Sdti_Hndl ) == TRUE ) {
			isReset = FALSE;
		}
		else 
		{
			TREG_16   Data[8];
			int       i;
            TREG_16 Wd = 0x0068;
            // Disable the watchdog
            WriteMemory( (MEM_TADDR)0x7029,M_DATA,&Wd,1 );

			/* Read the password locations */
			//XAR0 = *0x3F7FF8;
			//XAR0 = *0x3F7FF9;
			//XAR0 = *0x3F7FFA;
			//XAR0 = *0x3F7FFB;
			//XAR0 = *0x3F7FFC;
			//XAR0 = *0x3F7FFD;
			//XAR0 = *0x3F7FFE;
			//XAR0 = *0x3F7FFF;

			//ReadMemory( (MEM_TADDR)0x3F7FF8, M_DATA, Data, 8 );

			/* Assumes flash is erased */
			//*0xAE0 = 0xFFFF;
			//*0xAE1 = 0xFFFF;
			//*0xAE2 = 0xFFFF;
			//*0xAE3 = 0xFFFF;
			//*0xAE4 = 0xFFFF;
			//*0xAE5 = 0xFFFF;
			//*0xAE6 = 0xFFFF;
			//*0xAE7 = 0xFFFF;

			//for(i=0; i<8; i++ )
			//	Data[i] = 0xFFFF;
			//WriteMemory(  0xAE0, M_DATA, Data, 8 );
        }
	}
    // Reset can take us out of realtime mode to force reevaluation
    m_isRealTimeAllowed = 0;
	return( isReset );
}

/*F***************************************************************************
* NAME:  EnterRealtimeMode( BOOL Polite ) 
*
* DESCRIPTION:  Enter realtime mode.
*
*F***************************************************************************/
BOOL CoffLoader::EnableRealtimeMode()
{
    DWORD Mode;
    DWORD St1 = (DWORD)-1;

    // Always test for connection to prevent user calling in disconnected
    // state or with NULL handles.
    if( CheckConnection() == FALSE ) {
        return( FALSE );
    }

    // Requires revision 2 of the execution code to get support for
    // realtime mdoe.
    if( m_pSdti_Intf->pExe->Revision < 2 )
        return( FALSE );

    // DBGM bit in ST1 must be 0 to enter realtime mode
    if( ReadRegister( "ST1", &St1) == FALSE ){
        return( FALSE );
    }
    if( (St1 & 2 ) == 2 )
    {
        St1 &= ~2;
        if( WriteRegister( "ST1", &St1) == FALSE ) 
            return( FALSE );

        if( ReadRegister( "ST1", &St1) == FALSE ) 
            return( FALSE );
        if( (St1 & 2 ) == 2 )
            return( FALSE );
        m_isRealTimeAllowed = TRUE;
    }

    if( m_pSdti_Intf->pExe->EnterRealtimeMode(m_Sdti_Hndl, 0 ) == FALSE )
        return( FALSE );

    Mode = 7;
    if( m_isRealTimeAllowed == TRUE )
    {
        // Set the realtime polite/rude mode
        if( WriteRegister( "DBGM", &Mode) == FALSE ){
            while( CheckEvents()){}
            return( FALSE );
        }
        if( WriteRegister( "PREEMPT", &Mode) == FALSE ) {
            while( CheckEvents()){}
            return( FALSE );
        }
        m_isRealTimeAllowed = FALSE;
    }
	return( TRUE );
}
/*F***************************************************************************
* NAME:  ExitRealtimeMode( BOOL Polite ) 
*
* DESCRIPTION:  Exit realtime mode.
*
*F***************************************************************************/
BOOL CoffLoader::DisableRealtimeMode()
{
    // Always test for connection to prevent user calling in disconnected
    // state or with NULL handles.
    if( CheckConnection() == FALSE ) {
        return( FALSE );
    }

    if( m_pSdti_Intf->pExe->Revision < 2 )
        return( FALSE );

    if( m_pSdti_Intf->pExe->ExitRealtimeMode(m_Sdti_Hndl ) == FALSE )
        return( FALSE );

	return( TRUE );
}

/*F***************************************************************************
* NAME:  EnterRealtimeMode( BOOL Polite ) 
*
* DESCRIPTION:  Enter realtime mode.
*
*F***************************************************************************/
BOOL CoffLoader::SwitchRealtimeMode( BOOL Polite )
{
    DWORD Mode;

    // Always test for connection to prevent user calling in disconnected
    // state or with NULL handles.
    if( CheckConnection() == FALSE ) {
        return( FALSE );
    }

    // Requires revision 2 of the execution code to get support for
    // realtime mdoe.
    if( m_pSdti_Intf->pExe->Revision < 2 )
        return( FALSE );

    if( Polite == TRUE ) { 
        Mode = 0;
    }else{
        Mode = 7;
    }

   // Set the realtime mode polite/rude mode
    if( WriteRegister( "DBGM", &Mode) == FALSE ) 
        return( FALSE );
    if( WriteRegister( "PREEMPT", &Mode) == FALSE ) 
        return( FALSE );

	return( TRUE );
}

/*F***************************************************************************
* NAME: ReadFromSymbol( char *pSymbol, DWORD *pVal )
*
* DESCRIPTION:  Read either 16 or 32 bit data from given symbol name.  Size 
*               is taken from the symbol type.
*
*F***************************************************************************/
BOOL CoffLoader::ReadFromSymbol( char *pSymbol, DWORD *pVal )
{
	struct SYMBOL * s;
	TMEM_DESC  Tmem;
	int        DataSizeBytes;
	TREG_16    Data[2];

    // Always test for connection to prevent user calling in disconnected
    // state or with NULL handles.
    if( CheckConnection() == FALSE ) {
        return( FALSE );
    }

	s = FindSymbol(pSymbol);
	if (s == (struct SYMBOL *)NULL )
	   return( FALSE );    

	DataSizeBytes = BytesPerDataSize( s );
	if( DataSizeBytes == 0 )
		return( FALSE );

	Tmem.Taddr    = s->symaddr;
	Tmem.Space    = (s->sympage == 0) ? M_PROGRAM : M_DATA;
	Tmem.Asize    = M_SIZE16;
	Tmem.Bsize    = M_SIZE16;
	Tmem.Length   = DataSizeBytes/2;
	Tmem.pData    = Data;
	if( m_pSdti_Intf->pMem->Read( m_Sdti_Hndl, &Tmem ) == FALSE )
		return( FALSE );

    *pVal = (DWORD)Data[0] & 0x0000FFFFL;
    if( DataSizeBytes == 4 ) {
        *pVal |= ((DWORD)Data[1] & 0x0000FFFFL)<<16;
    }
	return( TRUE );
}

/*F***************************************************************************
* NAME: WriteToSymbol( char *pSymbol, DWORD *pVal )
*
* DESCRIPTION:  Write either 16 or 32 bit data to a given symbol name.  Size 
*               is taken from the symbol type.
*
*F***************************************************************************/
BOOL CoffLoader::WriteToSymbol( char *pSymbol, DWORD *pVal )
{
	struct SYMBOL * s;
	TMEM_DESC  Tmem;
	int        DataSizeBytes;
	TREG_16    Data[2];

    // Always test for connection to prevent user calling in disconnected
    // state or with NULL handles.
    if( CheckConnection() == FALSE ) {
        return( FALSE );
    }

	s = FindSymbol(pSymbol);
	if (s == (struct SYMBOL *)NULL )
	   return( FALSE );    

	DataSizeBytes = BytesPerDataSize( s );
	if( DataSizeBytes == 0 )
		return( FALSE );

    Data[0] = (TREG_16)*pVal;
    Data[1] = (TREG_16)(*pVal>>16);

	Tmem.Taddr    = s->symaddr;
	Tmem.Space    = (s->sympage == 0) ? M_PROGRAM : M_DATA;
	Tmem.Asize    = M_SIZE16;
	Tmem.Bsize    = M_SIZE16;
	Tmem.Length   = DataSizeBytes/2;
	Tmem.pData    = Data;
	if( m_pSdti_Intf->pMem->Write( m_Sdti_Hndl, &Tmem ) == FALSE )
		return( FALSE );

	return( TRUE );
}

/*F***************************************************************************
* NAME: WriteMemory( MEM_TADDR Addr, MEM_SPACE Space, TREG_16 *pData, 
*                    DWORD Count  )
*
* DESCRIPTION:  Write 16 bit data to memory
*
*F***************************************************************************/
BOOL CoffLoader::WriteMemory( MEM_TADDR Addr, 
							  MEM_SPACE Space, 
							  TREG_16 * pData, 
							  DWORD     Count  )
{
    TMEM_DESC Tmem;

    // Always test for connection to prevent user calling in disconnected
    // state or with NULL handles.
    if( CheckConnection() == FALSE ) {
        return( FALSE );
    }

	Tmem.Taddr    = Addr;

⌨️ 快捷键说明

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