You are on page 1of 20

EMBEDDED SYSTEMS

LAB MANUAL
M.TECH, VLSI&ES

2nd SEMESTER
LIST OF EXPERIMENTS
1. Register a new command in Command Line Interface(CLI) using
ARM - 926 with perfect RTOS.
2. Creating a new task using ARM-926 with perfect RTOS.
3. Interrupt handling using ARM-926 with perfect RTOS.
4.Allocate resource using semaphores using ARM-926
with perfect RTOS.

5. Share resource using MUTEX using ARM-926 with perfect RTOS


6. Synchronize two identical threads using MONITOR using ARM-926
with perfect RTOS.
7. Readers writers problem for concurrent tasks using ARM-926
with perfect RTOS.

1. Register a new command in Command Line Interface(CLI)


using
ARM - 926 with perfect RTOS.
AIM: To register a new command in Command Line Interface (CLI) using ARM-926 with
Perfect RTOS.
APPARATUS:
1. ARM-926 based Embedded Artist LPC3250 OEM board.
2. Personal computer with LINUX based perfect RTOS.
Program:
#include<stdio.h>
#include<RTL.h>
OS_TID id1,id2;
int a;
__task void task2(void) {
a++;
}
__task void task1(void)
{
a++;
}
__task void task0(void)
{
id1=os_tsk_create(task1,2);
id2=os_tsk_create(task2,2);
os_tsk_delete_self();
}
int main(void) {
os_sys_init(task0);
}
Result:

2. Creating a new task using ARM-926 with perfect RTOS.

AIM: To create a new task using ARM-926 with perfect RTOS.


APPARATUS:
1. ARM-926 based Embedded Artist LPC3250 OEM board .
2. Personal computer with LINUX based perfect RTOS.
Program:
/*---------------------------------------------------------------------------------------* Creating task1 and task2 using RL RTX Kernel for toggling LED1 and LED2 of
* Embedded Artist LPC3250 OEM board
*---------------------------------------------------------------------------------------* file : taskCrt.c
*---------------------------------------------------------------------------------------- */
#include <LPC325x.H>
#include<RTL.h>
#include<stdio.h>
OS_TID id1,id2;
__task void task0(void);
__task void task1(void);
__task void task2 (void);
__task void task1 (void){
while(1) {
/* Toggling LED1 */
P3_OUTP_SET=0x0002;
os_dly_wait(5);
P3_OUTP_CLR=0x0002;
os_dly_wait(3);
}
}
__task void task2(void){
while(1) {
/* toggling LED2 */
P3_OUTP_SET=0x4000;
os_dly_wait(3);
P3_OUTP_CLR=0x4000;

os_dly_wait(10);
}
}
__task void task0(void) {
id1=os_tsk_create(task1,0x1);
id2=os_tsk_create(task2,0x1);
os_tsk_delete_self();
}
int main(void) {
P3_OUTP_CLR=0x4002;
os_sys_init(task0);
}
Result:

3. Interrupt handling using ARM-926 with perfect RTOS.


AIM: To implement interrupt handling using ARM-926 with perfect RTOS.
APPARATUS:
1. ARM-926 based Embedded Artist LPC3250 OEM board.
2. Personal computer with LINUX based perfect RTOS.
Program:
#include<RTL.h>
#include <LPC325x.H>

