gonzui


Format: Advanced Search

mtkernel_3/kernel/tkernel/time_calls.hbare sourcepermlink (0.03 seconds)

Search this content:

    1: /*
    2:  *----------------------------------------------------------------------
    3:  *    micro T-Kernel 3.00.00
    4:  *
    5:  *    Copyright (C) 2006-2019 by Ken Sakamura.
    6:  *    This software is distributed under the T-License 2.1.
    7:  *----------------------------------------------------------------------
    8:  *
    9:  *    Released by TRON Forum(http://www.tron.org) at 2019/12/11.
   10:  *
   11:  *----------------------------------------------------------------------
   12:  */
   13: 
   14: /*
   15:  *      time_calls.h
   16:  *      Time Management Function
   17:  */
   18: 
   19: #ifndef _TIME_CALLS_H
   20: #define _TIME_CALLS_H
   21: 
   22: #define DIFF_TRON_UTC           (473385600000LL)         /* Differences between UTC and TRON-Time */
   23: 
   24: /*
   25:  * Cyclic handler control block
   26:  */
   27: typedef struct cyclic_handler_control_block {
   28:         void   *exinf;           /* Extended information */
   29:         ATR    cycatr;            /* Cyclic handler attribute */
   30:         FP     cychdr;             /* Cyclic handler address */
   31:         UINT   cycstat;  /* Cyclic handler state */
   32:         RELTIM cyctim;         /* Cyclic time */
   33:         TMEB   cyctmeb;  /* Timer event block */
   34: #if USE_OBJECT_NAME
   35:         UB     name[OBJECT_NAME_LENGTH];   /* name */
   36: #endif
   37: } CYCCB;
   38: 
   39: IMPORT CYCCB    knl_cyccb_table[]; /* Cyclic handler control block */
   40: IMPORT QUEUE    knl_free_cyccb;    /* FreeQue */
   41: 
   42: #define get_cyccb(id)   ( &knl_cyccb_table[INDEX_CYC(id)] )
   43: 
   44: 
   45: /*
   46:  * Next startup time
   47:  */
   48: Inline ABSTIM knl_cyc_next_time( CYCCB *cyccb )
   49: {
   50:         ABSTIM         tm, cur;
   51: 
   52:         cur = lltoul(knl_current_time);
   53:         tm = cyccb->cyctmeb.time + cyccb->cyctim;
   54: 
   55:         if ( knl_abstim_reached(cur, tm) ) {
   56:                 /* Adjust time to be later than current time */
   57:                 tm = ((cur - cyccb->cyctmeb.time) / cyccb->cyctim + 1) * cyccb->cyctim + cyccb->cyctmeb.time;
   58:         }
   59: 
   60:         return tm;
   61: }
   62: 
   63: IMPORT void knl_call_cychdr( CYCCB* cyccb );
   64: 
   65: /*
   66:  * Register timer event queue
   67:  */
   68: Inline void knl_cyc_timer_insert( CYCCB *cyccb, ABSTIM tm )
   69: {
   70:         knl_timer_insert_abs(&cyccb->cyctmeb, tm, (CBACK)knl_call_cychdr, cyccb);
   71: }
   72: 
   73: 
   74: /*
   75:  * Alarm handler control block
   76:  */
   77: typedef struct alarm_handler_control_block {
   78:         void   *exinf;           /* Extended information */
   79:         ATR    almatr;            /* Alarm handler attribute */
   80:         FP     almhdr;             /* Alarm handler address */
   81:         UINT   almstat;  /* Alarm handler state */
   82:         TMEB   almtmeb;  /* Timer event block */
   83: #if USE_OBJECT_NAME
   84:         UB     name[OBJECT_NAME_LENGTH];   /* name */
   85: #endif
   86: } ALMCB;
   87: /** [END Common Definitions] */
   88: 
   89: IMPORT ALMCB    knl_almcb_table[]; /* Alarm handler control block */
   90: IMPORT QUEUE    knl_free_almcb;    /* FreeQue */
   91: 
   92: #define get_almcb(id)   ( &knl_almcb_table[INDEX_ALM(id)] )
   93: 
   94: IMPORT void knl_call_almhdr( ALMCB *almcb );
   95: 
   96: /*
   97:  * Register onto timer event queue
   98:  */
   99: Inline void knl_alm_timer_insert( ALMCB *almcb, RELTIM reltim )
  100: {
  101:         ABSTIM tm;
  102: 
  103:         /* To guarantee to start the handler after the specified time, 
  104:            add TIMER_PERIOD */
  105:         tm = lltoul(knl_current_time) + reltim + TIMER_PERIOD;
  106: 
  107:         knl_timer_insert_abs(&almcb->almtmeb, tm, (CBACK)knl_call_almhdr, almcb);
  108: }
  109: 
  110: 
  111: #endif /* _TIME_CALLS_H */