µITRON API

To Contents

To previous page

To next page

 




µ ITRON API

The µ ITRON specification defines a highly flexible operating system architecture designed specifically for application in embedded systems. The specification addresses features which are common to the majority of processor architectures and deliberately avoids virtualization which would adversely impact real-time performance. The µ ITRON specification may be implemented on many hardware platforms and provides significant advantages by reducing the effort involved in understanding and porting application software to new processor architectures.

Several revisions of the µ ITRON specification exist. In this release, eCos supports the µ ITRON version 3.02 specification, with complete "Standard functionality" (level S), plus many "Extended" (level E) functions. The definitive reference on µ ITRON is Dr. Sakamura's book µ ITRON 3.0, An Open and Portable Real-Time Operating System for Embedded Systems. If you have purchased the eCos Developer's Kit, you will have received a copy of this book. Otherwise, the book can be purchased from the IEEE Press, and an ASCII version of the standard can be found online at

http://www.itron.gr.jp/

(The old address

still exists as a mirror site.)

The eCos kernel implements the functionality used by the µ ITRON compatibility subsystem. The configuration of the kernel influences the behavior of µ ITRON programs.

In particular, the default configuration has time slicing (also known as round-robin scheduling) switched on; this means that a task can be moved from RUN state to READY state at any time, in order that one of its peers may run. This is not strictly conformant to the µ ITRON specification, which states that timeslicing may be implemented by periodically issuing a rot_rdq(0) call from within a periodic task or cyclic handler; otherwise it is expected that a task runs until it is pre-empted in consequence of synchronization or communications calls it makes, or the effects of an interrupt or other external event on a higher priority task cause that task to become READY . To disable timeslicing functionality in the kernel and µ ITRON compatibility environment, please disable the CYGSEM_KERNEL_SCHED_TIMESLICE configuration option in the kernel package. A description of kernel scheduling is in Thread operations .

For another example, the semantics of task queueing when waiting on a synchronization object depend solely on the way the underlying kernel is configured. As discussed above, the multi-level queue scheduler is the only one which is µ ITRON compliant, and it queues waiting tasks in FIFO order. Future releases of that scheduler might be configurable to support priority ordering of task queues. Other schedulers might be different again: for example the bitmap scheduler can be used with the µ ITRON compatibility layer, even though it only allows one task at each priority and as such is not µ ITRON compliant, but it supports only priority ordering of task queues. So which queueing scheme is supported is not really a property of the µ ITRON compatibility layer; it depends on the kernel.

In this version of the µ ITRON compatibility layer, the calls to disable and enable scheduling and interrupts ( dis_dsp() , ena_dsp() , loc_cpu() and unl_cpu() ) call underlying kernel functions; in particular, the xxx_dsp() functions lock the scheduler entirely, which prevents dispatching of DSRs; functions implemented by DSRs include clock counters and alarm timers. Thus time "stops" while dispatching is disabled with dis_dsp() .

Like all parts of the eCos system, the detailed semantics of the µ ITRON layer are dependent on its configuration and the configuration of other components that it uses. The µ ITRON configuration options are all defined in the file pkgconf/uitron.h , and can be set using the configuration tool or editing this file by hand.

An important configuration option for the µ ITRON compatibility layer is CYGSEM_UITRON_BAD_PARAMS_RETURN_ERRORS (see "Option: Return Error Codes for Bad Params", in Section V), which allows a lot of the error checking code in the µ ITRON compatibility layer to be removed; of course this leaves a program open to undetected errors, so it should only be used once an application is fully debugged and tested. Its benefits include reduced code size and faster execution. However, it affects the API significantly, in that with this option enabled, bad calls do not return errors, but either cause an assert failure (if that is itself enabled) or malfunction internally. There is discussion in more detail about this in each section below.

We now give a brief description of the µ ITRON functions which are implemented in this release. Note that all C and C++ source files should have the following #include statement:

 

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

Task Management Functions

The following functions are fully supported in this release:

 
ER sta_tsk( 
    ID tskid,
    INT stacd )
void ext_tsk( void )
 
void exd_tsk( void )
ER dis_dsp( void )
ER ena_dsp( void )
ER chg_pri( 
    ID tskid,
    PRI tskpri )
ER rot_rdq( 
    PRI tskpri )
ER get_tid( 
    ID *p_tskid )
ER ref_tsk( 
    T_RTSK *pk_rtsk,
    ID tskid )
ER ter_tsk( 
    ID tskid )

ER rel_wai( 
    ID tskid )

