- Main Page
- Data Structures
- Files

# spi_at32ap7000.h

Go to the documentation of this file.

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