コード例 #1
0
void SaveCalibrationToFlash(U16 add_off, U8 packet_length)
{
   
   U8 flashCheckWrite[3] = {0xFF,0xFE,0xFD};

   // Erase our configuration Flash page
   // And copy our Calibration data into it

   add_off = add_off << 4;

   if(add_off == 0)
   {
      // Erase our configuration Flash page
      FLASH_PageErase( (FLADDR)(&CalInfo1[0]) );   
      // And copy our updated data into it
      FLASH_Write( (FLADDR)(&CalFlashCheck[0]),
         (U8 *)(&flashCheckWrite[0]), 
         3);     
   }

  
   FLASH_Write( (FLADDR)(&CalInfo1[0]) + add_off, 
         (U8 xdata *)(&MainRegister[SET_SENSOR6]), 
         packet_length);

   
}
コード例 #2
0
ファイル: F350_FlashUtils.c プロジェクト: ndpr43/CpE5170
//-----------------------------------------------------------------------------
// FLASH_Update
//-----------------------------------------------------------------------------
//
// This routine replaces <numbytes> from <src> to the FLASH addressed by
// <dest>.  This function calls FLASH_Clear() to handle the dirty work of
// initializing all <dest> bytes to 0xff's prior to copying the bytes from
// <src> to <dest>. This function accepts <numbytes> up to <FLASH_PAGESIZE>.
//
void FLASH_Update (FLADDR dest, char *src, unsigned numbytes)
{
   // 1. Erase <numbytes> starting from <dest>
   FLASH_Clear (dest, numbytes);

   // 2. Write <numbytes> from <src> to <dest>
   FLASH_Write (dest, src, numbytes);
}
コード例 #3
0
ファイル: F410_FlashUtils.c プロジェクト: antijiang/jiu2
void FLASH_Update (FLADDR dest, char *src, unsigned int numbytes)
{
	 int numbytestmp=numbytes;
//  Pause_Measure();
	do{		
			if(numbytestmp>FLASH_PAGESIZE)numbytes=FLASH_PAGESIZE;
			else numbytes=numbytestmp;
		   // 1. Erase <numbytes> starting from <dest>
		   FLASH_Clear (dest, numbytes);

		   // 2. Write <numbytes> from <src> to <dest>
		   FLASH_Write (dest, src, numbytes);
		   numbytestmp=numbytestmp-FLASH_PAGESIZE;
		   dest=dest+FLASH_PAGESIZE;
		   src=src+FLASH_PAGESIZE;
		}while(numbytestmp>0);
//   Restart_Measure() ;

	
}
コード例 #4
0
ファイル: F36x_Flash_Test.c プロジェクト: ndpr43/CpE5170
void main (void)
{
   unsigned char temp_byte = 0x00;
   FLADDR start_address = 0x5FFE;

   char test_write_buff[8] = "ABCDEFG";
   char test_write_buff2[3] = "HIJ";
   char test_read_buff[8] = {0};
   char test_compare_buff[8] = "ABCDEFG";

   unsigned char i;

   bit error_flag = 0;

   PCA0MD &= ~0x40;                    // WDTE = 0 (clear watchdog timer
                                       // enable)

   if ((RSTSRC & 0x02) != 0x02)
   {
      if ((RSTSRC & 0x40) == 0x40)
      {
         LED = 0;
         while(1);                     // Last reset was caused by a Flash
                                       // Error Device Reset
                                       // LED is off and loop forever to
                                       // indicate error
      }
   }

   Oscillator_Init();                  // Initialize the internal oscillator
                                       // to 24.5 MHz

   VDDMon_Init();

   Port_Init();

   LED = 1;

   SFRPAGE = LEGACY_PAGE;

   // Initially erase the test page of Flash
   FLASH_PageErase(start_address);

   //BEGIN TEST================================================================

   // Check if able to Write and Read the Flash--------------------------------
   FLASH_ByteWrite(start_address, 0xA5);

   temp_byte = FLASH_ByteRead(start_address);

   if (temp_byte != 0xA5)
   {
      error_flag = 1;
   }
   //--------------------------------------------------------------------------


   // Check if able to Erase a page of the Flash-------------------------------
   FLASH_PageErase(start_address);

   temp_byte = FLASH_ByteRead(start_address);

   if (temp_byte != 0xFF)
   {
      error_flag = 1;
   }
   //--------------------------------------------------------------------------

   // Check if able to write and read a series of bytes------------------------
   FLASH_Write(start_address, test_write_buff, sizeof(test_write_buff));

   FLASH_Read(test_read_buff, start_address, sizeof(test_write_buff));

   for (i = 0; i < sizeof(test_write_buff); i++)
   {
      if (test_read_buff[i] != test_write_buff[i])
      {
         error_flag = 1;
      }
   }
   //--------------------------------------------------------------------------

   // Check if able to Erase a few bytes---------------------------------------
   FLASH_Clear(start_address, 2);

   FLASH_Read(test_read_buff, start_address, sizeof(test_write_buff));

   // Simulate the same changes to a data array for comparison
   test_compare_buff[0] = 0xFF;
   test_compare_buff[1] = 0xFF;

   for (i = 0; i < sizeof(test_compare_buff); i++)
   {
      if (test_read_buff[i] != test_compare_buff[i])
      {
         error_flag = 1;
      }
   }
   //--------------------------------------------------------------------------

   // Check if able to "update" (erase then re-write) a few bytes--------------
   FLASH_Update (start_address, test_write_buff2, 3);

   FLASH_Read(test_read_buff, start_address, sizeof(test_write_buff));

   // Simulate the same changes to a data array for comparison
   test_compare_buff[0] = test_write_buff2[0];
   test_compare_buff[1] = test_write_buff2[1];
   test_compare_buff[2] = test_write_buff2[2];

   for (i = 0; i < sizeof(test_compare_buff); i++)
   {
      if (test_read_buff[i] != test_compare_buff[i])
      {
         error_flag = 1;
      }
   }
   //--------------------------------------------------------------------------

   // Check if able to copy data in the Flash----------------------------------
   FLASH_Copy (start_address+sizeof(test_write_buff), start_address,
               sizeof(test_write_buff));

   FLASH_Read(test_read_buff, start_address+sizeof(test_write_buff),
              sizeof(test_read_buff));

   for (i = 0; i < sizeof(test_write_buff); i++)
   {
      if (test_read_buff[i] != test_compare_buff[i])
      {
         error_flag = 1;
      }
   }
   //--------------------------------------------------------------------------

   // FLASH test routines------------------------------------------------------
   FLASH_Fill (start_address+sizeof(test_write_buff)*2, sizeof(test_write_buff),
               0x5A);

   FLASH_Read(test_read_buff, start_address+sizeof(test_write_buff)*2,
              sizeof(test_write_buff));

   for (i = 0; i < sizeof(test_write_buff); i++)
   {
      if (test_read_buff[i] != 0x5A)
      {
         error_flag = 1;
      }
   }
   //--------------------------------------------------------------------------

   //END OF TEST===============================================================

   while (1)                           // Loop forever
   {
      // Blink LED to indicate success
      if (error_flag == 0)
      {
         LED = ~LED;

         Timer0_Delay_ms (100);
      }
      else
      {
         LED = 0;
      }
   }
}