source: rtems/c/src/lib/libbsp/sparc/shared/timer/tlib.c @ 4a7d1026

4.11
Last change on this file since 4a7d1026 was 4a7d1026, checked in by Daniel Hellstrom <daniel@…>, on Apr 13, 2015 at 8:25:52 AM

sparc bsps: updated license to rtems.org

  • Property mode set to 100644
File size: 1.4 KB
Line 
1/*
2 *  Timer Library (TLIB)
3 *
4 *  COPYRIGHT (c) 2011.
5 *  Cobham Gaisler AB.
6 *
7 *  The license and distribution terms for this file may be
8 *  found in the file LICENSE in this distribution or at
9 *  http://www.rtems.org/license/LICENSE.
10 */
11
12#include <rtems.h>
13#include <bsp/tlib.h>
14
15struct tlib_dev *tlib_dev_head = NULL;
16struct tlib_dev *tlib_dev_tail = NULL;
17static int tlib_dev_cnt = 0;
18
19/* Register Timer device to Timer Library */
20int tlib_dev_reg(struct tlib_dev *newdev)
21{
22        /* Reset device */
23        newdev->status = 0;
24        newdev->isr_func = NULL;
25        newdev->index = tlib_dev_cnt;
26
27        /* Insert last in queue */
28        newdev->next = NULL;
29        if ( tlib_dev_tail == NULL ) {
30                tlib_dev_head = newdev;
31        } else {
32                tlib_dev_tail->next = newdev;
33        }
34        tlib_dev_tail = newdev;
35
36        /* Return Index of Registered Timer */
37        return tlib_dev_cnt++;
38}
39
40void *tlib_open(int timer_no)
41{
42        struct tlib_dev *dev;
43
44        if ( timer_no < 0 )
45                return NULL;
46
47        dev = tlib_dev_head;
48        while ( (timer_no > 0) && dev ) {
49                timer_no--;
50                dev = dev->next;
51        }
52        if ( dev ) {
53                if ( dev->status )
54                        return NULL;
55                dev->status = 1;
56                /* Reset Timer to initial state */
57                tlib_reset(dev);
58        }
59        return dev;
60}
61
62void tlib_close(void *hand)
63{
64        struct tlib_dev *dev = hand;
65
66        /* Stop any ongoing timer operation and unregister IRQ if registered */
67        tlib_stop(dev);
68        tlib_irq_unregister(dev);
69
70        /* Mark not open */
71        dev->status = 0;
72}
73
74int tlib_ntimer(void)
75{
76        return tlib_dev_cnt;
77}
Note: See TracBrowser for help on using the repository browser.