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

📄 win_ss.c

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

    TRC0(ssdInitDrvr);


    /* initialize the dependent portion of the driver task entries */
    for ( i = 0;  i < SS_MAX_DRVRTSKS;  i++ )
    {
        osCp.drvrTskTbl[i].dep.flag = FALSE;
    }


    /* create pipe for communication between SSetIntPend() and
     *  the isTskHdlr thread.
     */
	/*
    if ( ERROR == pipeDevCreate("isrCmdPipe", SS_MAX_ISRCMD, sizeof(WinIsFlag)) )
	*/
	if ( ROK != _pipe(osCp.dep.isFildes, sizeof(WinIsFlag)*SS_MAX_ISRCMD, _O_BINARY ) )
    {
        RETVALUE(RFAILED);
    }

    /*
	osCp.dep.isFildes = open("isrCmdPipe", O_RDWR,0644);
    if ( ERROR == osCp.dep.isFildes )
    {
        RETVALUE(RFAILED);
    }
	*/

    /* create the isTskHdlr thread */
    /*
    osCp.dep.isTskHdlrTID = taskSpawn("winIsrHndlr", ISR_PRIO, \
                                      VX_FP_TASK, ISRHNDLR_STK, \
                                      (FUNCPTR)winIsrHndlr, \
                                      0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
    
    if ( ERROR == osCp.dep.isTskHdlrTID )
    */
    osCp.dep.isTskHdlrTID = CreateThread(NULL, ISRHNDLR_STK, winIsrHndlr, 0, 0, NULL);

    if ( NULLP == osCp.dep.isTskHdlrTID
         || 0 == SetThreadPriority(osCp.dep.isTskHdlrTID, ISR_PRIO) )
    {
        RETVALUE(RFAILED);
    }

    RETVALUE(ROK);
}


/*
*
*       Fun:   Deinitialize driver information
*
*       Desc:  This function reverses the initialization performed in
*              ssdInitDrvr().
*
*       Ret:   ROK      - ok
*
*       Notes:
*
*       File:  win_ss.c
*
*/
    #ifdef ANSI
PUBLIC Void ssdDeinitDrvr
(
void
)
    #else
PUBLIC Void ssdDeinitDrvr()
    #endif
{
    TRC0(ssdDeinitDrvr);


    RETVOID;
}
#endif /* SS_DRVR_SUPPORT */


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


    osCp.dep.tmrTqCp.tmrLen = SS_MAX_TMRS;
    /*
    osCp.dep.tmrHdlrTID = taskSpawn("winTmr", TMR_PRIO, \
                                    VX_FP_TASK, TMRHNDLR_STK, \
                                    (FUNCPTR)winTmrHdlr, \
                                    0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
    if ( NULLP == osCp.dep.tmrHdlrTID )
    {
        RETVALUE(RFAILED);
    }
    */
    osCp.dep.tmrHdlrTID = CreateThread(NULL, TMRHNDLR_STK, winTmrHdlr, 0, 0, &tId);

    if ( NULLP == osCp.dep.tmrHdlrTID
         || 0 == SetThreadPriority(osCp.dep.tmrHdlrTID, TMR_PRIO) )
    {
        RETVALUE(RFAILED);
    }


    RETVALUE(ROK);
}


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

    RETVOID;
}


/*
*
*       Fun:   ssdInitFinal
*
*       Desc:  Pre-tst() initialization.
*
*       Ret:   ROK      - ok
*
*       Notes:
*
*       File:  win_ss.c
*
*/
#ifdef ANSI
PUBLIC S16 ssdInitFinal
(
void
)
#else
PUBLIC S16 ssdInitFinal()
#endif
{
    S32 flags;
#ifndef CONSTDIO
    int fd;
    struct termios tio;
#endif


    TRC0(ssdInitFinal);

    UNUSED(flags);

#ifdef CONAVL

    osCp.dep.conInFp = (FILE *) stdin;
    osCp.dep.conOutFp = (FILE *) stdout;


#ifndef CONSTDIO

    /* disable canonical input processing */
    fd = fileno(osCp.dep.conInFp);
    if ( (tcgetattr(fd, &tio)) != 0 )
    {
        RETVALUE(RFAILED);
    }

    tio.c_lflag &= ~ICANON;
    tio.c_cc[VMIN] = 0;
    tio.c_cc[VTIME] = 0;
    if ( (tcsetattr(fd, TCSANOW, &tio)) != 0 )
    {
        RETVALUE(RFAILED);
    }

#endif /* CONSTDIO */


    /* set up the input fd to block when no data is available */
    fd = fileno(osCp.dep.conInFp);
    flags = fcntl(fd, F_GETFL, &flags);
    flags &= ~O_NONBLOCK;
    if ( fcntl(fd, F_SETFL, flags) == -1 )
    {
        RETVALUE(RFAILED);
    }


    /* create the console handler thread */
    pthread_attr_init(&attr);
    pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
    if ( (pthread_create(&osCp.dep.conHdlrTID, &attr, mtConHdlr, NULLP)) != 0 )
    {
        RETVALUE(RFAILED);
    }

#endif /* CONAVL */


    RETVALUE(ROK);
}