OS_TID idT1,idT2;
void delay(int );
void delay(int a) {
for(;a<100000;a++);
}
__task void T1(void) {
for(;;) {
P3_OUTP_SET=0x0002;
os_dly_wait(25);
//
delay(0);
P3_OUTP_CLR=0x0002;
os_dly_wait(50);
// delay(0);
}
}
__task void T2(void){
for(;;){
os_evt_wait_and(0x0001,0xffff);
P3_OUTP_SET=0x4000;
os_dly_wait(2);
// delay(0);
P3_OUTP_CLR=0x4000;
}
}
__task void task0(void) {
P3_OUTP_CLR=0x4002;
idT1=os_tsk_create(T1,1);
idT2=os_tsk_create(T2,10);
os_evt_set(0x0001,idT2);
/* Initialize millisecond timer to generate interrupt every 100 ms
MSTIM_MATCH1 = 3200 - 1;
MSTIM_COUNTER = 0;
MSTIM_INT = (1 << 1);
MSTIM_MCTRL = (1 << 4) | (1 << 3);
MSTIM_CTRL = (1 << 0);
MIC_APR
|= (1 << 27);

*/

MIC_ATR
&= ~(1 << 27);
MIC_ITR
&= ~(1 << 27);
MIC_ER
|= (1 << 27);
os_tsk_delete_self();
}
int main(void) {
os_sys_init(task0);
}
Interrupt subroutine:
#include <RTL.h>
#include <LPC325x.H>
extern OS_TID idT2;
/* Milisecond Timer Interrupt Handler
void interrupt_mstim (void) __irq {
MSTIM_INT = (1 << 1);
/* Clear interrupt
MIC_RSR = (1 << 27);
isr_evt_set (0x0001, idT2);
/* Send event to taskB
}

*/
*/
*/

Result:
4. Allocate resource using semaphores using ARM-926
with perfect RTOS.
AIM: To allocate resource using semaphores using ARM-926 with perfect RTOS.
APPARATUS:
1. ARM-926 based Embedded Artist LPC3250 OEM board.
2. Personal computer with LINUX based perfect RTOS.
Program:
/*-----------------------------------------------------------------------------------------------------------* Controlling two tasks taskA and taskB using resource function 'led_toggle_fun' using RLRTX Kernel semaphore
* on Embedded Artist LPC3250 Board
*------------------------------------------------------------------------------------------------------------*/
#include<RTL.h>
#include<stdio.h>

#include<LPC325x.H>
#include "serial.h"
OS_TID id0,id1,id2;
OS_SEM sem1;
OS_RESULT ret;
__task void taskA(void);
__task void taskB(void);
__task void task0(void);
void led_toggle_fun(void);
void led_toggle_fun(void) {
P3_OUTP_CLR=0x0002;
os_dly_wait(10);
P3_OUTP_SET=0x0002;
os_dly_wait(50);
}
__task void taskA (void) {
//os_dly_wait(2);
ret=os_sem_wait(sem1,1);
if(ret != OS_R_TMO)
{
printf("TaskA executing the resource code:\n");
led_toggle_fun(); /* Critical Resource code */
}
os_sem_send(sem1);
}
__task void taskB(void) {
os_sem_wait(sem1,0xFFFF);
printf("TaskB:\n");
led_toggle_fun();
os_sem_send(sem1);
}
__task void task0(void){
led_toggle_fun();
os_sem_init(sem1,1);
id1=os_tsk_create(taskA,10);
id2=os_tsk_create(taskB,2);

os_tsk_delete_self();
}
int main(void) {
SER_Init();
P3_OUTP_CLR=0x0002;
os_sys_init(task0);
}
Result:

5. Share resource using MUTEX using ARM-926 with perfect RTOS.


AIM: To perform sharing of resource using MUTEX using ARM-926 with perfect
RTOS.
APPARATUS:
1. ARM-926 based Embedded Artist LPC3250 OEM board.
2. Personal computer with LINUX based perfect RTOS.
Program:
Synchronization
#include<stdio.h>
#include<RTL.h>
#include <LPC325x.H>
#include "serial.h"
OS_TID id1,id2;
OS_MUT MLOCK;
int count;
void sharedCode(void) {
unsigned long i;
os_mut_wait(&MLOCK,0xffff);
i=0;
count +=1;
printf("Task %d is started \n",count);

for(i=0;i<(0xfffffff); i++) ;
printf("Task %d is finished \n",count);
os_mut_release(&MLOCK);
}
__task void task1(void) {
os_mut_init(&MLOCK);
sharedCode();
os_tsk_delete_self();
}
__task void task2(void) {
sharedCode();
os_tsk_delete_self();
}
__task void init0(void) {
id1=os_tsk_create(task1,1);
id2=os_tsk_create(task2,1);
os_tsk_delete_self();
}
int main(void) {
SER_Init();
os_sys_init(init0);
}
No synchronization
#include<stdio.h>
#include<RTL.h>
#include <LPC325x.H>
#include "serial.h"
OS_TID id1,id2;
int count;

