OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [lib/] [libbsp/] [i960/] [cvme961/] [timer/] [timer.c] - Blame information for rev 173

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 30 unneback
/*  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.OARcorp.com/rtems/license.html.
24
 *
25
 *  $Id: timer.c,v 1.2 2001-09-27 11:59:58 chris Exp $
26
 */
27
 
28
 
29
#include <rtems.h>
30
#include <bsp.h>
31
#include <zilog/z8536.h>
32
 
33
#define TIMER       0xc00000a0
34
 
35
int Ttimer_val;
36
rtems_boolean Timer_driver_Find_average_overhead;
37
 
38
void flush_reg();
39
rtems_isr timerisr();
40
 
41
void Timer_initialize()
42
{
43
  set_vector( timerisr, 4, 0 );               /* install ISR */
44
 
45
  i960_mask_intr( 5 );                        /* disable VIC068 tick */
46
  flush_reg();                                /* timed code starts clean */
47
  Ttimer_val = 0;                             /* clear timer ISR count */
48
  Z8x36_WRITE( TIMER, MASTER_INTR,    0x01 ); /* reset              */
49
  Z8x36_WRITE( TIMER, MASTER_INTR,    0x00 ); /* clear reset        */
50
  Z8x36_WRITE( TIMER, MASTER_CFG,     0x00 ); /* disable everything */
51
  Z8x36_WRITE( TIMER, CNT_TMR_VECTOR, 0x72 ); /* clear intr vector  */
52
  Z8x36_WRITE( TIMER, MASTER_CFG,     0x20 ); /* clear intr info    */
53
  Z8x36_WRITE( TIMER, MASTER_CFG,     0xe0 ); /* disable interrupts */
54
  Z8x36_WRITE( TIMER, MASTER_CFG,     0x20 ); /* clear intr info    */
55
  Z8x36_WRITE( TIMER, MASTER_CFG,     0xe0 ); /* disable interrupts */
56
  Z8x36_WRITE( TIMER, MASTER_INTR,    0xe2 ); /* disable lower chain,   */
57
                                              /*   no vector, set right */
58
                                              /*   justified addr and   */
59
                                              /*   master int enable    */
60
  Z8x36_WRITE( TIMER, CT1_MODE_SPEC,      0x80 ); /* T1 continuous, and   */
61
                                                  /*   cycle/pulse output */
62
  Z8x36_WRITE( TIMER, CT1_TIME_CONST_MSB, 0x00 );
63
  Z8x36_WRITE( TIMER, CT1_TIME_CONST_LSB, 0x00 );
64
  Z8x36_WRITE( TIMER, CT1_CMD_STATUS,     0xc0 ); /* set INTR enable (IE) */
65
  Z8x36_WRITE( TIMER, MASTER_CFG,         0x40 ); /* enable timer1        */
66
  Z8x36_WRITE( TIMER, CT1_CMD_STATUS,     0x06 ); /* set trigger command  */
67
                                                  /*   (TCB) and gate     */
68
                                                  /* command (GCB) bits   */
69
}
70
 
71
#define AVG_OVERHEAD      11 /* It typically takes 5.5 microseconds */
72
                             /* (11 countdowns) to start/stop the timer. */
73
#define LEAST_VALID       15 /* Don't trust a value lower than this */
74
 
75
int Read_timer()
76
{
77
  rtems_unsigned8  msb, lsb;
78
  rtems_unsigned32 remaining, total;
79
 
80
  Z8x36_WRITE( TIMER, CT1_CMD_STATUS,  0xce );  /* read the counter value */
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
  total = (Ttimer_val * 0x10000) + remaining;
86
 
87
  if ( Timer_driver_Find_average_overhead == 1 )
88
    return total;          /* in one-half microsecond units */
89
  else {
90
    if ( total < LEAST_VALID )
91
      return 0;            /* below timer resolution */
92
    return (total-AVG_OVERHEAD) >> 1;
93
  }
94
}
95
 
96
rtems_status_code Empty_function( void )
97
{
98
  return RTEMS_SUCCESSFUL;
99
}
100
 
101
void Set_find_average_overhead(
102
  rtems_boolean find_flag
103
)
104
{
105
  Timer_driver_Find_average_overhead = find_flag;
106
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.