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

4.104.114.84.95
Last change on this file since d2632274 was 98e4ebf, checked in by Joel Sherrill <joel.sherrill@…>, on Oct 8, 1997 at 3:45:54 PM

Fixed typo in the pointer to the license terms.

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