General utilities functions.
More...
#include "FreeRTOS.h"
Go to the source code of this file.
|
#define | STR(x) _STR(x) |
| Stringify a macro.
|
|
#define | _STR(x) #x |
|
#define | STR_SIZE(x) (sizeof(x) -1) |
| Gets length of a macro string.
|
|
|
TickType_t | getTickDifference (TickType_t current_time, TickType_t start_time) |
| Calculate the difference between 2 tick values.
|
|
uint8_t | calculate_chksum (uint8_t *buffer, uint8_t range) |
| Calculate a n-byte message 2's complement checksum.
|
|
uint8_t | cmpBuffs (uint8_t *bufa, size_t len_a, uint8_t *bufb, size_t len_b) |
| Compare 2 buffers.
|
|
uint8_t | isPowerOfTwo (uint8_t x) |
| Check is a number is a power of 2.
|
|
General utilities functions.
- Author
- Henrique Silva
◆ _STR
◆ STR
Stringify a macro.
- Parameters
-
◆ STR_SIZE
#define STR_SIZE |
( |
| x | ) |
(sizeof(x) -1) |
Gets length of a macro string.
- Note
- This macro behaviour is equivalent to strlen()
- Parameters
-
◆ calculate_chksum()
uint8_t calculate_chksum |
( |
uint8_t * | buffer, |
|
|
uint8_t | range ) |
Calculate a n-byte message 2's complement checksum.
The checksum byte is calculated by perfoming a simple 8bit 2's complement of the sum of all previous bytes. Since we're using a unsigned int to hold the checksum value, we only need to subtract all bytes from it.
- Parameters
-
buffer | Pointer to the message bytes. |
range | How many bytes will be used in the calculation. |
- Returns
- Checksum of the specified bytes of the buffer.
◆ cmpBuffs()
uint8_t cmpBuffs |
( |
uint8_t * | bufa, |
|
|
size_t | len_a, |
|
|
uint8_t * | bufb, |
|
|
size_t | len_b ) |
Compare 2 buffers.
- Parameters
-
bufa | First buffer to compare |
len_a | Length of bufa |
bufb | Second buffer to compare |
len_b | Length of bufb |
- Return values
-
0x00 | Buffers are equal |
0xFF | Buffers are different |
◆ getTickDifference()
TickType_t getTickDifference |
( |
TickType_t | current_time, |
|
|
TickType_t | start_time ) |
Calculate the difference between 2 tick values.
Since the tick counter can overflow, we need to check if the current value is higher than the start time before performing any calculations. The Tick counter is expected to overflow at the portMAX_DELAY value
- Parameters
-
current_time | Current tick count |
start_time | Start tick count |
- Returns
- Tick difference between arguments
◆ isPowerOfTwo()
uint8_t isPowerOfTwo |
( |
uint8_t | x | ) |
|
Check is a number is a power of 2.
- Parameters
-
- Return values
-
1 | Number is a power of two |
0 | Number is not a power of two |