コード例 #1
0
ファイル: file_system.c プロジェクト: fgarsombke/Mist
void Schedule_Init(void)
{
    Flash_Init(CLOCK_FREQ_MHZ);

    ScheduleRegistry = (unsigned long *) SCHEDULE_REGISTRY_ADDR;
	  ScheduleRegistrySize = 0;

    // look for current schedule (if one exists!)
    while((ScheduleRegistry[ScheduleRegistrySize] != EMPTY_SCHEDULE_ENTRY) && (ScheduleRegistrySize < 256)) {
        ScheduleRegistrySize++;
    }

    // check if first time loading a schedule
    if((ScheduleRegistrySize % SCHEDULE_REGISTRY_SIZE) == 0) { 
        Flash_Erase(SCHEDULE_REGISTRY_ADDR);
        Flash_Erase(SCHEDULE_BUFFER_A_ADDR);
        Flash_Write(SCHEDULE_REGISTRY_ADDR, SCHEDULE_BUFFER_A_ADDR);
        Schedule = (schedule_entry_t *) SCHEDULE_BUFFER_A_ADDR;
			  TempSchedule = (schedule_entry_t *) SCHEDULE_BUFFER_B_ADDR;
        ScheduleSize = 0;
			  TempScheduleSize = 0;
			  ScheduleRegistrySize = 1;
    } else {
        Schedule = (schedule_entry_t *) ScheduleRegistry[ScheduleRegistrySize-1];
        ScheduleSize = TempScheduleSize;
			  TempScheduleSize = 0;
        if(Schedule == (schedule_entry_t *) SCHEDULE_BUFFER_A_ADDR)  {
            TempSchedule = (schedule_entry_t *) SCHEDULE_BUFFER_B_ADDR;
        } 
        else {  
            TempSchedule = (schedule_entry_t *) SCHEDULE_BUFFER_A_ADDR;
        }
    }
}
コード例 #2
0
void Flash_Write(U16 sector){
  U32 addr = ADDR + sector*SECTOR_SIZE;
  __disable_irq();
  Flash_Erase(sector);
  Flash_Program(sector,DATA_NUM,flashData);
  __enable_irq();
}
コード例 #3
0
ファイル: main.c プロジェクト: 201409366/msp430G2
/******************************************************************************************************
 * 名       称:Write_InfoFlashB()
 * 功       能:将打包好的InfoFlash_Data[]数组,依次写入InfoFlashB段
 * 入口参数:无
 * 出口参数:无
 * 说       明:确保所有CCS工程的Erase Options改为选择“Erase main memory only”,
 * 					只有这样存在InfoFlashB的校验参数才不会因为烧录程序而丢失。
 * 范       例:无
 ******************************************************************************************************/
void Write_InfoFlashB()		//步骤6:将校验数组写入InfoFlahB段
{
	unsigned char i=0;
	//-----写Flash前DCO时钟一定要重新确认一遍-----
    BCSCTL1 = CALBC1_1MHZ;      										/* Set DCO to 8MHz */
    DCOCTL = CALDCO_1MHZ;
    Flash_Init(3,'B');																// 初始化Flash
	Flash_Erase();																	// 擦除Info_B
	//-----把InfoFlash_Data[CAL_NUM]存入InfoFlashB-----
	for(i=0;i<CAL_NUM;i++)
		Flash_Direct_WriteWord(i*2,InfoFlash_Data[i]);		//不擦直接写
}
コード例 #4
0
UINT8 FEraseImage(void)
{
    UINT16 tmpAddr = F_START_ADDR;
    if (su16CurrSize > 0)
    {
        while ((tmpAddr - F_START_ADDR) <= su16CurrSize)
        {
         temp = Flash_Erase(tmpAddr); /* Erase current page */
            tmpAddr += 0x0200; /* Add a page size */
        }
    }
    return F_OK;
}
コード例 #5
0
ファイル: file_system.c プロジェクト: fgarsombke/Mist
void Schedule_Refresh(void) 
{
    if(ScheduleRegistrySize == 256) {
        Flash_Erase(SCHEDULE_REGISTRY_ADDR);
			  ScheduleRegistrySize = 0;
    }
		
		Flash_Write((unsigned long) &ScheduleRegistry[ScheduleRegistrySize], (unsigned long) TempSchedule);
		TempSchedule = Schedule;
	  Schedule = (schedule_entry_t *) ScheduleRegistry[ScheduleRegistrySize];
		ScheduleRegistrySize++;
	  
		ScheduleSize = TempScheduleSize;
	  TempScheduleSize = 0;
}
コード例 #6
0
ファイル: Fls.c プロジェクト: miaozhendaoren/PWC-Demonstrator
/**
 * Erase flash sectors
 *
 * @param TargetAddress Always from 0 to FLS_TOTAL_SIZE
 * @param Length
 * @return
 */
