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()21bool running_on_fpga() { 22 return !!((*(io_ro_32 *)TBMAN_BASE) & TBMAN_PLATFORM_FPGA_BITS); 23 } 24 #endif 25 26 #define MANUFACTURER_RPI 0x927 27 #define PART_RP2 0x2 28 rp2040_chip_version()29uint8_t rp2040_chip_version() { 30 // First register of sysinfo is chip id 31 uint32_t chip_id = *((io_ro_32*)(SYSINFO_BASE + SYSINFO_CHIP_ID_OFFSET)); 32 uint32_t __unused manufacturer = chip_id & SYSINFO_CHIP_ID_MANUFACTURER_BITS; 33 uint32_t __unused part = (chip_id & SYSINFO_CHIP_ID_PART_BITS) >> SYSINFO_CHIP_ID_PART_LSB; 34 assert(manufacturer == MANUFACTURER_RPI); 35 assert(part == PART_RP2); 36 // Version 1 == B0/B1 37 uint version = (chip_id & SYSINFO_CHIP_ID_REVISION_BITS) >> SYSINFO_CHIP_ID_REVISION_LSB; 38 return (uint8_t)version; 39 }