]> rtime.felk.cvut.cz Git - arc.git/blob - system/kernel/include/task_i.h
Isr almost done
[arc.git] / system / kernel / include / task_i.h
1 /* -------------------------------- Arctic Core ------------------------------\r
2  * Arctic Core - the open source AUTOSAR platform http://arccore.com\r
3  *\r
4  * Copyright (C) 2009  ArcCore AB <contact@arccore.com>\r
5  *\r
6  * This source code is free software; you can redistribute it and/or modify it\r
7  * under the terms of the GNU General Public License version 2 as published by the\r
8  * Free Software Foundation; See <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>.\r
9  *\r
10  * This program is distributed in the hope that it will be useful, but\r
11  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
12  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License\r
13  * for more details.\r
14  * -------------------------------- Arctic Core ------------------------------*/\r
15 \r
16 #ifndef TASK_I_H_\r
17 #define TASK_I_H_\r
18 \r
19 #include <stdlib.h>\r
20 #include <assert.h>\r
21 #include "internal.h"\r
22 \r
23 #include "Ramlog.h"\r
24 \r
25 static inline void os_pcb_print_rq( void ) {\r
26         OsTaskVarType *i_pcb;\r
27         int cnt = 0;\r
28 \r
29         TAILQ_FOREACH(i_pcb,&Os_Sys.ready_head,ready_list) {\r
30                 //printf("%02d: %02d %s\n",cnt,i_pcb->state,i_pcb->name);\r
31                 cnt++;\r
32 //              assert( i_pcb->state == ST_READY );\r
33         }\r
34 }\r
35 \r
36 // schedule()\r
37 static inline void Os_TaskRunningToReady( OsTaskVarType *pcb ) {\r
38         assert(pcb->state == ST_RUNNING );\r
39         pcb->state = ST_READY;\r
40 }\r
41 \r
42 \r
43 // ActivateTask(pid)\r
44 // SetEvent(pid)\r
45 static inline void Os_TaskMakeReady( OsTaskVarType *pcb ) {\r
46         if( !( pcb->state & ( ST_READY | ST_RUNNING )) ) {\r
47                 pcb->state = ST_READY;\r
48                 TAILQ_INSERT_TAIL(& Os_Sys.ready_head,pcb,ready_list);\r
49                 OS_DEBUG(D_TASK,"Added %s to ready list\n",pcb->name);\r
50         }\r
51 }\r
52 \r
53 // WaitEvent\r
54 static inline void Os_TaskMakeWaiting( OsTaskVarType *pcb )\r
55 {\r
56         assert( pcb->state & (ST_READY|ST_RUNNING) );\r
57 \r
58         pcb->state = ST_WAITING;\r
59         TAILQ_REMOVE(&Os_Sys.ready_head,pcb,ready_list);\r
60         OS_DEBUG(D_TASK,"Removed %s from ready list\n",pcb->name);\r
61 }\r
62 \r
63 // Terminate task\r
64 static inline void Os_TaskMakeSuspended( OsTaskVarType *pcb )\r
65         {\r
66         assert( pcb->state & (ST_READY|ST_RUNNING) );\r
67         pcb->state = ST_SUSPENDED;\r
68         TAILQ_REMOVE(&Os_Sys.ready_head,pcb,ready_list);\r
69         OS_DEBUG(D_TASK,"Removed %s from ready list\n",pcb->name);\r
70 }\r
71 \r
72 \r
73 /**\r
74  * Set the task to running state and remove from ready list\r
75  *\r
76  * @params pcb Ptr to pcb\r
77  */\r
78 static inline void Os_TaskMakeRunning( OsTaskVarType *pcb ) {\r
79         pcb->state = ST_RUNNING;\r
80 }\r
81 \r
82 _Bool os_pcb_pid_valid( OsTaskVarType *restrict pcb );\r
83 void Os_TaskStartExtended( void );\r
84 void Os_TaskStartBasic( void );\r
85 void Os_TaskContextInit( OsTaskVarType *pcb );\r
86 OsTaskVarType *Os_TaskGetTop( void );\r
87 \r
88 // Added by Mattias in order to avoid compiler warning\r
89 TaskType Os_AddTask( OsTaskVarType *pcb );\r
90 \r
91 #if 0 // Not used any more\r
92 OsTaskVarType  *os_find_higher_priority_task( OsPriorityType prio );\r
93 #endif\r
94 \r
95 \r
96 \r
97 \r
98 extern OsTaskVarType Os_TaskVarList[OS_TASK_CNT];\r
99 extern OsTaskConstType Os_TaskConstList[OS_TASK_CNT];\r
100 \r
101 static inline OsTaskVarType * Os_TaskGet( TaskType pid ) {\r
102         return &Os_TaskVarList[pid];\r
103 }\r
104 \r
105 static inline ApplicationType Os_TaskGetApplicationOwner( TaskType id ) {\r
106         return Os_TaskGet(id)->constPtr->applOwnerId;\r
107 }\r
108 \r
109 \r
110 #if 0\r
111 extern const OsTaskConstType  Os_TaskConstList[];\r
112 static inline const OsTaskConstType * os_get_rom_pcb( OsTaskidType pid ) {\r
113         return & Os_TaskConstList[pid];\r
114 }\r
115 #endif\r
116 \r
117 \r
118 #if 0\r
119 static inline OsPriorityType os_pcb_set_prio( OsTaskVarType *pcb, OsPriorityType new_prio ) {\r
120         OsPriorityType  old_prio;\r
121         old_prio = pcb->prio;\r
122         pcb->prio = new_prio;\r
123         //printf("set_prio of %s to %d from %d\n",pcb->name,new_prio,pcb->prio);\r
124         return old_prio;\r
125 }\r
126 #endif\r
127 \r
128 #define os_pcb_get_state(pcb) ((pcb)->state)\r
129 \r
130 void Os_TaskSwapContext(OsTaskVarType *old_pcb, OsTaskVarType *new_pcb );\r
131 void Os_TaskSwapContextTo(OsTaskVarType *old_pcb, OsTaskVarType *new_pcb );\r
132 \r
133 \r
134 #endif /*TASK_I_H_*/\r