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

SPECALIZED EXPERIMENTS ON EMBEDDED SYSTEMS

EXPERIMENTS ON EMBEDDED SYSTEMS

Uploaded by

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

SPECALIZED EXPERIMENTS ON EMBEDDED SYSTEMS

EXPERIMENTS ON EMBEDDED SYSTEMS

Uploaded by

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

CHONGQING UNIVERSITY

SPECALIZED EXPERIMENTS ON EMBEDDED SYSTEMS

COLLEGE OF COMMUNICATION ENGINEERING CHONGQING UNIVERSITY


PROGRAM STATEMENT: The program below shows the Inter task
communication and synchronization between the two task i-e Task A and
Task B using the Message Queues.

#include "vxWorks.h"
#include "taskLib.h"
#include "semLib.h"
#include "msgQLib.h"
#include "msgqdemo.h"
#include "sysLib.h"
#include "stdio.h"

LOCAL SEM_ID semId1; /* semaphore id of binary


semaphore 1 */
LOCAL SEM_ID semId2; /* semaphore id of binary
semaphore 2 */

/* function prototypes */

LOCAL STATUS producerTask (); /* producer task */


LOCAL STATUS consumerTask (); /* consumer task */

/* DESCRIPTION
* Creates a Message Queue for inter Task communication between
the producer Task and the consumer Task. Spawns the producer Task
that creates messages and sends messages to the consumer Task
using the message queue. Spawns the consumer Task that reads
messages from the message queue. After consumer Task has consumed
all the messages, the message queue is deleted.
*/

