![]() |
|
|||
File indexing completed on 2025-05-11 08:24:06
0001 /* SPDX-License-Identifier: BSD-2-Clause */ 0002 0003 /* 0004 * Timer Library (TLIB) 0005 * 0006 * COPYRIGHT (c) 2011. 0007 * Cobham Gaisler AB. 0008 * 0009 * Redistribution and use in source and binary forms, with or without 0010 * modification, are permitted provided that the following conditions 0011 * are met: 0012 * 1. Redistributions of source code must retain the above copyright 0013 * notice, this list of conditions and the following disclaimer. 0014 * 2. Redistributions in binary form must reproduce the above copyright 0015 * notice, this list of conditions and the following disclaimer in the 0016 * documentation and/or other materials provided with the distribution. 0017 * 0018 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 0019 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 0020 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 0021 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 0022 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 0023 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 0024 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 0025 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 0026 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 0027 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 0028 * POSSIBILITY OF SUCH DAMAGE. 0029 */ 0030 0031 #include <rtems.h> 0032 #include <grlib/tlib.h> 0033 0034 struct tlib_dev *tlib_dev_head = NULL; 0035 struct tlib_dev *tlib_dev_tail = NULL; 0036 static int tlib_dev_cnt = 0; 0037 0038 /* Register Timer device to Timer Library */ 0039 int tlib_dev_reg(struct tlib_dev *newdev) 0040 { 0041 /* Reset device */ 0042 newdev->status = 0; 0043 newdev->isr_func = NULL; 0044 newdev->index = tlib_dev_cnt; 0045 0046 /* Insert last in queue */ 0047 newdev->next = NULL; 0048 if ( tlib_dev_tail == NULL ) { 0049 tlib_dev_head = newdev; 0050 } else { 0051 tlib_dev_tail->next = newdev; 0052 } 0053 tlib_dev_tail = newdev; 0054 0055 /* Return Index of Registered Timer */ 0056 return tlib_dev_cnt++; 0057 } 0058 0059 void *tlib_open(int timer_no) 0060 { 0061 struct tlib_dev *dev; 0062 0063 if ( timer_no < 0 ) 0064 return NULL; 0065 0066 dev = tlib_dev_head; 0067 while ( (timer_no > 0) && dev ) { 0068 timer_no--; 0069 dev = dev->next; 0070 } 0071 if ( dev ) { 0072 if ( dev->status ) 0073 return NULL; 0074 dev->status = 1; 0075 /* Reset Timer to initial state */ 0076 tlib_reset(dev); 0077 } 0078 return dev; 0079 } 0080 0081 void tlib_close(void *hand) 0082 { 0083 struct tlib_dev *dev = hand; 0084 0085 /* Stop any ongoing timer operation and unregister IRQ if registered */ 0086 tlib_stop(dev); 0087 tlib_irq_unregister(dev); 0088 0089 /* Mark not open */ 0090 dev->status = 0; 0091 } 0092 0093 int tlib_ntimer(void) 0094 { 0095 return tlib_dev_cnt; 0096 }
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |