]> rtime.felk.cvut.cz Git - arc.git/commitdiff
Fixed bug in kernel ChainTask. Added application.c. osek-ctest
authortojo <tobias.johansson@arccore.com>
Thu, 26 Aug 2010 12:57:42 +0000 (14:57 +0200)
committertojo <tobias.johansson@arccore.com>
Thu, 26 Aug 2010 12:57:42 +0000 (14:57 +0200)
include/Os.h
system/kernel/application.c [new file with mode: 0644]
system/kernel/makefile
system/kernel/task.c

index 076b53372dd4ad7e7ad8962722d91e0e659dafe3..57d65a4847b103ea45e139fcd3526cb159073088 100644 (file)
@@ -249,7 +249,7 @@ StatusType ReleaseResource( ResourceType ResID);
 /*\r
  * Define the scheduler resource as ~0\r
  */\r
-#define        RES_SCHEDULER                   ~(ResourceType)0\r
+#define        RES_SCHEDULER                   (ResourceType)(~0)\r
 \r
 /*\r
  * Priorities of tasks and resources\r
diff --git a/system/kernel/application.c b/system/kernel/application.c
new file mode 100644 (file)
index 0000000..c0de676
--- /dev/null
@@ -0,0 +1,27 @@
+/* -------------------------------- 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
index 78a77f4809f5835e202e2fbbc438a6ba50145daa..81ece28a01198aecefe2928bc39d8a05302b9aee 100644 (file)
@@ -26,7 +26,7 @@ obj-y += sys_tick.o
 #obj-y += stack.o\r
 obj-y += isr.o\r
 obj-y += os_arctest.o\r
-#obj-y += application.o\r
+obj-y += application.o\r
 \r
 \r
 # These are VERY cpu dependent.. remove\r
index 534de83dd61e07c26c0ef24304b23be646abf934..0b3255de5adcb60eba9ab4f4406d95cea79854a1 100644 (file)
@@ -373,6 +373,13 @@ void Os_Arc_GetStackInfo( TaskType task, StackInfoType *s) {
 }\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
@@ -382,9 +389,13 @@ void Os_Arc_GetStackInfo( TaskType task, StackInfoType *s) {
  */\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
@@ -424,12 +435,6 @@ ISRType GetISRID( void ) {
        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
@@ -606,7 +611,7 @@ StatusType TerminateTask( void ) {
 \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
@@ -653,11 +658,7 @@ StatusType ChainTask( TaskType TaskId ) {
        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
@@ -682,7 +683,7 @@ StatusType ChainTask( TaskType TaskId ) {
                        }\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
@@ -690,8 +691,25 @@ StatusType ChainTask( TaskType TaskId ) {
                        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