1. 任务
BaseType_t xTaskCreatePinnedToCore(
TaskFunction_t pvTaskCode,
const char * constpcName,
const unit32_t usStackDepth,
void *constpvParameters,
UBaseType_t uxPriority,
TaskHandle_t * constpvCreatedTask,
const BaseType_t xCoreID)
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
void task1(void *param)
{
while(1)
{
}
}
void main(void)
{
xTaskCreatePinnedToCore(task1, "test", 2048, NULL, 3, NULL, 0)
}
2. 阻塞
void vTaskDelay(const TickType_t TicksToDelay)
void vTaskDelayUntil(TickType_t *pxPreviousWakeTime,
const TickType_t xTimeIncrement)
vTaskDelay(pdMS_TO_TICKS(100))
cnt = xTaskGetTickCount();
vTaskDelayUntil(&cnt, 100);
3. 队列操作
QueueHandle_t xQueueCreate(
UBaseType_t uxQueueLength,
UBaseType_t uxItemSize)
BaseType_t xQueueSend(
QueueHandle_t xQueue,
const void *pvItemToQueue,
TickType_t xTicksToWait)
BaseType_t xQueueReceive(
QueueHandle_t xQueue,
void *pvBuffer,
TickType_t xTicksToWait)
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/queue.h"
QueueHandle *queue_handle;
typeof struct{} queue_data_t;
void tRecieve(void *param)
{
queue_data_t data;
while(1)
{
if(pd=xQueueReceive(queue_handle, &data, 100)
{}
}
}
void tSend(void *param)
{
queue_data_t data;
memset(*data, 0, sizeof(queue_data_t));
while(1)
{
xQueueSend(queue_handle, &data, 100);
vTaskDelay(pdMS_TO_TICKS(100))
}
}
void main(void)
{
queue_handle = xQueueCreate(10, sizeof(queue_data_t));
xTaskCreatePinnedToCore(tRecieve, "receiveTask", 2048, NULL, 3, NULL, 0)
xTaskCreatePinnedToCore(tSend, "sendTask", 2048, NULL, 3, NULL, 0)
}
4. 信号量(互斥锁)
SemaphoreHandle_t xSemaphoreCreateBinary(void);
SemaphoreHandle_t xSemaphoreCreateCounting(
UBaseType_t uxMaxCount,
UBaseType_t uxInitialCount)
xSemaphoreTake(SemaphoreHandle_t xSemaphore,
TickType_t xTicksToWait)
xSemaphoreGive(SemaphoreHandle_t xSemaphore)
void xSemaphoreDelete(SemaphoreHandle_t xSemaphre)
SemaphoreHandle_t semaphore_handle = xSemaphoreCreateBinary();
xSemaphoreTake(semaphore_handle,portMAX_DELAY);
task()...
xSemaphoreGive(semaphore_handle);