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

4.104.114.84.9
Last change on this file since f4fe0092 was f4fe0092, checked in by Joel Sherrill <joel.sherrill@…>, on Sep 4, 2003 at 6:52:04 PM

2003-09-04 Joel Sherrill <joel@…>

  • clock/ckinit.c, console/console.c, consolex/cTest.c, consolex/consolex.c, consolex/consolex.h, include/bsp.h, include/coverhd.h, include/tod.h, startup/bspclean.c, startup/bspstart.c, startup/linkcmds, timer/timer.c, timer/timerisr.S, tod/tod.c: URL for license changed.
  • Property mode set to 100644
File size: 2.7 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-1999.
17 *  On-Line Applications Research Corporation (OAR).
18 *
19 *  The license and distribution terms for this file may be
20 *  found in the file LICENSE in this distribution or at
21 *  http://www.rtems.com/license/LICENSE.
22 *
23 *  Modifications of respective RTEMS file: COPYRIGHT (c) 1994.
24 *  EISCAT Scientific Association. M.Savitski
25 *
26 *  This material is a part of the MVME162 Board Support Package
27 *  for the RTEMS executive. Its licensing policies are those of the
28 *  RTEMS above.
29 *
30 *  $Id$
31 */
32
33#include <rtems.h>
34#include <bsp.h>
35
36/* Periodic tick interval */
37#define TICK_INTERVAL         0x10000U
38#define TIMER_INT_LEVEL       6
39
40rtems_unsigned32    Ttimer_val;
41rtems_boolean       Timer_driver_Find_average_overhead;
42
43rtems_isr timerisr();
44
45void Timer_initialize()
46{
47  (void) set_vector( timerisr, VBR0 * 0x10 + 0x8, 0 );
48 
49  Ttimer_val = 0;                     /* clear timer ISR count */
50  lcsr->vector_base |= MASK_INT;      /* unmask VMEchip2 interrupts */
51  lcsr->intr_clear |= 0x01000000;     /* clear pending interrupt */
52  lcsr->to_ctl = 0xE7;                /* prescaler to 1 MHz (see Appendix A1) */
53  lcsr->timer_cmp_1 = TICK_INTERVAL;
54  lcsr->timer_cnt_1 = 0;              /* clear counter */
55  lcsr->board_ctl |= 7;               /* increment, reset-on-compare, */
56                                      /*   and clear-overflow-cnt */
57
58  lcsr->intr_level[0] |= TIMER_INT_LEVEL; /* set int level */
59  lcsr->intr_ena |= 0x01000000;           /* enable tick timer 1 interrupt */
60}
61
62#define AVG_OVERHEAD      3U    /* It typically takes 3.0 microseconds */
63                                /* (3 countdowns) to start/stop the timer. */
64#define LEAST_VALID       10U   /* Don't trust a value lower than this */
65
66int Read_timer() 
67{
68  rtems_unsigned32    total;
69
70  total = (Ttimer_val * TICK_INTERVAL) + lcsr->timer_cnt_1;
71
72  if ( Timer_driver_Find_average_overhead == 1 )
73    return total;          /* in one-half microsecond units */
74
75  if ( total < LEAST_VALID )
76    return 0;            /* below timer resolution */
77
78  return (total-AVG_OVERHEAD) >> 1;
79}
80
81
82rtems_status_code Empty_function( void )
83{
84  return RTEMS_SUCCESSFUL;
85}
86
87void Set_find_average_overhead(
88  rtems_boolean find_flag
89)
90{
91  Timer_driver_Find_average_overhead = find_flag;
92}
Note: See TracBrowser for help on using the repository browser.