C
将Qt Quick Ultralite移植到实时操作系统(RTOS)
将Qt Quick Ultralite移植到RTOS平台,其步骤与本指南其他章节中介绍的裸机平台类似。以下各节概述了与裸机平台相比的一些差异。
在RTOS平台上,Qt Quick Ultralite应用程序通过调用Qul::Application::exec 作为RTOS任务/线程启动。该调用最终会调用PlatformContext::exec ,该函数将作为该进程的主循环。关于这一点,在“在FreeRTOS 上使用Qt Quick Ultralite”和“在Zephyr 上使用Qt Quick Ultralite”页面中有更详细的说明。
平台移植指南中介绍的所有平台 API 均可进行调整,以使用平台提供的服务或 API。此类调整的一个示例是Qt Quick Ultralite 在FreeRTOS 移植版本中的内存分配API,该 API 可通过操作系统提供的 API 实现。
extern void *pvPortMalloc(size_t xWantedSize); void *qul_malloc(std::size_t size) { return pvPortMalloc(size); }
让出线程
如果您的实时操作系统(RTOS)支持让出操作,则可以让出Qt Quick Ultralite RTOS 线程以释放计算资源。可在以下位置调用让出操作:
- 主循环中的
exec()函数内部void ExamplePlatform::exec() { while (true) { logFlush(); // Flush partially filled log buffer const uint64_t timestamp = this->update(); if (timestamp > Platform::getPlatformInstance()->currentTimestamp()) { // The device may yield or go into sleep mode } } }
- 另一个适合调用让步函数的时机,是在等待显示控制器释放后缓冲区时。
static volatile bool waitingForBufferFlip = false; static uint32_t idleTimeWaitingForDisplay = 0; static void waitForBufferFlip() { // Has there already been a buffer flip? if (!waitingForBufferFlip) return; const uint64_t startTime = getPlatformInstance()->currentTimestamp(); while (waitingForBufferFlip) { // The device may yield or go into sleep mode } idleTimeWaitingForDisplay = getPlatformInstance()->currentTimestamp() - startTime; } // Note: This line clearing waitingForBufferFlip will need to be moved to the // actual interrupt handler for the display available on the target platform. // It's needed to inform about when the buffer address used to scan out pixels // to the display has been updated, making the buffer free in order to start // drawing the next frame. void LCD_BufferFlipInterruptHandler() { waitingForBufferFlip = false; }
如果在下一刷新间隔被调度之前还有足够的时间,也可以进行让步
static void waitForRefreshInterval() { if (refreshCount < requestedRefreshInterval) { uint64_t startTime = getPlatformInstance()->currentTimestamp(); while (refreshCount < requestedRefreshInterval) { // The device may yield or go into sleep mode } idleTimeWaitingForDisplay += getPlatformInstance()->currentTimestamp() - startTime; } refreshCount = 0; }
有关
waitForBufferFlip()和waitForRefreshInterval()的更多信息,请参阅“实现基本图形”一节。 - 如果您的硬件平台支持图层,则可以在
presentFrame()函数中让出控制权。// This function has to replace your PlatformContext::presentFrame FrameStatistics presentFrame(const PlatformInterface::Screen *screen, const PlatformInterface::Rect &rect) { static unsigned int lastFrame = 0xffffffff; while (currentFrame == lastFrame) { // The device may yield or go into sleep mode } lastFrame = currentFrame; PlatformInterface::Rgba32 color = screen->backgroundColor(); // HW_SetScreenBackgroundColor(color.red(), color.blue(), color.green()); // No frame skip compensation implemented for layers return FrameStatistics(); }
有关详细信息,请参阅本节。
FreeRTOS具体细节
要启用 app_commonQUL_OS 框架,请通过 -DQUL_OS=FreeRTOS CMake 命令行选项,或在平台名称中包含 `QUL_OS `:
<platform_name>-freertos
Zephyr- 具体细节
有关如何使用 Zephyr 将Qt Quick Ultralite移植到特定平台的详细信息,请参阅《使用Qt Quick Ultralite与Zephyr 》页面。
在某些 Qt 许可下可用。
了解更多信息。