intsharedCode(void) {
inti=0;
count +=1;
printf("Task %d is started \n",count);
for(i=0;i<(0xfffffff); i++) ;
printf("Task %d is finished \n",count);
return NULL;
}
__task void task1(void) {
sharedCode();
os_tsk_delete_self();
}
__task void task2(void) {
sharedCode();
os_tsk_delete_self();
}
__task void init0(void) {
id1=os_tsk_create(task1,1);
id2=os_tsk_create(task2,1);
os_tsk_delete_self();
}
int main(void) {
SER_Init();
os_sys_init(init0);
}
Result:

6. Synchronize two identical threads using MONITOR using ARM-926


with perfect RTOS.
AIM: To synchronize two identical threads using MONITOR using ARM-926 with
Perfect RTOS.
APPARATUS:
1. ARM-926 based Embedded Artist LPC3250 OEM board.
2. Personal computer with LINUX based perfect RTOS.
Program:
/* ------------------------------------* This is the Synchronizing two identical threads using MONITOR. Solution
*--------------------------------------------------* File : ea3250_synchronize_MONITOR.c
*--------------------------------------------------- */
#include<stdio.h>
#include<RTL.h>
#include <LPC325x.H>
#include "serial.h"
#define TCOUNT 10
#define COUNT_LIMIT 10
OS_MUT mutCount;
OS_TID id1,id2,id3,id;
int count=0;
void inCount(id) {
inti;
//id=os_tsk_self();
for(i=0;i<TCOUNT;i++) {
os_mut_wait(&mutCount,0xffff);
count++;

if(count == COUNT_LIMIT) {

//

printf(" Threasholed reached..\n");


os_evt_set(0x0001,id1);
os_dly_wait(3);

}
printf("inCount(): Task=%u,Count=%d,unlockingmutex.\n",id,count);
os_mut_release(&mutCount);
os_dly_wait(30);
}
}
__task void taskA(void) {
printf("Starting watch count..\n");
os_mut_wait(&mutCount,0xffff);
while(count<COUNT_LIMIT) {
os_mut_release(&mutCount);
os_evt_wait_and(0x0001,0xffff);
count += 125;
printf("Watch count=%d \n",count);
}
os_mut_release(&mutCount);
os_tsk_delete_self();
}
__task void taskB(void) {
id2=os_tsk_self();
inCount(id2);
os_tsk_delete_self();
}
__task void taskC(void) {

id3=os_tsk_self();
inCount(id3);
os_tsk_delete_self();
}
__task void task0(void) {
id1=os_tsk_create(taskA,1);
os_tsk_create(taskB,1);
os_tsk_create(taskC,1);
os_mut_init(&mutCount);
os_tsk_delete_self();
}
int main(void) {
SER_Init();
os_sys_init(task0);
}
Result:

7. Readers writers problem for concurrent tasks using ARM-926 with


perfect RTOS.
AIM: To observe readers writers problem for concurrent tasks using ARM-926
with perfect RTOS.
APPARATUS:
1. ARM-926 based Embedded Artist LPC3250 OEM board.
2. Personal computer with LINUX based perfect RTOS.
Program:
Problem 1

