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

📄 utl.c

📁 基于东南大学开发的SEP3203的ARM7中的所有驱动
💻 C
📖 第 1 页 / 共 2 页
字号:
/************************************************************************
*                                                                       
*       Copyright (c)  1993 - 2001 Accelerated Technology, Inc.         
*                                                                       
* PROPRIETARY RIGHTS of Accelerated Technology are involved in the      
* subject matter of this material.  All manufacturing, reproduction,    
* use, and sales rights pertaining to this subject matter are governed  
* by the license agreement.  The recipient of this software implicitly  
* accepts the terms of the license.                                     
*                                                                       
*************************************************************************/

/* Portions of this program were written by:       */
/*************************************************************************
*                                                                         
*     part of:                                                            
*     TCP/IP kernel for NCSA Telnet                                       
*     by Tim Krauskopf                                                    
*                                                                         
*     National Center for Supercomputing Applications                     
*     152 Computing Applications Building                                 
*     605 E. Springfield Ave.                                             
*     Champaign, IL  61820                                                
*
*************************************************************************/

/*************************************************************************
*                                                                         
*   FILENAME                                                              
*                                                                         
*       UTL.C                                                             
*                                                                         
*   COMPONENT
*
*       Utilities
*
*   DESCRIPTION                                                           
*                                                                         
*       Session interface routines                                        
*                                                                         
*   DATA STRUCTURES
*
*       None
*
*   FUNCTIONS                                                             
*                                                                         
*       UTL_Checksum                                                      
*       UTL_Timerset                                                      
*       UTL_Timerunset                                                    
*       UTL_Zero                                                          
*       UTL_Rand                                                          
*       UTL_Get_Unique_Port_Number  
*       UTL_Is_Unique_Port_Number                                      
*                                                                         
*   DEPENDENCIES                                                          
*
*       nucleus.h                                                         
*       nu_defs.h                                                         
*       nu_extr.h                                                         
*       target.h                                                          
*       net_extr.h                                                        
*       externs.h                                                         
*       tcp.h                                                             
*       tcpdefs.h                                                         
*       nerrs.h
*       netevent.h                                                        
*
*************************************************************************/
#include "plus/nucleus.h"
#include "net/target.h"
#include "net/inc/externs.h"
#include "net/inc/ip.h"
#include "net/inc/net_extr.h"
#include "net/inc/tcp.h"
#include "net/inc/udp.h"
#include "net/inc/tcpdefs.h"
#include "net/inc/nerrs.h"
#include "net/inc/netevent.h"

extern NU_TASK           NU_EventsDispatcher_ptr;

/*************************************************************************
*                                                                       
*   FUNCTION                                                              
*                                                                       
*       UTL_Timerset(UNSIGNED, UNSIGNED, UNSIGNED, INT32)                
*                                                                       
*   DESCRIPTION                                                           
*                                                                       
*       Set an async timer, and when time elapses sticks an event in the 
*       network event queue.                                             
*                                                                       
*       Class, event, dat is what gets posted when howlong times out.    
*                                                                       
*   INPUTS                                                                
*
*       event                                                            
*       dat                                                              
*       howlong                                                          
*       seq_number                                                       
*                                                                      
*   OUTPUTS                                                               
*
*       NU_SUCCESS                                                       
*       -1                                                               
*                                                                       
*************************************************************************/
STATUS UTL_Timerset (UNSIGNED event, UNSIGNED dat, UNSIGNED howlong, 
                  INT32 seq_number)
{
    tqe_t *tqe;
    STATUS  status;
    tqe_t *return_ptr;

    /*  Get an entry from the freelist.  */
    tqe = (tqe_t *) DLL_Dequeue (&EQ_Event_Freelist);

    /*  Check to see if an entry was found.  If one was not found, need
        to allocate a new one. */

    if (!tqe)
    {
        /*  Get some memory for the new entry.  */
        status = NU_Allocate_Memory(&System_Memory, (void **) &return_ptr,
                                (UNSIGNED)sizeof(tqe_t),
                                (UNSIGNED)NU_NO_SUSPEND);

        /* check status of memory allocation */
        if (status == NU_SUCCESS)
        {
            return_ptr = (tqe_t *)TLS_Normalize_Ptr(return_ptr);
            tqe = return_ptr;
        }
        else
        {
            NERRS_Log_Error ( NERR_RECOVERABLE, __FILE__, __LINE__);
            return (-1);
        }
    }

    /*  Set up the new entry.  */
    tqe->tqe_event = event;
    tqe->tqe_data = dat;
    tqe->tqe_ext_data = seq_number;
    tqe->duetime = NU_Retrieve_Clock() + (UNSIGNED) howlong;

    /*  Place the new entry on the timerlist.  */
    tqpost ((tqe_t *) &EQ_Event_List, tqe);

    /* Check to see if the current task is the  events dispatcher.  If it
     * is we do not want to place an item onto the event queue.  If the queue
     * is full the events dispatcher will suspend on the queue, and since
     * the events dispatcher is the only task that removes items from the
     * queue, deadlock will occur.
     */
    if (NU_Current_Task_Pointer() == &NU_EventsDispatcher_ptr)
    {
        return(NU_SUCCESS);
    }

    /*  Wake up the event dispatcher from an indefinite wait */
    /*  iff this is the first entry on the timer list        */
    if (EQ_Event_List.flink == tqe)
      TLS_Put_Event(CONNULL, dat);

    return (NU_SUCCESS);
} /* UTL_Timerset */

/*************************************************************************
*                                                                       
*   FUNCTION                                                              
*                                                                       
*       UTL_Timerunset                                                   
*                                                                       
*   DESCRIPTION                                                           
*                                                                       
*       Remove all timer events from the queue that match the            
*       class/event/dat.                                                 
*                                                                       
*   INPUTS                                                                
*
*       event                                                            
*       dat                                                              
*       ack_num                                                          
*                                                                       
*   OUTPUTS                                                               
*
*       Nucleus Status Code                                              
*                                                                       
*************************************************************************/
STATUS UTL_Timerunset (UNSIGNED event, UNSIGNED dat, INT32 ack_num)
{
   return (EQ_Clear_Matching_Timer (&EQ_Event_List, event, dat, ack_num));
}  /* UTL_Timerunset */

/*************************************************************************
*                                                                       
*   FUNCTION                                                              
*                                                                       
*       UTL_Zero                                                         
*                                                                       
*   DESCRIPTION                                                           
*                                                                       
*       This function clears an area of memory to all zeros.             
*                                                                       
*   INPUTS                                                                
*                                                                       
*       ptr         Pointer to starting address.                         
*       size        The number of bytes of memory to zero.               
*                                                                       
*   OUTPUTS                                                               
*                                                                       
*       None                                                             
*                                                                       
*************************************************************************/
VOID UTL_Zero(VOID *ptr, UINT32 size)
{
  UINT8     *byteStartP;
  UINT8     *byteEndP;
  UNSIGNED  *wordStartP;
  UNSIGNED  *wordEndP;

  UINT8 clearByte = 0;              /* causes most compilers to place these */
  UNSIGNED clearWord = 0;          /*   variables in a register only once */

⌨️ 快捷键说明

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