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

📄 test7.c

📁 eCos/RedBoot for勤研ARM AnywhereII(4510) 含全部源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
//===========================================================================
//
//      test7.c
//
//      uITRON "C" test program seven
//
//===========================================================================
//####ECOSGPLCOPYRIGHTBEGIN####
// -------------------------------------------
// This file is part of eCos, the Embedded Configurable Operating System.
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
//
// eCos is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2 or (at your option) any later version.
//
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
// for more details.
//
// You should have received a copy of the GNU General Public License along
// with eCos; if not, write to the Free Software Foundation, Inc.,
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
//
// As a special exception, if other files instantiate templates or use macros
// or inline functions from this file, or you compile this file and link it
// with other works to produce a work based on this file, this file does not
// by itself cause the resulting work to be covered by the GNU General Public
// License. However the source code for this file must still be made available
// in accordance with section (3) of the GNU General Public License.
//
// This exception does not invalidate any other reasons why a work based on
// this file might be covered by the GNU General Public License.
//
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
// at http://sources.redhat.com/ecos/ecos-license/
// -------------------------------------------
//####ECOSGPLCOPYRIGHTEND####
//===========================================================================
//#####DESCRIPTIONBEGIN####
//
// Author(s):   hmt
// Contributors:        hmt
// Date:        1998-10-01
// Purpose:     uITRON API testing
// Description: 
//
//####DESCRIPTIONEND####
//
//===========================================================================

#include <pkgconf/uitron.h>             // uITRON setup CYGNUM_UITRON_SEMAS
                                        // CYGPKG_UITRON et al
#include <cyg/infra/testcase.h>         // testing infrastructure

#ifdef CYGPKG_UITRON                    // we DO want the uITRON package

#ifdef CYGSEM_KERNEL_SCHED_MLQUEUE      // we DO want prioritized threads

#ifdef CYGFUN_KERNEL_THREADS_TIMER      // we DO want timout-able calls

#ifdef CYGVAR_KERNEL_COUNTERS_CLOCK     // we DO want the realtime clock

// we're OK if it's C++ or neither of those two is defined:
#if defined( __cplusplus ) || \    (!defined( CYGIMP_UITRON_INLINE_FUNCS ) && \     !defined( CYGIMP_UITRON_CPP_OUTLINE_FUNCS) )

// =================== TEST CONFIGURATION ===================
#if \    /* test configuration for enough tasks */                      \    (CYGNUM_UITRON_TASKS >= 4)                                  && \    (CYGNUM_UITRON_TASKS < 90)                                  && \    (CYGNUM_UITRON_START_TASKS == 1)                            && \    ( !defined(CYGPKG_UITRON_TASKS_CREATE_DELETE) ||               \      CYGNUM_UITRON_TASKS_INITIALLY >= 4             )          && \                                                                   \    /* test configuration for enough semaphores */                 \    defined( CYGPKG_UITRON_SEMAS )                              && \    (CYGNUM_UITRON_SEMAS >= 3)                                  && \    (CYGNUM_UITRON_SEMAS < 90)                                  && \    ( !defined(CYGPKG_UITRON_SEMAS_CREATE_DELETE) ||               \      CYGNUM_UITRON_SEMAS_INITIALLY >= 3             )          && \                                                                   \    /* test configuration for enough flag objects */               \    defined( CYGPKG_UITRON_FLAGS )                              && \    (CYGNUM_UITRON_FLAGS >= 3)                                  && \    (CYGNUM_UITRON_FLAGS < 90)                                  && \    ( !defined(CYGPKG_UITRON_FLAGS_CREATE_DELETE) ||               \      CYGNUM_UITRON_FLAGS_INITIALLY >= 3             )          && \                                                                   \    /* test configuration for enough message boxes */              \    defined( CYGPKG_UITRON_MBOXES )                             && \    (CYGNUM_UITRON_MBOXES >= 3)                                 && \    (CYGNUM_UITRON_MBOXES < 90)                                 && \    ( !defined(CYGPKG_UITRON_MBOXES_CREATE_DELETE) ||              \      CYGNUM_UITRON_MBOXES_INITIALLY >= 3            )          && \                                                                   \    /* test configuration for enough fixed memory pools */         \    defined( CYGPKG_UITRON_MEMPOOLFIXED )                       && \    (CYGNUM_UITRON_MEMPOOLFIXED >= 3)                           && \    (CYGNUM_UITRON_MEMPOOLFIXED < 90)                           && \    ( !defined(CYGPKG_UITRON_MEMPOOLFIXED_CREATE_DELETE) ||        \      CYGNUM_UITRON_MEMPOOLFIXED_INITIALLY >= 3       )         && \                                                                   \    /* test configuration for enough variable mempools */          \    defined( CYGPKG_UITRON_MEMPOOLVAR )                         && \    (CYGNUM_UITRON_MEMPOOLVAR >= 3)                             && \    (CYGNUM_UITRON_MEMPOOLVAR < 90)                             && \    ( !defined(CYGPKG_UITRON_MEMPOOLVAR_CREATE_DELETE) ||          \      CYGNUM_UITRON_MEMPOOLVAR_INITIALLY >= 3       )           && \                                                                   \    /* the end of the large #if statement */                       \    1 

