NEWAthar Experiment ALL Rtos
NEWAthar Experiment ALL Rtos
Department
of
Multidisciplinary Engineering
Branch EECE
Section A
3.
4.
5.
6.
7.
8.
9.
10.
11.
Experiment No.- 1
Theory/Commands/Circuit diagram:
Step 1 - Installation
Requirements:
1. Development board (e.g., STM32, Arduino, Raspberry Pi, etc.).
2. Computer with internet access.
3. Appropriate development environment (e.g., Eclipse, Visual Studio Code, etc.).
4. USB cable for programming the development board.
Steps:
1. Download Free RTOS:
- Visit the official Free RTOS website: [https://www.freertos.org/]
(https://www.freertos.org/)
- Navigate to the "Quick Start Guide" or "Downloads" section.
- Download the Free RTOS source code or pre-built binaries suitable for your development
board.
Conclusion:
The experiment aims to successfully download, install, and run FreeRTOS on a development
board. Through this process, you gain hands-on experience with real-time operating systems
and can explore building more complex applications using FreeRTOS.
Experiment No.- 2
CODE :
void setup()
{
Serial.begin(9600); // Enable serial communication.
pinMode(4, OUTPUT); // define LED1 pin as a digital output
pinMode(5, OUTPUT); // define LED2 pin as a digital output
//Create the first task at priority 1
// Name of task is "LED1"
// Stack size is set to 100
// we do not pass any value to Task1. Hence, third agument is NULL
// Set the priority of task to one
// Task1 handler is not used. Therefore set to Null
xTaskCreate(Task1, "LED1", 100, NULL, 1, NULL); // xtaskcreate is used to create a fresh
task
// Start FreeRTOS scheduler in Preemptive timing silicing mode
vTaskStartScheduler(); // starts real time kernel
}
void loop()
{
// Do nothing as schduler will allocated CPU to Task1 and Task2 automatically
}
/* Task1 with priority 1 */
void Task1(void* pvParameters) // void* means we are pointing to an unknown type of data
{
while(1)
{
Serial.println("Task1 Running"); // print "Task1 Running" on Arduino Serial Monitor
digitalWrite(4, HIGH); // sets the digital pin 4 on
digitalWrite(5, LOW); // sets the digital pin 5 off
xTaskCreate(Task2, "LED2", 100, NULL, 2, &TaskHandle_2); // create task2 with priority
2
vTaskDelay( 100 / portTICK_PERIOD_MS ); // create delay between tasks, here wait for
one second
}
}
/* Task2 with priority 2 */
void Task2(void* pvParameters)
{
//digitalWrite(5, HIGH); // sets the digital pin 5 high
//digitalWrite(4, LOW); // sets the digital pin 4 low
Serial.println("Task2 is runnig and about to delete itself");
vTaskDelete(TaskHandle_2); //Delete own task by passing NULL(TaskHandle_2 can also
be used)
}
OUTPUT :
Experiment No.- 3
CODE :
1. Calculator in C
#include <stdio.h>
int main() {
int num1, num2;
float answer;
char oper;
printf("Enter an operator (+, -, *, /): ");
scanf("%c", &oper);
printf("Enter two numbers: ");
scanf("%d %d", &num1, &num2);
if (oper == '+') {
answer = num1 + num2;
printf("%d + %d = %.2f", num1, num2, answer);
}
else if (oper == '-') {
answer = num1 - num2;
printf("%d - %d = %.2f", num1, num2, answer);
}
else if (oper == '*') {
answer = num1 * num2;
printf("%d * %d = %.2f", num1, num2, answer);
}
else if (oper == '/') {
if (num2 != 0) {
answer = (float)num1 / num2;
printf("%d / %d = %.2f", num1, num2, answer);
} else {
printf("Error! Division by zero."); return 1;
}
}else {
printf("Error! Invalid operator.");
return 1;
}return 0;
}
OUTPUT :
#include <stdio.h>
#include <string.h>
int main()
{
char str[] = { "naman" };
int l = 0;
int h = strlen(str) - 1;
while (h > l) {
if (str[l++] != str[h--]) {
printf("%s is not a palindrome\n", str);
return 0;
}
}
return 0;
}
OUTPUT :
#include <stdio.h>
int main()
{
CODE :
#include<stdio.h>
int main()
{
findavgTime(processes, n, burst_time);
return 0;
}
OUTPUT :
Experiment No.- 5
CODE :
#include <Arduino_FreeRTOS.h>
void setup() {
Serial.begin(9600);
vTaskStartScheduler();
void loop()
{
while(1)
Serial.println("Task1");
digitalWrite(12, HIGH);
Serial.println("Task2");
digitalWrite(7, HIGH);
digitalWrite(7, LOW);
}
}
int counter = 0;
while(1)
{
counter++;
Serial.println(counter);
vTaskDelay(500 / portTICK_PERIOD_MS); }
}
OUTPUT :
Experiment No.- 6
CODE :
#include <Arduino_FreeRTOS.h>
TaskHandle_t Task1;
TaskHandle_t Task2;
TaskHandle_t Task3;
TaskHandle_t Task4;
OUTPUT :
Experiment No.- 7
CODE:
#include <stdio.h>
int main(){
int A[100][4];
int i, j, n, total = 0, index, temp;
float avg_wt, avg_tat;
printf("Enter number of process: ");
scanf("%d", &n);
printf("Enter Burst Time:\n");
for (i = 0; i < n; i++) {
printf("P%d: ", i + 1);
scanf("%d", &A[i][1]);
A[i][0] = i + 1;}
for (i = 0; i < n; i++) {
index = i;
for (j = i + 1; j < n; j++)
if (A[j][1] < A[index][1])
index = j;
temp = A[i][1];
A[i][1] = A[index][1];
A[index][1] = temp;
temp = A[i][0];
A[i][0] = A[index][0];
A[index][0] = temp;}
A[0][2] = 0;
for (i = 1; i < n; i++) {
A[i][2] = 0;
for (j = 0; j < i; j++)
A[i][2] += A[j][1];
total += A[i][2];}
avg_wt = (float)total / n;
total = 0;
printf("P BT WT TAT\n");
for (i = 0; i < n; i++) {
A[i][3] = A[i][1] + A[i][2];
total += A[i][3];
printf("P%d %d %d %d\n", A[i][0],
A[i][1], A[i][2], A[i][3]); }
avg_tat = (float)total / n;
printf("Average Waiting Time= %f", avg_wt);
printf("\nAverage Turnaround Time= %f", avg_tat);
}
OUTPUT :
Experiment No.- 8
THEORY:
Priority scheduling is one of the most common scheduling algorithms in batch
systems. Each process is assigned a priority. The process with the highest
priority is to be executed first and so on. Processes with the same priority are
executed on a first-come first served basis. Priority can be decided based on
memory requirements, time requirements or any other resource requirement.
Also priority can be decided on the ratio of average I/O to average CPU burst
time.
Implementation:
1- First input the processes with their burst time and priority.
2- Sort the processes, burst time and priority according to the priority.
3- Now simply apply FCFS algorithm.
CODE :
#include <bits/stdc++.h>
using namespace std;
struct Process {
int pid;
int bt;
int priority;
};
bool comparison(Process a, Process b)
{
return (a.priority > b.priority);
}
void findWaitingTime(Process proc[], int n, int wt[])
{
wt[0] = 0;
for (int i = 1; i < n; i++)
wt[i] = proc[i - 1].bt + wt[i - 1];
}
CODE :
#include<stdio.h>
#include<string.h>
int main()
{
int bt[20],at[10],n,i,j,temp,st[10],ft[10],wt[10],ta[10];
int totwt=0,totta=0;
double awt,ata;
char pn[10][10],t[10];
//clrscr();
printf("Enter the number of process:");
scanf("%d",&n);
for(i=0; i<n; i++)
{
printf("Enter process name, arrival time& burst time:");
scanf("%s%d%d",pn[i],&at[i],&bt[i]);
}
for(i=0; i<n; i++)
for(j=0; j<n; j++)
{
if(bt[i]<bt[j])
{
temp=at[i];
at[i]=at[j];
at[j]=temp;
temp=bt[i];
bt[i]=bt[j];
bt[j]=temp;
strcpy(t,pn[i]);
strcpy(pn[i],pn[j]);
strcpy(pn[j],t);
}
}
for(i=0; i<n; i++)
{
if(i==0)
st[i]=at[i];
else
st[i]=ft[i-1];
wt[i]=st[i]-at[i];
ft[i]=st[i]+bt[i];
ta[i]=ft[i]-at[i];
totwt+=wt[i];
totta+=ta[i];
}
awt=(double)totwt/n;
ata=(double)totta/n;
printf("\nProcessname\tarrivaltime\tbursttime\twaitingtime\tturnaroundtime");
for(i=0; i<n; i++)
{
printf("\n%s\t%5d\t\t%5d\t\t%5d\t\t%5d",pn[i],at[i],bt[i],wt[i],ta[i]);
}
printf("\nAverage waiting time: %f",awt);
printf("\nAverage turnaroundtime: %f",ata);
return 0;
}
OUTPUT :