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> 9 10 #include "debug.h" 11 #include "timer.h" /* _ddekit_timer_interrupt() */ 12 #include "thread.h" /* _ddekit_thread_set_myprio() */ 13 #include "irq.h" 14 15 16 static ddekit_sem_t *exit_sem; 17 18 unsigned long long jiffies; 19 20 void ddekit_pgtab_init(void); 21 22 static ddekit_thread_t *dispatch_th = 0; 23 24 25 static void dispatcher_thread(void * unused); 26 static void ddekit_dispatcher_thread_init(void); 27 28 /****************************************************************************/ 29 /* dispatcher_thread */ 30 /****************************************************************************/ dispatcher_thread(void * unused)31static void dispatcher_thread(void *unused) { 32 33 /* 34 * Gets all messages and dispatches them. 35 * 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! 39 */ 40 message m; 41 int r; 42 int i; 43 int ipc_status; 44 45 _ddekit_thread_set_myprio(0); 46 47 for( ; ; ) { 48 49 /* Trigger a timer interrupt at each loop iteration */ 50 _ddekit_timer_update(); 51 52 /* Wait for messages */ 53 if ((r = sef_receive_status(ANY, &m, &ipc_status)) != 0) { 54 ddekit_panic("ddekit", "sef_receive failed", r); 55 } 56 57 58 _ddekit_timer_interrupt(); 59 60 _ddekit_thread_wakeup_sleeping(); 61 62 if (is_notify(m.m_type)) { 63 switch (_ENDPOINT_P(m.m_source)) { 64 case HARDWARE: 65 for (i =0 ; i < 32 ; i++) 66 { 67 if(m.m_notify.interrupts & (1 << i)) 68 { 69 _ddekit_interrupt_trigger(i); 70 } 71 } 72 break; 73 case CLOCK: 74 _ddekit_timer_pending = 0; 75 break; 76 default: 77 ddekit_thread_schedule(); 78 } 79 80 } else { 81 82 /* 83 * I don't know how to handle this msg, 84 * but maybe we have a msg queue which can 85 * handle this msg. 86 */ 87 88 ddekit_minix_queue_msg(&m, ipc_status); 89 } 90 } 91 } 92 93 /****************************************************************************/ 94 /* ddekit_dispatcher_thread_init */ 95 /****************************************************************************/ ddekit_dispatcher_thread_init()96static void ddekit_dispatcher_thread_init() 97 { 98 99 dispatch_th = ddekit_thread_create(dispatcher_thread, NULL, "dispatch"); 100 101 ddekit_thread_schedule(); 102 } 103 104 /****************************************************************************/ 105 /* ddekit_init */ 106 /****************************************************************************/ ddekit_init(void)107void ddekit_init(void) 108 { 109 sef_startup(); 110 111 ddekit_pgtab_init(); 112 113 ddekit_init_threads(); 114 115 ddekit_init_irqs(); 116 117 ddekit_init_timers(); 118 119 ddekit_dispatcher_thread_init(); 120 121 exit_sem = ddekit_sem_init(0); 122 } 123 124 /****************************************************************************/ 125 /* dispatcher_shutdown */ 126 /****************************************************************************/ ddekit_shutdown()127void ddekit_shutdown() 128 { 129 ddekit_sem_up(exit_sem); 130 } 131 132 /****************************************************************************/ 133 /* ddekit_minix_wait_exit */ 134 /****************************************************************************/ ddekit_minix_wait_exit(void)135void ddekit_minix_wait_exit(void) 136 { 137 ddekit_sem_down(exit_sem); 138 } 139 140