Jump to content


  • Content Count

  • Joined

  • Last visited

Everything posted by MadMayonnaise

  1. 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?
  2. 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.
  3. 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,
  4. Hi @zeke, Thanks for the reply. I've already checked the links. Can you also roughly explain the following code snippet? I know the concept of context switching and what needs to be done prior to it, but the following steps confused me a little bit. int* multistack = (int*) __get_SP_register(); int i=0; while(i<tasks-1){ int j = stacksize[i]; if (!j) j = 24; multistack -= j; *(multistack) = (int) taskpnt[++i]; // prefill in PC *(multistack-1) = GIE; // prefill in SR taskstackpnt[i] = (int) multistack-26; // needs 12 d
  5. @tonyp12 and other folks, can anybody help me better understand the following lines? #ifndef COMMON_H_ #define COMMON_H_ #define tasks (sizeof(taskpnt)/2) __task void task1(void); __task void task2(void); __task void task3(void); typedef __task void (*funcpnt)(void); #endif and funcpnt const taskpnt[]={ task1, task2, task3, // <- PUT YOUR TASKS HERE }; Have a good one..
  • Create New...