]> rtime.felk.cvut.cz Git - arc.git/blobdiff - include/isr.h
Merge branch 'mikulka' of git@rtime.felk.cvut.cz:arc into mikulka
[arc.git] / include / isr.h
index e6441585ae5a69667fb46f3d63d9353d26c9686c..148dc3a4c6633f2670f1f71800bae4859bacd3ef 100644 (file)
 #ifndef ISR_H_\r
 #define ISR_H_\r
 \r
+#include "task_i.h"\r
+#include "resource_i.h"\r
+\r
 /*\r
  * INCLUDE "RULES"\r
- *  Since this types and methods defined here are used by the drivers, they should\r
+ *  Since the types and methods defined here are used by the drivers, they should\r
  *  include it. E.g. #include "isr.h"\r
  *\r
  *  This file is also used internally by the kernel\r
 #define ISR_TYPE_2                     1\r
 \r
 /* ----------------------------[macro]---------------------------------------*/\r
+#if 0\r
+//#ifdef CFG_DRIVERS_USE_CONFIG_ISRS\r
+#define ISR_INSTALL_ISR2( _name, _entry, _vector, _priority, _app )\r
+#define ISR_INSTALL_ISR1(_name,_entry, _vector,_priority,_app)\r
+#else\r
+#define ISR_DECLARE_ISR2(_name, _entry, _unique, _vector,_priority,_app )        \\r
+         static const OsIsrConstType _entry ## _unique = { \\r
+                       .vector = _vector,   \\r
+                       .type = ISR_TYPE_2, \\r
+                       .priority = _priority,      \\r
+                       .entry = _entry,      \\r
+                       .name = _name,      \\r
+                       .resourceMask = 0,  \\r
+                       .timingProtPtr = NULL, \\r
+                       .appOwner = _app,      \\r
+                 };                    \\r
+\r
+\r
+#define __ISR_INSTALL_ISR2(_name, _entry, _unique, _vector,_priority,_app )        \\r
+       do { \\r
+         static const OsIsrConstType _entry ## _unique = { \\r
+                       .vector = _vector,   \\r
+                       .type = ISR_TYPE_2, \\r
+                       .priority = _priority,      \\r
+                       .entry = _entry,      \\r
+                       .name = _name,      \\r
+                       .resourceMask = 0,  \\r
+                       .timingProtPtr = NULL, \\r
+                       .appOwner = _app,      \\r
+                 };                    \\r
+         Os_IsrAdd( & _entry ## _unique);   \\r
+       } while(0);\r
+\r
+\r
+\r
+#define _ISR_INSTALL_ISR2(_name,_entry, _unique, _vector,_priority,_app)        \\r
+               __ISR_INSTALL_ISR2(_name,_entry, _unique, _vector,_priority,_app)\r
+\r
+#define ISR_INSTALL_ISR2(_name,_entry, _vector,_priority,_app)        \\r
+               _ISR_INSTALL_ISR2(_name,_entry, __LINE__, _vector,_priority,_app)\r
+\r
+\r
+#define ISR_DECLARE_ISR1(_name, _entry, _unique, _vector,_priority,_app )        \\r
+         static const OsIsrConstType _entry ## _unique = { \\r
+                       .vector = _vector,   \\r
+                       .type = ISR_TYPE_1, \\r
+                       .priority = _priority,      \\r
+                       .entry = _entry,      \\r
+                       .name = _name,      \\r
+                       .resourceMask = 0,  \\r
+                       .timingProtPtr = NULL, \\r
+                       .appOwner = _app,      \\r
+                 };                    \\r
+\r
+#define __ISR_INSTALL_ISR1(_name, _entry, _unique, _vector,_priority,_app )        \\r
+       do { \\r
+         static const OsIsrConstType _entry ## _unique = { \\r
+                       .vector = _vector,   \\r
+                       .type = ISR_TYPE_1, \\r
+                       .priority = _priority,      \\r
+                       .entry = _entry,      \\r
+                       .name = _name,      \\r
+                       .resourceMask = 0,  \\r
+                       .timingProtPtr = NULL, \\r
+                       .appOwner = _app,      \\r
+                 };                    \\r
+         Os_IsrAdd( & _entry ## _unique);   \\r
+       } while(0);\r
+\r
+#define _ISR_INSTALL_ISR1(_name,_entry, _unique, _vector,_priority,_app)        \\r
+               __ISR_INSTALL_ISR1(_name,_entry, _unique, _vector,_priority,_app)\r
+\r
+#define ISR_INSTALL_ISR1(_name,_entry, _vector,_priority,_app)        \\r
+               _ISR_INSTALL_ISR1(_name,_entry, __LINE__, _vector,_priority,_app)\r
+\r
+#endif\r
+\r
 /* ----------------------------[typedef]-------------------------------------*/\r
 \r
 \r
