iLLD_TC29x  1.0
Bsp.h
Go to the documentation of this file.
1 /**
2  * \file Bsp.h
3  * \brief Board support package
4  * \ingroup library_srvsw_sysse_bsp_bsp
5  *
6  * \version iLLD_1_0_0_11_0
7  * \copyright Copyright (c) 2013 Infineon Technologies AG. All rights reserved.
8  *
9  *
10  * IMPORTANT NOTICE
11  *
12  *
13  * Infineon Technologies AG (Infineon) is supplying this file for use
14  * exclusively with Infineon's microcontroller products. This file can be freely
15  * distributed within development tools that are supporting such microcontroller
16  * products.
17  *
18  * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
19  * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
20  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
21  * INFINEON SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
22  * OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
23  *
24  * \defgroup library_srvsw_sysse_bsp_bsp Board support package
25  * This module implements the board support package
26  * \ingroup library_srvsw_sysse_bsp
27  *
28  */
29 
30 #ifndef BSP_H
31 #define BSP_H 1
32 
33 #include "Ifx_Cfg.h" /* Do not remove this include */
34 #include "Cpu/Std/IfxCpu_Intrinsics.h" /* Do not remove this include */
35 #include "_Utilities/Ifx_Assert.h" /* Do not remove this include */
36 
37 #include "Cpu/Std/IfxCpu.h"
38 #include "Port/Std/IfxPort.h"
39 #include "Src/Std/IfxSrc.h"
40 #include "Stm/Std/IfxStm.h"
41 #include "Scu/Std/IfxScuCcu.h"
42 
43 #ifndef BSP_DEFAULT_TIMER
44 /** Defined the default timer used */
45 #define BSP_DEFAULT_TIMER (&MODULE_STM0)
46 #endif
47 
48 /******************************************************************************/
49 /* Function prototypes */
50 /******************************************************************************/
51 
52 /** \addtogroup library_srvsw_sysse_bsp_bsp
53  * \{ */
54 /** \name Interrupt APIs
55  * \{ */
56 IFX_INLINE boolean areInterruptsEnabled(void);
57 IFX_INLINE boolean disableInterrupts(void);
58 IFX_INLINE void enableInterrupts(void);
59 IFX_INLINE void restoreInterrupts(boolean enabled);
61 /** \} */
62 /** \} */
63 
64 /******************************************************************************/
65 /* Functions */
66 /******************************************************************************/
67 
68 /** \brief Return the status of the global interrupts
69  *
70  * \retval TRUE if the global interrupts are enabled.
71  * \retval FALSE if the global interrupts are disabled.
72  *
73  * \see restoreInterrupts(), disableInterrupts()
74  */
76 {
78 }
79 
80 
81 /** \brief Disable the global interrupts
82  *
83  * \retval TRUE if the global interrupts were enabled before the call to the function.
84  * \retval FALSE if the global interrupts are disabled before the call to the function.
85  *
86  * \see areInterruptsEnabled(), restoreInterrupts()
87  */
89 {
90  return IfxCpu_disableInterrupts();
91 }
92 
93 
94 /** \brief Disable the global interrupts forcefully
95  *
96  *
97  * \see areInterruptsEnabled(), restoreInterrupts()
98  */
100 {
102 }
103 
104 
105 /** \brief enable the global interrupts
106  *
107  */
109 {
111 }
112 
113 
114 /** \brief Restore the state of the global interrupts.
115  *
116  * \param enabled if TRUE, re-enable the global interrupts, else do nothing.
117  *
118  * \return None.
119  *
120  * \see areInterruptsEnabled(), disableInterrupts()
121  */
122 IFX_INLINE void restoreInterrupts(boolean enabled)
123 {
124  IfxCpu_restoreInterrupts(enabled);
125 }
126 
127 
128 /******************************************************************************/
129 /* Macros */
130 /******************************************************************************/
131 #define TIMER_COUNT (11) /**< \internal \brief number of timer values defined */
132 #define TIMER_INDEX_10NS (0) /**< \internal \brief Index of the time value 10ns*/
133 #define TIMER_INDEX_100NS (1) /**< \internal \brief Index of the time value 100ns*/
134 #define TIMER_INDEX_1US (2) /**< \internal \brief Index of the time value 1us*/
135 #define TIMER_INDEX_10US (3) /**< \internal \brief Index of the time value 10us*/
136 #define TIMER_INDEX_100US (4) /**< \internal \brief Index of the time value 100us*/
137 #define TIMER_INDEX_1MS (5) /**< \internal \brief Index of the time value 1ms*/
138 #define TIMER_INDEX_10MS (6) /**< \internal \brief Index of the time value 10ms*/
139 #define TIMER_INDEX_100MS (7) /**< \internal \brief Index of the time value 100ms*/
140 #define TIMER_INDEX_1S (8) /**< \internal \brief Index of the time value 1s*/
141 #define TIMER_INDEX_10S (9) /**< \internal \brief Index of the time value 10s*/
142 #define TIMER_INDEX_100S (10) /**< \internal \brief Index of the time value 100s*/
143 
144 /** \internal
145  * Array containing the time constants. This variable should not be used in the application. TimeConst_0s, TimeConst_10ns, ... should be used instead
146  *
147  */
149 
150 /******************************************************************************/
151 /* Function prototypes */
152 /******************************************************************************/
153 /** \addtogroup library_srvsw_sysse_bsp_bsp
154  * \{ */
155 /** \name Time APIs
156  * \{ */
161 IFX_EXTERN void initTime(void);
162 IFX_INLINE boolean isDeadLine(Ifx_TickTime deadLine);
165 IFX_INLINE boolean poll(volatile boolean *test, Ifx_TickTime timeout);
166 IFX_INLINE Ifx_TickTime timingNoInterruptEnd(Ifx_TickTime since, boolean interruptEnabled);
167 IFX_INLINE Ifx_TickTime timingNoInterruptStart(boolean *interruptEnabled);
168 IFX_INLINE void wait(Ifx_TickTime timeout);
169 IFX_EXTERN void waitPoll(void);
170 IFX_EXTERN void waitTime(Ifx_TickTime timeout);
171 
172 /** Prototype for wait() functions */
173 typedef void (*WaitTimeFunction)(Ifx_TickTime timeout);
174 
175 #define TimeConst_0s ((Ifx_TickTime)0) /**< \brief time constant equal to 1s */
176 #define TimeConst_10ns (TimeConst[TIMER_INDEX_10NS]) /**< \brief time constant equal to 10ns */
177 #define TimeConst_100ns (TimeConst[TIMER_INDEX_100NS]) /**< \brief time constant equal to 100ns */
178 #define TimeConst_1us (TimeConst[TIMER_INDEX_1US]) /**< \brief time constant equal to 1us */
179 #define TimeConst_10us (TimeConst[TIMER_INDEX_10US]) /**< \brief time constant equal to 10us */
180 #define TimeConst_100us (TimeConst[TIMER_INDEX_100US]) /**< \brief time constant equal to 100us */
181 #define TimeConst_1ms (TimeConst[TIMER_INDEX_1MS]) /**< \brief time constant equal to 1ms */
182 #define TimeConst_10ms (TimeConst[TIMER_INDEX_10MS]) /**< \brief time constant equal to 10ms */
183 #define TimeConst_100ms (TimeConst[TIMER_INDEX_100MS]) /**< \brief time constant equal to 100ms */
184 #define TimeConst_1s (TimeConst[TIMER_INDEX_1S]) /**< \brief time constant equal to 1s */
185 #define TimeConst_10s (TimeConst[TIMER_INDEX_10S]) /**< \brief time constant equal to 10s */
186 #define TimeConst_100s (TimeConst[TIMER_INDEX_100S]) /**< \brief time constant equal to 100s */
187 
188 /**\}*/
189 /**\}*/
190 /******************************************************************************/
191 /* Functions */
192 /******************************************************************************/
193 
194 /** \brief Return system timer value (critical section).
195  *
196  * The function IfxStm_get() is called in a critical section, disabling
197  * the interrupts. The system timer value is limited to TIME_INFINITE.
198  *
199  * \return Returns system timer value.
200  */
202 {
203  Ifx_TickTime stmNow;
204  boolean interruptState;
205 
206  interruptState = disableInterrupts();
208  restoreInterrupts(interruptState);
209 
210  return stmNow;
211 }
212 
213 
214 /** \brief Return system timer value (without critical section).
215  *
216  * The function IfxStm_get() is called. The system timer value is limited to TIME_INFINITE.
217  *
218  * \return Returns system timer value.
219  */
221 {
222  Ifx_TickTime stmNow;
223 
225 
226  return stmNow;
227 }
228 
229 
230 /** \brief Add 2 Ifx_TickTime values and return the result
231  *
232  * \param a parameter a
233  * \param b parameter b
234  *
235  * \return a + b. If either a or b is TIME_INFINITE, the result is TIME_INFINITE
236  */
238 {
239  Ifx_TickTime result;
240 
241  if ((a == TIME_INFINITE) || (b == TIME_INFINITE))
242  {
243  result = TIME_INFINITE;
244  }
245  else
246  {
247  result = a + b; /* FIXME check for overflow */
248  }
249 
250  return result;
251 }
252 
253 
254 /** \brief Return the elapsed time in ticks.
255  *
256  * Return the elapsed time between the current time and the time passed as parameter
257  *
258  * \return Returns the elapsed time.
259  */
261 {
262  return now() - since;
263 }
264 
265 
266 /** \brief Return the time dead line.
267  *
268  * \param timeout Specifies the dead line from now: Deadline = Now + Timeout
269  *
270  * \return Return the time dead line.
271  */
273 {
274  Ifx_TickTime deadLine;
275 
276  if (timeout == TIME_INFINITE)
277  {
278  deadLine = TIME_INFINITE;
279  }
280  else
281  {
282  deadLine = now() + timeout;
283  }
284 
285  return deadLine;
286 }
287 
288 
289 /** \brief Return the time until the dead line.
290  *
291  * \param deadline Specifies the dead line from now: Deadline = Now + Timeout
292  *
293  * \return Return the time until the dead line.
294  */
296 {
297  Ifx_TickTime timeout;
298 
299  if (deadline == TIME_INFINITE)
300  {
301  timeout = TIME_INFINITE;
302  }
303  else
304  {
305  timeout = deadline - now();
306  }
307 
308  return timeout;
309 }
310 
311 
312 /** \brief Return TRUE if the dead line is over.
313  *
314  * \param deadLine Specifies the dead line.
315  *
316  * \retval TRUE Returns TRUE if the dead line is over
317  * \retval FALSE Returns FALSE if the dead line is not yet over
318  */
320 {
321  boolean result;
322 
323  if (deadLine == TIME_INFINITE)
324  {
325  result = FALSE;
326  }
327  else
328  {
329  result = now() >= deadLine;
330  }
331 
332  return result;
333 }
334 
335 
336 /** \brief Poll a variable for a time.
337  *
338  * \param test Specifies the variable to test.
339  * \param timeout Specifies the maximal time the variable will be tested
340  *
341  * \retval TRUE Returns TRUE if the variable gets TRUE before the timeout elapse
342  * \retval FALSE Returns FALSE if the variable is FALSE as the timeout elapse
343  */
344 IFX_INLINE boolean poll(volatile boolean *test, Ifx_TickTime timeout)
345 {
346  Ifx_TickTime deadLine = getDeadLine(timeout);
347 
348  while ((*test == FALSE) && (isDeadLine(deadLine) == FALSE))
349  {}
350 
351  return *test;
352 }
353 
354 
355 /** \brief Return the elapsed time in system timer ticks, and enable the interrupts.
356  *
357  * The interrupts are enable by the function
358  *
359  * \param since time returned by timingNoInterruptStart()
360  * \param interruptEnabled If TRUE, the interrupts will be enabled before the function exit. This parameter should be set to the value returned by \ref timingNoInterruptStart()
361  *
362  * \return Returns the elapsed time.
363  *
364  * \see timingNoInterruptStart()
365  */
367 {
368  Ifx_TickTime stmNow;
369 
370  stmNow = nowWithoutCriticalSection();
371  restoreInterrupts(interruptEnabled);
372 
373  return stmNow - since;
374 }
375 
376 
377 /** \brief Disable the interrupt and return system timer value.
378  *
379  * The interrupt remains disabled after the function call
380  *
381  * \return Returns system timer value.
382  *
383  * \see timingNoInterruptEnd()
384  */
386 {
387  *interruptEnabled = disableInterrupts();
388 
389  return nowWithoutCriticalSection();
390 }
391 
392 
393 /** \brief Wait for a while.
394  *
395  * \param timeout Specifies the waiting time
396  *
397  * \return None.
398  */
400 {
401  Ifx_TickTime deadLine = getDeadLine(timeout);
402 
403  while (isDeadLine(deadLine) == FALSE)
404  {}
405 }
406 
407 
408 #define PIN_DRIVER_STRONG_SHARP IfxPort_PadDriver_cmosAutomotiveSpeed1
409 #define Pin_setState(pin, mode) IfxPort_setPinState((pin)->port, (pin)->pinIndex, (mode))
410 #define Pin_setGroupState(pin, mask, data) IfxPort_setGroupState((pin)->port, (pin)->pinIndex, (mask), (data))
411 #define Pin_setMode(pin, mode) IfxPort_setPinMode((pin)->port, (pin)->pinIndex, (mode))
412 #define Pin_setDriver(pin, mode) IfxPort_setPinPadDriver((pin)->port, (pin)->pinIndex, (mode))
413 #define Pin_setStateHigh(pin) IfxPort_setPinHigh((pin)->port, (pin)->pinIndex)
414 #define Pin_setStateLow(pin) IfxPort_setPinLow((pin)->port, (pin)->pinIndex)
415 #define Pin_getState(pin) IfxPort_getPinState((pin)->port, (pin)->pinIndex)
416 #define Pin_setGroupModeOutput(pin, mask, mode, outputIdx) IfxPort_setGroupModeOutput((pin)->port, (pin)->pinIndex, (mask), (mode), (outputIdx))
417 #define Pin_setGroupModeInput(pin, mask, mode) IfxPort_setGroupModeInput((pin)->port, (pin)->pinIndex, (mask), (mode))
418 #define Pin_setGroupState(pin, mask, data) IfxPort_setGroupState((pin)->port, (pin)->pinIndex, (mask), (data))
419 #define Pin_getGroupState(pin, mask) IfxPort_getGroupState((pin)->port, (pin)->pinIndex, (mask))
420 #define Pin_enableEmgStop(pin) IfxPort_enableEmergencyStop((pin)->port, (pin)->pinIndex)
421 //------------------------------------------------------------------------------
422 
423 #endif /* BSP_H */