diff --git a/config/build.config.host b/config/build.config.host index 06e48f9e3..5b6ec0bda 100644 --- a/config/build.config.host +++ b/config/build.config.host @@ -38,7 +38,7 @@ KBUILD_CXXFLAGS := -DRAPIDJSON_HAS_STDSTRING KBUILD_CFLAGS_KERNEL := -D__OPTIMIZE__ -fdata-sections -ffunction-sections KBUILD_CXXFLAGS_KERNEL := -D__OPTIMIZE__ -DRAPIDJSON_HAS_STDSTRING -fdata-sections -ffunction-sections -KBUILD_CXXFLAGS += -Wall -O2 \ +KBUILD_CXXFLAGS += -Wall -g \ -fno-strict-aliasing \ -fno-common \ -Wno-return-type \ @@ -68,7 +68,7 @@ KBUILD_CXXFLAGS += -Wall -O2 \ -Wno-sizeof-pointer-memaccess \ -Wno-class-conversion -KBUILD_CFLAGS := -Wall -O2 \ +KBUILD_CFLAGS := -Wall -g \ -Wno-trigraphs \ -fno-strict-aliasing -fno-common \ -Wno-format-security \ diff --git a/project/entry/gui_demo/azure/guix/display/xwindow_display_driver.c b/project/entry/gui_demo/azure/guix/display/xwindow_display_driver.c index 067f7e760..24eadfb03 100644 --- a/project/entry/gui_demo/azure/guix/display/xwindow_display_driver.c +++ b/project/entry/gui_demo/azure/guix/display/xwindow_display_driver.c @@ -214,10 +214,8 @@ static void _gx_copy_canvas_to_buffer_24xrgb(char *dest, GX_CANVAS *canvas, GX_R int x, y; int width; int height; - GX_COLOR *put; - GX_COLOR *read; - GX_COLOR *put_row; - GX_COLOR *read_row; + GX_COLOR *put_row, *put_ptr; + GX_COLOR *read_row, *read_ptr; width = canvas->gx_canvas_x_resolution; height = canvas->gx_canvas_y_resolution; @@ -232,10 +230,10 @@ static void _gx_copy_canvas_to_buffer_24xrgb(char *dest, GX_CANVAS *canvas, GX_R read_row += dirty_area->gx_rectangle_top * width + dirty_area->gx_rectangle_left; for (y = dirty_area->gx_rectangle_top; y < dirty_area->gx_rectangle_bottom; y++) { - put = put_row; - read = read_row; + put_ptr = put_row; + read_ptr = read_row; for (x = dirty_area->gx_rectangle_left; x < dirty_area->gx_rectangle_right; x++) { - *put++ = *read++; + *put_ptr++ = *read_ptr++; } put_row += width; @@ -264,13 +262,11 @@ static void _gx_copy_canvas_to_buffer_565rgb(char *dest, GX_CANVAS *canvas, GX_R int x, y; int width; int height; - USHORT *read; GX_UBYTE red; GX_UBYTE blue; - GX_COLOR *put; GX_UBYTE green; - USHORT *read_row; - GX_COLOR *put_row; + USHORT *read_row, *read_ptr; + GX_COLOR *put_row, *put_ptr; width = canvas->gx_canvas_x_resolution; height = canvas->gx_canvas_y_resolution; @@ -285,27 +281,27 @@ static void _gx_copy_canvas_to_buffer_565rgb(char *dest, GX_CANVAS *canvas, GX_R read_row += dirty_area->gx_rectangle_top * width + dirty_area->gx_rectangle_left; for (y = dirty_area->gx_rectangle_top; y < dirty_area->gx_rectangle_bottom; y++) { - put = put_row; - read = read_row; + put_ptr = put_row; + read_ptr = read_row; for (x = dirty_area->gx_rectangle_left; x < dirty_area->gx_rectangle_right; x++) { - red = REDVAL_16BPP(*read) << 3; + red = REDVAL_16BPP(*read_ptr) << 3; if (red & 0x08) { red |= 0x07; } - green = GREENVAL_16BPP(*read) << 2; + green = GREENVAL_16BPP(*read_ptr) << 2; if (green & 0x04) { green |= 0x03; } - blue = BLUEVAL_16BPP(*read) << 3; + blue = BLUEVAL_16BPP(*read_ptr) << 3; if (blue & 0x08) { blue |= 0x07; } - *put++ = ASSEMBLECOLOR_32BPP(red, green, blue); - read++; + *put_ptr++ = ASSEMBLECOLOR_32BPP(red, green, blue); + read_ptr++; } put_row += width; @@ -318,13 +314,11 @@ static void _gx_copy_canvas_to_buffer_1555xrgb(char *dest, GX_CANVAS *canvas, GX int x, y; int width; int height; - USHORT *read; GX_UBYTE red; - GX_COLOR *put; GX_UBYTE blue; GX_UBYTE green; - USHORT *read_row; - GX_COLOR *put_row; + USHORT *read_row, *read_ptr; + GX_COLOR *put_row, *put_ptr; width = canvas->gx_canvas_x_resolution; height = canvas->gx_canvas_y_resolution; @@ -339,27 +333,27 @@ static void _gx_copy_canvas_to_buffer_1555xrgb(char *dest, GX_CANVAS *canvas, GX read_row += dirty_area->gx_rectangle_top * width + dirty_area->gx_rectangle_left; for (y = dirty_area->gx_rectangle_top; y < dirty_area->gx_rectangle_bottom; y++) { - put = put_row; - read = read_row; + put_ptr = put_row; + read_ptr = read_row; for (x = dirty_area->gx_rectangle_left; x < dirty_area->gx_rectangle_right; x++) { - red = ((*read) & 0x7c00) >> 7; + red = ((*read_ptr) & 0x7c00) >> 7; if (red & 0x08) { red |= 0x07; } - green = ((*read) & 0x03e0) >> 2; + green = ((*read_ptr) & 0x03e0) >> 2; if (green & 0x08) { green |= 0x03; } - blue = ((*read) & 0x1f) << 3; + blue = ((*read_ptr) & 0x1f) << 3; if (blue & 0x08) { blue |= 0x07; } - *put++ = ASSEMBLECOLOR_32BPP(red, green, blue); - read++; + *put_ptr++ = ASSEMBLECOLOR_32BPP(red, green, blue); + read_ptr++; } put_row += width; @@ -372,13 +366,11 @@ static void _gx_copy_canvas_to_buffer_4444argb(char *dest, GX_CANVAS *canvas, GX int x, y; int width; int height; - USHORT *read; GX_UBYTE red; - GX_COLOR *put; GX_UBYTE blue; GX_UBYTE green; - USHORT *read_row; - GX_COLOR *put_row; + USHORT *read_row, *read_ptr; + GX_COLOR *put_row, *put_ptr; width = canvas->gx_canvas_x_resolution; height = canvas->gx_canvas_y_resolution; @@ -393,21 +385,21 @@ static void _gx_copy_canvas_to_buffer_4444argb(char *dest, GX_CANVAS *canvas, GX read_row += dirty_area->gx_rectangle_top * width + dirty_area->gx_rectangle_left; for (y = dirty_area->gx_rectangle_top; y < dirty_area->gx_rectangle_bottom; y++) { - put = put_row; - read = read_row; + put_ptr = put_row; + read_ptr = read_row; for (x = dirty_area->gx_rectangle_left; x < dirty_area->gx_rectangle_right; x++) { - red = ((*read) & 0x0f00) >> 4; + red = ((*read_ptr) & 0x0f00) >> 4; red |= red >> 4; - green = (*read) & 0xf0; + green = (*read_ptr) & 0xf0; green |= green >> 4; - blue = ((*read) & 0x0f); + blue = ((*read_ptr) & 0x0f); blue |= blue << 4; - *put++ = ASSEMBLECOLOR_32BPP(red, green, blue); - read++; + *put_ptr++ = ASSEMBLECOLOR_32BPP(red, green, blue); + read_ptr++; } put_row += width; @@ -421,12 +413,10 @@ static void _gx_copy_canvas_to_buffer_332rgb(char *dest, GX_CANVAS *canvas, GX_R int width; int height; GX_UBYTE red; - GX_COLOR *put; GX_UBYTE blue; - GX_UBYTE *read; GX_UBYTE green; - GX_COLOR *put_row; - GX_UBYTE *read_row; + GX_COLOR *put_row, *put_ptr; + GX_UBYTE *read_row, *read_ptr; width = canvas->gx_canvas_x_resolution; height = canvas->gx_canvas_y_resolution; @@ -441,27 +431,27 @@ static void _gx_copy_canvas_to_buffer_332rgb(char *dest, GX_CANVAS *canvas, GX_R read_row += dirty_area->gx_rectangle_top * width + dirty_area->gx_rectangle_left; for (y = dirty_area->gx_rectangle_top; y < dirty_area->gx_rectangle_bottom; y++) { - put = put_row; - read = read_row; + put_ptr = put_row; + read_ptr = read_row; for (x = dirty_area->gx_rectangle_left; x < dirty_area->gx_rectangle_right; x++) { - red = (*read) & 0xe0; + red = (*read_ptr) & 0xe0; if (red & 0x20) { red |= 0x1f; } - green = ((*read) & 0x1c) << 3; + green = ((*read_ptr) & 0x1c) << 3; if (green & 0x20) { green |= 0x1f; } - blue = ((*read) & 0x03) << 6; + blue = ((*read_ptr) & 0x03) << 6; if (blue & 0x40) { blue |= 0x3f; } - *put++ = ASSEMBLECOLOR_32BPP(red, green, blue); - read++; + *put_ptr++ = ASSEMBLECOLOR_32BPP(red, green, blue); + read_ptr++; } put_row += width; @@ -474,11 +464,9 @@ static void _gx_copy_canvas_to_buffer_8bit_palette(char *dest, GX_CANVAS *canvas int x, y; int width; int height; - GX_COLOR *put; - GX_UBYTE *read; - GX_COLOR *put_row; - GX_UBYTE *read_row; GX_COLOR *palette_table; + GX_COLOR *put_row, *put_ptr; + GX_UBYTE *read_row, *read_ptr; width = canvas->gx_canvas_x_resolution; height = canvas->gx_canvas_y_resolution; @@ -494,11 +482,11 @@ static void _gx_copy_canvas_to_buffer_8bit_palette(char *dest, GX_CANVAS *canvas read_row += dirty_area->gx_rectangle_top * width + dirty_area->gx_rectangle_left; for (y = dirty_area->gx_rectangle_top; y < dirty_area->gx_rectangle_bottom; y++) { - put = put_row; - read = read_row; + put_ptr = put_row; + read_ptr = read_row; for (x = dirty_area->gx_rectangle_left; x < dirty_area->gx_rectangle_right; x++) { - *put++ = palette_table[*read++]; + *put_ptr++ = palette_table[*read_ptr++]; } put_row += width; @@ -511,12 +499,10 @@ static void _gx_copy_canvas_to_buffer_4bit_grayscale(char *dest, GX_CANVAS *canv int x, y; int width; int height; - GX_COLOR *put; - GX_UBYTE *read; - GX_COLOR *put_row; - GX_UBYTE *read_row; GX_UBYTE read_mask; GX_UBYTE read_pixel; + GX_COLOR *put_row, *put_ptr; + GX_UBYTE *read_row, *read_ptr; width = canvas->gx_canvas_x_resolution; height = canvas->gx_canvas_y_resolution; @@ -532,8 +518,8 @@ static void _gx_copy_canvas_to_buffer_4bit_grayscale(char *dest, GX_CANVAS *canv read_row += (dirty_area->gx_rectangle_left + 1 )>> 1; for (y = dirty_area->gx_rectangle_top; y < dirty_area->gx_rectangle_bottom; y++) { - put = put_row; - read = read_row; + put_ptr = put_row; + read_ptr = read_row; if (dirty_area->gx_rectangle_left & 1) { read_mask = 0x0f; @@ -542,7 +528,7 @@ static void _gx_copy_canvas_to_buffer_4bit_grayscale(char *dest, GX_CANVAS *canv } for (x = dirty_area->gx_rectangle_left; x < dirty_area->gx_rectangle_right; x++) { - read_pixel = read_mask & (*read); + read_pixel = read_mask & (*read_ptr); if (read_mask == 0xf0) { read_pixel |= read_pixel >> 4; @@ -550,10 +536,10 @@ static void _gx_copy_canvas_to_buffer_4bit_grayscale(char *dest, GX_CANVAS *canv } else { read_pixel |= read_pixel << 4; read_mask = 0xf0; - read++; + read_ptr++; } - *put++ = read_pixel | (read_pixel << 8) | (read_pixel << 16) | 0xff000000; + *put_ptr++ = read_pixel | (read_pixel << 8) | (read_pixel << 16) | 0xff000000; } put_row += width; @@ -566,11 +552,9 @@ static void _gx_copy_canvas_to_buffer_monochrome(char *dest, GX_CANVAS *canvas, int x, y; int width; int height; - GX_COLOR *put; - GX_UBYTE *read; - GX_COLOR *put_row; - GX_UBYTE *read_row; GX_UBYTE read_mask; + GX_COLOR *put_row, *put_ptr; + GX_UBYTE *read_row, *read_ptr; width = canvas->gx_canvas_x_resolution; height = canvas->gx_canvas_y_resolution; @@ -586,22 +570,22 @@ static void _gx_copy_canvas_to_buffer_monochrome(char *dest, GX_CANVAS *canvas, read_row += (dirty_area->gx_rectangle_left + 7) >> 3; for (y = dirty_area->gx_rectangle_top; y < dirty_area->gx_rectangle_bottom; y++) { - put = put_row; - read = read_row; + put_ptr = put_row; + read_ptr = read_row; read_mask = 0x80 >> (dirty_area->gx_rectangle_left & 0x07); for (x = dirty_area->gx_rectangle_left; x < dirty_area->gx_rectangle_right; x++) { - if (read_mask & (*read)) { - *put++ = 0xffffffff; + if (read_mask & (*read_ptr)) { + *put_ptr++ = 0xffffffff; } else { - *put++ = 0; + *put_ptr++ = 0; } read_mask >>= 1; if (read_mask == 0) { read_mask = 0x80; - read++; + read_ptr++; } } diff --git a/project/gui/azure/threadx/linux_gnu/tx_initialize_low_level.c b/project/gui/azure/threadx/linux_gnu/tx_initialize_low_level.c index 244a5fc6f..d4311b3ba 100644 --- a/project/gui/azure/threadx/linux_gnu/tx_initialize_low_level.c +++ b/project/gui/azure/threadx/linux_gnu/tx_initialize_low_level.c @@ -19,11 +19,14 @@ /** */ /**************************************************************************/ /**************************************************************************/ - +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif #define TX_SOURCE_CODE #define TX_THREAD_SMP_SOURCE_CODE - +#define TX_LINUX_MULTI_CORE +#define TX_LINUX_DEBUG_ENABLE /* Include necessary system files. */ @@ -33,7 +36,7 @@ #include #include #include - +#include /* Define various Linux objects used by the ThreadX port. */ @@ -230,6 +233,9 @@ extern VOID *_tx_initialize_unused_memory; /* 09-30-2020 William E. Lamie Initial Version 6.1 */ /* */ /**************************************************************************/ +static void *_tx_linux_thread_resume_handler_thread(void *arg); +static void *_tx_linux_thread_suspend_handler_thread(void *arg); + VOID _tx_initialize_low_level(VOID) { UINT i; @@ -294,8 +300,10 @@ cpu_set_t mask; /* Create semaphore for ISR thread. */ sem_init(&_tx_linux_isr_semaphore, 0, 0); + printf("create _tx_linux_timer_interrupt thread\n"); + /* Setup periodic timer interrupt. */ - if(pthread_create(&_tx_linux_timer_id, NULL, _tx_linux_timer_interrupt, /*(void *)&_tx_linux_timer_id*/NULL)) + if(pthread_create(&_tx_linux_timer_id, NULL, _tx_linux_timer_interrupt, (void *)&_tx_linux_timer_id/*NULL*/)) { /* Error creating the timer interrupt. */ @@ -312,21 +320,82 @@ cpu_set_t mask; pthread_setschedparam(_tx_linux_timer_id, SCHED_FIFO, &sp); /* Done, return to caller. */ + // pthread_t resumeThreadId, suspendThreadId; + // pthread_create(&resumeThreadId, NULL, _tx_linux_thread_resume_handler_thread, NULL); + // pthread_create(&suspendThreadId, NULL, _tx_linux_thread_suspend_handler_thread, NULL); } - +static int g_enterTimerInterrupt = 0; /* This routine is called after initialization is complete in order to start all interrupt threads. Interrupt threads in addition to the timer may be added to this routine as well. */ void _tx_initialize_start_interrupts(void) { - + g_enterTimerInterrupt = 1; /* Kick the timer thread off to generate the ThreadX periodic interrupt source. */ tx_linux_sem_post(&_tx_linux_timer_semaphore); } +// 获取自系统启动的单调递增时间 +unsigned long get_time_conv_seconds(struct timespec *curTime, unsigned int factor) +{ + clock_gettime(CLOCK_MONOTONIC, curTime); + return (unsigned long)(curTime->tv_sec) * factor; +} + +// 获取自系统启动的单例递增时间 -- 转换为微妙 +unsigned long get_monnotonic_time(void) +{ + struct timespec curTime; + unsigned long result = get_time_conv_seconds(&curTime, 1000000); + result += (unsigned int)(curTime.tv_nsec) / 1000; + + return result; +} + +#undef MIN +#define MIN(x, y) (x < y ? x : y) + +// sem_trywait + usleep方式实现延时。如果信号量大于0,则减少信号量并立即返回1;如果信号量小于0,则阻塞等待,当阻塞超时时返回0 +int wait_timeout(sem_t *sem, long timeoutUs) +{ + unsigned long delayUs = 0; + unsigned long timeWait = 1; + unsigned long elapsedUs = 0; + const unsigned long maxTimeWait = 10000; + const unsigned long startUs = get_monnotonic_time(); + + do { + // 如果信号量大于0,则减少信号量并立即返回1 + if (sem_trywait(sem) == 0) { + return 1; + } + + // 系统信号则立即返回0 + if (errno != EAGAIN) { + return 0; + } + + delayUs = timeoutUs - elapsedUs; + timeWait = MIN(delayUs, timeWait); + + int ret = usleep(timeWait); + if (ret != 0) { + return 0; + } + + timeWait *= 2; + timeWait = MIN(timeWait, maxTimeWait); + + // 开始计算时间到现在的运行时间 + elapsedUs = get_monnotonic_time() - startUs; + } while (elapsedUs < timeoutUs); + + return 0; +} + /* Define the ThreadX system timer interrupt. Other interrupts may be simulated in a similar way. */ @@ -345,10 +414,12 @@ int err; /* Wait startup semaphore. */ tx_linux_sem_wait(&_tx_linux_timer_semaphore); + // do { + // usleep(1); + // } while (g_enterTimerInterrupt == 0); while(1) { - clock_gettime(CLOCK_REALTIME, &ts); ts.tv_nsec += timer_periodic_nsec; if (ts.tv_nsec > 1000000000) @@ -356,6 +427,8 @@ int err; ts.tv_nsec -= 1000000000; ts.tv_sec++; } + + // printf("======%d\n", wait_timeout(&_tx_linux_timer_semaphore, (ts.tv_sec * 1000000 + ts.tv_nsec / 1000))); do { if (sem_timedwait(&_tx_linux_timer_semaphore, &ts) == 0) @@ -376,6 +449,47 @@ int err; } } +// void *_tx_linux_thread_resume_handler_thread(void *arg) +// { +// while (1) { +// usleep(10000); +// } + +// return NULL; +// } + +// static int g_startSuspend = 0; +// static pthread_t g_suspend_threadId; + +// void *_tx_linux_thread_suspend_handler_thread(void *arg) +// { +// while (1) { +// if (g_startSuspend != 0) { +// g_startSuspend = 0; +// printf("g_suspend_threadId:[%lu], _tx_linux_timer_id:[%lu]", g_suspend_threadId, _tx_linux_timer_id); +// if(pthread_equal(g_suspend_threadId, _tx_linux_timer_id)) +// tx_linux_sem_post(&_tx_linux_thread_timer_wait); +// else +// tx_linux_sem_post(&_tx_linux_thread_other_wait); + +// if(_tx_linux_thread_suspended) { +// printf("111111111111111111111111111\n"); +// continue; +// } + +// _tx_linux_thread_suspended = 1; +// sigsuspend(&_tx_linux_thread_wait_mask); +// _tx_linux_thread_suspended = 0; +// } else { +// usleep(1000); +// } + +// printf("=======================\n"); +// } + +// return NULL; +// } + /* Define functions for linux thread. */ void _tx_linux_thread_resume_handler(int sig) { @@ -402,6 +516,8 @@ void _tx_linux_thread_suspend(pthread_t thread_id) /* Send signal. */ _tx_linux_mutex_obtain(&_tx_linux_mutex); pthread_kill(thread_id, SUSPEND_SIG); + // g_startSuspend = 1; + // g_suspend_threadId = thread_id; _tx_linux_mutex_release(&_tx_linux_mutex); /* Wait until signal is received. */ diff --git a/project/gui/azure/threadx/linux_gnu/tx_thread_schedule.c b/project/gui/azure/threadx/linux_gnu/tx_thread_schedule.c index 4e518c630..d7f905509 100644 --- a/project/gui/azure/threadx/linux_gnu/tx_thread_schedule.c +++ b/project/gui/azure/threadx/linux_gnu/tx_thread_schedule.c @@ -351,6 +351,7 @@ UINT i; /* Get the Linux mutex. */ pthread_mutex_lock(&mutex -> tx_linux_mutex); + //pthread_mutex_trylock(&mutex -> tx_linux_mutex); /* At this point we have the mutex. */ diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 0f5a95acf..35baf5b6d 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -31,7 +31,7 @@ subdir-ccflags-y := subdir-cxxflags-y := ifeq ($(USE_STDCPP_VERSION),) -BUILD_STDCPP_VERSION ?= -std=c++11 +BUILD_STDCPP_VERSION ?= -std=gnu++11 else BUILD_STDCPP_VERSION ?= $(USE_STDCPP_VERSION) endif