From da0cb0cf18f4c86d623418b82ffe9729608df482 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Luc=20B=C3=A9chennec?= Date: Tue, 17 Oct 2023 12:09:08 +0200 Subject: [PATCH] [OS] fix error code returned by services when called from alarm callback. Now, E_OS_CALLEVEL is returned --- os/tpl_os_action.c | 50 +- os/tpl_os_alarm_kernel.c | 112 ++-- os/tpl_os_error.h | 1088 ++++++++++++++++++----------------- os/tpl_os_event_kernel.c | 59 +- os/tpl_os_kernel.c | 53 +- os/tpl_os_kernel.h | 295 +++++----- os/tpl_os_os_kernel.c | 35 +- os/tpl_os_resource_kernel.c | 70 ++- os/tpl_os_task_kernel.c | 62 +- os/tpl_os_timeobj_kernel.c | 384 +++++++------ 10 files changed, 1185 insertions(+), 1023 deletions(-) diff --git a/os/tpl_os_action.c b/os/tpl_os_action.c index 5154cf064..506b06b37 100644 --- a/os/tpl_os_action.c +++ b/os/tpl_os_action.c @@ -10,8 +10,8 @@ * * Trampoline RTOS * - * Trampoline is copyright (c) CNRS, University of Nantes, Ecole Centrale de Nantes - * Trampoline is protected by the French intellectual property law. + * Trampoline is copyright (c) CNRS, University of Nantes, Ecole Centrale de + * Nantes Trampoline is protected by the French intellectual property law. * * This software is distributed under the GNU Public Licence V2. * Check the LICENSE file in the root directory of Trampoline @@ -24,12 +24,13 @@ * $URL$ */ -#include "tpl_os_definitions.h" -#include "tpl_os_task_kernel.h" -#include "tpl_os_event_kernel.h" #include "tpl_os_action.h" +#include "tpl_os_definitions.h" #include "tpl_os_error.h" #include "tpl_os_errorhook.h" +#include "tpl_os_event_kernel.h" +#include "tpl_os_kernel.h" +#include "tpl_os_task_kernel.h" #define OS_START_SEC_CODE #include "tpl_memmap.h" @@ -37,9 +38,10 @@ /** * action function for action call back */ -FUNC(void, OS_CODE) tpl_action_callback( - P2CONST(tpl_action, AUTOMATIC, OS_APPL_CONST) action) +FUNC(void, OS_CODE) +tpl_action_callback(P2CONST(tpl_action, AUTOMATIC, OS_APPL_CONST) action) { + tpl_begin_alarm_callback(); /* * A tpl_action * is cast to a tpl_callback_action * * This violate MISRA rule 45. However, since the @@ -47,14 +49,14 @@ FUNC(void, OS_CODE) tpl_action_callback( * This cast behaves correctly. */ ((P2CONST(tpl_callback_action, AUTOMATIC, OS_APPL_CONST))action)->callback(); + tpl_end_alarm_callback(); } /** * action function for action by task activation */ -FUNC(void, OS_CODE) tpl_action_activate_task( - P2CONST(tpl_action, AUTOMATIC, OS_APPL_CONST) action -) +FUNC(void, OS_CODE) +tpl_action_activate_task(P2CONST(tpl_action, AUTOMATIC, OS_APPL_CONST) action) { /* * A tpl_action * is cast to a tpl_task_activation_action * @@ -68,13 +70,15 @@ FUNC(void, OS_CODE) tpl_action_activate_task( /* store information for error hook routine */ STORE_SERVICE(OSServiceId_ActivateTask) - STORE_TASK_ID(((P2CONST(tpl_task_activation_action, AUTOMATIC, OS_APPL_CONST))action)->task_id) + STORE_TASK_ID( + ((P2CONST(tpl_task_activation_action, AUTOMATIC, OS_APPL_CONST))action) + ->task_id) - /* call alarm action and save return value to launch error hook if alarm action goes wrong */ + /* call alarm action and save return value to launch error hook if alarm + * action goes wrong */ result_action = tpl_activate_task( - ((P2CONST(tpl_task_activation_action, - AUTOMATIC, - OS_APPL_CONST))action)->task_id); + ((P2CONST(tpl_task_activation_action, AUTOMATIC, OS_APPL_CONST))action) + ->task_id); PROCESS_ERROR(result_action) } @@ -84,8 +88,8 @@ FUNC(void, OS_CODE) tpl_action_activate_task( */ #if EVENT_COUNT > 0 -FUNC(void, OS_CODE) tpl_action_setevent( - P2CONST(tpl_action, AUTOMATIC, OS_APPL_CONST) action) +FUNC(void, OS_CODE) +tpl_action_setevent(P2CONST(tpl_action, AUTOMATIC, OS_APPL_CONST) action) { /* * A tpl_action * is cast to a tpl_setevent_action * @@ -99,13 +103,15 @@ FUNC(void, OS_CODE) tpl_action_setevent( /* store information for error hook routine */ STORE_SERVICE(OSServiceId_SetEvent) - STORE_TASK_ID(((P2CONST(tpl_setevent_action, AUTOMATIC, OS_APPL_CONST))action)->task_id) - STORE_EVENT_MASK(((P2CONST(tpl_setevent_action, AUTOMATIC, OS_APPL_CONST))action)->mask) - /* call alarm action and save return value to launch error hook if alarm action goes wrong */ + STORE_TASK_ID( + ((P2CONST(tpl_setevent_action, AUTOMATIC, OS_APPL_CONST))action)->task_id) + STORE_EVENT_MASK( + ((P2CONST(tpl_setevent_action, AUTOMATIC, OS_APPL_CONST))action)->mask) + /* call alarm action and save return value to launch error hook if alarm + * action goes wrong */ result_action = tpl_set_event( ((P2CONST(tpl_setevent_action, AUTOMATIC, OS_APPL_CONST))action)->task_id, - ((P2CONST(tpl_setevent_action, AUTOMATIC, OS_APPL_CONST))action)->mask - ); + ((P2CONST(tpl_setevent_action, AUTOMATIC, OS_APPL_CONST))action)->mask); PROCESS_ERROR(result_action); } diff --git a/os/tpl_os_alarm_kernel.c b/os/tpl_os_alarm_kernel.c index 9f2913656..d8f3b7dc2 100644 --- a/os/tpl_os_alarm_kernel.c +++ b/os/tpl_os_alarm_kernel.c @@ -25,11 +25,11 @@ */ #include "tpl_os_alarm_kernel.h" +#include "tpl_machine_interface.h" #include "tpl_os_definitions.h" -#include "tpl_os_kernel.h" #include "tpl_os_error.h" #include "tpl_os_errorhook.h" -#include "tpl_machine_interface.h" +#include "tpl_os_kernel.h" #include "tpl_trace.h" #include "tpl_debug.h" @@ -63,8 +63,8 @@ CONST(tpl_alarm_id, AUTOMATIC) INVALID_ALARM = (-1); * * @param time_obj The alarm to raise. */ -FUNC(void, OS_CODE) tpl_raise_alarm( - P2VAR(tpl_time_obj, AUTOMATIC, OS_APPL_DATA) time_obj) +FUNC(void, OS_CODE) +tpl_raise_alarm(P2VAR(tpl_time_obj, AUTOMATIC, OS_APPL_DATA) time_obj) { /* * A tpl_time_obj_static * is cast to a tpl_alarm_static * @@ -73,20 +73,19 @@ FUNC(void, OS_CODE) tpl_raise_alarm( * This cast behaves correctly. */ /* Get the alarm descriptor */ - P2VAR(tpl_alarm_static, AUTOMATIC, OS_APPL_DATA) stat_alarm = - (tpl_alarm_static *)time_obj->stat_part; + P2VAR(tpl_alarm_static, AUTOMATIC, OS_APPL_DATA) + stat_alarm = (tpl_alarm_static *)time_obj->stat_part; /* Get the action to perform from the alarm descriptor */ - CONSTP2VAR(tpl_action, AUTOMATIC, OS_APPL_CONST) action_desc = - stat_alarm->action; + CONSTP2VAR(tpl_action, AUTOMATIC, OS_APPL_CONST) + action_desc = stat_alarm->action; /* Call the action */ - (action_desc->action)(action_desc) ; + (action_desc->action)(action_desc); } - -FUNC(tpl_status, OS_CODE) tpl_get_alarm_base_service( - CONST(tpl_alarm_id, AUTOMATIC) alarm_id, - P2VAR(tpl_alarm_base, AUTOMATIC, OS_APPL_DATA) info) +FUNC(tpl_status, OS_CODE) +tpl_get_alarm_base_service(CONST(tpl_alarm_id, AUTOMATIC) alarm_id, + P2VAR(tpl_alarm_base, AUTOMATIC, OS_APPL_DATA) info) { GET_CURRENT_CORE_ID(core_id) VAR(tpl_status, AUTOMATIC) result = E_OK; @@ -97,17 +96,20 @@ FUNC(tpl_status, OS_CODE) tpl_get_alarm_base_service( LOCK_KERNEL() -/* check interrupts are not disabled by user */ + /* check interrupts are not disabled by user */ CHECK_INTERRUPT_LOCK(result) STORE_SERVICE(OSServiceId_GetAlarmBase) STORE_ALARM_ID(alarm_id) STORE_ALARM_BASE_REF(info) + /* Check call level error: forbidden from an alarm callback */ + CHECK_CALLBACK_CALL_LEVEL_ERROR(result, core_id) + CHECK_ALARM_ID_ERROR(alarm_id, result) - /* check access right */ - CHECK_ACCESS_RIGHTS_ALARM_ID(core_id, alarm_id, result) + /* check access right */ + CHECK_ACCESS_RIGHTS_ALARM_ID(core_id, alarm_id, result) /* check info is in an authorized memory region */ CHECK_DATA_LOCATION(core_id, info, result); @@ -130,9 +132,9 @@ FUNC(tpl_status, OS_CODE) tpl_get_alarm_base_service( return result; } -FUNC(tpl_status, OS_CODE) tpl_get_alarm_service( - CONST(tpl_alarm_id, AUTOMATIC) alarm_id, - P2VAR(tpl_tick, AUTOMATIC, OS_APPL_DATA) tick) +FUNC(tpl_status, OS_CODE) +tpl_get_alarm_service(CONST(tpl_alarm_id, AUTOMATIC) alarm_id, + P2VAR(tpl_tick, AUTOMATIC, OS_APPL_DATA) tick) { GET_CURRENT_CORE_ID(core_id) VAR(tpl_status, AUTOMATIC) result = E_OK; @@ -150,10 +152,13 @@ FUNC(tpl_status, OS_CODE) tpl_get_alarm_service( STORE_ALARM_ID(alarm_id) STORE_TICK_REF_1(tick) - CHECK_ALARM_ID_ERROR(alarm_id,result) + /* Check call level error: forbidden from an alarm callback */ + CHECK_CALLBACK_CALL_LEVEL_ERROR(result, core_id) + + CHECK_ALARM_ID_ERROR(alarm_id, result) /* check access right */ - CHECK_ACCESS_RIGHTS_ALARM_ID(core_id, alarm_id,result) + CHECK_ACCESS_RIGHTS_ALARM_ID(core_id, alarm_id, result) /* check tick is in an authorized memory region */ CHECK_DATA_LOCATION(core_id, tick, result); @@ -171,8 +176,8 @@ FUNC(tpl_status, OS_CODE) tpl_get_alarm_service( if (alarm->state == (tpl_time_obj_state)ALARM_ACTIVE) { VAR(tpl_tick, AUTOMATIC) alarm_date = alarm->date; - VAR(tpl_tick, AUTOMATIC) current_date = - alarm->stat_part->counter->current_date; + VAR(tpl_tick, AUTOMATIC) + current_date = alarm->stat_part->counter->current_date; if (alarm_date < current_date) { alarm_date += alarm->stat_part->counter->max_allowed_value; @@ -199,10 +204,10 @@ FUNC(tpl_status, OS_CODE) tpl_get_alarm_service( return result; } -FUNC(tpl_status, OS_CODE) tpl_set_rel_alarm_service( - CONST(tpl_alarm_id, AUTOMATIC) alarm_id, - CONST(tpl_tick, AUTOMATIC) increment, - CONST(tpl_tick, AUTOMATIC) cycle) +FUNC(tpl_status, OS_CODE) +tpl_set_rel_alarm_service(CONST(tpl_alarm_id, AUTOMATIC) alarm_id, + CONST(tpl_tick, AUTOMATIC) increment, + CONST(tpl_tick, AUTOMATIC) cycle) { GET_CURRENT_CORE_ID(core_id) VAR(tpl_status, AUTOMATIC) result = E_OK; @@ -215,7 +220,7 @@ FUNC(tpl_status, OS_CODE) tpl_set_rel_alarm_service( LOCK_KERNEL() -/* check interrupts are not disabled by user */ + /* check interrupts are not disabled by user */ CHECK_INTERRUPT_LOCK(result) STORE_SERVICE(OSServiceId_SetRelAlarm) @@ -223,13 +228,16 @@ FUNC(tpl_status, OS_CODE) tpl_set_rel_alarm_service( STORE_TICK_1(increment) STORE_TICK_2(cycle) - CHECK_ALARM_ID_ERROR(alarm_id,result) + /* Check call level error: forbidden from an alarm callback */ + CHECK_CALLBACK_CALL_LEVEL_ERROR(result, core_id) - /* check access right */ - CHECK_ACCESS_RIGHTS_ALARM_ID(core_id, alarm_id,result) + CHECK_ALARM_ID_ERROR(alarm_id, result) + + /* check access right */ + CHECK_ACCESS_RIGHTS_ALARM_ID(core_id, alarm_id, result) - CHECK_ALARM_INCREMENT_ERROR(alarm_id,increment,result) - CHECK_ALARM_MIN_CYCLE_ERROR(alarm_id,cycle,result) + CHECK_ALARM_INCREMENT_ERROR(alarm_id, increment, result) + CHECK_ALARM_MIN_CYCLE_ERROR(alarm_id, cycle, result) #if ALARM_COUNT > 0 IF_NO_EXTENDED_ERROR(result) @@ -247,7 +255,7 @@ FUNC(tpl_status, OS_CODE) tpl_set_rel_alarm_service( date = cnt->current_date + increment; if (date > cnt->max_allowed_value) { - date -= (cnt->max_allowed_value + 1); + date -= (cnt->max_allowed_value + 1); } alarm->date = date; alarm->cycle = cycle; @@ -281,10 +289,10 @@ FUNC(tpl_status, OS_CODE) tpl_set_rel_alarm_service( * * See page 64 of the OSEK spec */ -FUNC(tpl_status, OS_CODE) tpl_set_abs_alarm_service( - CONST(tpl_alarm_id, AUTOMATIC) alarm_id, - CONST(tpl_tick, AUTOMATIC) start, - CONST(tpl_tick, AUTOMATIC) cycle) +FUNC(tpl_status, OS_CODE) +tpl_set_abs_alarm_service(CONST(tpl_alarm_id, AUTOMATIC) alarm_id, + CONST(tpl_tick, AUTOMATIC) start, + CONST(tpl_tick, AUTOMATIC) cycle) { GET_CURRENT_CORE_ID(core_id) VAR(tpl_status, AUTOMATIC) result = E_OK; @@ -303,13 +311,16 @@ FUNC(tpl_status, OS_CODE) tpl_set_abs_alarm_service( STORE_TICK_1(start) STORE_TICK_2(cycle) - CHECK_ALARM_ID_ERROR(alarm_id,result) + /* Check call level error: forbidden from an alarm callback */ + CHECK_CALLBACK_CALL_LEVEL_ERROR(result, core_id) + + CHECK_ALARM_ID_ERROR(alarm_id, result) - /* check access right */ - CHECK_ACCESS_RIGHTS_ALARM_ID(core_id, alarm_id,result) + /* check access right */ + CHECK_ACCESS_RIGHTS_ALARM_ID(core_id, alarm_id, result) - CHECK_ALARM_INCREMENT_ERROR(alarm_id,start,result) - CHECK_ALARM_MIN_CYCLE_ERROR(alarm_id,cycle,result) + CHECK_ALARM_INCREMENT_ERROR(alarm_id, start, result) + CHECK_ALARM_MIN_CYCLE_ERROR(alarm_id, cycle, result) #if ALARM_COUNT > 0 IF_NO_EXTENDED_ERROR(result) @@ -355,8 +366,8 @@ FUNC(tpl_status, OS_CODE) tpl_set_abs_alarm_service( * * See page 65 of the OSEK spec */ -FUNC(tpl_status, OS_CODE) tpl_cancel_alarm_service( - CONST(tpl_alarm_id, AUTOMATIC) alarm_id) +FUNC(tpl_status, OS_CODE) +tpl_cancel_alarm_service(CONST(tpl_alarm_id, AUTOMATIC) alarm_id) { GET_CURRENT_CORE_ID(core_id) VAR(tpl_status, AUTOMATIC) result = E_OK; @@ -367,16 +378,19 @@ FUNC(tpl_status, OS_CODE) tpl_cancel_alarm_service( LOCK_KERNEL() - /* check interrupts are not disabled by user */ + /* check interrupts are not disabled by user */ CHECK_INTERRUPT_LOCK(result) STORE_SERVICE(OSServiceId_CancelAlarm) STORE_ALARM_ID(alarm_id) - CHECK_ALARM_ID_ERROR(alarm_id,result) + /* Check call level error: forbidden from an alarm callback */ + CHECK_CALLBACK_CALL_LEVEL_ERROR(result, core_id) - /* check access right */ - CHECK_ACCESS_RIGHTS_ALARM_ID(core_id, alarm_id,result) + CHECK_ALARM_ID_ERROR(alarm_id, result) + + /* check access right */ + CHECK_ACCESS_RIGHTS_ALARM_ID(core_id, alarm_id, result) #if ALARM_COUNT > 0 IF_NO_EXTENDED_ERROR(result) diff --git a/os/tpl_os_error.h b/os/tpl_os_error.h index 8dafb8ad5..04fc93cc3 100644 --- a/os/tpl_os_error.h +++ b/os/tpl_os_error.h @@ -9,7 +9,8 @@ * * Trampoline RTOS * - * Trampoline is copyright (c) CNRS, University of Nantes, Ecole Centrale de Nantes + * Trampoline is copyright (c) CNRS, + * University of Nantes, Ecole Centrale de Nantes * Trampoline is protected by the French intellectual property law. * * This software is distributed under the GNU Public Licence V2. @@ -33,8 +34,8 @@ #endif #if WITH_AUTOSAR == YES -#include "tpl_os_timeobj_kernel.h" #include "tpl_as_application.h" +#include "tpl_os_timeobj_kernel.h" #endif #if WITH_ORTI == YES @@ -42,13 +43,13 @@ #define OS_START_SEC_VAR_UNSPECIFIED #include "tpl_memmap.h" -# if NUMBER_OF_CORES > 1 +#if NUMBER_OF_CORES > 1 extern VAR(tpl_status, OS_VAR) tpl_last_error[NUMBER_OF_CORES]; #define TPL_LAST_ERROR(core) tpl_last_error[core] -# else +#else extern VAR(tpl_status, OS_VAR) tpl_last_error; #define TPL_LAST_ERROR(core) tpl_last_error -# endif +#endif #define OS_STOP_SEC_VAR_UNSPECIFIED #include "tpl_memmap.h" @@ -72,7 +73,8 @@ extern FUNC(tpl_bool, OS_CODE) tpl_get_interrupt_lock_status(void); #define OS_START_SEC_CODE #include "tpl_memmap.h" -extern FUNC(void, OS_CODE) tpl_call_error_hook(CONST(tpl_status, AUTOMATIC) error); +extern FUNC(void, OS_CODE) + tpl_call_error_hook(CONST(tpl_status, AUTOMATIC) error); #define OS_STOP_SEC_CODE #include "tpl_memmap.h" @@ -89,40 +91,46 @@ extern FUNC(void, OS_CODE) tpl_call_error_hook(CONST(tpl_status, AUTOMATIC) erro * @see #PARAM_BLOCK * @see #tpl_service */ -union ID_PARAM_BLOCK { - VAR(tpl_task_id, TYPEDEF) task_id; /**< used by - #ActivateTask, - #ChainTask, - #GetTaskState, - #SetEvent, - #GetEvent - */ +union ID_PARAM_BLOCK +{ + VAR(tpl_task_id, TYPEDEF) + task_id; /**< used by + #ActivateTask, + #ChainTask, + #GetTaskState, + #SetEvent, + #GetEvent + */ P2VAR(tpl_task_id, AUTOMATIC, TYPEDEF) task_id_ref; /**< used by #GetTaskID */ - VAR(tpl_resource_id, TYPEDEF) res_id; /**< used by #GetResource, - #ReleaseResource - */ - VAR(tpl_alarm_id, TYPEDEF) alarm_id; /**< used by #SetRelAlarm, #SetAbsAlarm, - #CancelAlarm, #GetAlarm and - #GetAlarmBase - */ + VAR(tpl_resource_id, TYPEDEF) + res_id; /**< used by #GetResource, + #ReleaseResource + */ + VAR(tpl_alarm_id, TYPEDEF) + alarm_id; /**< used by #SetRelAlarm, #SetAbsAlarm, + #CancelAlarm, #GetAlarm and + #GetAlarmBase + */ VAR(tpl_application_mode, TYPEDEF) mode; /**< used by StartOS */ #if WITH_AUTOSAR == YES VAR(tpl_schedtable_id, TYPEDEF) schedtable_id; /**< @todo document this */ - VAR(tpl_counter_id, TYPEDEF) counter_id; /**< @todo document this */ - VAR(tpl_app_id, TYPEDEF) application_id; /**< @todo document this */ + VAR(tpl_counter_id, TYPEDEF) counter_id; /**< @todo document this */ + VAR(tpl_app_id, TYPEDEF) application_id; /**< @todo document this */ #endif #if WITH_IOC == YES - VAR(tpl_ioc_id, TYPEDEF) ioc_id; /**< used by - #IOC_Send - #IOC_Receive - #IOC_Write - #IOC_Read - */ + VAR(tpl_ioc_id, TYPEDEF) + ioc_id; /**< used by + #IOC_Send + #IOC_Receive + #IOC_Write + #IOC_Read + */ #endif #if NUMBER_OF_CORES > 1 - VAR(tpl_core_id, TYPEDEF) core_id; /**< used by StartCore and - StartNonAutosarCore */ + VAR(tpl_core_id, TYPEDEF) + core_id; /**< used by StartCore and + StartNonAutosarCore */ VAR(tpl_spinlock_id, TYPEDEF) spinlock_id; /**< @todo document this */ #endif }; @@ -135,36 +143,43 @@ union ID_PARAM_BLOCK { * @see #PARAM_BLOCK * @see #tpl_service */ -union PARAM_PARAM_BLOCK { - P2VAR(tpl_proc_state, AUTOMATIC, TYPEDEF) state; /**< used by #GetTaskState - */ - VAR(tpl_tick, TYPEDEF) tick; /**< used by #SetRelAlarm, #SetAbsAlarm */ +union PARAM_PARAM_BLOCK +{ + P2VAR(tpl_proc_state, AUTOMATIC, TYPEDEF) + state; /**< used by #GetTaskState + */ + VAR(tpl_tick, TYPEDEF) tick; /**< used by #SetRelAlarm, #SetAbsAlarm */ P2VAR(tpl_tick, AUTOMATIC, TYPEDEF) tick_ref; /**< used by #GetAlarm */ - P2VAR(tpl_alarm_base, AUTOMATIC, TYPEDEF) alarm_base_ref; /**< used by - #GetAlarmBase - */ - VAR(tpl_event_mask, TYPEDEF) mask; /**< used by #SetEvent, - #ClearEvent, - #WaitEvent - */ + P2VAR(tpl_alarm_base, AUTOMATIC, TYPEDEF) + alarm_base_ref; /**< used by + #GetAlarmBase + */ + VAR(tpl_event_mask, TYPEDEF) + mask; /**< used by #SetEvent, + #ClearEvent, + #WaitEvent + */ P2VAR(tpl_event_mask, AUTOMATIC, TYPEDEF) mask_ref; /**< used by #GetEvent */ #if WITH_AUTOSAR == YES VAR(tpl_schedtable_id, TYPEDEF) next_st_id; /**< @todo document this */ - P2VAR(tpl_time_obj_state, AUTOMATIC, TYPEDEF) st_stat; /**< @todo document - this - */ + P2VAR(tpl_time_obj_state, AUTOMATIC, TYPEDEF) + st_stat; /**< @todo document + this + */ VAR(ObjectTypeType, TYPEDEF) object_type; /**< @todo document this */ - VAR(uint8, TYPEDEF) opt_termapp; /**< @todo document this */ + VAR(uint8, TYPEDEF) opt_termapp; /**< @todo document this */ #endif }; -union PARAM_PARAM_BLOCK_2 { - VAR(tpl_tick, TYPEDEF) tick; /**< used by #SetRelAlarm, #SetAbsAlarm */ - P2VAR(tpl_tick, AUTOMATIC, TYPEDEF) tick_ref; /**< used by - #GetElapsedCounterValue - */ +union PARAM_PARAM_BLOCK_2 +{ + VAR(tpl_tick, TYPEDEF) tick; /**< used by #SetRelAlarm, #SetAbsAlarm */ + P2VAR(tpl_tick, AUTOMATIC, TYPEDEF) + tick_ref; /**< used by + #GetElapsedCounterValue + */ #if WITH_AUTOSAR == YES - VAR(tpl_generic_id, TYPEDEF) object_id; /**< @todo document this */ + VAR(tpl_generic_id, TYPEDEF) object_id; /**< @todo document this */ #endif }; @@ -173,10 +188,11 @@ union PARAM_PARAM_BLOCK_2 { * * This structure gathers all parameters for an error hook */ -struct PARAM_BLOCK { - union ID_PARAM_BLOCK id; /**< identifies the OS element +struct PARAM_BLOCK +{ + union ID_PARAM_BLOCK id; /**< identifies the OS element concerned by the error */ - union PARAM_PARAM_BLOCK param; /**< gives more information about the + union PARAM_PARAM_BLOCK param; /**< gives more information about the reason of the error */ union PARAM_PARAM_BLOCK_2 param2; /**< more informations */ }; @@ -186,11 +202,13 @@ struct PARAM_BLOCK { * * This structure gathers the os service identifier and its parameters */ -struct SERVICE_CALL_DESCRIPTOR { - struct PARAM_BLOCK parameters; /**< information about conditions seen - when error has been detected */ - VAR(uint8, TYPEDEF) service_id; /**< identifier of the service which - raised the error */ +struct SERVICE_CALL_DESCRIPTOR +{ + struct PARAM_BLOCK parameters; /**< information about conditions seen + when error has been detected */ + VAR(uint8, TYPEDEF) + service_id; /**< identifier of the service which + raised the error */ }; /** @@ -260,7 +278,6 @@ extern VAR(tpl_service_call_desc, OS_VAR) tpl_service; #define OS_STOP_SEC_VAR_UNSPECIFIED #include "tpl_memmap.h" - /************************************************************************ * macros to access the service id and its parameters from hook routine * ************************************************************************/ @@ -274,7 +291,7 @@ extern VAR(tpl_service_call_desc, OS_VAR) tpl_service; * function */ #if WITH_USEGETSERVICEID == YES -#define OSErrorGetServiceId() (tpl_service.service_id) +#define OSErrorGetServiceId() (tpl_service.service_id) #endif /** @@ -505,7 +522,7 @@ extern VAR(tpl_service_call_desc, OS_VAR) tpl_service; * @see #OSError_GetAlarmBase_AlarmID */ #if WITH_USEPARAMETERACCESS == YES -#define OSError_GetAlarmBase_Info() \ +#define OSError_GetAlarmBase_Info() \ (tpl_service.parameters.param.alarm_base_ref) #endif @@ -741,10 +758,9 @@ extern VAR(tpl_service_call_desc, OS_VAR) tpl_service; * @see #OSErrorGetServiceId */ #if (WITH_ERROR_HOOK == YES) && (WITH_USEGETSERVICEID == YES) -# define STORE_SERVICE(service) \ - tpl_service.service_id = (service); +#define STORE_SERVICE(service) tpl_service.service_id = (service); #else -# define STORE_SERVICE(service) +#define STORE_SERVICE(service) #endif /** @@ -762,10 +778,9 @@ extern VAR(tpl_service_call_desc, OS_VAR) tpl_service; * */ #if (WITH_ERROR_HOOK == YES) && (WITH_USEPARAMETERACCESS == YES) -# define STORE_TASK_ID(taskid) \ - tpl_service.parameters.id.task_id = (taskid); +#define STORE_TASK_ID(taskid) tpl_service.parameters.id.task_id = (taskid); #else -# define STORE_TASK_ID(taskid) +#define STORE_TASK_ID(taskid) #endif /** @@ -779,10 +794,10 @@ extern VAR(tpl_service_call_desc, OS_VAR) tpl_service; * @see # */ #if (WITH_ERROR_HOOK == YES) && (WITH_USEPARAMETERACCESS == YES) -# define STORE_TASK_ID_REF(taskidref) \ - tpl_service.parameters.id.task_id_ref = (taskidref); +#define STORE_TASK_ID_REF(taskidref) \ + tpl_service.parameters.id.task_id_ref = (taskidref); #else -# define STORE_TASK_ID_REF(taskidref) +#define STORE_TASK_ID_REF(taskidref) #endif /** @@ -795,10 +810,10 @@ extern VAR(tpl_service_call_desc, OS_VAR) tpl_service; * @see #OSError_GetTaskState_State */ #if (WITH_ERROR_HOOK == YES) && (WITH_USEPARAMETERACCESS == YES) -# define STORE_TASK_STATE_REF(state) \ - tpl_service.parameters.param.state = (state); +#define STORE_TASK_STATE_REF(state) \ + tpl_service.parameters.param.state = (state); #else -# define STORE_TASK_STATE_REF(state) +#define STORE_TASK_STATE_REF(state) #endif /** @@ -812,10 +827,9 @@ extern VAR(tpl_service_call_desc, OS_VAR) tpl_service; * @see #OSError_ReleaseResource_ResID */ #if (WITH_ERROR_HOOK == YES) && (WITH_USEPARAMETERACCESS == YES) -# define STORE_RESOURCE_ID(res_id) \ - tpl_service.parameters.id.res_id = (res_id); +#define STORE_RESOURCE_ID(res_id) tpl_service.parameters.id.res_id = (res_id); #else -# define STORE_RESOURCE_ID(res_id) +#define STORE_RESOURCE_ID(res_id) #endif /** @@ -832,10 +846,10 @@ extern VAR(tpl_service_call_desc, OS_VAR) tpl_service; * @see #OSError_CancelAlarm_AlarmID */ #if (WITH_ERROR_HOOK == YES) && (WITH_USEPARAMETERACCESS == YES) -# define STORE_ALARM_ID(alarm_id) \ - tpl_service.parameters.id.alarm_id = (alarm_id); +#define STORE_ALARM_ID(alarm_id) \ + tpl_service.parameters.id.alarm_id = (alarm_id); #else -# define STORE_ALARM_ID(alarm_id) +#define STORE_ALARM_ID(alarm_id) #endif /** @@ -848,10 +862,10 @@ extern VAR(tpl_service_call_desc, OS_VAR) tpl_service; * @see #OSError_GetAlarmBase_Info */ #if (WITH_ERROR_HOOK == YES) && (WITH_USEPARAMETERACCESS == YES) -# define STORE_ALARM_BASE_REF(ref) \ - tpl_service.parameters.param.alarm_base_ref = (ref); +#define STORE_ALARM_BASE_REF(ref) \ + tpl_service.parameters.param.alarm_base_ref = (ref); #else -# define STORE_ALARM_BASE_REF(ref) +#define STORE_ALARM_BASE_REF(ref) #endif /** @@ -864,10 +878,9 @@ extern VAR(tpl_service_call_desc, OS_VAR) tpl_service; * @see #OSError_GetAlarm_Tick */ #if (WITH_ERROR_HOOK == YES) && (WITH_USEPARAMETERACCESS == YES) -# define STORE_TICK_REF_1(ref) \ - tpl_service.parameters.param.tick_ref = (ref); +#define STORE_TICK_REF_1(ref) tpl_service.parameters.param.tick_ref = (ref); #else -# define STORE_TICK_REF_1(ref) +#define STORE_TICK_REF_1(ref) #endif /** @@ -880,10 +893,9 @@ extern VAR(tpl_service_call_desc, OS_VAR) tpl_service; * @see #OSError_GetAlarm_Tick */ #if (WITH_ERROR_HOOK == YES) && (WITH_USEPARAMETERACCESS == YES) -# define STORE_TICK_REF_2(ref) \ - tpl_service.parameters.param2.tick_ref = (ref); +#define STORE_TICK_REF_2(ref) tpl_service.parameters.param2.tick_ref = (ref); #else -# define STORE_TICK_REF_2(ref) +#define STORE_TICK_REF_2(ref) #endif /** @@ -897,10 +909,9 @@ extern VAR(tpl_service_call_desc, OS_VAR) tpl_service; * @see OSError_SetAbsAlarm_start */ #if (WITH_ERROR_HOOK == YES) && (WITH_USEPARAMETERACCESS == YES) -# define STORE_TICK_1(t) \ - tpl_service.parameters.param.tick = (t); +#define STORE_TICK_1(t) tpl_service.parameters.param.tick = (t); #else -# define STORE_TICK_1(t) +#define STORE_TICK_1(t) #endif /** @@ -914,10 +925,9 @@ extern VAR(tpl_service_call_desc, OS_VAR) tpl_service; * @see #OSError_SetAbsAlarm_cycle */ #if (WITH_ERROR_HOOK == YES) && (WITH_USEPARAMETERACCESS == YES) -# define STORE_TICK_2(t) \ - tpl_service.parameters.param2.tick = (t); +#define STORE_TICK_2(t) tpl_service.parameters.param2.tick = (t); #else -# define STORE_TICK_2(t) +#define STORE_TICK_2(t) #endif /** @@ -933,10 +943,9 @@ extern VAR(tpl_service_call_desc, OS_VAR) tpl_service; * @see #OSError_WaitEvent_Mask */ #if (WITH_ERROR_HOOK == YES) && (WITH_USEPARAMETERACCESS == YES) -# define STORE_EVENT_MASK(m) \ - tpl_service.parameters.param.mask = (m); +#define STORE_EVENT_MASK(m) tpl_service.parameters.param.mask = (m); #else -# define STORE_EVENT_MASK(m) +#define STORE_EVENT_MASK(m) #endif /** @@ -948,10 +957,9 @@ extern VAR(tpl_service_call_desc, OS_VAR) tpl_service; * */ #if (WITH_ERROR_HOOK == YES) && (WITH_USEPARAMETERACCESS == YES) -# define STORE_EVENT_MASK_REF(ref) \ - tpl_service.parameters.param.mask_ref = (ref); +#define STORE_EVENT_MASK_REF(ref) tpl_service.parameters.param.mask_ref = (ref); #else -# define STORE_EVENT_MASK_REF(ref) +#define STORE_EVENT_MASK_REF(ref) #endif /** @@ -967,11 +975,11 @@ extern VAR(tpl_service_call_desc, OS_VAR) tpl_service; * @see #OSError_IOC_Read_IocID * */ -#if (WITH_ERROR_HOOK == YES) && (WITH_USEPARAMETERACCESS == YES) && (WITH_IOC == YES) -# define STORE_IOC_ID(iocid) \ -tpl_service.parameters.id.ioc_id = (iocid); +#if (WITH_ERROR_HOOK == YES) && (WITH_USEPARAMETERACCESS == YES) && \ + (WITH_IOC == YES) +#define STORE_IOC_ID(iocid) tpl_service.parameters.id.ioc_id = (iocid); #else -# define STORE_IOC_ID(iocid) +#define STORE_IOC_ID(iocid) #endif /** @@ -983,10 +991,9 @@ tpl_service.parameters.id.ioc_id = (iocid); * */ #if (WITH_ERROR_HOOK == YES) && (WITH_USEPARAMETERACCESS == YES) -# define STORE_MODE(mode) \ - tpl_service.parameters.id.mode = (mode); +#define STORE_MODE(mode) tpl_service.parameters.id.mode = (mode); #else -# define STORE_MODE(mode) +#define STORE_MODE(mode) #endif /** @@ -994,11 +1001,11 @@ tpl_service.parameters.id.ioc_id = (iocid); * * Stores a core identifier */ -#if (WITH_ERROR_HOOK == YES) && (WITH_USEPARAMETERACCESS == YES) && (NUMBER_OF_CORES > 1) -# define STORE_CORE_ID(core_id) \ - tpl_service.parameters.id.core_id = (core_id); +#if (WITH_ERROR_HOOK == YES) && (WITH_USEPARAMETERACCESS == YES) && \ + (NUMBER_OF_CORES > 1) +#define STORE_CORE_ID(core_id) tpl_service.parameters.id.core_id = (core_id); #else -# define STORE_CORE_ID(core_id) +#define STORE_CORE_ID(core_id) #endif /** @@ -1009,11 +1016,12 @@ tpl_service.parameters.id.ioc_id = (iocid); * @param spinlock_id type is #tpl_spinlock_id * */ -#if (WITH_ERROR_HOOK == YES) && (WITH_USEPARAMETERACCESS == YES) && (WITH_SPINLOCK == YES) -# define STORE_SPINLOCK_ID(spinlockid) \ -tpl_service.parameters.id.spinlock_id = (spinlockid); +#if (WITH_ERROR_HOOK == YES) && (WITH_USEPARAMETERACCESS == YES) && \ + (WITH_SPINLOCK == YES) +#define STORE_SPINLOCK_ID(spinlockid) \ + tpl_service.parameters.id.spinlock_id = (spinlockid); #else -# define STORE_SPINLOCK_ID(spinlockid) +#define STORE_SPINLOCK_ID(spinlockid) #endif /** @@ -1033,21 +1041,22 @@ tpl_service.parameters.id.spinlock_id = (spinlockid); #endif #if WITH_ORTI == YES -#define PROCESS_ERROR_ORTI(error) \ - { \ - GET_CURRENT_CORE_ID(core_id) \ - TPL_LAST_ERROR(core_id) = error; \ +#define PROCESS_ERROR_ORTI(error) \ + { \ + GET_CURRENT_CORE_ID(core_id) \ + TPL_LAST_ERROR(core_id) = error; \ } #else #define PROCESS_ERROR_ORTI(error) #endif #if (WITH_ERROR_HOOK == YES) || (WITH_ORTI == YES) -#define PROCESS_ERROR(error) \ - if ((error) != E_OK) { \ - PROCESS_ERROR_ERRHOOK(error) \ - PROCESS_ERROR_ORTI(error) \ - } +#define PROCESS_ERROR(error) \ + if ((error) != E_OK) \ + { \ + PROCESS_ERROR_ERRHOOK(error) \ + PROCESS_ERROR_ORTI(error) \ + } #else #define PROCESS_ERROR(error) #endif @@ -1090,10 +1099,9 @@ tpl_service.parameters.id.spinlock_id = (spinlockid); * @see #END_IF_NO_EXTENDED_ERROR */ #if WITH_OS_EXTENDED == YES -# define IF_NO_EXTENDED_ERROR(result) \ - if ((result) == E_OK) +#define IF_NO_EXTENDED_ERROR(result) if ((result) == E_OK) #else -# define IF_NO_EXTENDED_ERROR(result) +#define IF_NO_EXTENDED_ERROR(result) #endif /** @@ -1112,29 +1120,29 @@ tpl_service.parameters.id.spinlock_id = (spinlockid); /* No extended error checking (WITH_OS_EXTENDED == NO) */ #if WITH_OS_EXTENDED == NO - /* Does not check the task_id in this case */ -# define CHECK_TASK_ID_ERROR(task_id,result) +/* Does not check the task_id in this case */ +#define CHECK_TASK_ID_ERROR(task_id, result) #endif /* No Task and extended error checking (WITH_OS_EXTENDED == YES) */ #if (TASK_COUNT == 0) && (WITH_OS_EXTENDED == YES) - /* E_OS_ID is returned in this case */ -# define CHECK_TASK_ID_ERROR(task_id,result) \ - if (result == (tpl_status)E_OK) \ - { \ - result = (tpl_status)E_OS_ID; \ - } +/* E_OS_ID is returned in this case */ +#define CHECK_TASK_ID_ERROR(task_id, result) \ + if (result == (tpl_status)E_OK) \ + { \ + result = (tpl_status)E_OS_ID; \ + } #endif /* Any Task and extended error checking (WITH_OS_EXTENDED == YES) */ #if (TASK_COUNT > 0) && (WITH_OS_EXTENDED == YES) - /* E_OK or E_OS_LIMIT */ -# define CHECK_TASK_ID_ERROR(task_id,result) \ - if ((result == (tpl_status)E_OK) && \ - (((task_id) >= (tpl_task_id)TASK_COUNT) || ((task_id) < 0))) \ - { \ - result = (tpl_status)E_OS_ID; \ - } +/* E_OK or E_OS_LIMIT */ +#define CHECK_TASK_ID_ERROR(task_id, result) \ + if ((result == (tpl_status)E_OK) && \ + (((task_id) >= (tpl_task_id)TASK_COUNT) || ((task_id) < 0))) \ + { \ + result = (tpl_status)E_OS_ID; \ + } #endif /** @@ -1153,27 +1161,27 @@ tpl_service.parameters.id.spinlock_id = (spinlockid); /* No Task and extended error checking (WITH_OS_EXTENDED == YES). Since there is no task, there is no task level calling */ #if (TASK_COUNT == 0) && (WITH_OS_EXTENDED == YES) -# define CHECK_TASK_CALL_LEVEL_ERROR(a_core_id,result) \ - if (result == (tpl_status)E_OK) \ - { \ - result = (tpl_status)E_OS_CALLEVEL; \ - } +#define CHECK_TASK_CALL_LEVEL_ERROR(a_core_id, result) \ + if (result == (tpl_status)E_OK) \ + { \ + result = (tpl_status)E_OS_CALLEVEL; \ + } #endif /* Any Task and extended error checking (WITH_OS_EXTENDED == YES). */ #if (TASK_COUNT > 0) && (WITH_OS_EXTENDED == YES) -# define CHECK_TASK_CALL_LEVEL_ERROR(a_core_id,result) \ - if ((result == (tpl_status)E_OK) && \ - (tpl_current_os_state(CORE_ID_OR_NOTHING(a_core_id)) != \ - (tpl_os_state)OS_TASK)) \ - { \ - result = (tpl_status)E_OS_CALLEVEL; \ - } +#define CHECK_TASK_CALL_LEVEL_ERROR(a_core_id, result) \ + if ((result == (tpl_status)E_OK) && \ + (tpl_current_os_state(CORE_ID_OR_NOTHING(a_core_id)) != \ + (tpl_os_state)OS_TASK)) \ + { \ + result = (tpl_status)E_OS_CALLEVEL; \ + } #endif /* no extended error checking (WITH_OS_EXTENDED == NO). */ #if WITH_OS_EXTENDED == NO -# define CHECK_TASK_CALL_LEVEL_ERROR(a_core_id,result) +#define CHECK_TASK_CALL_LEVEL_ERROR(a_core_id, result) #endif /** @@ -1192,26 +1200,52 @@ tpl_service.parameters.id.spinlock_id = (spinlockid); /* No ISR and extended error checking (WITH_OS_EXTENDED == YES). Since there is no ISR2, there is no ISR2 level calling */ #if (ISR_COUNT == 0) && (WITH_OS_EXTENDED == YES) -# define CHECK_ISR2_CALL_LEVEL_ERROR(result,core_id) \ - if (result == (tpl_status)E_OK) \ - { \ - result = (tpl_status)E_OS_CALLEVEL; \ - } +#define CHECK_ISR2_CALL_LEVEL_ERROR(result, core_id) \ + if (result == (tpl_status)E_OK) \ + { \ + result = (tpl_status)E_OS_CALLEVEL; \ + } #endif /* Any ISR and extended error checking (WITH_OS_EXTENDED == YES). */ #if (ISR_COUNT > 0) && (WITH_OS_EXTENDED == YES) -# define CHECK_ISR2_CALL_LEVEL_ERROR(result,core_id) \ - if ((result == (tpl_status)E_OK) && \ - (tpl_current_os_state(CORE_ID_OR_NOTHING(core_id)) != (tpl_os_state)OS_ISR2)) \ - { \ - result = (tpl_status)E_OS_CALLEVEL; \ - } +#define CHECK_ISR2_CALL_LEVEL_ERROR(result, core_id) \ + if ((result == (tpl_status)E_OK) && \ + (tpl_current_os_state(CORE_ID_OR_NOTHING(core_id)) != \ + (tpl_os_state)OS_ISR2)) \ + { \ + result = (tpl_status)E_OS_CALLEVEL; \ + } #endif /* no extended error checking (WITH_OS_EXTENDED == NO). */ #if WITH_OS_EXTENDED == NO -# define CHECK_ISR2_CALL_LEVEL_ERROR(result,core_id) +#define CHECK_ISR2_CALL_LEVEL_ERROR(result, core_id) +#endif + +/** + * @def CHECK_CALLBACK_CALL_LEVEL_ERROR + * + * This macro checks for alarm callback call level errors. + * + * @param result error code variable to set (#StatusType) + * + * @note checking is disabled if WITH_OS_EXTENDED == NO + * @note the error code is set only if there was no previous error + * + * @see #tpl_os_state + */ +#if WITH_OS_EXTENDED == YES +#define CHECK_CALLBACK_CALL_LEVEL_ERROR(result, core_id) \ + if ((result == (tpl_status)E_OK) && tpl_alarm_callback_running()) \ + { \ + result = (tpl_status)E_OS_CALLEVEL; \ + } +#endif + +/* no extended error checking (WITH_OS_EXTENDED == NO). */ +#if WITH_OS_EXTENDED == NO +#define CHECK_CALLBACK_CALL_LEVEL_ERROR(result, core_id) #endif /** @@ -1227,15 +1261,14 @@ tpl_service.parameters.id.spinlock_id = (spinlockid); * @note checking is disabled when WITH_OS_EXTENDED == NO */ #if WITH_OS_EXTENDED == YES -# define CHECK_NOT_EXTENDED_TASK_ERROR(task_id,result) \ - if ((result == (tpl_status)E_OK) && \ - (tpl_stat_proc_table[task_id]->type != \ - (tpl_proc_type)TASK_EXTENDED)) \ - { \ - result = (tpl_status)E_OS_ACCESS; \ +#define CHECK_NOT_EXTENDED_TASK_ERROR(task_id, result) \ + if ((result == (tpl_status)E_OK) && \ + (tpl_stat_proc_table[task_id]->type != (tpl_proc_type)TASK_EXTENDED)) \ + { \ + result = (tpl_status)E_OS_ACCESS; \ } #else -# define CHECK_NOT_EXTENDED_TASK_ERROR(task_id,result) +#define CHECK_NOT_EXTENDED_TASK_ERROR(task_id, result) #endif /** @@ -1250,14 +1283,14 @@ tpl_service.parameters.id.spinlock_id = (spinlockid); * @note checking is disabled when WITH_OS_EXTENDED == NO */ #if WITH_OS_EXTENDED == YES -# define CHECK_NOT_EXTENDED_RUNNING_ERROR(a_core_id, result) \ - if ((result == (tpl_status)E_OK) && \ - (TPL_KERN(a_core_id).running_id >= EXTENDED_TASK_COUNT)) \ - { \ - result = (tpl_status)E_OS_ACCESS; \ +#define CHECK_NOT_EXTENDED_RUNNING_ERROR(a_core_id, result) \ + if ((result == (tpl_status)E_OK) && \ + (TPL_KERN(a_core_id).running_id >= EXTENDED_TASK_COUNT)) \ + { \ + result = (tpl_status)E_OS_ACCESS; \ } #else -# define CHECK_NOT_EXTENDED_RUNNING_ERROR(a_core_id, result) +#define CHECK_NOT_EXTENDED_RUNNING_ERROR(a_core_id, result) #endif /** @@ -1273,17 +1306,16 @@ tpl_service.parameters.id.spinlock_id = (spinlockid); * @note checking is disabled when WITH_OS_EXTENDED == NO */ #if WITH_OS_EXTENDED == YES -# define CHECK_SUSPENDED_TASK_ERROR(task_id,result) \ +#define CHECK_SUSPENDED_TASK_ERROR(task_id, result) \ if ((result == (tpl_status)E_OK) && \ - (tpl_dyn_proc_table[task_id]->state == (tpl_proc_state)SUSPENDED)) \ + (tpl_dyn_proc_table[task_id]->state == (tpl_proc_state)SUSPENDED)) \ { \ result = (tpl_status)E_OS_STATE; \ } #else -# define CHECK_SUSPENDED_TASK_ERROR(task_id,result) +#define CHECK_SUSPENDED_TASK_ERROR(task_id, result) #endif - /** * @def CHECK_RUNNING_OWNS_REZ_ERROR * @@ -1297,23 +1329,23 @@ tpl_service.parameters.id.spinlock_id = (spinlockid); /* If no Task, this error cannot happen */ #if TASK_COUNT == 0 -# define CHECK_RUNNING_OWNS_REZ_ERROR(a_core_id,result) +#define CHECK_RUNNING_OWNS_REZ_ERROR(a_core_id, result) #endif /* If any Task and not extended error checking (WITH_OS_EXTENDED == NO) the occurence is not tested */ #if (TASK_COUNT > 0) && (WITH_OS_EXTENDED == NO) -# define CHECK_RUNNING_OWNS_REZ_ERROR(a_core_id,result) +#define CHECK_RUNNING_OWNS_REZ_ERROR(a_core_id, result) #endif /* If any Task and extended error checking (WITH_OS_EXTENDED == YES) */ #if (TASK_COUNT > 0) && (WITH_OS_EXTENDED == YES) -# define CHECK_RUNNING_OWNS_REZ_ERROR(a_core_id,result) \ - if ((result == (tpl_status)E_OK) && \ - ((TPL_KERN(a_core_id).running->resources) != NULL)) \ - { \ - result = (tpl_status)E_OS_RESOURCE; \ - } +#define CHECK_RUNNING_OWNS_REZ_ERROR(a_core_id, result) \ + if ((result == (tpl_status)E_OK) && \ + ((TPL_KERN(a_core_id).running->resources) != NULL)) \ + { \ + result = (tpl_status)E_OS_RESOURCE; \ + } #endif /** @@ -1330,29 +1362,29 @@ tpl_service.parameters.id.spinlock_id = (spinlockid); /* No extended error checking (WITH_OS_EXTENDED == NO) */ #if (WITH_OS_EXTENDED == NO) - /* Does not check the task_id in this case */ -# define CHECK_ALARM_ID_ERROR(alarm_id,result) +/* Does not check the task_id in this case */ +#define CHECK_ALARM_ID_ERROR(alarm_id, result) #endif /* No Alarm and extended error checking (WITH_OS_EXTENDED == YES) */ #if (ALARM_COUNT == 0) && (WITH_OS_EXTENDED == YES) - /* E_OS_ID is returned in this case */ -# define CHECK_ALARM_ID_ERROR(alarm_id,result) \ - if (result == (tpl_status)E_OK) \ - { \ - result = (tpl_status)E_OS_ID; \ - } +/* E_OS_ID is returned in this case */ +#define CHECK_ALARM_ID_ERROR(alarm_id, result) \ + if (result == (tpl_status)E_OK) \ + { \ + result = (tpl_status)E_OS_ID; \ + } #endif /* Any Alarm and extended error checking (WITH_OS_EXTENDED == YES) */ #if (ALARM_COUNT > 0) && (WITH_OS_EXTENDED == YES) - /* E_OK or E_OS_LIMIT */ -# define CHECK_ALARM_ID_ERROR(alarm_id,result) \ - if ((result == (tpl_status)E_OK) && \ - ((alarm_id) >= (tpl_alarm_id)ALARM_COUNT)) \ - { \ - result = (tpl_status)E_OS_ID; \ - } +/* E_OK or E_OS_LIMIT */ +#define CHECK_ALARM_ID_ERROR(alarm_id, result) \ + if ((result == (tpl_status)E_OK) && \ + ((alarm_id) >= (tpl_alarm_id)ALARM_COUNT)) \ + { \ + result = (tpl_status)E_OS_ID; \ + } #endif /** @@ -1370,14 +1402,14 @@ tpl_service.parameters.id.spinlock_id = (spinlockid); /* No extended error checking (WITH_OS_EXTENDED == NO) */ #if (WITH_OS_EXTENDED == NO) - /* Does not check the task_id in this case */ -# define CHECK_ALARM_INCREMENT_ERROR(alarm_id,increment,result) +/* Does not check the task_id in this case */ +#define CHECK_ALARM_INCREMENT_ERROR(alarm_id, increment, result) #endif /* No Alarm and extended error checking (WITH_OS_EXTENDED == YES) */ #if (ALARM_COUNT == 0) && (WITH_OS_EXTENDED == YES) - /* E_OS_ID is returned in this case */ -# define CHECK_ALARM_INCREMENT_ERROR(alarm_id,increment,result) +/* E_OS_ID is returned in this case */ +#define CHECK_ALARM_INCREMENT_ERROR(alarm_id, increment, result) #endif /* @@ -1386,14 +1418,14 @@ tpl_service.parameters.id.spinlock_id = (spinlockid); */ #if (ALARM_COUNT > 0) && (WITH_OS_EXTENDED == YES) && (WITH_AUTOSAR == YES) /* E_OK or E_OS_VALUE */ -# define CHECK_ALARM_INCREMENT_ERROR(alarm_id,increment,result) \ - if ((result == (tpl_status)E_OK) && \ - (((increment) > \ - tpl_alarm_table[(alarm_id)]->stat_part->counter->max_allowed_value) \ - || ((increment) == 0) )) \ - { \ - result = (tpl_status)E_OS_VALUE; \ - } +#define CHECK_ALARM_INCREMENT_ERROR(alarm_id, increment, result) \ + if ((result == (tpl_status)E_OK) && \ + (((increment) > \ + tpl_alarm_table[(alarm_id)]->stat_part->counter->max_allowed_value) || \ + ((increment) == 0))) \ + { \ + result = (tpl_status)E_OS_VALUE; \ + } #endif /* @@ -1401,14 +1433,14 @@ tpl_service.parameters.id.spinlock_id = (spinlockid); * no AUTOSAR (WITH_AUTOSAR == NO) */ #if (ALARM_COUNT > 0) && (WITH_OS_EXTENDED == YES) && (WITH_AUTOSAR == NO) - /* E_OK or E_OS_VALUE */ -# define CHECK_ALARM_INCREMENT_ERROR(alarm_id,increment,result) \ - if ((result == (tpl_status)E_OK) && \ - (((increment) > \ - tpl_alarm_table[(alarm_id)]->stat_part->counter->max_allowed_value))) \ - { \ - result = (tpl_status)E_OS_VALUE; \ - } +/* E_OK or E_OS_VALUE */ +#define CHECK_ALARM_INCREMENT_ERROR(alarm_id, increment, result) \ + if ((result == (tpl_status)E_OK) && \ + (((increment) > \ + tpl_alarm_table[(alarm_id)]->stat_part->counter->max_allowed_value))) \ + { \ + result = (tpl_status)E_OS_VALUE; \ + } #endif /** @@ -1426,29 +1458,28 @@ tpl_service.parameters.id.spinlock_id = (spinlockid); /* No extended error checking (WITH_OS_EXTENDED == NO) */ #if (WITH_OS_EXTENDED == NO) - /* Does not check the task_id in this case */ -# define CHECK_ALARM_MIN_CYCLE_ERROR(alarm_id,cycle,result) +/* Does not check the task_id in this case */ +#define CHECK_ALARM_MIN_CYCLE_ERROR(alarm_id, cycle, result) #endif /* No Alarm and extended error checking (WITH_OS_EXTENDED == YES) */ #if (ALARM_COUNT == 0) && (WITH_OS_EXTENDED == YES) - /* E_OS_ID is returned in this case */ -# define CHECK_ALARM_MIN_CYCLE_ERROR(alarm_id,cycle,result) +/* E_OS_ID is returned in this case */ +#define CHECK_ALARM_MIN_CYCLE_ERROR(alarm_id, cycle, result) #endif /* Any Alarm and extended error checking (WITH_OS_EXTENDED == YES) */ #if (ALARM_COUNT > 0) && (WITH_OS_EXTENDED == YES) - /* E_OK or E_OS_LIMIT */ -# define CHECK_ALARM_MIN_CYCLE_ERROR(alarm_id,cycle,result) \ - if ((result == (tpl_status)E_OK) && ((cycle) != 0) && \ - (((cycle) > \ - tpl_alarm_table[(alarm_id)]->stat_part->counter->max_allowed_value) \ - || \ - ((cycle) < \ - tpl_alarm_table[(alarm_id)]->stat_part->counter->min_cycle))) \ - { \ - result = (tpl_status)E_OS_VALUE; \ - } +/* E_OK or E_OS_LIMIT */ +#define CHECK_ALARM_MIN_CYCLE_ERROR(alarm_id, cycle, result) \ + if ((result == (tpl_status)E_OK) && ((cycle) != 0) && \ + (((cycle) > \ + tpl_alarm_table[(alarm_id)]->stat_part->counter->max_allowed_value) || \ + ((cycle) < \ + tpl_alarm_table[(alarm_id)]->stat_part->counter->min_cycle))) \ + { \ + result = (tpl_status)E_OS_VALUE; \ + } #endif /** @@ -1461,14 +1492,14 @@ tpl_service.parameters.id.spinlock_id = (spinlockid); * @note error code is not set if it does not equal E_OK */ #if (WITH_OS_EXTENDED == YES) -# define CHECK_OS_NOT_STARTED(a_core_id, result) \ - if ((result == (tpl_status)E_OK) && \ - (tpl_current_os_state(CORE_ID_OR_NOTHING(a_core_id)) != OS_INIT)) \ - { \ - result = (tpl_status)E_OS_STATE; \ - } +#define CHECK_OS_NOT_STARTED(a_core_id, result) \ + if ((result == (tpl_status)E_OK) && \ + (tpl_current_os_state(CORE_ID_OR_NOTHING(a_core_id)) != OS_INIT)) \ + { \ + result = (tpl_status)E_OS_STATE; \ + } #else -# define CHECK_OS_NOT_STARTED(core_id, result) +#define CHECK_OS_NOT_STARTED(core_id, result) #endif /** @@ -1481,14 +1512,14 @@ tpl_service.parameters.id.spinlock_id = (spinlockid); * @note error code is not set if it does not equal E_OK */ #if (WITH_OS_EXTENDED == YES) -# define CHECK_STARTCORE_OS_NOT_STARTED(a_core_id, result) \ - if ((result == (tpl_status)E_OK) && \ - (tpl_current_os_state(CORE_ID_OR_NOTHING(a_core_id)) != OS_INIT)) \ - { \ - result = (tpl_status)E_OS_ACCESS; \ - } +#define CHECK_STARTCORE_OS_NOT_STARTED(a_core_id, result) \ + if ((result == (tpl_status)E_OK) && \ + (tpl_current_os_state(CORE_ID_OR_NOTHING(a_core_id)) != OS_INIT)) \ + { \ + result = (tpl_status)E_OS_ACCESS; \ + } #else -# define CHECK_STARTCORE_OS_NOT_STARTED(core_id, result) +#define CHECK_STARTCORE_OS_NOT_STARTED(core_id, result) #endif /** @@ -1505,30 +1536,30 @@ tpl_service.parameters.id.spinlock_id = (spinlockid); /* No extended error checking (WITH_OS_EXTENDED == NO) */ #if (WITH_OS_EXTENDED == NO) - /* Does not check the task_id in this case */ -# define CHECK_RESOURCE_ID_ERROR(res_id,result) +/* Does not check the task_id in this case */ +#define CHECK_RESOURCE_ID_ERROR(res_id, result) #endif /* No Resource and extended error checking (WITH_OS_EXTENDED == YES) */ #if (RESOURCE_COUNT == 0) && (WITH_OS_EXTENDED == YES) - /* E_OS_ID is returned in this case */ -# define CHECK_RESOURCE_ID_ERROR(res_id,result) \ - if ((result == (tpl_status)E_OK) && \ - ((res_id) != (tpl_resource_id)RES_SCHEDULER)) \ - { \ - result = (tpl_status)E_OS_ID; \ - } +/* E_OS_ID is returned in this case */ +#define CHECK_RESOURCE_ID_ERROR(res_id, result) \ + if ((result == (tpl_status)E_OK) && \ + ((res_id) != (tpl_resource_id)RES_SCHEDULER)) \ + { \ + result = (tpl_status)E_OS_ID; \ + } #endif /* Any Resource and extended error checking (WITH_OS_EXTENDED == YES) */ #if (RESOURCE_COUNT > 0) && (WITH_OS_EXTENDED == YES) - /* E_OK or E_OS_LIMIT */ -# define CHECK_RESOURCE_ID_ERROR(res_id,result) \ - if ((result == (tpl_status)E_OK) && \ - ((res_id) >= ((tpl_resource_id)RESOURCE_COUNT))) \ - { \ - result = (tpl_status)E_OS_ID; \ - } +/* E_OK or E_OS_LIMIT */ +#define CHECK_RESOURCE_ID_ERROR(res_id, result) \ + if ((result == (tpl_status)E_OK) && \ + ((res_id) >= ((tpl_resource_id)RESOURCE_COUNT))) \ + { \ + result = (tpl_status)E_OS_ID; \ + } #endif /** @@ -1548,16 +1579,15 @@ tpl_service.parameters.id.spinlock_id = (spinlockid); */ #if WITH_OS_EXTENDED == YES -# define CHECK_RESOURCE_PRIO_ERROR_ON_GET(core_id, res, result) \ - if ((result == (tpl_status)E_OK) && \ - (((res)->owner != INVALID_TASK) || \ - (TPL_KERN(core_id).s_running->base_priority > \ - res->ceiling_priority))) \ - { \ - result = (tpl_status)E_OS_ACCESS; \ - } +#define CHECK_RESOURCE_PRIO_ERROR_ON_GET(core_id, res, result) \ + if ((result == (tpl_status)E_OK) && \ + (((res)->owner != INVALID_TASK) || \ + (TPL_KERN(core_id).s_running->base_priority > res->ceiling_priority))) \ + { \ + result = (tpl_status)E_OS_ACCESS; \ + } #else -# define CHECK_RESOURCE_PRIO_ERROR_ON_GET(core_id, res, result) +#define CHECK_RESOURCE_PRIO_ERROR_ON_GET(core_id, res, result) #endif /** @@ -1573,15 +1603,15 @@ tpl_service.parameters.id.spinlock_id = (spinlockid); */ #if WITH_OS_EXTENDED == YES -# define CHECK_RESOURCE_PRIO_ERROR_ON_RELEASE(a_core_id, res, result) \ - if ((result == (tpl_status)E_OK) && \ - (TPL_KERN(a_core_id).s_running->base_priority > \ - (res)->ceiling_priority)) \ - { \ - result = (tpl_status)E_OS_ACCESS; \ - } +#define CHECK_RESOURCE_PRIO_ERROR_ON_RELEASE(a_core_id, res, result) \ + if ((result == (tpl_status)E_OK) && \ + (TPL_KERN(a_core_id).s_running->base_priority > \ + (res)->ceiling_priority)) \ + { \ + result = (tpl_status)E_OS_ACCESS; \ + } #else -# define CHECK_RESOURCE_PRIO_ERROR_ON_RELEASE(a_core_id, res, result) +#define CHECK_RESOURCE_PRIO_ERROR_ON_RELEASE(a_core_id, res, result) #endif /** @@ -1598,14 +1628,14 @@ tpl_service.parameters.id.spinlock_id = (spinlockid); */ #if WITH_OS_EXTENDED == YES -# define CHECK_RESOURCE_ORDER_ON_RELEASE(a_core_id, res, result) \ - if ((result == (tpl_status)E_OK) && \ - (TPL_KERN(a_core_id).running->resources != (res))) \ - { \ - result = (tpl_status)E_OS_NOFUNC; \ - } +#define CHECK_RESOURCE_ORDER_ON_RELEASE(a_core_id, res, result) \ + if ((result == (tpl_status)E_OK) && \ + (TPL_KERN(a_core_id).running->resources != (res))) \ + { \ + result = (tpl_status)E_OS_NOFUNC; \ + } #else -# define CHECK_RESOURCE_ORDER_ON_RELEASE(a_core_id, res,result) +#define CHECK_RESOURCE_ORDER_ON_RELEASE(a_core_id, res, result) #endif /** @@ -1617,11 +1647,11 @@ tpl_service.parameters.id.spinlock_id = (spinlockid); * @param result: error code returned */ -#define CHECK_INTERRUPT_LOCK(result) \ - if(FALSE!=tpl_get_interrupt_lock_status()) \ - { \ - result = E_OS_DISABLEDINT; \ - } +#define CHECK_INTERRUPT_LOCK(result) \ + if (FALSE != tpl_get_interrupt_lock_status()) \ + { \ + result = E_OS_DISABLEDINT; \ + } /** * @def CHECK_ACCESS_RIGHTS_TASK_ID @@ -1643,27 +1673,30 @@ tpl_service.parameters.id.spinlock_id = (spinlockid); */ #if (WITH_OS_EXTENDED == NO) || (WITH_OSAPPLICATION == NO) -# define CHECK_ACCESS_RIGHTS_TASK_ID(a_core_id, obj_id,result) +#define CHECK_ACCESS_RIGHTS_TASK_ID(a_core_id, obj_id, result) #elif (APP_COUNT == 0) -# define CHECK_ACCESS_RIGHTS_TASK_ID(a_core_id, obj_id,result) \ - if (result == (tpl_status)E_OK) \ - { \ - result = E_OS_ACCESS; \ +#define CHECK_ACCESS_RIGHTS_TASK_ID(a_core_id, obj_id, result) \ + if (result == (tpl_status)E_OK) \ + { \ + result = E_OS_ACCESS; \ } #else -# define CHECK_ACCESS_RIGHTS_TASK_ID(a_core_id, obj_id,result) \ - if (result == (tpl_status)E_OK) \ - { \ - CONST(uint8, AUTOMATIC) bit_shift = (obj_id & 0x7); \ - CONST(uint8, AUTOMATIC) byte_idx = obj_id >> 3; \ - extern CONSTP2CONST(tpl_app_access, AUTOMATIC, OS_APPL_CONST) tpl_app_table[APP_COUNT]; \ - CONSTP2CONST(tpl_app_access, AUTOMATIC, OS_APPL_CONST) app_access = \ - tpl_app_table[tpl_stat_proc_table[TPL_KERN(a_core_id).running_id]->app_id]; \ - if ( (((app_access->access_vec[OBJECT_TASK][byte_idx]) >> bit_shift) & 0x1)\ - == NO_ACCESS ) \ - { \ - result = E_OS_ACCESS; \ - } \ +#define CHECK_ACCESS_RIGHTS_TASK_ID(a_core_id, obj_id, result) \ + if (result == (tpl_status)E_OK) \ + { \ + CONST(uint8, AUTOMATIC) bit_shift = (obj_id & 0x7); \ + CONST(uint8, AUTOMATIC) byte_idx = obj_id >> 3; \ + extern CONSTP2CONST(tpl_app_access, AUTOMATIC, OS_APPL_CONST) \ + tpl_app_table[APP_COUNT]; \ + CONSTP2CONST(tpl_app_access, AUTOMATIC, OS_APPL_CONST) \ + app_access = \ + tpl_app_table[tpl_stat_proc_table[TPL_KERN(a_core_id).running_id] \ + ->app_id]; \ + if ((((app_access->access_vec[OBJECT_TASK][byte_idx]) >> bit_shift) & \ + 0x1) == NO_ACCESS) \ + { \ + result = E_OS_ACCESS; \ + } \ } #endif @@ -1687,28 +1720,31 @@ tpl_service.parameters.id.spinlock_id = (spinlockid); */ #if (WITH_OS_EXTENDED == NO) || (WITH_OSAPPLICATION == NO) || (ALARM_COUNT == 0) -# define CHECK_ACCESS_RIGHTS_ALARM_ID(a_core_id,obj_id,result) +#define CHECK_ACCESS_RIGHTS_ALARM_ID(a_core_id, obj_id, result) #elif (APP_COUNT == 0) -# define CHECK_ACCESS_RIGHTS_ALARM_ID(a_core_id,obj_id,result) \ - if (result == (tpl_status)E_OK) \ - { \ - result = E_OS_ACCESS; \ +#define CHECK_ACCESS_RIGHTS_ALARM_ID(a_core_id, obj_id, result) \ + if (result == (tpl_status)E_OK) \ + { \ + result = E_OS_ACCESS; \ } #else -# define CHECK_ACCESS_RIGHTS_ALARM_ID(a_core_id,obj_id,result) \ - if (result == (tpl_status)E_OK) \ - { \ - CONST(uint8, AUTOMATIC) bit_shift = (obj_id & 0x7); \ - CONST(uint8, AUTOMATIC) byte_idx = obj_id >> 3; \ - extern CONSTP2CONST(tpl_app_access, AUTOMATIC, OS_APPL_CONST) tpl_app_table[APP_COUNT]; \ - CONSTP2CONST(tpl_app_access, AUTOMATIC, OS_APPL_CONST) app_access = \ - tpl_app_table[tpl_stat_proc_table[TPL_KERN(a_core_id).running_id]->app_id]; \ - if ( (((app_access->access_vec[OBJECT_ALARM][byte_idx]) >> bit_shift) & 0x1) \ - == NO_ACCESS ) \ - { \ - result = E_OS_ACCESS; \ - } \ - } +#define CHECK_ACCESS_RIGHTS_ALARM_ID(a_core_id, obj_id, result) \ + if (result == (tpl_status)E_OK) \ + { \ + CONST(uint8, AUTOMATIC) bit_shift = (obj_id & 0x7); \ + CONST(uint8, AUTOMATIC) byte_idx = obj_id >> 3; \ + extern CONSTP2CONST(tpl_app_access, AUTOMATIC, OS_APPL_CONST) \ + tpl_app_table[APP_COUNT]; \ + CONSTP2CONST(tpl_app_access, AUTOMATIC, OS_APPL_CONST) \ + app_access = \ + tpl_app_table[tpl_stat_proc_table[TPL_KERN(a_core_id).running_id] \ + ->app_id]; \ + if ((((app_access->access_vec[OBJECT_ALARM][byte_idx]) >> bit_shift) & \ + 0x1) == NO_ACCESS) \ + { \ + result = E_OS_ACCESS; \ + } \ + } #endif /** @@ -1731,29 +1767,31 @@ tpl_service.parameters.id.spinlock_id = (spinlockid); */ #if ((WITH_OS_EXTENDED == NO)) || (WITH_OSAPPLICATION == NO) -# define CHECK_ACCESS_RIGHTS_RESOURCE_ID(a_core_id, obj_id,result) +#define CHECK_ACCESS_RIGHTS_RESOURCE_ID(a_core_id, obj_id, result) #elif (APP_COUNT == 0) -# define CHECK_ACCESS_RIGHTS_RESOURCE_ID(a_core_id, obj_id,result) \ - if (result == (tpl_status)E_OK) \ - { \ - result = E_OS_ACCESS; \ +#define CHECK_ACCESS_RIGHTS_RESOURCE_ID(a_core_id, obj_id, result) \ + if (result == (tpl_status)E_OK) \ + { \ + result = E_OS_ACCESS; \ } #else -# define CHECK_ACCESS_RIGHTS_RESOURCE_ID(a_core_id, obj_id,result) \ - if (result == (tpl_status)E_OK) \ - { \ - CONST(uint8, AUTOMATIC) bit_shift = (obj_id & 0x7); \ - CONST(uint8, AUTOMATIC) byte_idx = obj_id >> 3; \ - extern CONSTP2CONST(tpl_app_access, AUTOMATIC, OS_APPL_CONST) \ - tpl_app_table[APP_COUNT]; \ - CONSTP2CONST(tpl_app_access, AUTOMATIC, OS_APPL_CONST) app_access = \ - tpl_app_table[tpl_stat_proc_table[TPL_KERN(a_core_id).running_id]->app_id]; \ - if ( (((app_access->access_vec[OBJECT_RESOURCE][byte_idx]) >> bit_shift) & 0x1) \ - == NO_ACCESS ) \ - { \ - result = E_OS_ACCESS; \ - } \ - } +#define CHECK_ACCESS_RIGHTS_RESOURCE_ID(a_core_id, obj_id, result) \ + if (result == (tpl_status)E_OK) \ + { \ + CONST(uint8, AUTOMATIC) bit_shift = (obj_id & 0x7); \ + CONST(uint8, AUTOMATIC) byte_idx = obj_id >> 3; \ + extern CONSTP2CONST(tpl_app_access, AUTOMATIC, OS_APPL_CONST) \ + tpl_app_table[APP_COUNT]; \ + CONSTP2CONST(tpl_app_access, AUTOMATIC, OS_APPL_CONST) \ + app_access = \ + tpl_app_table[tpl_stat_proc_table[TPL_KERN(a_core_id).running_id] \ + ->app_id]; \ + if ((((app_access->access_vec[OBJECT_RESOURCE][byte_idx]) >> bit_shift) & \ + 0x1) == NO_ACCESS) \ + { \ + result = E_OS_ACCESS; \ + } \ + } #endif /** @@ -1775,29 +1813,33 @@ tpl_service.parameters.id.spinlock_id = (spinlockid); * @note checking is disable when WITH_OS_EXTENDED == NO */ -#if ((WITH_OS_EXTENDED == NO)) || (WITH_OSAPPLICATION == NO) || (COUNTER_COUNT == 0) -# define CHECK_ACCESS_RIGHTS_COUNTER_ID(a_core_id, obj_id, result) +#if ((WITH_OS_EXTENDED == NO)) || (WITH_OSAPPLICATION == NO) || \ + (COUNTER_COUNT == 0) +#define CHECK_ACCESS_RIGHTS_COUNTER_ID(a_core_id, obj_id, result) #elif (APP_COUNT == 0) -# define CHECK_ACCESS_RIGHTS_COUNTER_ID(a_core_id, obj_id, result) \ - if( result == (tpl_status)E_OK ) \ - { \ - result = E_OS_ACCESS; \ +#define CHECK_ACCESS_RIGHTS_COUNTER_ID(a_core_id, obj_id, result) \ + if (result == (tpl_status)E_OK) \ + { \ + result = E_OS_ACCESS; \ } #else -# define CHECK_ACCESS_RIGHTS_COUNTER_ID(a_core_id, obj_id, result) \ - if( result == (tpl_status)E_OK ) \ - { \ - CONST(uint8, AUTOMATIC) bit_shift = (obj_id & 0x7); \ - CONST(uint8, AUTOMATIC) byte_idx = obj_id >> 3; \ - extern CONSTP2CONST(tpl_app_access, AUTOMATIC, OS_APPL_CONST) tpl_app_table[APP_COUNT]; \ - CONSTP2CONST(tpl_app_access, AUTOMATIC, OS_APPL_CONST) app_access = \ - tpl_app_table[tpl_stat_proc_table[TPL_KERN(a_core_id).running_id]->app_id]; \ - if ( (((app_access->access_vec[OBJECT_COUNTER][byte_idx]) >> bit_shift) & 0x1) \ - == NO_ACCESS ) \ - { \ - result = E_OS_ACCESS; \ - } \ - } +#define CHECK_ACCESS_RIGHTS_COUNTER_ID(a_core_id, obj_id, result) \ + if (result == (tpl_status)E_OK) \ + { \ + CONST(uint8, AUTOMATIC) bit_shift = (obj_id & 0x7); \ + CONST(uint8, AUTOMATIC) byte_idx = obj_id >> 3; \ + extern CONSTP2CONST(tpl_app_access, AUTOMATIC, OS_APPL_CONST) \ + tpl_app_table[APP_COUNT]; \ + CONSTP2CONST(tpl_app_access, AUTOMATIC, OS_APPL_CONST) \ + app_access = \ + tpl_app_table[tpl_stat_proc_table[TPL_KERN(a_core_id).running_id] \ + ->app_id]; \ + if ((((app_access->access_vec[OBJECT_COUNTER][byte_idx]) >> bit_shift) & \ + 0x1) == NO_ACCESS) \ + { \ + result = E_OS_ACCESS; \ + } \ + } #endif /** @@ -1819,28 +1861,33 @@ tpl_service.parameters.id.spinlock_id = (spinlockid); * @note checking is disable when WITH_OS_EXTENDED == NO */ -#if (WITH_OS_EXTENDED == NO) || (WITH_OSAPPLICATION == NO) || (SCHEDTABLE_COUNT == 0) -# define CHECK_ACCESS_RIGHTS_SCHEDULETABLE_ID(a_core_id,obj_id,result) +#if (WITH_OS_EXTENDED == NO) || (WITH_OSAPPLICATION == NO) || \ + (SCHEDTABLE_COUNT == 0) +#define CHECK_ACCESS_RIGHTS_SCHEDULETABLE_ID(a_core_id, obj_id, result) #elif (APP_COUNT == 0) -# define CHECK_ACCESS_RIGHTS_SCHEDULETABLE_ID(a_core_id,obj_id,result) \ - if(result == (tpl_status)E_OK) \ - { \ - result = E_OS_ACCESS; \ +#define CHECK_ACCESS_RIGHTS_SCHEDULETABLE_ID(a_core_id, obj_id, result) \ + if (result == (tpl_status)E_OK) \ + { \ + result = E_OS_ACCESS; \ } #else -# define CHECK_ACCESS_RIGHTS_SCHEDULETABLE_ID(a_core_id,obj_id,result) \ - if( result == (tpl_status)E_OK ) \ - { \ - CONST(uint8, AUTOMATIC) bit_shift = (obj_id & 0x7); \ - CONST(uint8, AUTOMATIC) byte_idx = obj_id >> 3; \ - extern CONSTP2CONST(tpl_app_access, AUTOMATIC, OS_APPL_CONST) tpl_app_table[APP_COUNT]; \ - CONSTP2CONST(tpl_app_access, AUTOMATIC, OS_APPL_CONST) app_access = \ - tpl_app_table[tpl_stat_proc_table[TPL_KERN(a_core_id).running_id]->app_id]; \ - if ( (((app_access->access_vec[OBJECT_SCHEDULETABLE][byte_idx]) >> bit_shift) & 0x1)\ - == NO_ACCESS ) \ - { \ - result = E_OS_ACCESS; \ - } \ +#define CHECK_ACCESS_RIGHTS_SCHEDULETABLE_ID(a_core_id, obj_id, result) \ + if (result == (tpl_status)E_OK) \ + { \ + CONST(uint8, AUTOMATIC) bit_shift = (obj_id & 0x7); \ + CONST(uint8, AUTOMATIC) byte_idx = obj_id >> 3; \ + extern CONSTP2CONST(tpl_app_access, AUTOMATIC, OS_APPL_CONST) \ + tpl_app_table[APP_COUNT]; \ + CONSTP2CONST(tpl_app_access, AUTOMATIC, OS_APPL_CONST) \ + app_access = \ + tpl_app_table[tpl_stat_proc_table[TPL_KERN(a_core_id).running_id] \ + ->app_id]; \ + if ((((app_access->access_vec[OBJECT_SCHEDULETABLE][byte_idx]) >> \ + bit_shift) & \ + 0x1) == NO_ACCESS) \ + { \ + result = E_OS_ACCESS; \ + } \ } #endif @@ -1864,27 +1911,30 @@ tpl_service.parameters.id.spinlock_id = (spinlockid); */ #if (WITH_OS_EXTENDED == NO) || (WITH_OSAPPLICATION == NO) -# define CHECK_ACCESS_RIGHTS_SPINLOCK_ID(a_core_id, obj_id,result) +#define CHECK_ACCESS_RIGHTS_SPINLOCK_ID(a_core_id, obj_id, result) #elif (APP_COUNT == 0) -# define CHECK_ACCESS_RIGHTS_SPINLOCK_ID(a_core_id, obj_id,result) \ - if (result == (tpl_status)E_OK) \ - { \ - result = E_OS_ACCESS; \ +#define CHECK_ACCESS_RIGHTS_SPINLOCK_ID(a_core_id, obj_id, result) \ + if (result == (tpl_status)E_OK) \ + { \ + result = E_OS_ACCESS; \ } #else -# define CHECK_ACCESS_RIGHTS_SPINLOCK_ID(a_core_id, obj_id,result) \ - if (result == (tpl_status)E_OK) \ - { \ - CONST(uint8, AUTOMATIC) bit_shift = (obj_id & 0x7); \ - CONST(uint8, AUTOMATIC) byte_idx = obj_id >> 3; \ - extern CONSTP2CONST(tpl_app_access, AUTOMATIC, OS_APPL_CONST) tpl_app_table[APP_COUNT]; \ - CONSTP2CONST(tpl_app_access, AUTOMATIC, OS_APPL_CONST) app_access = \ - tpl_app_table[tpl_stat_proc_table[TPL_KERN(a_core_id).running_id]->app_id]; \ - if ( (((app_access->access_vec[OBJECT_SPINLOCK][byte_idx]) >> bit_shift) & 0x1) \ - == NO_ACCESS ) \ - { \ - result = E_OS_ACCESS; \ - } \ +#define CHECK_ACCESS_RIGHTS_SPINLOCK_ID(a_core_id, obj_id, result) \ + if (result == (tpl_status)E_OK) \ + { \ + CONST(uint8, AUTOMATIC) bit_shift = (obj_id & 0x7); \ + CONST(uint8, AUTOMATIC) byte_idx = obj_id >> 3; \ + extern CONSTP2CONST(tpl_app_access, AUTOMATIC, OS_APPL_CONST) \ + tpl_app_table[APP_COUNT]; \ + CONSTP2CONST(tpl_app_access, AUTOMATIC, OS_APPL_CONST) \ + app_access = \ + tpl_app_table[tpl_stat_proc_table[TPL_KERN(a_core_id).running_id] \ + ->app_id]; \ + if ((((app_access->access_vec[OBJECT_SPINLOCK][byte_idx]) >> bit_shift) & \ + 0x1) == NO_ACCESS) \ + { \ + result = E_OS_ACCESS; \ + } \ } #endif @@ -1898,8 +1948,9 @@ tpl_service.parameters.id.spinlock_id = (spinlockid); * @param loc_ptr the start address of the location * @param loc_size the size of the location */ -#define LOCATION_WITHIN(mem_region, loc_ptr) \ - (((void *)(loc_ptr) < mem_region.start) || ((void *)((loc_ptr) + (1)) > mem_region.end)) +#define LOCATION_WITHIN(mem_region, loc_ptr) \ + (((void *)(loc_ptr) < mem_region.start) || \ + ((void *)((loc_ptr) + (1)) > mem_region.end)) /** * @def CHECK_DATA_LOCATION * @@ -1915,39 +1966,37 @@ tpl_service.parameters.id.spinlock_id = (spinlockid); * @note checking is disabled when WITH_MEMORY_PROTECTION == NO */ #if (WITH_MEMORY_PROTECTION == NO) -# define CHECK_DATA_LOCATION(a_core_id,data_ptr, result) +#define CHECK_DATA_LOCATION(a_core_id, data_ptr, result) #elif (WITH_MEMORY_PROTECTION == YES) && (WITH_AUTOSAR == NO) -# define CHECK_DATA_LOCATION(a_core_id,data_ptr, result) \ - if (result == (tpl_status)E_OK) \ - { \ - CONSTP2CONST(tpl_mem_prot_desc, AUTOMATIC, OS_CONST) mp_desc = \ - tpl_mp_table[TPL_KERN(a_core_id).running_id]; \ +#define CHECK_DATA_LOCATION(a_core_id, data_ptr, result) \ + if (result == (tpl_status)E_OK) \ + { \ + CONSTP2CONST(tpl_mem_prot_desc, AUTOMATIC, OS_CONST) \ + mp_desc = tpl_mp_table[TPL_KERN(a_core_id).running_id]; \ if (TPL_KERN(a_core_id).running_trusted == 0) \ - { \ - if (LOCATION_WITHIN(mp_desc->proc_var, data_ptr) && \ - LOCATION_WITHIN(mp_desc->proc_stack, data_ptr) \ - ) \ - { \ - result = E_OS_PROTECTION_MEMORY; \ - } \ - } \ + { \ + if (LOCATION_WITHIN(mp_desc->proc_var, data_ptr) && \ + LOCATION_WITHIN(mp_desc->proc_stack, data_ptr)) \ + { \ + result = E_OS_PROTECTION_MEMORY; \ + } \ + } \ } #elif (WITH_MEMORY_PROTECTION == YES) && (WITH_AUTOSAR == YES) -# define CHECK_DATA_LOCATION(a_core_id, data_ptr, result) \ - if (result == (tpl_status)E_OK) \ - { \ - CONSTP2CONST(tpl_mem_prot_desc, AUTOMATIC, OS_CONST) mp_desc = \ - tpl_mp_table[TPL_KERN(a_core_id).running_id]; \ +#define CHECK_DATA_LOCATION(a_core_id, data_ptr, result) \ + if (result == (tpl_status)E_OK) \ + { \ + CONSTP2CONST(tpl_mem_prot_desc, AUTOMATIC, OS_CONST) \ + mp_desc = tpl_mp_table[TPL_KERN(a_core_id).running_id]; \ if (TPL_KERN(a_core_id).running_trusted == 0) \ - { \ - if (LOCATION_WITHIN(mp_desc->proc_var, data_ptr) && \ - LOCATION_WITHIN(mp_desc->proc_stack, data_ptr) && \ - LOCATION_WITHIN(mp_desc->osap_var, data_ptr) \ - ) \ - { \ - result = E_OS_PROTECTION_MEMORY; \ - } \ - } \ + { \ + if (LOCATION_WITHIN(mp_desc->proc_var, data_ptr) && \ + LOCATION_WITHIN(mp_desc->proc_stack, data_ptr) && \ + LOCATION_WITHIN(mp_desc->osap_var, data_ptr)) \ + { \ + result = E_OS_PROTECTION_MEMORY; \ + } \ + } \ } #endif @@ -1969,28 +2018,27 @@ tpl_service.parameters.id.spinlock_id = (spinlockid); /* No extended error checking (WITH_OS_EXTENDED == NO) */ #if WITH_OS_EXTENDED == NO /* Does not check the task_id in this case */ -# define CHECK_IOC_ID_ERROR(ioc_id,result) +#define CHECK_IOC_ID_ERROR(ioc_id, result) #endif /* No Task and extended error checking (WITH_OS_EXTENDED == YES) */ #if (IOC_COUNT == 0) && (WITH_OS_EXTENDED == YES) /* E_OS_ID is returned in this case */ -# define CHECK_IOC_ID_ERROR(ioc_id,result) \ -if (result == (tpl_status)E_OK) \ -{ \ -result = (tpl_status)E_OS_ID; \ -} +#define CHECK_IOC_ID_ERROR(ioc_id, result) \ + if (result == (tpl_status)E_OK) \ + { \ + result = (tpl_status)E_OS_ID; \ + } #endif /* Any Ioc and extended error checking (WITH_OS_EXTENDED == YES) */ #if (IOC_COUNT > 0) && (WITH_OS_EXTENDED == YES) /* E_OK or E_OS_LIMIT */ -# define CHECK_IOC_ID_ERROR(ioc_id,result) \ -if ((result == (tpl_status)E_OK) && \ -(ioc_id >= (tpl_ioc_id)IOC_COUNT)) \ -{ \ -result = (tpl_status)E_OS_ID; \ -} +#define CHECK_IOC_ID_ERROR(ioc_id, result) \ + if ((result == (tpl_status)E_OK) && (ioc_id >= (tpl_ioc_id)IOC_COUNT)) \ + { \ + result = (tpl_status)E_OS_ID; \ + } #endif /** @@ -2007,27 +2055,31 @@ result = (tpl_status)E_OS_ID; \ * @note checking is disable when WITH_OS_EXTENDED == NO */ #if (WITH_OS_EXTENDED == NO) || (WITH_IOC == NO) -# define CHECK_ACCESS_WRITE_IOC_ID(a_core_id,obj_id,result) +#define CHECK_ACCESS_WRITE_IOC_ID(a_core_id, obj_id, result) #elif (APP_COUNT == 0) -# define CHECK_ACCESS_WRITE_IOC_ID(a_core_id,obj_id,result) \ -if (result == IOC_E_OK) \ -{ \ -result = E_OS_ACCESS; \ -} +#define CHECK_ACCESS_WRITE_IOC_ID(a_core_id, obj_id, result) \ + if (result == IOC_E_OK) \ + { \ + result = E_OS_ACCESS; \ + } #else -# define CHECK_ACCESS_WRITE_IOC_ID(a_core_id,obj_id,result) \ - if (result == (tpl_status)E_OK) \ - { \ - CONST(uint8, AUTOMATIC) bit_shift = (obj_id & 0x7); \ - CONST(uint8, AUTOMATIC) byte_idx = obj_id >> 3; \ - extern CONSTP2CONST(tpl_app_access, AUTOMATIC, OS_APPL_CONST) tpl_app_table[APP_COUNT]; \ - CONSTP2CONST(tpl_app_access, AUTOMATIC, OS_APPL_CONST) app_access = \ - tpl_app_table[tpl_stat_proc_table[TPL_KERN(a_core_id).running_id]->app_id]; \ - if ( (((app_access->access_vec[OBJECT_IOC_SENDER][byte_idx]) >> bit_shift) & 0x1) \ - == NO_ACCESS ) \ - { \ - result = E_OS_ACCESS; \ - } \ +#define CHECK_ACCESS_WRITE_IOC_ID(a_core_id, obj_id, result) \ + if (result == (tpl_status)E_OK) \ + { \ + CONST(uint8, AUTOMATIC) bit_shift = (obj_id & 0x7); \ + CONST(uint8, AUTOMATIC) byte_idx = obj_id >> 3; \ + extern CONSTP2CONST(tpl_app_access, AUTOMATIC, OS_APPL_CONST) \ + tpl_app_table[APP_COUNT]; \ + CONSTP2CONST(tpl_app_access, AUTOMATIC, OS_APPL_CONST) \ + app_access = \ + tpl_app_table[tpl_stat_proc_table[TPL_KERN(a_core_id).running_id] \ + ->app_id]; \ + if ((((app_access->access_vec[OBJECT_IOC_SENDER][byte_idx]) >> \ + bit_shift) & \ + 0x1) == NO_ACCESS) \ + { \ + result = E_OS_ACCESS; \ + } \ } #endif @@ -2045,27 +2097,31 @@ result = E_OS_ACCESS; \ * @note checking is disable when WITH_OS_EXTENDED == NO */ #if (WITH_OS_EXTENDED == NO) || (WITH_IOC == NO) -# define CHECK_ACCESS_READ_IOC_ID(a_core_id,obj_id,result) +#define CHECK_ACCESS_READ_IOC_ID(a_core_id, obj_id, result) #elif (APP_COUNT == 0) -# define CHECK_ACCESS_READ_IOC_ID(a_core_id,obj_id,result) \ -if (result == IOC_E_OK) \ -{ \ -result = E_OS_ACCESS; \ -} +#define CHECK_ACCESS_READ_IOC_ID(a_core_id, obj_id, result) \ + if (result == IOC_E_OK) \ + { \ + result = E_OS_ACCESS; \ + } #else -# define CHECK_ACCESS_READ_IOC_ID(a_core_id,obj_id,result) \ - if (result == (tpl_status)E_OK) \ - { \ - CONST(uint8, AUTOMATIC) bit_shift = (obj_id & 0x7); \ - CONST(uint8, AUTOMATIC) byte_idx = obj_id >> 3; \ - extern CONSTP2CONST(tpl_app_access, AUTOMATIC, OS_APPL_CONST) tpl_app_table[APP_COUNT]; \ - CONSTP2CONST(tpl_app_access, AUTOMATIC, OS_APPL_CONST) app_access = \ - tpl_app_table[tpl_stat_proc_table[TPL_KERN(a_core_id).running_id]->app_id]; \ - if ( (((app_access->access_vec[OBJECT_IOC_RECEIVER][byte_idx]) >> bit_shift) & 0x1) \ - == NO_ACCESS ) \ - { \ - result = E_OS_ACCESS; \ - } \ +#define CHECK_ACCESS_READ_IOC_ID(a_core_id, obj_id, result) \ + if (result == (tpl_status)E_OK) \ + { \ + CONST(uint8, AUTOMATIC) bit_shift = (obj_id & 0x7); \ + CONST(uint8, AUTOMATIC) byte_idx = obj_id >> 3; \ + extern CONSTP2CONST(tpl_app_access, AUTOMATIC, OS_APPL_CONST) \ + tpl_app_table[APP_COUNT]; \ + CONSTP2CONST(tpl_app_access, AUTOMATIC, OS_APPL_CONST) \ + app_access = \ + tpl_app_table[tpl_stat_proc_table[TPL_KERN(a_core_id).running_id] \ + ->app_id]; \ + if ((((app_access->access_vec[OBJECT_IOC_RECEIVER][byte_idx]) >> \ + bit_shift) & \ + 0x1) == NO_ACCESS) \ + { \ + result = E_OS_ACCESS; \ + } \ } #endif @@ -2078,13 +2134,13 @@ result = E_OS_ACCESS; \ * having an occupied lock */ #if (WITH_OS_EXTENDED == YES) && (WITH_AUTOSAR == YES) && (SPINLOCK_COUNT > 0) -# define CHECK_SCHEDULE_WHILE_OCCUPED_SPINLOCK(a_core_id, a_result) \ - if (((a_result) == E_OK) && (HAS_SPINLOCK(a_core_id))) \ - { \ - result = E_OS_SPINLOCK; \ - } +#define CHECK_SCHEDULE_WHILE_OCCUPED_SPINLOCK(a_core_id, a_result) \ + if (((a_result) == E_OK) && (HAS_SPINLOCK(a_core_id))) \ + { \ + result = E_OS_SPINLOCK; \ + } #else -# define CHECK_SCHEDULE_WHILE_OCCUPED_SPINLOCK(a_core_id, a_result) +#define CHECK_SCHEDULE_WHILE_OCCUPED_SPINLOCK(a_core_id, a_result) #endif /** @@ -2093,13 +2149,13 @@ result = E_OS_ACCESS; \ * This macro checks the core_id is within 0 .. NUMBER_OF_CORES - 1 */ #if (WITH_OS_EXTENDED == YES) && (NUMBER_OF_CORES > 1) -# define CHECK_CORE_ID_ERROR(a_core_id, a_result) \ - if (((a_result) == E_OK) && ((a_core_id) >= NUMBER_OF_CORES)) \ - { \ - result = E_OS_ID; \ - } +#define CHECK_CORE_ID_ERROR(a_core_id, a_result) \ + if (((a_result) == E_OK) && ((a_core_id) >= NUMBER_OF_CORES)) \ + { \ + result = E_OS_ID; \ + } #else -# define CHECK_CORE_ID_ERROR(a_core_id, a_result) +#define CHECK_CORE_ID_ERROR(a_core_id, a_result) #endif /** @@ -2108,13 +2164,13 @@ result = E_OS_ACCESS; \ * This macro checks the core is not already started */ #if (WITH_OS_EXTENDED == YES) && (NUMBER_OF_CORES > 1) -# define CHECK_START_CORE_ERROR(a_core_id, a_result) \ - if (((a_result) == E_OK) && (tpl_core_status[a_core_id] != STOPPED_CORE)) \ - { \ - result = E_OS_STATE; \ - } +#define CHECK_START_CORE_ERROR(a_core_id, a_result) \ + if (((a_result) == E_OK) && (tpl_core_status[a_core_id] != STOPPED_CORE)) \ + { \ + result = E_OS_STATE; \ + } #else -# define CHECK_START_CORE_ERROR(a_core_id, a_result) +#define CHECK_START_CORE_ERROR(a_core_id, a_result) #endif /** @@ -2123,8 +2179,6 @@ result = E_OS_ACCESS; \ * This macro checks the os is not already started */ - - #endif /*TPL_OS_ERROR_H */ /* End of file tpl_os_error.h */ diff --git a/os/tpl_os_event_kernel.c b/os/tpl_os_event_kernel.c index a03993897..b86726d5e 100644 --- a/os/tpl_os_event_kernel.c +++ b/os/tpl_os_event_kernel.c @@ -9,8 +9,8 @@ * * Trampoline RTOS * - * Trampoline is copyright (c) CNRS, University of Nantes, Ecole Centrale de Nantes - * Trampoline is protected by the French intellectual property law. + * Trampoline is copyright (c) CNRS, University of Nantes, Ecole Centrale de + * Nantes Trampoline is protected by the French intellectual property law. * * This software is distributed under the GNU Public Licence V2. * Check the LICENSE file in the root directory of Trampoline @@ -23,19 +23,19 @@ * $URL$ */ +#include "tpl_machine_interface.h" #include "tpl_os_definitions.h" #include "tpl_os_error.h" #include "tpl_os_errorhook.h" #include "tpl_os_kernel.h" #include "tpl_os_task_kernel.h" -#include "tpl_machine_interface.h" #include "tpl_trace.h" #if WITH_AUTOSAR == YES #include "tpl_as_isr_kernel.h" #include "tpl_as_protec_hook.h" #if SPINLOCK_COUNT > 0 -# include "tpl_as_spinlock_kernel.h" +#include "tpl_as_spinlock_kernel.h" #endif #endif @@ -51,9 +51,9 @@ /* * tpl_set_event_service. */ -FUNC(tpl_status, OS_CODE) tpl_set_event_service( - CONST(tpl_task_id, AUTOMATIC) task_id, - CONST(tpl_event_mask, AUTOMATIC) event) +FUNC(tpl_status, OS_CODE) +tpl_set_event_service(CONST(tpl_task_id, AUTOMATIC) task_id, + CONST(tpl_event_mask, AUTOMATIC) event) { GET_CURRENT_CORE_ID(core_id) GET_PROC_CORE_ID(task_id, proc_core_id) @@ -69,15 +69,18 @@ FUNC(tpl_status, OS_CODE) tpl_set_event_service( STORE_TASK_ID(task_id) STORE_EVENT_MASK(event) - CHECK_TASK_ID_ERROR(task_id,result) + /* Check call level error: forbidden from an alarm callback */ + CHECK_CALLBACK_CALL_LEVEL_ERROR(result, core_id) + + CHECK_TASK_ID_ERROR(task_id, result) /* check access right */ - CHECK_ACCESS_RIGHTS_TASK_ID(core_id, task_id,result) + CHECK_ACCESS_RIGHTS_TASK_ID(core_id, task_id, result) /* checks the task is an extended one */ - CHECK_NOT_EXTENDED_TASK_ERROR(task_id,result) + CHECK_NOT_EXTENDED_TASK_ERROR(task_id, result) /* checks the task is not in the SUSPENDED state */ - CHECK_SUSPENDED_TASK_ERROR(task_id,result) + CHECK_SUSPENDED_TASK_ERROR(task_id, result) #if EXTENDED_TASK_COUNT > 0 IF_NO_EXTENDED_ERROR(result) @@ -98,12 +101,11 @@ FUNC(tpl_status, OS_CODE) tpl_set_event_service( return result; } - /* * tpl_clear_event_service */ -FUNC(tpl_status, OS_CODE) tpl_clear_event_service( - CONST(tpl_event_mask, AUTOMATIC) event) +FUNC(tpl_status, OS_CODE) +tpl_clear_event_service(CONST(tpl_event_mask, AUTOMATIC) event) { GET_CURRENT_CORE_ID(core_id) @@ -118,7 +120,7 @@ FUNC(tpl_status, OS_CODE) tpl_clear_event_service( STORE_EVENT_MASK(event) /* ClearEvent cannot be called from ISR level */ - CHECK_TASK_CALL_LEVEL_ERROR(core_id,result) + CHECK_TASK_CALL_LEVEL_ERROR(core_id, result) /* checks the calling task is an extended one */ CHECK_NOT_EXTENDED_RUNNING_ERROR(core_id, result) @@ -126,7 +128,7 @@ FUNC(tpl_status, OS_CODE) tpl_clear_event_service( IF_NO_EXTENDED_ERROR(result) { tpl_task_events_table[(tpl_proc_id)TPL_KERN(core_id).running_id]->evt_set &= - (tpl_event_mask)(~event); + (tpl_event_mask)(~event); TRACE_EVENT_RESET(event) } #endif @@ -141,9 +143,9 @@ FUNC(tpl_status, OS_CODE) tpl_clear_event_service( /* * tpl_get_event_service */ -FUNC(tpl_status, OS_CODE) tpl_get_event_service( - CONST(tpl_task_id, AUTOMATIC) task_id, - CONSTP2VAR(tpl_event_mask, AUTOMATIC, OS_APPL_DATA) event) +FUNC(tpl_status, OS_CODE) +tpl_get_event_service(CONST(tpl_task_id, AUTOMATIC) task_id, + CONSTP2VAR(tpl_event_mask, AUTOMATIC, OS_APPL_DATA) event) { GET_CURRENT_CORE_ID(core_id) @@ -158,15 +160,18 @@ FUNC(tpl_status, OS_CODE) tpl_get_event_service( STORE_TASK_ID(task_id) STORE_EVENT_MASK_REF(event) - CHECK_TASK_ID_ERROR(task_id,result) + /* Check call level error: forbidden from an alarm callback */ + CHECK_CALLBACK_CALL_LEVEL_ERROR(result, core_id) + + CHECK_TASK_ID_ERROR(task_id, result) /* check access right */ CHECK_ACCESS_RIGHTS_TASK_ID(core_id, task_id, result) /* checks the task is an extended one */ - CHECK_NOT_EXTENDED_TASK_ERROR(task_id,result) + CHECK_NOT_EXTENDED_TASK_ERROR(task_id, result) /* checks the task is not in the SUSPENDED state */ - CHECK_SUSPENDED_TASK_ERROR(task_id,result) + CHECK_SUSPENDED_TASK_ERROR(task_id, result) /* check event is in an authorized memory region */ CHECK_DATA_LOCATION(core_id, event, result); @@ -188,8 +193,8 @@ FUNC(tpl_status, OS_CODE) tpl_get_event_service( /* * tpl_wait_event_service */ -FUNC(tpl_status, OS_CODE) tpl_wait_event_service( - CONST(tpl_event_mask, AUTOMATIC) event) +FUNC(tpl_status, OS_CODE) +tpl_wait_event_service(CONST(tpl_event_mask, AUTOMATIC) event) { GET_CURRENT_CORE_ID(core_id) GET_TPL_KERN_FOR_CORE_ID(core_id, kern) @@ -197,8 +202,8 @@ FUNC(tpl_status, OS_CODE) tpl_wait_event_service( VAR(tpl_status, AUTOMATIC) result = E_OK; /* event mask of the caller */ - CONSTP2VAR(tpl_task_events, AUTOMATIC, OS_VAR) task_events = - tpl_task_events_table[TPL_KERN_REF(kern).running_id]; + CONSTP2VAR(tpl_task_events, AUTOMATIC, OS_VAR) + task_events = tpl_task_events_table[TPL_KERN_REF(kern).running_id]; LOCK_KERNEL() @@ -209,7 +214,7 @@ FUNC(tpl_status, OS_CODE) tpl_wait_event_service( STORE_EVENT_MASK(event) /* WaitEvent cannot be called from ISR level */ - CHECK_TASK_CALL_LEVEL_ERROR(core_id,result) + CHECK_TASK_CALL_LEVEL_ERROR(core_id, result) /* checks the calling task is an extended one */ CHECK_NOT_EXTENDED_RUNNING_ERROR(core_id, result) /* checks the task does not occupy resource(s) */ diff --git a/os/tpl_os_kernel.c b/os/tpl_os_kernel.c index 05bf1b438..5a223c253 100644 --- a/os/tpl_os_kernel.c +++ b/os/tpl_os_kernel.c @@ -149,8 +149,51 @@ INTERNAL_RES_SCHEDULER = { #define OS_STOP_SEC_VAR_UNSPECIFIED #include "tpl_memmap.h" +#define OS_START_SEC_VAR_BOOLEAN +#include "tpl_memmap.h" +/* + * alarm_callback_running is true if the current triggered alarm is running + * a callback routine and false otherwise. + */ +STATIC VAR(tpl_bool, OS_VAR) alarm_callback_running = FALSE; +#define OS_STOP_SEC_VAR_BOOLEAN +#include "tpl_memmap.h" + #define OS_START_SEC_CODE #include "tpl_memmap.h" +/* + * @internal + * + * tpl_begin_alarm_callback sets alarm_callback_running to TRUE. It is called + * from tpl_action_callback function (see tpl_os_action.c file) + */ +FUNC(void, OS_CODE) tpl_begin_alarm_callback(void) +{ + alarm_callback_running = TRUE; +} + +/* + * @internal + * + * tpl_end_alarm_callback sets alarm_callback_running to FALSE. It is called + * from tpl_action_callback function (see tpl_os_action.c file) + */ +FUNC(void, OS_CODE) tpl_end_alarm_callback(void) +{ + alarm_callback_running = FALSE; +} + +/* + * @internal + * + * tpl_alarm_callback_running returns alarm_callback_running. It is called + * from CHECK_NO_CALLBACK_CALL_LEVEL_ERROR macro (see tpl_os_error.h) and + * tpl_current_os_state function (see below). + */ +FUNC(tpl_bool, OS_CODE) tpl_alarm_callback_running(void) +{ + return alarm_callback_running; +} #ifdef WITH_DOW #include @@ -494,7 +537,11 @@ FUNC(tpl_os_state, OS_CODE) tpl_current_os_state(CORE_ID_OR_VOID(core_id)) GET_TPL_KERN_FOR_CORE_ID(core_id, kern) - if (TPL_KERN_REF(kern).running_id == INVALID_PROC_ID) + if (tpl_alarm_callback_running()) + { + state = OS_CALLBACK; + } + else if (TPL_KERN_REF(kern).running_id == INVALID_PROC_ID) { state = OS_INIT; } @@ -1088,8 +1135,8 @@ tpl_set_event(CONST(tpl_task_id, AUTOMATIC) task_id, result = E_OS_STATE; } #else - (void) task_id; - (void) incoming_event; + (void)task_id; + (void)incoming_event; #endif return result; diff --git a/os/tpl_os_kernel.h b/os/tpl_os_kernel.h index a0f3337cd..d76556fcb 100644 --- a/os/tpl_os_kernel.h +++ b/os/tpl_os_kernel.h @@ -9,8 +9,8 @@ * * Trampoline RTOS * - * Trampoline is copyright (c) CNRS, University of Nantes, Ecole Centrale de Nantes - * Trampoline is protected by the French intellectual property law. + * Trampoline is copyright (c) CNRS, University of Nantes, Ecole Centrale de + * Nantes Trampoline is protected by the French intellectual property law. * * This software is distributed under the GNU Public Licence V2. * Check the LICENSE file in the root directory of Trampoline @@ -53,6 +53,7 @@ * - #OS_TASK means running a task * - #OS_IDLE means no task running and the OS has nothing else to do * - #OS_ISR2 means running a category 2 interrupt service routine + * - #OS_CALLBACK means an alarm callback is running * - #OS_UNKNOWN means the OS is not in a known state. This should not happen. */ typedef uint8 tpl_os_state; @@ -64,35 +65,42 @@ typedef uint8 tpl_os_state; * and until a task get the CPU (#OS_TASK), it goes idle (#OS_IDLE) or an ISR2 * takes the CPU (#OS_ISR2) */ -#define OS_INIT 0 +#define OS_INIT 0 /** * @def OS_TASK * * A task is running */ -#define OS_TASK 1 +#define OS_TASK 1 /** * @def OS_IDLE * * A task is running */ -#define OS_IDLE 2 +#define OS_IDLE 2 /** * @def OS_IDLE * * An ISR2 is running */ -#define OS_ISR2 3 +#define OS_ISR2 3 + +/** + * @def OS_CALLBACK + * + * An alarm callback is running + */ +#define OS_CALLBACK 4 /** * @def OS_UNKNOWN * * The state is unknown. This should not happen. */ -#define OS_UNKNOWN 4 +#define OS_UNKNOWN 5 /** * @def AUTOSTART @@ -101,7 +109,7 @@ typedef uint8 tpl_os_state; * * @see #tpl_exec_state */ -#define AUTOSTART 0x4 +#define AUTOSTART 0x4 /** * @def READY_AND_NEW @@ -110,7 +118,7 @@ typedef uint8 tpl_os_state; * * @see #tpl_exec_state */ -#define READY_AND_NEW 0x5 +#define READY_AND_NEW 0x5 /** * @typedef tpl_exec_obj_type @@ -142,18 +150,19 @@ typedef P2FUNC(void, OS_APPL_CODE, tpl_proc_function)(void); * structure than tpl_resource since only one internal resource can be taken * and there is no need to store the owner */ -typedef struct { +typedef struct +{ CONST(tpl_priority, TYPEDEF) - ceiling_priority; /**< Ceiling priority as computed at system - generation time */ + ceiling_priority; /**< Ceiling priority as computed at system + generation time */ VAR(tpl_priority, TYPEDEF) - owner_prev_priority; /**< Priority of the owner prior to the access - to the resource. This field is used to - restore the priority of the task when the - resource is released */ + owner_prev_priority; /**< Priority of the owner prior to the access + to the resource. This field is used to + restore the priority of the task when the + resource is released */ VAR(tpl_bool, TYPEDEF) - taken; /**< Flag to tell if the internal resource - is taken or not */ + taken; /**< Flag to tell if the internal resource + is taken or not */ } tpl_internal_resource; /** @@ -163,44 +172,45 @@ typedef struct { * descriptors or category 2 Interrupt Service Routines. Static means this * part of the descriptor can be stored in ROM. */ -struct TPL_PROC_STATIC { +struct TPL_PROC_STATIC +{ VAR(tpl_context, TYPEDEF) - context; /**< context(s) of the task/isr */ + context; /**< context(s) of the task/isr */ VAR(tpl_stack, TYPEDEF) - stack; /**< stack(s) of the task/isr */ + stack; /**< stack(s) of the task/isr */ CONST(tpl_proc_function, TYPEDEF) - entry; /**< function that is the entry point - of the task/isr */ + entry; /**< function that is the entry point + of the task/isr */ CONSTP2VAR(tpl_internal_resource, TYPEDEF, OS_APPL_DATA) - internal_resource; /**< pointer to an internal resource. NULL if the - task does not have an internal resource */ + internal_resource; /**< pointer to an internal resource. NULL if the + task does not have an internal resource */ CONST(tpl_task_id, TYPEDEF) - id; /**< id of task/isr */ + id; /**< id of task/isr */ #if WITH_OSAPPLICATION == YES CONST(tpl_app_id, TYPEDEF) - app_id; /**< id of the OS application which owns - the task/ISR */ + app_id; /**< id of the OS application which owns + the task/ISR */ #endif #if NUMBER_OF_CORES > 1 CONST(tpl_core_id, TYPEDEF) - core_id; /**< id of the core the process is assigned to */ + core_id; /**< id of the core the process is assigned to */ #endif CONST(tpl_priority, TYPEDEF) - base_priority; /**< base priority of the task/isr */ + base_priority; /**< base priority of the task/isr */ CONST(tpl_activate_counter, TYPEDEF) - max_activate_count; /**< max activation count of a task/isr */ + max_activate_count; /**< max activation count of a task/isr */ CONST(tpl_proc_type, TYPEDEF) - type; /**< TASK_BASIC,TASK_EXTENDED or IS_ROUTINE */ + type; /**< TASK_BASIC,TASK_EXTENDED or IS_ROUTINE */ #if WITH_AUTOSAR_TIMING_PROTECTION == YES CONST(tpl_time, TYPEDEF) - executionbudget ; /**< execution budget */ + executionbudget; /**< execution budget */ CONST(tpl_time, TYPEDEF) - timeframe ; /**< length of the time frame */ + timeframe; /**< length of the time frame */ CONSTP2VAR(tpl_timing_protection, TYPEDEF, OS_APPL_CONST) - timing_protection; /**< dynamic variables needed to handle - the timing protection. Set to NULL if - the proc is not supervised by the mechanism */ -#endif /* WITH_AUTOSAR_TIMING_PROTECTION */ + timing_protection; /**< dynamic variables needed to handle + the timing protection. Set to NULL if + the proc is not supervised by the mechanism */ +#endif /* WITH_AUTOSAR_TIMING_PROTECTION */ }; /** @@ -218,19 +228,20 @@ typedef struct TPL_PROC_STATIC tpl_proc_static; * This structure gathers the common members of executable objects dynamic * descriptors */ -struct TPL_PROC { - struct P2VAR(TPL_RESOURCE, TYPEDEF, OS_APPL_DATA) - resources; /**< head of the ressources held */ +struct TPL_PROC +{ + struct P2VAR(TPL_RESOURCE, TYPEDEF, + OS_APPL_DATA) resources; /**< head of the ressources held */ #if WITH_OSAPPLICATION == YES VAR(tpl_trusted_count, TYPEDEF) - trusted_counter; /**< if > 0 the process is trusted */ -#endif /* WITH_OSAPPLICATION */ + trusted_counter; /**< if > 0 the process is trusted */ +#endif /* WITH_OSAPPLICATION */ VAR(tpl_activate_counter, TYPEDEF) - activate_count; /**< current activate count */ + activate_count; /**< current activate count */ VAR(tpl_priority, TYPEDEF) - priority; /**< current priority */ + priority; /**< current priority */ VAR(tpl_proc_state, TYPEDEF) - state; /**< state (READY, RUNNING, ...)*/ + state; /**< state (READY, RUNNING, ...)*/ }; /** @@ -249,32 +260,32 @@ typedef struct { P2CONST(tpl_proc_static, TYPEDEF, OS_CONST) s_running; P2CONST(tpl_proc_static, TYPEDEF, OS_CONST) s_elected; - P2VAR(tpl_proc, TYPEDEF, OS_VAR) running; - P2VAR(tpl_proc, TYPEDEF, OS_VAR) elected; - VAR(sint32, TYPEDEF) running_id; - VAR(sint32, TYPEDEF) elected_id; - -/** - * 2 bits are used in this field. - * bit 0 indicates a context switch is needed after calling a service, - * bit 1 indicated the context of the processus that loses the cpu - * should be saved. - */ - VAR(uint8, TYPEDEF) need_switch; - -/** - * Boolean used to notify a rescheduling should be done - */ - VAR(tpl_bool, TYPEDEF) need_schedule; + P2VAR(tpl_proc, TYPEDEF, OS_VAR) running; + P2VAR(tpl_proc, TYPEDEF, OS_VAR) elected; + VAR(sint32, TYPEDEF) running_id; + VAR(sint32, TYPEDEF) elected_id; + + /** + * 2 bits are used in this field. + * bit 0 indicates a context switch is needed after calling a service, + * bit 1 indicated the context of the processus that loses the cpu + * should be saved. + */ + VAR(uint8, TYPEDEF) need_switch; + + /** + * Boolean used to notify a rescheduling should be done + */ + VAR(tpl_bool, TYPEDEF) need_schedule; #if WITH_MEMORY_PROTECTION == YES -/** - * This flag is set before running a hook or a (transitionnal) trusted - * process to disable some checkings - */ - VAR(uint8, TYPEDEF) running_trusted; + /** + * This flag is set before running a hook or a (transitionnal) trusted + * process to disable some checkings + */ + VAR(uint8, TYPEDEF) running_trusted; #endif /* WITH_MEMORY_PROTECTION */ -/* VAR(tpl_priority, TYPEDEF) running_priority; */ + /* VAR(tpl_priority, TYPEDEF) running_priority; */ } tpl_kern_state; /** @@ -283,12 +294,12 @@ typedef struct * This type gather a key used to sort the heap and the identifier of * the process */ -typedef struct { - VAR(tpl_priority, TYPEDEF) key; - VAR(tpl_proc_id, TYPEDEF) id; +typedef struct +{ + VAR(tpl_priority, TYPEDEF) key; + VAR(tpl_proc_id, TYPEDEF) id; } tpl_heap_entry; - #define OS_START_SEC_VAR_UNSPECIFIED #include "tpl_memmap.h" @@ -328,7 +339,7 @@ extern VAR(tpl_internal_resource, OS_VAR) INTERNAL_RES_SCHEDULER; * @see #INVALID_TASK * */ -#define INVALID_PROC_ID -1 +#define INVALID_PROC_ID -1 /** * @internal @@ -338,24 +349,20 @@ extern VAR(tpl_internal_resource, OS_VAR) INTERNAL_RES_SCHEDULER; * In multicore does the intercore interrupt if needed */ #if WITH_SYSTEM_CALL == NO -#define LOCAL_SWITCH_CONTEXT(a_core_id) \ - if (TPL_KERN(a_core_id).need_switch != NO_NEED_SWITCH) \ - { \ - TPL_KERN(a_core_id).need_switch = NO_NEED_SWITCH; \ - tpl_switch_context( \ - tpl_run_elected(TRUE), \ - &(TPL_KERN(a_core_id).s_elected->context) \ - ); \ +#define LOCAL_SWITCH_CONTEXT(a_core_id) \ + if (TPL_KERN(a_core_id).need_switch != NO_NEED_SWITCH) \ + { \ + TPL_KERN(a_core_id).need_switch = NO_NEED_SWITCH; \ + tpl_switch_context(tpl_run_elected(TRUE), \ + &(TPL_KERN(a_core_id).s_elected->context)); \ } -#define LOCAL_SWITCH_CONTEXT_NOSAVE(a_core_id) \ - if (TPL_KERN(a_core_id).need_switch != NO_NEED_SWITCH) \ - { \ - TPL_KERN(a_core_id).need_switch = NO_NEED_SWITCH; \ - tpl_switch_context( \ - tpl_run_elected(FALSE), \ - &(TPL_KERN(a_core_id).s_elected->context) \ - ); \ +#define LOCAL_SWITCH_CONTEXT_NOSAVE(a_core_id) \ + if (TPL_KERN(a_core_id).need_switch != NO_NEED_SWITCH) \ + { \ + TPL_KERN(a_core_id).need_switch = NO_NEED_SWITCH; \ + tpl_switch_context(tpl_run_elected(FALSE), \ + &(TPL_KERN(a_core_id).s_elected->context)); \ } #else #define LOCAL_SWITCH_CONTEXT(a_core_id) @@ -366,46 +373,52 @@ extern VAR(tpl_internal_resource, OS_VAR) INTERNAL_RES_SCHEDULER; #define REMOTE_SWITCH_CONTEXT() -#define SWITCH_CONTEXT(a_core_id) LOCAL_SWITCH_CONTEXT(0) +#define SWITCH_CONTEXT(a_core_id) LOCAL_SWITCH_CONTEXT(0) #define SWITCH_CONTEXT_NOSAVE(a_core_id) LOCAL_SWITCH_CONTEXT_NOSAVE(0) #else /* NUMBER_OF_CORES > 1, Multicore definitions */ -#define REMOTE_SWITCH_CONTEXT(a_core_id) \ - if (TPL_KERN(a_core_id).need_switch != NO_NEED_SWITCH) \ - { \ - /* need_switch flag will be resetted by the remote core */ \ - tpl_send_intercore_it(a_core_id); \ +#define REMOTE_SWITCH_CONTEXT(a_core_id) \ + if (TPL_KERN(a_core_id).need_switch != NO_NEED_SWITCH) \ + { \ + /* need_switch flag will be resetted by the remote core */ \ + tpl_send_intercore_it(a_core_id); \ } #if WITH_SYSTEM_CALL == NO -#define SWITCH_CONTEXT(a_core_id) \ - if (a_core_id == tpl_get_core_id()) { \ - LOCAL_SWITCH_CONTEXT(a_core_id) \ - } \ - else { \ - REMOTE_SWITCH_CONTEXT(a_core_id); \ +#define SWITCH_CONTEXT(a_core_id) \ + if (a_core_id == tpl_get_core_id()) \ + { \ + LOCAL_SWITCH_CONTEXT(a_core_id) \ + } \ + else \ + { \ + REMOTE_SWITCH_CONTEXT(a_core_id); \ } -#define SWITCH_CONTEXT_NOSAVE(a_core_id) \ - if (a_core_id == tpl_get_core_id()) { \ - LOCAL_SWITCH_CONTEXT(a_core_id) \ - } \ - else { \ - REMOTE_SWITCH_CONTEXT(a_core_id); \ +#define SWITCH_CONTEXT_NOSAVE(a_core_id) \ + if (a_core_id == tpl_get_core_id()) \ + { \ + LOCAL_SWITCH_CONTEXT(a_core_id) \ + } \ + else \ + { \ + REMOTE_SWITCH_CONTEXT(a_core_id); \ } #else /* WITH_SYSTEM_CALL == YES */ -#define SWITCH_CONTEXT(a_core_id) \ - if (a_core_id != tpl_get_core_id()) { \ - tpl_send_intercore_it(a_core_id); \ +#define SWITCH_CONTEXT(a_core_id) \ + if (a_core_id != tpl_get_core_id()) \ + { \ + tpl_send_intercore_it(a_core_id); \ } -#define SWITCH_CONTEXT_NOSAVE(a_core_id) \ - if (a_core_id != tpl_get_core_id()) { \ - tpl_send_intercore_it(a_core_id); \ +#define SWITCH_CONTEXT_NOSAVE(a_core_id) \ + if (a_core_id != tpl_get_core_id()) \ + { \ + tpl_send_intercore_it(a_core_id); \ } #endif @@ -463,8 +476,8 @@ extern VAR(tpl_heap_entry, OS_VAR) tpl_ready_list[]; #define OS_START_SEC_CONST_UNSPECIFIED #include "tpl_memmap.h" -extern CONSTP2VAR(tpl_rank_count, OS_CONST, OS_VAR) - tpl_tail_for_prio[NUMBER_OF_CORES]; +extern CONSTP2VAR(tpl_rank_count, OS_CONST, + OS_VAR) tpl_tail_for_prio[NUMBER_OF_CORES]; #define OS_STOP_SEC_CONST_UNSPECIFIED #include "tpl_memmap.h" @@ -492,20 +505,25 @@ extern VAR(tpl_rank_count, OS_VAR) tpl_tail_for_prio[]; * (one Idle task per core). */ extern CONSTP2CONST(tpl_proc_static, AUTOMATIC, OS_APPL_DATA) - tpl_stat_proc_table[TASK_COUNT+ISR_COUNT+NUMBER_OF_CORES]; + tpl_stat_proc_table[TASK_COUNT + ISR_COUNT + NUMBER_OF_CORES]; extern CONSTP2VAR(tpl_proc, AUTOMATIC, OS_APPL_DATA) - tpl_dyn_proc_table[TASK_COUNT+ISR_COUNT+NUMBER_OF_CORES]; + tpl_dyn_proc_table[TASK_COUNT + ISR_COUNT + NUMBER_OF_CORES]; #define OS_STOP_SEC_CONST_UNSPECIFIED #include "tpl_memmap.h" - #define OS_START_SEC_CODE #include "tpl_memmap.h" /** * Kernel functions */ +FUNC(void, OS_CODE) tpl_begin_alarm_callback(void); + +FUNC(void, OS_CODE) tpl_end_alarm_callback(void); + +FUNC(tpl_bool, OS_CODE) tpl_alarm_callback_running(void); + FUNC(tpl_os_state, OS_CODE) tpl_current_os_state(CORE_ID_OR_VOID(core_id)); FUNC(void, OS_CODE) tpl_schedule_from_running(CORE_ID_OR_VOID(core_id)); @@ -528,7 +546,7 @@ FUNC(void, OS_CODE) tpl_start(CORE_ID_OR_VOID(core_id)); * that was running before the elected task replace it */ FUNC(P2CONST(tpl_context, AUTOMATIC, OS_CONST), OS_CODE) - tpl_run_elected(CONST(tpl_bool, AUTOMATIC) save); +tpl_run_elected(CONST(tpl_bool, AUTOMATIC) save); /** * @internal @@ -560,23 +578,21 @@ FUNC(tpl_heap_entry, OS_CODE) tpl_front_proc(CORE_ID_OR_VOID(core_id)); */ FUNC(void, OS_CODE) tpl_terminate(void); -FUNC(void, OS_CODE) tpl_init_proc( - CONST(tpl_proc_id, AUTOMATIC) proc_id); +FUNC(void, OS_CODE) tpl_init_proc(CONST(tpl_proc_id, AUTOMATIC) proc_id); -FUNC(void, OS_CODE) tpl_put_preempted_proc( - CONST(tpl_proc_id, AUTOMATIC) proc_id); +FUNC(void, OS_CODE) +tpl_put_preempted_proc(CONST(tpl_proc_id, AUTOMATIC) proc_id); -FUNC(void, OS_CODE) tpl_put_new_proc( - CONST(tpl_proc_id, AUTOMATIC) proc_id); +FUNC(void, OS_CODE) tpl_put_new_proc(CONST(tpl_proc_id, AUTOMATIC) proc_id); -FUNC(void, OS_CODE) tpl_init_os( - CONST(tpl_application_mode, AUTOMATIC) app_mode); +FUNC(void, OS_CODE) +tpl_init_os(CONST(tpl_application_mode, AUTOMATIC) app_mode); -FUNC(void, OS_CODE) tpl_get_internal_resource( - CONST(tpl_proc_id, AUTOMATIC) task_id); +FUNC(void, OS_CODE) +tpl_get_internal_resource(CONST(tpl_proc_id, AUTOMATIC) task_id); -FUNC(void, OS_CODE) tpl_release_internal_resource( - CONST(tpl_proc_id, AUTOMATIC) task_id); +FUNC(void, OS_CODE) +tpl_release_internal_resource(CONST(tpl_proc_id, AUTOMATIC) task_id); /** * If a task is ended without calling TerminateTask() : @@ -594,8 +610,7 @@ FUNC(void, OS_CODE) tpl_call_terminate_task_service(void); FUNC(void, OS_CODE) tpl_call_terminate_isr2_service(void); #if WITH_OSAPPLICATION == YES -FUNC(void, OS_CODE) tpl_remove_proc( - CONST(tpl_proc_id, AUTOMATIC) proc_id); +FUNC(void, OS_CODE) tpl_remove_proc(CONST(tpl_proc_id, AUTOMATIC) proc_id); #endif /** @@ -608,8 +623,8 @@ FUNC(void, OS_CODE) tpl_remove_proc( * * @param a_task pointer to the task structure of the task to activate. */ -FUNC(tpl_status, OS_CODE) tpl_activate_task( - CONST(tpl_task_id, AUTOMATIC) task_id); +FUNC(tpl_status, OS_CODE) +tpl_activate_task(CONST(tpl_task_id, AUTOMATIC) task_id); /** * @internal @@ -622,9 +637,9 @@ FUNC(tpl_status, OS_CODE) tpl_activate_task( * @param a_task pointer to the task structure of the target task. * @param incoming_event the event mask. */ -FUNC(tpl_status, OS_CODE) tpl_set_event( - CONST(tpl_task_id, AUTOMATIC) task_id, - CONST(tpl_event_mask, AUTOMATIC) incoming_event); +FUNC(tpl_status, OS_CODE) +tpl_set_event(CONST(tpl_task_id, AUTOMATIC) task_id, + CONST(tpl_event_mask, AUTOMATIC) incoming_event); #if NUMBER_OF_CORES > 1 /** @@ -633,7 +648,7 @@ FUNC(tpl_status, OS_CODE) tpl_set_event( * tpl_multi_schedule does multiple rescheduling when many tasks could * have been activated on several cores (messages, alarms, schedule tables) */ -FUNC(void, OS_CODE)tpl_multi_schedule(void); +FUNC(void, OS_CODE) tpl_multi_schedule(void); /** * @internal diff --git a/os/tpl_os_os_kernel.c b/os/tpl_os_os_kernel.c index 2746838d7..a4ce2c4d9 100644 --- a/os/tpl_os_os_kernel.c +++ b/os/tpl_os_os_kernel.c @@ -9,8 +9,8 @@ * * Trampoline RTOS * - * Trampoline is copyright (c) CNRS, University of Nantes, Ecole Centrale de Nantes - * Trampoline is protected by the French intellectual property law. + * Trampoline is copyright (c) CNRS, University of Nantes, Ecole Centrale de + * Nantes Trampoline is protected by the French intellectual property law. * * This software is distributed under the GNU Public Licence V2. * Check the LICENSE file in the root directory of Trampoline @@ -25,20 +25,20 @@ */ #include "tpl_os_os_kernel.h" -#include "tpl_os_kernel.h" +#include "tpl_machine_interface.h" #include "tpl_os_definitions.h" #include "tpl_os_error.h" -#include "tpl_machine_interface.h" -#include "tpl_trace.h" #include "tpl_os_hooks.h" +#include "tpl_os_kernel.h" +#include "tpl_trace.h" #if NUMBER_OF_CORES > 1 #include "tpl_os_multicore_kernel.h" -# if SPINLOCK_COUNT > 0 -# include "tpl_as_spinlock_kernel.h" -# endif +#if SPINLOCK_COUNT > 0 +#include "tpl_as_spinlock_kernel.h" +#endif -#define START_OS_SYNC_LOCK_ID 0 +#define START_OS_SYNC_LOCK_ID 0 #endif #define OS_START_SEC_VAR_UNSPECIFIED @@ -74,8 +74,8 @@ VAR(tpl_lock, OS_VAR) tpl_startos_sync_lock = UNLOCKED_LOCK; #define OS_START_SEC_CODE #include "tpl_memmap.h" -FUNC(tpl_application_mode, OS_CODE) tpl_get_active_application_mode_service( - void) +FUNC(tpl_application_mode, OS_CODE) +tpl_get_active_application_mode_service(void) { VAR(tpl_application_mode, AUTOMATIC) app_mode; VAR(tpl_status, AUTOMATIC) result = E_OK; @@ -102,8 +102,8 @@ FUNC(tpl_application_mode, OS_CODE) tpl_get_active_application_mode_service( return app_mode; } -FUNC(void, OS_CODE) tpl_start_os_service( - CONST(tpl_application_mode, AUTOMATIC) mode) +FUNC(void, OS_CODE) +tpl_start_os_service(CONST(tpl_application_mode, AUTOMATIC) mode) { GET_CURRENT_CORE_ID(core_id) @@ -170,8 +170,8 @@ FUNC(void, OS_CODE) tpl_start_os_service( UNLOCK_KERNEL() } -FUNC(void, OS_CODE) tpl_call_shutdown_os( - CONST(tpl_status, AUTOMATIC) error /*@unused@*/) +FUNC(void, OS_CODE) +tpl_call_shutdown_os(CONST(tpl_status, AUTOMATIC) error /*@unused@*/) { GET_CURRENT_CORE_ID(core_id) /* @@ -190,8 +190,8 @@ FUNC(void, OS_CODE) tpl_call_shutdown_os( tpl_shutdown(); } -FUNC(void, OS_CODE) tpl_shutdown_os_service( - CONST(tpl_status, AUTOMATIC) error /*@unused@*/) +FUNC(void, OS_CODE) +tpl_shutdown_os_service(CONST(tpl_status, AUTOMATIC) error /*@unused@*/) { GET_CURRENT_CORE_ID(core_id) @@ -223,4 +223,3 @@ FUNC(void, OS_CODE) tpl_shutdown_os_service( #include "tpl_memmap.h" /* End of file tpl_os_os_kernel.c */ - diff --git a/os/tpl_os_resource_kernel.c b/os/tpl_os_resource_kernel.c index aef59e419..d355fc4ba 100644 --- a/os/tpl_os_resource_kernel.c +++ b/os/tpl_os_resource_kernel.c @@ -10,8 +10,8 @@ * * Trampoline RTOS * - * Trampoline is copyright (c) CNRS, University of Nantes, Ecole Centrale de Nantes - * Trampoline is protected by the French intellectual property law. + * Trampoline is copyright (c) CNRS, University of Nantes, Ecole Centrale de + * Nantes Trampoline is protected by the French intellectual property law. * * This software is distributed under the GNU Public Licence V2. * Check the LICENSE file in the root directory of Trampoline @@ -25,13 +25,13 @@ */ #include "tpl_os_resource_kernel.h" +#include "tpl_dow.h" +#include "tpl_machine_interface.h" #include "tpl_os_definitions.h" -#include "tpl_os_kernel.h" #include "tpl_os_error.h" #include "tpl_os_errorhook.h" -#include "tpl_machine_interface.h" +#include "tpl_os_kernel.h" #include "tpl_trace.h" -#include "tpl_dow.h" #if WITH_AUTOSAR == YES #include "tpl_as_protec_hook.h" @@ -81,12 +81,12 @@ CONST(tpl_resource_id, AUTOMATIC) INVALID_RESOURCE = (tpl_resource_id)(-1); * of the process is not changed by this function. * No rescheduling is done. */ -FUNC(void, OS_CODE) tpl_release_all_resources( - CONST(tpl_proc_id, AUTOMATIC) proc_id) +FUNC(void, OS_CODE) +tpl_release_all_resources(CONST(tpl_proc_id, AUTOMATIC) proc_id) { /* Get the resource pointer of the process */ - P2VAR(tpl_resource, AUTOMATIC, OS_APPL_DATA) res = - tpl_dyn_proc_table[proc_id]->resources; + P2VAR(tpl_resource, AUTOMATIC, OS_APPL_DATA) + res = tpl_dyn_proc_table[proc_id]->resources; #if WITH_TRACE == YES GET_CURRENT_CORE_ID(core_id) #endif /* WITH_TRACE */ @@ -97,17 +97,18 @@ FUNC(void, OS_CODE) tpl_release_all_resources( do { - CONSTP2VAR(tpl_resource, AUTOMATIC, OS_APPL_DATA) next_res = - res->next_res; + CONSTP2VAR(tpl_resource, AUTOMATIC, OS_APPL_DATA) + next_res = res->next_res; res->owner = INVALID_TASK; res->next_res = NULL; - /* find the id of the resource for the trace */ + /* find the id of the resource for the trace */ #if WITH_TRACE == YES - TRACE_RES_CHANGE_STATE(res->res_id, (tpl_trace_resource_state)RESOURCE_FREE) + TRACE_RES_CHANGE_STATE(res->res_id, + (tpl_trace_resource_state)RESOURCE_FREE) #endif /* WITH_TRACE */ - res = next_res; + res = next_res; } while (res != NULL); } } @@ -119,8 +120,8 @@ FUNC(void, OS_CODE) tpl_release_all_resources( * The ressource RES_SCHEDULER is now put in the tpl_resource_table array * as the last item. This simplify tpl_get_resource_service. */ -FUNC(tpl_status, OS_CODE) tpl_get_resource_service( - CONST(tpl_resource_id, AUTOMATIC) res_id) +FUNC(tpl_status, OS_CODE) +tpl_get_resource_service(CONST(tpl_resource_id, AUTOMATIC) res_id) { GET_CURRENT_CORE_ID(core_id) GET_TPL_KERN_FOR_CORE_ID(core_id, kern) @@ -140,6 +141,9 @@ FUNC(tpl_status, OS_CODE) tpl_get_resource_service( STORE_SERVICE(OSServiceId_GetResource) STORE_RESOURCE_ID(res_id) + /* Check call level error */ + CHECK_CALLBACK_CALL_LEVEL_ERROR(result, core_id) + CHECK_RESOURCE_ID_ERROR(res_id, result) /* check access right */ @@ -171,9 +175,9 @@ FUNC(tpl_status, OS_CODE) tpl_get_resource_service( /* save the current priority of the task in the resource */ res->owner_prev_priority = TPL_KERN_REF(kern).running->priority; - DOW_DO(printf("*** GetResource: task %s stores priority %d\n", - proc_name_table[TPL_KERN_REF(kern).running_id], - TPL_KERN_REF(kern).running->priority)); + DOW_DO(printf("*** GetResource: task %s stores priority %d\n", + proc_name_table[TPL_KERN_REF(kern).running_id], + TPL_KERN_REF(kern).running->priority)); if (ACTUAL_PRIO(TPL_KERN_REF(kern).running->priority) < res->ceiling_priority) @@ -183,10 +187,11 @@ FUNC(tpl_status, OS_CODE) tpl_get_resource_service( if the ceiling priority is greater than the current priority of the task */ TPL_KERN_REF(kern).running->priority = - DYNAMIC_PRIO(res->ceiling_priority, tail_for_prio); + DYNAMIC_PRIO(res->ceiling_priority, tail_for_prio); } #if WITH_AUTOSAR_TIMING_PROTECTION == YES -/* tpl_start_resource_monitor((tpl_proc_id)TPL_KERN_REF(kern).running_id, res_id); */ +/* tpl_start_resource_monitor((tpl_proc_id)TPL_KERN_REF(kern).running_id, + * res_id); */ #endif /* WITH_AUTOSAR_TIMING_PROTECTION */ } } @@ -205,8 +210,8 @@ FUNC(tpl_status, OS_CODE) tpl_get_resource_service( * The ressource RES_SCHEDULER is now put in the tpl_resource_table array * as the last item. This simplify tpl_get_resource_service. */ -FUNC(tpl_status, OS_CODE) tpl_release_resource_service( - CONST(tpl_resource_id, AUTOMATIC) res_id) +FUNC(tpl_status, OS_CODE) +tpl_release_resource_service(CONST(tpl_resource_id, AUTOMATIC) res_id) { GET_CURRENT_CORE_ID(core_id) /* init the error to no error */ @@ -222,6 +227,9 @@ FUNC(tpl_status, OS_CODE) tpl_release_resource_service( STORE_SERVICE(OSServiceId_ReleaseResource) STORE_RESOURCE_ID(res_id) + /* Check call level error */ + CHECK_CALLBACK_CALL_LEVEL_ERROR(result, core_id) + CHECK_RESOURCE_ID_ERROR(res_id, result) /* check access right */ @@ -235,10 +243,9 @@ FUNC(tpl_status, OS_CODE) tpl_release_resource_service( res = NULL; /* error */ #endif - /* Return an error if the task that attempt to release - the resource has a higher priority than the resource */ - CHECK_RESOURCE_PRIO_ERROR_ON_RELEASE(core_id, res,result) + the resource has a higher priority than the resource */ + CHECK_RESOURCE_PRIO_ERROR_ON_RELEASE(core_id, res, result) /* the spec requires resources to be released in the reverse order of the getting. if the resource @@ -255,8 +262,8 @@ FUNC(tpl_status, OS_CODE) tpl_release_resource_service( TPL_KERN(core_id).running->priority = res->owner_prev_priority; DOW_DO(printf("*** ReleaseResource:task %s takes back priority %d\n", - proc_name_table[TPL_KERN(core_id).running_id], - TPL_KERN(core_id).running->priority)); + proc_name_table[TPL_KERN(core_id).running_id], + TPL_KERN(core_id).running->priority)); /* remove the resource from the resource list */ TPL_KERN(core_id).running->resources = res->next_res; @@ -265,9 +272,10 @@ FUNC(tpl_status, OS_CODE) tpl_release_resource_service( res->owner = INVALID_TASK; TRACE_RES_CHANGE_STATE(res_id, (tpl_trace_resource_state)RESOURCE_FREE) tpl_schedule_from_running(CORE_ID_OR_NOTHING(core_id)); -# if WITH_AUTOSAR_TIMING_PROTECTION == YES -/* tpl_stop_resource_monitor((tpl_proc_id)TPL_KERN(core_id).running_id, res_id); */ -# endif /* WITH_AUTOSAR_TIMING_PROTECTION */ +#if WITH_AUTOSAR_TIMING_PROTECTION == YES +/* tpl_stop_resource_monitor((tpl_proc_id)TPL_KERN(core_id).running_id, + * res_id); */ +#endif /* WITH_AUTOSAR_TIMING_PROTECTION */ LOCAL_SWITCH_CONTEXT(core_id) } diff --git a/os/tpl_os_task_kernel.c b/os/tpl_os_task_kernel.c index 76c23ba72..6afc5747f 100644 --- a/os/tpl_os_task_kernel.c +++ b/os/tpl_os_task_kernel.c @@ -9,8 +9,8 @@ * * Trampoline RTOS * - * Trampoline is copyright (c) CNRS, University of Nantes, Ecole Centrale de Nantes - * Trampoline is protected by the French intellectual property law. + * Trampoline is copyright (c) CNRS, University of Nantes, Ecole Centrale de + * Nantes Trampoline is protected by the French intellectual property law. * * This software is distributed under the GNU Public Licence V2. * Check the LICENSE file in the root directory of Trampoline @@ -23,20 +23,20 @@ * $URL$ */ +#include "tpl_os_task_kernel.h" +#include "tpl_dow.h" #include "tpl_machine_interface.h" #include "tpl_os_definitions.h" #include "tpl_os_error.h" -#include "tpl_os_hooks.h" #include "tpl_os_errorhook.h" -#include "tpl_os_task_kernel.h" +#include "tpl_os_hooks.h" #include "tpl_trace.h" -#include "tpl_dow.h" #if WITH_AUTOSAR == YES #include "tpl_as_isr_kernel.h" #include "tpl_as_protec_hook.h" #if SPINLOCK_COUNT > 0 -# include "tpl_as_spinlock_kernel.h" +#include "tpl_as_spinlock_kernel.h" #endif #endif @@ -52,8 +52,8 @@ extern CONST(tpl_proc_id, AUTOMATIC) INVALID_TASK; /* * Kernel service for task activation */ -FUNC(StatusType, OS_CODE) tpl_activate_task_service( - CONST(tpl_task_id, AUTOMATIC) task_id) +FUNC(StatusType, OS_CODE) +tpl_activate_task_service(CONST(tpl_task_id, AUTOMATIC) task_id) { GET_CURRENT_CORE_ID(core_id) GET_PROC_CORE_ID(task_id, proc_core_id) @@ -71,8 +71,11 @@ FUNC(StatusType, OS_CODE) tpl_activate_task_service( STORE_SERVICE(OSServiceId_ActivateTask) STORE_TASK_ID(task_id) - /* Check a task_id error */ - CHECK_TASK_ID_ERROR(task_id,result) + /* Check call level error */ + CHECK_CALLBACK_CALL_LEVEL_ERROR(result, core_id) + + /* Check a task_id error */ + CHECK_TASK_ID_ERROR(task_id, result) /* check access right */ CHECK_ACCESS_RIGHTS_TASK_ID(core_id, task_id, result) @@ -101,7 +104,6 @@ FUNC(StatusType, OS_CODE) tpl_activate_task_service( return result; } - FUNC(StatusType, OS_CODE) tpl_terminate_task_service(void) { GET_CURRENT_CORE_ID(core_id) @@ -116,7 +118,7 @@ FUNC(StatusType, OS_CODE) tpl_terminate_task_service(void) /* check interrupts are not disabled by user */ CHECK_INTERRUPT_LOCK(result) /* check we are at the task level */ - CHECK_TASK_CALL_LEVEL_ERROR(core_id,result) + CHECK_TASK_CALL_LEVEL_ERROR(core_id, result) /* check the task does not own a resource */ CHECK_RUNNING_OWNS_REZ_ERROR(core_id, result) /* checks the task does not occupy spinlock(s) */ @@ -147,13 +149,12 @@ FUNC(StatusType, OS_CODE) tpl_terminate_task_service(void) return result; } - -FUNC(StatusType, OS_CODE) tpl_chain_task_service( - CONST(tpl_task_id, AUTOMATIC) task_id) +FUNC(StatusType, OS_CODE) +tpl_chain_task_service(CONST(tpl_task_id, AUTOMATIC) task_id) { GET_CURRENT_CORE_ID(core_id) - VAR(StatusType, AUTOMATIC) result = E_OK; + VAR(StatusType, AUTOMATIC) result = E_OK; /* lock the kernel */ LOCK_KERNEL() @@ -166,9 +167,9 @@ FUNC(StatusType, OS_CODE) tpl_chain_task_service( STORE_TASK_ID(task_id) /* Check a call level error */ - CHECK_TASK_CALL_LEVEL_ERROR(core_id,result) + CHECK_TASK_CALL_LEVEL_ERROR(core_id, result) /* Check a task_id error */ - CHECK_TASK_ID_ERROR(task_id,result) + CHECK_TASK_ID_ERROR(task_id, result) /* Check no resource is held by the terminating task */ CHECK_RUNNING_OWNS_REZ_ERROR(core_id, result) /* checks the task does not occupy spinlock(s) */ @@ -234,7 +235,6 @@ FUNC(StatusType, OS_CODE) tpl_chain_task_service( return result; } - FUNC(StatusType, OS_CODE) tpl_schedule_service(void) { GET_CURRENT_CORE_ID(core_id) @@ -251,7 +251,7 @@ FUNC(StatusType, OS_CODE) tpl_schedule_service(void) STORE_SERVICE(OSServiceId_Schedule) /* Check a call level error */ - CHECK_TASK_CALL_LEVEL_ERROR(core_id,result) + CHECK_TASK_CALL_LEVEL_ERROR(core_id, result) /* Check no resource is held by the calling task */ CHECK_RUNNING_OWNS_REZ_ERROR(core_id, result) /* checks the task does not occupy spinlock(s) */ @@ -284,9 +284,9 @@ FUNC(StatusType, OS_CODE) tpl_schedule_service(void) return result; } - -FUNC(StatusType, OS_CODE) tpl_get_task_id_service( - CONSTP2VAR(tpl_task_id, AUTOMATIC, OS_APPL_DATA) task_id) +FUNC(StatusType, OS_CODE) +tpl_get_task_id_service(CONSTP2VAR(tpl_task_id, AUTOMATIC, OS_APPL_DATA) + task_id) { GET_CURRENT_CORE_ID(core_id) @@ -301,6 +301,9 @@ FUNC(StatusType, OS_CODE) tpl_get_task_id_service( STORE_SERVICE(OSServiceId_GetTaskID) STORE_TASK_ID_REF(task_id) + /* Check call level error */ + CHECK_CALLBACK_CALL_LEVEL_ERROR(result, core_id) + /* check state is in an authorized memory region */ CHECK_DATA_LOCATION(core_id, task_id, result); @@ -327,10 +330,10 @@ FUNC(StatusType, OS_CODE) tpl_get_task_id_service( return result; } - -FUNC(StatusType, OS_CODE) tpl_get_task_state_service( - CONST(tpl_task_id, AUTOMATIC) task_id, - CONSTP2VAR(tpl_proc_state, AUTOMATIC, OS_APPL_DATA) state) +FUNC(StatusType, OS_CODE) +tpl_get_task_state_service(CONST(tpl_task_id, AUTOMATIC) task_id, + CONSTP2VAR(tpl_proc_state, AUTOMATIC, OS_APPL_DATA) + state) { GET_CURRENT_CORE_ID(core_id) @@ -346,8 +349,11 @@ FUNC(StatusType, OS_CODE) tpl_get_task_state_service( STORE_TASK_ID(task_id) STORE_TASK_STATE_REF(state) + /* Check call level error */ + CHECK_CALLBACK_CALL_LEVEL_ERROR(result, core_id) + /* Check a task_id error */ - CHECK_TASK_ID_ERROR(task_id,result) + CHECK_TASK_ID_ERROR(task_id, result) /* check access right */ CHECK_ACCESS_RIGHTS_TASK_ID(core_id, task_id, result) diff --git a/os/tpl_os_timeobj_kernel.c b/os/tpl_os_timeobj_kernel.c index 106498294..95d612e86 100644 --- a/os/tpl_os_timeobj_kernel.c +++ b/os/tpl_os_timeobj_kernel.c @@ -10,8 +10,8 @@ * * Trampoline RTOS * - * Trampoline is copyright (c) CNRS, University of Nantes, Ecole Centrale de Nantes - * Trampoline is protected by the French intellectual property law. + * Trampoline is copyright (c) CNRS, University of Nantes, Ecole Centrale de + * Nantes Trampoline is protected by the French intellectual property law. * * This software is distributed under the GNU Public Licence V2. * Check the LICENSE file in the root directory of Trampoline @@ -26,9 +26,9 @@ /*#include "tpl_os_definitions.h"*/ #include "tpl_os_timeobj_kernel.h" -#include "tpl_os_kernel.h" -#include "tpl_os_definitions.h" #include "tpl_debug.h" +#include "tpl_os_definitions.h" +#include "tpl_os_kernel.h" #include "tpl_trace.h" #if WITH_AUTOSAR == YES @@ -49,7 +49,7 @@ STATIC VAR(tpl_bool, OS_VAR) tpl_counters_enabled = FALSE; FUNC(void, OS_CODE) tpl_enable_counters(void) { - tpl_counters_enabled = TRUE; + tpl_counters_enabled = TRUE; } /* @@ -61,121 +61,121 @@ FUNC(void, OS_CODE) tpl_enable_counters(void) * and a time object is inserted starting from the * head of the list */ -FUNC(void, OS_CODE) tpl_insert_time_obj( - P2VAR(tpl_time_obj, AUTOMATIC, OS_APPL_DATA) time_obj) +FUNC(void, OS_CODE) +tpl_insert_time_obj(P2VAR(tpl_time_obj, AUTOMATIC, OS_APPL_DATA) time_obj) { - /* get the counter */ - P2VAR(tpl_counter, AUTOMATIC, OS_APPL_DATA) - counter = time_obj->stat_part->counter; - /* initialize the current time object to the head */ - P2VAR(tpl_time_obj, AUTOMATIC, OS_APPL_DATA) - current_to = counter->first_to; - /* initialize the time object that precede the current one to NULL */ - P2VAR(tpl_time_obj, AUTOMATIC, OS_APPL_DATA) - prev_to = NULL_PTR; - - if (current_to == NULL) + /* get the counter */ + P2VAR(tpl_counter, AUTOMATIC, OS_APPL_DATA) + counter = time_obj->stat_part->counter; + /* initialize the current time object to the head */ + P2VAR(tpl_time_obj, AUTOMATIC, OS_APPL_DATA) + current_to = counter->first_to; + /* initialize the time object that precede the current one to NULL */ + P2VAR(tpl_time_obj, AUTOMATIC, OS_APPL_DATA) + prev_to = NULL_PTR; + + if (current_to == NULL) + { + /* The time object queue is empty + So the time object is alone in the queue */ + counter->first_to = time_obj; + counter->next_to = time_obj; + time_obj->next_to = time_obj->prev_to = NULL; + } + else + { + /* The time object queue is not empty + look for the place to insert the time object */ + while ((current_to != NULL) && (current_to->date <= time_obj->date)) { - /* The time object queue is empty - So the time object is alone in the queue */ - counter->first_to = time_obj; - counter->next_to = time_obj; - time_obj->next_to = time_obj->prev_to = NULL; + prev_to = current_to; + current_to = current_to->next_to; } - else - { - /* The time object queue is not empty - look for the place to insert the time object */ - while ((current_to != NULL) && - (current_to->date <= time_obj->date)) - { - prev_to = current_to; - current_to = current_to->next_to; - } - time_obj->next_to = current_to; - time_obj->prev_to = prev_to; + time_obj->next_to = current_to; + time_obj->prev_to = prev_to; - /* insert the alarm */ - if (current_to != NULL) - { - current_to->prev_to = time_obj; - } - if (prev_to != NULL) - { - /* add at the end of the queue or insert */ - prev_to->next_to = time_obj; - } - else - { - /* the condition current_to->date <= time_object->date was - false a the beginning of the while. So the time object - have to be added at the head of the time object queue */ - counter->first_to = time_obj; - } + /* insert the alarm */ + if (current_to != NULL) + { + current_to->prev_to = time_obj; + } + if (prev_to != NULL) + { + /* add at the end of the queue or insert */ + prev_to->next_to = time_obj; + } + else + { + /* the condition current_to->date <= time_object->date was + false a the beginning of the while. So the time object + have to be added at the head of the time object queue */ + counter->first_to = time_obj; + } - /* Update the next_to to point to the newly - inserted time_object if the date of the newly inserted time - object is within the current date and the next_alarm_to_raise - date, taking account the modulo */ - if (counter->next_to->date < counter->current_date) - { - if ((time_obj->date > counter->current_date) || - (time_obj->date < counter->next_to->date)) - { - counter->next_to = time_obj; - } - } - else - { - if ((time_obj->date > counter->current_date) && - (time_obj->date < counter->next_to->date)) - { - counter->next_to = time_obj; - } - } + /* Update the next_to to point to the newly + inserted time_object if the date of the newly inserted time + object is within the current date and the next_alarm_to_raise + date, taking account the modulo */ + if (counter->next_to->date < counter->current_date) + { + if ((time_obj->date > counter->current_date) || + (time_obj->date < counter->next_to->date)) + { + counter->next_to = time_obj; + } + } + else + { + if ((time_obj->date > counter->current_date) && + (time_obj->date < counter->next_to->date)) + { + counter->next_to = time_obj; + } } + } } /* * tpl_remove_time_obj removes a time object from the time object queue * of the counter it belongs to. */ -FUNC(void, OS_CODE) tpl_remove_time_obj( - P2VAR(tpl_time_obj, AUTOMATIC, OS_APPL_DATA) time_obj) +FUNC(void, OS_CODE) +tpl_remove_time_obj(P2VAR(tpl_time_obj, AUTOMATIC, OS_APPL_DATA) time_obj) { - P2VAR(tpl_counter, AUTOMATIC, OS_APPL_DATA) counter = time_obj->stat_part->counter; + P2VAR(tpl_counter, AUTOMATIC, OS_APPL_DATA) + counter = time_obj->stat_part->counter; - /* adjust the head of the queue if the - removed alarm is at the head */ - if (time_obj == counter->first_to) - { - counter->first_to = time_obj->next_to; - } - /* adjust the next alarm to raise if it is - the removed alarm */ - if (time_obj == counter->next_to) - { - counter->next_to = time_obj->next_to; - } - /* build the link between the previous and next alarm in the queue */ - if (time_obj->next_to != NULL) - { - time_obj->next_to->prev_to = time_obj->prev_to; - } - if (time_obj->prev_to != NULL) - { - time_obj->prev_to->next_to = time_obj->next_to; - } - /* if the next_alarm_to_raise was pointing to the - alarm and the alarm was at the end of the queue - next_alarm_to_raise is NULL and must be reset to - the first alarm of the queue */ - if (counter->next_to == NULL) - { - counter->next_to = counter->first_to; - } + /* adjust the head of the queue if the + removed alarm is at the head */ + if (time_obj == counter->first_to) + { + counter->first_to = time_obj->next_to; + } + /* adjust the next alarm to raise if it is + the removed alarm */ + if (time_obj == counter->next_to) + { + counter->next_to = time_obj->next_to; + } + /* build the link between the previous and next alarm in the queue */ + if (time_obj->next_to != NULL) + { + time_obj->next_to->prev_to = time_obj->prev_to; + } + if (time_obj->prev_to != NULL) + { + time_obj->prev_to->next_to = time_obj->next_to; + } + /* if the next_alarm_to_raise was pointing to the + alarm and the alarm was at the end of the queue + next_alarm_to_raise is NULL and must be reset to + the first alarm of the queue */ + if (counter->next_to == NULL) + { + counter->next_to = counter->first_to; + } } /* @@ -183,44 +183,46 @@ FUNC(void, OS_CODE) tpl_remove_time_obj( * the same date starting with the next_to of the counter given as parameter. * Added:jlb:2008-09-25. */ -STATIC FUNC(P2VAR(tpl_time_obj, AUTOMATIC, OS_APPL_DATA), OS_CODE) tpl_remove_timeobj_set( - P2VAR(tpl_counter, AUTOMATIC, OS_APPL_DATA) counter) +STATIC FUNC(P2VAR(tpl_time_obj, AUTOMATIC, OS_APPL_DATA), OS_CODE) + tpl_remove_timeobj_set(P2VAR(tpl_counter, AUTOMATIC, OS_APPL_DATA) counter) { P2VAR(tpl_time_obj, AUTOMATIC, OS_APPL_DATA) first_to = counter->next_to; P2VAR(tpl_time_obj, AUTOMATIC, OS_APPL_DATA) real_next_to = NULL; if (first_to != NULL) { - P2VAR(tpl_time_obj, AUTOMATIC, OS_APPL_DATA) last_to; - P2VAR(tpl_time_obj, AUTOMATIC, OS_APPL_DATA) t_obj = first_to; - P2VAR(tpl_time_obj, AUTOMATIC, OS_APPL_DATA) af_to; - VAR(tpl_tick, AUTOMATIC) date = first_to->date; + P2VAR(tpl_time_obj, AUTOMATIC, OS_APPL_DATA) last_to; + P2VAR(tpl_time_obj, AUTOMATIC, OS_APPL_DATA) t_obj = first_to; + P2VAR(tpl_time_obj, AUTOMATIC, OS_APPL_DATA) af_to; + VAR(tpl_tick, AUTOMATIC) date = first_to->date; VAR(tpl_bool, AUTOMATIC) object = FALSE; /* look for the last time object with the same date as the first one */ do { #if WITH_AUTOSAR == YES - /* if BOOSTRAP, let this object in the queue setting it as the previous object - to first_to */ - if ((t_obj->state & SCHEDULETABLE_BOOTSTRAP) == SCHEDULETABLE_BOOTSTRAP) - { - if (t_obj == counter->next_to) - { - /*Careful if all the objects are boostrap, remove date from the counter*/ - counter->next_to = t_obj->next_to; - first_to = t_obj->next_to; - last_to = t_obj; - t_obj->state = t_obj->state & ~SCHEDULETABLE_BOOTSTRAP; + /* if BOOSTRAP, let this object in the queue setting it as the previous + object to first_to */ + if ((t_obj->state & SCHEDULETABLE_BOOTSTRAP) == SCHEDULETABLE_BOOTSTRAP) + { + if (t_obj == counter->next_to) + { + /*Careful if all the objects are boostrap, remove date from the + * counter*/ + counter->next_to = t_obj->next_to; + first_to = t_obj->next_to; + last_to = t_obj; + t_obj->state = t_obj->state & ~SCHEDULETABLE_BOOTSTRAP; TRACE_TIMEOBJ_CHANGE_STATE(t_obj->stat_part->id, t_obj->state) - } - else - { - /* if next object is null, it's impossible to store next_to->prev_to, so*/ - if (t_obj->next_to != NULL) - { - t_obj->next_to->prev_to = t_obj->prev_to; - } + } + else + { + /* if next object is null, it's impossible to store next_to->prev_to, + * so*/ + if (t_obj->next_to != NULL) + { + t_obj->next_to->prev_to = t_obj->prev_to; + } t_obj->prev_to->next_to = t_obj->next_to; t_obj->prev_to = first_to->prev_to; t_obj->prev_to->next_to = t_obj; @@ -229,21 +231,20 @@ STATIC FUNC(P2VAR(tpl_time_obj, AUTOMATIC, OS_APPL_DATA), OS_CODE) tpl_remove_ti t_obj->state = t_obj->state & ~SCHEDULETABLE_BOOTSTRAP; TRACE_TIMEOBJ_CHANGE_STATE(t_obj->stat_part->id, t_obj->state) t_obj = last_to; - } - } - else - { - last_to = t_obj; - object = TRUE; - } - t_obj = t_obj->next_to; + } + } + else + { + last_to = t_obj; + object = TRUE; + } + t_obj = t_obj->next_to; #else - object = TRUE; - last_to = t_obj; - t_obj = t_obj->next_to; + object = TRUE; + last_to = t_obj; + t_obj = t_obj->next_to; #endif /* WITH_AUTOSAR */ - } - while ((t_obj != NULL) && (t_obj->date == date)); + } while ((t_obj != NULL) && (t_obj->date == date)); /* disconnect the chain of object(s). */ t_obj = first_to->prev_to; @@ -264,29 +265,29 @@ STATIC FUNC(P2VAR(tpl_time_obj, AUTOMATIC, OS_APPL_DATA), OS_CODE) tpl_remove_ti counter->first_to = af_to; } - /* if object == TRUE, return counter->next_to (by saving it first) - else, return NULL - */ - - if (object == TRUE) - { - real_next_to = counter->next_to; - } - - /* update the next_to of the counter */ - if (af_to != NULL) - { - counter->next_to = af_to; - } - else - { - counter->next_to = counter->first_to; - } - /* update the end of the chain of object(s) */ + /* if object == TRUE, return counter->next_to (by saving it first) + else, return NULL + */ + + if (object == TRUE) + { + real_next_to = counter->next_to; + } + + /* update the next_to of the counter */ + if (af_to != NULL) + { + counter->next_to = af_to; + } + else + { + counter->next_to = counter->first_to; + } + /* update the end of the chain of object(s) */ last_to->next_to = NULL; } - return real_next_to; + return real_next_to; } /* @@ -309,12 +310,13 @@ STATIC FUNC(P2VAR(tpl_time_obj, AUTOMATIC, OS_APPL_DATA), OS_CODE) tpl_remove_ti */ extern FUNC(void, OS_CODE) printrl(P2VAR(char, AUTOMATIC, OS_APPL_DATA) msg); -FUNC(void, OS_CODE) tpl_counter_tick( - P2VAR(tpl_counter, AUTOMATIC, OS_APPL_DATA) counter) +FUNC(void, OS_CODE) +tpl_counter_tick(P2VAR(tpl_counter, AUTOMATIC, OS_APPL_DATA) counter) { - P2VAR(tpl_time_obj, AUTOMATIC, OS_APPL_DATA) t_obj; - /* temporary pointeur to adjust the next object of a counter when the first time - object at a date is a "BOOTSTRAP" time object (for schedule table only) */ + P2VAR(tpl_time_obj, AUTOMATIC, OS_APPL_DATA) t_obj; + /* temporary pointeur to adjust the next object of a counter when the first + time object at a date is a "BOOTSTRAP" time object (for schedule table + only) */ P2VAR(tpl_time_obj, AUTOMATIC, OS_APPL_DATA) real_next_to_temp; /* * A non constant function pointer is used @@ -322,11 +324,14 @@ FUNC(void, OS_CODE) tpl_counter_tick( * the action on each alarm. The function pointed is know at conception time, * because only 3 function can be pointed to. */ - VAR(tpl_expire_func, AUTOMATIC) expire; - VAR(tpl_tick, AUTOMATIC) date; - /* this variable is added because the same name was used twice in this function for - 2 different variables, this behavior was dependent on the compiler */ - VAR(tpl_tick, AUTOMATIC) new_date; + VAR(tpl_expire_func, AUTOMATIC) expire; + VAR(tpl_tick, AUTOMATIC) date; + /* + * this variable is added because the same name was used twice in this + * function for 2 different variables, this behavior was dependent on the + * compiler + */ + VAR(tpl_tick, AUTOMATIC) new_date; if (tpl_counters_enabled) { @@ -355,11 +360,12 @@ FUNC(void, OS_CODE) tpl_counter_tick( extract the time object with this date from the list. (if object from schedule table has been BOOTSTRAP, don't process - the expiry point(s)) */ + the expiry point(s)) + */ real_next_to_temp = tpl_remove_timeobj_set(counter); - if( real_next_to_temp != NULL) + if (real_next_to_temp != NULL) { /* save the "real one" next_to (in case of a schedule table, if the first time object is a BOOTSTRAP, change the next_to's @@ -394,7 +400,8 @@ FUNC(void, OS_CODE) tpl_counter_tick( queue of the counter it belongs to */ tpl_insert_time_obj(t_obj); } - else { + else + { t_obj->state = TIME_OBJ_SLEEP; TRACE_TIMEOBJ_CHANGE_STATE(t_obj->stat_part->id, TIME_OBJ_SLEEP) } @@ -407,29 +414,31 @@ FUNC(void, OS_CODE) tpl_counter_tick( } #if TPL_OPTIMIZE_TICKS == YES -FUNC(tpl_tick, OS_CODE) tpl_time_before_next_tick( - P2VAR(tpl_counter, AUTOMATIC, OS_APPL_DATA) counter) +FUNC(tpl_tick, OS_CODE) +tpl_time_before_next_tick(P2VAR(tpl_counter, AUTOMATIC, OS_APPL_DATA) counter) { - P2VAR(tpl_time_obj, AUTOMATIC, OS_APPL_DATA) t_obj; - VAR(tpl_tick, AUTOMATIC) date; + P2VAR(tpl_time_obj, AUTOMATIC, OS_APPL_DATA) t_obj; + VAR(tpl_tick, AUTOMATIC) date; t_obj = counter->next_to; - if(counter->next_to == NULL) return -1; /* FIXME : 0 is a possible value */ + if (counter->next_to == NULL) + return -1; /* FIXME : 0 is a possible value */ /* FIXME : Ternaire ? */ date = counter->next_to->date; - if(date < counter->current_date){ + if (date < counter->current_date) + { date += counter->max_allowed_value + 1; } date -= counter->current_date; - return (date - 1 ) * counter->ticks_per_base - + (counter->ticks_per_base - counter->current_tick); + return (date - 1) * counter->ticks_per_base + + (counter->ticks_per_base - counter->current_tick); } -FUNC(void, OS_CODE) tpl_increment_counter( - P2VAR(tpl_counter, AUTOMATIC, OS_APPL_DATA) counter, - VAR(tpl_tick, AUTOMATIC) ticks) +FUNC(void, OS_CODE) +tpl_increment_counter(P2VAR(tpl_counter, AUTOMATIC, OS_APPL_DATA) counter, + VAR(tpl_tick, AUTOMATIC) ticks) { VAR(tpl_tick, AUTOMATIC) date; VAR(tpl_tick, AUTOMATIC) i; @@ -437,7 +446,7 @@ FUNC(void, OS_CODE) tpl_increment_counter( if (tpl_counters_enabled) { /* FIXME Should be done without a for */ - for(i = 0; i < ticks; i++) + for (i = 0; i < ticks; i++) { /* inc the current tick value of the counter */ counter->current_tick++; @@ -452,7 +461,6 @@ FUNC(void, OS_CODE) tpl_increment_counter( } counter->current_date = date; counter->current_tick = 0; - } } }