pdc.c

Go to the documentation of this file.
00001 /*This file has been prepared for Doxygen automatic documentation generation.*/
00022 /* Copyright (c) 2006, Atmel Corporation All rights reserved.
00023  *
00024  * Redistribution and use in source and binary forms, with or without
00025  * modification, are permitted provided that the following conditions are met:
00026  *
00027  * 1. Redistributions of source code must retain the above copyright notice,
00028  * this list of conditions and the following disclaimer.
00029  *
00030  * 2. Redistributions in binary form must reproduce the above copyright notice,
00031  * this list of conditions and the following disclaimer in the documentation
00032  * and/or other materials provided with the distribution.
00033  *
00034  * 3. The name of ATMEL may not be used to endorse or promote products derived
00035  * from this software without specific prior written permission.
00036  *
00037  * THIS SOFTWARE IS PROVIDED BY ATMEL ``AS IS'' AND ANY EXPRESS OR IMPLIED
00038  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00039  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND
00040  * SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT,
00041  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00042  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00043  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00044  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00045  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00046  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00047  */
00048 
00049 #include "pdc.h"
00050 
00052 #define PDC_TXTDIS_OFFSET   9
00053 #define PDC_TXTEN_OFFSET    8
00054 #define PDC_RXTDIS_OFFSET   1
00055 #define PDC_RXTEN_OFFSET    0
00056 
00058 struct peripheral_t
00059 {
00060     /* 0x00 */
00061     volatile       unsigned long _reserved[64];
00062     /* 0x100 PDC start */
00064     volatile       unsigned long rpr;
00066     volatile       unsigned long rcr;
00068     volatile       unsigned long tpr;
00070     volatile       unsigned long tcr;
00072     volatile       unsigned long rnpr;
00074     volatile       unsigned long rncr;
00076     volatile       unsigned long tnpr;
00078     volatile       unsigned long tncr;
00080     volatile       unsigned long ptcr;
00082     volatile const unsigned long ptsr;
00083 };
00084 
00085 
00090 void pdc_disable(void * dev)
00091 {
00092     /* Disable RX and TX */
00093     ((struct peripheral_t *)dev)->ptcr =
00094         (1<<PDC_RXTDIS_OFFSET)|(1<<PDC_TXTDIS_OFFSET);
00095 }
00096 
00097 
00102 void pdc_enable(void * dev)
00103 {
00104     /* Enable RX and TX */
00105     ((struct peripheral_t *)dev)->ptcr =
00106         (1<<PDC_RXTEN_OFFSET)|(1<<PDC_TXTEN_OFFSET);
00107 }
00108 
00109 
00114 void pdc_disableRx(void * dev)
00115 {
00116     /* Disable RX */
00117     ((struct peripheral_t *)dev)->ptcr = (1<<PDC_RXTDIS_OFFSET);
00118 }
00119 
00120 
00125 void pdc_disableTx(void * dev)
00126 {
00127     /* Disable TX */
00128     ((struct peripheral_t *)dev)->ptcr = (1<<PDC_TXTDIS_OFFSET);
00129 }
00130 
00131 
00138 void pdc_enableRx(void * dev)
00139 {
00140     /* Enable RX */
00141     ((struct peripheral_t *)dev)->ptcr = (1<<PDC_RXTEN_OFFSET);
00142 }
00143 
00144 
00151 void pdc_enableTx(void * dev)
00152 {
00153     ((struct peripheral_t *)dev)->ptcr = (1<<PDC_TXTEN_OFFSET);
00154 }
00155 
00156 
00166 void pdc_setRxBuf(void * dev,
00167         void * rp,
00168         unsigned short rc,
00169         void * rnp,
00170         unsigned short rnc)
00171 {
00172     pdc_disableRx(dev);
00173 
00174     if (rp == 0 || rc == 0) {
00175         return;
00176     }
00177 
00178     ((struct peripheral_t *)dev)->rpr = (long)rp;
00179     ((struct peripheral_t *)dev)->rcr = rc;
00180 
00181     if (rnp != 0) {
00182         ((struct peripheral_t *)dev)->rnpr = (long)rnp;
00183         ((struct peripheral_t *)dev)->rncr = rnc;
00184     }
00185 
00186     pdc_enableRx(dev);
00187 
00188     return;
00189 }
00190 
00191 
00199 void pdc_setRxNextBuf(void * dev,
00200         void * rnp,
00201         unsigned short rnc)
00202 {
00203     if (rnp == 0 || rnc == 0) {
00204         return;
00205     }
00206 
00207     ((struct peripheral_t *)dev)->rnpr = (long)rnp;
00208     ((struct peripheral_t *)dev)->rncr = rnc;
00209 
00210     return;
00211 }
00212 
00213 
00223 void pdc_setTxBuf(void * dev,
00224         void * tp,
00225         unsigned short tc,
00226         void * tnp,
00227         unsigned short tnc)
00228 {
00229     pdc_disableTx(dev);
00230 
00231     if (tp == 0 || tc == 0) {
00232         return;
00233     }
00234 
00235     ((struct peripheral_t *)dev)->tpr = (long)tp;
00236     ((struct peripheral_t *)dev)->tcr = tc;
00237 
00238     if (tnp != 0) {
00239         ((struct peripheral_t *)dev)->tnpr = (long)tnp;
00240         ((struct peripheral_t *)dev)->tncr = tnc;
00241     }
00242 
00243     pdc_enableTx(dev);
00244 
00245     return;
00246 }
00247 
00248 
00256 void pdc_setTxNextBuf(void * dev,
00257         void * tnp,
00258         unsigned short tnc)
00259 {
00260     if (tnp == 0 || tnc == 0) {
00261         return;
00262     }
00263 
00264     ((struct peripheral_t *)dev)->tnpr = (long)tnp;
00265     ((struct peripheral_t *)dev)->tncr = tnc;
00266 
00267     return;
00268 }
00269 
00270 
00277 int pdc_getRcr(void * dev)
00278 {
00279     int bytes = 0;
00280     bytes += ((struct peripheral_t *)dev)->rcr;
00281 
00282     return bytes;
00283 }
00284 
00285 
00292 int pdc_rxBytesLeft(void * dev)
00293 {
00294     int bytes = 0;
00295     bytes += ((struct peripheral_t *)dev)->rcr;
00296     bytes += ((struct peripheral_t *)dev)->rncr;
00297 
00298     return bytes;
00299 }
00300 
00301 
00308 int pdc_getTcr(void * dev)
00309 {
00310     int bytes = 0;
00311     bytes += ((struct peripheral_t *)dev)->tcr;
00312 
00313     return bytes;
00314 }
00315 
00316 
00323 int pdc_txBytesLeft(void * dev)
00324 {
00325     int bytes = 0;
00326     bytes += ((struct peripheral_t *)dev)->tcr;
00327     bytes += ((struct peripheral_t *)dev)->tncr;
00328 
00329     return bytes;
00330 }
00331 
00332 
00338 void pdc_flushCache(void * buffer, unsigned short size)
00339 {
00340     unsigned int i;
00341     long memoryAddress = (long) buffer;
00342 
00343     for (i = 0; i < size; ++i) {
00344 #ifdef __GNUC__
00345         __builtin_cache((void *)memoryAddress, 0x0C);
00346 #elif __ICCAVR32__
00347         __cache_control((void *)memoryAddress, 0x0C);
00348 #else
00349 #error No valid compiler for pdc_flushCache() function
00350 #endif
00351 
00352         memoryAddress += 32;
00353     }
00354 }
00355 
00356 
00365 void * pdc_translatePtr(void *pointerAddr)
00366 {
00367     unsigned long returnAddress = (unsigned long) pointerAddr;
00368 
00369     /* Mapping between virtual address and physical address when the
00370      * MCU has been reset, and the MMU is not being used, is done by
00371      * clearing MSB in the memory address.
00372      *
00373      * For more details conserning the MMU see application note
00374      * AVR32113 Configuration and Use of the Memory Managment Unit.
00375      */
00376     returnAddress &= ~(0x80000000);
00377 
00378     return (void *) returnAddress;
00379 }
00380 

Generated on Wed May 10 15:03:11 2006 for AVR32108 - Peripheral Direct Memory Access Driver by  doxygen 1.4.6-NO