iLLD_TC27xC  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_0_1_0_10
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);
60 /** \} */
61 /** \} */
62 
63 /******************************************************************************/
64 /* Functions */
65 /******************************************************************************/
66 
67 /** \brief Return the status of the global interrupts
68  *
69  * \retval TRUE if the global interrupts are enabled.
70  * \retval FALSE if the global interrupts are disabled.
71  *
72  * \see restoreInterrupts(), disableInterrupts()
73  */
75 {
77 }
78 
79 
80 /** \brief Disable the global interrupts
81  *
82  * \retval TRUE if the global interrupts were enabled before the call to the function.
83  * \retval FALSE if the global interrupts are disabled before the call to the function.
84  *
85  * \see areInterruptsEnabled(), restoreInterrupts()
86  */
88 {
89  return IfxCpu_disableInterrupts();
90 }
91 
92 
93 /** \brief enable the global interrupts
94  *
95  */
97 {
99 }
100 
101 
102 /** \brief Restore the state of the global interrupts.
103  *
104  * \param enabled if TRUE, re-enable the global interrupts, else do nothing.
105  *
106  * \return None.
107  *
108  * \see areInterruptsEnabled(), disableInterrupts()
109  */
110 IFX_INLINE void restoreInterrupts(boolean enabled)
111 {
112  IfxCpu_restoreInterrupts(enabled);
113 }
114 
115 
116 /******************************************************************************/
117 /* Macros */
118 /******************************************************************************/
119 #define TIMER_COUNT (11) /**< \internal \brief number of timer values defined */
120 #define TIMER_INDEX_10NS (0) /**< \internal \brief Index of the time value 10ns*/
121 #define TIMER_INDEX_100NS (1) /**< \internal \brief Index of the time value 100ns*/
122 #define TIMER_INDEX_1US (2) /**< \internal \brief Index of the time value 1us*/
123 #define TIMER_INDEX_10US (3) /**< \internal \brief Index of the time value 10us*/
124 #define TIMER_INDEX_100US (4) /**< \internal \brief Index of the time value 100us*/
125 #define TIMER_INDEX_1MS (5) /**< \internal \brief Index of the time value 1ms*/
126 #define TIMER_INDEX_10MS (6) /**< \internal \brief Index of the time value 10ms*/
127 #define TIMER_INDEX_100MS (7) /**< \internal \brief Index of the time value 100ms*/
128 #define TIMER_INDEX_1S (8) /**< \internal \brief Index of the time value 1s*/
129 #define TIMER_INDEX_10S (9) /**< \internal \brief Index of the time value 10s*/
130 #define TIMER_INDEX_100S (10) /**< \internal \brief Index of the time value 100s*/
131 
132 /** \internal
133  * Array containing the time constants. This variable should not be used in the application. TimeConst_0s, TimeConst_10ns, ... should be used instead
134  *
135  */
137 
138 /******************************************************************************/
139 /* Function prototypes */
140 /******************************************************************************/
141 /** \addtogroup library_srvsw_sysse_bsp_bsp
142  * \{ */
143 /** \name Time APIs
144  * \{ */
149 IFX_EXTERN void initTime(void);
150 IFX_INLINE boolean isDeadLine(Ifx_TickTime deadLine);
153 IFX_INLINE boolean poll(volatile boolean *test, Ifx_TickTime timeout);
154 IFX_INLINE Ifx_TickTime timingNoInterruptEnd(Ifx_TickTime since, boolean interruptEnabled);
155 IFX_INLINE Ifx_TickTime timingNoInterruptStart(boolean *interruptEnabled);
156 IFX_INLINE void wait(Ifx_TickTime timeout);
157 IFX_EXTERN void waitPoll(void);
158 IFX_EXTERN void waitTime(Ifx_TickTime timeout);
159 
160 /** Prototype for wait() functions */
161 typedef void (*WaitTimeFunction)(Ifx_TickTime timeout);
162 
163 #define TimeConst_0s ((Ifx_TickTime)0) /**< \brief time constant equal to 1s */
164 #define TimeConst_10ns (TimeConst[TIMER_INDEX_10NS]) /**< \brief time constant equal to 10ns */
165 #define TimeConst_100ns (TimeConst[TIMER_INDEX_100NS]) /**< \brief time constant equal to 100ns */
166 #define TimeConst_1us (TimeConst[TIMER_INDEX_1US]) /**< \brief time constant equal to 1us */
167 #define TimeConst_10us (TimeConst[TIMER_INDEX_10US]) /**< \brief time constant equal to 10us */
168 #define TimeConst_100us (TimeConst[TIMER_INDEX_100US]) /**< \brief time constant equal to 100us */
169 #define TimeConst_1ms (TimeConst[TIMER_INDEX_1MS]) /**< \brief time constant equal to 1ms */
170 #define TimeConst_10ms (TimeConst[TIMER_INDEX_10MS]) /**< \brief time constant equal to 10ms */
171 #define TimeConst_100ms (TimeConst[TIMER_INDEX_100MS]) /**< \brief time constant equal to 100ms */
172 #define TimeConst_1s (TimeConst[TIMER_INDEX_1S]) /**< \brief time constant equal to 1s */
173 #define TimeConst_10s (TimeConst[TIMER_INDEX_10S]) /**< \brief time constant equal to 10s */
174 #define TimeConst_100s (TimeConst[TIMER_INDEX_100S]) /**< \brief time constant equal to 100s */
175 
176 /**\}*/
177 /**\}*/
178 /******************************************************************************/
179 /* Functions */
180 /******************************************************************************/
181 
182 /** \brief Return system timer value (critical section).
183  *
184  * The function IfxStm_get() is called in a critical section, disabling
185  * the interrupts. The system timer value is limited to TIME_INFINITE.
186  *
187  * \return Returns system timer value.
188  */
190 {
191  Ifx_TickTime stmNow;
192  boolean interruptState;
193 
194  interruptState = disableInterrupts();
196  restoreInterrupts(interruptState);
197 
198  return stmNow;
199 }
200 
201 
202 /** \brief Return system timer value (without critical section).
203  *
204  * The function IfxStm_get() is called. The system timer value is limited to TIME_INFINITE.
205  *
206  * \return Returns system timer value.
207  */
209 {
210  Ifx_TickTime stmNow;
211 
213 
214  return stmNow;
215 }
216 
217 
218 /** \brief Add 2 Ifx_TickTime values and return the result
219  *
220  * \param a parameter a
221  * \param b parameter b
222  *
223  * \return a + b. If either a or b is TIME_INFINITE, the result is TIME_INFINITE
224  */
226 {
227  Ifx_TickTime result;
228 
229  if ((a == TIME_INFINITE) || (b == TIME_INFINITE))
230  {
231  result = TIME_INFINITE;
232  }
233  else
234  {
235  result = a + b; /* FIXME check for overflow */
236  }
237 
238  return result;
239 }
240 
241 
242 /** \brief Return the elapsed time in ticks.
243  *
244  * Return the elapsed time between the current time and the time passed as parameter
245  *
246  * \return Returns the elapsed time.
247  */
249 {
250  return now() - since;
251 }
252 
253 
254 /** \brief Return the time dead line.
255  *
256  * \param timeout Specifies the dead line from now: Deadline = Now + Timeout
257  *
258  * \return Return the time dead line.
259  */
261 {
262  Ifx_TickTime deadLine;
263 
264  if (timeout == TIME_INFINITE)
265  {
266  deadLine = TIME_INFINITE;
267  }
268  else
269  {
270  deadLine = now() + timeout;
271  }
272 
273  return deadLine;
274 }
275 
276 
277 /** \brief Return the time until the dead line.
278  *
279  * \param deadline Specifies the dead line from now: Deadline = Now + Timeout
280  *
281  * \return Return the time until the dead line.
282  */
284 {
285  Ifx_TickTime timeout;
286 
287  if (deadline == TIME_INFINITE)
288  {
289  timeout = TIME_INFINITE;
290  }
291  else
292  {
293  timeout = deadline - now();
294  }
295 
296  return timeout;
297 }
298 
299 
300 /** \brief Return TRUE if the dead line is over.
301  *
302  * \param deadLine Specifies the dead line.
303  *
304  * \retval TRUE Returns TRUE if the dead line is over
305  * \retval FALSE Returns FALSE if the dead line is not yet over
306  */
308 {
309  boolean result;
310 
311  if (deadLine == TIME_INFINITE)
312  {
313  result = FALSE;
314  }
315  else
316  {
317  result = now() >= deadLine;
318  }
319 
320  return result;
321 }
322 
323 
324 /** \brief Poll a variable for a time.
325  *
326  * \param test Specifies the variable to test.
327  * \param timeout Specifies the maximal time the variable will be tested
328  *
329  * \retval TRUE Returns TRUE if the variable gets TRUE before the timeout elapse
330  * \retval FALSE Returns FALSE if the variable is FALSE as the timeout elapse
331  */
332 IFX_INLINE boolean poll(volatile boolean *test, Ifx_TickTime timeout)
333 {
334  Ifx_TickTime deadLine = getDeadLine(timeout);
335 
336  while ((*test == FALSE) && (isDeadLine(deadLine) == FALSE))
337  {}
338 
339  return *test;
340 }
341 
342 
343 /** \brief Return the elapsed time in system timer ticks, and enable the interrupts.
344  *
345  * The interrupts are enable by the function
346  *
347  * \param since time returned by timingNoInterruptStart()
348  * \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()
349  *
350  * \return Returns the elapsed time.
351  *
352  * \see timingNoInterruptStart()
353  */
355 {
356  Ifx_TickTime stmNow;
357 
358  stmNow = nowWithoutCriticalSection();
359  restoreInterrupts(interruptEnabled);
360 
361  return stmNow - since;
362 }
363 
364 
365 /** \brief Disable the interrupt and return system timer value.
366  *
367  * The interrupt remains disabled after the function call
368  *
369  * \return Returns system timer value.
370  *
371  * \see timingNoInterruptEnd()
372  */
374 {
375  *interruptEnabled = disableInterrupts();
376 
377  return nowWithoutCriticalSection();
378 }
379 
380 
381 /** \brief Wait for a while.
382  *
383  * \param timeout Specifies the waiting time
384  *
385  * \return None.
386  */
388 {
389  Ifx_TickTime deadLine = getDeadLine(timeout);
390 
391  while (isDeadLine(deadLine) == FALSE)
392  {}
393 }
394 
395 
396 #define PIN_DRIVER_STRONG_SHARP IfxPort_PadDriver_cmosAutomotiveSpeed1
397 #define Pin_setState(pin, mode) IfxPort_setPinState((pin)->port, (pin)->pinIndex, (mode))
398 #define Pin_setGroupState(pin, mask, data) IfxPort_setGroupState((pin)->port, (pin)->pinIndex, (mask), (data))
399 #define Pin_setMode(pin, mode) IfxPort_setPinMode((pin)->port, (pin)->pinIndex, (mode))
400 #define Pin_setDriver(pin, mode) IfxPort_setPinPadDriver((pin)->port, (pin)->pinIndex, (mode))
401 #define Pin_setStateHigh(pin) IfxPort_setPinHigh((pin)->port, (pin)->pinIndex)
402 #define Pin_setStateLow(pin) IfxPort_setPinLow((pin)->port, (pin)->pinIndex)
403 #define Pin_getState(pin) IfxPort_getPinState((pin)->port, (pin)->pinIndex)
404 #define Pin_setGroupModeOutput(pin, mask, mode) IfxPort_setGroupModeOutput((pin)->port, (pin)->pinIndex, (mask), (mode))
405 #define Pin_setGroupModeInput(pin, mask, mode) IfxPort_setGroupModeInput((pin)->port, (pin)->pinIndex, (mask), (mode))
406 #define Pin_setGroupState(pin, mask, data) IfxPort_setGroupState((pin)->port, (pin)->pinIndex, (mask), (data))
407 #define Pin_getGroupState(pin, mask) IfxPort_getGroupState((pin)->port, (pin)->pinIndex, (mask))
408 #define Pin_enableEmgStop(pin) IfxPort_enableEmergencyStop((pin)->port, (pin)->pinIndex)
409 //------------------------------------------------------------------------------
410 
411 #endif /* BSP_H */