platform.h
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
10#include "hardware/platform_defs.h"
11#include <stddef.h>
12
13#ifdef __unix__
14
15#include <sys/cdefs.h>
16
17#endif
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
23#define __not_in_flash(group)
24#define __not_in_flash_func(func) func
25#define __no_inline_not_in_flash_func(func)
26#define __in_flash(group)
27#define __scratch_x(group)
28#define __scratch_y(group)
29
30#ifndef _MSC_VER
31#define __packed __attribute__((packed))
32#define __packed_aligned __packed __attribute((aligned))
33#else
34// MSVC requires #pragma pack which isn't compatible with a single attribute style define
35#define __packed
36#define __packed_aligned
37#endif
38
39#define __time_critical_func(x) x
40#define __after_data(group)
41
42//int running_on_fpga() { return false; }
43extern void tight_loop_contents();
44
45#ifndef __STRING
46#define __STRING(x) #x
47#endif
48
49#ifndef _MSC_VER
50#ifndef __noreturn
51#define __noreturn __attribute((noreturn))
52#endif
53
54#ifndef __unused
55#define __unused __attribute__((unused))
56#endif
57
58#ifndef __noinline
59#define __noinline __attribute__((noinline))
60#endif
61
62#ifndef __aligned
63#define __aligned(x) __attribute__((aligned(x)))
64#endif
65
66#define PICO_WEAK_FUNCTION_DEF(x) _Pragma(__STRING(weak x))
67#define PICO_WEAK_FUNCTION_IMPL_NAME(x) x
68
69#else
70#ifndef __noreturn
71#define __noreturn __declspec(noreturn)
72#endif
73
74#ifndef __unused
75#define __unused
76#endif
77
78#ifndef __noinline
79#define __noinline __declspec(noinline)
80#endif
81
82#ifndef __aligned
83#define __aligned(x) __declspec(align(x))
84#endif
85
86#ifndef __CONCAT
87#define __CONCAT(x,y) x ## y
88#endif
89
90#define __thread __declspec( thread )
91
92#define PICO_WEAK_FUNCTION_DEF(x) __pragma(comment(linker, __STRING(/alternatename:_##x=_##x##__weak)));
93#define PICO_WEAK_FUNCTION_IMPL_NAME(x) x ## __weak
94
95static __noreturn void __builtin_unreachable() {
96}
97
98#include <intrin.h>
99#define __builtin_clz __lzcnt
100#endif
101
102#ifndef count_of
103#define count_of(a) (sizeof(a)/sizeof((a)[0]))
104#endif
105
106#ifndef MAX
107#define MAX(a, b) ((a)>(b)?(a):(b))
108#endif
109
110#ifndef MIN
111#define MIN(a, b) ((b)>(a)?(a):(b))
112#endif
113
114// abort in our case
115void __noreturn __breakpoint();
116
117void __noreturn panic_unsupported();
118
119void __noreturn panic(const char *fmt, ...);
120
121// arggggghhhh there is a weak function called sem_init used by SDL
122#define sem_init sem_init_alternative
123
124extern uint32_t host_safe_hw_ptr_impl(uintptr_t x);
125// return a 32 bit handle for a raw ptr; DMA chaining for example embeds pointers in 32 bit values
126// which of course does not work if we're running the code natively on a 64 bit platforms. Therefore
127// we provide this macro which allows that code to provide a 64->32 bit mapping in host mode
128#define host_safe_hw_ptr(x) host_safe_hw_ptr_impl((uintptr_t)(x))
129void *decode_host_safe_hw_ptr(uint32_t ptr);
130
131#define __fast_mul(a,b) ((a)*(b))
132
133typedef unsigned int uint;
134
135static inline int32_t __mul_instruction(int32_t a,int32_t b)
136{
137 return a*b;
138}
139
140static inline void __compiler_memory_barrier(void) {
141}
142#ifdef __cplusplus
143}
144#endif
145#endif
void panic_unsupported(void)
Panics with the message "Unsupported".
Definition: platform_base.c:17
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
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 __always_inline void tight_loop_contents(void)
No-op function for the body of tight loops.
Definition: platform.h:347