mtkernel_3/kernel/sysdepend/cpu/core/armv7a/sys_timer.h | bare source | permlink (0.00 seconds) |
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: * sys_timer.h (ARMv7-A) 16: * Hardware-Dependent System Timer (SysTick) Processing 17: */ 18: 19: #ifndef _SYSDEPEND_CPU_CORE_SYSTIMER_ 20: #define _SYSDEPEND_CPU_CORE_SYSTIMER_ 21: 22: /* 23: * Timer start processing 24: * Initialize the timer and start the periodical timer interrupt. 25: */ 26: Inline void knl_start_hw_timer( void ) 27: { 28: UINT imask; 29: UD cnt; 30: 31: DI(imask); 32: 33: /* Convert microseconds to timer values */ 34: cnt = (((TIMER_PERIOD * 1000) * COUNT_PER_SEC) / 1000000LL); 35: 36: out_b(OSTM0_TT, 0x01); /* Stop timer */ 37: out_b(OSTM0_CTL, 0x01); /* Set Interval timer mode & Interrupt enabled */ 38: out_w(OSTM0_CMP, (UW)cnt); /* Set compare register */ 39: out_b(OSTM0_TS, 0x01); /* Start Timer */ 40: 41: EnableInt(INTNO_SYSTICK, INTPRI_SYSTICK); /* Enable interrupt(INTC level) */ 42: 43: EI(imask); 44: } 45: 46: /* 47: * Clear timer interrupt 48: * Clear the timer interrupt request. Depending on the type of 49: * hardware, there are two timings for clearing: at the beginning 50: * and the end of the interrupt handler. 51: * 'clear_hw_timer_interrupt()' is called at the beginning of the 52: * timer interrupt handler. 53: * 'end_of_hw_timer_interrupt()' is called at the end of the timer 54: * interrupt handler. 55: * Use either or both according to hardware. 56: */ 57: Inline void knl_clear_hw_timer_interrupt( void ) 58: { 59: } 60: 61: Inline void knl_end_of_hw_timer_interrupt( void ) 62: { 63: disint(); /* disint() in front of the EOI to prevent inadvertent interrupts. */ 64: EndOfInt(INTNO_SYSTICK); 65: } 66: 67: /* 68: * Timer stop processing 69: * Stop the timer operation. 70: * Called when system stops. 71: */ 72: Inline void knl_terminate_hw_timer( void ) 73: { 74: out_b(OSTM0_TT, 0x01); /* Stop Timer */ 75: } 76: 77: /* 78: * Get processing time from the previous timer interrupt to the 79: * current (nanosecond) 80: * Consider the possibility that the timer interrupt occurred 81: * during the interrupt disable and calculate the processing time 82: * within the following 83: * range: 0 <= Processing time < CFN_TIMER_PERIOD 84: */ 85: Inline UW knl_get_hw_timer_nsec( void ) 86: { 87: UW ofs, max; 88: 89: max = in_w(OSTM0_CMP); /* Timer cycle value */ 90: ofs = in_w(OSTM0_CNT); /* Current timer value (Down count) */ 91: 92: return ((max - ofs) * NSEC_PER_COUNT); 93: } 94: 95: #endif /* _SYSDEPEND_CPU_CORE_SYSTIMER_ */