OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /openrisc/trunk/rtos/ecos-2.0/packages/compat/uitron/v2_0/include
    from Rev 27 to Rev 174
    Reverse comparison

Rev 27 → Rev 174

/uit_ifnc.inl
0,0 → 1,218
#ifndef CYGONCE_COMPAT_UITRON_UIT_IFNC_INL
#define CYGONCE_COMPAT_UITRON_UIT_IFNC_INL
//===========================================================================
//
// uit_ifnc.inl
//
// uITRON compatibility functions
//
//===========================================================================
//####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: 1999-08-16
// Purpose: uITRON compatibility functions
// Description:
//
//####DESCRIPTIONEND####
//
//===========================================================================
 
#ifdef CYGPKG_UITRON
 
#ifdef CYGPRI_UITRON_FUNCS_HERE_AND_NOW
 
class Cyg_Uit_Action {
public:
typedef enum {
WUP_TSK,
SIG_SEM,
SET_FLG,
SND_MSG
} action;
};
 
extern volatile int cyg_uit_dsr_actions_head;
extern volatile int cyg_uit_dsr_actions_tail;
 
#define CYGNUM_UITRON_ISR_ACTION_QUEUEMASK (CYGNUM_UITRON_ISR_ACTION_QUEUESIZE-1)
 
#if ((~CYGNUM_UITRON_ISR_ACTION_QUEUEMASK) & \
~((~CYGNUM_UITRON_ISR_ACTION_QUEUEMASK)-1)) \
!= CYGNUM_UITRON_ISR_ACTION_QUEUESIZE
#error CYGNUM_UITRON_ISR_ACTION_QUEUESIZE not a power of 2
#endif
 
extern Cyg_Uit_Action::action
cyg_uit_dsr_actions[ CYGNUM_UITRON_ISR_ACTION_QUEUESIZE ];
 
extern ID
cyg_uit_dsr_act_ids[ CYGNUM_UITRON_ISR_ACTION_QUEUESIZE ];
 
extern CYG_ADDRWORD
cyg_uit_dsr_act_a1s[ CYGNUM_UITRON_ISR_ACTION_QUEUESIZE ];
 
CYG_UIT_FUNC_INLINE
ER
iwup_tsk ( ID tskid )
{
#ifdef CYGSEM_UITRON_ISRFUNCS_TRY_IMMEDIATE_EXECUTION
if ( 1 >= Cyg_Scheduler::get_sched_lock() ) {
// then this ISR is the first one, and the sched was locked by the
// interrupt code. So this is safe.
return wup_tsk( tskid );
}
#endif
register int i, head;
i = cyg_uit_dsr_actions_head;
head = CYGNUM_UITRON_ISR_ACTION_QUEUEMASK & ( 1 + i );
// If interrupts can be recursive, then there is a race here where a
// slot may be overwritten by a recursive interrupt, or actions from
// such lost; better though than having a slot contain *mixed* data
// from two intermingled interrupts.
if ( head != cyg_uit_dsr_actions_tail ) {
cyg_uit_dsr_actions_head = head;
cyg_uit_dsr_actions[ i ] = Cyg_Uit_Action::WUP_TSK;
cyg_uit_dsr_act_ids[ i ] = tskid;
}
return E_OK;
}
#ifdef CYGPKG_UITRON_SEMAS
#if 0 < CYG_UITRON_NUM( SEMAS )
CYG_UIT_FUNC_INLINE
ER
isig_sem ( ID semid )
{
#ifdef CYGSEM_UITRON_ISRFUNCS_TRY_IMMEDIATE_EXECUTION
if ( 1 >= Cyg_Scheduler::get_sched_lock() ) {
// then this ISR is the first one, and the sched was locked by the
// interrupt code. So this is safe.
return sig_sem( semid );
}
#endif
register int i, head;
i = cyg_uit_dsr_actions_head;
head = CYGNUM_UITRON_ISR_ACTION_QUEUEMASK & ( 1 + i );
// If interrupts can be recursive, then there is a race here where a
// slot may be overwritten by a recursive interrupt, or actions from
// such lost; better though than having a slot contain *mixed* data
// from two intermingled interrupts.
if ( head != cyg_uit_dsr_actions_tail ) {
cyg_uit_dsr_actions_head = head;
cyg_uit_dsr_actions[ i ] = Cyg_Uit_Action::SIG_SEM;
cyg_uit_dsr_act_ids[ i ] = semid;
}
return E_OK;
}
#endif // 0 < CYG_UITRON_NUM( SEMAS )
#endif // CYGPKG_UITRON_SEMAS
 
#ifdef CYGPKG_UITRON_FLAGS
#if 0 < CYG_UITRON_NUM( FLAGS )
CYG_UIT_FUNC_INLINE
ER
iset_flg ( ID flgid, UINT setptn )
{
#ifdef CYGSEM_UITRON_ISRFUNCS_TRY_IMMEDIATE_EXECUTION
if ( 1 >= Cyg_Scheduler::get_sched_lock() ) {
// then this ISR is the first one, and the sched was locked by the
// interrupt code. So this is safe.
return set_flg( flgid, setptn );
}
#endif
register int i, head;
i = cyg_uit_dsr_actions_head;
head = CYGNUM_UITRON_ISR_ACTION_QUEUEMASK & ( 1 + i );
// If interrupts can be recursive, then there is a race here where a
// slot may be overwritten by a recursive interrupt, or actions from
// such lost; better though than having a slot contain *mixed* data
// from two intermingled interrupts.
if ( head != cyg_uit_dsr_actions_tail ) {
cyg_uit_dsr_actions_head = head;
cyg_uit_dsr_actions[ i ] = Cyg_Uit_Action::SET_FLG;
cyg_uit_dsr_act_ids[ i ] = flgid;
cyg_uit_dsr_act_a1s[ i ] = (CYG_ADDRWORD)setptn;
}
return E_OK;
}
#endif // 0 < CYG_UITRON_NUM( FLAGS )
#endif // CYGPKG_UITRON_FLAGS
 
#ifdef CYGPKG_UITRON_MBOXES
#if 0 < CYG_UITRON_NUM( MBOXES )
CYG_UIT_FUNC_INLINE
ER
isnd_msg ( ID mbxid, T_MSG *pk_msg )
{
#ifdef CYGSEM_UITRON_ISRFUNCS_TRY_IMMEDIATE_EXECUTION
if ( 1 >= Cyg_Scheduler::get_sched_lock() ) {
// then this ISR is the first one, and the sched was locked by the
// interrupt code. So this is safe.
return snd_msg( mbxid, pk_msg );
}
#endif
register int i, head;
i = cyg_uit_dsr_actions_head;
head = CYGNUM_UITRON_ISR_ACTION_QUEUEMASK & ( 1 + i );
// If interrupts can be recursive, then there is a race here where a
// slot may be overwritten by a recursive interrupt, or actions from
// such lost; better though than having a slot contain *mixed* data
// from two intermingled interrupts.
if ( head != cyg_uit_dsr_actions_tail ) {
cyg_uit_dsr_actions_head = head;
cyg_uit_dsr_actions[ i ] = Cyg_Uit_Action::SND_MSG;
cyg_uit_dsr_act_ids[ i ] = mbxid;
cyg_uit_dsr_act_a1s[ i ] = (CYG_ADDRWORD)pk_msg;
}
return E_OK;
}
#endif // 0 < CYG_UITRON_NUM( MBOXES )
#endif // CYGPKG_UITRON_MBOXES
// ========================================================================
 
#endif // CYGPKG_UITRON
 
#endif // CYGPRI_UITRON_FUNCS_HERE_AND_NOW
 
#endif // CYGONCE_COMPAT_UITRON_UIT_IFNC_INL
//EOF uit_ifnc.inl
/uit_func.h
0,0 → 1,402
#ifndef CYGONCE_COMPAT_UITRON_UIT_FUNC_H
#define CYGONCE_COMPAT_UITRON_UIT_FUNC_H
//===========================================================================
//
// uit_func.h
//
// uITRON compatibility functions
//
//===========================================================================
//####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-03-13
// Purpose: uITRON compatibility functions
// Description:
//
//####DESCRIPTIONEND####
//
//===========================================================================
 
// ------------------------------------------------------------------------
// Source Code Organization
//
// First, see pkgconf/uitron.h for details of applicable configuration
// options.
//
// This file uit_func.h provides prototypes for the uITRON API. All the
// uITRON functions are listed here. The prototypes are configurable
// either to have C or C++ linkage, and if being compiled in a C++
// environment, to be inline.
//
// The function prototypes are all in terms of uITRON type definitions from
// uit_type.h, which is included at the head of uit_func.h.
//
// The implementations of the uITRON functions are in uit_func.inl, which
// is either included at the end of uit_func.h (if functions are inline) or
// in uit_func.cxx (if outline).
//
// uit_func.cxx provides some startup functions plus, if the uITRON
// functions are out of line, uit_func.inl is included to instantiate those
// functions.
//
// uITRON system objects (tasks, semaphores...) are described in
// uit_obj.hxx. This is a C++ file and is used by the implementation of
// the uITRON functions.
//
// The uITRON system objects are instantiated in uit_obj.cxx, which uses
// uit_obj.hxx to define the objects, and the configuration file
// pkgconf/uitron.h to construct them as required.
//
// The include graph from an application, which should only include
// uit_func.h, is similar to the following:
//
//
// [inline uITRON functions:]
//
// <your_app.c>
// . uit_func.h ; prototypes for funcs
// . . pkgconf/uitron.h ; configuration info
// . . uit_type.h ; typedefs for func args
// . (function prototypes)
// . . uit_func.inl ; full function bodies
// . . . uit_objs.hxx ; defs of uITRON data
// . . (function implementations)
//
//
// [out-of-line uITRON functions:]
//
// <your_app.c>
// . uit_func.h ; prototypes for funcs
// . . pkgconf/uitron.h ; configuration info
// . . uit_type.h ; typedefs for func args
// . (function prototypes)
//
//
// [other uITRON compilation units:]
//
// uit_func.cxx ; out-of-line functions
// . pkgconf/uitron.h ; configuration info
// . uit_func.h ; prototypes for funcs
// . . uit_type.h ; typedefs for func args
// . (function prototypes)
// . . uit_func.inl ; full function bodies
// . . . uit_objs.hxx ; defs of uITRON data
// . . (function implementations)
//
//
// uit_objs.cxx ; static uITRON data objects
// . pkgconf/uitron.h ; configuration info
// . uit_objs.hxx ; defs of uITRON data
// (static uITRON system objects)
//
//
// The various include files are protected against multiple inclusion and
// so may be safely re-included as convenient.
//
// ------------------------------------------------------------------------
 
#include <pkgconf/uitron.h> // uITRON setup CYGNUM_UITRON_SEMAS
// CYGPKG_UITRON et al
 
#ifdef CYGPKG_UITRON
 
#include <cyg/infra/cyg_type.h> // types; cyg_int32, CYG_ADDRWORD
 
#include <cyg/compat/uitron/uit_type.h> // uITRON types; ER ID TMO T_MSG
 
// ------------------------------------------------------------------------
// Object operations:
//
// The functions can be inlined in C compiled by C++, or C++ of course,
// and also outlined in extern "C" functions, eg. for taking the address
// of, or for use by a pure C program, or of course outlined in C++ for
// Code size reasons.
//
//
// Summary:
//
// IF compiling in C
// THEN functions must be C linkage and out of line:
// do NOT specify CYGIMP_UITRON_INLINE_FUNCS nor
// CYGIMP_UITRON_CPP_OUTLINE_FUNCS.
// IF compiling in C++
// THEN functions can be inline: specify CYGIMP_UITRON_INLINE_FUNCS
// OR by default, functions are out of line:
// outline functions can have C++ linkage:
// specify CYGIMP_UITRON_CPP_OUTLINE_FUNCS
// OR by default, outline functions have C linkage.
 
 
#ifdef __cplusplus
// C++ environment; functions can be inline or not as we please.
// If not inline they might as well be "C" linkage for sharing with
// any pure "C" code present.
 
#ifdef CYGIMP_UITRON_INLINE_FUNCS
 
#define CYG_UIT_FUNC_EXTERN_BEGIN
#define CYG_UIT_FUNC_EXTERN_END
#define CYG_UIT_FUNC_INLINE inline
#ifndef CYGPRI_UITRON_FUNCS_HERE_AND_NOW
#define CYGPRI_UITRON_FUNCS_HERE_AND_NOW
#endif
 
#else
 
#ifdef CYGIMP_UITRON_CPP_OUTLINE_FUNCS
#define CYG_UIT_FUNC_EXTERN_BEGIN extern "C++" {
#define CYG_UIT_FUNC_EXTERN_END }
#else
#define CYG_UIT_FUNC_EXTERN_BEGIN extern "C" {
#define CYG_UIT_FUNC_EXTERN_END }
#endif
 
#define CYG_UIT_FUNC_INLINE
#endif
 
#else // !__cplusplus
// Vanilla "C" environment; external "C" linkage, no inline functions
 
#ifdef CYGIMP_UITRON_INLINE_FUNCS
#error "Cannot inline uITRON functions in pure C environment"
#endif
#ifdef CYGIMP_UITRON_CPP_OUTLINE_FUNCS
#error "Cannot use C++ linkage of outline fns in pure C environment"
#endif
 
#define CYG_UIT_FUNC_EXTERN_BEGIN
#define CYG_UIT_FUNC_EXTERN_END
#define CYG_UIT_FUNC_INLINE
 
#endif // !__cplusplus
 
// ========================================================================
// u I T R O N F U N C T I O N S
// The function declarations themselves:
 
CYG_UIT_FUNC_EXTERN_BEGIN
 
// this routine is outside the uITRON specification; call it from main() to
// start the uITRON tasks and scheduler. It does not return.
 
#ifdef CYGNUM_UITRON_START_TASKS
void cyg_uitron_start( void );
#endif
 
// ******************************************************
// *** 6.5 C Language Interfaces ***
// ******************************************************
 
// - Task Management Functions
 
ER cre_tsk ( ID tskid, T_CTSK *pk_ctsk );
ER del_tsk ( ID tskid );
ER sta_tsk ( ID tskid, INT stacd );
void ext_tsk ( void );
void exd_tsk ( void );
ER ter_tsk ( ID tskid );
 
ER dis_dsp ( void );
ER ena_dsp ( void );
ER chg_pri ( ID tskid, PRI tskpri );
ER rot_rdq ( PRI tskpri );
ER rel_wai ( ID tskid );
ER get_tid ( ID *p_tskid );
ER ref_tsk ( T_RTSK *pk_rtsk, ID tskid );
// - Task-Dependent Synchronization Functions
ER sus_tsk ( ID tskid );
ER rsm_tsk ( ID tskid );
ER frsm_tsk ( ID tskid );
ER slp_tsk ( void );
ER tslp_tsk ( TMO tmout );
ER wup_tsk ( ID tskid );
ER can_wup ( INT *p_wupcnt, ID tskid );
// - Synchronization and Communication Functions
ER cre_sem ( ID semid, T_CSEM *pk_csem );
ER del_sem ( ID semid );
ER sig_sem ( ID semid );
ER wai_sem ( ID semid );
ER preq_sem ( ID semid );
ER twai_sem ( ID semid, TMO tmout );
ER ref_sem ( T_RSEM *pk_rsem, ID semid );
 
ER cre_flg ( ID flgid, T_CFLG *pk_cflg );
ER del_flg ( ID flgid );
ER set_flg ( ID flgid, UINT setptn );
ER clr_flg ( ID flgid, UINT clrptn );
ER wai_flg ( UINT *p_flgptn, ID flgid, UINT waiptn, UINT wfmode );
ER pol_flg ( UINT *p_flgptn, ID flgid, UINT waiptn, UINT wfmode );
ER twai_flg ( UINT *p_flgptn, ID flgid, UINT waiptn, UINT wfmode,
TMO tmout );
ER ref_flg ( T_RFLG *pk_rflg, ID flgid );
 
