annotate include/avriotools.h @ 1:f7c60e525801

cptest and cp_ping.py to test cmd_proto.c.
author Thinker K.F. Li <thinker@branda.to>
date Sat, 21 Feb 2009 20:20:06 +0800
parents a0ce8ebf2f18
children
rev   line source
0
a0ce8ebf2f18 LED on PINB0 & PINB1 and UART testing.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1 #ifndef __AVRIOTOOLS_H_
a0ce8ebf2f18 LED on PINB0 & PINB1 and UART testing.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
2 #define __AVRIOTOOLS_H_
a0ce8ebf2f18 LED on PINB0 & PINB1 and UART testing.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
3 #include <stdint.h>
a0ce8ebf2f18 LED on PINB0 & PINB1 and UART testing.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
4 #include <avr/io.h>
a0ce8ebf2f18 LED on PINB0 & PINB1 and UART testing.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
5
a0ce8ebf2f18 LED on PINB0 & PINB1 and UART testing.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
6 typedef enum {PM_INPUT, PM_OUTPUT} pin_mode_t;
a0ce8ebf2f18 LED on PINB0 & PINB1 and UART testing.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
7
a0ce8ebf2f18 LED on PINB0 & PINB1 and UART testing.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
8 extern int pin_mode(volatile uint8_t * port, int pin, pin_mode_t mode);
a0ce8ebf2f18 LED on PINB0 & PINB1 and UART testing.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
9 #define pin_hi(port, pin) do { port |= _BV(pin); } while(0)
a0ce8ebf2f18 LED on PINB0 & PINB1 and UART testing.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
10 #define pin_lo(port, pin) do { port &= ~_BV(pin); } while(0)
a0ce8ebf2f18 LED on PINB0 & PINB1 and UART testing.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
11
a0ce8ebf2f18 LED on PINB0 & PINB1 and UART testing.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
12
a0ce8ebf2f18 LED on PINB0 & PINB1 and UART testing.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
13 #define UBRRH UBRR0L
a0ce8ebf2f18 LED on PINB0 & PINB1 and UART testing.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
14 #define UBRRL UBRR0L
a0ce8ebf2f18 LED on PINB0 & PINB1 and UART testing.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
15 #define UCSRA UCSR0A
a0ce8ebf2f18 LED on PINB0 & PINB1 and UART testing.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
16 #define U2X U2X0
a0ce8ebf2f18 LED on PINB0 & PINB1 and UART testing.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
17 #define UDRE UDRE0
a0ce8ebf2f18 LED on PINB0 & PINB1 and UART testing.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
18 #define UDR UDR0
a0ce8ebf2f18 LED on PINB0 & PINB1 and UART testing.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
19 #define RXC RXC0
a0ce8ebf2f18 LED on PINB0 & PINB1 and UART testing.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
20 #define FE FE0
a0ce8ebf2f18 LED on PINB0 & PINB1 and UART testing.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
21 #define DOR DOR0
a0ce8ebf2f18 LED on PINB0 & PINB1 and UART testing.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
22
a0ce8ebf2f18 LED on PINB0 & PINB1 and UART testing.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
23 extern int uart_init(uint32_t baud);
a0ce8ebf2f18 LED on PINB0 & PINB1 and UART testing.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
24 #define uart_getc(c) \
a0ce8ebf2f18 LED on PINB0 & PINB1 and UART testing.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
25 do { \
a0ce8ebf2f18 LED on PINB0 & PINB1 and UART testing.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
26 loop_until_bit_is_set(UCSRA, RXC); \
a0ce8ebf2f18 LED on PINB0 & PINB1 and UART testing.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
27 if (UCSRA & _BV(FE)) \
a0ce8ebf2f18 LED on PINB0 & PINB1 and UART testing.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
28 continue; \
a0ce8ebf2f18 LED on PINB0 & PINB1 and UART testing.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
29 if (UCSRA & _BV(DOR)) \
a0ce8ebf2f18 LED on PINB0 & PINB1 and UART testing.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
30 continue; \
a0ce8ebf2f18 LED on PINB0 & PINB1 and UART testing.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
31 c = UDR; \
a0ce8ebf2f18 LED on PINB0 & PINB1 and UART testing.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
32 } while(0)
a0ce8ebf2f18 LED on PINB0 & PINB1 and UART testing.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
33 /*
a0ce8ebf2f18 LED on PINB0 & PINB1 and UART testing.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
34 * c == -1 if not data been read.
a0ce8ebf2f18 LED on PINB0 & PINB1 and UART testing.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
35 * \note c must be an integer.
a0ce8ebf2f18 LED on PINB0 & PINB1 and UART testing.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
36 */
a0ce8ebf2f18 LED on PINB0 & PINB1 and UART testing.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
37 #define uart_getc_nowait(c) \
a0ce8ebf2f18 LED on PINB0 & PINB1 and UART testing.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
38 do { \
a0ce8ebf2f18 LED on PINB0 & PINB1 and UART testing.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
39 c = -1; \
a0ce8ebf2f18 LED on PINB0 & PINB1 and UART testing.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
40 if(bit_is_clear(UCSRA, RXC)) break; \
a0ce8ebf2f18 LED on PINB0 & PINB1 and UART testing.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
41 if (UCSRA & _BV(FE)) \
a0ce8ebf2f18 LED on PINB0 & PINB1 and UART testing.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
42 break; \
a0ce8ebf2f18 LED on PINB0 & PINB1 and UART testing.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
43 if (UCSRA & _BV(DOR)) \
a0ce8ebf2f18 LED on PINB0 & PINB1 and UART testing.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
44 break; \
a0ce8ebf2f18 LED on PINB0 & PINB1 and UART testing.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
45 c = UDR; \
a0ce8ebf2f18 LED on PINB0 & PINB1 and UART testing.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
46 } while(0)
a0ce8ebf2f18 LED on PINB0 & PINB1 and UART testing.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
47 #define uart_putc(c) \
a0ce8ebf2f18 LED on PINB0 & PINB1 and UART testing.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
48 do { \
a0ce8ebf2f18 LED on PINB0 & PINB1 and UART testing.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
49 loop_until_bit_is_set(UCSRA, UDRE); \
a0ce8ebf2f18 LED on PINB0 & PINB1 and UART testing.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
50 UDR = ((uint8_t)(c & 0xff)); \
a0ce8ebf2f18 LED on PINB0 & PINB1 and UART testing.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
51 } while(0)
a0ce8ebf2f18 LED on PINB0 & PINB1 and UART testing.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
52 /*
a0ce8ebf2f18 LED on PINB0 & PINB1 and UART testing.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
53 * c == -1 if it been wrote out.
a0ce8ebf2f18 LED on PINB0 & PINB1 and UART testing.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
54 * \note c must be an integer.
a0ce8ebf2f18 LED on PINB0 & PINB1 and UART testing.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
55 */
a0ce8ebf2f18 LED on PINB0 & PINB1 and UART testing.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
56 #define uart_putc_nowait(c) \
a0ce8ebf2f18 LED on PINB0 & PINB1 and UART testing.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
57 do { \
a0ce8ebf2f18 LED on PINB0 & PINB1 and UART testing.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
58 if(bit_is_clear(UCSRA, UDRE)) \
a0ce8ebf2f18 LED on PINB0 & PINB1 and UART testing.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
59 break; \
a0ce8ebf2f18 LED on PINB0 & PINB1 and UART testing.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
60 UDR = ((uint8_t)(c & 0xff)); \
a0ce8ebf2f18 LED on PINB0 & PINB1 and UART testing.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
61 c = -1; \
a0ce8ebf2f18 LED on PINB0 & PINB1 and UART testing.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
62 } while(0)
a0ce8ebf2f18 LED on PINB0 & PINB1 and UART testing.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
63
a0ce8ebf2f18 LED on PINB0 & PINB1 and UART testing.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
64
a0ce8ebf2f18 LED on PINB0 & PINB1 and UART testing.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
65 #endif /* __AVRIOTOOLS_H_ */