gonzui


Format: Advanced Search

tkernel_2/kernel/tkernel/src/timer.hbare sourcepermlink (0.03 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 TRON Forum(http://www.tron.org/) at 2015/06/01.
   11:  *
   12:  *----------------------------------------------------------------------
   13:  */
   14: 
   15: /*
   16:  *      timer.h (T-Kernel/OS)
   17:  *      Timer Module Definition
   18:  */
   19: 
   20: #ifndef _TIMER_
   21: #define _TIMER_
   22: 
   23: #include <longlong.h>
   24: 
   25: /*
   26:  * conversion of milliseconds and microseconds
   27:  */
   28: #define to_msec(usec)   ( ((usec) + (D)999) / 1000 ) /* round up */
   29: #define to_usec(msec)   ( (msec) * (D)1000 )
   30: 
   31: #define to_usec_tmo(ms) ( ( (ms) > 0 )? to_usec(ms): (ms) )
   32: 
   33: /*
   34:  * SYSTIM internal expression and conversion
   35:  */
   36: typedef longlong        LSYSTIM;       /* SYSTIM int. expression */
   37: 
   38: Inline LSYSTIM toLSYSTIM( CONST SYSTIM *time )
   39: {
   40:         LSYSTIM                ltime;
   41: 
   42:         hilo_ll(ltime, time->hi, time->lo);
   43: 
   44:         /* conversion from milliseconds to microseconds */
   45:         ltime = li_mul(ltime, 1000);
   46: 
   47:         return ltime;
   48: }
   49: 
   50: Inline SYSTIM toSYSTIM( LSYSTIM ltime, UINT *us )
   51: {
   52:         SYSTIM         time;
   53:         longlong       t;
   54: 
   55:         /* conversion from microseconds to milliseconds (truncate) */
   56:         t = li_div(ltime, 1000);
   57: 
   58:         if ( us != NULL ) {
   59:                 /* return the sub-millisecond residue in microseconds */
   60:                 *us = lltol(ll_sub(ltime, li_mul(t, 1000)));
   61:         }
   62: 
   63:         ll_hilo(time.hi, time.lo, t);
   64: 
   65:         return time;
   66: }
   67: 
   68: /*
   69:  * Definition of timer event block
   70:  */
   71: typedef void    (*CBACK)(void*);   /* Type of callback function */
   72: 
   73: typedef struct timer_event_block {
   74:         QUEUE  queue;           /* Timer event queue */
   75:         LSYSTIM        time;          /* Event time */
   76:         CBACK  callback;        /* Callback function */
   77:         void   *arg;             /* Argument to be sent to callback function */
   78: } TMEB;
   79: 
   80: /*
   81:  * Timer interrupt interval (us)
   82:  */
   83: IMPORT RELTIM_U TIMER_PERIOD;
   84: 
   85: /*
   86:  * Current time (Software clock)
   87:  */
   88: IMPORT LSYSTIM  current_time;    /* System operation time */
   89: IMPORT LSYSTIM  real_time_ofs;   /* Difference from actual time */
   90: 
   91: /* Actual time */
   92: #define real_time()     ( ll_add(current_time, real_time_ofs) )
   93: 
   94: /*
   95:  * Timer initialization and stop
   96:  */
   97: IMPORT ER   timer_initialize( void );
   98: IMPORT void timer_shutdown( void );
   99: 
  100: /*
  101:  * Obtain the time for correction
  102:  */
  103: IMPORT RELTIM_U adjust_time( void );
  104: 
  105: /*
  106:  * Register timer event onto timer queue
  107:  */
  108: IMPORT void timer_insert( TMEB *evt, TMO_U tmout, CBACK cback, void *arg );
  109: IMPORT void timer_insert_reltim( TMEB *event, RELTIM_U tmout, CBACK callback, void *arg );
  110: IMPORT void timer_insert_abs( TMEB *evt, LSYSTIM time, CBACK cback, void *arg );
  111: 
  112: /*
  113:  * Delete from timer queue
  114:  */
  115: Inline void timer_delete( TMEB *event )
  116: {
  117:         QueRemove(&event->queue);
  118: }
  119: 
  120: #endif /* _TIMER_ */