EPPL  0.1 alpha
 All Files Typedefs Groups Pages
eppl_avr8_mapout.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_MAPOUT_H_INCLUDED
40 #define EPPL_AVR8_MAPOUT_H_INCLUDED
41 
68 #define EPPL_avr8_mapOutMaskedPins(pout, value, pos, pin, mask) \
69  (*(pout)) ^= (((*(pout)) ^ EPPL_avr8_LRSH(value, pin, pos)) & ((mask)<<(pin)))
70 
91  #define EPPL_avr8_mapOutFlag_direct 1
92 
98  #define EPPL_avr8_mapOutFlag_const 2
99 
121  #define EPPL_avr8_mapOutTempPinsNear1(pout, val, flags, pos, pin) \
122  do{ \
123  if((flags) & EPPL_avr8_mapOutFlag_direct) {\
124  if(val & (1U<<(pos))) \
125  eppl_avr8_asm_sbi(pout, EPPL_PINNR(pin)); \
126  else \
127  eppl_avr8_asm_cbi(pout, EPPL_PINNR(pin)); \
128  } else if((flags) & EPPL_avr8_mapOutFlag_const) \
129  EPPL_avr8_mapOutMaskedPins(pout, val, pos, EPPL_PINNR(pin), 0x01); \
130  else \
131  eppl_avr8_asm_bitcpy(*pout, EPPL_PINNR(pin), val, pos); \
132  } while(0)
133 
135  #define EPPL_avr8_mapOutTempPinsNear2(pout, val, flags, pos, pin) \
136  EPPL_avr8_mapOutMaskedPins(pout, val, pos, EPPL_PINNR(pin), 0x03)
137 
138  #define EPPL_avr8_mapOutTempPinsNear3(pout, val, flags, pos, pin) \
139  EPPL_avr8_mapOutMaskedPins(pout, val, pos, EPPL_PINNR(pin), 0x07)
140 
141  #define EPPL_avr8_mapOutTempPinsNear4(pout, val, flags, pos, pin) \
142  EPPL_avr8_mapOutMaskedPins(pout, val, pos, EPPL_PINNR(pin), 0x0f)
143 
144  #define EPPL_avr8_mapOutTempPinsNear5(pout, val, flags, pos, pin) \
145  EPPL_avr8_mapOutMaskedPins(pout, val, pos, EPPL_PINNR(pin), 0x1f)
146 
147  #define EPPL_avr8_mapOutTempPinsNear6(pout, val, flags, pos, pin) \
148  EPPL_avr8_mapOutMaskedPins(pout, val, pos, EPPL_PINNR(pin), 0x3f)
149 
150  #define EPPL_avr8_mapOutTempPinsNear7(pout, val, flags, pos, pin) \
151  EPPL_avr8_mapOutMaskedPins(pout, val, pos, EPPL_PINNR(pin), 0x7f)
152 
153  #define EPPL_avr8_mapOutTempPinsNear8(pout, val, flags, pos, pin) \
154  EPPL_avr8_mapOutMaskedPins(pout, val, pos, EPPL_PINNR(pin), 0xff)
155 
167  static inline void eppl_avr8_mapOutToOnePort1(uint8_t *pout, uint8_t port, uint8_t val, uint8_t flags, eppl_pin_t pin1) __attribute__((always_inline));
168  static inline void eppl_avr8_mapOutToOnePort2(uint8_t *pout, uint8_t port, uint8_t val, uint8_t flags, eppl_pin_t pin1, eppl_pin_t pin2) __attribute__((always_inline));
169  static inline void eppl_avr8_mapOutToOnePort3(uint8_t *pout, uint8_t port, uint8_t val, uint8_t flags, eppl_pin_t pin1, eppl_pin_t pin2, eppl_pin_t pin3) __attribute__((always_inline));
170  static inline void eppl_avr8_mapOutToOnePort4(uint8_t *pout, uint8_t port, uint8_t val, uint8_t flags, eppl_pin_t pin1, eppl_pin_t pin2, eppl_pin_t pin3, eppl_pin_t pin4) __attribute__((always_inline));
171  static inline void eppl_avr8_mapOutToOnePort5(uint8_t *pout, uint8_t port, uint8_t val, uint8_t flags, eppl_pin_t pin1, eppl_pin_t pin2, eppl_pin_t pin3, eppl_pin_t pin4, eppl_pin_t pin5) __attribute__((always_inline));
172  static inline void eppl_avr8_mapOutToOnePort6(uint8_t *pout, uint8_t port, uint8_t val, uint8_t flags, eppl_pin_t pin1, eppl_pin_t pin2, eppl_pin_t pin3, eppl_pin_t pin4, eppl_pin_t pin5, eppl_pin_t pin6) __attribute__((always_inline));
173  static inline void eppl_avr8_mapOutToOnePort7(uint8_t *pout, uint8_t port, uint8_t val, uint8_t flags, eppl_pin_t pin1, eppl_pin_t pin2, eppl_pin_t pin3, eppl_pin_t pin4, eppl_pin_t pin5, eppl_pin_t pin6, eppl_pin_t pin7) __attribute__((always_inline));
174  static inline void eppl_avr8_mapOutToOnePort8(uint8_t *pout, uint8_t port, uint8_t val, uint8_t flags, eppl_pin_t pin1, eppl_pin_t pin2, eppl_pin_t pin3, eppl_pin_t pin4, eppl_pin_t pin5, eppl_pin_t pin6, eppl_pin_t pin7, eppl_pin_t pin8) __attribute__((always_inline));
175 
189 #define eppl_avr8_mapOutToOnePort(pout, port, val, flags, pins...) EPPL_LC(eppl_avr8_mapOutToOnePort, EPPL_COUNTARGS(pins))(pout, port, val, flags, pins)
190 
203  #define EPPL_avr8_mapOutModify_DDR(m) xEPPL_avr8_mapOutModify_DDR(EPPL_avr8_modeGet(m))
204 
210  #define EPPL_avr8_mapOutModify_PORT(m) xEPPL_avr8_mapOutModify_PORT(EPPL_avr8_modeGet(m))
211 
217  #define EPPL_avr8_mapOutNegate_DDR(m) xEPPL_avr8_mapOutNegate_DDR(EPPL_avr8_modeGet(m))
218 
224  #define EPPL_avr8_mapOutNegate_PORT(m) xEPPL_avr8_mapOutNegate_PORT(EPPL_avr8_modeGet(m))
225 
227  #define xEPPL_avr8_mapOutModify_DDR(m) ( ((m)==EPPL_mode_outOC) || ((m)==EPPL_mode_outOE) || ((m)==EPPL_mode_outPU) )
228 
229  #define xEPPL_avr8_mapOutModify_PORT(m) ( ((m)==EPPL_mode_outPP) || ((m)==EPPL_mode_outOE) || ((m)==EPPL_mode_outPU) )
230 
231  #define xEPPL_avr8_mapOutNegate_DDR(m) ( ((m)==EPPL_mode_outOC) || ((m)==EPPL_mode_outPU) )
232 
233  #define xEPPL_avr8_mapOutNegate_PORT(m) ( 0 )
234 
253 #define EPPL_avr8_generateMapOutToOnePortOpt(repeatcntd, flags, mode, val, pins...) \
254  do{ \
255  if(0 != EPPL_GETSUBSET(EPPL_checkPortNr, repeatcntd, EPPL_extractPinPos, |, pins)) { \
256  if(1 == EPPL_GETSUBSET(EPPL_checkPortNr, repeatcntd, EPPL_extractOne, +, pins)) { \
257  if(EPPL_avr8_mapOutModify_DDR(mode)) \
258  eppl_avr8_mapOutToOnePort((uint8_t*)EPPL_avr8_CPORTREG(DDR, repeatcntd), repeatcntd, EPPL_avr8_mapOutNegate_DDR(mode) ? (uint8_t)~(val) : (val), (flags) | EPPL_avr8_mapOutFlag_direct, pins); \
259  if(EPPL_avr8_mapOutModify_PORT(mode)) \
260  eppl_avr8_mapOutToOnePort((uint8_t*)EPPL_avr8_CPORTREG(PORT, repeatcntd), repeatcntd, EPPL_avr8_mapOutNegate_PORT(mode) ? (uint8_t)~(val) : (val), (flags) | EPPL_avr8_mapOutFlag_direct, pins); \
261  } else { \
262  uint8_t sval = sval; \
263  eppl_avr8_mapOutToOnePort(&sval, repeatcntd, val, flags, pins); \
264  if(0xff == EPPL_GETSUBSET(EPPL_checkPortNr, repeatcntd, EPPL_extractPinPos, |, pins)) { \
265  if(EPPL_avr8_mapOutModify_DDR(mode)) \
266  *EPPL_avr8_CPORTREG(DDR, repeatcntd) = EPPL_avr8_mapOutNegate_DDR(mode) ? (uint8_t)~(sval) : (sval); \
267  if(EPPL_avr8_mapOutModify_PORT(mode)) \
268  *EPPL_avr8_CPORTREG(PORT, repeatcntd) = EPPL_avr8_mapOutNegate_PORT(mode) ? (uint8_t)~(sval) : (sval); \
269  } else { \
270  if(EPPL_avr8_mapOutModify_DDR(mode)) \
271  { \
272  uint8_t temp = *EPPL_avr8_CPORTREG(DDR, repeatcntd); \
273  temp ^= ( temp ^ ( EPPL_avr8_mapOutNegate_DDR(mode) ? (uint8_t)~(sval) : (sval) ) ) & EPPL_GETSUBSET(EPPL_checkPortNr, repeatcntd, EPPL_extractPinPos, |, pins); \
274  *EPPL_avr8_CPORTREG(DDR, repeatcntd) = temp; \
275  } \
276  if(EPPL_avr8_mapOutModify_PORT(mode)) \
277  { \
278  uint8_t temp = *EPPL_avr8_CPORTREG(PORT, repeatcntd); \
279  temp ^= ( temp ^ ( EPPL_avr8_mapOutNegate_PORT(mode) ? (uint8_t)~(sval) : (sval) ) ) & EPPL_GETSUBSET(EPPL_checkPortNr, repeatcntd, EPPL_extractPinPos, |, pins); \
280  *EPPL_avr8_CPORTREG(PORT, repeatcntd) = temp; \
281  } \
282  } \
283  } \
284  } \
285  }while(0);
286 
301 #define EPPL_avr8_generateMapOutToOnePort(repeatcntd, mode, val, pins...) EPPL_avr8_generateMapOutToOnePortOpt(repeatcntd, __builtin_constant_p(val) ? EPPL_avr8_mapOutFlag_const : 0, mode, val, pins)
302 
310 #define EPPL_avr8_MapOutIsAtomicAccessReg(reg, port, pinconfigs...) \
311  ( \
312  (0 == EPPL_GETSUBSET(EPPL_avr8_reinit_is##reg##UNSAFE, port, EPPL_extractPinPos, |, pinconfigs)) || \
313  (0xff == EPPL_GETSUBSET(EPPL_avr8_reinit_is##reg##UNSAFE, port, EPPL_extractPinPos, |, pinconfigs)) || \
314  ((1 == EPPL_GETSUBSET(EPPL_avr8_reinit_is##reg##UNSAFE, port, EPPL_extractOne, +, pinconfigs)) && EPPL_avr8_CheckRegSupportsBit(EPPL_avr8_CPORTREG(reg, port))) \
315  )
316 
329 #define EPPL_avr8_MapOutIsSafe(mode, port, pins...) \
330  (\
331  (\
332  !EPPL_avr8_mapOutModify_DDR(mode) || \
333  !EPPL_GETSUBSET(EPPL_avr8_reinit_isDDRUNSAFE, port, EPPL_extractPinPos, |, EPPL_HOTPINS) || \
334  EPPL_avr8_MapOutIsAtomicAccessReg(DDR, port, pins) \
335  ) && \
336  (\
337  !EPPL_avr8_mapOutModify_PORT(mode) || \
338  !EPPL_GETSUBSET(EPPL_avr8_reinit_isPORTUNSAFE, port, EPPL_extractPinPos, |, EPPL_HOTPINS) || \
339  EPPL_avr8_MapOutIsAtomicAccessReg(PORT, port, pins) \
340  ) \
341  )
342 
344 #endif /* EPPL_AVR8_MAPOUT_H_INCLUDED */