--- /dev/null
+/* -------------------------------- Arctic Core ------------------------------\r
+ * Arctic Core - the open source AUTOSAR platform http://arccore.com\r
+ *\r
+ * Copyright (C) 2009 ArcCore AB <contact@arccore.com>\r
+ *\r
+ * This source code is free software; you can redistribute it and/or modify it\r
+ * under the terms of the GNU General Public License version 2 as published by the\r
+ * Free Software Foundation; See <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>.\r
+ *\r
+ * This program is distributed in the hope that it will be useful, but\r
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License\r
+ * for more details.\r
+ * -------------------------------- Arctic Core ------------------------------*/\r
+\r
+#include <stdlib.h>\r
+#include "Os.h"\r
+\r
+#include "internal.h"\r
+#include "arc.h"\r
+#include "arch.h"\r
+\r
+\r
+StatusType GetActiveApplicationMode( AppModeType* mode) {\r
+ *mode = os_sys.appMode;\r
+ return E_OK;\r
+}\r
}\r
\r
\r
+#define TASK_CHECK_ID(x) \\r
+ if( (x) > Os_CfgGetTaskCnt()) { \\r
+ rv = E_OS_ID; \\r
+ goto err; \\r
+ }\r
+\r
+\r
/**\r
* Returns the state of a task (running, ready, waiting, suspended)\r
* at the time of calling GetTaskState.\r
*/\r
\r
StatusType GetTaskState(TaskType TaskId, TaskStateRefType State) {\r
- state_t curr_state = os_pcb_get_state(os_get_pcb(TaskId));\r
+ state_t curr_state;\r
StatusType rv = E_OK;\r
\r
+ TASK_CHECK_ID(TaskId);\r
+\r
+ curr_state = os_pcb_get_state(os_get_pcb(TaskId));\r
+\r
// TODO: Lazy impl. for now */\r
switch(curr_state) {\r
case ST_RUNNING: *State = TASK_STATE_RUNNING; break;\r
return (ISRType)Os_TaskGetCurrent()->pid;\r
}\r
\r
-#define TASK_CHECK_ID(x) \\r
- if( (x) > Os_CfgGetTaskCnt()) { \\r
- rv = E_OS_ID; \\r
- goto err; \\r
- }\r
-\r
static inline void Os_Arc_SetCleanContext( OsPcbType *pcb ) {\r
if (pcb->proc_type == PROC_EXTENDED) {\r
/** @req OSEK ActivateTask Cleanup events\r
\r
/* We are already in ready list..\r
* This should give us a clean start /tojo */\r
- Os_Arc_SetCleanContext(curr_pcb);\r
+// Os_Arc_SetCleanContext(curr_pcb);\r
}\r
\r
// Os_ContextReInit(curr_pcb);\r
Irq_Save(flags);\r
\r
if (curr_pcb == pcb) {\r
- /* If we are chaining same task just make a clean start */\r
- /* TODO: Is it allowed to chain same task if extended? */\r
- Os_Arc_SetCleanContext(curr_pcb);\r
-\r
- /* Force the dispatcher to find something, even if its us */\r
+ /* If we are chaining same task Dispatch will give us a clean start */\r
Os_Dispatch(1);\r
\r
Irq_Restore(flags);\r
}\r
}\r
\r
- // Terminate current task\r
+ /* Terminate current task */\r
--curr_pcb->activations;\r
if( curr_pcb->activations <= 0 ) {\r
curr_pcb->activations = 0;\r
Os_TaskMakeSuspended(curr_pcb);\r
}\r
\r
- rv = ActivateTask(TaskId);\r
- // we return here only if something is wrong\r
+ /* Activate chained task\r
+ * We know it's ok here */\r
+ pcb->activations++;\r
+ if( os_pcb_get_state(pcb) == ST_SUSPENDED ) {\r
+ Os_TaskMakeReady(pcb);\r
+ }\r
+\r
+ if( (os_sys.int_nest_cnt == 0) &&\r
+ (Os_SchedulerResourceIsFree()))\r
+ {\r
+ Os_Dispatch(1);\r
+ }\r
+\r
+ /* we will only come back here if we had activations left */\r
+ assert(curr_pcb->activations > 0);\r
+\r
+ /* restart ourselves */\r
+ Os_StackSetup(curr_pcb);\r
+ Os_ArchSetSpAndCall(curr_pcb->stack.curr, Os_TaskStartBasic);\r
}\r
\r
Irq_Restore(flags);\r