Std_ReturnType Fls_Erase(Fls_AddressType TargetAddress, Fls_LengthType Length) {
#if FLS_BASE_ADDRESS > 0
	/* Avoid compiler warning */
	TargetAddress += FLS_BASE_ADDRESS;
#endif

	/** @req SWS_Fls_00218  */
	/** @req SWS_Fls_00220 */
	/** @req SWS_Fls_00327 */

	/** @req SWS_Fls_00065 */
	VALIDATE_W_RV( Fls_Global.status != MEMIF_UNINIT, FLS_ERASE_ID, FLS_E_UNINIT, E_NOT_OK );
	/** @req SWS_Fls_00023 */
	VALIDATE_W_RV( Fls_Global.status != MEMIF_BUSY, FLS_ERASE_ID, FLS_E_BUSY, E_NOT_OK );
    /** @req SWS_Fls_00020 */
	VALIDATE_W_RV( E_OK == sectorAligned( TargetAddress ),
	        FLS_ERASE_ID, FLS_E_PARAM_ADDRESS, E_NOT_OK );
    /** @req SWS_Fls_00021  */
    VALIDATE_W_RV( (Length != 0) && (EE_OK == sectorAligned( TargetAddress + Length)),
            FLS_ERASE_ID, FLS_E_PARAM_LENGTH, E_NOT_OK );
#if defined(CFG_MPC5777M)
    VALIDATE_W_RV((E_OK == checkValidChunk(TargetAddress, TargetAddress + Length - 1)), FLS_ERASE_ID, FLS_E_INVALID_AREA, E_NOT_OK);
#endif

	Fls_Global.status = MEMIF_BUSY;				    /** @req SWS_Fls_00328 */
	Fls_Global.jobResultType = MEMIF_JOB_PENDING;   /** @req SWS_Fls_00329 */
	Fls_Global.jobType = FLS_JOB_ERASE;
	Fls_Global.flashAddr = TargetAddress;
	Fls_Global.length = Length;

	LOG_HEX2("Fls_Erase() ",TargetAddress," ", Length);

	/* Unlock */
	Flash_Lock(Fls_Global.config->FlsInfo,FLASH_OP_UNLOCK,TargetAddress, Length );

	/** @req SWS_Fls_00145 */
	if (EE_OK != Flash_Erase(Fls_Global.config->FlsInfo,TargetAddress, Length, NULL )) {
	    return E_NOT_OK;
	}

	return E_OK;	/** @req SWS_Fls_00330 */
}
コード例 #7
0
ファイル: flash.c プロジェクト: bobcat8/A2300
/**
* Action Message Handler
*/
void OnWcaAction( Dci_Context* pctxt)
{
	int	 ec;
	
	//TODO, need to define Action ID for Clearing Flash Memory.  
	//This needs to be updated in the ASR-2300 Communications Interface Specification.
	Dci_ExecuteAction *pact = (Dci_ExecuteAction*) pctxt->pMsg;
	switch( pact->idAction)
	{
		case FLASH_ActionErase:
			main_LogMsg( LOG_INFO, WCACOMP_FLASH,"Erasing", pctxt);
			ec = Flash_Erase();
			main_LogMsg( LOG_INFO, WCACOMP_FLASH,ec? "Erase Err":"Erase Success", pctxt);
		break;
		case FLASH_ActionValidate:
			//TODO
		break;
	}
	pctxt->bHandled = true;
}
コード例 #8
0
//------------Scoreboard_Record------------
// Record a score in the scoreboard, regardless of whether or
// not the numerical score is high enough to be shown at the top.
// Input: first  first initial
//        middle middle initial
//        last   last initial
//        score  numerical score earned in the game
// Output: none
void Scoreboard_Record(char first, char middle, char last, uint32_t score){
  int i, j;
  // compare the score with the RAM scoreboard so far
  for(i=0; i<SCOREBOARDSIZE; i=i+1){
    if(score > RAMScoreboard[i].score){
      // found a score better than one in RAM
      // shift all lower scores down
      for(j=(SCOREBOARDSIZE-1); j>i; j=j-1){
        RAMScoreboard[j].first = RAMScoreboard[j-1].first;
        RAMScoreboard[j].middle = RAMScoreboard[j-1].middle;
        RAMScoreboard[j].last = RAMScoreboard[j-1].last;
        RAMScoreboard[j].score = RAMScoreboard[j-1].score;
      }
      // insert the new score in the RAM scoreboard
      RAMScoreboard[i].first = first;
      RAMScoreboard[i].middle = middle;
      RAMScoreboard[i].last = last;
      RAMScoreboard[i].score = score;
      // do not over-write all lower scores
      break;
    }
  }
  if((boardptr <= (uint32_t *)(scoreblock + 0x3F8))){
    // there is still room in the block to hold more scores
    // append the new score to the end of the scores in flash
    Flash_Write((uint32_t)boardptr, (first<<24)|(middle<<16)|(last<<8));
    Flash_Write((uint32_t)(boardptr + 1), score);
    boardptr = boardptr + 2;
  } else{
    // there is no more room in the block to hold more scores
    // clear the block
    Flash_Erase(scoreblock);
    boardptr = (uint32_t *)scoreblock;
    // store the top 'SCOREBOARDSIZE' scores from the RAM buffer
    for(i=0; i<SCOREBOARDSIZE; i=i+1){
      Flash_Write((uint32_t)boardptr, (RAMScoreboard[i].first<<24)|(RAMScoreboard[i].middle<<16)|(RAMScoreboard[i].last<<8));
      Flash_Write((uint32_t)(boardptr + 1), RAMScoreboard[i].score);
      boardptr = boardptr + 2;
    }
  }
}
コード例 #9
0
ファイル: Fls.c プロジェクト: uincore/OpenSAR
/**
 * Erase flash sectors
 *
 * @param TargetAddress Always from 0 to FLS_TOTAL_SIZE
 * @param Length
 * @return
 */
