Nut/OS  4.10.3
API Reference
twif.c File Reference
#include <string.h>
#include <dev/irqreg.h>
#include <sys/event.h>
#include <sys/atom.h>
#include <sys/timer.h>
#include <sys/thread.h>
#include <sys/heap.h>
#include <dev/twif.h>
Include dependency graph for twif.c:

Go to the source code of this file.

Defines

#define TWGO   (_BV(TWINT) | _BV(TWEN) | _BV(TWIE))

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.

Variables

HANDLE tw_mm_mutex
HANDLE tw_mm_que
HANDLE tw_sr_que
HANDLE tw_st_que

Define Documentation

#define TWGO   (_BV(TWINT) | _BV(TWEN) | _BV(TWIE))

Definition at line 143 of file twif.c.

Referenced by TwSlaveRespond().


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:
This function is only available on ATmega128 systems. The function is not reentrant.
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 653 of file twif.c.

References _BV, inb, NutEnterCritical, NutEventWait(), NutExitCritical, outb, SIGNALED, tw_sr_que, and TWERR_TIMEOUT.

Here is the call graph for this function:

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:
This function is only available on ATmega128 systems.
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 727 of file twif.c.

References _BV, inb, NutEnterCritical, NutEventWait(), NutExitCritical, outb, SIGNALED, tw_st_que, TWERR_TIMEOUT, and TWGO.

Here is the call graph for this function:

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.

Note:
This function is only available on ATmega128 systems.

Definition at line 802 of file twif.c.


Variable Documentation

Definition at line 109 of file twif.c.

Referenced by TwInit(), TwMasterRegRead(), TwMasterRegWrite(), and TwMasterTransact().

Definition at line 110 of file twif.c.

Referenced by TwMasterRegRead(), TwMasterRegWrite(), and TwMasterTransact().

Definition at line 111 of file twif.c.

Referenced by TwSlaveListen().

Definition at line 112 of file twif.c.

Referenced by TwSlaveRespond().