1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
Commit Graph

643 Commits

Author SHA1 Message Date
Benjamin Valentin
b5ea78ad47 core/msg: make msg_avail() return 0 on no queue
For the caller there should be no difference if there is no message
in the queue and if there can't be a message in the queue.

The current API works as one would expect if there is a message queue,
but once called from a thread that does not have a message queue
configured, code that does

    while (msg_avail())

will end up in an infinite loop.

Remove this foot-gun from the API by making the return value of
msg_avail() independend of the availability of a message queue.
2021-11-29 12:04:16 +01:00
Marian Buschsieweke
9535447e6f
core/kernel_defines.h: drop ALIGN_OF()
Since we moved to C11 now for all platforms, using `alignof()` provided
by `<stdalign.h>` has become the better option.
2021-11-25 09:20:22 +01:00
Marian Buschsieweke
d7a0ea1eec
core/bitarthm: suppress false positives
Co-authored-by: chrysn <chrysn@fsfe.org>
2021-11-18 09:45:22 +01:00
Marian Buschsieweke
58e197098d
core: add WITHOUT_PEDANTIC() and DECLARE_CONSTANT()
`WITHOUT_PEDANTIC(expr)` disables `-Wpedantic` for `expr`, but switches
back to the previous diagnostic settings afterwards. This helps defining
macros that are not strictly ISO compliant without having to drop the
`-Wpedantic` flag entirely.

`DECLARE_CONSTANT(identifier, const_expr)` declares an anonymous `enum`
constant named `identifier` and assigns it the value `const_expr`. Here,
`const_expr` has to be a compile time constant, but is not needed to be
an integer constant expression. It basically is a tool to magically
convert a non-integer constant expression into a integer constant
expression.
2021-11-10 15:22:47 +01:00
Benjamin Valentin
e2639cb53a core/include/kernel_defines.h: Fix index_of()
Calculate the size of the element based on the array given, not based
on the element pointer.

The element might as well be given as a `void *` via a callback.
In that case, if the user forgets to cast the `void *` to the array
element type, the calculation returns false values.

