0% found this document useful (0 votes)
82 views

RTS Lab

The document provides details about experiments conducted to study task management functions in μC/OS-II. It lists key task management functions like OSTaskCreate(), OSTaskCreateExt(), OSTaskChangePrio(), and OSTaskSuspend(). The experiments involve creating multiple tasks with different priorities using these functions and suspending tasks. Output shows the tasks getting executed and suspended sequentially according to their priorities, demonstrating the working of task management in μC/OS-II.

Uploaded by

Jabez Winston
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
82 views

RTS Lab

The document provides details about experiments conducted to study task management functions in μC/OS-II. It lists key task management functions like OSTaskCreate(), OSTaskCreateExt(), OSTaskChangePrio(), and OSTaskSuspend(). The experiments involve creating multiple tasks with different priorities using these functions and suspending tasks. Output shows the tasks getting executed and suspended sequentially according to their priorities, demonstrating the working of task management in μC/OS-II.

Uploaded by

Jabez Winston
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 47

TABLE OF CONTENTS

S.NO

DATE

EXPERIMENT

Page
No.

13/01/2016

MAKE UTILITY

15/03/2016

MULTITASKING

20/03/2016

TASK MANAGEMENT

13

28/03/2016

SEMAPHORE MANAGEMENT

18

05/04/2016

MUTEX MANAGEMENT

27

13/04/2016

EVENT FLAG MANAGEMENT

32

20/04/2016

MAILBOX MANAGEMENT

37

31/04/2016

MESSAGE QUEUE MANAGEMENT

42

Ex No.1

MAKE UTILITY

13-01-2016

AIM:
To create a makefile for an application.

SOFTWARE TOOLS USED:


1. GCC Toolchain
2. GNU Make utility

INTRODUCTION TO GNU MAKE UTILITY:


GNU Make is a tool which controls the generation of executables and other non-source files of a
program from the program's source files.
Make gets its knowledge of how to build your program from a file called the makefile, which lists each
of the non-source files and how to compute it from other files. When you write a program, you should
write a makefile for it, so that it is possible to use Make to build and install the program.

CAPABILITIES OF MAKE:

Make enables the end user to build and install your package without knowing the details of how
that is done -- because these details are recorded in the makefile that you supply.
Make figures out automatically which files it needs to update, based on which source files have
changed. It also automatically determines the proper order for updating files, in case one nonsource file depends on another non-source file.
As a result, if you change a few source files and then run Make, it does not need to recompile
all of your program. It updates only those non-source files that depend directly or indirectly on
the source files that you changed.

Make is not limited to any particular language. For each non-source file in the program, the
makefile specifies the shell commands to compute it. These shell commands can run a compiler
to produce an object file, the linker to produce an executable, ar to update a library, or TeX or
Makeinfo to format documentation.
Make is not limited to building a package. You can also use Make to control installing or
deinstalling a package, generate tags tables for it, or anything else you want to do often enough
to make it worth while writing down how to do it.

MAKE RULES AND TARGETS


target: dependencies ...
commands
...

15EE52 Real-Time Systems Laboratory

Page 1

When you run Make, you can specify particular targets to update; otherwise, Make updates the first
target listed in the makefile. Of course, any other target files needed as input for generating these
targets must be updated first.
Make uses the makefile to figure out which target files ought to be brought up to date, and then
determines which of them actually need to be updated. If a target file is newer than all of its
dependencies, then it is already up to date, and it does not need to be regenerated. The other
target files do need to be updated, but in the right order: each target file must be regenerated
before it is used in regenerating other targets.
Source: https://www.gnu.org/software/make/
EXPERIMENT:
1. Create a C application project involving several C source files and associated header files. In
our application we created 10 C source files and a header file. The application is a simple
calculator application.
2. The contents of main source file, main.c .
/* main.c */
#include<stdio.h>
#include"calculator.h"
int main()
{
int a,b,c,ch;
a=get_number(1);
b=get_number(2);
print_menu();
printf("\nEnter your choice : ");
scanf("%d",&ch);
switch(ch)
{
case 1: c=add(a,b);
print_result(c);
break;
case 2: c=sub(a,b);
print_result(c);
break;
case 3: c=mul(a,b);
print_result(c);
break;
case 4: c=div(a,b);
print_result(c);
break;
case 5: c=mod(a,b);
print_result(c);
break;
default:print_error(ch);
}
return 0;
}

15EE52 Real-time Systems Laboratory

Page 2

3. Contents of other 10 files getnumber.c , print_menu.c ,add.c ,sub.c ,mul.c ,div.c ,mod.c
,print_result.c ,print_error.c
get_number.c
int get_number(int x)
{
int y;
printf("Enter number %d : ",x);
scanf("%d",&y);
return y;
}

print_menu.c
void print_menu()
{
printf("\nMENU");
printf("\n1.ADD");
printf("\n2.SUBTRACT");
printf("\n3.MULTIPLY");
printf("\n4.DIVIDE");
printf("\n5.MODULO");
}

add.c
int add(int x,int y)
{
int t;
t=x+y;
return t;
}

mul.c
int mul(int x,int y)
{
int t;
t=x*y;
return t;
}

sub.c
int sub(int x,int y)
{
int t;
t=x-y;
return t;
}

div.c
int div(int x,int y)
{
int t;
t=x/y;
return t;
}

mod.c
int mod(int x,int y)
{
int t;
t=x%y;
return t;
}

15EE52 Real-time Systems Laboratory

Page 3

print_result.c
void print_result(int x)
{
printf("Result is %d",x);
}

print_error.c
void print_error(int x)
{
printf("%d is invalid choice !!!",x);
}

calculator.h
void print_menu();
int get_number(int);
int add(int,int);
int sub(int,int);
int mul(int,int);
int div(int,int);
int mod(int,int);
void print_result(int);
void print_error(int);

DEPENDENCY TREE
Calculator.exe
main.o

main .c

get_number.o

getnumber.c

print_menu.o

print_menu.c

add.o

add.c

sub.o

sub.c

mul.o

mul.c

div.o

div.c

mod.o

mod.c

print_result.o

print_result.c

print_error.o

print_error.c

15EE52 Real-time Systems Laboratory

Page 4

4. Create a makefile as shown below using the dependency tree. The name of the file can be any
of the following three names GNUmakefile ,Makefile or makefile.
Makefile
Calculator.exe : main.o get_number.o print_menu.o add.o sub.o mul.o
div.o mod.o print_result.o print_error.o
gcc -o Calculator.exe *.o
main.o: main.c
gcc -c main.c
get_number.o: get_number.c
gcc -c get_number.c
print_menu.o: print_menu.c
gcc -c print_menu.c
add.o:add.c
gcc -c add.c
sub.o:sub.c
gcc -c sub.c
mul.o:mul.c
gcc -c mul.c
div.o:div.c
gcc -c div.c
mod.o:mod.c
gcc -c mod.c
print_result.o:print_result.c
gcc -c print_result.c

