コード例 #1
0
ファイル: istrata1.c プロジェクト: gxliu/MQX_3.8.0
boolean _intel_strata_program_1byte
   (  
      /* [IN] the base address of the device */
      IO_FLASHX_STRUCT_PTR  handle_ptr,

      /* [IN] where to copy data from */
      char_ptr              from_ptr,
      
      /* [OUT} where to copy data to */
      char_ptr              to_ptr,

      /* [IN] the sector size to copy */
      _mem_size             sector_size,

      /* [IN] the offset to start at */
      _mem_size             offset
   )
{ /* Body */
   boolean                 erase;
   boolean                 success;
   boolean                 timeout;
   _mqx_uint               j;
   MQX_TICK_STRUCT         start_ticks;

   /* First make sure we actually need to program the sector */
   erase = FALSE;

   for (j = offset; !erase && (j < sector_size); j++) {
      erase = ISTRATA_ERASE_UNIT(to_ptr[j], from_ptr[j]);
   } /* Endfor */

   if (erase) {
      success = _intel_strata_erase_1byte(handle_ptr, to_ptr, 
         sector_size, &start_ticks);
      if (!success) {
         return success;
      } /* Endif */
      /* 
      ** We erased the whole sector so we must program from the beginning of
      ** the sector
      */
      offset = 0;
   } else {
      success = TRUE;
   } /* Endif */

   if (handle_ptr->DEVICES == 1) {
      volatile uchar _PTR_  dest_ptr = (volatile uchar _PTR_)to_ptr;
      uchar _PTR_           src_ptr  = (uchar _PTR_)from_ptr;
      _mem_size             size = sector_size;
      uchar                 tmp, status;

      dest_ptr = dest_ptr + offset;
      src_ptr  = src_ptr  + offset;

      ISTRATA_PROGRAM(ISTRATA_READ_MODE_CMD_8X1, ISTRATA_WRITE_CMD_8X1, 
         ISTRATA_STATUS_BUSY_8X1);
   } else if (handle_ptr->DEVICES == 2) {
      volatile uint_16 _PTR_  dest_ptr = (volatile uint_16 _PTR_)((pointer)to_ptr);
      uint_16 _PTR_           src_ptr  = (uint_16 _PTR_)((pointer)from_ptr);
      _mem_size               size;
      uint_16                 tmp, status;

      size = sector_size >> 1;
      offset >>= 1;
      dest_ptr = dest_ptr + offset;
      src_ptr  = src_ptr  + offset;

      ISTRATA_PROGRAM(ISTRATA_READ_MODE_CMD_8X2, ISTRATA_WRITE_CMD_8X2, 
         ISTRATA_STATUS_BUSY_8X2);
   } else if (handle_ptr->DEVICES == 4) {
コード例 #2
0
ファイル: istrata4.c プロジェクト: gaodebang/eth-com-project
boolean _intel_strata_program_4byte
   (  
      /* [IN] the base address of the device */
      IO_FLASHX_STRUCT_PTR  handle_ptr,

      /* [IN] where to copy data from */
      uint_32_ptr           from_ptr,
      
      /* [OUT} where to copy data to */
      uint_32_ptr           to_ptr,

      /* [IN] the sector size to copy */
      _mem_size             sector_size,

      /* [IN] the offset to start at */
      _mem_size             offset
   )
{ /* Body */
   volatile uint_32 _PTR_  dest_ptr = (volatile uint_32 _PTR_)to_ptr;
   uint_32 _PTR_           src_ptr  = (uint_32 _PTR_)from_ptr;
   boolean                 erase;
   boolean                 success;
   boolean                 timeout;
   _mqx_uint               j;
   _mem_size               size = sector_size >> 2;
   MQX_TICK_STRUCT         start_ticks;
   uint_32                 tmp, status;

   erase    = FALSE;
   offset >>= 2;

   /* 
   ** Check to see if flash needs erasing.
   */ 
   for (j = offset; !erase && (j < size); j++) {
      erase = ISTRATA_ERASE_UNIT(to_ptr[j], from_ptr[j]);
   } /* Endfor */

   if (erase) {
      success = _intel_strata_erase_4byte(handle_ptr, to_ptr, size, 
         &start_ticks);
      if (!success) {
         return success;
      } /* Endif */
      /* 
      ** We erased the whole sector so we must program from the beginning of
      ** the sector
      */
      offset = 0;
   } else {
      success = TRUE;
   } /* Endif */

   dest_ptr = dest_ptr + offset;
   src_ptr  = src_ptr  + offset;

   ISTRATA_PROGRAM(ISTRATA_READ_MODE_CMD_32X1, ISTRATA_WRITE_CMD_32X1, 
      ISTRATA_STATUS_BUSY_32X1);

   if ( success ) {
      /* Verify sector is written correctly */
      for( j = 0; j < size; j++ ) {
         if ( from_ptr[j] != to_ptr[j] ) {
            success = FALSE;
            break;
         } /* Endif */
      } /* Endfor */
   } /* Endif */

   return success;

} /* Endbody */