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

📄 coffloader.cpp

📁 TMS320F2808的完整驱动测试程序源码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
	   m_swbplist = b;
   }
   return(TRUE);
}
/*F***************************************************************************
* NAME: AddSwbp( char * name ) 
*
* DESCRIPTION:  Add a software breakpoint to the list and put it in memory.
*
*F***************************************************************************/
BOOL CoffLoader::AddSwbp( char * name )
{

    SWBP_SYMBOL *  new_bp = NULL;
    SYMBOL      *  s = NULL;
    TEVT_DESC      Evt;

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

    s = FindSymbol( name );
    if( s == NULL )
        return( FALSE );

    Evt.EvtId = 0;
    Evt.Taddr = s->symaddr;
    Evt.Space = (s->sympage == 0) ? M_PROGRAM : M_DATA;
    Evt.Type  = EVT_SWBP;

    if( m_pSdti_Intf->pEvt->Add( m_Sdti_Hndl, &Evt ) == FALSE )
	    return( FALSE );

    new_bp       = (SWBP_SYMBOL *)new( SWBP_SYMBOL );
    if( new_bp == NULL )
       return( FALSE );
    new_bp->s    = s;
    new_bp->id   = Evt.EvtId;
    new_bp->prev = NULL;
    new_bp->next = m_swbplist;

    // Set previous to link backwards
    if( m_swbplist != NULL ) {
        m_swbplist->prev = new_bp;
    }
    // Set head to new bp
    m_swbplist   = new_bp;

    return( TRUE );
}

/*F***************************************************************************
* NAME: AddSwbp( char * name ) 
*
* DESCRIPTION:  Delete a swbp from memory and from the list.  If we get an
*               error on the delete then we will still take it out of the 
*               list.
*
*F***************************************************************************/
BOOL CoffLoader::DeleteSwbp( char * name )
{

    SWBP_SYMBOL *  bp = NULL;
    SWBP_SYMBOL *  previous;
    SWBP_SYMBOL *  next;
    TEVT_DESC      Evt;
    BOOL           Success = TRUE;

    // 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->IsRunning( m_Sdti_Hndl ) == TRUE )
        return( FALSE );

    bp = FindSwbp( name );
    if( bp == NULL )
        return( FALSE );

    Evt.EvtId = 0;
    Evt.Taddr = bp->s->symaddr;
    Evt.Space = (bp->s->sympage == 0) ? M_PROGRAM : M_DATA;
    Evt.Type  = EVT_SWBP;

    Success = m_pSdti_Intf->pEvt->Delete( m_Sdti_Hndl, bp->id );

    previous = bp->prev;
    next     = bp->next;
    delete( bp );

    if( previous == NULL ) 
    {   // Was top of list, just move up
        m_swbplist = next;
    }
    else 
    { 
        if( next == NULL ) 
        {   // Was at the bottom of list just patch previous
            previous->next = NULL;
        }
        else
        {  // In the middle of the list so patch preious and next
            previous->next = next;
            next->prev     = previous;
        }
    }

    return( Success );
}

