@web-font-path: "roboto-debian.css";
Loading...
Searching...
No Matches
platform.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
16#ifndef _PICO_PLATFORM_H
17#define _PICO_PLATFORM_H
18
19#ifndef _PICO_H
20#error pico/platform.h should not be included directly; include pico.h instead
21#endif
22
23#include "pico/platform/compiler.h"
24#include "pico/platform/sections.h"
25#include "pico/platform/panic.h"
26#include "hardware/regs/addressmap.h"
27#include "hardware/regs/sio.h"
28
29// PICO_CONFIG: PICO_STACK_SIZE, Minimum amount of stack space reserved in the linker script for each core. See also PICO_CORE1_STACK_SIZE, min=0x100, default=0x800, advanced=true, group=pico_platform
30#ifndef PICO_STACK_SIZE
31#define PICO_STACK_SIZE _u(0x800)
32#endif
33
34// PICO_CONFIG: PICO_HEAP_SIZE, Minimum amount of heap space reserved by the linker script, min=0x100, default=0x800, advanced=true, group=pico_platform
35#ifndef PICO_HEAP_SIZE
36#define PICO_HEAP_SIZE _u(0x800)
37#endif
38
39// PICO_CONFIG: PICO_NO_RAM_VECTOR_TABLE, Enable/disable the RAM vector table, type=bool, default=0, advanced=true, group=pico_platform
40#ifndef PICO_NO_RAM_VECTOR_TABLE
41#define PICO_NO_RAM_VECTOR_TABLE 0
42#endif
43
44// PICO_CONFIG: PICO_RP2040_B0_SUPPORTED, Whether to include any specific software support for RP2040 B0 revision, type=bool, default=1, advanced=true, group=pico_platform
45#ifndef PICO_RP2040_B0_SUPPORTED
46#define PICO_RP2040_B0_SUPPORTED 1
47#endif
48
49// PICO_CONFIG: PICO_FLOAT_SUPPORT_ROM_V1, Include float support code for RP2040 B0 when that chip revision is supported , type=bool, default=1, advanced=true, group=pico_platform
50#ifndef PICO_FLOAT_SUPPORT_ROM_V1
51#define PICO_FLOAT_SUPPORT_ROM_V1 1
52#endif
53
54// PICO_CONFIG: PICO_DOUBLE_SUPPORT_ROM_V1, Include double support code for RP2040 B0 when that chip revision is supported , type=bool, default=1, advanced=true, group=pico_platform
55#ifndef PICO_DOUBLE_SUPPORT_ROM_V1
56#define PICO_DOUBLE_SUPPORT_ROM_V1 1
57#endif
58
59// PICO_CONFIG: PICO_RP2040_B1_SUPPORTED, Whether to include any specific software support for RP2040 B1 revision, type=bool, default=1, advanced=true, group=pico_platform
60#ifndef PICO_RP2040_B1_SUPPORTED
61#define PICO_RP2040_B1_SUPPORTED 1
62#endif
63
64// PICO_CONFIG: PICO_RP2040_B2_SUPPORTED, Whether to include any specific software support for RP2040 B2 revision, type=bool, default=1, advanced=true, group=pico_platform
65#ifndef PICO_RP2040_B2_SUPPORTED
66#define PICO_RP2040_B2_SUPPORTED 1
67#endif
68
69// PICO_CONFIG: PICO_RP2350_A2_SUPPORTED, Whether to include any specific software support for RP2350 A2 revision, type=bool, default=1, advanced=true, group=pico_platform
70#ifndef PICO_RP2350_A2_SUPPORTED
71#define PICO_RP2350_A2_SUPPORTED 1
72#endif
73
74#ifndef PICO_RAM_VECTOR_TABLE_SIZE
75#define PICO_RAM_VECTOR_TABLE_SIZE (VTABLE_FIRST_IRQ + NUM_IRQS)
76#endif
77
78#ifndef __ASSEMBLER__
79
88
103static inline void busy_wait_at_least_cycles(uint32_t minimum_cycles) {
104 pico_default_asm_volatile(
105 "1: subs %0, #3\n"
106 "bcs 1b\n"
107 : "+l" (minimum_cycles) : : "cc", "memory"
108 );
109}
110
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#if PICO_NO_FPGA_CHECK
117static inline bool running_on_fpga(void) {return false;}
118#else
119bool running_on_fpga(void);
120#endif
121
125static __force_inline void __breakpoint(void) {
126 pico_default_asm_volatile ("bkpt #0" : : : "memory");
127}
128
134__force_inline static uint get_core_num(void) {
135 return (*(uint32_t *) (SIO_BASE + SIO_CPUID_OFFSET));
136}
137
152 uint exception;
153 pico_default_asm_volatile ( "mrs %0, ipsr" : "=l" (exception));
154 return exception;
155}
156
157#define host_safe_hw_ptr(x) ((uintptr_t)(x))
158#define native_safe_hw_ptr(x) host_safe_hw_ptr(x)
159
164uint8_t rp2040_chip_version(void);
165
170static inline uint8_t rp2040_rom_version(void) {
171 GCC_Pragma("GCC diagnostic push")
172 GCC_Pragma("GCC diagnostic ignored \"-Warray-bounds\"")
173 return *(uint8_t*)0x13;
174 GCC_Pragma("GCC diagnostic pop")
175}
176
187__force_inline static int32_t __mul_instruction(int32_t a, int32_t b) {
188#ifdef __riscv
189__asm ("mul %0, %0, %1" : "+l" (a) : "l" (b) : );
190#else
191pico_default_asm ("muls %0, %1" : "+l" (a) : "l" (b) : "cc");
192#endif
193return a;
194}
195
209#define __fast_mul(a, b) __builtin_choose_expr(__builtin_constant_p(b) && !__builtin_constant_p(a), \
210 (__builtin_popcount(b) >= 2 ? __mul_instruction(a,b) : (a)*(b)), \
211 (a)*(b))
212
213#endif // __ASSEMBLER__
214
215#endif
static __force_inline uint __get_current_exception(void)
Get the current exception level on this core.
Definition platform.h:151
#define __force_inline
Attribute to force inlining of a function regardless of optimization level.
Definition compiler.h:125
uint8_t rp2040_chip_version(void)
Returns the RP2040 chip revision number.
Definition platform.c:29
static void busy_wait_at_least_cycles(uint32_t minimum_cycles)
Helper method to busy-wait for at least the given number of cycles.
Definition platform.h:103
static __force_inline uint get_core_num(void)
Get the current core number.
Definition platform.h:134
static __force_inline void __breakpoint(void)
Execute a breakpoint instruction.
Definition platform.h:125
static __force_inline void tight_loop_contents(void)
No-op function for the body of tight loops.
Definition platform.h:87
static __force_inline int32_t __mul_instruction(int32_t a, int32_t b)
Multiply two integers using an assembly MUL instruction.
Definition platform.h:187
static uint8_t rp2040_rom_version(void)
Returns the RP2040 rom version number.
Definition platform.h:170