xprotd.c

来自「基于nucleus操作系统的GPRS无线数据传输终端全套源文件。包括支持ARM7」· C语言 代码 · 共 187 行

C
187
字号
/************************************************************************
*
* FILE NAME                                          
*
*     XPROTD.c                                       
*
* DESCRIPTION
*
*      Demonstration of the Extended Protocol Package consisting of;
*      Telnet, TFTP Server, FTP Server, FTP Client.  The demo requires
*      two parameters; (1) local ip address to be used with each of the
*      three servers and (2) remote ip address to which the ftp client
*      will connect.  These two parameters are configured in the demoi.c
*      file.
*
*      The four applications will use DEMOI_Local_Ip as their local ip
*      address.  The FTP client will connect to DEMOI_FTP_Server.
*
*      Within this file, configurable parameters are located in the
*      section titled "USER CONFIGURABLE PARAMETERS."
*
*************************************************************************/

#define FTPS_DEMO   1

/* Include necessary Nucleus files. */
#include "net/inc/nu_net.h"

/* FTP Includes */
#include "ftp/inc/nu_ftp.h"


/* USER CONFIGURABLE PARAMETERS */

#define SYSTEM_MEMORY_SIZE  3250000ul
#define XPROT_DEFAULT_DRIVE 0

/* END USER CONFIGURABLE PARAMETERS */

/* Define Application data structures */
NU_MEMORY_POOL  System_Memory;
NU_TASK         Init_Complete_TCB;
NU_EVENT_GROUP  Init_Complete;
VOID            *next_available_memory;

/* Local prototypes */
VOID XPR_Init(UNSIGNED argc, VOID *argv);

/* Define external references to functions */
extern VOID         NETI_Init_Task(UNSIGNED argc, VOID *argv);
extern VOID         NETI_Exit(INT n);
extern VOID         NU_Printf(CHAR *string, ...);

/* Define external references to data. */
extern NU_DEVICE    DEMOI_Devices[1];


/*****************************************************************************
*                                                                       
* FUNCTION                                                              
*                                                                       
*      Application_Initialize                                           
*                                                                       
* DESCRIPTION                                                           
*                                                                       
*      An Application_Initialize function must exist in all Nucleus applications.
*      Nucleus PLUS executes this function after the kernel is initialized. This 
*      routine is responsible for setting up the initial Nucleus PLUS application 
*      environment. At least one task must be created by Application_Initialize.
*                                                                       
******************************************************************************/
VOID Application_Initialize (VOID *first_available_memory)
{
    VOID    *pointer;
    STATUS  status;
    extern  Hw_Init(void);
    
	Hardware_Init();
	
    /* Create a system memory pool that will be used to allocate task stacks,
       queue areas, etc.  */
    status = NU_Create_Memory_Pool (&System_Memory, 
                                    "SYSMEM",
                                    first_available_memory,
                                    SYSTEM_MEMORY_SIZE,
                                    50,
                                    NU_FIFO);
    if (status != NU_SUCCESS)
    {
        NU_Printf("***** Unable to create system memory pool *****\n");
        NETI_Exit (-1);
    }

    /* Set the next available memory location for use by 
       the DEMOI.C module when initializing NET. */
    next_available_memory = (((UINT8 *)first_available_memory) + 
                                        SYSTEM_MEMORY_SIZE);

        /* Create Init_Complete_CB Task*/
    if (NU_Allocate_Memory(&System_Memory, &pointer, 3000, NU_NO_SUSPEND) != NU_SUCCESS ) 
    {

        NU_Printf ("ERROR --- <app_init>\tCan not allocate memory for INIT_Network_Task\n");
        NETI_Exit (0);   
    }
    
    if (NU_Create_Task(&Init_Complete_TCB, "demo_init", XPR_Init, 
                                  0, NU_NULL, pointer, 3000, 3, 0, NU_PREEMPT, 
                                  NU_START) != NU_SUCCESS) 
    {
        NU_Printf ("ERROR --- <app_init>\tCannot create INIT_Net_Task\n");
        NETI_Exit (1);
    }

    /* Allocate memory for and Create Each Task in the System */

    /* Create the initialization complete event */
    status = NU_Create_Event_Group (&Init_Complete, "init_net");
    if (status != NU_SUCCESS)
    {
        NU_Printf ("Cannot create initialization complete event group.\n");
        NETI_Exit(10);
    }
    
    /*
     * IIS Function
     *
     */
    Iis_Tx();

}  /* end Application_Initialize */

/************************************************************************
*                                                                       
* FUNCTION                                                              
*                                                                       
*      XPR_Init                                                         
*                                                                       
* DESCRIPTION                                                           
*                                                                       
*      Performs demo initialization.
*
*************************************************************************/
VOID XPR_Init(UNSIGNED argc, VOID *argv)
{
    STATUS  status;
    FAL_FILE fd;
    char *buf = "this is a ramdisk written by MeterChen \n and the username is meterchen the passwd is 123 \n the total ramdisk size if 192KB, so the file size \n you upload MUST not big than 192KB";  
    

    UNUSED_PARAMETER(argc);
    UNUSED_PARAMETER(argv);

    /* Initialize the file system. This must be done from a task in the case
       that the underlying file system is Nucleus FILE. */
    if (FAL_Sys_Init(XPROT_DEFAULT_DRIVE) != NU_SUCCESS)
    {
        NU_Printf("DEMOI_Init_Task cannot initialize FAL layer.\n");
        NETI_Exit(-4);
    }

    if(FAL_Set_Curr_Drive(FAL_Get_Curr_Drive()) != NU_SUCCESS)
    {
        NU_Printf("DEMOI_Init_Task cannot select the default drive.\n");
        NETI_Exit(-5);
    }
	
	/*
	 * Create a file in RAM disk
	 *
	 */
	fd = FAL_Open("a:\\meter.txt", PO_RDWR|PO_CREAT, FAL_IWRITE|FAL_IREAD);
	FAL_Fwrite(buf, strlen(buf), fd); 
	FAL_Fclose(fd, 0);
	
    /* Call the main demo initialization function. */
    NETI_Init_Task(0,0);

    /* Start the FTP server. */
    status = NU_FTP_Server_Init();

    if (status == NU_SUCCESS)
        NU_Printf("Accelerated Technology's FTP Server Ready\n\r");
    else
        NETI_Exit(-7);

} /* XPR_Init */

⌨️ 快捷键说明

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