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

4.104.114.84.95
Last change on this file since f05b2ac was f05b2ac, checked in by Ralf Corsepius <ralf.corsepius@…>, on 04/21/04 at 16:01:48

Remove duplicate white lines.

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