1 /* -------------------------------- Arctic Core ------------------------------
\r
2 * Arctic Core - the open source AUTOSAR platform http://arccore.com
\r
4 * Copyright (C) 2009 ArcCore AB <contact@arccore.com>
\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
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
14 * -------------------------------- Arctic Core ------------------------------*/
\r
21 #include "internal.h"
\r
25 static inline void os_pcb_print_rq( void ) {
\r
26 OsTaskVarType *i_pcb;
\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
32 // assert( i_pcb->state == ST_READY );
\r
37 static inline void Os_TaskRunningToReady( OsTaskVarType *pcb ) {
\r
38 assert(pcb->state == ST_RUNNING );
\r
39 pcb->state = ST_READY;
\r
43 // ActivateTask(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
54 static inline void Os_TaskMakeWaiting( OsTaskVarType *pcb )
\r
56 assert( pcb->state & (ST_READY|ST_RUNNING) );
\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
64 static inline void Os_TaskMakeSuspended( OsTaskVarType *pcb )
\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
74 * Set the task to running state and remove from ready list
\r
76 * @params pcb Ptr to pcb
\r
78 static inline void Os_TaskMakeRunning( OsTaskVarType *pcb ) {
\r
79 pcb->state = ST_RUNNING;
\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
88 // Added by Mattias in order to avoid compiler warning
\r
89 TaskType Os_AddTask( OsTaskVarType *pcb );
\r
91 #if 0 // Not used any more
\r
92 OsTaskVarType *os_find_higher_priority_task( OsPriorityType prio );
\r
98 extern OsTaskVarType Os_TaskVarList[OS_TASK_CNT];
\r
99 extern OsTaskConstType Os_TaskConstList[OS_TASK_CNT];
\r
101 static inline OsTaskVarType * Os_TaskGet( TaskType pid ) {
\r
102 return &Os_TaskVarList[pid];
\r
105 static inline ApplicationType Os_TaskGetApplicationOwner( TaskType id ) {
\r
106 return Os_TaskGet(id)->constPtr->applOwnerId;
\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
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
128 #define os_pcb_get_state(pcb) ((pcb)->state)
\r
130 void Os_TaskSwapContext(OsTaskVarType *old_pcb, OsTaskVarType *new_pcb );
\r
131 void Os_TaskSwapContextTo(OsTaskVarType *old_pcb, OsTaskVarType *new_pcb );
\r
134 #endif /*TASK_I_H_*/
\r