RT-AC56 3.0.0.4.374.37 core
[tomato.git] / release / src-rt-6.x.4708 / cfe / cfe / main / cfe_background.c
blob9a64e0a8a191c13ead8d27445ba20b589b440e81
1 /* *********************************************************************
2 * Broadcom Common Firmware Environment (CFE)
3 *
4 * Timer routines File: cfe_timer.c
5 *
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
9 * get called from.
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 /* *********************************************************************
59 * Constants
60 ********************************************************************* */
62 #define MAX_BACKGROUND_TASKS 16
65 /* *********************************************************************
66 * Globals
67 ********************************************************************* */
69 static void (*cfe_bg_tasklist[MAX_BACKGROUND_TASKS])(void *);
70 static void *cfe_bg_args[MAX_BACKGROUND_TASKS];
73 /* *********************************************************************
74 * cfe_bg_init()
76 * Initialize the background task list
78 * Input parameters:
79 * nothing
81 * Return value:
82 * nothing
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
95 * polling loop.
97 * Input parameters:
98 * func - function pointer
99 * arg - arg to pass to function
101 * Return value:
102 * nothing
103 ********************************************************************* */
105 void cfe_bg_add(void (*func)(void *x),void *arg)
107 int idx;
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;
113 return;
118 /* *********************************************************************
119 * cfe_bg_remove(func)
121 * Remove a function from the background polling loop
123 * Input parameters:
124 * func - function pointer
126 * Return value:
127 * nothing
128 ********************************************************************* */
130 void cfe_bg_remove(void (*func)(void *))
132 int idx;
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 /* *********************************************************************
151 * background()
153 * The main loop and other places that wait for stuff call
154 * this routine to make sure the background handlers get their
155 * time.
157 * Input parameters:
158 * nothing
160 * Return value:
161 * nothing
162 ********************************************************************* */
164 void background(void)
166 int idx;
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]);