spi.h

Go to the documentation of this file.
00001 /*This file has been prepared for Doxygen automatic documentation generation.*/
00021 /* Copyright (c) 2006, Atmel Corporation All rights reserved.
00022  *
00023  * Redistribution and use in source and binary forms, with or without
00024  * modification, are permitted provided that the following conditions are met:
00025  *
00026  * 1. Redistributions of source code must retain the above copyright notice,
00027  * this list of conditions and the following disclaimer.
00028  *
00029  * 2. Redistributions in binary form must reproduce the above copyright notice,
00030  * this list of conditions and the following disclaimer in the documentation
00031  * and/or other materials provided with the distribution.
00032  *
00033  * 3. The name of ATMEL may not be used to endorse or promote products derived
00034  * from this software without specific prior written permission.
00035  *
00036  * THIS SOFTWARE IS PROVIDED BY ATMEL ``AS IS'' AND ANY EXPRESS OR IMPLIED
00037  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00038  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND
00039  * SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT,
00040  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00041  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00042  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00043  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00044  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00045  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00046  */
00047 
00048 #ifndef _AVR32_SPI_H_
00049 #define _AVR32_SPI_H_
00050 
00051 #ifdef __GNUC__
00052 #include <avr32/io.h>
00053 #elif __ICCAVR32__
00054 #include <avr32/ioap7000.h>
00055 #else
00056 #error No known compiler used
00057 #endif
00058 
00060 #define SPI_TIMEOUT     10000
00061 
00062 #define SPI_ENABLE_PDC      1
00063 
00065 enum {
00066     SPI_ERROR = -1,
00067     SPI_OK = 0,
00068     SPI_ERROR_TIMEOUT = 1,
00069     SPI_ERROR_ARGUMENT,
00070     SPI_ERROR_OVERRUN,
00071     SPI_ERROR_MODE_FAULT,
00072     SPI_ERROR_OVERRUN_AND_MODE_FAULT
00073 };
00074 
00076 struct spi_options_t {
00078     unsigned char reg;
00079 
00081     unsigned int baudrate;
00082 
00084     unsigned char bits;
00085 
00087     unsigned char spck_delay;
00088 
00090     unsigned char trans_delay;
00091 
00093     unsigned char stay_act;
00094 
00096     unsigned char spi_mode;
00097 
00103     unsigned char fdiv;
00104 
00109     unsigned char modfdis;
00110 };
00111 
00112 #ifdef SPI_ENABLE_PDC
00113 struct spi_pdc {
00114     unsigned long none[0x40];   /* 0x000 */
00115     unsigned long rpr;      /* 0x100 */
00116     unsigned long rcr;      /* 0x104 */
00117     unsigned long tpr;      /* 0x108 */
00118     unsigned long tcr;      /* 0x10c */
00119     unsigned long rnpr;     /* 0x110 */
00120     unsigned long rncr;     /* 0x114 */
00121     unsigned long tnpr;     /* 0x118 */
00122     unsigned long tncr;     /* 0x11c */
00123     unsigned long ptcr;     /* 0x120 */
00124     unsigned long ptsr;     /* 0x124 */
00125 };
00126 typedef struct spi_pdc spi_pdc_t;
00127 #endif
00128 
00129 void spi_reset(volatile avr32_spi_t *spi);
00130 
00131 int spi_initSlave(volatile avr32_spi_t *spi,
00132         unsigned char bits,
00133         unsigned char spi_mode);
00134 
00135 int spi_initTest(volatile avr32_spi_t *spi);
00136 
00137 int spi_initMaster(volatile avr32_spi_t *spi, struct spi_options_t *options);
00138 
00139 int spi_selectionMode(volatile avr32_spi_t *spi,
00140         unsigned char variable_ps,
00141         unsigned char pcs_decode,
00142         unsigned char delay);
00143 
00144 int spi_selectChip(volatile avr32_spi_t *spi, unsigned char chip);
00145 
00146 int spi_unselectChip(volatile avr32_spi_t *spi, unsigned char chip);
00147 
00148 int spi_setupChipReg(volatile avr32_spi_t *spi,
00149         struct spi_options_t *options,
00150         unsigned int cpuHz);
00151 
00152 void spi_enable(volatile avr32_spi_t *spi);
00153 
00154 void spi_disable(volatile avr32_spi_t *spi);
00155 
00156 int spi_write(volatile avr32_spi_t *spi, unsigned short data);
00157 
00158 int spi_variableSlaveWrite(volatile avr32_spi_t *spi,
00159         unsigned short data,
00160         unsigned char pcs,
00161         unsigned char lastxfer);
00162 
00163 unsigned char spi_readRegisterFullCheck(volatile avr32_spi_t *spi);
00164 
00165 int spi_read(volatile avr32_spi_t *spi, unsigned short *data);
00166 
00167 #ifdef SPI_ENABLE_PDC
00168 void spi_disablePDC(volatile avr32_spi_t *spi);
00169 
00170 void spi_enablePDC(volatile avr32_spi_t *spi);
00171 
00172 int spi_set_RxBuf(volatile avr32_spi_t *spi,
00173         void *rp,
00174         unsigned short rc,
00175         void *rnp,
00176         unsigned short rnc);
00177 
00178 int spi_set_TxBuf(volatile avr32_spi_t *spi,
00179         void *tp,
00180         unsigned short tc,
00181         void *tnp,
00182         unsigned short tnc);
00183 
00184 unsigned short spi_getRcr(volatile avr32_spi_t *spi);
00185 
00186 unsigned short spi_getTcr(volatile avr32_spi_t *spi);
00187 #endif /* SPI_ENABLE_PDC */
00188 
00189 unsigned char spi_getStatus(volatile avr32_spi_t *spi);
00190 
00191 #endif /* #ifndef _AVR32_SPI_H_ */
00192 

Generated on Mon May 21 20:10:39 2007 for AVR32105 - Master and Slave SPI driver by  doxygen 1.5.1