EPPL  0.1 alpha
 All Files Typedefs Groups Pages
eppl_avr8_mapin.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_MAPIN_H_INCLUDED
40 #define EPPL_AVR8_MAPIN_H_INCLUDED
41 
66 #define EPPL_avr8_mapInMaskedPins(temp, pos, pin, mask) \
67  EPPL_avr8_LRSH((uint8_t)((uint8_t)(temp) & (uint8_t)((mask)<<EPPL_PINNR(pin))), pos, EPPL_PINNR(pin))
68 
89  #define EPPL_avr8_mapInTempPinsNear1(pout, temp, direct, pos, pin) \
90  do{ \
91  if(direct){ \
92  if((temp) & (uint8_t)(1U<<EPPL_PINNR(pin))) \
93  *(pout) |= (uint8_t)(1U<<(pos)); \
94  } \
95  else { \
96  eppl_avr8_asm_bitcpy(*(pout), pos, temp, EPPL_PINNR(pin)); \
97  } \
98  }while(0)
99 
100  #define EPPL_avr8_mapInTempPinsNear2(pout, temp, direct, pos, pin) *(pout) |= EPPL_avr8_mapInMaskedPins(temp, pos, pin, 0x03)
101 
102  #define EPPL_avr8_mapInTempPinsNear3(pout, temp, direct, pos, pin) *(pout) |= EPPL_avr8_mapInMaskedPins(temp, pos, pin, 0x07)
103 
104  #define EPPL_avr8_mapInTempPinsNear4(pout, temp, direct, pos, pin) *(pout) |= EPPL_avr8_mapInMaskedPins(temp, pos, pin, 0x0f)
105 
106  #define EPPL_avr8_mapInTempPinsNear5(pout, temp, direct, pos, pin) *(pout) |= EPPL_avr8_mapInMaskedPins(temp, pos, pin, 0x1f)
107 
108  #define EPPL_avr8_mapInTempPinsNear6(pout, temp, direct, pos, pin) *(pout) |= EPPL_avr8_mapInMaskedPins(temp, pos, pin, 0x3f)
109 
110  #define EPPL_avr8_mapInTempPinsNear7(pout, temp, direct, pos, pin) *(pout) |= EPPL_avr8_mapInMaskedPins(temp, pos, pin, 0x7f)
111 
112  #define EPPL_avr8_mapInTempPinsNear8(pout, temp, direct, pos, pin) *(pout) |= EPPL_avr8_mapInMaskedPins(temp, pos, pin, 0xff)
113 
125  static inline void eppl_avr8_mapInFromOnePort1(uint8_t *pout, uint8_t port, uint8_t temp, uint8_t direct, eppl_pin_t pin1) __attribute__((always_inline));
126  static inline void eppl_avr8_mapInFromOnePort2(uint8_t *pout, uint8_t port, uint8_t temp, uint8_t direct, eppl_pin_t pin1, eppl_pin_t pin2) __attribute__((always_inline));
127  static inline void eppl_avr8_mapInFromOnePort3(uint8_t *pout, uint8_t port, uint8_t temp, uint8_t direct, eppl_pin_t pin1, eppl_pin_t pin2, eppl_pin_t pin3) __attribute__((always_inline));
128  static inline void eppl_avr8_mapInFromOnePort4(uint8_t *pout, uint8_t port, uint8_t temp, uint8_t direct, eppl_pin_t pin1, eppl_pin_t pin2, eppl_pin_t pin3, eppl_pin_t pin4) __attribute__((always_inline));
129  static inline void eppl_avr8_mapInFromOnePort5(uint8_t *pout, uint8_t port, uint8_t temp, uint8_t direct, eppl_pin_t pin1, eppl_pin_t pin2, eppl_pin_t pin3, eppl_pin_t pin4, eppl_pin_t pin5) __attribute__((always_inline));
130  static inline void eppl_avr8_mapInFromOnePort6(uint8_t *pout, uint8_t port, uint8_t temp, uint8_t direct, 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));
131  static inline void eppl_avr8_mapInFromOnePort7(uint8_t *pout, uint8_t port, uint8_t temp, uint8_t direct, 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));
132  static inline void eppl_avr8_mapInFromOnePort8(uint8_t *pout, uint8_t port, uint8_t temp, uint8_t direct, 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));
133 
453 #define EPPL_avr8_mapInFromOnePort(pout, port, temp, direct, pins...) EPPL_LC(eppl_avr8_mapInFromOnePort, EPPL_COUNTARGS(pins))(pout, port, temp, direct, pins)
454 
464 #define EPPL_avr8_generateMapInFromOnePort(repeatcntd, pins...) \
465  (__extension__({ \
466  uint8_t out = 0; \
467  if(0 != EPPL_GETSUBSET(EPPL_checkPortNr, repeatcntd, EPPL_extractPinPos, |, pins)) { \
468  if(1 == EPPL_GETSUBSET(EPPL_checkPortNr, repeatcntd, EPPL_extractOne, +, pins)) { \
469  EPPL_avr8_mapInFromOnePort(&out, repeatcntd, *EPPL_avr8_CPORTREG(PIN, repeatcntd), 1, pins); \
470  } \
471  else { \
472  uint8_t temp = *EPPL_avr8_CPORTREG(PIN, repeatcntd); \
473  EPPL_avr8_mapInFromOnePort(&out, repeatcntd, temp, 0, pins); \
474  } \
475  } \
476  out; \
477  })) |
478 
480 #endif /* EPPL_AVR8_MAPIN_H_INCLUDED */