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 10/13/14 at 19:09:16

m68k/idp: Fix warnings

  • Property mode set to 100644
File size: 2.7 KB
RevLine 
[d4b4664b]1/*
[ac7d5ef0]2 *  Code Modified for the MC68230 by Doug McBride, Colorado Space Grant College
3 *
[08311cc3]4 *  COPYRIGHT (c) 1989-1999.
[ac7d5ef0]5 *  On-Line Applications Research Corporation (OAR).
6 *
[98e4ebf5]7 *  The license and distribution terms for this file may be
8 *  found in the file LICENSE in this distribution or at
[c499856]9 *  http://www.rtems.org/license/LICENSE.
[ac7d5ef0]10 */
11
[88d594a]12#include <rtems.h>
[26c17377]13#include <rtems/btimer.h>
[88d594a]14#include <bsp.h>
[7eb78e14]15#include <rtems/motorola/mc68230.h>
[ac7d5ef0]16
17#define TIMER_VECTOR 0x4D
18
19int Ttimer_val;
[907bf4b8]20bool benchmark_timer_find_average_overhead;
[ac7d5ef0]21
[6da91abb]22rtems_isr timerisr(rtems_vector_number);
[ac7d5ef0]23
[25c62b0]24void benchmark_timer_initialize(void)
[ac7d5ef0]25{
26  (void) set_vector( timerisr, TIMER_VECTOR, 0 );  /* install ISR */
[6128a4a]27
[ac7d5ef0]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; */
[c961d152]33  MC68230_WRITE (MC68230_TIVR, TIMER_VECTOR);
[ac7d5ef0]34
35  /* Set CPRH through CPRL to maximum count to reduce interrupt overhead
36      CPRH = 0xFF;
37      CPRM = 0xFF;
38      CPRL = 0xFF; */
[c961d152]39  MC68230_WRITE (MC68230_CPRH, 0xFF);
40  MC68230_WRITE (MC68230_CPRM, 0xFF);
41  MC68230_WRITE (MC68230_CPRL, 0xFF);
[ac7d5ef0]42
43  /* Enable timer and use it as an external periodic interrupt generator
44      TCR = 0xA1; */
[c961d152]45  MC68230_WRITE (MC68230_TCR, 0xA1);
[ac7d5ef0]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
[8fbe2e6]52benchmark_timer_t benchmark_timer_read(void)
[ac7d5ef0]53{
[629e12a]54  uint8_t         data;
55  uint8_t          msb, osb, lsb;
56  uint32_t         remaining, total;
[ac7d5ef0]57
58  /* Disable timer so that timer can be read
[c961d152]59        data = MC68230_TCR;
60        MC68230_TCR = (data & 0xFE); */
61  MC68230_READ (MC68230_TCR, data);
62  MC68230_WRITE (MC68230_TCR, (data & 0xFE));
[ac7d5ef0]63
64  /* Read the counter value
[c961d152]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);
[ac7d5ef0]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
[c961d152]77                MC68230_TCR = 0xA1; */
78  MC68230_WRITE (MC68230_TCR, 0xA1);
[ac7d5ef0]79
80  /* do not restore old vector */
[907bf4b8]81  if ( benchmark_timer_find_average_overhead == true )
[ac7d5ef0]82    return total;          /* in countdown units */
83
84  if ( total < LEAST_VALID )
85    return 0;            /* below timer resolution */
[6128a4a]86
[ac7d5ef0]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
[25c62b0]93void benchmark_timer_disable_subtracting_average_overhead(
[907bf4b8]94  bool find_flag
[ac7d5ef0]95)
96{
[25c62b0]97  benchmark_timer_find_average_overhead = find_flag;
[ac7d5ef0]98}
Note: See TracBrowser for help on using the repository browser.