source: rtems/c/src/lib/libbsp/sparc/shared/include/tlib.h @ 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: 4.6 KB
Line 
1/*
2 *  Timer Library (TLIB)
3 *
4 *  The Library rely on timer drivers, the timer presented by the
5 *  timer driver must look like a down-counter timer, which generates
6 *  interrupt (if configured) when underflown.
7 *
8 *  If Timer hardware is an up-counter the Timer driver must recalculate
9 *  into values that would match as if it was a down-counter.
10 *
11 *  COPYRIGHT (c) 2011.
12 *  Cobham Gaisler AB.
13 *
14 *  The license and distribution terms for this file may be
15 *  found in the file LICENSE in this distribution or at
16 *  http://www.rtems.org/license/LICENSE.
17 */
18
19#ifndef __TLIB_H__
20#define __TLIB_H__
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
26struct tlib_dev;
27
28typedef void (*tlib_isr_t)(void *data);
29
30struct tlib_drv {
31        /*** Functions ***/
32        void    (*reset)(struct tlib_dev *hand);
33        void    (*get_freq)(
34                struct tlib_dev *hand,
35                unsigned int *basefreq,
36                unsigned int *tickrate);
37        int     (*set_freq)(struct tlib_dev *hand, unsigned int tickrate);
38        void    (*irq_reg)(struct tlib_dev *hand, tlib_isr_t func, void *data);
39        void    (*irq_unreg)(struct tlib_dev *hand, tlib_isr_t func,void *data);
40        void    (*start)(struct tlib_dev *hand, int once);
41        void    (*stop)(struct tlib_dev *hand);
42        void    (*restart)(struct tlib_dev *hand);
43        void    (*get_counter)(struct tlib_dev *hand, unsigned int *counter);
44        int     (*custom)(struct tlib_dev *hand, int cmd, void *arg);
45        int     (*int_pend)(struct tlib_dev *hand, int ack);
46};
47
48struct tlib_dev {
49        struct tlib_dev *next;
50        char status; /* 0=closed, 1=open, 2=timer started */
51        char index; /* Timer Index */
52        tlib_isr_t isr_func;
53        void *isr_data;
54        struct tlib_drv *drv;
55};
56
57#ifdef RTEMS_DRVMGR_STARTUP
58/* Clock Driver Timer register function. Only used when the TLIB-Clock
59 * driver is used. A specific Timer is registered as the System Clock
60 * timer.
61 */
62extern void Clock_timer_register(int timer_number);
63#endif
64
65/* Register Timer. Called by Timer Drivers in order to register
66 * a Timer to the Timer Library. The registration order determines
67 * the Timer Number used in tlib_open() to identify a specific
68 * Timer.
69 */
70extern int tlib_dev_reg(struct tlib_dev *newdev);
71
72/* Allocate a Timer.
73 *
74 * A Timer handle is returned identifying the timer in later calls.
75 */
76extern void *tlib_open(int timer_no);
77
78/* Close Timer */
79extern void tlib_close(void *hand);
80
81/* Returns Number of Timers currently registered to Timer Library */
82extern int tlib_ntimer(void);
83
84static inline void tlib_reset(void *hand)
85{
86        struct tlib_dev *dev = hand;
87
88        dev->drv->reset(dev);
89}
90/* Get Frequencies:
91 *   - Base Frequency (unchangable base freq rate of timer, prescaler, clkinput)
92 *   - Current Tick Rate [in multiples of Base Frequency]
93 */
94static inline void tlib_get_freq(
95        void *hand,
96        unsigned int *basefreq,
97        unsigned int *tickrate)
98{
99        struct tlib_dev *dev = hand;
100
101        dev->drv->get_freq(dev, basefreq, tickrate);
102}
103
104/* Set current Tick Rate in number of "Base-Frequency ticks" */
105static inline int tlib_set_freq(void *hand, unsigned int tickrate)
106{
107        struct tlib_dev *dev = hand;
108
109        return dev->drv->set_freq(dev, tickrate);
110}
111
112/* Register ISR at Timer ISR */
113static inline void tlib_irq_unregister(void *hand)
114{
115        struct tlib_dev *dev = hand;
116
117        if ( dev->isr_func ) {
118                dev->drv->irq_unreg(dev, dev->isr_func, dev->isr_data);
119                dev->isr_func = NULL;
120        }
121}
122
123/* Register ISR at Timer ISR */
124static inline void tlib_irq_register(void *hand, tlib_isr_t func, void *data)
125{
126        struct tlib_dev *dev = hand;
127
128        /* Unregister previous ISR if installed */
129        tlib_irq_unregister(hand);
130        dev->isr_func = func;
131        dev->isr_data = data;
132        dev->drv->irq_reg(dev, func, data);
133}
134
135/* Start Timer, ISRs will be generated if enabled.
136 *
137 * once determines if timer should restart (=0) on underflow automatically,
138 * or stop when underflow is reached (=1).
139 */
140static inline void tlib_start(void *hand, int once)
141{
142        struct tlib_dev *dev = hand;
143
144        dev->drv->start(dev, once);
145}
146
147/* Stop Timer, no more ISRs will be generated */
148static inline void tlib_stop(void *hand)
149{
150        struct tlib_dev *dev = hand;
151
152        dev->drv->stop(dev);
153}
154
155/* Restart/Reload Timer, may be usefull if a Watchdog Timer */
156static inline void tlib_restart(void *hand)
157{
158        struct tlib_dev *dev = hand;
159
160        dev->drv->restart(dev);
161}
162
163/* Get current counter value (since last tick) */
164static inline void tlib_get_counter(void *hand, unsigned int *counter)
165{
166        struct tlib_dev *dev = hand;
167
168        dev->drv->get_counter(dev, counter);
169}
170
171/* Do a custom operation  */
172static inline void tlib_custom(void *hand, int cmd, void *arg)
173{
174        struct tlib_dev *dev = hand;
175
176        dev->drv->custom(dev, cmd, arg);
177}
178
179static inline int tlib_interrupt_pending(void *hand, int ack)
180{
181        struct tlib_dev *dev = hand;
182
183        return dev->drv->int_pend(dev, ack);
184}
185
186#ifdef __cplusplus
187}
188#endif
189
190#endif
Note: See TracBrowser for help on using the repository browser.