Skip to content

Commit cf56ddd

Browse files
committed
move interdependent vars into new pico/platform/common.h, and deduplicate some other platform code
1 parent b653c83 commit cf56ddd

File tree

17 files changed

+145
-117
lines changed

17 files changed

+145
-117
lines changed

src/cmake/rp2_common.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ endif()
8282

8383
# Basic bootrom headers
8484
pico_add_subdirectory(rp2_common/boot_bootrom_headers)
85+
pico_add_subdirectory(rp2_common/pico_platform_common)
8586
pico_add_subdirectory(rp2_common/pico_platform_compiler)
8687
pico_add_subdirectory(rp2_common/pico_platform_sections)
8788
pico_add_subdirectory(rp2_common/pico_platform_panic)

src/rp2040/pico_platform/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ cc_library(
2727
deps = [
2828
"//src/rp2040/hardware_regs",
2929
"//src/rp2040/hardware_regs:platform_defs",
30+
"//src/rp2_common/pico_platform_common",
3031
"//src/rp2_common/pico_platform_compiler",
3132
"//src/rp2_common/pico_platform_panic:pico_platform_panic_headers",
3233
"//src/rp2_common/pico_platform_sections",
@@ -44,6 +45,7 @@ cc_library(
4445
"//src/rp2040/hardware_regs",
4546
"//src/rp2040/hardware_regs:platform_defs",
4647
"//src/rp2_common/hardware_base",
48+
"//src/rp2_common/pico_platform_common",
4749
"//src/rp2_common/pico_platform_compiler",
4850
"//src/rp2_common/pico_platform_panic",
4951
"//src/rp2_common/pico_platform_sections",

src/rp2040/pico_platform/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ if (NOT TARGET pico_platform)
1717

1818
target_link_libraries(pico_platform_headers INTERFACE hardware_regs)
1919
pico_mirrored_target_link_libraries(pico_platform INTERFACE
20+
pico_platform_common
2021
pico_platform_compiler
2122
pico_platform_panic
2223
pico_platform_sections

src/rp2040/pico_platform/include/pico/platform.h

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "pico/platform/compiler.h"
2424
#include "pico/platform/sections.h"
2525
#include "pico/platform/panic.h"
26+
#include "pico/platform/common.h"
2627
#include "hardware/regs/addressmap.h"
2728
#include "hardware/regs/sio.h"
2829

@@ -73,15 +74,6 @@
7374

7475
#ifndef __ASSEMBLER__
7576

76-
/*! \brief No-op function for the body of tight loops
77-
* \ingroup pico_platform
78-
*
79-
* No-op function intended to be called by any tight hardware polling loop. Using this ubiquitously
80-
* makes it much easier to find tight loops, but also in the future \#ifdef-ed support for lockup
81-
* debugging might be added
82-
*/
83-
static __force_inline void tight_loop_contents(void) {}
84-
8577
/*! \brief Helper method to busy-wait for at least the given number of cycles
8678
* \ingroup pico_platform
8779
*
@@ -104,17 +96,6 @@ static inline void busy_wait_at_least_cycles(uint32_t minimum_cycles) {
10496
);
10597
}
10698

107-
// PICO_CONFIG: PICO_NO_FPGA_CHECK, Remove the FPGA platform check for small code size reduction, type=bool, default=1, advanced=true, group=pico_runtime
108-
#ifndef PICO_NO_FPGA_CHECK
109-
#define PICO_NO_FPGA_CHECK 1
110-
#endif
111-
112-
#if PICO_NO_FPGA_CHECK
113-
static inline bool running_on_fpga(void) {return false;}
114-
#else
115-
bool running_on_fpga(void);
116-
#endif
117-
11899
/*! \brief Execute a breakpoint instruction
119100
* \ingroup pico_platform
120101
*/
@@ -150,9 +131,6 @@ static __force_inline uint __get_current_exception(void) {
150131
return exception;
151132
}
152133

153-
#define host_safe_hw_ptr(x) ((uintptr_t)(x))
154-
#define native_safe_hw_ptr(x) host_safe_hw_ptr(x)
155-
156134
/*! \brief Returns the RP2040 chip revision number
157135
* \ingroup pico_platform
158136
* @return the RP2040 chip revision number (1 for B0/B1, 2 for B2)

src/rp2040/pico_platform/platform.c

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,8 @@
66

77
#include "pico.h"
88
#include "hardware/address_mapped.h"
9-
#include "hardware/regs/tbman.h"
109
#include "hardware/regs/sysinfo.h"
1110

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)
21-
bool running_on_fpga(void) {
22-
return (*(io_ro_32 *)TBMAN_BASE) & TBMAN_PLATFORM_FPGA_BITS;
23-
}
24-
#endif
25-
2611
#define MANUFACTURER_RPI 0x927
2712
#define PART_RP2 0x2
2813

src/rp2350/pico_platform/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ cc_library(
2727
deps = [
2828
"//src/rp2350/hardware_regs",
2929
"//src/rp2350/hardware_regs:platform_defs",
30+
"//src/rp2_common/pico_platform_common",
3031
"//src/rp2_common/pico_platform_compiler",
3132
"//src/rp2_common/pico_platform_panic:pico_platform_panic_headers",
3233
"//src/rp2_common/pico_platform_sections",
@@ -44,6 +45,7 @@ cc_library(
4445
"//src/rp2350/hardware_regs",
4546
"//src/rp2350/hardware_regs:platform_defs",
4647
"//src/rp2_common/hardware_base",
48+
"//src/rp2_common/pico_platform_common",
4749
"//src/rp2_common/pico_platform_compiler",
4850
"//src/rp2_common/pico_platform_panic",
4951
"//src/rp2_common/pico_platform_sections",

src/rp2350/pico_platform/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ if (NOT TARGET pico_platform)
2323
hardware_regs
2424
)
2525
pico_mirrored_target_link_libraries(pico_platform INTERFACE
26+
pico_platform_common
2627
pico_platform_compiler
2728
pico_platform_panic
2829
pico_platform_sections

src/rp2350/pico_platform/include/pico/platform.h

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@
2323
#include "pico/platform/compiler.h"
2424
#include "pico/platform/sections.h"
2525
#include "pico/platform/panic.h"
26+
#include "pico/platform/common.h"
2627
#include "hardware/regs/addressmap.h"
2728
#include "hardware/regs/sio.h"
2829
#ifdef __riscv
2930
#include "hardware/regs/rvcsr.h"
3031
#endif
3132

32-
// PICO_CONFIG: PICO_RP2350A, Whether the current board has an RP2350 in an A (30 GPIO) package, type=bool, default=Usually provided via board header, group=pico_platform
33+
// PICO_CONFIG: PICO_RP2350A, Whether the current board has an RP2350 in an A (30 GPIO) package - set to 0 for RP2350in a B (48 GPIO) package, type=bool, default=Usually provided via board header, group=pico_platform
3334
#if 0 // make tooling checks happy
3435
#define PICO_RP2350A 0
3536
#endif
@@ -66,15 +67,6 @@
6667

6768
#ifndef __ASSEMBLER__
6869

69-
/*! \brief No-op function for the body of tight loops
70-
* \ingroup pico_platform
71-
*
72-
* No-op function intended to be called by any tight hardware polling loop. Using this ubiquitously
73-
* makes it much easier to find tight loops, but also in the future \#ifdef-ed support for lockup
74-
* debugging might be added
75-
*/
76-
static __force_inline void tight_loop_contents(void) {}
77-
7870
/*! \brief Helper method to busy-wait for at least the given number of cycles
7971
* \ingroup pico_platform
8072
*
@@ -108,27 +100,6 @@ static inline void busy_wait_at_least_cycles(uint32_t minimum_cycles) {
108100
);
109101
}
110102

111-
// PICO_CONFIG: PICO_NO_FPGA_CHECK, Remove the FPGA platform check for small code size reduction, type=bool, default=1, advanced=true, group=pico_runtime
112-
#ifndef PICO_NO_FPGA_CHECK
113-
#define PICO_NO_FPGA_CHECK 1
114-
#endif
115-
116-
// PICO_CONFIG: PICO_NO_SIM_CHECK, Remove the SIM platform check for small code size reduction, type=bool, default=1, advanced=true, group=pico_runtime
117-
#ifndef PICO_NO_SIM_CHECK
118-
#define PICO_NO_SIM_CHECK 1
119-
#endif
120-
121-
#if PICO_NO_FPGA_CHECK
122-
static inline bool running_on_fpga(void) {return false;}
123-
#else
124-
bool running_on_fpga(void);
125-
#endif
126-
#if PICO_NO_SIM_CHECK
127-
static inline bool running_in_sim(void) {return false;}
128-
#else
129-
bool running_in_sim(void);
130-
#endif
131-
132103
/*! \brief Execute a breakpoint instruction
133104
* \ingroup pico_platform
134105
*/
@@ -213,9 +184,6 @@ __force_inline static bool pico_processor_state_is_nonsecure(void) {
213184
#endif
214185
}
215186

216-
#define host_safe_hw_ptr(x) ((uintptr_t)(x))
217-
#define native_safe_hw_ptr(x) host_safe_hw_ptr(x)
218-
219187
/*! \brief Returns the RP2350 chip revision number
220188
* \ingroup pico_platform
221189
* @return the RP2350 chip revision number (1 for B0/B1, 2 for B2)

src/rp2350/pico_platform/platform.c

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,8 @@
66

77
#include "pico.h"
88
#include "hardware/address_mapped.h"
9-
#include "hardware/regs/tbman.h"
109
#include "hardware/regs/sysinfo.h"
1110

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)
21-
bool __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
26-
bool __attribute__((weak)) running_in_sim(void) {
27-
return (*(io_ro_32 *)TBMAN_BASE) & TBMAN_PLATFORM_HDLSIM_BITS;
28-
}
29-
#endif
30-
3111
#define MANUFACTURER_RPI 0x926
3212
#define PART_RP4 0x4
3313

src/rp2_common/hardware_irq/include/hardware/irq.h

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,6 @@
2323
#define PICO_VTABLE_PER_CORE 0
2424
#endif
2525

26-
// note this is defined here as it simplifies dependencies
27-
// PICO_CONFIG: PICO_MINIMAL_STORED_VECTOR_TABLE, Only store a very minimal vector table in the binary on Arm, type=bool, default=0, advanced=true, group=pico_crt0
28-
#ifndef PICO_MINIMAL_STORED_VECTOR_TABLE
29-
#define PICO_MINIMAL_STORED_VECTOR_TABLE 0
30-
#endif
31-
32-
#if PICO_MINIMAL_STORED_VECTOR_TABLE && (PICO_NO_FLASH && !defined(__riscv))
33-
#if PICO_NUM_VTABLE_IRQS
34-
#warning PICO_NUM_VTABLE_IRQS is specied with PICO_MINIMAL_STORED_VECTOR_TABLE for NO_FLASH Arm binary; ignored
35-
#undef PICO_NUM_VTABLE_IRQS
36-
#endif
37-
#define PICO_NUM_VTABLE_IRQS 0
38-
#else
39-
// PICO_CONFIG: PICO_NUM_VTABLE_IRQS, Number of IRQ handlers in the vector table - can be lowered to save space if you aren't using some higher IRQs, type=int, default=NUM_IRQS, group=hardware_irq
40-
#ifndef PICO_NUM_VTABLE_IRQS
41-
#define PICO_NUM_VTABLE_IRQS NUM_IRQS
42-
#endif
43-
#endif
44-
4526
#ifndef __ASSEMBLER__
4627

4728
#include "pico.h"

0 commit comments

Comments
 (0)