Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(nxp/pxp): add Zephyr Support #6298

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Conversation

faxe1008
Copy link
Contributor

Description of the feature or fix

Reopening of #6159 since it got merged and reverted the original PR does not track changes anymore (@nicusorcitu ).

Notes

@nicusorcitu
Copy link
Contributor

@cristian-stoica

@FASTSHIFT FASTSHIFT changed the title PXP Zephyr Support feat(nxp/pxp): add Zephyr Support May 30, 2024
#include "FreeRTOS.h"
#include "semphr.h"

#if defined(__ZEPHYR__)
Copy link
Contributor

@nicusorcitu nicusorcitu May 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those should not be included - they will get over lv_os.h inclusion

NVIC_SetPriority(PXP_IRQ_ID, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY + 1);
NVIC_EnableIRQ(PXP_IRQ_ID);
#elif defined(__ZEPHYR__)
IRQ_CONNECT(DT_IRQN(DT_NODELABEL(pxp)), CONFIG_LV_Z_PXP_INTERRUPT_PRIORITY, PXP_ZephyrIRQHandler, NULL, 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand now, you included the ZEPHYR header just for this CONFIG_LV_Z_PXP_INTERRUPT_PRIORITY.

We should not mix any longer this with lv_osal support.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The includes are needed for the entire interrupt logic (retrieving nodes from DT, hooking up the IRQ).

@cristian-stoica
Copy link
Contributor

cristian-stoica commented Jun 10, 2024


-#if defined(SDK_OS_FREE_RTOS)
-    #include "FreeRTOS.h"
-    #include "semphr.h"
+
+#if defined(__ZEPHYR__)
+    #include <zephyr/kernel.h>
+    #include <zephyr/irq.h>
#endif

I have a problem with the code above. It is not exactly OSAL as it claims and it also breaks our build. There has to be a better way

@faxe1008
Copy link
Contributor Author


-#if defined(SDK_OS_FREE_RTOS)
-    #include "FreeRTOS.h"
-    #include "semphr.h"
+
+#if defined(__ZEPHYR__)
+    #include <zephyr/kernel.h>
+    #include <zephyr/irq.h>
#endif

I have a problem with the code above. It is not exactly OSAL as it claims and it also breaks our build. There has to be a better way

Yeah, these includes are needed for the interrupts. Personally I think that an OSAL is maybe not the right place for an abstraction for this, the OSAL should be kept as thin as possible. Maybe it would be an option somehow provide the user a way to give LVGL a setup and teardown method for any of the drawing engines so that this can be handled by each OS?

Add semaphore and connect IRQ.
Originally proposed by @0xFarahFl.
@faxe1008 faxe1008 force-pushed the pxp_zephyr branch 2 times, most recently from e339205 to cb4c167 Compare June 17, 2024 14:15
src/osal/lv_freertos.c Outdated Show resolved Hide resolved
src/osal/lv_freertos.c Outdated Show resolved Hide resolved
@kisvegabor
Copy link
Member

kisvegabor commented Jun 21, 2024

We got a lot request about updating Zephyr to LVGL v9 so I wonder if we can help to make it happen soon. @becseya is interested in Zephyr, so he can help with LVGL related issues. We also have several NXP boards so we can help with PXP as well.

@faxe1008 faxe1008 force-pushed the pxp_zephyr branch 2 times, most recently from 0f12024 to 083a95b Compare June 21, 2024 06:48
@kisvegabor
Copy link
Member

155 | lv_result_t lv_thread_sync_signal_isr(lv_thread_sync_t * sync)

Please add LV_UNUSED(sync);

@faxe1008
Copy link
Contributor Author

The function var had to be renamed to pxCond :^)

@kisvegabor
Copy link
Member

The function var had to be renamed to pxCond

Which one? 🙂

@nicusorcitu
Copy link
Contributor

image

As a general rule, inside the FreeRTOS files I have used FreeRTOS style while naming variables, functions...
Thanks for keeping it on the same manner.

@cristian-stoica
Copy link
Contributor

The last version of these patches fix the build regression I was looking at (PXP = 1 , OS_NONE on MCUXpresso SDK projects that always define SDK_OS_FREE_RTOS). There are other improvements that could be made but they can be addressed later.
I'm OK with this for now modulo other issues discussed in different threads.

@kisvegabor
Copy link
Member

Please add lv_thread_sync_signal_isr to lv_os_none.c too.

@faxe1008
Copy link
Contributor Author

@kisvegabor added it to lv_os_none :^)

@kisvegabor
Copy link
Member

Thanks, I've fixed the unused variable warnings.

kisvegabor
kisvegabor previously approved these changes Jun 25, 2024
Copy link
Collaborator

@liamHowatt liamHowatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice atomic CAS loop!

In another PR we should correct the implementation of lv_mutex_lock_isr for cmsis_rtos2. See this comment.

Comment on lines +101 to +113
#if defined(__ZEPHYR__)
static void PXP_ZephyrIRQHandler(void *)
{
PXP_IRQHandler();
}
#endif
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please put this in the static functions section and forward declare it. Maybe also change the name to make it seem less like a platform specific global function definition (unless it is).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah it kinda is - I do not know how many other RTOS give the possibility to add userdata to an ISR.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I mean is the name implies that it's overriding a weak definition in the OS like a systick handler that gets called by the OS, but it's really just a local function.

Also, does PXP_IRQHandler need to be global? Does it get called by anything external?

Comment on lines 332 to 335
/* Acquire the mutex. */
if(pdFALSE == xSemaphoreTakeFromISR(pxCond->xSyncMutex, NULL)) {
return LV_RESULT_INVALID;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this fails because lv_thread_sync_wait has the mutex, will the signal never be sent and a deadlock would occur?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True - what would be the best solution for this? Not using the mutex at all and disabling interrupts instead so we can not be preempted by another ISR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my last commit, if the change is ok from your side, I'll squash it :^)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think that should work, nice. Is the CAS loop no longer needed now?

Changes the PXP osal to use the thread_sync to signal PXP readyness from
the ISR.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants