Real Time OS Code based ARM Development Suite

Status
Not open for further replies.

limesp

Newbie level 1
Joined
Apr 22, 2013
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,294
Hi All,

I am new to Real Time OS. Can anyone explain the code stated as below to me in details?

First part:
OS_STK MainTaskStk[MainTaskStkLengh];
OS_STK Task0Stk [Task0StkLengh]; // Define the Task0 stack
OS_STK Task1Stk [Task1StkLengh]; // Define the Task1 stack
OS_STK Task2Stk [Task2StkLengh]; // Define the Task2 stack


Second part:

#define rGPKCON0 (*(volatile unsigned *)(0x7F008800))
#define rGPKCON1 (*(volatile unsigned *)(0x7F008804))
#define rGPKDAT (*(volatile unsigned *)(0x7F008808))
#define rGPKPUD (*(volatile unsigned *)(0x7F00880C))


void Port_Init(void)
{
rGPKCON0 = (rGPKCON0 & ~(0xffffU<<16))|(0x1111U<<16);
rGPKPUD = (rGPKPUD & ~(0xffU << 8))|(0x00U<<8);
}

void Led_Display(int data)
{
rGPKDAT = (rGPKDAT & ~(0xf<<4)) | ((data & 0xf)<<4);
}

void Task2 (void *pdata)
{
Port_Init();

while(1)
{
OSPrintf("this is from task2\n");
Led_Display(0x9); // 1001
OSTimeDly(OS_TICKS_PER_SEC/4);
Led_Display(0x6); // 0110
OSTimeDly(OS_TICKS_PER_SEC/4);
}
}

Third part:
- How to create Task 3?

Fourth part:
- There are four leds in hardware. How led blinking based on Task0,Task1 and Task2 from this program code?

Attached is the whole program code used in ARM Developer Suite.

Appreciated and Thanks.
 

Attachments

  • main.c program code.txt
    3.2 KB · Views: 116

Greetings,

What specific processor are you using? This will help me help you.
Just by looking at the code it looks like you are using Micrium's uC/os-II or -III.

Lets walk through the code...

Part 1..
The first part is declaring the stacks that will be used to save the contents of the registers during multitasking (i.e. switching from one task to another). The size of stacks 0, 1, & 2 are Task0StkLengh, Task1StkLengh, and Task2StkLengh, respectively. You would have to see where this variable is defined to actually know the amount of memory being allocated to each stack

Part 2..
Without knowing what processor and development kit you are using, it is a little bit difficult to explain the processor specific operations, as this would require a working knowledge of the registers and such. I can help you understand the second half though...
Code:
while(1)
{
OSPrintf("this is from task2\n");
Led_Display(0x9); // 1001
OSTimeDly(OS_TICKS_PER_SEC/4);
Led_Display(0x6); // 0110
OSTimeDly(OS_TICKS_PER_SEC/4);
}	
}

OsTimeDly() is a uC/OS function that is used to delay a function. In real-time kernels, this means that, when you call this function, the task "yield", or relinquishes control to the CPU for the amount of time indicated in the function call; in this case, the current task will yield for OS_TICKS_PER_SEC/4. Upon expiration of this time, the task regains control of the CPU, calls the Led_Display() function, and then yields again. When the task yields, the next highest priority task that is ready to run will gain control of the CPU. If there are no other tasks, then the default system idle task will run until a user task requests the CPU.

Part 3..
In uC/OS, tasks are created by using the OSTaskCreate() or OSTaskCreateExt() functions; they are essentially the same, except the OSTaskCreateExt() has slightly more functionality. I have posted an example below that creates a new task called "initialization_task"...
Code:
OSTaskCreateExt((void (*)(void *)) initialization_task,
                    (void           *) 0,
                    (OS_STK         *)&INITIALIZATION_TASK_STACK[INITIALIZATION_TASK_STACK_SIZE - 1],
                    (INT8U           ) INITIALIZATION_TASK_PRIO,
                    (INT16U          ) INITIALIZATION_TASK_PRIO,
                    (OS_STK         *)&INITIALIZATION_TASK_STACK[0],
                    (INT32U          ) INITIALIZATION_TASK_STACK_SIZE,
                    (void           *) 0,
                    (INT16U          )(OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR));
It might be helpful to reference the user documentation to gain a more detailed understanding of this function and all the options that are required to create a new task.

Part 4...
How led blinking based on Task0,Task1 and Task2 from this program code?

uC/OS-II is a preemptive, real-time, deterministic, multitasking kernel. This means, among other things, that tasks operate based on an assigned priority. Here is an example...

Let us assume that we have three tasks, labeled Task 1, Task 2, and Task 3; furthermore, let us assume that Task 1 has priority 2, Task 2 has priority 3, and Task 3 has priority 4 (I would have assigned Task 1 priority 1 and so on, but priority 1 is reserved for a system task by uC/OS). Once all the initialization are performed and the tasks are created, you call the function OSStart(), which essentially means that multitasking has commenced and the system is running. If we assume that all of the tasks are empty, Task 1 will occupy 100% of the execution time, and Task 2 and 3 will never run. The only way that Task 2 can run is if Task 1 yields and relinquishes control of the CPU. One way to do this is, as mentioned earlier, by calling the OSTimeDly function. There is also another function, OSTimeDlyHMSM(), that allows you to yield for a specific amount of hours, minutes, seconds, and milliseconds. If we call OSTimeDlyHMSM(0,0,1,0) from within Task 1, that means that Task 1 will yield for exactly 1 second. The next highest priority task that is ready to run will begin to execute; in this case, this is Task 2. If we then call OSTimeDlyHMSM(0, 0, 1 ,0) immediately upon entering Task 2, what will happen? Will Task 1 or Task 3 execute?....

In this case, Task 3 will execute, because Task 1 yielded for a full second, and is therefore not in the ready state; however, as soon as that initial second expires, Task 1 will resume control of the CPU regardless of what task is executing, since it holds the highest priority; this is known as preemption.

I hope this helped answer some questions for you.

Kind Regards,
Willis
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…