/*F***************************************************************************
* NAME: LoadGeneric   
*
* DESCRIPTION: Main entry point of the application worker thread.
*
*
*F***************************************************************************/
void CoffLoader::LoadGeneric( LPVOID lpParam )
{
    DWORD RanTheTest          = 0;
    DWORD Error_CheckPattern  = 0;
    DWORD Error_AddressAsData = 0;
    DWORD Error_AltPattern    = 0;
	DWORD Error_Can           = 0;
	DWORD Error_TxAToRxB      = 0;
	DWORD Error_TxBToRxA      = 0;
	DWORD Error_I2C           = 0;

    BOOL  TestPassed          = TRUE;

    // Fetch the SDLoader object that called this thread 
    CSDLoaderDlg* sdloaderObject = ( ( CSDLoaderDlg* )lpParam );

    // User inputs
    m_entryPoint        = sdloaderObject->m_entryPoint;
    m_useAltEntry       = sdloaderObject->m_useAltEntry;

	m_verboseError      = sdloaderObject->m_ErrorVerbose;
	m_verboseMessage    = sdloaderObject->m_MessageVerbose;
	m_SciLoopBack       = sdloaderObject->m_SciLoopBack;
	m_CanLoopBack       = sdloaderObject->m_CanLoopBack;
	m_I2CLoopBack       = sdloaderObject->m_I2CLoopBack;

    // Enviroment variables 
    m_mainWindow        = sdloaderObject->m_mainWindow;
    m_workingDirectory  = sdloaderObject->m_workingDirectory;

    // Path variables 
    m_driverPath        = sdloaderObject->m_driverPath;
    m_driverName        = sdloaderObject->m_driverName;
    m_targetPath        = sdloaderObject->m_targetPath;
    m_boardName         = sdloaderObject->m_boardName;

    // Processor Variables 
    m_procFamily        = sdloaderObject->m_procFamily;
    m_procName          = sdloaderObject->m_procName;
    m_procAddr          = sdloaderObject->m_procAddr;
    m_coffFileName      = sdloaderObject->m_coffFileName;

	m_ExecTimeoutMs      = 20000;  // ~20 seconds

	m_BoardFile = "DevBoardName=" + m_workingDirectory;
	int Len = m_BoardFile.GetLength();
	if( m_BoardFile[Len-1] == '\\' )
		m_BoardFile += m_boardName;
	else
		m_BoardFile += '\\' + m_boardName;

    
    // In order to load a program using SD device drivers, the
    // drivers need to located and use configuration files on the computer.
    // The driver itself needs to located and loaded for use in the
    // application.  This code set the working directory path to were these
    // files reside.  Note that some emulation drivers require the file
    // rtdx.dll.  Generally this file is copied from <CCS_INSTALL>\ccs\bin
    // directory into the current executable directory. Note that RTDX is
    // not used by this app but emulation drivers still have to find this
    // dll.
    SetCurrentDirectory( m_driverPath );

    if( OpenConnection() == FALSE ) {
        goto LOADGENERIC_ERROR;
    }

    
    //  Reset the processor to known good state.
    // 
	if( DoReset() == FALSE )
    {
        ErrMsg( "ERROR \tFailed to reset the Target." );
        goto LOADGENERIC_ERROR;
    }

    
    // Loading a coff file requires an in depth knowledge of the
    // how a coff file is structured.  The raw data is extracted from file
    // and loaded onto the processor through a series of memory writes.
    // The functions below take care of the extraction and writing of data.
    // The "entry point" to the program is set after the memory writes allowing
    // for program execution to begin.
    // 
    if ( ! LoadCoff( ) )
    {
        ErrMsg( "ERROR \tFailed to Load Coff File." );
        goto LOADGENERIC_ERROR;
    }

    // Go to main before setting any test variables
    if( GoMain() == FALSE )
    {
        ErrMsg( "ERROR \tCannot goto main." );
        goto LOADGENERIC_ERROR;
    }

    // Set variable to indicate test has not been run yet
    if( WriteToSymbol("_RanTheTest",  &RanTheTest ) == FALSE )
    {
        ErrMsg( "ERROR \tFailed to set test variables" );
        goto LOADGENERIC_ERROR;
    }

	// Enable SCI test if selected
	if( m_SciLoopBack == TRUE )
	{
		DWORD Val = 1;
		WriteToSymbol("_SciLoopBack",  &Val );
	}

	// Enable CAN test if selected
	if( m_CanLoopBack == TRUE )
	{
		DWORD Val = 1;
		WriteToSymbol("_CanLoopBack",  &Val );
	}

	// Enable CAN test if selected
	if( m_I2CLoopBack == TRUE )
	{
		DWORD Val = 1;
		WriteToSymbol("_I2CLoopBack",  &Val );
	}

    // Start test program running and wait for breakpoint.  Test code
    // has a breakpoint embedded so it should stop when done or simply
    // timeout.
	Message( "Running Target" );
    if ( RunTargetTillDone() == FALSE )
    {
        ErrMsg( "ERROR \tFailed to run test to completion" );
        goto LOADGENERIC_ERROR;
    }

    // These are "C" symbol names so they have a leading '_'.
    if(    ( ReadFromSymbol("_RanTheTest",  &RanTheTest                  ) == FALSE )
        || ( ReadFromSymbol("_Error_CheckPattern",  &Error_CheckPattern  ) == FALSE )
        || ( ReadFromSymbol("_Error_AddressAsData", &Error_AddressAsData ) == FALSE )
        || ( ReadFromSymbol("_Error_AltPattern",    &Error_AltPattern    ) == FALSE )
		|| ( ReadFromSymbol("_Error_Can",           &Error_Can           ) == FALSE )
		|| ( ReadFromSymbol("_Error_TxAToRxB",      &Error_TxAToRxB      ) == FALSE )
		|| ( ReadFromSymbol("_Error_TxBToRxA",      &Error_TxBToRxA      ) == FALSE )
		|| ( ReadFromSymbol("_Error_I2C",           &Error_I2C           ) == FALSE ))

    {
        ErrMsg( "ERROR \tFailed to read test results." );
        goto LOADGENERIC_ERROR;
    }

    if( RanTheTest == 0 ) {
        ErrMsg( "ERROR \tFailed to run the memory tests" );
        TestPassed = FALSE;
    }

    if( Error_CheckPattern != 0 ) {
        ErrMsg( "ERROR \tFailed memory pattern test." );
        TestPassed = FALSE;
    }

    if( Error_AddressAsData != 0 ) {
        ErrMsg( "ERROR \tFailed memory address==data test." );
        TestPassed = FALSE;
    }

    if( Error_AltPattern != 0 ) {
        ErrMsg( "ERROR \tFailed memory alt pattern test." );
        TestPassed = FALSE;
    }

	if( TestPassed == TRUE ) {
        Message( "Memory Tests Passed");
	}

	if( m_CanLoopBack == TRUE ) {

		if( Error_Can != 0 ) {
			ErrMsg( "ERROR \tFailed CAN loopback test." );
			TestPassed = FALSE;
		} else {
			Message( "CAN Loop Back Tests Passed");
		}
	}

	if( m_SciLoopBack == TRUE ) {
		if( Error_TxAToRxB != 0 ) {
			ErrMsg( "ERROR \tFailed SCI TXA to RXB." );
			TestPassed = FALSE;
		} else {
			Message( "SCI TXA to RXB Tests Passed");
		}

		if( Error_TxBToRxA != 0 ) {
			ErrMsg( "ERROR \tFailed SCI TXB to RXA." );
			TestPassed = FALSE;
		}else {
			Message( "SCI TXB to RXA Tests Passed");
		}
	}

	if( m_I2CLoopBack == TRUE ) {

		if( Error_I2C != 0 ) {
			ErrMsg( "ERROR \tFailed I2C loopback test." );
			TestPassed = FALSE;
		} else {
			Message( "I2C Loop Back Tests Passed");
		}
	}

    if( TestPassed == TRUE ){
        ErrMsg( "\tPASSED\tPASSED\tPASSED" );
        ErrMsg( "\tPASSED\tPASSED\tPASSED" );
        ErrMsg( "\tPASSED\tPASSED\tPASSED" );
        ErrMsg( "\tPASSED\tPASSED\tPASSED" );
    }

    //RealtimeDemo();

LOADGENERIC_ERROR:


    // Close the emulation connection
    CloseConnection();

    /* Post a Message to the Dialog Window to notify of completion */ 
    m_mainWindow->PostMessage( UWM_ONTHREADSTOP, NULL, NULL );

	// Restore the working directory as we changed it to load the driver
    SetCurrentDirectory( m_workingDirectory );

    return;
}


