source: rtems/c/src/lib/libbsp/m68k/idp/timer/timer.c @ 6da91abb

4.115
Last change on this file since 6da91abb was 6da91abb, checked in by Joel Sherrill <joel.sherrill@…>, on Oct 13, 2014 at 7:09:16 PM

m68k/idp: Fix warnings

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