porttran.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2008 by egnite GmbH
00003  *
00004  * All rights reserved.
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions
00008  * are met:
00009  *
00010  * 1. Redistributions of source code must retain the above copyright
00011  *    notice, this list of conditions and the following disclaimer.
00012  * 2. Redistributions in binary form must reproduce the above copyright
00013  *    notice, this list of conditions and the following disclaimer in the
00014  *    documentation and/or other materials provided with the distribution.
00015  * 3. Neither the name of the copyright holders nor the names of
00016  *    contributors may be used to endorse or promote products derived
00017  *    from this software without specific prior written permission.
00018  *
00019  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00020  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00021  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00022  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00023  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00024  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00025  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
00026  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
00027  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00028  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
00029  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00030  * SUCH DAMAGE.
00031  *
00032  * For additional information see http://www.ethernut.de/
00033  *
00034  */
00035 
00036 /*
00037  * $Id: porttran.h,v 1.1 2008/10/23 08:55:10 haraldkipp Exp $
00038  */
00039 
00040 #include <cfg/arch.h>
00041 
00046 
00110 /*
00111  * Remove any previously defined register names.
00112  */
00113 #undef  GPIO_PE_REG
00114 #undef  GPIO_PD_REG
00115 #undef  GPIO_PS_REG
00116 
00117 #undef  GPIO_OE_REG
00118 #undef  GPIO_OD_REG
00119 #undef  GPIO_OS_REG
00120 
00121 #undef  GPIO_SOD_REG
00122 #undef  GPIO_COD_REG
00123 #undef  GPIO_ODS_REG
00124 
00125 #undef  GPIO_PDS_REG
00126 
00127 #undef  GPIO_PUE_REG
00128 #undef  GPIO_PUD_REG
00129 #undef  GPIO_PUS_REG
00130 
00131 #if defined(__AVR__)
00132 /*
00133  * Determine AVR port names.
00134  */
00135 #include <cfg/arch/avr.h>
00136 
00137 #if GPIO_ID == PIOB_ID
00138 #define GPIO_PDS_REG    PINB
00139 #define GPIO_SOD_REG    PORTB
00140 #define GPIO_OE_REG     DDRB
00141 #define GPIO_PUE_REG    PORTB
00142 
00143 #elif  GPIO_ID == PIOC_ID
00144 #define GPIO_PDS_REG    PINC
00145 #define GPIO_SOD_REG    PORTC
00146 #define GPIO_OE_REG     DDRC
00147 #define GPIO_PUE_REG    PORTC
00148 
00149 #elif  GPIO_ID == PIOD_ID
00150 #define GPIO_PDS_REG    PIND
00151 #define GPIO_SOD_REG    PORTD
00152 #define GPIO_OE_REG     DDRD
00153 #define GPIO_PUE_REG    PORTD
00154 
00155 #elif  GPIO_ID == PIOE_ID
00156 #define GPIO_PDS_REG    PINE
00157 #define GPIO_SOD_REG    PORTE
00158 #define GPIO_OE_REG     DDRE
00159 #define GPIO_PUE_REG    PORTE
00160 
00161 #elif  GPIO_ID == PIOF_ID
00162 #define GPIO_PDS_REG    PINF
00163 #define GPIO_SOD_REG    PORTF
00164 #define GPIO_OE_REG     DDRF
00165 #define GPIO_PUE_REG    PORTF
00166 
00167 #elif  GPIO_ID == PIOG_ID
00168 #define GPIO_PDS_REG    PING
00169 #define GPIO_SOD_REG    PORTG
00170 #define GPIO_OE_REG     DDRG
00171 #define GPIO_PUE_REG    PORTG
00172 
00173 #elif  GPIO_ID == PIOH_ID
00174 #define GPIO_PDS_REG    PINH
00175 #define GPIO_SOD_REG    PORTH
00176 #define GPIO_OE_REG     DDRH
00177 #define GPIO_PUE_REG    PORTH
00178 
00179 #elif  GPIO_ID == PIOI_ID
00180 #define GPIO_PDS_REG    PINI
00181 #define GPIO_SOD_REG    PORTI
00182 #define GPIO_OE_REG     DDRI
00183 #define GPIO_PUE_REG    PORTI
00184 
00185 #elif  GPIO_ID == PIOJ_ID
00186 #define GPIO_PDS_REG    PINJ
00187 #define GPIO_SOD_REG    PORTJ
00188 #define GPIO_OE_REG     DDRJ
00189 #define GPIO_PUE_REG    PORTJ
00190 
00191 #elif  GPIO_ID == PIOK_ID
00192 #define GPIO_PDS_REG    PINK
00193 #define GPIO_SOD_REG    PORTK
00194 #define GPIO_OE_REG     DDRK
00195 #define GPIO_PUE_REG    PORTK
00196 
00197 #elif  GPIO_ID == PIOL_ID
00198 #define GPIO_PDS_REG    PINL
00199 #define GPIO_SOD_REG    PORTL
00200 #define GPIO_OE_REG     DDRL
00201 #define GPIO_PUE_REG    PORTL
00202 
00203 #else
00204 #define GPIO_PDS_REG    PINA
00205 #define GPIO_SOD_REG    PORTA
00206 #define GPIO_OE_REG     DDRA
00207 #define GPIO_PUE_REG    PORTA
00208 #endif
00209 
00210 #elif defined(MCU_AT91)
00211 /*
00212  * Determine AT91 port names.
00213  */
00214 #include <arch/arm/at91.h>
00215 
00216 #if GPIO_ID == PIOA_ID
00217 #define  GPIO_PE_REG    PIOA_PER
00218 #define  GPIO_PD_REG    PIOA_PDR
00219 #define  GPIO_PS_REG    PIOA_PSR
00220 #define  GPIO_OE_REG    PIOA_OER
00221 #define  GPIO_OD_REG    PIOA_ODR
00222 #define  GPIO_OS_REG    PIOA_OSR
00223 #define  GPIO_SOD_REG   PIOA_SODR
00224 #define  GPIO_COD_REG   PIOA_CODR
00225 #define  GPIO_ODS_REG   PIOA_ODSR
00226 #define  GPIO_PDS_REG   PIOA_PDSR
00227 #if defined(PIOA_PUER)
00228 #define  GPIO_PUE_REG   PIOA_PUER
00229 #if defined(PIOA_PUDR)
00230 #define  GPIO_PUD_REG   PIOA_PUDR
00231 #define  GPIO_PUS_REG   PIOA_PUSR
00232 #endif /* PIOA_PUDR */
00233 #endif /* PIOA_PUER */
00234 #if defined(PIOA_MDER)
00235 #define  GPIO_MDE_REG   PIOA_MDER
00236 #if defined(PIOA_MDDR)
00237 #define  GPIO_MDD_REG   PIOA_MDDR
00238 #define  GPIO_MDS_REG   PIOA_MDSR
00239 #endif /* PIOA_MDDR */
00240 #endif /* PIOA_MDER */
00241 #if defined(PIOA_IFER)
00242 #define  GPIO_IFE_REG   PIOA_IFER
00243 #if defined(PIOA_IFDR)
00244 #define  GPIO_IFD_REG   PIOA_IFDR
00245 #define  GPIO_IFS_REG   PIOA_IFSR
00246 #endif /* PIOA_IFDR */
00247 #endif /* PIOA_IFER */
00248 
00249 #elif GPIO_ID == PIOB_ID
00250 #define  GPIO_PE_REG    PIOB_PER
00251 #define  GPIO_PD_REG    PIOB_PDR
00252 #define  GPIO_PS_REG    PIOB_PSR
00253 #define  GPIO_OE_REG    PIOB_OER
00254 #define  GPIO_OD_REG    PIOB_ODR
00255 #define  GPIO_OS_REG    PIOB_OSR
00256 #define  GPIO_SOD_REG   PIOB_SODR
00257 #define  GPIO_COD_REG   PIOB_CODR
00258 #define  GPIO_ODS_REG   PIOB_ODSR
00259 #define  GPIO_PDS_REG   PIOB_PDSR
00260 #if defined(PIOB_PUER)
00261 #define  GPIO_PUE_REG   PIOB_PUER
00262 #if defined(PIOB_PUDR)
00263 #define  GPIO_PUD_REG   PIOB_PUDR
00264 #define  GPIO_PUS_REG   PIOB_PUSR
00265 #endif /* PIOB_PUDR */
00266 #endif /* PIOB_PUER */
00267 #if defined(PIOB_MDER)
00268 #define  GPIO_MDE_REG   PIOB_MDER
00269 #if defined(PIOB_MDDR)
00270 #define  GPIO_MDD_REG   PIOB_MDDR
00271 #define  GPIO_MDS_REG   PIOB_MDSR
00272 #endif /* PIOB_MDDR */
00273 #endif /* PIOB_MDER */
00274 #if defined(PIOB_IFER)
00275 #define  GPIO_IFE_REG   PIOB_IFER
00276 #if defined(PIOB_IFDR)
00277 #define  GPIO_IFD_REG   PIOB_IFDR
00278 #define  GPIO_IFS_REG   PIOB_IFSR
00279 #endif /* PIOB_IFDR */
00280 #endif /* PIOB_IFER */
00281 
00282 #elif GPIO_ID == PIOC_ID
00283 #define  GPIO_PE_REG    PIOC_PER
00284 #define  GPIO_PD_REG    PIOC_PDR
00285 #define  GPIO_PS_REG    PIOC_PSR
00286 #define  GPIO_OE_REG    PIOC_OER
00287 #define  GPIO_OD_REG    PIOC_ODR
00288 #define  GPIO_OS_REG    PIOC_OSR
00289 #define  GPIO_SOD_REG   PIOC_SODR
00290 #define  GPIO_COD_REG   PIOC_CODR
00291 #define  GPIO_ODS_REG   PIOC_ODSR
00292 #define  GPIO_PDS_REG   PIOC_PDSR
00293 #if defined(PIOC_PUER)
00294 #define  GPIO_PUE_REG   PIOC_PUER
00295 #if defined(PIOC_PUDR)
00296 #define  GPIO_PUD_REG   PIOC_PUDR
00297 #define  GPIO_PUS_REG   PIOC_PUSR
00298 #endif /* PIOC_PUDR */
00299 #endif /* PIOC_PUER */
00300 #if defined(PIOC_MDER)
00301 #define  GPIO_MDE_REG   PIOC_MDER
00302 #if defined(PIOC_MDDR)
00303 #define  GPIO_MDD_REG   PIOC_MDDR
00304 #define  GPIO_MDS_REG   PIOC_MDSR
00305 #endif /* PIOC_MDDR */
00306 #endif /* PIOC_MDER */
00307 #if defined(PIOC_IFER)
00308 #define  GPIO_IFE_REG   PIOC_IFER
00309 #if defined(PIOC_IFDR)
00310 #define  GPIO_IFD_REG   PIOC_IFDR
00311 #define  GPIO_IFS_REG   PIOC_IFSR
00312 #endif /* PIOC_IFDR */
00313 #endif /* PIOC_IFER */
00314 
00315 #else /* GPIO_ID */
00316 #define  GPIO_PE_REG    PIO_PER
00317 #define  GPIO_PD_REG    PIO_PDR
00318 #define  GPIO_PS_REG    PIO_PSR
00319 #define  GPIO_OE_REG    PIO_OER
00320 #define  GPIO_OD_REG    PIO_ODR
00321 #define  GPIO_OS_REG    PIO_OSR
00322 #define  GPIO_SOD_REG   PIO_SODR
00323 #define  GPIO_COD_REG   PIO_CODR
00324 #define  GPIO_ODS_REG   PIO_ODSR
00325 #define  GPIO_PDS_REG   PIO_PDSR
00326 #if defined(PIO_PUER)
00327 #define  GPIO_PUE_REG   PIO_PUER
00328 #if defined(PIO_PUDR)
00329 #define  GPIO_PUD_REG   PIO_PUDR
00330 #define  GPIO_PUS_REG   PIO_PUSR
00331 #endif /* PIO_PUDR */
00332 #endif /* PIO_PUER */
00333 #if defined(PIO_MDER)
00334 #define  GPIO_MDE_REG   PIO_MDER
00335 #if defined(PIO_MDDR)
00336 #define  GPIO_MDD_REG   PIO_MDDR
00337 #define  GPIO_MDS_REG   PIO_MDSR
00338 #endif /* PIO_MDDR */
00339 #endif /* PIO_MDER */
00340 #if defined(PIO_IFER)
00341 #define  GPIO_IFE_REG   PIO_IFER
00342 #if defined(PIO_IFDR)
00343 #define  GPIO_IFD_REG   PIO_IFDR
00344 #define  GPIO_IFS_REG   PIO_IFSR
00345 #endif /* PIO_IFDR */
00346 #endif /* PIO_IFER */
00347 
00348 #endif /* GPIO_ID */
00349 
00350 /* Additional targets can be added here. */
00351 
00352 #endif /* MCU */
00353 
00354 
00355 /*
00356  * Remove any previously defined port macros.
00357  */
00358 #undef GPIO_SET_LO
00359 #undef GPIO_SET_HI
00360 #undef GPIO_IS_HI
00361 #undef GPIO_GET
00362 #undef GPIO_ENABLE
00363 #undef GPIO_CFG_OUTPUT
00364 #undef GPIO_CFG_INPUT
00365 #undef GPIO_PULLUP_ON
00366 #undef GPIO_PULLUP_OFF
00367 #undef GPIO_OPENDRAIN
00368 #undef GPIO_PUSHPULL
00369 
00370 #if defined(GPIO_COD_REG)
00371 #define GPIO_SET_LO(b)      outr(GPIO_COD_REG, _BV(b))
00372 #define GPIO_SET_HI(b)      outr(GPIO_SOD_REG, _BV(b))
00373 #elif defined(GPIO_SOD_REG)
00374 #define GPIO_SET_LO(b)      cbi(GPIO_SOD_REG, b)
00375 #define GPIO_SET_HI(b)      sbi(GPIO_SOD_REG, b)
00376 #else
00377 #define GPIO_SET_LO(b)
00378 #define GPIO_SET_HI(b)
00379 #endif
00380 
00381 #if defined(GPIO_ODS_REG)
00382 #define GPIO_IS_HI(b)       ((inr(GPIO_ODS_REG) & _BV(b)) == _BV(b))
00383 #elif defined(GPIO_SOD_REG)
00384 #define GPIO_IS_HI(b)       ((inr(GPIO_SOD_REG) & _BV(b)) == _BV(b))
00385 #else
00386 #define GPIO_IS_HI(b)
00387 #endif
00388 
00389 #if defined(GPIO_PDS_REG)
00390 #define GPIO_GET(b)         ((inr(GPIO_PDS_REG) & _BV(b)) == _BV(b))
00391 #else
00392 #define GPIO_GET(b)
00393 #endif
00394 
00395 #if defined(GPIO_PE_REG)
00396 #define GPIO_ENABLE(b)      outr(GPIO_PE_REG, _BV(b))
00397 #else
00398 #define GPIO_ENABLE(b)
00399 #endif
00400 
00401 #if defined(GPIO_OD_REG)
00402 #define GPIO_CFG_OUTPUT(b)  outr(GPIO_OE_REG, _BV(b))
00403 #elif defined(GPIO_OE_REG)
00404 #define GPIO_CFG_OUTPUT(b)  sbi(GPIO_OE_REG, b)
00405 #else
00406 #define GPIO_CFG_OUTPUT(b)
00407 #endif
00408 
00409 #if defined(GPIO_OD_REG)
00410 #define GPIO_CFG_INPUT(b)   outr(GPIO_OD_REG, _BV(b))
00411 #elif defined(GPIO_OE_REG)
00412 #define GPIO_CFG_INPUT(b)   cbi(GPIO_OE_REG, b)
00413 #else
00414 #define GPIO_CFG_INPUT(b)
00415 #endif
00416 
00417 #if defined(GPIO_PUD_REG)
00418 #define GPIO_PULLUP_ON(b)   outr(GPIO_PUE_REG, _BV(b))
00419 #elif defined(GPIO_PUE_REG)
00420 #define GPIO_PULLUP_ON(b)   sbi(GPIO_PUE_REG, b)
00421 #else
00422 #define GPIO_PULLUP_ON(b)
00423 #endif
00424 
00425 #if defined(GPIO_PUD_REG)
00426 #define GPIO_PULLUP_OFF(b)  outr(GPIO_PUD_REG, _BV(b))
00427 #elif defined(GPIO_PUE_REG)
00428 #define GPIO_PULLUP_OFF(b)  cbi(GPIO_PUE_REG, b)
00429 #else
00430 #define GPIO_PULLUP_OFF(b)
00431 #endif
00432 
00433 #if defined(GPIO_IFD_REG)
00434 #define GPIO_FILTER_ON(b)   outr(GPIO_IFE_REG, _BV(b))
00435 #elif defined(GPIO_IFE_REG)
00436 #define GPIO_FILTER_ON(b)   sbi(GPIO_IFE_REG, b)
00437 #else
00438 #define GPIO_FILTER_ON(b)
00439 #endif
00440 
00441 #if defined(GPIO_IFD_REG)
00442 #define GPIO_FILTER_OFF(b)  outr(GPIO_IFD_REG, _BV(b))
00443 #elif defined(GPIO_IFE_REG)
00444 #define GPIO_FILTER_OFF(b)  cbi(GPIO_IFE_REG, b)
00445 #else
00446 #define GPIO_FILTER_OFF(b)
00447 #endif
00448 
00449 #if defined(GPIO_MDD_REG)
00450 #define GPIO_OPENDRAIN(b)   outr(GPIO_MDE_REG, _BV(b))
00451 #elif defined(GPIO_MDE_REG)
00452 #define GPIO_OPENDRAIN(b)   sbi(GPIO_MDE_REG, b)
00453 #else
00454 #define GPIO_OPENDRAIN(b)
00455 #endif
00456 
00457 #if defined(GPIO_MDD_REG)
00458 #define GPIO_PUSHPULL(b)  outr(GPIO_MDD_REG, _BV(b))
00459 #elif defined(GPIO_MDE_REG)
00460 #define GPIO_PUSHPULL(b)  cbi(GPIO_MDE_REG, b)
00461 #else
00462 #define GPIO_PUSHPULL(b)
00463 #endif
00464 

© 2000-2007 by egnite Software GmbH - visit http://www.ethernut.de/