The following two functions are supported in this release, when enabled with the configuration option CYGPKG_UITRON_TASKS_CREATE_DELETE with some restrictions:

 
ER cre_tsk( 
    ID tskid,
    T_CTSK *pk_ctsk )
ER del_tsk( 
    ID tskid )

These functions are restricted as follows:

Because of the static initialization facilities provided for system objects, a task is allocated stack space statically in the configuration. So while tasks can be created and deleted, the same stack space is used for that task (task ID number) each time. Thus the stack size (pk_ctskstksz) requested in cre_tsk() is checked for being less than that which was statically allocated, and otherwise ignored. This ensures that the new task will have enough stack to run. For this reason del_tsk() does not in any sense free the memory that was in use for the task's stack.

The task attributes (pk_ctsktskatr) are ignored; current versions of eCos do not need to know whether a task is written in assembler or C/C++ so long as the procedure call standard appropriate to the CPU is followed.

Extended information (pk_ctskexinf) is ignored.

Error checking

For all these calls, an invalid task id (tskid) (less than 1 or greater than the number of configured tasks) only returns E_ID when bad params return errors ( CYGSEM_UITRON_BAD_PARAMS_RETURN_ERRORS is enabled, see above).

Similarly, the following conditions are only checked for, and only return errors if CYGSEM_UITRON_BAD_PARAMS_RETURN_ERRORS is enabled:

The following conditions are checked for, and return error codes if appropriate, regardless of the setting of CYGSEM_UITRON_BAD_PARAMS_RETURN_ERRORS :

Task-Dependent Synchronization Functions

These functions are fully supported in this release:

 
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 )
Error checking

The following conditions are only checked for, and only return errors if CYGSEM_UITRON_BAD_PARAMS_RETURN_ERRORS is enabled (see "Option: Return Error Codes for Bad Params", in Section V):

The following conditions are checked for, and can return error codes, regardless of the setting of CYGSEM_UITRON_BAD_PARAMS_RETURN_ERRORS :

Synchronization and Communication Functions

These functions are fully supported in this release:

 
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 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 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 )

The following functions are supported in this release (with some restrictions) if enabled with the appropriate configuration option for the object type (for example CYGPKG_UITRON_SEMAS_CREATE_DELETE ) :

 
ER cre_sem( 
    ID semid,
    T_CSEM *pk_csem )
 
ER del_sem( 
    ID semid )
ER cre_flg( 
    ID flgid,
    T_CFLG *pk_cflg )
ER del_flg( 
    ID flgid )
ER cre_mbx( 
    ID mbxid,
    T_CMBX *pk_cmbx )
ER del_mbx( 
    ID mbxid )

In general the queueing order when waiting on a synchronization object depends on the underlying kernel configuration. The multi-level queue scheduler is required for strict µ ITRON conformance and it queues tasks in FIFO order, so requests to create an object with priority queueing of tasks ( pk_cxxxxxxatr = TA_TPRI ) are rejected with E_RSATR. Additional undefined bits in the attributes fields must be zero.

In general, extended information (pk_cxxxexinf) is ignored.

For semaphores, the initial semaphore count (pk_csemisemcnt) is supported; the new semaphore's count is set. The maximum count is not supported, and is not in fact defined in type pk_csem.

For flags, multiple tasks are allowed to wait. Because single task waiting is a subset of this, the W bit (TA_WMUL) of the flag attributes is ignored; all other bits must be zero. The initial flag value is supported.

For mailboxes, the buffer count is defined statically by kernel configuration option CYGNUM_KERNEL_SYNCH_MBOX_QUEUE_SIZE; therefore the buffer count field is not supported and is not in fact defined in type pk_cmbx. Queueing of messages is FIFO ordered only, so TA_MPRI (in pk_cmbxmbxatr) is not supported.

Error checking

The following conditions are only checked for, and only return errors if CYGSEM_UITRON_BAD_PARAMS_RETURN_ERRORS is enabled:

The following conditions are checked for, and can return error codes, regardless of the setting of CYGSEM_UITRON_BAD_PARAMS_RETURN_ERRORS :

Extended Synchronization and Communication Functions

None of these functions are supported in this release.

Interrupt management functions

These functions are fully supported in this release:

void ret_int( void )
ER loc_cpu( void )
ER unl_cpu( void ) ER dis_int( UINT eintno ) ER ena_int( UINT eintno ) void ret_wup( ID tskid ) ER iwup_tsk( ID tskid ) ER isig_sem( ID semid ) ER iset_flag( ID flgid,
UINT setptn ) ER isnd_msg( ID mbxid,
T_MSG *pkmsg )

Note that ret_int() and ret_wup() are implemented as macros, containing a "return" statement.

Also note that ret_wup() and the ixxx_yyy() style functions will only work when called from an ISR whose associated DSR is cyg_uitron_dsr(), as specified in the include file <cyg/compat/uitron/uit_ifnc.h>, which defines the ixxx_yyy() style functions also. Do not use them from a DSR: use plain xxx_yyy() style functions instead.

The following functions are not supported in this release:

 
ER def_int( 
    UINT dintno,
    T_DINT *pk_dint )

ER chg_iXX( 
    UINT iXXXX )

ER ref_iXX( 
    UINT * p_iXXXX )

These unsupported functions are all Level C (CPU dependent). Equivalent functionality is available via other eCos -specific APIs.

Error checking

The following conditions are only checked for, and only return errors, if CYGSEM_UITRON_BAD_PARAMS_RETURN_ERRORS is enabled:

Memory pool Management Functions

These functions are fully supported in this release:

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 )
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 )

Note that of the memory provided for a particular pool to manage in the static initialization of the memory pool objects, some memory will be used to manage the pool itself. Therefore the number of blocks * the blocksize will be less than the total memory size.

The following functions are supported in this release, when enabled with CYGPKG_UITRON_MEMPOOLVAR_CREATE_DELETE or CYGPKG_UITRON_MEMPOOLFIXED_CREATE_DELETE as appropriate, with some restrictions:

 
ER cre_mpl( 
    ID mplid,
    T_CMPL *pk_cmpl )
ER del_mpl( 
    ID mplid )
ER cre_mpf( 
    ID mpfid,
    T_CMPF *pk_cmpf )
ER del_mpf( 
    ID mpfid )

Because of the static initialization facilities provided for system objects, a memory pool is allocated a region of memory to manage statically in the configuration. So while memory pools can be created and deleted, the same area of memory is used for that memory pool (memory pool ID number) each time. The requested variable pool size (pk_cmplmplsz) or the number of fixed-size blocks (pk_cmpfmpfcnt) times the block size (pk_cmpfblfsz) are checked for fitting within the statically allocated memory area, so if a create call succeeds, the resulting pool will be at least as large as that requested. For this reason del_mpl() and del_mpf() do not in any sense free the memory that was managed by the deleted pool for use by other pools; it may only be managed by a pool of the same object id.

For both fixed and variable memory pools, the queueing order when waiting on a synchronization object depends on the underlying kernel configuration. The multi-level queue scheduler is required for strict µ ITRON conformance and it queues tasks in FIFO order, so requests to create an object with priority queueing of tasks (pk_cxxxxxxatr = TA_TPRI) are rejected with E_RSATR. Additional undefined bits in the attributes fields must be zero.

In general, extended information (pk_cxxxexinf) is ignored.

Error checking

The following conditions are only checked for, and only return errors if CYGSEM_UITRON_BAD_PARAMS_RETURN_ERRORS is enabled:

The following conditions are checked for, and can return error codes, regardless of the setting of CYGSEM_UITRON_BAD_PARAMS_RETURN_ERRORS :

Time Management Functions

These functions are fully supported in this release:

 
ER set_tim( 
    SYSTIME *pk_tim )

CAUTION

Setting the time may cause erroneous operation of the kernel, for example a task performing a wait with a time-out may never awaken.

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 )
void ret_tmr( void )

    Error checking

The following conditions are only checked for, and only return errors if CYGSEM_UITRON_BAD_PARAMS_RETURN_ERRORS is enabled:

The following conditions are checked for, and can return error codes, regardless of the setting of CYGSEM_UITRON_BAD_PARAMS_RETURN_ERRORS :

System Management Functions

These functions are fully supported in this release:

ER get_ver( 
    T_VER *pk_ver )
ER ref_sys( 
    T_RSYS *pk_rsys )
ER ref_cfg( 
    T_RCFG *pk_rcfg )

Note that the information returned by each of these calls may be configured to match the user's own versioning system, and the values supplied by the default configuration may be inappropriate.

These functions are not supported in this release:

ER def_svc( 
    FN s_fncd,
    T_DSVC *pk_dsvc )
ER def_exc( 
    UINT exckind,
    T_DEXC *pk_dexc )
Error checking

The following conditions are only checked for, and only return errors if CYGSEM_UITRON_BAD_PARAMS_RETURN_ERRORS is enabled:

Network Support Functions

None of these functions are supported in this release.


µITRON API

To Contents

To previous page

To next page