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

📄 main.c

📁 AT91SAM7X256
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
**********************************************************************
*                          Micrium, Inc.
*                      949 Crestview Circle
*                     Weston,  FL 33327-1848
*
*                            uC/FS
*
*             (c) Copyright 2001 - 2003, Micrium, Inc.
*                      All rights reserved.
*
***********************************************************************

----------------------------------------------------------------------
File        : main.c
Purpose     : Sample program for using the file system
----------------------------------------------------------------------
Known problems or limitations with current version
----------------------------------------------------------------------
None.
---------------------------END-OF-HEADER------------------------------
*/

/*********************************************************************
*
*             #include Section
*
**********************************************************************
*/

#include "fs_api.h"
#include "string.h"
#include "stdio.h"

#include "includes.h"    // for ucos_II
#include "board.h"       // as top

#include "mmc.h"
#include "fs_dev.h"
#include "dbgu.h"

#if (FS_OS_EMBOS)
  #include "RTOS.H"
#endif


/*********************************************************************
*
*             Global variables
*
**********************************************************************
*/
//_____________________________for UCOS_II ___________________________
#define  TASK_STK_SIZE             128

#define  Task_main_Prio            7
#define  Task_1_Prio               6
#define  Task_2_Prio               5

//*******************************************************************
//                          stack declare
//*******************************************************************
unsigned int    Task_1_STK[TASK_STK_SIZE];
OS_STK          Task_2_STK[TASK_STK_SIZE];

OS_STK          Task_main_STK[TASK_STK_SIZE];

//*******************************************************************
//                      foundation declare
//*******************************************************************
void  Task_1_Prog(void *arg) ;
void  Task_2_Prog(void *arg) ;

void Menu_FS_mmc_SD(char)    ;          //文件操作接口
void Print_FS_Option_description(void); //文件系统操作表提示信息
//extern int FS__find_fsl(const char *pFullName, FS_FARCHARPTR *pFileName) ;
extern int _FS_ReadBPB(int Idx, FS_u32 Unit) ;
//void AT91F_DBGU_Init() ;
//extern void AT91F_DBGU_Printk(	char *buffer) ;

DRESULT disk_read (
	BYTE *buff,		/* Data buffer to store read data */
	DWORD sector,		/* Sector number (LBA) */
	BYTE count			/* Sector count (1..255) */
)  ;
//______________________________________for uCFS____________________
FS_FILE *myfile;
char mybuffer[0x100];
char buff[50];
const char dev_sdc_msg[]="This text was written on your SDC disk.\n";  //____

void *mytext="This text was written on your default device.\n";    //for些文件
#if (FS_OS_EMBOS)
  OS_STACKPTR int MainStack[0x400]; /* Stack-space */
  OS_TASK MainTCB;                  /* Task-control-blocks */

  #if (((FS_USE_SMC_DRIVER) && (FS_SMC_HW_NEEDS_POLL)) || ((FS_USE_MMC_DRIVER) && (FS_MMC_HW_NEEDS_POLL)) \
      || ((FS_USE_IDE_DRIVER) && (FS_IDE_HW_NEEDS_POLL)))
    OS_STACKPTR int DiskChangeStack[0x100]; /* Stack-space */
    OS_TASK DiskChangeTCB;                  /* Task-control-blocks */
  #endif
#endif

/*********************************************************************
*
*             Local functions
*
**********************************************************************
*/

/*********************************************************************
*
*             debug output routines
*/

static void _error(const char *msg) {
#if (FS_OS_EMBOS)
  if (strlen(msg)) {
    OS_SendString(msg);
  }
#else
  printf("%s",msg);
#endif
}
//----------------------------------
static void _log(const char *msg) {
#if (FS_OS_EMBOS)
  if (strlen(msg)) {
  OS_SendString(msg);
  }
#else
  printf("%s",msg);
#endif
}


/*********************************************************************
*
*             _write_file
*
  This routine demonstrates, how to create and write to a file
  using the file system.
*/

static void _write_file(const char *name, const char *txt)
 {
  int x;

  /* create file */
  myfile = FS_FOpen(name,"w");
  if (myfile)
   {
      /* write to file */
       x = FS_FWrite(txt,1,strlen(txt),myfile);
      /* all data written ? */
      if (x!=(int)strlen(txt))
       {
        /* check, why not all data was written */
        x = FS_FError(myfile);
        sprintf(mybuffer,"Not all bytes written because of error %d.\n",x);
        AT91F_DBGU_Printk(mybuffer);
        _error(mybuffer);
       }
      /* close file */
      FS_FClose(myfile);
      AT91F_DBGU_Printk("file created !");

  }
  else
   {
    sprintf(mybuffer,"Unable to create file %s\n",name);
    _error(mybuffer);
    AT91F_DBGU_Printk(mybuffer) ;
   }
}
//----------------------------------
char GetChar(void)
 {
  char ch=0 ;
  while(1)
   {
     ch=AT91F_US_GetChar((AT91PS_USART)AT91C_BASE_DBGU) ;
     if(ch!=0)
       return ch ;
   }
 }
