1 /**
2  ****************************************************************************************
3  *
4  * @file ble_arch.h
5  *
6  * @brief This file contains the definitions of the macros and functions that are
7  * architecture dependent.  The implementation of those is implemented in the
8  * appropriate architecture directory.
9  *
10  * Copyright (C) RivieraWaves 2009-2015
11  *
12  *
13  ****************************************************************************************
14  */
15 
16 
17 #ifndef _BLE_ARCH_H_
18 #define _BLE_ARCH_H_
19 
20 /**
21  ****************************************************************************************
22  * @defgroup REFIP
23  * @brief Reference IP Platform
24  *
25  * This module contains reference platform components - REFIP.
26  *
27  *
28  * @{
29  ****************************************************************************************
30  */
31 
32 /**
33  ****************************************************************************************
34  * @defgroup DRIVERS
35  * @ingroup REFIP
36  * @brief Reference IP Platform Drivers
37  *
38  * This module contains the necessary drivers to run the platform with the
39  * RW BT SW protocol stack.
40  *
41  * This has the declaration of the platform architecture API.
42  *
43  *
44  * @{
45  ****************************************************************************************
46  */
47 
48 /*
49  * INCLUDE FILES
50  ****************************************************************************************
51  */
52 #include <stdint.h>        // standard integer definition
53 #include <stdio.h>
54 #include <stdbool.h>
55 #include "rwip_config.h"
56 
57 #define GLOBAL_INT_DISABLE()    \
58 do{\
59      __disable_irq();\  //__set_PRIMASK(1);\
60 }while (0);\
61 
62 #define GLOBAL_INT_RESTORE()    \
63 do{\
64  __enable_irq();\   //  __set_PRIMASK(0);\
65 }while (0);\
66 
67 //#include "compiler.h"      // inline functions
68 #define __INLINE  inline
69 
70 #ifndef NULL
71 #define NULL  0
72 #endif
73 
74 /// define the IRQ handler attribute for this compiler
75 #define __IRQ __attribute__ ((interrupt))
76 /// define the BLE IRQ handler attribute for this compiler
77 #define __BTIRQ
78 
79 /// define the BLE IRQ handler attribute for this compiler
80 #define __BLEIRQ
81 
82 /// define the FIQ handler attribute for this compiler
83 #define __FIQ __attribute__ ((interrupt))
84 /// define size of an empty array (used to declare structure with an array size not defined)
85 #define __ARRAY_EMPTY
86 
87 /// Put a variable in a memory maintained during deep sleep
88 #define __LOWPOWER_SAVED
89 
90 
91 /*
92  * CPU WORD SIZE
93  ****************************************************************************************
94  */
95 /// ARM is a 32-bit CPU
96 #define CPU_WORD_SIZE   4
97 
98 /*
99  * CPU Endianness
100  ****************************************************************************************
101  */
102 /// ARM is little endian
103 #define CPU_LE          1
104 
105 
106 
107 /*
108  * NVDS
109  ****************************************************************************************
110  */
111 
112 /// NVDS
113 #ifdef CFG_NVDS
114 #define PLF_NVDS             1
115 #else // CFG_NVDS
116 #define PLF_NVDS             0
117 #endif // CFG_NVDS
118 
119 
120 /*
121  * UART
122  ****************************************************************************************
123  */
124 
125 /// UART
126 #define PLF_UART             1
127 
128 /*
129  * DEFINES
130  ****************************************************************************************
131  */
132 
133 /// Possible errors detected by FW
134 #define    RESET_NO_ERROR         0x00000000
135 #define    RESET_MEM_ALLOC_FAIL   0xF2F2F2F2
136 
137 /// Reset platform and stay in ROM
138 #define    RESET_TO_ROM           0xA5A5A5A5
139 /// Reset platform and reload FW
140 #define    RESET_AND_LOAD_FW      0xC3C3C3C3
141 
142 /// Exchange memory size limit
143 #define    EM_SIZE_LIMIT          0x8000
144 /*
145  * EXPORTED FUNCTION DECLARATION
146  ****************************************************************************************
147  */
148 
149 /**
150  ****************************************************************************************
151  * @brief Compute size of SW stack used.
152  *
153  * This function is compute the maximum size stack used by SW.
154  *
155  * @return Size of stack used (in bytes)
156  ****************************************************************************************
157  */
158 uint16_t get_stack_usage(void);
159 
160 /**
161  ****************************************************************************************
162  * @brief Re-boot FW.
163  *
164  * This function is used to re-boot the FW when error has been detected, it is the end of
165  * the current FW execution.
166  * After waiting transfers on UART to be finished, and storing the information that
167  * FW has re-booted by itself in a non-loaded area, the FW restart by branching at FW
168  * entry point.
169  *
170  * Note: when calling this function, the code after it will not be executed.
171  *
172  * @param[in] error      Error detected by FW
173  ****************************************************************************************
174  */
175 void platform_reset(uint32_t error);
176 
177 #if PLF_DEBUG
178 /**
179  ****************************************************************************************
180  * @brief Print the assertion error reason and loop forever.
181  *
182  * @param condition C string containing the condition.
183  * @param file C string containing file where the assertion is located.
184  * @param line Line number in the file where the assertion is located.
185  ****************************************************************************************
186  */
187 void eif_assert_err(const char *condition, const char * file, int line);
188 
189 /**
190  ****************************************************************************************
191  * @brief Print the assertion error reason and loop forever.
192  * The parameter value that is causing the assertion will also be disclosed.
193  *
194  * @param param0 parameter value 0.
195  * @param param1 parameter value 1.
196  * @param file C string containing file where the assertion is located.
197  * @param line Line number in the file where the assertion is located.
198  ****************************************************************************************
199  */
200 void eif_assert_param(int param0, int param1, const char * file, int line);
201 
202 /**
203  ****************************************************************************************
204  * @brief Print the assertion warning reason.
205  *
206  * @param param0 parameter value 0.
207  * @param param1 parameter value 1.
208  * @param file C string containing file where the assertion is located.
209  * @param line Line number in the file where the assertion is located.
210  ****************************************************************************************
211  */
212 void eif_assert_warn(int param0, int param1, const char * file, int line);
213 
214 
215 /**
216  ****************************************************************************************
217  * @brief Dump data value into FW.
218  *
219  * @param data start pointer of the data.
220  * @param length data size to dump
221  ****************************************************************************************
222  */
223 void dump_data(uint8_t* data, uint16_t length);
224 #endif //PLF_DEBUG
225 
226 
227 /*
228  * ASSERTION CHECK
229  ****************************************************************************************
230  */
231 #if PLF_DEBUG
232 
233 
234 /// Assertions showing a critical error that could require a full system reset
235 #define ASSERT_ERR(cond)                              \
236     do {                                              \
237         if (!(cond)) {                                \
238             eif_assert_err(#cond, __MODULE__, __LINE__);  \
239         }                                             \
240     } while (0)
241 
242 /// Assertions showing a critical error that could require a full system reset
243 #define ASSERT_INFO(cond, param0, param1)             \
244     do {                                              \
245         if (!(cond)) {                                \
246             eif_assert_param((int)param0, (int)param1, __MODULE__, __LINE__);  \
247         }                                             \
248     } while (0)
249 
250 /// Assertions showing a non-critical problem that has to be fixed by the SW
251 #define ASSERT_WARN(cond, param0, param1)             \
252     do {                                              \
253         if (!(cond)) {                                \
254             eif_assert_warn((int)param0, (int)param1, __MODULE__, __LINE__);  \
255         }                                             \
256     } while (0)
257 
258 #define DUMP_DATA(data, length) \
259     dump_data((uint8_t*)data, length)
260 
261 #else
262 /// Assertions showing a critical error that could require a full system reset
263 #define ASSERT_ERR(cond)
264 
265 /// Assertions showing a critical error that could require a full system reset
266 #define ASSERT_INFO(cond, param0, param1)
267 
268 /// Assertions showing a non-critical problem that has to be fixed by the SW
269 #define ASSERT_WARN(cond, param0, param1)
270 
271 /// DUMP data array present in the SW.
272 #define DUMP_DATA(data, length)
273 #endif //PLF_DEBUG
274 
275 
276 /// Object allocated in shared memory - check linker script
277 #define __SHARED __attribute__ ((section("shram")))
278 
279 // required to define GLOBAL_INT_** macros as inline assembly. This file is included after
280 // definition of ASSERT macros as they are used inside ll.h
281 //#include "ll.h"     // ll definitions
282 /// @} DRIVERS
283 #endif // _BLE_ARCH_H_
284