From: Michel Pollet Date: Sat, 10 Apr 2010 17:05:30 +0000 (+0100) Subject: twi: Stripped down TWI module to fix compile X-Git-Tag: v1.0a2~5 X-Git-Url: https://git.htl-mechatronik.at/public/?a=commitdiff_plain;h=b25803fd49b7c51e7c4bb1fc4336aa77ee78060d;p=sx%2Fsimavr.git twi: Stripped down TWI module to fix compile New system will take it's place soon Signed-off-by: Michel Pollet --- diff --git a/simavr/sim/avr_twi.c b/simavr/sim/avr_twi.c index 6ebe7bb..cc521d0 100644 --- a/simavr/sim/avr_twi.c +++ b/simavr/sim/avr_twi.c @@ -70,18 +70,6 @@ static void avr_twi_irq_input(struct avr_irq_t * irq, uint32_t value, void * par #endif } -static int twi_slave_event(struct twi_slave_t* p, uint8_t address, enum twi_event event) -{ - switch (event) { - case TWI_START: - break; - case TWI_STOP: - break; - case TWI_PROBE: - break; - } - return 0; -} // handle a data write, after a (re)start static int twi_slave_write(struct twi_slave_t* p, uint8_t v) @@ -95,11 +83,6 @@ static uint8_t twi_slave_read(struct twi_slave_t* p) return 0; } -static twi_slave_t slave_driver = { - .event = twi_slave_event, - .write = twi_slave_write, - .read = twi_slave_read -}; static int avr_twi_ioctl(struct avr_io_t * port, uint32_t ctl, void * io_param) { @@ -132,7 +115,7 @@ void avr_twi_init(avr_t * avr, avr_twi_t * p) p->io = _io; avr_register_io(avr, &p->io); avr_register_vector(avr, &p->twi); - p->slave = slave_driver; // get default callbacks +// p->slave = slave_driver; // get default callbacks twi_slave_init(&p->slave, 0, p); twi_bus_init(&p->bus); diff --git a/simavr/sim/sim_twi.c b/simavr/sim/sim_twi.c index b0eea39..7434fd6 100644 --- a/simavr/sim/sim_twi.c +++ b/simavr/sim/sim_twi.c @@ -23,10 +23,12 @@ #include #include +#include #include "sim_twi.h" static void twi_bus_master_irq_notify(struct avr_irq_t * irq, uint32_t value, void * param) { + twi_bus_t * bus = (twi_bus_t *)param; switch (irq->irq) { case TWI_MASTER_STOP: bus->peer = NULL; @@ -42,7 +44,7 @@ static void twi_bus_master_irq_notify(struct avr_irq_t * irq, uint32_t value, vo bus->ack = 0; break; case TWI_MASTER_ACK: - if (!peer) { + if (!bus->peer) { } break; } @@ -66,7 +68,7 @@ static void twi_bus_slave_irq_notify(struct avr_irq_t * irq, uint32_t value, voi } } -static void twi_slave_master_irq_notify(struct avr_irq_t * irq, uint32_t value, void * param) +static void twi_slave_irq_notify(struct avr_irq_t * irq, uint32_t value, void * param) { twi_slave_t * slave = (twi_slave_t*)param; switch (irq->irq) { @@ -77,7 +79,7 @@ static void twi_slave_master_irq_notify(struct avr_irq_t * irq, uint32_t value, slave->match = 0; break; case TWI_MASTER_START: - if ((value & 0xfe) == slave->address & 0xfe) { + if ((value & 0xfe) == (slave->address & 0xfe)) { if (slave->match) { // restart } @@ -97,7 +99,7 @@ static void twi_slave_master_irq_notify(struct avr_irq_t * irq, uint32_t value, void twi_bus_init(twi_bus_t * bus) { memset(bus, 0, sizeof(twi_bus_t)); - avr_init_irq(bus->irq, 0, TWI_STATE_COUNT); + avr_init_irq(bus->irq, 0, TWI_MASTER_STATE_COUNT); for (int i = 0; i < TWI_MASTER_STATE_COUNT; i++) avr_irq_register_notify(bus->irq + i, twi_bus_master_irq_notify, bus); } @@ -126,34 +128,12 @@ void twi_bus_stop(twi_bus_t * bus) avr_raise_irq(bus->irq + TWI_MASTER_STOP, 0); } -int twi_bus_write(twi_bus_t * bus, uint8_t data) -{ - if (!bus->peer || !bus->peer->write) - return 0; - - int res = bus->peer->write(bus->peer, data); - if (bus->peer) - bus->peer->byte_index++; - return res; -} - -uint8_t twi_bus_read(twi_bus_t * bus) -{ - if (!bus->peer || !bus->peer->read) - return 0; - - uint8_t res = bus->peer->read(bus->peer); - if (bus->peer) - bus->peer->byte_index++; - return res; -} void twi_slave_init(twi_slave_t * slave, uint8_t address, void * param) { memset(slave, 0, sizeof(twi_slave_t)); slave->address = address; - slave->param = param; - +// slave->param = param; } void twi_slave_detach(twi_slave_t * slave) @@ -176,10 +156,3 @@ void twi_slave_detach(twi_slave_t * slave) } } -int twi_slave_match(twi_slave_t * slave, uint8_t address) -{ - if (slave->address) - return (address & ~1) == (slave->address & ~1); - return slave->event(slave, address, TWI_PROBE); -} -