]> rtime.felk.cvut.cz Git - arc.git/blobdiff - system/kernel/application.c
Isr almost done
[arc.git] / system / kernel / application.c
index c0de676c2c8e09f0a52668bcdea7e3b050ccf8eb..0c63b5c2282761ba633d420987a95ac559f8e446 100644 (file)
  * for more details.\r
  * -------------------------------- Arctic Core ------------------------------*/\r
 \r
+/* ----------------------------[includes]------------------------------------*/\r
+\r
 #include <stdlib.h>\r
+#include <stdint.h>\r
 #include "Os.h"\r
 \r
 #include "internal.h"\r
 #include "arc.h"\r
 #include "arch.h"\r
 \r
+/* ----------------------------[private define]------------------------------*/\r
+/* ----------------------------[private macro]-------------------------------*/\r
+#define APPL_ID_TO_MASK(_x)   (1<<(_x))\r
+\r
+/* ----------------------------[private typedef]-----------------------------*/\r
+/* ----------------------------[private function prototypes]-----------------*/\r
+/* ----------------------------[private variables]---------------------------*/\r
+#if OS_APPLICATION_CNT!=0\r
+OsAppVarType Os_AppVar[OS_APPLICATION_CNT];\r
+#endif\r
+\r
+/* ----------------------------[private functions]---------------------------*/\r
+/* ----------------------------[public functions]----------------------------*/\r
+\r
+\r
+/* @req OS547\r
+ *   Availability of AllowAccess(): Available in Scalability Classes 3 and 4.\r
+ * @req OS536\r
+ *    Availability of TerminateApplication(): Available in Scalability Classes 3 and 4.\r
+ * @req OS520\r
+ *    Availability  of  CheckObjectOwnership():Available  in  Scalability  Classes 3 and 4.\r
+ *\r
+ */\r
+\r
+\r
+#if    (OS_USE_APPLICATIONS == STD_ON)\r
+\r
+/**\r
+ * This service determines the currently running OS-Application (a unique\r
+ * identifier has to be allocated to each application).\r
+ *
+ * @return <identifier of running OS-Application> or INVALID_OSAPPLICATION
+ */\r
+\r
+ApplicationType GetApplicationID( void ) {\r
+       return Os_Sys.currApplId;\r
+}\r
+\r
+\r
+/**\r
+ * A (trusted or non-trusted) OS-Application uses this service to call a trusted\r
+ * function\r
+ *
+ * @param FunctionIndex                Index of the function to be called.
+ * @param FunctionParams    Pointer to the parameters for the function -\r
+ *                                                     specified by the FunctionIndex - to be called.\r
+ *                                                     If no parameters are provided, a NULL pointer has\r
+ *                                                     to be passed.
+ * @return
+ */\r
+StatusType     CallTrustedFunction(    TrustedFunctionIndexType FunctionIndex,\r
+                                                                       TrustedFunctionParameterRefType FunctionParams ) {\r
+\r
+\r
+       return E_OK;\r
+}\r
+\r
+\r
+\r
+/**\r
+ * This service checks if a memory region is write/read/execute accessible\r
+ * and also returns information if the memory region is part of the stack\r
+ * space.\r
+ *
+ * @param ISRID                ISR reference
+ * @param Address   Start of memory area
+ * @param Size      Size of memory area
+ * @return
+ */\r
+AccessType CheckISRMemoryAccess( ISRType isrId,\r
+                                                               MemoryStartAddressType address,\r
+                                                               MemorySizeType size )\r
+{\r
+       ptrdiff_t addr = (ptrdiff_t)address;\r
+       (void)addr;\r
+       (void)size;\r
+\r
+       if( isrId > OS_TASK_CNT ) {\r
+               return 0;\r
+       }\r
+       return 0;\r
+}\r
+/**\r
+ * This service checks if a memory region is write/read/execute accessible\r
+ * and also returns information if the memory region is part of the stack\r
+ * space.\r
+ *\r
+ * Check returned accesstype with:\r
+ *   OSMEMORY_IS_READABLE(<AccessType>)\r
+ *   OSMEMORY_IS_WRITEABLE(<AccessType>)\r
+ *   OSMEMORY_IS_EXECUTABLE(<AccessType>)\r
+ *   OSMEMORY_IS_STACKSPACE(<AccessType>)\r
+ *\r
+ * TODO: Not really sure what this function is actually good for? Add a use-case!\r
+ *
+ * @param TaskID   Task reference
+ * @param Address  Start of memory area
+ * @param Size     Size of memory area
+ * @return
+ */\r
+AccessType CheckTaskMemoryAccess(      TaskType taskId,\r
+                                                                       MemoryStartAddressType address,\r
+                                                                       MemorySizeType size )\r
+{\r
+       ptrdiff_t addr = (ptrdiff_t)address;\r
+       (void)addr;\r
+       (void)size;\r
+\r
+       /* @req OS270:\r
+        * if the Task reference <TaskID> in a call of CheckTaskMemoryAccess() is\r
+        * not valid, CheckTaskMemoryAccess() shall yield no access rights.\r
+        */\r
+       if( taskId > OS_TASK_CNT ) {\r
+               return 0;\r
+       }\r
+\r
+       /* TODO: Add body :) */\r
+       return 0;\r
+}\r
+\r
+\r
+/**\r
+ * This service determines if the OS-Applications, given by ApplID,\r
+ * is allowed to use the IDs of a Task, ISR, Resource, Counter,\r
+ * Alarm or Schedule Table in API calls.\r
+ *\r
+ * @param ApplID      OS-Application identifier
+ * @param ObjectType  Type of the following parameter
+ * @param object      The object to be examined
+ * @return ACCESS if the ApplID has access to the object\r
+ * NO_ACCESS otherwise
+ */\r
+ObjectAccessType CheckObjectAccess( ApplicationType ApplId,\r
+                                                                       ObjectTypeType ObjectType,\r
+                                                                       uint32_t objectId )\r
+{\r
+       uint32 appMask = APPL_ID_TO_MASK(ApplId);\r
+       ObjectAccessType orv;\r
+       _Bool rv = 0;\r
+\r
+\r
+       /* @req OS423\r
+        * If in a call of CheckObjectAccess() the object to  be examined\r
+        * is not avalid object OR <ApplID> is invalid OR <ObjectType> is\r
+        * invalid THEN CheckObjectAccess() shall return NO_ACCESS.\r
+        */\r
+       if( ApplId > OS_APPLICATION_CNT ) {\r
+               return NO_ACCESS;\r
+       }\r
+\r
+       /* @req OS272\r
+        * If the OS-Application <ApplID> in a call of CheckObjectAccess() has no\r
+        * access to the queried object, CheckObjectAccess() shall return NO_ACCESS.\r
+        *\r
+        * TODO: Could be that OS450 comes into play here....and then this is wrong.\r
+        */\r
+       if( Os_AppVar[ApplId].state != APPLICATION_ACCESSIBLE ) {\r
+               return NO_ACCESS;\r
+       }\r
+\r
+       /* TODO: check id */\r
+       switch( ObjectType ) {\r
+       case OBJECT_ALARM:\r
+               rv =  ((OsAlarmType *)objectId)->accessingApplMask & (appMask);\r
+               break;\r
+       case OBJECT_COUNTER:\r
+               rv =  ((OsCounterType *)objectId)->accessingApplMask & (appMask);\r
+               break;\r
+       case OBJECT_ISR:\r
+               /* TODO: Add more things here for missing objects */\r
+               break;\r
+       case OBJECT_MESSAGE:\r
+       case OBJECT_RESOURCE:\r
+       case OBJECT_SCHEDULETABLE:\r
+               break;\r
+       case OBJECT_TASK:\r
+               rv = ((OsCounterType *)objectId)->accessingApplMask & (appMask);\r
+               break;\r
+       default:\r
+               /* @req OS423 */\r
+               rv = NO_ACCESS;\r
+               break;\r
+       }\r
 \r
+       orv = rv ? ACCESS : NO_ACCESS;\r
+\r
+       return orv;\r
+}\r
+\r
+/**\r
+ * This service determines to which OS-Application a given Task, ISR, Resource,\r
+ * Counter, Alarm or Schedule Table belongs\r
+ *
+ * @param ObjectType Type of the following parameter
+ * @param object     The object to be examined\r
+ * @return The OS-Application to which the object ObjectType belongs or\r
+ * INVALID_OSAPPLICATION if the object does not exists
+ */\r
+ApplicationType CheckObjectOwnership( ObjectTypeType ObjectType,\r
+                                                                       uint32_t objectId )\r
+{\r
+       ApplicationType rv = INVALID_OSAPPLICATION;\r
+\r
+       switch( ObjectType ) {\r
+       case OBJECT_ALARM:\r
+               break;\r
+       case OBJECT_COUNTER:\r
+               break;\r
+       case OBJECT_ISR:\r
+               break;\r
+       case OBJECT_MESSAGE:\r
+               break;\r
+       case OBJECT_RESOURCE:\r
+               break;\r
+       case OBJECT_SCHEDULETABLE:\r
+               break;\r
+       case OBJECT_TASK:\r
+               if( objectId < OS_TASK_CNT ) {\r
+                       rv = Os_TaskGetApplicationOwner((TaskType)objectId);\r
+               }\r
+               break;\r
+       default:\r
+               break;\r
+       }\r
+\r
+       return rv;\r
+}\r
+\r
+\r
+/**\r
+ * This service terminates the OS-Application to which the calling Task/Category 2\r
+ * ISR/application specific error hook belongs.\r
+ *
+ * @param      Application - The identifier of the OS-Application to be terminated.\r
+ *                     If the caller belongs to <Application> the call results in a\r
+ *                     self termination.\r
+ *\r
+ * @param      RestartOption - Either RESTART for doing a restart of the\r
+ *                     OS-Application or NO_RESTART if OS-Application shall not be restarted.\r
+ *
+ * @return  E_OK: No errors\r
+ *                     E_OS_ID: <Application> was not valid\r
+ *                     E_OS_VALUE: <RestartOption> was neither RESTART nor NO_RESTART\r
+ *                     E_OS_ACCESS: The caller does not have the right to terminate <Application>\r
+ *                     E_OS_STATE: The state of <Application> does not allow terminating <Application>
+ */\r
+StatusType TerminateApplication(  ApplicationType applId, RestartType restartOption ) {\r
+       (void)applId;\r
+       (void)restartOption;\r
+       return E_OK;\r
+}\r
+\r
+\r
+/**\r
+ * This service sets the own state of an OS-Application from\r
+ * APPLICATION_RESTARTING to APPLICATION_ACCESSIBLE.\r
+ *
+ * @return  E_OK : No errors\r
+ *                     E_OS_STATE : The OS-Application of the caller is in the wrong\r
+state
+ */\r
+StatusType AllowAccess( void ) {\r
+       ApplicationType applId = Os_Sys.currApplId;\r
+\r
+       /* @req OS497 */\r
+       if( Os_AppVar[applId].state != APPLICATION_RESTARTING ) {\r
+               return E_OS_STATE;\r
+       }\r
+\r
+       /* @req OS498 */\r
+       Os_AppVar[applId].state = APPLICATION_ACCESSIBLE;\r
+       return E_OK;\r
+}\r
+\r
+/**\r
+ * This service returns the current state of an OS-Application.\r
+ * SC: SC3 and SC4\r
+ *
+ * @param ApplId               The OS-Application from which the state is requested
+ * @param Value                The current state of the application
+ * @return  E_OK: No errors, E_OS_ID: <Application> is not valid
+ */\r
+StatusType GetApplicationState(   ApplicationType applId,  ApplicationStateRefType value ) {\r
+\r
+       if(applId > OS_APPLICATION_CNT ) {\r
+               return E_OS_ID;\r
+       }\r
+\r
+       *value = Os_AppVar[applId].state;\r
+\r
+       return E_OK;\r
+}\r
+\r
+\r
+/**\r
+ * TODO: Move somewhere else
+ * @param mode
+ * @return
+ */\r
 StatusType GetActiveApplicationMode( AppModeType* mode) {\r
-        *mode = os_sys.appMode;\r
+        *mode = Os_Sys.appMode;\r
         return E_OK;\r
 }\r
+\r
+\r
+/**\r
+ *
+ */\r
+void Os_ApplStart( void ) {\r
+       uint16_t i;\r
+\r
+       /* Call startuphooks for all applications */\r
+       for(i=0;i<OS_APPLICATION_CNT;i++) {\r
+\r
+               Os_AppVar[i].state = APPLICATION_ACCESSIBLE;\r
+\r
+               if( Os_AppConst[i].StartupHook != NULL ) {\r
+                       Os_AppConst[i].StartupHook();\r
+               }\r
+       }\r
+}\r
+\r
+uint8_t Os_ApplGetCore( ApplicationType appl )\r
+{\r
+       return Os_AppConst[appl].core;\r
+}\r
+\r
+\r
+#endif\r