]> rtime.felk.cvut.cz Git - arc.git/blobdiff - include/Os.h
EcuM: More EcuM fixes.
[arc.git] / include / Os.h
index 667dbe6389f0262eedae28bf2a19be28b3b84012..0d9e8e1edb449157806a8baa6283db60fd015855 100644 (file)
@@ -1,32 +1,65 @@
-/* -------------------------------- Arctic Core ------------------------------
- * Arctic Core - the open source AUTOSAR platform http://arccore.com
- *
- * Copyright (C) 2009  ArcCore AB <contact@arccore.com>
- *
- * This source code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 as published by the
- * Free Software Foundation; See <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * for more details.
- * -------------------------------- Arctic Core ------------------------------*/
-
-
+/* -------------------------------- 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
+\r
+\r
 \r
 #ifndef OS_H_\r
 #define OS_H_\r
 \r
-#define OS_SW_MAJOR_VERSION    1
-#define OS_SW_MINOR_VERSION    0
+#define OS_SW_MAJOR_VERSION    2\r
+#define OS_SW_MINOR_VERSION    0\r
 #define OS_SW_PATCH_VERSION    0\r
-
+\r
 #include <assert.h>\r
 #include "Std_Types.h"\r
 #include "Os_Cfg.h"\r
 #include "MemMap.h"\r
 #include "Cpu.h"\r
+#include "limits.h"\r
+#include <sys/queue.h>\r
+\r
+typedef uint8 StatusType;\r
+\r
+#if (OS_ISR_CNT > OS_ISR_MAX_CNT)\r
+#error OS configuration error. OS_ISR_MAX_CNT must be bigger or equal to OS_ISR_CNT\r
+#endif\r
+\r
+#define E_OS_ACCESS (StatusType)1               /**< STD OSEK */\r
+#define        E_OS_CALLEVEL (StatusType)2             /**< STD OSEK */\r
+#define        E_OS_ID (StatusType)3                   /**< STD OSEK */\r
+#define        E_OS_LIMIT (StatusType)4                /**< STD OSEK */\r
+#define        E_OS_NOFUNC (StatusType)5               /**< STD OSEK */\r
+#define        E_OS_RESOURCE (StatusType)6             /**< STD OSEK */\r
+#define        E_OS_STATE (StatusType)7                /**< STD OSEK */\r
+#define        E_OS_VALUE (StatusType)8                /**< STD OSEK */\r
+\r
+#define        E_OS_SERVICEID (StatusType)9                /**< AUTOSAR, see 7.10 */\r
+#define        E_OS_RATE (StatusType)10                    /**< AUTOSAR, see 7.10 */\r
+#define        E_OS_ILLEGAL_ADDRESS (StatusType)11         /**< AUTOSAR, see 7.10 */\r
+#define        E_OS_MISSINGEND (StatusType)12              /**< AUTOSAR, see 7.10 */\r
+#define        E_OS_DISABLEDINT (StatusType)13             /**< AUTOSAR, see 7.10 */\r
+#define        E_OS_STACKFAULT (StatusType)14              /**< AUTOSAR, see 7.10 */\r
+#define        E_OS_PROTECTION_MEMORY (StatusType)15       /**< AUTOSAR, see 7.10 */\r
+#define        E_OS_PROTECTION_TIME (StatusType)16         /**< AUTOSAR, see 7.10 */\r
+#define        E_OS_PROTECTION_LOCKED (StatusType)17       /**< AUTOSAR, see 7.10 */\r
+#define        E_OS_PROTECTION_EXCEPTION (StatusType)18    /**< AUTOSAR, see 7.10 */\r
+#define        E_OS_PROTECTION_RATE (StatusType)19          /**< AUTOSAR, see 7.10 */\r
+\r
+#define E_COM_ID 255 // TODO: var ska E_COM_ID vara?"\r
+\r
 \r
 typedef uint32_t               EventMaskType;\r
 typedef EventMaskType *        EventMaskRefType;\r
@@ -37,20 +70,40 @@ typedef enum {
        TASK_STATE_WAITING,\r
        TASK_STATE_READY,\r
        TASK_STATE_SUSPENDED,\r
-       TASK_STATE_RUNNING,\r
+       TASK_STATE_RUNNING\r
 } TaskStateType;\r
 \r
+#define INVALID_TASK   0xdeadU\r
 \r
 typedef TaskStateType *TaskStateRefType;\r
 \r
 /* FIXME: OSMEMORY_IS__ , see 8.2*/\r
 \r
