1 /* -------------------------------- Arctic Core ------------------------------
2 * Arctic Core - the open source AUTOSAR platform http://arccore.com
4 * Copyright (C) 2009 ArcCore AB <contact@arccore.com>
6 * This source code is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published by the
8 * Free Software Foundation; See <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * -------------------------------- Arctic Core ------------------------------*/
30 #include "internal.h"
\r
33 #include "ext_config.h"
\r
36 #define valid_standard_id() (rid->nr < Oil_GetResourceCnt()) //&& !(rid->type == RESOURCE_TYPE_INTERNAL) )
\r
37 #define valid_internal_id() (rid->nr < Oil_GetResourceCnt()) //&& (rid->type == RESOURCE_TYPE_INTERNAL) )
\r
40 static StatusType GetResource_( resource_obj_t * );
\r
41 StatusType ReleaseResource_( resource_obj_t * );
\r
43 StatusType GetResource( ResourceType ResID ) {
\r
44 resource_obj_t *rid = Oil_GetResource(ResID);
\r
45 StatusType rv = GetResource_(rid);
\r
50 OS_STD_END_1(OSServiceId_GetResource,ResID);
\r
54 StatusType GetResourceInternal( ResourceType ResID ) {
\r
55 return GetResource_(ResID,1);
\r
59 static StatusType GetResource_( resource_obj_t * rid ) {
\r
60 StatusType rv = E_OK;
\r
62 if( rid->nr == RES_SCHEDULER ) {
\r
63 // Lock the sheduler
\r
65 os_sys.scheduler_lock = 1;
\r
66 //simple_printf("RES_SCHEDULER, NOT supported yet\n");
\r
69 // Check if valid resource
\r
70 if( !valid_standard_id() ) {
\r
74 // Check that the resource does not belong to another application or task
\r
75 if( ( (os_task_nr_to_mask(get_curr_pid()) & rid->task_mask ) == 0 )
\r
76 || ( get_curr_application_id() != rid->application_owner_id)
\r
77 || ( rid->owner != (TaskType)(-1)))
\r
83 rid->owner = get_curr_pid();
\r
84 rid->old_task_prio = os_pcb_set_prio(os_get_curr_pcb() ,rid->ceiling_priority);
\r
92 StatusType ReleaseResource( ResourceType ResID) {
\r
93 StatusType rv = E_OK;
\r
94 if( ResID == RES_SCHEDULER ) {
\r
96 os_sys.scheduler_lock=0;
\r
98 resource_obj_t *rid = Oil_GetResource(ResID);
\r
99 rv = ReleaseResource_(rid);
\r
105 OS_STD_END_1(OSServiceId_ReleaseResource,ResID);
\r
108 StatusType ReleaseResource_( resource_obj_t * rid ) {
\r
109 if (!valid_standard_id()) {
\r
114 rid->owner = (TaskType) (-1);
\r
115 os_pcb_set_prio(os_get_curr_pcb(), rid->old_task_prio);
\r
121 // TODO: Remove this function later.. this is done in oil generator
\r
123 void os_resource_calc_attributes( void ) {
\r
125 // ResourceType *rsrc;
\r
126 for( int i=0;i<Oil_GetResourceCnt();i++) {
\r
127 // rsrc = Oil_GetResource();
\r
128 /* TODO: Do this when there's more time */
\r
134 void os_resource_get_internal( void ) {
\r
135 resource_obj_t *rt = os_get_resource_int_p();
\r
138 //simple_printf("Get IR proc:%s prio:%d old_task_prio:%d\n",get_curr_pcb()->name, rt->ceiling_priority,rt->old_task_prio);
\r
141 //GetResourceInternal(os_get_curr_pcb()->resource_internal);
\r
144 void os_resource_release_internal( void ) {
\r
145 resource_obj_t *rt = os_get_resource_int_p();
\r
148 //simple_printf("Rel IR proc:%s prio:%d old_task_prio:%d\n",get_curr_pcb()->name,rt->ceiling_priority,rt->old_task_prio);
\r
149 ReleaseResource_(rt);
\r
151 //ReleaseResource(os_get_curr_pcb()->resource_internal);
\r