mtkernel_3/lib/libtk/sysdepend/cpu/core/rxv2/wusec_rvx2.c | bare source | permlink (0.00 seconds) |
1: /* 2: *---------------------------------------------------------------------- 3: * micro T-Kernel 3.00.01 4: * 5: * Copyright (C) 2006-2020 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 2020/05/29. 10: * 11: *---------------------------------------------------------------------- 12: */ 13: 14: #include <sys/machine.h> 15: #ifdef CPU_CORE_RXV2 16: 17: /* 18: * waitusec.c 19: * 20: * Micro Wait: Busy loop wait time in micro-sec (RXv2 Core) 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 = *(_UH*)(CMT0_COR) + 1; 31: rem = max * usec / (TIMER_PERIOD * 1000); 32: 33: cur = *(_UH*)CMT0_CNT; 34: 35: for ( ;; ) { 36: pre = cur; 37: cur = *(_UH*)CMT0_CNT; 38: 39: ofs = (pre <= cur) ? (cur - pre) : (max + cur - pre); 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_RXV2 */