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

📄 win_ss.c

📁 中国石油二期加油站IC系统后台通讯软件
💻 C
📖 第 1 页 / 共 5 页
字号:


/********************************************************************20**
  
     Name:     Multi-threaded Real_Time System Services - VxWorks
  
     Type:     C source file
  
     Desc:     C source code for the MTSS-Solaris implementation of
               System Services.
  
     File:     win_ss.c
  
     Sid:      win_ss.c 1.1  -  10/15/98 10:33:04
   
     Prg:      kp
  
*********************************************************************21*/



/* POSIX includes */
#ifndef _POSIX_C_SOURCE
    #define _POSIX_C_SOURCE         199309L
#endif

#include <stdio.h>
/*
#include <taskLib.h>
*/
#include <signal.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <time.h>


/* header include files (.h) */

#include "envopt.h"        /* environment options */
#include "envdep.h"        /* environment dependent */
#include "envind.h"        /* environment independent */

#include "gen.h"           /* general layer */
#include "ssi.h"           /* system services */

#include "cm5.h"           /* common timers */

#ifdef WIN32
#include "win_ss.h"         /* WINSS specific */
#include "win_err.h"         /* WINSS specific */
#endif

#include "ss_queue.h"      /* queues */
#include "ss_task.h"       /* tasking */
#include "ss_msg.h"        /* messaging */
#include "ss_mem.h"        /* memory management interface */
#include "ss_gen.h"        /* general */

#include "cm_mem.h"        /* common memory manager */


/* header/extern include files (.x) */

#include "gen.x"           /* general layer */
#include "ssi.x"           /* system services */

#include "cm5.x"           /* common timers */

#ifdef WIN32
#include "win_ss.x"         /* WINSS specific */

#include <fcntl.h>
#include <io.h>
#endif

#include "ss_queue.x"      /* queues */
#include "ss_task.x"       /* tasking */
#include "ss_timer.x"      /* timers */
#include "ss_strm.x"       /* STREAMS */
#include "ss_msg.x"        /* messaging */
#include "ss_mem.x"        /* memory management interface */
#include "ss_drvr.x"       /* driver tasks */
#include "ss_gen.x"        /* general */

#include "cm_mem.x"        /* common memory manager */
#include "ss_err.h"

#include "ss_region.x"
/*
#include "vxWorks.h"
#include "pipeDrv.h"
#include "ioLib.h"
*/
/*
#include <dos.h>
*/
/* forward references */
/* modify by julian */
/*
PRIVATE Void *winTskHdlr ARGS((void *));

PRIVATE Void *winTmrHdlr ARGS((void *));
*/
DWORD WINAPI winTskHdlr ARGS((void *));

DWORD WINAPI winTmrHdlr ARGS((void *));
/* modify by julian */

PRIVATE Void winTimeout ARGS((PTR tCb, S16 evnt));

PRIVATE Void winExit ARGS((int));

#ifdef CONAVL
PRIVATE Void *mtConHdlr ARGS((void *));
#endif

#ifdef SS_DRVR_SUPPORT
enum PIPES { READ, WRITE }; 
/*
PRIVATE Void *winIsrHndlr ARGS((void *));
*/
DWORD WINAPI winIsrHndlr ARGS((void *));
#endif

PRIVATE Void winGetOpts ARGS((void));



/* type declarations */

#ifdef SS_DRVR_SUPPORT
typedef struct winIsFlag
{
    U16 id;
    U8 action;

} WinIsFlag;
#endif



/* public variable declarations */

PUBLIC S32 winEnableOutputFile = TRUE;

PUBLIC S16 msOptInd;
PUBLIC S8  *msOptArg;
PUBLIC Txt **msArgv;
PUBLIC S16 msArgc;

/* private variable declarations */

/*** modify by shang , 2002-1-3 ***/
#if 0
PRIVATE CmMmRegCfg winCMMRegCfg;
PRIVATE CmMmRegCb *winCMMRegCb;
#endif

/*** modify by shang is over ***/


PRIVATE RegionCfg_s dfltRegionCfg[] = 
{
    { WIN_MBUF_DSIZE, WIN_MBUF_NMB_BUFS, 0 },
    { WIN_DBUF_DSIZE, WIN_DBUF_NMB_BUFS, WIN_HEAP_SIZE}
};

/*** add by shang is over ***/

/*
*
*       Fun:   WINOSInit
*
*       Desc:  This function is the entry point for the final binary. It
*              calls SInit() in the common code. It can be replaced by a
*              user function if required (SInit() must still be called).
*
*       Ret:   none on success
*              exit on failure
*
*       Notes:
*
*       File:  win_ss.c
*
*/
#ifdef ANSI
void WINOSInit
(
void
)
#else
PUBLIC void WINOSInit()
#endif
{
    TRC0(WINOSInit);
    SInit();
}


/*
*  initialization functions
*/

/*
*
*       Fun:   Initialize OS control point
*
*       Desc:  This function initializes WINSS-specific information
*              in the OS control point.
*
*       Ret:   ROK      - ok
*
*       Notes:
*
*       File:  win_ss.c
*
*/
#ifdef ANSI
PUBLIC S16 ssdInitGen
(
void
)
#else
PUBLIC S16 ssdInitGen()
#endif
{
    TRC0(ssdInitGen);


    osCp.dep.sysTicks = 0;

#ifndef NOFILESYS
    osCp.dep.fileOutFp = NULLP;
    if ( winEnableOutputFile )
    {
        osCp.dep.fileOutFp = fopen(WIN_OUTPUT_FILE, "w");
    }
#endif

    /* initialize the started semaphore */
    if ( ssInitSema(&osCp.dep.ssStarted, 0) != 0 )
    {
        RETVALUE(RFAILED);
    }
    /* add by Julian */
    /* initialize the task lock */
    if ( ssInitLockTsk() != ROK )
    {
        RETVALUE(RFAILED);
    }
    /* add by Julian */

    RETVALUE(ROK);
}


/*
*
*       Fun:   De-initialize OS control point
*
*       Desc:  This function reverses the initialization in ssdInitGen().
*
*       Ret:   ROK      - ok
*
*       Notes:
*
*       File:  win_ss.c
*
*/
#ifdef ANSI
PUBLIC Void ssdDeinitGen
(
void
)
#else
PUBLIC Void ssdDeinitGen()
#endif
{
    TRC0(ssdDeinitGen);


    ssDestroySema(&osCp.dep.ssStarted);

    /* add by julian */
    ssDestroyLockTsk();
    /* add by julian */

    RETVOID;
}


/*
*
*       Fun:   SGetOpt
*
*       Desc:  Get options from command line
*
*       Ret:   option  - success
*              '?'     - fail
*              EOF     - end of options
*
*       Notes: Handles command lines like the following
*
*              if opts = "abc:d" 
*                 then command line should look like this...
*                    -a foo -b foo1 -c -d foo
*
*              code usage:
*
*              while ((ret = SGetOpt(msArgc, msArgv, "ls")) != EOF )
*              {
*                 switch(ret)
*                 {
*                    case 'l':
*                       nloops = atoi(msArgv[msOptInd]);
*                       break;
*                    case 's':
*                       state1 = atoi(msArgv[msOptInd]);
*                    case '?':
*                    default:
*                       break;
*                 }
*              }
*
*       File:  win_ss.c
*
*/
#ifdef ANSI
PUBLIC S16 SGetOpt
(
int argc,                   /* argument count */
char **argv,                /* argument value */
char *opts                  /* options */
)
#else
PUBLIC S16 SGetOpt(argc, argv, opts)
int argc;                   /* argument count */
char **argv;                /* argument value */
char *opts;                 /* options */
#endif
{
    S16 sp;
    S16 c;
    S8 *cp;


    TRC1(SGetOpt);


    sp = 1;
    if ( sp == 1 )
    {
        if ( msOptInd >= (S16) argc  ||  argv[msOptInd][0] == '\0' ) RETVALUE(EOF);
        else
        {
            if ( !strcmp(argv[msOptInd], "--") )
            {
                msOptInd++;
                RETVALUE(EOF);
            }
            else if ( argv[msOptInd][0] != '-' )
            {
                msOptInd++;
                RETVALUE('?');
            }
        }
    }

    c = argv[msOptInd][sp];
    if ( c == ':'  ||  (cp = (S8 *) strchr(opts, c)) == (S8 *) NULLP )
    {
        if ( argv[msOptInd][++sp] == '\0' )
        {
            msOptInd++;
            sp = 1;
        }

        RETVALUE('?');
    }

    if ( *++cp == ':' )
    {
        if ( argv[msOptInd][sp+1] != '\0' ) msOptArg = &argv[msOptInd++][sp+1];
        else
        {
            if ( ++msOptInd >= (S16) argc )
            {
                sp = 1;
                RETVALUE('?');
            }
            else msOptArg = argv[msOptInd++];

            sp = 1;
        }
    }
    else
    {
        if ( argv[msOptInd][++sp] == '\0' )
        {
            sp = 1;
            msOptInd++;
        }

        msOptArg = NULLP;
    }


    RETVALUE(c);
}


