Pumpkin, Inc.

Pumpkin User Forums

OS_Delay problem with 2 tasks

For issues specific to TI's MSP430 line of ultra-low-power microcontrollers, including compilers (e.g. Quadravox AQ430), IDEs (e.g. IAR Embedded Workbench) and development tools (e.g. TI MSP-FET430 Flash Emulation Tool).

OS_Delay problem with 2 tasks

Postby saguaro » Fri Jan 23, 2009 5:17 am

Hi, I got a problem with OS_Delay running with two tasks. I am running Salvo 4 Free, with IAR 4 on TI MSP430F1232. When I have only one task and context switch with OS_Delay(250) everything works fine, and the corresponding task switches every 1 second. I have about 4ms tick = 65000 clocks on 16MHz
I am calling OSTimer in TIMER1A interrupt service. The problem is if I add another task with some delay, let say OS_Delay(250) again. At this point strange things happen. Either the second task never runs, or the system resets to the beginning (first line of main loop). Regardless of the priorities I set on the two tasks, I never have switching between the two tasks.


Below is my code posted:

code:

salvocfg.h
#define OSUSE_LIBRARY TRUE
#define OSLIBRARY_TYPE OSF
#define OSLIBRARY_CONFIG OSA
#define OSEVENTS 2
#define OSEVENT_FLAGS 0
#define OSMESSAGE_QUEUES 0
#define OSTASKS 2


void TempInit(void){

OSCreateTask(TempTask, TASK_TEMP, PRIO_TEMP);
no_temp_comp = 0;
temp_calc = 0;


}

TASK1

void TempTask(void) {
while(1){
sensor_voltage = (double)(temp_sum)/50;
}

//OS_Yield();
OS_Delay(50);
}

}


TASK2

void LedInit(void){

OSCreateTask(LedTask, TASK_LED, PRIO_LED);
ucModeCharge = FLASH;
ucModeError = FLASH;


}
////////////////////////////////////////////////////////////////////////////////
void SetChargeLed(unsigned char ucMode){
ucModeCharge = ucMode;
}
////////////////////////////////////////////////////////////////////////////////
void SetErrorLed(unsigned char ucMode){
ucModeError = ucMode;
}
////////////////////////////////////////////////////////////////////////////////

void LedTask(void){


while(1){
bTogleLed ^= 1;

switch(ucModeCharge){
case OFF:
CLED_CHARGE(OFF);
break;
case FLASH:
CLED_CHARGE(bTogleLed);
break;
default :
CLED_CHARGE(ON);
break;
}

switch(ucModeError){
case OFF:
ELED(OFF);
break;
case FLASH:
ELED(bTogleLed);
break;
case ON:
ELED(ON);
break;
default:
break;
}


OS_Delay(250);
//OS_Yield();

}
}


INTERRUPTS

#pragma vector=TIMER1_A1_VECTOR
__interrupt void OS_tick(void) {
OSTimer();
TA1CTL &= ~TAIFG;

}

void OSEnableHook(void){

//TA1CTL = s;
TA1CTL |= TAIE;

}


void OSDisableHook(void){
//istate t = TA1CTL; /* get timer1 interrupt status */
TA1CTL &= ~TAIE; /* disable timer1 interrupt */
//s=t; /* save interrupt status */
}


MAIN

void main(void)
{

__disable_interrupt();



init();
configADC();
OSInit();

TempInit();
LedInit();

__enable_interrupt();

while(1){
OSSched();
}


}


[This message has been edited by aek (edited January 23, 2009).]

saguaro
 
Posts: 3
Joined: Fri Jan 23, 2009 12:00 am
Location: Koper, SI

Re: OS_Delay problem with 2 tasks

Postby aek » Fri Jan 23, 2009 8:24 am

1. I'm not sure that your timer ISR is correct -- you may want to use the "form" that we use in our examples instead.

2. You may be getting hit by the WDT.

The rest looks fine.

------------------

-------
aek
aek
 
Posts: 1888
Joined: Sat Aug 26, 2000 11:00 pm

Re: OS_Delay problem with 2 tasks

Postby saguaro » Sat Jan 24, 2009 10:12 am

