megaRF TWI master and slave driver.
Copyright (c) 2014-2018 Microchip Technology Inc. and its subsidiaries.
#include "twi_megarf.h"
Macros | |
#define | MASTER 0 |
TWI Mode of operation. More... | |
#define | SLAVE 1 |
Functions | |
ISR (TWI_vect) | |
TWI interrupt Vector. More... | |
static void | twi_interrupt_handler (void) |
TWI Interrupt Handler. More... | |
static void | twi_master_addr_ack (void) |
Notification that address byte was written to the TWI and need to send ACK or NACK. More... | |
static void | twi_master_bus_reset (void) |
Reset TWI bus. More... | |
static void | twi_master_data_write (void) |
Sending data to twi bus. More... | |
status_code_t | twi_master_get_status (void) |
returns the status of TWI bus More... | |
status_code_t | twi_master_init (volatile void *twi, twi_master_options_t *opt) |
Inits TWI module as master. More... | |
static void | twi_master_internal_addr_write (void) |
Sending internal device address to twi bus. More... | |
status_code_t | twi_master_read (volatile void *twi, const twi_package_t *package) |
Reads the series of bytes from the TWI bus. More... | |
static void | twi_master_read_done (uint8_t data) |
Notification that byte was read by the TWI. More... | |
static void | twi_master_read_last_byte (uint8_t data) |
Notification that last byte was read from the TWI. More... | |
static void | twi_master_start (void) |
Notification about the start condition was sent. More... | |
status_code_t | twi_master_write (volatile void *twi, const twi_package_t *package) |
Perform a TWI master write transfer. More... | |
static void | twi_master_write_done (void) |
Notification that byte was written to the TWI. More... | |
static void | twi_slave_bus_reset (void) |
Reset TWI bus. More... | |
static void | twi_slave_data_read (uint8_t data) |
Read received data. More... | |
static void | twi_slave_data_write (void) |
Sending data to twi bus. More... | |
static void | twi_slave_enable (void) |
Enable TWI as slave. More... | |
status_code_t | twi_slave_init (uint8_t twi_slave_ownadd) |
Initialize TWI as Slave. More... | |
static void | twi_slave_last_byte_write_done (void) |
Notification of Last byte is transmitted. More... | |
status_code_t | twi_slave_start (slave_data_buffer_t *package) |
Start the slave Transceiver. More... | |
int | twi_slave_state_get (void) |
Get the state of TWI transceiver. More... | |
int | twi_slave_status_get (void) |
Get the status of TWI transceiver. More... | |
void | twi_slave_status_reset (void) |
Resets the slave state and status to initial for next transmission/reception. More... | |
static void | twi_slave_write_byte (uint8_t data) |
writing an byte to TWI. More... | |
Variables | |
struct { | |
int addr_count | |
unsigned int data_count | |
twi_package_t * pkg | |
uint8_t state | |
status_code_t status | |
} | master_transfer |
Master Transfer Descriptor. More... | |
struct { | |
slave_data_buffer_t * data_buffer | |
unsigned int data_count | |
uint8_t state | |
int status | |
} | slave_transfer |
Slave Transfer Descriptor. More... | |
static volatile bool | twi_master_busy = false |
static volatile bool | twi_mode = MASTER |
#define MASTER 0 |
TWI Mode of operation.
Referenced by twi_interrupt_handler(), and twi_master_init().
#define SLAVE 1 |
Referenced by twi_slave_status_reset().
ISR | ( | TWI_vect | ) |
TWI interrupt Vector.
References twi_interrupt_handler().
|
static |
TWI Interrupt Handler.
References ERR_BUSY, ERR_IO_ERROR, ERR_PROTOCOL, MASTER, master_transfer, slave_transfer, status, TWI_IDLE, twi_master_addr_ack(), twi_master_bus_reset(), twi_master_busy, twi_master_read_done(), twi_master_read_last_byte(), twi_master_start(), twi_master_write_done(), twi_mode, TWI_PROCESS, twi_read_byte(), twi_slave_bus_reset(), twi_slave_data_read(), twi_slave_data_write(), twi_slave_enable(), twi_slave_last_byte_write_done(), TWI_STATUS_IO_ERROR, TWI_STATUS_PROTOCOL_ERROR, TWI_STATUS_RX_COMPLETE, TWI_TWSR_STATUS_MASK, TWS_BUSERROR, TWS_M_ARB_LOST, TWS_MR_DATA_ACK, TWS_MR_DATA_NACK, TWS_MR_SLA_ACK, TWS_MR_SLA_NACK, TWS_MT_DATA_ACK, TWS_MT_DATA_NACK, TWS_MT_SLA_ACK, TWS_MT_SLA_NACK, TWS_RSTART, TWS_SR_GEN_ACK, TWS_SR_GEN_ACK_M_ARB_LOST, TWS_SR_GEN_DATA_ACK, TWS_SR_GEN_DATA_NACK, TWS_SR_SLA_ACK, TWS_SR_SLA_ACK_M_ARB_LOST, TWS_SR_SLA_DATA_ACK, TWS_SR_SLA_DATA_NACK, TWS_SR_STOP_RESTART, TWS_ST_DATA_ACK, TWS_ST_DATA_ACK_LAST_BYTE, TWS_ST_DATA_NACK, TWS_ST_SLA_ACK, TWS_ST_SLA_ACK_M_ARB_LOST, and TWS_START.
Referenced by ISR().
int addr_count |
slave_data_buffer_t* data_buffer |
Referenced by main().
unsigned int data_count |
struct { ... } master_transfer |
Master Transfer Descriptor.
Referenced by twi_interrupt_handler(), twi_master_addr_ack(), twi_master_bus_reset(), twi_master_data_write(), twi_master_get_status(), twi_master_internal_addr_write(), twi_master_read(), twi_master_read_done(), twi_master_read_last_byte(), twi_master_start(), twi_master_write(), and twi_master_write_done().
twi_package_t* pkg |
struct { ... } slave_transfer |
Slave Transfer Descriptor.
Referenced by twi_interrupt_handler(), twi_slave_bus_reset(), twi_slave_data_read(), twi_slave_data_write(), twi_slave_init(), twi_slave_last_byte_write_done(), twi_slave_start(), twi_slave_state_get(), twi_slave_status_get(), and twi_slave_status_reset().
uint8_t state |
Referenced by nwkFrameAlloc(), phyTrxSetState(), RxHandler(), and set_main_state().
int status |
|
static |
|
static |
Referenced by twi_interrupt_handler(), twi_master_init(), and twi_slave_status_reset().