00001
00018
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
00048
00049 #ifndef _SPI_H_
00050 #define _SPI_H_
00051
00052 #include <avr32/io.h>
00053
00054
00056 #define SPI_TIMEOUT 10000
00057
00058
00060 typedef enum
00061 {
00062 SPI_ERROR = -1,
00063 SPI_OK = 0,
00064 SPI_ERROR_TIMEOUT = 1,
00065 SPI_ERROR_ARGUMENT,
00066 SPI_ERROR_OVERRUN,
00067 SPI_ERROR_MODE_FAULT,
00068 SPI_ERROR_OVERRUN_AND_MODE_FAULT
00069 } spi_status_t;
00070
00072 typedef struct
00073 {
00075 unsigned char reg;
00076
00078 unsigned int baudrate;
00079
00081 unsigned char bits;
00082
00084 unsigned char spck_delay;
00085
00087 unsigned char trans_delay;
00088
00090 unsigned char stay_act;
00091
00093 unsigned char spi_mode;
00094
00098 unsigned char modfdis;
00099 } spi_options_t;
00100
00101
00106 extern void spi_reset(volatile avr32_spi_t *spi);
00107
00118 extern spi_status_t spi_initSlave(volatile avr32_spi_t *spi,
00119 unsigned char bits,
00120 unsigned char spi_mode);
00121
00130 extern spi_status_t spi_initTest(volatile avr32_spi_t *spi);
00131
00141 extern spi_status_t spi_initMaster(volatile avr32_spi_t *spi, const spi_options_t *options);
00142
00156 extern spi_status_t spi_selectionMode(volatile avr32_spi_t *spi,
00157 unsigned char variable_ps,
00158 unsigned char pcs_decode,
00159 unsigned char delay);
00160
00171 extern spi_status_t spi_selectChip(volatile avr32_spi_t *spi, unsigned char chip);
00172
00186 extern spi_status_t spi_unselectChip(volatile avr32_spi_t *spi, unsigned char chip);
00187
00204 extern spi_status_t spi_setupChipReg(volatile avr32_spi_t *spi,
00205 const spi_options_t *options,
00206 unsigned int pba_hz);
00207
00212 extern void spi_enable(volatile avr32_spi_t *spi);
00213
00222 extern void spi_disable(volatile avr32_spi_t *spi);
00223
00230 extern int spi_is_enabled(volatile avr32_spi_t *spi);
00231
00240 extern unsigned char spi_writeRegisterEmptyCheck(volatile avr32_spi_t *spi);
00241
00260 extern spi_status_t spi_write(volatile avr32_spi_t *spi, unsigned short data);
00261
00285 extern spi_status_t spi_variableSlaveWrite(volatile avr32_spi_t *spi,
00286 unsigned short data,
00287 unsigned char pcs,
00288 unsigned char lastxfer);
00289
00298 extern unsigned char spi_writeEndCheck(volatile avr32_spi_t *spi);
00299
00308 extern unsigned char spi_readRegisterFullCheck(volatile avr32_spi_t *spi);
00309
00324 extern spi_status_t spi_read(volatile avr32_spi_t *spi, unsigned short *data);
00325
00337 extern unsigned char spi_getStatus(volatile avr32_spi_t *spi);
00338
00339
00340 #endif // _SPI_H_