You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
143 lines
3.3 KiB
C++
143 lines
3.3 KiB
C++
/*
|
|
* Flash.cpp
|
|
*
|
|
* Author: Aleksey Gerasimenko
|
|
* gerasimenko.aleksey.n@gmail.com
|
|
*/
|
|
|
|
#include "DSP28335/FLASH.h"
|
|
|
|
namespace DSP28335
|
|
{
|
|
|
|
//CONSTRUCTOR
|
|
FLASH::FLASH():
|
|
DSP28335::CPUBase(),
|
|
m_mask_sector(0),
|
|
//
|
|
m_operation_status_erase(0),
|
|
m_operation_status_program(0),
|
|
m_operation_status_verify(0),
|
|
//
|
|
m_version_hex_default(API_VERSION_DEFAULT),
|
|
m_version_hex(0)
|
|
{
|
|
m_sector.StartAddr = 0;
|
|
m_sector.EndAddr = 0;
|
|
//
|
|
m_status_erase.FirstFailAddr = 0;
|
|
m_status_erase.ExpectedData = 0;
|
|
m_status_erase.ActualData = 0;
|
|
//
|
|
m_status_program.FirstFailAddr = 0;
|
|
m_status_program.ExpectedData = 0;
|
|
m_status_program.ActualData = 0;
|
|
//
|
|
m_status_verify.FirstFailAddr = 0;
|
|
m_status_verify.ExpectedData = 0;
|
|
m_status_verify.ActualData = 0;
|
|
//
|
|
}//end CONSTRUCTOR
|
|
|
|
void FLASH::setup(Uint16 mask_sector, Uint16 *StartAddr, Uint16 *EndAddr)
|
|
{
|
|
m_mask_sector = mask_sector;
|
|
m_sector.StartAddr = StartAddr;
|
|
m_sector.EndAddr = EndAddr;
|
|
|
|
//SCALE_FACTOR is defined in Flash2833x_API_Config.h
|
|
//EALLOW;
|
|
Flash_CPUScaleFactor = SCALE_FACTOR;
|
|
//EDIS;
|
|
//
|
|
m_mode = DSP28335::FLASH::OPERATIONAL;
|
|
//
|
|
}//end
|
|
|
|
Uint16 FLASH::erase()
|
|
{
|
|
//Uint16 status = 0;
|
|
//Flash_Erase(Uint16 SectorMask, FLASH_ST *FEraseStat);
|
|
//status = Flash_Erase(m_mask_sector, &m_status_erase);
|
|
//return status;
|
|
return Flash_Erase(m_mask_sector, &m_status_erase);
|
|
//
|
|
}//end
|
|
|
|
Uint16 FLASH::read(Uint16 *Dest, Uint32 Length)
|
|
{
|
|
Uint16 *Source = m_sector.StartAddr;
|
|
Uint16 status = 0;
|
|
if(Length <= 0x4000)
|
|
{
|
|
for(Uint32 i=0; i<Length; i++)
|
|
{
|
|
(*Dest++) = (*Source++);
|
|
//
|
|
}//end for
|
|
status = 1;
|
|
//
|
|
}//end if
|
|
//
|
|
return status;
|
|
//
|
|
}//end
|
|
|
|
Uint16 FLASH::program(Uint16 *BufAddr, Uint32 Length)
|
|
{
|
|
Uint16 status = STATUS_SUCCESS;
|
|
|
|
m_status_erase.FirstFailAddr = 0;
|
|
m_status_erase.ExpectedData = 0;
|
|
m_status_erase.ActualData = 0;
|
|
|
|
m_status_program.FirstFailAddr = 0;
|
|
m_status_program.ExpectedData = 0;
|
|
m_status_program.ActualData = 0;
|
|
|
|
m_status_verify.FirstFailAddr = 0;
|
|
m_status_verify.ExpectedData = 0;
|
|
m_status_verify.ActualData = 0;
|
|
|
|
status = Flash_Erase(m_mask_sector, &m_status_erase);
|
|
|
|
if(status != STATUS_SUCCESS) return status;
|
|
|
|
//Flash_Program(Uint16 *FlashAddr, Uint16 *BufAddr, Uint32 Length, FLASH_ST *FProgStatus);
|
|
status = Flash_Program(m_sector.StartAddr, BufAddr, Length, &m_status_program);
|
|
|
|
if(status != STATUS_SUCCESS) return status;
|
|
|
|
//Flash_Verify(Uint16 *StartAddr, Uint16 *BufAddr, Uint32 Length, FLASH_ST *FVerifyStat);
|
|
status = Flash_Verify(m_sector.StartAddr, BufAddr, Length, &m_status_verify);
|
|
|
|
return status;
|
|
//
|
|
}//end
|
|
|
|
Uint16 FLASH::verify(Uint16 *BufAddr, Uint32 Length)
|
|
{
|
|
Uint16 status = STATUS_SUCCESS;
|
|
|
|
m_status_verify.FirstFailAddr = 0;
|
|
m_status_verify.ExpectedData = 0;
|
|
m_status_verify.ActualData = 0;
|
|
|
|
//Flash_Verify(Uint16 *StartAddr, Uint16 *BufAddr, Uint32 Length, FLASH_ST *FVerifyStat);
|
|
status = Flash_Verify(m_sector.StartAddr, BufAddr, Length, &m_status_verify);
|
|
|
|
return status;
|
|
//
|
|
}//end
|
|
|
|
Uint16 FLASH::APIVersionHex()
|
|
{
|
|
Uint16 version = 0;
|
|
version = Flash_APIVersionHex();
|
|
|
|
return version;
|
|
//
|
|
}//end
|
|
|
|
} /* namespace DSP28335 */
|