EPPL  0.1 alpha
 All Files Typedefs Groups Pages
eppl_avr8.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2013, Radoslaw Koppel
3  All rights reserved.
4 
5  Redistribution and use in source and binary forms, with or without
6  modification, are permitted provided that the following conditions are met:
7 
8  - Redistributions of source code must retain the above copyright
9  notice, this list of conditions and the following disclaimer.
10 
11  - Redistributions in binary form must reproduce the above copyright
12  notice, this list of conditions and the following disclaimer in the
13  documentation and/or other materials provided with the distribution.
14 
15  - Neither the name of the copyright holders nor the
16  names of its contributors may be used to endorse or promote products
17  derived from this software without specific prior written permission.
18 
19  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER BE LIABLE FOR ANY
23  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
39 #ifndef EPPL_AVR8_H_INCLUDED
40 #define EPPL_AVR8_H_INCLUDED
41 #include <inttypes.h>
42 #include <avr/io.h>
43 #include <avr/interrupt.h>
45 
65 #define EPPL_avr8_PORTSIZE 8L
66 
68 #define EPPL_avr8_PORTCNT 12
69 
70 #ifndef NULL
71 #define NULL ((void*)0)
72 #endif
73 
74 
83  #ifdef PORTA
84 
85  #define _PA(n) EPPL_DEFPP( 0, n)
86  #endif
87  #ifdef PORTB
88 
89  #define _PB(n) EPPL_DEFPP( 1, n)
90  #endif
91  #ifdef PORTC
92 
93  #define _PC(n) EPPL_DEFPP( 2, n)
94  #endif
95  #ifdef PORTD
96 
97  #define _PD(n) EPPL_DEFPP( 3, n)
98  #endif
99  #ifdef PORTE
100 
101  #define _PE(n) EPPL_DEFPP( 4, n)
102  #endif
103  #ifdef PORTF
104 
105  #define _PF(n) EPPL_DEFPP( 5, n)
106  #endif
107  #ifdef PORTG
108 
109  #define _PG(n) EPPL_DEFPP( 6, n)
110  #endif
111  #ifdef PORTH
112 
113  #define _PH(n) EPPL_DEFPP( 7, n)
114  #endif
115  #ifdef PORTI
116 
117  #define _PI(n) EPPL_DEFPP( 8, n)
118  #endif
119  #ifdef PORTJ
120 
121  #define _PJ(n) EPPL_DEFPP( 9, n)
122  #endif
123  #ifdef PORTK
124 
125  #define _PK(n) EPPL_DEFPP(10, n)
126  #endif
127  #ifdef PORTL
128 
129  #define _PL(n) EPPL_DEFPP(11, n)
130  #endif
131 
153  #define EPPL_mode_mask (0x0f << 2)
154 
156  #define EPPL_mode_flag (0x08 << 2)
157 
159  #define EPPL_outSet_mask 0x03
160 
162  #define EPPL_outSet_value 0x01
163 
165  #define EPPL_outSet_flag 0x02
166 
172  #define EPPL_mode_out (0x04 << 2)
173 
183  #define EPPL_mode_outPP (EPPL_mode_flag | EPPL_mode_out | (0x00 << 2))
184 
192  #define EPPL_mode_outOC (EPPL_mode_flag | EPPL_mode_out | (0x01 << 2))
193 
200  #define EPPL_mode_outOE (EPPL_mode_flag | EPPL_mode_out | (0x02 << 2))
201 
208  #define EPPL_mode_outPU (EPPL_mode_flag | EPPL_mode_out | (0x03 << 2))
209 
216  #define EPPL_mode_inHZ (EPPL_mode_flag | EPPL_outSet_0)
217 
223  #define EPPL_mode_inPU (EPPL_mode_flag | EPPL_outSet_1)
224 
231  #define EPPL_outSet_0 (EPPL_outSet_flag | 0)
232 
238  #define EPPL_outSet_1 (EPPL_outSet_flag | 1)
239 
243  #define EPPL_configBits 6
244 
248  #define EPPL_avr8_CONFSIZE (1U<<(EPPL_configBits))
249 
258  #define EPPL_mode_outPP_0 (EPPL_mode_outPP | EPPL_outSet_0)
259  #define EPPL_mode_outPP_1 (EPPL_mode_outPP | EPPL_outSet_1)
261  #define EPPL_mode_outOC_0 (EPPL_mode_outOC | EPPL_outSet_0)
262  #define EPPL_mode_outOC_1 (EPPL_mode_outOC | EPPL_outSet_1)
264  #define EPPL_mode_outOE_0 (EPPL_mode_outOE | EPPL_outSet_0)
265  #define EPPL_mode_outOE_1 (EPPL_mode_outOE | EPPL_outSet_1)
267  #define EPPL_mode_outPU_0 (EPPL_mode_outPU | EPPL_outSet_0)
268  #define EPPL_mode_outPU_1 (EPPL_mode_outPU | EPPL_outSet_1)
284 #define eppl_avr8_LockableBlockBegin(lock) \
285  do{ \
286  uint8_t lockableblock_sreg_copy=lockableblock_sreg_copy; \
287  if(lock) { \
288  lockableblock_sreg_copy = SREG; \
289  cli(); \
290  } \
291  do{
292 
301 #define eppl_avr8_LockableBlockEnd(locked) \
302  }while(0); \
303  if(locked) \
304  SREG = lockableblock_sreg_copy; \
305  }while(0)
306 
312 
313 #endif /* EPPL_AVR8_H_INCLUDED */