/*
*
*       Fun:   Initialize region/pool tables
*
*       Desc:  This function initializes MTSS-specific information
*              in the region/pool tables and configures the common
*              memory manager for use.
*
*       Ret:   ROK      - ok
*
*       Notes:
*
*       File:  win_ss.c
*
*/
#ifdef ANSI
PUBLIC S16 ssdInitMem
(
void
)
#else
PUBLIC S16 ssdInitMem()
#endif
{
    TRC0(ssdInitMem);

    
    /*** modify by shang , 2002-1-3 ***/
    #if 0
    
    /* allocate space for the region control block */
    winCMMRegCb = (CmMmRegCb *)calloc(1, sizeof(CmMmRegCb));
    if ( NULLP == winCMMRegCb )
    {
        RETVALUE(RFAILED);
    }
    /* allocate space for the region */
    winCMMRegCfg.vAddr = (Data *)calloc(headSize + (mBufNmb * mBufSize) + (dBufNmb * dBufSize), sizeof(Data));
    if ( winCMMRegCfg.vAddr == NULLP )
    {
        free(winCMMRegCb);
        RETVALUE(RFAILED);
    }

    /* set up the CMM configuration structure */
    winCMMRegCfg.size = headSize + (mBufNmb * mBufSize) + (dBufNmb * dBufSize);
    winCMMRegCfg.lType = SS_LOCK_MUTEX;
    winCMMRegCfg.chFlag = 0;
    winCMMRegCfg.bktQnSize = 16;
    winCMMRegCfg.numBkts = 2;

    winCMMRegCfg.bktCfg[0].size = WIN_MBUF_DSIZE;
    winCMMRegCfg.bktCfg[0].numBlks = WIN_MBUF_NMB_BUFS;

    winCMMRegCfg.bktCfg[1].size = WIN_DBUF_DSIZE;
    winCMMRegCfg.bktCfg[1].numBlks = WIN_DBUF_NMB_BUFS;

    if ( cmMmRegInit(SS_DFLT_REGION, winCMMRegCb, &winCMMRegCfg) != ROK )
    {
        free(winCMMRegCfg.vAddr);
        free(winCMMRegCb);
        RETVALUE(RFAILED);
    }
    SLock(&regionCb.mutex);
    regionCb.regionIdTbl[0].regCb = winCMMRegCb;
    SUnlock(&regionCb.mutex);
    #else
    
    if (ROK != SCreateRegion(ENTSS, 0, SS_DFLT_REGION, dfltRegionCfg, 2))
    {
        RETVALUE(RFAILED);
    }
    

    /* initialize the STREAMS module */
    if ( ssStrmCfg(SS_DFLT_REGION, SS_DFLT_REGION) != ROK )
    {
        SDelRegion(SS_DFLT_REGION);
        RETVALUE(RFAILED);
    }

    #endif
    RETVALUE(ROK);

    /*** modify by shang is over ***/

}





/*
*
*       Fun:   De-initialize region/pool tables
*
*       Desc:  This function reverses the initialization in ssdInitMem().
*
*       Ret:   ROK      - ok
*
*       Notes:
*
*       File:  win_ss.c
*
*/
#ifdef ANSI
PUBLIC Void ssdDeinitMem
(
void
)
#else
PUBLIC Void ssdDeinitMem()
#endif
{
    TRC0(ssdDeinitMem);
    
    /*** modify by shang , 2002-1-3 ***/
    #if 0
    cmMmRegDeInit(winCMMRegCb);
    free(winCMMRegCfg.vAddr);
    free(winCMMRegCb);
    #else
    
    SDelRegion(SS_DFLT_REGION);
    #endif
    /*** modify by shang is over ***/

    RETVOID;
}


/*
*
*       Fun:   Initialize task table
*
*       Desc:  This function initializes WINSS-specific information
*              in the task table.
*
*       Ret:   ROK      - ok
*
*       Notes:
*
*       File:  win_ss.c
*
*/
#ifdef ANSI
PUBLIC S16 ssdInitTsk
(
void
)
#else
PUBLIC S16 ssdInitTsk()
#endif
{
    TRC0(ssdInitTsk);


    RETVALUE(ROK);
}


/*
*
*       Fun:   Deinitialize task table
*
*       Desc:  This function reverses the initialization perfomed in
*              ssdInitTsk().
*
*       Ret:   ROK      - ok
*
*       Notes:
*
*       File:  win_ss.c
*
*/
#ifdef ANSI
PUBLIC Void ssdDeinitTsk
(
void
)
#else
PUBLIC Void ssdDeinitTsk()
#endif
{
    TRC0(ssdDeinitTsk);

    RETVOID;
}

#ifdef SS_DRVR_SUPPORT
/*
*
*       Fun:   Initialize driver task table
*
*       Desc:  This function initializes MTSS-specific information
*              in the driver task table.
*
*       Ret:   ROK      - ok
*
*       Notes:
*
*       File:  win_ss.c
*
*/
    #ifdef ANSI
PUBLIC S16 ssdInitDrvr
(
void
)
    #else
PUBLIC S16 ssdInitDrvr()
    #endif
{
    S16 i;

⌨️ 快捷键说明

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