Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:23:48

0001 /*
0002  *  This routine initializes the Tick Timer 2 on the MVME162 board.
0003  *  The tick frequency is 1 millisecond.
0004  */
0005 
0006 /*
0007  *  COPYRIGHT (c) 1989-1999.
0008  *  On-Line Applications Research Corporation (OAR).
0009  *
0010  *  The license and distribution terms for this file may be
0011  *  found in the file LICENSE in this distribution or at
0012  *  http://www.rtems.org/license/LICENSE.
0013  *
0014  *  Modifications of respective RTEMS file: COPYRIGHT (c) 1994.
0015  *  EISCAT Scientific Association. M.Savitski
0016  *
0017  *  This material is a part of the MVME162 Board Support Package
0018  *  for the RTEMS executive. Its licensing policies are those of the
0019  *  RTEMS above.
0020  */
0021 
0022 #include <stdlib.h>
0023 
0024 #include <bsp.h>
0025 #include <rtems/clockdrv.h>
0026 
0027 #define MS_COUNT          1000            /* T2's countdown constant (1 ms) */
0028 #define CLOCK_INT_LEVEL   6               /* T2's interrupt level */
0029 
0030 uint32_t         Clock_isrs;                  /* ISRs until next tick */
0031 volatile uint32_t         Clock_driver_ticks; /* ticks since initialization */
0032 rtems_isr_entry  Old_ticker;
0033 
0034 static void Clock_exit( void );
0035 
0036 #define CLOCK_VECTOR (VBR0 * 0x10 + 0x9)
0037 
0038 /*
0039  *  ISR Handler
0040  */
0041 static rtems_isr Clock_isr(rtems_vector_number vector)
0042 {
0043   Clock_driver_ticks += 1;
0044   lcsr->timer_cnt_2 = 0;            /* clear counter */
0045   lcsr->intr_clear |= 0x02000000;
0046 
0047   if ( Clock_isrs == 1 ) {
0048     rtems_clock_tick();
0049     Clock_isrs = rtems_configuration_get_microseconds_per_tick() / 1000;
0050   }
0051   else
0052     Clock_isrs -= 1;
0053 }
0054 
0055 static void Install_clock(rtems_isr_entry clock_isr )
0056 {
0057 
0058   Clock_driver_ticks = 0;
0059   Clock_isrs = rtems_configuration_get_microseconds_per_tick() / 1000;
0060 
0061   Old_ticker = (rtems_isr_entry) set_vector( clock_isr, CLOCK_VECTOR, 1 );
0062   lcsr->vector_base |= MASK_INT;   /* unmask VMEchip2 interrupts */
0063   lcsr->to_ctl = 0xE7;             /* prescaler to 1 MHz (see Appendix A1) */
0064   lcsr->timer_cmp_2 = MS_COUNT;
0065   lcsr->timer_cnt_2 = 0;           /* clear counter */
0066   lcsr->board_ctl |= 0x700;        /* increment, reset-on-compare, and */
0067                                    /*   clear-overflow-cnt */
0068 
0069   lcsr->intr_level[0] |= CLOCK_INT_LEVEL * 0x10;      /* set int level */
0070   lcsr->intr_ena |= 0x02000000;       /* enable tick timer 2 interrupt */
0071 
0072   atexit( Clock_exit );
0073 }
0074 
0075 void Clock_exit( void )
0076 {
0077 /* Dummy for now. See other m68k BSP's for code examples */
0078 }
0079 
0080 void _Clock_Initialize( void )
0081 {
0082   Install_clock( Clock_isr );
0083 }