Inconsistent eecfg leads to build error

Forum related to ERIKA Enterprise and RT-Druid version 2

Moderator: paolo.gai

AlTi
Newbie
Posts: 40
Joined: Thu Jun 25, 2015 9:52 am

Inconsistent eecfg leads to build error

Post by AlTi » Wed Feb 03, 2016 5:57 pm

Hi,

I get a build error if I add a Resource to my multicore-project and try to build it. The resource is used by 2 ISR2s and one Task on Core0. The error is caused by the definition of this array

Code: Select all

EE_UREG EE_isr2_nesting_level[EE_MAX_ISR2];
which is defined eecfg.c and the declaration in ee_oo_common.h

Code: Select all

extern EE_UREG                EE_isr2_nesting_level[EE_MAX_ISR2_WITH_RESOURCES];
that differs from the definition.

Which one is correct?
Btw: EE_MAX_ISR2 is 5 in eecfg.h, but there are only 2 ISR2s in the application. 1 additional ISR2 because of the rpc and the others?

Here´s the complete eecfg.h with all options:

Code: Select all

#ifndef RTDH_EECFG_H
#define RTDH_EECFG_H


#define RTDRUID_CONFIGURATOR_NUMBER 1278



/***************************************************************************
 *
 * Common defines ( CPU 0 )
 *
 **************************************************************************/

    /* TASK definition */
    #define EE_MAX_TASK 2
    #define TaskERSIn 0
    #define TaskERSOut 1

    /* MUTEX definition */
    #define EE_MAX_RESOURCE 2U
    #define RES_SCHEDULER 0U
    #define ResourceCAN 1U

    #define EE_MAX_ISR2_WITH_RESOURCES 2
    #define EE_ISR2_MAX_LEVEL          11U

    /* ALARM definition */
    #define EE_MAX_ALARM 2U
    #define Alarm1 0U
    #define Alarm2 1U

    /* SCHEDULING TABLE definition */
    #define EE_MAX_SCHEDULETABLE 0U

    /* COUNTER OBJECTS definition */
    #define EE_MAX_COUNTER_OBJECTS (EE_MAX_ALARM + EE_MAX_SCHEDULETABLE)

    /* CPU CLOCK definition */
    #define EE_CPU_CLOCK      200000000U

    /* COUNTER definition */
    #define EE_MAX_COUNTER 1U
    #define SystemTimer 0U

    /* APPMODE definition */
    #define EE_MAX_APPMODE 1U

    /* CPUs */
    #define EE_MAX_CPU 2
    #define EE_CURRENTCPU 0

    /* Number of isr 2 */
    /* Remote procedure call requires an additional ISR2 */
    #define EE_MAX_ISR2   5
    #define EE_MAX_ISR_ID 12

#ifndef __DISABLE_EEOPT_DEFINES__


/***************************************************************************
 *
 * User options
 *
 **************************************************************************/
#define EE_DEBUG
#define __ASSERT__
#define EE_SAVE_TEMP_FILES
#define EE_ICACHE_ENABLED
#define EE_DCACHE_ENABLED
#define EE_BUILD_SINGLE_ELF


/***************************************************************************
 *
 * Automatic options
 *
 **************************************************************************/
#define __RTD_CYGWIN__
#define __MSRP__
#define EE_TRICORE__
#define EE_TC27X__
#define EE_BUILD_SINGLE_ELF
#define EE_GNU__
#define EE_START_CPU1
#define ENABLE_SYSTEM_TIMER
#define EE_AS_RPC__
#define EE_AS_USER_SPINLOCKS__
#define EE_AS_OSAPPLICATIONS__
#define __EE_MEMORY_PROTECTION__
#define __OO_BCC1__
#define __OO_EXTENDED_STATUS__
#define __OO_HAS_STARTUPHOOK__
#define __OO_HAS_SHUTDOWNHOOK__
#define __MULTI__
#define EE_SERVICE_PROTECTION__
#define __OO_HAS_USERESSCHEDULER__
#define __OO_ISR2_RESOURCES__
#define __OO_AUTOSTART_ALARM__
#define __ALLOW_NESTED_IRQ__
#define EE_AS_HAS_PROTECTIONHOOK__
#define EE_STACK_MONITORING__

#endif



/***************************************************************************
 *
 * Remote tasks
 *
 **************************************************************************/
    #define TaskBalancing ((EE_TID)2U + (EE_TID)EE_REMOTE_TID)
    #define TaskChargeHeating ((EE_TID)3U + (EE_TID)EE_REMOTE_TID)
    #define TaskCharging ((EE_TID)4U + (EE_TID)EE_REMOTE_TID)
    #define TaskFlyHeating ((EE_TID)5U + (EE_TID)EE_REMOTE_TID)


/***************************************************************************
 *
 * Remote alarms
 *
 **************************************************************************/


/***************************************************************************
 *
 * Remote counters
 *
 **************************************************************************/


