comparison include/avriotools.h @ 0:a0ce8ebf2f18

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