ER cre_mbx ( ID mbxid, T_CMBX* pk_cmbx );
ER del_mbx ( ID mbxid );
ER snd_msg ( ID mbxid, T_MSG *pk_msg );
ER rcv_msg ( T_MSG **ppk_msg, ID mbxid );
ER prcv_msg ( T_MSG **ppk_msg, ID mbxid );
ER trcv_msg ( T_MSG **ppk_msg, ID mbxid, TMO tmout );
ER ref_mbx ( T_RMBX *pk_rmbx, ID mbxid );
// - Extended Synchronization and Communication Functions
#if 0 // NOT SUPPORTED
ER cre_mbf ( ID mbfid, T_CMBF *pk_cmbf );
ER del_mbf ( ID mbfid );
ER snd_mbf ( ID mbfid, VP msg, INT msgsz );
ER psnd_mbf ( ID mbfid, VP msg, INT msgsz );
ER tsnd_mbf ( ID mbfid, VP msg, INT msgsz, TMO tmout );
ER rcv_mbf ( VP msg, INT *p_msgsz, ID mbfid );
ER prcv_mbf ( VP msg, INT *p_msgsz, ID mbfid );
ER trcv_mbf ( VP msg, INT *p_msgsz, ID mbfid, TMO tmout );
ER ref_mbf ( T_RMBF *pk_rmbf, ID mbfid );
ER cre_por ( ID porid, T_CPOR *pk_cpor );
ER del_por ( ID porid );
ER cal_por ( VP msg, INT *p_rmsgsz, ID porid, UINT calptn, INT
cmsgsz );
ER pcal_por ( VP msg, INT *p_rmsgsz, ID porid, UINT calptn, INT
cmsgsz );
ER tcal_por ( VP msg, INT *p_rmsgsz, ID porid, UINT calptn, INT
cmsgsz, TMO tmout );
ER acp_por ( RNO *p_rdvno, VP msg, INT *p_cmsgsz, ID porid, UINT
acpptn );
ER pacp_por ( RNO *p_rdvno, VP msg, INT *p_cmsgsz, ID porid, UINT
acpptn );
ER tacp_por ( RNO *p_rdvno, VP msg, INT *p_cmsgsz, ID porid, UINT
acpptn, TMO tmout );
ER fwd_por ( ID porid, UINT calptn, RNO rdvno, VP msg, INT cmsgsz
);
ER rpl_rdv ( RNO rdvno, VP msg, INT rmsgsz );
ER ref_por ( T_RPOR *pk_rpor, ID porid );
#endif
// - Interrupt Management Functions
#if 0 // NOT SUPPORTED
ER def_int ( UINT dintno, T_DINT *pk_dint );
void ret_wup ( ID tskid );
#endif
#if 0
void ret_int ( void );
#endif
#define ret_int() return
ER loc_cpu ( void );
ER unl_cpu ( void );
 
ER dis_int ( UINT eintno );
ER ena_int ( UINT eintno );
 
#if 0 // NOT SUPPORTED
ER chg_iXX ( UINT iXXXX );
ER ref_iXX ( UINT *p_iXXXX );
#endif
// - Memorypool Management Functions
ER cre_mpl ( ID mplid, T_CMPL *pk_cmpl );
ER del_mpl ( ID mplid );
ER get_blk ( VP *p_blk, ID mplid, INT blksz );
ER pget_blk ( VP *p_blk, ID mplid, INT blksz );
ER tget_blk ( VP *p_blk, ID mplid, INT blksz, TMO tmout );
ER rel_blk ( ID mplid, VP blk );
ER ref_mpl ( T_RMPL *pk_rmpl, ID mplid );
 
ER cre_mpf ( ID mpfid, T_CMPF *pk_cmpf );
ER del_mpf ( ID mpfid );
ER get_blf ( VP *p_blf, ID mpfid );
ER pget_blf ( VP *p_blf, ID mpfid );
ER tget_blf ( VP *p_blf, ID mpfid, TMO tmout );
ER rel_blf ( ID mpfid, VP blf );
ER ref_mpf ( T_RMPF *pk_rmpf, ID mpfid );
// - Time Management Functions
ER set_tim ( SYSTIME *pk_tim );
ER get_tim ( SYSTIME *pk_tim );
ER dly_tsk ( DLYTIME dlytim );
ER def_cyc ( HNO cycno, T_DCYC *pk_dcyc );
ER act_cyc ( HNO cycno, UINT cycact );
ER ref_cyc ( T_RCYC *pk_rcyc, HNO cycno );
ER def_alm ( HNO almno, T_DALM *pk_dalm );
ER ref_alm ( T_RALM *pk_ralm, HNO almno );
#if 0
void ret_tmr ( void );
#endif
#define ret_tmr() return
// - System Management Functions
ER get_ver ( T_VER *pk_ver );
ER ref_sys ( T_RSYS *pk_rsys );
ER ref_cfg ( T_RCFG *pk_rcfg );
#if 0 // NOT SUPPORTED
ER def_svc ( FN s_fncd, T_DSVC *pk_dsvc );
ER def_exc ( UINT exckind, T_DEXC *pk_dexc );
#endif
// - Network Support Functions
#if 0 // NOT SUPPORTED
ER nrea_dat ( INT *p_reasz, VP dstadr, NODE srcnode, VP srcadr,
INT datsz );
ER nwri_dat ( INT *p_wrisz, NODE dstnode, VP dstadr, VP srcadr,
INT datsz );
ER nget_nod ( NODE *p_node );
ER nget_ver ( T_VER *pk_ver, NODE node );
#endif
 
CYG_UIT_FUNC_EXTERN_END
 
// ========================================================================
 
#ifdef CYGPRI_UITRON_FUNCS_HERE_AND_NOW
// functions are inline OR we are in the outline implementation, so define
// the functions as inlines or plain functions depending on the value of
// CYG_UIT_FUNC_INLINE from above.
#include <cyg/compat/uitron/uit_func.inl>
#endif // CYGPRI_UITRON_FUNCS_HERE_AND_NOW
 
// ------------------------------------------------------------------------
#endif // CYGPKG_UITRON
 
#endif // CYGONCE_COMPAT_UITRON_UIT_FUNC_H
// EOF uit_func.h
/uit_objs.hxx
0,0 → 1,177
#ifndef CYGONCE_COMPAT_UITRON_UIT_OBJS_HXX
#define CYGONCE_COMPAT_UITRON_UIT_OBJS_HXX
//===========================================================================
//
// uit_objs.hxx
//
// uITRON static objects
//
//===========================================================================
//####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-03-13
// Purpose: uITRON static system objects
// Description:
//
//####DESCRIPTIONEND####
//
//===========================================================================
 
#include <pkgconf/uitron.h> // uITRON setup CYGNUM_UITRON_SEMAS
// CYGPKG_UITRON et al
 
#ifdef CYGPKG_UITRON
 
#include <cyg/infra/cyg_type.h> // types; cyg_int32, CYG_ADDRWORD
 
#include <pkgconf/kernel.h>
 
#include <cyg/kernel/ktypes.h>
 
#include <cyg/kernel/thread.hxx> // Cyg_Thread
#include <cyg/kernel/mbox.hxx> // Cyg_Mbox
#include <cyg/kernel/flag.hxx> // Cyg_Flag
#include <cyg/kernel/sema2.hxx> // Cyg_Counting_Semaphore2
#include <cyg/memalloc/memfixed.hxx> // Cyg_Mempool_Fixed
#include <cyg/memalloc/memvar.hxx> // Cyg_Mempool_Variable
#include <cyg/kernel/timer.hxx> // Cyg_Timer
 
// ------------------------------------------------------------------------
// Some pasting macros to create names of the config macro and the
// static data resulting:
 
#define CYG_UITRON_NUM( _which_ ) (CYGNUM_UITRON_ ## _which_)
#define CYG_UITRON_OBJS( _which_ ) cyg_uitron_ ## _which_
#define CYG_UITRON_PTRS( _which_ ) cyg_uitron_ ## _which_ ## _ptrs
// ------------------------------------------------------------------------
// CYG_UITRON_DECL
//
// Macro to declare static uitron static objects; uses the appropriate
// config define for the number of them to have.
 
#define CYG_UITRON_OBJS_INIT_PRIORITY CYG_INIT_PRIORITY( COMPAT )
 
#define CYG_UITRON_DECL( _which_ ) \
CYG_UITRON_OBJS( _which_ ) [ CYG_UITRON_NUM( _which_ ) ] \
CYG_UITRON_OBJS_INIT_PRIORITY
 
// and the array of pointers to them for those with dynamic existence:
#define CYG_UITRON_DECL_PTRS( _which_ ) \
CYG_UITRON_PTRS( _which_ ) [ CYG_UITRON_NUM( _which_ ) ]
 
 
// ------------------------------------------------------------------------
// The external system objects themselves.
 
#ifdef CYGPKG_UITRON_SEMAS
extern
Cyg_Counting_Semaphore2 CYG_UITRON_OBJS( SEMAS ) [];
#ifdef CYGPKG_UITRON_SEMAS_CREATE_DELETE
extern
Cyg_Counting_Semaphore2 *CYG_UITRON_PTRS( SEMAS ) [];
#endif
#endif
#ifdef CYGPKG_UITRON_MBOXES
extern
Cyg_Mbox CYG_UITRON_OBJS( MBOXES ) [];
#ifdef CYGPKG_UITRON_MBOXES_CREATE_DELETE
extern
Cyg_Mbox *CYG_UITRON_PTRS( MBOXES ) [];
#endif
#endif
#ifdef CYGPKG_UITRON_FLAGS
extern
Cyg_Flag CYG_UITRON_OBJS( FLAGS ) [];
#ifdef CYGPKG_UITRON_FLAGS_CREATE_DELETE
extern
Cyg_Flag *CYG_UITRON_PTRS( FLAGS ) [];
#endif
#endif
// there must always be tasks
extern
Cyg_Thread CYG_UITRON_OBJS( TASKS ) [];
#ifdef CYGPKG_UITRON_TASKS_CREATE_DELETE
extern
Cyg_Thread *CYG_UITRON_PTRS( TASKS ) [];
#endif
// no endif
#ifdef CYGPKG_UITRON_MEMPOOLFIXED
extern
Cyg_Mempool_Fixed CYG_UITRON_OBJS( MEMPOOLFIXED ) [];
#ifdef CYGPKG_UITRON_MEMPOOLFIXED_CREATE_DELETE
extern
Cyg_Mempool_Fixed *CYG_UITRON_PTRS( MEMPOOLFIXED )[];
#endif
#endif
#ifdef CYGPKG_UITRON_MEMPOOLVAR
extern
Cyg_Mempool_Variable CYG_UITRON_OBJS( MEMPOOLVAR ) [];
#ifdef CYGPKG_UITRON_MEMPOOLVAR_CREATE_DELETE
extern
Cyg_Mempool_Variable *CYG_UITRON_PTRS( MEMPOOLVAR ) [];
#endif
#endif
#ifdef CYGPKG_UITRON_CYCLICS
extern
Cyg_Timer CYG_UITRON_OBJS( CYCLICS ) [];
#endif
#ifdef CYGPKG_UITRON_ALARMS
extern
Cyg_Timer CYG_UITRON_OBJS( ALARMS ) [];
#endif
 
// ------------------------------------------------------------------------
// Ancillary system objects - cleaner than extending the basic class
 
#ifdef CYGIMP_THREAD_PRIORITY
// An array of priorities, for resetting back to the "created" prio when a
// task cycles though exit, dormancy, restart.
extern cyg_priority
cyg_uitron_task_initial_priorities[ CYG_UITRON_NUM( TASKS ) ];
// and an accessor macro, for the addressing of this is naturally
// from 1..N also:
#define CYG_UITRON_TASK_INITIAL_PRIORITY( _tskid_ ) \
(cyg_uitron_task_initial_priorities[ (_tskid_) - 1 ])
#endif // CYGIMP_THREAD_PRIORITY
 
// ------------------------------------------------------------------------
 
#endif // CYGPKG_UITRON
 
#endif // CYGONCE_COMPAT_UITRON_UIT_OBJS_HXX
// EOF uit_objs.hxx
/uit_ifnc.h
0,0 → 1,182
#ifndef CYGONCE_COMPAT_UITRON_UIT_IFNC_H
#define CYGONCE_COMPAT_UITRON_UIT_IFNC_H
//===========================================================================
//
// uit_ifnc.h
//
// uITRON compatibility functions
//
//===========================================================================
//####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: 1999-08-16
// Purpose: uITRON compatibility functions
// Description:
//
//####DESCRIPTIONEND####
//
//===========================================================================
 
// ------------------------------------------------------------------------
// Source Code Organization
//
// First, see pkgconf/uitron.h for details of applicable configuration
// options.
//
// This file uit_ifnc.h provides prototypes for the task-independent parts
// of the uITRON API, that is functions named ixxx_yyy() for calling in
// ISRs. We also define the uitron helper DSR that is needed to despool
// stored up requests.
// ------------------------------------------------------------------------
 
#include <pkgconf/uitron.h> // uITRON setup CYGNUM_UITRON_SEMAS
// CYGPKG_UITRON et al
 
#ifdef CYGPKG_UITRON
 
#include <cyg/infra/cyg_type.h> // types; cyg_int32, CYG_ADDRWORD
 
#include <cyg/compat/uitron/uit_type.h> // uITRON types; ER ID TMO T_MSG
#include <cyg/compat/uitron/uit_func.h> // uITRON funcs and control macros.
 
// ========================================================================
// u I T R O N F U N C T I O N S
// The function declarations themselves:
 
// ------------------- These functions can be inline if so configured
CYG_UIT_FUNC_EXTERN_BEGIN
 
// ******************************************************
// *** 6.5 C Language Interfaces ***
// ******************************************************
 
// - Task Management Functions
 
// (None)
// - Task-Dependent Synchronization Functions
//ER irsm_tsk ( ID tskid );
//ER ifrsm_tsk ( ID tskid );
 
ER iwup_tsk ( ID tskid );
// - Synchronization and Communication Functions
ER isig_sem ( ID semid );
 
ER iset_flg ( ID flgid, UINT setptn );
 
ER isnd_msg ( ID mbxid, T_MSG *pk_msg );
// - Extended Synchronization and Communication Functions
// - Interrupt Management Functions
// (None)
// ---------------------------------------------------------------
 
#define CYGPRI_UITRON_SET_RETCODE( _z_ ) do { \
extern volatile int cyg_uit_dsr_actions_head; \
extern volatile int cyg_uit_dsr_actions_tail; \
(_z_) = (cyg_uit_dsr_actions_head == cyg_uit_dsr_actions_tail) ? 1 : 3; \
} while ( 0 )
 
//void ret_wup ( ID tskid );
// Awaken the task (safely) and return Cyg_Interrupt::CALL_DSR
#define ret_wup( _id_ ) do { \
register int retcode; \
(void)iwup_tsk( (_id_) ); \
CYGPRI_UITRON_SET_RETCODE( retcode ); \
return retcode; \
} while ( 0 )
 
// Subsitute a version of ret_int that returns Cyg_Interrupt::CALL_DSR
#undef ret_int
#define ret_int() do { \
register int retcode; \
CYGPRI_UITRON_SET_RETCODE( retcode ); \
return retcode; \
} while ( 0 )
 
 
// - Memorypool Management Functions
 
// (None)
// - Time Management Functions
// (None)
// - System Management Functions
// (None)
// - Network Support Functions
// (None)
CYG_UIT_FUNC_EXTERN_END
// ------------------- End of functions that can be inlined
 
 
// ========================================================================
// DSR: use this DSR with the uITRON-type ISR that uses the functions above
// to get delayed/safe execution of the wakeup-type functions above.
 
#ifdef __cplusplus
extern "C"
#endif
void cyg_uitron_dsr( unsigned int vector, unsigned int count, unsigned int data );
 
 
// ========================================================================
 
#ifdef CYGPRI_UITRON_FUNCS_HERE_AND_NOW
// functions are inline OR we are in the outline implementation, so define
// the functions as inlines or plain functions depending on the value of
// CYG_UIT_FUNC_INLINE from above.
#include <cyg/compat/uitron/uit_ifnc.inl>
#endif // CYGPRI_UITRON_FUNCS_HERE_AND_NOW
 
// ------------------------------------------------------------------------
#endif // CYGPKG_UITRON
 
#endif // CYGONCE_COMPAT_UITRON_UIT_IFNC_H
// EOF uit_ifnc.h
/uit_type.h
0,0 → 1,687
#ifndef CYGONCE_COMPAT_UITRON_UIT_TYPE_H
#define CYGONCE_COMPAT_UITRON_UIT_TYPE_H
//===========================================================================
//
// uit_type.h
//
// uITRON specific data types as required by the API
//
//===========================================================================
//####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-03-13
// Purpose: uITRON specific data types as required by the API
// Description:
//
//####DESCRIPTIONEND####
//
//===========================================================================
 
#include <pkgconf/uitron.h> // uITRON setup CYGNUM_UITRON_SEMAS
// CYGPKG_UITRON et al
 
#ifdef CYGPKG_UITRON
 
// ------------------------------------------------------------------------
// uITRON types
//
 
// from this section of the uITRON 3.02 manual:
// ***********************************************************************
// *** 6.4 Data Types ***
// ***********************************************************************
//
// *** General-Purpose Data Types ***************************************
 
typedef cyg_int8 B; // signed 8-bit integer
typedef cyg_int16 H; // signed 16-bit integer
typedef cyg_int32 W; // signed 32-bit integer
typedef cyg_uint8 UB; // unsigned 8-bit integer
typedef cyg_uint16 UH; // unsigned 16-bit integer
typedef cyg_uint32 UW; // unsigned 32-bit integer
//
typedef cyg_uint32 VW; // unpredictable data type (32-bit size)
typedef cyg_uint16 VH; // unpredictable data type (16-bit size)
typedef cyg_uint8 VB; // unpredictable data type (8-bit size)
typedef void * VP; // pointer to an unpredictable data type
typedef CYG_ADDRWORD FP; // program start address
 
