1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-14 20:10:18 +03:00

exti_io from Peter Ledvina

This commit is contained in:
Petr Ledvina 2016-05-31 21:19:00 +10:00 committed by borisbstyle
parent a74acccb84
commit 9e30e69cee
34 changed files with 2020 additions and 19 deletions

View file

@ -18,6 +18,7 @@
#pragma once
#include <stddef.h>
#include <stdint.h>
#define ARRAYLEN(x) (sizeof(x) / sizeof((x)[0]))
@ -27,6 +28,14 @@
#define STR_HELPER(x) #x
#define STR(x) STR_HELPER(x)
#define EXPAND_I(x) x
#define EXPAND(x) EXPAND_I(x)
#define UNUSED(x) (void)(x)
#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
#define BIT(x) (1 << (x))
/*
http://resnet.uoregon.edu/~gurney_j/jmpc/bitwise.html
*/
@ -35,6 +44,19 @@ http://resnet.uoregon.edu/~gurney_j/jmpc/bitwise.html
#define UNUSED(x) (void)(x)
/*
* https://groups.google.com/forum/?hl=en#!msg/comp.lang.c/attFnqwhvGk/sGBKXvIkY3AJ
* Return (v ? floor(log2(v)) : 0) when 0 <= v < 1<<[8, 16, 32, 64].
* Inefficient algorithm, intended for compile-time constants.
*/
#define LOG2_8BIT(v) (8 - 90/(((v)/4+14)|1) - 2/((v)/2+1))
#define LOG2_16BIT(v) (8*((v)>255) + LOG2_8BIT((v) >>8*((v)>255)))
#define LOG2_32BIT(v) (16*((v)>65535L) + LOG2_16BIT((v)*1L >>16*((v)>65535L)))
#define LOG2_64BIT(v) \
(32*((v)/2L>>31 > 0) \
+ LOG2_32BIT((v)*1L >>16*((v)/2L>>31 > 0) \
>>16*((v)/2L>>31 > 0)))
#if 0
// ISO C version, but no type checking
#define container_of(ptr, type, member) \