Hi,
I have corrected the TIMER usage as in your advice. Previously I have used TIMER1 in UP mode, now I am using TIMER0 in CONTINUOUS mode as documented in the examples. I have also not used my own hooks, but the default that disables all the interrupts. For clarity I have commented out all the computations in the two tasks and have left only the contest switching. However as previously the system is switching with only one task, but crashes (resets) with two tasks.
It is important to mention that I get the following warnings from IAR linker:

Warning[w6]: Type conflict for external/entry "OSCreateTask", in module led against
external/entry in module salvoinit2; function types differ in parameter 2; class/struct/union
types have different sizes
Warning[w6]: Type conflict for external/entry "OScTcbP", in module salvodelay against
external/entry in module salvomem; class/struct/union types have different sizes
Warning[w6]: Type conflict for external/entry "OSsigQinP", in module salvobinsem against
external/entry in module salvomem; class/struct/union types have different sizes
Warning[w6]: Type conflict for external/entry "OSsigQoutP", in module salvobinsem against
external/entry in module salvomem; class/struct/union types have different sizes
Warning[w6]: Type conflict for external/entry "OStcbArea", in module salvocyclic against
external/entry in module salvomem; array types have different element types;
class/struct/union types have different sizes
Warning[w35]: There is more than one definition for the struct/union type with tag 'tcb';
class/struct/union types have different sizes
Warning[w35]: There is more than one definition for the struct/union type with tag 'ecb';
class/struct/union field/base types do not match for field/base 'tcbP'; class/struct/union types
have different sizes

I am very sorry I am asking such an elementary question as a simple switching between two tasks...
If I comment out TempInit(); or LedInit(); the remaining task works, with both of them enabled none of the tasks executes and the system resets periodically. Note that the WATCH DOG is stopped. Hope someone can help me please :)

I am posting the entire code below (lacking only some variables/macro definitions) :

//MAIN
void main(void)
{


__disable_interrupt();
init();
OSInit();
TempInit();
LedInit();
__enable_interrupt();

while(1){
OSSched();
}
}

//INIT
void init(void){
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
DCOCTL = 0xe0;
BCSCTL2 = 0x00;
BCSCTL1 = XT2OFF + RSEL0 + RSEL1 + RSEL2 + RSEL3;
TACTL = TASSEL1 + TACLR; // SMCLK, clear TAR.
CCTL0 = CCIE; // CCR0 interrupt enabled.
CCR0 = 50000; // 10ms ticks.
TACTL |= MC1; // Start Timer_A in continuous mode.
}

//TIMERA0 INTERRUPT
#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A (void)
{
CCR0 += 50000;
OSTimer();
}

//TASK LED
void LedTask(void){


while(1){
bTogleLed ^= 1;

switch(ucModeCharge){
case OFF:
CLED_CHARGE(OFF);
break;
case FLASH:
CLED_CHARGE(bTogleLed);
break;
default :
CLED_CHARGE(ON);
break;
}

switch(ucModeError){
case OFF:
ELED(OFF);
break;
case FLASH:
ELED(bTogleLed);
break;
case ON:
ELED(ON);
break;
default:
break;
}


OS_Delay(100);
//OS_Yield();

}
}

void LedInit(void){

OSCreateTask(LedTask, TASK_LED, PRIO_LED);
ucModeCharge = FLASH;
ucModeError = FLASH;


}

//TASK TEMP

void TempTask(void) {
while(1){
//sensor_voltage = (double)(temp_sum)/50;
// if (sensor_voltage > max_val) no_temp_comp = 1;
// else {
// kt = sensor_voltage/V_25;
// battery_temp = (25.0 + (sqrt(alpha_t*alpha_t - 4.0*beta_t+4.0*beta_t*kt) - alpha_t)/(2.0*beta_t));
// comp_addend = (battery_temp - 25.0)*alpha_N;
// Vbat_max = 842 + (int)(comp_addend*58.457);
// Vbat_min = 743 + (int)(comp_addend*58.457);
// temp_test = (int)(comp_addend*58.457);
//
// }

//OS_Yield();
OS_Delay(250);
}

}

void TempInit(void){

OSCreateTask(TempTask, TASK_TEMP, PRIO_TEMP);
no_temp_comp = 0;
temp_calc = 0;


}


