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(demos): add demo for the OSAL #6182

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

Conversation

faxe1008
Copy link
Contributor

@faxe1008 faxe1008 commented May 5, 2024

Adds a demo demonstrating the use of the OSAL.

Resolves: #6049

Description of the feature or fix

A clear and concise description of what the bug or new feature is.

Notes

Copy link
Member

@kisvegabor kisvegabor left a comment

Choose a reason for hiding this comment

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

Thank you Fabian!

Here you can see some errors reported by CI. Fortunately, they are easy to fix.

I feel like this update could be rather an example. Usually we add complex eye catching things in the demos folder. So would you mind moving it to the examples folder?

demos/osal/lv_demo_osal.c Outdated Show resolved Hide resolved
demos/osal/lv_demo_osal.c Outdated Show resolved Hide resolved
demos/osal/lv_demo_osal.c Outdated Show resolved Hide resolved
uint32_t press_count = 0;

counter_label = lv_label_create(lv_scr_act());
lv_obj_align(counter_label, LV_ALIGN_CENTER, 0, 0);
Copy link
Member

Choose a reason for hiding this comment

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

Don't we need a mutex here? What if this thread is running concurrently with the thread of lv_timer_handler?

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, but this would mean that the lv_timer_handler thread would also need to take this lock. I do not understand how this can be achieved though.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Correct. See the latest comments in #6059

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So if I followed the disussion correctly there will be some sort of global mutex that may be taken on the PR for that is ready, right?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, after that PR, there will be a new API you can use in this PR to acquire the global mutex.

@FASTSHIFT FASTSHIFT changed the title feat(demos): Add demo for the OSAL feat(demos): add demo for the OSAL May 12, 2024
@faxe1008 faxe1008 force-pushed the osal_demo branch 3 times, most recently from f095d89 to 9c099e3 Compare May 16, 2024 08:30
@faxe1008
Copy link
Contributor Author

Moved this to examples/porting as it felt the most appropriate. How can I make sure that this is build during CI?

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.

Add

#include "porting/osal/lv_example_osal.h"

to lv_examples.h

examples/porting/osal/lv_example_osal.c Outdated Show resolved Hide resolved
examples/porting/osal/lv_example_osal.c Outdated Show resolved Hide resolved
Copy link
Member

@kisvegabor kisvegabor left a comment

Choose a reason for hiding this comment

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

If we want to run it with the CI we need to add it here. However now the CI is running only with pthread. Do you think it still makes sens to run it as a test?

.devcontainer/__lv_conf.h__ Outdated Show resolved Hide resolved
@kisvegabor
Copy link
Member

lv_conf_internal.h is generated by scripts/lv_conf_internal_gen.py and shouldn't be edited by manually.

Adds a example demonstrating the use of the OSAL.

Resolves: lvgl#6049
@kisvegabor
Copy link
Member

The original example was failing for me so I added a little bit update. With the help lv_lock and lv_unlock it's easier to create a thread safe app.

What do you think?

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 @kisvegabor, I think yes, this PR is actually a good place to add the global lock, so this PR doesn't have to wait for another PR. After this, we just have to update the Windows driver. Thanks!!

It surprised me that we have lv_mutex_lock_isr. If it has to block, it will deadlock, because the OS can't suspend the ISR to switch to the thread holding it the lock.

We implement it with xSemaphoreTakeFromISR in our FreeRTOS OSAL. Here's the description from the FreeRTOS docs (link):

A version of xSemaphoreTake() that can be called from
an ISR. Unlike xSemaphoreTake(), xSemaphoreTakeFromISR() does not permit a block
time to be specified.

So it's okay. It's just fallible. I think we can remove the LV_LOG_ERROR since it's a possible and expected failure.

However for cmsis_rtos2 we call osMutexAcquire which according to the docs, always fails in an ISR (link):

osErrorISR: cannot be called from interrupt service routines.

Mutex management functions cannot be called from Interrupt Service Routines (ISR), unlike a binary semaphore that can be released from an ISR.

All that to say, my feedback for your changes for now is to make the new function lv_lock_isr return lv_result_t and we can merge it.

src/osal/lv_os.h Outdated Show resolved Hide resolved
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.

Thank you faxe1008 and kisvegabor!

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.

Demo for the OSAL
3 participants