gonzui


Format: Advanced Search

tkernel_2/include/sys/bitop.hbare sourcepermlink (0.02 seconds)

Search this content:

    1: /*
    2:  *----------------------------------------------------------------------
    3:  *    T-Kernel 2.0 Software Package
    4:  *
    5:  *    Copyright 2011 by Ken Sakamura.
    6:  *    This software is distributed under the latest version of T-License 2.x.
    7:  *----------------------------------------------------------------------
    8:  *
    9:  *    Released by T-Engine Forum(http://www.t-engine.org/) at 2011/05/17.
   10:  *    Modified by T-Engine Forum at 2013/12/19.
   11:  *    Modified by TRON Forum(http://www.tron.org/) at 2015/06/01.
   12:  *
   13:  *----------------------------------------------------------------------
   14:  */
   15: 
   16: /*
   17:  *      @(#)bitop.h (sys)
   18:  *
   19:  *      Bit operation
   20:  *
   21:  *      Bit string is defined as follows according to endian of CPU:
   22:  *
   23:  *              Big endian          Little endian
   24:  *      offset        0 ...... 7            7 ...... 0
   25:  *              +----------+                +----------+
   26:  *      base +0      |MSB LSB|            |MSB      LSB|
   27:  *              +----------+                +----------+
   28:  *
   29:  *      offset        8 ..... 15            15 ..... 8
   30:  *              +----------+                +----------+
   31:  *      base +1      |MSB LSB|            |MSB      LSB|
   32:  *              +----------+                +----------+
   33:  *
   34:  *      Specify bit positions with base and offset.
   35:  *      Cannot specify a position that precede base or "offset < 0".
   36:  */
   37: 
   38: #ifndef __SYS_BITOP_H__
   39: #define __SYS_BITOP_H__
   40: 
   41: #include <basic.h>
   42: 
   43: #ifdef __cplusplus
   44: extern "C" {
   45: #endif
   46: 
   47: /*
   48:  * Clear/set/flip specified bit
   49:  */
   50: IMPORT void     BitClr( void *base, UW offset );
   51: IMPORT void     BitSet( void *base, UW offset );
   52: IMPORT void     BitNot( void *base, UW offset );
   53: 
   54: /*
   55:  * Test specified bit
   56:  *      When specified bit is 0, return FALSE; when specified bit is 1, return TRUE(!=0).
   57:  */
   58: IMPORT BOOL     BitTest( const void *base, UW offset );
   59: 
   60: /*
   61:  * Retrieve bit
   62:  *      Retrieve the width bits from the position of specified bit and return the position.
   63:  *      If not found, return -1.
   64:  *      The found position is returned in relative position from the retrieval start position.
   65:  *      When found, the return value is between 0 and width-1.
   66:  */
   67: IMPORT W        BitSearch0( const void *base, W offset, W width ); /* Retrieve bit 0 */
   68: IMPORT W        BitSearch1( const void *base, W offset, W width ); /* Retrieve bit 1 */
   69: 
   70: /* Faster BitSearch for aligned memory */
   71: IMPORT W        BitSearch0_w( const UW *base, W offset, W width ); /* Retrieve bit 0 */
   72: IMPORT W        BitSearch1_w( const UW *base, W offset, W width ); /* Retrieve bit 1 */
   73: 
   74: /*
   75:  * Clear/set bit string
   76:  *      Clear or set the width bits from the position of specified bit.
   77:  */
   78: IMPORT void     BitsClr( void *base, W offset, W width );
   79: IMPORT void     BitsSet( void *base, W offset, W width );
   80: 
   81: #ifdef __cplusplus
   82: }
   83: #endif
   84: #endif /* __SYS_BITOP_H__ */