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

Subversion Repositories openrisc

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

Go to most recent revision | 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-1997.
19
 *  On-Line Applications Research Corporation (OAR).
20
 *  Copyright assigned to U.S. Government, 1994.
21
 *
22
 *  The license and distribution terms for this file may in
23
 *  the file LICENSE in this distribution or at
24
 *  http://www.OARcorp.com/rtems/license.html.
25
 *
26
 *  $Id: timer.c,v 1.2 2001-09-27 12:00:00 chris Exp $
27
 */
28
 
29
 
30
#include <rtems.h>
31
#include <bsp.h>
32
#include <stdlib.h>
33
#include <i960RP.h>
34
#include <rtems/libio.h>
35
 
36
 
37
#define TIMER_VECTOR 34
38
 
39
int Ttimer_val;
40
rtems_boolean Timer_driver_Find_average_overhead = 0;
41
 
42
void flush_reg();
43
rtems_isr timerisr();
44
 
45
void Timer_initialize()
46
{
47
  volatile unsigned int *tmr1 = (unsigned int *) TMR1_ADDR;
48
  volatile unsigned int *trr1 = (unsigned int *) TRR1_ADDR;
49
  volatile unsigned int *tcr1 = (unsigned int *) TCR1_ADDR;
50
  volatile unsigned int *imsk = (unsigned int *) IMSK_ADDR;
51
  volatile unsigned int *icon = (unsigned int *) ICON_ADDR;
52
  volatile unsigned int *ipnd = (unsigned int *) IPND_ADDR;
53
  volatile unsigned int *imap2 = (unsigned int *) IMAP2_ADDR;
54
 
55
    #define BUS_CLOCK_1 0
56
    #define TMR_WRITE_CNTL 8
57
    #define TMR_AUTO_RELOAD 4
58
    #define TMR_ENABLE 2
59
    #define TMR_TERM_CNT_STAT 1
60
 
61
    *tmr1 = BUS_CLOCK_1 | TMR_AUTO_RELOAD;
62
     *icon = 0x6000;
63
 
64
 
65
    set_vector( (((unsigned int) timerisr) | 0x2), TIMER_VECTOR, 1 );
66
 
67
    *imap2 = (*imap2 & 0xff0fffff) | (((TIMER_VECTOR >> 4) & 0xf) << 20);
68
 
69
    /* initialize the i960RP timer 1 here */
70
 
71
    /* set the timer countdown */
72
    *trr1 = 33 * BSP_Configuration.microseconds_per_tick;
73
    *tcr1 = 33 * BSP_Configuration.microseconds_per_tick;
74
 
75
    *ipnd &= ~(1<<13);
76
    *imsk |= (1 << 13);
77
    Ttimer_val = 0;
78
    *tmr1 = BUS_CLOCK_1 | TMR_AUTO_RELOAD | TMR_ENABLE;
79
 
80
}
81
 
82
 
83
 
84
rtems_isr timerisr(
85
  rtems_vector_number vector
86
)
87
{
88
  /* enable_tracing(); */
89
  Ttimer_val++;
90
  i960_clear_intr( 13 );
91
}
92
 
93
#define AVG_OVERHEAD      4 /* It typically takes 5.5 microseconds */
94
                             /* (11 countdowns) to start/stop the timer. */
95
#define LEAST_VALID       5 /* Don't trust a value lower than this */
96
 
97
int Read_timer()
98
{
99
  volatile unsigned int *tcr1 = (unsigned int *) TCR1_ADDR;
100
  volatile unsigned int *trr1 = (unsigned int *) TRR1_ADDR;
101
  rtems_unsigned32 remaining, total;
102
 
103
  /* this routine is supposed to count in 1/2 uSec units */
104
  /* pretty funny when using a 33MHz clock for the counter */
105
  remaining =  *tcr1;
106
  remaining =  *trr1 - remaining;
107
  total = (2 * ((Ttimer_val * *trr1) + remaining)) / 33;
108
/*
109
  putnum(remaining);
110
  console_sps_putc(':');
111
  putnum(total);
112
*/
113
 
114
  if ( Timer_driver_Find_average_overhead == 1 )
115
    return total;          /* in one-half microsecond units */
116
  else {
117
    if ( total < LEAST_VALID )
118
      return 0;            /* below timer resolution */
119
    return (total-AVG_OVERHEAD) >> 1;
120
  }
121
}
122
 
123
rtems_status_code Empty_function( void )
124
{
125
  return RTEMS_SUCCESSFUL;
126
}
127
 
128
void Set_find_average_overhead(
129
  rtems_boolean find_flag
130
)
131
{
132
  Timer_driver_Find_average_overhead = find_flag;
133
}

powered by: WebSVN 2.1.0

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