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

📄 app.c

📁 基于LPC2468处理器的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
**************************************************************************************************************
*                                               USB Host Stack
*
*                                (c) Copyright 2008, OnChip  Technologies LLC
*                                             All Rights Reserved
*
*                                               www.onchiptech.com
*
* LICENSING TERMS:
*
*   This software is protected by international copyright laws. Knowledge of the source code may not be used to
*   write a similar product. This file may only be used in accordance with a license and should not be
*   redistributed in any way.  We appreciate your understanding, fairness and honesty.
*
*   This material or any other copies thereof may not be provided or otherwise made available to any other
*   person without written permission by Onchip Technologies. Its receipt and/or possession does
*   not convey any right to alter, reproduce, disclose, transmit, manufacture, use or sell anything it may
*   describe.
*
* File           : app.c
* Programmer(s)  : Ravikanth.P
* Version        : V1.00
*
**************************************************************************************************************
*/

/*
**************************************************************************************************************
*                                       INCLUDE HEADER FILES
**************************************************************************************************************
*/

#include <RTL.h>
#include "app_cfg.h"
#include "ot_types.h"
#include "usbh_api.h"
#include "file_api.h"
#include "ot_err.h"

/*
**************************************************************************************************************
*                                         MACROs
**************************************************************************************************************
*/

#define  PRINT_Log        UART_Printf
#define  ALIGNED(x, a)    ((CPU_INT32U)(x) % (a) ? (a) - ((CPU_INT32U)(x) % (a)) + (CPU_INT32U)(x) :\
                           (CPU_INT32U)(x))

/*
**************************************************************************************************************
*                                        CONSTANTS
**************************************************************************************************************
*/

#define    APP_READ_FILE                  "A:/Read.txt"
#define    APP_WRITE_FILE                 "A:/Write.txt"
#define    APP_DEL_FILE                   "A:/Write.txt"
#define    APP_CREAT_DIR                  "A:/Directory"
#define    APP_DEL_DIR                    "A:/Directory"
#define    APP_NAV_START_FILE             "A:/"

#define    APP_BUFFER_SIZE                (1024 * 2)           /* Application buffer size                   */                         

/*
**************************************************************************************************************
*                                         GLOBAL VARIABLES
**************************************************************************************************************
*/

        CPU_INT08U  APP_Buf[APP_BUFFER_SIZE];
static  CPU_INT32U  APP_Stack[APP_CFG_TASK_STK_SIZE];


/*
**************************************************************************************************************
*                                     STATIC FUNCTION PROTOTYPES
**************************************************************************************************************
*/

        void  task             (void);
static  void  APP_Task         (void  *context);

#if (APP_CFG_TEST_COPY == DEF_ENABLED)
static  void  APP_TestCopy     (void);

#elif (APP_CFG_TEST_DEL_FILE == DEF_ENABLED)
static  void  APP_TestDelFile  (void);

#elif (APP_CFG_TEST_CREAT_DIR == DEF_ENABLED)
static  void  APP_TestCreatDir (void);

#elif (APP_CFG_TEST_DEL_DIR == DEF_ENABLED)
static  void  APP_TestDelDir   (void);

#elif (APP_CFG_TEST_NAV == DEF_ENABLED)
static  void  APP_TestNav      (void);

#endif

/*
**************************************************************************************************************
*                                           OS MAIN
*
* Description: This is the main function from where the execution begins
*
* Arguments  : None
*
* Returns    : None.
*
**************************************************************************************************************
*/

main()
{
    os_sys_init(task);
}

/*
**************************************************************************************************************
*                                           TASK
*
* Description: This task initializes the UART#1 to see the log messages, initializes the OTUSB host stack, and
*              then creates a mass storage demo file thread.
*
* Arguments  : None
*
* Returns    : None.
*
**************************************************************************************************************
*/

void  task (void)
{   
    CPU_INT32U  *a_stack;                       /* 8 byte aligned stack pointer                             */
    CPU_INT32U   a_stack_size;                  /* 8 byte aligned stack size                                */
    

    a_stack      = (void *)ALIGNED(APP_Stack, 8);  /* Align the stack to 8 bytes                            */
    a_stack_size = (((APP_CFG_TASK_STK_SIZE * 4)/8) * 8);

    os_tsk_create_user_ex(APP_Task,                /* Create Application Task                               */
                          APP_CFG_TASK_PRIO,
                          a_stack,
                          (CPU_INT16U)(a_stack_size - (a_stack - APP_Stack)),
                          NULL);
    while (1) {
        os_dly_wait(10);
    }
}

/*
**************************************************************************************************************
*                                           DEMO FILE THREAD
*
* Description: This is the Mass Storage Demo File Thread function. This function initializes the UART#1 serial
*              port with a baudrate of 115200, initializes the host stack, and then calls one of the test 
*              functions. The user can select one among five test functions. The selection can be made by
*              enabling the corresponding selection definition defined in app_cfg.h
*
* Arguments  : context             In this case it is NULL.
*
* Returns    : None.
*
**************************************************************************************************************
*/

static  void  APP_Task (void  *context)
{
    UART_Init(9600);                       /* Initialize the UART#1                                       */
    USBHost_Init(USBH_CFG_TASK_PRIO);        /* Initialize the Mass Storage Demo                            */

    while (1) {
        if (FS_IsDevConn() == 1) {           /* Wait until a file system device is connected,               */
            break;
        }
        os_dly_wait(100);
    }
#if (APP_CFG_TEST_COPY == DEF_ENABLED)
    APP_TestCopy();
#elif (APP_CFG_TEST_DEL_FILE == DEF_ENABLED)
    APP_TestDelFile();
#elif (APP_CFG_TEST_CREAT_DIR == DEF_ENABLED)
    APP_TestCreatDir();
#elif (APP_CFG_TEST_DEL_DIR == DEF_ENABLED)
    APP_TestDelDir();
#elif (APP_CFG_TEST_NAV == DEF_ENABLED)
    APP_TestNav();
#endif
    while (1) {
        os_dly_wait(10);
    }
}

/*
**************************************************************************************************************
*                                           COPY
*
* Description: This function copies the contents of one file to another file. The file name for the file from
*              which the data to be read is defined as APP_READ_FILE and the file name for the file into which
*              the data to be written is defined as APP_WRITE_FILE.
*
* Arguments  : None
*
* Returns    : None.
*
**************************************************************************************************************
*/

#if (APP_CFG_TEST_COPY == DEF_ENABLED)
 
static  void  APP_TestCopy (void)
{
    CPU_INT32U   fd_rd;                      /* File descriptor to the file FS_EXAMPLE_READ_FILE            */
    CPU_INT32U   fd_wr;                      /* File descriptor to the file FS_EXAMPLE_WRITE_FILE           */
    CPU_INT32U   byts_rd;                    /* Bytes read when a read call is issued                       */
    CPU_INT32U   byts_wr;                    /* Bytes written when a write call is issued                   */
    CPU_INT32S   err;


    PRINT_Log("\n");
    PRINT_Log("Copying from %s to %s...\n", APP_READ_FILE, APP_WRITE_FILE);

    fd_rd = FILE_Open(APP_READ_FILE, RDONLY, &err);     /* Open a file from the mass storage device         */
    if (fd_rd == 0) {
        PRINT_Log("Could not open file %s. err = %d\n", APP_READ_FILE, err);
        return;
    }

⌨️ 快捷键说明

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