2 #include <ddekit/initcall.h>
3 #include <ddekit/minix/msg_queue.h>
4 #include <ddekit/panic.h>
5 #include <ddekit/pci.h>
6 #include <ddekit/semaphore.h>
7 #include <ddekit/timer.h>
11 #include "timer.h" /* _ddekit_timer_interrupt() */
12 #include "thread.h" /* _ddekit_thread_set_myprio() */
16 static ddekit_sem_t
*exit_sem
;
18 unsigned long long jiffies
;
20 void ddekit_pgtab_init(void);
22 static ddekit_thread_t
*dispatch_th
= 0;
25 static void dispatcher_thread(void * unused
);
26 static void ddekit_dispatcher_thread_init(void);
28 /****************************************************************************/
29 /* dispatcher_thread */
30 /****************************************************************************/
31 static void dispatcher_thread(void *unused
) {
34 * Gets all messages and dispatches them.
36 * NOTE: this thread runs only when no other ddekit is
37 * ready. So please take care that youre threads
38 * leave some time for the others!
45 _ddekit_thread_set_myprio(0);
49 /* Trigger a timer interrupt at each loop iteration */
50 _ddekit_timer_update();
52 /* Wait for messages */
53 if ((r
= sef_receive_status(ANY
, &m
, &ipc_status
)) != 0) {
54 ddekit_panic("ddekit", "sef_receive failed", r
);
58 _ddekit_timer_interrupt();
60 _ddekit_thread_wakeup_sleeping();
62 if (is_notify(m
.m_type
)) {
63 switch (_ENDPOINT_P(m
.m_source
)) {
65 for (i
=0 ; i
< 32 ; i
++)
67 if(m
.NOTIFY_ARG
& (1 << i
))
69 _ddekit_interrupt_trigger(i
);
74 _ddekit_timer_pending
= 0;
77 ddekit_thread_schedule();
83 * I don't know how to handle this msg,
84 * but maybe we have a msg queue which can
88 ddekit_minix_queue_msg(&m
, ipc_status
);
93 /****************************************************************************/
94 /* ddekit_dispatcher_thread_init */
95 /****************************************************************************/
96 static void ddekit_dispatcher_thread_init()
99 dispatch_th
= ddekit_thread_create(dispatcher_thread
, NULL
, "dispatch");
101 ddekit_thread_schedule();
104 /****************************************************************************/
106 /****************************************************************************/
107 void ddekit_init(void)
113 ddekit_init_threads();
117 ddekit_init_timers();
119 ddekit_dispatcher_thread_init();
121 exit_sem
= ddekit_sem_init(0);
124 /****************************************************************************/
125 /* dispatcher_shutdown */
126 /****************************************************************************/
127 void ddekit_shutdown()
129 ddekit_sem_up(exit_sem
);
132 /****************************************************************************/
133 /* ddekit_minix_wait_exit */
134 /****************************************************************************/
135 void ddekit_minix_wait_exit(void)
137 ddekit_sem_down(exit_sem
);