|
SAM4SD32 (SAM4S-EK2)
|
Driver for the TWI (Two-Wire Interface). More...
Macros | |
| #define | I2C_FAST_MODE_SPEED 400000 |
| #define | LOW_LEVEL_TIME_LIMIT 384000 |
| #define | TWI_CLK_CALC_ARGU 4 |
| #define | TWI_CLK_DIV_MAX 0xFF |
| #define | TWI_CLK_DIV_MIN 7 |
| #define | TWI_CLK_DIVIDER 2 |
| #define | TWI_WP_KEY_VALUE TWI_WPMR_WPKEY_PASSWD |
Functions | |
| void | twi_disable_interrupt (Twi *p_twi, uint32_t ul_sources) |
| Disable TWI interrupts. | |
| void | twi_disable_master_mode (Twi *p_twi) |
| Disable TWI master mode. | |
| void | twi_disable_slave_mode (Twi *p_twi) |
| Disable TWI slave mode. | |
| void | twi_enable_interrupt (Twi *p_twi, uint32_t ul_sources) |
| Enable TWI interrupts. | |
| void | twi_enable_master_mode (Twi *p_twi) |
| Enable TWI master mode. | |
| void | twi_enable_slave_mode (Twi *p_twi) |
| Enable TWI slave mode. | |
| uint32_t | twi_get_interrupt_mask (Twi *p_twi) |
| Read TWI interrupt mask. | |
| uint32_t | twi_get_interrupt_status (Twi *p_twi) |
| Get TWI interrupt status. | |
| Pdc * | twi_get_pdc_base (Twi *p_twi) |
| Get TWI PDC base address. | |
| uint32_t | twi_master_init (Twi *p_twi, const twi_options_t *p_opt) |
| Initialize TWI master mode. | |
| uint32_t | twi_master_read (Twi *p_twi, twi_packet_t *p_packet) |
| Read multiple bytes from a TWI compatible slave device. | |
| uint32_t | twi_master_write (Twi *p_twi, twi_packet_t *p_packet) |
| Write multiple bytes to a TWI compatible slave device. | |
| uint32_t | twi_mk_addr (const uint8_t *addr, int len) |
| Construct the TWI module address register field. | |
| uint32_t | twi_probe (Twi *p_twi, uint8_t uc_slave_addr) |
| Test if a chip answers a given I2C address. | |
| uint8_t | twi_read_byte (Twi *p_twi) |
| Reads a byte from the TWI bus. | |
| void | twi_reset (Twi *p_twi) |
| Reset TWI. | |
| void | twi_set_slave_addr (Twi *p_twi, uint32_t ul_device_addr) |
| Set TWI slave address. | |
| uint32_t | twi_set_speed (Twi *p_twi, uint32_t ul_speed, uint32_t ul_mck) |
| Set the I2C bus speed in conjunction with the clock frequency. | |
| void | twi_slave_init (Twi *p_twi, uint32_t ul_device_addr) |
| Initialize TWI slave mode. | |
| uint32_t | twi_slave_read (Twi *p_twi, uint8_t *p_data) |
| Read data from master. | |
| uint32_t | twi_slave_write (Twi *p_twi, uint8_t *p_data) |
| Write data to TWI bus. | |
| void | twi_write_byte (Twi *p_twi, uint8_t uc_byte) |
| Sends a byte of data to one of the TWI slaves on the bus. | |
Driver for the TWI (Two-Wire Interface).
This driver provides access to the main features of the TWI controller. The TWI interconnects components on a unique two-wire bus. The TWI is programmable as a master or a slave with sequential or single-byte access. Multiple master capability is supported.
| #define I2C_FAST_MODE_SPEED 400000 |
Definition at line 72 of file twi.c.
Referenced by twi_set_speed().
| #define LOW_LEVEL_TIME_LIMIT 384000 |
Definition at line 71 of file twi.c.
Referenced by twi_set_speed().
| #define TWI_CLK_CALC_ARGU 4 |
Definition at line 77 of file twi.c.
Referenced by twi_set_speed().
| #define TWI_CLK_DIV_MAX 0xFF |
Definition at line 79 of file twi.c.
Referenced by twi_set_speed().
| #define TWI_CLK_DIV_MIN 7 |
Definition at line 80 of file twi.c.
Referenced by twi_set_speed().
| #define TWI_CLK_DIVIDER 2 |
Definition at line 73 of file twi.c.
Referenced by twi_set_speed().
| void twi_disable_interrupt | ( | Twi * | p_twi, |
| uint32_t | ul_sources ) |
Disable TWI interrupts.
| p_twi | Pointer to a TWI instance. |
| ul_sources | Interrupts to be disabled. |
Definition at line 426 of file twi.c.
References Twi::TWI_IDR, and Twi::TWI_SR.
| void twi_disable_master_mode | ( | Twi * | p_twi | ) |
Disable TWI master mode.
| p_twi | Pointer to a TWI instance. |
Definition at line 104 of file twi.c.
References Twi::TWI_CR, and TWI_CR_MSDIS.
| void twi_disable_slave_mode | ( | Twi * | p_twi | ) |
Disable TWI slave mode.
| p_twi | Pointer to a TWI instance. |
Definition at line 501 of file twi.c.
References Twi::TWI_CR, and TWI_CR_SVDIS.
| void twi_enable_interrupt | ( | Twi * | p_twi, |
| uint32_t | ul_sources ) |
Enable TWI interrupts.
| p_twi | Pointer to a TWI instance. |
| ul_sources | Interrupts to be enabled. |
Definition at line 414 of file twi.c.
References Twi::TWI_IER.
| void twi_enable_master_mode | ( | Twi * | p_twi | ) |
Enable TWI master mode.
| p_twi | Pointer to a TWI instance. |
Definition at line 89 of file twi.c.
References Twi::TWI_CR, TWI_CR_MSDIS, TWI_CR_MSEN, and TWI_CR_SVDIS.
Referenced by twi_master_init().
| void twi_enable_slave_mode | ( | Twi * | p_twi | ) |
Enable TWI slave mode.
| p_twi | Pointer to a TWI instance. |
Definition at line 486 of file twi.c.
References Twi::TWI_CR, TWI_CR_MSDIS, TWI_CR_SVDIS, and TWI_CR_SVEN.
Referenced by twi_slave_init().
| uint32_t twi_get_interrupt_mask | ( | Twi * | p_twi | ) |
Read TWI interrupt mask.
| p_twi | Pointer to a TWI instance. |
Definition at line 453 of file twi.c.
References Twi::TWI_IMR.
| uint32_t twi_get_interrupt_status | ( | Twi * | p_twi | ) |
Get TWI interrupt status.
| p_twi | Pointer to a TWI instance. |
| TWI | interrupt status. |
Definition at line 441 of file twi.c.
References Twi::TWI_SR.
| Pdc * twi_get_pdc_base | ( | Twi * | p_twi | ) |
Get TWI PDC base address.
| p_twi | Pointer to a TWI instance. |
Definition at line 623 of file twi.c.
| uint32_t twi_master_init | ( | Twi * | p_twi, |
| const twi_options_t * | p_opt ) |
Initialize TWI master mode.
| p_twi | Pointer to a TWI instance. |
| p_opt | Options for initializing the TWI module (see twi_options_t). |
Definition at line 118 of file twi.c.
References twi_options::master_clk, twi_options::smbus, twi_options::speed, Twi::TWI_CR, TWI_CR_QUICK, twi_enable_master_mode(), Twi::TWI_IDR, TWI_INVALID_ARGUMENT, twi_reset(), twi_set_speed(), Twi::TWI_SR, and TWI_SUCCESS.
Referenced by twi_master_setup().
| uint32_t twi_master_read | ( | Twi * | p_twi, |
| twi_packet_t * | p_packet ) |
Read multiple bytes from a TWI compatible slave device.
| p_twi | Pointer to a TWI instance. |
| p_packet | Packet information and data (see twi_packet_t). |
Definition at line 278 of file twi.c.
References twi_packet::addr, twi_packet::addr_length, twi_packet::buffer, twi_packet::chip, twi_packet::length, Twi::TWI_CR, TWI_CR_START, TWI_CR_STOP, TWI_ERROR_TIMEOUT, Twi::TWI_IADR, TWI_INVALID_ARGUMENT, twi_mk_addr(), Twi::TWI_MMR, TWI_MMR_DADR, TWI_MMR_IADRSZ_Msk, TWI_MMR_IADRSZ_Pos, TWI_MMR_MREAD, TWI_RECEIVE_NACK, Twi::TWI_RHR, Twi::TWI_SR, TWI_SR_NACK, TWI_SR_RXRDY, TWI_SR_TXCOMP, TWI_SUCCESS, and TWI_TIMEOUT.
| uint32_t twi_master_write | ( | Twi * | p_twi, |
| twi_packet_t * | p_packet ) |
Write multiple bytes to a TWI compatible slave device.
| p_twi | Pointer to a TWI instance. |
| p_packet | Packet information and data (see twi_packet_t). |
Definition at line 353 of file twi.c.
References twi_packet::addr, twi_packet::addr_length, twi_packet::buffer, twi_packet::chip, twi_packet::length, Twi::TWI_CR, TWI_CR_STOP, Twi::TWI_IADR, TWI_INVALID_ARGUMENT, twi_mk_addr(), Twi::TWI_MMR, TWI_MMR_DADR, TWI_MMR_IADRSZ_Msk, TWI_MMR_IADRSZ_Pos, TWI_RECEIVE_NACK, Twi::TWI_SR, TWI_SR_NACK, TWI_SR_TXCOMP, TWI_SR_TXRDY, TWI_SUCCESS, and Twi::TWI_THR.
Referenced by twi_probe().
| uint32_t twi_mk_addr | ( | const uint8_t * | addr, |
| int | len ) |
Construct the TWI module address register field.
The TWI module address register is sent out MSB first. And the size controls which byte is the MSB to start with.
Please see the device datasheet for details on this.
Definition at line 249 of file twi.c.
Referenced by twi_master_read(), and twi_master_write().
| uint32_t twi_probe | ( | Twi * | p_twi, |
| uint8_t | uc_slave_addr ) |
Test if a chip answers a given I2C address.
| p_twi | Pointer to a TWI instance. |
| uc_slave_addr | Address of the remote chip to search for. |
Definition at line 219 of file twi.c.
References twi_packet::addr, twi_packet::addr_length, twi_packet::buffer, twi_packet::chip, twi_packet::length, and twi_master_write().
| uint8_t twi_read_byte | ( | Twi * | p_twi | ) |
Reads a byte from the TWI bus.
| p_twi | Pointer to a TWI instance. |
Definition at line 465 of file twi.c.
References Twi::TWI_RHR.
| void twi_reset | ( | Twi * | p_twi | ) |
Reset TWI.
| p_twi | Pointer to a TWI instance. |
Definition at line 609 of file twi.c.
References Twi::TWI_CR, TWI_CR_SWRST, and Twi::TWI_RHR.
Referenced by twi_master_init(), and twi_slave_init().
| void twi_set_slave_addr | ( | Twi * | p_twi, |
| uint32_t | ul_device_addr ) |
Set TWI slave address.
| p_twi | Pointer to a TWI instance. |
| ul_device_addr | Device address of the SAM slave device on the I2C bus. |
Definition at line 535 of file twi.c.
References Twi::TWI_SMR, and TWI_SMR_SADR.
| uint32_t twi_set_speed | ( | Twi * | p_twi, |
| uint32_t | ul_speed, | ||
| uint32_t | ul_mck ) |
Set the I2C bus speed in conjunction with the clock frequency.
| p_twi | Pointer to a TWI instance. |
| ul_speed | The desired I2C bus speed (in Hz). |
| ul_mck | Main clock of the device (in Hz). |
| PASS | New speed setting is accepted. |
| FAIL | New speed setting is rejected. |
Definition at line 156 of file twi.c.
References I2C_FAST_MODE_SPEED, LOW_LEVEL_TIME_LIMIT, TWI_CLK_CALC_ARGU, TWI_CLK_DIV_MAX, TWI_CLK_DIV_MIN, TWI_CLK_DIVIDER, Twi::TWI_CWGR, TWI_CWGR_CHDIV, TWI_CWGR_CKDIV, and TWI_CWGR_CLDIV.
Referenced by twi_master_init().
| void twi_slave_init | ( | Twi * | p_twi, |
| uint32_t | ul_device_addr ) |
Initialize TWI slave mode.
| p_twi | Pointer to a TWI instance. |
| ul_device_addr | Device address of the SAM slave device on the I2C bus. |
Definition at line 513 of file twi.c.
References twi_enable_slave_mode(), Twi::TWI_IDR, twi_reset(), Twi::TWI_SMR, TWI_SMR_SADR, and Twi::TWI_SR.
Referenced by twi_slave_setup().
| uint32_t twi_slave_read | ( | Twi * | p_twi, |
| uint8_t * | p_data ) |
Read data from master.
| p_twi | Pointer to a TWI instance. |
| p_data | Pointer to the data buffer where data received will be stored. |
Definition at line 551 of file twi.c.
References Twi::TWI_RHR, Twi::TWI_SR, TWI_SR_EOSACC, TWI_SR_GACC, TWI_SR_RXRDY, TWI_SR_SVACC, TWI_SR_SVREAD, and TWI_SR_TXCOMP.
| uint32_t twi_slave_write | ( | Twi * | p_twi, |
| uint8_t * | p_data ) |
Write data to TWI bus.
| p_twi | Pointer to a TWI instance. |
| p_data | Pointer to the data buffer to be sent. |
Definition at line 583 of file twi.c.
References Twi::TWI_SR, TWI_SR_EOSACC, TWI_SR_GACC, TWI_SR_SVACC, TWI_SR_SVREAD, TWI_SR_TXCOMP, TWI_SR_TXRDY, and Twi::TWI_THR.
| void twi_write_byte | ( | Twi * | p_twi, |
| uint8_t | uc_byte ) |
Sends a byte of data to one of the TWI slaves on the bus.
| p_twi | Pointer to a TWI instance. |
| uc_byte | The byte to send. |
Definition at line 476 of file twi.c.
References Twi::TWI_THR.