1 /* -------------------------------- Arctic Core ------------------------------
2 * Arctic Core - the open source AUTOSAR platform http://arccore.com
4 * Copyright (C) 2009 ArcCore AB <contact@arccore.com>
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>.
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
14 * -------------------------------- Arctic Core ------------------------------*/
21 #define OS_SW_MAJOR_VERSION 2
22 #define OS_SW_MINOR_VERSION 0
23 #define OS_SW_PATCH_VERSION 0
\r
26 #include "Std_Types.h"
\r
31 typedef uint32_t EventMaskType;
\r
32 typedef EventMaskType * EventMaskRefType;
\r
33 typedef uint16_t TaskType;
\r
34 typedef TaskType * TaskRefType;
\r
39 TASK_STATE_SUSPENDED,
\r
44 typedef TaskStateType *TaskStateRefType;
\r
46 /* FIXME: OSMEMORY_IS__ , see 8.2*/
\r
48 #define OSDEFAULTAPPMODE 1
\r
50 #define INVALID_OSAPPLICATION (-1)
\r
52 /* TODO, I have no idea what this should be*/
\r
53 typedef sint32 ApplicationType;
\r
55 /* See oil config for defines */
\r
56 typedef sint32 AppModeType;
\r
58 /* FIXME: more types here */
\r
59 typedef uint16 ScheduleTableType;
\r
60 typedef uint16 GlobalTimeTickType;
\r
63 SCHEDULETABLE_STOPPED,
\r
65 SCHEDULETABLE_WAITING,
\r
66 SCHEDULETABLE_RUNNING,
\r
67 SCHEDULETABLE_RUNNING_AND_SYNCHRONOUS
\r
68 } ScheduleTableStatusType;
\r
70 typedef ScheduleTableStatusType *ScheduleTableStatusRefType;
\r
72 /* Flags for AccessType */
\r
73 #define ACCESSTYPE_W 1
\r
74 #define ACCESSTYPE_R (1<<1)
\r
76 typedef uint32 AccessType;
\r
89 OBJECT_SCHEDULETABLE,
\r
96 PRO_KILLAPPL_RESTART,
\r
98 } ProtectionReturnType;
\r
106 typedef ProtectionReturnType (*ProtectionHookType)( StatusType);
\r
107 typedef void (*StartupHookType)( void );
\r
108 typedef void (*ShutdownHookType)( StatusType );
\r
109 typedef void (*ErrorHookType)( StatusType );
\r
110 typedef void (*PreTaskHookType)( void );
\r
111 typedef void (*PostTaskHookType)( void );
\r
113 ProtectionReturnType ProtectionHook( StatusType FatalError );
\r
114 void StartupHook( void );
\r
115 void ShutdownHook( StatusType Error );
\r
116 void ErrorHook( StatusType Error );
\r
117 void PreTaskHook( void );
\r
118 void PostTaskHook( void );
\r
120 typedef uint16 TrustedFunctionIndexType;
\r
121 typedef void * TrustedFunctionParameterRefType;
\r
124 #define INVALID_ISR ((sint16)(-1))
\r
125 typedef sint16 ISRType;
\r
127 typedef void * MemoryStartAddressType;
\r
128 typedef uint32 MemorySizeType;
\r
131 #define WaitEvent(...) SC_CALL(WaitEvent,1,1,__VA_ARGS__)
\r
132 #define SetEvent(...) SC_CALL(SetEvent,2,2,__VA_ARGS__)
\r
133 #define ClearEvent(...) SC_CALL(ClearEvent,3,1,__VA_ARGS__)
\r
135 StatusType WaitEvent( EventMaskType Mask );
\r
136 StatusType SetEvent( TaskType TaskID, EventMaskType Mask );
\r
137 StatusType ClearEvent( EventMaskType Mask);
\r
138 StatusType GetEvent( TaskType TaskId, EventMaskRefType Mask);
\r
141 void StartOS( AppModeType Mode );
145 ApplicationType GetApplicationID( void );
\r
146 ISRType GetISRID( void );
\r
148 typedef int8_t Os_IntCounterType;
150 /* requirements here: OS368(ISR2), OS092 */
152 extern Os_IntCounterType Os_IntDisableAllCnt;
153 extern Os_IntCounterType Os_IntSuspendAllCnt;
154 extern Os_IntCounterType Os_IntSuspendOsCnt;
159 /* OSEK: States that " service does not support nesting", but says
160 * nothing what to do about it.
162 * OS092: " If EnableAllInterrupts()/ResumeAllInterrupts()/ResumeOSInterrupts()
163 * are called and no corresponding DisableAllInterupts()/SuspendAllInterrupts()/
164 * SuspendOSInterrupts() was done before, the Operating System shall not
165 * perform this OS service.
167 static inline void DisableAllInterrupts( void ) {
169 Os_IntDisableAllCnt++;
170 /* No nesting allowed */
171 assert(Os_IntDisableAllCnt>1);
174 static inline void EnableAllInterrupts( void ) {
176 if(Os_IntDisableAllCnt==0) {
177 /** @req OS092 EnableAllInterrupts */
179 Os_IntDisableAllCnt--;
184 static inline void SuspendAllInterrupts( void ) {
186 Os_IntSuspendAllCnt++;
189 static inline void ResumeAllInterrupts( void ) {
191 if(Os_IntSuspendAllCnt==0) {
192 /** @req OS092 ResumeAllInterrupts */
194 Os_IntSuspendAllCnt--;
199 /* Only ISR2 interrupts should be suspended but this can NEVER be
200 * done in a more efficient way than to disable all, so let's
201 * do that for all targets.
204 static inline void SuspendOSInterrupts( void ) {
206 Os_IntSuspendOsCnt++;
209 static inline void ResumeOSInterrupts( void ) {
211 if(Os_IntSuspendOsCnt==0) {
212 /** @req OS092 ResumeOSInterrupts */
214 Os_IntSuspendOsCnt--;
220 * Class 2,3 and 4 API
222 ApplicationType GetApplicationID( void );
\r
223 AccessType CheckISRMemoryAccess( ISRType ISRID,
\r
224 MemoryStartAddressType Address,
\r
225 MemorySizeType Size );
\r
227 AccessType CheckTaskMemoryAccess( TaskType TaskID,
\r
228 MemoryStartAddressType Address,
\r
229 MemorySizeType Size );
231 StatusType CallTrustedFunction( TrustedFunctionIndexType FunctionIndex,
\r
232 TrustedFunctionParameterRefType FunctionParams );
\r
234 StatusType GetTaskID( TaskRefType TaskID );
\r
235 StatusType GetTaskState( TaskType task_id, TaskStateRefType state);
\r
237 void ShutdownOS( StatusType );
\r
238 StatusType ActivateTask( TaskType TaskID );
\r
239 StatusType TerminateTask( void );
\r
240 StatusType ChainTask( TaskType TaskID );
\r
241 StatusType Schedule( void );
\r
243 typedef uint32 ResourceType;
\r
244 #define DeclareResource(x) extern ResourceType (x);
\r
245 StatusType GetResource( ResourceType ResID );
\r
246 StatusType ReleaseResource( ResourceType ResID);
\r
249 * Define the scheduler resource as 0
251 #define RES_SCHEDULER ~(ResourceType)0
\r
254 * Priorities of tasks and resources
256 #define OS_TASK_PRIORITY_MIN 0
257 #define OS_TASK_PRIORITY_MAX 31
258 /* Logical priority is higher higher than normal tasks */
259 #define OS_RES_SCHEDULER_PRIO 32
\r
261 typedef struct OsDriver_s {
\r
262 int OsGptChannelRef;
\r
265 /*-------------------------------------------------------------------
\r
266 * Free running timer
\r
267 *-----------------------------------------------------------------*/
268 typedef const uint32 OsTickType;
269 void Os_SysTickInit( void );
\r
270 void Os_SysTickStart(uint32_t period_ticks);
\r
271 uint32_t Os_SysTickGetTimeElapsed( void );
\r
273 /*-------------------------------------------------------------------
\r
275 *-----------------------------------------------------------------*/
\r
276 typedef sint16 CounterType;
278 typedef uint32 TickType;
\r
279 typedef TickType *TickRefType;
\r
281 StatusType IncrementCounter( CounterType );
\r
282 StatusType GetCounterValue( CounterType, TickRefType );
\r
283 StatusType GetElapsedCounterValue( CounterType, TickRefType val, TickRefType elapsed_val);
\r
285 /*-------------------------------------------------------------------
\r
287 *-----------------------------------------------------------------*/
\r
289 StatusType StartScheduleTableRel(ScheduleTableType sid, TickType offset);
\r
290 StatusType StartScheduleTableAbs(ScheduleTableType sid, TickType val );
\r
291 StatusType StartScheduleTableSynchron(ScheduleTableType sid );
\r
292 StatusType StopScheduleTable(ScheduleTableType sid);
\r
293 StatusType NextScheduleTable( ScheduleTableType sid_curr, ScheduleTableType sid_next);
\r
294 StatusType SyncScheduleTable( ScheduleTableType sid, GlobalTimeTickType global_time );
\r
295 StatusType GetScheduleTableStatus( ScheduleTableType sid, ScheduleTableStatusRefType status );
\r
296 StatusType SetScheduleTableAsync( ScheduleTableType sid );
\r
299 /*-------------------------------------------------------------------
\r
301 *-----------------------------------------------------------------*/
\r
303 typedef uint16 AlarmType;
\r
306 TickType maxallowedvalue;
\r
307 TickType tickperbase;
\r
311 typedef AlarmBaseType *AlarmBaseRefType;
\r
313 StatusType GetAlarmBase( AlarmType AlarmId, AlarmBaseRefType Info );
\r
314 StatusType GetAlarm(AlarmType AlarmId, TickRefType Tick);
\r
315 StatusType SetRelAlarm(AlarmType AlarmId, TickType Increment, TickType Cycle);
\r
316 StatusType SetAbsAlarm(AlarmType AlarmId, TickType Start, TickType Cycle);
\r
317 StatusType CancelAlarm(AlarmType AlarmId);
\r
320 /*-------------------------------------------------------------------
\r
322 *-----------------------------------------------------------------*/
\r
324 OSServiceId_ActivateTask,
\r
325 OSServiceId_TerminateTask,
\r
326 OSServiceId_ChainTask,
\r
327 OSServiceId_Schedule,
\r
328 OSServiceId_GetTaskID,
\r
329 OSServiceId_GetResource,
\r
330 OSServiceId_ReleaseResource,
\r
331 OSServiceId_SetEvent,
\r
332 OSServiceId_ClearEvent,
\r
333 OSServiceId_GetEvent,
\r
334 OSServiceId_WaitEvent,
\r
335 OSServiceId_GetAlarmBase,
\r
336 OSServiceId_GetAlarm,
\r
337 OSServiceId_SetRelAlarm,
\r
338 OSServiceId_SetAbsAlarm,
\r
339 OSServiceId_CancelAlarm,
\r
340 OSServiceId_StartOS,
\r
341 OSServiceId_ShutdownOS,
\r
342 OSServiceId_ErrorHook,
\r
343 OSServiceId_PreTaskHook,
\r
344 OSServiceId_PostTaskHook,
\r
345 OSServiceId_StartupHook,
\r
346 OSServiceId_ShutdownHook,
\r
347 OSServiceId_GetTaskState,
\r
348 } OsServiceIdType;;
\r
350 typedef struct os_error_s {
\r
351 OsServiceIdType serviceId;
\r
357 extern os_error_t os_error;
\r
359 // TODO: Add the service id to all OS service methods.
\r
360 static inline OsServiceIdType OSErrorGetServiceId(void) {
\r
361 return os_error.serviceId;
\r
364 extern os_error_t os_error;
\r
366 #define OSError_ActivateTask_TaskID ((TaskType) os_error.param1)
\r
367 #define OSError_ChainTask_TaskID ((TaskType) os_error.param1)
\r
368 #define OSError_GetTaskID_TaskID ((TaskRefType) os_error.param1)
\r
369 #define OSError_GetResource_ResID ((ResourceType) os_error.param1)
\r
370 #define OSError_ReleaseResource_ResID ((ResourceType) os_error.param1)
\r
371 #define OSError_SetEvent_TaskID ((TaskType) os_error.param1)
\r
372 #define OSError_SetEvent_Mask ((EventMaskType) os_error.param2)
\r
373 #define OSError_ClearEvent_Mask ((EventMaskType) os_error.param1)
\r
374 #define OSError_GetEvent_TaskId ((TaskType) os_error.param1)
\r
375 #define OSError_GetEvent_Mask ((EventMaskRefType) os_error.param2)
\r
376 #define OSError_WaitEvent_Mask ((EventMaskType) os_error.param1)
\r
377 #define OSError_GetAlarmBase_AlarmId ((AlarmType) os_error.param1)
\r
378 #define OSError_GetAlarmBase_Info ((AlarmBaseRefType) os_error.param2)
\r
379 #define OSError_GetAlarm_AlarmId ((AlarmType) os_error.param1)
\r
380 #define OSError_GetAlarm_Tick ((TickRefType) os_error.param2)
\r
381 #define OSError_SetRelAlarm_AlarmId ((AlarmType) os_error.param1)
\r
382 #define OSError_SetRelAlarm_Increment ((TickType) os_error.param2)
\r
383 #define OSError_SetRelAlarm_Cycle ((TickType) os_error.param3)
\r
384 #define OSError_SetAbsAlarm_AlarmId ((AlarmType) os_error.param1)
\r
385 #define OSError_SetAbsAlarm_Start ((TickType) os_error.param2)
\r
386 #define OSError_SetAbsAlarm_Cycle ((TickType) os_error.param3)
\r
387 #define OSError_CancelAlarm_AlarmId ((AlarmType) os_error.param1)
\r
388 #define OSError_StartOS_Mode ((AppModeType) os_error.param1)
\r
389 #define OSError_ErrorHook_Error ((StatusType) os_error.param1)
\r
390 #define OSError_ShutdownHook_Error ((StatusType) os_error.param1)
\r
391 #define OSError_GetTaskState_TaskId ((TaskType) os_error.param1)
\r
392 #define OSError_GetTaskState_State ((TaskStateRefType) os_error.param2)
\r
395 #if defined(LOCALMESSAGESONLY)
396 #error LOCALMESSAGESONLY shall not be defined
400 /*-------------------------------------------------------------------
\r
401 * COM ( TODO : move )
\r
402 *-----------------------------------------------------------------*/
\r
405 * The only information about the COM that is valid is
\r
406 * in the COM specification ..SWS_COM.pdf.
\r
408 * The most important requirements are COM010 and COM013
\r
414 * No. GetMessageStatus()
\r
415 * No. SendZeroMessage()
\r
416 * No. SendDynamicMessage(), RecieveDynamicMessage()
\r
418 * Yes. SendMessage()
\r
423 typedef uint32 MessageType;
\r
424 typedef void *ApplicationDataRef;
\r
427 StatusType SendMessage( MessageType message_id, ApplicationDataRef dataRef );
\r
428 StatusType ReceiveMessage( MessageType message_id, ApplicationDataRef dataRef );
\r
431 * ArcCore extensions
\r
433 TickType GetOsTick();
\r
437 #define OS_ISR_TYPE2 0
\r
438 #define OS_ISR_TYPE1 1
\r
442 void (*entry)(void);
\r
447 #define TTY_WINIDEA 4