⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 docsys.c

📁 H3 M-system NAND flash driver in Linux OS, M-DOC driver
💻 C
📖 第 1 页 / 共 4 页
字号:
/*----------------------------------------------------------------------
   f l 1 6 b i t D o c R e a d N o S h i f t

   Note - this routine can read only even number of bytes 

   Read 'count' bytes from M+ DiskOnChip with none shifted address bus.
------------------------------------------------------------------------*/

void FAR1 fl16bitDocReadNoShift (volatile  FLByte FAR0 * win, FLWord offset, FLByte FAR1 * dest, FLWord count )
{
   volatile FLWord FAR0 * swin = (volatile FLWord FAR0 *)( win + offset);
   register int         i;
   register FLWord        tmp;

#ifndef FL_NO_INIT_MMU_PAGES
  if (count == 0)
     return;

  dest[0] = 0;
  *((FLByte FAR1*)addToFarPointer(dest, (count - 1)) ) = (FLByte)0;
#endif /* FL_NO_INIT_MMU_PAGES */

   if( (FLDword)dest & 0x1 )
   {
      /* rare case: unaligned target buffer */
      for (i = 0; i < (int)count; )
      {
         tmp = FLREAD_IO_WORD(swin);
#ifdef FL_BIG_ENDIAN
         dest[i++] = (FLByte)(tmp>>8);
         dest[i++] = (FLByte)tmp;
#else
         dest[i++] = (FLByte)tmp;
         dest[i++] = (FLByte)(tmp>>8);
#endif /* FL_BIG_ENDIAN */
      }
   }
   else
   {   /* mainstream case */
#ifdef FL_ENVIRONMENT_VARS
      /* Some memcpy implementations from none 4 bytes aligned destination
	   * buffer may use a for loop of single byte calls to the first 2 
	   * bytes. This implementation may be good for RAM, but will be 
	   * problematic to 16bit DiskOnChip that does not have a BHE signal.
	   * so if the buffer is not dword aligned we would not perform memcpy */

      if ((flPreventMemcpy == 0) &&  (((FLDword)dest&0x3)==0)   )
      {
        TFFSCPY_FROM_IO_16_BITS( dest,win + offset, count); 
      }
      else
#endif /* FL_ENVIRONMENT_VARS */
      {   /* read in short words */
         for (i = 0, count = count >> 1; i < (int)count; i++)
#ifndef FL_XSCALE_BOOT_MODE
            /* while incrementing DiskOnChip offset */
            ((FLWord FAR1 *)dest)[i] = FLREAD_IO_WORD(swin+i);
#else
            /* but do not increment DiskOnChip offset */
            ((FLWord FAR1 *)dest)[i] = FLREAD_IO_WORD(swin);
#endif /* FL_XSCALE_BOOT_MODE */
      }
   }
}

/*----------------------------------------------------------------------
   f l 1 6 b i t D o c W r i t e N o S h i f t

   Note - this routine can write only even number of bytes 

   Write 'count' bytes to M+ DiskOnChip with none shifted address bus.
------------------------------------------------------------------------*/

void FAR1 fl16bitDocWriteNoShift ( volatile  FLByte FAR0 * win , FLWord offset ,
                             FLByte FAR1 * src, FLWord count )
{
   volatile FLWord FAR0 * swin = (volatile FLWord FAR0 *)( win + offset);
   register int         i;
   register FLWord        tmp;

   if( (FLDword)src & 0x1 ) /* rare case: unaligned source buffer */
   {
       for (i = 0; i < (int)count; i+=2)
       {
          /* tmp variable is just a precation from compiler optimizations */
#ifdef FL_BIG_ENDIAN
          tmp = ((FLWord)src[i]<<8) + (FLWord)src[i+1];
#else
          tmp = (FLWord)src[i] + ((FLWord)src[i+1]<<8);
#endif /* FL_BIG_ENDIAN */
         FLWRITE_IO_WORD(tmp,swin);
        }
   }
   else /* mainstream case */
   {
#ifdef FL_ENVIRONMENT_VARS
      if ((flPreventMemcpy == 0) && (((FLDword)src&0x3)==0))
      {
        TFFSCPY_TO_IO_16_BITS(win + offset,src,count);
      }
      else
#endif /* FL_ENVIRONMENT_VARS */
      {
         /* write in short words */
         for (i = 0, count = count >> 1; i < (int)count; i++)
           /* while incrementing DiskOnChip offset */
           /* but do not increament DiskOnChip offset */
            FLWRITE_IO_WORD(((FLWord FAR1 *)src)[i],swin);
      }
   }
}

