tornado/fw/avr/io.h |
| 1 | /* |
| 2 | * fw/io.h - I/O helper macros |
| 3 | * |
| 4 | * Written 2012 by Werner Almesberger |
| 5 | * Copyright 2012 Werner Almesberger |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | */ |
| 12 | |
| 13 | #ifndef IO_H |
| 14 | #define IO_H |
| 15 | |
| 16 | #include <avr/io.h> |
| 17 | |
| 18 | |
| 19 | #define LED_DS D, 1 |
| 20 | #define LED_LCLK D, 2 |
| 21 | #define LED_SCLK D, 4 |
| 22 | |
| 23 | #define CARD_nPWR B, 6 |
| 24 | #define CARD_DAT2 B, 2 |
| 25 | #define CARD_DAT3 B, 1 |
| 26 | #define CARD_CMD B, 3 |
| 27 | #define CARD_CLK B, 0 |
| 28 | #define CARD_DAT0 B, 4 |
| 29 | #define CARD_DAT1 B, 5 |
| 30 | |
| 31 | #define SW_N C, 3 |
| 32 | #define SW_E C, 4 |
| 33 | #define SW_S C, 0 |
| 34 | #define SW_W C, 2 |
| 35 | #define SW_SW C, 1 |
| 36 | |
| 37 | #define ADC_X 6 |
| 38 | #define ADC_Y 7 |
| 39 | |
| 40 | #define __SET(port, bit) PORT##port |= 1 << (bit) |
| 41 | #define __CLR(port, bit) PORT##port &= ~(1 << (bit)) |
| 42 | #define __OUT(port, bit) DDR##port |= 1 << (bit) |
| 43 | #define __IN(port, bit) DDR##port &= ~(1 << (bit)) |
| 44 | #define __PIN(port, bit) ((PIN##port >> (bit)) & 1) |
| 45 | |
| 46 | #define SET(...) __SET(__VA_ARGS__) |
| 47 | #define CLR(...) __CLR(__VA_ARGS__) |
| 48 | #define OUT(...) __OUT(__VA_ARGS__) |
| 49 | #define IN(...) __IN(__VA_ARGS__) |
| 50 | #define PIN(...) __PIN(__VA_ARGS__) |
| 51 | |
| 52 | #define __SEL_BB(v) (v) |
| 53 | #define __SEL_CC(v) (v) |
| 54 | #define __SEL_DD(v) (v) |
| 55 | |
| 56 | #define __SEL_BC(v) (0) |
| 57 | #define __SEL_BD(v) (0) |
| 58 | #define __SEL_CB(v) (0) |
| 59 | #define __SEL_CD(v) (0) |
| 60 | #define __SEL_DB(v) (0) |
| 61 | #define __SEL_DC(v) (0) |
| 62 | |
| 63 | #define __MASK(sel, port, bit) __SEL_##sel##port(1 << (bit)) |
| 64 | #define MASK(...) __MASK(__VA_ARGS__) |
| 65 | |
| 66 | #endif /* IO_H */ |
tornado/fw/ben/ben-io.h |
1 | | /* |
2 | | * ben/ben-io.h - I/O helper macros (for cross-platform testing on the Ben) |
3 | | * |
4 | | * Written 2012 by Werner Almesberger |
5 | | * Copyright 2012 Werner Almesberger |
6 | | * |
7 | | * This program is free software; you can redistribute it and/or modify |
8 | | * it under the terms of the GNU General Public License as published by |
9 | | * the Free Software Foundation; either version 2 of the License, or |
10 | | * (at your option) any later version. |
11 | | */ |
12 | | |
13 | | #ifndef BEN_IO_H |
14 | | #define BEN_IO_H |
15 | | |
16 | | #include <stdint.h> |
17 | | |
18 | | |
19 | | #define CARD_nPWR (1 << 2) /* PD02 */ |
20 | | #define CARD_DAT2 (1 << 12) /* PD12 */ |
21 | | #define CARD_DAT3 (1 << 13) /* PD13 */ |
22 | | #define CARD_CMD (1 << 8) /* PD08 */ |
23 | | #define CARD_CLK (1 << 9) /* PD09 */ |
24 | | #define CARD_DAT0 (1 << 10) /* PD10 */ |
25 | | #define CARD_DAT1 (1 << 11) /* PD11 */ |
26 | | |
27 | | |
28 | | #define REG(n) (*(volatile uint32_t *) (ben_mem+(n))) |
29 | | |
30 | | #define GPIO(n) REG(0x10000+(n)) |
31 | | |
32 | | #define PDPIN GPIO(0x300) /* port D pin level */ |
33 | | #define PDDATS GPIO(0x314) /* port D data set */ |
34 | | #define PDDATC GPIO(0x318) /* port D data clear */ |
35 | | #define PDFUNS GPIO(0x344) /* port D function set */ |
36 | | #define PDFUNC GPIO(0x348) /* port D function clear */ |
37 | | #define PDDIRS GPIO(0x364) /* port D direction set */ |
38 | | #define PDDIRC GPIO(0x368) /* port D direction clear */ |
39 | | |
40 | | #define SET(mask) PDDATS = mask |
41 | | #define CLR(mask) PDDATC = mask |
42 | | #define OUT(mask) PDDIRS = mask |
43 | | #define IN(mask) PDDIRC = mask |
44 | | #define PIN(mask) (!!(PDPIN & (mask))) |
45 | | |
46 | | |
47 | | extern void *ben_mem; |
48 | | |
49 | | #endif /* BEN_IO_H */ |
tornado/fw/ben/io.h |
| 1 | /* |
| 2 | * ben/io.h - I/O helper macros (for cross-platform testing on the Ben) |
| 3 | * |
| 4 | * Written 2012 by Werner Almesberger |
| 5 | * Copyright 2012 Werner Almesberger |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | */ |
| 12 | |
| 13 | #ifndef BEN_IO_H |
| 14 | #define BEN_IO_H |
| 15 | |
| 16 | #include <stdint.h> |
| 17 | |
| 18 | |
| 19 | #define CARD_nPWR (1 << 2) /* PD02 */ |
| 20 | #define CARD_DAT2 (1 << 12) /* PD12 */ |
| 21 | #define CARD_DAT3 (1 << 13) /* PD13 */ |
| 22 | #define CARD_CMD (1 << 8) /* PD08 */ |
| 23 | #define CARD_CLK (1 << 9) /* PD09 */ |
| 24 | #define CARD_DAT0 (1 << 10) /* PD10 */ |
| 25 | #define CARD_DAT1 (1 << 11) /* PD11 */ |
| 26 | |
| 27 | |
| 28 | #define REG(n) (*(volatile uint32_t *) (ben_mem+(n))) |
| 29 | |
| 30 | #define GPIO(n) REG(0x10000+(n)) |
| 31 | |
| 32 | #define PDPIN GPIO(0x300) /* port D pin level */ |
| 33 | #define PDDATS GPIO(0x314) /* port D data set */ |
| 34 | #define PDDATC GPIO(0x318) /* port D data clear */ |
| 35 | #define PDFUNS GPIO(0x344) /* port D function set */ |
| 36 | #define PDFUNC GPIO(0x348) /* port D function clear */ |
| 37 | #define PDDIRS GPIO(0x364) /* port D direction set */ |
| 38 | #define PDDIRC GPIO(0x368) /* port D direction clear */ |
| 39 | |
| 40 | #define SET(mask) PDDATS = mask |
| 41 | #define CLR(mask) PDDATC = mask |
| 42 | #define OUT(mask) PDDIRS = mask |
| 43 | #define IN(mask) PDDIRC = mask |
| 44 | #define PIN(mask) (!!(PDPIN & (mask))) |
| 45 | |
| 46 | |
| 47 | extern void *ben_mem; |
| 48 | |
| 49 | #endif /* BEN_IO_H */ |
tornado/fw/io.h |
1 | | /* |
2 | | * fw/io.h - I/O helper macros |
3 | | * |
4 | | * Written 2012 by Werner Almesberger |
5 | | * Copyright 2012 Werner Almesberger |
6 | | * |
7 | | * This program is free software; you can redistribute it and/or modify |
8 | | * it under the terms of the GNU General Public License as published by |
9 | | * the Free Software Foundation; either version 2 of the License, or |
10 | | * (at your option) any later version. |
11 | | */ |
12 | | |
13 | | #ifndef IO_H |
14 | | #define IO_H |
15 | | |
16 | | #include <avr/io.h> |
17 | | |
18 | | |
19 | | #define LED_DS D, 1 |
20 | | #define LED_LCLK D, 2 |
21 | | #define LED_SCLK D, 4 |
22 | | |
23 | | #define CARD_nPWR B, 6 |
24 | | #define CARD_DAT2 B, 2 |
25 | | #define CARD_DAT3 B, 1 |
26 | | #define CARD_CMD B, 3 |
27 | | #define CARD_CLK B, 0 |
28 | | #define CARD_DAT0 B, 4 |
29 | | #define CARD_DAT1 B, 5 |
30 | | |
31 | | #define SW_N C, 3 |
32 | | #define SW_E C, 4 |
33 | | #define SW_S C, 0 |
34 | | #define SW_W C, 2 |
35 | | #define SW_SW C, 1 |
36 | | |
37 | | #define ADC_X 6 |
38 | | #define ADC_Y 7 |
39 | | |
40 | | #define __SET(port, bit) PORT##port |= 1 << (bit) |
41 | | #define __CLR(port, bit) PORT##port &= ~(1 << (bit)) |
42 | | #define __OUT(port, bit) DDR##port |= 1 << (bit) |
43 | | #define __IN(port, bit) DDR##port &= ~(1 << (bit)) |
44 | | #define __PIN(port, bit) ((PIN##port >> (bit)) & 1) |
45 | | |
46 | | #define SET(...) __SET(__VA_ARGS__) |
47 | | #define CLR(...) __CLR(__VA_ARGS__) |
48 | | #define OUT(...) __OUT(__VA_ARGS__) |
49 | | #define IN(...) __IN(__VA_ARGS__) |
50 | | #define PIN(...) __PIN(__VA_ARGS__) |
51 | | |
52 | | #define __SEL_BB(v) (v) |
53 | | #define __SEL_CC(v) (v) |
54 | | #define __SEL_DD(v) (v) |
55 | | |
56 | | #define __SEL_BC(v) (0) |
57 | | #define __SEL_BD(v) (0) |
58 | | #define __SEL_CB(v) (0) |
59 | | #define __SEL_CD(v) (0) |
60 | | #define __SEL_DB(v) (0) |
61 | | #define __SEL_DC(v) (0) |
62 | | |
63 | | #define __MASK(sel, port, bit) __SEL_##sel##port(1 << (bit)) |
64 | | #define MASK(...) __MASK(__VA_ARGS__) |
65 | | |
66 | | #endif /* IO_H */ |