Pumpkin, Inc.

Pumpkin User Forums

Context Switching along with delay

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).

Context Switching along with delay

Postby Syed Akbar » Wed Dec 14, 2005 4:01 am

Hello Aek,

As i have stated in my earlier posts that i have been developing a salvo appliation for interfacing two sensors. Now i face a small problem regarding context switching using OS_Delay.

My task looks like this:

code:
void read_sht75(void)
{
UINT16 i;
int counter;
for (i = 0; i < 0x10FF; i++);
reset_SHT75();


P3OUT = 0x00;
P3DIR = 0xC0; // Set P3.6 and P3.7 to output direction
for(;;){
counter = 60;
do
{
OS_Delay(100, read_sht75_label);
TOGGLE_GLED; // Toggle GLED
counter--;
}while(counter!=0);
get_SHT75();
}

}


This tasks measures temperature and Relative humidity by calling the function get_SHT75(). But this task should be implemented only every 1 minute. Therefore, inorder to delay this task i have used 10ms TimerA and OS_Delay as shown within a do while loop with a counter. And hence u can see, that the function is called after 1 minute. But since the OS_Delay also context switches the task, then do you think it is the correct way?

When i have debugged, i could c that, the program doesnt stop!! The Green Led continously toggles. But when i have debugged with the break point at get_SHT75(), the Green Led toggles for the entire loop and then stops at the break point. When i run it further, the Green toggles again 30 times(On/Off in total 60) and then the program stops and i could read the values.

Can u please have a look on the things and suggest me the correct usage.

Waiting for your response!
Thank you very much
-Syed Akbar

------------------
Akbar

[This message has been edited by aek (edited December 14, 2005).]

Akbar
Syed Akbar
 
Posts: 13
Joined: Sun May 22, 2005 11:00 pm
Location: Bremen, Bremen, Germany

Re: Context Switching along with delay

Postby aek » Wed Dec 14, 2005 7:51 am

Hello.

One of the "golden rules" of Salvo -- and one of the reasons it requires so little RAM -- is that local (auto) variables are not preserved across context switches. This is covered in the user manual.

Therefore, you need to declare your counter variable as static.

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

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

Re: Context Switching along with delay

Postby aek » Wed Dec 14, 2005 7:52 am

Note that in your example code, i does not need to be static.

To save some memory, however, you could use counter in place of i, and counter has to be static (because it is used across the OS_Delay() context switch).

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

-------
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 1 guest

cron