00001
00019
00020
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 #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];
00114 unsigned long rpr;
00115 unsigned long rcr;
00116 unsigned long tpr;
00117 unsigned long tcr;
00118 unsigned long rnpr;
00119 unsigned long rncr;
00120 unsigned long tnpr;
00121 unsigned long tncr;
00122 unsigned long ptcr;
00123 unsigned long ptsr;
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
00187
00188 unsigned char spi_getStatus(volatile avr32_spi_t *spi);
00189
00190 #endif
00191