source: rtems/c/src/lib/libbsp/m68k/mvme136/timer/timer.c @ ac7d5ef0

4.104.114.84.95
Last change on this file since ac7d5ef0 was ac7d5ef0, checked in by Joel Sherrill <joel.sherrill@…>, on 05/11/95 at 17:39:37

Initial revision

  • Property mode set to 100644
File size: 3.4 KB
Line 
1/*  Timer_init()
2 *
3 *  This routine initializes the Z8036 timer on the MVME136 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 to the Z8036
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 *  $Id$
25 */
26
27
28#include <rtems.h>
29#include <bsp.h>
30#include <z8036.h>
31
32#define TIMER 0xfffb0000   /* address of Z8036 on MVME136 */
33
34int Ttimer_val;
35rtems_boolean Timer_driver_Find_average_overhead;
36
37rtems_isr timerisr();
38
39void Timer_initialize()
40{
41  (void) set_vector( timerisr, 66, 0 );       /* install ISR */
42
43  Ttimer_val = 0;                             /* clear timer ISR count */
44  Z8x36_WRITE( TIMER, MASTER_INTR, 0x01 ); /* reset */
45  Z8x36_WRITE( TIMER, MASTER_INTR, 0x00 ); /* clear reset */
46  Z8x36_WRITE( TIMER, MASTER_INTR, 0xe2 ); /* disable lower chain, no vec */
47                                           /*  set right justified addr */
48                                              /*  and master int enable */
49  Z8x36_WRITE( TIMER, CT1_MODE_SPEC,  0x80 ); /* T1 continuous, and   */
50                                              /* cycle/pulse output   */
51
52  *((rtems_unsigned16 *)0xfffb0016) = 0x0000; /* write countdown value */
53/*
54  Z8x36_WRITE( TIMER, CT1_TIME_CONST_MSB, 0x00 );
55  Z8x36_WRITE( TIMER, CT1_TIME_CONST_LSB, 0x00 );
56*/
57  Z8x36_WRITE( TIMER, MASTER_CFG,         0xc4 ); /* enable timer1        */
58
59  Z8x36_WRITE( TIMER, CT1_CMD_STATUS,     0xc6 ); /* set INTR enable (IE), */
60                                                 /*  trigger command      */
61                                                 /*  (TCB) and gate       */
62                                                 /* command (GCB) bits    */
63  *((rtems_unsigned8 *)0xfffb0038) &= 0xfd;      /* enable timer INTR on  */
64                                                 /*    VME controller     */
65}
66
67#define AVG_OVERHEAD      6  /* It typically takes 3.0 microseconds */
68                             /* (6 countdowns) to start/stop the timer. */
69#define LEAST_VALID       10 /* Don't trust a value lower than this */
70
71int Read_timer()
72{
73/*
74  rtems_unsigned8  msb, lsb;
75*/
76  rtems_unsigned32 remaining, total;
77
78  Z8x36_WRITE( TIMER, CT1_CMD_STATUS,  0xce ); /* read the counter value */
79remaining = 0xffff - *((rtems_unsigned16 *) 0xfffb0010);
80/*
81  Z8x36_READ(  TIMER, CT1_CUR_CNT_MSB, msb );
82  Z8x36_READ(  TIMER, CT1_CUR_CNT_LSB, lsb );
83
84  remaining = 0xffff - ((msb << 8) + lsb);
85*/
86  total = (Ttimer_val * 0x10000) + remaining;
87
88  if ( Timer_driver_Find_average_overhead == 1 )
89    return total;          /* in one-half microsecond units */
90
91  else {
92    if ( total < LEAST_VALID )
93      return 0;            /* below timer resolution */
94    return (total-AVG_OVERHEAD) >> 1;
95  }
96}
97
98rtems_status_code Empty_function( void )
99{
100  return RTEMS_SUCCESSFUL;
101}
102
103void Set_find_average_overhead(
104  rtems_boolean find_flag
105)
106{
107  Timer_driver_Find_average_overhead = find_flag;
108}
Note: See TracBrowser for help on using the repository browser.