[NEW] Improved PAL driver with synchronous API

This forum is dedicated to feedback, discussions about ongoing or future developments, ideas and suggestions regarding the ChibiOS projects are welcome. This forum is NOT for support.
User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: [NEW] Improved PAL driver with synchronous API

Postby Giovanni » Mon Apr 16, 2018 7:28 pm

Hi,

You don't need to write IRQ handlers, the various drivers declare their own handlers internally and give you callbacks. The structure el0 and el1 are used to associate an event source to a thread, once registered there is no need to touch those again. The demo application is an example of various ways to do the same thing, using events or callbacks or direct synchronization.

Giovanni

TKorho
Posts: 18
Joined: Mon Sep 13, 2021 6:46 pm
Has thanked: 2 times
Been thanked: 1 time

The different ways to use PAL triggers?

Postby TKorho » Mon Sep 13, 2021 7:35 pm

Hello Giovanni / ChibiOS,
The ChibiOS seems excellent, well thought and well supported RTOS/HAL! Thank you for all the work on it!
Sorry to necro this old thread, but this seems to match my query the best. I feel inadequate starting with the PAL callbacks and events... :?

In the HAL-event-demo there are some routes: the palWaitLineTimeout is obvious and clear, but not useful for me, when I need to wait on several different lines and work differently on each of them. And there are also other threads abound.

The callback API is very clear! Excellent.
But the example implementation leans on callback-broadcast-event-catch-trigger-thread(s). It seems very proficient also, but very intimidating.

==> Can the PAL callback be used directly, in simple fast use case? :?: instead of main-(or other )thread event waiting and event rerouting? If I set

Code: Select all

palSetLineCallback(BUTTON_A, button_A_cb, NULL);
, can I work directly on it with

Code: Select all

void button_A_cb() { setLedA(LED::ON); }
? Or do I need to declare the events, fire them from the bound callback, and then sort them somewhere in a chEvtWait-thread? Like the main-thread in PAL_USE_CALLBACKS example. I can understand this might be required because of interrupt priority/MCU/core needs, but that isn't close to my heart at this time.

The Events look to be good and efficient low level mechanism, but it isn't packaged very neat, and looks quite intimidating for beginner ChibiOSer. I would need to define numerous events, and would have largish Event switch case... I'd rather prefer simpler approach with direct interrupt-callback? If the above is possible, then the HAL-event-demo would benefit from having third use case "PAL_USE_EVENTS". :idea:

Sorry, and thanks for possible tips!

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: [NEW] Improved PAL driver with synchronous API

Postby Giovanni » Mon Sep 13, 2021 7:44 pm

Hi,

It is not that complex, in ChibiOS all callbacks are called from ISRs, you can use in there any function that can be called from ISRs, in ChibiOS those functions are tagged by the "I" or "X" name suffixes (please look at docs about suffixes or in the online book).

Manipulating a GPIO is one of those things you can do directly from callbacks, just call normal PAL functions even if not suffixed, PAL is a special case, it is register-level code and it is all inlined, very fast.

No need to use the RTOS events at all, those are just part of the example.

Giovanni

TKorho
Posts: 18
Joined: Mon Sep 13, 2021 6:46 pm
Has thanked: 2 times
Been thanked: 1 time

Re: [NEW] Improved PAL driver with synchronous API

Postby TKorho » Mon Sep 13, 2021 8:58 pm

Oh my, thank you for the lightning fast reply! :)

The use case is slightly more complex than I represented: storing data into (global) data structures, just a pair of lines of processing. Later utilizing that in same or lower priority threads. But I understand your answer, to at least at least make the effort to test this in practice!

And for learning, I'll be sure to make also event distribution practice, to get over it. And to understand the I and X levels. Any playembedded level articles on those? Mille grazie!

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: [NEW] Improved PAL driver with synchronous API

Postby Giovanni » Mon Sep 13, 2021 9:04 pm

Events are a bit hard hard (because extremely flexible), better start from something else. The PAL demo is an example of Events anyway.

You should look PlayEmbedded for basic articles, the book in the documentation section and the various articles also on chibios.org.

Giovanni


Return to “Development and Feedback”

Who is online

Users browsing this forum: No registered users and 27 guests