79 lines
1.8 KiB
C
79 lines
1.8 KiB
C
#ifndef OS_SAMPLE_H
|
|
#define OS_SAMPLE_H
|
|
|
|
#include <stdint.h>
|
|
#include <stddef.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#ifdef _WIN32
|
|
#ifndef WIN32_LEAN_AND_MEAN
|
|
#define WIN32_LEAN_AND_MEAN // 阻止 windows.h 包含旧版 winsock.h
|
|
#endif
|
|
#include <semaphore.h>
|
|
#include <windows.h>
|
|
#elif defined(__linux__)
|
|
#include <unistd.h>
|
|
#include <time.h>
|
|
#include <pthread.h>
|
|
#endif
|
|
|
|
/**
|
|
* @brief 状态返回码枚举
|
|
*/
|
|
typedef enum {
|
|
#ifndef ERROR
|
|
ERROR = 0,
|
|
#endif
|
|
#ifndef SUCCESS
|
|
SUCCESS = 1
|
|
#endif
|
|
} Status;
|
|
|
|
// 常用公共宏定义
|
|
#define ENABLE 1
|
|
#define DISABLE 0
|
|
|
|
/* 时间常数定义 */
|
|
#define portMAX_DELAY (TickType_t)0xFFFFFFFFUL
|
|
|
|
/* FreeRTOS 基础类型模拟 */
|
|
typedef int32_t BaseType_t;
|
|
typedef uint32_t TickType_t;
|
|
typedef uint32_t UBaseType_t;
|
|
typedef void* TaskHandle_t;
|
|
typedef void* QueueHandle_t;
|
|
|
|
#define pdTRUE 1
|
|
#define pdFALSE 0
|
|
#define pdPASS 1
|
|
#define pdFAIL 0
|
|
#define errQUEUE_FULL 0 // 或者根据你现有的定义调整
|
|
|
|
/* 任务函数指针定义 */
|
|
typedef void (*TaskFunction_t)(void *);
|
|
|
|
/* --- 严格一致的接口声明 --- */
|
|
|
|
// 延时 (ms)
|
|
void vTaskDelay(const TickType_t xTicksToDelay);
|
|
|
|
// 创建任务
|
|
BaseType_t xTaskCreate(
|
|
TaskFunction_t pvTaskCode,
|
|
const char * const pcName,
|
|
const uint16_t usStackDepth,
|
|
void * const pvParameters,
|
|
UBaseType_t uxPriority,
|
|
TaskHandle_t * const pxCreatedTask
|
|
);
|
|
|
|
void vTaskStartScheduler(void);
|
|
|
|
// 队列操作
|
|
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 * const pvBuffer, TickType_t xTicksToWait);
|
|
|
|
#endif |