/***************************************************************************
 *
 * Remote OsApplication
 *
 **************************************************************************/
    #define App_ERM ((EE_TID)2U + (EE_TID)EE_REMOTE_TID)
    #define App_Shared_Data_Access_Layer_CPU1 ((EE_TID)3U + (EE_TID)EE_REMOTE_TID)


/***************************************************************************
 *
 * Remote Schedule Tables
 *
 **************************************************************************/


/***************************************************************************
 *
 * Spin lock IDs
 *
 **************************************************************************/
    #define EE_MAX_SPINLOCK_USER 2

    #define EE_SPINLOCK_CORE0 3U	 /* master */
    #define EE_SPINLOCK_CORE1 2U	 /* slave1 */
    #define spinlock_test_assert 0U
    #define spinlock_1 1U
    #define EE_MAX_SPINLOCK 4
    #define EE_MAX_SPINLOCK_OS 4


    /* System stack size */
    #define EE_SYS_STACK_SIZE     8192



/***************************************************************************
 *
 * ISR definition
 *
 **************************************************************************/
#define EE_TC_10_ISR ISR_CAN_Rcv_FIFO_Full_Handler0
#define EE_TC_10_ISR_PRI EE_ISR_PRI_10
#define EE_TC_10_ISR_CAT 2
#define EE_ISR2_ID_ISR_CAN_Rcv_FIFO_Full_Handler0 10
#define EE_TC_11_ISR ISR_CAN_Rcv_FIFO_Full_Handler1
#define EE_TC_11_ISR_PRI EE_ISR_PRI_11
#define EE_TC_11_ISR_CAT 2
#define EE_ISR2_ID_ISR_CAN_Rcv_FIFO_Full_Handler1 11


/***************************************************************************
 *
 * HW counter definition
 *
 **************************************************************************/
#define EE_MAX_COUNTER_HW 1
#define EE_SYSTEM_TIMER   SystemTimer
#define EE_SYSTEM_TIMER_DEVICE   EE_TC_STM_SR0

#define EE_TC_2_ISR EE_tc_system_timer_handler
#define EE_TC_2_ISR_PRI EE_ISR_PRI_2
#define EE_TC_2_ISR_CAT 2
#define EE_ISR2_ID_EE_tc_system_timer_handler 2

/* Max ISR priority */
#define EE_TC_MAX_ISR_ID     EE_ISR_PRI_11



/***************************************************************************
 *
 * OS APPLICATIONS definition
 *
 **************************************************************************/
    #define EE_MAX_APP 3U
    #define App_ERS 1U
    #define App_CAN 2U



/***************************************************************************
 *
 * ISR definition
 *
 **************************************************************************/
    #define EE_MAX_NESTING_LEVEL   5

/* ISR to Application mapping */
    #define ISR2_APP_Internally defined	0
    #define ISR2_APP_SystemTimer	0
    #define ISR2_APP_ISR_CAN_Rcv_FIFO_Full_Handler0	2
    #define ISR2_APP_ISR_CAN_Rcv_FIFO_Full_Handler1	2



/***************************************************************************
 *
 * System Calls
 *
 **************************************************************************/
#define EE_ID_EnableAllInterrupts                      0
#define EE_ID_DisableAllInterrupts                     1
#define EE_ID_ResumeAllInterrupts                      2
#define EE_ID_SuspendAllInterrupts                     3
#define EE_ID_ResumeOSInterrupts                       4
#define EE_ID_SuspendOSInterrupts                      5
#define EE_ID_ActivateTask                             6
#define EE_ID_TerminateTask                            7
#define EE_ID_ChainTask                                8
#define EE_ID_Schedule                                 9
#define EE_ID_ForceSchedule                           10
#define EE_ID_GetTaskID                               11
#define EE_ID_GetTaskState                            12
#define EE_ID_GetActiveApplicationMode                13
#define EE_ID_StartOS                                 14
#define EE_ID_ShutdownOS                              15
#define EE_ID_thread_not_terminated                   16
#define EE_ID_TerminateISR2                           17
#define EE_ID_GetResource                             18
#define EE_ID_ReleaseResource                         19
#define EE_ID_GetAlarmBase                            20
#define EE_ID_GetAlarm                                21
#define EE_ID_SetRelAlarm                             22
#define EE_ID_SetAbsAlarm                             23
#define EE_ID_CancelAlarm                             24
#define EE_ID_IncrementCounter                        25
#define EE_ID_TerminateApplication                    26
#define EE_ID_AllowAccess                             27
#define EE_ID_GetSpinlock                             28
#define EE_ID_ReleaseSpinlock                         29
#define EE_ID_TryToGetSpinlock                        30
#define EE_ID_rpc                                     31
#define EE_ID_ShutdownAllCores                        32
#define EE_ID_CallTrustedFunction                     33
#define EE_ID_TRUSTED_CAN_SendNode2                   34
#define EE_ID_TRUSTED_CAN_Read                        35
#define EE_ID_TRUSTED_test_assert_CPU0                36

