BeRTOS
Defines | Functions
twi_at91.c File Reference

Driver for the AT91 ARM TWI (implementation) More...

#include "twi_at91.h"
#include "cfg/cfg_i2c.h"
#include <cfg/compiler.h>
#include <cfg/debug.h>
#include <cfg/macros.h>
#include <cfg/module.h>
#include <drv/timer.h>
#include <io/arm.h>

Go to the source code of this file.

Defines

#define TWI_TIMEOUT   ms_to_ticks(50)
 Timeout for ACK slave waiting.

Functions

bool twi_write (uint8_t id, twi_iaddr_t byte1, twi_iaddr_t byte2, twi_iaddr_t byte3, const void *_buf, size_t size)
 Send size bytes over the twi line to slave id.
bool twi_read (uint8_t id, twi_iaddr_t byte1, twi_iaddr_t byte2, twi_iaddr_t byte3, void *_buf, size_t size)
 Read size bytes from the twi line from slave id.
void twi_init (void)
 Init the (broken) sam7 twi driver.

Detailed Description

Driver for the AT91 ARM TWI (implementation)

Author:
Francesco Sacchi <batt@develer.com>

Definition in file twi_at91.c.


Function Documentation

bool twi_read ( uint8_t  id,
twi_iaddr_t  byte1,
twi_iaddr_t  byte2,
twi_iaddr_t  byte3,
void *  _buf,
size_t  size 
)

Read size bytes from the twi line from slave id.

If the device requires internal addressing before reading, byte1 byte2 and byte3 must be specified. Internal addressign bytes not used *must* be set to TWI_NO_IADDR. If 1 or 2 bytes are required for internal addressing you *must* first use byte1 and than byte2.

Note:
Atmel TWI implementation is broken so it was not possible to supply a better interface. Additionally NACK handling is also broken, so if the i2c device reply nack this function will return after TWI_TIMEOUT.
Returns:
true if ok, false on slave timeout.

Definition at line 140 of file twi_at91.c.

bool twi_write ( uint8_t  id,
twi_iaddr_t  byte1,
twi_iaddr_t  byte2,
twi_iaddr_t  byte3,
const void *  _buf,
size_t  size 
)

Send size bytes over the twi line to slave id.

If the device requires internal addressing before writing, byte1 byte2 and byte3 can be specified. Internal addressign bytes not used *must* be set to TWI_NO_IADDR. If 1 or 2 bytes are required for internal addressing you *must* first use byte1 and than byte2.

Note:
Atmel TWI implementation is broken so it was not possible to supply a better interface. Additionally NACK handling is also broken, so if the i2c device reply nack this function will return after TWI_TIMEOUT.
Returns:
true if ok, false on slave timeout.

Definition at line 66 of file twi_at91.c.