mirror of
https://github.com/raspberrypi/pico-sdk.git
synced 2025-12-10 07:14:36 +01:00
Move unique_id (configurably) earlier in the static init process (#2379)
This enables using the unique_id in C++ static initializers by default
This commit is contained in:
parent
a5ba689cb5
commit
bb5b5f96e2
2 changed files with 29 additions and 1 deletions
|
|
@ -41,6 +41,28 @@ extern "C" {
|
||||||
|
|
||||||
#define PICO_UNIQUE_BOARD_ID_SIZE_BYTES 8
|
#define PICO_UNIQUE_BOARD_ID_SIZE_BYTES 8
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Static initialization order
|
||||||
|
* \ingroup pico_unique_id
|
||||||
|
*
|
||||||
|
* This defines the init_priority of the pico_unique_id. By default, it is 1000. The valid range is
|
||||||
|
* from 101-65535. Set it to -1 to set the priority to none, thus putting it after 65535. Changing
|
||||||
|
* this value will initialize the unique_id earlier or later in the static initialization order.
|
||||||
|
* This is most useful for C++ consumers of the pico-sdk.
|
||||||
|
*
|
||||||
|
* See https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-constructor-function-attribute
|
||||||
|
* and https://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Attributes.html#index-init_005fpriority-variable-attribute
|
||||||
|
*
|
||||||
|
* Here is an example of C++ static initializers that will run before, and then after, pico_unique_id is loaded:
|
||||||
|
*
|
||||||
|
* [[gnu::init_priority(500)]] my_class before_instance;
|
||||||
|
* [[gnu::init_priority(2000)]] my_class after_instance;
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#ifndef PICO_UNIQUE_BOARD_ID_INIT_PRIORITY
|
||||||
|
#define PICO_UNIQUE_BOARD_ID_INIT_PRIORITY 1000
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Unique board identifier
|
* \brief Unique board identifier
|
||||||
* \ingroup pico_unique_id
|
* \ingroup pico_unique_id
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,13 @@ static_assert(PICO_UNIQUE_BOARD_ID_SIZE_BYTES <= FLASH_UNIQUE_ID_SIZE_BYTES, "Bo
|
||||||
|
|
||||||
static pico_unique_board_id_t retrieved_id;
|
static pico_unique_board_id_t retrieved_id;
|
||||||
|
|
||||||
static void __attribute__((constructor)) _retrieve_unique_id_on_boot(void) {
|
#if PICO_UNIQUE_BOARD_ID_INIT_PRIORITY == -1
|
||||||
|
#define PICO_UNIQUE_BOARD_ID_INIT_ATTRIBUTES constructor
|
||||||
|
#else
|
||||||
|
#define PICO_UNIQUE_BOARD_ID_INIT_ATTRIBUTES constructor(PICO_UNIQUE_BOARD_ID_INIT_PRIORITY)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static void __attribute__((PICO_UNIQUE_BOARD_ID_INIT_ATTRIBUTES)) _retrieve_unique_id_on_boot(void) {
|
||||||
#if PICO_RP2040
|
#if PICO_RP2040
|
||||||
#if PICO_NO_FLASH
|
#if PICO_NO_FLASH
|
||||||
// The hardware_flash call will panic() if called directly on a NO_FLASH
|
// The hardware_flash call will panic() if called directly on a NO_FLASH
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue