From 457521399bcb28366bc1003522bbcbbb9f5ffc5b Mon Sep 17 00:00:00 2001 From: mahi Date: Sun, 7 Mar 2010 11:05:07 +0100 Subject: [PATCH] Again, changes to generator macro. GEN_RESOURCE, GEN_ETASK, GEN_BTASK have changed --- examples/simple/config/Os_Cfg.c | 55 +++++------- examples/tiny/config/Os_Cfg.c | 58 ++++++------- include/Os.h | 6 -- include/os_config_macros.h | 101 +++++++---------------- system/kernel/include/alarm_i.h | 3 +- system/kernel/include/kernel.h | 29 +++---- system/kernel/init.c | 12 ++- system/kernel/resource.c | 52 ++++++------ system/kernel/testsystem/config/Os_Cfg.c | 28 +++---- tools/t32/config.cmm | 44 +++++----- tools/t32/load.cmm | 58 +++++++++++-- tools/t32/start.cmm | 25 +++--- 12 files changed, 231 insertions(+), 240 deletions(-) diff --git a/examples/simple/config/Os_Cfg.c b/examples/simple/config/Os_Cfg.c index c0ae401c..ea0a9c9d 100644 --- a/examples/simple/config/Os_Cfg.c +++ b/examples/simple/config/Os_Cfg.c @@ -29,26 +29,13 @@ OsTickType OsTickFreq = 1000; // atleast 1 #define SERVICE_CNT 1 - - -#if ( OS_SC3 == STD_ON) || ( OS_SC4==STD_ON) -GEN_TRUSTEDFUNCTIONS_LIST - -//--- APPLICATIONS ---- - -GEN_APPLICATION_HEAD { - - GEN_APPLICATON( 0, - "application_1", - true, - NULL,NULL,NULL , 0,0,0,0,0,0 ) -}; -#endif // --- RESOURCES --- GEN_RESOURCE_HEAD { - GEN_RESOURCE(RES_SCHEDULER,RESOURCE_TYPE_STANDARD,0,0,0), // Standard resource.. + GEN_RESOURCE( RES_SCHEDULER, + RESOURCE_TYPE_STANDARD, /* standard, linked, internal */ + 0) /* ceiling priority */ }; //--- TASKS ---- @@ -60,33 +47,33 @@ DECLARE_STACK(btask_3,PRIO_STACK_SIZE); GEN_TASK_HEAD { GEN_ETASK( OsIdle, - 0, - true/*auto*/, - NULL/*tm*/, - APPLICATION_ID_application_1/*app*/, - NULL/*rsrc*/), + 0, + FULL, /* scheduling */ + true, /* autostart */ + NULL, /* internal resource */ + 0 /* rsrc mask */), GEN_ETASK( etask_1, 1, - true/*auto*/, - NULL/*tm*/, - APPLICATION_ID_application_1/*app*/, - NULL/*rsrc*/), + FULL, /* scheduling */ + true, /* autostart */ + NULL, /* internal resource */ + 0 /* rsrc mask */), GEN_ETASK( etask_2, 2, - true/*auto*/, - NULL/*tm*/, - APPLICATION_ID_application_1/*app*/, - NULL/*rsrc*/), - + FULL, /* scheduling */ + true, /* autostart */ + NULL, /* internal resource */ + 0 /* rsrc mask */), GEN_BTASK( btask_3, 3, - false/*auto*/, - NULL/*tm*/, - APPLICATION_ID_application_1/*app*/, - NULL/*rsrc*/), + FULL, /* scheduling */ + false, /* autostart */ + NULL, /* internal resource */ + 0, /* rsrc mask */ + 1 /* activation limit */), }; GEN_PCB_LIST() diff --git a/examples/tiny/config/Os_Cfg.c b/examples/tiny/config/Os_Cfg.c index dfce64b5..b5665195 100644 --- a/examples/tiny/config/Os_Cfg.c +++ b/examples/tiny/config/Os_Cfg.c @@ -36,7 +36,7 @@ OsTickType OsTickFreq = 1000; // --- RESOURCES --- GEN_RESOURCE_HEAD { - GEN_RESOURCE(RES_SCHEDULER,RESOURCE_TYPE_STANDARD,0,0,0), // Standard resource.. + GEN_RESOURCE(RES_SCHEDULER,RESOURCE_TYPE_STANDARD,0), // Standard resource.. }; //--- TASKS ---- @@ -47,34 +47,34 @@ DECLARE_STACK(etask_2,PRIO_STACK_SIZE); DECLARE_STACK(btask_3,PRIO_STACK_SIZE); GEN_TASK_HEAD { - GEN_ETASK( OsIdle, - 0, - true/*auto*/, - NULL/*tm*/, - APPLICATION_ID_application_1/*app*/, - NULL/*rsrc*/), - - GEN_ETASK( etask_1, - 1, - true/*auto*/, - NULL/*tm*/, - APPLICATION_ID_application_1/*app*/, - NULL/*rsrc*/), - - GEN_ETASK( etask_2, - 2, - true/*auto*/, - NULL/*tm*/, - APPLICATION_ID_application_1/*app*/, - NULL/*rsrc*/), - - - GEN_BTASK( btask_3, - 3, - false/*auto*/, - NULL/*tm*/, - APPLICATION_ID_application_1/*app*/, - NULL/*rsrc*/), + GEN_ETASK( OsIdle, + 0, + FULL, /* scheduling */ + true, /* autostart */ + NULL, /* internal resource */ + 0 /* rsrc mask */), + + GEN_ETASK( etask_1, + 1, + FULL, /* scheduling */ + true, /* autostart */ + NULL, /* internal resource */ + 0 /* rsrc mask */), + + GEN_ETASK( etask_2, + 2, + FULL, /* scheduling */ + true, /* autostart */ + NULL, /* internal resource */ + 0 /* rsrc mask */), + + GEN_BTASK( btask_3, + 3, + FULL, /* scheduling */ + false, /* autostart */ + NULL, /* internal resource */ + 0, /* rsrc mask */ + 1 /* activation limit */), }; GEN_PCB_LIST() diff --git a/include/Os.h b/include/Os.h index 4bcadec6..1c484a52 100644 --- a/include/Os.h +++ b/include/Os.h @@ -215,12 +215,6 @@ static inline void ResumeOSInterrupts( void ) { Irq_ResumeOs(); } } - -#if 0 -/* Can't find these anymore, removed from Autosar? */ -StatusType EnableInterruptSource( ISRType EnableISR ); -StatusType DisableInterruptSource( ISRType EnableISR ); -#endif /* * Class 2,3 and 4 API diff --git a/include/os_config_macros.h b/include/os_config_macros.h index b3e9507d..7d627ce9 100644 --- a/include/os_config_macros.h +++ b/include/os_config_macros.h @@ -61,45 +61,20 @@ -#if !( OS_CFG_API_VERSION) - -#define GEN_ETASK( _id, _priority, _autostart, _timing_protection, _application_id, _resource_int_p ) \ -{ \ - .pid = TASK_ID_##_id, \ - .name = #_id, \ - .entry = _id, \ - .prio = _priority, \ - .proc_type = PROC_EXTENDED, \ - .stack.size = sizeof stack_##_id, \ - .stack.top = stack_##_id, \ - .autostart = _autostart, \ - .timing_protection = _timing_protection,\ - .application_id = _application_id, \ - .resource_int_p = _resource_int_p, \ - .scheduling = FULL, \ - .resourceAccess = -1UL \ -} - -#define GEN_BTASK( _id, _priority, _autostart, _timing_protection, _application_id, _resource_int_p ) \ -{ \ - .pid = TASK_ID_##_id, \ - .name = #_id, \ - .entry = _id, \ - .prio = _priority, \ - .proc_type = PROC_BASIC, \ - .stack.size = sizeof stack_##_id, \ - .stack.top = stack_##_id, \ - .autostart = _autostart, \ - .timing_protection = _timing_protection,\ - .application_id = _application_id, \ - .resource_int_p = _resource_int_p, \ - .scheduling = FULL, \ - .resourceAccess = -1UL \ -} -#else - -#define GEN_ETASK( _id, _priority, _autostart, _timing_protection, _application_id, \ - _resource_int_p, _scheduling, _resource_mask ) \ +/** + * _id + * _priority The task priority + * _autostart true/false + * _resource_int_p Pointer to internal resource. + * NULL - if no internal resource or scheduling==NON + * Pointer to + * _scheduling FULL or NON + * _resource_mask Mask of the resources used. Applies to STANDARD and LINKED (NOT INTERNAL) + * For example if this task would use resource with id 2 and 4 the mask would + * become (1<<2)|(1<<4) = 0x14 (limits resources to 32). + * Currently used for calculating the ceiling priority. + */ +#define GEN_ETASK( _id, _priority, _scheduling, _autostart, _resource_int_p, _resource_mask ) \ { \ .pid = TASK_ID_##_id, \ .name = #_id, \ @@ -109,16 +84,13 @@ .stack.size = sizeof stack_##_id, \ .stack.top = stack_##_id, \ .autostart = _autostart, \ - .timing_protection = _timing_protection,\ - .application_id = _application_id, \ .resource_int_p = _resource_int_p, \ .scheduling = _scheduling, \ .resourceAccess = _resource_mask, \ .activationLimit = 1, \ } -#define GEN_BTASK( _id, _priority, _autostart, _timing_protection, _application_id, \ - _resource_int_p, _scheduling, _resource_mask, _activation ) \ +#define GEN_BTASK( _id, _priority, _scheduling, _autostart, _resource_int_p, _resource_mask, _activation_limit ) \ { \ .pid = TASK_ID_##_id, \ .name = #_id, \ @@ -128,42 +100,20 @@ .stack.size = sizeof stack_##_id, \ .stack.top = stack_##_id, \ .autostart = _autostart, \ - .timing_protection = _timing_protection,\ - .application_id = _application_id, \ .resource_int_p = _resource_int_p, \ .scheduling = _scheduling, \ .resourceAccess = _resource_mask, \ - .activationLimit = _activation, \ + .activationLimit = _activation_limit, \ } -#endif - - -#define GEN_TASK( _id, _name, _entry, _priority, _process_type, _stack_size, _stack_top, \ - _autostart, _timing_protection, _application_id, _resource_int_p ) \ -{ \ - .pid = _id, \ - .name = _name, \ - .entry = _entry, \ - .prio = _priority, \ - .proc_type = _process_type, \ - .stack.size = _stack_size, \ - .stack.top = _stack_top, \ - .autostart = _autostart, \ - .timing_protection = _timing_protection,\ - .application_id = _application_id, \ - .resource_int_p = _resource_int_p, \ -} -#define GEN_ISR_2( _id, _name, _entry, _priority, _process_type, _vector, _timing_protection, _application_id ) \ +#define GEN_ISR_2( _id, _name, _entry, _priority, _vector ) \ { \ .pid = _id, \ .name = _name, \ .entry = _entry, \ .prio = _priority, \ - .proc_type = _process_type, \ + .proc_type = PROC_ISR2, \ .vector = _vector, \ - .timing_protection = _timing_protection,\ - .application_id = _application_id, \ } @@ -180,14 +130,19 @@ //#define GEN_PCB_LIST() uint8_t pcb_list[PCB_T_SIZE*ARRAY_SIZE(rom_pcb_list)]; #define GEN_PCB_LIST() OsPcbType pcb_list[ARRAY_SIZE(rom_pcb_list)]; -#define GEN_RESOURCE_HEAD OsResourceType resource_list[] = -#define GEN_RESOURCE( _id, _type, _ceiling_priority, _application_id, _task_mask) \ +#define GEN_RESOURCE_HEAD OsResourceType resource_list[] = + + +/** + * _id + * _type RESOURCE_TYPE_STANDARD, RESOURCE_TYPE_LINKED or RESOURCE_TYPE_INTERNAL + * _ceiling_priority The calculated ceiling priority + */ +#define GEN_RESOURCE( _id, _type, _ceiling_priority ) \ { \ .nr= _id, \ .type= _type, \ .ceiling_priority = _ceiling_priority, \ - .application_owner_id = _application_id, \ - .task_mask = _task_mask, \ .owner = (-1), \ } @@ -242,7 +197,7 @@ * _type * _alarms_time * _cycle_time - * _app_mode + * _app_mode Mask of the application modes. */ #define GEN_ALARM_AUTOSTART(_id, _type, _alarm_time, _cycle_time, _app_mode ) \ const OsAlarmAutostartType Os_AlarmAutoStart_ ## _id = \ diff --git a/system/kernel/include/alarm_i.h b/system/kernel/include/alarm_i.h index 19045ee5..4cab47a1 100644 --- a/system/kernel/include/alarm_i.h +++ b/system/kernel/include/alarm_i.h @@ -114,9 +114,8 @@ typedef struct OsAlarm { SLIST_ENTRY(OsAlarm) alarm_list; #if (OS_SC1 == STD_ON) -#warning Alarm callbacks NOT implemented /* TODO: OS242, callback in scalability class 1 only..*/ - /** @req OS242 */ + /** Missing req OS242 */ #endif } OsAlarmType; diff --git a/system/kernel/include/kernel.h b/system/kernel/include/kernel.h index abbbfccf..dbe71750 100644 --- a/system/kernel/include/kernel.h +++ b/system/kernel/include/kernel.h @@ -58,21 +58,20 @@ typedef void ( * trusted_func_t)( TrustedFunctionIndexType , TrustedFunctionPara * OS_RES_SCHEDULER * */ +/** + * STD container: OsResource + * OsResourceProperty: 1 INTERNAL, LINKED, STANDARD + * OsResourceAccessingApplication: 0..* + * OsResourceLinkedResourceRef: 0..1 + */ typedef enum { /* External resource */ - RESOURCE_TYPE_STANDARD, + RESOURCE_TYPE_STANDARD,//!< RESOURCE_TYPE_STANDARD /* ?? */ - RESOURCE_TYPE_LINKED, + RESOURCE_TYPE_LINKED, //!< RESOURCE_TYPE_LINKED /* Internal resource */ - RESOURCE_TYPE_INTERNAL -} OsResourceTypeType; - -typedef struct { - - OsResourceTypeType type; - /* used only if type is RESOURCE_TYPE_LINKED */ - ResourceType linked_resource; + RESOURCE_TYPE_INTERNAL //!< RESOURCE_TYPE_INTERNAL } OsResourcePropertyType; /*-----------------------------------------------------------------*/ @@ -86,15 +85,17 @@ typedef struct OsResource { uint32 old_task_prio; // What application may access this resource. A resource may only be - // accessed by one application - uint32 application_owner_id; + // accessed by one application +#if ( OS_SC3 == STD_ON ) || ( OS_SC4 == STD_ON ) + uint32 application_owner_id; +#endif // What tasks may access this resource. A resource may be be shared // several tasks. - uint32 task_mask; +// uint32 task_mask; // Owner of the resource... TaskType owner; - OsResourceTypeType type; + OsResourcePropertyType type; // used only if type is RESOURCE_TYPE_LINKED ResourceType linked_resource; diff --git a/system/kernel/init.c b/system/kernel/init.c index 8e070e30..7bf7fc46 100644 --- a/system/kernel/init.c +++ b/system/kernel/init.c @@ -93,8 +93,18 @@ static void os_resource_init( void ) { rsrc_p->ceiling_priority = topPrio; } - /* Assign an internal resource with prio 32 to the tasks + + + /* From OSEK: + * Non preemptable tasks are the most common usage of the concept + * of internal resources; they are tasks with a special internal + * resource of highest task priority assigned. + * --> Interpret this as we can set the priority to 32. + * + * Assign an internal resource with prio 32 to the tasks * with scheduling=NON + * + * */ for( int i; i < Oil_GetTaskCnt(); i++) { pcb_p = os_get_pcb(i); diff --git a/system/kernel/resource.c b/system/kernel/resource.c index 4b23f527..379573c7 100644 --- a/system/kernel/resource.c +++ b/system/kernel/resource.c @@ -53,16 +53,16 @@ * */ -#define valid_standard_id() (rid->nr < Oil_GetResourceCnt()) //&& !(rid->type == RESOURCE_TYPE_INTERNAL) ) -#define valid_internal_id() (rid->nr < Oil_GetResourceCnt()) //&& (rid->type == RESOURCE_TYPE_INTERNAL) ) +#define valid_standard_id() (rPtr->nr < Oil_GetResourceCnt()) //&& !(rPtr->type == RESOURCE_TYPE_INTERNAL) ) +#define valid_internal_id() (rPtr->nr < Oil_GetResourceCnt()) //&& (rPtr->type == RESOURCE_TYPE_INTERNAL) ) static StatusType GetResource_( OsResourceType * ); StatusType ReleaseResource_( OsResourceType * ); StatusType GetResource( ResourceType ResID ) { - OsResourceType *rid = Oil_GetResource(ResID); - StatusType rv = GetResource_(rid); + OsResourceType *rPtr = Oil_GetResource(ResID); + StatusType rv = GetResource_(rPtr); if (rv != E_OK) goto err; @@ -70,16 +70,10 @@ StatusType GetResource( ResourceType ResID ) { OS_STD_END_1(OSServiceId_GetResource,ResID); } -#if 0 -StatusType GetResourceInternal( ResourceType ResID ) { - return GetResource_(ResID,1); -} -#endif - -static StatusType GetResource_( OsResourceType * rid ) { +static StatusType GetResource_( OsResourceType * rPtr ) { StatusType rv = E_OK; - if( rid->nr == RES_SCHEDULER ) { + if( rPtr->nr == RES_SCHEDULER ) { // Lock the scheduler os_sys.scheduler_lock = 1; } @@ -89,22 +83,28 @@ static StatusType GetResource_( OsResourceType * rid ) { rv = E_OS_ID; goto err; } - // Check that the resource does not belong to another application or task - if( ( (os_task_nr_to_mask(get_curr_pid()) & rid->task_mask ) == 0 ) + + /* @req OSEK + * Attempt to get a resource which is already occupied by any task + * or ISR, or the statically assigned priority of the calling task or + * interrupt routine is higher than the calculated ceiling priority, + * E_OS_ACCESS + */ + if( (Os_TaskGetCurrent()->prio > rPtr->ceiling_priority ) #if ( OS_SC3 == STD_ON ) || ( OS_SC4 == STD_ON ) - || ( get_curr_application_id() != rid->application_owner_id) + || ( get_curr_application_id() != rPtr->application_owner_id) #endif - || ( rid->owner != (TaskType)(-1))) + || ( rPtr->owner != (TaskType)(-1))) { rv = E_OS_ACCESS; goto err; } - rid->owner = get_curr_pid(); - rid->old_task_prio = os_pcb_set_prio(Os_TaskGetCurrent() ,rid->ceiling_priority); + rPtr->owner = get_curr_pid(); + rPtr->old_task_prio = os_pcb_set_prio(Os_TaskGetCurrent() ,rPtr->ceiling_priority); - if( rid->type != RESOURCE_TYPE_INTERNAL ) { - TAILQ_INSERT_TAIL(&Os_TaskGetCurrent()->resource_head, rid, listEntry); + if( rPtr->type != RESOURCE_TYPE_INTERNAL ) { + TAILQ_INSERT_TAIL(&Os_TaskGetCurrent()->resource_head, rPtr, listEntry); } goto ok; @@ -119,8 +119,8 @@ StatusType ReleaseResource( ResourceType ResID) { if( ResID == RES_SCHEDULER ) { os_sys.scheduler_lock=0; } else { - OsResourceType *rid = Oil_GetResource(ResID); - rv = ReleaseResource_(rid); + OsResourceType *rPtr = Oil_GetResource(ResID); + rv = ReleaseResource_(rPtr); } if (rv != E_OK) @@ -129,15 +129,15 @@ StatusType ReleaseResource( ResourceType ResID) { OS_STD_END_1(OSServiceId_ReleaseResource,ResID); } -StatusType ReleaseResource_( OsResourceType * rid ) { +StatusType ReleaseResource_( OsResourceType * rPtr ) { if (!valid_standard_id()) { return E_OS_ID; } else { // Release it... - rid->owner = (TaskType) (-1); - TAILQ_REMOVE(&Os_TaskGetCurrent()->resource_head, rid, listEntry); - os_pcb_set_prio(Os_TaskGetCurrent(), rid->old_task_prio); + rPtr->owner = (TaskType) (-1); + TAILQ_REMOVE(&Os_TaskGetCurrent()->resource_head, rPtr, listEntry); + os_pcb_set_prio(Os_TaskGetCurrent(), rPtr->old_task_prio); return E_OK; } } diff --git a/system/kernel/testsystem/config/Os_Cfg.c b/system/kernel/testsystem/config/Os_Cfg.c index 4d9d3d13..bd47de9c 100644 --- a/system/kernel/testsystem/config/Os_Cfg.c +++ b/system/kernel/testsystem/config/Os_Cfg.c @@ -129,15 +129,15 @@ uint8 stack_btask_sup_h[STACK_SIZE_btask_sup_h] SECTION_BSS_SUPER; //------------------------------------------------------------------- GEN_RESOURCE_HEAD { - GEN_RESOURCE(RES_SCHEDULER,RESOURCE_TYPE_STANDARD,0,0,0), // Standard resource.. + GEN_RESOURCE(RES_SCHEDULER,RESOURCE_TYPE_STANDARD,0), // Standard resource.. // Internal resources - GEN_RESOURCE(1,RESOURCE_TYPE_INTERNAL,8, APPLICATION_ID_application_1,(1<