C

Qt Quick Ultralite freertos_multitask Example

/****************************************************************************** ** ** Copyright (C) 2020 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the Qt Quick Ultralite module. ** ** $QT_BEGIN_LICENSE:COMM$ ** ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms ** and conditions see http://www.qt.io/terms-conditions. For further ** information use the contact form at http://www.qt.io/contact-us. ** ** $QT_END_LICENSE$ ** ******************************************************************************/
#include <qul/application.h> #include <qul/qul.h> #include <platforminterface/log.h> #include <climits> #include <FreeRTOS.h> #include <task.h> #include <board_utils/led.h> #include "freertos_multitask.h" static void Qul_Thread(void *argument); static void Led_Thread(void *argument); #ifndef QUL_STACK_SIZE #error QUL_STACK_SIZE must be defined. #endif TaskHandle_t QulTask = NULL, LedTask = NULL; int main() { Qul::initHardware(); Qul::initPlatform(); BoardUtils::initLED(); if (xTaskCreate(Qul_Thread, "QulExec", QUL_STACK_SIZE, 0, 4, &QulTask) != pdPASS) { Qul::PlatformInterface::log("Task creation failed!.\r\n"); configASSERT(false); } if (xTaskCreate(Led_Thread, "LedToggle", configMINIMAL_STACK_SIZE, 0, 4, &LedTask) != pdPASS) { Qul::PlatformInterface::log("LED task creation failed!.\r\n"); configASSERT(false); } vTaskStartScheduler(); // Should not reach this point configASSERT(false); } static void Qul_Thread(void *argument) { (void) argument; Qul::Application app; static freertos_multitask item; app.setRootItem(&item); app.exec(); } static void Led_Thread(void *argument) { (void) argument; uint32_t speed = 1; uint32_t newSpeed = 0; while (true) { const TickType_t ticks = speed > 0 ? (350 / (portTICK_PERIOD_MS * speed)) : portMAX_DELAY; if (xTaskNotifyWait(0, ULONG_MAX, &newSpeed, ticks) == pdTRUE) { speed = newSpeed; } BoardUtils::toggleLED(); taskYIELD(); } }