?? main.c
字號:
///////////////////////////////////////////////////////////////////////////////////////
//NAME: main.c (AMD Parallel Flash Programmer)
//DATE: 01/26/06
//PURPOSE: Program the Parallel Flash for the ADSP-21369 Ezkit
//
//USAGE: This file contains the main code for programming the PP flash on the
// ADSP-21369 Ezkit lite.
//
// If more than one file is to be programmed, either include all files in the
// same buffer (for contiguous location), or make sure that the files will not
// occupy any common 64K sectors in the flash, as programming the subsequent
// buffers will erase parts of the previously programmed buffers.
//
// For the AMD Am29LV081B the sectors occupy the following byte addresses:
// Sector Address Range
// SA0 0x00000 - 0x0FFFF
// SA1 0x10000 - 0x1FFFF
// SA2 0x20000 - 0x2FFFF
// SA3 0x30000 - 0x3FFFF
// SA4 0x40000 - 0x4FFFF
// SA5 0x50000 - 0x5FFFF
// SA6 0x60000 - 0x6FFFF
// SA7 0x70000 - 0x7FFFF
// SA8 0x80000 - 0x8FFFF
// SA9 0x90000 - 0x9FFFF
// SA10 0xA0000 - 0xAFFFF
// SA11 0xB0000 - 0xBFFFF
// SA12 0xC0000 - 0xCFFFF
// SA13 0xD0000 - 0xDFFFF
// SA14 0xE0000 - 0xEFFFF
// SA15 0xF0000 - 0xFFFFF
//
//
////////////////////////////////////////////////////////////////////////////////////////
#include <stdlib.h> // malloc includes
#include <Services_Sharc.h> // system services buffers
#include <adi_am29lv081b.h> // flash-AM29LV081B includes
#include <util.h> // library struct includes
#include <Errors.h> // error type includes
#ifdef __ADSP21369__
#include <Cdef21369.h>
#include <def21369.h>
#define FLASH_START_ADDR 0x4000000
static char *pEzKitTitle = "ADSP-21369 EZ-KIT Lite";
#elif __ADSP21364__
#define FLASH_START_ADDR 0x1000000
static char *pEzKitTitle = "ADSP-21364 EZ-KIT Lite";
#elif __ADSP21262__
#define FLASH_START_ADDR 0x1000000
static char *pEzKitTitle = "ADSP-21262 EZ-KIT Lite";
#endif
#define BUFFER_SIZE 0x600
//Flash Programmer commands
typedef enum
{
NO_COMMAND, // 0
GET_CODES, // 1
RESET, // 2
WRITE, // 3
FILL, // 4
ERASE_ALL, // 5
ERASE_SECT, // 6
READ, // 7
GET_SECTNUM, // 8
GET_SECSTARTEND,// 9
}enProgCmds;
//----- g l o b a l s -----//
char *AFP_Title ; // EzKit info: ADSP-21369 EZ-KIT Lite
char *AFP_Description; // Device Description: AMD AM29LV081B
char *AFP_DeviceCompany; // Device Company
char *AFP_DrvVersion = "1.01.0"; // Driver Version
char *AFP_BuildDate = __DATE__; // Driver Build Date
enProgCmds AFP_Command = NO_COMMAND; // command sent down from the GUI
int AFP_ManCode = -1; // 0x01 = Atmel
int AFP_DevCode = -1; // 0x38 = AT49BV040
unsigned long AFP_Offset = 0x0; // offset into flash
int *AFP_Buffer; // buffer used to read and write flash
long AFP_Size = BUFFER_SIZE; // buffer size
long AFP_Count = -1; // count of locations to be read or written
long AFP_Stride = -1; // stride used when reading or writing
int AFP_NumSectors = NUM_SECTORS; // number of sectors in the flash device
int AFP_Sector = -1; // sector number
int AFP_Error = 0; // contains last error encountered
bool AFP_Verify = TRUE; // verify writes or not
unsigned long AFP_StartOff = 0x0; // sector start offset
unsigned long AFP_EndOff = 0x0; // sector end offset
int AFP_FlashWidth = 0x8; // width of the flash device
int *AFP_SectorInfo;
bool bExit = FALSE; //exit flag
//----- c o n s t a n t d e f i n i t i o n s -----//
// structure for flash sector information
typedef struct _SECTORLOCATION
{
unsigned long ulStartOff;
unsigned long ulEndOff;
}SECTORLOCATION;
SECTORLOCATION SectorInfo[NUM_SECTORS];
//----- f u n c t i o n p r o t o t y p e s -----//
ERROR_CODE AllocateAFPBuffer(void);
ERROR_CODE GetSectorMap(void);
ERROR_CODE GetFlashInfo(void);
ERROR_CODE SetupForFlash(void);
ERROR_CODE FillData( unsigned long ulStart, long lCount, long lStride, int *pnData );
ERROR_CODE ReadData( unsigned long ulStart, long lCount, long lStride, int *pnData );
ERROR_CODE WriteData( unsigned long ulStart, long lCount, long lStride, int *pnData );
void FreeAFPBuffer(void);
//Declare the destination address in the flash of the file which is the flash start address
#define LDR_START_ADDR 0x4000000
//Declare a variable in SDRAM to hold the file data to program
section("seg_sdram") int ldr_source[] = {
#include "Core_Timer.ldr"
};
//------------- m a i n ( ) ----------------//
bool main(void )
{
ERROR_CODE ErrorCode = NO_ERR; //return error code
COMMAND_STRUCT CmdStruct;
// open the device
AFP_Error = ADIAM29LV081BEntryPoint.adi_pdd_Open( NULL, // DevMgr handle
0, // pdd entry point
NULL, // device instance
NULL, // client handle callback identifier
ADI_DEV_DIRECTION_BIDIRECTIONAL,// data direction for this device
NULL, // DevMgr handle for this device
NULL, // handle to DmaMgr for this device
NULL, // handle to deferred callback service
NULL ); // client's callback function
// allocate AFP_Buffer
if (( AFP_Error = AllocateAFPBuffer()) != NO_ERR)
return FALSE;
// get sector map
if (( AFP_Error = GetSectorMap())!= NO_ERR)
return FALSE;
// 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 = GetFlashInfo()) != NO_ERR)
return FALSE;
// erase the entire flash
CmdStruct.SEraseAll.ulFlashStartAddr = FLASH_START_ADDR; //FlashStartAddress
AFP_Error = (ERROR_CODE) ADIAM29LV081BEntryPoint.adi_pdd_Control(NULL, CNTRL_ERASE_ALL, &CmdStruct );
// get manufacturer and device codes
CmdStruct.SGetCodes.pManCode = (unsigned long *)&AFP_ManCode; // Manufacturer Code
CmdStruct.SGetCodes.pDevCode = (unsigned long *)&AFP_DevCode; // Device Code
CmdStruct.SGetCodes.ulFlashStartAddr = FLASH_START_ADDR;
AFP_Error = (ERROR_CODE) ADIAM29LV081BEntryPoint.adi_pdd_Control(NULL, CNTRL_GET_CODES, &CmdStruct);
// Reset the Flash
CmdStruct.SGetCodes.ulFlashStartAddr = FLASH_START_ADDR;
AFP_Error = (ERROR_CODE) ADIAM29LV081BEntryPoint.adi_pdd_Control(NULL, CNTRL_RESET, &CmdStruct);
AFP_Error = WriteData( 0, sizeof(ldr_source) , 1, ldr_source );
// Clear the AFP_Buffer
FreeAFPBuffer();
// Close the Device
AFP_Error = ADIAM29LV081BEntryPoint.adi_pdd_Close(NULL);
return TRUE;
}
//----------- A l l o c a t e A F P B u f f e r ( ) ----------//
//
// PURPOSE
// Allocate memory for the AFP_Buffer
//
// RETURN VALUE
// ERROR_CODE - value if any error occurs
// NO_ERR - otherwise
//
// CHANGES
// 9-28-2005 Created
ERROR_CODE AllocateAFPBuffer()
{
ERROR_CODE ErrorCode = NO_ERR; //return error code
// by making AFP_Buffer as big as possible the plug-in can send and
// receive more data at a time making the data transfer quicker
//
// by allocating it on the heap the compiler does not create an
// initialized array therefore making the driver image smaller
// and faster to load
//
// The linker description file (LDF) could be modified so that
// the heap is larger, therefore allowing the BUFFER_SIZE to increase.
AFP_Buffer = (int *)malloc(BUFFER_SIZE);
// AFP_Buffer will be NULL if we could not allocate storage for the
// buffer
if ( AFP_Buffer == NULL )
{
// tell GUI that our buffer was not initialized
ErrorCode = BUFFER_IS_NULL;
}
return(ErrorCode);
}
//----------- F r e e A F P B u f f e r ( ) ----------//
//
// PURPOSE
// Free the AFP_Buffer
//
// RETURN VALUE
// ERROR_CODE - value if any error occurs
// NO_ERR - otherwise
//
// CHANGES
// 9-28-2005 Created
void FreeAFPBuffer()
{
// free the buffer if we were able to allocate one
if ( AFP_Buffer )
free( AFP_Buffer );
}
//----------- S e t u p F o r F l a s h ( ) ----------//
//
// PURPOSE
// Perform necessary setup for the processor to talk to the
// flash such as external memory interface registers, etc.
//
// RETURN VALUE
// ERROR_CODE - value if any error occurs during Opcode scan
// NO_ERR - otherwise
ERROR_CODE SetupForFlash()
{
#ifdef __ADSP21369__
// setup EPCTL to use bank 2 (MS1) core accesses.
*pEPCTL = (((*pEPCTL) & (~B1SD)) | EPBRCORE);
// setup for max waitstates
// NOTE: The PKDIS bit is set which makes a 1 to 1 mapping, each 8 bit byte
/// maps to an address.
*pAMICTL1 = ( PKDIS | WS31 | HC1 | HC2 | RHC1 | RHC2 | IC7 | AMIEN | AMIFLSH);
#endif
return NO_ERR;
}
//----------- G e t S e c t o r M a p ( ) ----------//
//
// PURPOSE
// Get the start and end offset for each sector in the flash.
//
// RETURN VALUE
// ERROR_CODE - value if any error occurs
// NO_ERR - otherwise
//
// CHANGES
// 9-28-2005 Created
ERROR_CODE GetSectorMap()
{
ERROR_CODE ErrorCode = NO_ERR; //return error code
GET_SECTSTARTEND_STRUCT SSectStartEnd; //structure for GetSectStartEnd
int i; //index
//initiate sector information structures
for( i=0;i<AFP_NumSectors; i++)
{
SSectStartEnd.nSectorNum = i;
SSectStartEnd.pStartOffset = &SectorInfo[i].ulStartOff;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -