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
16 /* ----------------------------[includes]------------------------------------*/
\r
22 #include "internal.h"
\r
26 /* ----------------------------[private define]------------------------------*/
\r
27 /* ----------------------------[private macro]-------------------------------*/
\r
28 #define APPL_ID_TO_MASK(_x) (1<<(_x))
\r
30 /* ----------------------------[private typedef]-----------------------------*/
\r
31 /* ----------------------------[private function prototypes]-----------------*/
\r
32 /* ----------------------------[private variables]---------------------------*/
\r
33 #if OS_APPLICATION_CNT!=0
\r
34 OsAppVarType Os_AppVar[OS_APPLICATION_CNT];
\r
37 /* ----------------------------[private functions]---------------------------*/
\r
38 /* ----------------------------[public functions]----------------------------*/
\r
42 * Availability of AllowAccess(): Available in Scalability Classes 3 and 4.
\r
44 * Availability of TerminateApplication(): Available in Scalability Classes 3 and 4.
\r
46 * Availability of CheckObjectOwnership():Available in Scalability Classes 3 and 4.
\r
51 #if (OS_USE_APPLICATIONS == STD_ON)
\r
54 * This service determines the currently running OS-Application (a unique
\r
55 * identifier has to be allocated to each application).
\r
57 * @return <identifier of running OS-Application> or INVALID_OSAPPLICATION
60 ApplicationType GetApplicationID( void ) {
\r
61 return Os_Sys.currApplId;
\r
66 * A (trusted or non-trusted) OS-Application uses this service to call a trusted
\r
69 * @param FunctionIndex Index of the function to be called.
70 * @param FunctionParams Pointer to the parameters for the function -
\r
71 * specified by the FunctionIndex - to be called.
\r
72 * If no parameters are provided, a NULL pointer has
\r
76 StatusType CallTrustedFunction( TrustedFunctionIndexType FunctionIndex,
\r
77 TrustedFunctionParameterRefType FunctionParams ) {
\r
86 * This service checks if a memory region is write/read/execute accessible
\r
87 * and also returns information if the memory region is part of the stack
\r
90 * @param ISRID ISR reference
91 * @param Address Start of memory area
92 * @param Size Size of memory area
95 AccessType CheckISRMemoryAccess( ISRType isrId,
\r
96 MemoryStartAddressType address,
\r
97 MemorySizeType size )
\r
99 ptrdiff_t addr = (ptrdiff_t)address;
\r
103 if( isrId > OS_TASK_CNT ) {
\r
109 * This service checks if a memory region is write/read/execute accessible
\r
110 * and also returns information if the memory region is part of the stack
\r
113 * Check returned accesstype with:
\r
114 * OSMEMORY_IS_READABLE(<AccessType>)
\r
115 * OSMEMORY_IS_WRITEABLE(<AccessType>)
\r
116 * OSMEMORY_IS_EXECUTABLE(<AccessType>)
\r
117 * OSMEMORY_IS_STACKSPACE(<AccessType>)
\r
119 * TODO: Not really sure what this function is actually good for? Add a use-case!
\r
121 * @param TaskID Task reference
122 * @param Address Start of memory area
123 * @param Size Size of memory area
126 AccessType CheckTaskMemoryAccess( TaskType taskId,
\r
127 MemoryStartAddressType address,
\r
128 MemorySizeType size )
\r
130 ptrdiff_t addr = (ptrdiff_t)address;
\r
135 * if the Task reference <TaskID> in a call of CheckTaskMemoryAccess() is
\r
136 * not valid, CheckTaskMemoryAccess() shall yield no access rights.
\r
138 if( taskId > OS_TASK_CNT ) {
\r
142 /* TODO: Add body :) */
\r
148 * This service determines if the OS-Applications, given by ApplID,
\r
149 * is allowed to use the IDs of a Task, ISR, Resource, Counter,
\r
150 * Alarm or Schedule Table in API calls.
\r
152 * @param ApplID OS-Application identifier
153 * @param ObjectType Type of the following parameter
154 * @param object The object to be examined
155 * @return ACCESS if the ApplID has access to the object
\r
156 * NO_ACCESS otherwise
158 ObjectAccessType CheckObjectAccess( ApplicationType ApplId,
\r
159 ObjectTypeType ObjectType,
\r
160 uint32_t objectId )
\r
162 uint32 appMask = APPL_ID_TO_MASK(ApplId);
\r
163 ObjectAccessType orv;
\r
168 * If in a call of CheckObjectAccess() the object to be examined
\r
169 * is not avalid object OR <ApplID> is invalid OR <ObjectType> is
\r
170 * invalid THEN CheckObjectAccess() shall return NO_ACCESS.
\r
172 if( ApplId > OS_APPLICATION_CNT ) {
\r
177 * If the OS-Application <ApplID> in a call of CheckObjectAccess() has no
\r
178 * access to the queried object, CheckObjectAccess() shall return NO_ACCESS.
\r
180 * TODO: Could be that OS450 comes into play here....and then this is wrong.
\r
182 if( Os_AppVar[ApplId].state != APPLICATION_ACCESSIBLE ) {
\r
186 /* TODO: check id */
\r
187 switch( ObjectType ) {
\r
189 rv = ((OsAlarmType *)objectId)->accessingApplMask & (appMask);
\r
191 case OBJECT_COUNTER:
\r
192 rv = ((OsCounterType *)objectId)->accessingApplMask & (appMask);
\r
195 /* TODO: Add more things here for missing objects */
\r
197 case OBJECT_MESSAGE:
\r
198 case OBJECT_RESOURCE:
\r
199 case OBJECT_SCHEDULETABLE:
\r
202 rv = ((OsCounterType *)objectId)->accessingApplMask & (appMask);
\r
210 orv = rv ? ACCESS : NO_ACCESS;
\r
216 * This service determines to which OS-Application a given Task, ISR, Resource,
\r
217 * Counter, Alarm or Schedule Table belongs
\r
219 * @param ObjectType Type of the following parameter
220 * @param object The object to be examined
\r
221 * @return The OS-Application to which the object ObjectType belongs or
\r
222 * INVALID_OSAPPLICATION if the object does not exists
224 ApplicationType CheckObjectOwnership( ObjectTypeType ObjectType,
\r
225 uint32_t objectId )
\r
227 ApplicationType rv = INVALID_OSAPPLICATION;
\r
229 switch( ObjectType ) {
\r
232 case OBJECT_COUNTER:
\r
236 case OBJECT_MESSAGE:
\r
238 case OBJECT_RESOURCE:
\r
240 case OBJECT_SCHEDULETABLE:
\r
244 if( objectId < OS_TASK_CNT ) {
\r
245 rv = Os_TaskGet(objectId)
\r
249 OsTaskVarTypeapplOwnerId
\r
250 if( objectId > OS_MAX )
\r
262 * This service terminates the OS-Application to which the calling Task/Category 2
\r
263 * ISR/application specific error hook belongs.
\r
265 * @param Application - The identifier of the OS-Application to be terminated.
\r
266 * If the caller belongs to <Application> the call results in a
\r
267 * self termination.
\r
269 * @param RestartOption - Either RESTART for doing a restart of the
\r
270 * OS-Application or NO_RESTART if OS-Application shall not be restarted.
\r
272 * @return E_OK: No errors
\r
273 * E_OS_ID: <Application> was not valid
\r
274 * E_OS_VALUE: <RestartOption> was neither RESTART nor NO_RESTART
\r
275 * E_OS_ACCESS: The caller does not have the right to terminate <Application>
\r
276 * E_OS_STATE: The state of <Application> does not allow terminating <Application>
278 StatusType TerminateApplication( ApplicationType applId, RestartType restartOption ) {
\r
280 (void)restartOption;
\r
286 * This service sets the own state of an OS-Application from
\r
287 * APPLICATION_RESTARTING to APPLICATION_ACCESSIBLE.
\r
289 * @return E_OK : No errors
\r
290 * E_OS_STATE : The OS-Application of the caller is in the wrong
\r
293 StatusType AllowAccess( void ) {
\r
294 ApplicationType applId = Os_Sys.currApplId;
\r
297 if( Os_AppVar[applId].state != APPLICATION_RESTARTING ) {
\r
302 Os_AppVar[applId].state = APPLICATION_ACCESSIBLE;
\r
307 * This service returns the current state of an OS-Application.
\r
310 * @param ApplId The OS-Application from which the state is requested
311 * @param Value The current state of the application
312 * @return E_OK: No errors, E_OS_ID: <Application> is not valid
314 StatusType GetApplicationState( ApplicationType applId, ApplicationStateRefType value ) {
\r
316 if(applId > OS_APPLICATION_CNT ) {
\r
320 *value = Os_AppVar[applId].state;
\r
327 * TODO: Move somewhere else
331 StatusType GetActiveApplicationMode( AppModeType* mode) {
\r
332 *mode = Os_Sys.appMode;
\r
339 void Os_ApplStart( void ) {
\r
342 /* Call startuphooks for all applications */
\r
343 for(i=0;i<OS_APPLICATION_CNT;i++) {
\r
345 Os_AppVar[i].state = APPLICATION_ACCESSIBLE;
\r
347 if( Os_AppConst[i].StartupHook != NULL ) {
\r
348 Os_AppConst[i].StartupHook();
\r