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

Subversion Repositories openrisc

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 30 unneback
/*  timer.c
2
 *
3
 *  NOTE: These routines will not work if the optimizer is enabled
4
 *        for some compilers.  The multiple writes to the Z8036
5
 *        may be optimized away.
6
 *
7
 *        It is important that the timer start/stop overhead be
8
 *        determined when porting or modifying this code.
9
 *
10
 *  COPYRIGHT (c) 1989-1999.
11
 *  On-Line Applications Research Corporation (OAR).
12
 *
13
 *  The license and distribution terms for this file may be
14
 *  found in the file LICENSE in this distribution or at
15
 *  http://www.OARcorp.com/rtems/license.html.
16
 *
17
 *  $Id: timer.c,v 1.2 2001-09-27 12:00:01 chris Exp $
18
 */
19
 
20
 
21
#include <rtems.h>
22
#include <bsp.h>
23
 
24
int Ttimer_val;
25
rtems_boolean Timer_driver_Find_average_overhead;
26
 
27
rtems_isr timerisr();
28
 
29
void Timer_initialize()
30
{
31
  rtems_unsigned8 data;
32
 
33
  (void) set_vector( timerisr, TIMER_VECTOR, 0 );  /* install ISR */
34
 
35
  Ttimer_val = 0;                          /* clear timer ISR count */
36
  Z8x36_READ ( TIMER, MASTER_INTR, data );
37
  Z8x36_WRITE( TIMER, MASTER_INTR, (data & 0x01) );
38
 
39
  Z8x36_WRITE( TIMER, MASTER_CFG, 0xd4 );
40
  Z8x36_READ ( TIMER, MASTER_INTR, data );
41
  Z8x36_WRITE( TIMER, MASTER_INTR, (data & 0x7E) );
42
  Z8x36_WRITE( TIMER, CT1_TIME_CONST_MSB, 0x00 );
43
  Z8x36_WRITE( TIMER, CT1_TIME_CONST_LSB, 0x00 );
44
  Z8x36_WRITE( TIMER, CT1_MODE_SPEC, 0x87 );
45
  Z8x36_WRITE( TIMER, CNT_TMR_VECTOR, TIMER_VECTOR );
46
  Z8x36_WRITE( TIMER, CT1_CMD_STATUS, 0x20 );
47
  Z8x36_WRITE( TIMER, CT1_CMD_STATUS, 0x26 );
48
  Z8x36_READ ( TIMER, MASTER_INTR, data );
49
  Z8x36_WRITE( TIMER, MASTER_INTR, (data & 0xDA) | 0x80 );
50
 
51
  Z8x36_WRITE( TIMER, CT1_CMD_STATUS, 0xC6 );
52
 
53
  /*
54
   * ACC_IC54 - interrupt 5 will be vectored and mapped to level 6
55
   */
56
 
57
  data = (*(rtems_unsigned8 *)0x0D00000B);
58
  (*(rtems_unsigned8 *)0x0D00000B) = (data & 0x0F) | 0x60;
59
 
60
}
61
 
62
#define AVG_OVERHEAD      9  /* It typically takes 3.65 microseconds */
63
                             /* (9 countdowns) to start/stop the timer. */
64
#define LEAST_VALID       10 /* Don't trust a value lower than this */
65
 
66
int Read_timer()
67
{
68
  rtems_unsigned8 data;
69
  rtems_unsigned8  msb, lsb;
70
  rtems_unsigned32 remaining, total;
71
 
72
  Z8x36_WRITE( TIMER, CT1_CMD_STATUS,  0xce ); /* read the counter value */
73
  Z8x36_READ(  TIMER, CT1_CUR_CNT_MSB, msb );
74
  Z8x36_READ(  TIMER, CT1_CUR_CNT_LSB, lsb );
75
 
76
  remaining = 0x10000 - ((msb << 8) + lsb);
77
  total = (Ttimer_val * 0x10000) + remaining;
78
 
79
  Z8x36_READ ( TIMER, MASTER_INTR, data );
80
  Z8x36_WRITE( TIMER, MASTER_INTR, (data & 0x01) );
81
 
82
  /* do not restore old vector */
83
  if ( Timer_driver_Find_average_overhead == 1 )
84
    return total;          /* in countdown units */
85
 
86
  if ( total < LEAST_VALID )
87
    return 0;            /* below timer resolution */
88
 
89
  /* Clocked at 2.4615 Mhz */
90
 
91
  return (int)(((float)(total-AVG_OVERHEAD)) / 2.4615 * 2.0);
92
}
93
 
94
rtems_status_code Empty_function( void )
95
{
96
  return RTEMS_SUCCESSFUL;
97
}
98
 
99
void Set_find_average_overhead(
100
  rtems_boolean find_flag
101
)
102
{
103
  Timer_driver_Find_average_overhead = find_flag;
104
}

powered by: WebSVN 2.1.0

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