Exemple #1
0
ERROR_CODE SetupForFlash(void)
{

	ERROR_CODE ErrorCode = NO_ERR;			//return error code

	//there is no setup for the BF561

	ErrorCode = GetNumSectors();

	return NO_ERR;
}
int main(void)
{

    SECTORLOCATION *pSectorInfo;
    ERROR_CODE Result;							// result

    /* open flash driver */
    AFP_Error = m25p16_Open();

    // setup the device so the DSP can access it
    if (SetupForFlash() != NO_ERR)
        return FALSE;

    // get flash manufacturer & device codes, title & desc
    if( AFP_Error == NO_ERR )
    {
        AFP_Error = GetFlashInfo();
    }

    // get the number of sectors for this device
    if( AFP_Error == NO_ERR )
    {
        AFP_Error = GetNumSectors();
    }

    if( AFP_Error == NO_ERR )
    {
        // malloc enough space to hold our start and end offsets
        pSectorInfo = (SECTORLOCATION *)malloc(AFP_NumSectors * sizeof(SECTORLOCATION));
    }

    // allocate AFP_Buffer
    if( AFP_Error == NO_ERR )
    {
        AFP_Error = AllocateAFPBuffer();
    }

    // get sector map
    if( AFP_Error == NO_ERR )
    {
        AFP_Error = GetSectorMap(pSectorInfo);
    }

    // point AFP_SectorInfo to our sector info structure
    if( AFP_Error == NO_ERR )
    {
        AFP_SectorInfo = (int*)pSectorInfo;
    }

    // command processing loop
    while ( !bExit )
    {
        // the plug-in will set a breakpoint at "AFP_BreakReady" so it knows
        // when we are ready for a new command because the DSP will halt
        //
        // the jump is used so that the label will be part of the debug
        // information in the driver image otherwise it may be left out
        // since the label is not referenced anywhere
        asm("AFP_BreakReady:");
        asm("nop;");
        if ( FALSE )
            asm("jump AFP_BreakReady;");

        // Make a call to the ProcessCommand
        AFP_Error = ProcessCommand();
    }

    // Clear the AFP_Buffer
    FreeAFPBuffer();

    if( pSectorInfo )
    {
        free(pSectorInfo);
        pSectorInfo = NULL;
    }

    // Close the Device
    AFP_Error = m25p16_Close();

    if (AFP_Error != NO_ERR)
        return FALSE;

    return TRUE;
}