ISIX-RTOS - small operating system for ARM microcontrollers 1.2
|
00001 #ifndef _ISIX_TASK_H 00002 #define _ISIX_TASK_H 00003 /*-----------------------------------------------------------------------*/ 00004 #ifdef __cplusplus 00005 extern "C" { 00006 namespace isix { 00007 #endif /*__cplusplus*/ 00008 00009 /*-----------------------------------------------------------------------*/ 00010 #include <isix/types.h> 00011 #include <isix/scheduler.h> 00012 00013 /*-----------------------------------------------------------------------*/ 00014 #ifndef __cplusplus 00015 00016 #define ISIX_TASK_FUNC(FUNC, ARG) \ 00017 void FUNC(void *ARG) __attribute__ ((noreturn)); \ 00018 void FUNC(void *ARG) 00019 00020 #endif 00021 /*-----------------------------------------------------------------------*/ 00028 task_t* isix_task_create(task_func_ptr_t task_func, void *func_param, unsigned long stack_depth, prio_t priority); 00029 00030 /*-----------------------------------------------------------------------*/ 00032 int isixp_task_change_prio(task_t *task,prio_t new_prio,bool yield); 00033 00034 /*-----------------------------------------------------------------------*/ 00040 static inline int isix_task_change_prio( task_t* task, prio_t new_prio ) 00041 { 00042 return isixp_task_change_prio(task,new_prio,true); 00043 } 00044 00045 /*-----------------------------------------------------------------------*/ 00046 00051 int isix_task_delete(task_t *task); 00052 00053 /*-----------------------------------------------------------------------*/ 00054 00058 task_t* isix_task_self(void); 00059 00060 /*-----------------------------------------------------------------------*/ 00065 #if ISIX_CONFIG_TASK_STACK_CHECK == ISIX_ON 00066 size_t isix_free_stack_space(const task_t *task); 00067 #endif 00068 00069 /*-----------------------------------------------------------------------*/ 00070 00071 #ifdef __cplusplus 00072 } //end namespace 00073 } //end extern-C 00074 #endif /* __cplusplus */ 00075 00076 /****************************** C++ API ***********************************/ 00077 #ifdef __cplusplus 00078 #include <cstddef> 00079 00080 namespace isix { 00081 /*-----------------------------------------------------------------------*/ 00083 class task_base 00084 { 00085 public: 00090 explicit task_base(std::size_t stack_depth, prio_t priority) 00091 { 00092 task_id = isix_task_create( start_task, this, stack_depth, priority ); 00093 } 00095 virtual ~task_base() 00096 { 00097 isix_task_delete(task_id); 00098 } 00102 task_t* get_taskid() { return task_id; } 00106 bool is_valid() { return task_id!=0; } 00107 protected: 00109 virtual void main() = 0; 00110 00111 private: 00112 __attribute__ ((noreturn)) static void start_task(void *ptr) 00113 { 00114 static_cast<task_base*>(ptr)->main(); 00115 while(1) isix_wait(-1); 00116 } 00117 private: 00118 task_base(const task_base&); 00119 task_base& operator=(const task_base&); 00120 private: 00121 task_t *task_id; 00122 }; 00123 00124 00125 /*-----------------------------------------------------------------------*/ 00126 } 00127 #endif /* __cplusplus */ 00128 /*-----------------------------------------------------------------------*/ 00129 #endif /* __ISIX_TASK_H */ 00130 00131 /*-----------------------------------------------------------------------*/