/*
*
*       Fun:   ssdDeinitFinal
*
*       Desc:  This function reverses the initialization performed in
*              ssdInitFinal().
*
*       Ret:   ROK      - ok
*
*       Notes:
*
*       File:  win_ss.c
*
*/
#ifdef ANSI
PUBLIC Void ssdDeinitFinal
(
void
)
#else
PUBLIC Void ssdDeinitFinal()
#endif
{
    TRC0(ssdDeinitFinal);


    RETVOID;
}


/*
*
*       Fun:   winGetOpts
*
*       Desc:  This function gets command line options.
*
*       Ret:
*
*       Notes:
*
*       File:  win_ss.c
*
*/
#ifdef ANSI
PRIVATE Void winGetOpts
(
void
)
#else
PRIVATE Void winGetOpts()
#endif
{

    TRC0(winGetOpts);
}


/*
*
*       Fun:   ssdStart
*
*       Desc:  This function starts system services execution; the
*              permanent tasks are started and the system enters a
*              ready state.
*
*       Ret:   Void
*
*       Notes: 
*
*       File:  win_ss.c
*
*/
#ifdef ANSI
PUBLIC Void ssdStart
(
void
)
#else
PUBLIC Void ssdStart()
#endif
{
    S16 i;


    TRC0(ssdStart);


    for ( i = 0;  i < SS_MAX_STSKS;  i++ )
    {
        ssPostSema(&osCp.dep.ssStarted);
    }


    RETVOID;
}


/*
*     indirect interface functions to system services service user
*/


/*
*
*       Fun:   ssdAttachTTsk
*
*       Desc:  This function sends the initial tick message to a TAPA
*              task if the task is a permanent task.
*
*       Ret:   ROK      - ok
*
*       Notes:
*
*       File:  win_ss.c
*
*/
#ifdef ANSI
PUBLIC S16 ssdAttachTTsk
(
SsTTskEntry *tTsk           /* pointer to TAPA task entry */
)
#else
PUBLIC S16 ssdAttachTTsk(sTsk)
SsTTskEntry *tTsk;          /* pointer to TAPA task entry */
#endif
{
    Buffer *mBuf;
    SsMsgInfo *mInfo;
    S16 ret;


    TRC0(ssdAttachTTsk);


    if ( tTsk->tskType == SS_TSK_PERMANENT )
    {
        /* Send a permanent tick message to this task, to start
         * execution.
         */
        ret = SGetMsg(SS_DFLT_REGION, SS_DFLT_POOL, &mBuf);
        if ( ret != ROK )
        {
#if (ERRCLASS & ERRCLS_DEBUG)
            WINLOGERROR(ERRCLS_DEBUG, EMT001, ret, "SGetMsg() failed");
#endif
            RETVALUE(RFAILED);
        }

        mInfo = (SsMsgInfo *)mBuf->b_rptr;
        mInfo->eventInfo.event = SS_EVNT_PERMTICK;

        /* set up post structure */
        mInfo->pst.dstProcId = SFndProcId();
        mInfo->pst.srcProcId = SFndProcId();
        mInfo->pst.selector  = SEL_LC_NEW;
        mInfo->pst.region    = DFLT_REGION;
        mInfo->pst.pool      = DFLT_POOL;
        mInfo->pst.prior     = PRIOR3;
        mInfo->pst.route     = RTESPEC;
        mInfo->pst.event     = 0;
        mInfo->pst.dstEnt    = tTsk->ent;
        mInfo->pst.dstInst   = tTsk->inst;
        mInfo->pst.srcEnt    = tTsk->ent;
        mInfo->pst.srcInst   = tTsk->inst;

        ret = ssDmndQPutLast(&tTsk->sTsk->dQ, mBuf,
                             (tTsk->tskPrior * SS_MAX_MSG_PRI) + PRIOR3);

        if ( ret != ROK )
        {
            SPutMsg(mBuf);

#if (ERRCLASS & ERRCLS_DEBUG)
            WINLOGERROR(ERRCLS_DEBUG, EMT002, ret,
                       "Could not write to demand queue");
#endif
            RETVALUE(RFAILED);
        }
    }


    RETVALUE(ROK);
}


/*
*
*       Fun:   ssdDetachTTsk
*
*       Desc:  Does nothing.
*
*       Ret:   ROK      - ok
*
*       Notes:
*
*       File:  win_ss.c
*
*/
#ifdef ANSI
PUBLIC S16 ssdDetachTTsk
(
SsTTskEntry *tTsk           /* pointer to TAPA task entry */
)
#else
PUBLIC S16 ssdDetachTTsk(sTsk)
SsTTskEntry *tTsk;          /* pointer to TAPA task entry */
#endif
{
    TRC0(ssdDetachTTsk);


    RETVALUE(ROK);
}