/*----------------------------------------------------------------------
   f l 1 6 b i t D o c S e t N o S h i f t

   Note - this routine can write only even number of bytes 

   Set 'count' bytes of M+ DiskOnChip with none shifted address bus
------------------------------------------------------------------------*/

void FAR1 fl16bitDocSetNoShift ( volatile  FLByte FAR0 * win , FLWord offset ,
                                  FLWord count , FLByte val)
{
   volatile FLWord FAR0 * swin = (volatile FLWord FAR0 *)( win + offset);
   register int         i;
   register FLWord        tmpVal = (FLWord)val * 0x0101;

#ifdef FL_ENVIRONMENT_VARS
   if (flPreventMemcpy == 0)
   {
       TFFSSET_IO_16_BITS(win + offset, val, count );
   }
   else
#endif /* FL_ENVIRONMENT_VARS */
   {   /* write in short words */
      for (i = 0; i < (int)count; i+=2)
       FLWRITE_IO_WORD(tmpVal,swin);
   }
}

/*************************************************************/
/*    16-Bit DiskOnChip - No Shift - Only 8 bits are valid   */
/*************************************************************/

/*----------------------------------------------------------------------
   f l 1 6 b i t D o c R e a d N o S h i f t I g n o r e H i g h e r 8 B i t s

   Note : offset must be 16-bits aligned.

   Read 'count' bytes from M+ DiskOnChip connected with all 16 data bits, but
   in interleave-1 mode , therefore only one of the 8 bits contains actual data.
   The DiskOnChip is connected without an address shift.
------------------------------------------------------------------------*/

void FAR1 fl16bitDocReadNoShiftIgnoreHigher8bits(volatile  FLByte FAR0 * win, FLWord offset, FLByte FAR1 * dest, FLWord count )
{
   volatile FLWord FAR0 * swin = (volatile FLWord FAR0 *)( win + offset);
   register int         i;

#ifndef FL_NO_INIT_MMU_PAGES
  if (count == 0)
     return;

  dest[0] = 0;
  *((FLByte FAR1*)addToFarPointer(dest, (count - 1)) ) = (FLByte)0;
#endif /* FL_NO_INIT_MMU_PAGES */

   for (i = 0; i < (int)count; i++)
   {
#ifndef FL_XSCALE_BOOT_MODE
      /* Read while incrementing DiskOnChip window offset */
#ifdef FL_BIG_ENDIAN
      dest[i] = (FLByte)(FLREAD_IO_WORD((volatile void FAR0 *)(swin+i))>>8);
#else
      dest[i] = (FLByte)FLREAD_IO_WORD((volatile void FAR0 *)(swin+i));
#endif /* FL_BIG_ENDIAN */
#else
      /* Read while not incrementing DiskOnChip window offset */
#ifdef FL_BIG_ENDIAN
   dest[i] = (FLByte)(FLREAD_IO_WORD(swin)>>8);
#else
   dest[i] = (FLByte)(FLREAD_IO_WORD(swin));
#endif /* FL_BIG_ENDIAN */
#endif /* FL_XSCALE_BOOT_MODE */
   }
}

/*----------------------------------------------------------------------
   f l 1 6 D o c W r i t e N o S h i f t I g n o r e H i g h e r 8 b i t s

   Note : offset must be 16-bits aligned.

   Write 'count' bytes to M+ DiskOnChip connected with all 16 data bits, but
   in interleave-1 mode , therefore only one of the 8bits contains actual data.
   The DiskOnChip is connected without an address shift.
------------------------------------------------------------------------*/

void FAR1 fl16bitDocWriteNoShiftIgnoreHigher8bits ( volatile  FLByte FAR0 * win , FLWord offset ,
                             FLByte FAR1 * src, FLWord count )
{
   volatile FLWord FAR0 * swin = (volatile FLWord FAR0 *)( win + offset);
   register int         i;

   for (i = 0; i < (int)count; i++)
   {
      /* Write while not incrementing DiskOnChip window offset */
#ifdef FL_BIG_ENDIAN
      FLWRITE_IO_WORD((((FLWord)src[i])<<8),swin);
#else
      FLWRITE_IO_WORD((FLWord)src[i],swin);
#endif /* FL_BIG_ENDIAN */
   }
}

/*----------------------------------------------------------------------
   f l 1 6 D o c S e t N o S h i f t I g n o r e H i g h e r 8 b i t s

   Note : offset must be 16-bits aligned.

   Set 'count' bytes to M+ DiskOnChip connected with all 16 data bits, but
   in interleave-1 mode , therefore only one of the 8bits contains actual data.
   The DiskOnChip is connected without an address shift.
------------------------------------------------------------------------*/