Disarm this foot gun by basing the element size off the given array.
2021-11-06 00:35:39 +01:00
Benjamin Valentin
01a49d3d19 core/include/kernel_defines.h: add index_of() macro 2021-11-05 16:42:38 +01:00
Martine Lenders
e27fd3018e
core/thread.h: fix new uncrustify error 2021-11-05 09:27:00 +01:00
Martine Lenders
f08989a3c8
core: make SCHED_TEST_STACK boolean and default to 1 with DEVELHELP 2021-11-05 09:27:00 +01:00
Hauke Petersen
3d7d797a57
core/sched: add sched_change_priority() function
Co-authored-by: Marian Buschsieweke <marian.buschsieweke@ovgu.de>
2021-11-02 20:44:32 +01:00
Marian Buschsieweke
ff7e7c26cf
core/log: Add anchor to doc to allow stable references 2021-10-10 21:35:31 +02:00
Martine Lenders
ea8e632eda
Merge pull request #16765 from benpicco/RIOT_VERSION_CODE
build system: add machine-readable RIOT_VERSION_CODE macro
2021-09-22 12:47:35 +02:00
Benjamin Valentin
7ef2594327 core/include/kernel_defines.h: add RIOT_VERSION_NUM macro 2021-09-21 17:43:29 +02:00
4fd1ae89a7
Merge pull request #16463 from kfessel/p-sched-int
core/sched: add runq_callback hook and runq inspection functions
2021-09-15 15:43:50 +03:00
2b2c5fe746 core/thread: provide getters for thread_t fields as used by ps() 2021-09-15 10:16:45 +02:00
chrysn
137399c8cb core/msg doc: Clarify; elaborating on interaction with queue 2021-09-01 14:56:41 +02:00
Hauke Petersen
b526394d82 core/irq.h: add irq_is_enabled() function 2021-08-25 08:01:05 +02:00
Jan Romann
4384795cb9
treewide: Remove excessive newlines 2021-08-13 19:50:38 +02:00
Karl Fessel
3508012942 core/sched: name inspection functions the same as the used clist fns 2021-08-09 14:18:18 +02:00
Francisco
d7b3328601
Merge pull request #16098 from kfessel/p-remove-lifo
core/lifo: Remove lifo [after 2021.04]
2021-06-15 13:55:30 +02:00
Karl Fessel
9f00528a58 core/sched: add runq_callback hook and runq inspection functions 2021-05-10 15:01:58 +02:00
95a2456457
Merge pull request #16330 from kfessel/p-add-clist-special
core/clist: add special cardinality tests and matching unittest
2021-04-15 12:14:58 +02:00
Karl Fessel
5735d99971 core/clist: add special cardinality tests and matching unittest
adds clist_exactly_one() and clist_more_than_one()
and a unittest that tests them
2021-04-14 21:00:10 +02:00
Karl Fessel
1dde0f42d4 core/sched: keep scheduler clist internal to sched
adds sched_runq_advance(prio)
used it in core/thread and
test malloc_thread_safety
2021-04-14 09:53:04 +02:00
020945a773 core/clist: add clist_is_empty() 2021-04-09 10:54:29 +02:00
e8e8405c4a core/thread: move thread configuration into seperate header 2021-03-02 11:56:11 +01:00
Karl Fessel
1c1f051ab7 core/lifo: Remove lifo 2021-02-27 11:59:36 +01:00
Karl Fessel
55a0ca402b core/lifo: deprecate file for remove after 2021.04 2021-02-27 10:17:33 +01:00
Karl Fessel
9ab0681634 core/lifo: remove lifo.c, keep api with lifo.h
use LOG_DEBUG instead of DEBUG
2021-02-26 17:45:31 +01:00
2861d1f353 core/xfa: typeof() -> __typeof__() 2021-02-23 13:37:19 +01:00
df4dc36d91 core/xfa: add "experimental" note 2021-02-18 10:46:08 +01:00
d310044a88 core/xfa: fix doxygen issues 2021-02-18 10:46:08 +01:00
249ed5f2e1 core/include/xfa.h: uncrustify 2021-02-18 10:46:08 +01:00
2bc7bb4740 core/xfa: make externc happy 2021-02-18 10:46:08 +01:00
e827f0bdf1 core/xfa: add comments explaining the pragmas 2021-02-18 10:46:08 +01:00
50dc68bd21 core/xfa: make const XFA's volatile
This prevents gcc from figuring out that an XFA that has been
initialized in the same file is technically empty when the compilation
unit is seen by itself. This happened with gcc 10.1.0 on msp430-elf.
2021-02-18 10:46:08 +01:00
b54afa1449 xfa: remove duplicate "const" from _XFA_CONST 2021-02-18 10:46:08 +01:00
bdd59ae7f2 core: disable -Warray-bounds for XFA users 2021-02-18 10:46:08 +01:00
66092f5506 core: Introduce cross file arrays (XFA)
Co-Authored-By: Joakim Nohlgård <joakim.nohlgard@eistec.se>
2021-02-16 14:21:32 +01:00
Martine Lenders
9b40bb63c2
core: apply uncrustify patches 2021-02-02 22:21:14 +01:00
9d5f87bf67
core/thread: Allow for inline thread_yield_higher
Similar to irq.h, this allows for inline the often trivial
thread_yield_higher function
2021-01-19 11:03:20 +01:00
f0ce992d4a
core/thread: uncrustify header file 2021-01-19 10:28:58 +01:00
323fa3b5ac
core/mutex: fix typo in documentation 2020-12-29 11:48:48 +01:00
Marian Buschsieweke
8bbe56c302
core/mutex: compatibility with non-C languages
Due to limited compatibility with C, we cannot use the inline mutex_trylock
implementation for C++. Instead, we provide a mutex_trylock_ffi() intended for
foreign function interfaces. This should also benefit rust users.
2020-12-09 11:53:48 +01:00
Marian Buschsieweke
472d6d0abc
core/mutex: fix documentation 2020-12-08 23:04:16 +01:00
229291ef01
Merge pull request #15442 from maribu/mutex_abort
core/mutex: Add mutex_cancel
2020-12-08 17:12:52 +01:00
Marian Buschsieweke
df66dd0272
core/mutex: uncrustify 2020-12-08 14:50:50 +01:00
Marian Buschsieweke
e348407888
core/mutex: Add mutex_cancel() & mutex_lock_cancelable()
Add a version of `mutex_lock()` that can be canceled with the obvious name
`mutex_lock_cancelable()`. This function returns `0` on success, and
`-ECANCELED` when the calling thread was unblocked via a call to
`mutex_cancel()` (and hence without obtaining the mutex).

