#include <PropWare/utility/utility.h>
|
static uint8_t | count_bits (uint32_t par) |
| Count the number of set bits in a parameter. More...
|
|
static uint8_t | count_bits (int32_t par) |
| Count the number of set bits in a parameter. More...
|
|
static uint32_t | measure_time_interval (const register uint32_t start) |
| Determine the number of microseconds passed since a starting point. More...
|
|
static uint32_t | measure_time_interval (const register int32_t start) |
|
static size_t | get_largest_free_block_size (const uint8_t precision=32) |
| Determine the size of the largest block of free memory. More...
|
|
static void | to_lower (char string[]) |
| Convert each alphabetical character in a null-terminated character array to lowercase letters. More...
|
|
static void | to_upper (char string[]) |
| Convert each alphabetical character in a null-terminated character array to uppercase letters. More...
|
|
static const char * | to_string (const bool b) |
| Convert a boolean to the string-literal either "true" or "false" More...
|
|
static int | rom_log (int x) |
| Compute the mathematical expression log2(x). Result is in fixed-point format (16 digits to the left and right of the decimal point. More...
|
|
static unsigned int | reverse (unsigned int x, unsigned int bits=0) |
| Reverse some of the bits in x More...
|
|
static bool | empty (const char string[]) |
|
template<typename T , size_t N> |
static size_t | size_of_array (const T(&array)[N]) |
| Determine the size of an array. More...
|
|
static void | reboot () |
| Perform hard reboot. More...
|
|
static Bit | to_bit (const uint_fast8_t bitNumber) |
|
static bool | bit_read (const uint32_t x, const Bit bit) |
|
template<typename T > |
static void | bit_write (T &x, const Bit bit, const bool value) |
|
template<typename T > |
static void | bit_set (T &x, const Bit bit) |
|
template<typename T > |
static void | bit_clear (T &x, const Bit bit) |
|
Basic, static, convenience methods
- Examples
- StringBuilder_Demo.cpp, and Utility_Demo.cpp.
Definition at line 35 of file utility.h.
◆ count_bits() [1/2]
static uint8_t PropWare::Utility::count_bits |
( |
int32_t |
par | ) |
|
|
static |
Count the number of set bits in a parameter.
- Parameters
-
[in] | par | Parameter whose bits should be counted |
- Returns
- Number of bits that are non-zero in par
Definition at line 63 of file utility.h.
◆ count_bits() [2/2]
static uint8_t PropWare::Utility::count_bits |
( |
uint32_t |
par | ) |
|
|
static |
Count the number of set bits in a parameter.
- Parameters
-
[in] | par | Parameter whose bits should be counted |
- Returns
- Number of bits that are non-zero in par
Definition at line 44 of file utility.h.
◆ get_largest_free_block_size()
static size_t PropWare::Utility::get_largest_free_block_size |
( |
const uint8_t |
precision = 32 | ) |
|
|
static |
Determine the size of the largest block of free memory.
malloc
is used to find free memory. Be aware that the execution time of malloc
is not predictable and it is called repeatedly - so this method can, potentially, take a long time to execute
- Parameters
-
[in] | precision | The precision (in bytes) with which the method will be executed. Result can be off by +/- precision bytes. Lower values will increase execution time |
- Returns
- Returns the size of the largest free block of memory
Definition at line 124 of file utility.h.
◆ measure_time_interval() [1/2]
static uint32_t PropWare::Utility::measure_time_interval |
( |
const register int32_t |
start | ) |
|
|
static |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 109 of file utility.h.
◆ measure_time_interval() [2/2]
static uint32_t PropWare::Utility::measure_time_interval |
( |
const register uint32_t |
start | ) |
|
|
static |
Determine the number of microseconds passed since a starting point.
GCC is very clever about optimizations - sometimes too clever. Be sure that your start variable is declared as volatile
. For instance, the following code is likely to be optimized by GCC in such a way that this function returns 0:
const uint32_t start =
CNT;
foo();
This is because GCC sees that start
is never modified by the call to foo()
, so it optimizes the above code into the following:
Not too helpful :(
Instead, simply add the keyword volatile
to your variable, and all will be good:
const volatile uint32_t start =
CNT;
foo();
- Parameters
-
[in] | start | A value from the system counter (CNT) |
- Returns
- Microseconds since start
Definition at line 102 of file utility.h.
◆ reboot()
static void PropWare::Utility::reboot |
( |
| ) |
|
|
static |
Perform hard reboot.
Also known as reset or power down/up, this will restart the entire chip as if power was just applied. Note that this will reboot all 8 cogs, not just one.
Definition at line 242 of file utility.h.
◆ reverse()
static unsigned int PropWare::Utility::reverse |
( |
unsigned int |
x, |
|
|
unsigned int |
bits = 0 |
|
) |
| |
|
static |
Reverse some of the bits in x
See the rev
assembly instruction
- Parameters
-
[in] | x | Value to be reversed |
[in] | bits | The least significant 32-bits bits will reversed |
- Returns
- A bitwise flip of some of the bits in
x
Definition at line 213 of file utility.h.
◆ rom_log()
static int PropWare::Utility::rom_log |
( |
int |
x | ) |
|
|
static |
Compute the mathematical expression log2(x). Result is in fixed-point format (16 digits to the left and right of the decimal point.
Contributed by Dave Hein
- Parameters
-
[in] | x | Input to log function |
- Returns
- Result of log function
Definition at line 190 of file utility.h.
◆ size_of_array()
template<typename T , size_t N>
static size_t PropWare::Utility::size_of_array |
( |
const T(&) |
array[N] | ) |
|
|
static |
◆ to_lower()
static void PropWare::Utility::to_lower |
( |
char |
string[] | ) |
|
|
static |
Convert each alphabetical character in a null-terminated character array to lowercase letters.
- Parameters
-
[out] | string[] | Characters array to be converted |
Definition at line 156 of file utility.h.
◆ to_string()
static const char* PropWare::Utility::to_string |
( |
const bool |
b | ) |
|
|
static |
Convert a boolean to the string-literal either "true"
or "false"
- Parameters
-
[in] | b | Boolean to be checked |
Definition at line 176 of file utility.h.
◆ to_upper()
static void PropWare::Utility::to_upper |
( |
char |
string[] | ) |
|
|
static |
Convert each alphabetical character in a null-terminated character array to uppercase letters.
- Parameters
-
[out] | string[] | Characters array to be converted |
Definition at line 166 of file utility.h.
The documentation for this class was generated from the following file: