#include <Arduino_FreeRTOS.h> //iniatilize the headerfile as freertos
#include "queue.h"//iniatilize the queue header file
QueueHandle_t xStringQueue;//initilize the string queue
int timer1_counter ;
void setup()
{
Serial.begin(9600);
//create Api for sting
xTaskCreate(vStringPrinter," String Printer", 100, NULL, 1,NULL);
//create Queue for string with size of the queue and stored in the handler variable here
xStringQueue = xQueueCreate(6,sizeof(char *));
//iniatilize the interrupt here
InterruptInit();
}
//main function stringprinter with void pointer
void vStringPrinter(void *pvParameters)
{
char *pcString;//declaring the string return type
//iniatilize the while with infinity loop
while(1)
{
//here we receive the string queue in the arguments handler variable,string return type,delay.
xQueueReceive(xStringQueue,&pcString,portMAX_DELAY);
Serial.println(pcString);// print the string in output console of wokwi simulator
}
}
//read and write the queue using interrupt service routine
ISR(TIMER1_OVF_vect)//enabling the timer 1 for interrupt hanndling with overflow flag
{
TCNT1 = timer1_counter;//iniatilize timer1 counter and return the value to TCNT1
uint32_t receivedNumber;
//defining the array of the string.
static const char *pcStrings[]=
{
"Hello\r\n",
"Hi\r\n",
"I\r\n",
"am\r\n",
"GIRI\r\n",
"here\r\n",
};
//send the string from ISR with aruguments of handler variable,address of the index,pdfalse is not a null it send more string back
xQueueSendToBackFromISR(xStringQueue,&pcStrings[4],pdFALSE);
}
void loop(){}
void InterruptInit()
{
//here interrupt is 0
noInterrupts();
//Timer counter control register 1 have 16bit register
TCCR1A =0;
TCCR1B =0;
timer1_counter =34286 ;
TCNT1 = timer1_counter;//TCNT1=34286
TCCR1B |=(1<<CS12);// here i declare the prescaler value
//timer counter1 interrupt masking register
TIMSK1 |= (1 << TOIE1); //enabling interrupt of TIFR
interrupts();
}