+#define OSMEMORY_IS_READABLE(_access)\r
+#define OSMEMORY_IS_WRITEABLE(_access)\r
+#define OSMEMORY_IS_EXECUTABLE(_access)\r
+#define OSMEMORY_IS_STACKSPACE(_access)\r
+\r
+#define OSDEFAULTAPPMODE  1\r
 \r
 #define INVALID_OSAPPLICATION (-1)\r
 \r
+#define TASK(_task)            void _task( void )\r
+\r
+\r
 /* TODO, I have no idea what this should be*/\r
+#if (OS_USE_APPLICATIONS == STD_ON)\r
 typedef sint32 ApplicationType;\r
 \r
+typedef enum {\r
+       APPLICATION_ACCESSIBLE,\r
+       APPLICATION_RESTARTING,\r
+       APPLICATION_TERMINATED\r
+} ApplicationStateType;\r
+\r
+typedef ApplicationStateType *ApplicationStateRefType;\r
+#endif\r
+\r
 /* See oil config for defines */\r
 typedef sint32 AppModeType;\r
 \r
@@ -123,6 +176,8 @@ typedef  void * TrustedFunctionParameterRefType;
 #define INVALID_ISR            ((sint16)(-1))\r
 typedef        sint16 ISRType;\r
 \r
+#define APP_NO_OWNER   (-1UL)\r
+\r
 typedef void * MemoryStartAddressType;\r
 typedef uint32 MemorySizeType;\r
 \r
@@ -135,95 +190,90 @@ StatusType WaitEvent( EventMaskType Mask );
 StatusType SetEvent( TaskType TaskID, EventMaskType Mask );\r
 StatusType ClearEvent( EventMaskType Mask);\r
 StatusType GetEvent( TaskType TaskId, EventMaskRefType Mask);\r
-
-void InitOS( void );
-void StartOS( AppModeType Mode );
-
 \r
+void InitOS( void );\r
+void StartOS( AppModeType Mode );\r
 \r
-ApplicationType GetApplicationID( void );\r
 ISRType GetISRID( void );\r
-
-typedef int8_t Os_IntCounterType;
-\r
-/* requirements here: OS368(ISR2), OS092 */
-
-extern Os_IntCounterType Os_IntDisableAllCnt;
-extern Os_IntCounterType Os_IntSuspendAllCnt;
-extern Os_IntCounterType Os_IntSuspendOsCnt;
-
-
-
-/** @req OS299 */
-/* OSEK: States that " service  does  not  support  nesting", but says
- * nothing what to do about it.
- *
- * OS092: "  If EnableAllInterrupts()/ResumeAllInterrupts()/ResumeOSInterrupts()
- * are called and no corresponding DisableAllInterupts()/SuspendAllInterrupts()/
- * SuspendOSInterrupts()  was  done  before,  the Operating System shall not
- * perform this OS service.
- */
-static inline void DisableAllInterrupts( void ) {
-       Irq_Disable();
-       Os_IntDisableAllCnt++;
-       /* No nesting allowed */
-       assert(Os_IntDisableAllCnt>1);
-}
-
-static inline void EnableAllInterrupts( void ) {
-
-       if(Os_IntDisableAllCnt==0) {
-               /** @req OS092 EnableAllInterrupts */
-       } else {
-               Os_IntDisableAllCnt--;
-               Irq_Enable();
-       }
-}
-
-static inline void SuspendAllInterrupts( void ) {
-       Irq_SuspendAll();
-       Os_IntSuspendAllCnt++;
-}
-
-static inline void ResumeAllInterrupts( void ) {
-
-       if(Os_IntSuspendAllCnt==0) {
-               /** @req OS092 ResumeAllInterrupts */
-       } else {
-               Os_IntSuspendAllCnt--;
-               Irq_ResumeAll();
-       }
-}
-
-/* Only ISR2 interrupts should be suspended but this can NEVER be
- * done in a more efficient way than to disable all, so let's
- * do that for all targets.
- */
-
-static inline void SuspendOSInterrupts( void ) {
-       Irq_SuspendOs();
-       Os_IntSuspendOsCnt++;
-}
-
-static inline void ResumeOSInterrupts( void ) {
-
-       if(Os_IntSuspendOsCnt==0) {
-               /** @req OS092 ResumeOSInterrupts */
-       } else {
-               Os_IntSuspendOsCnt--;
-               Irq_ResumeOs();
-       }
-}
-
-#if 0
-/* Can't find these anymore, removed from Autosar? */\r
-StatusType EnableInterruptSource( ISRType EnableISR );\r
-StatusType DisableInterruptSource( ISRType EnableISR );\r
-#endif
-\r
-/*
- * Class 2,3 and 4 API
+StatusType GetActiveApplicationMode( AppModeType* mode);\r
+\r
+typedef int8_t Os_IntCounterType;\r
+\r
+/* requirements here: OS368(ISR2), OS092 */\r
+\r
+extern Os_IntCounterType Os_IntDisableAllCnt;\r
+extern Os_IntCounterType Os_IntSuspendAllCnt;\r
+extern Os_IntCounterType Os_IntSuspendOsCnt;\r
+\r
+\r
+\r
+/** @req OS299 */\r
+/* OSEK: States that " service  does  not  support  nesting", but says\r
+ * nothing what to do about it.\r
+ *\r
+ * OS092: "  If EnableAllInterrupts()/ResumeAllInterrupts()/ResumeOSInterrupts()\r
+ * are called and no corresponding DisableAllInterupts()/SuspendAllInterrupts()/\r
+ * SuspendOSInterrupts()  was  done  before,  the Operating System shall not\r
+ * perform this OS service.\r
  */\r
+static inline void DisableAllInterrupts( void ) {\r
+       Irq_Disable();\r
+       Os_IntDisableAllCnt++;\r
+       /* No nesting allowed */\r
+       assert(Os_IntDisableAllCnt==1);\r
+}\r
+\r
+static inline void EnableAllInterrupts( void ) {\r
+\r
+       if(Os_IntDisableAllCnt==0) {\r
+               /** @req OS092 EnableAllInterrupts */\r
+       } else {\r
+               Os_IntDisableAllCnt--;\r
+               Irq_Enable();\r
+       }\r
+}\r
+\r
+static inline void SuspendAllInterrupts( void ) {\r
+       Irq_SuspendAll();\r
+       Os_IntSuspendAllCnt++;\r
+}\r
+\r
+static inline void ResumeAllInterrupts( void ) {\r
+\r
+       if(Os_IntSuspendAllCnt==0) {\r
+               /** @req OS092 ResumeAllInterrupts */\r
+       } else {\r
+               Os_IntSuspendAllCnt--;\r
+               Irq_ResumeAll();\r
+       }\r
+}\r
+\r
+/* Only ISR2 interrupts should be suspended but this can NEVER be\r
+ * done in a more efficient way than to disable all, so let's\r
+ * do that for all targets.\r
+ */\r
+\r
+static inline void SuspendOSInterrupts( void ) {\r
+       Irq_SuspendOs();\r
+       Os_IntSuspendOsCnt++;\r
+}\r
+\r
+static inline void ResumeOSInterrupts( void ) {\r
+\r
+       if(Os_IntSuspendOsCnt==0) {\r
+               /** @req OS092 ResumeOSInterrupts */\r
+       } else {\r
+               Os_IntSuspendOsCnt--;\r
+               Irq_ResumeOs();\r
+       }\r
+}\r
+\r
+/*\r
+ * Class 2,3 and 4 API\r
+ */\r
+\r
+#if (OS_USE_APPLICATIONS == STD_ON)\r
+\r
 ApplicationType GetApplicationID( void );\r
 AccessType     CheckISRMemoryAccess(   ISRType ISRID,\r
                                                                        MemoryStartAddressType Address,\r
@@ -231,10 +281,19 @@ AccessType        CheckISRMemoryAccess(   ISRType ISRID,
 \r
 AccessType     CheckTaskMemoryAccess(  TaskType TaskID,\r
                                                                        MemoryStartAddressType Address,\r
-                                                                       MemorySizeType Size );
+                                                                       MemorySizeType Size );\r
 \r
+ObjectAccessType CheckObjectAccess( ApplicationType ApplId,\r
+                                                                       ObjectTypeType ObjectType,\r
+                                                                       uint32_t objectId );\r
+ApplicationType CheckObjectOwnership( ObjectTypeType ObjectType,\r
+                                                                       uint32_t objectId );\r
+StatusType TerminateApplication(  ApplicationType Application, RestartType RestartOption );\r
+StatusType AllowAccess( void );\r
+StatusType GetApplicationState(   ApplicationType Application,  ApplicationStateRefType Value );\r
 StatusType     CallTrustedFunction(    TrustedFunctionIndexType FunctionIndex,\r
                                                                        TrustedFunctionParameterRefType FunctionParams );\r
+#endif\r
 \r
 StatusType     GetTaskID(              TaskRefType TaskID );\r
 StatusType     GetTaskState(   TaskType task_id, TaskStateRefType state);\r
@@ -245,40 +304,34 @@ StatusType        TerminateTask( void );
 StatusType     ChainTask( TaskType TaskID );\r
 StatusType     Schedule( void );\r
 \r
-typedef uint32 ResourceType;\r
+typedef uint8 ResourceType;\r
 #define DeclareResource(x) extern ResourceType (x);\r
 StatusType GetResource( ResourceType ResID );\r
 StatusType ReleaseResource( ResourceType ResID);\r
-
-/*
- * Define the scheduler resource as 0
- */
-#define        RES_SCHEDULER                   0\r
-
-/*
- * Priorities of tasks and resources
- */
-#define OS_TASK_PRIORITY_MIN   0
-#define OS_TASK_PRIORITY_MAX   31
-/* Logical priority is higher higher than normal tasks */
+\r
+/*\r
+ * Define scheduler as topmost\r
+ */\r
+#define        RES_SCHEDULER                   OS_RESOURCE_CNT\r
+\r
+/*\r
+ * Priorities of tasks and resources\r
+ */\r
+#define OS_TASK_PRIORITY_MIN   0\r
+#define OS_TASK_PRIORITY_MAX   31\r
+/* Logical priority is higher higher than normal tasks */\r
 #define OS_RES_SCHEDULER_PRIO  32\r
 \r
 typedef struct OsDriver_s {\r
        int     OsGptChannelRef;\r
 } OsDriver;\r
 \r
-/*-------------------------------------------------------------------\r
- * Free running timer\r
- *-----------------------------------------------------------------*/
-typedef const uint32 OsTickType;
-void Os_SysTickInit( void );\r
-void Os_SysTickStart(uint32_t period_ticks);\r
-uint32_t Os_SysTickGetTimeElapsed( void );\r
+\r
 \r
 /*-------------------------------------------------------------------\r
  * Counters\r
  *-----------------------------------------------------------------*/\r
-typedef sint16 CounterType;
+typedef sint16 CounterType;\r
 \r
 typedef uint32 TickType;\r
 typedef TickType *TickRefType;\r
@@ -287,6 +340,54 @@ StatusType IncrementCounter( CounterType );
 StatusType GetCounterValue( CounterType, TickRefType );\r
 StatusType GetElapsedCounterValue( CounterType, TickRefType val, TickRefType elapsed_val);\r
 \r
+\r
+/*-------------------------------------------------------------------\r
+ * System timer\r
+ *-----------------------------------------------------------------*/\r
+typedef const uint32 OsTickType;\r
+\r
+extern OsTickType OsTickFreq;\r
+void Os_SysTickInit( void );\r
+void Os_SysTickStart(TickType period_ticks);\r
+TickType Os_SysTickGetValue( void );\r
+TickType Os_SysTickGetElapsedValue( TickType preValue );\r
+\r
+/* Return a value that is always a free running timer */\r
+TickType GetOsTick( void );\r
+\r
+/* Since this is based on SW ticks, no use to have ns resolution */\r
+#define OSTICKDURATION_US              (OSTICKDURATION/1000UL)\r
+\r
+/* Have special macros to always get the OsTick */\r
+#define OS_TICKS2SEC_OS_TICK(_ticks)           ( (OSTICKDURATION_US * (_ticks))/1000000UL )\r
+#define OS_TICKS2MS_OS_TICK(_ticks)            ( (OSTICKDURATION_US * (_ticks))/1000UL )\r
+#define OS_TICKS2US_OS_TICK(_ticks)            (OSTICKDURATION_US * (_ticks))\r
+#define OS_TICKS2NS_OS_TICK(_ticks)            (OSTICKDURATION * (_ticks))\r
+\r
+/*-------------------------------------------------------------------\r
+ * Kernel extra\r
+ *-----------------------------------------------------------------*/\r
+\r
+#if defined(USE_KERNEL_EXTRA)\r
+\r
+#define TICK_MAX       UINT_MAX\r
+\r
+typedef struct OsSemaphore {\r
+       int val;\r
+       STAILQ_HEAD(,OsTaskVar) taskHead;\r
+} OsSemaphoreType;\r
+\r
+typedef OsSemaphoreType OsMutexType;\r
+\r
+StatusType Sleep( TickType ticks );\r
+StatusType InitSemaphore( OsSemaphoreType *semPtr, int initialCount  );\r
+StatusType WaitSemaphore( OsSemaphoreType *semPtr, TickType tmo );\r
+void SignalSemaphore( OsSemaphoreType *semPtr );\r
+StatusType WaitMutex( OsMutexType *mutexPtr );\r
+StatusType ReleaseMutex( OsMutexType *mutexPtr );\r
+#endif\r
+\r
+\r
 /*-------------------------------------------------------------------\r
  * Schedule Tables\r
  *-----------------------------------------------------------------*/\r
@@ -350,23 +451,48 @@ typedef enum {
     OSServiceId_StartupHook,\r
     OSServiceId_ShutdownHook,\r
     OSServiceId_GetTaskState,\r
-} OsServiceIdType;;\r
+    OSServiceId_GetApplicationID,\r
+    OSServiceId_GetISRID,\r
+    OSServiceId_CallTrustedFunction,\r
+    OSServiceId_CheckISRMemoryAccess,\r
+    OSServiceId_TaskMemoryAccess,\r
+    OSServiceId_CheckObjectAccess,\r
+    OSServiceId_CheckObjectOwnership,\r
+    OSServiceId_StartScheduleTableRel,\r
+    OSServiceId_StartScheduleTableAbs,\r
+    OSServiceId_StopScheduleTable,\r
+    OSServiceId_NextScheduleTable,\r
+    OSServiceId_StartScheduleTableSynchron,\r
+    OSServiceId_SyncScheduleTable,\r
+    OSServiceId_GetScheduleTable,\r
+    OSServiceId_SetScheduleTableAsync,\r
+    OSServiceId_IncrementCounter,\r
+    OSServiceId_GetCounterValue,\r
+    OSServiceId_GetElapsedValue,\r
+    OSServiceId_TerminateApplication,\r
+    OSServiceId_AllowAccess,\r
+    OSServiceId_GetApplicationState,\r
+\r
+#if defined(USE_KERNEL_EXTRA)\r
+    OSServiceId_Sleep,\r
+#endif\r
+} OsServiceIdType;\r
 \r
-typedef struct os_error_s {\r
+typedef struct OsError {\r
        OsServiceIdType serviceId;\r
        uint32_t param1;\r
        uint32_t param2;\r
        uint32_t param3;\r
-} os_error_t;\r
+} OsErrorType;\r
 \r
-extern os_error_t os_error;\r
+extern OsErrorType os_error;\r
 \r
 // TODO: Add the service id to all OS service methods.\r
 static inline OsServiceIdType OSErrorGetServiceId(void)  {\r
        return os_error.serviceId;\r
 }\r
 \r
-extern os_error_t os_error;\r
+extern OsErrorType os_error;\r
 \r
 #define OSError_ActivateTask_TaskID ((TaskType) os_error.param1)\r
 #define OSError_ChainTask_TaskID ((TaskType) os_error.param1)\r
@@ -395,12 +521,12 @@ extern os_error_t os_error;
 #define OSError_ShutdownHook_Error ((StatusType) os_error.param1)\r
 #define OSError_GetTaskState_TaskId ((TaskType) os_error.param1)\r
 #define OSError_GetTaskState_State ((TaskStateRefType) os_error.param2)\r
-
-/** @req OS398 */
-#if defined(LOCALMESSAGESONLY)
-#error LOCALMESSAGESONLY shall not be defined
-#endif
-
+\r
+/** @req OS398 */\r
+#if defined(LOCALMESSAGESONLY)\r
+#error LOCALMESSAGESONLY shall not be defined\r
+#endif\r
+\r
 \r
 /*-------------------------------------------------------------------\r
  * COM ( TODO : move )\r
@@ -438,7 +564,7 @@ StatusType ReceiveMessage( MessageType message_id, ApplicationDataRef dataRef );
 TickType GetOsTick();\r
 void OsTick(void);\r
 void OsIdle(void);\r
-
+\r
 #define OS_ISR_TYPE2   0\r
 #define OS_ISR_TYPE1   1\r
 \r
@@ -447,4 +573,10 @@ union isr_attr {
        void (*entry)(void);\r
 };\r
 \r
+#define TTY_NONE               1\r
+#define TTY_T32                2\r
+#define TTY_WINIDEA    4\r
+#define TTY_SERIAL             8\r
+#define RAMLOG         16\r
+\r
 #endif /*OS_H_*/\r