[ac7d5ef0] | 1 | /* ckinit.c |
---|
| 2 | * |
---|
| 3 | * This file provides a template for the clock device driver initialization. |
---|
| 4 | * |
---|
[08311cc3] | 5 | * COPYRIGHT (c) 1989-1999. |
---|
[ac7d5ef0] | 6 | * On-Line Applications Research Corporation (OAR). |
---|
| 7 | * |
---|
[98e4ebf5] | 8 | * The license and distribution terms for this file may be |
---|
| 9 | * found in the file LICENSE in this distribution or at |
---|
[03f2154e] | 10 | * http://www.OARcorp.com/rtems/license.html. |
---|
[ac7d5ef0] | 11 | * |
---|
| 12 | * $Id$ |
---|
| 13 | */ |
---|
| 14 | |
---|
| 15 | #include <stdlib.h> |
---|
| 16 | |
---|
| 17 | #include <rtems.h> |
---|
[7f6a24ab] | 18 | #include <rtems/libio.h> |
---|
[ac7d5ef0] | 19 | #include <bsp.h> |
---|
[7f6a24ab] | 20 | |
---|
| 21 | void Clock_exit( void ); |
---|
| 22 | rtems_isr Clock_isr( rtems_vector_number vector ); |
---|
| 23 | |
---|
[ac7d5ef0] | 24 | |
---|
| 25 | /* |
---|
| 26 | * The interrupt vector number associated with the clock tick device |
---|
| 27 | * driver. |
---|
| 28 | */ |
---|
| 29 | |
---|
| 30 | #define CLOCK_VECTOR 4 |
---|
| 31 | |
---|
| 32 | /* |
---|
| 33 | * Clock_driver_ticks is a monotonically increasing counter of the |
---|
| 34 | * number of clock ticks since the driver was initialized. |
---|
| 35 | */ |
---|
[7f6a24ab] | 36 | |
---|
[ac7d5ef0] | 37 | volatile rtems_unsigned32 Clock_driver_ticks; |
---|
| 38 | |
---|
| 39 | /* |
---|
| 40 | * Clock_isrs is the number of clock ISRs until the next invocation of |
---|
| 41 | * the RTEMS clock tick routine. The clock tick device driver |
---|
| 42 | * gets an interrupt once a millisecond and counts down until the |
---|
| 43 | * length of time between the user configured microseconds per tick |
---|
| 44 | * has passed. |
---|
| 45 | */ |
---|
| 46 | |
---|
| 47 | rtems_unsigned32 Clock_isrs; /* ISRs until next tick */ |
---|
| 48 | |
---|
| 49 | /* |
---|
[7f6a24ab] | 50 | * These are set by clock driver during its init |
---|
[ac7d5ef0] | 51 | */ |
---|
[7f6a24ab] | 52 | |
---|
| 53 | rtems_device_major_number rtems_clock_major = ~0; |
---|
| 54 | rtems_device_minor_number rtems_clock_minor; |
---|
[ac7d5ef0] | 55 | |
---|
| 56 | /* |
---|
[7f6a24ab] | 57 | * The previous ISR on this clock tick interrupt vector. |
---|
[ac7d5ef0] | 58 | */ |
---|
| 59 | |
---|
[7f6a24ab] | 60 | rtems_isr_entry Old_ticker; |
---|
[ac7d5ef0] | 61 | |
---|
[3a4ae6c] | 62 | void Clock_exit( void ); |
---|
| 63 | |
---|
| 64 | |
---|
[ac7d5ef0] | 65 | /* |
---|
[3a4ae6c] | 66 | * Isr Handler |
---|
[ac7d5ef0] | 67 | */ |
---|
| 68 | |
---|
[3a4ae6c] | 69 | rtems_isr Clock_isr( |
---|
| 70 | rtems_vector_number vector |
---|
[ac7d5ef0] | 71 | ) |
---|
| 72 | { |
---|
[3a4ae6c] | 73 | /* |
---|
| 74 | * bump the number of clock driver ticks since initialization |
---|
| 75 | * |
---|
| 76 | * determine if it is time to announce the passing of tick as configured |
---|
| 77 | * to RTEMS through the rtems_clock_tick directive |
---|
| 78 | * |
---|
| 79 | * perform any timer dependent tasks |
---|
| 80 | */ |
---|
[ac7d5ef0] | 81 | } |
---|
| 82 | |
---|
| 83 | /* |
---|
| 84 | * Install_clock |
---|
| 85 | * |
---|
| 86 | * Install a clock tick handler and reprograms the chip. This |
---|
| 87 | * is used to initially establish the clock tick. |
---|
| 88 | */ |
---|
| 89 | |
---|
| 90 | void Install_clock( |
---|
| 91 | rtems_isr_entry clock_isr |
---|
| 92 | ) |
---|
| 93 | { |
---|
| 94 | /* |
---|
| 95 | * Initialize the clock tick device driver variables |
---|
| 96 | */ |
---|
| 97 | |
---|
| 98 | Clock_driver_ticks = 0; |
---|
| 99 | Clock_isrs = BSP_Configuration.microseconds_per_tick / 1000; |
---|
| 100 | |
---|
[0dd1d44] | 101 | Old_ticker = (rtems_isr_entry) set_vector( clock_isr, CLOCK_VECTOR, 1 ); |
---|
[ac7d5ef0] | 102 | /* |
---|
[0dd1d44] | 103 | * Hardware specific initialize goes here |
---|
[ac7d5ef0] | 104 | */ |
---|
| 105 | |
---|
[0dd1d44] | 106 | /* XXX */ |
---|
[ac7d5ef0] | 107 | |
---|
| 108 | /* |
---|
| 109 | * Schedule the clock cleanup routine to execute if the application exits. |
---|
| 110 | */ |
---|
| 111 | |
---|
| 112 | atexit( Clock_exit ); |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | /* |
---|
| 116 | * Clean up before the application exits |
---|
| 117 | */ |
---|
| 118 | |
---|
| 119 | void Clock_exit( void ) |
---|
| 120 | { |
---|
[0dd1d44] | 121 | /* XXX: turn off the timer interrupts */ |
---|
[ac7d5ef0] | 122 | |
---|
[0dd1d44] | 123 | /* XXX: If necessary, restore the old vector */ |
---|
[ac7d5ef0] | 124 | } |
---|
[7f6a24ab] | 125 | |
---|
| 126 | /* |
---|
| 127 | * Clock_initialize |
---|
| 128 | * |
---|
| 129 | * Device driver entry point for clock tick driver initialization. |
---|
| 130 | */ |
---|
| 131 | |
---|
| 132 | rtems_device_driver Clock_initialize( |
---|
| 133 | rtems_device_major_number major, |
---|
| 134 | rtems_device_minor_number minor, |
---|
| 135 | void *pargp |
---|
| 136 | ) |
---|
| 137 | { |
---|
[3a4ae6c] | 138 | Install_clock( Clock_isr ); |
---|
| 139 | |
---|
[7f6a24ab] | 140 | /* |
---|
| 141 | * make major/minor avail to others such as shared memory driver |
---|
| 142 | */ |
---|
[3a4ae6c] | 143 | |
---|
[7f6a24ab] | 144 | rtems_clock_major = major; |
---|
[3a4ae6c] | 145 | rtems_clock_minor = minor; |
---|
| 146 | |
---|
[7f6a24ab] | 147 | return RTEMS_SUCCESSFUL; |
---|
| 148 | } |
---|
| 149 | |
---|
| 150 | rtems_device_driver Clock_control( |
---|
| 151 | rtems_device_major_number major, |
---|
| 152 | rtems_device_minor_number minor, |
---|
| 153 | void *pargp |
---|
| 154 | ) |
---|
| 155 | { |
---|
[9700578] | 156 | rtems_unsigned32 isrlevel; |
---|
[7f6a24ab] | 157 | rtems_libio_ioctl_args_t *args = pargp; |
---|
| 158 | |
---|
| 159 | if (args == 0) |
---|
| 160 | goto done; |
---|
| 161 | |
---|
| 162 | /* |
---|
| 163 | * This is hokey, but until we get a defined interface |
---|
| 164 | * to do this, it will just be this simple... |
---|
| 165 | */ |
---|
| 166 | |
---|
| 167 | if (args->command == rtems_build_name('I', 'S', 'R', ' ')) |
---|
| 168 | { |
---|
| 169 | Clock_isr(CLOCK_VECTOR); |
---|
| 170 | } |
---|
| 171 | else if (args->command == rtems_build_name('N', 'E', 'W', ' ')) |
---|
| 172 | { |
---|
[9700578] | 173 | rtems_interrupt_disable( isrlevel ); |
---|
| 174 | (void) set_vector( args->buffer, CLOCK_VECTOR, 1 ); |
---|
| 175 | rtems_interrupt_enable( isrlevel ); |
---|
[7f6a24ab] | 176 | } |
---|
| 177 | |
---|
| 178 | done: |
---|
| 179 | return RTEMS_SUCCESSFUL; |
---|
| 180 | } |
---|