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

Add overridable wait hook #1

Open
wants to merge 15 commits into
base: sleep_api
Choose a base branch
from

Conversation

geky
Copy link

@geky geky commented May 29, 2019

From ARMmbed#10693

Changed to fit into ARMmbed#10104.

I understand hal_sleep exists, and it's useful for the target, but it can't be used to catch sleep calls by the application (similar to mbed_target_override_serial vs mbed_override_serial).

While we're on the topic of naming, I went with mbed_override_sleep_hook to match the above serial names, but am open to other suggestions.

This is a follow from ARMmbed#10693

kjbracey and others added 15 commits May 29, 2019 11:45
Provide partial RTOS API for bare metal builds - things that
can be done in a single threaded environment.

Allows more code to work in both RTOS and bare metal builds without
change, and in particular gives easy access to the ability to
efficiently wait for something occurring in interrupt.

Available in bare-metal:
* ThisThread
* osThreadFlagsSet to set flags on main thread (can be set from IRQ)
* EventFlags (can be set from IRQ)
* Semaphores (can be released from IRQ)
* Mutex (dummy implementation)

Not useful:
* ConditionVariable (could only be signalled from 2nd thread)
* RtosTimer (calls in a second thread context)
* Thread

Unimplemented:
* Mail, Queue, MemoryPool

Possible future work:
* ConditionVariableCS to act as IRQ signalled ConditionVariable
Switch from CMSIS-RTOS to mbed C++ API, which are available in bare
metal build.

Other minor tidies, like removing unnecessary volatile.
Revert back to older behaviour where we hold deep sleep lock only while
timing a sleep. Previous version was a speed optimisation, but broke
some tests.
@kjbracey
Copy link
Owner

kjbracey commented May 30, 2019

For your use case, wouldn't you actually want to replace the hal sleep? (Like the override_console replaces the target_override_console). The replacement would of course be free to pass the call onto the hal/target, conditionally.

For example, if you do some of your work, decide it's now finished so you need to signal a thread, you would not want to actually go into sleep, you'd want to leave idle immediately.

Also, unfortunately, sleep is entered with interrupts disabled in a normal idle situation - race-free checking of "do I need to sleep" requires this. So this approach isn't going to quite work - it's too low level.

But I think we can slot this into the ARMmbed#10104 "do_sleep" framework, into the "preparation" section which always has interrupts enabled, prior to making the actual IRQ off/sleep bit. That would also handle the "not idle any more" case, as it would precede the "sleep predicate" check.

kjbracey pushed a commit that referenced this pull request Jun 3, 2019
kjbracey pushed a commit that referenced this pull request Jun 3, 2019
Fix LWIP warning issues found by Coverity scan

lwip_dns.c in function: dns_add_interface_server
CID 1399051 (#1 of 1): Buffer not null terminated (BUFFER_SIZE_WARNING)10. buffer_size_warning: Calling strncpy with a maximum size argument of 6 bytes on destination array new_interface_server->interface_name of size 6 bytes might leave the destination string unterminated.
line 434 strncpy(new_interface_server->interface_name, interface_name, INTERFACE_NAME_MAX_SIZE);

lwip_ip4_frag.c in function: ip_reass_free_complete_datagram

CID 1373164 (#1 of 1): Dereference after null check (FORWARD_NULL)7. var_deref_model: Passing null pointer prev to ip_reass_dequeue_datagram, which dereferences it. [show details]
line 209 ip_reass_dequeue_datagram(ipr, prev);

lwip_ip4_frag.c in function: ip_reass

CID 1373163 (#1-2 of 2): Dereference after null check (FORWARD_NULL)38. var_deref_model: Passing null pointer ipr_prev to ip_reass_dequeue_datagram, which dereferences it. [show details]
line 663 ip_reass_dequeue_datagram(ipr, ipr_prev);

lwip_api_msg.c in function: lwip_netconn_do_connected

CID 1373162 (#1 of 1): Explicit null dereferenced (FORWARD_NULL)10. var_deref_model: Passing null pointer op_completed_sem to sys_sem_signal, which dereferences it. [show details]
line 1336 sys_sem_signal(op_completed_sem);
@kjbracey
Copy link
Owner

kjbracey commented Jun 3, 2019

One more thought - what sort of work are we talking about here? Very short-running, or long-running?

There's a fundamental choice to make - is this hook run

  • a) as part of the idle thread while the kernel is active, so it can be pre-empted by high-priority threads, or

  • b) while the kernel is suspended - in effect making it the highest-priority thing in the system below interrupts, until it chooses to yield.

b) is a bit scary - it's a priority inversion of the idle thread. Would be fine for something very short-running, but if you're intending to do real work, it seems like you need a). Which is effectively the "idle hook" we already have, except we don't have a nice chaining mechanism to let you move on to standard sleep.

kjbracey pushed a commit that referenced this pull request Jun 11, 2019
@kjbracey kjbracey force-pushed the sleep_api branch 7 times, most recently from 1231f84 to 0ca5c57 Compare July 4, 2019 11:58
@kjbracey kjbracey force-pushed the sleep_api branch 4 times, most recently from ab49061 to ed4bf52 Compare July 15, 2019 07:14
kjbracey pushed a commit that referenced this pull request Jan 7, 2020
Update CMSIS-pack info for STM32G-family
kjbracey pushed a commit that referenced this pull request Feb 13, 2020
Signed-off-by: PARKJIHOON <[email protected]>
kjbracey pushed a commit that referenced this pull request Dec 3, 2020
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.

3 participants