You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
250 lines
6.3 KiB
250 lines
6.3 KiB
/*
|
|
* FreeRTOS示例测试文件
|
|
* 用于测试LLM生成的FreeRTOS特定验证规范
|
|
*/
|
|
|
|
#include "FreeRTOS.h"
|
|
#include "task.h"
|
|
#include "queue.h"
|
|
#include "semphr.h"
|
|
#include "event_groups.h"
|
|
|
|
// FreeRTOS任务函数示例
|
|
void vTaskFunction(void *pvParameters) {
|
|
int *param_value = (int*)pvParameters;
|
|
|
|
for (;;) {
|
|
if (param_value != NULL) {
|
|
(*param_value)++;
|
|
}
|
|
|
|
vTaskDelay(pdMS_TO_TICKS(1000));
|
|
}
|
|
}
|
|
|
|
// FreeRTOS队列操作函数
|
|
BaseType_t send_to_queue(QueueHandle_t xQueue, const void *pvItemToQueue, TickType_t xTicksToWait) {
|
|
if (xQueue == NULL || pvItemToQueue == NULL) {
|
|
return pdFAIL;
|
|
}
|
|
|
|
return xQueueSend(xQueue, pvItemToQueue, xTicksToWait);
|
|
}
|
|
|
|
// FreeRTOS队列接收函数
|
|
BaseType_t receive_from_queue(QueueHandle_t xQueue, void *pvBuffer, TickType_t xTicksToWait) {
|
|
if (xQueue == NULL || pvBuffer == NULL) {
|
|
return pdFAIL;
|
|
}
|
|
|
|
return xQueueReceive(xQueue, pvBuffer, xTicksToWait);
|
|
}
|
|
|
|
// FreeRTOS二进制信号量创建函数
|
|
SemaphoreHandle_t create_binary_semaphore(void) {
|
|
SemaphoreHandle_t xSemaphore = xSemaphoreCreateBinary();
|
|
return xSemaphore;
|
|
}
|
|
|
|
// FreeRTOS互斥量创建函数
|
|
SemaphoreHandle_t create_mutex(void) {
|
|
SemaphoreHandle_t xMutex = xSemaphoreCreateMutex();
|
|
return xMutex;
|
|
}
|
|
|
|
// FreeRTOS信号量获取函数
|
|
BaseType_t take_semaphore(SemaphoreHandle_t xSemaphore, TickType_t xTicksToWait) {
|
|
if (xSemaphore == NULL) {
|
|
return pdFAIL;
|
|
}
|
|
|
|
return xSemaphoreTake(xSemaphore, xTicksToWait);
|
|
}
|
|
|
|
// FreeRTOS信号量释放函数
|
|
BaseType_t give_semaphore(SemaphoreHandle_t xSemaphore) {
|
|
if (xSemaphore == NULL) {
|
|
return pdFAIL;
|
|
}
|
|
|
|
return xSemaphoreGive(xSemaphore);
|
|
}
|
|
|
|
// FreeRTOS任务创建函数
|
|
TaskHandle_t create_task(TaskFunction_t pvTaskCode, const char * const pcName, uint32_t usStackDepth, void *pvParameters, UBaseType_t uxPriority, TaskHandle_t *pxCreatedTask) {
|
|
if (pvTaskCode == NULL || pcName == NULL) {
|
|
return NULL;
|
|
}
|
|
|
|
BaseType_t xResult = xTaskCreate(
|
|
pvTaskCode,
|
|
pcName,
|
|
usStackDepth,
|
|
pvParameters,
|
|
uxPriority,
|
|
pxCreatedTask
|
|
);
|
|
|
|
return (xResult == pdPASS) ? (pxCreatedTask ? *pxCreatedTask : NULL) : NULL;
|
|
}
|
|
|
|
// FreeRTOS任务删除函数
|
|
void delete_task(TaskHandle_t xTask) {
|
|
vTaskDelete(xTask);
|
|
}
|
|
|
|
// FreeRTOS任务挂起函数
|
|
void suspend_task(TaskHandle_t xTask) {
|
|
vTaskSuspend(xTask);
|
|
}
|
|
|
|
// FreeRTOS任务恢复函数
|
|
void resume_task(TaskHandle_t xTask) {
|
|
vTaskResume(xTask);
|
|
}
|
|
|
|
// FreeRTOS事件组创建函数
|
|
EventGroupHandle_t create_event_group(void) {
|
|
return xEventGroupCreate();
|
|
}
|
|
|
|
// FreeRTOS事件组设置位函数
|
|
EventBits_t set_event_bits(EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet) {
|
|
if (xEventGroup == NULL) {
|
|
return 0;
|
|
}
|
|
|
|
return xEventGroupSetBits(xEventGroup, uxBitsToSet);
|
|
}
|
|
|
|
// FreeRTOS事件组清除位函数
|
|
EventBits_t clear_event_bits(EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToClear) {
|
|
if (xEventGroup == NULL) {
|
|
return 0;
|
|
}
|
|
|
|
return xEventGroupClearBits(xEventGroup, uxBitsToClear);
|
|
}
|
|
|
|
// FreeRTOS事件组等待位函数
|
|
EventBits_t wait_for_event_bits(EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToWaitFor, BaseType_t xClearOnExit, BaseType_t xWaitForAllBits, TickType_t xTicksToWait) {
|
|
if (xEventGroup == NULL) {
|
|
return 0;
|
|
}
|
|
|
|
return xEventGroupWaitBits(
|
|
xEventGroup,
|
|
uxBitsToWaitFor,
|
|
xClearOnExit,
|
|
xWaitForAllBits,
|
|
xTicksToWait
|
|
);
|
|
}
|
|
|
|
// FreeRTOS队列查询函数
|
|
UBaseType_t get_queue_messages_waiting(QueueHandle_t xQueue) {
|
|
if (xQueue == NULL) {
|
|
return 0;
|
|
}
|
|
|
|
return uxQueueMessagesWaiting(xQueue);
|
|
}
|
|
|
|
// FreeRTOS队列空间查询函数
|
|
UBaseType_t get_queue_spaces_available(QueueHandle_t xQueue) {
|
|
if (xQueue == NULL) {
|
|
return 0;
|
|
}
|
|
|
|
return uxQueueSpacesAvailable(xQueue);
|
|
}
|
|
|
|
// FreeRTOS任务状态查询函数
|
|
eTaskState get_task_state(TaskHandle_t xTask) {
|
|
if (xTask == NULL) {
|
|
return eInvalid;
|
|
}
|
|
|
|
return eTaskGetState(xTask);
|
|
}
|
|
|
|
// FreeRTOS任务优先级设置函数
|
|
void set_task_priority(TaskHandle_t xTask, UBaseType_t uxNewPriority) {
|
|
if (xTask == NULL) {
|
|
return;
|
|
}
|
|
|
|
vTaskPrioritySet(xTask, uxNewPriority);
|
|
}
|
|
|
|
// FreeRTOS任务优先级获取函数
|
|
UBaseType_t get_task_priority(TaskHandle_t xTask) {
|
|
if (xTask == NULL) {
|
|
return 0;
|
|
}
|
|
|
|
return uxTaskPriorityGet(xTask);
|
|
}
|
|
|
|
// FreeRTOS任务通知发送函数
|
|
BaseType_t notify_task(TaskHandle_t xTask, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotificationValue) {
|
|
if (xTask == NULL) {
|
|
return pdFAIL;
|
|
}
|
|
|
|
return xTaskNotify(xTask, ulValue, eAction);
|
|
}
|
|
|
|
// FreeRTOS任务通知等待函数
|
|
BaseType_t wait_for_notification(uint32_t *pulNotificationValue, uint32_t ulBitsToClearOnEntry, uint32_t ulBitsToClearOnExit, TickType_t xTicksToWait) {
|
|
if (pulNotificationValue == NULL) {
|
|
return pdFAIL;
|
|
}
|
|
|
|
return xTaskNotifyWait(ulBitsToClearOnEntry, ulBitsToClearOnExit, pulNotificationValue, xTicksToWait);
|
|
}
|
|
|
|
// FreeRTOS软件定时器回调函数类型定义
|
|
typedef void (*TimerCallbackFunction_t)(TimerHandle_t xTimer);
|
|
|
|
// FreeRTOS软件定时器创建函数
|
|
TimerHandle_t create_timer(const char * const pcTimerName, const TickType_t xTimerPeriodInTicks, const UBaseType_t uxAutoReload, void * const pvTimerID, TimerCallbackFunction_t pxCallbackFunction) {
|
|
if (pcTimerName == NULL || pxCallbackFunction == NULL) {
|
|
return NULL;
|
|
}
|
|
|
|
return xTimerCreate(
|
|
pcTimerName,
|
|
xTimerPeriodInTicks,
|
|
uxAutoReload,
|
|
pvTimerID,
|
|
pxCallbackFunction
|
|
);
|
|
}
|
|
|
|
// FreeRTOS软件定时器启动函数
|
|
BaseType_t start_timer(TimerHandle_t xTimer, const TickType_t xTicksToWait) {
|
|
if (xTimer == NULL) {
|
|
return pdFAIL;
|
|
}
|
|
|
|
return xTimerStart(xTimer, xTicksToWait);
|
|
}
|
|
|
|
// FreeRTOS软件定时器停止函数
|
|
BaseType_t stop_timer(TimerHandle_t xTimer, const TickType_t xTicksToWait) {
|
|
if (xTimer == NULL) {
|
|
return pdFAIL;
|
|
}
|
|
|
|
return xTimerStop(xTimer, xTicksToWait);
|
|
}
|
|
|
|
// FreeRTOS软件定时器删除函数
|
|
BaseType_t delete_timer(TimerHandle_t xTimer, const TickType_t xTicksToWait) {
|
|
if (xTimer == NULL) {
|
|
return pdFAIL;
|
|
}
|
|
|
|
return xTimerDelete(xTimer, xTicksToWait);
|
|
} |