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

4.104.114.95
Last change on this file since 1e6aed25 was 12bd47e, checked in by Joel Sherrill <joel.sherrill@…>, on 12/11/07 at 15:49:53

2007-12-11 Joel Sherrill <joel.sherrill@…>

  • clock/ckinit.c, include/bsp.h, startup/bspstart.c: Eliminate copies of the Configuration Table. Use the RTEMS provided accessor macros to obtain configuration fields.
  • Property mode set to 100644
File size: 2.9 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.com/license/LICENSE.
16 *
17 *  $Id$
18 */
19
20#include <stdlib.h>
21#include <bsp.h>
22#include <rtems/libio.h>
23#include <mrm332.h>
24
25#define CLOCK_VECTOR   MRM_PIV
26
27uint32_t         Clock_isrs;        /* ISRs until next tick */
28volatile uint32_t         Clock_driver_ticks;
29                                    /* ticks since initialization */
30rtems_isr_entry  Old_ticker;
31
32void Clock_exit( void );
33
34/*
35 * These are set by clock driver during its init
36 */
37
38rtems_device_major_number rtems_clock_major = ~0;
39rtems_device_minor_number rtems_clock_minor;
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(
54  rtems_isr_entry clock_isr
55)
56{
57  Clock_driver_ticks = 0;
58  Clock_isrs = rtems_configuration_get_microseconds_per_tick() / 1000;
59
60  Old_ticker = (rtems_isr_entry) set_vector( clock_isr, CLOCK_VECTOR, 1 );
61
62  /* enable 1mS interrupts */
63  *PITR = (unsigned short int)( SAM(0x09,0,PITM) );/* load counter */
64  *PICR = (unsigned short int)                     /* enable interrupt */
65    ( SAM(ISRL_PIT,8,PIRQL) | SAM(CLOCK_VECTOR,0,PIV) );
66
67  atexit( Clock_exit );
68}
69
70void Clock_exit( void )
71{
72  /* shutdown the periodic interrupt */
73  *PICR = (unsigned short int)
74    ( SAM(0,8,PIRQL) | SAM(CLOCK_VECTOR,0,PIV) );
75  /*     ^^ zero disables interrupt */
76
77  /* do not restore old vector */
78}
79
80rtems_device_driver Clock_initialize(
81  rtems_device_major_number major,
82  rtems_device_minor_number minor,
83  void *pargp
84)
85{
86  Install_clock( Clock_isr );
87
88  /*
89   * make major/minor avail to others such as shared memory driver
90   */
91
92  rtems_clock_major = major;
93  rtems_clock_minor = minor;
94
95  return RTEMS_SUCCESSFUL;
96}
97
98rtems_device_driver Clock_control(
99  rtems_device_major_number major,
100  rtems_device_minor_number minor,
101  void *pargp
102)
103{
104    uint32_t         isrlevel;
105    rtems_libio_ioctl_args_t *args = pargp;
106
107    if (args == 0)
108        goto done;
109
110    /*
111     * This is hokey, but until we get a defined interface
112     * to do this, it will just be this simple...
113     */
114
115    if (args->command == rtems_build_name('I', 'S', 'R', ' '))
116    {
117        Clock_isr(CLOCK_VECTOR);
118    }
119    else if (args->command == rtems_build_name('N', 'E', 'W', ' '))
120    {
121      rtems_interrupt_disable( isrlevel );
122       (void) set_vector( args->buffer, CLOCK_VECTOR, 1 );
123      rtems_interrupt_enable( isrlevel );
124    }
125
126done:
127    return RTEMS_SUCCESSFUL;
128}
Note: See TracBrowser for help on using the repository browser.