void FAR1 fl16bitDocSetNoShiftIgnoreHigher8bits ( volatile  FLByte FAR0 * win , FLWord offset ,
                                  FLWord count , FLByte val)
{
   volatile FLWord FAR0 * swin = (volatile FLWord FAR0 *)( win + offset );
   register int         i;
   register FLWord        tmpVal = val * 0x0101;

   for (i = 0; i < (int)count; i++)
    FLWRITE_IO_WORD(tmpVal,swin);
}

/****************************************/
/*   16-Bit DiskOnChip - Single Shift   */
/****************************************/

/*----------------------------------------------------------------------
   f l 1 6 b i t D o c R e a d S i n g l e S h i f t
 
   Read 'count' bytes from M+ DiskOnChip with none shifted address bus.
------------------------------------------------------------------------*/

void FAR1 fl16bitDocReadSingleShift (volatile  FLByte FAR0 * win, FLWord offset, FLByte FAR1 * dest, FLWord count )
{
   volatile FLDword FAR0 * swin = ((volatile FLDword FAR0 *)win) + (offset>>1);
   register int         i;
   register FLDword       tmp;

#ifndef FL_NO_INIT_MMU_PAGES 
  if (count == 0)
     return;

  dest[0] = 0;
  *((FLByte FAR1*)addToFarPointer(dest, (count - 1)) ) = (FLByte)0;
#endif /* FL_NO_INIT_MMU_PAGES */

   if( (FLDword)dest & 0x1 )
   {
      /* rare case: unaligned target buffer */
      for (i = 0; i < (int)count; )
      {
         tmp = FLREAD_IO_DWORD(swin);
#ifdef FL_BIG_ENDIAN
         dest[i++] = (FLByte)(tmp>>24);
         dest[i++] = (FLByte)(tmp>>16);
#else
         dest[i++] = (FLByte)tmp;
         dest[i++] = (FLByte)(tmp>>8);
#endif /* FL_BIG_ENDIAN */
      }
   }
   else
   {   /* mainstream case */
      for (i = 0, count = count >> 1; i < (int)count; i++)
      {
#ifdef FL_BIG_ENDIAN         
         ((FLWord FAR1 *)dest)[i]=(FLWord)(FLREAD_IO_DWORD(swin+i)>>16);
#else
         ((FLWord FAR1 *)dest)[i] = (FLWord)FLREAD_IO_DWORD(swin+i);
#endif /* FL_BIG_ENDIAN */
      }
   }
}

/*----------------------------------------------------------------------
   f l 1 6 b i t D o c W r i t e S i n g l e S h i f t
 
   Write 'count' bytes to M+ DiskOnChip with none shifted address bus.
------------------------------------------------------------------------*/

void FAR1 fl16bitDocWriteSingleShift ( volatile  FLByte FAR0 * win , FLWord offset ,
                             FLByte FAR1 * src, FLWord count )
{
   volatile FLDword FAR0 * swin = ((volatile FLDword FAR0 *)win)+ (offset>>1);
   register int         i;
   register FLDword       tmp;

   if( (FLDword)src & 0x1 ) /* rare case: unaligned source buffer */
   {       
       for (i = 0; i < (int)count; i+=2)
       {
#ifdef FL_BIG_ENDIAN
          tmp = (((FLDword)src[i])<<24) + (((FLDword)src[i+1])<<16);
#else
          tmp = (FLDword)src[i] + (((FLDword)src[i+1])<<8);
#endif /* FL_BIG_ENDIAN */
           FLWRITE_IO_DWORD(tmp,swin);
       }
   }
   else /* mainstream case */
   {    
      for (i = 0, count = count >> 1; i < (int)count; i++)
#ifdef FL_BIG_ENDIAN
        FLWRITE_IO_DWORD(((FLDword)((FLWord FAR1 *)src)[i])<<16,swin);
#else
        FLWRITE_IO_DWORD(((FLDword)((FLWord FAR1 *)src)[i]),swin);
#endif /* FL_BIG_ENDIAN */
   }
}

/*----------------------------------------------------------------------
   f l 1 6 b i t D o c S e t S i n g l e S h i f t
 
   Set 'count' bytes of M+ DiskOnChip with none shifted address bus
------------------------------------------------------------------------*/

void FAR1 fl16bitDocSetSingleShift ( volatile  FLByte FAR0 * win , FLWord offset ,
                                  FLWord count , FLByte val)
{
   volatile FLDword FAR0 * swin = ((volatile FLDword FAR0 *)win)+ (offset>>1);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -