gonzui


Format: Advanced Search

mtkernel_3/include/tk/syslib.hbare sourcepermlink (0.01 seconds)

Search this content:

    1: /*
    2:  *----------------------------------------------------------------------
    3:  *    micro T-Kernel 3.00.05
    4:  *
    5:  *    Copyright (C) 2006-2021 by Ken Sakamura.
    6:  *    This software is distributed under the T-License 2.2.
    7:  *----------------------------------------------------------------------
    8:  *
    9:  *    Released by TRON Forum(http://www.tron.org) at 2021/11.
   10:  *
   11:  *----------------------------------------------------------------------
   12:  */
   13: 
   14: 
   15: /*
   16:  *      syslib.h
   17:  *
   18:  *      micro T-Kernel System Library
   19:  */
   20: 
   21: 
   22: #ifndef __TK_SYSLIB_H__
   23: #define __TK_SYSLIB_H__
   24: 
   25: #include "typedef.h"
   26: 
   27: 
   28: /* ------------------------------------------------------------------------ */
   29: /*
   30:  * System dependencies  (CPU Intrrupt contrl , I/O port access)
   31:  */
   32: #define SYSLIB_PATH_(a)         #a
   33: #define SYSLIB_PATH(a)          SYSLIB_PATH_(a)
   34: #define SYSLIB_SYSDEP()         SYSLIB_PATH(sysdepend/TARGET_DIR/syslib.h)
   35: #include SYSLIB_SYSDEP()
   36: 
   37: 
   38: /*----------------------------------------------------------------------*/
   39: /*
   40:  * Interrupt controller Control
   41:  *
   42:  */
   43: #if TK_SUPPORT_INTCTRL
   44: #if TK_HAS_ENAINTLEVEL
   45: IMPORT void EnableInt( UINT intno, INT level ); /* Enable the interrupt specified by 'intno.' */
   46: #else
   47: IMPORT void EnableInt( UINT intno );            /* Enable the interrupt specified by 'intno.' */
   48: #endif /* TK_HAS_ENAINTLEVEL */
   49: 
   50: IMPORT void DisableInt( UINT intno );   /* Disable the interrupt specified by 'intno.' */
   51: IMPORT void ClearInt(UINT intno);       /* Clear the state that the specified interrupt has been asserted. */
   52: IMPORT void EndOfInt(UINT intno);       /* Issue EOI to Interrupt Controller. */
   53: IMPORT BOOL CheckInt( UINT intno );     /* Check active state for the associated interrupt */
   54: 
   55: #endif /* TK_SUPPORT_INTCTRL */
   56: 
   57: #if TK_SUPPORT_INTMODE
   58: IMPORT void SetIntMode(UINT intno, UINT mode);  /* Set interrupt mode */
   59: #endif /* TK_SUPPORT_INTMODE */
   60: 
   61: #if TK_SUPPORT_CPUINTLEVEL
   62: IMPORT void SetCpuIntLevel( INT level );
   63: IMPORT INT GetCpuIntLevel( void );
   64: #endif /* TK_SUPPORT_CPUINTLEVEL */
   65: 
   66: #if TK_SUPPORT_CTRLINTLEVEL
   67: IMPORT void SetCtrlIntLevel(INT level); /* Set interrupt mask level in interrupt controller */
   68: IMPORT INT  GetCtrlIntLevel(void);      /* Get interrupt mask level in interrupt controller */
   69: #endif /* TK_SUPPORT_CTRLINTLEVEL */
   70: 
   71: 
   72: /* ------------------------------------------------------------------------ */
   73: /*
   74:  * Micro Wait
   75:  */
   76: 
   77: IMPORT void WaitUsec( UW usec );        /* micro second wait */
   78: IMPORT void WaitNsec( UW nsec );        /* nano second wait */
   79: 
   80: 
   81: /* ------------------------------------------------------------------------ */
   82: /*
   83:  * Fast Lock
   84:  */
   85: typedef struct {
   86:         INT            cnt;
   87:         ID             id;
   88:         CONST UB       *name;
   89: } FastLock;
   90: 
   91: IMPORT ER CreateLock( FastLock *lock, CONST UB *name );
   92: IMPORT void DeleteLock( FastLock *lock );
   93: IMPORT void Lock( FastLock *lock );
   94: IMPORT void Unlock( FastLock *lock );
   95: 
   96: 
   97: /* ------------------------------------------------------------------------ */
   98: /*
   99:  * Multi Lock
  100:  *      Can use the maximum of 16 or 32 independent locks with a single FastMLock.
  101:  *      Divided by the lock number (no). Can specify 0-15 or 0-31 for 'no.'
  102:  *      (Slightly less efficient than FastLock)
  103:  */
  104: typedef struct {
  105:         UINT           flg;
  106:         INT            wai;
  107:         ID             id;
  108:         CONST UB       *name;
  109: } FastMLock;
  110: 
  111: IMPORT ER CreateMLock( FastMLock *lock, CONST UB *name );
  112: IMPORT ER DeleteMLock( FastMLock *lock );
  113: IMPORT ER MLockTmo( FastMLock *lock, INT no, TMO tmout );
  114: IMPORT ER MLock( FastMLock *lock, INT no );
  115: IMPORT ER MUnlock( FastMLock *lock, INT no );
  116: 
  117: 
  118: /* ------------------------------------------------------------------------ */
  119: /*
  120:  * Memory allocation
  121:  */
  122: #if TK_SUPPORT_MEMLIB
  123: 
  124: #ifndef PROHIBIT_DEF_SIZE_T
  125: typedef SZ              size_t;
  126: #endif
  127: 
  128: IMPORT void *Kmalloc( size_t size );
  129: IMPORT void *Kcalloc( size_t nmemb, size_t size );
  130: IMPORT void *Krealloc( void *ptr, size_t size);
  131: IMPORT void Kfree( void *ptr );
  132: 
  133: #endif /* TK_SUPPORT_MEMLIB */
  134: 
  135: 
  136: /* ------------------------------------------------------------------------ */
  137: /*
  138:  * Physical timer
  139:  */
  140: #if TK_SUPPORT_PTIMER
  141: 
  142: #define TA_ALM_PTMR     0
  143: #define TA_CYC_PTMR     1
  144: 
  145: typedef struct {
  146:         void   *exinf;           /* Extended Information */
  147:         ATR    ptmratr;   /* Physical Timer Attribute */
  148:         FP     ptmrhdr;    /* Physical Timer Handler Address */
  149: } T_DPTMR;
  150: 
  151: typedef struct {
  152:         UW     ptmrclk;    /* Physical Timer Clock Frequency */
  153:         UW     maxcount;   /* Maximum Count */
  154:         BOOL   defhdr;           /* Handler Support */
  155: } T_RPTMR;
  156: 
  157: IMPORT ER StartPhysicalTimer( UINT ptmrno, UW limit, UINT mode);
  158: IMPORT ER StopPhysicalTimer( UINT ptmrno );
  159: IMPORT ER GetPhysicalTimerCount( UINT ptmrno, UW *p_count );
  160: IMPORT ER DefinePhysicalTimerHandler( UINT ptmrno, CONST T_DPTMR *pk_dptmr );
  161: IMPORT ER GetPhysicalTimerConfig(UINT ptmrno, T_RPTMR *pk_rptmr);
  162: 
  163: #endif /* TK_SUPPORT_PTIMER */
  164: 
  165: 
  166: /* ------------------------------------------------------------------------ */
  167: /*
  168:  * 4-character object name
  169:  *      (Example)
  170:  *      T_CTSK       ctsk;
  171:  *      SetOBJNAME(ctsk.exinf, "TEST");
  172:  */
  173: union objname {
  174:         char   s[4];
  175:         void   *i;
  176: };
  177: 
  178: #define SetOBJNAME(exinf, name)                                 \
  179:         {                                                      \
  180:                 UB *d, *s; INT i;                             \
  181:                 d = (UB*)&(exinf);                            \
  182:                 s = (UB*)name;                                        \
  183:                 for(i=0; i<4; i++) *d++ = *s++;                       \
  184:         }
  185: 
  186: #endif /* __TK_SYSLIB_H__ */