00001
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
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];
00115 unsigned long rpr;
00116 unsigned long rcr;
00117 unsigned long tpr;
00118 unsigned long tcr;
00119 unsigned long rnpr;
00120 unsigned long rncr;
00121 unsigned long tnpr;
00122 unsigned long tncr;
00123 unsigned long ptcr;
00124 unsigned long ptsr;
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
00188
00189 unsigned char spi_getStatus(volatile avr32_spi_t *spi);
00190
00191 #endif
00192