+\r
+/* STD container : OsIsrResourceLock\r
+ * Class: 2 and 4\r
+ *\r
+ * OsIsrResourceLockBudget     1    Float in seconds (MAXRESOURCELOCKINGTIME)\r
+ * OsIsrResourceLockResourceRef 1    Ref to OsResource\r
+ * */\r
+\r
+typedef struct OsIsrResourceLock {\r
+       uint32_t lockBudget;\r
+       uint32_t lockResourceRef;       /* Wrong type */\r
+} OsIsrResourceLockType;\r
+\r
+\r
+/* STD container : OsIsrTimingProtection\r
+ * Class: 2 and 4\r
+ *\r
+ * OsIsrAllInterruptLockBudget  0..1 float\r
+ * OsIsrExecutionBudget                0..1 float\r
+ * OsIsrOsInterruptLockBudget  0..1 float\r
+ * OsIsrTimeFrame                              0..1 float\r
+ * OsIsrResourceLock[C]                0..*\r
+ * */\r
+\r
+typedef struct OsIsrTimingProtection {\r
+       uint32_t allInterruptLockBudget;\r
+       uint32_t executionBudget;\r
+       uint32_t osInterruptLockBudget;\r
+       uint32_t timeFrame;\r
+       uint32_t resourceLock;          /* Wrong type */\r
+} OsIsrTimingProtectionType;\r
+\r
 typedef struct {\r
        void            *curr;  /* Current stack ptr( at swap time ) */\r
        void            *top;   /* Top of the stack( low address )   */\r
@@ -49,10 +161,15 @@ typedef struct {
 } OsIsrStackType;\r
 \r
 \r
-/*\r
- * This type should map against the AUTOSAR OsISR type\r
- */\r
-typedef struct {\r
+/* STD container : OsIsr\r
+ * Class: ALL\r
+ *\r
+ * OsIsrCategory:                              1    CATEGORY_1 or CATEGORY_2\r
+ * OsIsrResourceRef:                   0..* Reference to OsResources\r
+ * OsIsrTimingProtection[C]    0..1\r
+ * */\r
+\r
+typedef struct OsIsrConst {\r
        const char              *name;\r
        uint8_t                 core;\r
        int16_t                 vector;\r
@@ -73,17 +190,98 @@ typedef struct {
 /*\r
  *\r
  */\r
-typedef struct {\r
-       OsIsrStackType          stack;\r
+typedef struct OsIsrVar{\r
+       ISRType id;\r
+//     OsIsrStackType          stack;\r
        int                                     state;\r
        const OsIsrConstType *constPtr;\r
+#if defined(CFG_ARM_CR4)\r
+       int16_t activeVector;\r
+#endif\r
+\r
+       /* List of resource held by this ISR */\r
+       TAILQ_HEAD(,OsResource) resourceHead;\r
 } OsIsrVarType;\r
 \r
 \r
 /* ----------------------------[functions]-----------------------------------*/\r
 \r
+#if OS_ISR_MAX_CNT!=0\r
+extern OsIsrVarType Os_IsrVarList[OS_ISR_MAX_CNT];\r
+#endif\r
+\r
 void Os_IsrInit( void );\r
 ISRType Os_IsrAdd( const OsIsrConstType * restrict isrPtr );\r
-const OsIsrConstType * Os_IsrGet( int16_t vector);\r
+void Os_IsrGetStackInfo( OsIsrStackType *stack );\r
+void *Os_Isr( void *stack, int16_t vector);\r
+#if defined(CFG_ARM_CR4)\r
+void *Os_Isr_cr4( void *stack, int16_t virtualVector, int16_t vector );\r
+#endif\r
+#if defined(CFG_ARM_CM3)\r
+void Os_Isr_cm3( int16_t vector );\r
+void TailChaining(void *stack);\r
+#endif\r
+\r
+static inline const OsIsrVarType *Os_IsrGet( ISRType id ) {\r
+#if OS_ISR_CNT != 0\r
+       return &Os_IsrVarList[id];\r
+#else\r
+       (void)id;\r
+       return NULL;\r
+#endif\r
+}\r
+\r
+static inline ApplicationType Os_IsrGetApplicationOwner( ISRType id ) {\r
+       ApplicationType rv = INVALID_OSAPPLICATION;\r
+\r
+#if (OS_ISR_CNT!=0)\r
+       if( id < OS_ISR_CNT ) {\r
+               rv = Os_IsrGet(id)->constPtr->appOwner;\r
+       }\r
+#else\r
+       (void)id;\r
+#endif\r
+       return rv;\r
+}\r
+\r
+static inline void Os_IsrResourceAdd( OsResourceType *rPtr, OsIsrVarType *isrPtr) {\r
+       /* Save old task prio in resource and set new task prio */\r
+       rPtr->owner = isrPtr->id;\r
+\r
+       assert( rPtr->type != RESOURCE_TYPE_INTERNAL );\r
+}\r
+\r
+static inline  void Os_IsrResourceRemove( OsResourceType *rPtr , OsIsrVarType *isrPtr) {\r
+       assert( rPtr->owner == isrPtr->id );\r
+       rPtr->owner = NO_TASK_OWNER;\r
+\r
+       if( rPtr->type != RESOURCE_TYPE_INTERNAL ) {\r
+               /* The list can't be empty here */\r
+               assert( !TAILQ_EMPTY(&isrPtr->resourceHead) );\r
+\r
+               /* The list should be popped in LIFO order */\r
+               assert( TAILQ_LAST(&isrPtr->resourceHead, head) == rPtr );\r
+\r
+               /* Remove the entry */\r
+               TAILQ_REMOVE(&isrPtr->resourceHead, rPtr, listEntry);\r
+       }\r
+}\r
+\r
+static inline void Os_IsrResourceFreeAll( OsIsrVarType *isrPtr ) {\r
+       OsResourceType *rPtr;\r
+\r
+       /* Pop the queue */\r
+       TAILQ_FOREACH(rPtr, &isrPtr->resourceHead, listEntry ) {\r
+               Os_IsrResourceRemove(rPtr,isrPtr);\r
+       }\r
+}\r
+\r
+static inline _Bool Os_IsrOccupiesResources(  OsIsrVarType *isrPtr ) {\r
+       return !(TAILQ_EMPTY(&isrPtr->resourceHead));\r
+}\r
+\r
+\r
+\r
+\r
 \r
 #endif /*ISR_H_*/\r