5
Rev | Line | |
---|
[cd64fbf] | 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 |
---|
[4a7d1026] | 9 | * http://www.rtems.org/license/LICENSE. |
---|
[cd64fbf] | 10 | */ |
---|
| 11 | |
---|
| 12 | #include <rtems.h> |
---|
[31720925] | 13 | #include <grlib/tlib.h> |
---|
[cd64fbf] | 14 | |
---|
| 15 | struct tlib_dev *tlib_dev_head = NULL; |
---|
| 16 | struct tlib_dev *tlib_dev_tail = NULL; |
---|
| 17 | static int tlib_dev_cnt = 0; |
---|
| 18 | |
---|
| 19 | /* Register Timer device to Timer Library */ |
---|
| 20 | int 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 | |
---|
| 40 | void *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 | |
---|
| 62 | void 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 | |
---|
| 74 | int tlib_ntimer(void) |
---|
| 75 | { |
---|
| 76 | return tlib_dev_cnt; |
---|
| 77 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.