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

📄 _fs_write.c

📁 keil arm flash fs 最新版 在Keil arm下使用
💻 C
字号:
/*----------------------------------------------------------------------------
 *      R T L  -  F l a s h   F i l e   S y s t e m
 *----------------------------------------------------------------------------
 *      Name:    _FS_WRITE.C 
 *      Purpose: Low level File Write Block Function
 *      Rev.:    V3.22
 *----------------------------------------------------------------------------
 *      This code is part of the RealView Run-Time Library.
 *      Copyright (c) 2004-2008 KEIL - An ARM Company. All rights reserved.
 *---------------------------------------------------------------------------*/

#include "File_Config.h"

/*--------------------------- __write ---------------------------------------*/

int __write (int handle, const U8 *buf, U32 len) {
   /* Low level file write function. */
   FALLOC alloc;
   IOB *fcb;
   BOOL wralloc;
   U32 size;

   if (buf == NULL) {
      /* Invalid buffer, return error. */
      return (-1);
   }
   fcb = &_iob[handle];

   if (fcb->drive == DRV_MCARD) {
      /* Write data to Flash Memory Card. */
      if (fat_write (fcb, buf, len) == __FALSE) {
         /* Error, data not written to file. */
         return (-1);
      }
      return (0);
   }

   wralloc = __FALSE;
   if (len & 3) {
      wralloc = __TRUE;
   }
   while (len) {
      size = fcb->_ftop - fcb->_fbot - sizeof (FALLOC);
      if (size > len) {
         size = len;
      }
      len -= size;
      fs_WriteBlock (((DEVCONF *)fcb->DevCfg)[fcb->_fblock].bStart + fcb->_fbot,
                     (void *)buf, size, fcb);
      buf += size;
      fcb->_fbot += size;

      if (fs_BlockFull (fcb) == __TRUE) {
         /* Current Flash Block is full, allocate next one */
         if (fs_AllocBlock (fcb) == __FALSE) {
            return (-1);
         }
         /* Do not write alloc record for empty segment. */
         if (len == 0) {
            goto ex;
         }
      }
   }
   if (wralloc == __FALSE) {
      /* Set flag 'Write Allocation Requested'. */
      fcb->flags |= _IOWALLOC;
   }
   else {
      /* If buffer is not full, write also allocation record. */
      alloc.end    = fcb->_fbot;
      alloc.fileID = fcb->fileID;
      alloc.index  = fcb->_fidx++;
      fs_WriteBlock (((DEVCONF *)fcb->DevCfg)[fcb->_fblock].bStart + fcb->_ftop,
                     &alloc, sizeof (FALLOC), fcb);
      /* Always write on 4-byte boundaries. */
      fcb->_ftop -= sizeof (FALLOC);
      fcb->_fbot = (fcb->_fbot + 3) & ~3;
ex:   fcb->flags &= ~_IOWALLOC;
   }
   return (0);
}

/*----------------------------------------------------------------------------
 * end of file
 *---------------------------------------------------------------------------*/

⌨️ 快捷键说明

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