source: rtems/c/src/lib/libbsp/no_cpu/no_bsp/clock/ckinit.c @ ac7d5ef0

4.104.114.84.95
Last change on this file since ac7d5ef0 was ac7d5ef0, checked in by Joel Sherrill <joel.sherrill@…>, on 05/11/95 at 17:39:37

Initial revision

  • Property mode set to 100644
File size: 3.2 KB
Line 
1/*  ckinit.c
2 *
3 *  This file provides a template for the clock device driver initialization.
4 *
5 *  COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994.
6 *  On-Line Applications Research Corporation (OAR).
7 *  All rights assigned to U.S. Government, 1994.
8 *
9 *  This material may be reproduced by or for the U.S. Government pursuant
10 *  to the copyright license under the clause at DFARS 252.227-7013.  This
11 *  notice must appear in all copies of this file and its derivatives.
12 *
13 *  $Id$
14 */
15
16#include <stdlib.h>
17
18#include <rtems.h>
19#include <bsp.h>
20#include <clockdrv.h>
21
22/*
23 *  The interrupt vector number associated with the clock tick device
24 *  driver.
25 */
26
27#define CLOCK_VECTOR    4
28
29/*
30 *  Clock_driver_ticks is a monotonically increasing counter of the
31 *  number of clock ticks since the driver was initialized.
32 */
33volatile rtems_unsigned32 Clock_driver_ticks;
34
35/*
36 *  Clock_isrs is the number of clock ISRs until the next invocation of
37 *  the RTEMS clock tick routine.  The clock tick device driver
38 *  gets an interrupt once a millisecond and counts down until the
39 *  length of time between the user configured microseconds per tick
40 *  has passed.
41 */
42
43rtems_unsigned32 Clock_isrs;              /* ISRs until next tick */
44
45/*
46 *  The previous ISR on this clock tick interrupt vector.
47 */
48
49rtems_isr_entry  Old_ticker;
50
51/*
52 *  Clock_initialize
53 *
54 *  Device driver entry point for clock tick driver initialization.
55 */
56
57rtems_device_driver Clock_initialize(
58  rtems_device_major_number major,
59  rtems_device_minor_number minor,
60  void *pargp,
61  rtems_id tid,
62  rtems_unsigned32 *rval
63)
64{
65  Install_clock( Clock_isr );
66}
67
68/*
69 *  Reinstall_clock
70 *
71 *  Install a clock tick handler without reprogramming the chip.  This
72 *  is used by the polling shared memory device driver.
73 */
74
75void ReInstall_clock(
76  rtems_isr_entry clock_isr
77)
78{
79  rtems_unsigned32 isrlevel = 0;
80
81  /*
82   *  Disable interrupts and install the clock ISR vector using the
83   *  BSP dependent set_vector routine.  In the below example, the clock
84   *  ISR is on vector 4 and is an RTEMS interrupt.
85   */
86
87  rtems_interrupt_disable( isrlevel );
88   (void) set_vector( clock_isr, CLOCK_VECTOR, 1 );
89  rtems_interrupt_enable( isrlevel );
90}
91
92/*
93 *  Install_clock
94 *
95 *  Install a clock tick handler and reprograms the chip.  This
96 *  is used to initially establish the clock tick.
97 */
98
99void Install_clock(
100  rtems_isr_entry clock_isr
101)
102{
103  /*
104   *  Initialize the clock tick device driver variables
105   */
106
107  Clock_driver_ticks = 0;
108  Clock_isrs = BSP_Configuration.microseconds_per_tick / 1000;
109
110  /*
111   *  If ticks_per_timeslice is configured as non-zero, then the user
112   *  wants a clock tick.
113   */
114
115  if ( BSP_Configuration.ticks_per_timeslice ) {
116    Old_ticker = ( rtems_isr_entry ) set_vector( clock_isr, CLOCK_VECTOR, 1 );
117    /*
118     *  Hardware specific initialize goes here
119     */
120
121    /* XXX */
122  }
123
124  /*
125   *  Schedule the clock cleanup routine to execute if the application exits.
126   */
127
128  atexit( Clock_exit );
129}
130
131/*
132 *  Clean up before the application exits
133 */
134
135void Clock_exit( void )
136{
137  if ( BSP_Configuration.ticks_per_timeslice ) {
138
139    /* XXX: turn off the timer interrupts */
140
141    /* XXX: If necessary, restore the old vector */
142  }
143}
Note: See TracBrowser for help on using the repository browser.