//SALVOCFG

#define OSUSE_LIBRARY TRUE
#define OSLIBRARY_TYPE OSF
#define OSLIBRARY_CONFIG OSA
#define OSEVENTS 2
#define OSEVENT_FLAGS 0
#define OSMESSAGE_QUEUES 0
#define OSTASKS 2


//DEFINITIONS PERTAINING TO SALVO
#define TASK_LED OSTCBP(1)
#define PRIO_LED 3

#define TASK_TEMP OSTCBP(2)
#define PRIO_TEMP 3

saguaro
 
Posts: 3
Joined: Fri Jan 23, 2009 12:00 am
Location: Koper, SI

Re: OS_Delay problem with 2 tasks

Postby aek » Sat Jan 24, 2009 11:08 am

Please copy-and-paste the entire Build Results window (from a Build All).

I suspect you are linking to the wrong library -- those warnings mean the build is not correct.

------------------

-------
aek
aek
 
Posts: 1888
Joined: Sat Aug 26, 2000 11:00 pm

Re: OS_Delay problem with 2 tasks

Postby saguaro » Sun Jan 25, 2009 7:03 am

Here's the Build's messages:

Building configuration: batterycharger - Debug
Updating build tree...
J:SoftwareDebugObjfet120_ta_PWM_batChg.r43
J:SoftwareDebugObjled.r43
J:SoftwareDebugObjsalvomem.r43
J:SoftwareDebugObj emp.r43
J:SoftwareDebugObjfet120_ta_PWM_batChg.pbi
J:SoftwareDebugObjled.pbi
J:SoftwareDebugObjsalvomem.pbi
J:SoftwareDebugObj emp.pbi
J:SoftwareDebugExeatterycharger.d43
J:SoftwareDebugListatterycharger.map
J:SoftwareDebugObjatterycharger.pbd

11 file(s) deleted.
Updating build tree...

fet120_ta_PWM_batChg.c
icc430.exe J:Softwarefet120_ta_PWM_batChg.c -lC J:SoftwareDebugList -o J:Software
DebugObj --no_cse --no_unroll --no_inline --no_code_motion --no_tbaa --debug
-D__MSP430F2132__ -e --double=32 -I D:SalvoInc -I D:SalvoIncIAR430 -I J:Software -I
D:IAR SystemsEmbedded Workbench 5.0430INC -I D:IAR SystemsEmbedded
Workbench 5.0430INCCLIB -On

IAR MSP430 C/C++ Compiler V4.11B/W32 [Kickstart LMS]
Copyright 1996-2008 IAR Systems. All rights reserved.
Warning[Pe177]: variable "s" was declared but never referenced J:Softwarefet120_ta_PWM_batChg.c 76

502 bytes of CODE memory
22 bytes of CONST memory (+ 8 bytes shared)
193 bytes of DATA memory (+ 24 bytes shared)

Errors: none
Warnings: 1

led.c
icc430.exe J:Softwareled.c -lC J:SoftwareDebugList -o J:SoftwareDebugObj --no_cse
--no_unroll --no_inline --no_code_motion --no_tbaa --debug -D__MSP430F2132__ -e
--double=32 -I D:SalvoInc -I D:SalvoIncIAR430 -I J:Software -I D:IAR Systems
Embedded Workbench 5.0430INC -I D:IAR SystemsEmbedded Workbench 5.0430INC
CLIB -On

IAR MSP430 C/C++ Compiler V4.11B/W32 [Kickstart LMS]
Copyright 1996-2008 IAR Systems. All rights reserved.

154 bytes of CODE memory
3 bytes of DATA memory (+ 2 bytes shared)

Errors: none
Warnings: none

salvomem.c
icc430.exe D:SalvoSrcsalvomem.c -lC J:SoftwareDebugList -o J:SoftwareDebugObj
--no_cse --no_unroll --no_inline --no_code_motion --no_tbaa --debug -D__MSP430F2132__
-e --double=32 -I D:SalvoInc -I D:SalvoIncIAR430 -I J:Software -I D:IAR Systems
Embedded Workbench 5.0430INC -I D:IAR SystemsEmbedded Workbench 5.0430INC
CLIB -On

