1 /* 2 * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #include "pico.h" 8 #include "hardware/address_mapped.h" 9 #include "hardware/regs/tbman.h" 10 #include "hardware/regs/sysinfo.h" 11 12 // Note we leave the FPGA check in by default so that we can run bug repro 13 // binaries coming in from the wild on the FPGA platform. It takes up around 14 // 48 bytes if you include all the calls, so you can pass PICO_NO_FPGA_CHECK=1 15 // to remove it. The FPGA check is used to skip initialisation of hardware 16 // (mainly clock generators and oscillators) that aren't present on FPGA. 17 18 #if !PICO_NO_FPGA_CHECK 19 // Inline stub provided in header if this code is unused (so folding can be 20 // done in each TU instead of relying on LTO) running_on_fpga(void)21bool __attribute__((weak)) running_on_fpga(void) { 22 return (*(io_ro_32 *)TBMAN_BASE) & TBMAN_PLATFORM_FPGA_BITS; 23 } 24 #endif 25 #if !PICO_NO_SIM_CHECK running_in_sim(void)26bool __attribute__((weak)) running_in_sim(void) { 27 return (*(io_ro_32 *)TBMAN_BASE) & TBMAN_PLATFORM_HDLSIM_BITS; 28 } 29 #endif 30 31 #define MANUFACTURER_RPI 0x926 32 #define PART_RP4 0x4 33 rp2350_chip_version(void)34uint8_t rp2350_chip_version(void) { 35 // First register of sysinfo is chip id 36 uint32_t chip_id = *((io_ro_32*)(SYSINFO_BASE + SYSINFO_CHIP_ID_OFFSET)); 37 uint32_t __unused manufacturer = chip_id & SYSINFO_CHIP_ID_MANUFACTURER_BITS; 38 uint32_t __unused part = (chip_id & SYSINFO_CHIP_ID_PART_BITS) >> SYSINFO_CHIP_ID_PART_LSB; 39 assert(manufacturer == MANUFACTURER_RPI); 40 assert(part == PART_RP4); 41 // 0 == A0, 1 == A1, 2 == A2 42 uint version = (chip_id & SYSINFO_CHIP_ID_REVISION_BITS) >> SYSINFO_CHIP_ID_REVISION_LSB; 43 return (uint8_t)version; 44 }