Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F102815635
utils.c
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Mon, Feb 24, 11:36
Size
1 KB
Mime Type
text/x-c
Expires
Wed, Feb 26, 11:36 (2 d)
Engine
blob
Format
Raw Data
Handle
24331089
Attached To
R2671 HHRI-software
utils.c
View Options
#include "utils.h"
/**
* @brief Endless loop function to stop the execution of the program here.
* @note This function does nothing if CPU_TRAPS_ENABLED is set to zero.
*/
void
utils_TrapCpu
(
void
)
{
#if CPU_TRAPS_ENABLED
while
(
1
)
;
#endif
}
/**
* @brief "Busy wait" delay function
* @param duration: Delay time in [us] (approximative value based on a 168MHz core clock)
*/
void
utils_DelayUs
(
uint32_t
duration
)
{
uint32_t
i
=
0
;
uint32_t
j
=
0
;
for
(
i
=
0
;
i
<=
duration
;
i
++
)
{
for
(
j
=
0
;
j
<=
26
;
j
++
)
{
__asm
{
NOP
};
__asm
{
NOP
};
}
}
}
/**
* @brief "Busy wait" delay function
* @param duration: Delay time in [ms] (approximative value based on a 168MHz core clock).
* @note This delay is approximative, and may last longer if there are many interrupts.
*/
void
utils_DelayMs
(
uint32_t
duration
)
{
uint32_t
i
=
0
;
uint32_t
j
=
0
;
for
(
i
=
0
;
i
<=
duration
;
i
++
)
{
for
(
j
=
0
;
j
<=
33600
;
j
++
)
{
__asm
{
NOP
};
}
}
}
/**
* @brief Saturate a float number between two bounds.
* @param val: value to constrain between two limits.
* @param min: minimum
* @param max: maximum
* @retval None.
*/
void
utils_SaturateF
(
float32_t
*
val
,
float32_t
min
,
float32_t
max
)
{
if
(
*
val
<
min
)
*
val
=
min
;
else
if
(
*
val
>
max
)
*
val
=
max
;
}
/**
* @brief Saturate an integer number between two bounds.
* @param val: value to constrain between the two limits.
* @param min: lower limit.
* @param max: upper limit.
* @retval None.
*/
void
utils_SaturateU
(
uint32_t
*
val
,
uint32_t
min
,
uint32_t
max
)
{
if
(
*
val
<
min
)
*
val
=
min
;
else
if
(
*
val
>
max
)
*
val
=
max
;
}
/**
* @brief Compute the mean of the array values.
* @param array: array of float number to get the mean from.
* @param size: size of the array.
* @retval the mean of the array values.
*/
float32_t
utils_Mean
(
float32_t
*
array
,
int
size
)
{
int
i
;
float32_t
sum
=
0.0f
;
for
(
i
=
0
;
i
<
size
;
i
++
)
sum
+=
array
[
i
];
return
sum
/
(
float32_t
)
size
;
}
Event Timeline
Log In to Comment