print_error.o:print_error.c
gcc -c print_error.c
clean:
rm *.o Calculator.exe

The source files, header file and makefile related to Calculator application are placed in a folder.

15EE52 Real-time Systems Laboratory

Page 5

Fig 1.1 : Calc folder containing C source files ,header files and Makefile

Fig 1.2 : Invocation of Make utility using make command

15EE52 Real-time Systems Laboratory

Page 6

Fig 1.3 : Running the executable file

Fig 1.4 : Source file print_result.c is modified and hence newer than Calculator.exe

15EE52 Real-time Systems Laboratory

Page 7

Fig 1.5 : Only print_result.c is compiled and linked with Calculator.exe,The modified output is
also shown

Fig 1.6 : Invocation of make clean to remove executable files and object files from project
folder
RESULT: Thus Makefile was created and used with GCC ToolChain and GNU Make utility.

15EE52 Real-time Systems Laboratory

Page 8

Ex No.2

MULTITASKING

15-03-2016

AIM:
To multitask in C/OS-II (v2.52).

SOFTWARE TOOLS USED:


1. Borland C Compiler
2. C/OS II (v2.52) source code
3. DOSBox
DOCUMENTATION:
MicroC/OS II ,The Real-Time Kernel by Jean J. Labrosse

LIST OF FUNCTIONS USED FOR MULTITASKING:


1. OSTaskSuspend()
OSTaskSuspend(INT8U prio);

2. OSTaskResume()
void OSTaskResume(INT8U prio);

3. OSTimeDlyHMSS()
OSTimeDlyHMSS (INT8U hours,INT8U minutes,INT8U seconds,INT8U milli);

15EE52 Real-Time Systems Laboratory

Page 9

PROGRAM:
#include "includes.h"

OS_STK
OS_STK
OS_STK
OS_STK
OS_STK

TaskStartStk[TASK_STK_SIZE];
Task1Stk[TASK_STK_SIZE];
Task2Stk[TASK_STK_SIZE];
Task3Stk[TASK_STK_SIZE];
Task4Stk[TASK_STK_SIZE];

......
......
......
void
void
void
void

Task1(void
Task2(void
Task3(void
Task4(void

*data);
*data);
*data);
*data);

......
......

TaskStartCreateTasks:
.....
.....
void TaskStartCreateTasks (void)
{
OSTaskCreate(Task1,(void *)0,&Task1Stk[TASK_STK_SIZE - 1],11);
OSTaskCreate(Task2,(void *)0,&Task2Stk[TASK_STK_SIZE - 1],12);
OSTaskCreate(Task3,(void *)0, &Task3Stk[TASK_STK_SIZE - 1],13);
OSTaskCreate(Task4,(void *)0,&Task4Stk[TASK_STK_SIZE - 1],14);
OSTaskCreate(Task5,(void *)0,&Task4Stk[TASK_STK_SIZE - 1],15);
}
.......
.......

