uTask 0.3.3
|
00001 /* 00002 Copyright (c) 2010 Bartosz Bielawski, Marcin Zapolski 00003 Copyright (c) 2011 Bartosz Bielawski 00004 This software is licensed under MIT License, see LICENSE file. 00005 */ 00006 00007 00008 #ifndef UTASK_H 00009 #define UTASK_H 00010 00061 //------------------------ USER CONFIG STARTS HERE ---------------------------------- 00062 00063 #include <stdint.h> 00064 00066 #define UTASK_VER_STR "0.3.3" 00067 00068 #define UTASK_VER_MAJOR 0 00069 00070 #define UTASK_VER_MINOR 3 00071 00072 #define UTASK_VER_REV 3 00073 00075 #define UTASK_SIMPLE_ADD 00076 00078 #define UTASK_EXIT 00079 00081 #define UTASK_STATS 00082 00084 #define UTASK_SUSPEND_RESUME 00085 00087 #define UTASK_NAME 00088 00090 #define UTASK_TID 00091 00093 #define UTASK_ARG 00094 00096 #define UTASK_SEM 00097 00099 #define UTASK_SEM_CHANGE 00100 00102 #define UTASK_DATA 1 00103 00105 #define UTASKS 10 00106 00108 #define UTASK_PACKED_STRUCT 00109 00111 #define UTASK_CHECK_MCU_SLEEP 00112 00114 typedef uint32_t utask_timer_t; 00116 typedef uint32_t utask_state_t; 00118 typedef uint32_t utask_sem_t; 00120 typedef uint32_t utask_data_t; 00121 00122 #define UTASK_SLEEP_MAX 0xFFFFFFFF 00123 00124 /* 00125 //suggested sizes for 16-bit uCs (MSP430, PIC24...) 00126 typedef uint32_t utask_timer_t; 00127 typedef uint16_t utask_state_t; 00128 typedef uint16_t utask_istate_t; 00129 typedef uint16_t utask_sem_t; 00130 typedef uint16_t utask_data_t; 00131 #define UTASK_SLEEP_MAX 0xFFFFFFFF 00132 00133 //suggested sizes for 8-bit uCs (ATmega, AT90, PIC10/12/14/16/18) 00134 typedef uint16_t utask_timer_t; 00135 typedef uint8_t utask_state_t; 00136 typedef uint8_t utask_istate_t; 00137 typedef uint8_t utask_sem_t; 00138 typedef uint8_t utask_data_t; 00139 #define UTASK_SLEEP_MAX 0xFFFF 00140 */ 00141 00142 00143 //------------------------ END OF USER CONFIG ---------------------------------- 00144 00145 00146 #ifdef UTASK_SEM_CHANGE 00147 #ifndef UTASK_SEM 00148 #define UTASK_SEM 00149 #endif 00150 #endif 00151 00153 #define UTS_NONE 0 00154 00155 #define UTS_SUSP 1 00156 00157 #define UTS_READY 2 00158 00159 #define UTS_SLEEP 3 00160 00161 #ifdef UTASK_SEM 00162 #ifndef UTASK_SEM_CHANGE 00163 00164 #define UTS_WAIT_Z 4 00165 00166 #define UTS_WAIT_NZ 5 00167 #else 00168 00169 #define UTS_WAIT_E 4 00170 00171 #define UTS_WAIT_NE 5 00172 #endif 00173 #endif 00174 00175 #ifdef UTASK_PACKED_STRUCT 00176 #pragma pack(1) 00177 #endif 00178 00179 #ifdef UTASK_CHECK_MCU_SLEEP 00180 extern void (*utask_put_mcu_to_sleep)(utask_data_t d); 00181 #endif 00182 00183 00190 typedef struct utask 00191 { 00193 volatile utask_state_t state; 00195 volatile utask_state_t istate; 00196 #ifdef UTASK_SEM 00197 00198 volatile utask_sem_t* sem; 00199 #ifdef UTASK_SEM_CHANGE 00200 00201 volatile utask_sem_t sem_val; 00202 #endif 00203 #endif 00204 00205 volatile utask_timer_t sleep; 00207 void (*fun)(struct utask* t); 00208 00209 #ifdef UTASK_DATA 00210 #if UTASK_DATA > 0 00211 00212 utask_data_t data[UTASK_DATA]; 00213 #endif 00214 #endif 00215 00216 #ifdef UTASK_ARG 00217 00218 utask_data_t arg; 00219 #endif 00220 00221 #ifdef UTASK_TID 00222 00223 utask_data_t tid; 00224 #endif 00225 00226 #ifdef UTASK_NAME 00227 00228 const char* name; 00229 #endif 00230 } utask_t; 00231 00233 typedef void (*utask_fun)(utask_t* t); 00234 00241 void utask_init(void); 00242 00243 00250 void utask_schedule(void); 00251 00252 00260 void utask_sleep_process(void); 00261 00262 00282 utask_t* utask_add(utask_fun fun); 00283 00284 #ifdef UTASK_NAME 00285 00294 utask_t* utask_add_name(utask_fun fun, const char *name); 00295 #endif 00296 00297 00298 #ifdef UTASK_EXIT 00299 00305 void utask_exit(utask_t* t); 00306 #endif 00307 00308 00316 void utask_sleep (utask_t* t,utask_timer_t ticks); 00317 00318 00319 #ifdef UTASK_SUSPEND_RESUME 00320 00326 void utask_suspend(utask_t* t); 00327 00328 00335 void utask_resume(utask_t* t); 00336 #endif 00337 00346 void utask_wait_zero(utask_t* t, utask_sem_t* sem, utask_timer_t timeout); 00347 00357 void utask_wait_nzero(utask_t* t,utask_sem_t* sem, utask_timer_t timeout); 00358 00359 #ifdef UTASK_SEM_CHANGE 00360 00370 void utask_wait_eq(utask_t* t, utask_sem_t* sem, utask_sem_t sem_val, utask_timer_t timeout); 00371 00382 void utask_wait_neq(utask_t* t, utask_sem_t* sem, utask_sem_t sem_val, utask_timer_t timeout); 00383 #endif 00384 00385 00386 #ifdef UTASK_STATS 00387 00393 utask_data_t utask_get_free_slots(void); 00394 00395 00403 utask_data_t utask_get_task_cnt(utask_fun fun); 00404 #endif 00405 00406 #ifdef UTASK_TID 00407 00414 utask_t* utask_get_by_tid(utask_data_t tid); 00415 #endif 00416 00417 00418 #endif //UTASK_H 00419 00420