*/
#include <stdlib.h>
/* Scheduler includes. */
#include "FreeRTOS.h"
#include "task.h"
/*-----------------------------------------------------------*/
/* Constants used by the "check" task. As described at the head of this file
the check task toggles an LED. The rate at which the LED flashes is used to
indicate whether an error has been detected or not. If the LED toggles every
3 seconds then no errors have been detected. If the rate increases to 500ms
then an error has been detected in at least one of the demo application tasks. */
#define mainCHECK_LED (7)
#define mainNO_ERROR_FLASH_PERIOD ( ( portTickType ) 3000 /
portTICK_RATE_MS )
#define mainERROR_FLASH_PERIOD ( ( portTickType ) 500 /
portTICK_RATE_MS )
/*-----------------------------------------------------------*/
/*Batch b2
Roll no 16
Title: scheduling two tasks to print characters on serial port. Observe output with and
without using SEMAPHORE*/
#include"LPC21xx.h"
//#include"FreeRTOS.h"
//#include"task.h"
//#include"list.h"
#include"semphr.h"
int main(void)
{
Init_hardware();
xTaskCreate(uart1, "uart1",configMINIMAL_STACK_SIZE,
NULL,TASK_PRIORITY1,&xHandle1);
xTaskCreate(uart2, "uart2",configMINIMAL_STACK_SIZE,
NULL,TASK_PRIORITY2,&xHandle2);
vTaskStartScheduler();
}
void Init_hardware()
{
PINSEL0 = 0x00000005; //set line ctrl reg. for UART0 with above parameters
U0LCR = 0x83; //set bit 7 to 1 to set divisor latches
U0DLM = 0X01;
U0DLL = 0X86;
U0LCR = 0x03;
}
static void uart1(void *pvParameters)
{
long int n;
char msg[]={"\n\rTASK1"};
(void) pvParameters;
while(1)
{
n=0;
if(xSemaphore!=NULL)
{
if(xSemaphoreTake(xSemaphore,(portTickType)10)==
pdTRUE)
{
n=0;
while(msg[n]!='\0') //chk end of msg
{
U0THR = msg[n++];
while(!(U0LSR&0x40));
}
}
}
xSemaphoreGive(xSemaphore);
}
}