I am a newbie to freeRTOS and I was trying to learn about semaphores,I am using ATmega32a microcontroller, the plan was to create 3 tasks each is blinking the same led for some time with different frequencies the result was the led is just on forever.
so I canceled 2 tasks and kept only one task to catch the problem and the led is just on forever again.
I used the debugger and what happens is that it never continue the loop of for loop it toggles the bit and then delay and then toggle again and then go out to check the semaphore and repeat, this is very strange behavior.
but that's in the debugger, in reality, it never toggles it's on forever. can you help me?
#include <avr/io.h>
/* FreeRTOS files. */
#include "FreeRTOS.h"
#include "task.h"
#include "croutine.h"
#include "FreeRTOSConfig.h"
#include "semphr.h"
#include <avr/interrupt.h>
/* Define all the tasks */
static void ledBlinkingtask1(void* pvParameters);
xSemaphoreHandle MySemaphore = 0;
int main(void) {
DDRB=0xff;
/* Call FreeRTOS APIs to create tasks, all tasks has the same priority "1" with the
same stack size*/
xTaskCreate(ledBlinkingtask1,"LED1",
configMINIMAL_STACK_SIZE, NULL, 1, NULL );
// Start the RTOS kernel
vTaskStartScheduler();
return 0;
}
static void ledBlinkingtask1(void* pvParameters){
const uint16_t blinkDelay = 500;
while (1)
{
if (xSemaphoreTake(MySemaphore,2000))
{
for (int i =0;i<9;i++)
{
PORTB ^= (1<<0); //toggle PB0 //PB0
vTaskDelay(blinkDelay); //wait some time
}
xSemaphoreGive(MySemaphore);
}
}
}