Xmega Application Note


twi_slave_driver.h

Go to the documentation of this file.
00001 
00044 #ifndef TWI_DRIVER_H
00045 #define TWI_DRIVER_H
00046 
00047 #include "avr_compiler.h"
00048 
00049 
00050 /* Transaction status defines.*/
00051 #define TWIS_STATUS_READY                0
00052 #define TWIS_STATUS_BUSY                 1
00053 
00054 /* Transaction result enumeration */
00055 typedef enum TWIS_RESULT_enum {
00056         TWIS_RESULT_UNKNOWN            = (0x00<<0),
00057         TWIS_RESULT_OK                 = (0x01<<0),
00058         TWIS_RESULT_BUFFER_OVERFLOW    = (0x02<<0),
00059         TWIS_RESULT_TRANSMIT_COLLISION = (0x03<<0),
00060         TWIS_RESULT_BUS_ERROR          = (0x04<<0),
00061         TWIS_RESULT_FAIL               = (0x05<<0),
00062         TWIS_RESULT_ABORTED            = (0x06<<0),
00063 } TWIS_RESULT_t;
00064 
00065 /* Buffer size defines. */
00066 #define TWIS_RECEIVE_BUFFER_SIZE         8
00067 #define TWIS_SEND_BUFFER_SIZE            8
00068 
00069 
00070 
00076 typedef struct TWI_Slave {
00077         TWI_t *interface;                               
00078         void (*Process_Data) (void);                    
00079         register8_t receivedData[TWIS_RECEIVE_BUFFER_SIZE]; 
00080         register8_t sendData[TWIS_SEND_BUFFER_SIZE];        
00081         register8_t bytesReceived;                          
00082         register8_t bytesSent;                              
00083         register8_t status;                                 
00084         register8_t result;                                 
00085         bool abort;                                     
00086         bool nextNack;
00087 } TWI_Slave_t;
00088 
00089 
00090 
00091 void TWI_SlaveInitializeDriver(TWI_Slave_t *twi,
00092                                TWI_t *module,
00093                                void (*processDataFunction) (void));
00094 
00095 void TWI_SlaveInitializeModule(TWI_Slave_t *twi,
00096                                uint8_t address,
00097                                TWI_SLAVE_INTLVL_t intLevel);
00098 
00099 static void TWI_SlaveInterruptHandler(TWI_Slave_t *twi);
00100 static void TWI_SlaveAddressMatchHandler(TWI_Slave_t *twi);
00101 static void TWI_SlaveStopHandler(TWI_Slave_t *twi);
00102 static void TWI_SlaveDataHandler(TWI_Slave_t *twi);
00103 static void TWI_SlaveReadHandler(TWI_Slave_t *twi);
00104 static void TWI_SlaveWriteHandler(TWI_Slave_t *twi);
00105 static void TWI_SlaveTransactionFinished(TWI_Slave_t *twi, uint8_t result);
00106 
00107 #endif /* TWI_DRIVER_H */
@DOC_TITLE@
Generated on Tue Jan 19 18:41:58 2010 for AVR1320: True 400kHz operation for TWI slave by doxygen 1.5.8