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