source: rtems/c/src/lib/libcpu/powerpc/ppc403/timer/timer.c @ d3d9ef37

4.104.114.84.95
Last change on this file since d3d9ef37 was 66c373bf, checked in by Ralf Corsepius <ralf.corsepius@…>, on 03/31/04 at 02:04:00

2004-03-30 Ralf Corsepius <ralf_corsepius@…>

  • mpc505/timer/timer.c, mpc5xx/timer/timer.c, mpc6xx/clock/c_clock.c, mpc6xx/timer/timer.c, mpc8260/clock/clock.c, mpc8260/console-generic/console-generic.c, mpc8260/cpm/cp.c, mpc8260/cpm/dpram.c, mpc8260/include/cpm.h, mpc8260/include/mmu.h, mpc8260/include/mpc8260.h, mpc8260/mmu/mmu.c, mpc8260/timer/timer.c, mpc8xx/clock/clock.c, mpc8xx/console-generic/console-generic.c, mpc8xx/cpm/cp.c, mpc8xx/cpm/dpram.c, mpc8xx/include/cpm.h, mpc8xx/include/mmu.h, mpc8xx/include/mpc8xx.h, mpc8xx/mmu/mmu.c, mpc8xx/timer/timer.c, ppc403/clock/clock.c, ppc403/console/console.c, ppc403/console/console405.c, ppc403/ictrl/ictrl.c, ppc403/ictrl/ictrl.h, ppc403/timer/timer.c, ppc403/tty_drv/tty_drv.c, rtems/powerpc/cache.h, shared/src/cache.c: Convert to using c99 fixed size types.
  • Property mode set to 100644
File size: 3.2 KB
Line 
1/*  timer.c
2 *
3 *  This file manages the interval timer on the PowerPC 403*.
4 *  We shall use the bottom 32 bits of the timebase register,
5 *
6 *  NOTE: It is important that the timer start/stop overhead be
7 *        determined when porting or modifying this code.
8 *
9 *  Author:     Andrew Bray <andy@i-cubed.co.uk>
10 *
11 *  COPYRIGHT (c) 1995 by i-cubed ltd.
12 *
13 *  To anyone who acknowledges that this file is provided "AS IS"
14 *  without any express or implied warranty:
15 *      permission to use, copy, modify, and distribute this file
16 *      for any purpose is hereby granted without fee, provided that
17 *      the above copyright notice and this notice appears in all
18 *      copies, and that the name of i-cubed limited not be used in
19 *      advertising or publicity pertaining to distribution of the
20 *      software without specific, written prior permission.
21 *      i-cubed limited makes no representations about the suitability
22 *      of this software for any purpose.
23 *
24 *  Derived from c/src/lib/libcpu/hppa1.1/timer/timer.c:
25 *
26 *  COPYRIGHT (c) 1989-1999.
27 *  On-Line Applications Research Corporation (OAR).
28 *
29 *  The license and distribution terms for this file may be
30 *  found in the file LICENSE in this distribution or at
31 *  http://www.rtems.com/license/LICENSE.
32 *
33 *  Modifications for PPC405GP by Dennis Ehlin
34 *
35 *  $Id$
36 *
37 */
38
39#include <rtems.h>
40
41static volatile uint32_t   Timer_starting;
42static rtems_boolean Timer_driver_Find_average_overhead;
43
44/*
45 *  This is so small that this code will be reproduced where needed.
46 */
47static inline uint32_t   get_itimer(void)
48{
49   uint32_t   ret;
50
51#ifndef ppc405
52   asm volatile ("mfspr %0, 0x3dd" : "=r" ((ret))); /* TBLO */
53#else /* ppc405 */
54/*   asm volatile ("mfspr %0, 0x3dd" : "=r" ((ret)));  TBLO */
55
56   asm volatile ("mfspr %0, 0x10c" : "=r" ((ret))); /* 405GP TBL */
57#endif /* ppc405 */
58
59   return ret;
60}
61
62void Timer_initialize()
63{
64  uint32_t   iocr;
65
66#ifndef ppc405
67  asm volatile ("mfdcr %0, 0xa0" : "=r" (iocr)); /* IOCR */
68  iocr &= ~4;
69  iocr |= 4;  /* Select external timer clock */
70  asm volatile ("mtdcr 0xa0, %0" : "=r" (iocr) : "0" (iocr)); /* IOCR */
71#else /* ppc405 */
72  asm volatile ("mfdcr %0, 0x0b2" : "=r" (iocr));  /*405GP CPC0_CR1 */
73/*  asm volatile ("mfdcr %0, 0xa0" : "=r" (iocr)); IOCR */
74
75  /* iocr |= 0x800000;  select external timer clock CETE*/
76  iocr &= ~0x800000; /* timer clocked from system clock CETE*/
77
78  asm volatile ("mtdcr 0x0b2, %0" : "=r" (iocr) : "0" (iocr)); /* 405GP CPC0_CR1 */
79/*  asm volatile ("mtdcr 0xa0, %0" : "=r" (iocr) : "0" (iocr));  IOCR */
80#endif /* ppc405 */
81
82  Timer_starting = get_itimer();
83}
84
85int Read_timer()
86{
87  uint32_t   clicks;
88  uint32_t   total;
89
90  clicks = get_itimer();
91
92  total = clicks - Timer_starting;
93
94  if ( Timer_driver_Find_average_overhead == 1 )
95    return total;          /* in XXX microsecond units */
96
97  else {
98    if ( total < rtems_cpu_configuration_get_timer_least_valid() )
99      return 0;            /* below timer resolution */
100    return (total - rtems_cpu_configuration_get_timer_average_overhead());
101  }
102}
103
104rtems_status_code Empty_function( void )
105{
106  return RTEMS_SUCCESSFUL;
107}
108
109void Set_find_average_overhead(
110  rtems_boolean find_flag
111)
112{
113  Timer_driver_Find_average_overhead = find_flag;
114}
Note: See TracBrowser for help on using the repository browser.