2 * Copyright (c) 2013 Qualcomm Atheros, Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted (subject to the limitations in the
7 * disclaimer below) provided that the following conditions are met:
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the
17 * * Neither the name of Qualcomm Atheros nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
22 * GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
23 * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
24 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
30 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
32 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
33 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 #include "athos_api.h"
38 #include "tasklet_api.h"
40 ////////////////////////////////////////////
42 typedef struct _tasklet_context {
43 A_tasklet_t *schedule_tasks;
46 static tasklet_context g_tasklet_ctx;
48 /* Initialize timer software. Called once during initialization. */
50 cmnos_tasklet_init(void)
53 g_tasklet_ctx.schedule_tasks = NULL;
57 cmnos_tasklet_init_task(A_TASKLET_FUNC fn, void * arg, A_tasklet_t *tasklet)
62 tasklet->state = A_TASKLET_STATE_DISABLE;
66 cmnos_tasklet_schedule(A_tasklet_t *tasklet)
68 if ( tasklet->state == A_TASKLET_STATE_SCHEDULED ) {
72 tasklet->state = A_TASKLET_STATE_SCHEDULED;
73 if ( g_tasklet_ctx.schedule_tasks == NULL ) {
74 g_tasklet_ctx.schedule_tasks = tasklet;
76 tasklet->next = g_tasklet_ctx.schedule_tasks;
77 g_tasklet_ctx.schedule_tasks = tasklet;
82 cmnos_tasklet_disable(A_tasklet_t *tasklet)
85 A_tasklet_t *prev = NULL;
87 if ( tasklet->state != A_TASKLET_STATE_SCHEDULED ) {
91 tmp = g_tasklet_ctx.schedule_tasks;
92 while ( tmp != NULL ) {
93 if ( tmp == tasklet ) {
95 g_tasklet_ctx.schedule_tasks = NULL;
97 prev->next = tmp->next;
100 tasklet->state = A_TASKLET_STATE_DISABLE;
110 cmnos_tasklet_run(void)
114 tmp = g_tasklet_ctx.schedule_tasks;
115 while ( tmp != NULL ) {
116 g_tasklet_ctx.schedule_tasks = tmp->next;
119 tmp->state = A_TASKLET_STATE_RUNNING;
121 tmp->state = A_TASKLET_STATE_DISABLE;
123 tmp = g_tasklet_ctx.schedule_tasks;
126 g_tasklet_ctx.schedule_tasks = NULL;
130 cmnos_tasklet_module_install(struct tasklet_api *tbl)
132 tbl->_tasklet_init = cmnos_tasklet_init;
133 tbl->_tasklet_init_task = cmnos_tasklet_init_task;
134 tbl->_tasklet_disable = cmnos_tasklet_disable;
135 tbl->_tasklet_schedule = cmnos_tasklet_schedule;
136 tbl->_tasklet_run = cmnos_tasklet_run;
139 //#define CMNOS_TASKLET_UT
140 #ifdef CMNOS_TASKLET_UT
142 #include <adf_os_defer.h>
147 void test_tasklet(void *arg)
149 adf_os_bh_t *tmpBH = (adf_os_bh_t *)arg;
152 adf_os_print("Tasklet1 running...\n");
153 else if ( tmpBH == &bh2 )
154 adf_os_print("Tasklet2 running...\n");
160 adf_os_init_bh(NULL, &bh, test_tasklet, &bh);
161 adf_os_init_bh(NULL, &bh2, test_tasklet, &bh2);
163 adf_os_sched_bh(NULL, &bh);
164 adf_os_sched_bh(NULL, &bh2);