-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin' into 81-bmsfaultpriority-v2
- Loading branch information
Showing
8 changed files
with
86 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
repos: | ||
- repo: local | ||
hooks: | ||
- id: clang_restage | ||
name: Restage formatted files | ||
entry: clang_restage | ||
language: system | ||
pass_filenames: false | ||
always_run: true | ||
repos: | ||
- repo: local | ||
hooks: | ||
- id: clang_restage | ||
name: Restage formatted files | ||
entry: clang_restage | ||
language: system | ||
pass_filenames: false | ||
always_run: true | ||
stages: [pre-commit] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,29 @@ | ||
#ifndef C_UTILS | ||
#define C_UTILS | ||
|
||
/* | ||
* Will retrieve the container of a certain pointer given the container type and | ||
* its pointer Trick pulled from Linux Kernel | ||
*/ | ||
#define CONTAINER_OF(ptr, type, member) \ | ||
((type *)((char *)(ptr) - offsetof(type, member))) | ||
|
||
#endif /* C_UTILS */ | ||
|
||
void endian_swap(void *ptr, int size); | ||
|
||
/// @brief Reverses the bit order of a byte | ||
/// @param b byte | ||
/// @return the same byte but wuth the bits reversed | ||
unsigned char reverse_bits(unsigned char b); | ||
#ifndef C_UTILS | ||
#define C_UTILS | ||
|
||
/* | ||
* Will retrieve the container of a certain pointer given the container type and | ||
* its pointer Trick pulled from Linux Kernel | ||
*/ | ||
#define CONTAINER_OF(ptr, type, member) \ | ||
((type *)((char *)(ptr) - offsetof(type, member))) | ||
|
||
/* | ||
* Gets a bit of a binary number at desired location | ||
*/ | ||
#define NER_GET_BIT(num, bit) ((num >> bit) & 1) | ||
|
||
/* | ||
* Sets a bit of a binary number at desired location | ||
*/ | ||
#define NER_SET_BIT(num, bit) \ | ||
bit < (sizeof(num) * 8) ? (num |= (1UL << bit)) : num | ||
|
||
void endian_swap(void *ptr, int size); | ||
|
||
/// @brief Reverses the bit order of a byte | ||
/// @param b byte | ||
/// @return the same byte but wuth the bits reversed | ||
unsigned char reverse_bits(unsigned char b); | ||
|
||
#endif /* C_UTILS */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#include <stdio.h> | ||
#include "simple_ema.h" | ||
|
||
void ema_filter(float current_value, float *previous_ema, float alpha) | ||
{ | ||
*previous_ema = | ||
(alpha * current_value) + ((1 - alpha) * (*previous_ema)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#ifndef SIMPLE_EMA | ||
#define SIMPLE_EMA | ||
|
||
// Exponential Moving Average Lowpass Filter | ||
void ema_filter(float current_value, float *previous_ema, float alpha); | ||
|
||
#endif /* SIMPLE_EMA */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,20 @@ | ||
#include "c_utils.h" | ||
|
||
void endian_swap(void *ptr, int size) | ||
{ | ||
char *p = (char *)ptr; | ||
char tmp; | ||
for (int i = 0; i < size / 2; i++) { | ||
tmp = p[i]; | ||
p[i] = p[size - i - 1]; | ||
p[size - i - 1] = tmp; | ||
} | ||
} | ||
|
||
unsigned char reverse_bits(unsigned char b) | ||
{ | ||
b = (b & 0xF0) >> 4 | (b & 0x0F) << 4; | ||
b = (b & 0xCC) >> 2 | (b & 0x33) << 2; | ||
b = (b & 0xAA) >> 1 | (b & 0x55) << 1; | ||
return b; | ||
#include "c_utils.h" | ||
|
||
void endian_swap(void *ptr, int size) | ||
{ | ||
char *p = (char *)ptr; | ||
char tmp; | ||
for (int i = 0; i < size / 2; i++) { | ||
tmp = p[i]; | ||
p[i] = p[size - i - 1]; | ||
p[size - i - 1] = tmp; | ||
} | ||
} | ||
|
||
unsigned char reverse_bits(unsigned char b) | ||
{ | ||
b = (b & 0xF0) >> 4 | (b & 0x0F) << 4; | ||
b = (b & 0xCC) >> 2 | (b & 0x33) << 2; | ||
b = (b & 0xAA) >> 1 | (b & 0x55) << 1; | ||
return b; | ||
} |