?? flashfunctions.c
字號:
///////////////////////////////////////////////////////////////////////////////////////
//NAME: flashFunctions.c (AMD Parallel Flash Programmer)
//DATE: 9/18/03
//PURPOSE: Program the Parallel Flash for the ADSP-21262 Ezkit
//
//USAGE: This file contains the subroutines called to program the PP Flash on the
// ADSP-21262 Ezkit lite.
//
////////////////////////////////////////////////////////////////////////////////////////
#include "ppflash.h"
//----------------------------------------
//RESET THE STATE OF THE FLASH SUBROUTINE
//Writes the reset command to the Flash
//Inputs - flash_addr - address to write to in external memory (pointer)
//Returns- none
//Address is only required to make sure that the flash is selected by the address decoder
void flashReset(int *flash_addr)
{
int wordToWrite = {0xF0};
writeToPP(&wordToWrite,flash_addr,1);
}
//----------------------------------------
//SECTOR ERASE SUBROUTINE
//Erases the selected number of sectors in the flash, starting with the supplied address
//Inputs - flash_addr - address to write to in external memory (pointer)
// num_sectors - number of 32-bit words to write.
//Returns- none
void sectorErase(int *flash_addr, int num_sectors)
{
int wordToWrite[2] = {0x55aa0000, 0x3055aa80};
int i;
//Send the erase command once for each affected sector
for(i=0;i<num_sectors;i++)
{
writeToPP(wordToWrite,(flash_addr+(i*SECTOR_SIZE)),2);
//Wait for the flash to finish erasing the sector
while((0xFF & readFromPP(flash_addr+(i*SECTOR_SIZE)))!=0xFF)
{};
}
}
//----------------------------------------
//WRITE DATA TO FLASH SUBROUTINE
//Programs the specified amount of bytes to the flash.
//Inputs - buffer_addr - address of the buffer holding the 32-bit words to write (pointer)
// flash_addr - address to write to in external memory (pointer)
// buffer_length - number of bytes to write.
//Returns- none
void programBlock(int *buffer_addr, int *flash_addr, int buffer_length)
{
int i;
int wordToWrite;
for(i=0;i<buffer_length;i++)
{
//construct a single word containing the 24-bit write command and byte to write
wordToWrite = (readFromPP(buffer_addr+i)<<24)|0xa055aa;
//Write this 32-bit word to the Flash
writeToPP(&wordToWrite,(flash_addr+i),1);
//Wait for the flash to finish programming
pollFlash(flash_addr+i);
}
}
//----------------------------------------
//VERIFY DATA IN FLASH SUBROUTINE
//Reads the specified amount of bytes to the flash and compares it to the source buffer.
//Inputs - buffer_addr - address of the buffer holding the 32-bit words to write (pointer)
// flash_addr - address to write to in external memory (pointer)
// buffer_length - number of bytes to write.
//Returns- none
void verifyBlock(int *buffer_addr, int *flash_addr, int buffer_length)
{
int i,
fromFlash,
fromSRAM;
for(i=0;i<buffer_length;i++)
{
//Read the word from the flash
fromFlash = 0xFF & readFromPP(flash_addr+i);
//Read the word from SRAM
fromSRAM = 0xFF & readFromPP(buffer_addr+i);
//Wait here forever if they don't match
if(fromFlash != fromSRAM)
while(1){};
}
}
//----------------------------------------
//POLL THE FLASH SUBROUTINE
//Reads the flash after it has been programmed to detect when the programming is finished
//Inputs - flash_addr - address to write to in external memory (pointer)
//Returns- none
//Address is only required to make sure that the flash is selected by the address decoder
int pollFlash(int *flash_address)
{
int flash_word[3];
int i;
while(1)
{
//Read a word from the flash, 32-bits will be read
flash_word[0]=readFromPP(flash_address);
//Extract the first and second byte into separate words
flash_word[1]=(flash_word[0] & 0xFF);
flash_word[2]=((flash_word[0]>>8) & 0xFF);
//The flash will toggle bits in the word for each read
//When the first and second byte match, the programming is complete
if(flash_word[1]==flash_word[2])
break;
}
return flash_word[0];
}
//----------------------------------------
//WRITE A VALUE TO LEDS SUBROUTINE
//Lights the LEDs with the specified pattern
//Inputs - flag_value - 8-bit value to display on the 8 LEDs on the ADSP-21262 Ezkit lite
//Returns- none
void writeToLEDs(int flag_value)
{
//the MSB of the word will be displayed
flag_value <<= 24;
//write this value to the PP at the LED address
writeToPP(&flag_value, (int *) LED_ADDRESS, 1);
}
//----------------------------------------
//Parallel Port Interrupt Service Routine
//Vector jumped to upon PP interrupt
//Returns- Sets a semaphore for the PP Interrupt which the main routines poll for status
void ppInterruptHandler(int sig_int)
{
//Set the PP Interrupt Semaphore
ppInterruptFlag = 1;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -