]> rtime.felk.cvut.cz Git - arc.git/blob - system/kernel/include/sched_table_i.h
Initial commit of changes to add applications. Nothing works....
[arc.git] / system / kernel / include / sched_table_i.h
1 /* -------------------------------- Arctic Core ------------------------------\r
2  * Arctic Core - the open source AUTOSAR platform http://arccore.com\r
3  *\r
4  * Copyright (C) 2009  ArcCore AB <contact@arccore.com>\r
5  *\r
6  * This source code is free software; you can redistribute it and/or modify it\r
7  * under the terms of the GNU General Public License version 2 as published by the\r
8  * Free Software Foundation; See <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>.\r
9  *\r
10  * This program is distributed in the hope that it will be useful, but\r
11  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
12  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License\r
13  * for more details.\r
14  * -------------------------------- Arctic Core ------------------------------*/\r
15 \r
16 #ifndef SCHED_TABLE_I_H_\r
17 #define SCHED_TABLE_I_H_\r
18 \r
19 /* Should hold the internal API used by the schedule tables */\r
20 \r
21 #define SCHEDULE_ACTION_ACTIVATETASK    0\r
22 #define SCHEDULE_ACTION_SETEVENT        1\r
23 \r
24 #include "alist_i.h"\r
25 #include "counter_i.h"\r
26 \r
27 struct OsCounter;\r
28 \r
29 #define SINGLE_SHOT     0\r
30 #define REPEATING               1\r
31 \r
32 #if ( OS_SC2 == STD_ON ) || ( OS_SC4 == STD_ON )\r
33 enum OsScheduleTableSyncStrategy {\r
34         /* Support for sync, this is same as no OS */\r
35         NONE,\r
36         /* synchronize with "external" counter */\r
37         EXPLICIT,\r
38         /* sync internal */\r
39         IMPLICIT,\r
40 };\r
41 #endif\r
42 \r
43 enum OsScheduleTableAutostartType {\r
44         // Start with StartScheduleTableAbs()\r
45         SCHTBL_AUTOSTART_ABSOLUTE,\r
46         // Start with StartScheduleTableRel()\r
47         SCHTBL_AUTOSTART_RELATIVE,\r
48         // Start with StartScheduleTableSyncon()\r
49         SCHTBL_AUTOSTART_SYNCHRONE,\r
50 };\r
51 \r
52 \r
53 /* STD container: OsScheduleTableEventSetting\r
54  * OsScheduleTableSetEventRef:          1\r
55  * OsScheduleTableSetEventTaskRef:      1\r
56 */\r
57 typedef struct OsScheduleTableEventSetting {\r
58         EventMaskType   event;\r
59         TaskType     task;\r
60 } OsScheduleTableEventSettingType;\r
61 \r
62 /* OsScheduleTableTaskActivation */\r
63 \r
64 /* STD container: OsScheduleTableExpiryPoint\r
65  * OsScheduleTblExpPointOffset:         1    Int\r
66  * OsScheduleTableEventSetting:         0..*\r
67  * OsScheduleTableTaskActivation:       0..*\r
68  * OsScheduleTblAdjustableExpPoint:     0..1\r
69  * */\r
70 \r
71 /** @req OS402 */\r
72 /** @req OS403 */\r
73 typedef struct OsScheduleTableExpiryPoint {\r
74         /* The expiry point offset, OsScheduleTblExpPointOffset */\r
75         /** @req OS404 */\r
76         uint64                  offset;\r
77         // delta to next action\r
78 \r
79         //uint64                delta;\r
80 \r
81         /* List of events to activate */\r
82         const TaskType          *taskList;\r
83         uint8_t                 taskListCnt;\r
84 \r
85         /* List of events to activate */\r
86         const OsScheduleTableEventSettingType *eventList;\r
87         uint8_t                 eventListCnt;\r
88 } OsScheduleTableExpiryPointType;\r
89 \r
90 \r
91 #if ( OS_SC2 == STD_ON ) || ( OS_SC4 == STD_ON )\r
92 typedef struct OsScheduleTableSync {\r
93 \r
94 /* SPEC */\r
95         enum OsScheduleTableSyncStrategy syncStrategy;\r
96         // from spec. (only if syncStrategy==EXPLICIT )\r
97         int explicitPrecision;\r
98 \r
99 /* OWN */\r
100         // This counter is advanced by the driver counter but is synchronized\r
101         // by SyncScheduleTable()\r
102         GlobalTimeTickType syncCounter;\r
103 \r
104         // This is the deviation from the sync counter to the drive counter.\r
105         // (set by SyncScheduleTable())\r
106         // Calculated as 'driver count' - 'global time count from SyncScheduleTable()'\r
107         int deviation;\r
108 \r
109 } OsScheduleTableSyncType;\r
110 \r
111 \r
112 /* SPEC */\r
113 typedef struct OsSchTblAdjExpPoint {\r
114         uint8_t maxAdvance;\r
115         uint8_t maxRetard;\r
116 } OsSchTblAdjExpPointType;\r
117 #endif\r
118 \r
119 /* STD container: OsScheduleTableAutostart\r
120  * OsScheduleTableAbsValue              1    Int\r
121  * OsScheduleTableAutostartType     1    Enum\r
122  * OsScheduleTableRelOffset         1    Int\r
123  * OsScheduleTableAppModeRef            1..* Ref to OsAppMode\r
124  */\r
125 struct OsSchTblAutostart {\r
126         enum OsScheduleTableAutostartType type;\r
127         /* offset applies to both rel and abs */\r
128         TickType offset;\r
129         uint32_t appMode;       // TODO\r
130 };\r
131 \r
132 \r
133 /* STD container: OsScheduleTable\r
134  * OsScheduleTableDuration:             1    Int\r
135  * OsScheduleTableRepeating:            1        Bool\r
136  * OsSchTblAccessingApplication         0..* Ref\r
137  * OsScheduleTableCounterRef:           1        Ref\r
138  * OsScheduleTableAutostart[C]          0..1\r
139  * OsScheduleTableExpiryPoint[C]        1..*\r
140  * OsScheduleTableSync                          0..1\r
141  */\r
142 \r
143 typedef struct OsSchTbl {\r
144         /* OsScheduleTableDuration */\r
145         TickType duration;\r
146 \r
147         char *name;\r
148         /* If true, the schedule is periodic, OS009\r
149          * OsScheduleTableRepeating , 0 - SINGLE_SHOT */\r
150         /** @req OS413 */\r
151         _Bool repeating;\r
152 \r
153 #if defined(SC3) || defined(SC4)\r
154         uint32 accessingAppMask;\r
155 #endif\r
156 \r
157         // pointer to this tables counter\r
158         // OsScheduleTableCounterRef\r
159         /** @req OS409 */\r
160         struct OsCounter *counter;\r
161 \r
162         /* OsScheduleTableAutostart[C] */\r
163         const struct OsSchTblAutostart *autostartPtr;\r
164 \r
165         /* NULL if NONE, and non-NULL if EXPLICIT and IMPLICIT */\r
166         struct OsScheduleTableSync *sync;\r
167 \r
168 #if (OS_SC3 == STD_ON ) || (OS_SC4 == STD_ON )\r
169         uint32 app_mask;\r
170 #endif\r
171 \r
172 #if ( OS_SC2 == STD_ON ) || ( OS_SC4 == STD_ON )\r
173         struct OsSchTblAdjExpPoint adjExpPoint;\r
174 #endif\r
175 // RAM\r
176 \r
177         uint32 id;\r
178 \r
179         /* The current index into the expire list\r
180          * The value is updated at each expire point. */\r
181         int expire_curr_index;\r
182 \r
183         /* When this table expires the next time\r
184          * This value should be compared to the counter that drives\r
185          * the counter to check if it has expired.\r
186          * The value is updated at each expire point. */\r
187         TickType expire_val;\r
188 \r
189         ScheduleTableStatusType state;\r
190 \r
191         /* Pointer to next schedule table, if any\r
192          * (don't use normal lists here since we have no list head) */\r
193         struct OsSchTbl *next;\r
194 \r
195         /* Head of static expire point list\r
196          * OsScheduleTableExpiryPoint[C] */\r
197         SA_LIST_HEAD(alist,OsScheduleTableExpiryPoint) expirePointList;\r
198 \r
199         /* Entry in the list of schedule tables connected to a specific\r
200          * counter  */\r
201         SLIST_ENTRY(OsSchTbl) sched_list;\r
202 \r
203 } OsSchTblType;\r
204 \r
205 /*\r
206 #define os_stbl_get_action(x)           SA_LIST_GET(&(x)->expirePointList,(x)->expire_curr_index)\r
207 #define os_stbl_get_action_type(x) os_stbl_get_action(x)->type\r
208 #define os_stbl_get_action_offset(x) os_stbl_get_action(x)->offset\r
209 #define os_stbl_get_action_pid(x) os_stbl_get_action(x)->pid\r
210 #define os_stbl_get_action_event(x) os_stbl_get_action(x)->event\r
211 */\r
212 \r
213 void Os_SchTblInit( void );\r
214 void Os_SchTblAutostart( void );\r
215 void Os_SchTblCalcExpire( OsSchTblType *stbl );\r
216 void Os_SchTblCheck(OsCounterType *c_p);\r
217 void Os_SchTblAutostart( void );\r
218 \r
219 \r
220 static inline TickType Os_SchTblGetInitialOffset( OsSchTblType *sPtr ) {\r
221         return SA_LIST_GET(&sPtr->expirePointList,0)->offset;\r
222 }\r
223 \r
224 static inline TickType Os_SchTblGetFinalOffset( OsSchTblType *sPtr ) {\r
225         return (sPtr->duration -\r
226                         SA_LIST_GET(&sPtr->expirePointList, SA_LIST_CNT(&sPtr->expirePointList)-1)->offset);\r
227 }\r
228 \r
229 void Os_SchTblCheck(OsCounterType *c_p);\r
230 \r
231 \r
232 #endif /*SCHED_TABLE_I_H_*/\r