Aim high with the goal in mind. Exp 2 Exp 3 Exp 1Largest response:
Lab08 Real Time Os-exp-1
-
Upload
rahul-wali -
Category
Documents
-
view
215 -
download
0
Transcript of Lab08 Real Time Os-exp-1
-
8/8/2019 Lab08 Real Time Os-exp-1
1/18
SOC Consortium Course MaterialSoC Design Laboratory
Lab8 REAL TIME OSLab8 REAL TIME OS--1_Experiment1_Experiment
Speaker: Yung-Chih ChenAdvisor: Prof. Chun-Yao Wang
November 17, 2003
Department of Computer ScienceNational Tsing Hua University
-
8/8/2019 Lab08 Real Time Os-exp-1
2/18
SOC Consortium Course MaterialSoC Design Laboratory 2
Outline
Lab C/OS-II Building C/OS-II
Porting Program to C/OS-II
Building Program with C/OS-II
Exercise & Discussion
-
8/8/2019 Lab08 Real Time Os-exp-1
3/18
SOC Consortium Course MaterialSoC Design Laboratory 3
Building C/OS-II (1/3)
1. Open C/OS-II project file in ./Lab8/Codes/SW/ucos2/ with Code Warrior
2. Edit OS_CFG.h to customize C/OS-II
In DebugRel target settings dialog ,turn to Language Settings > ARM CCompiler> Preprocessor. Add INTEGRATOR to List of#DEFINEs to generatespecific code for Integrator
-
8/8/2019 Lab08 Real Time Os-exp-1
4/18
SOC Consortium Course MaterialSoC Design Laboratory 4
Building C/OS-II (2/3)
4. Add or modify 2 directories to the Access Path so header files could be found.
In target settings dialog, select Target > Access Paths. Add or modify${AFS_ROOT}/AFSv1_4/Source/uHAL/h/ and${AFS_ROOT}/AFSv1_4/Source/uHAL/Boards/INTEGRATOR/
5. Repeat sub-step 3~4 for target Release and Debug
-
8/8/2019 Lab08 Real Time Os-exp-1
5/18
SOC Consortium Course MaterialSoC Design Laboratory 5
Building C/OS-II (3/3)
6. Press the Make button, C/OS-II library should be built successfully. A static
library ucos2.a is created. Check the file in your working directory
-
8/8/2019 Lab08 Real Time Os-exp-1
6/18
SOC Consortium Course MaterialSoC Design Laboratory 6
Porting Program to C/OS-II (1/5)
1. Open the project eg1 at ./Lab8/Codes/SW/eg1/ with CodeWorrior
2. The original code of eg1.c is listed. This program asks user for name and age,then it prints greeting message
12
34
567
8910
1112
131415
1617
18
1920
#include
int main(void){
char name[64];int age;
printf("please enter your name: ");scanf("%s", name);
do{
printf("please enter your age: ");scanf("%d", &age);
}while(age < 0);
printf("Hello, %s. Nice to meet you!\nYour age is %d.\n", name, age);
return(0);}
-
8/8/2019 Lab08 Real Time Os-exp-1
7/18
SOC Consortium Course MaterialSoC Design Laboratory 7
Porting Program to C/OS-II (2/5)
3. To port the program to C/OS-II, include includes.h in eg1.c. The header file
is an interface for C/OS-II4. Change the function name from main() to Task1(). In addition, change return
type from int to void because a task never returns. Remove the returnstatements, too.
12
3
#include "includes.h" /* uC/OS-II interface */
#include
1 void Task1(void *pdata)2 {
3 4
5 return(0);
-
8/8/2019 Lab08 Real Time Os-exp-1
8/18
SOC Consortium Course MaterialSoC Design Laboratory 8
Porting Program to C/OS-II (3/5)
5. A task must receive an argument of type (void*), so change argument list from
void to void *pdata. The purpose of this pointer is to pass initialization value totask.
6. A task is an infinite loop, so wrap the codes with a for loop. Remember, all taskshould call at least one kernel service in its code body. Otherwise, themultitasking mechanism of C/OS-II will not work. You can call OSTimeDly()service to pause for a while after each round of processing, allowing lower
priority task to execute.
1 void Task1(void *pata)2 {
3 for(;;)4 {
5 // user code6 7
8 OSTimeDly(100);
9 }10 }
-
8/8/2019 Lab08 Real Time Os-exp-1
9/18
SOC Consortium Course MaterialSoC Design Laboratory 9
Porting Program to C/OS-II (4/5)
7. Insert a new main function at the bottom of eg1.c. In the main function, create
an instance for Task1.
int main(int argc, char *argv[]){
/* do target (uHAL based ARM system) initialization */ARMTargetInit();
/* needed by uC/OS */OSInit();
/* create the tasks in uC/OS */OSTaskCreate(Task1, (void *)0, (void*)&Stack1[STACKSIZE - 1], 3);
/* Start the (uHAL based ARM system) system running */
ARMTargetStart();
/* start the game */
OSStart();
/* never reached */return(0);
}
-
8/8/2019 Lab08 Real Time Os-exp-1
10/18
SOC Consortium Course MaterialSoC Design Laboratory 10
Porting Program to C/OS-II (5/5)
8. Insert the following code near the top of eg1.c to create a stack for Task1. Each
task must have its own stack. The actual stack size needed depends onprocessor type, depth of interrupt allowed and the work your task isrunningetc. System crashes on stack overflow. So, its better to allocate a
bigger stack first than try to decrease the value.
9. Finally, eg1.c is an executable program at C/OS-II
/* allocate memory for tasks' stacks */#ifdef SEMIHOSTED
#defineSTACKSIZE(64+SEMIHOSTED_STACK_NEEDS)#else
#defineSTACKSIZE64#endif
OS_STK Stack1[STACKSIZE];
-
8/8/2019 Lab08 Real Time Os-exp-1
11/18
SOC Consortium Course MaterialSoC Design Laboratory 11
Building Program with C/OS-II (1/5)
1. Open the project eg1 at ./Lab08/Codes/SW/eg1/ with CodeWorrior
2. Add C/OS-II as a sub-project. This enables automatic rebuilt of sub-projectwhenever necessary. This approach is more flexible than add the pre-compiled ucos2.a library file
3. Add ARM uHAL library as a sub-project. The project file is located in${AFS_ROOT}\Source\uHAL\Build\Integrator.b\uHALlibrary.mcp
-
8/8/2019 Lab08 Real Time Os-exp-1
12/18
SOC Consortium Course MaterialSoC Design Laboratory 12
Building Program with C/OS-II (2/5)
4. Now, specify which target to build and link. In project window, click the Target
tab to display the Targets view for the project. Then, click the plus sign next toa build target containing the subproject to expand the hierarchy. Each buildtarget in the subproject is listed in the hierarchy
Build target hierarchy view
Build targets for C/OS-II
Build targets for uHAL
-
8/8/2019 Lab08 Real Time Os-exp-1
13/18
SOC Consortium Course MaterialSoC Design Laboratory 13
Building Program with C/OS-II (3/5)
5. Click on the Target icon next to the subproject build targets you want to build
along with the main project. The CodeWarrior IDE displays an arrow andtarget icon for selected build targets
6. Click in the Link Column next to the subproject build targets. Select the targetyou want to link with the main project
targets tobuild
targets tolink with
main project
Select target to build and link with
-
8/8/2019 Lab08 Real Time Os-exp-1
14/18
SOC Consortium Course MaterialSoC Design Laboratory 14
Building Program with C/OS-II (4/5)
7. Define SEMIHOSTED for programs to run in semihosted mode. In semihosted
mode, an extra space of 1K bytes is needed for stack
-
8/8/2019 Lab08 Real Time Os-exp-1
15/18
SOC Consortium Course MaterialSoC Design Laboratory 15
Building Program with C/OS-II (5/5)
8. Build the main project. An executable file that contains both user application
and operating system will be created9. Press Run button, you can see programs running on C/OS-II in AXD console
window
-
8/8/2019 Lab08 Real Time Os-exp-1
16/18
SOC Consortium Course MaterialSoC Design Laboratory 16
Outline
L
ab C/OS-II Building C/OS-II Porting Program to C/OS-II
Building Program with C/OS-II
Exercise & Discussion
-
8/8/2019 Lab08 Real Time Os-exp-1
17/18
SOC Consortium Course MaterialSoC Design Laboratory 17
Exercise
Write an ID checking engine. The checking rule is in the reference section.
User input:
The ID numbers
Program output:
The ID numberCheck result
Example:
Please enter ID : A123456789
======= check result =======
A123456789 valid
-
8/8/2019 Lab08 Real Time Os-exp-1
18/18
SOC Consortium Course MaterialSoC Design Laboratory 18
Discussion
1.What are the advantages of using RTOS in SoC design? And what are the
disadvantages?2.Write down your suggestions about this lab