#define EE_ID_interrupts_last                          5
#define EE_MAX_SYS_SERVICEID                          34
#define EE_SYSCALL_NR                                 37


/***************************************************************************
 *
 * Counter defines
 *
 **************************************************************************/
#define OSMAXALLOWEDVALUE_SystemTimer 2147483647U
#define OSTICKSPERBASE_SystemTimer    1U
#define OSMINCYCLE_SystemTimer        1U

#define OSMAXALLOWEDVALUE 2147483647U
#define OSTICKSPERBASE    1U
#define OSMINCYCLE        1U
#define OSTICKDURATION    1000000U



/***************************************************************************
 *
 * Vector size defines
 *
 **************************************************************************/
    #define EE_ACTION_ROM_SIZE 2
    #define EE_ALARM_ROM_SIZE 2
    #define EE_AS_RPC_ALARMS_SIZE 2
    #define EE_AS_RPC_COUNTERS_SIZE 1
    #define EE_AS_RPC_OSAPPLS_SIZE 4
    #define EE_AS_RPC_REMOTE_ACCESS_RULES_SIZE 18
    #define EE_AS_RPC_SERVICES_TABLE_SIZE 5
    #define EE_AS_RPC_TASKS_SIZE 6
    #define EE_COUNTER_HW_ROM_SIZE 1
    #define EE_COUNTER_OBJECTS_ROM_SIZE 2
    #define EE_COUNTER_ROM_SIZE 1
    #define EE_OO_AUTOSTART_ALARM_MODE_OSDEFAULTAPPMODE_SIZE 2
    #define EE_TC_SYSTEM_BOS_SIZE 7
    #define EE_TC_SYSTEM_TOS_SIZE 7


#endif


Best regards,
Alex

e.guidieri
Full Member
Posts: 166
Joined: Tue May 10, 2011 2:05 pm

Re: Inconsistent eecfg leads to build error

Post by e.guidieri » Wed Feb 03, 2016 7:15 pm

Could you please copy and paste your OIL too?

I have an idea for what it's going on, I think its tied to the fact that you are using Spinlocks with resorces shared with ISR2 (I suspect that there is not a automatic test with this scenario), but still there's things that I do not understand, as EE_MAX_ISR2 value to 5, because it should be 4 (2 yours + 1 for RPC +1 for system timer).

Out of curiosity, are you using priority 10 and 11 for yours interrupts to give enough priorities to the OS? Because in this case it will be enough if you just leave priority 1 (for RPC) and 2 (for system timer).

Speaking about that I think that with RPC, since the communication is blocking, the inter processor IRQ should have to be configured with the highest ISR2 priority by default, I need to think about that.

Regards,
Errico

paolo.gai
Administrator
Posts: 875
Joined: Thu Dec 07, 2006 12:11 pm

Re: Inconsistent eecfg leads to build error

Post by paolo.gai » Wed Feb 03, 2016 7:29 pm

