cocoOS  5.0.1
os_task.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012 Peter Eckstrand
3  *
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted (subject to the limitations in the
8  * disclaimer below) provided that the following conditions are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in the
15  * documentation and/or other materials provided with the
16  * distribution.
17  *
18  * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
19  * GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
20  * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
21  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
22  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
27  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
29  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
30  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  * This file is part of the cocoOS operating system.
33  * Author: Peter Eckstrand <info@cocoos.net>
34  */
35 
36 
37 #ifndef OS_TASK_H__
38 #define OS_TASK_H__
39 
42 #include "os_defines.h"
43 #include "os_msgqueue.h"
44 
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48 
49 typedef struct tcb tcb;
50 
51 typedef enum {
52  SUSPENDED,
53  WAITING_SEM,
54  WAITING_TIME,
55  WAITING_EVENT,
56  WAITING_EVENT_TIMEOUT,
57  READY,
58  RUNNING,
59  KILLED
60 } TaskState_t;
61 
62 
63 #define TASK_OFS1 30000
64 #define TASK_OFS2 31000
65 
66 #define OS_SUSPEND_TASK( id ) do {\
67  os_task_suspend( id );\
68  if ( id == running_tid ) {\
69  OS_SCHEDULE(TASK_OFS1);\
70  }\
71  } while (0)
72 
73 
74 
75 
76 #define OS_RESUME_TASK( id ) do {\
77  os_task_resume( id );\
78  if ( id == running_tid ) {\
79  OS_SCHEDULE(TASK_OFS2);\
80  }\
81  } while (0)
82 
83 
84 void os_task_init(void);
85 uint8_t os_task_highest_prio_ready_task( void );
86 uint8_t os_task_next_ready_task( void );
87 void os_task_ready_set( uint8_t tid );
88 void os_task_wait_sem_set( uint8_t tid, Sem_t sem );
89 void os_task_suspend( uint8_t tid );
90 void os_task_resume( uint8_t tid );
91 void os_task_kill( uint8_t tid );
92 uint8_t os_task_prio_get( uint8_t tid );
93 void os_task_clear_wait_queue( uint8_t tid );
94 void os_task_wait_time_set( uint8_t tid, uint8_t id, uint16_t time );
95 void os_task_wait_event( uint8_t tid, Evt_t eventId, uint8_t waitSingleEvent, uint16_t timeout );
96 void os_task_tick( uint8_t id, uint16_t tickSize );
97 void os_task_signal_event( Evt_t eventId );
98 void os_task_run( void );
99 uint16_t os_task_internal_state_get( uint8_t tid );
100 void os_task_internal_state_set( uint8_t tid, uint16_t state );
101 void os_task_release_waiting_task( Sem_t sem );
102 uint8_t os_task_waiting_this_semaphore( Sem_t sem );
103 MsgQ_t os_task_msgQ_get( uint8_t tid );
104 void os_task_set_wait_queue(uint8_t tid, MsgQ_t queue);
105 MsgQ_t os_task_get_wait_queue(uint8_t tid);
106 void os_task_set_change_event(uint8_t tid, Evt_t event);
107 Evt_t os_task_get_change_event(uint8_t tid);
108 void os_task_set_msg_result(uint8_t tid, uint8_t result);
109 uint8_t os_task_get_msg_result(uint8_t tid);
110 uint16_t os_task_timeout_get(uint8_t tid);
111 
112 
113 
114 #ifdef __cplusplus
115 }
116 #endif
117 
118 
119 #endif
TaskState_t state
current runstate
Definition: os_task.c:43
Definition: os_task.c:41