0% found this document useful (0 votes)
5 views5 pages

Implementation Assignment On Scheduling Algorithms

This document provides a code implementation for a Real-Time Operating System (RTOS) that schedules three tasks in a round-robin manner using priorities. The tasks include reading a character from UART0, writing a character to UART1, and blinking LEDs. The code initializes the serial ports, defines the tasks, and sets up the system to run the tasks concurrently.
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)
5 views5 pages

Implementation Assignment On Scheduling Algorithms

This document provides a code implementation for a Real-Time Operating System (RTOS) that schedules three tasks in a round-robin manner using priorities. The tasks include reading a character from UART0, writing a character to UART1, and blinking LEDs. The code initializes the serial ports, defines the tasks, and sets up the system to run the tasks concurrently.
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

1.

Implement a RTOS code to schedule 3 tasks in round robin


using priorities where Task1 – reads a character from uart0
Task 2 - writes a character to uart1 Task3- blink leds…
#include <rtl.h>
#include <lpc21xx.h>

unsigned char global_char = 0;


int counter3 = 0;

void serial0_init()
{
PINSEL0 |= 0x00000005; // P0.0 = TXD0, P0.1 = RXD0
U0LCR = 0x83; // 8-bit, enable DLAB
U0DLL = 0x61; // 9600 baud @ 15MHz
U0LCR = 0x03; // Disable DLAB
}

void serial1_init()
{
PINSEL0 |= 0x00050000; // P0.8 = TXD1, P0.9 = RXD1
U1LCR = 0x83; // 8-bit, enable DLAB
U1DLL = 0x61; // 9600 baud @ 15MHz
U1LCR = 0x03; // Disable DLAB
}
void delay(unsigned int j)
{ unsigned int i;
for(i=0;i<j;i++);
}

__task void job1(void)


{
while(1)
{
while(!(U0LSR & 0x01)); // Wait for data
global_char = U0RBR; // Read byte

os_dly_wait(5);
}
}

__task void job2(void)


{
while(1)
{
while(!(U1LSR & 0x20)); // Wait for THR empty
U1THR = global_char; // Send received byte

os_dly_wait(5);
}
}

__task void job3(void)


{

PINSEL0|=0X00000000;
IODIR0=0X000F0000; // Configure P0.16-P0.19 as Output
while(1)
{
IOCLR0=0X000F0000; // CLEAR (0) P0.16-P0.19 to turn LEDs
ON
os_dly_wait(2);
IOSET0=0X000F0000; // SET (1) P0.16-P0.19 to turn LEDs OFF
//delay(100000);
os_dly_wait(2);
}
}

__task void init_task(void)


{
serial0_init();
serial1_init();

os_tsk_create(job1, 1);
os_tsk_create(job2, 1);
os_tsk_create(job3, 1);

os_tsk_delete_self(); // Remove init task


}

int main(void)
{
os_sys_init(init_task);
for(;;);
}

You might also like