Well probably having a priority less than the highest should also work, but the risk is to further make the RPC longer (if the interprocessor interrupt is preempted by someone else...

PJ

AlTi
Newbie
Posts: 40
Joined: Thu Jun 25, 2015 9:52 am

Re: Inconsistent eecfg leads to build error

Post by AlTi » Thu Feb 04, 2016 9:20 am

The main reason for using 10/11 as priorities was the even number, but I wasn´t completely sure that ERIKA would use only 2 priorities in any case too.

Here´s the complete oil-File:

Code: Select all

CPU test_application {

OS EE {
	EE_OPT = "EE_DEBUG";
	EE_OPT = "__ASSERT__";
	EE_OPT = "EE_SAVE_TEMP_FILES";
	EE_OPT = "EE_ICACHE_ENABLED";
	EE_OPT = "EE_DCACHE_ENABLED";
	EE_OPT = "EE_BUILD_SINGLE_ELF";	 

	SERVICE_PROTECTION = TRUE;
	MEMORY_PROTECTION = TRUE;
	STACKMONITORING = TRUE;

	REMOTENOTIFICATION = USE_RPC; 

	MASTER_CPU = "master";

	CPU_DATA = TRICORE { 
		CPU_CLOCK = 200.0;
		ID = "master";
		APP_SRC = "master.c";
		APP_SRC = "iLLD_App_Interface/can_app.c";
		APP_SRC = "iLLD_App_Interface/RegisterAccessProtection.c";
		APP_SRC = "iLLD_App_Interface/BusMemoryProtection.c";
		APP_SRC = "App/ERS/ERS.c";
		APP_SRC = "trusted.c";
		APP_SRC = "App/Shared_Data_Access_Functions.c";
		APP_SRC = "App/Shared_Data.c";		
		MULTI_STACK = TRUE;
		COMPILER_TYPE = GNU {
			EXPORT_FILE = "export_master.exp";
		};
	};

	CPU_DATA = TRICORE {
		ID = "slave1";
		APP_SRC = "slave1.c";
		APP_SRC = "App/ERM/Balancing/ERM_Balancing.c";
		APP_SRC = "App/ERM/Charging/ERM_Charging.c";
		APP_SRC = "App/ERM/Heating/ERM_Heating.c";
		APP_SRC = "trusted.c";
		APP_SRC = "App/Shared_Data_Access_Functions.c";
		MULTI_STACK = TRUE;
		COMPILER_TYPE = GNU;
	};

	MCU_DATA = TRICORE {
		MODEL = TC27x;
	};

	STATUS = EXTENDED;
	STARTUPHOOK = TRUE;
	SHUTDOWNHOOK = TRUE;
	PROTECTIONHOOK = TRUE;

	USEREMOTETASK = ALWAYS;
	//USEREMOTEEVENT = ALWAYS; 

	KERNEL_TYPE = BCC1;
};

	TASK TaskERSIn {
		CPU_ID = "master";
		PRIORITY = 7;
		AUTOSTART = FALSE;
		STACK = PRIVATE {
			SYS_SIZE = 512;
		};
		ACTIVATION = 1;
		SCHEDULE = NON;		
		RESOURCE = "ResourceCAN";
	};

	TASK TaskERSOut {
		CPU_ID = "master";
		PRIORITY = 6;
		AUTOSTART = FALSE;
		STACK = PRIVATE {
			SYS_SIZE = 512;
		};
		ACTIVATION = 1;
		SCHEDULE = NON;
		RESOURCE = "ResourceCAN";
	};

	TASK TaskBalancing {
		CPU_ID = "slave1"; 
		PRIORITY = 6;
		AUTOSTART = FALSE;
		STACK = PRIVATE {
			SYS_SIZE = 512;
		};
		ACTIVATION = 1;
		SCHEDULE = NON;		
		ACCESSING_APPLICATION = App_ERS;
	};
	
	TASK TaskChargeHeating {
		CPU_ID = "slave1"; 
		PRIORITY = 5;
		AUTOSTART = FALSE;
		STACK = PRIVATE {
			SYS_SIZE = 512;
		};
		ACTIVATION = 1;
		SCHEDULE = NON;		
		ACCESSING_APPLICATION = App_ERS;
	};
	
	TASK TaskCharging {
		CPU_ID = "slave1"; 
		PRIORITY = 4;
		AUTOSTART = FALSE;
		STACK = PRIVATE {
			SYS_SIZE = 512;
		};
		ACTIVATION = 1;
		SCHEDULE = NON;		
		ACCESSING_APPLICATION = App_ERS;
	};
	
	TASK TaskFlyHeating {
		CPU_ID = "slave1"; 
		PRIORITY = 3;
		AUTOSTART = FALSE;
		STACK = PRIVATE {
			SYS_SIZE = 512;
		};
		ACTIVATION = 1;
		SCHEDULE = NON;		
		ACCESSING_APPLICATION = App_ERS; 
	};
  
	ISR ISR_CAN_Rcv_FIFO_Full_Handler0 {
		CPU_ID = "master";
		CATEGORY = 2;
		PRIORITY = 10;
		HANDLER = "ISR_CAN_Rcv_FIFO_Full_Handler0";
		RESOURCE = "ResourceCAN";
	};

	ISR ISR_CAN_Rcv_FIFO_Full_Handler1 {
		CPU_ID = "master";
		CATEGORY = 2;
		PRIORITY = 11;
		HANDLER = "ISR_CAN_Rcv_FIFO_Full_Handler1";
		RESOURCE = "ResourceCAN";
	};
	
	RESOURCE ResourceCAN { RESOURCEPROPERTY = STANDARD; };
	
	SPINLOCK spinlock_test_assert { 
		ACCESSING_APPLICATION = App_ERS;
		ACCESSING_APPLICATION = App_ERM;
	}; 
	SPINLOCK spinlock_1  { 
		ACCESSING_APPLICATION = App_ERS;
		ACCESSING_APPLICATION = App_ERM;	
	};	

	ALARM Alarm1 { 
		COUNTER = SystemTimer;
		ACTION = ACTIVATETASK{
			TASK = TaskERSIn;
		};
		AUTOSTART = TRUE {
			ALARMTIME = 1;
			CYCLETIME = 40;
		};
	};

	ALARM Alarm2 { 
		COUNTER = SystemTimer;
		ACTION = ACTIVATETASK{
			TASK = TaskERSOut;
		};
		AUTOSTART = TRUE {
			ALARMTIME = 7;	
			CYCLETIME = 40;
		};
	};

	COUNTER SystemTimer { 
		CPU_ID = "master";
		MINCYCLE = 1;
		MAXALLOWEDVALUE = 2147483647;			
		TICKSPERBASE = 1;
		TYPE = HARDWARE {
			DEVICE = "STM_SR0";
			SYSTEM_TIMER = TRUE;
			PRIORITY = 2;
		};
		SECONDSPERTICK = 0.001;
	};  

	APPLICATION App_ERS {
		CPU_ID = "master";	
		TRUSTED = TRUE;
		TASK = TaskERSIn;
		TASK = TaskERSOut;
		ALARM = Alarm1;
		ALARM = Alarm2;
		SHARED_STACK_SIZE = 256;
		IRQ_STACK_SIZE = 256;
	};

	APPLICATION App_CAN {
		CPU_ID = "master";
		TRUSTED = TRUE {
			TRUSTED_FUNCTION = TRUE {
				NAME = "CAN_SendNode2";
			};
			TRUSTED_FUNCTION = TRUE {
				NAME = "CAN_Read";
			};
			TRUSTED_FUNCTION = TRUE {
				NAME = "test_assert_CPU0";
			};
		};
		ISR = "ISR_CAN_Rcv_FIFO_Full_Handler0";
		ISR = "ISR_CAN_Rcv_FIFO_Full_Handler1";
		SHARED_STACK_SIZE = 256;
		IRQ_STACK_SIZE = 256;
	};
	
	APPLICATION App_ERM {
		CPU_ID = "slave1";
		TRUSTED = FALSE;		
		TASK = TaskBalancing; 
    	TASK = TaskChargeHeating;
    	TASK = TaskCharging;
    	TASK = TaskFlyHeating;
		SHARED_STACK_SIZE = 256;
		IRQ_STACK_SIZE = 256;		
	};

	APPLICATION App_Shared_Data_Access_Layer_CPU1 {
		CPU_ID = "slave1";
		TRUSTED = TRUE {
			TRUSTED_FUNCTION = TRUE {
				NAME = "empty1";
			};
			TRUSTED_FUNCTION = TRUE {
				NAME = "test_assert_CPU1";
			};
			TRUSTED_FUNCTION = TRUE {
				NAME = "getLoadingState";
			};
			TRUSTED_FUNCTION = TRUE {
				NAME = "isPowerElectronicsTorque";
			};
			TRUSTED_FUNCTION = TRUE {
				NAME = "getCellVoltage";
			};
			TRUSTED_FUNCTION = TRUE {
				NAME = "getMinCellVoltage";
			};
			TRUSTED_FUNCTION = TRUE {
				NAME = "getAvgCellTemp";
			};
			TRUSTED_FUNCTION = TRUE {
				NAME = "getMaxCellTemp";
			};
			TRUSTED_FUNCTION = TRUE {
				NAME = "getUTMCountHeatingOff";
			};
			TRUSTED_FUNCTION = TRUE {
				NAME = "getUTMCountHeatingOn";
			};
			TRUSTED_FUNCTION = TRUE {
				NAME = "checkUTMs";
			};
			TRUSTED_FUNCTION = TRUE {
				NAME = "getChargingCurr";
			};
			TRUSTED_FUNCTION = TRUE {
				NAME = "getChargingCurrentTarget";
			};
			TRUSTED_FUNCTION = TRUE {
				NAME = "getChargingCurrentMax";
			};
			TRUSTED_FUNCTION = TRUE {
				NAME = "getTemp1";
			};
			TRUSTED_FUNCTION = TRUE {
				NAME = "getTemp2";
			};
			TRUSTED_FUNCTION = TRUE {
				NAME = "getTemp3";
			};
			TRUSTED_FUNCTION = TRUE {
				NAME = "getTemp4";
			};
			TRUSTED_FUNCTION = TRUE {
				NAME = "getMaxCellVolatage";
			};		
			TRUSTED_FUNCTION = TRUE {
				NAME = "setCellBalRes";
			};
			TRUSTED_FUNCTION = TRUE {
				NAME = "setHeating";
			};
			TRUSTED_FUNCTION = TRUE {
				NAME = "setChargingCurrentTarget";
			};
			TRUSTED_FUNCTION = TRUE {
				NAME = "isChargeSwitch";
			};
			TRUSTED_FUNCTION = TRUE {
				NAME = "setStopCharging";
			};
		};
		SHARED_STACK_SIZE = 256;
		IRQ_STACK_SIZE = 256;
	};
};

e.guidieri
Full Member
Posts: 166
Joined: Tue May 10, 2011 2:05 pm

Re: Inconsistent eecfg leads to build error

Post by e.guidieri » Thu Feb 04, 2016 6:55 pm

The code fix has been committed, so you could update your repository working copy and test it. If you have local modifications and don't want to risk conflits this is the patch:

Code: Select all

--- a/pkg/kernel/oo/inc/ee_oo_common.h
+++ b/pkg/kernel/oo/inc/ee_oo_common.h
@@ -449,11 +449,11 @@ extern EE_UREG EE_resource_stack[EE_MAX_RESOURCE];
 #include "MemMap.h"
 #endif /* EE_SUPPORT_MEMMAP_H */
 
-#if defined (EE_MAX_ISR2_WITH_RESOURCES)
+#if (defined(EE_MAX_ISR2_WITH_RESOURCES)) && (!defined(EE_AS_USER_SPINLOCKS__))
 #if (EE_MAX_ISR2_WITH_RESOURCES > 0)
 /* Array to hold corresponding isr2 nesting levels */
 extern EE_UREG                EE_isr2_nesting_level[EE_MAX_ISR2_WITH_RESOURCES]
-#endif /* EE_MAX_ISR2_WITH_RESOURCES > 0 */
+#endif /* (EE_MAX_ISR2_WITH_RESOURCES > 0) && !EE_AS_USER_SPINLOCKS__ */
 #elif defined (EE_MAX_ISR2)
 #if (EE_MAX_ISR2 > 0)
 extern EE_UREG                EE_isr2_nesting_level[EE_MAX_ISR2];
There's still a small issue with RT-Druid that don not generate the right value for EE_MAX_ISR2, but it's not a big deal because it will generate a bigger value than the one needed so the only issue is a small inneficence in size (really, small +4 bytes :) )

