Changeset 75acd9e in rtems
- Timestamp:
- 04/01/15 13:33:25 (7 years ago)
- Branches:
- 4.11, 5, master
- Children:
- a9c4f15d
- Parents:
- 7cd2484
- git-author:
- Alexander Krutwig <alexander.krutwig@…> (04/01/15 13:33:25)
- git-committer:
- Sebastian Huber <sebastian.huber@…> (05/20/15 06:40:34)
- Location:
- c/src/lib
- Files:
-
- 48 edited
Legend:
- Unmodified
- Added
- Removed
-
c/src/lib/libbsp/arm/beagle/clock.c
r7cd2484 r75acd9e 16 16 17 17 #include <rtems.h> 18 #include <rtems/timecounter.h> 18 19 #include <bsp.h> 19 20 20 21 #include <libcpu/omap_timer.h> 21 22 22 #ifdef ARM_MULTILIB_ARCH_V4 23 static struct timecounter beagle_clock_tc; 23 24 24 25 static omap_timer_registers_t regs_v1 = { … … 116 117 #endif 117 118 118 static int done = 0;119 120 119 #if IS_AM335X 121 120 #define FRCLOCK_HZ (16*1500000) … … 182 181 mmio_set(fr_timer->base + fr_timer->regs->TCLR, 183 182 OMAP3_TCLR_OVF_TRG | OMAP3_TCLR_AR | OMAP3_TCLR_ST); 184 done = 1; 185 } 186 187 static inline uint32_t 188 read_frc(void) 189 { 190 if (done == 0) { 191 return 0; 192 } 183 } 184 185 static uint32_t 186 beagle_clock_get_timecount(struct timecounter *tc) 187 { 193 188 return mmio_read(fr_timer->base + fr_timer->regs->TCRR); 194 189 } 195 196 static uint32_t last_tick_nanoseconds;197 190 198 191 static void … … 263 256 #endif 264 257 258 /* Install timecounter */ \ 259 beagle_clock_tc.tc_get_timecount = beagle_clock_get_timecount; 260 beagle_clock_tc.tc_counter_mask = 0xffffffff; 261 beagle_clock_tc.tc_frequency = FRCLOCK_HZ; 262 beagle_clock_tc.tc_quality = RTEMS_TIMECOUNTER_QUALITY_CLOCK_DRIVER; 263 rtems_timecounter_install(&beagle_clock_tc); 265 264 } 266 265 267 266 static void beagle_clock_at_tick(void) 268 267 { 269 last_tick_nanoseconds = read_frc();270 271 268 mmio_write(timer->base + timer->regs->TISR, 272 269 OMAP3_TISR_MAT_IT_FLAG | OMAP3_TISR_OVF_IT_FLAG | … … 316 313 } 317 314 318 static inline uint32_t beagle_clock_nanoseconds_since_last_tick(void)319 {320 /* this arithmetic also works if read_frc() wraps around, as long321 * as the subtraction wraps around too322 */323 return (read_frc() - (uint64_t) last_tick_nanoseconds) * 1000000000 / FRCLOCK_HZ;324 }325 326 315 #define Clock_driver_support_at_tick() beagle_clock_at_tick() 327 316 #define Clock_driver_support_initialize_hardware() beagle_clock_initialize() … … 333 322 334 323 #define Clock_driver_support_shutdown_hardware() beagle_clock_cleanup() 335 #define Clock_driver_nanoseconds_since_last_tick \336 beagle_clock_nanoseconds_since_last_tick337 324 338 325 /* Include shared source clock driver code */ 339 326 #include "../../shared/clockdrv_shell.h" 340 341 #endif /* ARM_MULTILIB_ARCH_V4 */ -
c/src/lib/libbsp/arm/edb7312/clock/clockdrv.c
r7cd2484 r75acd9e 69 69 } while (0) 70 70 71 #define CLOCK_DRIVER_USE_DUMMY_TIMECOUNTER 72 71 73 #include "../../../shared/clockdrv_shell.h" -
c/src/lib/libbsp/arm/gba/clock/clockdrv.c
r7cd2484 r75acd9e 93 93 } 94 94 95 #define CLOCK_DRIVER_USE_DUMMY_TIMECOUNTER 96 95 97 #include "../../../shared/clockdrv_shell.h" -
c/src/lib/libbsp/arm/lpc176x/include/lpc-clock-config.h
r7cd2484 r75acd9e 34 34 #define LPC_CLOCK_INTERRUPT LPC176X_IRQ_TIMER_0 35 35 #define LPC_CLOCK_TIMER_BASE TMR0_BASE_ADDR 36 #define LPC_CLOCK_TIMECOUNTER_BASE TMR1_BASE_ADDR 36 37 #define LPC_CLOCK_REFERENCE LPC176X_PCLK 37 38 #define LPC_CLOCK_MODULE_ENABLE() \ -
c/src/lib/libbsp/arm/lpc24xx/include/lpc-clock-config.h
r7cd2484 r75acd9e 36 36 #define LPC_CLOCK_TIMER_BASE TMR0_BASE_ADDR 37 37 38 #define LPC_CLOCK_TIMECOUNTER_BASE TMR1_BASE_ADDR 39 38 40 #define LPC_CLOCK_REFERENCE LPC24XX_PCLK 39 41 -
c/src/lib/libbsp/arm/lpc32xx/include/lpc-clock-config.h
r7cd2484 r75acd9e 45 45 #define LPC_CLOCK_TIMER_BASE LPC32XX_BASE_TIMER_0 46 46 47 #define LPC_CLOCK_TIMECOUNTER_BASE LPC32XX_BASE_TIMER_1 48 47 49 #define LPC_CLOCK_REFERENCE LPC32XX_PERIPH_CLK 48 50 -
c/src/lib/libbsp/arm/nds/clock/clock.c
r7cd2484 r75acd9e 82 82 } 83 83 84 #define CLOCK_DRIVER_USE_DUMMY_TIMECOUNTER 85 84 86 #include "../../../shared/clockdrv_shell.h" -
c/src/lib/libbsp/arm/raspberrypi/clock/clockdrv.c
r7cd2484 r75acd9e 73 73 } 74 74 75 /*76 * Return the nanoseconds since last tick77 */78 static uint32_t raspberrypi_clock_nanoseconds_since_last_tick(void)79 {80 return 0;81 }82 83 75 #define Clock_driver_support_at_tick() raspberrypi_clock_at_tick() 84 76 … … 93 85 #define Clock_driver_support_shutdown_hardware() raspberrypi_clock_cleanup() 94 86 95 #define Clock_driver_nanoseconds_since_last_tick \ 96 raspberrypi_clock_nanoseconds_since_last_tick 97 87 #define CLOCK_DRIVER_USE_DUMMY_TIMECOUNTER 98 88 99 89 #include "../../../shared/clockdrv_shell.h" -
c/src/lib/libbsp/arm/shared/arm-a9mpcore-clock-config.c
r7cd2484 r75acd9e 1 1 /* 2 * Copyright (c) 2013-201 4embedded brains GmbH. All rights reserved.2 * Copyright (c) 2013-2015 embedded brains GmbH. All rights reserved. 3 3 * 4 4 * embedded brains GmbH … … 18 18 #include <bsp/arm-a9mpcore-regs.h> 19 19 #include <bsp/arm-a9mpcore-clock.h> 20 #include <rtems/timecounter.h> 20 21 21 22 #define A9MPCORE_GT ((volatile a9mpcore_gt *) BSP_ARM_A9MPCORE_GT_BASE) 22 23 23 static uint64_t a9mpcore_clock_last_tick_k; 24 25 static uint32_t a9mpcore_clock_last_tick_cmpvallower; 26 27 static uint32_t a9mpcore_clock_autoinc; 24 static struct timecounter a9mpcore_tc; 28 25 29 26 /* This is defined in clockdrv_shell.h */ … … 39 36 { 40 37 volatile a9mpcore_gt *gt = A9MPCORE_GT; 41 42 /*43 * FIXME: Now the _TOD_Get_with_nanoseconds() yields wrong values until44 * _TOD_Tickle_ticks() managed to update the uptime. See also PR2180.45 */46 a9mpcore_clock_last_tick_cmpvallower =47 gt->cmpvallower - a9mpcore_clock_autoinc;48 38 49 39 gt->irqst = A9MPCORE_GT_IRQST_EFLG; … … 81 71 } 82 72 73 static uint32_t a9mpcore_clock_get_timecount(struct timecounter *tc) 74 { 75 volatile a9mpcore_gt *gt = A9MPCORE_GT; 76 77 return gt->cntrlower; 78 } 79 83 80 static void a9mpcore_clock_initialize(void) 84 81 { … … 99 96 gt->autoinc = interval; 100 97 101 a9mpcore_clock_last_tick_k = (UINT64_C(1000000000) << 32) / periphclk;102 a9mpcore_clock_last_tick_cmpvallower = (uint32_t) cmpval - interval;103 a9mpcore_clock_autoinc = interval;104 105 98 gt->ctrl = A9MPCORE_GT_CTRL_AUTOINC_EN 106 99 | A9MPCORE_GT_CTRL_IRQ_EN 107 100 | A9MPCORE_GT_CTRL_COMP_EN 108 101 | A9MPCORE_GT_CTRL_TMR_EN; 102 103 a9mpcore_tc.tc_get_timecount = a9mpcore_clock_get_timecount; 104 a9mpcore_tc.tc_counter_mask = 0xffffffff; 105 a9mpcore_tc.tc_frequency = periphclk; 106 a9mpcore_tc.tc_quality = RTEMS_TIMECOUNTER_QUALITY_CLOCK_DRIVER; 107 rtems_timecounter_install(&a9mpcore_tc); 109 108 } 110 109 … … 148 147 } 149 148 150 static uint32_t a9mpcore_clock_nanoseconds_since_last_tick(void)151 {152 volatile a9mpcore_gt *gt = A9MPCORE_GT;153 uint64_t k = a9mpcore_clock_last_tick_k;154 uint32_t n = a9mpcore_clock_last_tick_cmpvallower;155 uint32_t c = gt->cntrlower;156 157 return (uint32_t) (((c - n) * k) >> 32);158 }159 160 149 #define Clock_driver_support_at_tick() \ 161 150 a9mpcore_clock_at_tick() … … 166 155 #define Clock_driver_support_install_isr(isr, old_isr) \ 167 156 do { \ 168 a9mpcore_clock_handler_install(); 157 a9mpcore_clock_handler_install(); \ 169 158 old_isr = NULL; \ 170 159 } while (0) … … 173 162 a9mpcore_clock_cleanup() 174 163 175 #define Clock_driver_nanoseconds_since_last_tick \176 a9mpcore_clock_nanoseconds_since_last_tick177 178 164 /* Include shared source clock driver code */ 179 165 #include "../../shared/clockdrv_shell.h" -
c/src/lib/libbsp/arm/shared/armv7m/clock/armv7m-clock-config.c
r7cd2484 r75acd9e 14 14 15 15 #include <rtems.h> 16 #include <rtems/timecounter.h> 16 17 #include <rtems/score/armv7m.h> 17 18 … … 23 24 static void Clock_isr(void *arg); 24 25 25 #define _ARMV7M_Systick_get_factor(freq) \ 26 ((1000000000ULL << 32) / (freq)) 26 static rtems_timecounter_simple _ARMV7M_TC; 27 27 28 #ifdef BSP_ARMV7M_SYSTICK_FREQUENCY 29 #define _ARMV7M_Systick_factor \ 30 _ARMV7M_Systick_get_factor(BSP_ARMV7M_SYSTICK_FREQUENCY) 31 #else 32 static uint64_t _ARMV7M_Systick_factor; 33 #endif 28 static uint32_t _ARMV7M_TC_get(rtems_timecounter_simple *tc) 29 { 30 volatile ARMV7M_Systick *systick = _ARMV7M_Systick; 31 32 return systick->cvr; 33 } 34 35 static bool _ARMV7M_TC_is_pending(rtems_timecounter_simple *tc) 36 { 37 volatile ARMV7M_SCB *scb = _ARMV7M_SCB; 38 39 return ((scb->icsr & ARMV7M_SCB_ICSR_PENDSTSET) != 0); 40 } 41 42 static uint32_t _ARMV7M_TC_get_timecount(struct timecounter *tc) 43 { 44 return rtems_timecounter_simple_downcounter_get( 45 tc, 46 _ARMV7M_TC_get, 47 _ARMV7M_TC_is_pending 48 ); 49 } 50 51 static void _ARMV7M_TC_tick(void) 52 { 53 rtems_timecounter_simple_downcounter_tick(&_ARMV7M_TC, _ARMV7M_TC_get); 54 } 34 55 35 56 static void _ARMV7M_Systick_at_tick(void) … … 68 89 uint64_t interval = (freq * us_per_tick) / 1000000ULL; 69 90 70 #ifndef BSP_ARMV7M_SYSTICK_FREQUENCY71 _ARMV7M_Systick_factor = _ARMV7M_Systick_get_factor(freq);72 #endif73 74 91 systick->rvr = (uint32_t) interval; 75 92 systick->cvr = 0; … … 77 94 | ARMV7M_SYSTICK_CSR_TICKINT 78 95 | ARMV7M_SYSTICK_CSR_CLKSOURCE; 96 97 rtems_timecounter_simple_install( 98 &_ARMV7M_TC, 99 freq, 100 interval, 101 _ARMV7M_TC_get_timecount 102 ); 79 103 } 80 104 … … 86 110 } 87 111 88 static uint32_t _ARMV7M_Systick_nanoseconds_since_last_tick(void) 89 { 90 volatile ARMV7M_Systick *systick = _ARMV7M_Systick; 91 volatile ARMV7M_SCB *scb = _ARMV7M_SCB; 92 uint32_t rvr = systick->rvr; 93 uint32_t c = rvr - systick->cvr; 94 95 if ((scb->icsr & ARMV7M_SCB_ICSR_PENDSTSET) != 0) { 96 c = rvr - systick->cvr + rvr; 97 } 98 99 return (uint32_t) ((c * _ARMV7M_Systick_factor) >> 32); 100 } 112 #define Clock_driver_timecounter_tick() _ARMV7M_TC_tick() 101 113 102 114 #define Clock_driver_support_at_tick() \ … … 115 127 _ARMV7M_Systick_cleanup() 116 128 117 #define Clock_driver_nanoseconds_since_last_tick \118 _ARMV7M_Systick_nanoseconds_since_last_tick119 120 129 /* Include shared source clock driver code */ 121 130 #include "../../../../shared/clockdrv_shell.h" -
c/src/lib/libbsp/arm/shared/lpc/clock/lpc-clock-config.c
r7cd2484 r75acd9e 8 8 9 9 /* 10 * Copyright (c) 2009-201 2embedded brains GmbH. All rights reserved.10 * Copyright (c) 2009-2015 embedded brains GmbH. All rights reserved. 11 11 * 12 12 * embedded brains GmbH 13 * Obere Lagerstr. 3013 * Dornierstr. 4 14 14 * 82178 Puchheim 15 15 * Germany … … 22 22 23 23 #include <rtems.h> 24 #include <rtems/timecounter.h> 24 25 25 26 #include <bsp/lpc-clock-config.h> … … 33 34 static volatile lpc_timer *const lpc_clock = 34 35 (volatile lpc_timer *) LPC_CLOCK_TIMER_BASE; 36 37 static volatile lpc_timer *const lpc_timecounter = 38 (volatile lpc_timer *) LPC_CLOCK_TIMECOUNTER_BASE; 39 40 static struct timecounter lpc_clock_tc; 41 42 static uint32_t lpc_clock_tc_get_timecount(struct timecounter *tc) 43 { 44 return lpc_timecounter->tc; 45 } 35 46 36 47 static void lpc_clock_at_tick(void) … … 57 68 static void lpc_clock_initialize(void) 58 69 { 70 uint32_t mask; 59 71 uint64_t interval = ((uint64_t) LPC_CLOCK_REFERENCE 60 72 * (uint64_t) rtems_configuration_get_microseconds_per_tick()) / 1000000; … … 86 98 /* Enable timer */ 87 99 lpc_clock->tcr = LPC_TIMER_TCR_EN; 100 101 /* Install timecounter */ 102 lpc_clock_tc.tc_get_timecount = lpc_clock_tc_get_timecount; 103 lpc_clock_tc.tc_counter_mask = 0xffffffff; 104 lpc_clock_tc.tc_frequency = LPC_CLOCK_REFERENCE; 105 lpc_clock_tc.tc_quality = RTEMS_TIMECOUNTER_QUALITY_CLOCK_DRIVER; 106 rtems_timecounter_install(&lpc_clock_tc); 88 107 } 89 108 … … 106 125 } 107 126 108 static uint32_t lpc_clock_nanoseconds_since_last_tick(void)109 {110 uint64_t k = (1000000000ULL << 32) / LPC_CLOCK_REFERENCE;111 uint64_t c = lpc_clock->tc;112 113 if ((lpc_clock->ir & LPC_TIMER_IR_MR0) != 0) {114 c = lpc_clock->tc + lpc_clock->mr0;115 }116 117 return (uint32_t) ((c * k) >> 32);118 }119 120 127 #define Clock_driver_support_at_tick() lpc_clock_at_tick() 121 128 #define Clock_driver_support_initialize_hardware() lpc_clock_initialize() … … 127 134 128 135 #define Clock_driver_support_shutdown_hardware() lpc_clock_cleanup() 129 #define Clock_driver_nanoseconds_since_last_tick \130 lpc_clock_nanoseconds_since_last_tick131 136 132 137 /* Include shared source clock driver code */ -
c/src/lib/libbsp/arm/tms570/clock/clock.c
r7cd2484 r75acd9e 31 31 #include <bsp/tms570-rti.h> 32 32 #include <rtems/counter.h> 33 #include <rtems/timecounter.h> 33 34 34 /** 35 * holds HW counter value since last interrupt event 36 * sets in tms570_clock_driver_support_at_tick 37 * used in tms570_clock_driver_nanoseconds_since_last_tick 38 */39 static uint32_t tms570_rti_last_tick_fcr0; 35 static struct timecounter tms570_rti_tc; 36 37 static uint32_t tms570_rti_get_timecount(struct timecounter tc) 38 { 39 return TMS570_RTI.RTIFRC0; 40 } 40 41 41 42 /** … … 73 74 /* enable timer */ 74 75 TMS570_RTI.RTIGCTRL = 1; 76 /* set timecounter */ 77 tms570_rti_tc.tc_get_timecount = tms570_rti_get_timecount; 78 tms570_rti_tc.tc_counter_mask = 0xffffffff; 79 tms570_rti_tc.tc_frequency = BSP_PLL_OUT_CLOCK; 80 tms570_rti_tc.tc_quality = RTEMS_TIMECOUNTER_QUALITY_CLOCK_DRIVER; 81 rtems_timecounter_install(&tms570_rti_tc); 75 82 } 76 83 … … 83 90 { 84 91 TMS570_RTI.RTIINTFLAG = 0x00000001; 85 tms570_rti_last_tick_fcr0 = TMS570_RTI.RTICOMP0 - TMS570_RTI.RTIUDCP0;86 92 } 87 93 … … 125 131 } 126 132 127 /**128 * @brief returns the nanoseconds since last tick129 *130 * Return the nanoseconds since last tick131 *132 * @retval x nanoseconds133 *134 */135 static uint32_t tms570_clock_driver_nanoseconds_since_last_tick( void )136 {137 uint32_t actual_fcr0 = TMS570_RTI.RTIFRC0;138 uint32_t usec_since_tick;139 140 usec_since_tick = actual_fcr0 - tms570_rti_last_tick_fcr0;141 142 return usec_since_tick * 1000;143 }144 145 133 #define Clock_driver_support_initialize_hardware \ 146 134 tms570_clock_driver_support_initialize_hardware … … 151 139 #define Clock_driver_support_shutdown_hardware \ 152 140 tms570_clock_driver_support_shutdown_hardware 153 #define Clock_driver_nanoseconds_since_last_tick \154 tms570_clock_driver_nanoseconds_since_last_tick155 141 156 142 #define Clock_driver_support_install_isr(Clock_isr, Old_ticker ) \ -
c/src/lib/libbsp/i386/pc386/clock/ckinit.c
r7cd2484 r75acd9e 29 29 #include <libcpu/cpuModel.h> 30 30 #include <assert.h> 31 #include <rtems/timecounter.h> 31 32 32 33 #define CLOCK_VECTOR 0 … … 40 41 static void Clock_driver_support_at_tick_empty(void); 41 42 static void clockOff(void); 42 static void Clock_driver_support_at_tick_tsc(void);43 static uint32_t bsp_clock_nanoseconds_since_last_tick_tsc(void);44 static uint32_t bsp_clock_nanoseconds_since_last_tick_i8254(void);45 43 static void Clock_isr_handler(void *param); 46 44 47 45 /* 48 * Roughly the number of cycles per tick and per nanosecond. Note that these46 * Roughly the number of cycles per second. Note that these 49 47 * will be wildly inaccurate if the chip speed changes due to power saving 50 48 * or thermal modes. … … 52 50 * NOTE: These are only used when the TSC method is used. 53 51 */ 54 uint64_t pc586_tsc_per_tick; 55 uint64_t pc586_nanoseconds_per_tick; 56 57 uint64_t pc586_tsc_at_tick; 52 static uint64_t pc586_tsc_frequency; 53 54 static struct timecounter pc386_tc; 58 55 59 56 /* this driver may need to count ISRs per tick */ … … 61 58 #define CLOCK_DRIVER_ISRS_PER_TICK_VALUE pc386_isrs_per_tick 62 59 63 /* The driver uses the count in Clock_driver_support_at_tick */ 64 extern volatile uint32_t Clock_driver_isrs; 60 extern volatile uint32_t Clock_driver_ticks; 65 61 66 62 #define READ_8254( _lsb, _msb ) \ … … 75 71 * tick method is preferred. 76 72 */ 77 void (*Clock_driver_support_at_tick)(void) = NULL; 78 uint32_t (*Clock_driver_nanoseconds_since_last_tick)(void) = NULL; 79 80 /* 81 * What do we do at each clock tick? 82 */ 83 static void Clock_driver_support_at_tick_tsc(void) 84 { 85 pc586_tsc_at_tick = rdtsc(); 86 } 87 88 static void Clock_driver_support_at_tick_empty(void) 89 { 90 } 73 #define Clock_driver_support_at_tick() 91 74 92 75 #define Clock_driver_support_install_isr( _new, _old ) \ … … 95 78 } while(0) 96 79 97 /* 98 * Get nanoseconds using Pentium-compatible TSC register 99 */ 100 static uint32_t bsp_clock_nanoseconds_since_last_tick_tsc(void) 101 { 102 uint64_t diff_nsec; 103 104 diff_nsec = rdtsc() - pc586_tsc_at_tick; 105 106 /* 107 * At this point, with a hypothetical 10 GHz CPU clock and 100 Hz tick 108 * clock, diff_nsec <= 27 bits. 109 */ 110 diff_nsec *= pc586_nanoseconds_per_tick; /* <= 54 bits */ 111 diff_nsec /= pc586_tsc_per_tick; 112 113 if (diff_nsec > pc586_nanoseconds_per_tick) 114 /* 115 * Hmmm... Some drift or rounding. Pin the value to 1 nanosecond before 116 * the next tick. 117 */ 118 /* diff_nsec = pc586_nanoseconds_per_tick - 1; */ 119 diff_nsec = 12345; 120 121 return (uint32_t)diff_nsec; 122 } 123 124 /* 125 * Get nanoseconds using 8254 timer chip 126 */ 127 static uint32_t bsp_clock_nanoseconds_since_last_tick_i8254(void) 128 { 129 uint32_t usecs, clicks, isrs; 130 uint32_t usecs1, usecs2; 80 static uint32_t pc386_get_timecount_tsc(struct timecounter *tc) 81 { 82 return (uint32_t)rdtsc(); 83 } 84 85 static uint32_t pc386_get_timecount_i8254(struct timecounter *tc) 86 { 87 uint32_t irqs; 131 88 uint8_t lsb, msb; 132 89 rtems_interrupt_level level; … … 137 94 rtems_interrupt_disable(level); 138 95 READ_8254(lsb, msb); 139 i srs = Clock_driver_isrs;96 irqs = Clock_driver_ticks; 140 97 rtems_interrupt_enable(level); 141 98 142 /* 143 * Now do the math 144 */ 145 /* convert values read into counter clicks */ 146 clicks = ((msb << 8) | lsb); 147 148 /* whole ISRs we have done since the last tick */ 149 usecs1 = (pc386_isrs_per_tick - isrs - 1) * pc386_microseconds_per_isr; 150 151 /* the partial ISR we in the middle of now */ 152 usecs2 = pc386_microseconds_per_isr - TICK_TO_US(clicks); 153 154 /* total microseconds */ 155 usecs = usecs1 + usecs2; 156 #if 0 157 printk( "usecs1=%d usecs2=%d ", usecs1, usecs2 ); 158 printk( "maxclicks=%d clicks=%d ISRs=%d ISRsper=%d usersPer=%d usecs=%d\n", 159 pc386_clock_click_count, clicks, 160 Clock_driver_isrs, pc386_isrs_per_tick, 161 pc386_microseconds_per_isr, usecs ); 162 #endif 163 164 /* return it in nanoseconds */ 165 return usecs * 1000; 166 99 return (irqs + 1) * pc386_microseconds_per_isr - ((msb << 8) | lsb); 167 100 } 168 101 … … 175 108 uint8_t then_lsb, then_msb, now_lsb, now_msb; 176 109 uint32_t i; 177 178 pc586_nanoseconds_per_tick =179 rtems_configuration_get_microseconds_per_tick() * 1000;180 110 181 111 /* … … 205 135 } 206 136 207 pc586_tsc_per_tick = rdtsc() - begin_time; 208 209 /* Initialize "previous tick" counters */ 210 pc586_tsc_at_tick = rdtsc(); 137 pc586_tsc_frequency = rdtsc() - begin_time; 211 138 212 139 #if 0 213 printk( "CPU clock at %u MHz\n", (uint32_t)(pc586_tsc_ per_tick/ 1000000));140 printk( "CPU clock at %u MHz\n", (uint32_t)(pc586_tsc_frequency / 1000000)); 214 141 #endif 215 216 pc586_tsc_per_tick /= rtems_clock_get_ticks_per_second();217 142 } 218 143 … … 300 225 if ( use_8254 ) { 301 226 /* printk( "Use 8254\n" ); */ 302 Clock_driver_support_at_tick = Clock_driver_support_at_tick_empty;303 Clock_driver_nanoseconds_since_last_tick =304 bsp_clock_nanoseconds_since_last_tick_i8254;227 pc386_tc.tc_get_timecount = pc386_get_timecount_i8254; 228 pc386_tc.tc_counter_mask = 0xffffffff; 229 pc386_tc.tc_frequency = TIMER_TICK; 305 230 } else { 306 231 /* printk( "Use TSC\n" ); */ 307 Clock_driver_support_at_tick = Clock_driver_support_at_tick_tsc; 308 Clock_driver_nanoseconds_since_last_tick = 309 bsp_clock_nanoseconds_since_last_tick_tsc; 310 } 311 312 /* Shell installs nanosecond handler before calling 313 * Clock_driver_support_initialize_hardware() :-( 314 * so we do it again now that we're ready. 315 */ 316 rtems_clock_set_nanoseconds_extension( 317 Clock_driver_nanoseconds_since_last_tick 318 ); 319 232 pc386_tc.tc_get_timecount = pc386_get_timecount_tsc; 233 pc386_tc.tc_counter_mask = 0xffffffff; 234 pc386_tc.tc_frequency = pc586_tsc_frequency; 235 } 236 237 pc386_tc.tc_quality = RTEMS_TIMECOUNTER_QUALITY_CLOCK_DRIVER; 238 rtems_timecounter_install(&pc386_tc); 320 239 Clock_isr_enabled = true; 321 240 } -
c/src/lib/libbsp/lm32/shared/clock/ckinit.c
r7cd2484 r75acd9e 76 76 } 77 77 78 #define CLOCK_DRIVER_USE_DUMMY_TIMECOUNTER 79 78 80 #include "../../../shared/clockdrv_shell.h" 79 81 -
c/src/lib/libbsp/lm32/shared/milkymist_clock/ckinit.c
r7cd2484 r75acd9e 47 47 } 48 48 49 #define CLOCK_DRIVER_USE_DUMMY_TIMECOUNTER 50 49 51 #include "../../../shared/clockdrv_shell.h" -
c/src/lib/libbsp/m68k/av5282/clock/clock.c
r7cd2484 r75acd9e 59 59 } while (0) 60 60 61 #define CLOCK_DRIVER_USE_DUMMY_TIMECOUNTER 62 61 63 #include "../../../shared/clockdrv_shell.h" -
c/src/lib/libbsp/m68k/gen68360/clock/clock.c
r7cd2484 r75acd9e 99 99 } while (0) 100 100 101 #define CLOCK_DRIVER_USE_DUMMY_TIMECOUNTER 102 101 103 #include "../../../shared/clockdrv_shell.h" -
c/src/lib/libbsp/m68k/genmcf548x/clock/clock.c
r7cd2484 r75acd9e 99 99 } while (0) 100 100 101 #define CLOCK_DRIVER_USE_DUMMY_TIMECOUNTER 102 101 103 #include "../../../shared/clockdrv_shell.h" 102 104 -
c/src/lib/libbsp/m68k/mcf52235/clock/clock.c
r7cd2484 r75acd9e 4 4 5 5 #include <rtems.h> 6 #include <rtems/timecounter.h> 6 7 #include <bsp.h> 7 8 … … 11 12 #define CLOCK_VECTOR (64+56) 12 13 13 static uint32_t s_pcntrAtTick = 0; 14 static uint32_t s_nanoScale = 0; 14 static rtems_timecounter_simple mcf52235_tc; 15 15 16 /* 17 * Provide nanosecond extension 18 * Interrupts are disabled when this is called 19 */ 20 static uint32_t bsp_clock_nanoseconds_since_last_tick(void) 16 static uint32_t mcf52235_tc_get(rtems_timecounter_simple *tc) 21 17 { 22 uint32_t i; 23 24 if (MCF_PIT1_PCSR & MCF_PIT_PCSR_PIF) { 25 i = s_pcntrAtTick + (MCF_PIT1_PMR - MCF_PIT1_PCNTR); 26 } 27 else { 28 i = s_pcntrAtTick - MCF_PIT1_PCNTR; 29 } 30 return i * s_nanoScale; 18 return MCF_PIT1_PCNTR; 31 19 } 32 20 33 #define Clock_driver_nanoseconds_since_last_tick bsp_clock_nanoseconds_since_last_tick 21 static bool mcf52235_tc_is_pending(rtems_timecounter_simple *tc) 22 { 23 return (MCF_PIT1_PCSR & MCF_PIT_PCSR_PIF) != 0; 24 } 25 26 static uint32_t mcf52235_tc_get_timecount(struct timecounter *tc) 27 { 28 return rtems_timecounter_simple_downcounter_get( 29 tc, 30 mcf52235_tc_get, 31 mcf52235_tc_is_pending 32 ); 33 } 34 35 static void mcf52235_tc_tick(void) 36 { 37 rtems_timecounter_simple_downcounter_tick(&mcf52235_tc, mcf52235_tc_get); 38 } 34 39 35 40 /* … … 38 43 #define Clock_driver_support_at_tick() \ 39 44 do { \ 40 s_pcntrAtTick = MCF_PIT1_PCNTR; \41 45 MCF_PIT1_PCSR |= MCF_PIT_PCSR_PIF; \ 42 46 } while (0) \ … … 65 69 static void Clock_driver_support_initialize_hardware(void) 66 70 { 71 uint32_t mask; 67 72 int level; 68 73 uint32_t pmr; … … 77 82 preScaleCode++; 78 83 } 79 s_nanoScale = 1000000000 / (clk >> preScaleCode);80 84 81 85 MCF_INTC0_ICR56 = MCF_INTC_ICR_IL(PIT3_IRQ_LEVEL) | … … 91 95 MCF_PIT1_PCSR = MCF_PIT_PCSR_PRE(preScaleCode) | 92 96 MCF_PIT_PCSR_PIE | MCF_PIT_PCSR_RLD | MCF_PIT_PCSR_EN; 93 s_pcntrAtTick = MCF_PIT1_PCNTR; 97 98 rtems_timecounter_simple_install( 99 &mcf52235_tc, 100 clk >> preScaleCode, 101 pmr, 102 mcf52235_tc_get_timecount 103 ); 94 104 } 95 105 106 #define Clock_driver_timecounter_tick() mcf52235_tc_tick() 107 96 108 #include "../../../shared/clockdrv_shell.h" -
c/src/lib/libbsp/m68k/mcf5225x/clock/clock.c
r7cd2484 r75acd9e 4 4 5 5 #include <rtems.h> 6 #include <rtems/timecounter.h> 6 7 #include <bsp.h> 7 8 … … 11 12 #define CLOCK_VECTOR (64+56) 12 13 13 static uint32_t s_pcntrAtTick = 0; 14 static uint32_t s_nanoScale = 0; 14 static rtems_timecounter_simple mcf5225x_tc; 15 15 16 /* 17 * Provide nanosecond extension 18 * Interrupts are disabled when this is called 19 */ 20 static uint32_t bsp_clock_nanoseconds_since_last_tick(void) 16 static uint32_t mcf5225x_tc_get(rtems_timecounter_simple *tc) 21 17 { 22 return MCF_PIT1_PCSR & MCF_PIT_PCSR_PIF ? (s_pcntrAtTick + (MCF_PIT1_PMR - MCF_PIT1_PCNTR)) * s_nanoScale : (s_pcntrAtTick - MCF_PIT1_PCNTR) * s_nanoScale;18 return MCF_PIT1_PCNTR; 23 19 } 24 20 25 #define Clock_driver_nanoseconds_since_last_tick bsp_clock_nanoseconds_since_last_tick 21 static bool mcf5225x_tc_is_pending(rtems_timecounter_simple *tc) 22 { 23 return (MCF_PIT1_PCSR & MCF_PIT_PCSR_PIF) != 0; 24 } 25 26 static uint32_t mcf5225x_tc_get_timecount(struct timecounter *tc) 27 { 28 return rtems_timecounter_simple_downcounter_get( 29 tc, 30 mcf5225x_tc_get, 31 mcf5225x_tc_is_pending 32 ); 33 } 34 35 static void mcf5225x_tc_tick(void) 36 { 37 rtems_timecounter_simple_downcounter_tick(&mcf5225x_tc, mcf5225x_tc_get); 38 } 26 39 27 40 /* … … 30 43 #define Clock_driver_support_at_tick() \ 31 44 do { \ 32 s_pcntrAtTick = MCF_PIT1_PCNTR; \33 45 MCF_PIT1_PCSR |= MCF_PIT_PCSR_PIF; \ 34 46 } while (0) \ … … 57 69 static void Clock_driver_support_initialize_hardware(void) 58 70 { 71 uint32_t mask; 59 72 int level; 60 73 uint32_t pmr; … … 69 82 preScaleCode++; 70 83 } 71 s_nanoScale = 1000000000 / (clk >> preScaleCode);72 84 73 85 MCF_INTC0_ICR56 = MCF_INTC_ICR_IL(PIT3_IRQ_LEVEL) | … … 83 95 MCF_PIT1_PCSR = MCF_PIT_PCSR_PRE(preScaleCode) | 84 96 MCF_PIT_PCSR_PIE | MCF_PIT_PCSR_RLD | MCF_PIT_PCSR_EN; 85 s_pcntrAtTick = MCF_PIT1_PCNTR; 97 98 rtems_timecounter_simple_install( 99 &mcf5225x_tc, 100 clk >> preScaleCode, 101 pmr, 102 mcf5225x_tc_get_timecount 103 ); 86 104 } 87 105 106 #define Clock_driver_timecounter_tick() mcf5225x_tc_tick() 107 88 108 #include "../../../shared/clockdrv_shell.h" -
c/src/lib/libbsp/m68k/mcf5235/clock/clock.c
r7cd2484 r75acd9e 59 59 } while (0) 60 60 61 #define CLOCK_DRIVER_USE_DUMMY_TIMECOUNTER 62 61 63 #include "../../../shared/clockdrv_shell.h" -
c/src/lib/libbsp/m68k/mcf5329/clock/clock.c
r7cd2484 r75acd9e 4 4 5 5 #include <rtems.h> 6 #include <rtems/timecounter.h> 6 7 #include <bsp.h> 7 8 … … 11 12 #define CLOCK_VECTOR (128+46) 12 13 13 static uint32_t s_pcntrAtTick = 0; 14 static uint32_t s_nanoScale = 0; 14 static rtems_timecounter_simple mcf5329_tc; 15 15 16 /* 17 * Provide nanosecond extension 18 */ 19 static uint32_t bsp_clock_nanoseconds_since_last_tick(void) 16 static uint32_t mcf5329_tc_get(rtems_timecounter_simple *tc) 20 17 { 21 uint32_t i; 22 23 if (MCF_PIT3_PCSR & MCF_PIT_PCSR_PIF) { 24 i = s_pcntrAtTick + (MCF_PIT3_PMR - MCF_PIT3_PCNTR); 25 } else { 26 i = s_pcntrAtTick - MCF_PIT3_PCNTR; 27 } 28 return i * s_nanoScale; 18 return MCF_PIT3_PCNTR; 29 19 } 30 20 31 #define Clock_driver_nanoseconds_since_last_tick bsp_clock_nanoseconds_since_last_tick 21 static bool mcf5329_tc_is_pending(rtems_timecounter_simple *tc) 22 { 23 return (MCF_PIT3_PCSR & MCF_PIT_PCSR_PIF) != 0; 24 } 25 26 static uint32_t mcf5329_tc_get_timecount(struct timecounter *tc) 27 { 28 return rtems_timecounter_simple_downcounter_get( 29 tc, 30 mcf5329_tc_get, 31 mcf5329_tc_is_pending 32 ); 33 } 34 35 static void mcf5329_tc_tick(void) 36 { 37 rtems_timecounter_simple_downcounter_tick(&mcf5329_tc, mcf5329_tc_get); 38 } 32 39 33 40 /* … … 36 43 #define Clock_driver_support_at_tick() \ 37 44 do { \ 38 s_pcntrAtTick = MCF_PIT3_PCNTR; \39 45 MCF_PIT3_PCSR |= MCF_PIT_PCSR_PIF; \ 40 46 } while (0) \ 41 42 47 43 48 /* … … 76 81 preScaleCode++; 77 82 } 78 s_nanoScale = 1000000000 / (clk >> preScaleCode);79 80 83 MCF_INTC1_ICR46 = MCF_INTC_ICR_IL(PIT3_IRQ_LEVEL); 81 84 … … 90 93 MCF_PIT3_PCSR = MCF_PIT_PCSR_PRE(preScaleCode) | 91 94 MCF_PIT_PCSR_PIE | MCF_PIT_PCSR_RLD | MCF_PIT_PCSR_EN; 92 s_pcntrAtTick = MCF_PIT3_PCNTR; 95 96 rtems_timecounter_simple_install( 97 &mcf5329_tc, 98 clk >> preScaleCode, 99 pmr, 100 mcf5329_tc_get_timecount 101 ); 93 102 } 94 103 104 #define Clock_driver_timecounter_tick() mcf5329_tc_tick() 105 95 106 #include "../../../shared/clockdrv_shell.h" -
c/src/lib/libbsp/m68k/sim68000/clock/clockdrv.c
r7cd2484 r75acd9e 49 49 } 50 50 51 #define CLOCK_DRIVER_USE_DUMMY_TIMECOUNTER 52 51 53 #include "../../../shared/clockdrv_shell.h" -
c/src/lib/libbsp/m68k/uC5282/clock/clock.c
r7cd2484 r75acd9e 13 13 14 14 #include <rtems.h> 15 #include <rtems/timecounter.h> 15 16 #include <bsp.h> 16 17 #include <mcf5282/mcf5282.h> … … 20 21 */ 21 22 #define CLOCK_VECTOR (64+58) 23 24 static rtems_timecounter_simple uC5282_tc; 25 26 static uint32_t uC5282_tc_get(rtems_timecounter_simple *tc) 27 { 28 return MCF5282_PIT3_PCNTR; 29 } 30 31 static bool uC5282_tc_is_pending(rtems_timecounter_simple *tc) 32 { 33 return (MCF5282_PIT3_PCSR & MCF5282_PIT_PCSR_PIF) != 0; 34 } 35 36 static uint32_t uC5282_tc_get_timecount(struct timecounter *tc) 37 { 38 return rtems_timecounter_simple_downcounter_get( 39 tc, 40 uC5282_tc_get, 41 uC5282_tc_is_pending 42 ); 43 } 44 45 static void uC5282_tc_tick(void) 46 { 47 rtems_timecounter_simple_downcounter_tick(&uC5282_tc, uC5282_tc_get); 48 } 22 49 23 50 /* … … 31 58 #define NSEC_PER_PITC __SRAMBASE.nsec_per_pitc 32 59 #define FILTER_SHIFT 6 33 34 static uint32_t bsp_clock_nanoseconds_since_last_tick(void)35 {36 int i = MCF5282_PIT3_PCNTR;37 if (MCF5282_PIT3_PCSR & MCF5282_PIT_PCSR_PIF)38 i = MCF5282_PIT3_PCNTR - PITC_PER_TICK;39 return (PITC_PER_TICK - i) * NSEC_PER_PITC;40 }41 42 #define Clock_driver_nanoseconds_since_last_tick \43 bsp_clock_nanoseconds_since_last_tick44 60 45 61 /* … … 84 100 #define Clock_driver_support_initialize_hardware() \ 85 101 do { \ 86 102 unsigned long long N; \ 87 103 int level; \ 88 104 int preScaleCode = 0; \ … … 117 133 MCF5282_PIT_PCSR_RLD | \ 118 134 MCF5282_PIT_PCSR_EN; \ 135 rtems_timecounter_simple_install( \ 136 &uC5282_tc, \ 137 bsp_get_CPU_clock_speed() >> (preScaleCode + 1), \ 138 PITC_PER_TICK, \ 139 uC5282_tc_get_timecount \ 140 ); \ 119 141 } while (0) 120 142 … … 136 158 } 137 159 160 #define Clock_driver_timecounter_tick() uC5282_tc_tick() 161 138 162 #include "../../../shared/clockdrv_shell.h" -
c/src/lib/libbsp/mips/csb350/clock/clockdrv.c
r7cd2484 r75acd9e 89 89 #define Clock_driver_support_shutdown_hardware() 90 90 91 #define CLOCK_DRIVER_USE_DUMMY_TIMECOUNTER 92 91 93 #include "../../../shared/clockdrv_shell.h" -
c/src/lib/libbsp/mips/genmongoosev/clock/clockdrv.c
r7cd2484 r75acd9e 55 55 MONGOOSEV_WRITE_REGISTER( CLOCK_BASE, MONGOOSEV_TIMER_CONTROL_REGISTER, 0 ) 56 56 57 #define CLOCK_DRIVER_USE_DUMMY_TIMECOUNTER 58 57 59 #include "../../../shared/clockdrv_shell.h" -
c/src/lib/libbsp/mips/jmr3904/clock/clockdrv.c
r7cd2484 r75acd9e 56 56 #define Clock_driver_support_shutdown_hardware() 57 57 58 #define CLOCK_DRIVER_USE_DUMMY_TIMECOUNTER 59 58 60 #include "../../../shared/clockdrv_shell.h" -
c/src/lib/libbsp/mips/rbtx4925/clock/clockdrv.c
r7cd2484 r75acd9e 124 124 } while(0) 125 125 126 #define CLOCK_DRIVER_USE_DUMMY_TIMECOUNTER 126 127 127 128 #include "../../../shared/clockdrv_shell.h" -
c/src/lib/libbsp/mips/rbtx4938/clock/clockdrv.c
r7cd2484 r75acd9e 115 115 116 116 117 #define CLOCK_DRIVER_USE_DUMMY_TIMECOUNTER 118 117 119 #include "../../../shared/clockdrv_shell.h" -
c/src/lib/libbsp/mips/shared/clock/clockdrv.c
r7cd2484 r75acd9e 44 44 } while(0) 45 45 46 static uint32_t bsp_clock_nanoseconds_since_last_tick(void)47 {48 return 0;49 }50 51 #define Clock_driver_nanoseconds_since_last_tick \52 bsp_clock_nanoseconds_since_last_tick53 54 46 #define Clock_driver_support_shutdown_hardware() \ 55 47 do { \ … … 57 49 } while (0) 58 50 51 #define CLOCK_DRIVER_USE_DUMMY_TIMECOUNTER 52 59 53 #include "../../../shared/clockdrv_shell.h" -
c/src/lib/libbsp/nios2/nios2_iss/clock/clock.c
r7cd2484 r75acd9e 50 50 } 51 51 52 #define CLOCK_DRIVER_USE_DUMMY_TIMECOUNTER 53 52 54 #include "../../../shared/clockdrv_shell.h" 53 55 -
c/src/lib/libbsp/or1k/generic_or1k/clock/clockdrv.c
r7cd2484 r75acd9e 23 23 #include <rtems/score/cpu.h> 24 24 #include <rtems/score/or1k-utility.h> 25 #include <rtems/timecounter.h> 25 26 26 27 /* The number of clock cycles before generating a tick timer interrupt. */ 27 28 #define TTMR_NUM_OF_CLOCK_TICKS_INTERRUPT 0x09ED9 28 29 #define OR1K_CLOCK_CYCLE_TIME_NANOSECONDS 10 30 31 static struct timecounter or1ksim_tc; 29 32 30 33 /* CPU counter */ … … 70 73 } 71 74 75 static uint32_t or1ksim_get_timecount(struct timecounter *tc) 76 { 77 uint32_t ticks_since_last_timer_interrupt; 78 79 ticks_since_last_timer_interrupt = _OR1K_mfspr(CPU_OR1K_SPR_TTCR); 80 81 return cpu_counter_ticks + ticks_since_last_timer_interrupt; 82 } 83 84 CPU_Counter_ticks _CPU_Counter_read(void) 85 { 86 return or1ksim_get_timecount(NULL); 87 } 88 72 89 static void generic_or1k_clock_initialize(void) 73 90 { 91 uint64_t frequency = (1000000000 / OR1K_CLOCK_CYCLE_TIME_NANOSECONDS); 74 92 uint32_t TTMR; 75 93 … … 91 109 _OR1K_mtspr(CPU_OR1K_SPR_TTCR, 0); 92 110 93 /* Initialize CPU Counter */ 94 cpu_counter_ticks = 0; 111 /* Initialize timecounter */ 112 or1ksim_tc.tc_get_timecount = or1ksim_get_timecount; 113 or1ksim_tc.tc_counter_mask = 0xffffffff; 114 or1ksim_tc.tc_frequency = frequency; 115 or1ksim_tc.tc_quality = RTEMS_TIMECOUNTER_QUALITY_CLOCK_DRIVER; 116 rtems_timecounter_install(&or1ksim_tc); 95 117 } 96 118 97 119 static void generic_or1k_clock_cleanup(void) 98 120 { 99 121 uint32_t sr; … … 110 132 } 111 133 112 /*113 * Return the nanoseconds since last tick114 */115 static uint32_t generic_or1k_clock_nanoseconds_since_last_tick(void)116 {117 return118 TTMR_NUM_OF_CLOCK_TICKS_INTERRUPT * OR1K_CLOCK_CYCLE_TIME_NANOSECONDS;119 }120 121 CPU_Counter_ticks _CPU_Counter_read(void)122 {123 uint32_t ticks_since_last_timer_interrupt;124 125 ticks_since_last_timer_interrupt = _OR1K_mfspr(CPU_OR1K_SPR_TTCR);126 127 return cpu_counter_ticks + ticks_since_last_timer_interrupt;128 }129 130 134 CPU_Counter_ticks _CPU_Counter_difference( 131 135 CPU_Counter_ticks second, … … 135 139 return second - first; 136 140 } 141 137 142 #define Clock_driver_support_at_tick() generic_or1k_clock_at_tick() 138 143 … … 147 152 #define Clock_driver_support_shutdown_hardware() generic_or1k_clock_cleanup() 148 153 149 #define Clock_driver_nanoseconds_since_last_tick \150 generic_or1k_clock_nanoseconds_since_last_tick151 152 154 #include "../../../shared/clockdrv_shell.h" -
c/src/lib/libbsp/powerpc/mpc55xxevb/clock/clock-config.c
r7cd2484 r75acd9e 27 27 #include <mpc55xx/regs.h> 28 28 29 #include <rtems/timecounter.h> 30 29 31 void Clock_isr(void *arg); 30 32 31 static uint64_t mpc55xx_clock_factor;33 static rtems_timecounter_simple mpc55xx_tc; 32 34 33 35 #if defined(MPC55XX_CLOCK_EMIOS_CHANNEL) 34 36 35 37 #include <mpc55xx/emios.h> 38 39 static uint32_t mpc55xx_tc_get(rtems_timecounter_simple *tc) 40 { 41 return EMIOS.CH [MPC55XX_CLOCK_EMIOS_CHANNEL].CCNTR.R; 42 } 43 44 static bool mpc55xx_tc_is_pending(rtems_timecounter_simple *tc) 45 { 46 return EMIOS.CH [MPC55XX_CLOCK_EMIOS_CHANNEL].CSR.B.FLAG != 0; 47 } 48 49 static uint32_t mpc55xx_tc_get_timecount(struct timecounter *tc) 50 { 51 return rtems_timecounter_simple_upcounter_get( 52 tc, 53 mpc55xx_tc_get, 54 mpc55xx_tc_is_pending 55 ); 56 } 57 58 static void mpc55xx_tc_tick(void) 59 { 60 rtems_timecounter_simple_upcounter_tick(&mpc55xx_tc, mpc55xx_tc_get); 61 } 36 62 37 63 static void mpc55xx_clock_at_tick(void) … … 61 87 static void mpc55xx_clock_initialize(void) 62 88 { 89 uint32_t mask; 63 90 volatile struct EMIOS_CH_tag *regs = &EMIOS.CH [MPC55XX_CLOCK_EMIOS_CHANNEL]; 64 91 union EMIOS_CCR_tag ccr = MPC55XX_ZERO_FLAGS; … … 68 95 uint64_t us_per_tick = rtems_configuration_get_microseconds_per_tick(); 69 96 uint64_t interval = (reference_clock * us_per_tick) / 1000000; 70 71 mpc55xx_clock_factor = (1000000000ULL << 32) / reference_clock;72 97 73 98 /* Apply prescaler */ … … 111 136 ccr.B.FREN = 1; 112 137 regs->CCR.R = ccr.R; 138 139 rtems_timecounter_simple_install( 140 &mpc55xx_tc, 141 reference_clock, 142 interval, 143 mpc55xx_tc_get_timecount 144 ); 113 145 } 114 146 … … 123 155 } 124 156 125 static uint32_t mpc55xx_clock_nanoseconds_since_last_tick(void)126 {127 volatile struct EMIOS_CH_tag *regs = &EMIOS.CH [MPC55XX_CLOCK_EMIOS_CHANNEL];128 uint64_t c = regs->CCNTR.R;129 union EMIOS_CSR_tag csr = { .R = regs->CSR.R };130 uint64_t k = mpc55xx_clock_factor;131 132 if (csr.B.FLAG != 0) {133 c = regs->CCNTR.R + regs->CADR.R + 1;134 }135 136 return (uint32_t) ((c * k) >> 32);137 }138 139 157 #elif defined(MPC55XX_CLOCK_PIT_CHANNEL) 158 159 static uint32_t mpc55xx_tc_get(rtems_timecounter_simple *tc) 160 { 161 return PIT_RTI.CHANNEL [MPC55XX_CLOCK_PIT_CHANNEL].CVAL.R; 162 } 163 164 static bool mpc55xx_tc_is_pending(rtems_timecounter_simple *tc) 165 { 166 return PIT_RTI.CHANNEL [MPC55XX_CLOCK_PIT_CHANNEL].TFLG.B.TIF != 0; 167 } 168 169 static uint32_t mpc55xx_tc_get_timecount(struct timecounter *tc) 170 { 171 return rtems_timecounter_simple_downcounter_get( 172 tc, 173 mpc55xx_tc_get, 174 mpc55xx_tc_is_pending 175 ); 176 } 177 178 static void mpc55xx_tc_tick(void) 179 { 180 rtems_timecounter_simple_downcounter_tick(&mpc55xx_tc, mpc55xx_tc_get); 181 } 140 182 141 183 static void mpc55xx_clock_at_tick(void) … … 167 209 static void mpc55xx_clock_initialize(void) 168 210 { 211 uint32_t mask; 169 212 volatile PIT_RTI_CHANNEL_tag *channel = 170 213 &PIT_RTI.CHANNEL [MPC55XX_CLOCK_PIT_CHANNEL]; … … 175 218 PIT_RTI_TCTRL_32B_tag tctrl = { .B = { .TIE = 1, .TEN = 1 } }; 176 219 177 mpc55xx_clock_factor = (1000000000ULL << 32) / reference_clock;178 179 220 PIT_RTI.PITMCR.R = pitmcr.R; 180 221 channel->LDVAL.R = interval; 181 222 channel->TCTRL.R = tctrl.R; 223 224 rtems_timecounter_simple_install( 225 &mpc55xx_tc, 226 reference_clock, 227 interval, 228 mpc55xx_tc_get_timecount 229 ); 182 230 } 183 231 … … 190 238 } 191 239 192 static uint32_t mpc55xx_clock_nanoseconds_since_last_tick(void)193 {194 volatile PIT_RTI_CHANNEL_tag *channel =195 &PIT_RTI.CHANNEL [MPC55XX_CLOCK_PIT_CHANNEL];196 uint32_t c = channel->CVAL.R;197 uint32_t i = channel->LDVAL.R;198 uint64_t k = mpc55xx_clock_factor;199 200 if (channel->TFLG.B.TIF != 0) {201 c = channel->CVAL.R - i;202 }203 204 return (uint32_t) (((i - c) * k) >> 32);205 }206 207 240 #endif 208 241 242 #define Clock_driver_timecounter_tick() mpc55xx_tc_tick() 209 243 #define Clock_driver_support_at_tick() \ 210 244 mpc55xx_clock_at_tick() … … 218 252 #define Clock_driver_support_shutdown_hardware() \ 219 253 mpc55xx_clock_cleanup() 220 #define Clock_driver_nanoseconds_since_last_tick \221 mpc55xx_clock_nanoseconds_since_last_tick222 254 223 255 /* Include shared source clock driver code */ -
c/src/lib/libbsp/powerpc/qoriq/clock/clock-config.c
r7cd2484 r75acd9e 8 8 9 9 /* 10 * Copyright (c) 2011-201 2embedded brains GmbH. All rights reserved.10 * Copyright (c) 2011-2015 embedded brains GmbH. All rights reserved. 11 11 * 12 12 * embedded brains GmbH 13 * Obere Lagerstr. 3013 * Dornierstr. 4 14 14 * 82178 Puchheim 15 15 * Germany … … 20 20 * http://www.rtems.org/license/LICENSE. 21 21 */ 22 23 #include <rtems/timecounter.h> 22 24 23 25 #include <libcpu/powerpc-utility.h> … … 30 32 static rtems_isr Clock_isr(void *arg); 31 33 32 static uint32_t qoriq_clock_last_ccr;33 34 static uint32_t qoriq_clock_nanoseconds_per_timer_tick;35 36 34 static volatile qoriq_pic_global_timer *const qoriq_clock = 37 35 #if QORIQ_CLOCK_TIMER < 4 … … 41 39 #endif 42 40 41 static volatile qoriq_pic_global_timer *const qoriq_timecounter = 42 #if QORIQ_CLOCK_TIMECOUNTER < 4 43 &qoriq.pic.gta [QORIQ_CLOCK_TIMECOUNTER]; 44 #else 45 &qoriq.pic.gtb [QORIQ_CLOCK_TIMECOUNTER - 4]; 46 #endif 47 43 48 #define CLOCK_INTERRUPT (QORIQ_IRQ_GT_BASE + QORIQ_CLOCK_TIMER) 49 50 static struct timecounter qoriq_clock_tc; 44 51 45 52 static void qoriq_clock_handler_install(rtems_isr_entry *old_isr) … … 78 85 } 79 86 87 static uint32_t qoriq_clock_get_timecount(struct timecounter *tc) 88 { 89 uint32_t ccr = qoriq_timecounter->ccr; 90 91 return GTCCR_COUNT_GET(-ccr); 92 } 93 80 94 static void qoriq_clock_initialize(void) 81 95 { 82 96 uint32_t timer_frequency = BSP_bus_frequency / 8; 83 uint32_t nanoseconds_per_second = 1000000000;84 97 uint32_t interval = (uint32_t) (((uint64_t) timer_frequency 85 98 * (uint64_t) rtems_configuration_get_microseconds_per_tick()) / 1000000); 86 99 87 qoriq_clock_nanoseconds_per_timer_tick = 88 nanoseconds_per_second / timer_frequency; 100 qoriq_clock->bcr = GTBCR_COUNT(interval); 89 101 90 qoriq_clock->bcr = GTBCR_COUNT(interval); 91 qoriq_clock_last_ccr = qoriq_clock->ccr; 102 qoriq_timecounter->bcr = GTBCR_COUNT(0xffffffff); 103 104 qoriq_clock_tc.tc_get_timecount = qoriq_clock_get_timecount; 105 qoriq_clock_tc.tc_counter_mask = GTCCR_COUNT_GET(0xffffffff); 106 qoriq_clock_tc.tc_frequency = timer_frequency; 107 qoriq_clock_tc.tc_quality = RTEMS_TIMECOUNTER_QUALITY_CLOCK_DRIVER; 108 rtems_timecounter_install(&qoriq_clock_tc); 92 109 } 93 110 … … 108 125 } 109 126 110 static void qoriq_clock_at_tick(void) 111 { 112 qoriq_clock_last_ccr = qoriq_clock->ccr; 113 } 114 115 static uint32_t qoriq_clock_nanoseconds_since_last_tick(void) 116 { 117 uint32_t ccr = qoriq_clock->ccr; 118 uint32_t bcr = qoriq_clock->bcr; 119 120 if ((ccr & GTCCR_TOG) != (qoriq_clock_last_ccr & GTCCR_TOG)) { 121 bcr += bcr; 122 } 123 124 return (bcr - GTCCR_COUNT_GET(ccr)) * qoriq_clock_nanoseconds_per_timer_tick; 125 } 126 127 #define Clock_driver_support_at_tick() \ 128 qoriq_clock_at_tick() 127 #define Clock_driver_support_at_tick() 129 128 #define Clock_driver_support_initialize_hardware() \ 130 129 qoriq_clock_initialize() … … 133 132 #define Clock_driver_support_shutdown_hardware() \ 134 133 qoriq_clock_cleanup() 135 #define Clock_driver_nanoseconds_since_last_tick \136 qoriq_clock_nanoseconds_since_last_tick137 134 138 135 /* Include shared source clock driver code */ -
c/src/lib/libbsp/powerpc/qoriq/configure.ac
r7cd2484 r75acd9e 155 155 RTEMS_BSPOPTS_HELP([QORIQ_CLOCK_TIMER],[global timer used for system clock, 0..3 maps to A0..A3, and 4..7 maps to B0..B3]) 156 156 157 RTEMS_BSPOPTS_SET([QORIQ_CLOCK_TIMECOUNTER],[qoriq_core_1],[5]) 158 RTEMS_BSPOPTS_SET([QORIQ_CLOCK_TIMECOUNTER],[*],[1]) 159 RTEMS_BSPOPTS_HELP([QORIQ_CLOCK_TIMECOUNTER],[global timer used for the timecounter, 0..3 maps to A0..A3, and 4..7 maps to B0..B3]) 160 157 161 RTEMS_BSPOPTS_SET([QORIQ_CHIP_VARIANT],[qoriq_t2080*],[QORIQ_CHIP_T2080]) 158 162 RTEMS_BSPOPTS_SET([QORIQ_CHIP_VARIANT],[qoriq_t4240*],[QORIQ_CHIP_T4240]) -
c/src/lib/libbsp/powerpc/shared/clock/clock.c
r7cd2484 r75acd9e 8 8 9 9 /* 10 * Copyright (c) 2008-201 3embedded brains GmbH. All rights reserved.10 * Copyright (c) 2008-2015 embedded brains GmbH. All rights reserved. 11 11 * 12 12 * embedded brains GmbH … … 23 23 #include <rtems.h> 24 24 #include <rtems/clockdrv.h> 25 #include <rtems/timecounter.h> 25 26 26 27 #include <libcpu/powerpc-utility.h> … … 47 48 static uint32_t ppc_clock_next_time_base; 48 49 49 static uint64_t ppc_clock_factor; 50 static struct timecounter ppc_tc; 51 52 static uint32_t ppc_get_timecount(struct timecounter *tc) 53 { 54 return ppc_time_base(); 55 } 50 56 51 57 static void ppc_clock_no_tick(void) … … 162 168 } 163 169 164 static uint32_t ppc_clock_nanoseconds_since_last_tick(void)165 {166 uint64_t k = ppc_clock_factor;167 uint32_t c = ppc_decrementer_register();168 uint32_t i = ppc_clock_decrementer_value + 1;169 170 return (uint32_t) (((i - c) * k) >> 32);171 }172 173 static uint32_t ppc_clock_nanoseconds_since_last_tick_ppc405(void)174 {175 uint64_t k = ppc_clock_factor;176 uint32_t i = ppc_clock_decrementer_value;177 uint32_t c = i - PPC_SPECIAL_PURPOSE_REGISTER(PPC405_PIT);178 179 if ((PPC_SPECIAL_PURPOSE_REGISTER(PPC405_TSR) & BOOKE_TSR_DIS) != 0) {180 c = i - PPC_SPECIAL_PURPOSE_REGISTER(PPC405_PIT) + i;181 }182 183 return (uint32_t) ((c * k) >> 32);184 }185 186 170 void Clock_exit(void) 187 171 { … … 202 186 uint64_t us_per_tick = rtems_configuration_get_microseconds_per_tick(); 203 187 uint32_t interval = (uint32_t) ((frequency * us_per_tick) / 1000000); 188 uint32_t mask; 204 189 205 190 /* 206 191 * Set default ticker. 207 *208 * The function rtems_clock_tick() returns a status code. This value209 * will be discarded since the RTEMS documentation claims that it is210 * always successful.211 192 */ 212 ppc_clock_tick = (void (*)(void)) rtems_clock_tick; 213 214 /* Factor for nano seconds extension */ 215 ppc_clock_factor = (1000000000ULL << 32) / frequency; 193 ppc_clock_tick = rtems_timecounter_tick; 216 194 217 195 if (ppc_cpu_is_bookE() != PPC_BOOKE_405) { … … 224 202 RTEMS_SYSLOG_ERROR( "decrementer value would be zero, will be set to maximum value instead\n"); 225 203 } 226 227 /* Set the nanoseconds since last tick handler */228 rtems_clock_set_nanoseconds_extension( ppc_clock_nanoseconds_since_last_tick);229 230 204 if (ppc_cpu_is_bookE()) { 231 205 /* Set decrementer auto-reload value */ … … 254 228 ppc_clock_decrementer_value = interval; 255 229 256 /* Set the nanoseconds since last tick handler */257 rtems_clock_set_nanoseconds_extension(ppc_clock_nanoseconds_since_last_tick_ppc405);258 259 230 /* Install exception handler */ 260 231 ppc_exc_set_handler(ASM_BOOKE_DEC_VECTOR, ppc_clock_exception_handler_ppc405); … … 267 238 } 268 239 240 /* Install timecounter */ 241 ppc_tc.tc_get_timecount = ppc_get_timecount; 242 ppc_tc.tc_counter_mask = 0xffffffff; 243 ppc_tc.tc_frequency = frequency; 244 ppc_tc.tc_quality = RTEMS_TIMECOUNTER_QUALITY_CLOCK_DRIVER; 245 rtems_timecounter_install(&ppc_tc); 246 269 247 return RTEMS_SUCCESSFUL; 270 248 } -
c/src/lib/libbsp/shared/clock_driver_simidle.c
r7cd2484 r75acd9e 28 28 clock_driver_enabled = false; \ 29 29 } while (0) 30 31 #define CLOCK_DRIVER_USE_DUMMY_TIMECOUNTER 30 32 31 33 #include "clockdrv_shell.h" -
c/src/lib/libbsp/shared/clockdrv_shell.h
r7cd2484 r75acd9e 21 21 #include <rtems/clockdrv.h> 22 22 23 #ifdef Clock_driver_nanoseconds_since_last_tick 24 #error "Update driver to use the timecounter instead of nanoseconds extension" 25 #endif 26 23 27 /** 24 28 * @defgroup bsp_clock Clock Support … … 38 42 #ifndef Clock_driver_support_find_timer 39 43 #define Clock_driver_support_find_timer() 44 #endif 45 46 /* 47 * A specialized clock driver may use for example rtems_timecounter_tick_simple() 48 * instead of the default. 49 */ 50 #ifndef Clock_driver_timecounter_tick 51 #ifdef CLOCK_DRIVER_USE_DUMMY_TIMECOUNTER 52 #define Clock_driver_timecounter_tick() rtems_clock_tick() 53 #else 54 #define Clock_driver_timecounter_tick() rtems_timecounter_tick() 55 #endif 40 56 #endif 41 57 … … 79 95 80 96 #if CLOCK_DRIVER_USE_FAST_IDLE 81 do { 82 rtems_clock_tick(); 83 } while ( 84 _Thread_Heir == _Thread_Executing 85 && _Thread_Executing->Start.entry_point 86 == (Thread_Entry) rtems_configuration_get_idle_task() 87 ); 88 89 Clock_driver_support_at_tick(); 90 return; 97 { 98 struct timecounter *tc = _Timecounter; 99 uint64_t us_per_tick = rtems_configuration_get_microseconds_per_tick(); 100 uint32_t interval = (uint32_t) 101 ((tc->tc_frequency * us_per_tick) / 1000000); 102 103 Clock_driver_timecounter_tick(); 104 105 while ( 106 _Thread_Heir == _Thread_Executing 107 && _Thread_Executing->Start.entry_point 108 == (Thread_Entry) rtems_configuration_get_idle_task() 109 ) { 110 _Timecounter_Tick_simple(interval, (*tc->tc_get_timecount)(tc)); 111 } 112 113 Clock_driver_support_at_tick(); 114 } 91 115 #else 92 116 /* … … 102 126 */ 103 127 if ( !Clock_driver_isrs ) { 104 rtems_clock_tick();128 Clock_driver_timecounter_tick(); 105 129 106 130 Clock_driver_isrs = CLOCK_DRIVER_ISRS_PER_TICK; … … 111 135 * The driver is one ISR per clock tick. 112 136 */ 113 rtems_clock_tick();137 Clock_driver_timecounter_tick(); 114 138 #endif 115 139 #endif … … 161 185 Clock_driver_support_install_isr( Clock_isr, Old_ticker ); 162 186 163 #if defined(Clock_driver_nanoseconds_since_last_tick)164 rtems_clock_set_nanoseconds_extension(165 Clock_driver_nanoseconds_since_last_tick166 );167 #endif168 169 187 /* 170 188 * Now initialize the hardware that is the source of the tick ISR. -
c/src/lib/libbsp/sparc/erc32/clock/ckinit.c
r7cd2484 r75acd9e 26 26 #include <bspopts.h> 27 27 #include <rtems/counter.h> 28 #include <rtems/timecounter.h> 28 29 29 30 #if SIMSPARC_FAST_IDLE==1 … … 45 46 extern int CLOCK_SPEED; 46 47 47 static uint32_t bsp_clock_nanoseconds_since_last_tick(void) 48 static rtems_timecounter_simple erc32_tc; 49 50 static uint32_t erc32_tc_get( rtems_timecounter_simple *tc ) 48 51 { 49 uint32_t clicks; 50 uint32_t usecs; 51 52 clicks = ERC32_MEC.Real_Time_Clock_Counter; 53 54 if ( ERC32_Is_interrupt_pending( ERC32_INTERRUPT_REAL_TIME_CLOCK ) ) { 55 clicks = ERC32_MEC.Real_Time_Clock_Counter; 56 usecs = (2*rtems_configuration_get_microseconds_per_tick() - clicks); 57 } else { 58 usecs = (rtems_configuration_get_microseconds_per_tick() - clicks); 59 } 60 return usecs * 1000; 52 return ERC32_MEC.Real_Time_Clock_Counter; 61 53 } 62 54 63 #define Clock_driver_nanoseconds_since_last_tick \ 64 bsp_clock_nanoseconds_since_last_tick 55 static bool erc32_tc_is_pending( rtems_timecounter_simple *tc ) 56 { 57 return ERC32_Is_interrupt_pending( ERC32_INTERRUPT_REAL_TIME_CLOCK ); 58 } 59 60 static uint32_t erc32_tc_get_timecount( struct timecounter *tc ) 61 { 62 return rtems_timecounter_simple_downcounter_get( 63 tc, 64 erc32_tc_get, 65 erc32_tc_is_pending 66 ); 67 } 68 69 static void erc32_tc_tick( void ) 70 { 71 rtems_timecounter_simple_downcounter_tick( 72 &erc32_tc, 73 erc32_tc_get 74 ); 75 } 65 76 66 77 static CPU_Counter_ticks erc32_counter_difference( … … 76 87 #define Clock_driver_support_initialize_hardware() \ 77 88 do { \ 89 uint32_t frequency = 1000000; \ 78 90 /* approximately 1 us per countdown */ \ 79 91 ERC32_MEC.Real_Time_Clock_Scalar = CLOCK_SPEED - 1; \ … … 90 102 ERC32_MEC_TIMER_COUNTER_ENABLE_COUNTING | \ 91 103 ERC32_MEC_TIMER_COUNTER_RELOAD_AT_ZERO \ 104 ); \ 105 rtems_timecounter_simple_install( \ 106 &erc32_tc, \ 107 frequency, \ 108 rtems_configuration_get_microseconds_per_tick(), \ 109 erc32_tc_get_timecount \ 92 110 ); \ 93 111 _SPARC_Counter_initialize( \ … … 95 113 erc32_counter_difference \ 96 114 ); \ 97 rtems_counter_initialize_converter( 1000000); \115 rtems_counter_initialize_converter( frequency ); \ 98 116 } while (0) 117 118 #define Clock_driver_timecounter_tick() erc32_tc_tick() 99 119 100 120 #define Clock_driver_support_shutdown_hardware() \ -
c/src/lib/libbsp/sparc/leon2/clock/ckinit.c
r7cd2484 r75acd9e 25 25 #include <bsp.h> 26 26 #include <bspopts.h> 27 #include <rtems/timecounter.h> 27 28 28 29 #if SIMSPARC_FAST_IDLE==1 29 30 #define CLOCK_DRIVER_USE_FAST_IDLE 1 30 31 #endif 32 33 static rtems_timecounter_simple leon2_tc; 34 35 static uint32_t leon2_tc_get( rtems_timecounter_simple *tc ) 36 { 37 return LEON_REG.Timer_Counter_1; 38 } 39 40 static bool leon2_tc_is_pending( rtems_timecounter_simple *tc ) 41 { 42 return LEON_Is_interrupt_pending( LEON_INTERRUPT_TIMER1 ); 43 } 44 45 static uint32_t leon2_tc_get_timecount( struct timecounter *tc ) 46 { 47 return rtems_timecounter_simple_downcounter_get( 48 tc, 49 leon2_tc_get, 50 leon2_tc_is_pending 51 ); 52 } 53 54 static void leon2_tc_tick( void ) 55 { 56 rtems_timecounter_simple_downcounter_tick( &leon2_tc, leon2_tc_get ); 57 } 31 58 32 59 /* … … 55 82 LEON_REG_TIMER_COUNTER_LOAD_COUNTER \ 56 83 ); \ 84 rtems_timecounter_simple_install( \ 85 &leon2_tc, \ 86 1000000, \ 87 rtems_configuration_get_microseconds_per_tick(), \ 88 leon2_tc_get_timecount \ 89 ); \ 57 90 } while (0) 58 91 … … 63 96 } while (0) 64 97 65 static uint32_t bsp_clock_nanoseconds_since_last_tick(void) 66 { 67 uint32_t clicks; 68 uint32_t usecs; 69 70 clicks = LEON_REG.Timer_Counter_1; 71 72 if ( LEON_Is_interrupt_pending( LEON_INTERRUPT_TIMER1 ) ) { 73 clicks = LEON_REG.Timer_Counter_1; 74 usecs = (2*rtems_configuration_get_microseconds_per_tick() - clicks); 75 } else { 76 usecs = (rtems_configuration_get_microseconds_per_tick() - clicks); 77 } 78 return usecs * 1000; 79 } 80 81 #define Clock_driver_nanoseconds_since_last_tick \ 82 bsp_clock_nanoseconds_since_last_tick 98 #define Clock_driver_timecounter_tick() leon2_tc_tick() 83 99 84 100 #include "../../../shared/clockdrv_shell.h" -
c/src/lib/libbsp/sparc/leon3/clock/ckinit.c
r7cd2484 r75acd9e 25 25 #include <ambapp.h> 26 26 #include <rtems/score/profiling.h> 27 #include <rtems/timecounter.h> 27 28 28 29 /* The LEON3 BSP Timer driver can rely on the Driver Manager if the … … 40 41 /* LEON3 Timer system interrupt number */ 41 42 static int clkirq; 43 44 static bool leon3_tc_use_irqmp; 45 46 static rtems_timecounter_simple leon3_tc; 47 48 static uint32_t leon3_tc_get(rtems_timecounter_simple *tc) 49 { 50 return LEON3_Timer_Regs->timer[LEON3_CLOCK_INDEX].value; 51 } 52 53 static bool leon3_tc_is_pending(rtems_timecounter_simple *tc) 54 { 55 return LEON_Is_interrupt_pending(clkirq); 56 } 57 58 static uint32_t leon3_tc_get_timecount(struct timecounter *tc) 59 { 60 return rtems_timecounter_simple_downcounter_get( 61 tc, 62 leon3_tc_get, 63 leon3_tc_is_pending 64 ); 65 } 66 67 static uint32_t leon3_tc_get_timecount_irqmp(struct timecounter *tc) 68 { 69 return LEON3_IrqCtrl_Regs->timestamp[0].counter; 70 } 71 72 static void leon3_tc_tick(void) 73 { 74 if (leon3_tc_use_irqmp) { 75 rtems_timecounter_tick(); 76 } else { 77 rtems_timecounter_simple_downcounter_tick(&leon3_tc, leon3_tc_get); 78 } 79 } 42 80 43 81 static void leon3_clock_profiling_interrupt_delay(void) … … 113 151 } 114 152 153 static void leon3_clock_initialize(void) 154 { 155 volatile struct irqmp_timestamp_regs *irqmp_ts = 156 &LEON3_IrqCtrl_Regs->timestamp[0]; 157 158 LEON3_Timer_Regs->timer[LEON3_CLOCK_INDEX].reload = 159 rtems_configuration_get_microseconds_per_tick() - 1; 160 LEON3_Timer_Regs->timer[LEON3_CLOCK_INDEX].ctrl = 161 GPTIMER_TIMER_CTRL_EN | GPTIMER_TIMER_CTRL_RS | 162 GPTIMER_TIMER_CTRL_LD | GPTIMER_TIMER_CTRL_IE; 163 164 if (leon3_irqmp_has_timestamp(irqmp_ts)) { 165 leon3_tc.tc.tc_get_timecount = leon3_tc_get_timecount_irqmp; 166 leon3_tc.tc.tc_counter_mask = 0xffffffff; 167 leon3_tc.tc.tc_frequency = ambapp_freq_get(&ambapp_plb, LEON3_Timer_Adev); 168 leon3_tc.tc.tc_quality = RTEMS_TIMECOUNTER_QUALITY_CLOCK_DRIVER; 169 leon3_tc_use_irqmp = true; 170 rtems_timecounter_install(&leon3_tc.tc); 171 } else { 172 rtems_timecounter_simple_install( 173 &leon3_tc, 174 LEON3_GPTIMER_0_FREQUENCY_SET_BY_BOOT_LOADER, 175 rtems_configuration_get_microseconds_per_tick(), 176 leon3_tc_get_timecount 177 ); 178 } 179 } 180 115 181 #define Clock_driver_support_initialize_hardware() \ 116 do { \ 117 LEON3_Timer_Regs->timer[LEON3_CLOCK_INDEX].reload = \ 118 rtems_configuration_get_microseconds_per_tick() - 1; \ 119 \ 120 LEON3_Timer_Regs->timer[LEON3_CLOCK_INDEX].ctrl = \ 121 GPTIMER_TIMER_CTRL_EN | GPTIMER_TIMER_CTRL_RS | \ 122 GPTIMER_TIMER_CTRL_LD | GPTIMER_TIMER_CTRL_IE; \ 123 } while (0) 182 leon3_clock_initialize() 124 183 125 184 #define Clock_driver_support_shutdown_hardware() \ … … 129 188 } while (0) 130 189 131 static uint32_t bsp_clock_nanoseconds_since_last_tick(void) 132 { 133 uint32_t clicks; 134 uint32_t usecs; 135 136 if ( !LEON3_Timer_Regs ) 137 return 0; 138 139 clicks = LEON3_Timer_Regs->timer[LEON3_CLOCK_INDEX].value; 140 141 if ( LEON_Is_interrupt_pending( clkirq ) ) { 142 clicks = LEON3_Timer_Regs->timer[LEON3_CLOCK_INDEX].value; 143 usecs = (2*rtems_configuration_get_microseconds_per_tick() - clicks); 144 } else { 145 usecs = (rtems_configuration_get_microseconds_per_tick() - clicks); 146 } 147 return usecs * 1000; 148 } 149 150 #define Clock_driver_nanoseconds_since_last_tick \ 151 bsp_clock_nanoseconds_since_last_tick 190 #define Clock_driver_timecounter_tick() leon3_tc_tick() 152 191 153 192 #include "../../../shared/clockdrv_shell.h" -
c/src/lib/libbsp/sparc64/shared/clock/ckinit.c
r7cd2484 r75acd9e 115 115 } while ( 0 ) 116 116 117 #define CLOCK_DRIVER_USE_DUMMY_TIMECOUNTER 118 117 119 #include "../../../shared/clockdrv_shell.h" 118 120 -
c/src/lib/libcpu/arm/at91rm9200/clock/clock.c
r7cd2484 r75acd9e 22 22 #include <at91rm9200.h> 23 23 #include <at91rm9200_pmc.h> 24 25 static unsigned long st_pimr_reload;26 24 27 25 /** … … 78 76 } while(0) 79 77 80 uint16_t st_pimr_value;81 78 static void Clock_driver_support_initialize_hardware(void) 82 79 { 83 80 uint32_t st_str; 84 81 int slck; 82 unsigned long value; 85 83 86 84 /* the system timer is driven from SLCK */ 87 85 slck = at91rm9200_get_slck(); 88 st_pimr_value = (((rtems_configuration_get_microseconds_per_tick() * slck) +86 value = (((rtems_configuration_get_microseconds_per_tick() * slck) + 89 87 (1000000/2))/ 1000000); 90 st_pimr_reload = st_pimr_value;91 88 92 89 /* read the status to clear the int */ … … 98 95 99 96 /* set the timer value */ 100 ST_REG(ST_PIMR) = st_pimr_reload;97 ST_REG(ST_PIMR) = value; 101 98 } 102 103 static uint32_t bsp_clock_nanoseconds_since_last_tick(void)104 {105 uint16_t slck_counts;106 107 slck_counts = st_pimr_value - st_pimr_reload;108 return (rtems_configuration_get_microseconds_per_tick() * slck_counts * 1000)109 / st_pimr_value;110 }111 112 #define Clock_driver_nanoseconds_since_last_tick \113 bsp_clock_nanoseconds_since_last_tick114 99 115 100 #define Clock_driver_support_at_tick() \ … … 127 112 } 128 113 114 #define CLOCK_DRIVER_USE_DUMMY_TIMECOUNTER 115 129 116 #include "../../../../libbsp/shared/clockdrv_shell.h" -
c/src/lib/libcpu/arm/lpc22xx/clock/clockdrv.c
r7cd2484 r75acd9e 18 18 #include <lpc22xx.h> 19 19 #include <rtems/bspIo.h> /* for printk */ 20 #include <rtems/timecounter.h> 20 21 21 22 void Clock_isr(rtems_irq_hdl_param arg); … … 23 24 static void clock_isr_off(const rtems_irq_connect_data *unused); 24 25 static int clock_isr_is_on(const rtems_irq_connect_data *irq); 26 27 static rtems_timecounter_simple lpc22xx_tc; 28 29 static uint32_t lpc22xx_tc_get(rtems_timecounter_simple *tc) 30 { 31 return T0TC; 32 } 33 34 static bool lpc22xx_tc_is_pending(rtems_timecounter_simple *tc) 35 { 36 return (T0IR & 0x1) != 0; 37 } 38 39 static uint32_t lpc22xx_tc_get_timecount(struct timecounter *tc) 40 { 41 return rtems_timecounter_simple_upcounter_get( 42 tc, 43 lpc22xx_tc_get, 44 lpc22xx_tc_is_pending 45 ); 46 } 47 48 static void lpc22xx_tc_tick(void) 49 { 50 rtems_timecounter_simple_upcounter_tick(&lpc22xx_tc, lpc22xx_tc_get); 51 } 25 52 26 53 /* Replace the first value with the clock's interrupt name. */ … … 75 102 #define Clock_driver_support_initialize_hardware() \ 76 103 do { \ 104 uint32_t mask; \ 77 105 /* disable and clear timer 0, set to */ \ 78 106 T0TCR &= 0; \ 79 /* TC is incremente ton every pclk.*/ \107 /* TC is incremented on every pclk.*/ \ 80 108 T0PC = 0; \ 81 109 /* initialize the timer period and prescaler */ \ … … 90 118 /* enable interrupt, skyeye will check this*/ \ 91 119 T0IR |= 0x01; \ 120 /* install timecounter */ \ 121 rtems_timecounter_simple_install( \ 122 &lpc22xx_tc, \ 123 LPC22xx_Fpclk, \ 124 T0MR0, \ 125 lpc22xx_tc_get_timecount \ 126 ); \ 92 127 } while (0) 93 128 … … 104 139 BSP_remove_rtems_irq_handler(&clock_isr_data); \ 105 140 } while (0) 106 107 static uint32_t bsp_clock_nanoseconds_since_last_tick(void)108 {109 uint32_t clicks;110 uint32_t microseconds;111 112 clicks = T0TC; /* T0TC is the 32bit time counter 0 */113 114 microseconds = (rtems_configuration_get_microseconds_per_tick() - clicks);115 return microseconds * 1000;116 }117 118 #define Clock_driver_nanoseconds_since_last_tick \119 bsp_clock_nanoseconds_since_last_tick120 141 121 142 /** … … 150 171 } 151 172 173 #define Clock_driver_timecounter_tick() lpc22xx_tc_tick() 174 152 175 /* Make sure to include this, and only at the end of the file */ 153 176 #include "../../../../libbsp/shared/clockdrv_shell.h" -
c/src/lib/libcpu/arm/mc9328mxl/clock/clockdrv.c
r7cd2484 r75acd9e 131 131 } 132 132 133 #define CLOCK_DRIVER_USE_DUMMY_TIMECOUNTER 134 133 135 /* Make sure to include this, and only at the end of the file */ 136 134 137 #include "../../../../libbsp/shared/clockdrv_shell.h" -
c/src/lib/libcpu/arm/pxa255/clock/clock.c
r7cd2484 r75acd9e 117 117 } 118 118 119 #define CLOCK_DRIVER_USE_DUMMY_TIMECOUNTER 120 119 121 #include "../../../../libbsp/shared/clockdrv_shell.h" -
c/src/lib/libcpu/arm/s3c24xx/clock/clockdrv.c
r7cd2484 r75acd9e 27 27 .isOn = clock_isr_is_on, 28 28 }; 29 30 /**31 * Return the nanoseconds since last tick32 */33 static uint32_t clock_driver_get_nanoseconds_since_last_tick(void)34 {35 return 0;36 }37 38 #define Clock_driver_nanoseconds_since_last_tick \39 clock_driver_get_nanoseconds_since_last_tick40 29 41 30 /** … … 75 64 uint32_t cr; \ 76 65 uint32_t freq; \ 66 uint32_t mask; \ 77 67 /* set MUX for Timer4 to 1/16 */ \ 78 68 cr=rTCFG1 & 0xFFF0FFFF; \ … … 132 122 } 133 123 124 #define CLOCK_DRIVER_USE_DUMMY_TIMECOUNTER 125 134 126 /* Make sure to include this, and only at the end of the file */ 135 127 #include "../../../../libbsp/shared/clockdrv_shell.h" -
c/src/lib/libcpu/powerpc/mpc6xx/clock/c_clock.c
r7cd2484 r75acd9e 30 30 #include <rtems/bspIo.h> /* for printk() */ 31 31 #include <libcpu/powerpc-utility.h> 32 #include <rtems/timecounter.h> 32 33 33 34 #include <bspopts.h> /* for CLOCK_DRIVER_USE_FAST_IDLE */ … … 49 50 static uint32_t Clock_Decrementer_value; 50 51 51 /* 52 * This is the value by which elapsed count down timer ticks are multiplied to 53 * give an elapsed duration in nanoseconds, left-shifted by 32 bits 54 */ 55 static uint64_t Clock_Decrementer_reference; 52 static struct timecounter Clock_TC; 53 54 static uint32_t Clock_Get_timecount(struct timecounter *tc) 55 { 56 return ppc_time_base(); 57 } 56 58 57 59 void clockOff(void* unused) … … 95 97 { 96 98 #if (CLOCK_DRIVER_USE_FAST_IDLE == 1) 97 do { 98 rtems_clock_tick(); 99 } while ( 99 rtems_interrupt_level level; 100 uint32_t tb; 101 102 rtems_interrupt_disable(level); 103 104 tb = ppc_time_base(); 105 rtems_timecounter_tick(); 106 107 while ( 100 108 _Thread_Heir == _Thread_Executing 101 109 && _Thread_Executing->Start.entry_point 102 110 == (Thread_Entry) rtems_configuration_get_idle_task() 103 ); 104 111 ) { 112 tb += Clock_Decrementer_value; 113 ppc_set_time_base( tb ); 114 rtems_timecounter_tick(); 115 } 116 117 rtems_interrupt_enable(level); 105 118 #else 106 rtems_ clock_tick();119 rtems_timecounter_tick(); 107 120 #endif 108 121 } … … 142 155 143 156 Clock_driver_ticks += 1; 144 145 157 /* 146 158 * Real Time Clock counter/timer is set to automatically reload. … … 188 200 } 189 201 190 191 202 /* 192 203 * Clock_exit … … 198 209 { 199 210 (void) BSP_disconnect_clock_handler (); 200 }201 202 static uint32_t Clock_driver_nanoseconds_since_last_tick(void)203 {204 uint32_t clicks, tmp;205 206 PPC_Get_decrementer( clicks );207 208 /*209 * Multiply by 1000 here separately from below so we do not overflow210 * and get a negative value.211 */212 tmp = (Clock_Decrementer_value - clicks) * 1000;213 tmp /= (BSP_bus_frequency/BSP_time_base_divisor);214 215 return tmp * 1000;216 }217 218 static uint32_t Clock_driver_nanoseconds_since_last_tick_bookE(void)219 {220 uint32_t clicks;221 uint64_t c;222 223 PPC_Get_decrementer( clicks );224 c = Clock_Decrementer_value - clicks;225 226 /*227 * Check whether a clock tick interrupt is pending and hence that the228 * decrementer's wrapped. If it has, we'll compensate by returning a time one229 * tick period longer.230 *231 * We have to check interrupt status after reading the decrementer. If we232 * don't, we may miss an interrupt and read a wrapped decrementer value233 * without compensating for it234 */235 if ( _read_BOOKE_TSR() & BOOKE_TSR_DIS )236 {237 /*238 * Re-read the decrementer: The tick interrupt may have been239 * generated and the decrementer wrapped during the time since we240 * last read it and the time we checked the interrupt status241 */242 PPC_Get_decrementer( clicks );243 c = (Clock_Decrementer_value - clicks) + Clock_Decrementer_value;244 }245 246 return (uint32_t)((c * Clock_Decrementer_reference) >> 32);247 211 } 248 212 … … 263 227 rtems_configuration_get_milliseconds_per_tick(); 264 228 265 Clock_Decrementer_reference = ((uint64_t)1000000U<<32)/266 (BSP_bus_frequency/BSP_time_base_divisor);267 268 229 /* set the decrementer now, prior to installing the handler 269 230 * so no interrupts will happen in a while. … … 284 245 285 246 rtems_interrupt_enable(l); 286 287 /* 288 * Set the nanoseconds since last tick handler 289 */ 290 rtems_clock_set_nanoseconds_extension( 291 Clock_driver_nanoseconds_since_last_tick_bookE 292 ); 293 } 294 else 295 { 296 /* 297 * Set the nanoseconds since last tick handler 298 */ 299 rtems_clock_set_nanoseconds_extension( 300 Clock_driver_nanoseconds_since_last_tick 301 ); 302 } 247 } 248 249 Clock_TC.tc_get_timecount = Clock_Get_timecount; 250 Clock_TC.tc_counter_mask = 0xffffffff; 251 Clock_TC.tc_frequency = (1000 * BSP_bus_frequency) / BSP_time_base_divisor; 252 Clock_TC.tc_quality = RTEMS_TIMECOUNTER_QUALITY_CLOCK_DRIVER; 253 rtems_timecounter_install(&Clock_TC); 303 254 304 255 /*
Note: See TracChangeset
for help on using the changeset viewer.