MadMayonnaise 0 Posted December 23, 2018 Share Posted December 23, 2018 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.. Quote Link to post Share on other sites
zeke 693 Posted December 24, 2018 Share Posted December 24, 2018 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? veryalive 1 Quote Link to post Share on other sites
MadMayonnaise 0 Posted December 24, 2018 Share Posted December 24, 2018 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. Quote Link to post Share on other sites
Frida 4 Posted December 25, 2018 Share Posted December 25, 2018 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) { Quote Link to post Share on other sites
MadMayonnaise 0 Posted December 25, 2018 Share Posted December 25, 2018 Initially i=0 so while(0<2) is true, next i=1 while(1<2) is true, next i=2 while(2<2) is not true and the loop ends. The loop has run 2 times in total, isn’t it like this? Quote Link to post Share on other sites
Frida 4 Posted December 26, 2018 Share Posted December 26, 2018 You're right, I was too fast, sorry Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.