1 /* 2 * Copyright (c) 2022 ASR Microelectronics (Shanghai) Co., Ltd. All rights reserved. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 /** 17 **************************************************************************************** 18 * 19 * @file arch.h 20 * 21 * @brief This file contains the definitions of the macros and functions that are 22 * architecture dependent. The implementation of those is implemented in the 23 * appropriate architecture directory. 24 * 25 **************************************************************************************** 26 */ 27 28 #ifndef _ARCH_H_ 29 #define _ARCH_H_ 30 31 /* 32 * INCLUDE FILES 33 **************************************************************************************** 34 */ 35 #include <stdint.h> // standard integer definition 36 #include <stdio.h> 37 #include "compiler.h" // inline functions 38 #include "sonata_stack_config.h" 39 40 /* 41 * MACRO DEFINES 42 **************************************************************************************** 43 */ 44 // SECTION PARTITIONING 45 #ifdef CFG_SEG 46 #define CRITICAL_FUNC_SEG __attribute__((section("seg_critical_function"))) 47 #else 48 #define CRITICAL_FUNC_SEG 49 #endif // CFG_SEG 50 51 // ARM is a 32-bit CPU 52 #define CPU_WORD_SIZE 4 53 54 // ARM is little endian 55 #define CPU_LE 1 56 57 // debug configuration 58 #if defined(CFG_DBG) 59 #define PLF_DEBUG 1 60 #else // CFG_DBG 61 #define PLF_DEBUG 0 62 #endif // CFG_DBG 63 64 // NVDS configuration 65 #ifdef CFG_NVDS 66 #define PLF_NVDS 1 67 #else // CFG_NVDS 68 #define PLF_NVDS 0 69 #endif // CFG_NVDS 70 71 // ble rom support 72 #if defined(CFG_BLE_ROM) 73 #define BLE_ROM 1 74 #else 75 #define BLE_ROM 0 76 #endif 77 78 // Possible errors detected by FW 79 #define RESET_NO_ERROR 0x00000000 80 #define RESET_MEM_ALLOC_FAIL 0xF2F2F2F2 81 82 // Reset platform and stay in ROM 83 #define RESET_TO_ROM 0xA5A5A5A5 84 // Reset platform and reload FW 85 #define RESET_AND_LOAD_FW 0xC3C3C3C3 86 87 // Exchange memory size limit 88 #define EM_SIZE_LIMIT 0x8000 89 90 // maximum assert number 91 #define ASSERT_ID_LAST 3703s 92 93 /* 94 * EXPORTED FUNCTION DECLARATION 95 **************************************************************************************** 96 */ 97 98 /** 99 **************************************************************************************** 100 * @brief Compute size of SW stack used. 101 * 102 * This function is compute the maximum size stack used by SW. 103 * 104 * @return Size of stack used (in bytes) 105 **************************************************************************************** 106 */ 107 uint16_t get_stack_usage(void); 108 109 /** 110 **************************************************************************************** 111 * @brief Re-boot FW. 112 * 113 * This function is used to re-boot the FW when error has been detected, it is the end of 114 * the current FW execution. 115 * After waiting transfers on UART to be finished, and storing the information that 116 * FW has re-booted by itself in a non-loaded area, the FW restart by branching at FW 117 * entry point. 118 * 119 * Note: when calling this function, the code after it will not be executed. 120 * 121 * @param[in] error Error detected by FW 122 **************************************************************************************** 123 */ 124 void platform_reset(uint32_t error); 125 126 /** 127 **************************************************************************************** 128 * @brief Print the assertion error reason and loop forever. 129 * 130 * @param condition C string containing the condition. 131 * @param file C string containing file where the assertion is located. 132 * @param line Line number in the file where the assertion is located. 133 **************************************************************************************** 134 */ 135 void assert_err(uint16_t id, int cond); 136 137 /** 138 **************************************************************************************** 139 * @brief Print the assertion error reason and loop forever. 140 * The parameter value that is causing the assertion will also be disclosed. 141 * 142 * @param param0 parameter value 0. 143 * @param param1 parameter value 1. 144 * @param file C string containing file where the assertion is located. 145 * @param line Line number in the file where the assertion is located. 146 **************************************************************************************** 147 */ 148 void assert_param(uint16_t id, int param0, int param1); 149 150 /** 151 **************************************************************************************** 152 * @brief Print the assertion warning reason. 153 * 154 * @param param0 parameter value 0. 155 * @param param1 parameter value 1. 156 * @param file C string containing file where the assertion is located. 157 * @param line Line number in the file where the assertion is located. 158 **************************************************************************************** 159 */ 160 void assert_warn(uint16_t id, int param0, int param1); 161 162 /** 163 **************************************************************************************** 164 * @brief Dump data value into FW. 165 * 166 * @param data start pointer of the data. 167 * @param length data size to dump 168 **************************************************************************************** 169 */ 170 void dump_data(uint8_t *data, uint16_t length); 171 172 /* 173 * ASSERTION CHECK 174 **************************************************************************************** 175 */ 176 #if PLF_DEBUG 177 178 extern void (*pf_sonata_assert_err)(uint16_t id, int cond); 179 extern void (*pf_sonata_assert_param)(uint16_t id, int param0, int param1); 180 extern void (*pf_sonata_assert_warn)(uint16_t id, int param0, int param1); 181 182 // Assertions showing a critical error that could require a full system reset 183 #define ASSERT_ERR(id, cond) \ 184 do { \ 185 if (!(cond)) { \ 186 if(pf_sonata_assert_err) \ 187 { \ 188 pf_sonata_assert_err(id,1); \ 189 } \ 190 } \ 191 } while (0) 192 193 // Assertions showing a critical error that could require a full system reset 194 #define ASSERT_INFO(id, cond, param0, param1) \ 195 do { \ 196 if (!(cond)) { \ 197 if(pf_sonata_assert_param) \ 198 { \ 199 pf_sonata_assert_param(id, (int)(param0), (int)(param1)); \ 200 } \ 201 } \ 202 } while (0) 203 204 // Assertions showing a non-critical problem that has to be fixed by the SW 205 #define ASSERT_WARN(id, cond, param0, param1) \ 206 do { \ 207 if (!(cond)) { \ 208 if(pf_sonata_assert_warn) \ 209 { \ 210 pf_sonata_assert_warn(id, (int)(param0), (int)(param1)); \ 211 } \ 212 } \ 213 } while (0) 214 215 // modified for rom code 20200224 216 217 #define DUMP_DATA(data, length) \ 218 dump_data((uint8_t*)(data), length) 219 220 #else 221 // Assertions showing a critical error that could require a full system reset 222 #define ASSERT_ERR(id, cond) 223 224 // Assertions showing a critical error that could require a full system reset 225 #define ASSERT_INFO(id, cond, param0, param1) 226 227 // Assertions showing a non-critical problem that has to be fixed by the SW 228 #define ASSERT_WARN(id, cond, param0, param1) 229 230 // DUMP data array present in the SW. 231 #define DUMP_DATA(data, length) 232 #endif // PLF_DEBUG 233 234 // required to define GLOBAL_INT_** macros as inline assembly. This file is included after 235 // definition of ASSERT macros as they are used inside ll.h 236 237 #ifdef SONATA_RTOS_SUPPORT 238 239 /* Initialises a counting semaphore and set count to 0 */ 240 int rtos_init_semaphore(void **semaphore, int value); 241 242 /* Get (wait/decrement) a semaphore */ 243 int rtos_get_semaphore(void **semaphore, uint32_t timeout_ms); 244 245 /* Set (post/put/increment) a semaphore */ 246 int rtos_set_semaphore(void **semaphore); 247 248 #endif // (SONATA_RTOS_SUPPORT) 249 250 // @} DRIVERS 251 #endif // _ARCH_H_ 252