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

📄 app.c

📁 AT91SAM7X256微处理器
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
*********************************************************************************************************
*                                                uC/OS-II
*                                          The Real-Time Kernel
*
*                                 (c) Copyright 2004, Micrium, Weston, FL
*                                          All Rights Reserved
*
*                                            Freescale i.MX21ADS
*                                              Sample code
* File : APP.C
* By   : Eric Shufro
*********************************************************************************************************
*/
#define __inline inline
#include <includes.h>
#include <string.h>
#include <stdio.h>
#include "fs_api.h"
#include "lib_AT91SAM7X256.h"
#include "dbgu.h"
#include "usb-cdc-app.h"

/*
*********************************************************************************************************
*                                               VARIABLES
*********************************************************************************************************
*/

static  OS_STK  AppTaskStartStk[APP_TASK_START_STK_SIZE];
static  OS_STK  FSTaskStk[FS_TASK_SIZE];
static  OS_STK  USBCDCTaskStk[USB_CDC_TASK_SIZE];
static  OS_STK  ADCTaskStk[ADC_TASK_SIZE];

#if uC_TCPIP_MODULE > 0
static  OS_STK          AppTaskPhyStk[APP_TASK_PHY_STK_SIZE];
        NET_IP_ADDR   ip;
        NET_IP_ADDR   msk;
        NET_IP_ADDR   gateway;
#endif
        
/*********************************************************************
*
*             Global variables
*
**********************************************************************
*/

        
FS_FILE *MyFile;
char MyBuffer[0x100];


const char dev_default_msg[]="This text was written on your default device.\n";
const char dev_ram_msg[]="This text was written on your RAM disk.\n";


static void FSTask(void *arg);
static void AppInit_TCPIP (void);
static  void  AppTaskStart (void *p_arg);
static  void  TaskStartCreateTasks (void);
static  void  USBCDCTask(void *arg);
static  void  ADCTask(void *arg);
static  void            AppTaskPhy                  (void *p_arg);
/*********************************************************************
*
*             Local functions
*
**********************************************************************
*/

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

static void _error(const char *msg)
{
   // AT91F_DBGU_Printk(msg);
}


static void _log(const char *msg) 
{
    //AT91F_DBGU_Printk(msg);

}
/*********************************************************************
*
*             _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);
                _error(MyBuffer);
            }
            /* close file */
            FS_FClose(MyFile);
      }
      else 
      {
            sprintf(MyBuffer,"Unable to create file %s\n",name);
            _error(MyBuffer);
      }
}


/*********************************************************************
*
*             _dump_file
*
  This routine demonstrates, how to open and read from a file using
  the file system.
*/

static 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);
              }
                /* close file */
                  FS_FClose(MyFile);
         } 
        else 
        {
              sprintf(MyBuffer,"Unable to open file %s.\n",name);
               _error(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);
         }
        else 
        {
              _error("Unable to open directory\n");
        }
}
#endif /* FS_POSIX_DIR_SUPPORT */


/*********************************************************************
*
*             _show_free
*
  This routine demonstrates, how to read disk space information.
*/

static void _show_free(const char *device) 
{
          FS_DISKFREE_T disk_data;
          int x;
          _log("Disk information of ");
          _log(device);
          _log("\n");
          x = FS_IoCtl(device,FS_CMD_GET_DISKFREE,0,(void*) &disk_data);
          if (x==0)
          {
                    sprintf(MyBuffer,"total clusters     : %lu\navailable clusters : %lu\nsectors/cluster    : %u\nbytes per sector   : %u\n",
                    disk_data.total_clusters, disk_data.avail_clusters, disk_data.sectors_per_cluster, disk_data.bytes_per_sector);
                    _log(MyBuffer);
          }
          else 
          {
                    _error("Invalid drive specified\n");
          }
}


/*********************************************************************
*
*             Global functions
*
**********************************************************************
*/

/*********************************************************************
*
*             DiskChange
*/

#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)))
      void DiskChange(void) 
      {
            char name[8];
            int i;
            while (1) 
            {
                  #if ((FS_USE_SMC_DRIVER) && (FS_SMC_HW_NEEDS_POLL))
                  for (i=0;i<FS_SMC_MAXUNIT;i++) 
                  {
                        sprintf(name,"smc:%d:",i);
                        FS_IoCtl(name,FS_CMD_CHK_DSKCHANGE,0,0); /* check smc socket periodically */
                  }
                  #endif
                  #if ((FS_USE_MMC_DRIVER) && (FS_MMC_HW_NEEDS_POLL))
                  for (i=0;i<FS_MMC_MAXUNIT;i++) 
                  {
                        sprintf(name,"mmc:%d:",i);
                        FS_IoCtl(name,FS_CMD_CHK_DSKCHANGE,0,0); /* check mmc socket periodically */
                  }
                  #endif
                  #if ((FS_USE_IDE_DRIVER) && (FS_IDE_HW_NEEDS_POLL))
                  for (i=0;i<FS_IDE_MAXUNIT;i++)
                  {
                        sprintf(name,"ide:%d:",i);
                        FS_IoCtl(name,FS_CMD_CHK_DSKCHANGE,0,0); /* check ide socket periodically */
                  }
                  #endif

            }
  }
#endif



/*********************************************************************************************************
*                                          FUNCTION PROTOTYPES
*********************************************************************************************************
*/
static  void    AppTaskStart(void *p_arg);

#if OS_VIEW_MODULE > 0
static  void  AppTerminalRx(INT8U rx_data);
static  void  AppInit_OSView(void);
#endif

#if OS_VIEW_MODULE > 0
static  void  AppTerminalRx(INT8U rx_data);
#endif

#if uC_TCPIP_MODULE > 0
static  void  AppInit_TCPIP(void);
#endif


/*
*********************************************************************************************************
*                                             C ENTRY POINT
*********************************************************************************************************
*/

int  main (void)
{
    CPU_INT08U err;
    
    BSP_IntDisAll();                            /* Disable ALL interrupts to the interrupt controller  */
      

    OSInit();                                   /* Initialize uC/OS-II                                 */

⌨️ 快捷键说明

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