source: rtems/c/src/lib/libbsp/i960/rxgen960/timer/timer.c @ bc85fd5a

4.104.114.84.95
Last change on this file since bc85fd5a was bc85fd5a, checked in by Joel Sherrill <joel.sherrill@…>, on Jul 11, 2000 at 7:31:04 PM

Reworked score/cpu/i960 so it can be safely compiled multilib. All
routines and structures that require CPU model specific information
are now in libcpu. This required significant rework of the
score/cpu header files and the creation of multiple header files
and subdirectories in libcpu/i960.

  • Property mode set to 100644
File size: 3.4 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-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$
27 */
28
29
30#include <bsp.h>
31#include <stdlib.h>
32#include <rtems/libio.h>
33
34
35#define TIMER_VECTOR 34
36
37int Ttimer_val;
38rtems_boolean Timer_driver_Find_average_overhead = 0;
39
40void flush_reg();
41rtems_isr timerisr();
42
43void Timer_initialize()
44{
45  volatile unsigned int *tmr1 = (unsigned int *) TMR1_ADDR;
46  volatile unsigned int *trr1 = (unsigned int *) TRR1_ADDR;
47  volatile unsigned int *tcr1 = (unsigned int *) TCR1_ADDR;
48  volatile unsigned int *imsk = (unsigned int *) IMSK_ADDR;
49  volatile unsigned int *icon = (unsigned int *) ICON_ADDR;
50  volatile unsigned int *ipnd = (unsigned int *) IPND_ADDR;
51  volatile unsigned int *imap2 = (unsigned int *) IMAP2_ADDR;
52
53    #define BUS_CLOCK_1 0
54    #define TMR_WRITE_CNTL 8
55    #define TMR_AUTO_RELOAD 4
56    #define TMR_ENABLE 2
57    #define TMR_TERM_CNT_STAT 1
58 
59    *tmr1 = BUS_CLOCK_1 | TMR_AUTO_RELOAD; 
60     *icon = 0x6000; 
61
62
63    set_vector( (((unsigned int) timerisr) | 0x2), TIMER_VECTOR, 1 );
64
65    *imap2 = (*imap2 & 0xff0fffff) | (((TIMER_VECTOR >> 4) & 0xf) << 20);
66
67    /* initialize the i960RP timer 1 here */
68   
69    /* set the timer countdown */
70    *trr1 = 33 * BSP_Configuration.microseconds_per_tick;
71    *tcr1 = 33 * BSP_Configuration.microseconds_per_tick;
72 
73    *ipnd &= ~(1<<13);
74    *imsk |= (1 << 13); 
75    Ttimer_val = 0;
76    *tmr1 = BUS_CLOCK_1 | TMR_AUTO_RELOAD | TMR_ENABLE;
77
78}
79
80
81
82rtems_isr timerisr(
83  rtems_vector_number vector
84)
85{
86  /* enable_tracing(); */
87  Ttimer_val++;
88  i960_clear_intr( 13 );
89}
90
91#define AVG_OVERHEAD      4 /* It typically takes 5.5 microseconds */
92                             /* (11 countdowns) to start/stop the timer. */
93#define LEAST_VALID       5 /* Don't trust a value lower than this */
94
95int Read_timer()
96{
97  volatile unsigned int *tcr1 = (unsigned int *) TCR1_ADDR;
98  volatile unsigned int *trr1 = (unsigned int *) TRR1_ADDR;
99  rtems_unsigned32 remaining, total;
100
101  /* this routine is supposed to count in 1/2 uSec units */
102  /* pretty funny when using a 33MHz clock for the counter */
103  remaining =  *tcr1;
104  remaining =  *trr1 - remaining;
105  total = (2 * ((Ttimer_val * *trr1) + remaining)) / 33;
106/*
107  putnum(remaining);
108  console_sps_putc(':');
109  putnum(total);
110*/
111
112  if ( Timer_driver_Find_average_overhead == 1 )
113    return total;          /* in one-half microsecond units */
114  else {
115    if ( total < LEAST_VALID )
116      return 0;            /* below timer resolution */
117    return (total-AVG_OVERHEAD) >> 1;
118  }
119}
120
121rtems_status_code Empty_function( void )
122{
123  return RTEMS_SUCCESSFUL;
124}
125
126void Set_find_average_overhead(
127  rtems_boolean find_flag
128)
129{
130  Timer_driver_Find_average_overhead = find_flag;
131}
Note: See TracBrowser for help on using the repository browser.