1 /* *********************************************************************
2 * Broadcom Common Firmware Environment (CFE)
4 * Timer routines File: cfe_timer.c
6 * This module manages the list of routines to call periodically
7 * during "background processing." CFE has no interrupts or
8 * multitasking, so this is just where all the polling routines
11 * Author: Mitch Lichtenberg (mpl@broadcom.com)
13 *********************************************************************
15 * Copyright 2000,2001,2002,2003
16 * Broadcom Corporation. All rights reserved.
18 * This software is furnished under license and may be used and
19 * copied only in accordance with the following terms and
20 * conditions. Subject to these conditions, you may download,
21 * copy, install, use, modify and distribute modified or unmodified
22 * copies of this software in source and/or binary form. No title
23 * or ownership is transferred hereby.
25 * 1) Any source code used, modified or distributed must reproduce
26 * and retain this copyright notice and list of conditions
27 * as they appear in the source file.
29 * 2) No right is granted to use any trade name, trademark, or
30 * logo of Broadcom Corporation. The "Broadcom Corporation"
31 * name may not be used to endorse or promote products derived
32 * from this software without the prior written permission of
33 * Broadcom Corporation.
35 * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR
36 * IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED
37 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
38 * PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT
39 * SHALL BROADCOM BE LIABLE FOR ANY DAMAGES WHATSOEVER, AND IN
40 * PARTICULAR, BROADCOM SHALL NOT BE LIABLE FOR DIRECT, INDIRECT,
41 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
42 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
43 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
44 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
45 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
46 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE), EVEN IF ADVISED OF
47 * THE POSSIBILITY OF SUCH DAMAGE.
48 ********************************************************************* */
52 #include "lib_types.h"
53 #include "lib_string.h"
54 #include "lib_printf.h"
56 #include "cfe_timer.h"
58 /* *********************************************************************
60 ********************************************************************* */
62 #define MAX_BACKGROUND_TASKS 16
65 /* *********************************************************************
67 ********************************************************************* */
69 static void (*cfe_bg_tasklist
[MAX_BACKGROUND_TASKS
])(void *);
70 static void *cfe_bg_args
[MAX_BACKGROUND_TASKS
];
73 /* *********************************************************************
76 * Initialize the background task list
83 ********************************************************************* */
85 void cfe_bg_init(void)
87 memset(cfe_bg_tasklist
,0,sizeof(cfe_bg_tasklist
));
91 /* *********************************************************************
92 * cfe_bg_add(func,arg)
94 * Add a function to be called periodically in the background
98 * func - function pointer
99 * arg - arg to pass to function
103 ********************************************************************* */
105 void cfe_bg_add(void (*func
)(void *x
),void *arg
)
109 for (idx
= 0; idx
< MAX_BACKGROUND_TASKS
; idx
++) {
110 if (cfe_bg_tasklist
[idx
] == NULL
) {
111 cfe_bg_tasklist
[idx
] = func
;
112 cfe_bg_args
[idx
] = arg
;
118 /* *********************************************************************
119 * cfe_bg_remove(func)
121 * Remove a function from the background polling loop
124 * func - function pointer
128 ********************************************************************* */
130 void cfe_bg_remove(void (*func
)(void *))
134 for (idx
= 0; idx
< MAX_BACKGROUND_TASKS
; idx
++) {
135 if (cfe_bg_tasklist
[idx
] == func
) break;
138 if (idx
== MAX_BACKGROUND_TASKS
) return;
140 for (; idx
< MAX_BACKGROUND_TASKS
-1; idx
++) {
141 cfe_bg_tasklist
[idx
] = cfe_bg_tasklist
[idx
+1];
142 cfe_bg_args
[idx
] = cfe_bg_args
[idx
+1];
145 cfe_bg_tasklist
[idx
] = NULL
;
146 cfe_bg_args
[idx
] = NULL
;
150 /* *********************************************************************
153 * The main loop and other places that wait for stuff call
154 * this routine to make sure the background handlers get their
162 ********************************************************************* */
164 void background(void)
167 void (*func
)(void *arg
);
169 for (idx
= 0; idx
< MAX_BACKGROUND_TASKS
; idx
++) {
170 func
= cfe_bg_tasklist
[idx
];
171 if (func
== NULL
) break;
172 (*func
)(cfe_bg_args
[idx
]);