📄 main.c
字号:
///////////////////////////////////////////////////////////////////////////////////////
//NAME: main.c (AMD Parallel Flash Programmer)
//DATE: 01/26/06
//PURPOSE: Program the Parallel Flash for the ADSP-21364 Ezkit
//
//USAGE: This file contains the main code for programming the PP flash on the
// ADSP-21364 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 <stdio.h>
#include <stdlib.h> // malloc includes
#include <adi_am29lv081b.h> // flash-AM29LV081B includes
#include <Services_Sharc.h> // system services buffers
#include <util.h> // library struct includes
#include <Errors.h> // error type includes
//#include "ppflash.h"
//#include <signal.h>
#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);
//#include "flash.h"
// The following definition allows the SRU macro to check for errors. Once the routings have
// been verified, this definition can be removed to save some program memory space.
// The preprocessor will issue a warning stating this when using the SRU macro without this
// definition
#define SRUDEBUG // Check SRU Routings for errors.
#include <SRU.h>
//Declare a variable in SDRAM to hold the file data to program
section("seg_dmda") int ldr_source[] = {
// #include "EZKit_Push_Button.ldr"
#include "test.txt"
};
int dest[32];
int i;
//------------- m a i n ( ) ----------------//
//Declare a semaphore variable to use in the parallel port interrupt
int ppInterruptFlag = 0;
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 );
// sysreg_bit_set(sysreg_FLAGS,FLG4O|FLG5O|FLG6O|FLG7O ); //Set the flags as outputs
// initSRU(); // function used to route the flag outputs to light the LEDS
// 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);
//////////test/////read//////////
// 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;
// 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 = ReadData( 0, sizeof(ldr_source) , 1, dest );
// Clear the AFP_Buffer
FreeAFPBuffer();
// Close the Device
AFP_Error = ADIAM29LV081BEntryPoint.adi_pdd_Close(NULL);
for(i=0;i<32;i++)
printf("dest[%d] = %x\n",i,dest[i]);
return TRUE;
}
// Routes the flag outputs to light the corresponding LEDs
/*
void initSRU()
{
SRU2(FLAG4_O,DPI_PB06_I); // Connects Flag4 output to DPI pin 6 connected to LED1 on the Ez-kit
SRU2(HIGH,DPI_PBEN06_I); // enables DPI pin6 as input
SRU2(FLAG5_O,DPI_PB07_I); // Connects Flag5 output to DPI pin 7 connected to LED2 on the Ez-kit
SRU2(HIGH,DPI_PBEN07_I); // enables DPI pin 7 as input
SRU2(FLAG6_O,DPI_PB08_I); // Connects Flag6 output to DPI pin 8 connected to LED3 on the Ez-kit
SRU2(HIGH,DPI_PBEN08_I); // enables DPI pin 8 as input
SRU2(FLAG7_O,DPI_PB13_I); // Connects Flag7 output to DPI pin 13 connected to LED4 on the Ez-kit
SRU2(HIGH,DPI_PBEN13_I); // enables DPI pin 8 as input
}
*/
//----------- 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.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -