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

4.104.114.84.95
Last change on this file since 9980062 was 9980062, checked in by Joel Sherrill <joel.sherrill@…>, on Sep 4, 2003 at 6:51:36 PM

2003-09-04 Joel Sherrill <joel@…>

  • clock/ckinit.c, console/console.c, include/bsp.h, include/coverhd.h, spurious/spinit.c, startup/bspclean.c, startup/bspstart.c, startup/linkcmds, startup/vmeintr.c, timer/timer.c, timer/timerisr.S: URL for license changed.
  • 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-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
21#include <rtems.h>
22#include <bsp.h>
23
24int Ttimer_val;
25rtems_boolean Timer_driver_Find_average_overhead;
26
27rtems_isr timerisr();
28
29void 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
66int 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
94rtems_status_code Empty_function( void )
95{
96  return RTEMS_SUCCESSFUL;
97}
98
99void Set_find_average_overhead(
100  rtems_boolean find_flag
101)
102{
103  Timer_driver_Find_average_overhead = find_flag;
104}
Note: See TracBrowser for help on using the repository browser.