source: rtems/c/src/lib/libbsp/m68k/dmv152/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: 2.8 KB
Line 
1/*  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.rtems.com/license/LICENSE.
16 *
17 *  $Id$
18 */
19
20#include <rtems.h>
21#include <bsp.h>
22
23int Ttimer_val;
24rtems_boolean Timer_driver_Find_average_overhead;
25
26rtems_isr timerisr();
27
28void Timer_initialize()
29{
30  uint8_t         data;
31
32  (void) set_vector( timerisr, TIMER_VECTOR, 0 );  /* install ISR */
33
34  Ttimer_val = 0;                          /* clear timer ISR count */
35  Z8x36_READ ( TIMER, MASTER_INTR, data );
36  Z8x36_WRITE( TIMER, MASTER_INTR, (data & 0x01) );
37
38  Z8x36_WRITE( TIMER, MASTER_CFG, 0xd4 );
39  Z8x36_READ ( TIMER, MASTER_INTR, data );
40  Z8x36_WRITE( TIMER, MASTER_INTR, (data & 0x7E) );
41  Z8x36_WRITE( TIMER, CT1_TIME_CONST_MSB, 0x00 );
42  Z8x36_WRITE( TIMER, CT1_TIME_CONST_LSB, 0x00 );
43  Z8x36_WRITE( TIMER, CT1_MODE_SPEC, 0x87 );
44  Z8x36_WRITE( TIMER, CNT_TMR_VECTOR, TIMER_VECTOR );
45  Z8x36_WRITE( TIMER, CT1_CMD_STATUS, 0x20 );
46  Z8x36_WRITE( TIMER, CT1_CMD_STATUS, 0x26 );
47  Z8x36_READ ( TIMER, MASTER_INTR, data );
48  Z8x36_WRITE( TIMER, MASTER_INTR, (data & 0xDA) | 0x80 );
49
50  Z8x36_WRITE( TIMER, CT1_CMD_STATUS, 0xC6 );
51
52  /*
53   * ACC_IC54 - interrupt 5 will be vectored and mapped to level 6
54   */
55
56  data = (*(uint8_t*)0x0D00000B);
57  (*(uint8_t*)0x0D00000B) = (data & 0x0F) | 0x60;
58
59}
60
61#define AVG_OVERHEAD      9  /* It typically takes 3.65 microseconds */
62                             /* (9 countdowns) to start/stop the timer. */
63#define LEAST_VALID       10 /* Don't trust a value lower than this */
64
65int Read_timer()
66{
67  uint8_t         data;
68  uint8_t          msb, lsb;
69  uint32_t         remaining, total;
70
71  Z8x36_WRITE( TIMER, CT1_CMD_STATUS,  0xce ); /* read the counter value */
72  Z8x36_READ(  TIMER, CT1_CUR_CNT_MSB, msb );
73  Z8x36_READ(  TIMER, CT1_CUR_CNT_LSB, lsb );
74
75  remaining = 0x10000 - ((msb << 8) + lsb);
76  total = (Ttimer_val * 0x10000) + remaining;
77
78  Z8x36_READ ( TIMER, MASTER_INTR, data );
79  Z8x36_WRITE( TIMER, MASTER_INTR, (data & 0x01) );
80
81  /* do not restore old vector */
82  if ( Timer_driver_Find_average_overhead == 1 )
83    return total;          /* in countdown units */
84
85  if ( total < LEAST_VALID )
86    return 0;            /* below timer resolution */
87
88  /* Clocked at 2.4615 Mhz */
89
90  return (int)(((float)(total-AVG_OVERHEAD)) / 2.4615 * 2.0);
91}
92
93rtems_status_code Empty_function( void )
94{
95  return RTEMS_SUCCESSFUL;
96}
97
98void Set_find_average_overhead(
99  rtems_boolean find_flag
100)
101{
102  Timer_driver_Find_average_overhead = find_flag;
103}
Note: See TracBrowser for help on using the repository browser.