Qt Quick Ultralite freertos_app_switch Example

/****************************************************************************** ** ** Copyright (C) 2022 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/qul.h> #include <qul/application.h> #include <platforminterface/log.h> #include "boardutils.h" #include "appswitch.h" #include <FreeRTOS.h> #include <task.h> static void App1_thread(void *argument); static void App2_thread(void *argument); #ifndef QUL_STACK_SIZE #error QUL_STACK_SIZE must be defined. #endif TaskHandle_t QulTask = NULL, LedTask = NULL; #define APP1 1 #define APP2 2 #define N_BLINKS 20 int main() { Qul::initHardware(); Qul::initPlatform(); initLED(); int boot = readBootValue(); Qul::PlatformInterface::log("\r\nBootloader...\tbooting into application #%d\r\n", boot); if (boot != APP2) { Qul::PlatformInterface::log("Application #1...QUL Application Switch\r\n"); if (xTaskCreate(App1_thread, "QulExec", QUL_STACK_SIZE, 0, 4, &QulTask) != pdPASS) { Qul::PlatformInterface::log("Task creation failed!\r\n"); configASSERT(false); } } else { Qul::PlatformInterface::log("Application #2...blinking LED\r\n"); if (xTaskCreate(App2_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 App1_thread(void *argument) { (void) argument; Qul::Application app; static appswitch item; app.setRootItem(&item); app.exec(); } static void App2_thread(void *argument) { (void) argument; displayApp2Background(); //Blink for N_BLINKS times then reboot into App1 for (int i = 0; i < N_BLINKS; ++i) { xTaskNotifyWait(0, ULONG_MAX, NULL, pdMS_TO_TICKS(500)); toggleLED(); taskYIELD(); } reset(APP1); }