diff options
author | Joel Sherrill <joel.sherrill@OARcorp.com> | 1995-05-11 17:39:37 +0000 |
---|---|---|
committer | Joel Sherrill <joel.sherrill@OARcorp.com> | 1995-05-11 17:39:37 +0000 |
commit | ac7d5ef06a6d6e8d84abbd1f0b82162725f98326 (patch) | |
tree | 9304cf759a73f2a1c6fd3191948f00e870af3787 /c/src/lib/libbsp/m68k/idp/timer | |
download | rtems-ac7d5ef06a6d6e8d84abbd1f0b82162725f98326.tar.bz2 |
Initial revision
Diffstat (limited to 'c/src/lib/libbsp/m68k/idp/timer')
-rw-r--r-- | c/src/lib/libbsp/m68k/idp/timer/timer.c | 121 | ||||
-rw-r--r-- | c/src/lib/libbsp/m68k/idp/timer/timerisr.s | 38 |
2 files changed, 159 insertions, 0 deletions
diff --git a/c/src/lib/libbsp/m68k/idp/timer/timer.c b/c/src/lib/libbsp/m68k/idp/timer/timer.c new file mode 100644 index 0000000000..176f393e45 --- /dev/null +++ b/c/src/lib/libbsp/m68k/idp/timer/timer.c @@ -0,0 +1,121 @@ +/* Timer_init() + * + * This routine initializes the MC68230 timer on the Motorola IDP board. + * + * Input parameters: NONE + * + * Output parameters: NONE + * + * NOTE: This routine will not work if the optimizer is enabled + * for some compilers. The multiple writes to the MC68230 + * may be optimized away. + * + * It is important that the timer start/stop overhead be + * determined when porting or modifying this code. + * + * Code Modified for the MC68230 by Doug McBride, Colorado Space Grant College + * + * COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994. + * On-Line Applications Research Corporation (OAR). + * All rights assigned to U.S. Government, 1994. + * + * This material may be reproduced by or for the U.S. Government pursuant + * to the copyright license under the clause at DFARS 252.227-7013. This + * notice must appear in all copies of this file and its derivatives. + * + * $Id$ + */ + + +#include "rtems.h" +#include "cpu.h" +#include "bsp.h" +#include "mc68230.h" + +#define TIMER_VECTOR 0x4D + +int Ttimer_val; +rtems_boolean Timer_driver_Find_average_overhead; + +rtems_isr timerisr(); + +void Timer_initialize() +{ + (void) set_vector( timerisr, TIMER_VECTOR, 0 ); /* install ISR */ + + Ttimer_val = 0; /* clear timer ISR count */ + + /* some PI/T initialization stuff here */ + /* Set up the interrupt vector on the MC68230 chip: + TIVR = TIMER_VECTOR; */ + MC68230_WRITE (TIVR, TIMER_VECTOR); + + /* Set CPRH through CPRL to maximum count to reduce interrupt overhead + CPRH = 0xFF; + CPRM = 0xFF; + CPRL = 0xFF; */ + MC68230_WRITE (CPRH, 0xFF); + MC68230_WRITE (CPRM, 0xFF); + MC68230_WRITE (CPRL, 0xFF); + + /* Enable timer and use it as an external periodic interrupt generator + TCR = 0xA1; */ + MC68230_WRITE (TCR, 0xA1); + +} + +#define AVG_OVERHEAD 9 /* may not be right -- do this later */ +#define LEAST_VALID 10 /* Don't trust a value lower than this */ + +int Read_timer() +{ + rtems_unsigned8 data; + rtems_unsigned8 msb, osb, lsb; + rtems_unsigned32 remaining, total; + + /* Disable timer so that timer can be read + data = TCR; + TCR = (data & 0xFE); */ + MC68230_READ (TCR, data); + MC68230_WRITE (TCR, (data & 0xFE)); + + /* Read the counter value + msb = CNTRH; + osb = CNTRM; + lsb = CNTRL; */ + MC68230_READ (CNTRH, msb); + MC68230_READ (CNTRM, osb); + MC68230_READ (CNTRL, lsb); + + /* Calculate the time so far */ + remaining = 0x1000000 - ((msb << 16) + (osb << 8) + lsb); + total = (Ttimer_val * 0x1000000) + remaining; + + /* Enable timer so that timer can continue + TCR = 0xA1; */ + MC68230_WRITE (TCR, 0xA1); + + /* do not restore old vector */ + if ( Timer_driver_Find_average_overhead == 1 ) + return total; /* in countdown units */ + + if ( total < LEAST_VALID ) + return 0; /* below timer resolution */ + + /* Clocked at 6.5 Mhz */ + /* Avoid floating point problems, be lazy, and return the total minus + the average overhead */ + return (total - AVG_OVERHEAD); +} + +rtems_status_code Empty_function( void ) +{ + return RTEMS_SUCCESSFUL; +} + +void Set_find_average_overhead( + rtems_boolean find_flag +) +{ + Timer_driver_Find_average_overhead = find_flag; +} diff --git a/c/src/lib/libbsp/m68k/idp/timer/timerisr.s b/c/src/lib/libbsp/m68k/idp/timer/timerisr.s new file mode 100644 index 0000000000..cd8173be52 --- /dev/null +++ b/c/src/lib/libbsp/m68k/idp/timer/timerisr.s @@ -0,0 +1,38 @@ +/* timer_isr() + * + * This routine provides the ISR for the MC68230 timer on the Motorola + * IDP board. The timer is set up to generate an interrupt at maximum + * intervals. + * + * Code modified by Doug McBride, Colorado Space Grant College + * countdown should be loaded automatically + * + * Input parameters: NONE + * + * Output parameters: NONE + * + * COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994. + * On-Line Applications Research Corporation (OAR). + * All rights assigned to U.S. Government, 1994. + * + * This material may be reproduced by or for the U.S. Government pursuant + * to the copyright license under the clause at DFARS 252.227-7013. This + * notice must appear in all copies of this file and its derivatives. + * + * $Id$ + */ + +#include "asm.h" + +BEGIN_CODE + +.set TSR, 0x00c0106B | base address of PIT register "TSR" + + PUBLIC (timerisr) +SYM (timerisr): + movb #1,TSR | acknowledge interrupt + addql #1, SYM (Ttimer_val) | increment timer value + rte + +END_CODE +END |