Xmega Application Note


twi_slave_driver.h File Reference

XMEGA TWI slave driver header file. More...

#include "avr_compiler.h"

Include dependency graph for twi_slave_driver.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  TWI_Slave
 TWI slave driver struct. More...

Defines

#define TWIS_RECEIVE_BUFFER_SIZE   8
#define TWIS_SEND_BUFFER_SIZE   8
#define TWIS_STATUS_BUSY   1
#define TWIS_STATUS_READY   0

Typedefs

typedef struct TWI_Slave TWI_Slave_t
 TWI slave driver struct.
typedef enum TWIS_RESULT_enum TWIS_RESULT_t

Enumerations

enum  TWIS_RESULT_enum {
  TWIS_RESULT_UNKNOWN = (0x00<<0), TWIS_RESULT_OK = (0x01<<0), TWIS_RESULT_BUFFER_OVERFLOW = (0x02<<0), TWIS_RESULT_TRANSMIT_COLLISION = (0x03<<0),
  TWIS_RESULT_BUS_ERROR = (0x04<<0), TWIS_RESULT_FAIL = (0x05<<0), TWIS_RESULT_ABORTED = (0x06<<0)
}

Functions

static void TWI_SlaveAddressMatchHandler (TWI_Slave_t *twi)
static void TWI_SlaveDataHandler (TWI_Slave_t *twi)
void TWI_SlaveInitializeDriver (TWI_Slave_t *twi, TWI_t *module, void(*processDataFunction)(void))
 Initalizes TWI slave driver structure.
void TWI_SlaveInitializeModule (TWI_Slave_t *twi, uint8_t address, TWI_SLAVE_INTLVL_t intLevel)
 Initialize the TWI module.
static void TWI_SlaveInterruptHandler (TWI_Slave_t *twi)
static void TWI_SlaveReadHandler (TWI_Slave_t *twi)
static void TWI_SlaveStopHandler (TWI_Slave_t *twi)
static void TWI_SlaveTransactionFinished (TWI_Slave_t *twi, uint8_t result)
static void TWI_SlaveWriteHandler (TWI_Slave_t *twi)


Detailed Description

XMEGA TWI slave driver header file.

Application note:
AVR1320: True 400kHz operation for TWI slave
Documentation
For comprehensive code documentation, supported compilers, compiler settings and supported devices see readme.html
Author:
Atmel Corporation: http://www.atmel.com
Support email: avr@atmel.com
Copyright (c) 2007, Atmel Corporation All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

3. The name of ATMEL may not be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY ATMEL ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Definition in file twi_slave_driver.h.


Define Documentation

#define TWIS_RECEIVE_BUFFER_SIZE   8

Definition at line 66 of file twi_slave_driver.h.

Referenced by TWI_SlaveReadHandler().

#define TWIS_SEND_BUFFER_SIZE   8

Definition at line 67 of file twi_slave_driver.h.

Referenced by TWI_SlaveWriteHandler().

#define TWIS_STATUS_BUSY   1

Definition at line 52 of file twi_slave_driver.h.

Referenced by TWI_SlaveAddressMatchHandler().

#define TWIS_STATUS_READY   0


Typedef Documentation

typedef struct TWI_Slave TWI_Slave_t

TWI slave driver struct.

TWI slave struct. Holds pointer to TWI module and data processing routine, buffers and necessary varibles.


Enumeration Type Documentation

Enumerator:
TWIS_RESULT_UNKNOWN 
TWIS_RESULT_OK 
TWIS_RESULT_BUFFER_OVERFLOW 
TWIS_RESULT_TRANSMIT_COLLISION 
TWIS_RESULT_BUS_ERROR 
TWIS_RESULT_FAIL 
TWIS_RESULT_ABORTED 

Definition at line 55 of file twi_slave_driver.h.

00055                               {
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;


Function Documentation

static void TWI_SlaveAddressMatchHandler ( TWI_Slave_t twi  )  [static]

static void TWI_SlaveDataHandler ( TWI_Slave_t twi  )  [static]

void TWI_SlaveInitializeDriver ( TWI_Slave_t twi,
TWI_t *  module,
void(*)(void)  processDataFunction 
)

Initalizes TWI slave driver structure.

Initialize the instance of the TWI Slave and set the appropriate values.

Parameters:
twi The TWI_Slave_t struct instance.
module Pointer to the TWI module.
processDataFunction Pointer to the function that handles incoming data.

Definition at line 68 of file twi_slave_driver.c.

References TWI_Slave::abort, TWI_Slave::bytesReceived, TWI_Slave::bytesSent, CLKSYS_Disable(), CLKSYS_Enable, CLKSYS_IsReady, CLKSYS_Main_ClockSource_Select(), TWI_Slave::interface, TWI_Slave::Process_Data, TWI_Slave::result, TWI_Slave::status, TWIS_RESULT_UNKNOWN, and TWIS_STATUS_READY.

Referenced by main().

00071 {
00072    twi->interface = module;
00073    twi->Process_Data = processDataFunction;
00074    twi->bytesReceived = 0;
00075    twi->bytesSent = 0;
00076    twi->status = TWIS_STATUS_READY;
00077    twi->result = TWIS_RESULT_UNKNOWN;
00078    twi->abort = false;
00079           
00080    CLKSYS_Enable( OSC_RC32MEN_bm );
00081    do {} while ( CLKSYS_IsReady( OSC_RC32MRDY_bm ) == 0 );
00082         
00083    /* 32MHz Internal RC*/
00084    CLKSYS_Main_ClockSource_Select( CLK_SCLKSEL_RC32M_gc );
00085         
00086    CLKSYS_Disable( OSC_RC2MEN_bm | OSC_RC32KEN_bm );    
00087 }

Here is the call graph for this function:

void TWI_SlaveInitializeModule ( TWI_Slave_t twi,
uint8_t  address,
TWI_SLAVE_INTLVL_t  intLevel 
)

Initialize the TWI module.

Enables interrupts on address recognition and data available. Remember to enable interrupts globally from the main application.

Parameters:
twi The TWI_Slave_t struct instance.
address Slave address for this module.
intLevel Interrupt level for the TWI slave interrupt handler.

Definition at line 99 of file twi_slave_driver.c.

References TWI_Slave::interface.

Referenced by main().

00102 {
00103    twi->interface->SLAVE.CTRLA = intLevel |
00104                                  TWI_SLAVE_DIEN_bm |
00105                                  TWI_SLAVE_APIEN_bm |
00106                                  TWI_SLAVE_ENABLE_bm;
00107    twi->interface->SLAVE.ADDR = (address<<1);
00108 }

static void TWI_SlaveInterruptHandler ( TWI_Slave_t twi  )  [static]

static void TWI_SlaveReadHandler ( TWI_Slave_t twi  )  [static]

static void TWI_SlaveStopHandler ( TWI_Slave_t twi  )  [static]

static void TWI_SlaveTransactionFinished ( TWI_Slave_t twi,
uint8_t  result 
) [static]

static void TWI_SlaveWriteHandler ( TWI_Slave_t twi  )  [static]

@DOC_TITLE@
Generated on Tue Jan 19 18:42:01 2010 for AVR1320: True 400kHz operation for TWI slave by doxygen 1.5.8