rafaeladel wrote on Friday, January 22, 2016:
I’m trying to run a simple example with queues using Atmega32.
I have
- Two sending tasks
- One receiving task
- Buzzer
- 3 LEDS (for errors detection)
The first sending task turns on the buzzer. The second sending task turns off the buzzer.
The receiver task receive execution code from either one of the sending tasks and act according to that code (0x01 to turn on buzzer , 0x02 to turn off buzzer).
The 3 leds are for error detection.
- Pin 5 led -> queue empty (Receiver side)
- Pin 6 led -> queue not empty (when it should be) (Receiver side)
- Pin 7 led -> queue is full (Sender side)
The receiver task has higher priority than the two sender tasks. And it waits for 100ms in block state till any data arrives in queue.
The problem is, I always get pin (5) led on !! meaning the queue is empty. Where I thing the buzzer should go on and off without toggeling any leds for errors.
My assumption that the two sender tasks never run and the schedular always run the receiver (having the highest priority), but again there’s (100ms) for the receiver in block state where the two sender should operate.
Here’s my code:
#define F_CPU 8000000UL
#include <avr/io.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/queue.h"
#include "freertos/FreeRTOSConfig.h"
void task_sender(void *pvParameters);
void task_receiver(void *pvParameters);
QueueHandle_t my_queue;
int main(void)
{
my_queue = xQueueCreate(1, sizeof(char));
if(my_queue != NULL) {
DDRD = 0xf0;
char sender_one = 0x01;
char sender_two = 0x02;
xTaskCreate(task_sender, NULL, 50, &sender_one, 1, NULL);
xTaskCreate(task_sender, NULL, 50, &sender_two, 1, NULL);
xTaskCreate(task_receiver, NULL, 50, NULL, 2, NULL);
vTaskStartScheduler();
}
return 0;
}
void task_sender(void *pvParameters)
{
char msg = '\0';
portBASE_TYPE status = '\0';
while(1)
{
PORTD = 1 << PD7;
msg = (char) pvParameters;
status = xQueueSendToBack(my_queue, &msg, 0);
if(status == errQUEUE_FULL)
{
PORTD = 1 << PD7;
}
taskYIELD();
}
}
void task_receiver(void *pvParameters)
{
char recieved_msg = '\0';
portTickType timeToWait = 100 / portTICK_RATE_MS;
portBASE_TYPE status = '\0';
while(1)
{
if(uxQueueMessagesWaiting(my_queue) != 0)
{
PORTD = 1 << PD6;
}
status = xQueueReceive(my_queue, &recieved_msg, timeToWait);
if(status == pdPASS)
{
if(recieved_msg == 0x01) {
PORTD = 1 << PD4;
} else if(recieved_msg == 0x02) {
PORTD &= ~(1 << PD4);
}
} else if(status == errQUEUE_EMPTY){
PORTD = 1 << PD5;
}
}
}
My FreeRTOSConfig.h:
#define configUSE_PREEMPTION 1
#define configUSE_IDLE_HOOK 0
#define configUSE_TICK_HOOK 0
#define configCPU_CLOCK_HZ ( ( unsigned long ) 8000000 )
#define configTICK_RATE_HZ ( ( portTickType ) 1 )
#define configMAX_PRIORITIES ( ( unsigned portBASE_TYPE ) 3)
#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 85 )
#define configTOTAL_HEAP_SIZE ( (size_t ) ( 600 ) )
#define configMAX_TASK_NAME_LEN ( 8 )
#define configUSE_TRACE_FACILITY 0
#define configUSE_16_BIT_TICKS 1
#define configIDLE_SHOULD_YIELD 0
#define configQUEUE_REGISTRY_SIZE 0
/* Co-routine definitions. */
#define configUSE_CO_ROUTINES 0
#define configMAX_CO_ROUTINE_PRIORITIES ( 2 )
/* Set the following definitions to 1 to include the API function, or zero
to exclude the API function. */
#define INCLUDE_vTaskPrioritySet 0
#define INCLUDE_uxTaskPriorityGet 0
#define INCLUDE_vTaskDelete 1
#define INCLUDE_vTaskCleanUpResources 0
#define INCLUDE_vTaskSuspend 0
#define INCLUDE_vTaskDelayUntil 1
#define INCLUDE_vTaskDelay 1