diff --git a/goil/templates/code/resource_descriptor.goilTemplate b/goil/templates/code/resource_descriptor.goilTemplate index bafd0f1ca..b94941c48 100755 --- a/goil/templates/code/resource_descriptor.goilTemplate +++ b/goil/templates/code/resource_descriptor.goilTemplate @@ -31,7 +31,7 @@ VAR(tpl_resource, OS_VAR) % !resource::NAME %_rez_desc = { /* ceiling priority of the resource */ % !resource::PRIORITY %, /* owner previous priority */ 0, /* owner of the resource */ INVALID_PROC_ID, -#if WITH_OSAPPLICATION == YES +#if RESOURCE_BELONGS_TO_OS_APP == YES /* OS Application id */ % if AUTOSAR then if OS::SCALABILITYCLASS >= 3 then diff --git a/goil/templates/code/tpl_app_define_h.goilTemplate b/goil/templates/code/tpl_app_define_h.goilTemplate index 1925eadcf..34e70ca39 100755 --- a/goil/templates/code/tpl_app_define_h.goilTemplate +++ b/goil/templates/code/tpl_app_define_h.goilTemplate @@ -33,12 +33,22 @@ #include "tpl_config_def.h" +% +let rezBelongToApp := OS::SCALABILITYCLASS > 2 & + OILDECIMAL >= 31 & + OILDECIMAL <= 40 +% + /*============================================================================= * Configuration flags */ #define TARGET_ARCH "% !ARCH %" #define TARGET_CHIP "% !CHIP %" #define TARGET_BOARD "% !BOARD %" +#define MAJOR_OIL_VERSION % !OILMAJOR % +#define MINOR_OIL_VERSION % !OILMINOR % +#define DECIMAL_OIL_VERSION % !OILDECIMAL % +#define RESOURCE_BELONGS_TO_OS_APP % !yesNo(rezBelongToApp) % #define NUMBER_OF_CORES % !exists OS::NUMBER_OF_CORES default (1) % #define WITH_OS_EXTENDED % !yesNo(OS::STATUS == "EXTENDED") % #define WITH_ORTI % !yesNo(OS::WITHORTI) % diff --git a/goil/templates/config/autosar_common.oil b/goil/templates/config/autosar_common.oil new file mode 100644 index 000000000..272037e58 --- /dev/null +++ b/goil/templates/config/autosar_common.oil @@ -0,0 +1,97 @@ +IMPLEMENTATION trampoline_autosar_common { + + OS { + /* Autosar OIL */ + BOOLEAN PROTECTIONHOOK = FALSE; + ENUM WITH_AUTO [SC1,SC2,SC3,SC4] SCALABILITYCLASS = AUTO; + BOOLEAN STACKMONITORING = FALSE; + }; + + ALARM [] { + ENUM [ + ACTIVATETASK { TASK_TYPE TASK; }, + SETEVENT { TASK_TYPE TASK; EVENT_TYPE EVENT; }, + INCREMENTCOUNTER { COUNTER_TYPE COUNTER; } + ] ACTION; + APPLICATION_TYPE ACCESSING_APPLICATION[]; + }; + + TASK [] { + BOOLEAN [ + TRUE { + UINT32 EXECUTIONBUDGET; + UINT32 TIMEFRAME; + }, + FALSE + ] TIMING_PROTECTION = FALSE; + APPLICATION_TYPE ACCESSING_APPLICATION[]; + }; + + ISR [] { + BOOLEAN [ + TRUE, + FALSE + ] TIMING_PROTECTION = FALSE; + APPLICATION_TYPE ACCESSING_APPLICATION[]; + }; + + COUNTER [] { + ENUM [ HARDWARE, SOFTWARE ] TYPE = HARDWARE; + APPLICATION_TYPE ACCESSING_APPLICATION[]; + }; + + RESOURCE [] { + APPLICATION_TYPE ACCESSING_APPLICATION[]; + }; + + SCHEDULETABLE [] { + COUNTER_TYPE COUNTER; + ENUM [ + NONE, + ABSOLUTE { UINT64 START; APPMODE_TYPE APPMODE[]; }, + RELATIVE { UINT64 OFFSET; APPMODE_TYPE APPMODE[]; }, + SYNCHRON { APPMODE_TYPE APPMODE[]; } + ] AUTOSTART = NONE; + BOOLEAN [ + TRUE { + ENUM [ IMPLICIT, EXPLICIT ] SYNC_STRATEGY; + UINT64 PRECISION; + }, + FALSE + ] LOCAL_TO_GLOBAL_TIME_SYNCHRONIZATION; + BOOLEAN PERIODIC; + UINT64 LENGTH; + STRUCT { + UINT64 OFFSET; + ENUM [ + ACTIVATETASK { TASK_TYPE TASK; }, + SETEVENT { TASK_TYPE TASK; EVENT_TYPE EVENT; } + ] ACTION []; + BOOLEAN [ + TRUE { UINT64 MAX_ADVANCE; UINT64 MAX_RETARD; }, + FALSE + ] ADJUSTABLE = FALSE; + } EXPIRY_POINT []; + APPLICATION_TYPE ACCESSING_APPLICATION[]; + }; + + APPLICATION [] { + BOOLEAN [ + TRUE { IDENTIFIER TRUSTED_FUNCTION []; }, + FALSE + ] TRUSTED = FALSE; + BOOLEAN STARTUPHOOK = FALSE; + BOOLEAN SHUTDOWNHOOK = FALSE; + BOOLEAN ERRORHOOK = FALSE; + BOOLEAN [ + TRUE { TASK_TYPE RESTARTTASK; }, + FALSE + ] HAS_RESTARTTASK = FALSE; + TASK_TYPE TASK []; + ISR_TYPE ISR []; + ALARM_TYPE ALARM []; + SCHEDULETABLE_TYPE SCHEDULETABLE []; + COUNTER_TYPE COUNTER []; + MESSAGE_TYPE MESSAGE []; + }; +}; diff --git a/goil/templates/config/autosar_multicore.oil b/goil/templates/config/autosar_multicore.oil new file mode 100644 index 000000000..125e89c90 --- /dev/null +++ b/goil/templates/config/autosar_multicore.oil @@ -0,0 +1,69 @@ +/* + * AUTOSAR multicore objects. Objects defined here are: + * - IOC + * - SPINLOCK + * + * Objects reciving additional attributes are: + * - OS: NUMBER_OF_CORES. + * - ALARM: ACTION as an INCREMENTCOUNTER value for software counters and + * ACCESSING_APPLICATION. + * - TASK: TIMINGPROTECTION and ACCESSING_APPLICATION. + * - ISR: TIMINGPROTECTION and ACCESSING_APPLICATION. + * - COUNTER: TYPE and ACCESSING_APPLICATION. + * - RESOURCE: ACCESSING_APPLICATION. + */ +IMPLEMENTATION autosar_multicore { + OS { + UINT32 [1..65535] NUMBER_OF_CORES = 1; + }; + + IOC [] { + STRUCT { + ENUM [ + DATA, + REFERENCE + ] DATATYPEPROPERTY; + } DATATYPENAME []; + + ENUM [ + QUEUED { + UINT32 BUFFER_LENGTH; + }, + LAST_IS_BEST { + STRING WITH_AUTO INIT_VALUE_SYMBOL = AUTO; + } + ] SEMANTICS = QUEUED; + + STRUCT { + APPLICATION_TYPE RCV_OSAPPLICATION; + STRING WITH_AUTO RECEIVER_PULL_CB = AUTO; + ENUM [ + NONE, + ACTIVATETASK { TASK_TYPE TASK; }, + SETEVENT {TASK_TYPE TASK; EVENT_TYPE EVENT; } + ] ACTION = NONE; + } RECEIVER []; + + STRUCT { + UINT32 WITH_AUTO SENDER_ID = AUTO; + APPLICATION_TYPE SND_OSAPPLICATION; + } SENDER [] ; + + }; + + SPINLOCK [] { + APPLICATION_TYPE ACCESSING_APPLICATION []; + SPINLOCK_TYPE SUCCESSOR[]; + ENUM [ + LOCK_ALL_INTERRUPTS, + LOCK_CAT2_INTERRUPTS, + LOCK_WITH_RES_SCHEDULER, + LOCK_NOTHING + ] LOCKMETHOD = LOCK_NOTHING; + }; + + APPLICATION [] { + IOC_TYPE IOC []; + UINT32 CORE = 0; + }; +}; diff --git a/goil/templates/config/config3.1.oil b/goil/templates/config/config3.1.oil index f471ab070..8fff4e062 100755 --- a/goil/templates/config/config3.1.oil +++ b/goil/templates/config/config3.1.oil @@ -1,100 +1,12 @@ -IMPLEMENTATION trampoline_autosar { - - OS { - /* Autosar OIL */ - BOOLEAN PROTECTIONHOOK = FALSE; - ENUM WITH_AUTO [SC1,SC2,SC3,SC4] SCALABILITYCLASS = AUTO; - BOOLEAN STACKMONITORING = FALSE; - }; - - ALARM [] { - ENUM [ - ACTIVATETASK { TASK_TYPE TASK; }, - SETEVENT { TASK_TYPE TASK; EVENT_TYPE EVENT; }, - INCREMENTCOUNTER { COUNTER_TYPE COUNTER; } - ] ACTION; - APPLICATION_TYPE ACCESSING_APPLICATION[]; - }; - - TASK [] { - BOOLEAN [ - TRUE { - UINT32 EXECUTIONBUDGET; - UINT32 TIMEFRAME; - }, - FALSE - ] TIMING_PROTECTION = FALSE; - APPLICATION_TYPE ACCESSING_APPLICATION[]; - }; +/* + * AUTOSAR 3.1 + * + * This version of AUTOSAR add the RESOURCE attribute in the APPLICATION object. + */ +#include "autosar_common.oil" - ISR [] { - BOOLEAN [ - TRUE, - FALSE - ] TIMING_PROTECTION = FALSE; - APPLICATION_TYPE ACCESSING_APPLICATION[]; - }; - - COUNTER [] { - ENUM [ HARDWARE, SOFTWARE ] TYPE = HARDWARE; - APPLICATION_TYPE ACCESSING_APPLICATION[]; - }; - - RESOURCE [] { - APPLICATION_TYPE ACCESSING_APPLICATION[]; - }; - - SCHEDULETABLE [] { - COUNTER_TYPE COUNTER; - ENUM [ - NONE, - ABSOLUTE { UINT64 START; APPMODE_TYPE APPMODE[]; }, - RELATIVE { UINT64 OFFSET; APPMODE_TYPE APPMODE[]; }, - SYNCHRON { APPMODE_TYPE APPMODE[]; } - ] AUTOSTART = NONE; - BOOLEAN [ - TRUE { - ENUM [ IMPLICIT, EXPLICIT ] SYNC_STRATEGY; - UINT64 PRECISION; - }, - FALSE - ] LOCAL_TO_GLOBAL_TIME_SYNCHRONIZATION; - BOOLEAN PERIODIC; - UINT64 LENGTH; - STRUCT { - UINT64 OFFSET; - ENUM [ - ACTIVATETASK { TASK_TYPE TASK; }, - SETEVENT { TASK_TYPE TASK; EVENT_TYPE EVENT; } - ] ACTION []; - BOOLEAN [ - TRUE { UINT64 MAX_ADVANCE; UINT64 MAX_RETARD; }, - FALSE - ] ADJUSTABLE = FALSE; - } EXPIRY_POINT []; - APPLICATION_TYPE ACCESSING_APPLICATION[]; - }; - +IMPLEMENTATION trampoline_autosar { APPLICATION [] { - BOOLEAN [ - TRUE { IDENTIFIER TRUSTED_FUNCTION []; }, - FALSE - ] TRUSTED = FALSE; - BOOLEAN STARTUPHOOK = FALSE; - BOOLEAN SHUTDOWNHOOK = FALSE; - BOOLEAN ERRORHOOK = FALSE; - BOOLEAN [ - TRUE { TASK_TYPE RESTARTTASK; }, - FALSE - ] HAS_RESTARTTASK = FALSE; - TASK_TYPE TASK []; - ISR_TYPE ISR []; - ALARM_TYPE ALARM []; - SCHEDULETABLE_TYPE SCHEDULETABLE []; - COUNTER_TYPE COUNTER []; RESOURCE_TYPE RESOURCE []; - MESSAGE_TYPE MESSAGE []; }; }; - -/*#include "api_autosar.oil"*/ diff --git a/goil/templates/config/config4.0.oil b/goil/templates/config/config4.0.oil index 5bef9afab..1c3270917 100755 --- a/goil/templates/config/config4.0.oil +++ b/goil/templates/config/config4.0.oil @@ -1,60 +1,9 @@ +/* + * AUTOSAR 4.0 + * + * This version of AUTOSAR is basically the 3.1 plus the multicore one. + */ #include "config3.1.oil" - -IMPLEMENTATION autosar4 { - OS { - UINT32 [1..65535] NUMBER_OF_CORES = 1; - }; - - IOC [] { - STRUCT { - ENUM [ - DATA, - REFERENCE - ] DATATYPEPROPERTY; - } DATATYPENAME []; - - ENUM [ - QUEUED { - UINT32 BUFFER_LENGTH; - }, - LAST_IS_BEST { - STRING WITH_AUTO INIT_VALUE_SYMBOL = AUTO; - } - ] SEMANTICS = QUEUED; - - STRUCT { - APPLICATION_TYPE RCV_OSAPPLICATION; - STRING WITH_AUTO RECEIVER_PULL_CB = AUTO; - ENUM [ - NONE, - ACTIVATETASK { TASK_TYPE TASK; }, - SETEVENT {TASK_TYPE TASK; EVENT_TYPE EVENT; } - ] ACTION = NONE; - } RECEIVER []; - - STRUCT { - UINT32 WITH_AUTO SENDER_ID = AUTO; - APPLICATION_TYPE SND_OSAPPLICATION; - } SENDER [] ; - - }; - - SPINLOCK [] { - APPLICATION_TYPE ACCESSING_APPLICATION []; - SPINLOCK_TYPE SUCCESSOR[]; - ENUM [ - LOCK_ALL_INTERRUPTS, - LOCK_CAT2_INTERRUPTS, - LOCK_WITH_RES_SCHEDULER, - LOCK_NOTHING - ] LOCKMETHOD = LOCK_NOTHING; - }; - - APPLICATION [] { - IOC_TYPE IOC []; - UINT32 CORE = 0; - }; - -}; +#include "autosar_multicore.oil" /*#include "api_ioc.oil"*/ diff --git a/goil/templates/config/config4.2.oil b/goil/templates/config/config4.2.oil new file mode 100644 index 000000000..386be8c71 --- /dev/null +++ b/goil/templates/config/config4.2.oil @@ -0,0 +1,9 @@ +/* + * AUTOSAR 4.2 + * + * This version of AUTOSAR is the common plus the multicore one. + * Compared to 4.0, RESOURCE attribute is no longer included in + * APPLICATION object + */ +#include "autosar_common.oil" +#include "autosar_multicore.oil" diff --git a/goil/templates/lib/check.gtm b/goil/templates/lib/check.gtm new file mode 100644 index 000000000..bc2e083af --- /dev/null +++ b/goil/templates/lib/check.gtm @@ -0,0 +1,10 @@ +% +# +# Various checking getter and functions +# +getter @string isUnsigned() result + let result := true + loop i from 0 to [self length] - 1 do + let result := result & [[self charAtIndex : i] isDigit] + end loop +end getter \ No newline at end of file diff --git a/goil/templates/root.goilTemplate b/goil/templates/root.goilTemplate index e632b09e6..19a764c04 100644 --- a/goil/templates/root.goilTemplate +++ b/goil/templates/root.goilTemplate @@ -22,6 +22,7 @@ # $URL$ # +import "check" import "vectors" #------------------------------------------------------------------------------* @@ -41,6 +42,24 @@ if not exists OS then error here : "No OS object defined in your OIL files. Unable to generate a system" end if +#------------------------------------------------------------------------------* +# OIL version is a string. Check it contains a X.Y string where X and Y are +# unsigned integers. + +let oilVersionItems := [OILVERSION componentsSeparatedByString: "."] +if [oilVersionItems length] != 2 then + error OILVERSION : "Badly formatted OILVERSION attribute. It should take the form X.Y, where X is the major version and Y the minor version." +end if +if not [oilVersionItems[0] isUnsigned] then + error OILVERSION : "Major version is not an unsigned number" +end if +if not [oilVersionItems[1] isUnsigned] then + error OILVERSION : "Minor version is not an unsigned number" +end if +let OILMAJOR := [oilVersionItems[0] unsigned] +let OILMINOR := [oilVersionItems[1] unsigned] +let OILDECIMAL := OILMAJOR * 10 + OILMINOR + #------------------------------------------------------------------------------* # Check the OIL version conforms to declarations if OILVERSION == "2.5" then @@ -55,7 +74,7 @@ end if # # AUTOSAR is true if OIL_VERSION is 3.1 # -let AUTOSAR := (OILVERSION == "3.1" | OILVERSION == "4.0") +let AUTOSAR := (OILVERSION == "3.1" | OILVERSION == "4.0" | OILVERSION == "4.2") #------------------------------------------------------------------------------* # Compute a default OS::NUMBER_OF_CORES if it is not defined @@ -448,18 +467,22 @@ if AUTOSAR & OS::SCALABILITYCLASS >= 3 then end foreach let ALARM := alarm_with_app - # Normally a resource should not be in any application. Fix that. - let rez_with_app := @() - foreach resource in RESOURCE do - if not exists resource_map[resource::NAME] then - error resource::NAME : "Resource "+resource::NAME+" does not belong to any Application" - else - let app := [resource_map[resource::NAME] first] - let resource::APPLICATION := app - let rez_with_app += resource - end if - end foreach - let RESOURCE := rez_with_app + # In AUTOSAR 3.1 and 4.0, a RESOURCE should belong to an OS APPLICATION but + # in AUTOSAR 4.2, It should not. So the following checking is only + # done in AUTOSAR 3.1 and 4.0 + if OILVERSION == "4.0" | OILVERSION == "3.1" then + let rez_with_app := @() + foreach resource in RESOURCE do + if not exists resource_map[resource::NAME] then + error resource::NAME : "Resource "+resource::NAME+" does not belong to any Application" + else + let app := [resource_map[resource::NAME] first] + let resource::APPLICATION := app + let rez_with_app += resource + end if + end foreach + let RESOURCE := rez_with_app + end if let mess_with_app := @() foreach message in MESSAGE do diff --git a/os/tpl_os_resource_kernel.h b/os/tpl_os_resource_kernel.h index 299873f48..312a6aae8 100644 --- a/os/tpl_os_resource_kernel.h +++ b/os/tpl_os_resource_kernel.h @@ -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 @@ -38,31 +38,32 @@ * * This structure describes all attributes of a resource */ -struct TPL_RESOURCE { +struct TPL_RESOURCE +{ 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 before accessing 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 before accessing to + the resource. This field is used to restore + the priority of the task when the resource + is released */ VAR(tpl_proc_id, TYPEDEF) - owner; /**< Id of the owner of the resource or -1 - if the resource is not owned */ -#if WITH_OSAPPLICATION == YES + owner; /**< Id of the owner of the resource or -1 + if the resource is not owned */ +#if RESOURCE_BELONGS_TO_OS_APP == YES CONST(tpl_app_id, TYPEDEF) - app_id; /**< Id of the OS Application which owns the - resource. */ + app_id; /**< Id of the OS Application which owns the + resource. */ #endif #if WITH_ID == YES CONST(tpl_resource_id, TYPEDEF) - res_id; /**< Index of the resource in the resource table */ + res_id; /**< Index of the resource in the resource table */ #endif - struct P2VAR(TPL_RESOURCE, TYPEDEF, OS_APPL_DATA) - next_res; /**< Pointer to the next resource used to link - them together when a task get more than one - resource */ + struct P2VAR(TPL_RESOURCE, TYPEDEF, + OS_APPL_DATA) next_res; /**< Pointer to the next resource used to + link them together when a task get + more than one resource */ }; /** @@ -75,26 +76,26 @@ struct TPL_RESOURCE { typedef struct TPL_RESOURCE tpl_resource; #if RESOURCE_COUNT > 0 -# if NUMBER_OF_CORES == 1 +#if NUMBER_OF_CORES == 1 /** * Array of all resources descriptors * * Index in this array correspond to the #ResourceType of the resource */ -extern CONSTP2VAR(tpl_resource, AUTOMATIC, OS_APPL_DATA) - tpl_resource_table[RESOURCE_COUNT]; -# define TPL_RESOURCE_TABLE(a_core_id) tpl_resource_table -# else +extern CONSTP2VAR(tpl_resource, AUTOMATIC, + OS_APPL_DATA) tpl_resource_table[RESOURCE_COUNT]; +#define TPL_RESOURCE_TABLE(a_core_id) tpl_resource_table +#else /** * Array of all resources descriptors * * In multicore, tpl_ressource_table is an array indexed by a core id * containing the addresses of the core's tpl_ressource_table. */ -extern CONSTP2CONST(tpl_resource*, AUTOMATIC, OS_CONST) - tpl_resource_table[NUMBER_OF_CORES]; -# define TPL_RESOURCE_TABLE(a_core_id) (tpl_resource_table[a_core_id]) -# endif +extern CONSTP2CONST(tpl_resource *, AUTOMATIC, + OS_CONST) tpl_resource_table[NUMBER_OF_CORES]; +#define TPL_RESOURCE_TABLE(a_core_id) (tpl_resource_table[a_core_id]) +#endif #endif /* RESOURCE_COUNT */ @@ -105,26 +106,24 @@ extern CONSTP2CONST(tpl_resource*, AUTOMATIC, OS_CONST) * * @param proc_id process's id */ -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); /** * Getting a resource. * * see #GetResource */ -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); /** * Releasing a resource * * see #ReleaseResource */ -FUNC(tpl_status, OS_CODE) tpl_release_resource_service( - CONST(tpl_resource_id, AUTOMATIC) res); - +FUNC(tpl_status, OS_CODE) +tpl_release_resource_service(CONST(tpl_resource_id, AUTOMATIC) res); #define OS_STOP_SEC_CODE #include "tpl_memmap.h"