source: rtems/c/src/lib/libbsp/m68k/mrm332/clock/ckinit.c @ 3660154

4.115
Last change on this file since 3660154 was 3660154, checked in by Joel Sherrill <joel.sherrill@…>, on Jun 1, 2014 at 11:18:28 PM

mrm332: Tests now build and fewer warnings

  • Property mode set to 100644
File size: 2.2 KB
Line 
1/*  Clock_init()
2 *
3 *  This routine initailizes the periodic interrupt timer on
4 *  the Motorola 68332.
5 *
6 *  Input parameters:  NONE
7 *
8 *  Output parameters:  NONE
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.org/license/LICENSE.
16 */
17
18#include <stdlib.h>
19#include <bsp.h>
20#include <mrm332.h>
21
22#define CLOCK_VECTOR   MRM_PIV
23
24uint32_t         Clock_isrs;        /* ISRs until next tick */
25volatile uint32_t         Clock_driver_ticks;
26                                    /* ticks since initialization */
27rtems_isr_entry  Old_ticker;
28
29void Clock_exit( void );
30
31/*
32 * These are set by clock driver during its init
33 */
34
35rtems_device_major_number rtems_clock_major = ~0;
36rtems_device_minor_number rtems_clock_minor;
37
38rtems_isr Clock_isr(rtems_vector_number vector);
39void Install_clock(rtems_isr_entry clock_isr);
40
41rtems_isr Clock_isr(rtems_vector_number vector)
42{
43  Clock_driver_ticks += 1;
44
45  if ( Clock_isrs == 1 ) {
46    rtems_clock_tick();
47    Clock_isrs = rtems_configuration_get_microseconds_per_tick() / 1000;
48  }
49  else
50    Clock_isrs -= 1;
51}
52
53void Install_clock(rtems_isr_entry clock_isr)
54{
55  Clock_driver_ticks = 0;
56  Clock_isrs = rtems_configuration_get_microseconds_per_tick() / 1000;
57
58  Old_ticker = (rtems_isr_entry) set_vector( clock_isr, CLOCK_VECTOR, 1 );
59
60  /* enable 1mS interrupts */
61  *PITR = (unsigned short int)( SAM(0x09,0,PITM) );/* load counter */
62  *PICR = (unsigned short int)                     /* enable interrupt */
63    ( SAM(ISRL_PIT,8,PIRQL) | SAM(CLOCK_VECTOR,0,PIV) );
64
65  atexit( Clock_exit );
66}
67
68void Clock_exit( void )
69{
70  /* shutdown the periodic interrupt */
71  *PICR = (unsigned short int)
72    ( SAM(0,8,PIRQL) | SAM(CLOCK_VECTOR,0,PIV) );
73  /*     ^^ zero disables interrupt */
74
75  /* do not restore old vector */
76}
77
78rtems_device_driver Clock_initialize(
79  rtems_device_major_number major,
80  rtems_device_minor_number minor,
81  void *pargp
82)
83{
84  Install_clock( Clock_isr );
85
86  /*
87   * make major/minor avail to others such as shared memory driver
88   */
89
90  rtems_clock_major = major;
91  rtems_clock_minor = minor;
92
93  return RTEMS_SUCCESSFUL;
94}
Note: See TracBrowser for help on using the repository browser.