3 * Copyright (C) 2009 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
4 * Copyright (C) 2010 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 /** Interval Time Scheduler - NOTE: it's not a task/process scheduler */
27 extern unsigned long timer_ticks
;
29 unsigned int its_unregister (its_t
*its
)
34 its
->next
->prev
= its
->prev
;
35 its
->prev
->next
= its
->next
;
44 for (;; schedule ()) {
46 for (its
= its_list
.next
; its
!= &its_list
; its
= its
->next
)
47 if ((timer_ticks
-its
->timer
) >= its
->interval
) {
48 if (!its
->handler (its
->arg
)) {
53 its
->timer
= timer_ticks
;
60 unsigned int its_register (unsigned long interval
, its_handler_t
*handler
, void *arg
)
62 its_t
*its
= its_list
.next
;
63 /* create ITS' task when it's really needed */
65 task_create ("its", (unsigned) task_its
, 255);
67 /* alloc and init context */
68 its
= (its_t
*) kmalloc (sizeof (its_t
));
73 its
->timer
= timer_ticks
;
74 its
->interval
= interval
;
75 its
->handler
= handler
;
79 its
->next
= &its_list
;
80 its
->prev
= its_list
.prev
;
81 its
->prev
->next
= its
;
82 its
->next
->prev
= its
;
84 DPRINT (DBG_CORE
, "its_register () -> 0x%x every %dms", handler
, interval
);
90 unsigned int test_its_handler (void *arg
)
99 unsigned int init_its ()
101 its_list
.next
= &its_list
;
102 its_list
.prev
= &its_list
;
105 its_register (10000, &test_its_handler
, "test");