IAR MSP430 C/C++ Compiler V4.11B/W32 [Kickstart LMS]
Copyright 1996-2008 IAR Systems. All rights reserved.

45 bytes of DATA memory

Errors: none
Warnings: none

temp.C
icc430.exe J:Software emp.C -lC J:SoftwareDebugList -o J:SoftwareDebugObj
--no_cse --no_unroll --no_inline --no_code_motion --no_tbaa --debug -D__MSP430F2132__
-e --double=32 -I D:SalvoInc -I D:SalvoIncIAR430 -I J:Software -I D:IAR Systems
Embedded Workbench 5.0430INC -I D:IAR SystemsEmbedded Workbench 5.0430INC
CLIB -On

IAR MSP430 C/C++ Compiler V4.11B/W32 [Kickstart LMS]
Copyright 1996-2008 IAR Systems. All rights reserved.
Warning[Pe260]: explicit type is missing ("int" assumed) J:Software emp.C 14
Warning[Pe260]: explicit type is missing ("int" assumed) J:Software emp.C 16
Warning[Pe260]: explicit type is missing ("int" assumed) J:Software emp.C 16

42 bytes of CODE memory
20 bytes of CONST memory
26 bytes of DATA memory

Errors: none
Warnings: 3

Linking
xlink.exe D:SalvoLibIAR430-v4salvofiar430-t.r43 J:SoftwareDebugObj
fet120_ta_PWM_batChg.r43 J:SoftwareDebugObjled.r43 J:SoftwareDebugObj
salvomem.r43 J:SoftwareDebugObj emp.r43 -o J:SoftwareDebugExe
batterycharger.d43 -l J:SoftwareDebugListatterycharger.map -xmsni -ID:IAR Systems
Embedded Workbench 5.0430LIB -f D:IAR SystemsEmbedded Workbench 5.0430
CONFIGlnk430F1232.xcl -D_STACK_SIZE=50 -rt D:IAR SystemsEmbedded Workbench
5.0430LIBCLIBcl430f.r43 -D_DATA16_HEAP_SIZE=50 -s __program_start
-D_DATA20_HEAP_SIZE=50

IAR Universal Linker V4.61E/386
Copyright 1987-2008 IAR Systems. All rights reserved.
Warning[w6]: Type conflict for external/entry "OSCreateTask", in module led against
external/entry in module salvoinit2; function types differ in parameter 2; class/struct/union
types have different sizes
Warning[w6]: Type conflict for external/entry "OScTcbP", in module salvodelay against
external/entry in module salvomem; class/struct/union types have different sizes
Warning[w6]: Type conflict for external/entry "OSsigQinP", in module salvobinsem against
external/entry in module salvomem; class/struct/union types have different sizes
Warning[w6]: Type conflict for external/entry "OSsigQoutP", in module salvobinsem against
external/entry in module salvomem; class/struct/union types have different sizes
Warning[w6]: Type conflict for external/entry "OStcbArea", in module salvocyclic against
external/entry in module salvomem; array types have different element types;
class/struct/union types have different sizes
Warning[w35]: There is more than one definition for the struct/union type with tag 'tcb';
class/struct/union types have different sizes
Warning[w35]: There is more than one definition for the struct/union type with tag 'ecb';
class/struct/union field/base types do not match for field/base 'tcbP'; class/struct/union types
have different sizes

1 768 bytes of CODE memory
170 bytes of DATA memory (+ 15 absolute )
8 bytes of CONST memory

Errors: none
Warnings: 7


Total number of errors: 0
Total number of warnings: 11

saguaro
 
Posts: 3
Joined: Fri Jan 23, 2009 12:00 am
Location: Koper, SI

Re: OS_Delay problem with 2 tasks

Postby aek » Sun Jan 25, 2009 8:34 am

quote:
xlink.exe D:SalvoLibIAR430-v4salvofiar430-t.r43 ...
This is the wrong library for an OSCONFIG of OSA -- see RM-IAR430.PDF.

------------------

-------
aek
aek
 
Posts: 1888
Joined: Sat Aug 26, 2000 11:00 pm


Return to TI's MSP430

Who is online

Users browsing this forum: No registered users and 0 guests

cron