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 | * |
| 35 | * $Id: ek.h,v 1.1 2003/04/09 12:55:06 adamdunkels Exp $ |
| 36 | * |
| 37 | */ |
| 38 | /*-----------------------------------------------------------------------------------*/ |
| 39 | #ifndef __EK_H__ |
| 40 | #define __EK_H__ |
| 41 | |
| 42 | #include "ek-conf.h" |
| 43 | |
| 44 | /* Signals defined by ek: */ |
| 45 | #define EK_SIGNAL_NONE 0 |
| 46 | |
| 47 | /* Errors: */ |
| 48 | #define EK_ERR_OK 0 |
| 49 | #define EK_ERR_FULL 1 |
| 50 | #define EK_ERR_NOTUNIQUE 2 |
| 51 | #define EK_ERR_NOTFOUND 3 |
| 52 | |
| 53 | /* Special IDs defined by ek: */ |
| 54 | #define EK_ID_NONE 0 |
| 55 | #define EK_ID_ALL 0 |
| 56 | |
| 57 | typedef unsigned char ek_err_t; |
| 58 | |
| 59 | /* Callback functions (must be implemented by the system/application |
| 60 | program using ek): */ |
| 61 | |
| 62 | /* ek_idle: |
| 63 | * |
| 64 | * Is called repeatedly by ek when there is nothing else to do. This |
| 65 | * function can be used to implement polling operations by the |
| 66 | * system/application program using ek. |
| 67 | */ |
| 68 | void ek_idle(void); |
| 69 | |
| 70 | /* ek_dispatcher: |
| 71 | * |
| 72 | * Is called by ek when a signal has been omitted. The "id" parameter |
| 73 | * can be used to distinguish listeners. |
| 74 | * |
| 75 | * Return values: TBA |
| 76 | */ |
| 77 | ek_err_t ek_dispatcher(ek_signal_t s, ek_data_t data, ek_id_t id); |
| 78 | |
| 79 | /* ek_clock: |
| 80 | * |
| 81 | * Should return the current value of the system clock. |
| 82 | */ |
| 83 | ek_clock_t ek_clock(void); |
| 84 | |
| 85 | |
| 86 | /* API functions (are used by programs using ek): */ |
| 87 | |
| 88 | /* ek_listen: |
| 89 | * |
| 90 | * Registers the listener identified by "id" with the signal "s". When |
| 91 | * the signal "s" is emitted, the ek dispatcher callback will be |
| 92 | * invoked for the listener "id". |
| 93 | * |
| 94 | * The meaning of the identifier "id" is defined by the caller (i.e., |
| 95 | * the application program using the ek kernel). |
| 96 | * |
| 97 | * Return values: TBA |
| 98 | */ |
| 99 | ek_err_t ek_listen(ek_signal_t s, ek_id_t id); |
| 100 | |
| 101 | /* ek_unlisten: |
| 102 | * |
| 103 | * Unregisters a previously registered listener. |
| 104 | * |
| 105 | * Return values: TBA |
| 106 | */ |
| 107 | ek_err_t ek_unlisten(ek_signal_t s, ek_id_t id); |
| 108 | |
| 109 | /* ek_emit: |
| 110 | * |
| 111 | * Emits the signal "s". When control returns to ek, the ek signal |
| 112 | * dispatcher will be called for each of the registered listeners for |
| 113 | * the signal. If no listeners are registered, the signal is |
| 114 | * dropped. |
| 115 | * |
| 116 | * Return values: TBA |
| 117 | */ |
| 118 | ek_err_t ek_emit(ek_signal_t s, ek_data_t data, ek_id_t id); |
| 119 | |
| 120 | /* ek_timer: |
| 121 | * |
| 122 | * Sets a timer that will make the signal "s" to be emitted after "t" |
| 123 | * number of clock ticks. The granularity of the clock ticks is |
| 124 | * determined by the underlying system on which ek is run. |
| 125 | * |
| 126 | * Return values: TBA |
| 127 | */ |
| 128 | ek_err_t ek_timer(ek_signal_t s, ek_data_t data, ek_id_t id, |
| 129 | ek_ticks_t t); |
| 130 | |
| 131 | /* ek_init: |
| 132 | * |
| 133 | * Initializes ek. |
| 134 | */ |
| 135 | void ek_init(void); |
| 136 | |
| 137 | /* ek_signals: |
| 138 | * |
| 139 | * Called internally by ek_run(). Processes signals. |
| 140 | */ |
| 141 | void ek_signals(void); |
| 142 | |
| 143 | /* ek_run: |
| 144 | * |
| 145 | * The main function in ek that is called to start ek. This function |
| 146 | * never returns. |
| 147 | */ |
| 148 | void ek_run(void); |
| 149 | |
| 150 | #endif /* __EK_H__ */ |
| 151 | /*-----------------------------------------------------------------------------------*/ |