|
| 1 | +/* |
| 2 | + * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + */ |
| 6 | +#include <stddef.h> |
| 7 | +#include "assert.h" |
| 8 | +#include "soc/lpperi_struct.h" |
| 9 | + |
| 10 | +#define LPPERI_REV1_2_DATE (0x2308030) |
| 11 | +#define LPPERI_REG_ADDR(reg) ((LPPERI_REV1_2.date.lpperi_date >= LPPERI_REV1_2_DATE) ? \ |
| 12 | + &LPPERI_REV1_2.reg : \ |
| 13 | + (volatile typeof(LPPERI_REV1_2.reg) *)&LPPERI_REV0_0.reg) |
| 14 | + |
| 15 | +/** |
| 16 | + * @brief Compatible LPPERI instance |
| 17 | + * @note Set NULL as default so that to abort when use the LPPEIR before initialization |
| 18 | + * If you want to use the LPPERI before it is initialized, please use `lpperi_reg.h` instead |
| 19 | + */ |
| 20 | +lpperi_dev_t LPPERI = {}; |
| 21 | + |
| 22 | +/** |
| 23 | + * @brief Initialize the LP_PERI register address according to the register version |
| 24 | + */ |
| 25 | +void lpperi_compatible_reg_addr_init(void) |
| 26 | +{ |
| 27 | + LPPERI.clk_en = LPPERI_REG_ADDR(clk_en); |
| 28 | + LPPERI.reset_en = LPPERI_REG_ADDR(reset_en); |
| 29 | + LPPERI.rng_cfg = ((LPPERI_REV1_2.date.lpperi_date >= LPPERI_REV1_2_DATE) ? &LPPERI_REV1_2.rng_cfg : NULL); |
| 30 | + LPPERI.rng_data = LPPERI_REG_ADDR(rng_data); |
| 31 | + LPPERI.cpu = LPPERI_REG_ADDR(cpu); |
| 32 | + LPPERI.bus_timeout = LPPERI_REG_ADDR(bus_timeout); |
| 33 | + LPPERI.bus_timeout_addr = LPPERI_REG_ADDR(bus_timeout_addr); |
| 34 | + LPPERI.bus_timeout_uid = LPPERI_REG_ADDR(bus_timeout_uid); |
| 35 | + LPPERI.mem_ctrl = LPPERI_REG_ADDR(mem_ctrl); |
| 36 | + LPPERI.interrupt_source = LPPERI_REG_ADDR(interrupt_source); |
| 37 | + LPPERI.debug_sel0 = LPPERI_REG_ADDR(debug_sel0); |
| 38 | + LPPERI.debug_sel1 = LPPERI_REG_ADDR(debug_sel1); |
| 39 | + LPPERI.date = LPPERI_REG_ADDR(date); |
| 40 | +} |
| 41 | + |
| 42 | +__attribute__((constructor)) |
| 43 | +static void s_lpperi_compatible_init_check(void) |
| 44 | +{ |
| 45 | + // Make sure it is initialized |
| 46 | + assert(LPPERI.clk_en != NULL); |
| 47 | +} |
0 commit comments