不知道你们初学RTOS的时候,是不是也有这样的疑问:MCU裸机应用程序如何迁移到RTOS实时操作系统中?
裸机代码迁移说明
迁移案例说明
uint8_t sensorData[2];
int main(void)
{
while(1)
{
LED_TOGGLE(); //LED亮灭
ReadSensor(&sensorData); //读取传感器数据并显示
DisplayData(&sensorData);
UARTSend(&sensorData); //发送数据
Delay(100);
}
}
xTaskCreate(Task1_LED, "Task1_LED", STACK1_LED, NULL, STASK1_LED, NULL);
xTaskCreate(Task2_READSENSOR, "Task2_READSENSOR", STACK2_READSENSOR, NULL, STASK2_READSENSOR, NULL);
xTaskCreate(Task3_SEND, "Task3_SEND", STACK3_SEND, NULL, STASK3_SEND, NULL);
QueueHandle_t xSENSORSendQueue = NULL;
xSENSORSendQueue = xQueueCreate(SENSORSEND_QUEUE_LEN, SENSORSEND_QUEUE_SIZE);
void Task1_LED(void *pvParameters)
{
for(;;)
{
LED_TOGGLE();
vTaskDelay(500);
}
}
void Task2_READSENSOR(void *pvParameters)
{
for(;;)
{
ReadSensor(&sensorData);
DisplayData(&sensorData);
xQueueSend(xSENSORSendQueue , &sensorData, 100)
vTaskDelay(100);
}
}
static uint8_t sensorData[2];
void Task3_SEND(void *pvParameters)
{
for(;;)
{
if(xQueueReceive(xSENSORSendQueue, &sensorData, 100) == pdTRUE)
{
UARTSend(&sensorData);
}
vTaskDelay(10);
}
}
推荐阅读
【关注】查看往期精彩
▼
👇