pkgin_all: script to auto-install all packages
[minix.git] / lib / libddekit / src / dde.c
blob8fc7fd4736a14e09d7f4f8f978307e761528c47a
1 #include "common.h"
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>
8 #include <signal.h>
10 #include "debug.h"
11 #include "timer.h" /* _ddekit_timer_interrupt() */
12 #include "thread.h" /* _ddekit_thread_set_myprio() */
13 #include "irq.h"
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!
40 message m;
41 int r;
42 int i;
43 int ipc_status;
45 _ddekit_thread_set_myprio(0);
47 for( ; ; ) {
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)) {
64 case HARDWARE:
65 for (i =0 ; i < 32 ; i++)
67 if(m.NOTIFY_ARG & (1 << i))
69 _ddekit_interrupt_trigger(i);
72 break;
73 case CLOCK:
74 _ddekit_timer_pending = 0;
75 break;
76 default:
77 ddekit_thread_schedule();
80 } else {
83 * I don't know how to handle this msg,
84 * but maybe we have a msg queue which can
85 * handle this msg.
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 /****************************************************************************/
105 /* ddekit_init */
106 /****************************************************************************/
107 void ddekit_init(void)
109 sef_startup();
111 ddekit_pgtab_init();
113 ddekit_init_threads();
115 ddekit_init_irqs();
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);