// ============================ END ============================



#include <cyg/compat/uitron/uit_func.h> // uITRON

externC void
cyg_package_start( void )
{
    CYG_TEST_INIT();
    CYG_TEST_INFO( "Calling cyg_uitron_start()" );
    cyg_uitron_start();
}

// ========================================================================

typedef enum {
    START_WAITOP = 0,
    SLEEP = 0,
    DELAY,
    SEMGET,
    FLAGWAIT,
    MSGGET,
    MEMFIXEDGET,
    MEMVARGET,
    DONE_WAITOP
} WAITOP;

typedef enum {
    START_TYPE = 0,
    PLAIN = 0,
    TIMED = 1,
    DONE_TYPE
} WAITTYPE;

typedef enum {
    START_KILLOP = 0,

    // These are the 5 ways out of a wait that we perm
    // with other circumstances:
    SIGNAL = 0,                         // do the appropriate producer op
    TIMEOUT,                            // wait for the timeout to fire
    RELEASE,                            // do a rel_wai()
    DELETE,                             // delete the object; del_xxx()
    KILL,                               // do a ter_tsk() on the waiter

    SUSPEND_SIGNAL_RESUME,
    SUSPEND_TIMEOUT_RESUME,
    SUSPEND_RELEASE_RESUME,
    SUSPEND_DELETE_RESUME,
    SUSPEND_KILL,                       // resume not applicable

    SUSPEND_SIGNAL_KILL,
    SUSPEND_TIMEOUT_KILL,
    SUSPEND_RELEASE_KILL,
    SUSPEND_DELETE_KILL,
    // SUSPEND_KILL_KILL not applicable

#if 0
    // support these later if _really_ keen.
    SUSPEND_SIGNAL_DELETE_RESUME,
    SUSPEND_TIMEOUT_DELETE_RESUME,
    SUSPEND_RELEASE_DELETE_RESUME,
    // SUSPEND_DELETE_DELETE_RESUME not applicable
    // SUSPEND_KILL_DELETE_RESUME not applicable

    SUSPEND_SIGNAL_DELETE_KILL,
    SUSPEND_TIMEOUT_DELETE_KILL,
    SUSPEND_RELEASE_DELETE_KILL,
    // SUSPEND_DELETE_DELETE_KILL,
    SUSPEND_KILL_DELETE                 // 2nd kill not applicable
#endif
          
    DONE_KILLOP
} KILLOP;
        
// ========================================================================

char * waitstrings[] =
{ "Sleep ", "Delay ", "Sema  ", "Flag  ", "Mbox  ", "MemFix", "MemVar" };

char * typestrings[] =
{ " (Plain) : ", " (Timed) : " };

char * killstrings[] =
{ "Signal",
  "Wait-for-timeout",
  "Release-wait",
  "Delete-object",
  "Kill-task",

  "Suspend/Signal/Resume",
  "Suspend/Wait-for-timeout/Resume",
  "Suspend/Release-wait/Resume",
  "Suspend/Delete-object/Resume",
  "Suspend/Kill-task",

  "Suspend/Signal/Kill-task",
  "Suspend/Wait-for-timeout/Kill-task",
  "Suspend/Release-wait/Kill-task",
  "Suspend/Delete-object/Kill-task",
  

};

