pdc.c File Reference


Detailed Description

SSC I2S example application.

This file gives an example of using the PDC to burst data on the USART.

Author:
Atmel Corporation: http://www.atmel.com
Support email: avr32@atmel.com
$Name$
Revision
42
$RCSfile$
Date
2006-03-22 09:08:08 +0100 (Wed, 22 Mar 2006)

Definition in file pdc.c.

#include "pdc.h"

Include dependency graph for pdc.c:

Go to the source code of this file.

Data Structures

struct  peripheral_t

Defines

#define PDC_RXTDIS_OFFSET   1
#define PDC_RXTEN_OFFSET   0
#define PDC_TXTDIS_OFFSET   9
#define PDC_TXTEN_OFFSET   8

Functions

void pdc_disable (void *dev)
 Disable the PDC for the given peripheral device.
void pdc_disableRx (void *dev)
 Disable the PDC receiver.
void pdc_disableTx (void *dev)
 Disable the PDC transmitter.
void pdc_enable (void *dev)
 Enable the PDC for the given peripheral device.
void pdc_enableRx (void *dev)
 Enable the PDC receiver, the buffers will remain the same as they were before PDC got disabled (ie. the PDC continues were it left of.
void pdc_enableTx (void *dev)
 Enable the PDC transmitter, the buffers will remain the same as they were before PDC got disabled (ie. the PDC continues were it left of).
void pdc_flushCache (void *buffer, unsigned short size)
 Flush the cache at a given address.
int pdc_getRcr (void *dev)
 Check remaining size of current receive buffer.
int pdc_getTcr (void *dev)
 Check remaining size of current transmit buffer.
int pdc_rxBytesLeft (void *dev)
 Check total remaining size of the receive buffers.
void pdc_setRxBuf (void *dev, void *rp, unsigned short rc, void *rnp, unsigned short rnc)
 Give pointers and size of receive buffers to the PDC (Peripheral DMA Controller), and enables the receiver.
void pdc_setRxNextBuf (void *dev, void *rnp, unsigned short rnc)
 Give pointers and size of the next receive buffers to the PDC (Peripheral DMA Controller).
void pdc_setTxBuf (void *dev, void *tp, unsigned short tc, void *tnp, unsigned short tnc)
 Give pointers and size of transmit buffers to the PDC (Peripheral DMA Controller), and enables the transmitter.
void pdc_setTxNextBuf (void *dev, void *tnp, unsigned short tnc)
 Give pointers and size of the next transmit buffers to add to the PDC (Peripheral DMA Controller).
void * pdc_translatePtr (void *pointerAddr)
 Translates memory addresses from P1, P2, P3 and P4 memory space to the P0 memory space. This function is only valid if the MMU is not used.
int pdc_txBytesLeft (void *dev)
 Check total remaining size of the transmit buffers.


Define Documentation

#define PDC_RXTDIS_OFFSET   1

Definition at line 26 of file pdc.c.

Referenced by pdc_disable(), and pdc_disableRx().

#define PDC_RXTEN_OFFSET   0

Definition at line 27 of file pdc.c.

Referenced by pdc_enable(), and pdc_enableRx().

#define PDC_TXTDIS_OFFSET   9

Defines to ease code readability, specific for AP7000 device

Definition at line 24 of file pdc.c.

Referenced by pdc_disable(), and pdc_disableTx().

#define PDC_TXTEN_OFFSET   8

Definition at line 25 of file pdc.c.

Referenced by pdc_enable(), and pdc_enableTx().


Function Documentation

void pdc_disable ( void *  dev  ) 

Disable the PDC for the given peripheral device.

Parameters:
dev pointer to the base memory address of the device

Definition at line 62 of file pdc.c.

References PDC_RXTDIS_OFFSET, and PDC_TXTDIS_OFFSET.

00063 {
00064         /* Disable RX and TX */
00065         ((struct peripheral_t *)dev)->ptcr =
00066                 (1<<PDC_RXTDIS_OFFSET)|(1<<PDC_TXTDIS_OFFSET);
00067 }

void pdc_disableRx ( void *  dev  ) 

Disable the PDC receiver.

Parameters:
dev pointer to the base memory address of the device

Definition at line 86 of file pdc.c.

References PDC_RXTDIS_OFFSET.

Referenced by pdc_setRxBuf().

00087 {
00088         /* Disable RX */
00089         ((struct peripheral_t *)dev)->ptcr = (1<<PDC_RXTDIS_OFFSET);
00090 }

void pdc_disableTx ( void *  dev  ) 

Disable the PDC transmitter.

Parameters:
dev pointer to the base memory address of the device

Definition at line 97 of file pdc.c.

References PDC_TXTDIS_OFFSET.

Referenced by pdc_setTxBuf().

00098 {
00099         /* Disable TX */
00100         ((struct peripheral_t *)dev)->ptcr = (1<<PDC_TXTDIS_OFFSET);
00101 }

void pdc_enable ( void *  dev  ) 

Enable the PDC for the given peripheral device.

Parameters:
dev pointer to the base memory address of the device

Definition at line 74 of file pdc.c.

References PDC_RXTEN_OFFSET, and PDC_TXTEN_OFFSET.

Referenced by main().

00075 {
00076         /* Enable RX and TX */
00077         ((struct peripheral_t *)dev)->ptcr =
00078                 (1<<PDC_RXTEN_OFFSET)|(1<<PDC_TXTEN_OFFSET);
00079 }

void pdc_enableRx ( void *  dev  ) 

Enable the PDC receiver, the buffers will remain the same as they were before PDC got disabled (ie. the PDC continues were it left of.

Parameters:
dev pointer to the base memory address of the device

Definition at line 110 of file pdc.c.

References PDC_RXTEN_OFFSET.

Referenced by pdc_setRxBuf().

00111 {
00112         /* Enable RX */
00113         ((struct peripheral_t *)dev)->ptcr = (1<<PDC_RXTEN_OFFSET);
00114 }

void pdc_enableTx ( void *  dev  ) 

Enable the PDC transmitter, the buffers will remain the same as they were before PDC got disabled (ie. the PDC continues were it left of).

Parameters:
dev pointer to the base memory address of the device

Definition at line 123 of file pdc.c.

References PDC_TXTEN_OFFSET.

Referenced by pdc_setTxBuf().

00124 {
00125         ((struct peripheral_t *)dev)->ptcr = (1<<PDC_TXTEN_OFFSET);
00126 }

void pdc_flushCache ( void *  buffer,
unsigned short  size 
)

Flush the cache at a given address.

Parameters:
buffer address to a buffer in memory
size size of the buffer

Definition at line 310 of file pdc.c.

Referenced by main(), and usart_int_handler().

00311 {
00312         unsigned int i;
00313         long memoryAddress = (long) buffer;
00314 
00315         for( i = 0; i < size; ++i ) {
00316                 __asm__ volatile ( "cache %0, 0x0C\n"
00317                                 :
00318                                 : "r"(memoryAddress) );
00319 
00320                 memoryAddress += 32;
00321         }
00322 }

int pdc_getRcr ( void *  dev  ) 

Check remaining size of current receive buffer.

Parameters:
dev pointer to the base memory address of the device
Returns:
number of free bytes remaining in the current receive buffer

Definition at line 249 of file pdc.c.

00250 {
00251         int bytes = 0;
00252         bytes += ((struct peripheral_t *)dev)->rcr;
00253 
00254         return bytes;
00255 }

int pdc_getTcr ( void *  dev  ) 

Check remaining size of current transmit buffer.

Parameters:
dev pointer to the base memory address of the device
Returns:
number of free bytes remaining in the current transmit buffer

Definition at line 280 of file pdc.c.

00281 {
00282         int bytes = 0;
00283         bytes += ((struct peripheral_t *)dev)->tcr;
00284 
00285         return bytes;
00286 }

int pdc_rxBytesLeft ( void *  dev  ) 

Check total remaining size of the receive buffers.

Parameters:
dev pointer to the base memory address of the device
Returns:
total number of free bytes remaining in the receive buffers

Definition at line 264 of file pdc.c.

00265 {
00266         int bytes = 0;
00267         bytes += ((struct peripheral_t *)dev)->rcr;
00268         bytes += ((struct peripheral_t *)dev)->rncr;
00269 
00270         return bytes;
00271 }

void pdc_setRxBuf ( void *  dev,
void *  rp,
unsigned short  rc,
void *  rnp,
unsigned short  rnc 
)

Give pointers and size of receive buffers to the PDC (Peripheral DMA Controller), and enables the receiver.

Parameters:
dev pointer to the base memory address of the device
rp pointer to the receive buffer
rc size of the receive buffer
rnp pointer to the next receive buffer
rnc size of the next receive buffer

Definition at line 138 of file pdc.c.

References pdc_disableRx(), and pdc_enableRx().

Referenced by main().

00143 {
00144         pdc_disableRx( dev );
00145 
00146         if( rp == 0 || rc == 0 ) {
00147                 return;
00148         }
00149 
00150         ((struct peripheral_t *)dev)->rpr = (long)rp;
00151         ((struct peripheral_t *)dev)->rcr = rc;
00152 
00153         if( rnp != 0 ) {
00154                 ((struct peripheral_t *)dev)->rnpr = (long)rnp;
00155                 ((struct peripheral_t *)dev)->rncr = rnc;
00156         }
00157 
00158         pdc_enableRx( dev );
00159 
00160         return;
00161 }

Here is the call graph for this function:

void pdc_setRxNextBuf ( void *  dev,
void *  rnp,
unsigned short  rnc 
)

Give pointers and size of the next receive buffers to the PDC (Peripheral DMA Controller).

Parameters:
dev pointer to the base memory address of the device
rnp pointer to the next receive buffer
rnc size of the next receive buffer

Definition at line 171 of file pdc.c.

Referenced by usart_int_handler().

00174 {
00175         if( rnp == 0 || rnc == 0 ) {
00176                 return;
00177         }
00178 
00179         ((struct peripheral_t *)dev)->rnpr = (long)rnp;
00180         ((struct peripheral_t *)dev)->rncr = rnc;
00181 
00182         return;
00183 }

void pdc_setTxBuf ( void *  dev,
void *  tp,
unsigned short  tc,
void *  tnp,
unsigned short  tnc 
)

Give pointers and size of transmit buffers to the PDC (Peripheral DMA Controller), and enables the transmitter.

Parameters:
dev pointer to the base memory address of the device
tp pointer to the transmit buffer
tc size of the transmit buffer
tnp pointer to the next transmit buffer
tnc size of the next transmit buffer

Definition at line 195 of file pdc.c.

References pdc_disableTx(), and pdc_enableTx().

Referenced by main().

00200 {
00201         pdc_disableTx( dev );
00202 
00203         if( tp == 0 || tc == 0 ) {
00204                 return;
00205         }
00206 
00207         ((struct peripheral_t *)dev)->tpr = (long)tp;
00208         ((struct peripheral_t *)dev)->tcr = tc;
00209 
00210         if( tnp != 0 ) {
00211                 ((struct peripheral_t *)dev)->tnpr = (long)tnp;
00212                 ((struct peripheral_t *)dev)->tncr = tnc;
00213         }
00214 
00215         pdc_enableTx( dev );
00216 
00217         return;
00218 }

Here is the call graph for this function:

void pdc_setTxNextBuf ( void *  dev,
void *  tnp,
unsigned short  tnc 
)

Give pointers and size of the next transmit buffers to add to the PDC (Peripheral DMA Controller).

Parameters:
dev pointer to the base memory address of the device
tnp pointer to the next transmit buffer
tnc size of the next transmit buffer

Definition at line 228 of file pdc.c.

00231 {
00232         if( tnp == 0 || tnc == 0 ) {
00233                 return;
00234         }
00235 
00236         ((struct peripheral_t *)dev)->tnpr = (long)tnp;
00237         ((struct peripheral_t *)dev)->tncr = tnc;
00238 
00239         return;
00240 }

void* pdc_translatePtr ( void *  pointerAddr  ) 

Translates memory addresses from P1, P2, P3 and P4 memory space to the P0 memory space. This function is only valid if the MMU is not used.

Parameters:
pointerAddr address to the pointer which shall be translated
Returns:
translated address

Definition at line 333 of file pdc.c.

Referenced by main(), and usart_int_handler().

00334 {
00335         unsigned long returnAddress = (unsigned long) pointerAddr;
00336 
00337         /* Mapping between virtual address and physical address when the
00338          * MCU has been reset, and the MMU is not being used, is done by
00339          * clearing MSB in the memory address.
00340          *
00341          * For more details conserning the MMU see application note
00342          * AVR32113 Configuration and Use of the Memory Managment Unit.
00343          */
00344         returnAddress &= ~(0x80000000);
00345 
00346         return (void *) returnAddress;
00347 }

int pdc_txBytesLeft ( void *  dev  ) 

Check total remaining size of the transmit buffers.

Parameters:
dev pointer to the base memory address of the device
Returns:
total number of free bytes remaining in the transmit buffers

Definition at line 295 of file pdc.c.

00296 {
00297         int bytes = 0;
00298         bytes += ((struct peripheral_t *)dev)->tcr;
00299         bytes += ((struct peripheral_t *)dev)->tncr;
00300 
00301         return bytes;
00302 }


Generated on Thu May 10 14:14:48 2007 for AVR321000 Communication with the AVR32 USART by  doxygen 1.5.1