Nut/OS  4.10.3
API Reference
twbbif.c File Reference

Bit banging two wire interface. More...

#include <cfg/os.h>
#include <cfg/twi.h>
#include <cfg/arch/gpio.h>
#include <dev/twif.h>
Include dependency graph for twbbif.c:

Go to the source code of this file.

Functions

int TwMasterTransact (uint8_t sla, CONST void *txdata, uint16_t txlen, void *rxdata, uint16_t rxsiz, uint32_t tmo)
 Transmit and/or receive data as a master.
int TwMasterError (void)
 Get last master mode error.
int TwSlaveListen (uint8_t *sla, void *rxdata, uint16_t rxsiz, uint32_t tmo)
 Listen for incoming data from a master.
int TwSlaveRespond (void *txdata, uint16_t txlen, uint32_t tmo)
 Send response to a master.
int TwSlaveError (void)
 Get last slave mode error.
int TwIOCtl (int req, void *conf)
 Perform TWI control functions.
int TwInit (uint8_t sla)
 Initialize TWI interface.

Detailed Description

Bit banging two wire interface.

Tested with AT91R40008 only. Other ARMs or AVR may not work.

 *
 * $Log$
 * Revision 1.11  2008/08/11 06:59:42  haraldkipp
 * BSD types replaced by stdint types (feature request #1282721).
 *
 * Revision 1.10  2008/02/15 17:04:49  haraldkipp
 * Spport for AT91SAM7SE512 added.
 *
 * Revision 1.9  2007/10/04 20:16:57  olereinhardt
 * Support for SAM7S256 added
 *
 * Revision 1.8  2007/07/09 13:38:50  olereinhardt
 * 2007-07-09  Ole Reinhardt <ole.reinhardt@embedded-it.de>
 *         * dev/twbbif.c: Added default TWI_DELAY for avr architecture
 *         to allow in-tree compilation
 *         * net/Makefile: Commented out igmp support as long as it does
 *         not exists to allow in-tree compilation
 *
 * Revision 1.7  2007/02/15 16:25:40  haraldkipp
 * Configurable port bits. Should work now on all AT91 MCUs.
 *
 * Revision 1.6  2006/10/08 16:48:09  haraldkipp
 * Documentation fixed
 *
 * Revision 1.5  2006/06/28 17:10:35  haraldkipp
 * Include more general header file for ARM.
 *
 * Revision 1.4  2006/05/25 09:30:23  haraldkipp
 * Compiles for AVR. Still not tested, though.
 *
 * Revision 1.3  2006/04/07 12:50:20  haraldkipp
 * Added additional delays in TwAck.
 * Clock and data forced to high before switching to input gives better
 * waveforms.
 * Additional delay added to set clock to 50% duty cycle. The PCF8563
 * seems to fail, if the clock's high time is much longer than the low time.
 *
 * Revision 1.2  2006/01/23 17:32:35  haraldkipp
 * Automatic initialization added.
 *
 * Revision 1.1  2005/10/24 10:21:57  haraldkipp
 * Initial check in.
 *
 *
 * 

Definition in file twbbif.c.


Function Documentation

int TwSlaveListen ( uint8_t sla,
void *  rxdata,
uint16_t  rxsiz,
uint32_t  tmo 
)

Listen for incoming data from a master.

If this function returns without error, the bus is blocked. The caller must immediately process the request and return a response by calling TwSlaveRespond().

Note:
Slave mode is not implemented in the bit banging version. Thus the function always returns -1.
Parameters:
slaPoints to a byte variable, which receives the slave address sent by the master. This can be used by the caller to determine whether the the interface has been addressed by a general call or its individual address.
rxdataPoints to a data buffer where the received data bytes are stored.
rxsizSpecifies the maximum number of data bytes to receive.
tmoTimeout in milliseconds. To disable timeout, set this parameter to NUT_WAIT_INFINITE.
Returns:
The number of bytes received, -1 in case of an error or timeout.

Definition at line 660 of file twbbif.c.

int TwSlaveRespond ( void *  txdata,
uint16_t  txlen,
uint32_t  tmo 
)

Send response to a master.

This function must be called as soon as possible after TwSlaveListen() returned successfully, even if no data needs to be returned. Not doing so will completely block the bus.

Note:
Slave mode is not implemented in the bit banging version. Thus the function always returns -1.
Parameters:
txdataPoints to the data to transmit. Ignored, if the number of bytes to transmit is zero.
txlenNumber of data bytes to transmit.
tmoTimeout in milliseconds. To disable timeout, set this parameter to NUT_WAIT_INFINITE.
Returns:
The number of bytes transmitted, -1 in case of an error or timeout.

Definition at line 683 of file twbbif.c.

int TwSlaveError ( void  )

Get last slave mode error.

You may call this function to determine the specific cause of an error after TwSlaveListen() or TwSlaveRespond() failed.

Returns:
Error code or 0 if no error occurred.
Note:
Slave mode is not implemented in the bit banging version. Thus the function always returns TWERR_BUS.

Definition at line 699 of file twbbif.c.

References TWERR_BUS.