adamdunkels | 2f5291c | 2003-04-09 12:55:06 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2002, Adam Dunkels. |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions |
| 7 | * are met: |
| 8 | * 1. Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above |
| 11 | * copyright notice, this list of conditions and the following |
| 12 | * disclaimer in the documentation and/or other materials provided |
| 13 | * with the distribution. |
| 14 | * 3. All advertising materials mentioning features or use of this |
| 15 | * software must display the following acknowledgement: |
| 16 | * This product includes software developed by Adam Dunkels. |
| 17 | * 4. The name of the author may not be used to endorse or promote |
| 18 | * products derived from this software without specific prior |
| 19 | * written permission. |
| 20 | * |
| 21 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS |
| 22 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 23 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
| 25 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE |
| 27 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 29 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 30 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 31 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 32 | * |
| 33 | * This file is part of the "ek" event kernel. |
| 34 | * |
adamdunkels | caebe7d | 2003-04-09 19:15:25 +0000 | [diff] [blame] | 35 | * $Id: dispatcher.h,v 1.2 2003/04/09 19:15:27 adamdunkels Exp $ |
adamdunkels | 2f5291c | 2003-04-09 12:55:06 +0000 | [diff] [blame] | 36 | * |
| 37 | */ |
| 38 | #ifndef __DISPATCHER_H__ |
| 39 | #define __DISPATCHER_H__ |
| 40 | |
| 41 | #include "ek.h" |
adamdunkels | caebe7d | 2003-04-09 19:15:25 +0000 | [diff] [blame] | 42 | #include "cc.h" |
adamdunkels | 2f5291c | 2003-04-09 12:55:06 +0000 | [diff] [blame] | 43 | |
| 44 | void dispatcher_init(void); |
| 45 | |
| 46 | #define DISPATCHER_BROADCAST EK_ID_ALL |
| 47 | |
| 48 | #define DISPATCHER_PROC(name, idle, signal, uip) \ |
| 49 | NULL, 0, name, idle, signal, uip |
| 50 | struct dispatcher_proc { |
| 51 | struct dispatcher_proc *next; |
| 52 | ek_id_t id; |
| 53 | char *name; |
| 54 | void (* idle)(void); |
adamdunkels | caebe7d | 2003-04-09 19:15:25 +0000 | [diff] [blame] | 55 | #if CC_FUNCTION_POINTER_ARGS |
adamdunkels | 2f5291c | 2003-04-09 12:55:06 +0000 | [diff] [blame] | 56 | void (* signalhandler)(ek_signal_t s, ek_data_t data); |
adamdunkels | caebe7d | 2003-04-09 19:15:25 +0000 | [diff] [blame] | 57 | #else /* CC_FUNCTION_POINTER_ARGS */ |
| 58 | void (* signalhandler)(void); |
| 59 | #endif /* CC_FUNCTION_POINTER_ARGS */ |
adamdunkels | 2f5291c | 2003-04-09 12:55:06 +0000 | [diff] [blame] | 60 | void (* uiphandler)(void *state); |
| 61 | }; |
| 62 | |
| 63 | #define DISPATCHER_CURRENT() dispatcher_current |
| 64 | |
| 65 | ek_signal_t dispatcher_sigalloc(void); |
| 66 | |
| 67 | ek_id_t dispatcher_start(struct dispatcher_proc *p); |
| 68 | void dispatcher_exit(struct dispatcher_proc *p); |
| 69 | |
| 70 | void dispatcher_listen(ek_signal_t s); |
| 71 | void dispatcher_timer(ek_signal_t s, ek_data_t data, ek_ticks_t t); |
| 72 | #define dispatcher_emit ek_emit |
| 73 | |
| 74 | struct dispatcher_proc *dispatcher_process(ek_id_t id); |
| 75 | |
| 76 | struct dispatcher_uipstate { |
| 77 | ek_id_t id; |
| 78 | void *state; |
| 79 | }; |
| 80 | |
adamdunkels | caebe7d | 2003-04-09 19:15:25 +0000 | [diff] [blame] | 81 | /* We must do some C macro trickery to make things work with sdcc, |
| 82 | which doesn't support passing arguments to functions called as |
| 83 | function pointers. */ |
| 84 | #if CC_FUNCTION_POINTER_ARGS |
| 85 | #define DISPATCHER_SIGHANDLER(name, s, data) \ |
| 86 | void name(ek_signal_t s, ek_data_t data) |
| 87 | |
| 88 | #define DISPATCHER_SIGHANDLER_ARGS(s, data) |
| 89 | |
| 90 | #else /* CC_FUNCTION_POINTER_ARGS */ |
| 91 | #define DISPATCHER_SIGHANDLER(name, s, data) \ |
| 92 | void name(void) |
| 93 | |
| 94 | #define DISPATCHER_SIGHANDLER_ARGS(s, data) ek_signal_t s = dispatcher_sighandler_s; \ |
| 95 | ek_data_t data = dispatcher_sighandler_data |
| 96 | |
| 97 | extern ek_signal_t dispatcher_sighandler_s; |
| 98 | extern ek_data_t dispatcher_sighandler_data; |
| 99 | #endif /* CC_FUNCTION_POINTER_ARGS */ |
adamdunkels | 2f5291c | 2003-04-09 12:55:06 +0000 | [diff] [blame] | 100 | |
| 101 | #define UIP_APPCALL dispatcher_uipcall |
| 102 | #define UIP_APPSTATE_SIZE sizeof(struct dispatcher_uipstate) |
| 103 | |
| 104 | |
| 105 | #include "uip.h" |
| 106 | |
| 107 | struct uip_conn; |
| 108 | |
| 109 | void dispatcher_uipcall(void); |
| 110 | |
| 111 | void dispatcher_markconn(struct uip_conn *conn, |
| 112 | void *appstate); |
| 113 | void dispatcher_uiplisten(u16_t port); |
| 114 | |
| 115 | extern ek_id_t dispatcher_current; |
| 116 | |
adamdunkels | caebe7d | 2003-04-09 19:15:25 +0000 | [diff] [blame] | 117 | |
adamdunkels | 2f5291c | 2003-04-09 12:55:06 +0000 | [diff] [blame] | 118 | #endif /* __DISPATCHER_H__ */ |