tinyOS  v1.00
tTask.h
Go to the documentation of this file.
1 
14 #ifndef TTASK_H
15 #define TTASK_H
16 
17 #define TINYOS_TASK_STATE_RDY 0
18 #define TINYOS_TASK_STATE_DESTROYED (1 << 0)
19 #define TINYOS_TASK_STATE_DELAYED (1 << 1)
20 #define TINYOS_TASK_STATE_SUSPEND (1 << 2)
21 
22 #define TINYOS_TASK_WAIT_MASK (0xFF << 16)
23 
24 // 前置声明
25 struct _tEvent;
26 
27 // Cortex-M的堆栈单元类型:堆栈单元的大小为32位,所以使用uint32_t
28 typedef uint32_t tTaskStack;
29 
30 // 任务结构:包含了一个任务的所有信息
31 typedef struct _tTask {
32  // 任务所用堆栈的当前堆栈指针。每个任务都有他自己的堆栈,用于在运行过程中存储临时变量等一些环境参数
33  // 在tinyOS运行该任务前,会从stack指向的位置处,会读取堆栈中的环境参数恢复到CPU寄存器中,然后开始运行
34  // 在切换至其它任务时,会将当前CPU寄存器值保存到堆栈中,等待下一次运行该任务时再恢复。
35  // stack保存了最后保存环境参数的地址位置,用于后续恢复
36  uint32_t *stack;
37  uint32_t *stackBase;
39  uint32_t stackSize;
42  uint32_t delayTicks;
45  uint32_t prio;
47  uint32_t state;
48  uint32_t slice;
50  uint32_t suspendCount;
52  void (*clean) (void *param);
53  void *cleanParam;
57  struct _tEvent *waitEvent;
58  void *eventMsg;
59  uint32_t waitEventResult;
60  uint32_t waitFlagsType;
61  uint32_t eventFlags;
62 } tTask;
63 
64 // 任务相关信息结构
65 typedef struct _tTaskInfo {
66  uint32_t delayTicks;
67  uint32_t prio;
68  uint32_t state;
69  uint32_t slice;
70  uint32_t suspendCount;
71  uint32_t stackSize;
72  uint32_t stackFree;
73 } tTaskInfo;
74 
75 void tTaskInit (tTask *task, void (*entry) (void *), void *param, uint32_t prio, uint32_t *stack, uint32_t size);
76 void tTaskSuspend (tTask *task);
77 void tTaskWakeUp (tTask *task);
78 void tTaskSetCleanCallFunc (tTask *task, void (*clean) (void *param), void *param);
79 void tTaskForceDelete (tTask *task);
80 void tTaskRequestDelete (tTask *task);
81 uint8_t tTaskIsRequestedDelete (void);
82 void tTaskDeleteSelf (void);
83 void tTaskGetInfo (tTask *task, tTaskInfo *info);
84 
85 #endif /* TTASK_H */
86 
uint32_t stackSize
Definition: tTask.h:71
uint32_t * stack
Definition: tTask.h:36
Definition: tTask.h:31
uint32_t tTaskStack
Definition: tTask.h:25
void * eventMsg
Definition: tTask.h:58
void tTaskSetCleanCallFunc(tTask *task, void(*clean)(void *param), void *param)
Definition: tTask.c:143
void tTaskDeleteSelf(void)
Definition: tTask.c:217
void tTaskSuspend(tTask *task)
Definition: tTask.c:83
struct _tEvent * waitEvent
Definition: tTask.h:57
uint32_t prio
Definition: tTask.h:67
void * cleanParam
Definition: tTask.h:53
Definition: tLib.h:35
uint32_t suspendCount
Definition: tTask.h:70
uint8_t requestDeleteFlag
Definition: tTask.h:54
void tTaskInit(tTask *task, void(*entry)(void *), void *param, uint32_t prio, uint32_t *stack, uint32_t size)
Definition: tTask.c:23
Definition: tEvent.h:32
struct _tTaskInfo tTaskInfo
uint32_t suspendCount
Definition: tTask.h:50
void tTaskRequestDelete(tTask *task)
Definition: tTask.c:183
struct _tTask tTask
void(* clean)(void *param)
Definition: tTask.h:52
uint32_t slice
Definition: tTask.h:48
tNode delayNode
Definition: tTask.h:43
uint32_t eventFlags
Definition: tTask.h:61
uint32_t prio
Definition: tTask.h:45
uint32_t waitFlagsType
Definition: tTask.h:60
uint32_t * stackBase
Definition: tTask.h:37
uint32_t delayTicks
Definition: tTask.h:66
void tTaskGetInfo(tTask *task, tTaskInfo *info)
Definition: tTask.c:242
void tTaskForceDelete(tTask *task)
Definition: tTask.c:152
uint32_t state
Definition: tTask.h:47
tNode linkNode
Definition: tTask.h:40
uint32_t slice
Definition: tTask.h:69
void tTaskWakeUp(tTask *task)
Definition: tTask.c:114
uint32_t delayTicks
Definition: tTask.h:42
uint32_t stackFree
Definition: tTask.h:72
uint32_t stackSize
Definition: tTask.h:39
uint8_t tTaskIsRequestedDelete(void)
Definition: tTask.c:199
uint32_t state
Definition: tTask.h:68
uint32_t waitEventResult
Definition: tTask.h:59