/*
*
*       Fun:   ssdCreateSTsk
*
*       Desc:  This function creates a system task. A thread is started
*              on the system task handler function defined later.
*
*       Ret:   ROK      - ok
*
*       Notes:
*
*       File:  win_ss.c
*
*/
#ifdef ANSI
PUBLIC S16 ssdCreateSTsk
(
SsSTskEntry *sTsk           /* pointer to system task entry */
)
#else
PUBLIC S16 ssdCreateSTsk(sTsk)
SsSTskEntry *sTsk;          /* pointer to system task entry */
#endif
{
    TRC0(ssdCreateSTsk);


#ifdef SS_SINGLE_THREADED
    if ( osCp.numSTsks > 0 )
    {
        RETVALUE(ROK);
    }
#endif


    /* set the current executing entity and instance IDs to
     * 'not configured'. create the lock to access them.
     */
    sTsk->dep.ent = ENTNC;
    sTsk->dep.inst = INSTNC;
    if ( (SInitLock(&sTsk->dep.lock, SS_LOCK_MUTEX)) != ROK )
    {

#if (ERRCLASS & ERRCLS_DEBUG)
        WINLOGERROR(ERRCLS_DEBUG, EMT003, ERRZERO, "Could not create lock");
#endif

        RETVALUE(RFAILED);
    }
    /* create the thread */
    /*
    sTsk->dep.tId = taskSpawn("sysTsk", sTsk->tskPrior, \
                              VX_FP_TASK, TMRHNDLR_STK, \
                              (FUNCPTR)winTskHdlr, \
                              (S32)sTsk, 0, 0, 0, 0, 0, 0, 0, 0, 0);
    if ( NULLP == sTsk->dep.tId )
    */
    sTsk->dep.tHnd = CreateThread(NULL, TMRHNDLR_STK, winTskHdlr, sTsk, 0, &sTsk->dep.tId);

    if ( NULLP == sTsk->dep.tHnd
         || 0 == SetThreadPriority(sTsk->dep.tHnd, THREAD_PRIORITY_NORMAL) )
    {
        SDestroyLock(&sTsk->dep.lock);

#if (ERRCLASS & ERRCLS_DEBUG)
        WINLOGERROR(ERRCLS_DEBUG, EMT004, ERRZERO, "Could not create thread");
#endif

        RETVALUE(RFAILED);
    }


    RETVALUE(ROK);
}


/*
*
*       Fun:   ssdDestroySTsk
*
*       Desc:  This function destroys a system task. A terminate
*              event message is sent to the thread function.
*
*       Ret:   ROK      - ok
*
*       Notes:
*
*       File:  win_ss.c
*
*/
#ifdef ANSI
PUBLIC S16 ssdDestroySTsk
(
SsSTskEntry *sTsk           /* pointer to system task entry */
)
#else
PUBLIC S16 ssdDestroySTsk(sTsk)
SsSTskEntry *sTsk;          /* pointer to system task entry */
#endif
{
    Buffer *mBuf;
    SsMsgInfo *mInfo;


    TRC0(ssdDestroySTsk);


    /* we send a message to this system task to tell it to die */
    if ( SGetMsg(SS_DFLT_REGION, SS_DFLT_POOL, &mBuf) != ROK )
    {

#if (ERRCLASS & ERRCLASS_DEBUG)
        WINLOGERROR(ERRCLS_DEBUG, EMT005, ERRZERO, "Could not get a message");
#endif

        RETVALUE(RFAILED);
    }

    mInfo = (SsMsgInfo *)mBuf->b_rptr;
    mInfo->eventInfo.event = SS_EVNT_TERM;

    if ( ssDmndQPutLast(&sTsk->dQ, mBuf, 0) != ROK )
    {
        SPutMsg(mBuf);

#if (ERRCLASS & ERRCLASS_DEBUG)
        WINLOGERROR(ERRCLS_DEBUG, EMT006, ERRZERO,
                   "Could not write to demand queue");
#endif

        RETVALUE(RFAILED);
    }


    RETVALUE(ROK);
}


/*
*
*       Fun:   Register timer
*
*       Desc:  This function is used to register a timer
*              function for the service user. System services
*              will invoke the timer activation function
*              passed to it at the specified intervals.
*
*       Ret:   ROK      - ok
*
*       Notes: Timing is handled by the common timers. The
*              ticks are handled by a thread that uses
*              nanosleep() and thus timing precision will not
*              be very accurate.
*
*       File:  win_ss.c
*
*/
#ifdef ANSI
PUBLIC S16 ssdRegTmr
(
SsTmrEntry *tmr             /* pointer to timer entry */
)   
#else
PUBLIC S16 ssdRegTmr(tmr)

⌨️ 快捷键说明

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