//------------------------- 等待输入参数 -----------------------------
//*
//* Object              : Get a string to USART manage Blackspace and echo
//* Input Parameters    : com descriptor, type string & val return value
//* Output Parameters   : none
//  the parameter of type are the format of val,same as : "%x" , "%d"
//*-------------------------------------------------------------------
char * AT91F_DBGU_scanf(char * type)
{
   //* Begin
    unsigned int read = 0;
   // unsigned char * val  ;

    for(int i=0;i<50;i++)
      buff[i]=0 ;
    unsigned int nb_read =0;
    while( (read != 0x0D) && (nb_read != sizeof(buff)) )
     {
        //* wait the USART Ready for reception
     //    if((AT91C_BASE_DBGU->DBGU_CSR  & AT91C_US_RXBUFF)!=0)
     //      read = AT91C_BASE_DBGU->DBGU_RHR ;
	 while((AT91C_BASE_DBGU->DBGU_CSR  & AT91C_US_RXRDY) == 0 ) ;
        //* Get a char
	read = AT91C_BASE_DBGU->DBGU_RHR ;
        buff[nb_read]= (char)read;
        //* Manage Blackspace
        while((AT91C_BASE_DBGU->DBGU_CSR & AT91C_US_TXRDY) ==0)  {}
        if ((char)read == 0x08) {
            if ( nb_read != 0 ) {
              nb_read--;
              AT91C_BASE_DBGU->DBGU_THR = read;
            }
        }
        else {
          //* echo
          AT91C_BASE_DBGU->DBGU_THR = read;
          if(read != 0x0A)                    //去掉 0x0A字符的干扰
             nb_read++;
        }
    }
    for(int i=0;i<50;i++)                    //去掉 0x0D字符的干扰
     {
        if(buff[i]==0x0D)
         {
           buff[i]=0 ;
           break ;
         }
     }
    //* scan the value
//    sscanf(buff,type,val);
    return (char *)buff ;
}//* End

//--------------读出文件中的内容------------
/*
*             _dump_file
*
  This routine demonstrates, how to open and read from a file using
  the file system.
*/
//----------------------------------
void _dump_file(const char *name)
 {
  int x;

  /* open file */
  myfile = FS_FOpen(name,"r");
  if (myfile)
    {
    /* read until EOF has been reached */
      do {
          x = FS_FRead(mybuffer,1,sizeof(mybuffer)-1,myfile);
          mybuffer[x]=0;
          if (x) {
            _log(mybuffer);
         }
    } while (x);
    /* check, if there is no more data, because of EOF */
    x = FS_FError(myfile);
    if (x!=FS_ERR_EOF) {
      /* there was a problem during read operation */
      sprintf(mybuffer,"Error %d during read operation.\n",x);
      _error(mybuffer);
      AT91F_DBGU_Printk(mybuffer) ;
    }
    /* close file */
    FS_FClose(myfile);
  }
  else
   {
    sprintf(mybuffer,"Unable to open file %s.\n",name);
    _error(mybuffer);
    AT91F_DBGU_Printk(mybuffer) ;
   }
}
//----------------------------------
/*
*
*             _show_directory
*
  This routine demonstrates, how to read a directory.
*/
//----------------------------------
#if FS_POSIX_DIR_SUPPORT

static void _show_directory(const char *name)
 {
    FS_DIR *dirp;
    struct FS_DIRENT *direntp;

    _log("Directory of ");
    _log(name);
    _log("\n");
    dirp = FS_OpenDir(name);
    if (dirp)
      {
        do
         {
            direntp = FS_ReadDir(dirp);
            if (direntp)
              {
                sprintf(mybuffer,"%s\n",direntp->d_name);
                _log(mybuffer);
              }
         } while (direntp);

        FS_CloseDir(dirp);
        AT91F_DBGU_Printk(mybuffer);
      }
    else
     {
      _error("Unable to open directory\n");
      AT91F_DBGU_Printk("Unable to open directory\n");
     }

 }

#endif /* FS_POSIX_DIR_SUPPORT */

//--------------显示磁盘空间的信息-----------
/*
*             _show_free
*
  This routine demonstrates, how to read disk space information.

⌨️ 快捷键说明

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