// ========================================================================

inline int task2arg( WAITOP wait, WAITTYPE waittype, KILLOP kill )
{
    return waittype + (wait << 1) + (kill << 8);
}

inline void decodearg( int arg, WAITOP *pwait, WAITTYPE *pwaittype, KILLOP *pkill )
{
    *pwaittype = (arg & 1) ? TIMED : PLAIN;
    *pwait  = (arg >> 1) & 0x7f;
    *pkill  = (arg >> 8);
}

static char *strdog( char *p, char *q )
{
    while ( 0 != (*p++ = *q++) );
    return p - 1;
}

static char *
makemsg( char *z, WAITOP wait, WAITTYPE waittype, KILLOP kill )
{
    static char buf[ 1000 ];
    char *p = buf;
    p = strdog( p, z );
    p = strdog( p, waitstrings[ wait ] );
    p = strdog( p, typestrings[ waittype ] );
    p = strdog( p, killstrings[ kill ] );
    *p = 0;
    return buf;
}

// ========================================================================

volatile int intercom = 0;

// ========================================================================

T_RTSK rtsk;

void
do_suspend( void )
{
    ER ercd;
    ercd = ref_tsk( &rtsk, 2 );
    CYG_TEST_CHECK( E_OK == ercd, "ref_tsk bad ercd" );
    CYG_TEST_CHECK( TTS_WAI == rtsk.tskstat, "bad tskstat !TTS_WAI" );
    ercd = sus_tsk( 2 );
    CYG_TEST_CHECK( E_OK == ercd, "sus_tsk bad ercd" );
    ercd = ref_tsk( &rtsk, 2 );
    CYG_TEST_CHECK( E_OK == ercd, "ref_tsk bad ercd" );
    CYG_TEST_CHECK( TTS_WAS == rtsk.tskstat, "bad tskstat !TTS_WAS" );
}

void
do_resume( void )
{
    ER ercd;
    ercd = ref_tsk( &rtsk, 2 );
    CYG_TEST_CHECK( E_OK == ercd, "ref_tsk bad ercd" );
    CYG_TEST_CHECK( TTS_SUS == rtsk.tskstat, "bad tskstat !TTS_SUS" );
    ercd = dis_dsp();
    CYG_TEST_CHECK( E_OK == ercd, "dis_dsp bad ercd" );
    ercd = rsm_tsk( 2 );
    CYG_TEST_CHECK( E_OK == ercd, "rsm_tsk bad ercd" );
    ercd = ref_tsk( &rtsk, 2 );
    CYG_TEST_CHECK( E_OK == ercd, "ref_tsk bad ercd" );
    CYG_TEST_CHECK( TTS_RDY == rtsk.tskstat, "bad tskstat !TTS_RDY" );
    ercd = ena_dsp();
    CYG_TEST_CHECK( E_OK == ercd, "ena_dsp bad ercd" );
}

// ========================================================================

#define T1_WAIT (7)
#define T2_WAIT (5)

#define T1_MALLOC (110)
#ifdef CYGSEM_KERNEL_MEMORY_COALESCE
#define T2_MALLOC (100)
#else
#define T2_MALLOC T1_MALLOC
#endif

VP vptmp;
VP vp = NULL;
VP vp1 = NULL;
VP t2vp = NULL;
VP t2vp_backup = NULL;

UINT scratch;

T_MSG *msg = (T_MSG *)&scratch;
T_MSG *msg1;

void
do_prep( WAITOP wait )
{
    ER ercd;
    switch ( wait ) {
    case SLEEP:
    case DELAY:
    case SEMGET:
    case FLAGWAIT:
    case MSGGET:
        // do nothing for all of those
        break;
    case MEMFIXEDGET:
        // allocate all the memory in the pool; remember a couple
        // for freeing as the signalling operation:
        t2vp = NULL;
        vp = vptmp = NULL;
        do {
            vp1 = vptmp;
            vptmp = vp;
            ercd = pget_blf( &vp, 1 );

⌨️ 快捷键说明

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