openMMC
Open Source Modular MMC for AMCs
Loading...
Searching...
No Matches
utils.h File Reference

General utilities functions. More...

#include "FreeRTOS.h"
Include dependency graph for utils.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#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.
 

Functions

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.
 

Detailed Description

General utilities functions.

Author
Henrique Silva

Macro Definition Documentation

◆ _STR

#define _STR ( x)    #x

◆ STR

#define STR ( x)    _STR(x)

Stringify a macro.

Parameters
xValue to be stringifyed

◆ STR_SIZE

#define STR_SIZE ( x)    (sizeof(x) -1)

Gets length of a macro string.

Note
This macro behaviour is equivalent to strlen()
Parameters
xMacro string

Function Documentation

◆ 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
bufferPointer to the message bytes.
rangeHow 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
bufaFirst buffer to compare
len_aLength of bufa
bufbSecond buffer to compare
len_bLength of bufb
Return values
0x00Buffers are equal
0xFFBuffers 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_timeCurrent tick count
start_timeStart tick count
Returns
Tick difference between arguments

◆ isPowerOfTwo()

uint8_t isPowerOfTwo ( uint8_t x)

Check is a number is a power of 2.

Parameters
xNumber to be tested
Return values
1Number is a power of two
0Number is not a power of two