Std_ReturnType Fls_Erase(Fls_AddressType TargetAddress, Fls_LengthType Length) {
	TargetAddress += FLS_BASE_ADDRESS;

	/** @req FLS250 3.0/4.0 */
	/** @req FLS218 3.0/4.0 */
	/** @req FLS220 3.0/4.0 */
	/** @req FLS327 4.0     */

	/** @req FLS065 */
	VALIDATE_W_RV( Fls_Global.status != MEMIF_UNINIT, FLS_ERASE_ID, FLS_E_UNINIT, E_NOT_OK );
	/** @req FLS023 */
	VALIDATE_W_RV( Fls_Global.status != MEMIF_BUSY, FLS_ERASE_ID, FLS_E_BUSY, E_NOT_OK );
    /** @req FLS020 3.0/4.0 */
	VALIDATE_W_RV( E_OK == fls_SectorAligned( TargetAddress ),
	        FLS_ERASE_ID, FLS_E_PARAM_ADDRESS, E_NOT_OK );
    /** @req FLS021 3.0/4.0 */
    VALIDATE_W_RV( (Length != 0) && (EE_OK == fls_SectorAligned( TargetAddress + Length)),
            FLS_ERASE_ID, FLS_E_PARAM_LENGTH, E_NOT_OK );

	// Check if we trying to erase a partition that we are executing in
#if 0
	pc = fls_GetPc();
#endif


	Fls_Global.status = MEMIF_BUSY;				    /** @req FLS219 3.0 */ /** @req FLS328 4.0 */
	Fls_Global.jobResultType = MEMIF_JOB_PENDING;   /** @req FLS329 4.0 */
	Fls_Global.jobType = FLS_JOB_ERASE;
	Fls_Global.flashAddr = TargetAddress;
	Fls_Global.length = Length;

	LOG_HEX2("Fls_Erase() ",TargetAddress," ", Length);

	/* Unlock */
	Flash_Lock(Fls_Global.config->FlsInfo,FLASH_OP_UNLOCK,TargetAddress, Length );

	/** @req FLS145 */
	Flash_Erase(Fls_Global.config->FlsInfo,TargetAddress, Length, NULL );

	return E_OK;	/** @req FLS330 4.0 */
}
コード例 #10
0
ファイル: file_system.c プロジェクト: fgarsombke/Mist
int Schedule_Enter(schedule_entry_t *entry_ptr)
{
    unsigned long next_entry_addr = (unsigned long) &TempSchedule[TempScheduleSize];
    // make sure sure schedule buffer is not full
    // TODO make -1 an error enum?

    // TODO make SCHEDULE_SIZE
    if(next_entry_addr > ((unsigned long) TempSchedule + 0x4000)) 
        return -1;

    // erase flash sector before starting to write schedule there
    if(next_entry_addr % 0x400 == 0) // TODO FLASH_SECTOR_SIZE
        Flash_Erase(next_entry_addr);

    //entry_ptr->not_completed = 0xFFFFFFFF; // TODO
    Flash_ProgramArray((unsigned long *) entry_ptr, next_entry_addr, 4);

    TempScheduleSize++;

    return 0; // TODO SUCCESS
}
コード例 #11
0
void Example_CallFlashAPI(void)
{
   Uint16  i;
   Uint16  Status;
   Uint16  *Flash_ptr;     // Pointer to a location in flash
   Uint32  Length;         // Number of 16-bit values to be programmed
   float32 Version;        // Version of the API in floating point
   Uint16  VersionHex;     // Version of the API in decimal encoded hex

/*------------------------------------------------------------------
  Toggle Test

  The toggle test is run to verify the frequency configuration of
  the API functions.
  
  The selected pin will toggle at 10kHz (100uS cycle time) if the
  API is configured correctly.
  
  Example_ToggleTest() supports common output pins. Other pins can be used
  by modifying the Example_ToggleTest() function or calling the Flash_ToggleTest()
  function directly.
  
  Select a pin that makes sense for the hardware platform being used.
  
  This test will run forever and not return, thus only run this test
  to confirm frequency configuration and not during normal API use.
------------------------------------------------------------------*/
     
   // Example: Toggle GPIO0
   // Example_ToggleTest(0);
   
   // Example: Toggle GPIO10
   // Example_ToggleTest(10);
   
   // Example: Toggle GPIO15
   // Example_ToggleTest(15);   
   
   // Example: Toggle GPIO31
   // Example_ToggleTest(31);   

   // Example: Toggle GPIO34
   // Example_ToggleTest(34);   

/*------------------------------------------------------------------
  Check the version of the API
  
  Flash_APIVersion() returns the version in floating point.
  FlashAPIVersionHex() returns the version as a decimal encoded hex.
  
  FlashAPIVersionHex() can be used to avoid processing issues
  associated with floating point values.    
------------------------------------------------------------------*/
   VersionHex = Flash_APIVersionHex();
   if(VersionHex != 0x0100)
   {
       // Unexpected API version
       // Make a decision based on this info. 
       asm("    ESTOP0");
   }   


   Version = Flash_APIVersion();
   if(Version != (float32)1.00)
   {
       // Unexpected API version
       // Make a decision based on this info. 
       asm("    ESTOP0");
   }
   
   
   
  


/*------------------------------------------------------------------
  Before programming make sure the sectors are Erased. 

------------------------------------------------------------------*/

   // Example: Erase Sector B - Sector H
   // Sectors A has example code so leave them unerased
   
   // SECTORA-SECTORH are defined in Flash2803x_API_Library.h
   Status = Flash_Erase((SECTORB|SECTORC|SECTORD|SECTORE|SECTORF|SECTORG|SECTORH),&FlashStatus);
   if(Status != STATUS_SUCCESS) 
   {
       Example_Error(Status);
   } 
   

/*------------------------------------------------------------------
  Program Flash Examples

------------------------------------------------------------------*/

// A buffer can be supplied to the program function.  Each word is
// programmed until the whole buffer is programmed or a problem is 
// found.  If the buffer goes outside of the range of OTP or Flash
// then nothing is done and an error is returned. 

 
    // Example: Program 0x400 values in Flash SectorG
     
    // In this case just fill a buffer with data to program into the flash. 
    for(i=0;i<WORDS_IN_FLASH_BUFFER;i++)
    {
        Buffer[i] = 0x100+i;
    }
    
    Flash_ptr = Sector[1].StartAddr;
    Length = 0x400;
    Status = Flash_Program(Flash_ptr,Buffer,Length,&FlashStatus);
    if(Status != STATUS_SUCCESS) 
    {
        Example_Error(Status);
    }


    
    // Verify the values programmed.  The Program step itself does a verify
    // as it goes.  This verify is a 2nd verification that can be done.      
    Status = Flash_Verify(Flash_ptr,Buffer,Length,&FlashStatus);
    if(Status != STATUS_SUCCESS) 
    {
        Example_Error(Status);
    }            

// --------------

    // Example: Program 0x199 values in Flash SectorG 

    for(i=0;i<WORDS_IN_FLASH_BUFFER;i++)
    {
        Buffer[i] = 0x4500+i;
    }
    
    Flash_ptr = (Uint16 *)Sector[1].StartAddr+0x450;
    Length = 0x199;
    Status = Flash_Program(Flash_ptr,Buffer,Length,&FlashStatus);
    if(Status != STATUS_SUCCESS) 
    {
        Example_Error(Status);
    }
    
    // Verify the values programmed.  The Program step itself does a verify
    // as it goes.  This verify is a 2nd verification that can be done.      
    Status = Flash_Verify(Flash_ptr,Buffer,Length,&FlashStatus);
    if(Status != STATUS_SUCCESS) 
    {
        Example_Error(Status);
    } 


// --------------
// You can program a single bit in a memory location and then go back to 
// program another bit in the same memory location. 

   // Example: Program bit 0 in location in Flash SectorF.  
   // That is program the value 0xFFFE
   Flash_ptr = Sector[2].StartAddr;
   i = 0xFFFE;
   Length = 1;
   Status = Flash_Program(Flash_ptr,&i,Length,&FlashStatus);
   if(Status != STATUS_SUCCESS) 
   {
       Example_Error(Status);
   }

   // Example: Program bit 1 in the same location. Remember
   // that bit 0 was already programmed so the value will be 0xFFFC
   // (bit 0 and bit 1 will both be 0) 
   
   i = 0xFFFC;
   Length = 1;
   Status = Flash_Program(Flash_ptr,&i,Length,&FlashStatus);
   if(Status != STATUS_SUCCESS) 
   {
       Example_Error(Status);
   }
   

    // Verify the value.  This first verify should fail. 
    i = 0xFFFE;    
    Status = Flash_Verify(Flash_ptr,&i,Length,&FlashStatus);
    if(Status != STATUS_FAIL_VERIFY) 
    {
        Example_Error(Status);
    } 
    
    // This is the correct value and will pass.
    i = 0xFFFC;
    Status = Flash_Verify(Flash_ptr,&i,Length,&FlashStatus);
    if(Status != STATUS_SUCCESS) 
    {
        Example_Error(Status);
    } 

// --------------
// If a bit has already been programmed, it cannot be brought back to a 1 by
// the program function.  The only way to bring a bit back to a 1 is by erasing
// the entire sector that the bit belongs to.  This example shows the error
// that program will return if a bit is specified as a 1 when it has already
// been programmed to 0.

   // Example: Program a single 16-bit value 0x0002, in Flash Sector B
   Flash_ptr = Sector[2].StartAddr+1;
   i = 0x0002;
   Length = 1;
   Status = Flash_Program(Flash_ptr,&i,Length,&FlashStatus);
   if(Status != STATUS_SUCCESS) 
   {
       Example_Error(Status);
   }

   // Example: This will return an error!!  Can't program 0x0001
   // because bit 0 in the the location was previously programmed
   // to zero!
   
   i = 0x0001;
   Length = 1;
   Status = Flash_Program(Flash_ptr,&i,Length,&FlashStatus);
   // This should return a STATUS_FAIL_ZERO_BIT_ERROR
   if(Status != STATUS_FAIL_ZERO_BIT_ERROR) 
   {
       Example_Error(Status);
   }
   
// --------------   
   
   // Example: This will return an error!!  The location specified
   // is outside of the Flash and OTP!
   Flash_ptr = (Uint16 *)0x00340000;
   i = 0x0001;
   Length = 1;
   Status = Flash_Program(Flash_ptr,&i,Length,&FlashStatus);
   // This should return a STATUS_FAIL_ADDR_INVALID error
   if(Status != STATUS_FAIL_ADDR_INVALID) 
   {
       Example_Error(Status);
   }
   
// --------------   
   
   // Example: This will return an error!!  Can't program 1
   // because bit 0 in the the location was previously programmed
   // to zero!
    for(i=0;i<WORDS_IN_FLASH_BUFFER;i++)
    {
        Buffer[i] = 0xFFFF;
    }
    
    Flash_ptr = Sector[0].EndAddr;
    Length = 13;
    Status = Flash_Program(Flash_ptr,Buffer,Length,&FlashStatus);
    if(Status != STATUS_FAIL_ZERO_BIT_ERROR)//STATUS_FAIL_ADDR_INVALID) 
    {
        Example_Error(Status);
    }   


/*------------------------------------------------------------------
  More Erase Sectors Examples - Clean up the sectors we wrote to:

------------------------------------------------------------------*/

   // Example: Erase Sector G
   // SECTORB is defined in Flash2803x_API_Library.h
   Status = Flash_Erase(SECTORG,&FlashStatus);
   if(Status != STATUS_SUCCESS) 
   {
       Example_Error(Status);
   }
   
   // Example: Erase Sector F
   // SECTORC is defined in Flash2803x_API_Library.h
   Status = Flash_Erase((SECTORF),&FlashStatus);
   if(Status != STATUS_SUCCESS) 
   {
       Example_Error(Status);
   }
   
   
   // Example: This will return an error. No valid sector is specified.
   Status = Flash_Erase(0,&FlashStatus);
   // Should return STATUS_FAIL_NO_SECTOR_SPECIFIED
   if(Status != STATUS_FAIL_NO_SECTOR_SPECIFIED) 
   {
       Example_Error(Status);
   }

   Example_Done();
 
} 
コード例 #12
0
ファイル: Shared_Boot.c プロジェクト: 14Ohm/Energia
void CopyData()
{

   struct HEADER {
     Uint16 BlockSize;
     Uint32 DestAddr;
     Uint32 ProgBuffAddr;
   } BlockHeader;

   Uint16 wordData;
   Uint16 status;
   Uint16 i,j;

   //Make sure code security is disabled
   CsmUnlock();

   EALLOW;
   Flash_CPUScaleFactor = SCALE_FACTOR;
   Flash_CallbackPtr = NULL;
   EDIS;

   status = Flash_Erase((SECTORA | SECTORB | SECTORC | SECTORD), &FlashStatus);
   if(status != STATUS_SUCCESS)
   {
	   //TODO fix so that it returns a serial error and reboot device
       return;
   }

   // After Flash Erase, send the checksum to PC program.
   SendCheckSum();
   // Get the size in words of the first block
   BlockHeader.BlockSize = (*GetOnlyWordData)();

   // While the block size is > 0 copy the data
   // to the DestAddr.  There is no error checking
   // as it is assumed the DestAddr is a valid
   // memory location

   while(BlockHeader.BlockSize != (Uint16)0x0000)
   {

	  if(BlockHeader.BlockSize > PROG_BUFFER_LENGTH){
		  //Block is to big to fit into our buffer so we must program it in chunks
	      BlockHeader.DestAddr = GetLongData();
	      //Program as many full buffers as possible
	      for(j = 0; j < (BlockHeader.BlockSize / PROG_BUFFER_LENGTH); j++){
		      BlockHeader.ProgBuffAddr = (Uint32)progBuf;
		      for(i = 1; i <= PROG_BUFFER_LENGTH; i++)
		      {
		          wordData = (*GetOnlyWordData)();
		          *(Uint16 *)BlockHeader.ProgBuffAddr++ = wordData;
		      }
		      status = Flash_Program((Uint16 *) BlockHeader.DestAddr, (Uint16 *)progBuf, PROG_BUFFER_LENGTH, &FlashStatus);
		      if(status != STATUS_SUCCESS)
		      {
		          return;
		      }
		      BlockHeader.DestAddr += PROG_BUFFER_LENGTH;
		      // After Flash program, send the checksum to PC program.
		      SendCheckSum();
	      }
	      //Program the leftovers
	      BlockHeader.ProgBuffAddr = (Uint32)progBuf;
	      for(i = 1; i <= (BlockHeader.BlockSize % PROG_BUFFER_LENGTH); i++)
	      {
	          wordData = (*GetOnlyWordData)();
	          *(Uint16 *)BlockHeader.ProgBuffAddr++ = wordData;
	      }
	      status = Flash_Program((Uint16 *) BlockHeader.DestAddr, (Uint16 *)progBuf, (BlockHeader.BlockSize % PROG_BUFFER_LENGTH), &FlashStatus);
	      if(status != STATUS_SUCCESS)
	      {
	          return;
	      }
	      // After Flash program, send the checksum to PC program.
	      SendCheckSum();
	  }else{
		  //Block will fit into our buffer so we'll program it all at once
	      BlockHeader.DestAddr = GetLongData();
	      BlockHeader.ProgBuffAddr = (Uint32)progBuf;
	      for(i = 1; i <= BlockHeader.BlockSize; i++)
	      {
	          wordData = (*GetOnlyWordData)();
	          *(Uint16 *)BlockHeader.ProgBuffAddr++ = wordData;
	      }
	      status = Flash_Program((Uint16 *) BlockHeader.DestAddr, (Uint16 *)progBuf, BlockHeader.BlockSize, &FlashStatus);
	      if(status != STATUS_SUCCESS)
	      {
	          return;
	      }
	      // After Flash program, send the checksum to PC program.
	      SendCheckSum();
	  }



      // Get the size of the next block
      BlockHeader.BlockSize = (*GetOnlyWordData)();
   }
   return;
}
コード例 #13
0
ファイル: flash.c プロジェクト: BraedanJ/AutonomousExplorer
// bQuick=TRUE: just check first and last block 
bool FLASH_Verify(char *pFlashName, alt_u8 InitValue, bool bShowMessage, bool bQuickVerify){
    bool bPass = TRUE;
    int i, k, BlockNum;
    FLASH_HANDLE hFlash;
    alt_u32 Offset, Size;
    alt_u8 *pBuf, Cnt;
    const int nBufSize = 8*1024; // 16K
    int nWriteSizeSum, nWriteSize;
    int nReadSizeSum, nReadSize;
    
    hFlash = Flash_Open(pFlashName);
    if (!hFlash){
        if (bShowMessage)
            printf("Failed to open flash.\r\n");
        return FALSE;
    }        
        
        
    BlockNum = Flash_GetBlockCount(hFlash);
    
    //===== alloc buffer
    pBuf = (alt_u8 *)malloc(nBufSize);
    if (!pBuf){
        if (bShowMessage)
            printf("[Error] Failed to alloc memory.\r\n");
        return FALSE;
    }        
    
    
    //===== erase
    for(i=0;i<BlockNum && bPass;i++){
        if (bQuickVerify && (i !=0 )&& (i != (BlockNum-1)))
            continue;
        bPass = Flash_Erase(hFlash, i);
        if (bShowMessage){
            if (!bPass)
                printf("[Error] Failed to erase flash block %d/%d\r\n.\r\n", i, BlockNum);
            else
                printf("Erase Block %d/%d\r\n", i, BlockNum);
        }            
    }        
    
    //===== write
    if (bPass){
        Cnt = InitValue;
        for(i=0;i<BlockNum && bPass;i++){
            if (bQuickVerify && (i !=0 )&& (i != (BlockNum-1)))
                continue;
            
            bPass = Flash_GetBlockInfo(hFlash, i, &Offset, &Size);
            if (!bPass)
                continue;
                
            if (bShowMessage)            
                printf("Write Block[%d/%d], size=%d\r\n", i, BlockNum, (int)Size);
            nWriteSizeSum = 0;
            while(nWriteSizeSum < Size && bPass){
                // cal write size
                nWriteSize = nBufSize;
                if (nWriteSize > (Size - nWriteSizeSum))
                    nWriteSize = Size - nWriteSizeSum;
                // fill data
                for(k=0;k<nWriteSize;k++){
                    *(pBuf+k) = Cnt++;
                }                     
                // write data block
                bPass = Flash_Write(hFlash, Offset+nWriteSizeSum, pBuf, nWriteSize);
                if (bShowMessage && !bPass)            
                    printf("[Error] Write Block[%d/%d] NG\r\n", i, BlockNum);
                //
                usleep(20*1000);
                //
                nWriteSizeSum += nWriteSize;
            }
        }
    }
  
    if (bPass){
        if (bShowMessage)      
            printf("alt_dcache_flush_all\r\n");
        alt_dcache_flush_all();
    }        
      
    //===== read & verify
    if (bPass){
        Cnt = InitValue;
        for(i=0;i<BlockNum && bPass;i++){
            if (bQuickVerify && (i !=0 )&& (i != (BlockNum-1)))
                continue;
            
            bPass = Flash_GetBlockInfo(hFlash, i, &Offset, &Size);
            if (!bPass){
                if (bShowMessage)      
                    printf("[Error] Flash_GetBlockInfo at block %d\r\n", i);
                continue;
            }    
            if (bShowMessage)            
                printf("Read Block[%d/%d], size=%d\r\n", i, BlockNum, (int)Size);
            nReadSizeSum = 0;
            while(nReadSizeSum < Size && bPass){
                // cal write size
                nReadSize = nBufSize;
                if (nReadSize > (Size - nReadSizeSum))
                    nReadSize = Size - nReadSizeSum;
                    
                // read data block
                bPass = Flash_Read(hFlash, Offset+nReadSizeSum, pBuf, nReadSize);
                if (!bPass){
                    if (bShowMessage)      
                        printf("[Error] Flash_Read fail at block-offset %d-%d\r\n", i, (int)Offset+nReadSizeSum);
                }else{
                    // verify
                    // verify data
                    for(k=0;k<nReadSize && bPass;k++){
                        if (*(pBuf+k) != Cnt){
                            if (bShowMessage)      
                                printf("[Error] Verify fail, block:%d, index:%d, read=%Xh, expected=%Xh\r\n", i, nReadSizeSum+k, *(pBuf+k), Cnt);
                            bPass = FALSE;
                        }else{    
                            Cnt++;
                        }
                    }                     
                }                        
                //
                nReadSizeSum += nReadSize;
            }
        }  
    }
    
    if (pBuf)
        free(pBuf);
    
    if (hFlash)
        Flash_Close(hFlash);
    
    //
    return bPass;
}
コード例 #14
0
void WBootloader_Handler(void){       
      
   INT8U  retorno = 0;
   INT32U crc_casting = 0;
   INT32U status = 0;
   INT8U  k=0;
   INT8U  dir;
   
    LATITUDE   lat;
    LONGITUDE  lon;
    
    // Reset timeout counter    
    error = 0;

    retorno = Decode_Data_Profile();
    if((retorno == BOOTLOADER_OK) || (retorno == BOOTLOADER_CRC_OK))
    {
         resp[0]=BOOTLOADER_DATA_OK;
         resp[1]=bootloader_data[5];
         resp[2]=bootloader_data[6];
         resp[3]=bootloader_data[7];  
    } 
    else
    {
        resp[0] = retorno;
        
        /* erase flash memory */
        WBootloader_Wireless_Flash_EraseAll(CODE_START);
        
        UserEnterCritical();                   
          crc_codigo = 0xffff;
          crc_codigo2 = 0xffff;
          CRC16 = 0xffff;
          endereco = CODE_START;
        UserExitCritical(); 
    }


    if(resp[0])
    {      
      /* copy source address */
      for(k=0;k<4;k++)
      {
        lat.bytes[k] = nwk_packet.NWK_Src_Lat[k];
      }
      
      for(k=0;k<4;k++)
      {
        lon.bytes[k] = nwk_packet.NWK_Src_Long[k];
      }        
      
      dst_gps_latX  = lat.x;
      dst_gps_longY = lon.y; 
      
      dir = UP_ROUTE;
      
      for(k=0;k<MAX_BASE_STATION;k++){
        
        if(BaseStations[k].GPS_Latitude.x == lat.x && BaseStations[k].GPS_Longitude.y == lon.y){
          dir = DOWN_ROUTE;
          break;
        }
      }
      
      if(NetSimpledata(dir, (INT8U)BOOT_INSTALLER,&resp[0]) != OK)
      {
        error++;
      }else
      {
        if (retorno == BOOTLOADER_CRC_OK)
        {
        
            /* 
            passa para a variavel status um valor que sera a
            armazenado na posicao STATUS_ADDR. 
            Ao iniciar o programa este valor sera lido 
            para decidir se o programa vai para o main ou 
            para o  bootloader
            */                  
            status=0xFFFF0000;  
                        
            UserEnterCritical();             
              
              #if (PROCESSOR == COLDFIRE_V1)
              /* erase also position, mac and pan id */
                  Flash_Erase(LAT_MEM_ADDRESS);
              #endif
            
            Flash_Prog(STATUS_ADDR,(dword)&status,1);
              crc_casting = (INT32U)(crc_codigo2 & 0xFFFF);
            Flash_Prog(CRC_ADDR,(dword)&crc_casting,1);
            
            /* força reinicialização (por watchdog) */
            for(;;)
            {
                asm(nop);
            } 
        }
      }
      
      resp[0]=0;
      resp[1]=0;
      resp[2]=0;
      resp[3]=0;
    }  
コード例 #15
0
void FContextChange()
{
  
  UINT8 u8ByteCount = 0;
  UINT16 u16Addr = 0x0000;
  UINT8 *pu8srcData = (UINT8 *)F_START_ADDR;
  UINT8 *pu8dstData = (UINT8 *) 0;
  UINT16 u16Index = 0;
  UINT8 i=0;  
  /* Let's first erase all the pages to which the image references */
  while (u16Index <= su16CurrSize)
  {
    /*Find addr*/
    u16Addr  = (UINT16)pu8srcData[u16Index]<<8;
    u16Addr |= (UINT16)pu8srcData[++u16Index];
    pu8dstData = (UINT8 *) u16Addr;
    u8ByteCount = pu8srcData[++u16Index];
    if (u8ByteCount == 0xFF)
      break;  // End of file reached
    for (i=0;i<u8ByteCount;i++)
    {
      if (*(pu8dstData) != 0xFF)
      {
        (void)Flash_Erase(pu8dstData);
        break;
      }
      pu8dstData++;
    }
    pu8dstData = (UINT8 *) u16Addr;
    
    
    u16Index += u8ByteCount;
    u16Index++;
    u16Index++;
  }
  u16Index = 0;
  i=0;  
  
  /* Now let's program the addresses referenced by the image */
  while (u16Index <= su16CurrSize)
  {
    /*Find addr*/
    u16Addr  = (UINT16)pu8srcData[u16Index]<<8;
    u16Addr |= (UINT16)pu8srcData[++u16Index];
    pu8dstData = (UINT8 *) u16Addr;
    u8ByteCount = pu8srcData[++u16Index];
    if (u8ByteCount == 0xFF)
      break;  // End of file reached
    pu8dstData = (UINT8 *) u16Addr;
    
    for (i=0;i<u8ByteCount;i++, pu8dstData++)
    {
      (void)Flash_Program(pu8dstData, pu8srcData[++u16Index]);
    }
    //Flash_Burst(pu8dstData, u8ByteCount, &pu8srcData[++u16Index]);
    
    //u16Index += u8ByteCount;
    u16Index++;
    u16Index++;
  }

  __asm SWI;
}