init: add INIT_LEVEL_ORD
This patch introduces a new helper: INIT_LEVEL_ORD, which given a level
token, e.g. EARLY, PRE_KERNEL_1, etc. returns its ordinal. This can be
useful for sorting purposes, as level tokens do not result in the right
initialization order if sorted, e.g. POST_KERNEL < APPLICATION, but P >
A.
The implementation uses a bit of macrobatics to achieve this. First, we
define some helpers Z_INIT_XX_XX that evaluate to 1, and where XX
correspond to init levels. With them, we can perform equality checks
like this:
COND_CODE_1(Z_INIT_XX_##level, (VAL_IF_EXISTS), (VAL_IF_NOT_EXISTS))
It's a bit obscure, but it seems to work.
Signed-off-by:
Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
Loading
Please sign in to comment