// * The difference between VB, VH and VW and B, H and W is that only the
// number of bits is known for the former, not the data type of the
// contents. The latter clearly represent integers.
//
// *** Data Types Dependent on ITRON Specification ***
//
// In order to clarify the meanings of certain parameters, the following
// names are used for data types which appear frequently and/or have
// special meanings.
 
typedef cyg_int32 INT; // Signed integer (bit width of processor)
typedef cyg_uint32 UINT; // Unsigned integer (bit width of processor)
typedef cyg_int32 BOOL; // Boolean value. TRUE (1) or FALSE (0).
typedef cyg_uint16 FN; // Function code. Signed integer. Maximum 2 bytes.
typedef INT ID; // Object ID number (???id)
typedef INT BOOL_ID;// Boolean value or ID number
typedef INT HNO; // Handler number
typedef INT RNO; // Rendezvous number
typedef INT NODE; // Node Number. Usually a signed integer.
typedef UINT ATR; // Object or handler attribute. An unsigned integer.
typedef INT ER; // Error code. A signed integer.
typedef INT PRI; // Task priority. A signed integer.
typedef UB T_MSG; // Message packet data structure used for mailboxes
typedef INT TMO; // Timeout value. A signed integer.
// TMO_POL = 0 indicates polling,
// while TMO_FEVR = -1 indicates wait forever.
 
typedef cyg_uint64 CYGTM;
typedef CYGTM SYSTIME;// Data types used for specifying times.
typedef CYGTM CYCTIME;// Often split into upper and lower sections.
typedef CYGTM ALMTIME;// For details, see the chapter giving system
typedef CYGTM DLYTIME;// call descriptions;.
 
// ***********************************************************************
// *** 6.7 Error Codes ***
// ***********************************************************************
 
enum {
//------------------------------------------------------
//Mnemonic Value Description
//------------------------------------------------------
E_OK = 0, // Normal completion
// - - - - - - - - // - - - - - - - - - - - - - - - - - -
E_SYS = (-5), // System error
// - - - - - - - - // - - - - - - - - - - - - - - - - - -
E_NOMEM = (-10), // Insufficient memory
// - - - - - - - - // - - - - - - - - - - - - - - - - - -
E_NOSPT = (-17), // Feature not supported
E_INOSPT = (-18), // Feature not supported by ITRON/FILE specification
E_RSFN = (-20), // Reserved function code number
E_RSATR = (-24), // Reserved attribute
// - - - - - - - - // - - - - - - - - - - - - - - - - - -
E_PAR = (-33), // Parameter error
E_ID = (-35), // Invalid ID number
// - - - - - - - - // - - - - - - - - - - - - - - - - - -
E_NOEXS = (-52), // Object does not exist
E_OBJ = (-63), // Invalid object state
// - - - - - - - - // - - - - - - - - - - - - - - - - - -
E_MACV = (-65), // Memory access disabled or memory access violation
E_OACV = (-66), // Object access violation
// - - - - - - - - // - - - - - - - - - - - - - - - - - -
E_CTX = (-69), // Context error
// - - - - - - - - // - - - - - - - - - - - - - - - - - -
E_QOVR = (-73), // Queuing or nesting overflow
// - - - - - - - - // - - - - - - - - - - - - - - - - - -
E_DLT = (-81), // Object being waited for was deleted
// - - - - - - - - // - - - - - - - - - - - - - - - - - -
E_TMOUT = (-85), // Polling failure or timeout exceeded
E_RLWAI = (-86), // WAIT state was forcibly released
// - - - - - - - - // - - - - - - - - - - - - - - - - - - -
#if 0 // CONNECTION FUNCTIONS ARE NOT SUPPORTED
EN_NOND = (-113), // Target node does not exist or cannot be accessed
EN_OBJNO = (-114), // Specifies an object number which could not be
// accessed on the target node
EN_PROTO = (-115), // Protocol not supported on target node
EN_RSFN = (-116), // System call or function not supported on target node
EN_COMM = (-117), // No response from target node
EN_RLWAI = (-118), // Connection function response wait state was forcibly
// released
EN_PAR = (-119), // A value outside the range supported by the target
// node and/or transmission packet format was specified
// as a parameter
EN_RPAR = (-120), // A value outside the range supported by the issuing
// node and/or transmission packet format was returned
// as a return parameter
EN_CTXID = (-121), // An object on another node was specified to a system
// call issued from a task in dispatch disabled state
// or from a task-independent portion
EN_EXEC = (-122), // System call could not be executed due to
// insufficient resources on the target node
EN_NOSPT = (-123), // Connection function not supported
#endif // 0 CONNECTION FUNCTIONS ARE NOT SUPPORTED
// - - - - - - - - // - - - - - - - - - - - - - - - - - - -
};
 
 
// *******************************************************************
// *** 6.6 Common Constants and Data Structure Packet Formats ***
// *******************************************************************
 
/* --- overall ----------------------- */
 
/* invalid address or pointer value */
#define NADR ((void *)(-1))
 
enum {
TRUE = 1, /* true */
FALSE = 0, /* false */
};
 
/* TMO tmout: */
enum {
TMO_POL = 0, /* polling */
TMO_FEVR = (-1) /* wait forever */
};
 
/* --- for task management functions ----------------------- */
 
// cre_tsk:
typedef struct t_ctsk {
VP exinf; /* extended information */
ATR tskatr; /* task attributes */
FP task; /* task start address */
PRI itskpri; /* initial task priority */
INT stksz; /* stack size */
// ...
/* additional information may be included depending on the
implementation */
// ...
} T_CTSK;
 
// tskatr:
enum {
TA_ASM = 0x00, /* program written in assembly language */
TA_HLNG = 0x01, /* program written in high-level language */
TA_COP0 = 0x8000, /* uses coprocessor having ID = 0 */
TA_COP1 = 0x4000, /* uses coprocessor having ID = 1 */
TA_COP2 = 0x2000, /* uses coprocessor having ID = 2 */
TA_COP3 = 0x1000, /* uses coprocessor having ID = 3 */
TA_COP4 = 0x0800, /* uses coprocessor having ID = 4 */
TA_COP5 = 0x0400, /* uses coprocessor having ID = 5 */
TA_COP6 = 0x0200, /* uses coprocessor having ID = 6 */
TA_COP7 = 0x0100, /* uses coprocessor having ID = 7 */
};
 
// tskid:
enum {
TSK_SELF = 0, /* task specifies itself */
/* FALSE = 0, */ /* indicates a task-independent portion (return
parameters only) */
};
// tskpri:
enum {
TPRI_INI = 0, /* specifies the initial priority on task startup
(chg_pri) */
TPRI_RUN = 0, /* specifies the highest priority during execution
(rot_rdq) */
};
/* ref_tsk */
typedef struct t_rtsk {
VP exinf; /* extended information */
PRI tskpri; /* current priority */
UINT tskstat; /* task state */
/* the following are represent extended features of support
[level X] (implementation-dependent) */
#if 0 // NOT SUPPORTED
UINT tskwait; /* cause of wait */
ID wid; /* ID of object being waited for */
INT wupcnt; /* wakeup request count */
INT suscnt; /* SUSPEND request count */
ATR tskatr; /* task attributes */
FP task; /* task start address */
PRI itskpri; /* initial task priority */
INT stksz; /* stack size */
// ...
#endif
} T_RTSK;
 
// tskstat:
enum {
TTS_RUN = 0x01, /* RUN */
TTS_RDY = 0x02, /* READY */
TTS_WAI = 0x04, /* WAIT */
TTS_SUS = 0x08, /* SUSPEND */
TTS_WAS = 0x0C, /* WAIT-SUSPEND */
TTS_DMT = 0x10, /* DORMANT */
};
// tskwait:
enum {
TTW_SLP = 0x0001, /* wait due to slp_tsk or tslp_tsk */
TTW_DLY = 0x0002, /* wait due to dly_tsk */
TTW_NOD = 0x0008, /* connection function response wait */
TTW_FLG = 0x0010, /* wait due to wai_flg or twai_flg */
TTW_SEM = 0x0020, /* wait due to wai_sem or twai_sem */
TTW_MBX = 0x0040, /* wait due to rcv_msg or trcv_msg */
TTW_SMBF = 0x0080, /* wait due to snd_mbf or tsnd_mbf */
TTW_MBF = 0x0100, /* wait due to rcv_mbf or trcv_mbf */
TTW_CAL = 0x0200, /* wait for rendezvous call */
TTW_ACP = 0x0400, /* wait for rendezvous accept */
TTW_RDV = 0x0800, /* wait for rendezvous completion */
TTW_MPL = 0x1000, /* wait due to get_blk or tget_blk */
TTW_MPF = 0x2000, /* wait due to get_blf or tget_blf */
};
/* Since the task states given by tskstat and tskwait are expressed
by bit correspondences, they are convenient when looking for OR
conditions (such as whether a task is in WAIT or READY state).
*/
 
/* --- for semaphore functions ----------------------- */
 
/* cre_sem */
typedef struct t_csem {
VP exinf; /* extended information */
ATR sematr; /* semaphore attributes */
/* Following is the extended function for [level X]. */
INT isemcnt; /* initial semaphore count */
/* INT maxsem; NOT SUPPORTED maximum semaphore count */
// ...
/* additional information may be included depending on the
implementation */
// ...
} T_CSEM;
 
/* ref_sem */
typedef struct t_rsem {
VP exinf; /* extended information */
BOOL_ID wtsk; /* indicates whether or not there is a
waiting task */
INT semcnt; /* current semaphore count */
// ...
/* additional information may be included depending on the
implementation */
// ...
} T_RSEM;
 
/* --- for eventflag functions ----------------------- */
 
/* cre_flg */
typedef struct t_cflg {
VP exinf; /* extended information */
ATR flgatr; /* eventflag attribute */
UINT iflgptn; /* initial eventflag */
// ...
/* additional information may be included depending on the
implementation */
// ...
} T_CFLG;
 
// flgatr:
enum {
TA_WSGL = 0x00, /* multiple tasks are not allowed to wait (Wait
Single Task) */
TA_WMUL = 0x08, /* multiple tasks are allowed to wait (Wait
Multiple Task) */
};
// wfmode:
enum {
TWF_ANDW = 0x00, /* AND wait */
TWF_ORW = 0x02, /* OR wait */
TWF_CLR = 0x01, /* clear specification */
};
/* ref_flg */
typedef struct t_rflg {
VP exinf; /* extended information */
BOOL_ID wtsk; /* indicates whether or not there is a
waiting task */
UINT flgptn; /* eventflag bit pattern */
// ...
/* additional information may be included depending on the
implementation */
// ...
} T_RFLG;
 
/* --- for mailbox functions ----------------------- */
 
/* cre_mbx */
typedef struct t_cmbx {
VP exinf; /* extended information */
ATR mbxatr; /* mailbox attributes */
/* Following is implementation-dependent function */
/* INT bufcnt; NOT SUPPORTED ring buffer size IS FIXED */
// ...
/* additional information may be included depending on the
implementation */
// ...
} T_CMBX;
 
// mbxatr:
enum {
TA_TFIFO = 0x00, /* waiting tasks are handled by FIFO */
TA_TPRI = 0x01, /* waiting tasks are handled by priority */
TA_MFIFO = 0x00, /* messages are handled by FIFO */
TA_MPRI = 0x02, /* messages are handled by priority */
};
 
/* ref_mbx */
typedef struct t_rmbx {
VP exinf; /* extended information */
BOOL_ID wtsk; /* indicates whether or not there is a
waiting task */
T_MSG* pk_msg; /* message to be sent next */
// ...
/* additional information may be included depending on the
implementation */
// ...
} T_RMBX;
 
/* --- for messagebuffer functions ----------------------- */
 
#if 0 // NOT SUPPORTED
/* cre_mbf */
typedef struct t_cmbf {
VP exinf; /* extended information */
ATR mbfatr; /* messagebuffer attributes */
INT bufsz; /* messagebuffer size */
INT maxmsz; /* maximum size of messages */
// ...
/* additional information may be included depending on the
implementation */
// ...
} T_CMBF;
 
// mbfatr:
// mbfid:
enum {
TMBF_OS = (-4), /* messagebuffer used for OS error log */
TMBF_DB = (-3), /* messagebuffer used for debugging */
};
/* ref_mbf */
typedef struct t_rmbf {
VP exinf; /* extended information */
BOOL_ID wtsk; /* indicates whether or not there is a
task waiting to receive a message */
BOOL_ID stsk; /* indicates whether or not there is a
task waiting to send a message */
INT msgsz; /* size of message to be sent next */
INT frbufsz; /* size of free buffer */
// ...
/* additional information may be included depending on the
implementation */
// ...
} T_RMBF;
 
#endif
/* --- for port or rendezvous functions ----------------------- */
 
#if 0 // NOT SUPPORTED
 
/* cre_por */
typedef struct t_cpor {
VP exinf; /* extended information */
ATR poratr; /* port attributes */
INT maxcmsz; /* maximum call message size */
INT maxrmsz; /* maximum reply message size */
// ...
/* additional information may be included depending on the
implementation */
// ...
} T_CPOR;
 
// poratr:
enum {
TA_NULL = 0, /* specifies no particular attributes */
/* TA_NULL should be used in place of zeroes to turn off all
attribute features. */
};
/* ref_por */
typedef struct t_rpor {
VP exinf; /* extended information */
BOOL_ID wtsk; /* indicates whether or not there is a task
waiting to call a rendezvous */
BOOL_ID atsk; /* indicates whether or not there is a task
waiting to accept a rendezvous */
// ...
/* additional information may be included depending on the
implementation */
// ...
} T_RPOR;
#endif
 
/* --- for interrupt management functions ----------------------- */
 
#if 0 // NOT SUPPORTED
/* def_int */
typedef struct t_dint {
ATR intatr; /* interrupt handler attributes */
FP inthdr; /* interrupt handler address */
// ...
/* additional information may be included depending on the
implementation */
// ...
} T_DINT;
#endif
 
/* --- for memorypool management functions ----------------------- */
 
/* cre_mpl */
typedef struct t_cmpl {
VP exinf; /* extended information */
ATR mplatr; /* memorypool attributes */
INT mplsz; /* memorypool size */
// ...
/* additional information may be included depending on the
implementation */
// ...
} T_CMPL;
 
// mplatr:
// mplid:
enum {
TMPL_OS = (-4) /* memorypool used by OS */
};
/* ref_mpl */
typedef struct t_rmpl {
VP exinf; /* extended information */
BOOL_ID wtsk; /* indicates whether or not there are
waiting tasks */
INT frsz; /* total size of free memory */
INT maxsz; /* size of largest contiguous memory */
// ...
/* additional information may be included depending on the
implementation */
// ...
} T_RMPL;
 
/* cre_mpf */
typedef struct t_cmpf {
VP exinf; /* extended information */
ATR mpfatr; /* memorypool attributes */
INT mpfcnt; /* block count for entire memorypool */
INT blfsz; /* fixed-size memory block size */
// ...
/* additional information may be included depending on the
implementation */
// ...
} T_CMPF;
 
// mpfatr:
/* ref_mpf */
typedef struct t_rmpf {
VP exinf; /* extended information */
BOOL_ID wtsk; /* indicates whether or not there are
waiting tasks */
INT frbcnt; /* free block count */
/* additional information may be included depending on the
implementation */
INT numbcnt; /* total number of blocks */
INT bsize; /* block size */
 
} T_RMPF;
 
/* --- for time management functions ----------------------- */
 
#if 0 // native definition is at head of this file
/* example for 32-bit CPUs */
typedef struct t_systime {
H utime; /* upper 16 bits */
UW ltime; /* lower 32 bits */
} SYSTIME, CYCTIME, ALMTIME;
 
/* example for 16-bit CPUs */
typedef struct t_systime {
H utime; /* upper 16 bits */
UH mtime; /* middle 16 bits */
UH ltime; /* lower 16 bits */
} SYSTIME, CYCTIME, ALMTIME;
#endif
/* Member configuration depends on the bit width of the processor and
on the implementation. A total of 48 bits is recommended. */
 
/* def_cyc */
typedef struct t_dcyc {
VP exinf; /* extended information */
ATR cycatr; /* cyclic handler attributes */
FP cychdr; /* cyclic handler address */
UINT cycact; /* cyclic handler activation */
CYCTIME cyctim; /* cyclic startup period */
} T_DCYC;
 