BOOL CoffLoader::RealtimeDemo()
{

    DWORD  SavedTimeout     = m_ExecTimeoutMs;
    DWORD  EnableInterrupts = 1;
    DWORD  ToggleUpdate     = 1;
    DWORD  TogglePeriod     = 0;
    BOOL   isEvt;
    BOOL   Success          = TRUE;
    DWORD  Loop             = 10;
    DWORD  MaxPasses        = 10;

    // The test code stopped on an embedded SW breakpoint (ESTOP0).
    // We have to step off of this breakpoint before setting up for
    // realtime mode.  This should ensure that all the breakpoint
    // state has been cleared out before attempting to enter realtime
    // mode.
    if( StepTarget( 1 ) == FALSE )
    {
        ErrMsg( "ERROR \tFailed to step over the embedded breakpoint" );
        return( FALSE );
    }

    // Read the current update rate.  We use this as our base value
    if( ReadFromSymbol("_TogglePeriod", &ToggleUpdate ) == FALSE )
    {
        ErrMsg( "ERROR \tFailed to read _TogglePeriod parameter" );
        return( FALSE );
    }

    // Set EnableInterrupts to 1 to enable the realtime interrupt.  If target
    // code sees this value as 1 then it will enable the 28xx timer0 for
    // the realtime demo.
    if( WriteToSymbol("_EnableInterrupts", &EnableInterrupts ) == FALSE )
    {
        ErrMsg( "ERROR \tFailed to write to EnableInterrupts" );
        return( FALSE );
    }

    // Enter realtime mode
    if( EnableRealtimeMode() == FALSE )
    {
        ErrMsg( "ERROR \tFailed to enter realtime mode" );
        return( FALSE );
    }
    // Goto Polite realtime mode
    if( SwitchRealtimeMode( REALMODE_POLITE ) == FALSE )
    {
        ErrMsg( "ERROR \tFailed to enter polite realtime mode" );
        return( FALSE );
    }

    // Now run the code whichl will immediately hit another breakpoint
    // following the interrupt setup.  At this point the main cpu loop will
    // have stopped but the critical interrupt will continu to run.  We
    // can show this by feeding the ISR a update value to change the LED.
    if( RunTarget() == FALSE )
    {
        ErrMsg( "ERROR \tFailed to run target in realtime mode" );
        return( FALSE );
    }

    // We will loop writing to ToggleUpdate and reading ToggleRate to
    // verify it was set.  Then wait for a while and adjust the delay.
    // We are going to use the WaitForHaltEvent() function to politely
    // wait for an event.  Once we get going there should not be any halt
    // events but this will also catch errors.
    //
    m_ExecTimeoutMs = 1000;

    while( Loop-- )
    {
        isEvt = WaitForHaltEvent();
        if( isEvt == TRUE )
        {
            // We should fall into this loop right after running.  But on
            // subsequent calles we should not unless there is an error.
            if( m_Evt.System != EVT_SYS_NONE )
            {
                ErrMsg( "ERROR \tError during realtime" );
                Success = FALSE;
                goto EXIT_REALTIME_DEMO;
            }
            if( m_Evt.Type == EVT_SWBP ){
                // This is the breakpoint that should stop main loop
                // exeuction but allow interrupts to proceed.
                Message("Realtime demo is stopped on breakpoint");
                Message("However target interrupts are still active");
            }
        }
        ToggleUpdate += (ToggleUpdate/2);

        if( WriteToSymbol("_ToggleUpdate", &ToggleUpdate ) == FALSE )
        {
            ErrMsg( "ERROR \tFailed to write _ToggleUpdate parameter" );
            return( FALSE );
        }
        
        MaxPasses = 10;
        do {

            if( ReadFromSymbol("_TogglePeriod", &TogglePeriod ) == FALSE )
            {
                ErrMsg( "ERROR \tFailed to read _TogglePeriod parameter" );
                return( FALSE );
            }
        }while( (TogglePeriod != ToggleUpdate ) && ( MaxPasses-- > 0 ) );

        if( MaxPasses <= 0 )
            break;
    }

EXIT_REALTIME_DEMO:
    m_ExecTimeoutMs = SavedTimeout;
    return( Success );  
}

⌨️ 快捷键说明

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