anonymous wrote on Tuesday, February 19, 2013:
Hello,
I have started with FreeRTOS and have succesfully written, compiled and ported FreeRTOS code for Cortex M4-F (STM32F4DISCOVERY).
I also did same for Queue where I created two sending task with same priority (2) and one receiving task with lower priority (1). I have made use of an array xSend = {100,200,300} and I’m sending xSend and xSend to Queue via two sender task. However while receiving the receive first receives 200 and then 100 instead of 100 and then 200.
May anyone please through light on why ?
Also to control the things if I wish to integrate Semaphores Mutex with Queues then what should be the best way to move forward as I’m still trying to understand how things work.
This is current code :
#include "stm32f4xx.h"
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
typedef struct {
xQueueHandle IntQueue;
} HandlesType;
HandlesType* getHandles() {
static HandlesType h;
return &h;
}
uint32_t xSend[] = {100,200,300};
void task_tx(void* p) {
int i = 0;
while (1) {
i++;
if (!xQueueSend(getHandles()->IntQueue, p, 500)) {
puts("Failed to send item to queue within 500ms");
}
vTaskDelay(1000);
}
}
void task_rx(void* p) {
int myInt = 0;
uint32_t xReceive[3];
while (1) {
myInt++;
if (!xQueueReceive(getHandles()->IntQueue, &(xReceive[myInt]), 1000)) {
puts("Failed to receive item within 1000 ms");
} else {
printf("Received: %u\n", xReceive);
}
}
}
int main() {
getHandles()->IntQueue = xQueueCreate(2, sizeof(int));
xTaskCreate(task_tx, (signed char*) "t1", 2048, &(xSend[0]), 2, 0);
xTaskCreate(task_tx, (signed char*) "t3", 2048, &(xSend[1]), 2, 0);
xTaskCreate(task_rx, (signed char*) "t2", 2048, 0, 1, 0);
vTaskStartScheduler();
return -1;
}