This will fixed at dead time (or if someone would pay for it :) )

Errico

AlTi
Newbie
Posts: 40
Joined: Thu Jun 25, 2015 9:52 am

Re: Inconsistent eecfg leads to build error

Post by AlTi » Fri Feb 05, 2016 2:50 pm

Thank you very much and the patch worked :) ... but now I have another question:

My Task ERSIn is activated every 40ms by an alarm that is tied to the system timer. I have observed that this Task sometimes starts the execution delayed ... by 1 to 3ms. This happens only if my ISR2 is called several times in a row (roughly 26 times in 40ms). I would expect some delay because of a possible preemption by the ISR2 (the execution time of the ISR2-Body is about 3us), but I feel that 1-3ms is too much and I would like to know what´s going on. Also, I noticed that the delay is always 1ms*x (x = 1,2,3) - I think my ISR2 interferes with the SystemTimer-ISR2 (called every 1ms).

Another, maybe important info: Inside my ISR2 GetResource/ReleaseResource is called.

Do you have any idea?

e.guidieri
Full Member
Posts: 166
Joined: Tue May 10, 2011 2:05 pm

Re: Inconsistent eecfg leads to build error

Post by e.guidieri » Fri Feb 05, 2016 3:18 pm

As you said I think that the reason for the behaviour you observe is tied to the use of the resource, but you are looking at the wrong side.

