XgAt91Twi


Defines

#define TWI_PIO_ASR   PIOA_ASR
#define TWI_PIO_PDR   PIOA_PDR
#define TWI_PIO_MDER   PIOA_MDER

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 TwMasterRegRead (uint8_t sla, uint32_t iadr, uint8_t iadrlen, void *rxdata, uint16_t rxsiz, uint32_t tmo)
 Receive data as a master from a device having internal addressable registers.
int TwMasterRegWrite (uint8_t sla, uint32_t iadr, uint8_t iadrlen, CONST void *txdata, uint16_t txsiz, uint32_t tmo)
 Transmit data as a master to a device having internal addressable registers.
int TwMasterError (void)
 Get last master mode error.
uint16_t TwMasterIndexes (uint8_t idx)
 Get last transfer results.
int TwIOCtl (int req, void *conf)
 Perform TWI control functions.
int TwInit (uint8_t sla)
 Initialize TWI interface.

Define Documentation

#define TWI_PIO_ASR   PIOA_ASR

Definition at line 77 of file at91_twi.c.

Referenced by TwInit().

#define TWI_PIO_PDR   PIOA_PDR

Definition at line 80 of file at91_twi.c.

Referenced by TwInit().

#define TWI_PIO_MDER   PIOA_MDER

Definition at line 83 of file at91_twi.c.

Referenced by TwInit().


Function Documentation

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.

The two-wire serial interface must have been initialized by calling TwInit() before this function can be used.

Parameters:
sla Slave address of the destination. This slave address must be specified as a 7-bit address. For example, the PCF8574A may be configured to slave addresses from 0x38 to 0x3F.
txdata Points to the data to transmit. Ignored, if the number of data bytes to transmit is zero.
txlen Number of data bytes to transmit. If zero, then the interface will not send any data to the slave device and will directly enter the master receive mode.
rxdata Points to a buffer, where the received data will be stored. Ignored, if the maximum number of bytes to receive is zero.
rxsiz Maximum number of bytes to receive. Set to zero, if no bytes are expected from the slave device.
tmo Timeout 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 173 of file at91_twi.c.

References NutEventPost(), NutEventWait(), outr, tw_mm_mutex, tw_mm_que, TWERR_IF_LOCKED, TWERR_TIMEOUT, TWI_CR, TWI_DADR_LSB, TWI_IDR, TWI_IER, TWI_MMR, TWI_MREAD, TWI_RXRDY, TWI_START, TWI_STOP, TWI_THR, and TWI_TXRDY.

int TwMasterRegRead ( uint8_t  sla,
uint32_t  iadr,
uint8_t  iadrlen,
void *  rxdata,
uint16_t  rxsiz,
uint32_t  tmo 
)

Receive data as a master from a device having internal addressable registers.

The two-wire serial interface must have been initialized by calling TwInit() before this function can be used.

Parameters:
sla Slave address of the destination. This slave address must be specified as a 7-bit address. For example, the PCF8574A may be configured to slave addresses from 0x38 to 0x3F.
iadr Address send to the device to access certain registers or memory addresses of it.
iadrlen Number of bytes to send as address, maximum 3 bytes are supported from AT91SAM7
rxdata Points to a buffer, where the received data will be stored.
rxsiz Maximum number of bytes to receive.
tmo Timeout 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 269 of file at91_twi.c.

References NutEventPost(), NutEventWait(), outr, tw_mm_mutex, tw_mm_que, TWERR_IF_LOCKED, TWERR_TIMEOUT, TWI_CR, TWI_DADR_LSB, TWI_IADRR, TWI_IDR, TWI_IER, TWI_MMR, TWI_MREAD, TWI_RXRDY, TWI_START, and TWI_STOP.

int TwMasterRegWrite ( uint8_t  sla,
uint32_t  iadr,
uint8_t  iadrlen,
CONST void *  txdata,
uint16_t  txsiz,
uint32_t  tmo 
)

Transmit data as a master to a device having internal addressable registers.

The two-wire serial interface must have been initialized by calling TwInit() before this function can be used.

Parameters:
sla Slave address of the destination. This slave address must be specified as a 7-bit address. For example, the PCF8574A may be configured to slave addresses from 0x38 to 0x3F.
iadr Address send to the device to access certain registers or memory addresses of it.
iadrlen Number of bytes to send as address, maximum 3 bytes are supported from AT91SAM7
txdata Points to a buffer, where the data to transmit will be stored.
txsiz Maximum number of bytes to transmit.
tmo Timeout 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. Number could be less if slave end transmission with NAK.

Definition at line 343 of file at91_twi.c.

References NutEventPost(), NutEventWait(), outb, outr, tw_mm_mutex, tw_mm_que, TWERR_IF_LOCKED, TWERR_TIMEOUT, TWI_DADR_LSB, TWI_IADRR, TWI_IDR, TWI_IER, TWI_MMR, TWI_THR, and TWI_TXRDY.

int TwMasterError ( void   ) 

Get last master mode error.

You may call this function to determine the specific cause of an error after twi transaction failed.

Definition at line 391 of file at91_twi.c.

uint16_t TwMasterIndexes ( uint8_t  idx  ) 

Get last transfer results.

Todo:
Do we really need this. It may not work with competing threads.
You may call this function to determine how many bytes where transferred before the twi transaction failed.

Definition at line 407 of file at91_twi.c.

int TwIOCtl ( int  req,
void *  conf 
)

Perform TWI control functions.

Parameters:
req Requested control function. May be set to one of the following constants:
  • TWI_SETSPEED, if conf points to an uint32_t value containing the bitrate.
  • TWI_GETSPEED, if conf points to an uint32_t value receiving the current bitrate.
conf Points to a buffer that contains any data required for the given control function or receives data from that function.
Returns:
0 on success, -1 otherwise.
Note:
Timeout is limited to the granularity of the system timer.

Definition at line 436 of file at91_twi.c.

References inr, NUT_HWCLK_PERIPHERAL, NutClockGet, NutGetCpuClock(), outr, TWI_CWGR, TWI_GETSPEED, TWI_GETSTATUS, TWI_SETSPEED, and TWI_SETSTATUS.

int TwInit ( uint8_t  sla  ) 

Initialize TWI interface.

The specified slave address is not used here as we don't support twi-slave on AT91SAM7X

Note:
This function is only available on AT91SAM7xxxx systems.
Parameters:
sla Slave address, must be specified as a 7-bit address, always lower than 128.

Definition at line 501 of file at91_twi.c.

References _BV, NUT_IRQMODE_LEVEL, NutEventPost(), NutIrqEnable(), NutIrqSetMode(), NutRegisterIrqHandler(), outr, PMC_PCER, tw_mm_mutex, TWI_CR, TWI_ID, TWI_IDR, TWI_MSEN, TWI_PIO_ASR, TWI_PIO_MDER, TWI_PIO_PDR, TWI_SETSPEED, TWI_SVDIS, TWI_SWRST, and TwIOCtl().


© 2000-2007 by egnite Software GmbH - visit http://www.ethernut.de/