source: rtems/c/src/lib/libbsp/unix/posix/clock/clock.c @ 9700578

4.104.114.84.95
Last change on this file since 9700578 was 9700578, checked in by Joel Sherrill <joel.sherrill@…>, on 10/30/95 at 21:54:45

SPARC port passes all tests

  • Property mode set to 100644
File size: 2.4 KB
Line 
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, 1990, 1991, 1992, 1993, 1994.
7 *  On-Line Applications Research Corporation (OAR).
8 *  All rights assigned to U.S. Government, 1994.
9 *
10 *  This material may be reproduced by or for the U.S. Government pursuant
11 *  to the copyright license under the clause at DFARS 252.227-7013.  This
12 *  notice must appear in all copies of this file and its derivatives.
13 *
14 *  $Id$
15 */
16
17#include <bsp.h>
18#include <rtems/libio.h>
19#include <stdlib.h>
20
21void Clock_exit(void);
22
23volatile rtems_unsigned32 Clock_driver_ticks;
24
25rtems_unsigned32 Clock_driver_vector;
26
27/*
28 * These are set by clock driver during its init
29 */
30
31rtems_device_major_number rtems_clock_major = ~0;
32rtems_device_minor_number rtems_clock_minor;
33
34void Install_clock(rtems_isr_entry clock_isr)
35{
36    Clock_driver_ticks = 0;
37
38    (void) set_vector( clock_isr, Clock_driver_vector, 1 );
39
40    _CPU_Start_clock( BSP_Configuration.microseconds_per_tick );
41
42    atexit(Clock_exit);
43}
44
45void Clock_isr(int vector)
46{
47    Clock_driver_ticks++;
48    rtems_clock_tick();
49}
50
51/*
52 * Called via atexit()
53 * Remove the clock signal
54 */
55
56void Clock_exit(void)
57{
58  _CPU_Stop_clock();
59
60  (void) set_vector( 0, Clock_driver_vector, 1 );
61}
62
63rtems_device_driver Clock_initialize(
64  rtems_device_major_number major,
65  rtems_device_minor_number minor,
66  void *pargp
67)
68{
69    Clock_driver_vector = _CPU_Get_clock_vector();
70
71    Install_clock((rtems_isr_entry) Clock_isr);
72
73    /*
74     * make major/minor avail to others such as shared memory driver
75     */
76    rtems_clock_major = major;
77    rtems_clock_minor = minor;
78
79    return RTEMS_SUCCESSFUL;
80}
81
82rtems_device_driver Clock_control(
83  rtems_device_major_number major,
84  rtems_device_minor_number minor,
85  void *pargp
86)
87{
88    rtems_unsigned32 isrlevel;
89    rtems_libio_ioctl_args_t *args = pargp;
90
91    if (args == 0)
92        goto done;
93
94    /*
95     * This is hokey, but until we get a defined interface
96     * to do this, it will just be this simple...
97     */
98
99    if (args->command == rtems_build_name('I', 'S', 'R', ' '))
100    {
101        Clock_isr(Clock_driver_vector);
102    }
103    else if (args->command == rtems_build_name('N', 'E', 'W', ' '))
104    {
105      rtems_interrupt_disable( isrlevel );
106       (void) set_vector( args->buffer, Clock_driver_vector, 1 );
107      rtems_interrupt_enable( isrlevel );
108    }
109   
110done:
111    return RTEMS_SUCCESSFUL;
112}
Note: See TracBrowser for help on using the repository browser.