]> rtime.felk.cvut.cz Git - arc.git/blob - system/kernel/testsystem/config/Os_Cfg.c
Again, loads of refactoring and removing and adding files.
[arc.git] / system / kernel / testsystem / config / Os_Cfg.c
1 /* -------------------------------- Arctic Core ------------------------------
2  * Arctic Core - the open source AUTOSAR platform http://arccore.com
3  *
4  * Copyright (C) 2009  ArcCore AB <contact@arccore.com>
5  *
6  * This source code is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License version 2 as published by the
8  * Free Software Foundation; See <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
13  * for more details.
14  * -------------------------------- Arctic Core ------------------------------*/
15 \r
16 /*\r
17  * Configuration\r
18  * ------------------------------------------------\r
19  * 3 Tasks\r
20  *  - 3 extended ( do NOT terminate )\r
21  *  - 3 basic ( terminate )\r
22  *\r
23  * 2 Counters\r
24  *  - 1 system timer\r
25  *  - 1 soft( incremented with IncrementCounter(X) )\r
26  *\r
27  *\r
28  * 2 Alarms\r
29  *  - 1 hardware alarm\r
30  *  - 1 soft alarm\r
31  *    - Running on the soft counter above\r
32  *    - Triggers the basic task through ActivateTask() in alarm\r
33  *\r
34  * 2 ISRs\r
35  *  - 1 ISR type 1\r
36  *  - 1 ISR type, system counter\r
37  *\r
38  * 1 Schedule Table\r
39  *  - Running on the system timer\r
40  *  - Using 3 Tasks\r
41  *\r
42  *\r
43  *\r
44  * System timer\r
45  * ----------------------------------\r
46  * A system MUST have a system counter to function. This is almost\r
47  * always a hardware timer. So where is this timer configured?\r
48  *\r
49  * decrementer exception\r
50  * --> generate a prioritised interrupt through INTC soft interrupt\r
51  *\r
52  * Using the decrementer without generating the soft interrupt is not\r
53  * recommended since it's not prioritised( it's and exception that blocks\r
54  * interrupts from INTC )\r
55  *\r
56  * The timers are initialized in EcuM() using Gpt_Init(X). A StartupHook() must\r
57  * be used to start the timer. Example\r
58  *\r
59  *      Gpt_StartTimer( GPT_CHANNEL_DEC, 10000UL);\r
60  *      Gpt_EnableNotification(GPT_CHANNEL_DEC);\r
61  *\r
62  *                                  Note!\r
63  *       The counter configuration, e.g. timeout is not yet configured\r
64  *       through the counter in the configuration.\r
65  *\r
66  * ISR's\r
67  * ----------------------------------\r
68  * dec_exception ( From Mcu_Exception.S )\r
69  *  This exception installed HARD in the exception_tbl( Mcu_Exceptions )\r
70  *\r
71  *\r
72  * Note!\r
73  * - Do NOT use internal resource unless you are very sure that you to it right..\r
74  *\r
75  *\r
76  *
77  */\r
78 #define OS_CFG_API_VERSION 2
79 \r
80 #include <stdlib.h>\r
81 #include <stdint.h>\r
82 #include "os_config_macros.h"\r
83 #include "Platform_Types.h"\r
84 #include "Os.h"                         // includes Os_Cfg.h\r
85 #include "os_test.h"\r
86 #include "kernel.h"\r
87 #include "kernel_offset.h"\r
88 #include "alist_i.h"
89 #include "Mcu.h"
90
91 OsTickType OsTickFreq = 1000;\r
92 \r
93 extern void dec_exception( void );\r
94
95 #if ( OS_SC1 == STD_ON ) || ( OS_SC4 == STD_ON )
96 // atleast 1
97 #define SERVICE_CNT 1
98 \r
99 GEN_TRUSTEDFUNCTIONS_LIST\r
100 #endif
101 \r
102 \r
103 //-------------------------------------------------------------------\r
104
105 #if ( OS_SC1 == STD_ON ) || ( OS_SC4 == STD_ON )\r
106 GEN_APPLICATION_HEAD {\r
107         GEN_APPLICATON(0,"application_1",true,NULL,NULL,NULL , 0,0,0,0,0,0 )\r
108 };
109 #endif
110 \r
111 //-------------------------------------------------------------------\r
112 \r
113 #define ALIGN_16(x) (((x)>>4)<<4)\r
114 \r
115 //\r
116 uint8 stack_OsIdle[STACK_SIZE_OsIdle] SECTION_BSS_SUPER;\r
117 uint8 stack_etask_master[STACK_SIZE_etask_master] SECTION_BSS_SUPER;\r
118 uint8 stack_etask_sup_l[STACK_SIZE_etask_sup_l] SECTION_BSS_SUPER;\r
119 uint8 stack_etask_sup_m[STACK_SIZE_etask_sup_m] SECTION_BSS_SUPER;\r
120 uint8 stack_etask_sup_h[STACK_SIZE_etask_sup_h] SECTION_BSS_SUPER;\r
121 uint8 stack_btask_sup_l[STACK_SIZE_btask_sup_l] SECTION_BSS_SUPER;\r
122 uint8 stack_btask_sup_m[STACK_SIZE_btask_sup_m] SECTION_BSS_SUPER;\r
123 uint8 stack_btask_sup_h[STACK_SIZE_btask_sup_h] SECTION_BSS_SUPER;\r
124 \r
125 #define INTC_VECTOR_EXCEPTION_DEC               (320+10)\r
126 #define INTC_VECTOR_SSCIR0                              0\r
127 #define INTC_VECTOR_SSCIR7                              7\r
128 \r
129 //-------------------------------------------------------------------\r
130 \r
131 GEN_RESOURCE_HEAD {\r
132         GEN_RESOURCE(RES_SCHEDULER,RESOURCE_TYPE_STANDARD,0,0,0),               // Standard resource..\r
133 // Internal resources\r
134         GEN_RESOURCE(1,RESOURCE_TYPE_INTERNAL,8, APPLICATION_ID_application_1,(1<<TASK_ID_etask_sup_l)),\r
135 // external resource\r
136         GEN_RESOURCE(2,RESOURCE_TYPE_STANDARD,3,0,0),
137 // external resource
138         GEN_RESOURCE(3,RESOURCE_TYPE_STANDARD,4,0,0),
139 // external resource
140         GEN_RESOURCE(4,RESOURCE_TYPE_STANDARD,5,0,0),
141 \r
142 };\r
143 \r
144 //-------------------------------------------------------------------\r
145 \r
146 GEN_TASK_HEAD {\r
147 \r
148         GEN_ETASK(OsIdle,0,true/*auto*/, NULL/*tm*/, APPLICATION_ID_application_1/*app*/,NULL/*rsrc*/, FULL, 0 ),\r
149 \r
150 /* extended */\r
151         GEN_ETASK(etask_master,1,true/*auto*/, NULL/*tm*/, APPLICATION_ID_application_1/*app*/,NULL/*rsrc*/, NON, 0),\r
152 \r
153         GEN_ETASK(etask_sup_l,2,false/*auto*/, NULL/*tm*/, APPLICATION_ID_application_1/*app*/,NULL/*rsrc*/, FULL, 0 ),\r
154         GEN_ETASK(etask_sup_m,3,false/*auto*/, NULL/*tm*/, APPLICATION_ID_application_1/*app*/,NULL/*rsrc*/, FULL, 0 ),\r
155         GEN_ETASK(etask_sup_h,4,false/*auto*/, NULL/*tm*/, APPLICATION_ID_application_1/*app*/,NULL/*rsrc*/, FULL, 0 ),\r
156 \r
157 /* basic */\r
158         GEN_BTASK(btask_sup_l,2,false/*auto*/, NULL/*tm*/, APPLICATION_ID_application_1/*app*/,NULL/*rsrc*/, FULL, 0, 1 ),\r
159         GEN_BTASK(btask_sup_m,3,false/*auto*/, NULL/*tm*/, APPLICATION_ID_application_1/*app*/,NULL/*rsrc*/, FULL, 0, 1 ),\r
160         GEN_BTASK(btask_sup_h,4,false/*auto*/, NULL/*tm*/, APPLICATION_ID_application_1/*app*/,NULL/*rsrc*/, FULL, 0, 1 ),\r
161 \r
162         GEN_ISR_2(  TASK_ID_os_tick, "dec", OsTick, /*prio*/ 11, /*type*/ PROC_ISR2,  INTC_VECTOR_EXCEPTION_DEC , NULL, APPLICATION_ID_application_1),\r
163 #if 0\r
164         // Use the intc_vector tables for now\r
165         GEN_ISR_2(  TASK_ID_isr_dec, "dec", my_dec, /*prio*/ 11, /*type*/ PROC_ISR2,  INTC_VECTOR_EXCEPTION_DEC , NULL, APPLICATION_ID_application_1),\r
166         GEN_ISR_1(  TASK_ID_isr_soft7, "exception_sc", my_intc_soft7, /*prio*/ 12, INTC_VECTOR_SSCIR7 ),\r
167 #endif\r
168 };\r
169 \r
170 \r
171 GEN_PCB_LIST()\r
172 \r
173 //-------------------------------------------------------------------\r
174 typedef void (*exc_func_t)(uint32_t *);\r
175 \r
176 // Print all to stdout\r
177 uint32 os_dbg_mask = 0;\r
178 \r
179 #if 0\r
180 uint32 os_dbg_mask = \\r
181         D_MASTER_PRINT |\\r
182         D_ISR_MASTER_PRINT |\\r
183         D_STDOUT |\\r
184         D_ISR_STDOUT;\r
185 #endif\r
186 \r
187 \r
188 //      D_ALARM | D_TASK;\r
189 \r
190 // --- INTERRUPTS ---
191
192 uint8_t os_interrupt_stack[OS_INTERRUPT_STACK_SIZE] __attribute__ ((aligned (0x10)));
193
194 GEN_IRQ_VECTOR_TABLE_HEAD {};
195 GEN_IRQ_ISR_TYPE_TABLE_HEAD {};
196 GEN_IRQ_PRIORITY_TABLE_HEAD {};
197 \r
198 //-------------------------------------------------------------------\r
199 \r
200 // Generate as <type> <msg_name>_data\r
201 #if 0
202 #ifdef ALARM_USE\r
203 int MsgRx_1_data;\r
204 int MsgTx_1_data;\r
205 \r
206 OsMessageType message_list[] = {\r
207 {\r
208         .property = RECEIVE_UNQUEUED_INTERNAL,\r
209         .data = &MsgRx_1_data,\r
210         .data_size = sizeof(MsgRx_1_data),\r
211 \r
212 },\r
213 {\r
214         .property = SEND_STATIC_INTERNAL,\r
215         .data = &MsgTx_1_data,\r
216         .data_size = sizeof(MsgTx_1_data),\r
217 },\r
218 };\r
219 #endif\r
220 \r
221 \r
222 #if 0\r
223 #define MESSAGE_CLASS(_name,_ctype ,_property,_queued ,_notification) \\r
224         struct message ## _name ## _s { \\r
225                 _ctype a;                               \\r
226         };\r
227 \r
228 MESSAGE_CLASS(rx1,int,,,);\r
229 #endif\r
230 #endif
231 \r
232 /*\r
233 typedef struct {\r
234         message_type_t type;            // RECEIVE_UNQUEUED_INTERNAL, RECEIVE_QUEUE_INTERNAL\r
235         MessageType send_id;\r
236         OsMessageNotificationType *notification;\r
237         void *queue_data;\r
238         uint32  queue_size;\r
239 } message_rx_t;\r
240 \r
241 #define DeclareMessage(x)               (x)\r
242 \r
243 #define msgTx_1                 0\r
244 #define msgRx_1                 1\r
245 */\r
246 \r
247 //-------------------------------------------------------------------\r
248 #if MESSAGE_USE!=0\r
249 \r
250 \r
251 //  SEND_STATIC_INTERNAL is the only message that needs an object\r
252 \r
253 \r
254 \r
255 // RECEIVE_UNQUEUED_INTERNAL, RECEIVE_QUEUE_INTERNAL have notification and\r
256 \r
257 \r
258 \r
259 #endif\r
260 //-------------------------------------------------------------------\r
261 \r
262 //#define COUNTER_SOFT_1                1\r
263 //#define EVENT_1                               1\r
264 \r
265 \r
266 GEN_COUNTER_HEAD {\r
267         GEN_COUNTER(COUNTER_ID_os_tick, "COUNTER_ID_OsTick",COUNTER_TYPE_HARD,\r
268                                 COUNTER_UNIT_NANO, 0xffff,1,1,0 ),\r
269         GEN_COUNTER(COUNTER_ID_soft_1,  "counter_soft_1",COUNTER_TYPE_SOFT,\r
270                                 COUNTER_UNIT_NANO, 10,1,1,0),\r
271         GEN_COUNTER(COUNTER_ID_soft_2,  "counter_soft_2",COUNTER_TYPE_SOFT,\r
272                                 COUNTER_UNIT_NANO, 100,1,1,0),\r
273 };\r
274
275 CounterType Os_Arc_OsTickCounter = COUNTER_ID_OsTick;
276 \r
277 //-------------------------------------------------------------------\r
278 \r
279 #ifdef ALARM_USE\r
280 GEN_ALARM_HEAD {\r
281         {\r
282                 .counter = &counter_list[COUNTER_ID_OsTick],\r
283                 .counter_id = COUNTER_ID_OsTick,\r
284                 .action =\r
285                 {\r
286                                 .type = ALARM_ACTION_ACTIVATETASK,\r
287                                 .task_id = TASK_ID_btask_sup_h,\r
288                                 .event_id = 0,\r
289                 }\r
290         },\r
291                 {\r
292                 /* Set EVENT_1 in etask_sup_m, driven by soft counter */\r
293                 .counter = &counter_list[COUNTER_ID_OsTick],\r
294                 .counter_id = COUNTER_ID_OsTick,\r
295                 .action = {\r
296                                 .type = ALARM_ACTION_SETEVENT,\r
297                                 .task_id = TASK_ID_etask_sup_m,\r
298                                 .event_id = EVENT_1,\r
299                 }\r
300         },{\r
301                 /* Set EVENT_1 in etask_sup_m, driven by counter_soft_1 */\r
302                 .counter = &counter_list[COUNTER_ID_soft_1],\r
303                 .counter_id = COUNTER_ID_soft_1,\r
304                 .action = {\r
305                         .type = ALARM_ACTION_SETEVENT,\r
306                         .task_id = TASK_ID_etask_sup_m,\r
307                         .event_id = EVENT_1,\r
308                 }\r
309         },{\r
310                 .counter = &counter_list[COUNTER_ID_soft_1],\r
311                 .counter_id = COUNTER_ID_soft_1,\r
312                 .action = {\r
313                         .type = ALARM_ACTION_INCREMENTCOUNTER,\r
314                         .counter_id = COUNTER_ID_soft_2,\r
315                 }\r
316         }\r
317 };\r
318 #endif\r
319 \r
320 //-------------------------------------------------------------------\r
321 \r
322 \r
323 #if defined(SCHEDULETABLE_USE)\r
324 \r
325 \r
326 OsScheduleTableActionType sched_expire_list_0[] = {\r
327         {\r
328                 .type = SCHEDULE_ACTION_ACTIVATETASK,\r
329                 .offset = 5,\r
330                 .task_id = TASK_ID_etask_sup_m,\r
331         },{\r
332                 .type = SCHEDULE_ACTION_SETEVENT,\r
333                 .offset = 7,\r
334                 .task_id = TASK_ID_etask_sup_m,\r
335                 .event_id = EVENT_2,\r
336         }\r
337 };\r
338 \r
339 \r
340 OsScheduleTableActionType sched_expire_list_1[] = {\r
341         {\r
342                 .type = SCHEDULE_ACTION_ACTIVATETASK,\r
343                 .offset = 2,\r
344                 .task_id = TASK_ID_etask_sup_m,\r
345         }\r
346 };\r
347 \r
348 \r
349 GEN_SCHEDULETABLE_HEAD {\r
350         GEN_SCHEDULETABLE(\r
351                         0,                                              // id\r
352                         "stable0",                              // name\r
353                     COUNTER_ID_soft_2,          // counter\r
354                     REPEATING,                          // periodic
355                         SCHEDULETABLE_DURATION_1,       // duration\r
356                         0,                                              // app_mask\r
357                         ARRAY_SIZE(sched_expire_list_0),                                // action count\r
358                         sched_expire_list_0,    // expire ref\r
359                         0,0,0,0,                                // autostart\r
360                         NONE,0,                                 // sync\r
361                         0,0                                     // adjExpPoint\r
362                         ),\r
363 \r
364         GEN_SCHEDULETABLE(\r
365                         1,                                              // id\r
366                         "stable1",                              // name\r
367                         COUNTER_ID_soft_2,              // counter\r
368                         REPEATING,                              // periodic\r
369                         SCHEDULETABLE_DURATION_2,       // duration\r
370                         0,                                              // app_mask\r
371                         ARRAY_SIZE(sched_expire_list_1),                                // action count\r
372                         sched_expire_list_1,    // expire ref\r
373                         0,0,0,0,                                // autostart\r
374                         NONE,0,                                 // sync\r
375                         0,0                                     // adjExpPoint\r
376                         ),\r
377 };\r
378 \r
379 #endif\r
380 \r
381 \r
382 // --- HOOKS ---\r
383 \r
384 struct OsHooks os_conf_global_hooks = {\r
385                 .StartupHook = StartupHook,
386 #if (  OS_SC2 == STD_ON ) || ( OS_SC1 == STD_ON ) || ( OS_SC4 == STD_ON )\r
387                 .ProtectionHook = ProtectionHook,
388 #endif\r
389                 .ShutdownHook = ShutdownHook,\r
390                 .ErrorHook = ErrorHook,\r
391                 .PreTaskHook = PreTaskHook,\r
392                 .PostTaskHook = PostTaskHook,\r
393 };\r
394 \r
395 \r
396 #include "os_config_funcs.h"\r