// cycact:
enum {
TCY_OFF = 0x00, /* do not invoke cyclic handler */
TCY_ON = 0x01, /* invoke cyclic handler */
TCY_INT = 0x02, /* initialize cycle count */
/* Following changed from TCY_INT to TCY_INI to match
description in the body of the standard. I assume TCY_INT
is a hypercorrection/typo; keep both */
TCY_INI = 0x02, /* initialize cycle count */
};
/* ref_cyc */
typedef struct t_rcyc {
VP exinf; /* extended information */
CYCTIME lfttim; /* time left before next handler startup */
UINT cycact; /* cyclic handler activation */
// ...
/* additional information may be included depending on the
implementation */
// ...
} T_RCYC;
 
/* def_alm */
typedef struct t_dalm {
VP exinf; /* extended information */
ATR almatr; /* alarm handler attributes */
FP almhdr; /* alarm handler address */
UINT tmmode; /* start time specification mode */
ALMTIME almtim; /* handler startup time */
} T_DALM;
 
// tmmode:
enum {
TTM_ABS = 0x00, /* specified as an absolute time */
TTM_REL = 0x01, /* specified as a relative time */
};
/* ref_alm */
typedef struct t_ralm {
VP exinf; /* extended information */
ALMTIME lfttim; /* time left before next handler startup */
// ...
/* additional information may be included depending on the
implementation */
// ...
} T_RALM;
 
/* --- for system management functions ----------------------- */
 
/* get_ver */
typedef struct t_ver {
UH maker; /* vendor */
UH id; /* format number */
UH spver; /* specification version */
UH prver; /* product version */
UH prno[4]; /* product control information */
UH cpu; /* CPU information */
UH var; /* variation descriptor */
} T_VER;
 
/* ref_sys */
typedef struct t_rsys {
INT sysstat; /* system state */
// ...
/* additional information may be included depending on the
implementation */
// ...
} T_RSYS;
 
// sysstat:
enum {
TSS_TSK = 0, /* normal state in which dispatching is enabled during
task portion execution */
TSS_DDSP = 1, /* state after dis_dsp has been executed during task
portion execution (dispatch disabled) */
TSS_LOC = 3, /* state after loc_cpu has been executed during task
portion execution (interrupt and dispatch disabled)
*/
TSS_INDP = 4, /* state during execution of task-independent portions
(interrupt and timer handlers) */
};
/* ref_cfg */
typedef struct t_rcfg {
/* details concerning members are implementation dependent */
} T_RCFG;
 
#if 0 // NOT SUPPORTED
/* def_svc */
typedef struct t_dsvc {
ATR svcatr; /* extended SVC handler attributes */
FP svchdr; /* extended SVC handler address */
// ...
/* additional information may be included depending on the
implementation */
// ...
} T_DSVC;
 
/* def_exc */
typedef struct t_dexc {
ATR excatr; /* exception handler attributes */
FP exchdr; /* exception handler address */
// ...
/* additional information may be included depending on the
implementation */
// ...
} T_DEXC;
#endif
 
/* --- for network management functions ----------------------- */
 
#if 0 // NOT SUPPORTED
// NODE srcnode, dstnode, node:
enum {
TND_SELF = 0, /* specifies the local node */
TND_OTHR = (-1) /* specifies default remote node */
};
#endif
/* ------------------------------------------------------ */
 
 
 
#endif // CYGPKG_UITRON
 
#endif // CYGONCE_COMPAT_UITRON_UIT_TYPE_H
// EOF uit_type.h
/uit_func.inl
0,0 → 1,1950
#ifndef CYGONCE_COMPAT_UITRON_UIT_FUNC_INL
#define CYGONCE_COMPAT_UITRON_UIT_FUNC_INL
//===========================================================================
//
// uit_func.inl
//
// uITRON compatibility functions
//
//===========================================================================
//####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-03-13
// Purpose: uITRON compatibility functions
// Description:
//
//####DESCRIPTIONEND####
//
//===========================================================================
 
#ifdef CYGPKG_UITRON
 
#ifdef CYGPRI_UITRON_FUNCS_HERE_AND_NOW
 
#include <cyg/compat/uitron/uit_objs.hxx> // uITRON setup CYGNUM_UITRON_SEMAS
 
// kernel facilities only needed here
#include <cyg/kernel/intr.hxx>
#include <cyg/kernel/sched.hxx>
 
// and the implementations of other kernel facilities
#include <cyg/kernel/thread.inl>
#include <cyg/kernel/sched.inl>
#include <cyg/kernel/clock.inl>
 
 
// ------------------------------------------------------------------------
// The variable where dis_dsp/ena_dsp state is held:
extern cyg_uint32 cyg_uitron_dis_dsp_old_priority;
 
// ------------------------------------------------------------------------
// Parameter checking; either check the expression and return an error code
// if not true, or assert the truth with a made-up message.
 
