1 //***************************************************************************** 2 // 3 //! @file am_hal_global.c 4 //! 5 //! @brief Locate global variables here. 6 //! 7 //! This module contains global variables that are used throughout the HAL, 8 //! but not necessarily those designated as const (which typically end up in 9 //! flash). Consolidating globals here will make it easier to manage them. 10 //! 11 //! @addtogroup global3p Global - Global Variables 12 //! @ingroup apollo3p_hal 13 //! @{ 14 // 15 //***************************************************************************** 16 17 //***************************************************************************** 18 // 19 // Copyright (c) 2024, Ambiq Micro, Inc. 20 // All rights reserved. 21 // 22 // Redistribution and use in source and binary forms, with or without 23 // modification, are permitted provided that the following conditions are met: 24 // 25 // 1. Redistributions of source code must retain the above copyright notice, 26 // this list of conditions and the following disclaimer. 27 // 28 // 2. Redistributions in binary form must reproduce the above copyright 29 // notice, this list of conditions and the following disclaimer in the 30 // documentation and/or other materials provided with the distribution. 31 // 32 // 3. Neither the name of the copyright holder nor the names of its 33 // contributors may be used to endorse or promote products derived from this 34 // software without specific prior written permission. 35 // 36 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 37 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 38 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 39 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 40 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 41 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 42 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 43 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 44 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 45 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 46 // POSSIBILITY OF SUCH DAMAGE. 47 // 48 // This is part of revision release_sdk_3_2_0-dd5f40c14b of the AmbiqSuite Development Package. 49 // 50 //***************************************************************************** 51 #ifndef AM_HAL_GLOBAL_H 52 #define AM_HAL_GLOBAL_H 53 54 #ifdef __cplusplus 55 extern "C" 56 { 57 #endif 58 59 //***************************************************************************** 60 // 61 //! Include the SDK global version information. 62 // 63 //***************************************************************************** 64 #include "../../am_sdk_version.h" 65 66 //***************************************************************************** 67 // 68 //! Device definitions 69 // 70 //***************************************************************************** 71 #define AM_HAL_DEVICE_NAME "Apollo3 Blue Plus" 72 73 //***************************************************************************** 74 // 75 // Macro definitions 76 // 77 //***************************************************************************** 78 //! Utility for compile time assertions 79 //! Will cause divide by 0 error at build time 80 #define _AM_ASSERT_CONCAT_(a, b) a##b 81 #define _AM_ASSERT_CONCAT(a, b) _AM_ASSERT_CONCAT_(a, b) 82 #define am_ct_assert(e) enum { _AM_ASSERT_CONCAT(assert_line_, __LINE__) = 1/(!!(e)) } 83 84 //***************************************************************************** 85 // 86 //! Macros to determine compiler version information 87 // 88 //***************************************************************************** 89 // 90 // Since the stringize operator itself does not first expand macros, two levels 91 // of indirection are required in order to fully resolve the pre-defined 92 // compiler (integer) macros. The 1st level expands the macro, and the 2nd 93 // level actually stringizes it. 94 // This method will also work even if the argument is not a macro. However, if 95 // the argument is already a string, the string will end up with inserted quote 96 // marks. 97 // 98 #define STRINGIZE_VAL(n) STRINGIZE_VAL2(n) 99 #define STRINGIZE_VAL2(n) #n 100 101 // 102 // The Arm6 compiler defines both GNUC and ARMCC_VERSION. So check ARMCC first. 103 // 104 #if defined(__ARMCC_VERSION) 105 #define COMPILER_VERSION ("ARMCC " STRINGIZE_VAL(__ARMCC_VERSION)) 106 #elif __GNUC__ 107 #define COMPILER_VERSION ("GCC " __VERSION__) 108 #elif defined(__KEIL__) 109 #define COMPILER_VERSION "KEIL_CARM " STRINGIZE_VAL(__CA__) 110 #elif defined(__IAR_SYSTEMS_ICC__) 111 #define COMPILER_VERSION __VERSION__ 112 #else 113 #define COMPILER_VERSION "Compiler unknown" 114 #endif 115 116 //***************************************************************************** 117 // 118 //! Utility Macros 119 // 120 //***************************************************************************** 121 // As long as the two values are not apart by more that 2^31, this should give 122 // correct result, taking care of wraparound 123 #define AM_HAL_U32_GREATER(val1, val2) ((int32_t)((int32_t)(val1) - (int32_t)(val2)) > 0) 124 #define AM_HAL_U32_SMALLER(val1, val2) ((int32_t)((int32_t)(val1) - (int32_t)(val2)) < 0) 125 126 //****************************************************************************** 127 // 128 //! Global typedefs 129 // 130 //****************************************************************************** 131 typedef union 132 { 133 uint32_t u32; 134 struct 135 { 136 uint32_t resvd : 7; // [6:0] 137 uint32_t bAMREGS : 1; // [7] 138 uint32_t Revision : 8; // [15:8] 139 uint32_t Minor : 8; // [23:16] 140 uint32_t Major : 8; // [31:24] 141 } s; 142 } am_hal_version_t; 143 144 typedef union 145 { 146 uint32_t u32; 147 struct 148 { 149 uint32_t magic : 24; 150 uint32_t bInit : 1; 151 uint32_t bEnable : 1; 152 uint32_t resv : 6; 153 } s; 154 } am_hal_handle_prefix_t; 155 156 //***************************************************************************** 157 // 158 //! Global Variables extern declarations. 159 // 160 //***************************************************************************** 161 extern const uint8_t g_ui8HALcompiler[]; 162 extern const am_hal_version_t g_ui32HALversion; 163 164 #if (defined (__ARMCC_VERSION)) && (__ARMCC_VERSION < 6000000) 165 __asm void 166 am_hal_triple_read( uint32_t ui32TimerAddr, uint32_t ui32Data[]); 167 #elif (defined (__ARMCC_VERSION)) && (__ARMCC_VERSION >= 6000000) 168 void 169 am_hal_triple_read(uint32_t ui32TimerAddr, uint32_t ui32Data[]); 170 #elif defined(__GNUC_STDC_INLINE__) 171 __attribute__((naked)) 172 173 //***************************************************************************** 174 //! @brief 175 //! 176 //! @param ui32TimerAddr 177 //! @param ui32Data 178 //***************************************************************************** 179 void 180 am_hal_triple_read(uint32_t ui32TimerAddr, uint32_t ui32Data[]); 181 #elif defined(__IAR_SYSTEMS_ICC__) 182 __stackless void 183 am_hal_triple_read( uint32_t ui32TimerAddr, uint32_t ui32Data[]); 184 #else 185 #error Compiler is unknown, please contact Ambiq support team 186 #endif 187 188 #ifdef __cplusplus 189 } 190 #endif 191 //***************************************************************************** 192 // 193 // End Doxygen group. 194 //! @} 195 // 196 //***************************************************************************** 197 198 #endif // AM_HAL_GLOBAL_H 199