#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include "list.h"
#include "supporting_functions.h"
void vTask1(void * pvParameters);
void vTask2(void * pvParameters);
TaskHandle_t xTask2Handle;
int main()
{
xTaskCreate(vTask1, "Task 1", 1000, NULL, 1, NULL);
vTaskStartScheduler();
for (;;);
return 0;
}
void vTask1(void * pvParameters)
{
const TickType_t xDelay1000ms = pdMS_TO_TICKS(1000UL);
for (;;)
{
vPrintString("Task1 is running\n");
xTaskCreate(vTask2, "Task 2", 1000, NULL, 1, &xTask2Handle);
vTaskDelay(xDelay1000ms);
}
}
void vTask2(void * pvParameters)
{
vPrintString("Task2 is running and about to delete itself\n");
vTaskDelete(xTask2Handle);
}
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include "list.h"
#include "supporting_functions.h"
#define mainDELAY_LOOP_COUNT (0xffffff)
void vTaskFunction(void * pvParameters);
const char * pcTextForTask1 = "Task 1 is running\n";
const char * pcTextForTask2 = "Task 2 is running\n";
int main(void)
{
xTaskCreate(vTaskFunction, "Task1", 1000, (void*)pcTextForTask1, 1, NULL);
xTaskCreate(vTaskFunction, "Task2", 1000, (void*)pcTextForTask2, 2, NULL);
vTaskStartScheduler();
for (;;);
return 0;
}
void vTaskFunction(void * pvParameters)
{
char * pcTaskName = (char*)pvParameters;
const TickType_t xDelay250ms = pdMS_TO_TICKS(250UL);
for (;;)
{
vPrintString(pcTaskName);
vTaskDelay(xDelay250ms);
}
}
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include "list.h"
#include "supporting_functions.h"
#define mainDELAY_LOOP_COUNT (0xffffff)
void vTaskFunction(void * pvParameters);
const char * pcTextForTask1 = "Task 1 is running\n";
const char * pcTextForTask2 = "Task 2 is running\n";
int main(void)
{
xTaskCreate(vTaskFunction, "Task1", 1000, (void*)pcTextForTask1, 1, NULL);
xTaskCreate(vTaskFunction, "Task2", 1000, (void*)pcTextForTask2, 2, NULL);
vTaskStartScheduler();
for (;;);
return 0;
}
void vTaskFunction(void * pvParameters)
{
char * pcTaskName = (char*)pvParameters;
const TickType_t xDelay250ms = pdMS_TO_TICKS(250UL);
TickType_t xLastWakeTime = xTaskGetTickCount();
for (;;)
{
vPrintString(pcTaskName);
vTaskDelayUntil(&xLastWakeTime, xDelay250ms);
}
}
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include "list.h"
#include "supporting_functions.h"
static void vSenderTask(void * pvParameters);
static void vReceiverTask(void * pvParameters);
QueueHandle_t xQueue;
typedef enum
{
eSender1,
eSender2
} DataSource_t;
typedef struct
{
uint8_t ucValue;
DataSource_t eDataSource;
} Data_t;
static const Data_t xStructToSend[2] =
{
{100, eSender1},
{200, eSender2}
};
int main()
{
xQueue = xQueueCreate(3, sizeof(Data_t));
if (xQueue != NULL)
{
xTaskCreate(vSenderTask, "Sender1", 1000, (void*)&(xStructToSend[0]), 2, NULL);
xTaskCreate(vSenderTask, "Sender2", 1000, (void*)&(xStructToSend[1]), 2, NULL);
xTaskCreate(vReceiverTask, "Receiver", 1000, NULL, 1, NULL);
vTaskStartScheduler();
}
else
{
}
for (;;);
return 0;
}
static void vSenderTask(void * pvParameters)
{
BaseType_t xStatus;
const TickType_t xTicksToWait = pdMS_TO_TICKS(100UL);
for (;;)
{
xStatus = xQueueSendToBack(xQueue, pvParameters, xTicksToWait);
if (xStatus != pdPASS)
{
vPrintString("Could not send to the queue.\n");
}
}
}
static void vReceiverTask(void * pvParameters)
{
Data_t xReceivedStructure;
BaseType_t xStatus;
for (;;)
{
if (uxQueueMessagesWaiting(xQueue) != 3)
{
vPrintString("Queue should have been full\n");
}
xStatus = xQueueReceive(xQueue, &xReceivedStructure, 0);
if (xStatus == pdPASS)
{
if (xReceivedStructure.eDataSource == eSender1)
{
vPrintStringAndNumber("From Sender 1 = ", xReceivedStructure.ucValue);
}
else
{
vPrintStringAndNumber("From Sender 2 = ", xReceivedStructure.ucValue);
}
}
else
{
vPrintString("Could not receive from the queue.\n");
}
}
}
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include "list.h"
#include "supporting_functions.h"
void vSenderTask1(void *pvParameters);
void vSenderTask2(void *pvParameters);
void vReceiverTask(void *pvParameters);
static QueueHandle_t xQueue1 = NULL;
static QueueHandle_t xQueue2 = NULL;
static QueueSetHandle_t xQueueSet = NULL;
int main()
{
xQueue1 = xQueueCreate(1, sizeof(char*));
xQueue2 = xQueueCreate(1, sizeof(char*));
xQueueSet = xQueueCreateSet(1 * 2);
xQueueAddToSet(xQueue1, xQueueSet);
xQueueAddToSet(xQueue2, xQueueSet);
xTaskCreate(vSenderTask1, "Sender1", 1000, NULL, 1, NULL);
xTaskCreate(vSenderTask1, "Sender2", 1000, NULL, 1, NULL);
xTaskCreate(vReceiverTask, "Receiver", 1000, NULL, 2, NULL);
vTaskStartScheduler();
for (;;);
return 0;
}
void vSenderTask1(void *pvParameters)
{
const TickType_t xBlockTime = pdMS_TO_TICKS(1000);
const char * const pcMessage = "Message from vSenderTask1\n";
for (;;)
{
vTaskDelay(xBlockTime);
xQueueSend(xQueue1, &pcMessage, 0);
}
}
void vSenderTask2(void *pvParameters)
{
const TickType_t xBlockTime = pdMS_TO_TICKS(2000);
const char * const pcMessage = "Message from vSenderTask2\n";
for (;;)
{
vTaskDelay(xBlockTime);
xQueueSend(xQueue2, &pcMessage, 0);
}
}
void vReceiverTask(void *pvParameters)
{
QueueHandle_t xQueueThatContainsData;
char * pcReceivedString;
for (;;)
{
xQueueThatContainsData = (QueueHandle_t)xQueueSelectFromSet(xQueueSet, portMAX_DELAY);
xQueueReceive(xQueueThatContainsData, &pcReceivedString, 0);
vPrintString(pcReceivedString);
}
}
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include "list.h"
#include "supporting_functions.h"
static void vSenderTask(void * pvParameters);
static void vReceiverTask(void * pvParameters);
QueueHandle_t xQueue;
int main()
{
xQueue = xQueueCreate(5, sizeof(int32_t));
if (xQueue != NULL)
{
xTaskCreate(vSenderTask, "Sender1", 1000, (void*)100, 1, NULL);
xTaskCreate(vSenderTask, "Sender2", 1000, (void*)200, 1, NULL);
xTaskCreate(vReceiverTask, "Receiver", 1000, NULL, 2, NULL);
vTaskStartScheduler();
}
else
{
}
for (;;);
return 0;
}
static void vSenderTask(void * pvParameters)
{
int32_t lValueToSend;
BaseType_t xStatus;
lValueToSend = (int32_t)pvParameters;
for (;;)
{
xStatus = xQueueSendToBack(xQueue, &lValueToSend, 0);
if (xStatus != pdPASS)
{
vPrintString("Could not send to the queue.\n");
}
}
}
static void vReceiverTask(void * pvParameters)
{
int32_t lReceivedValue;
BaseType_t xStatus;
const TickType_t xTicksToWait = pdMS_TO_TICKS(100UL);
for (;;)
{
UBaseType_t xItemNum = uxQueueMessagesWaiting(xQueue);
printf("Queue item number = %d\n", xItemNum);
xStatus = xQueueReceive(xQueue, &lReceivedValue, xTicksToWait);
if (xStatus == pdPASS)
{
vPrintStringAndNumber("Received = ", lReceivedValue);
}
else
{
vPrintString("Could not receive from the queue.\n");
}
}
}