1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef _STM_TAGGED_PTR_H_ 18 #define _STM_TAGGED_PTR_H_ 19 20 #include <stdbool.h> 21 #include <stdint.h> 22 23 24 #define TAG 0x80000000UL //no valid pointers that we care about in STM32F are at 0x80000000 or further 25 26 typedef uintptr_t TaggedPtr; 27 taggedPtrToPtr(TaggedPtr tPtr)28static inline void *taggedPtrToPtr(TaggedPtr tPtr) 29 { 30 return (void*)tPtr; 31 } 32 taggedPtrToUint(TaggedPtr tPtr)33static inline uintptr_t taggedPtrToUint(TaggedPtr tPtr) 34 { 35 return tPtr &~ TAG; 36 } 37 taggedPtrIsPtr(TaggedPtr tPtr)38static inline bool taggedPtrIsPtr(TaggedPtr tPtr) 39 { 40 return !(tPtr & TAG); 41 } 42 taggedPtrIsUint(TaggedPtr tPtr)43static inline bool taggedPtrIsUint(TaggedPtr tPtr) 44 { 45 return !taggedPtrIsPtr(tPtr); 46 } 47 taggedPtrMakeFromPtr(const void * ptr)48static inline TaggedPtr taggedPtrMakeFromPtr(const void* ptr) 49 { 50 return (uintptr_t)ptr; 51 } 52 taggedPtrMakeFromUint(uintptr_t ptr)53static inline TaggedPtr taggedPtrMakeFromUint(uintptr_t ptr) 54 { 55 return ptr | TAG; 56 } 57 58 #endif 59 60