gonzui


Format: Advanced Search

mtkernel_3/lib/libtk/sysdepend/cpu/core/armv7m/wusec_armv7m.cbare sourcepermlink (0.02 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: #include <sys/machine.h>
   15: #ifdef CPU_CORE_ARMV7M
   16: 
   17: /*
   18:  *      waitusec_armv7m.c
   19:  *
   20:  *      Micro Wait: Busy loop wait time in micro-sec (ARMv7M)
   21:  */
   22: 
   23: #include <tk/tkernel.h>
   24: #include <config.h>
   25: 
   26: LOCAL void wait_us( UW usec )
   27: {
   28:         UW     max, pre, cur, ofs, rem;
   29: 
   30:         max = in_w(SYST_RVR);
   31:         rem = max * usec / (TIMER_PERIOD * 1000) + 1;
   32: 
   33:         cur = in_w(SYST_CVR) & 0x00ffffff;
   34: 
   35:         for ( ;; ) {
   36:                 pre = cur;
   37:                 cur = in_w(SYST_CVR) & 0x00ffffff;
   38: 
   39:                 ofs = (pre >= cur) ? (pre - cur) : (pre + max - cur);
   40:                 if ( ofs >= rem ) {
   41:                         break;
   42:                 }
   43:                 rem -= ofs;
   44:         }
   45: }
   46: 
   47: /* maximum time (in microseconds) that wait_us() can handle at a time */
   48: #define WAIT_US_STEP 10000
   49: 
   50: EXPORT void WaitUsec( UW usec )
   51: {
   52:         for ( ; usec >= WAIT_US_STEP; usec -= WAIT_US_STEP ) {
   53:                 wait_us(WAIT_US_STEP);
   54:         }
   55:         wait_us(usec);
   56: }
   57: 
   58: EXPORT void WaitNsec( UW nsec )
   59: {
   60:         for ( ; nsec >= (WAIT_US_STEP * 1000); nsec -= (WAIT_US_STEP * 1000) ) {
   61:                 wait_us(WAIT_US_STEP);
   62:         }
   63:         wait_us(nsec / 1000 + 1);
   64: }
   65: 
   66: #endif /* CPU_CORE_ARMV7M */