source: rtems/c/src/lib/libbsp/i960/cvme961/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.7 KB
Line 
1/*  Timer_init()
2 *
3 *  This routine initializes the Z8536 timer on the SQSIO4 SQUALL
4 *  board for the CVME961 board.  The timer is setup to provide a
5 *  tick every 1 millisecond.
6 *
7 *  Input parameters:  NONE
8 *
9 *  Output parameters:  NONE
10 *
11 *  NOTE: This routine will not work if the optimizer is enabled
12 *        for most compilers.  The multiple writes to the Z8536
13 *        will be optimized away.
14 *
15 *        It is important that the timer start/stop overhead be
16 *        determined when porting or modifying this code.
17 *
18 *  COPYRIGHT (c) 1989-1999.
19 *  On-Line Applications Research Corporation (OAR).
20 *
21 *  The license and distribution terms for this file may be
22 *  found in the file LICENSE in this distribution or at
23 *  http://www.rtems.com/license/LICENSE.
24 *
25 *  $Id$
26 */
27
28#include <rtems.h>
29#include <bsp.h>
30#include <rtems/zilog/z8536.h>
31
32#define TIMER       0xc00000a0
33
34int Ttimer_val;
35rtems_boolean Timer_driver_Find_average_overhead;
36
37void flush_reg();
38rtems_isr timerisr();
39
40void Timer_initialize()
41{
42  set_vector( timerisr, 4, 0 );               /* install ISR */
43
44  i960_mask_intr( 5 );                        /* disable VIC068 tick */
45  flush_reg();                                /* timed code starts clean */
46  Ttimer_val = 0;                             /* clear timer ISR count */
47  Z8x36_WRITE( TIMER, MASTER_INTR,    0x01 ); /* reset              */
48  Z8x36_WRITE( TIMER, MASTER_INTR,    0x00 ); /* clear reset        */
49  Z8x36_WRITE( TIMER, MASTER_CFG,     0x00 ); /* disable everything */
50  Z8x36_WRITE( TIMER, CNT_TMR_VECTOR, 0x72 ); /* clear intr vector  */
51  Z8x36_WRITE( TIMER, MASTER_CFG,     0x20 ); /* clear intr info    */
52  Z8x36_WRITE( TIMER, MASTER_CFG,     0xe0 ); /* disable interrupts */
53  Z8x36_WRITE( TIMER, MASTER_CFG,     0x20 ); /* clear intr info    */
54  Z8x36_WRITE( TIMER, MASTER_CFG,     0xe0 ); /* disable interrupts */
55  Z8x36_WRITE( TIMER, MASTER_INTR,    0xe2 ); /* disable lower chain,   */
56                                              /*   no vector, set right */
57                                              /*   justified addr and   */
58                                              /*   master int enable    */
59  Z8x36_WRITE( TIMER, CT1_MODE_SPEC,      0x80 ); /* T1 continuous, and   */
60                                                  /*   cycle/pulse output */
61  Z8x36_WRITE( TIMER, CT1_TIME_CONST_MSB, 0x00 );
62  Z8x36_WRITE( TIMER, CT1_TIME_CONST_LSB, 0x00 );
63  Z8x36_WRITE( TIMER, CT1_CMD_STATUS,     0xc0 ); /* set INTR enable (IE) */
64  Z8x36_WRITE( TIMER, MASTER_CFG,         0x40 ); /* enable timer1        */
65  Z8x36_WRITE( TIMER, CT1_CMD_STATUS,     0x06 ); /* set trigger command  */
66                                                  /*   (TCB) and gate     */
67                                                  /* command (GCB) bits   */
68}
69
70#define AVG_OVERHEAD      11 /* It typically takes 5.5 microseconds */
71                             /* (11 countdowns) to start/stop the timer. */
72#define LEAST_VALID       15 /* Don't trust a value lower than this */
73
74int Read_timer()
75{
76  uint8_t          msb, lsb;
77  uint32_t         remaining, total;
78
79  Z8x36_WRITE( TIMER, CT1_CMD_STATUS,  0xce );  /* read the counter value */
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  total = (Ttimer_val * 0x10000) + remaining;
85
86  if ( Timer_driver_Find_average_overhead == 1 )
87    return total;          /* in one-half microsecond units */
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.