common: list: an interface to a static list which can have elements added and removed...
[avr_work.git] / lline / debug.h
blob567cd64e5508e428c014f02ce87e3a20c820a091
1 #ifndef _DEBUG_H_
2 #define _DEBUG_H_
4 #include "defines.h"
5 #include "common.h"
6 #include <stdint.h>
7 #include <util/delay.h>
8 #include <avr/io.h>
10 #define DEBUG_LED_P A
11 #define DEBUG_LED_I 4
13 #define DEBUG_LED_PIN PIN(DEBUG_LED_P)
14 #define DEBUG_LED_DDR DDR(DEBUG_LED_P)
15 #define DEBUG_LED_PORT PORT(DEBUG_LED_P)
17 #define debug_led_off() DEBUG_LED_PORT |= (1<<DEBUG_LED_I)
18 #define debug_led_on() DEBUG_LED_PORT &= (uint8_t)~(1<<DEBUG_LED_I)
19 #define debug_led_flip() DEBUG_LED_PIN |= (1<<DEBUG_LED_I)
20 #define debug_led_init() DEBUG_LED_DDR |= (1<<DEBUG_LED_I)
22 inline static void debug_led_flash(uint16_t len,uint16_t out) {
23 // no lead in, depend on lead out of previous call.
25 // blink
26 debug_led_on();
27 _delay_ms(len);
28 debug_led_off();
30 // lead out
31 _delay_ms(out);
35 #define led_d(state) \
36 if (state==0) \
37 debug_led_off(); \
38 else \
39 debug_led_on()
41 /* Debuging */
42 #define DEBUG 1
43 #define DEBUG_L(LEVEL) (DEBUG>=LEVEL)
45 #if DEBUG_L(1)
46 #define dpf_P(...) printf_P(__VA_ARGS__)
47 #define dpf(...) printf(__VA_ARGS__)
48 #else
49 #define dpf_P(...)
50 #define dpf(...)
51 #endif
52 #if DEBUG_L(2)
53 #define dpfv(...) printf(__VA_ARGS__)
54 #define dpfv_P(...) printf_P(__VA_ARGS__)
55 #else
56 #define dpfv(...)
57 #define dpfv_P(...)
58 #endif
59 #if DEBUG_L(3)
60 #define dpfV(...) printf(__VA_ARGS__)
61 #define dpfV_P(...) printf_P(__VA_ARGS__)
62 #else
63 #define dpfV(...)
64 #define dpfV_P(...)
65 #endif
67 #endif /* _DEBUG_H_ */