1 | /* Clock |
---|
2 | * |
---|
3 | * This routine generates clock ticks using standard POSIX services. |
---|
4 | * The tick frequency is specified by the bsp. |
---|
5 | * |
---|
6 | * COPYRIGHT (c) 1989-1999. |
---|
7 | * On-Line Applications Research Corporation (OAR). |
---|
8 | * |
---|
9 | * The license and distribution terms for this file may be |
---|
10 | * found in the file LICENSE in this distribution or at |
---|
11 | * http://www.rtems.com/license/LICENSE. |
---|
12 | * |
---|
13 | * $Id$ |
---|
14 | */ |
---|
15 | |
---|
16 | #include <bsp.h> |
---|
17 | #include <rtems/libio.h> |
---|
18 | #include <stdlib.h> |
---|
19 | |
---|
20 | void Clock_exit(void); |
---|
21 | |
---|
22 | volatile uint32_t Clock_driver_ticks; |
---|
23 | |
---|
24 | uint32_t Clock_driver_vector; |
---|
25 | |
---|
26 | /* |
---|
27 | * These are set by clock driver during its init |
---|
28 | */ |
---|
29 | |
---|
30 | rtems_device_major_number rtems_clock_major = ~0; |
---|
31 | rtems_device_minor_number rtems_clock_minor; |
---|
32 | |
---|
33 | void Install_clock(rtems_isr_entry clock_isr) |
---|
34 | { |
---|
35 | Clock_driver_ticks = 0; |
---|
36 | |
---|
37 | (void) set_vector( clock_isr, Clock_driver_vector, 1 ); |
---|
38 | |
---|
39 | _CPU_Start_clock( rtems_configuration_get_microseconds_per_tick() ); |
---|
40 | |
---|
41 | atexit(Clock_exit); |
---|
42 | } |
---|
43 | |
---|
44 | void Clock_isr(int vector) |
---|
45 | { |
---|
46 | Clock_driver_ticks++; |
---|
47 | rtems_clock_tick(); |
---|
48 | } |
---|
49 | |
---|
50 | /* |
---|
51 | * Called via atexit() |
---|
52 | * Remove the clock signal |
---|
53 | */ |
---|
54 | |
---|
55 | void Clock_exit(void) |
---|
56 | { |
---|
57 | _CPU_Stop_clock(); |
---|
58 | |
---|
59 | (void) set_vector( 0, Clock_driver_vector, 1 ); |
---|
60 | } |
---|
61 | |
---|
62 | rtems_device_driver Clock_initialize( |
---|
63 | rtems_device_major_number major, |
---|
64 | rtems_device_minor_number minor, |
---|
65 | void *pargp |
---|
66 | ) |
---|
67 | { |
---|
68 | Clock_driver_vector = _CPU_Get_clock_vector(); |
---|
69 | |
---|
70 | Install_clock((rtems_isr_entry) Clock_isr); |
---|
71 | |
---|
72 | /* |
---|
73 | * make major/minor avail to others such as shared memory driver |
---|
74 | */ |
---|
75 | rtems_clock_major = major; |
---|
76 | rtems_clock_minor = minor; |
---|
77 | |
---|
78 | return RTEMS_SUCCESSFUL; |
---|
79 | } |
---|