main:
void
{

main (void)
......
......
......
OSTaskCreate(TaskStart,(void *)0,&TaskStartStk[TASK_STK_SIZE - 1],0);
OSStart();

15EE52 Real-time Systems Laboratory

Page 10

Task1:
void Task1 (void *pdata)
{
INT8U err;
pdata=pdata;
for(;;)
{
printf("\n\n\n\t\t\tTASK 1 is running...");
printf("\nTASK 1 Suspended...");
OSTaskSuspend(OS_PRIO_SELF);
}
}

Task2:
void Task2 (void *pdata)
{
INT8U err;
pdata=pdata;
for(;;)
{
printf("\n\t\t\tTASK 2 is running...");
printf("\nTASK 2 Suspended...");
OSTaskSuspend(OS_PRIO_SELF);
}
}

Task3:
void Task3 (void *pdata)
{
INT8U err;
pdata=pdata;
for(;;)
{
printf("\n\t\t\tTASK 3 is running...");
printf("\nTASK 3 Suspended...");
OSTaskSuspend(OS_PRIO_SELF);
}
}

Task4:
void Task4 (void *pdata)
{
INT8U err;
pdata=pdata;
for(;;)
{
printf("\n\t\t\tTASK 4 is running...");
printf("\nTASK 4 Suspended...");
OSTaskSuspend(OS_PRIO_SELF);
}
}

15EE52 Real-time Systems Laboratory

Page 11

Task5:
void
{

Task5 (void *pdata)


INT8U err;
pdata=pdata;
for (;;)
{
printf("\n\t\t\tTASK 5 is running...");
printf("\nTASK 5 Suspended...");
OSTimeDlyHMSM(0,0,2,0);
OSTaskResume(11);
OSTaskResume(12);
OSTaskResume(13);
OSTaskResume(14);
}

OUTPUT:

Fig 2.1 Mulitasking (Output)

RESULT:
Thus
simple
multitasking
was
carried
out
with
OSTaskSuspend(),OSTaskResume() and OSTimeDlyHMSM().

15EE52 Real-time Systems Laboratory

the

C/OS-II

primitives

Page 12

Ex No.3

TASK MANAGEMENT

20 -03-2016

AIM:
To study the working of Task Management functions in C/OS-II (v2.52).

SOFTWARE TOOLS USED:


1. Borland C Compiler
2. C/OS II (v2.52) source code
3. DOSBox
DOCUMENTATION:
MicroC/OS II ,The Real-Time kernel by Jean J. Labrosse

LIST OF TASK MANAGEMENT FUNCTIONS:


1. OSTaskCreate()
INT8U OSTaskCreate(void (*task)(void *pd), void *pdata, OS_STK *ptos, INT8U
prio);

2. OSTaskCreateExt()
INT8U
INT8U
opt);

OSTaskCreateExt(void (*task)(void *pd), void


*pdata, OS_STK *ptos,
prio,INT16U id,OS_STK *pbos,INT32U stk_size,void
*pext,INT16U

3. OSTaskChangePrio()
INT8U OSTaskChangePrio(INT8U oldprio, INT8U newprio);
4. OSTaskSuspend()
INT8U OSTaskSuspend (INT8U prio)
5. OSTaskResume()
INT8U OSTaskResume(INT8U prio)
6. OSTaskQuery()
INT8U OSTaskQuery(INT8U prio, OS_TCB *pdata);
7. OSTaskStkChk()
INT8U OSTaskStkChk(INT8U prio, OS_STK_DATA *pdata);

15EE52 Real-Time Systems Laboratory

Page 13

8. OSTaskDelReq()
INT8U OSTaskDelReq(INT8U prio);
9. OSTaskDel()
INT8U OSTaskDel(INT8U prio);
PROGRAM:
#include "includes.h"
#include <string.h>
#define
#define
#define
OS_STK
OS_STK
OS_STK
OS_STK
OS_STK
OS_STK

TASK_STK_SIZE
1024
TASK_2_ID
12
TASK_2_PRIO
12
TaskStartStk[TASK_STK_SIZE];
Task1Stk[TASK_STK_SIZE];
Task2Stk[TASK_STK_SIZE];
Task3Stk[TASK_STK_SIZE];
Task4Stk[TASK_STK_SIZE];
Task5Stk[TASK_STK_SIZE];

......
......
......
void
void
void
void
void

Task1(void
Task2(void
Task3(void
Task4(void
Task5(void

*data);
*data);
*data);
*data);
*data);

......
......

TaskStartCreateTasks:
.....
.....
void TaskStartCreateTasks (void)
{
OSTaskCreate(Task1,(void *)0,&Task1Stk[TASK_STK_SIZE - 1],11);
OSTaskCreateExt(Task2,(void *)0,&Task2Stk[1023],TASK_2_PRIO,
TASK_2_ID,&Task2Stk[0], 1024,(void *)0,OS_TASK_OPT_STK_CHK |
OS_TASK_OPT_STK_CLR);
OSTaskCreate(Task3,(void *)0,&Task3Stk[TASK_STK_SIZE - 1],13);
OSTaskCreateExt(Task4,(void*)0,&Task4Stk[1023],14,22,&Task4Stk[0],1024,
(void *)0,OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);
OSTaskCreate(Task5,(void *)0,&Task5Stk[TASK_STK_SIZE - 1],15);
}
.......
.......

15EE52 Real-time Systems Laboratory

Page 14

Task1:
void Task1 (void *pdata)
{
char *a;
INT8U err;
pdata=pdata;
a=(char *)malloc(5*sizeof(char));
strcpy(a,"Hi !");
for(;;)
{
if(OSTaskDelReq(OS_PRIO_SELF)==OS_TASK_DEL_REQ)
{
printf("\nFreeing resources used by Task 1");
free(a);
printf("\nTask 1 deleted");
OSTaskDel(OS_PRIO_SELF);
}
printf("\n\n\n\t\t\tTASK 1 is running...");
printf("%s",a);
printf("\n\t\t\tTASK 2 SUSPENDED ...");
OSTaskSuspend(OS_PRIO_SELF);
}
}

Task2:

void Task2 (void *pdata)


{
INT16U a,b,c;
INT8U err;
OS_STK_DATA data;
pdata=pdata;
for(;;)
{
printf("\n\t\t\tTASK 2 is running...");
err = OSTaskStkChk(12, &data);
if (err == OS_NO_ERR)
{
printf("\nTotal stack size for task2:%d",data.OSFree + data.OSUsed);
printf("\nTotal stack size free:%d",data.OSFree);
printf("\nTotal stack size used:%d",data.OSUsed);
}
printf("\n\t\t\tTASK 2 SUSPENDED ...");
OSTaskSuspend(OS_PRIO_SELF);
}
}

15EE52 Real-time Systems Laboratory

Page 15

Task3:
void
{

Task3 (void *pdata)

INT8U err;
pdata=pdata;
for (;;) {
printf("\n\t\t\tTASK 3 is running...");
err=OSTaskChangePrio(14, 16);
if(err==OS_NO_ERR)
printf("\n\t\t\tTASK 4 PRIORITY CHANGED by TASK 3...");
err = OSTaskDelReq(11);
if(err==OS_NO_ERR)
{
printf("\nTask3 placing delete request to Task1");
OSTaskResume(11);
}
printf("\n\t\t\tTASK 3 SUSPENDED ...");
OSTaskSuspend(OS_PRIO_SELF);
}
}

Task4:
void
{

Task4 (void *pdata)


INT16U a,b,c;
INT8U err;
pdata=pdata;
for (;;) {
printf("\n\t\t\tTASK 4 is running...");
printf("\n\t\t\tTASK 4 is resuming TASK 2...");
OSTaskResume(12);
OSTaskResume(13);
OSTimeDlyHMSM(0, 0, 10, 0);
}

Task5:
void
{

Task5 (void *pdata)

INT8U err;
OS_TCB Task4_TCB;
pdata=pdata;
for (;;)
{
printf("\n\t\t\tTASK 5 is running...");
printf("\nQuerying Task4 TCB...");
err=OSTaskQuery(16,&Task4_TCB);
if(err==OS_NO_ERR)
printf("Task4 ID=%d Task4 Priority =%d",Task4_TCB.OSTCBId,Task4_TCB.OSTCBPrio);
printf("\n\t\t\tTASK 5 DELETED BY ITSELF...");
OSTaskDel(15);
}
}

15EE52 Real-time Systems Laboratory

Page 16

OUTPUT:

Fig 3.1a Task Management (Output)

Fig 3.1b Task Management (Output)

RESULT:
Thus the task management functions in C/OS-II were studied and experimented.

15EE52 Real-time Systems Laboratory

Page 17

Ex No.4

SEMAPHORE MANAGEMENT

28 -03-2016

AIM:
To study the working of Semaphore Management functions in C/OS-II (v2.52).

SOFTWARE TOOLS USED:


1. Borland C Compiler
2. C/OS II (v2.52) source code
3. DOSBox
DOCUMENTATION:
MicroC/OS II ,The Real-Time kernel by Jean J. Labrosse

LIST OF SEMAPHORE MANAGEMENT FUNCTIONS:


1. OSSemCreate()
OS_EVENT *OSSemCreate(INT16U value);
2. OSSemPend()
void OSSemPend(OS_EVENT *pevent, INT16U

timeout, INT8U *err);

3. OSSemPost()
INT8U OSSemPost (INT8U prio);
4. OSSemAccept()
INT8U OSSemAccept(INT8U prio);
5. OSSemQuery()
INT8U OSSemQuery(INT8U prio, OS_SEM_DATA *pdata);
6. OSSemDel()
OS_EVENT* OSSemDel(INT8U prio, INT8U opt,INT8U *err);

15EE52 Real-Time Systems Laboratory

Page 18

PROGRAM:
a.Binary Semaphore
#include "includes.h"
#define
#define
#define
#define
OS_STK
OS_STK
OS_STK
OS_STK
OS_STK
OS_STK

TASK_STK_SIZE
1024
MSG_QUEUE_SIZE
20
TASK_2_ID
12
TASK_2_PRIO
12
TaskStartStk[TASK_STK_SIZE];
Task1Stk[TASK_STK_SIZE];
Task2Stk[TASK_STK_SIZE];
Task3Stk[TASK_STK_SIZE];
Task4Stk[TASK_STK_SIZE];
Task5Stk[TASK_STK_SIZE];

OS_EVENT
*Binary_Semaphore;
int Protected_Variable;
......
......
......
void
void
void
void
void

Task1(void
Task2(void
Task3(void
Task4(void
Task5(void

*data);
*data);
*data);
*data);
*data);

......
......

TaskStartCreateTasks:
.....
.....
void TaskStartCreateTasks (void)
{
OSTaskCreate(Task1,(void *)0,&Task1Stk[TASK_STK_SIZE - 1],11);
OSTaskCreateExt(Task2,(void *)0,&Task2Stk[1023],TASK_2_PRIO,
TASK_2_ID,&Task2Stk[0], 1024,(void *)0,OS_TASK_OPT_STK_CHK |
OS_TASK_OPT_STK_CLR);
OSTaskCreate(Task3,(void *)0,&Task3Stk[TASK_STK_SIZE - 1],13);
OSTaskCreateExt(Task4,(void*)0,&Task4Stk[1023],14,22,&Task4Stk[0],1024,
(void *)0,OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);
OSTaskCreate(Task5,(void *)0,&Task5Stk[TASK_STK_SIZE - 1],15);
}
.......
.......

15EE52 Real-time Systems Laboratory

Page 19

main:
void
{

main (void)
......
......
......
Binary_Semaphore=OSSemCreate(1);
OSTaskCreate(TaskStart,(void *)0,&TaskStartStk[TASK_STK_SIZE - 1],0);
OSStart();

Task1:
void Task1 (void *pdata)
{
INT8U err;
pdata=pdata;
for(;;)
{
printf("\n\n\n\t\t\tTASK 1 is running...");
OSSemPend(Binary_Semaphore,0,&err);
if(err==OS_NO_ERR)
{
printf("\n\nTASK 1 acquired Binary Semaphore !");
Protected_Variable = 100;
printf("\nWrote 100 to Protected_Variable....");
printf("Protected_Variable = %d",Protected_Variable);
printf("\nTASK 1 releasing Binary Semaphore");
OSSemPost(Binary_Semaphore);
}
OSTaskSuspend(11);
}
}

15EE52 Real-time Systems Laboratory

Page 20

Task2:
void Task2 (void *pdata)
{
INT8U err;
INT16U value;
pdata=pdata;
for(;;)
{
printf("\n\t\t\tTASK 2 is running...\n");
value=OSSemAccept(Binary_Semaphore);
if (value>0)
{
printf("\nTASK 2 acquired Binary Semaphore !");
Protected_Variable = 200;
printf("\nWrote 200 to Protected_Variable....");
printf("Protected_Variable = %d",Protected_Variable);
OSTaskSuspend(12);
}
}
}

Task3:
void
{

Task3 (void *pdata)

INT8U err;
pdata=pdata;
for (;;)
{
printf("\n\t\t\tTASK 3 is running...\n");
printf("\nTASK 3 attempting to acquire Binary Semaphore");
OSSemPend(Binary_Semaphore,0,&err);
if(err==OS_NO_ERR)
{
printf("\nTASK 3 acquired Binary Semaphore!");
Protected_Variable = 300;
printf("\nWrote 300 to Protected_Variable....");
printf("Protected_Variable = %d",Protected_Variable);
OSSemPost(Binary_Semaphore);
printf("\nTask 3 released the Binary Semaphore");
}
OSTaskSuspend(13);
}
}

15EE52 Real-time Systems Laboratory

Page 21

Task4:
void
{

Task4 (void *pdata)


INT8U err;
pdata=pdata;
for (;;) {
printf("\n\t\t\tTASK 4 is running...");
printf("\nTASK 4 attempting to acquire Binary Semaphore");
OSSemPend(Binary_Semaphore,0,&err);
if(err==OS_NO_ERR)
{
printf("\nTASK 4 acquired Binary Semaphore!");
Protected_Variable = 400;
printf("\nWrote 400 to Protected_Variable....");
printf("Protected_Variable = %d",Protected_Variable);
OSSemPost(Binary_Semaphore);
printf("\nTask 4 released the Binary Semaphore");
}
OSTaskSuspend(14);
}

Task5:
void
{

Task5 (void *pdata)


OS_SEM_DATA Semaphore_Data;
INT8U err;
pdata=pdata;
for (;;) {
printf("\n\t\t\tTASK 5 is running...");
OSSemQuery(Binary_Semaphore,&Semaphore_Data);
printf("\nSemaphore count = %d",Semaphore_Data.OSCnt);
printf("\nTASK 5 releasing Binary Semaphore!");
OSSemPost(Binary_Semaphore);
OSTaskSuspend(15);
}

15EE52 Real-time Systems Laboratory

Page 22

b.Counting Semaphore:
#include "includes.h"
#define
#define
#define
#define
OS_STK
OS_STK
OS_STK
OS_STK
OS_STK
OS_STK

TASK_STK_SIZE
1024
MSG_QUEUE_SIZE
20
TASK_2_ID
12
TASK_2_PRIO
12
TaskStartStk[TASK_STK_SIZE];
Task1Stk[TASK_STK_SIZE];
Task2Stk[TASK_STK_SIZE];
Task3Stk[TASK_STK_SIZE];
Task4Stk[TASK_STK_SIZE];
Task5Stk[TASK_STK_SIZE];

OS_EVENT
*Counting_Semaphore;
int Protected_Array[4],i=0,Test_Value;
......
......
......
void
void
void

Task1(void *data);
Task2(void *data);
Task3(void *data);

......
......

main:
void
{

main (void)
......
......
......
Counting_Semaphore=OSSemCreate(4);
OSTaskCreate(TaskStart,(void *)0,&TaskStartStk[TASK_STK_SIZE - 1],0);
OSStart();

15EE52 Real-time Systems Laboratory

Page 23

TaskStartCreateTasks:
.....
.....
void TaskStartCreateTasks (void)
{
OSTaskCreate(Task1,(void *)0,&Task1Stk[TASK_STK_SIZE - 1],11);
OSTaskCreateExt(Task2,(void *)0,&Task2Stk[1023],TASK_2_PRIO,
TASK_2_ID,&Task2Stk[0], 1024,(void *)0,OS_TASK_OPT_STK_CHK |
OS_TASK_OPT_STK_CLR);
OSTaskCreate(Task3,(void *)0,&Task3Stk[TASK_STK_SIZE - 1],13);
OSTaskCreateExt(Task4,(void*)0,&Task4Stk[1023],14,22,&Task4Stk[0],1024,
(void *)0,OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);
OSTaskCreate(Task5,(void *)0,&Task5Stk[TASK_STK_SIZE - 1],15);
}
.......
.......

Task1:
void Task1 (void *pdata)
{
INT8U a;
INT16U value;
pdata=pdata;
for(;;)
{
printf("\n\t\t\tTASK 1 is running...");
for(a=0;a<4;a++)
{
value=OSSemAccept(Counting_Semaphore);
if(value>0)
Protected_Array[a]=(a+1)*100;
i++;
}
for(a=0;a<i;a++)
printf("\nProtected_Array[%d]= %d",a,Protected_Array[a]);
printf("\nAll credits of the Counting_Semaphore Taken !!!");
OSTaskSuspend(11);

}
}

15EE52 Real-time Systems Laboratory

Page 24

Task2:
void Task2 (void *pdata)
{
INT8U err;
INT16U value;
pdata=pdata;
for(;;)
{
printf("\n\t\t\tTASK 2 is running...");
OSSemPend(Counting_Semaphore,0,&err);
if(err==OS_NO_ERR)
{
Protected_Array[i]=Test_Value;
printf("\nTask2 wrote %d to Protected_Array[%d]",Protected_Array[i],i);
}
else
{
OSTaskSuspend(12);
}
}
}

Task3:
void Task3 (void *pdata)
{
INT8U err,a=0;
pdata=pdata;
for (;;)
{
printf("\n\t\t\tTASK 3 is running...\n");
for(a=0;a<4;a++)
{
Test_Value=500+(a+1)*100;
printf("Task 3 released %d credit(s) of Counting_Semaphore",a+1);
i--;
OSSemPost(Counting_Semaphore);
}
OSTaskSuspend(13);
}
}

15EE52 Real-time Systems Laboratory

Page 25

OUTPUT:
a.Binary Semaphore

Fig 4.1 Binary Semaphore (Output)


b.Counting Semaphore

Fig 4.2 Counting Semaphore (Output)

RESULT:
Thus the semaphore management functions in C/OS-II were studied and experimented for both binary and
counting semaphores.

15EE52 Real-time Systems Laboratory

Page 26

Ex No.5

MUTEX MANAGEMENT

05-04-2016

AIM:
To study the working of Mutex Management functions in C/OS-II (v2.52).

SOFTWARE TOOLS USED:


1. Borland C Compiler
2. C/OS II (v2.52) source code
3. DOSBox
DOCUMENTATION:
MicroC/OS II ,The Real-Time kernel by Jean J. Labrosse

LIST OF MUTEX MANAGEMENT FUNCTIONS:


1. OSMutexCreate()
OS_EVENT *OSMutexCreate(INT8U prio , INT8U *err);

2. OSMutexPend()
void OSMutexPend(OS_EVENT *pevent, INT16U

timeout, INT8U *err);

3. OSMutexPost()
INT8U OSMutexPost (OS_EVENT *pevent);
4. OSMutexAccept()
INT8U OSMutexAccept(OS_EVENT *pevent,INT8U *err);
5. OSMutexQuery()
INT8U OSMutexQuery(OS_EVENT *pevent, OS_MUTEX_DATA *pdata);
6. OSMutexDel()
OS_EVENT* OSMutexDel(OS_EVENT *pevent,INT8U opt,INT8U *err);

15EE52 Real-Time Systems Laboratory

Page 27

PROGRAM:
#include "includes.h"
#define
#define
#define
#define

TASK_STK_SIZE
1024
MSG_QUEUE_SIZE
20
TASK_2_ID
12
TASK_2_PRIO
12

OS_STK
OS_STK
OS_STK
OS_STK
OS_STK

TaskStartStk[TASK_STK_SIZE];
Task1Stk[TASK_STK_SIZE];
Task2Stk[TASK_STK_SIZE];
Task3Stk[TASK_STK_SIZE];
Task4Stk[TASK_STK_SIZE];

OS_EVENT
int a=0;
......
......
void
void
void
void

*Mutex_1;

Task1(void
Task2(void
Task3(void
Task4(void

*data);
*data);
*data);
*data);

......
......

TaskStartCreateTasks:
.....
.....
void TaskStartCreateTasks (void)
{
OSTaskCreate(Task1,(void *)0,&Task1Stk[TASK_STK_SIZE - 1],11);
OSTaskCreateExt(Task2,(void *)0,&Task2Stk[1023],TASK_2_PRIO,
TASK_2_ID,&Task2Stk[0], 1024,(void *)0,OS_TASK_OPT_STK_CHK |
OS_TASK_OPT_STK_CLR);
OSTaskCreate(Task3,(void *)0,&Task3Stk[TASK_STK_SIZE - 1],13);
OSTaskCreateExt(Task4,(void*)0,&Task4Stk[1023],14,22,&Task4Stk[0],1024,
(void *)0,OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);
OSTaskCreate(Task5,(void *)0,&Task5Stk[TASK_STK_SIZE - 1],15);
}
.......
.......

15EE52 Real-time Systems Laboratory

Page 28

main:
void
{

main (void)
......
......
......
Mutex_1 = OSMutexCreate(8,&err);
OSTaskCreate(TaskStart,(void *)0,&TaskStartStk[TASK_STK_SIZE - 1],0);
OSStart();

Task1:
void Task1 (void *pdata)
{
INT8U err;
pdata=pdata;
for(;;)
{
printf("\n\n\n\t\t\tTASK 1 is running...");
OSMutexPend(Mutex_1,0,&err);
if(err==OS_NO_ERR)
{
printf("\nTASK 1 acquired Mutex !");
Protected_Variable = 100;
printf("\nWrote 100 to Protected_Variable....");
printf("Protected_Variable = %d",Protected_Variable);
err=OSMutexPost(Mutex_1);
if(err==OS_NO_ERR)
printf("\nTASK 1 released Mutex");
OSTaskSuspend(OS_PRIO_SELF);
}
}

15EE52 Real-time Systems Laboratory

Page 29

Task2:
void Task2 (void *pdata)
{
INT8U err;
INT16U value;
pdata=pdata;
for(;;)
{
if(a==1)
{
err=OSMutexPost(Mutex_1);
if(err==OS_NO_ERR)
{
printf("\nMutex successfully released");
OSTaskSuspend(OS_PRIO_SELF);
}
}
printf("\n\t\t\tTASK 2 is running...\n");
value=OSMutexAccept(Mutex_1,&err);
if (err==OS_NO_ERR&& value==1)
{
printf("\nTASK 2 acquired Mutex_1 !");
Protected_Variable = 200;
printf("\nWrote 200 to Protected_Variable....");
printf("Protected_Variable = %d",Protected_Variable);
}
OSTaskSuspend(OS_PRIO_SELF);
}
}

Task3:
void
{

Task3 (void *pdata)

INT8U err;
pdata=pdata;
for (;;)
{
printf("\n\t\t\tTASK 3 is running...\n");
printf("\nTASK 3 attempting to acquire Mutex");
OSMutexPend(Mutex_1,0,&err);
if(err==OS_NO_ERR)
{
printf("\nTASK 3 acquired Mutex!");
Protected_Variable = 300;
printf("\nWrote 300 to Protected_Variable....");
printf("Protected_Variable = %d",Protected_Variable);
OSMutexPost(Mutex_1);
printf("\nTask 3 released the Mutex");
OSTaskSuspend(OS_PRIO_SELF);
}
}
}

15EE52 Real-time Systems Laboratory

Page 30

Task4:
void
{

Task4 (void *pdata)

INT8U err;
OS_MUTEX_DATA mutexData1;
pdata=pdata;
for (;;)
{
printf("\n\t\t\tTASK 4 is running...\n");
OSMutexQuery(Mutex_1,&mutexData1);
printf("\nMutex Data:");
printf("\nOSOwnerPrio=%d OSMutexPIP=%d OSValue = %d", mutexData1.OSOwnerPrio
,mutexData1.OSMutexPIP,mutexData1.OSValue);
printf("\nTASK 4 attempting to release Mutex");
err=OSMutexPost(Mutex_1);
if(err==OS_ERR_NOT_MUTEX_OWNER)
{
a=1;
printf("\nTask 4 is not owner of Mutex...requesting Task2 to release Mutex");
OSTaskResume(12);
}
OSMutexDel(Mutex_1,OS_DEL_NO_PEND,&err);
if(err==OS_NO_ERR)
printf("\nMutex deleted !!!");
OSTaskSuspend(OS_PRIO_SELF);
}
}

OUTPUT:

Fig 5.1 Mutex Management (Output)


RESULT:
Thus Mutex Management functions in C/OS-II were studied and experimented.

15EE52 Real-time Systems Laboratory

Page 31

Ex No.6

EVENT MANAGEMENT

13-04-2016

AIM:
To study the working of Event Management functions in C/OS-II (v2.52).

SOFTWARE TOOLS USED:


1. Borland C Compiler
2. C/OS II (v2.52) source code
3. DOSBox
DOCUMENTATION:
MicroC/OS II ,The Real-Time kernel by Jean J. Labrosse

LIST OF EVENT MANAGEMENT FUNCTIONS:


1. OSFlagCreate()
OS_FLAG_GRP *OSFlagCreate(OS_FLAGS flags,INT8U* err);

2. OSFlagPend()
OS_FLAGS OSFlagPend(OS_FLAG_GRP *pgrp,OS_FLAGS flags,INT8U wait_type, INT16U
timeout, INT8U *err);

3. OSFlagPost()
OS_FLAGS OSFlagPost (OS_FLAG_GRP *pgrp,OS_FLAGS flags,INT8U opt,INT8U *err);

4. OSFlagAccept()
OS_FLAGS OSFlagAccept(OS_FLAG_GRP *pgrp,OS_FLAGS flags,INT8U wait_type,INT8U
*err);

5. OSFlagQuery()
OS_FLAGS OSFlagQuery(OS_FLAG_GRP *pgrp, INT8U *err);

6. OSFlagDel()
OS_FLAG_GRP *OSFlagDel(OS_FLAG_GRP *pgrp, INT8U opt,INT8U *err);

15EE52 Real-Time Systems Laboratory

Page 32

PROGRAM:
#include "includes.h"

#define
#define
#define
#define

OS_STK
OS_STK
OS_STK
OS_STK
OS_STK

EVENT0
EVENT1
EVENT2
EVENT3

(1<<0)
(1<<1)
(1<<2)
(1<<3)

TaskStartStk[TASK_STK_SIZE];
Task1Stk[TASK_STK_SIZE];
Task2Stk[TASK_STK_SIZE];
Task3Stk[TASK_STK_SIZE];
Task4Stk[TASK_STK_SIZE];

OS_FLAG_GRP *Flag_1;
......
......
......
void
void
void
void

Task1(void
Task2(void
Task3(void
Task4(void

*data);
*data);
*data);
*data);

......
......

TaskStartCreateTasks:
.....
.....
void TaskStartCreateTasks (void)
{
OSTaskCreate(Task1,(void *)0,&Task1Stk[TASK_STK_SIZE - 1],11);
OSTaskCreate(Task2,(void *)0,&Task2Stk[TASK_STK_SIZE - 1],12);
OSTaskCreate(Task3,(void *)0, &Task3Stk[TASK_STK_SIZE - 1],13);
OSTaskCreate(Task4,(void *)0,&Task4Stk[TASK_STK_SIZE - 1],14);
}
.......
.......

main:
void
{

main (void)
......
......
......
Flag_1 = OSFlagCreate(0x00,&err);
OSTaskCreate(TaskStart,(void *)0,&TaskStartStk[TASK_STK_SIZE - 1],0);
OSStart();

15EE52 Real-time Systems Laboratory

Page 33

Task1:
void Task1 (void *pdata)
{
INT8U err;
pdata=pdata;
for(;;)
{
printf("\n\n\n\t\t\tTASK 1 is running...");
printf("\nWaiting for EVENT1 and EVENT2 to occur !!");
OSFlagPend(Flag_1,EVENT1+EVENT2,OS_FLAG_WAIT_SET_ALL+OS_FLAG_CONSUME,0,&err);
if(err==OS_NO_ERR)
{
printf("\n\n\n\t\t\tTASK 1 is running...");
printf("\n EVENT1 and EVENT2 has occured !!");
OSTaskSuspend(OS_PRIO_SELF);
}
}

Task2:
void Task2 (void *pdata)
{
INT8U err;
OS_FLAGS value;
pdata=pdata;
for(;;)
{

printf("\n\t\t\tTASK 2 is running...\n");
value=OSFlagPost(Flag_1,EVENT1,OS_FLAG_SET,&err);
printf("\nTask1 Posting EVENT1");
if (err==OS_NO_ERR && value == EVENT1)
{
printf("\nEVENT1 successfully posted\n");
value=OSFlagQuery(Flag_1,&err);
printf("Flag_1 value = %d",value);
}
OSTaskSuspend(OS_PRIO_SELF);
}
}

15EE52 Real-time Systems Laboratory

Page 34

Task3:
void
{

Task3 (void *pdata)

INT8U err;
OS_FLAGS value;
pdata=pdata;
for (;;)
{
printf("\n\t\t\tTASK 3 is running...\n");
printf("\nTask 3 Posting EVENT2");
value=OSFlagPost(Flag_1,EVENT2,OS_FLAG_SET,&err);
OSTaskSuspend(OS_PRIO_SELF);
}
}

Task4:
void
{

Task4 (void *pdata)

INT8U err;
OS_FLAGS value;
OS_FLAG_GRP *test;
pdata=pdata;
for (;;)
{
printf("\n\t\t\tTASK 4 is running...\n");
value=OSFlagAccept(Flag_1,0xFF,OS_FLAG_WAIT_CLR_ALL,&err);
if(err==OS_NO_ERR&& value==0)
{
printf("\n EVENT1 and EVENT2 flags cleared !!");
test=OSFlagDel(Flag_1,OS_DEL_ALWAYS,&err);
if(test==(OS_FLAG_GRP *)0)
printf("\nEvent Flag successfully deleted");
OSTaskSuspend(OS_PRIO_SELF);
}
}
}

15EE52 Real-time Systems Laboratory

Page 35

OUTPUT:

Fig 6.1 Event Management (output)

RESULT: Thus event management functions in C/OS-II were studied and experimented.
15EE52 Real-time Systems Laboratory

Page 36

Ex No.7

MAILBOX MANAGEMENT

20-04-2016

AIM:
To study the working of Mailbox Management functions in C/OS-II (v2.52).

SOFTWARE TOOLS USED:


1. Borland C Compiler
2. C/OS II (v2.52) source code
3. DOSBox
DOCUMENTATION:
MicroC/OS II ,The Real-Time kernel by Jean J. Labrosse

LIST OF MAILBOX MANAGEMENT FUNCTIONS:


1. OSMboxCreate()
OS_EVENT *OSMboxCreate(void *msg);

2. OSMboxPend()
void *OSMboxPend(OS_EVENT *pevent, INT16U

timeout, INT8U *err);

3. OSMboxPost()
INT8U OSMboxPost (OS_EVENT *pevent,void *msg);
4. OSMboxPostOpt()
INT8U OSMboxPost (OS_EVENT *pevent,void *msg,INT8U opt);
5. OSMboxAccept()
void *OSMboxAccept(OS_EVENT *pevent);
6. OSMboxQuery()
INT8U OSMboxQuery(OS_EVENT *pevent, OS_MBOX_DATA *pdata);
7. OSMboxDel()
OS_EVENT* OSMboxDel(OS_EVENT *pevent, INT8U opt ,INT8U *err);

15EE52 Real-Time Systems Laboratory

Page 37

PROGRAM:
#include "includes.h"

OS_STK
OS_STK
OS_STK
OS_STK
OS_STK

TaskStartStk[TASK_STK_SIZE];
Task1Stk[TASK_STK_SIZE];
Task2Stk[TASK_STK_SIZE];
Task3Stk[TASK_STK_SIZE];
Task4Stk[TASK_STK_SIZE];

OS_EVENT *MailBox_1;
int a=0;
......
......
......
void
void
void
void

Task1(void
Task2(void
Task3(void
Task4(void

*data);
*data);
*data);
*data);

......
......

TaskStartCreateTasks:
.....
.....
void TaskStartCreateTasks (void)
{
OSTaskCreate(Task1,(void *)0,&Task1Stk[TASK_STK_SIZE - 1],11);
OSTaskCreate(Task2,(void *)0,&Task2Stk[TASK_STK_SIZE - 1],12);
OSTaskCreate(Task3,(void *)0, &Task3Stk[TASK_STK_SIZE - 1],13);
OSTaskCreate(Task4,(void *)0,&Task4Stk[TASK_STK_SIZE - 1],14);
}
.......
.......

main:
void
{

main (void)
......
......
......
MailBox_1 = OSMboxCreate((void *)0);
OSTaskCreate(TaskStart,(void *)0,&TaskStartStk[TASK_STK_SIZE - 1],0);
OSStart();

15EE52 Real-time Systems Laboratory

Page 38

Task1:
void Task1 (void *pdata)
{
INT8U err;
void *msg;
pdata=pdata;
for(;;)
{
if(a==1)
{
msg=OSMboxPend(MailBox_1,0,&err);
if(err==OS_NO_ERR)
{
printf("\nTask1 is running... %s",(char *)msg);
OSTaskSuspend(OS_PRIO_SELF);
}
}
printf("\n\n\n\t\t\tTASK 1 is running...");
printf("\nTask 1 waiting for some message to be posted in Mailbox...");
msg=OSMboxPend(MailBox_1,0,&err);
if(err==OS_NO_ERR)
{
printf("\n\t\t\tTASK 1 is running...");
printf("\nNew Message Received !!\n");
printf("%s",msg);
OSTaskSuspend(OS_PRIO_SELF);
}
}

Task2:
void Task2 (void *pdata)
{
INT8U err;
void *msg;
pdata=pdata;
for(;;)
{
if(a==1)
{
msg=OSMboxPend(MailBox_1,0,&err);
if(err==OS_NO_ERR)
{
printf("\nTask 2 is running... %s",(char *)msg);
OSTaskSuspend(OS_PRIO_SELF);
}
}
printf("\n\t\t\tTASK 2 is running...\n");
printf("Posting a message to Mailbox");
OSMboxPost(MailBox_1,(void *)"\"Hello..!!!\" from Task 2");
OSTaskSuspend(OS_PRIO_SELF);
}
}

15EE52 Real-time Systems Laboratory

Page 39

Task3:
void
{

Task3 (void *pdata)

INT8U err;
void *msg;
OS_MBOX_DATA MailBoxInfo;
pdata=pdata;
for (;;)
{
if(a==1)
{
printf("\n\t\t\tTASK 3 is running...");
printf("\nQuerying MailBox Data..");
err=OSMboxQuery(MailBox_1,&MailBoxInfo);
if(err==OS_NO_ERR)
printf("\nAddress of Message Pointer=%p Event
Group=%d",MailBoxInfo.OSMsg,MailBoxInfo.OSEventGrp);
msg=OSMboxAccept(MailBox_1);
if(msg!=(void *)0)
{
printf("\n%s",msg);
OSTaskSuspend(OS_PRIO_SELF);
}
}
printf("\n\t\t\tTASK 3 is running...");
OSTaskSuspend(OS_PRIO_SELF);
}
}

Task4:
void
{

Task4 (void *pdata)

INT8U err;
pdata=pdata;
for (;;)
{
printf("\n\t\t\tTASK 4 is running...\n");
a=1;
OSTaskResume(11);
OSTaskResume(12);
printf("Posting a broadcast message !!");
OSMboxPostOpt(MailBox_1,(void *)"Task4:Hi everyone !! :-) (Broadcasted
message)",OS_POST_OPT_BROADCAST);
OSMboxPost(MailBox_1,(void*)"Task 4: :-D");
OSTaskResume(13);
OSMboxDel(MailBox_1,OS_DEL_ALWAYS,&err);
if(err==OS_NO_ERR)
printf("\nMailBox deleted !!!");
OSTaskSuspend(OS_PRIO_SELF);
}
}

15EE52 Real-time Systems Laboratory

Page 40

OUTPUT:

Fig 7.1: Mailbox Management

RESULT: Thus Mailbox Management functions in C/OS-II were studied and experimented.

15EE52 Real-time Systems Laboratory

Page 41

Ex No.8

MESSAGE QUEUE MANAGEMENT

31-04-2016

AIM:
To study the working of Message Queue Management functions in C/OS-II (v2.52).

SOFTWARE TOOLS USED:


1. Borland C Compiler
2. C/OS II (v2.52) source code
3. DOSBox
DOCUMENTATION:
MicroC/OS II ,The Real-Time kernel by Jean J. Labrosse

LIST OF MESSAGE QUEUE MANAGEMENT FUNCTIONS:


1. OSQCreate()
OS_EVENT *OSQCreate(void **start,INT16U size);

2. OSQPend()
void OSQPend(OS_EVENT *pevent, INT16U

timeout, INT8U *err);

3. OSQPost()
INT8U OSQPost (OS_EVENT *pevent,void *msg);
4. OSQAccept()
void* OSQAccept(OS_EVENT *pevent);
5. OSQQuery()
INT8U OSQQuery(INT8U prio, OS_Q_DATA *pdata);
6. OSQDel()
OS_EVENT *OSQDel(OS_EVENT *pevent,INT8U opt,INT8U *err);
7. OSQPostFront()
INT8U OSQPostFront(OS_EVENT *pevent,void *msg);
8. OSQFlush()
INT8U OSQFlush(OS_EVENT *pevent);

15EE52 Real-Time Systems Laboratory

Page 42

9. OSQPostOpt()
INT8U OSQPostFront(OS_EVENT *pevent,void *msg,INT8U opt);
PROGRAM:
#include "includes.h"

OS_STK
OS_STK
OS_STK
OS_STK
OS_STK

TaskStartStk[TASK_STK_SIZE];
Task1Stk[TASK_STK_SIZE];
Task2Stk[TASK_STK_SIZE];
Task3Stk[TASK_STK_SIZE];
Task4Stk[TASK_STK_SIZE];

OS_EVENT *MsgQ_1;
void *Msg_Ptr[5];
......
......
......
void
void
void
void

Task1(void
Task2(void
Task3(void
Task4(void

*data);
*data);
*data);
*data);

......
......

TaskStartCreateTasks:
.....
.....
void TaskStartCreateTasks (void)
{
OSTaskCreate(Task1,(void *)0,&Task1Stk[TASK_STK_SIZE - 1],11);
OSTaskCreate(Task2,(void *)0,&Task2Stk[TASK_STK_SIZE - 1],12);
OSTaskCreate(Task3,(void *)0, &Task3Stk[TASK_STK_SIZE - 1],13);
OSTaskCreate(Task4,(void *)0,&Task4Stk[TASK_STK_SIZE - 1],14);
}
.......
.......

main:
void
{

main (void)
......
......
......
MsgQ_1 = OSQCreate(Msg_Ptr,5);
OSTaskCreate(TaskStart,(void *)0,&TaskStartStk[TASK_STK_SIZE - 1],0);
OSStart();

15EE52 Real-time Systems Laboratory

Page 43

Task1:
void Task1 (void *pdata)
{
INT8U err;
void *msg;
pdata=pdata;
for(;;)
{
printf("\n\n\n\t\t\tTASK 1 is running...");
printf("\nTask 1 waiting for some message to be posted in Message
Queue...");
msg=OSQPend(MsgQ_1,0,&err);
if(err==OS_NO_ERR)
{
printf("Task1:New Message Received !!\n");
printf("%s",(char *)msg);
OSTaskSuspend(OS_PRIO_SELF);
}
}
}

Task2:
void Task2 (void *pdata)
{
INT8U err;
OS_Q_DATA QData_1;
pdata=pdata;
for(;;)
{
printf("\n\t\t\tTASK 2 is running...\n");
OSQPost(MsgQ_1,(void *)"\"Hello..!!!\" from Task 2");
OSQPost(MsgQ_1,(void *)"\nTask2:How are you ?");
OSQPost(MsgQ_1,(void*)"\nTask2: ???!!!");
printf("\nQuerying Queue Data...");
OSQQuery(MsgQ_1,&QData_1);
printf("\nNumber of messages in Queue=%d
QData_1.OSNMsgs,QData_1.OSQSize);

Queue Size = %d",

printf("\nFlushing Queue....!!!");
OSQFlush(MsgQ_1);
printf("\nQuerying Queue Data again...");
OSQQuery(MsgQ_1,&QData_1);
printf("\nNumber of messages in Queue=%d
QData_1.OSNMsgs,QData_1.OSQSize);

Queue Size = %d",

OSTaskSuspend(OS_PRIO_SELF);
}
}

15EE52 Real-time Systems Laboratory

Page 44

Task3:
void
{

Task3 (void *pdata)

INT8U err;
pdata=pdata;
for (;;)
{
printf("\n\t\t\tTASK 3 is running...\n");
OSQPost(MsgQ_1,(void *)"Task3:Hi..!!!");
OSQPost(MsgQ_1,(void *)"Task3:How are you ?");
OSQPostFront(MsgQ_1,(void *)"Task3:I'm the last to be in but first to be
out !! (LIFO) ;-)");
printf("\nEnqueued Queue with 3 messages");
OSTaskSuspend(OS_PRIO_SELF);
}
}

Task4:
void
{

Task4 (void *pdata)

INT8U err,i;
void *msg;
pdata=pdata;
for (;;)
{
printf("\n\t\t\tTASK 4 is running...\n");
for(i=0;i<3;i++)
{
msg=OSQAccept(MsgQ_1);
if(msg!=(void*)0)
{
printf("\n%s",(char*)msg);
}
}
OSQDel(MsgQ_1,OS_DEL_NO_PEND,&err);
if(err==OS_NO_ERR)
printf("\nQueue has been successfully deleted!!!");
OSTaskSuspend(OS_PRIO_SELF);
}
}

15EE52 Real-time Systems Laboratory

Page 45

OUTPUT:

Fig 8.1 Message Queue Management (Output)

RESULT: Thus message queue management functions in C/OS-II were studied and experimented.

15EE52 Real-time Systems Laboratory

Page 46

You might also like