#ifdef CYGSEM_UITRON_BAD_PARAMS_RETURN_ERRORS
// default: uitron error codes are returned
#define CYG_UIT_PARAMCHECK( _true_, _error_ ) CYG_MACRO_START \
if ( ! (_true_) ) return (_error_); \
CYG_MACRO_END
#else
// ...but they are asserted if asserts are on
#define CYG_UIT_PARAMCHECK( _true_, _error_ ) CYG_MACRO_START \
CYG_ASSERT( (_true_), "CYG_UIT_PARAMCHECK fail: " #_true_ ); \
CYG_MACRO_END
#endif // else !CYGSEM_UITRON_BAD_PARAMS_RETURN_ERRORS
 
// ------------------------------------------------------------------------
// CYG_UITRON_CHECK_AND_GETP
//
// Macro to rangecheck and do the addressing of a static uitron system
// object; _which_ sort of object is given, and token pasting is used
// horribly to get the static array, limits and the like.
//
// Usage:
// INT snd_msg( ID mbxid, ... ) {
// Cyg_Mbox *p;
// CYG_UITRON_CHECK_AND_GETP_MBOXES( mbxid, p );
// p->...(...);
 
// internal: plain assignment to the object pointer, from static array
#define CYG_UIT_SPTR( _which_, _idx_, _ptr_ ) CYG_MACRO_START \
(_ptr_) = CYG_UITRON_OBJS( _which_ ) + ((_idx_) - 1); \
CYG_MACRO_END
 
// internal: plain assignment to the object pointer, from pointer array
// with error checking.
#define CYG_UIT_SPTR_PTR( _which_, _idx_, _ptr_ ) CYG_MACRO_START \
(_ptr_) = CYG_UITRON_PTRS( _which_ )[ ((_idx_) - 1) ]; \
if ( NULL == (_ptr_) ) return E_NOEXS; \
CYG_MACRO_END
 
#define CYG_UITRON_CHECK_AND_GETP_DIRECT( _which_, _idx_, _ptr_ ) \
CYG_MACRO_START \
CYG_UIT_PARAMCHECK( 0 < (_idx_), E_ID ); \
CYG_UIT_PARAMCHECK( CYG_UITRON_NUM( _which_ ) >= (_idx_), E_ID ); \
CYG_UIT_SPTR( _which_, _idx_, _ptr_ ); \
CYG_MACRO_END
 
#define CYG_UITRON_CHECK_AND_GETP_INDIRECT( _which_, _idx_, _ptr_ ) \
CYG_MACRO_START \
CYG_UIT_PARAMCHECK( 0 < (_idx_), E_ID ); \
CYG_UIT_PARAMCHECK( CYG_UITRON_NUM( _which_ ) >= (_idx_), E_ID ); \
CYG_UIT_SPTR_PTR( _which_, _idx_, _ptr_ ); \
CYG_MACRO_END
 
// As above but for handler numbers which return E_PAR when out of range
#define CYG_UITRON_CHECK_AND_GETHDLR( _which_, _num_, _ptr_ ) \
CYG_MACRO_START \
CYG_UIT_PARAMCHECK( 0 < (_num_), E_PAR ); \
CYG_UIT_PARAMCHECK( CYG_UITRON_NUM( _which_ ) >= (_num_), E_PAR ); \
CYG_UIT_SPTR( _which_, _num_, _ptr_ ); \
CYG_MACRO_END
 
// And a macro to check that creation of an object is OK
#define CYG_UITRON_CHECK_NO_OBJ_LOCK_SCHED( _which_, _idx_ ) \
CYG_MACRO_START \
CYG_UIT_PARAMCHECK( 0 < (_idx_), E_ID ); \
CYG_UIT_PARAMCHECK( CYG_UITRON_NUM( _which_ ) >= (_idx_), E_ID ); \
Cyg_Scheduler::lock(); \
if ( NULL != CYG_UITRON_PTRS( _which_ )[ ((_idx_) - 1) ] ) { \
Cyg_Scheduler::unlock(); \
return E_OBJ; \
} \
CYG_MACRO_END
 
// define a magic new operator in order to call constructors
#define CYG_UITRON_NEWFUNCTION( _class_ ) \
inline void *operator new(size_t size, _class_ *ptr) \
{ \
CYG_CHECK_DATA_PTR( ptr, "Bad pointer" ); \
return ptr; \
}
 
// now configury to support selectable create/delete support ie. an
// array of pointers to the objects themselves.
#ifdef CYGPKG_UITRON_TASKS_CREATE_DELETE
#define CYG_UITRON_CHECK_AND_GETP_TASKS( _idx_, _ptr_ ) \
CYG_UITRON_CHECK_AND_GETP_INDIRECT( TASKS, _idx_, _ptr_ )
#else
#define CYG_UITRON_CHECK_AND_GETP_TASKS( _idx_, _ptr_ ) \
CYG_UITRON_CHECK_AND_GETP_DIRECT( TASKS, _idx_, _ptr_ )
#endif
 
#ifdef CYGPKG_UITRON_SEMAS_CREATE_DELETE
#define CYG_UITRON_CHECK_AND_GETP_SEMAS( _idx_, _ptr_ ) \
CYG_UITRON_CHECK_AND_GETP_INDIRECT( SEMAS, _idx_, _ptr_ )
#else
#define CYG_UITRON_CHECK_AND_GETP_SEMAS( _idx_, _ptr_ ) \
CYG_UITRON_CHECK_AND_GETP_DIRECT( SEMAS, _idx_, _ptr_ )
#endif
 
#ifdef CYGPKG_UITRON_MBOXES_CREATE_DELETE
#define CYG_UITRON_CHECK_AND_GETP_MBOXES( _idx_, _ptr_ ) \
CYG_UITRON_CHECK_AND_GETP_INDIRECT( MBOXES, _idx_, _ptr_ )
#else
#define CYG_UITRON_CHECK_AND_GETP_MBOXES( _idx_, _ptr_ ) \
CYG_UITRON_CHECK_AND_GETP_DIRECT( MBOXES, _idx_, _ptr_ )
#endif
 
#ifdef CYGPKG_UITRON_FLAGS_CREATE_DELETE
#define CYG_UITRON_CHECK_AND_GETP_FLAGS( _idx_, _ptr_ ) \
CYG_UITRON_CHECK_AND_GETP_INDIRECT( FLAGS, _idx_, _ptr_ )
#else
#define CYG_UITRON_CHECK_AND_GETP_FLAGS( _idx_, _ptr_ ) \
CYG_UITRON_CHECK_AND_GETP_DIRECT( FLAGS, _idx_, _ptr_ )
#endif
 
#ifdef CYGPKG_UITRON_MEMPOOLFIXED_CREATE_DELETE
#define CYG_UITRON_CHECK_AND_GETP_MEMPOOLFIXED( _idx_, _ptr_ ) \
CYG_UITRON_CHECK_AND_GETP_INDIRECT( MEMPOOLFIXED, _idx_, _ptr_ )
#else
#define CYG_UITRON_CHECK_AND_GETP_MEMPOOLFIXED( _idx_, _ptr_ ) \
CYG_UITRON_CHECK_AND_GETP_DIRECT( MEMPOOLFIXED, _idx_, _ptr_ )
#endif
 
#ifdef CYGPKG_UITRON_MEMPOOLVAR_CREATE_DELETE
#define CYG_UITRON_CHECK_AND_GETP_MEMPOOLVAR( _idx_, _ptr_ ) \
CYG_UITRON_CHECK_AND_GETP_INDIRECT( MEMPOOLVAR, _idx_, _ptr_ )
#else
#define CYG_UITRON_CHECK_AND_GETP_MEMPOOLVAR( _idx_, _ptr_ ) \
CYG_UITRON_CHECK_AND_GETP_DIRECT( MEMPOOLVAR, _idx_, _ptr_ )
#endif
 
// ------------------------------------------------------------------------
// Common error checking macros
 
#if !defined( CYGSEM_UITRON_BAD_PARAMS_RETURN_ERRORS ) && \
!defined( CYGDBG_USE_ASSERTS )
// if not checking and not asserted, these are removed to avoid usused
// variable warnings.
#define CYG_UITRON_CHECK_TASK_CONTEXT_SELF( _self_ ) CYG_EMPTY_STATEMENT
#define CYG_UITRON_CHECK_TASK_CONTEXT() CYG_EMPTY_STATEMENT
#define CYG_UITRON_CHECK_DISPATCH_ENABLED() CYG_EMPTY_STATEMENT
#define CYG_UITRON_CHECK_DISPATCH_ENABLED_TMO( _tmout_ ) CYG_EMPTY_STATEMENT
 
#else
// the default:
// Check a task is actually a uITRON task
#define CYG_UITRON_CHECK_TASK_CONTEXT_SELF( _self_ ) CYG_MACRO_START \
CYG_UIT_PARAMCHECK( \
(&cyg_uitron_TASKS[0] <= (_self_)) && \
((_self_) < &cyg_uitron_TASKS[CYGNUM_UITRON_TASKS]), \
E_CTX ); \
CYG_MACRO_END
 
#define CYG_UITRON_CHECK_TASK_CONTEXT() CYG_MACRO_START \
Cyg_Thread *self = Cyg_Thread::self(); \
CYG_UITRON_CHECK_TASK_CONTEXT_SELF( self ); \
CYG_MACRO_END
 
// Check dispatching is enabled for calls which might wait
#define CYG_UITRON_CHECK_DISPATCH_ENABLED() CYG_MACRO_START \
CYG_UIT_PARAMCHECK( 0 == cyg_uitron_dis_dsp_old_priority, E_CTX ); \
CYG_MACRO_END
 
#define CYG_UITRON_CHECK_DISPATCH_ENABLED_TMO(_tmout_) CYG_MACRO_START \
CYG_UIT_PARAMCHECK( -1 <= (_tmout_), E_PAR ); \
if ( TMO_POL != (_tmout_) ) \
CYG_UITRON_CHECK_DISPATCH_ENABLED(); \
CYG_MACRO_END
 
#endif
 
#ifdef CYGSEM_UITRON_PARAMS_NULL_IS_GOOD_PTR
#define CYG_UIT_PARAMCHECK_PTR( _p_ ) CYG_MACRO_START \
CYG_UIT_PARAMCHECK( NADR != (_p_), E_PAR ); \
CYG_MACRO_END
#else // do check for NULL
#define CYG_UIT_PARAMCHECK_PTR( _p_ ) CYG_MACRO_START \
CYG_UIT_PARAMCHECK( NADR != (_p_), E_PAR ); \
CYG_UIT_PARAMCHECK( NULL != (_p_), E_PAR ); \
CYG_MACRO_END
#endif // !CYGSEM_UITRON_PARAMS_NULL_IS_GOOD_PTR
 
// ------------------------------------------------------------------------
// CYG_UITRON_FAIL_RETURN
//
// After a call which waits, it might return with success, or due to a
// timeout or a release wait (a forced escape from the waiting condition).
// This macro examines context and finds out which, then executes a return
// with the correct uITRON condition code.
 
#define CYG_UITRON_FAIL_RETURN_SELF( _self_ ) CYG_MACRO_START \
Cyg_Thread::cyg_reason reason = (_self_)->get_wake_reason(); \
if ( Cyg_Thread::TIMEOUT == reason ) \
return E_TMOUT; \
if ( Cyg_Thread::BREAK == reason ) \
return E_RLWAI; \
if ( Cyg_Thread::DESTRUCT == reason ) \
return E_DLT; \
return E_SYS; /* if no plausible reason was found */ \
CYG_MACRO_END
 
#define CYG_UITRON_FAIL_RETURN() CYG_MACRO_START \
Cyg_Thread *self = Cyg_Thread::self(); \
CYG_UITRON_FAIL_RETURN_SELF( self ); \
CYG_MACRO_END
 
// ------------------------------------------------------------------------
// Interrupts disabled?
#define CYG_UITRON_CHECK_CPU_UNLOC() \
CYG_UIT_PARAMCHECK( (Cyg_Interrupt::interrupts_enabled()), E_CTX )
 
// ------------------------------------------------------------------------
// Timing: is it in eCos clock ticks or milliSeconds (or something else?)
 
#ifdef CYGVAR_KERNEL_COUNTERS_CLOCK
 
#ifdef CYGSEM_UITRON_TIME_IS_MILLISECONDS
extern Cyg_Clock::converter uit_clock_to_system;
extern Cyg_Clock::converter uit_clock_from_system;
 
#define CYG_UITRON_TIME_UIT_TO_SYS32( t ) \
Cyg_Clock::convert( (cyg_uint64)(t), &uit_clock_to_system )
 
#define CYG_UITRON_TIME_SYS_TO_UIT32( t ) \
Cyg_Clock::convert( (cyg_uint64)(t), &uit_clock_from_system )
 
// long (cyg_uint64) versions:
#define CYG_UITRON_TIME_UIT_TO_SYS64( t ) \
Cyg_Clock::convert( (t), &uit_clock_to_system )
 
#define CYG_UITRON_TIME_SYS_TO_UIT64( t ) \
Cyg_Clock::convert( (t), &uit_clock_from_system )
 
#else // Time is whatever the system clock is doing:
 
// Straight through - int (cyg_int32) argument versions:
#define CYG_UITRON_TIME_UIT_TO_SYS32( t ) ( t )
#define CYG_UITRON_TIME_SYS_TO_UIT32( t ) ( t )
// long (cyg_uint64) versions:
#define CYG_UITRON_TIME_UIT_TO_SYS64( t ) ( t )
#define CYG_UITRON_TIME_SYS_TO_UIT64( t ) ( t )
#endif
 
#endif // CYGVAR_KERNEL_COUNTERS_CLOCK - otherwise these should not be used.
 
// ------------------------------------------------------------------------
// the function definitions themselves:
 
// ******************************************************
// *** 6.5 C Language Interfaces ***
// ******************************************************
 
// - Task Management Functions
 
#ifdef CYGPKG_UITRON_TASKS_CREATE_DELETE
CYG_UITRON_NEWFUNCTION( Cyg_Thread )
 
CYG_UIT_FUNC_INLINE
ER
cre_tsk ( ID tskid, T_CTSK *pk_ctsk )
{
ER ret = E_OK;
CYG_UIT_PARAMCHECK_PTR( pk_ctsk );
CYG_UITRON_CHECK_NO_OBJ_LOCK_SCHED( TASKS, tskid );
 
Cyg_Thread *p = &(CYG_UITRON_OBJS( TASKS )[ tskid - 1 ]);
cyg_uint32 state = p->get_state();
if ( 0 == (state & Cyg_Thread::EXITED) )
ret = E_OBJ; // how did it get to be running?
else if ( ((INT)p->get_stack_size()) < pk_ctsk->stksz )
ret = E_NOMEM; // more stack requested than available
else {
CYG_UITRON_PTRS( TASKS )[ tskid - 1 ] =
new( p ) Cyg_Thread(
(CYG_ADDRWORD) pk_ctsk->itskpri,
(cyg_thread_entry *)pk_ctsk->task,
(CYG_ADDRWORD) 0,
// preserve the original name and stack:
#ifdef CYGVAR_KERNEL_THREADS_NAME
p->get_name(),
#else
NULL,
#endif
p->get_stack_base(),
p->get_stack_size() );
// but ensure the task state is dormant:
// (it is not constructed dormant, but suspended)
p->kill();
#ifdef CYGIMP_THREAD_PRIORITY
// and record the initial priority outside the task too.
CYG_UITRON_TASK_INITIAL_PRIORITY( tskid ) = pk_ctsk->itskpri;
#endif
}
Cyg_Scheduler::unlock();
return ret;
}
 
CYG_UIT_FUNC_INLINE
ER
del_tsk ( ID tskid )
{
Cyg_Thread *p;
ER ret = E_OK;
CYG_UITRON_CHECK_AND_GETP_TASKS( tskid, p );
Cyg_Scheduler::lock();
// deal with the race condition here
if ( p != CYG_UITRON_PTRS( TASKS )[ tskid - 1 ] ) {
Cyg_Scheduler::unlock();
return E_NOEXS;
}
cyg_uint32 state = p->get_state();
if ( state & Cyg_Thread::EXITED )
// just disconnect the pointer from its object
CYG_UITRON_PTRS( TASKS )[ tskid - 1 ] = NULL;
else
ret = E_OBJ;
Cyg_Scheduler::unlock();
return ret;
}
#endif // CYGPKG_UITRON_TASKS_CREATE_DELETE
 
CYG_UIT_FUNC_INLINE
ER
sta_tsk ( ID tskid, INT stacd )
{
Cyg_Thread *p;
ER ret = E_OK;
CYG_UITRON_CHECK_AND_GETP_TASKS( tskid, p );
Cyg_Scheduler::lock();
cyg_uint32 state = p->get_state();
#ifdef CYGPKG_UITRON_TASKS_CREATE_DELETE
// there is a race condition with deleting the task
// so test it now that we have the scheduler locked
if ( p != CYG_UITRON_PTRS( TASKS )[ tskid - 1 ] )
ret = E_NOEXS;
else // NOTE dangling else to the next line:
#endif
if ( state & Cyg_Thread::EXITED ) {
p->reinitialize();
#ifdef CYGIMP_THREAD_PRIORITY
p->set_priority( CYG_UITRON_TASK_INITIAL_PRIORITY( tskid ) );
#endif
p->set_entry_data( (CYG_ADDRWORD)stacd );
p->force_resume();
}
else
ret = E_OBJ;
Cyg_Scheduler::unlock();
return ret;
}
 
CYG_UIT_FUNC_INLINE
void
ext_tsk ( void )
{
Cyg_Thread::exit();
}
 
CYG_UIT_FUNC_INLINE
void
exd_tsk ( void )
{
#ifdef CYGPKG_UITRON_TASKS_CREATE_DELETE
Cyg_Thread *p;
 
Cyg_Scheduler::lock();
p = Cyg_Thread::self();
ID tskid = (p - (&cyg_uitron_TASKS[0])) + 1;
// just disconnect the pointer from its object
CYG_UITRON_PTRS( TASKS )[ tskid - 1 ] = NULL;
// Any associated storage management, and possibly calling the task
// destructor, is for future versions.
#else
// do nothing - deletion not supported so just exit...
#endif
Cyg_Thread::exit();
// does not return, does unlock the scheduler for us
}
 
CYG_UIT_FUNC_INLINE
ER
ter_tsk ( ID tskid )
{
Cyg_Thread *p;
ER ret = E_OK;
CYG_UITRON_CHECK_AND_GETP_TASKS( tskid, p );
CYG_UIT_PARAMCHECK( Cyg_Thread::self() != p, E_OBJ );
Cyg_Scheduler::lock();
if ( (0 != (Cyg_Thread::EXITED & p->get_state())) ||
(Cyg_Thread::EXIT == p->get_wake_reason()) )
// already dormant
ret = E_OBJ;
else {
p->force_resume(); // let it run
p->kill(); // and set prio high so it runs RIGHT NOW!!
#ifdef CYGIMP_THREAD_PRIORITY
#if CYGINT_KERNEL_SCHEDULER_UNIQUE_PRIORITIES != 0
// see if we are already at prio 0:
if ( 0 == cyg_uitron_dis_dsp_old_priority )
// then dispatch is enabled, we are not at prio 0
#endif
p->set_priority( (cyg_priority) 0 );
// if we do not do this, then we are not running a strictly
// uITRON compatible scheduler - so just hope for the best.
#endif
}
Cyg_Scheduler::unlock();
#ifdef CYGIMP_THREAD_PRIORITY
#if CYGINT_KERNEL_SCHEDULER_UNIQUE_PRIORITIES == 0
if ( (E_OK == ret) && (0 != cyg_uitron_dis_dsp_old_priority) ) {
// then dispatching is disabled, so our prio is 0 too
Cyg_Thread::yield(); // so let the dying thread run;
Cyg_Thread::yield(); // no cost here of making sure.
}
#endif
#endif
return ret;
}
 
CYG_UIT_FUNC_INLINE
ER
dis_dsp ( void )
{
CYG_UITRON_CHECK_TASK_CONTEXT();
CYG_UITRON_CHECK_CPU_UNLOC();
Cyg_Scheduler::lock();
// Prevent preemption by going up to prio 0
if ( 0 == cyg_uitron_dis_dsp_old_priority ) {
#ifdef CYGIMP_THREAD_PRIORITY
Cyg_Thread *p = Cyg_Thread::self();
cyg_uitron_dis_dsp_old_priority = p->get_priority();
p->set_priority( 0 );
#else
cyg_uitron_dis_dsp_old_priority = 1;
#endif
}
Cyg_Scheduler::unlock();
return E_OK;
}
 
CYG_UIT_FUNC_INLINE
ER
ena_dsp ( void )
{
CYG_UITRON_CHECK_TASK_CONTEXT();
CYG_UITRON_CHECK_CPU_UNLOC();
Cyg_Scheduler::lock();
// Enable dispatching (if disabled) and maybe switch threads
if ( 0 != cyg_uitron_dis_dsp_old_priority ) {
// We had prevented preemption by going up to prio 0
#ifdef CYGIMP_THREAD_PRIORITY
Cyg_Thread *p = Cyg_Thread::self();
p->set_priority( cyg_uitron_dis_dsp_old_priority );
p->to_queue_head(); // to ensure we continue to run
// if nobody higher pri
#endif
cyg_uitron_dis_dsp_old_priority = 0;
}
Cyg_Scheduler::unlock();
CYG_UITRON_CHECK_DISPATCH_ENABLED(); // NB: afterwards!
return E_OK;
}
 
 
CYG_UIT_FUNC_INLINE
ER
chg_pri ( ID tskid, PRI tskpri )
{
Cyg_Thread *p;
ER ret = E_OK;
if ( 0 == tskid ) {
p = Cyg_Thread::self();
CYG_UITRON_CHECK_TASK_CONTEXT_SELF( p );
}
else
CYG_UITRON_CHECK_AND_GETP_TASKS( tskid, p );
 
#ifdef CYGIMP_THREAD_PRIORITY
if ( 0 == tskpri )
// then use the initial priority [Level X]
tskpri = CYG_UITRON_TASK_INITIAL_PRIORITY( tskid );
#endif
CYG_UIT_PARAMCHECK( 0 < tskpri, E_PAR );
#ifdef CYGIMP_THREAD_PRIORITY
#if CYG_THREAD_MAX_PRIORITY < CYG_THREAD_MIN_PRIORITY
CYG_UIT_PARAMCHECK( CYG_THREAD_MAX_PRIORITY <= tskpri &&
tskpri <= CYG_THREAD_MIN_PRIORITY, E_PAR );
#else
CYG_UIT_PARAMCHECK( CYG_THREAD_MAX_PRIORITY >= tskpri &&
tskpri >= CYG_THREAD_MIN_PRIORITY, E_PAR );
#endif
// Handle changing our own prio specially, if dispatch disabled:
if ( 0 != cyg_uitron_dis_dsp_old_priority ) {
// our actual prio is 0 now and must remain so:
if ( Cyg_Thread::self() == p ) { // by whichever route p was set
// set the priority we will return to when dispatch is enabled:
cyg_uitron_dis_dsp_old_priority = (cyg_uint32)tskpri;
return E_OK;
}
}
Cyg_Scheduler::lock();
if ( (p->get_state() & (Cyg_Thread::EXITED | Cyg_Thread::CREATING)) ||
(Cyg_Thread::EXIT == p->get_wake_reason()) )
ret = E_OBJ; // task is dormant
else
p->set_priority( (cyg_priority)tskpri );
Cyg_Scheduler::unlock();
#endif // CYGIMP_THREAD_PRIORITY got priorities at all?
return ret;
}
 
CYG_UIT_FUNC_INLINE
ER
rot_rdq ( PRI tskpri )
{
// zero means our level; easiet way is to yield() the CPU.
if ( 0 == tskpri ) {
Cyg_Thread::yield();
return E_OK;
}
#ifdef CYGIMP_THREAD_PRIORITY
#if CYG_THREAD_MAX_PRIORITY < CYG_THREAD_MIN_PRIORITY
CYG_UIT_PARAMCHECK( CYG_THREAD_MAX_PRIORITY <= tskpri &&
tskpri <= CYG_THREAD_MIN_PRIORITY, E_PAR );
#else
CYG_UIT_PARAMCHECK( CYG_THREAD_MAX_PRIORITY >= tskpri &&
tskpri >= CYG_THREAD_MIN_PRIORITY, E_PAR );
#endif
Cyg_Thread::rotate_queue( tskpri );
#endif // CYGIMP_THREAD_PRIORITY got priorities at all?
return E_OK;
}
 
CYG_UIT_FUNC_INLINE
ER
rel_wai ( ID tskid )
{
Cyg_Thread *p;
ER ret = E_OK;
CYG_UITRON_CHECK_AND_GETP_TASKS( tskid, p );
CYG_UIT_PARAMCHECK( Cyg_Thread::self() != p, E_OBJ );
Cyg_Scheduler::lock(); // get an atomic view of the task
if ( (p->get_state() & (Cyg_Thread::EXITED | Cyg_Thread::CREATING)) ||
(Cyg_Thread::EXIT == p->get_wake_reason()) )
ret = E_OBJ; // task is dormant
else {
p->release();
// return E_OBJ if the thread was not sleeping
if ( Cyg_Thread::BREAK != p->get_wake_reason() )
ret = E_OBJ;
}
Cyg_Scheduler::unlock();
return ret;
}
 
CYG_UIT_FUNC_INLINE
ER
get_tid ( ID *p_tskid )
{
Cyg_Thread *self = Cyg_Thread::self();
CYG_UIT_PARAMCHECK_PTR( p_tskid );
if ( (&cyg_uitron_TASKS[0] <= (self)) &&
((self) < &cyg_uitron_TASKS[CYGNUM_UITRON_TASKS]) &&
(0 == Cyg_Scheduler::get_sched_lock()) )
// then I am a uITRON task and not in an interrupt or DSR
*p_tskid = (self - (&cyg_uitron_TASKS[0])) + 1;
else
*p_tskid = 0; // Otherwise, non-task portion
return E_OK;
}
 
CYG_UIT_FUNC_INLINE
ER
ref_tsk ( T_RTSK *pk_rtsk, ID tskid )
{
Cyg_Thread *p;
if ( 0 == tskid ) {
p = Cyg_Thread::self();
CYG_UITRON_CHECK_TASK_CONTEXT_SELF( p );
tskid = (p - (&cyg_uitron_TASKS[0])) + 1; // it gets used below
}
else
CYG_UITRON_CHECK_AND_GETP_TASKS( tskid, p );
 
CYG_UIT_PARAMCHECK_PTR( pk_rtsk );
pk_rtsk->exinf = NADR;
Cyg_Scheduler::lock(); // get an atomic view of the task
cyg_uint32 state = p->get_state();
if ( (state & (Cyg_Thread::EXITED | Cyg_Thread::CREATING)) ||
(Cyg_Thread::EXIT == p->get_wake_reason()) )
pk_rtsk->tskstat = TTS_DMT;
else if ( state == Cyg_Thread::RUNNING )
// If it's us, it's running, else it's ready
pk_rtsk->tskstat = (Cyg_Thread::self() == p)
? TTS_RUN // RUN state (we are it)
: TTS_RDY; // READY state
else if ( state & Cyg_Thread::SUSPENDED )
pk_rtsk->tskstat =
(state & (Cyg_Thread::COUNTSLEEP | Cyg_Thread::SLEEPING))
? TTS_WAS // WAIT-SUSPEND state
: TTS_SUS; // SUSPEND state
else
pk_rtsk->tskstat =
(state & (Cyg_Thread::COUNTSLEEP | Cyg_Thread::SLEEPING))
? TTS_WAI // WAIT state
: 0; // Not sure what's happening here!
#ifdef CYGIMP_THREAD_PRIORITY
if ( TTS_DMT == pk_rtsk->tskstat )
pk_rtsk->tskpri = CYG_UITRON_TASK_INITIAL_PRIORITY( tskid );
else if ( (TTS_RUN == pk_rtsk->tskstat) &&
(0 != cyg_uitron_dis_dsp_old_priority) )
// then we are it and dispatching is disabled, so
// report our "real" priority - it is 0 in the kernel at the moment
pk_rtsk->tskpri = cyg_uitron_dis_dsp_old_priority;
else
pk_rtsk->tskpri = p->get_priority();
#else
pk_rtsk->tskpri = -1; // Not applicable
#endif
Cyg_Scheduler::unlock();
return E_OK;
}
// - Task-Dependent Synchronization Functions
CYG_UIT_FUNC_INLINE
ER
sus_tsk ( ID tskid )
{
Cyg_Thread *p;
ER ret = E_OK;
CYG_UITRON_CHECK_AND_GETP_TASKS( tskid, p );
CYG_UIT_PARAMCHECK( Cyg_Thread::self() != p, E_OBJ );
Cyg_Scheduler::lock(); // get an atomic view of the task
if ( (p->get_state() & (Cyg_Thread::EXITED | Cyg_Thread::CREATING)) ||
(Cyg_Thread::EXIT == p->get_wake_reason()) )
ret = E_OBJ; // task is dormant
else
p->suspend();
Cyg_Scheduler::unlock();
return ret;
}
 
CYG_UIT_FUNC_INLINE
ER
rsm_tsk ( ID tskid )
{
Cyg_Thread *p;
ER ret = E_OK;
CYG_UITRON_CHECK_AND_GETP_TASKS( tskid, p );
CYG_UIT_PARAMCHECK( Cyg_Thread::self() != p, E_OBJ );
Cyg_Scheduler::lock(); // get an atomic view of the task
cyg_uint32 state = p->get_state();
if ( 0 == (Cyg_Thread::SUSPENDED & state) )
ret = E_OBJ; // thread is not suspended
else
p->resume();
Cyg_Scheduler::unlock();
return ret;
}
 
CYG_UIT_FUNC_INLINE
ER
frsm_tsk ( ID tskid )
{
Cyg_Thread *p;
ER ret = E_OK;
CYG_UITRON_CHECK_AND_GETP_TASKS( tskid, p );
CYG_UIT_PARAMCHECK( Cyg_Thread::self() != p, E_OBJ );
Cyg_Scheduler::lock(); // get an atomic view of the task
cyg_uint32 state = p->get_state();
if ( 0 == (Cyg_Thread::SUSPENDED & state) )
ret = E_OBJ; // thread is not suspended
else
p->force_resume();
Cyg_Scheduler::unlock();
return ret;
}
 
CYG_UIT_FUNC_INLINE
ER
slp_tsk ( void )
{
Cyg_Thread *self = Cyg_Thread::self();
CYG_UITRON_CHECK_TASK_CONTEXT_SELF( self );
CYG_UITRON_CHECK_DISPATCH_ENABLED();
// do this now for the case when no sleeping actually occurs
self->set_wake_reason( Cyg_Thread::DONE );
Cyg_Thread::counted_sleep();
if ( Cyg_Thread::DONE != self->get_wake_reason() )
CYG_UITRON_FAIL_RETURN_SELF( self );
return E_OK;
}
 
#ifdef CYGFUN_KERNEL_THREADS_TIMER
CYG_UIT_FUNC_INLINE
ER
tslp_tsk ( TMO tmout )
{
Cyg_Thread *self = Cyg_Thread::self();
CYG_UITRON_CHECK_TASK_CONTEXT_SELF( self );
CYG_UIT_PARAMCHECK( -1 <= tmout, E_PAR );
CYG_UITRON_CHECK_DISPATCH_ENABLED();
// do this now for the case when no sleeping actually occurs
self->set_wake_reason( Cyg_Thread::DONE );
// note that TMO_POL is not treated specially, though it
// happens to work almost as a poll (some sleeping may occur)
if ( TMO_FEVR == tmout )
Cyg_Thread::counted_sleep();
else
Cyg_Thread::counted_sleep(
(cyg_tick_count)CYG_UITRON_TIME_UIT_TO_SYS32( tmout ) );
if ( Cyg_Thread::DONE != self->get_wake_reason() )
CYG_UITRON_FAIL_RETURN_SELF( self );
return E_OK;
}
#endif // CYGFUN_KERNEL_THREADS_TIMER
 
CYG_UIT_FUNC_INLINE
ER
wup_tsk ( ID tskid )
{
Cyg_Thread *p;
ER ret = E_OK;
CYG_UITRON_CHECK_AND_GETP_TASKS( tskid, p );
CYG_UIT_PARAMCHECK( Cyg_Thread::self() != p, E_OBJ );
Cyg_Scheduler::lock(); // get an atomic view of the task
if ( (p->get_state() & (Cyg_Thread::EXITED | Cyg_Thread::CREATING)) ||
(Cyg_Thread::EXIT == p->get_wake_reason()) )
ret = E_OBJ; // task is dormant
else
p->counted_wake();
Cyg_Scheduler::unlock();
return ret;
}
 
CYG_UIT_FUNC_INLINE
ER
can_wup ( INT *p_wupcnt, ID tskid )
{
Cyg_Thread *p;
ER ret = E_OK;
if ( 0 == tskid ) {
p = Cyg_Thread::self();
CYG_UITRON_CHECK_TASK_CONTEXT_SELF( p );
}
else
CYG_UITRON_CHECK_AND_GETP_TASKS( tskid, p );
CYG_UIT_PARAMCHECK_PTR( p_wupcnt );
Cyg_Scheduler::lock(); // get an atomic view of the task
if ( (p->get_state() & (Cyg_Thread::EXITED | Cyg_Thread::CREATING)) ||
(Cyg_Thread::EXIT == p->get_wake_reason()) )
ret = E_OBJ; // task is dormant
else {
cyg_uint32 result = p->cancel_counted_wake();
*p_wupcnt = result;
}
Cyg_Scheduler::unlock();
return ret;
}
// - Synchronization and Communication Functions
#ifdef CYGPKG_UITRON_SEMAS
#if 0 < CYG_UITRON_NUM( SEMAS )
 
#ifdef CYGPKG_UITRON_SEMAS_CREATE_DELETE
 
CYG_UITRON_NEWFUNCTION( Cyg_Counting_Semaphore2 )
 
CYG_UIT_FUNC_INLINE
ER
cre_sem ( ID semid, T_CSEM *pk_csem )
{
ER ret = E_OK;
CYG_UIT_PARAMCHECK_PTR( pk_csem );
CYG_UITRON_CHECK_NO_OBJ_LOCK_SCHED( SEMAS, semid );
if ( TA_TFIFO != pk_csem->sematr )
ret = E_RSATR;
else
CYG_UITRON_PTRS( SEMAS )[ semid - 1 ] =
new( &(CYG_UITRON_OBJS( SEMAS )[ semid - 1 ]) )
Cyg_Counting_Semaphore2( (cyg_count32)pk_csem->isemcnt );
Cyg_Scheduler::unlock();
return ret;
}
 
CYG_UIT_FUNC_INLINE
ER
del_sem ( ID semid )
{
Cyg_Counting_Semaphore2 *p;
CYG_UITRON_CHECK_AND_GETP_SEMAS( semid, p );
Cyg_Scheduler::lock();
// deal with the race condition here
if ( p != CYG_UITRON_PTRS( SEMAS )[ semid - 1 ] ) {
Cyg_Scheduler::unlock();
return E_NOEXS;
}
CYG_UITRON_PTRS( SEMAS )[ semid - 1 ] = NULL;
p->~Cyg_Counting_Semaphore2();
Cyg_Scheduler::unlock();
return E_OK;
}
#endif // CYGPKG_UITRON_SEMAS_CREATE_DELETE
 
CYG_UIT_FUNC_INLINE
ER
sig_sem( ID semid )
{
Cyg_Counting_Semaphore2 *p;
CYG_UITRON_CHECK_AND_GETP_SEMAS( semid, p );
p->post();
return E_OK;
}
 
CYG_UIT_FUNC_INLINE
ER
wai_sem( ID semid )
{
Cyg_Counting_Semaphore2 *p;
CYG_UITRON_CHECK_AND_GETP_SEMAS( semid, p );
CYG_UITRON_CHECK_DISPATCH_ENABLED();
cyg_bool result = p->wait();
if ( !result )
CYG_UITRON_FAIL_RETURN();
return E_OK;
}
 
CYG_UIT_FUNC_INLINE
ER
preq_sem ( ID semid )
{
Cyg_Counting_Semaphore2 *p;
CYG_UITRON_CHECK_AND_GETP_SEMAS( semid, p );
cyg_bool result = p->trywait();
if ( !result )
return E_TMOUT;
return E_OK;
}
 
#ifdef CYGFUN_KERNEL_THREADS_TIMER
CYG_UIT_FUNC_INLINE
ER
twai_sem ( ID semid, TMO tmout )
{
Cyg_Counting_Semaphore2 *p;
CYG_UITRON_CHECK_AND_GETP_SEMAS( semid, p );
CYG_UITRON_CHECK_DISPATCH_ENABLED_TMO( tmout );
// do this now for the case when no sleeping actually occurs
Cyg_Thread *self = Cyg_Thread::self();
self->set_wake_reason( Cyg_Thread::TIMEOUT );
cyg_bool result;
if ( TMO_FEVR == tmout )
result = p->wait();
else if ( TMO_POL == tmout )
result = p->trywait();
else
result = p->wait(
Cyg_Clock::real_time_clock->current_value() +
(cyg_tick_count)CYG_UITRON_TIME_UIT_TO_SYS32( tmout ) );
if ( ! result )
CYG_UITRON_FAIL_RETURN_SELF( self );
return E_OK;
 
}
#endif // CYGFUN_KERNEL_THREADS_TIMER
 
CYG_UIT_FUNC_INLINE
ER
ref_sem ( T_RSEM *pk_rsem, ID semid )
{
Cyg_Counting_Semaphore2 *p;
CYG_UITRON_CHECK_AND_GETP_SEMAS( semid, p );
CYG_UIT_PARAMCHECK_PTR( pk_rsem );
pk_rsem->exinf = NADR;
pk_rsem->wtsk = p->waiting();
pk_rsem->semcnt = p->peek();
return E_OK;
}
 
#endif // 0 < CYG_UITRON_NUM( SEMAS )
#endif // CYGPKG_UITRON_SEMAS
 
#ifdef CYGPKG_UITRON_FLAGS
#if 0 < CYG_UITRON_NUM( FLAGS )
 
#ifdef CYGPKG_UITRON_FLAGS_CREATE_DELETE
 
CYG_UITRON_NEWFUNCTION( Cyg_Flag )
 
CYG_UIT_FUNC_INLINE
ER
cre_flg ( ID flgid, T_CFLG *pk_cflg )
{
ER ret = E_OK;
CYG_UIT_PARAMCHECK_PTR( pk_cflg );
CYG_UITRON_CHECK_NO_OBJ_LOCK_SCHED( FLAGS, flgid );
if ( 0 != ((~(TA_WMUL | TA_WSGL)) & pk_cflg->flgatr) )
ret = E_RSATR;
else
CYG_UITRON_PTRS( FLAGS )[ flgid - 1 ] =
new( &(CYG_UITRON_OBJS( FLAGS )[ flgid - 1 ]) )
Cyg_Flag( (Cyg_FlagValue) pk_cflg->iflgptn );
Cyg_Scheduler::unlock();
return ret;
}
 
CYG_UIT_FUNC_INLINE
ER
del_flg ( ID flgid )
{
Cyg_Flag *p;
CYG_UITRON_CHECK_AND_GETP_FLAGS( flgid, p );
Cyg_Scheduler::lock();
// deal with the race condition here
if ( p != CYG_UITRON_PTRS( FLAGS )[ flgid - 1 ] ) {
Cyg_Scheduler::unlock();
return E_NOEXS;
}
CYG_UITRON_PTRS( FLAGS )[ flgid - 1 ] = NULL;
p->~Cyg_Flag();
Cyg_Scheduler::unlock();
return E_OK;
}
#endif // CYGPKG_UITRON_FLAGS_CREATE_DELETE
 
CYG_UIT_FUNC_INLINE
ER
set_flg ( ID flgid, UINT setptn )
{
Cyg_Flag *p;
CYG_UITRON_CHECK_AND_GETP_FLAGS( flgid, p );
p->setbits( setptn );
return E_OK;
}
 
CYG_UIT_FUNC_INLINE
ER
clr_flg ( ID flgid, UINT clrptn )
{
Cyg_Flag *p;
CYG_UITRON_CHECK_AND_GETP_FLAGS( flgid, p );
p->maskbits( clrptn );
return E_OK;
}
 
CYG_UIT_FUNC_INLINE
ER
wai_flg ( UINT *p_flgptn, ID flgid, UINT waiptn, UINT wfmode )
{
Cyg_Flag *p;
CYG_UITRON_CHECK_AND_GETP_FLAGS( flgid, p );
CYG_UIT_PARAMCHECK_PTR( p_flgptn );
CYG_UIT_PARAMCHECK( 0 == (wfmode & ~Cyg_Flag::MASK), E_PAR );
CYG_UIT_PARAMCHECK( 0 != waiptn, E_PAR );
CYG_UITRON_CHECK_DISPATCH_ENABLED();
// check we can use the wfmode value unchanged
CYG_ASSERT( Cyg_Flag::AND == TWF_ANDW, "Flag AND value bad" );
CYG_ASSERT( Cyg_Flag::OR == TWF_ORW, "Flag OR value bad" );
CYG_ASSERT( Cyg_Flag::CLR == TWF_CLR, "Flag CLR value bad" );
 
UINT result = p->wait( waiptn, wfmode );
if ( ! result )
CYG_UITRON_FAIL_RETURN();
*p_flgptn = result;
return E_OK;
}
 
CYG_UIT_FUNC_INLINE
ER
pol_flg ( UINT *p_flgptn, ID flgid, UINT waiptn, UINT wfmode )
{
Cyg_Flag *p;
CYG_UITRON_CHECK_AND_GETP_FLAGS( flgid, p );
CYG_UIT_PARAMCHECK_PTR( p_flgptn );
CYG_UIT_PARAMCHECK( 0 == (wfmode & ~Cyg_Flag::MASK), E_PAR );
CYG_UIT_PARAMCHECK( 0 != waiptn, E_PAR );
// check we can use the wfmode value unchanged
CYG_ASSERT( Cyg_Flag::AND == TWF_ANDW, "Flag AND value bad" );
CYG_ASSERT( Cyg_Flag::OR == TWF_ORW, "Flag OR value bad" );
CYG_ASSERT( Cyg_Flag::CLR == TWF_CLR, "Flag CLR value bad" );
 
UINT result = p->poll( waiptn, wfmode );
if ( ! result )
return E_TMOUT;
*p_flgptn = result;
return E_OK;
}
 
#ifdef CYGFUN_KERNEL_THREADS_TIMER
CYG_UIT_FUNC_INLINE
ER
twai_flg ( UINT *p_flgptn, ID flgid, UINT waiptn, UINT wfmode,
TMO tmout )
{
Cyg_Flag *p;
CYG_UITRON_CHECK_AND_GETP_FLAGS( flgid, p );
CYG_UIT_PARAMCHECK_PTR( p_flgptn );
CYG_UIT_PARAMCHECK( 0 == (wfmode & ~Cyg_Flag::MASK), E_PAR );
CYG_UIT_PARAMCHECK( 0 != waiptn, E_PAR );
CYG_UITRON_CHECK_DISPATCH_ENABLED_TMO( tmout );
// check we can use the wfmode value unchanged
CYG_ASSERT( Cyg_Flag::AND == TWF_ANDW, "Flag AND value bad" );
CYG_ASSERT( Cyg_Flag::OR == TWF_ORW, "Flag OR value bad" );
CYG_ASSERT( Cyg_Flag::CLR == TWF_CLR, "Flag CLR value bad" );
 
// do this now for the case when no sleeping actually occurs
Cyg_Thread *self = Cyg_Thread::self();
self->set_wake_reason( Cyg_Thread::TIMEOUT );
UINT result;
if ( TMO_FEVR == tmout )
result = p->wait( waiptn, wfmode );
else if ( TMO_POL == tmout )
result = p->poll( waiptn, wfmode );
else
result = p->wait( waiptn, wfmode,
Cyg_Clock::real_time_clock->current_value() +
(cyg_tick_count)CYG_UITRON_TIME_UIT_TO_SYS32( tmout ) );
if ( ! result )
CYG_UITRON_FAIL_RETURN_SELF( self );
*p_flgptn = result;
return E_OK;
}
#endif // CYGFUN_KERNEL_THREADS_TIMER
 
CYG_UIT_FUNC_INLINE
ER
ref_flg ( T_RFLG *pk_rflg, ID flgid )
{
Cyg_Flag *p;
CYG_UITRON_CHECK_AND_GETP_FLAGS( flgid, p );
CYG_UIT_PARAMCHECK_PTR( pk_rflg );
pk_rflg->exinf = NADR;
pk_rflg->wtsk = p->waiting();
pk_rflg->flgptn = p->peek();
return E_OK;
}
 
#endif // 0 < CYG_UITRON_NUM( FLAGS )
#endif // CYGPKG_UITRON_FLAGS
 
#ifdef CYGPKG_UITRON_MBOXES
#if 0 < CYG_UITRON_NUM( MBOXES )
 
#ifdef CYGPKG_UITRON_MBOXES_CREATE_DELETE
CYG_UITRON_NEWFUNCTION( Cyg_Mbox )
 
CYG_UIT_FUNC_INLINE
ER
cre_mbx ( ID mbxid, T_CMBX* pk_cmbx )
{
ER ret = E_OK;
CYG_UIT_PARAMCHECK_PTR( pk_cmbx );
CYG_UITRON_CHECK_NO_OBJ_LOCK_SCHED( MBOXES, mbxid );
if ( ((ATR)(TA_TFIFO + TA_MFIFO)) != pk_cmbx->mbxatr )
ret = E_RSATR;
else
CYG_UITRON_PTRS( MBOXES )[ mbxid - 1 ] =
new( &(CYG_UITRON_OBJS( MBOXES )[ mbxid - 1 ]) )
Cyg_Mbox();
Cyg_Scheduler::unlock();
return ret;
}
 
CYG_UIT_FUNC_INLINE
ER
del_mbx ( ID mbxid )
{
Cyg_Mbox *p;
CYG_UITRON_CHECK_AND_GETP_MBOXES( mbxid, p );
Cyg_Scheduler::lock();
// deal with the race condition here
if ( p != CYG_UITRON_PTRS( MBOXES )[ mbxid - 1 ] ) {
Cyg_Scheduler::unlock();
return E_NOEXS;
}
CYG_UITRON_PTRS( MBOXES )[ mbxid - 1 ] = NULL;
p->~Cyg_Mbox();
Cyg_Scheduler::unlock();
return E_OK;
}
#endif // CYGPKG_UITRON_MBOXES_CREATE_DELETE
 
// This bit of unpleasantness is to allow uITRON programs to send a NULL
// message - if permitted by the parameter checking.
//
// NULL is used internally to mean no message; but -1 is fine. So we send
// a NULL as a NADR and if we see a NULL coming back, change it to a NADR.
//
// One hopes that often this will be optimized out, since the one or both
// of these being true has been detected and errored out just above.
 
#ifdef CYGSEM_UITRON_PARAMS_NULL_IS_GOOD_PTR
// represent a NULL as NADR internally
#define CYG_UIT_TMSG_FIXUP_IN( _p_ ) CYG_MACRO_START \
if ( NULL == (_p_) ) \
(_p_) = (T_MSG *)NADR; \
CYG_MACRO_END
 
// we get a NADR back sometimes, meaning NULL
#define CYG_UIT_TMSG_FIXUP_OUT( _p_ ) CYG_MACRO_START \
if ( NADR == (_p_) ) \
(_p_) = (T_MSG *)NULL; \
CYG_MACRO_END
 
#else
// NULL is checked for and makes an error
#define CYG_UIT_TMSG_FIXUP_IN( _p_ ) CYG_EMPTY_STATEMENT
#define CYG_UIT_TMSG_FIXUP_OUT( _p_ ) CYG_EMPTY_STATEMENT
#endif
 
// and sometimes either in status enquiries
#define CYG_UIT_TMSG_FIXUP_ALL( _p_ ) CYG_MACRO_START \
if ( NULL == (_p_) ) \
(_p_) = (T_MSG *)NADR; \
else if ( NADR == (_p_) ) \
(_p_) = (T_MSG *)NULL; \
CYG_MACRO_END
 
CYG_UIT_FUNC_INLINE
ER
snd_msg ( ID mbxid, T_MSG *pk_msg )
{
Cyg_Mbox *p;
CYG_UITRON_CHECK_AND_GETP_MBOXES( mbxid, p );
CYG_UIT_PARAMCHECK_PTR( pk_msg );
CYG_UIT_TMSG_FIXUP_IN( pk_msg );
cyg_bool result = p->tryput( (void *)pk_msg );
if ( ! result )
return E_QOVR;
return E_OK;
}
 
 
CYG_UIT_FUNC_INLINE
ER
rcv_msg ( T_MSG **ppk_msg, ID mbxid )
{
Cyg_Mbox *p;
CYG_UITRON_CHECK_AND_GETP_MBOXES( mbxid, p );
CYG_UIT_PARAMCHECK_PTR( ppk_msg );
CYG_UITRON_CHECK_DISPATCH_ENABLED();
T_MSG *result = (T_MSG *)p->get();
if ( ! result )
CYG_UITRON_FAIL_RETURN();
CYG_UIT_TMSG_FIXUP_OUT( result );
*ppk_msg = result;
return E_OK;
}
 
CYG_UIT_FUNC_INLINE
ER
prcv_msg ( T_MSG **ppk_msg, ID mbxid )
{
Cyg_Mbox *p;
CYG_UITRON_CHECK_AND_GETP_MBOXES( mbxid, p );
CYG_UIT_PARAMCHECK_PTR( ppk_msg );
T_MSG *result = (T_MSG *)p->tryget();
if ( ! result )
return E_TMOUT;
CYG_UIT_TMSG_FIXUP_OUT( result );
*ppk_msg = result;
return E_OK;
}
 
#ifdef CYGFUN_KERNEL_THREADS_TIMER
CYG_UIT_FUNC_INLINE
ER
trcv_msg ( T_MSG **ppk_msg, ID mbxid, TMO tmout )
{
Cyg_Mbox *p;
CYG_UITRON_CHECK_AND_GETP_MBOXES( mbxid, p );
CYG_UIT_PARAMCHECK_PTR( ppk_msg );
CYG_UITRON_CHECK_DISPATCH_ENABLED_TMO( tmout );
// do this now for the case when no sleeping actually occurs
Cyg_Thread *self = Cyg_Thread::self();
self->set_wake_reason( Cyg_Thread::TIMEOUT );
T_MSG *result;
if ( TMO_FEVR == tmout )
result = (T_MSG *)p->get();
else if ( TMO_POL == tmout )
result = (T_MSG *)p->tryget();
else
result = (T_MSG *)p->get(
Cyg_Clock::real_time_clock->current_value() +
(cyg_tick_count)CYG_UITRON_TIME_UIT_TO_SYS32( tmout ) );
if ( ! result )
CYG_UITRON_FAIL_RETURN_SELF( self );
CYG_UIT_TMSG_FIXUP_OUT( result );
*ppk_msg = result;
return E_OK;
}
#endif // CYGFUN_KERNEL_THREADS_TIMER
 
CYG_UIT_FUNC_INLINE
ER
ref_mbx ( T_RMBX *pk_rmbx, ID mbxid )
{
Cyg_Mbox *p;
CYG_UITRON_CHECK_AND_GETP_MBOXES( mbxid, p );
CYG_UIT_PARAMCHECK_PTR( pk_rmbx );
pk_rmbx->exinf = NADR;
pk_rmbx->wtsk = p->waiting_to_get();
pk_rmbx->pk_msg = (T_MSG *)p->peek_item();
CYG_UIT_TMSG_FIXUP_ALL( pk_rmbx->pk_msg );
return E_OK;
}
 
#undef CYG_UIT_TMSG_FIXUP_IN
#undef CYG_UIT_TMSG_FIXUP_OUT
#undef CYG_UIT_TMSG_FIXUP_ALL
#endif // 0 < CYG_UITRON_NUM( MBOXES )
#endif // CYGPKG_UITRON_MBOXES
 
// - Extended Synchronization and Communication Functions
#if 0 // NOT SUPPORTED
ER cre_mbf ( ID mbfid, T_CMBF *pk_cmbf );
ER del_mbf ( ID mbfid );
ER snd_mbf ( ID mbfid, VP msg, INT msgsz );
ER psnd_mbf ( ID mbfid, VP msg, INT msgsz );
ER tsnd_mbf ( ID mbfid, VP msg, INT msgsz, TMO tmout );
ER rcv_mbf ( VP msg, INT *p_msgsz, ID mbfid );
ER prcv_mbf ( VP msg, INT *p_msgsz, ID mbfid );
ER trcv_mbf ( VP msg, INT *p_msgsz, ID mbfid, TMO tmout );
ER ref_mbf ( T_RMBF *pk_rmbf, ID mbfid );
ER cre_por ( ID porid, T_CPOR *pk_cpor );
ER del_por ( ID porid );
ER cal_por ( VP msg, INT *p_rmsgsz, ID porid, UINT calptn, INT
cmsgsz );
ER pcal_por ( VP msg, INT *p_rmsgsz, ID porid, UINT calptn, INT
cmsgsz );
ER tcal_por ( VP msg, INT *p_rmsgsz, ID porid, UINT calptn, INT
cmsgsz, TMO tmout );
ER acp_por ( RNO *p_rdvno, VP msg, INT *p_cmsgsz, ID porid, UINT
acpptn );
ER pacp_por ( RNO *p_rdvno, VP msg, INT *p_cmsgsz, ID porid, UINT
acpptn );
ER tacp_por ( RNO *p_rdvno, VP msg, INT *p_cmsgsz, ID porid, UINT
acpptn, TMO tmout );
ER fwd_por ( ID porid, UINT calptn, RNO rdvno, VP msg, INT cmsgsz
);
ER rpl_rdv ( RNO rdvno, VP msg, INT rmsgsz );
ER ref_por ( T_RPOR *pk_rpor, ID porid );
#endif
// - Interrupt Management Functions
#if 0 // NOT SUPPORTED
ER def_int ( UINT dintno, T_DINT *pk_dint );
void ret_wup ( ID tskid );
#endif
 
CYG_UIT_FUNC_INLINE
ER
loc_cpu ( void )
{
CYG_UITRON_CHECK_TASK_CONTEXT();
Cyg_Scheduler::lock();
// Prevent preemption by going up to prio 0
if ( 0 == cyg_uitron_dis_dsp_old_priority ) {
#ifdef CYGIMP_THREAD_PRIORITY
Cyg_Thread *p = Cyg_Thread::self();
cyg_uitron_dis_dsp_old_priority = p->get_priority();
p->set_priority( 0 );
#else
cyg_uitron_dis_dsp_old_priority = 1;
#endif
}
Cyg_Interrupt::disable_interrupts();
Cyg_Scheduler::unlock();
return E_OK;
}
 
CYG_UIT_FUNC_INLINE
ER
unl_cpu ( void )
{
CYG_UITRON_CHECK_TASK_CONTEXT();
Cyg_Scheduler::lock();
// Enable dispatching (if disabled) and maybe switch threads
if ( 0 != cyg_uitron_dis_dsp_old_priority ) {
// We had prevented preemption by going up to prio 0
#ifdef CYGIMP_THREAD_PRIORITY
Cyg_Thread *p = Cyg_Thread::self();
p->set_priority( cyg_uitron_dis_dsp_old_priority );
#endif
cyg_uitron_dis_dsp_old_priority = 0;
}
Cyg_Interrupt::enable_interrupts();
Cyg_Scheduler::unlock();
CYG_UITRON_CHECK_DISPATCH_ENABLED(); // NB: afterwards!
return E_OK;
}
 
CYG_UIT_FUNC_INLINE
ER
dis_int ( UINT eintno )
{
CYG_INTERRUPT_STATE old_ints;
#if 0 < CYGNUM_HAL_ISR_MIN
CYG_UIT_PARAMCHECK( CYGNUM_HAL_ISR_MIN <= eintno, E_PAR );
#endif
CYG_UIT_PARAMCHECK( CYGNUM_HAL_ISR_MAX >= eintno, E_PAR );
HAL_DISABLE_INTERRUPTS(old_ints);
HAL_INTERRUPT_MASK( eintno );
HAL_RESTORE_INTERRUPTS(old_ints);
return E_OK;
}
 
CYG_UIT_FUNC_INLINE
ER
ena_int ( UINT eintno )
{
CYG_INTERRUPT_STATE old_ints;
 
#if 0 < CYGNUM_HAL_ISR_MIN
CYG_UIT_PARAMCHECK( CYGNUM_HAL_ISR_MIN <= eintno, E_PAR );
#endif
CYG_UIT_PARAMCHECK( CYGNUM_HAL_ISR_MAX >= eintno, E_PAR );
HAL_DISABLE_INTERRUPTS(old_ints);
HAL_INTERRUPT_UNMASK( eintno );
HAL_RESTORE_INTERRUPTS(old_ints);
return E_OK;
}
 
#if 0 // NOT SUPPORTED
ER chg_iXX ( UINT iXXXX );
ER ref_iXX ( UINT *p_iXXXX );
#endif
// - Memorypool Management Functions
#ifdef CYGPKG_UITRON_MEMPOOLVAR
#if 0 < CYG_UITRON_NUM( MEMPOOLVAR )
 
#ifdef CYGPKG_UITRON_MEMPOOLVAR_CREATE_DELETE
 
CYG_UITRON_NEWFUNCTION( Cyg_Mempool_Variable )
 
CYG_UIT_FUNC_INLINE
ER
cre_mpl ( ID mplid, T_CMPL *pk_cmpl )
{
ER ret = E_OK;
CYG_UIT_PARAMCHECK_PTR( pk_cmpl );
CYG_UITRON_CHECK_NO_OBJ_LOCK_SCHED( MEMPOOLVAR, mplid );
Cyg_Mempool_Variable *p = &(CYG_UITRON_OBJS( MEMPOOLVAR )[ mplid - 1 ]);
Cyg_Mempool_Status stat;
 
// preserve the original memory area to use
p->get_status( CYG_MEMPOOL_STAT_ORIGBASE|CYG_MEMPOOL_STAT_ORIGSIZE, stat );
 
if ( stat.origsize < pk_cmpl->mplsz )
ret = E_NOMEM;
else if ( TA_TFIFO != pk_cmpl->mplatr )
ret = E_RSATR;
else
CYG_UITRON_PTRS( MEMPOOLVAR )[ mplid - 1 ] =
new( p ) Cyg_Mempool_Variable(
const_cast<cyg_uint8 *>(stat.origbase), stat.origsize );
Cyg_Scheduler::unlock();
return ret;
}
 
CYG_UIT_FUNC_INLINE
ER
del_mpl ( ID mplid )
{
Cyg_Mempool_Variable *p;
CYG_UITRON_CHECK_AND_GETP_MEMPOOLVAR( mplid, p );
Cyg_Scheduler::lock();
// deal with the race condition here
if ( p != CYG_UITRON_PTRS( MEMPOOLVAR )[ mplid - 1 ] ) {
Cyg_Scheduler::unlock();
return E_NOEXS;
}
CYG_UITRON_PTRS( MEMPOOLVAR )[ mplid - 1 ] = NULL;
p->~Cyg_Mempool_Variable();
Cyg_Scheduler::unlock();
return E_OK;
}
#endif // CYGPKG_UITRON_MEMPOOLVAR_CREATE_DELETE
 
CYG_UIT_FUNC_INLINE
ER
get_blk ( VP *p_blk, ID mplid, INT blksz )
{
Cyg_Mempool_Variable *p;
CYG_UITRON_CHECK_AND_GETP_MEMPOOLVAR( mplid, p );
CYG_UIT_PARAMCHECK_PTR( p_blk );
CYG_UIT_PARAMCHECK( blksz > 0, E_PAR );
CYG_UITRON_CHECK_DISPATCH_ENABLED();
VP result = (VP)p->alloc(blksz);
if ( ! result )
CYG_UITRON_FAIL_RETURN();
*p_blk = result;
return E_OK;
}
 
 
CYG_UIT_FUNC_INLINE
ER
pget_blk ( VP *p_blk, ID mplid, INT blksz )
{
Cyg_Mempool_Variable *p;
CYG_UITRON_CHECK_AND_GETP_MEMPOOLVAR( mplid, p );
CYG_UIT_PARAMCHECK_PTR( p_blk );
CYG_UIT_PARAMCHECK( blksz > 0, E_PAR );
VP result = (VP)p->try_alloc(blksz);
if ( ! result )
return E_TMOUT;
*p_blk = result;
return E_OK;
}
 
#ifdef CYGFUN_KERNEL_THREADS_TIMER
CYG_UIT_FUNC_INLINE
ER
tget_blk ( VP *p_blk, ID mplid, INT blksz, TMO tmout )
{
Cyg_Mempool_Variable *p;
CYG_UITRON_CHECK_AND_GETP_MEMPOOLVAR( mplid, p );
CYG_UIT_PARAMCHECK_PTR( p_blk );
CYG_UIT_PARAMCHECK( blksz > 0, E_PAR );
CYG_UITRON_CHECK_DISPATCH_ENABLED_TMO( tmout );
// do this now for the case when no sleeping actually occurs
Cyg_Thread *self = Cyg_Thread::self();
self->set_wake_reason( Cyg_Thread::TIMEOUT );
VP result;
if ( TMO_FEVR == tmout )
result = p->alloc(blksz);
else if ( TMO_POL == tmout )
result = p->try_alloc(blksz);
else
result = p->alloc( blksz,
Cyg_Clock::real_time_clock->current_value() +
(cyg_tick_count)CYG_UITRON_TIME_UIT_TO_SYS32( tmout ) );
if ( ! result )
CYG_UITRON_FAIL_RETURN_SELF( self );
*p_blk = result;
return E_OK;
}
#endif // CYGFUN_KERNEL_THREADS_TIMER
 
CYG_UIT_FUNC_INLINE
ER
rel_blk ( ID mplid, VP blk )
{
Cyg_Mempool_Variable *p;
CYG_UITRON_CHECK_AND_GETP_MEMPOOLVAR( mplid, p );
CYG_UIT_PARAMCHECK_PTR( blk );
cyg_bool result = p->free( (cyg_uint8 *)blk );
if ( ! result )
return E_PAR;
return E_OK;
}
 
CYG_UIT_FUNC_INLINE
ER
ref_mpl ( T_RMPL *pk_rmpl, ID mplid )
{
Cyg_Mempool_Variable *p;
Cyg_Mempool_Status stat;
CYG_UITRON_CHECK_AND_GETP_MEMPOOLVAR( mplid, p );
CYG_UIT_PARAMCHECK_PTR( pk_rmpl );
p->get_status( CYG_MEMPOOL_STAT_WAITING|
CYG_MEMPOOL_STAT_TOTALFREE|
CYG_MEMPOOL_STAT_MAXFREE, stat );
 
pk_rmpl->exinf = NADR;
pk_rmpl->wtsk = stat.waiting;
pk_rmpl->frsz = stat.totalfree;
pk_rmpl->maxsz = stat.maxfree;
 
return E_OK;
}
 
#endif // 0 < CYG_UITRON_NUM( MEMPOOLVAR )
#endif // CYGPKG_UITRON_MEMPOOLVAR
 
#ifdef CYGPKG_UITRON_MEMPOOLFIXED
#if 0 < CYG_UITRON_NUM( MEMPOOLFIXED )
 
#ifdef CYGPKG_UITRON_MEMPOOLFIXED_CREATE_DELETE
 
CYG_UITRON_NEWFUNCTION( Cyg_Mempool_Fixed )
 
CYG_UIT_FUNC_INLINE
ER
cre_mpf ( ID mpfid, T_CMPF *pk_cmpf )
{
ER ret = E_OK;
CYG_UIT_PARAMCHECK_PTR( pk_cmpf );
CYG_UITRON_CHECK_NO_OBJ_LOCK_SCHED( MEMPOOLFIXED, mpfid );
Cyg_Mempool_Fixed *p = &(CYG_UITRON_OBJS( MEMPOOLFIXED )[ mpfid - 1 ]);
Cyg_Mempool_Status stat;
 
// preserve the original memory area to use
p->get_status( CYG_MEMPOOL_STAT_ORIGBASE|CYG_MEMPOOL_STAT_ORIGSIZE, stat );
 
if ( stat.origsize < (pk_cmpf->blfsz * (pk_cmpf->mpfcnt + 1)) )
ret = E_NOMEM;
else if ( TA_TFIFO != pk_cmpf->mpfatr )
ret = E_RSATR;
else
CYG_UITRON_PTRS( MEMPOOLFIXED )[ mpfid - 1 ] =
new( p )
Cyg_Mempool_Fixed( const_cast<cyg_uint8 *>(stat.origbase),
stat.origsize, (CYG_ADDRWORD)pk_cmpf->blfsz );
Cyg_Scheduler::unlock();
return ret;
}
 
CYG_UIT_FUNC_INLINE
ER
del_mpf ( ID mpfid )
{
Cyg_Mempool_Fixed *p;
CYG_UITRON_CHECK_AND_GETP_MEMPOOLFIXED( mpfid, p );
Cyg_Scheduler::lock();
// deal with the race condition here
if ( p != CYG_UITRON_PTRS( MEMPOOLFIXED )[ mpfid - 1 ] ) {
Cyg_Scheduler::unlock();
return E_NOEXS;
}
CYG_UITRON_PTRS( MEMPOOLFIXED )[ mpfid - 1 ] = NULL;
p->~Cyg_Mempool_Fixed();
Cyg_Scheduler::unlock();
return E_OK;
}
#endif // CYGPKG_UITRON_MEMPOOLFIXED_CREATE_DELETE
 
CYG_UIT_FUNC_INLINE
ER
get_blf ( VP *p_blf, ID mpfid )
{
Cyg_Mempool_Fixed *p;
CYG_UITRON_CHECK_AND_GETP_MEMPOOLFIXED( mpfid, p );
CYG_UIT_PARAMCHECK_PTR( p_blf );
CYG_UITRON_CHECK_DISPATCH_ENABLED();
VP result = (VP)p->alloc();
if ( ! result )
CYG_UITRON_FAIL_RETURN();
*p_blf = result;
return E_OK;
}
 
CYG_UIT_FUNC_INLINE
ER
pget_blf ( VP *p_blf, ID mpfid )
{
Cyg_Mempool_Fixed *p;
CYG_UITRON_CHECK_AND_GETP_MEMPOOLFIXED( mpfid, p );
CYG_UIT_PARAMCHECK_PTR( p_blf );
VP result = (VP)p->try_alloc();
if ( ! result )
return E_TMOUT;
*p_blf = result;
return E_OK;
}
 
#ifdef CYGFUN_KERNEL_THREADS_TIMER
CYG_UIT_FUNC_INLINE
ER
tget_blf ( VP *p_blf, ID mpfid, TMO tmout )
{
Cyg_Mempool_Fixed *p;
CYG_UITRON_CHECK_AND_GETP_MEMPOOLFIXED( mpfid, p );
CYG_UIT_PARAMCHECK_PTR( p_blf );
CYG_UITRON_CHECK_DISPATCH_ENABLED_TMO( tmout );
// do this now for the case when no sleeping actually occurs
Cyg_Thread *self = Cyg_Thread::self();
self->set_wake_reason( Cyg_Thread::TIMEOUT );
VP result;
if ( TMO_FEVR == tmout )
result = p->alloc();
else if ( TMO_POL == tmout )
result = p->try_alloc();
else
result = p->alloc(
Cyg_Clock::real_time_clock->current_value() +
(cyg_tick_count)CYG_UITRON_TIME_UIT_TO_SYS32( tmout ) );
if ( ! result )
CYG_UITRON_FAIL_RETURN_SELF( self );
*p_blf = result;
return E_OK;
}
#endif // CYGFUN_KERNEL_THREADS_TIMER
 
CYG_UIT_FUNC_INLINE
ER
rel_blf ( ID mpfid, VP blf )
{
Cyg_Mempool_Fixed *p;
CYG_UITRON_CHECK_AND_GETP_MEMPOOLFIXED( mpfid, p );
CYG_UIT_PARAMCHECK_PTR( blf );
cyg_bool result = p->free( (cyg_uint8 *)blf );
if ( ! result )
return E_PAR;
return E_OK;
}
 
CYG_UIT_FUNC_INLINE
ER
ref_mpf ( T_RMPF *pk_rmpf, ID mpfid )
{
Cyg_Mempool_Fixed *p;
Cyg_Mempool_Status stat;
CYG_UITRON_CHECK_AND_GETP_MEMPOOLFIXED( mpfid, p );
CYG_UIT_PARAMCHECK_PTR( pk_rmpf );
 
p->get_status( CYG_MEMPOOL_STAT_WAITING|
CYG_MEMPOOL_STAT_TOTALFREE|
CYG_MEMPOOL_STAT_TOTALALLOCATED|
CYG_MEMPOOL_STAT_BLOCKSIZE, stat );
 
pk_rmpf->exinf = NADR;
pk_rmpf->wtsk = stat.waiting;
 
pk_rmpf->frbcnt = stat.totalfree / stat.blocksize;
// these two are "implementation dependent" ie. eCos only
pk_rmpf->numbcnt = stat.totalallocated / stat.blocksize;
pk_rmpf->bsize = stat.blocksize;
 
return E_OK;
}
#endif // 0 < CYG_UITRON_NUM( MEMPOOLFIXED )
#endif // CYGPKG_UITRON_MEMPOOLFIXED
 
// - Time Management Functions
#ifdef CYGVAR_KERNEL_COUNTERS_CLOCK
CYG_UIT_FUNC_INLINE
ER
set_tim ( SYSTIME *pk_tim )
{
CYG_UIT_PARAMCHECK_PTR( pk_tim );
Cyg_Clock::real_time_clock->set_value(
CYG_UITRON_TIME_UIT_TO_SYS64( *pk_tim ) );
return E_OK;
}
 
CYG_UIT_FUNC_INLINE
ER
get_tim ( SYSTIME *pk_tim )
{
CYG_UIT_PARAMCHECK_PTR( pk_tim );
*pk_tim = CYG_UITRON_TIME_SYS_TO_UIT64(
Cyg_Clock::real_time_clock->current_value() );
return E_OK;
}
#endif // CYGVAR_KERNEL_COUNTERS_CLOCK
 
 
#ifdef CYGFUN_KERNEL_THREADS_TIMER
CYG_UIT_FUNC_INLINE
ER
dly_tsk ( DLYTIME dlytim )
{
CYG_UIT_PARAMCHECK( 0 <= dlytim, E_PAR );
CYG_UITRON_CHECK_DISPATCH_ENABLED();
if ( 0 >= dlytim )
return E_OK;
Cyg_Thread *self = Cyg_Thread::self();
CYG_UITRON_CHECK_TASK_CONTEXT_SELF( self );
self->delay( CYG_UITRON_TIME_UIT_TO_SYS64( dlytim ) );
if ( Cyg_Thread::DONE != self->get_wake_reason() )
CYG_UITRON_FAIL_RETURN_SELF( self );
return E_OK;
}
#endif // CYGFUN_KERNEL_THREADS_TIMER
 
#ifdef CYGVAR_KERNEL_COUNTERS_CLOCK
#ifdef CYGPKG_UITRON_CYCLICS
#if 0 < CYG_UITRON_NUM( CYCLICS )
CYG_UIT_FUNC_INLINE
ER
def_cyc ( HNO cycno, T_DCYC *pk_dcyc )
{
// pk_dcyc->cycatr is ignored
// The only relevant attribute is TA_HLNG/TA_ASM.
// This can be ignored as assembler routines are defined to be
// more conservative with registers than the procedure call standard.
cyg_tick_count t;
Cyg_Timer *p;
CYG_UITRON_CHECK_AND_GETHDLR( CYCLICS, cycno, p );
#ifndef CYGSEM_UITRON_PARAMS_NULL_IS_GOOD_PTR
CYG_UIT_PARAMCHECK( NULL != pk_dcyc, E_PAR );
#endif
if( NADR == pk_dcyc ) {
p->~Cyg_Timer();
return E_OK;
}
CYG_UIT_PARAMCHECK( 0 == (pk_dcyc->cycact & ~TCY_ON), E_PAR );
CYG_UIT_PARAMCHECK( 0 < pk_dcyc->cyctim, E_PAR );
t = CYG_UITRON_TIME_UIT_TO_SYS64( pk_dcyc->cyctim );
p->initialize(
Cyg_Clock::real_time_clock,
(cyg_alarm_fn *)pk_dcyc->cychdr,
(CYG_ADDRWORD)pk_dcyc->exinf,
Cyg_Clock::real_time_clock->current_value() + t,
t,
pk_dcyc->cycact);
return E_OK;
}
 
CYG_UIT_FUNC_INLINE
ER
act_cyc ( HNO cycno, UINT cycact )
{
Cyg_Timer *p;
CYG_UITRON_CHECK_AND_GETHDLR( CYCLICS, cycno, p );
CYG_UIT_PARAMCHECK( p->is_initialized(), E_NOEXS);
CYG_UIT_PARAMCHECK( 0 == (cycact & ~(TCY_ON | TCY_INI)), E_PAR );
p->activate(cycact);
return E_OK;
}
 
 
CYG_UIT_FUNC_INLINE
ER
ref_cyc ( T_RCYC *pk_rcyc, HNO cycno )
{
Cyg_Timer *p;
cyg_tick_count t;
CYG_UITRON_CHECK_AND_GETHDLR( CYCLICS, cycno, p );
CYG_UIT_PARAMCHECK( p->is_initialized(), E_NOEXS);
CYG_UIT_PARAMCHECK_PTR( pk_rcyc );
 
pk_rcyc->exinf = (VP)p->get_data();
Cyg_Scheduler::lock();
t = p->get_trigger() - Cyg_Clock::real_time_clock->current_value();
Cyg_Scheduler::unlock();
pk_rcyc->lfttim = CYG_UITRON_TIME_SYS_TO_UIT64( t );
pk_rcyc->cycact = (UINT)p->is_enabled();
return E_OK;
}
#endif // 0 < CYG_UITRON_NUM( CYCLICS )
#endif // CYGPKG_UITRON_CYCLICS
 
#ifdef CYGPKG_UITRON_ALARMS
#if 0 < CYG_UITRON_NUM( ALARMS )
CYG_UIT_FUNC_INLINE
ER
def_alm ( HNO almno, T_DALM *pk_dalm )
{
Cyg_Timer *p;
cyg_tick_count t, now;
CYG_UITRON_CHECK_AND_GETHDLR( ALARMS, almno, p );
#ifndef CYGSEM_UITRON_PARAMS_NULL_IS_GOOD_PTR
CYG_UIT_PARAMCHECK( NULL != pk_dalm, E_PAR );
#endif
if( NADR == pk_dalm ) {
p->~Cyg_Timer();
return E_OK;
}
 
CYG_UIT_PARAMCHECK( 0 == (pk_dalm->tmmode & ~TTM_REL), E_PAR );
CYG_UIT_PARAMCHECK( 0 < pk_dalm->almtim, E_PAR );
 
// make the time arithmetic safe without locking
now = Cyg_Clock::real_time_clock->current_value();
t = CYG_UITRON_TIME_UIT_TO_SYS64( pk_dalm->almtim );
if( TTM_REL & pk_dalm->tmmode )
t += now;
 
CYG_UIT_PARAMCHECK( now < t, E_PAR );
 
p->initialize(Cyg_Clock::real_time_clock,
(cyg_alarm_fn *)pk_dalm->almhdr,
(CYG_ADDRWORD)pk_dalm->exinf,
t, 0, Cyg_Timer::ENABLE);
 
return E_OK;
}
 
CYG_UIT_FUNC_INLINE
ER
ref_alm ( T_RALM *pk_ralm, HNO almno )
{
Cyg_Timer *p;
cyg_tick_count t;
 
CYG_UITRON_CHECK_AND_GETHDLR( ALARMS, almno, p );
CYG_UIT_PARAMCHECK_PTR( pk_ralm );
CYG_UIT_PARAMCHECK( p->is_initialized(), E_NOEXS);
 
Cyg_Scheduler::lock();
t = p->get_trigger() - Cyg_Clock::real_time_clock->current_value();
Cyg_Scheduler::unlock();
pk_ralm->exinf = (VP)p->get_data();
pk_ralm->lfttim = CYG_UITRON_TIME_SYS_TO_UIT64( t );
return E_OK;
}
#endif // 0 < CYG_UITRON_NUM( ALARMS )
#endif // CYGPKG_UITRON_ALARMS
 
#endif // CYGVAR_KERNEL_COUNTERS_CLOCK
// - System Management Functions
CYG_UIT_FUNC_INLINE
ER
get_ver ( T_VER *pk_ver )
{
CYG_UIT_PARAMCHECK_PTR( pk_ver );
 
pk_ver->maker = CYGNUM_UITRON_VER_MAKER;
pk_ver->id = CYGNUM_UITRON_VER_ID;
pk_ver->spver = CYGNUM_UITRON_VER_SPVER;
pk_ver->prver = CYGNUM_UITRON_VER_PRVER;
pk_ver->prno[0] = CYGNUM_UITRON_VER_PRNO_0;
pk_ver->prno[1] = CYGNUM_UITRON_VER_PRNO_1;
pk_ver->prno[2] = CYGNUM_UITRON_VER_PRNO_2;
pk_ver->prno[3] = CYGNUM_UITRON_VER_PRNO_3;
pk_ver->cpu = CYGNUM_UITRON_VER_CPU;
pk_ver->var = CYGNUM_UITRON_VER_VAR;
return E_OK;
}
 
CYG_UIT_FUNC_INLINE
ER
ref_sys ( T_RSYS *pk_rsys )
{
CYG_UIT_PARAMCHECK_PTR( pk_rsys );
if ( ! Cyg_Interrupt::interrupts_enabled() )
// CPU is locked
pk_rsys->sysstat = TSS_LOC;
else
pk_rsys->sysstat =
(0 == cyg_uitron_dis_dsp_old_priority) ? TSS_TSK : TSS_DDSP;
return E_OK;
}
 
CYG_UIT_FUNC_INLINE
ER
ref_cfg ( T_RCFG *pk_rcfg )
{
CYG_UIT_PARAMCHECK_PTR( pk_rcfg );
// no details here yet
return E_OK;
}
 
#if 0 // NOT SUPPORTED
ER def_svc ( FN s_fncd, T_DSVC *pk_dsvc );
ER def_exc ( UINT exckind, T_DEXC *pk_dexc );
#endif
// - Network Support Functions
#if 0 // NOT SUPPORTED
ER nrea_dat ( INT *p_reasz, VP dstadr, NODE srcnode, VP srcadr,
INT datsz );
ER nwri_dat ( INT *p_wrisz, NODE dstnode, VP dstadr, VP srcadr,
INT datsz );
ER nget_nod ( NODE *p_node );
ER nget_ver ( T_VER *pk_ver, NODE node );
#endif
 
// ========================================================================
 
#endif // CYGPKG_UITRON
 
#endif // CYGPRI_UITRON_FUNCS_HERE_AND_NOW
 
#endif // CYGONCE_COMPAT_UITRON_UIT_FUNC_INL
//EOF uit_func.inl

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.