STATUS msgQDemo()
{
notDone = TRUE; /* initialize the global flag */

/* semaphore semId1 is availble after creation*/


if ((semId1 = semBCreate (SEM_Q_PRIORITY, SEM_FULL)) == NULL)
{
perror ("synchronizeDemo: Error in creating semId1
semaphore");
return (ERROR);
}

/* semaphore semId2 is not available after creation*/


if ((semId2 = semBCreate (SEM_Q_PRIORITY, SEM_EMPTY)) ==
NULL)
{
perror ("synchronizeDemo: Error in creating semId2
semaphore");
return (ERROR);
}

/* Create the message queue*/


if ((msgQId = msgQCreate (numMsg, sizeof (struct msg),
MSG_Q_FIFO))

== NULL)
{
perror ("Error in creating msgQ");
return (ERROR);
}

/* Spwan the producerTask task */


if (taskSpawn ("tProducerTask", PRODUCER_TASK_PRI, 0,
TASK_STACK_SIZE, (FUNCPTR) producerTask, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0) == ERROR)
{
perror ("producerTask: Error in spawning demoTask");
return (ERROR);
}

/* Spwan the consumerTask task */


if (taskSpawn ("tConsumerTask", CONSUMER_TASK_PRI, 0,
TASK_STACK_SIZE, (FUNCPTR) consumerTask, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0) == ERROR)
{
perror ("consumerTask: Error in spawning demoTask");
return (ERROR);
}

/* polling is not recommended. But used to make this


demonstration simple*/
while (notDone)
taskDelay (sysClkRateGet ());

/* Delete the created semaphores */


if (semDelete (semId1) == ERROR)
{
perror ("syncronizeDemo: Error in deleting semId1
semaphore");
return (ERROR);
}
if (semDelete (semId2) == ERROR)
{
perror ("syncronizeDemo: Error in deleting semId1
semaphore");
return (ERROR);
}

if (msgQDelete (msgQId) == ERROR)


{
perror ("Error in deleting msgQ");
return (ERROR);
}
return (OK);
}
/****************************************************************
* producerTask - produces messages, and sends messages to the
consumerTask
* using the message queue.
* RETURNS: OK or ERROR
*/

STATUS producerTask (void)


{
int count;
int value;
struct msg producedItem; /* producer item - produced data */

printf ("producerTask started: task id = %#x \n", taskIdSelf


());

/* Produce numMsg number of messages & send these messages */

for (count = 1; count <= numMsg; count++)


{
value = count * 10; /* produce a value */

/* Fill in the data structure for message passing */


producedItem.tid = taskIdSelf ();
producedItem.value = value;
if (semTake (semId1, WAIT_FOREVER) == ERROR)
{
perror ("taskA: Error in semTake");
return (ERROR);
}

/* Send Messages */
if ((msgQSend (msgQId, (char *) &producedItem, sizeof
(producedItem), WAIT_FOREVER, MSG_PRI_NORMAL)) == ERROR)
{
perror ("Error in sending the message");
return (ERROR);
}
else
{
if (semGive (semId2) == ERROR)
{
perror ("taskA: Error in semGive");
return (ERROR);
}
printf ("ProducerTask: tid = %#x, produced value
= %d \n", taskIdSelf (), value);
}
}
return (OK);
}
/**************************************************************
* consumerTask - consumes all the messages from the message
queue.
* RETURNS: OK or ERROR
*/

STATUS consumerTask (void)


{
int count;
struct msg consumedItem; /* consumer item -
consumed data */
printf ("\n\nConsumerTask: Started - task id = %#x\n",
taskIdSelf());

/* consume numMsg number of messages */


for (count = 1; count <= numMsg; count++)
{
/* Receive messages */
if (semTake (semId2,WAIT_FOREVER) == ERROR)
{
perror ("taskB: Error in semTake");
return (ERROR);
}
if ((msgQReceive (msgQId, (char *) &consumedItem,
sizeof (consumedItem), WAIT_FOREVER)) == ERROR)
{
perror ("Error in receiving the message");
return (ERROR);
}
else
{
if (semGive (semId1) == ERROR)
{
perror ("taskB: Error in semGive");
return (ERROR);
}
printf ("ConsumerTask: Consuming msg of
value %d from tid = %#x\n",consumedItem.value, consumedItem.tid);
}
}
notDone = FALSE; /* set the global flag to FALSE to
indicate completion*/
return (OK);
}

IMPLEMENTING THE CODE USING TORNADO SOFTWARE:

Tornado is an integrated environment for software cross-


development. It provides
an efficient way to develop real-time and embedded applications
with minimal intrusion on the target system.
Tornado comprises the following elements:
 VxWorks, a high-performance real-time operating system.
 Application-building tools (compilers and associated
programs).
 A development environment that facilitates managing and
building projects, establishing and managing host-target
communication, and running, debugging, and monitoring
VxWorks applications.

The Tornado interactive development tools include:


 The launcher, an integrated target-management utility.
 A project management facility.
 Integrated C and C++ compilers and make.
 The browser, a collection of visualization aids to monitor the
target system.
 CrossWind, a graphically enhanced source-level debugger.
 WindSh, a C-language command shell that controls the target.
 An integrated version of the VxWorks target simulator, VxSim.
 An integrated version of theWindView logic analyzer for the
target simulator.

CREATING A PROJECT:

The project facility is a key element of the Tornado development


environment. It provides graphical and automated mechanisms for
creating applications that can be downloaded to VxWorks, for
configuring VxWorks with selected features, and for creating
applications that can be linked with a VxWorks image and started
when the target system boots.

1. Open the tornado main window and create project in the


workspace.
2. Now create a bootable VxWorks Image…and press OK.
3. Now name the project and also select the location.

4. Now we will specify which Board Support Package we want, so we selected


hwa-xpc860 for this project and press Next….
5. Tornado workspace window will appear. Click on the workspace and create
another new project.

6. For that new project create a new workspace and create the downloadable
application modules and press OK….
7. Again specify the type and location of this new project which is created.

8. Now specify the toolchain for building this project. So we selected


PPC860gnu and press Next…..
9. This window shows the Workspace location, project location and the tool
chain we selected.

10. Again we come to the main workspace window where we can see the new
project we created. Click on the project files and Rebuild All in VxWorks.
11. If properly done, the following will be the results.

12. Click “new” and select C/C++ as a Source File and give the “C” file name and
also give the location.
13. So a new c-file is added in the project and now we compile the program.

14. After compilation we get the following results as it is succesfully build.


15. Now open the Vx Work system boot window and press a key to see the boot results

16. It is succesfully executed so get the following results.


17. Now again taking the example “c” program in consideration….

18. Go to the “Tools” and select “Target Server” and click “Configure”
19. Now configure the target servers. Give the target server name and specify its properties
also give file name and give Target IP address.

20. Go back to workspace and expand the object Modules. Click “ex1.o” and download it.
21. After downloading we get the following results….

22. Simultaneously on the Vxworks window we get the following output….

You might also like