Skip to content

Commit

Permalink
[OS] fix error code returned by services when called from alarm callb…
Browse files Browse the repository at this point in the history
…ack. Now, E_OS_CALLEVEL is returned
  • Loading branch information
jlbirccyn committed Oct 17, 2023
1 parent 85e0afb commit da0cb0c
Show file tree
Hide file tree
Showing 10 changed files with 1,185 additions and 1,023 deletions.
50 changes: 28 additions & 22 deletions os/tpl_os_action.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -24,37 +24,39 @@
* $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"

/**
* 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
* first member of tpl_callback_action is a tpl_action
* 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 *
Expand All @@ -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)
}
Expand All @@ -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 *
Expand All @@ -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);
}
Expand Down
112 changes: 63 additions & 49 deletions os/tpl_os_alarm_kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 *
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -215,21 +220,24 @@ 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)
STORE_ALARM_ID(alarm_id)
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)
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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)
Expand Down Expand Up @@ -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;
Expand All @@ -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)
Expand Down
Loading

0 comments on commit da0cb0c

Please sign in to comment.