source: rtems/c/src/lib/libbsp/sparc/shared/timer/tlib.c @ 445e253

4.115
Last change on this file since 445e253 was cd64fbf, checked in by Daniel Hellstrom <daniel@…>, on 12/16/11 at 09:37:49

LEON: GPTIMER driver, Timer Library and System Clock for LEON3

With this patch the LEON family can access the GRLIB GPTIMER using
the Timer library (TLIB).

A System Clock driver instead of BSP/clock/ck_init.c is provided
using the TLIB. The classic clock driver is split in two parts,
clock driver and timer driver. The BSPs need only to fullfill the
timer interface instead of the clock interface. Currently only
LEON3 uses it. The LEON2 Timer is not ported to TLIB.

The GPTIMER driver is implemented using the Driver Manager, so the
System Clock Driver is at this point only suitable for LEON3 when
the driver manager is initialized during BSP startup. When the DrvMgr?
is not initialized during startup the standard BSP/clock dirver is
used.

LEON2 sometimes also needs to access GPTIMER when a off-chip GRLIB AMBA
systems is connected, for example AMBA-over-PCI.

  • 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.com/license/LICENSE.
10 */
11
12#include <rtems.h>
13#include <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.