source: rtems/c/src/lib/libbsp/m68k/dmv152/timer/timer.c @ 60b791ad

4.104.114.84.95
Last change on this file since 60b791ad was 60b791ad, checked in by Joel Sherrill <joel.sherrill@…>, on 02/17/98 at 23:46:28

updated copyright to 1998

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