mtkernel_3/kernel/sysdepend/cpu/core/rxv2/sys_timer.h | 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: /* 15: * sys_timer.h (RXv2) 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: 29: /* set Timer Count */ 30: out_h(CMT0_COR, EXTAL_CLOCK/PCLK_DIV/1000*TIMER_PERIOD/CMCR_DIV - 1); 31: 32: /* Interrupt is Enable, Set Frequency Dividing */ 33: out_h(CMT0_CR, CMT0_CR_CMIE | CMCR_CKS_PLCK8); 34: 35: /* CMI0 Interrupt Enable, Interrupt Level is 15. */ 36: EnableInt( INTNO_SYS_TICK , INTLEVEL_SYS_TICK); 37: 38: /* Start timer count */ 39: out_h(CMT_STR0, CMT_STR0_STR0); 40: } 41: 42: /* 43: * Clear timer interrupt 44: * Clear the timer interrupt request. Depending on the type of 45: * hardware, there are two timings for clearing: at the beginning 46: * and the end of the interrupt handler. 47: * 'clear_hw_timer_interrupt()' is called at the beginning of the 48: * timer interrupt handler. 49: * 'end_of_hw_timer_interrupt()' is called at the end of the timer 50: * interrupt handler. 51: * Use either or both according to hardware. 52: */ 53: Inline void knl_clear_hw_timer_interrupt( void ) 54: { 55: /* Nothing required to do at this point */ 56: } 57: 58: Inline void knl_end_of_hw_timer_interrupt( void ) 59: { 60: /* Nothing required to do at this point */ 61: } 62: 63: /* 64: * Timer stop processing 65: * Stop the timer operation. 66: * Called when system stops. 67: */ 68: Inline void knl_terminate_hw_timer( void ) 69: { 70: UH cmstr0; 71: 72: DisableInt( INTNO_SYS_TICK ); /* Disable timer interrupt */ 73: 74: out_h(CMT0_CR, 0); /* Disable compare match interrupt */ 75: cmstr0 = in_h(CMT_STR0) & ~(CMT_STR0_STR0); 76: out_h(CMT_STR0, cmstr0); /* Stop timer count */ 77: } 78: 79: /* 80: * Get processing time from the previous timer interrupt to the 81: * current (nanosecond) 82: * Consider the possibility that the timer interrupt occurred 83: * during the interrupt disable and calculate the processing time 84: * within the following 85: * range: 0 <= Processing time < TIMER_PERIOD * 2 86: */ 87: Inline UW knl_get_hw_timer_nsec( void ) 88: { 89: UW ofs, max; 90: UB unf; 91: UINT imask; 92: 93: DI(imask); 94: 95: max = in_h(CMT0_COR) + 1; /* Timer Count */ 96: do { 97: unf = CheckInt(INTNO_SYS_TICK); /* Get Interrupt Status */ 98: ofs = in_h(CMT0_CNT); /* Current Count */ 99: } while ( unf != CheckInt(INTNO_SYS_TICK)); /* Check Interrupt Status */ 100: if ( unf != 0 ) { 101: ofs += max; 102: } 103: 104: EI(imask); 105: 106: return ofs * 1000 * CMCR_DIV / (EXTAL_CLOCK/MHz/PCLK_DIV); 107: } 108: 109: #endif /* _SYSDEPEND_CPU_CORE_SYSTIMER_ */