/* ------------------------------------* This is the First Readers-Writers Problem Solution


*--------------------------------------------------* File : ea3250_readwriteProblem_1.c
*--------------------------------------------------- */
#include<stdio.h>
#include<RTL.h>
#include "serial.h"
OS_MUT mutLock;
OS_SEM wRight;
OS_TID id1,id2,id3,id4,id5;
intreadCount=0;
int count;
void writeFun() {
count += 1;
printf("Wright started\n");
printf("count value=%d\n",count);
}
void readFun(int b) {
int a;
os_mut_wait(mutLock,0xffff);
readCount++;
if(readCount == 1)
{
os_sem_wait(wRight,0xffff);
}
os_mut_release(mutLock);
printf("Read%d: is reading\n",b);
a=count;
printf("read value=%d\n",a);
printf("Read%d: is finished\n",b);
os_mut_wait(mutLock,0xffff);
readCount--;
if(readCount==0)
os_sem_send(wRight);

os_mut_release(mutLock);
}
__task void readA(void) {
readFun(id1);
os_tsk_delete_self();
}
__task void readB(void) {
readFun(id2);
os_tsk_delete_self();
}
__task void readC(void) {
readFun(id3);
os_tsk_delete_self();
}
__task void writeA(void) {
os_sem_wait(wRight,0xffff);
writeFun();
os_sem_send(wRight);
}
__task void task0(void) {
id1=os_tsk_create(readA,1);
id2=os_tsk_create(readB,1);
id3=os_tsk_create(readC,1);
id4=os_tsk_create(writeA,1);
os_sem_init(wRight,1);
os_sem_send(wRight);
os_mut_init(&mutLock);
os_tsk_delete_self();

}
int main(void) {
SER_Init();
os_sys_init(task0);
}

Problem 2
/* ------------------------------------* This is the Writers-Preference of Readers-Writers Problem Solution
*--------------------------------------------------* File : ea3250_readwriterProblem_2.c
*--------------------------------------------------- */
#include<stdio.h>
#include<RTL.h>
#include "serial.h"
OS_SEM sem1,sem2,sem3;
OS_MUT r,w;
// r is for proctecting read operation and w for write operation.
OS_TID id1,id2,id3,id4,id5;
intreadCount=0,writeCount=0;
int count;
void writeFun() {
os_sem_wait(sem2,0xffff);
writeCount += 1;
if(writeCount==1)
os_mut_wait(r,0xffff);
os_sem_send(sem2);

os_mut_wait(w,0xffff);
printf("Writing Starts \n");
count +=1;
printf("count=%d\n",count);
os_mut_release(w);
os_sem_wait(sem2,0xffff);
writeCount=writeCount-1;
if(writeCount==0)
os_mut_release(r);
os_sem_send(sem2);
}
void readFun() {
int a;
os_sem_wait(sem3,0xffff);
os_mut_wait(r,0xffff);
os_sem_wait(sem1,0xffff);
readCount +=1;
if(readCount == 1)
os_mut_wait(w,0xffff);
os_sem_send(sem1);
os_mut_release(r);
os_sem_send(sem3);
printf("Read: Starts..\n");
printf("Count=%d\n",count);
printf("Read: finish..\n");
os_sem_wait(sem1,0xffff);
readCount -= 1;
if(readCount==0)
os_mut_release(w);
os_sem_send(sem1);
}
__task void readA(void) {
readFun();
os_tsk_delete_self();
}
__task void readB(void) {

readFun();
os_tsk_delete_self();
}
__task void readC(void) {
readFun();
os_tsk_delete_self();
}
__task void writeA(void) {
writeFun();
}
__task void writeB(void) {
writeFun();
}
__task void task0(void) {
id1=os_tsk_create(readA,1);
id2=os_tsk_create(readB,1);
id3=os_tsk_create(readC,1);
id4=os_tsk_create(writeA,1);
id5=os_tsk_create(writeB,1);
os_sem_init(sem1,1);
os_sem_init(sem2,1);
os_sem_init(sem3,1);
os_sem_send(sem1);
os_sem_send(sem2);
os_sem_send(sem3);
os_mut_init(r);
os_mut_init(w);
os_tsk_delete_self();
}
int main(void) {
SER_Init();
os_sys_init(task0);
}
Result: