1 /* -------------------------------- Arctic Core ------------------------------
\r
2 * Arctic Core - the open source AUTOSAR platform http://arccore.com
\r
4 * Copyright (C) 2009 ArcCore AB <contact@arccore.com>
\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
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
14 * -------------------------------- Arctic Core ------------------------------*/
\r
21 #define OS_SW_MAJOR_VERSION 2
\r
22 #define OS_SW_MINOR_VERSION 0
\r
23 #define OS_SW_PATCH_VERSION 0
\r
26 #include "Std_Types.h"
\r
31 #include <sys/queue.h>
\r
33 typedef uint8 StatusType;
\r
35 #define E_OS_ACCESS (StatusType)1 /**< STD OSEK */
\r
36 #define E_OS_CALLEVEL (StatusType)2 /**< STD OSEK */
\r
37 #define E_OS_ID (StatusType)3 /**< STD OSEK */
\r
38 #define E_OS_LIMIT (StatusType)4 /**< STD OSEK */
\r
39 #define E_OS_NOFUNC (StatusType)5 /**< STD OSEK */
\r
40 #define E_OS_RESOURCE (StatusType)6 /**< STD OSEK */
\r
41 #define E_OS_STATE (StatusType)7 /**< STD OSEK */
\r
42 #define E_OS_VALUE (StatusType)8 /**< STD OSEK */
\r
44 #define E_OS_SERVICEID (StatusType)9 /**< AUTOSAR, see 7.10 */
\r
45 #define E_OS_RATE (StatusType)10 /**< AUTOSAR, see 7.10 */
\r
46 #define E_OS_ILLEGAL_ADDRESS (StatusType)11 /**< AUTOSAR, see 7.10 */
\r
47 #define E_OS_MISSINGEND (StatusType)12 /**< AUTOSAR, see 7.10 */
\r
48 #define E_OS_DISABLEDINT (StatusType)13 /**< AUTOSAR, see 7.10 */
\r
49 #define E_OS_STACKFAULT (StatusType)14 /**< AUTOSAR, see 7.10 */
\r
50 #define E_OS_PROTECTION_MEMORY (StatusType)15 /**< AUTOSAR, see 7.10 */
\r
51 #define E_OS_PROTECTION_TIME (StatusType)16 /**< AUTOSAR, see 7.10 */
\r
52 #define E_OS_PROTECTION_LOCKED (StatusType)17 /**< AUTOSAR, see 7.10 */
\r
53 #define E_OS_PROTECTION_EXCEPTION (StatusType)18 /**< AUTOSAR, see 7.10 */
\r
54 #define E_OS_PROTECTION_RATE (StatusType)19 /**< AUTOSAR, see 7.10 */
\r
56 #define E_COM_ID 255 // TODO: var ska E_COM_ID vara?"
\r
59 typedef uint32_t EventMaskType;
\r
60 typedef EventMaskType * EventMaskRefType;
\r
61 typedef uint16_t TaskType;
\r
62 typedef TaskType * TaskRefType;
\r
67 TASK_STATE_SUSPENDED,
\r
71 #define INVALID_TASK 0xdeadU
\r
73 typedef TaskStateType *TaskStateRefType;
\r
75 /* FIXME: OSMEMORY_IS__ , see 8.2*/
\r
77 #define OSMEMORY_IS_READABLE(_access)
\r
78 #define OSMEMORY_IS_WRITEABLE(_access)
\r
79 #define OSMEMORY_IS_EXECUTABLE(_access)
\r
80 #define OSMEMORY_IS_STACKSPACE(_access)
\r
82 #define OSDEFAULTAPPMODE 1
\r
84 #define INVALID_OSAPPLICATION (-1)
\r
86 /* TODO, I have no idea what this should be*/
\r
87 #if (OS_USE_APPLICATIONS == STD_ON)
\r
88 typedef sint32 ApplicationType;
\r
91 APPLICATION_ACCESSIBLE,
\r
92 APPLICATION_RESTARTING,
\r
93 APPLICATION_TERMINATED
\r
94 } ApplicationStateType;
\r
96 typedef ApplicationStateType *ApplicationStateRefType;
\r
99 /* See oil config for defines */
\r
100 typedef sint32 AppModeType;
\r
102 /* FIXME: more types here */
\r
103 typedef uint16 ScheduleTableType;
\r
104 typedef uint16 GlobalTimeTickType;
\r
107 SCHEDULETABLE_STOPPED,
\r
108 SCHEDULETABLE_NEXT,
\r
109 SCHEDULETABLE_WAITING,
\r
110 SCHEDULETABLE_RUNNING,
\r
111 SCHEDULETABLE_RUNNING_AND_SYNCHRONOUS
\r
112 } ScheduleTableStatusType;
\r
114 typedef ScheduleTableStatusType *ScheduleTableStatusRefType;
\r
116 /* Flags for AccessType */
\r
117 #define ACCESSTYPE_W 1
\r
118 #define ACCESSTYPE_R (1<<1)
\r
120 typedef uint32 AccessType;
\r
125 } ObjectAccessType;
\r
133 OBJECT_SCHEDULETABLE,
\r
140 PRO_KILLAPPL_RESTART,
\r
142 } ProtectionReturnType;
\r
150 typedef ProtectionReturnType (*ProtectionHookType)( StatusType);
\r
151 typedef void (*StartupHookType)( void );
\r
152 typedef void (*ShutdownHookType)( StatusType );
\r
153 typedef void (*ErrorHookType)( StatusType );
\r
154 typedef void (*PreTaskHookType)( void );
\r
155 typedef void (*PostTaskHookType)( void );
\r
157 ProtectionReturnType ProtectionHook( StatusType FatalError );
\r
158 void StartupHook( void );
\r
159 void ShutdownHook( StatusType Error );
\r
160 void ErrorHook( StatusType Error );
\r
161 void PreTaskHook( void );
\r
162 void PostTaskHook( void );
\r
164 typedef uint16 TrustedFunctionIndexType;
\r
165 typedef void * TrustedFunctionParameterRefType;
\r
168 #define INVALID_ISR ((sint16)(-1))
\r
169 typedef sint16 ISRType;
\r
171 #define APP_NO_OWNER (-1UL)
\r
173 typedef void * MemoryStartAddressType;
\r
174 typedef uint32 MemorySizeType;
\r
177 #define WaitEvent(...) SC_CALL(WaitEvent,1,1,__VA_ARGS__)
\r
178 #define SetEvent(...) SC_CALL(SetEvent,2,2,__VA_ARGS__)
\r
179 #define ClearEvent(...) SC_CALL(ClearEvent,3,1,__VA_ARGS__)
\r
181 StatusType WaitEvent( EventMaskType Mask );
\r
182 StatusType SetEvent( TaskType TaskID, EventMaskType Mask );
\r
183 StatusType ClearEvent( EventMaskType Mask);
\r
184 StatusType GetEvent( TaskType TaskId, EventMaskRefType Mask);
\r
186 void InitOS( void );
\r
187 void StartOS( AppModeType Mode );
\r
189 ISRType GetISRID( void );
\r
190 StatusType GetActiveApplicationMode( AppModeType* mode);
\r
192 typedef int8_t Os_IntCounterType;
\r
194 /* requirements here: OS368(ISR2), OS092 */
\r
196 extern Os_IntCounterType Os_IntDisableAllCnt;
\r
197 extern Os_IntCounterType Os_IntSuspendAllCnt;
\r
198 extern Os_IntCounterType Os_IntSuspendOsCnt;
\r
203 /* OSEK: States that " service does not support nesting", but says
\r
204 * nothing what to do about it.
\r
206 * OS092: " If EnableAllInterrupts()/ResumeAllInterrupts()/ResumeOSInterrupts()
\r
207 * are called and no corresponding DisableAllInterupts()/SuspendAllInterrupts()/
\r
208 * SuspendOSInterrupts() was done before, the Operating System shall not
\r
209 * perform this OS service.
\r
211 static inline void DisableAllInterrupts( void ) {
\r
213 Os_IntDisableAllCnt++;
\r
214 /* No nesting allowed */
\r
215 assert(Os_IntDisableAllCnt==1);
\r
218 static inline void EnableAllInterrupts( void ) {
\r
220 if(Os_IntDisableAllCnt==0) {
\r
221 /** @req OS092 EnableAllInterrupts */
\r
223 Os_IntDisableAllCnt--;
\r
228 static inline void SuspendAllInterrupts( void ) {
\r
230 Os_IntSuspendAllCnt++;
\r
233 static inline void ResumeAllInterrupts( void ) {
\r
235 if(Os_IntSuspendAllCnt==0) {
\r
236 /** @req OS092 ResumeAllInterrupts */
\r
238 Os_IntSuspendAllCnt--;
\r
243 /* Only ISR2 interrupts should be suspended but this can NEVER be
\r
244 * done in a more efficient way than to disable all, so let's
\r
245 * do that for all targets.
\r
248 static inline void SuspendOSInterrupts( void ) {
\r
250 Os_IntSuspendOsCnt++;
\r
253 static inline void ResumeOSInterrupts( void ) {
\r
255 if(Os_IntSuspendOsCnt==0) {
\r
256 /** @req OS092 ResumeOSInterrupts */
\r
258 Os_IntSuspendOsCnt--;
\r
264 * Class 2,3 and 4 API
\r
267 #if (OS_USE_APPLICATIONS == STD_ON)
\r
269 ApplicationType GetApplicationID( void );
\r
270 AccessType CheckISRMemoryAccess( ISRType ISRID,
\r
271 MemoryStartAddressType Address,
\r
272 MemorySizeType Size );
\r
274 AccessType CheckTaskMemoryAccess( TaskType TaskID,
\r
275 MemoryStartAddressType Address,
\r
276 MemorySizeType Size );
\r
278 ObjectAccessType CheckObjectAccess( ApplicationType ApplId,
\r
279 ObjectTypeType ObjectType,
\r
280 uint32_t objectId );
\r
281 ApplicationType CheckObjectOwnership( ObjectTypeType ObjectType,
\r
282 uint32_t objectId );
\r
283 StatusType TerminateApplication( ApplicationType Application, RestartType RestartOption );
\r
284 StatusType AllowAccess( void );
\r
285 StatusType GetApplicationState( ApplicationType Application, ApplicationStateRefType Value );
\r
286 StatusType CallTrustedFunction( TrustedFunctionIndexType FunctionIndex,
\r
287 TrustedFunctionParameterRefType FunctionParams );
\r
290 StatusType GetTaskID( TaskRefType TaskID );
\r
291 StatusType GetTaskState( TaskType task_id, TaskStateRefType state);
\r
293 void ShutdownOS( StatusType );
\r
294 StatusType ActivateTask( TaskType TaskID );
\r
295 StatusType TerminateTask( void );
\r
296 StatusType ChainTask( TaskType TaskID );
\r
297 StatusType Schedule( void );
\r
299 typedef uint8 ResourceType;
\r
300 #define DeclareResource(x) extern ResourceType (x);
\r
301 StatusType GetResource( ResourceType ResID );
\r
302 StatusType ReleaseResource( ResourceType ResID);
\r
305 * Define scheduler as topmost
\r
307 #define RES_SCHEDULER OS_RESOURCE_CNT
\r
310 * Priorities of tasks and resources
\r
312 #define OS_TASK_PRIORITY_MIN 0
\r
313 #define OS_TASK_PRIORITY_MAX 31
\r
314 /* Logical priority is higher higher than normal tasks */
\r
315 #define OS_RES_SCHEDULER_PRIO 32
\r
317 typedef struct OsDriver_s {
\r
318 int OsGptChannelRef;
\r
323 /*-------------------------------------------------------------------
\r
325 *-----------------------------------------------------------------*/
\r
326 typedef sint16 CounterType;
\r
328 typedef uint32 TickType;
\r
329 typedef TickType *TickRefType;
\r
331 StatusType IncrementCounter( CounterType );
\r
332 StatusType GetCounterValue( CounterType, TickRefType );
\r
333 StatusType GetElapsedCounterValue( CounterType, TickRefType val, TickRefType elapsed_val);
\r
336 /*-------------------------------------------------------------------
\r
338 *-----------------------------------------------------------------*/
\r
339 typedef const uint32 OsTickType;
\r
340 void Os_SysTickInit( void );
\r
341 void Os_SysTickStart(TickType period_ticks);
\r
342 TickType Os_SysTickGetValue( void );
\r
343 TickType Os_SysTickGetElapsedValue( TickType preValue );
\r
345 /*-------------------------------------------------------------------
\r
347 *-----------------------------------------------------------------*/
\r
349 #if defined(USE_KERNEL_EXTRA)
\r
351 #define TICK_MAX UINT_MAX
\r
353 typedef struct OsSemaphore {
\r
355 STAILQ_HEAD(,OsTaskVar) taskHead;
\r
358 typedef OsSemaphoreType OsMutexType;
\r
360 StatusType Sleep( TickType ticks );
\r
361 StatusType InitSemaphore( OsSemaphoreType *semPtr, int initialCount );
\r
362 StatusType WaitSemaphore( OsSemaphoreType *semPtr, TickType tmo );
\r
363 void SignalSemaphore( OsSemaphoreType *semPtr );
\r
364 StatusType WaitMutex( OsMutexType *mutexPtr );
\r
365 StatusType ReleaseMutex( OsMutexType *mutexPtr );
\r
369 /*-------------------------------------------------------------------
\r
371 *-----------------------------------------------------------------*/
\r
373 StatusType StartScheduleTableRel(ScheduleTableType sid, TickType offset);
\r
374 StatusType StartScheduleTableAbs(ScheduleTableType sid, TickType val );
\r
375 StatusType StartScheduleTableSynchron(ScheduleTableType sid );
\r
376 StatusType StopScheduleTable(ScheduleTableType sid);
\r
377 StatusType NextScheduleTable( ScheduleTableType sid_curr, ScheduleTableType sid_next);
\r
378 StatusType SyncScheduleTable( ScheduleTableType sid, GlobalTimeTickType global_time );
\r
379 StatusType GetScheduleTableStatus( ScheduleTableType sid, ScheduleTableStatusRefType status );
\r
380 StatusType SetScheduleTableAsync( ScheduleTableType sid );
\r
383 /*-------------------------------------------------------------------
\r
385 *-----------------------------------------------------------------*/
\r
387 typedef uint16 AlarmType;
\r
390 TickType maxallowedvalue;
\r
391 TickType tickperbase;
\r
395 typedef AlarmBaseType *AlarmBaseRefType;
\r
397 StatusType GetAlarmBase( AlarmType AlarmId, AlarmBaseRefType Info );
\r
398 StatusType GetAlarm(AlarmType AlarmId, TickRefType Tick);
\r
399 StatusType SetRelAlarm(AlarmType AlarmId, TickType Increment, TickType Cycle);
\r
400 StatusType SetAbsAlarm(AlarmType AlarmId, TickType Start, TickType Cycle);
\r
401 StatusType CancelAlarm(AlarmType AlarmId);
\r
404 /*-------------------------------------------------------------------
\r
406 *-----------------------------------------------------------------*/
\r
408 OSServiceId_ActivateTask,
\r
409 OSServiceId_TerminateTask,
\r
410 OSServiceId_ChainTask,
\r
411 OSServiceId_Schedule,
\r
412 OSServiceId_GetTaskID,
\r
413 OSServiceId_GetResource,
\r
414 OSServiceId_ReleaseResource,
\r
415 OSServiceId_SetEvent,
\r
416 OSServiceId_ClearEvent,
\r
417 OSServiceId_GetEvent,
\r
418 OSServiceId_WaitEvent,
\r
419 OSServiceId_GetAlarmBase,
\r
420 OSServiceId_GetAlarm,
\r
421 OSServiceId_SetRelAlarm,
\r
422 OSServiceId_SetAbsAlarm,
\r
423 OSServiceId_CancelAlarm,
\r
424 OSServiceId_StartOS,
\r
425 OSServiceId_ShutdownOS,
\r
426 OSServiceId_ErrorHook,
\r
427 OSServiceId_PreTaskHook,
\r
428 OSServiceId_PostTaskHook,
\r
429 OSServiceId_StartupHook,
\r
430 OSServiceId_ShutdownHook,
\r
431 OSServiceId_GetTaskState,
\r
432 OSServiceId_GetApplicationID,
\r
433 OSServiceId_GetISRID,
\r
434 OSServiceId_CallTrustedFunction,
\r
435 OSServiceId_CheckISRMemoryAccess,
\r
436 OSServiceId_TaskMemoryAccess,
\r
437 OSServiceId_CheckObjectAccess,
\r
438 OSServiceId_CheckObjectOwnership,
\r
439 OSServiceId_StartScheduleTableRel,
\r
440 OSServiceId_StartScheduleTableAbs,
\r
441 OSServiceId_StopScheduleTable,
\r
442 OSServiceId_NextScheduleTable,
\r
443 OSServiceId_StartScheduleTableSynchron,
\r
444 OSServiceId_SyncScheduleTable,
\r
445 OSServiceId_GetScheduleTable,
\r
446 OSServiceId_SetScheduleTableAsync,
\r
447 OSServiceId_IncrementCounter,
\r
448 OSServiceId_GetCounterValue,
\r
449 OSServiceId_GetElapsedValue,
\r
450 OSServiceId_TerminateApplication,
\r
451 OSServiceId_AllowAccess,
\r
452 OSServiceId_GetApplicationState
\r
455 typedef struct OsError {
\r
456 OsServiceIdType serviceId;
\r
462 extern OsErrorType os_error;
\r
464 // TODO: Add the service id to all OS service methods.
\r
465 static inline OsServiceIdType OSErrorGetServiceId(void) {
\r
466 return os_error.serviceId;
\r
469 extern OsErrorType os_error;
\r
471 #define OSError_ActivateTask_TaskID ((TaskType) os_error.param1)
\r
472 #define OSError_ChainTask_TaskID ((TaskType) os_error.param1)
\r
473 #define OSError_GetTaskID_TaskID ((TaskRefType) os_error.param1)
\r
474 #define OSError_GetResource_ResID ((ResourceType) os_error.param1)
\r
475 #define OSError_ReleaseResource_ResID ((ResourceType) os_error.param1)
\r
476 #define OSError_SetEvent_TaskID ((TaskType) os_error.param1)
\r
477 #define OSError_SetEvent_Mask ((EventMaskType) os_error.param2)
\r
478 #define OSError_ClearEvent_Mask ((EventMaskType) os_error.param1)
\r
479 #define OSError_GetEvent_TaskId ((TaskType) os_error.param1)
\r
480 #define OSError_GetEvent_Mask ((EventMaskRefType) os_error.param2)
\r
481 #define OSError_WaitEvent_Mask ((EventMaskType) os_error.param1)
\r
482 #define OSError_GetAlarmBase_AlarmId ((AlarmType) os_error.param1)
\r
483 #define OSError_GetAlarmBase_Info ((AlarmBaseRefType) os_error.param2)
\r
484 #define OSError_GetAlarm_AlarmId ((AlarmType) os_error.param1)
\r
485 #define OSError_GetAlarm_Tick ((TickRefType) os_error.param2)
\r
486 #define OSError_SetRelAlarm_AlarmId ((AlarmType) os_error.param1)
\r
487 #define OSError_SetRelAlarm_Increment ((TickType) os_error.param2)
\r
488 #define OSError_SetRelAlarm_Cycle ((TickType) os_error.param3)
\r
489 #define OSError_SetAbsAlarm_AlarmId ((AlarmType) os_error.param1)
\r
490 #define OSError_SetAbsAlarm_Start ((TickType) os_error.param2)
\r
491 #define OSError_SetAbsAlarm_Cycle ((TickType) os_error.param3)
\r
492 #define OSError_CancelAlarm_AlarmId ((AlarmType) os_error.param1)
\r
493 #define OSError_StartOS_Mode ((AppModeType) os_error.param1)
\r
494 #define OSError_ErrorHook_Error ((StatusType) os_error.param1)
\r
495 #define OSError_ShutdownHook_Error ((StatusType) os_error.param1)
\r
496 #define OSError_GetTaskState_TaskId ((TaskType) os_error.param1)
\r
497 #define OSError_GetTaskState_State ((TaskStateRefType) os_error.param2)
\r
500 #if defined(LOCALMESSAGESONLY)
\r
501 #error LOCALMESSAGESONLY shall not be defined
\r
505 /*-------------------------------------------------------------------
\r
506 * COM ( TODO : move )
\r
507 *-----------------------------------------------------------------*/
\r
510 * The only information about the COM that is valid is
\r
511 * in the COM specification ..SWS_COM.pdf.
\r
513 * The most important requirements are COM010 and COM013
\r
519 * No. GetMessageStatus()
\r
520 * No. SendZeroMessage()
\r
521 * No. SendDynamicMessage(), RecieveDynamicMessage()
\r
523 * Yes. SendMessage()
\r
528 typedef uint32 MessageType;
\r
529 typedef void *ApplicationDataRef;
\r
532 StatusType SendMessage( MessageType message_id, ApplicationDataRef dataRef );
\r
533 StatusType ReceiveMessage( MessageType message_id, ApplicationDataRef dataRef );
\r
536 * ArcCore extensions
\r
538 TickType GetOsTick();
\r
542 #define OS_ISR_TYPE2 0
\r
543 #define OS_ISR_TYPE1 1
\r
547 void (*entry)(void);
\r
552 #define TTY_WINIDEA 4
\r
553 #define TTY_SERIAL 8
\r