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

4.104.114.84.95
Last change on this file since 5f57730 was 08311cc3, checked in by Joel Sherrill <joel.sherrill@…>, on 11/17/99 at 17:51:34

Updated copyright notice.

  • Property mode set to 100644
File size: 2.3 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-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.OARcorp.com/rtems/license.html.
12 *
13 *  $Id$
14 */
15
16#include <bsp.h>
17#include <rtems/libio.h>
18#include <stdlib.h>
19
20void Clock_exit(void);
21
22volatile rtems_unsigned32 Clock_driver_ticks;
23
24rtems_unsigned32 Clock_driver_vector;
25
26/*
27 * These are set by clock driver during its init
28 */
29
30rtems_device_major_number rtems_clock_major = ~0;
31rtems_device_minor_number rtems_clock_minor;
32
33void 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( BSP_Configuration.microseconds_per_tick );
40
41    atexit(Clock_exit);
42}
43
44void 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
55void Clock_exit(void)
56{
57  _CPU_Stop_clock();
58
59  (void) set_vector( 0, Clock_driver_vector, 1 );
60}
61
62rtems_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}
80
81rtems_device_driver Clock_control(
82  rtems_device_major_number major,
83  rtems_device_minor_number minor,
84  void *pargp
85)
86{
87    rtems_unsigned32 isrlevel;
88    rtems_libio_ioctl_args_t *args = pargp;
89
90    if (args == 0)
91        goto done;
92
93    /*
94     * This is hokey, but until we get a defined interface
95     * to do this, it will just be this simple...
96     */
97
98    if (args->command == rtems_build_name('I', 'S', 'R', ' '))
99    {
100        Clock_isr(Clock_driver_vector);
101    }
102    else if (args->command == rtems_build_name('N', 'E', 'W', ' '))
103    {
104      rtems_interrupt_disable( isrlevel );
105       (void) set_vector( args->buffer, Clock_driver_vector, 1 );
106      rtems_interrupt_enable( isrlevel );
107    }
108   
109done:
110    return RTEMS_SUCCESSFUL;
111}
Note: See TracBrowser for help on using the repository browser.