source: rtems/c/src/lib/libbsp/m68k/mvme162/timer/timer.c @ 254b4450

4.104.114.84.95
Last change on this file since 254b4450 was c6fb8e90, checked in by Joel Sherrill <joel.sherrill@…>, on Aug 1, 1995 at 3:33:39 PM

updated mvme162 code from Misha (mms@…)

  • Property mode set to 100644
File size: 2.8 KB
Line 
1/*  Timer_init()
2 *
3 *  This routine initializes the Tick Timer 1 on the MVME162 board.
4 *
5 *  Input parameters:  NONE
6 *
7 *  Output parameters:  NONE
8 *
9 *  NOTE: This routine will not work if the optimizer is enabled
10 *        for some compilers.  The multiple writes
11 *        may be optimized away.
12 *
13 *        It is important that the timer start/stop overhead be
14 *        determined when porting or modifying this code.
15 *
16 *  COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994.
17 *  On-Line Applications Research Corporation (OAR).
18 *  All rights assigned to U.S. Government, 1994.
19 *
20 *  This material may be reproduced by or for the U.S. Government pursuant
21 *  to the copyright license under the clause at DFARS 252.227-7013.  This
22 *  notice must appear in all copies of this file and its derivatives.
23 *
24 *  Modifications of respective RTEMS file: COPYRIGHT (c) 1994.
25 *  EISCAT Scientific Association. M.Savitski
26 *
27 *  This material is a part of the MVME162 Board Support Package
28 *  for the RTEMS executive. Its licensing policies are those of the
29 *  RTEMS above.
30 *
31 *  $Id$
32 */
33
34#include <rtems.h>
35#include <bsp.h>
36
37/* Periodic tick interval */
38#define TICK_INTERVAL         0x10000U
39#define TIMER_INT_LEVEL       6
40
41rtems_unsigned32    Ttimer_val;
42rtems_boolean       Timer_driver_Find_average_overhead;
43
44rtems_isr timerisr();
45
46void Timer_initialize()
47{
48  (void) set_vector( timerisr, VBR0 * 0x10 + 0x8, 0 );
49 
50  Ttimer_val = 0;                     /* clear timer ISR count */
51  lcsr->vector_base |= MASK_INT;      /* unmask VMEchip2 interrupts */
52  lcsr->intr_clear |= 0x01000000;     /* clear pending interrupt */
53  lcsr->to_ctl = 0xE7;                /* prescaler to 1 MHz (see Appendix A1) */
54  lcsr->timer_cmp_1 = TICK_INTERVAL;
55  lcsr->timer_cnt_1 = 0;              /* clear counter */
56  lcsr->board_ctl |= 7;               /* increment, reset-on-compare, */
57                                      /*   and clear-overflow-cnt */
58
59  lcsr->intr_level[0] |= TIMER_INT_LEVEL; /* set int level */
60  lcsr->intr_ena |= 0x01000000;           /* enable tick timer 1 interrupt */
61}
62
63#define AVG_OVERHEAD      3U    /* It typically takes 3.0 microseconds */
64                                /* (3 countdowns) to start/stop the timer. */
65#define LEAST_VALID       10U   /* Don't trust a value lower than this */
66
67int Read_timer() 
68{
69  rtems_unsigned32    total;
70
71  total = (Ttimer_val * TICK_INTERVAL) + lcsr->timer_cnt_1;
72
73  if ( Timer_driver_Find_average_overhead == 1 )
74    return total;          /* in one-half microsecond units */
75
76  if ( total < LEAST_VALID )
77    return 0;            /* below timer resolution */
78
79  return (total-AVG_OVERHEAD) >> 1;
80}
81
82
83rtems_status_code Empty_function( void )
84{
85  return RTEMS_SUCCESSFUL;
86}
87
88void Set_find_average_overhead(
89  rtems_boolean find_flag
90)
91{
92  Timer_driver_Find_average_overhead = find_flag;
93}
Note: See TracBrowser for help on using the repository browser.