Go to the documentation of this file.
43 #include <avr/interrupt.h>
45 #include <util/delay.h>
54 #error fehlerhafte Definition fuer TRUE
60 #error fehlerhafte Definition fuer FALSE
64 #define NULL ((void*)0)
74 #define DEGREE_TO_RAD(x) ((x * M_PI) / 180)
84 #define LOW_BYTE(x) ((uint8_t) (x & 0xff))
85 #define HIGH_BYTE(x) ((uint8_t) (x >> 8))
86 #define LOW_WORD(x) ((uint16_t) (x & 0xffff))
87 #define HIGH_WORD(x) ((uint16_t) (x >> 16))
108 #if defined(__DOXYGEN__)
110 #define ENTER_CRITICAL_SECTION
111 #define LEAVE_CRITICAL_SECTION
115 #if __AVR_LIBC_VERSION__ >= 10600 && !defined (__cplusplus)
117 #include <util/atomic.h>
119 #define ENTER_CRITICAL_SECTION ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
120 #define LEAVE_CRITICAL_SECTION }
122 #define IRQ_LOCK ATOMIC_BLOCK(ATOMIC_RESTORESTATE)
126 #define ENTER_CRITICAL_SECTION do { unsigned char sreg_ = SREG; cli();
127 #define LEAVE_CRITICAL_SECTION SREG = sreg_; } while (0);
160 #define vu8(x) (*(volatile uint8_t*)&(x))
161 #define vs8(x) (*(volatile int8_t*)&(x))
162 #define vu16(x) (*(volatile uint16_t*)&(x))
163 #define vs16(x) (*(volatile int16_t*)&(x))
164 #define vu32(x) (*(volatile uint32_t*)&(x))
165 #define vs32(x) (*(volatile int32_t*)&(x))
203 #if defined(__DOXYGEN__)
209 #define SET_OUTPUT(x)
211 #define SET_PULLUP(x)
213 #define SET_INPUT_WITH_PULLUP(x)
222 #define PORT(x) _port2(x)
223 #define DDR(x) _ddr2(x)
224 #define PIN(x) _pin2(x)
225 #define REG(x) _reg(x)
226 #define PIN_NUM(x) _pin_num(x)
228 #define RESET(x) RESET2(x)
229 #define SET(x) SET2(x)
230 #define TOGGLE(x) TOGGLE2(x)
231 #define SET_OUTPUT(x) SET_OUTPUT2(x)
232 #define SET_INPUT(x) SET_INPUT2(x)
233 #define SET_PULLUP(x) SET2(x)
234 #define IS_SET(x) IS_SET2(x)
236 #define SET_INPUT_WITH_PULLUP(x) SET_INPUT_WITH_PULLUP2(x)
238 #define _port2(x) PORT ## x
239 #define _ddr2(x) DDR ## x
240 #define _pin2(x) PIN ## x
243 #define _pin_num(x,y) y
245 #define RESET2(x,y) PORT(x) &= ~(1<<y)
246 #define SET2(x,y) PORT(x) |= (1<<y)
247 #define TOGGLE2(x,y) PORT(x) ^= (1<<y)
249 #define SET_OUTPUT2(x,y) DDR(x) |= (1<<y)
250 #define SET_INPUT2(x,y) DDR(x) &= ~(1<<y)
251 #define SET_INPUT_WITH_PULLUP2(x,y) SET_INPUT2(x,y);SET2(x,y)
253 #define IS_SET2(x,y) ((PIN(x) & (1<<y)) != 0)
264 #if defined(__DOXYGEN__)
266 #define _bit_is_set(pin, bit)
267 #define _bit_is_clear(pin, bit)
273 #define _bit_is_set(pin, bit) (pin & (1<<bit))
274 #define _bit_is_clear(pin, bit) (!(pin & (1<<bit)))
276 #define STRING(x) _STRING(x)
277 #define _STRING(x) #x
291 if (__builtin_constant_p(
x))
292 x = (
x << 4) | (
x >> 4);
294 asm volatile (
"swap %0" :
"=r" (
x) :
"0" (
x));
304 #if defined(DEBUG_LEVEL) && DEBUG_LEVEL
306 #define DEBUG_PRINT(s, ...) do { static const char __s[] PROGMEM = (s); \
307 printf_P(__s, ## __VA_ARGS__); } while (0)
309 #define DEBUG_PRINT(s, ...)
325 n = ((n >> 1) & 0x55) + (n & 0x55);
326 n = ((n >> 2) & 0x33) + (n & 0x33);
327 n = ((n >> 4) + n) & 0xf;
332 #define MASK_01010101 (((uint32_t)(-1))/3)
333 #define MASK_00110011 (((uint32_t)(-1))/5)
334 #define MASK_00001111 (((uint32_t)(-1))/17)
354 #define START_TIMED_BLOCK(time, gettime) \
356 static uint16_t last_time__; \
357 uint16_t current_time__ = gettime; \
358 if ((uint16_t) (current_time__ - last_time__) > time) { \
359 last_time__ = current_time__;
361 #define END_TIMED_BLOCK \
366 #define TO_DEG(x) (x * 180.0 / M_PI)
367 #define TO_RAD(x) (x * M_PI / 180.0)
374 #define USE_IT(x) (void) x
#define ENTER_CRITICAL_SECTION
static uint8_t read_and_replace_atomar(volatile uint8_t *data, uint8_t new_data)
atomare Operationen
static uint8_t bit_count8(uint8_t n)
Zählt die Anzahl der gesetzten Bits in einem Byte.
static uint8_t swap(uint8_t x)
Dreht die beiden Nibble in einem Byte um.
#define LEAVE_CRITICAL_SECTION
static uint8_t bit_count32(uint32_t n)
Zählt die Anzahl der gesetzten Bits in einem Byte.