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
7#ifndef _PICO_PLATFORM_H_
8#define _PICO_PLATFORM_H_
9
19#include "hardware/platform_defs.h"
20
21// Marker for builds targeting the RP2040
22#define PICO_RP2040 1
23
24// PICO_CONFIG: PICO_STACK_SIZE, Stack Size, min=0x100, default=0x800, advanced=true, group=pico_platform
25#ifndef PICO_STACK_SIZE
26#define PICO_STACK_SIZE _u(0x800)
27#endif
28
29// PICO_CONFIG: PICO_HEAP_SIZE, Heap size to reserve, min=0x100, default=0x800, advanced=true, group=pico_platform
30#ifndef PICO_HEAP_SIZE
31#define PICO_HEAP_SIZE _u(0x800)
32#endif
33
34// PICO_CONFIG: PICO_NO_RAM_VECTOR_TABLE, Enable/disable the RAM vector table, type=bool, default=0, advanced=true, group=pico_platform
35#ifndef PICO_NO_RAM_VECTOR_TABLE
36#define PICO_NO_RAM_VECTOR_TABLE 0
37#endif
38
39// 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
40#ifndef PICO_RP2040_B0_SUPPORTED
41#define PICO_RP2040_B0_SUPPORTED 1
42#endif
43
44// 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
45#ifndef PICO_FLOAT_SUPPORT_ROM_V1
46#define PICO_FLOAT_SUPPORT_ROM_V1 1
47#endif
48
49// 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
50#ifndef PICO_DOUBLE_SUPPORT_ROM_V1
51#define PICO_DOUBLE_SUPPORT_ROM_V1 1
52#endif
53
54
55// 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
56#ifndef PICO_RP2040_B1_SUPPORTED
57#define PICO_RP2040_B1_SUPPORTED 1
58#endif
59
60// 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
61#ifndef PICO_RP2040_B2_SUPPORTED
62#define PICO_RP2040_B2_SUPPORTED 1
63#endif
64
65// --- remainder of file is not included by assembly code ---
66
67#ifndef __ASSEMBLER__
68
69#include <sys/cdefs.h>
70#include "pico/types.h"
71
72#ifdef __cplusplus
73extern "C" {
74#endif
75
82#define __isr
83
96#define __after_data(group) __attribute__((section(".after_data." group)))
97
110#define __not_in_flash(group) __attribute__((section(".time_critical." group)))
111
127#define __scratch_x(group) __attribute__((section(".scratch_x." group)))
128
144#define __scratch_y(group) __attribute__((section(".scratch_y." group)))
145
161#define __uninitialized_ram(group) __attribute__((section(".uninitialized_ram." #group))) group
162
175#define __in_flash(group) __attribute__((section(".flashdata" group)))
176
191#define __not_in_flash_func(func_name) __not_in_flash(__STRING(func_name)) func_name
192
210#define __time_critical_func(func_name) __not_in_flash_func(func_name)
211
224#define __no_inline_not_in_flash_func(func_name) __noinline __not_in_flash_func(func_name)
225
226#define __packed_aligned __packed __aligned(4)
227
236#if defined(__GNUC__) && __GNUC__ <= 7
237#define __force_inline inline __always_inline
238#else
239#define __force_inline __always_inline
240#endif
241
245#ifndef count_of
246#define count_of(a) (sizeof(a)/sizeof((a)[0]))
247#endif
248
252#ifndef MAX
253#define MAX(a, b) ((a)>(b)?(a):(b))
254#endif
255
259#ifndef MIN
260#define MIN(a, b) ((b)>(a)?(a):(b))
261#endif
262
266static inline void __breakpoint(void) {
267 __asm__("bkpt #0");
268}
269
283 __asm__ volatile ("" : : : "memory");
284}
285
294#define host_safe_hw_ptr(x) ((uintptr_t)(x))
295#define native_safe_hw_ptr(x) host_safe_hw_ptr(x)
296
297
302void __attribute__((noreturn)) panic_unsupported(void);
303
313void __attribute__((noreturn)) panic(const char *fmt, ...);
314
315// PICO_CONFIG: PICO_NO_FPGA_CHECK, Remove the FPGA platform check for small code size reduction, type=bool, default=0, advanced=true, group=pico_runtime
316#ifndef PICO_NO_FPGA_CHECK
317#define PICO_NO_FPGA_CHECK 0
318#endif
319
320#if PICO_NO_FPGA_CHECK
321static inline bool running_on_fpga(void) {return false;}
322#else
323bool running_on_fpga(void);
324#endif
325
330uint8_t rp2040_chip_version(void);
331
336static inline uint8_t rp2040_rom_version(void) {
337 return *(uint8_t*)0x13;
338}
339
348
359__force_inline static int32_t __mul_instruction(int32_t a, int32_t b) {
360 asm ("mul %0, %1" : "+l" (a) : "l" (b) : );
361 return a;
362}
363
377#define __fast_mul(a, b) __builtin_choose_expr(__builtin_constant_p(b) && !__builtin_constant_p(a), \
378(__builtin_popcount(b) >= 2 ? __mul_instruction(a,b) : (a)*(b)), \
379(a)*(b))
380
387#define __check_type_compatible(type_a, type_b) static_assert(__builtin_types_compatible_p(type_a, type_b), __STRING(type_a) " is not compatible with " __STRING(type_b));
388
395
396#define WRAPPER_FUNC(x) __wrap_ ## x
397#define REAL_FUNC(x) __real_ ## x
398
399#ifdef __cplusplus
400}
401#endif
402
403#else // __ASSEMBLER__
404
405#define WRAPPER_FUNC_NAME(x) __wrap_##x
406#define SECTION_NAME(x) .text.##x
407#define RAM_SECTION_NAME(x) .time_critical.##x
408
409#endif // !__ASSEMBLER__
410
411#endif
#define __force_inline
Attribute to force inlining of a function regardless of optimization level.
Definition: platform.h:239
void panic_unsupported(void)
Panics with the message "Unsupported".
Definition: platform_base.c:17
uint8_t rp2040_chip_version(void)
Returns the RP2040 chip revision number.
Definition: platform.c:29
static __always_inline int32_t __mul_instruction(int32_t a, int32_t b)
Multiply two integers using an assembly MUL instruction.
Definition: platform.h:359
static void __breakpoint(void)
Execute a breakpoint instruction.
Definition: platform.h:266
uint __get_current_exception(void)
Get the current exception level on this core.
static __always_inline void __compiler_memory_barrier(void)
Ensure that the compiler does not move memory access across this method call.
Definition: platform.h:282
void panic(const char *fmt,...)
Displays a panic message and halts execution.
Definition: platform_base.c:25
static uint8_t rp2040_rom_version(void)
Returns the RP2040 rom version number.
Definition: platform.h:336
static __always_inline void tight_loop_contents(void)
No-op function for the body of tight loops.
Definition: platform.h:347