From your OIL I see that TaskERSIn and TaskERSOut TASKs use the CAN resourse. these means, because immediate priority ceiling protocol, that the priority of these TASKs when they get the resource raises to the one of CAN interrupts,
masking Interrupts with below priority until the resource is realesed, in fact masking System Timer and Interprocessor Interrupt too (and because of that I think that will be better if we raise the priority of inter processor ISR to ISR2 max...).

So you have to code the critical section with care, shrinking it as much as is possible.

BTW in yours scenario using resources at interrupts level do not provvide advantage from Suspend/Resume interrupts, since the resource is used by the most priviliged ISR.

Regards,
Errico

AlTi
Newbie
Posts: 40
Joined: Thu Jun 25, 2015 9:52 am

Re: Inconsistent eecfg leads to build error

Post by AlTi » Fri Feb 05, 2016 4:06 pm

Ok, I measured the execution time of TaskERSIn and it´s roughly 100us. So let´s assume the critical section is 100us. Could this be an issue since the system timer isr occurs only every 1ms? TaskERSOut doesn´t use the resource - that´s an error in the OIL.

Maybe I will delete the ISR2s because they are not really necessary. :)

e.guidieri
Full Member
Posts: 166
Joined: Tue May 10, 2011 2:05 pm

Re: Inconsistent eecfg leads to build error

Post by e.guidieri » Fri Feb 05, 2016 4:33 pm

