Jump to content
tonyp12

tiny msp430 preemptive multitasking system

Recommended Posts

Yes, thanks @zeke.

But, I don’t see how the following statement works. After the equal sign, shouldn’t be there the address of some variable, e.g. the address of SP register in this case? How does casting (int*) help?

int* multistack = (int*) __get_SP_register();

And any idea why the comma after "task3" is there in the below statement? I noticed it makes "tasks" variable to be 4 and enable the while(i<tasks-1) loop to iterate 3 times. But it must have some other role, right? If not, why not write while(i<tasks) instead?

funcpnt const taskpnt[]={ task1, task2, task3,  // <- PUT YOUR TASKS HERE
}; 

Cheers..

Share this post


Link to post
Share on other sites

We have to unpack all that is going on in that get stack pointer statement.

The function getstackpointer() returns a value. The (int*) transforms that into “the address of that return value” which will be 16 bits large. Then that 16 bit address is assigned to the multi stack variable. 

 

The author is asking us to modify the list of function names in the taskpnt function since (s)he doesn’t know what we will be doing. So that is up to us. 

So task1, task2, and so on, are functions that we write to do one specific thing. Something atomic, like SwitchOnLED(LED1) or SwitchGPIO(P1-7), etc.  

Does that make sense?

Share this post


Link to post
Share on other sites

Okay, let me put it this way. The author seems to have 3 tasks, but he loops the while(i<tasks-1){...} loop only 2 times due to 'i<tasks-1' statement. My question is that is there any purpose of doing this? What happened to the remaining task? 

And, another question: why are we saving Global Interrupt Enable bit on The Stack? Where are we using it again later?

Thanks. 

Share this post


Link to post
Share on other sites

There are 3 tasks in array, and index starts with 0, so counting from 0 to 2, and all three tasks running.

   int i = 0; while (i <tasks -1) {

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×