This is intended to simplify the implementation of `xtimer_mutex_lock_timeout()`
and to implement `ztimer_mutex_lock_timeout()`.
2020-12-08 14:50:49 +01:00
benpicco
aabd5eaca5
Merge pull request #15506 from kaspar030/refactor_thread_info
core: refactor thread info
2020-11-26 13:01:09 +01:00
ceea0ba949 core/thread: add thread_is_active() 2020-11-25 20:49:00 +01:00
1d5e2e9cd9 all: remove traces of kernel_types.h
Automatically removed using:

    $ git grep -l kernel_types | xargs sed -i '/^#include .kernel_types/d'
2020-11-25 17:52:34 +01:00
017e9e9d4d core/thread: add thread_get_status() 2020-11-25 14:39:22 +01:00
5321bcde89 core: thread: move thread_state_to_string() from ps.c 2020-11-25 14:35:00 +01:00
65f997026f core: drop kernel_types.h 2020-11-25 13:18:53 +01:00
1711b4b649 core/include/kernel_types.h: re-add c++ compat parts 2020-11-23 17:13:35 +01:00
0b801c4de0 all: adapt to moved sched defines 2020-11-23 16:56:34 +01:00
7fa8b69912 core: include inttypes.h in sched.h
sched.h now defines PRIkernel_pid to PRIi16, which in turn is defined in
inttypes.h.
2020-11-23 16:56:34 +01:00
1ca0c23173 core/msg: adapt to changed thread define location 2020-11-23 16:56:34 +01:00
369e9b30e2 core: move scheduler defines to sched.h 2020-11-23 16:56:34 +01:00
91111555a6 core/mbox: add mbox_size() and mbox_avail() 2020-11-20 10:38:17 +01:00
Marian Buschsieweke
a06a7978d3
core/mutex: clean up mutex_lock()
- Split out handling of the blocking code path of mutex_lock() into a static
  `_block()` function. This improves readability a bit and will ease review of
  a follow up PR.
- Return `void` instead of `int`.
2020-11-18 11:58:49 +01:00
c4ef8b71e1
Merge pull request #15327 from maribu/mutex_cleanup_splitout
core/mutex: Cleanup
2020-11-13 18:37:27 +01:00
Benjamin Valentin
eea2df99a3 core/msg_bus: enhace documentation 2020-11-09 21:13:08 +01:00
Marian Buschsieweke
d760e931ae
core/mutex: Cleanup
- Use static inline function for `mutex_try_lock()`
    - The implementation is trivial enough with the inline-able IRQ API to just
      always be inline-ed
- Rename `_mutex_lock()` to `mutex_lock()` and drop the blocking parameter
    - This was possible to the stand-alone `mutex_try_lock()` implementation
    - This yields a measurable performance bump
2020-11-06 23:27:13 +01:00
Marian Buschsieweke
876d500846
core/mutex: improve documentation 2020-11-06 18:23:26 +01:00
Martine Lenders
dd81a070f0
Merge pull request #15365 from miri64/core/enh/debug-IS_ACTIVE
core: debug: remove parenthesis around ENABLE_DEBUG define
2020-11-03 17:49:14 +01:00
benpicco
ee7a52db2f
Merge pull request #14023 from benpicco/core/msg_bus-bus_flag
core/msg_bus: allow to differ between messages form bus and from thread
2020-11-03 13:51:19 +01:00
Martine Lenders
2df29a6806
core: debug: remove parenthesis around ENABLE_DEBUG define 2020-11-03 13:01:08 +01:00
Benjamin Valentin
d6a6c218a3 core/msg_bus: allow to differ between messages form bus and from thread
Currently it is not possible to check if a message was sent over a bus
or if it was send the usual way using `msg_send()`.

This adds a flag to the `sender_pid` if the message was sent over a bus.
`MAXTHREADS` is currently set to 32, so there is still plenty of room in
the PID space. (`kernel_pid_t` is `int16_t`)

