Jump to content

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


Link to post
Share on other sites
  • Replies 35
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Popular Posts

Tested on G2553 Launchpad with IAR, I recommend G2955 with 1K RAM if you want more than 3 task #include "msp430.h" #include "common.h" //=========================(C) Tony Philipsson 2016 ==========

preemptive means that the code (e.g.each task that is pretty much its own main.c) does not know it is sharing a single mcu core. it does not need to say "i take a pause now so next task can go on", yo

a ISR always have way to trick the RETI by modifying the SR values on stack.   I trick the RETI with a different stack location , task 1 have a stack as normal as first entry in to ISR the PC,SR and

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?

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?


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...