@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
15
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
24#include "pico/platform/sections.h"
25#include "pico/platform/panic.h"
27#include "hardware/regs/addressmap.h"
28#include "hardware/regs/sio.h"
29
30// 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
31#ifndef PICO_STACK_SIZE
32#define PICO_STACK_SIZE _u(0x800)
33#endif
34
35// PICO_CONFIG: PICO_HEAP_SIZE, Minimum amount of heap space reserved by the linker script, min=0x100, default=0x800, advanced=true, group=pico_platform
36#ifndef PICO_HEAP_SIZE
37#define PICO_HEAP_SIZE _u(0x800)
38#endif
39
40// PICO_CONFIG: PICO_NO_RAM_VECTOR_TABLE, Enable/disable the RAM vector table, type=bool, default=0, advanced=true, group=pico_platform
41#ifndef PICO_NO_RAM_VECTOR_TABLE
42#define PICO_NO_RAM_VECTOR_TABLE 0
43#endif
44
45// 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
46#ifndef PICO_RP2040_B0_SUPPORTED
47#define PICO_RP2040_B0_SUPPORTED 1
48#endif
49
50// 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
51#ifndef PICO_FLOAT_SUPPORT_ROM_V1
52#define PICO_FLOAT_SUPPORT_ROM_V1 1
53#endif
54
55// 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
56#ifndef PICO_DOUBLE_SUPPORT_ROM_V1
57#define PICO_DOUBLE_SUPPORT_ROM_V1 1
58#endif
59
60// 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
61#ifndef PICO_RP2040_B1_SUPPORTED
62#define PICO_RP2040_B1_SUPPORTED 1
63#endif
64
65// 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
66#ifndef PICO_RP2040_B2_SUPPORTED
67#define PICO_RP2040_B2_SUPPORTED 1
68#endif
69
70// PICO_CONFIG: PICO_CLKDIV_ROUND_NEAREST, True if floating point clock divisors should be rounded to the nearest possible clock divisor by default rather than rounding down, type=bool, default=1, group=pico_platform
71#ifndef PICO_CLKDIV_ROUND_NEAREST
72#define PICO_CLKDIV_ROUND_NEAREST 1
73#endif
74
75#ifndef __ASSEMBLER__
76
77#ifdef __cplusplus
78extern "C" {
79#endif
94static inline void busy_wait_at_least_cycles(uint32_t minimum_cycles) {
95 pico_default_asm_volatile(
96 "1: subs %0, #3\n"
97 "bcs 1b\n"
98 : "+l" (minimum_cycles) : : "cc", "memory"
99 );
100}
101
105static __force_inline void __breakpoint(void) {
106 pico_default_asm_volatile ("bkpt #0" : : : "memory");
107}
108
114__force_inline static uint get_core_num(void) {
115 return (*(uint32_t *) (SIO_BASE + SIO_CPUID_OFFSET));
116}
117
132 uint exception;
133 pico_default_asm_volatile ( "mrs %0, ipsr" : "=l" (exception));
134 return exception;
135}
136
141uint8_t rp2040_chip_version(void);
142
147static inline uint8_t rp2040_rom_version(void) {
148 GCC_Pragma("GCC diagnostic push")
149 GCC_Pragma("GCC diagnostic ignored \"-Warray-bounds\"")
150 return *(uint8_t*)0x13;
151 GCC_Pragma("GCC diagnostic pop")
152}
153
164__force_inline static int32_t __mul_instruction(int32_t a, int32_t b) {
165#ifdef __riscv
166__asm ("mul %0, %0, %1" : "+l" (a) : "l" (b) : );
167#else
168pico_default_asm ("muls %0, %1" : "+l" (a) : "l" (b) : "cc");
169#endif
170return a;
171}
172
186#define __fast_mul(a, b) __builtin_choose_expr(__builtin_constant_p(b) && !__builtin_constant_p(a), \
187 (__builtin_popcount(b) >= 2 ? __mul_instruction(a,b) : (a)*(b)), \
188 (a)*(b))
189
190#ifdef __cplusplus
191}
192#endif
193
194#endif // __ASSEMBLER__
195
196#endif
Macros and definitions common to all rp2 platforms but not specific to any library.
Macros and definitions (and functions when included by non assembly code) to adapt for different comp...
static __force_inline uint __get_current_exception(void)
Get the current exception level on this core.
Definition platform.h:131
#define __force_inline
Attribute to force inlining of a function regardless of optimization level.
Definition compiler.h:128
uint8_t rp2040_chip_version(void)
Returns the RP2040 chip revision number.
Definition platform.c:14
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:94
static __force_inline uint get_core_num(void)
Get the current core number.
Definition platform.h:114
static __force_inline void __breakpoint(void)
Execute a breakpoint instruction.
Definition platform.h:105
static __force_inline int32_t __mul_instruction(int32_t a, int32_t b)
Multiply two integers using an assembly MUL instruction.
Definition platform.h:164
static uint8_t rp2040_rom_version(void)
Returns the RP2040 rom version number.
Definition platform.h:147