The message type for bus message type is already accessed through a getter
function, so it's just consistent to do the same for sender_pid.
2020-11-03 10:52:43 +01:00
benpicco
c979fda1f3
Merge pull request #14367 from basilfx/feature/cortex_m33
cpu/cortex: add initial support for Cortex-M33
2020-10-08 22:55:06 +02:00
Bas Stottelaar
0f8cecb50b cpu/cortexm_common: add support for Cortex-M33 2020-10-06 17:11:26 +02:00
c59349482a
core/msg_bus: fix typo 'busses' -> 'buses'
Also fix typo 'seach' -> 'search'
2020-10-02 07:52:18 +02:00
benpicco
ab15d67e80
Merge pull request #15059 from maribu/core-thread-cast-align
core/thread.c: Silence -Wcast-align flase positives
2020-09-26 16:31:58 +02:00
Marian Buschsieweke
e028f6bbe6
core/thread: thread_measure_stack_free() const arg
Add `const` to stack pointer passed to thread_measure_stack_free()
2020-09-25 14:30:33 +02:00
Marian Buschsieweke
85e506e893
core/include/kernel_defines.h: Fix container_of()
container_of() is safe to use in regard to alignment requirements, when used
correctly. Using `uintptr_t` instead of `char *` for applying the offset results
in -Wcast-align not complaining.
2020-09-22 15:13:03 +02:00
Francisco
64f6b7ffa4
Merge pull request #14702 from maribu/sched_active_thread
treewide: Fix direct access to scheduler internals
2020-09-21 09:09:59 +02:00
Jim O'Brien
bd149e7db9 thread: Add THREAD_NAMES make flag
Separate thread names from DEVELHELP so thread names can be
enabled in non-development/debug builds when required/desired.
THREAD_NAMES will be enabled by default then DEVELHELP is set to 1.
2020-09-10 10:08:27 +02:00
Marian Buschsieweke
2d8bdf9b83
core/sched: Drop declaration of sched_active_{pid,thread}
This should increase odds that developers use thread_get_active() and
thread_getpid() instead.
2020-09-07 12:59:55 +02:00
77735e7e10
Merge pull request #14709 from bergzand/pr/sched/return_thread 2020-09-03 10:18:47 +02:00
495644adc0
sched: return the new thread on sched_run 2020-09-02 13:32:14 +02:00
c83b78a567
Merge pull request #14762 from maribu/move_byteorder
core/byteorder: Moved to sys
2020-09-01 15:02:11 +02:00
Keith Packard
531050ada2 picolibc: Enable TLS support [v4]
Allocate and initialize a thread-local block for each thread at the
top of the stack.

Set the tls base when switching to a new thread.

Add tdata/tbss linker instructions to cortex_m and risc-v scripts.

Signed-off-by: Keith Packard <keithp@keithp.com>

---

v2:
	Squash fixes

v3:
	Replace tabs with spaces

v4:
	Add tbss to fe310 linker script
2020-08-24 08:26:16 -07:00
Marian Buschsieweke
164d2ac8f2
core/byteoder: Moved to sys
The byteorder utilities are never used in `core`, but extensively in `sys`.
They seem to be better located in `sys`.
2020-08-14 16:28:59 +02:00
Marian Buschsieweke
81d40d3f66
core/byteorder: Add byteoder_htobebufll & inverse
- Add `byteorder_bebuftohll()` to read an 64 bit value from a big endian buffer
- Add `byteorder_htobebufll()` to write an 64 bit value into a big endian buffer
2020-08-14 13:36:40 +02:00
Marian Buschsieweke
57264c5059
core: Access internal vars via helper funcs
Replace accesses to `sched_active_thread`, `sched_active_pid`, and
`sched_threads` with `thread_get_active()`, `thread_get_active_pid()`, and
`thread_get_unchecked()` where sensible.
2020-08-06 16:47:33 +02:00
Marian Buschsieweke
4a31578982
core/thread: Add/change helper access functions
- Add `thread_get_active()` to access the TCB
- Add `thread_get_unchecked()` as fast alternative to `thread_get()`
- Drop `volatile` qualifier in `thread_get()`
    - Right now every caller of this function does this. It is better to
      contain this undefined behavior to at least one place in code
2020-08-06 14:35:43 +02:00
5dbcfa3391
Merge pull request #14698 from benpicco/core/bitarithm-msb_clz
core/bitarithm: use __builtin_clz() for bitarithm_msb()
2020-08-06 13:00:34 +02:00
Marian Buschsieweke
315cdcdb5f
core/thread: Make thread_get inlineable 2020-08-05 10:51:16 +02:00
Benjamin Valentin
14144030fa core/bitarithm: use __builtin_clz() for bitarithm_msb()
The `clz` instruction pretty much implements getting the most significant bit
in hardware, so use it instead of the software implementation.

This reults in both a reduction in code size as in a speedup:

master:

  text    data     bss     dec     hex filename
 14816     136    2424   17376    43e0 tests/bitarithm_timings/bin/same54-xpro/tests_bitarithm_timings.elf

 + bitarithm_msb: 3529411 iterations per second

this patch:

  text    data     bss     dec     hex filename
 14768     136    2424   17328    43b0 tests/bitarithm_timings/bin/same54-xpro/tests_bitarithm_timings.elf

 + bitarithm_msb: 9230761 iterations per second
2020-08-04 17:50:09 +02:00
Marian Buschsieweke
e4387c84fd
core/byteorder: Fix from/to be buffers on be
Big endian buffers on big endian systems are already in big endian byte order,
so no byte shuffling is needed. However, byte buffers might be unaligned, so
copy operations that are safe with unaligned memory accesses need to be
used.
2020-07-28 22:34:25 +02:00
Leandro Lanzieri
72d6d9047f
Merge pull request #14429 from benpicco/core/boot_msg
core/init: make boot message configurable
2020-07-28 16:40:08 +02:00
Benjamin Valentin
25e67e019e core/init: make boot message configurable
It can be desirable to not have the boot message printed each time
(e.g. logs are transferred over a wireless link on battery) while
still retaining the ability to receive INFO level logs.

This adds the option to disable the boot-up message (and also to customize
it if that is desireable).
2020-07-28 11:04:55 +02:00
benpicco
6ef4276c35
Merge pull request #14621 from benpicco/core/byteorder-be
core/byteorder: add Big Endian implementations
2020-07-28 10:30:27 +02:00
d59233baf1
Merge pull request #14556 from benpicco/bitarithm_test_and_clear
core/bitarithm: add bitarithm_test_and_clear()
2020-07-28 10:11:47 +02:00
Benjamin Valentin
df18bfb459 core/byteorder: add Big Endian implementations 2020-07-27 18:36:07 +02:00
Benjamin Valentin
4d34cee72f core: add comments to symbols used by OpenOCD
OpenOCD makes assumptions about those symbol names / enum entries,
so add a note about it as a comment.
2020-07-27 16:14:42 +02:00
Benjamin Valentin
46b89eb723 core/msg_bus: fix shift on 8-bit platforms
The previous shift would wrap if the compiler defaults to 16 bit words.
Use explicit `unsigned long` integer constants to mitigate that.

before:

2020-07-22 15:25:17,063 # THREAD 1 start
2020-07-22 15:25:17,063 # THREAD 2 start
2020-07-22 15:25:17,065 # THREAD 3 start
2020-07-22 15:25:17,066 # THREADS CREATED
2020-07-22 15:25:17,068 # Posted event 22 to 0 threads
2020-07-22 15:25:17,071 # Posted event 23 to 0 threads
2020-07-22 15:25:17,076 # Posted event 24 to 0 threads
2020-07-22 15:25:17,076 # SUCCESS
2020-07-22 15:26:00,188 # Exiting Pyterm

after:

2020-07-22 15:26:10,374 # THREAD 1 start
2020-07-22 15:26:10,374 # THREAD 2 start
2020-07-22 15:26:10,377 # THREAD 3 start
2020-07-22 15:26:10,377 # THREADS CREATED
2020-07-22 15:26:10,380 # Posted event 22 to 0 threads
2020-07-22 15:26:10,383 # T1 recv: Hello Threads! (type=23)
2020-07-22 15:26:10,386 # T3 recv: Hello Threads! (type=23)
2020-07-22 15:26:10,388 # Posted event 23 to 2 threads
2020-07-22 15:26:10,391 # T2 recv: Hello Threads! (type=24)
2020-07-22 15:26:10,394 # Posted event 24 to 1 threads
2020-07-22 15:26:10,396 # SUCCESS
2020-07-22 15:27:31 +02:00
Benjamin Valentin
a8904edd7d core/bitarithm: add bitarithm_test_and_clear() 2020-07-21 16:03:59 +02:00
benpicco
e2e51ae7ef
Merge pull request #14368 from jia200x/pr/byteorder_bebuftohs
core/byteorder: add uint32 from/to buffer funcs
2020-07-13 12:31:43 +02:00
Jose Alamos
244d5191c8 core/byteorder: add uint32 from/to buffer funcs 2020-07-13 11:21:30 +02:00
e3f6c0f340 core: make idle thread optional 2020-06-25 16:02:28 +02:00