source: rtems/c/src/lib/libbsp/m68k/idp/timer/timer.c @ 67c191b2

4.9
Last change on this file since 67c191b2 was 67c191b2, checked in by Joel Sherrill <joel.sherrill@…>, on 09/30/08 at 16:28:39

2008-09-30 Joel Sherrill <joel.sherrill@…>

  • timer/timer.c: Eliminate uses of old benchmark timer names.
  • Property mode set to 100644
File size: 2.7 KB
Line 
1/*
2 *  Code Modified for the MC68230 by Doug McBride, Colorado Space Grant College
3 *
4 *  COPYRIGHT (c) 1989-1999.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 *  The license and distribution terms for this file may be
8 *  found in the file LICENSE in this distribution or at
9 *  http://www.rtems.com/license/LICENSE.
10 *
11 *  $Id$
12 */
13
14#include <rtems.h>
15#include <bsp.h>
16#include <rtems/motorola/mc68230.h>
17
18#define TIMER_VECTOR 0x4D
19
20int Ttimer_val;
21bool benchmark_timer_find_average_overhead;
22
23rtems_isr timerisr(void);
24
25void benchmark_timer_initialize(void)
26{
27  (void) set_vector( timerisr, TIMER_VECTOR, 0 );  /* install ISR */
28
29  Ttimer_val = 0;                          /* clear timer ISR count */
30
31  /* some PI/T initialization stuff here */
32  /* Set up the interrupt vector on the MC68230 chip:
33     TIVR = TIMER_VECTOR; */
34  MC68230_WRITE (MC68230_TIVR, TIMER_VECTOR);
35
36  /* Set CPRH through CPRL to maximum count to reduce interrupt overhead
37      CPRH = 0xFF;
38      CPRM = 0xFF;
39      CPRL = 0xFF; */
40  MC68230_WRITE (MC68230_CPRH, 0xFF);
41  MC68230_WRITE (MC68230_CPRM, 0xFF);
42  MC68230_WRITE (MC68230_CPRL, 0xFF);
43
44  /* Enable timer and use it as an external periodic interrupt generator
45      TCR = 0xA1; */
46  MC68230_WRITE (MC68230_TCR, 0xA1);
47
48}
49
50#define AVG_OVERHEAD      9  /* may not be right -- do this later */
51#define LEAST_VALID       10 /* Don't trust a value lower than this */
52
53int benchmark_timer_read(void)
54{
55  uint8_t         data;
56  uint8_t          msb, osb, lsb;
57  uint32_t         remaining, total;
58
59  /* Disable timer so that timer can be read
60        data = MC68230_TCR;
61        MC68230_TCR = (data & 0xFE); */
62  MC68230_READ (MC68230_TCR, data);
63  MC68230_WRITE (MC68230_TCR, (data & 0xFE));
64
65  /* Read the counter value
66        msb = MC68230_CNTRH;
67        osb = MC68230_CNTRM;
68        lsb = MC68230_CNTRL; */
69  MC68230_READ (MC68230_CNTRH, msb);
70  MC68230_READ (MC68230_CNTRM, osb);
71  MC68230_READ (MC68230_CNTRL, lsb);
72
73  /* Calculate the time so far */
74  remaining = 0x1000000 - ((msb << 16) + (osb << 8) + lsb);
75  total = (Ttimer_val * 0x1000000) + remaining;
76
77  /* Enable timer so that timer can continue
78                MC68230_TCR = 0xA1; */
79  MC68230_WRITE (MC68230_TCR, 0xA1);
80
81  /* do not restore old vector */
82  if ( benchmark_timer_find_average_overhead == true )
83    return total;          /* in countdown units */
84
85  if ( total < LEAST_VALID )
86    return 0;            /* below timer resolution */
87
88  /* Clocked at 6.5 Mhz */
89  /* Avoid floating point problems, be lazy, and return the total minus
90     the average overhead */
91  return (total - AVG_OVERHEAD);
92}
93
94void benchmark_timer_disable_subtracting_average_overhead(
95  bool find_flag
96)
97{
98  benchmark_timer_find_average_overhead = find_flag;
99}
Note: See TracBrowser for help on using the repository browser.