Could you try to use the Suspend/Resume AllInterrupts primitives, instead of Get/Release Resource (or just remove ISR2 as you said even though I don't understand how you will handle CAN...).

If the behaviour change and after the change and everything will working it could menas that the problem is in the reasource at isr2 level impletation, otherwise could be somenthing at interrupts level (no idea, what...).

Errico

AlTi
Newbie
Posts: 40
Joined: Thu Jun 25, 2015 9:52 am

Re: Inconsistent eecfg leads to build error

Post by AlTi » Fri Feb 05, 2016 4:59 pm

I will try it.

The ISR2 is not really necessary because I´m using the buffer inside the CAN Controller of the AURIX and this buffer is read out every cycle in TaskERSIn. The ISR2 just handles the exception "buffer overflow".

e.guidieri
Full Member
Posts: 166
Joined: Tue May 10, 2011 2:05 pm

Re: Inconsistent eecfg leads to build error

Post by e.guidieri » Fri Feb 05, 2016 5:05 pm

The best will just remove the resource from ISR2 and handle mutual exclusion in the ISR with less priority, with Suspend/Resume OsInterrupts. Let me know

AlTi
Newbie
Posts: 40
Joined: Thu Jun 25, 2015 9:52 am

Re: Inconsistent eecfg leads to build error

Post by AlTi » Mon Feb 08, 2016 12:43 pm

I removed most of my user-code to have a simple example and I deactivated my second ISR2. SuspendXYZ is only called in the ISR2 now (not anymore in TaskERSIn).

I tested with SuspendOSInterrupts and SuspendAllInterrupts inside the ISR2. To generate the interrupts, I sent CAN-messages to the microcontroller - an Interrupt occurs in my application, when the Rcv-buffer overflows which happens roughly every 10ms in my current test. I measured how often my Tasks and the ISR2 were executed and how often the execution of TaskERSIn gets delayed. The results are:

-With SuspendOSInterrupts:
InCallCNT = 1963
ISR0CallCNT = 7005
TaskExecutionDelayCNT = 4
Maximum Delay measured = 1ms

-With SuspendAllInterrupts:
InCallCNT = 1978
ISR0CallCNT = 70058
TaskExecutionDelayCNT = 11
Maximum Delay measured = 1ms

"Delay count" was higher with SuspendAllInterrupts, but I wouldn´t interpret too much into this.

Here´s my simple test-application:

Code: Select all

EE_UREG InCallCNT;
EE_UREG OutCallCNT;
EE_UREG TaskExecutionDelayCNT;

TASK(TaskERSIn)
{
	MeasureTime(&ERSInFrame, MICRO, frequencyCPU);

	EE_UREG starttime = EE_tc2Yx_stm_get_time_lower_word();
	ERSInFrame.Start = starttime;
	InToOut.Start = starttime;

	if (ERSInFrame.Time > 40200.0){
		++TaskExecutionDelayCNT;
	}

	++InCallCNT;

	ExeTimeTaskERSIn = EE_tc2Yx_stm_get_time_lower_word() - starttime;
	if(ExeTimeTaskERSIn > ExeTimeTaskERSInMax){
		ExeTimeTaskERSInMax = ExeTimeTaskERSIn;
	}

	TerminateTask();
}

TASK(TaskERSOut)
{
	MeasureTime(&InToOut, MICRO, frequencyCPU);
	MeasureTime(&ERSOutFrame, MICRO, frequencyCPU);
	EE_UREG starttime = EE_tc2Yx_stm_get_time_lower_word();
	ERSOutFrame.Start = starttime;

	++OutCallCNT;

	ExeTimeTaskERSOut = EE_tc2Yx_stm_get_time_lower_word() - starttime;
	if(ExeTimeTaskERSOut > ExeTimeTaskERSOutMax){
		ExeTimeTaskERSOutMax = ExeTimeTaskERSOut;
	}

	TerminateTask();
}

EE_UREG ISR0CallCNT;
void ISR_CAN_Rcv_FIFO_Full_Handler0()
{
	EE_UREG starttime = EE_tc2Yx_stm_get_time_lower_word();

	//SuspendOSInterrupts();
	//GetResource(ResourceCAN);
	SuspendAllInterrupts();
	++ISR0CallCNT;

	EE_tc2Yx_delay(5);

	ResumeAllInterrupts();
	//ReleaseResource(ResourceCAN);
	//ResumeOSInterrupts();

	ExeTimeISR1= EE_tc2Yx_stm_get_time_lower_word() - starttime;
	if(ExeTimeISR1 > ExeTimeISR1Max){
		ExeTimeISR1Max = ExeTimeISR1;
	}
}

AlTi
Newbie
Posts: 40
Joined: Thu Jun 25, 2015 9:52 am

Re: Inconsistent eecfg leads to build error

Post by AlTi » Mon Feb 08, 2016 1:02 pm

I have tested another configuration too, without SuspendXYZInterrupts() in the ISR2:

InCallCNT = 1958
ISR0CallCNT = 6716
TaskExecutionDelayCNT = 7
Maximum delay measured = 1ms

Edit: My thought is, that something, most probably in the system-timer-ISR is not interrupt safe.

e.guidieri
Full Member
Posts: 166
Joined: Tue May 10, 2011 2:05 pm

Re: Inconsistent eecfg leads to build error

Post by e.guidieri » Mon Feb 08, 2016 4:40 pm

The only thing that can happen is that, from some reason, maybe for other interrupts or critical sections, the next tick comparison is evaluated in the past;
this is a problem in common with all the upper counting system timers, the best you could do, without complicate too much the tick handling code, is to reduce the time that system syncronize back after such a problem.

The following patch, almost recovered from the original STM implementation, changed after a wrong behaviour you discovered, is probably the best we can do (without complicate too much the code). Actually I cannot test it and so I cannot commit it in the repository: if you want to give a try....

Code: Select all

diff --git a/pkg/mcu/infineon_common_tc2Yx/src/ee_tc2Yx_system.c b/pkg/mcu/infineon_common_tc2Yx/src/ee_tc2Yx_system.c
index ea428c1..8bf8df6 100644
--- a/pkg/mcu/infineon_common_tc2Yx/src/ee_tc2Yx_system.c
+++ b/pkg/mcu/infineon_common_tc2Yx/src/ee_tc2Yx_system.c
@@ -267,21 +267,26 @@ void EE_tc2Yx_stm_set_clockpersec(void)
 EE_STM_SR0_STORAGE void EE_tc2Yx_stm_set_sr0(EE_UINT32 usec,
     EE_TYPEISR2PRIO intvec)
 {
+  EE_UREG  us_in_ticks;
+  EE_UINT8 size_of_compare;
+
   /* I need to make this setup atomic */
   /* USING SUSPEND/RESUME IRQ WOULD BE BETTER (code executable even with isr
      disabled) BUT IS NOT COMPATIBLE WITH NOT-TRUSTED USER-1 PROFILE */
   EE_tc_disableIRQ();
 
-  /*  Evaluate next compare value (actual value + increment,
-      I don't need to handle wrap around) */
+  /* Get Interrupt period in ticks */
+  us_in_ticks = EE_tc2Yx_stm_us_ticks(usec);
+  /* Adjust the size of the mask */
+  size_of_compare = 31U - EE_tc_clz(us_in_ticks);
 
-  /* Set Compare Value Register */
-  EE_STM_CMP0.U = EE_tc2Yx_stm_us_ticks(usec) +
-    EE_tc2Yx_stm_get_time_lower_word();
+  /*  Set Compare Value Register (actual value + increment,
+      I don't need to handle wrap around) */
+  EE_STM_CMP0.U = us_in_ticks + EE_tc2Yx_stm_get_time_lower_word();
 
   if ( intvec != (EE_TYPEISR2PRIO)EE_ISR_UNMASKED ) {
     EE_STM_CMCON.B.MSTART0 = 0U;
-    EE_STM_CMCON.B.MSIZE0  = 31U;
+    EE_STM_CMCON.B.MSIZE0  = size_of_compare;
     /* Tie STM Service Request 0 with Compare Register 0 */
     EE_STM_ICR.B.CMP0OS = 0U;
     /* Enable STM Service Request Source */
@@ -319,18 +324,26 @@ EE_STM_SR0_STORAGE void EE_tc2Yx_stm_set_sr0_next_match(EE_UINT32 usec)
 EE_STM_SR1_STORAGE void EE_tc2Yx_stm_set_sr1(EE_UINT32 usec,
   EE_TYPEISR2PRIO intvec)
 {
+  EE_UREG  us_in_ticks;
+  EE_UINT8 size_of_compare;
+
   /* I need to make this setup atomic */
   /* USING SUSPEND/RESUME IRQ WOULD BE BETTER (code executable even with isr
      disabled) BUT IS NOT COMPATIBLE WITH NOT-TRUSTED USER-1 PROFILE */
   EE_tc_disableIRQ();
-  /*  Evaluate next compare value (actual value + increment,
+
+  /* Get Interrupt period in ticks */
+  us_in_ticks = EE_tc2Yx_stm_us_ticks(usec);
+  /* Adjust the size of the mask */
+  size_of_compare = 31U - EE_tc_clz(us_in_ticks);
+
+  /*  Set Compare Value Register (actual value + increment,
       I don't need to handle wrap around) */
-  EE_STM_CMP1.U = EE_tc2Yx_stm_us_ticks(usec) +
-    EE_tc2Yx_stm_get_time_lower_word();
+  EE_STM_CMP1.U = us_in_ticks + EE_tc2Yx_stm_get_time_lower_word();
 
   if ( intvec != (EE_TYPEISR2PRIO)EE_ISR_UNMASKED ) {
     EE_STM_CMCON.B.MSTART1 = 0U;
-    EE_STM_CMCON.B.MSIZE1  = 31U;
+    EE_STM_CMCON.B.MSIZE1  = size_of_compare;
     /* Tie STM Service Request 1 with Compare Register 1 */
     EE_STM_ICR.B.CMP1OS = 1U;
     /* Enable STM Service Request Source */
Regards,
Errico Guidieri

AlTi
Newbie
Posts: 40
Joined: Thu Jun 25, 2015 9:52 am

Re: Inconsistent eecfg leads to build error

Post by AlTi » Wed Feb 10, 2016 10:25 am

Hi Errico, thanks for the patch, but I still have problems to apply the patches. I always get an error "corrupt patch at line 6" when I try to do "git apply patch". Maybe it´s a format issue? Wen can either figure this out or you just copy the whole file.
Attachments
patch.PNG
patch.PNG (48.6 KiB) Viewed 5445 times

Post Reply