summaryrefslogtreecommitdiff
path: root/n
diff options
context:
space:
mode:
authordemonchy2005-05-01 17:47:09 +0000
committerdemonchy2005-05-01 17:47:09 +0000
commit990bc98cb0c2a1b511f2fc1865cfb2975d686b60 (patch)
tree0cf584a7bdd7789533a0cf14b1a3423d89420e37 /n
parent0e6511695ac0b3ffa124d965e80229ff6a3c5294 (diff)
Slave transmitter avec double buffer débuggué
Diffstat (limited to 'n')
-rw-r--r--n/avr/twi-slave/twi_slave.c58
1 files changed, 26 insertions, 32 deletions
diff --git a/n/avr/twi-slave/twi_slave.c b/n/avr/twi-slave/twi_slave.c
index 777400f..c3d084f 100644
--- a/n/avr/twi-slave/twi_slave.c
+++ b/n/avr/twi-slave/twi_slave.c
@@ -37,13 +37,19 @@ static volatile uint8_t buf_send1[SIZE_BUF_SEND];
static volatile uint8_t buf_send2[SIZE_BUF_SEND];
static volatile uint8_t *buf_send_sys, *buf_send_user;
static volatile int8_t send_switch;
-static volatile int8_t state;
+static volatile int8_t update;
+
+#if 0
+#define TWI_DEBUG(x) rs232_putc (x)
+#else
+#define TWI_DEBUG(x)
+#endif
void
twi_init (uint8_t addr)
{
- state = 0;
send_switch = 0;
+ update = 0;
buf_send_sys = buf_send1;
buf_send_user = buf_send2;
TWAR = addr;
@@ -54,26 +60,32 @@ twi_init (uint8_t addr)
SIGNAL (SIG_2WIRE_SERIAL)
{
- rs232_putc (';');
+ TWI_DEBUG (';');
switch (TW_STATUS)
{
/* slave transmitter mode */
/* START + SLA|W + ACK */
case TW_ST_SLA_ACK:
case TW_ST_ARB_LOST_SLA_ACK:
- state = 1;
- rs232_putc ('a');
+ TWI_DEBUG ('a');
+ if (send_switch && !update)
+ {
+ volatile uint8_t *tmp = buf_send_sys;
+ buf_send_sys = buf_send_user;
+ buf_send_user = tmp;
+ send_switch = 0;
+ }
send_idx = 0;
/* no break */
case TW_ST_DATA_ACK:
- rs232_putc ('b');
+ TWI_DEBUG ('b');
TWDR = buf_send_sys[send_idx++];
if (SIZE_BUF_SEND == send_idx)
TWCR &= ~_BV(TWEA);
break;
case TW_ST_DATA_NACK:
case TW_ST_LAST_DATA:
- rs232_putc ('c');
+ TWI_DEBUG ('c');
TWCR |= _BV (TWEA);
break;
/* slave receiver mode */
@@ -82,8 +94,7 @@ SIGNAL (SIG_2WIRE_SERIAL)
case TW_SR_ARB_LOST_SLA_ACK:
case TW_SR_GCALL_ACK:
case TW_SR_ARB_LOST_GCALL_ACK:
- rs232_putc ('z');
- state = 2;
+ TWI_DEBUG ('z');
data_ready = 0;
twi_rcpt_tail = 0;
if (SIZE_BUF_RCPT == 1)
@@ -92,7 +103,7 @@ SIGNAL (SIG_2WIRE_SERIAL)
/* DATA + ACK */
case TW_SR_DATA_ACK:
case TW_SR_GCALL_DATA_ACK:
- rs232_putc ('y');
+ TWI_DEBUG ('y');
buf_rcpt[twi_rcpt_tail++] = TWDR;
if (SIZE_BUF_RCPT - twi_rcpt_tail == 1)
TWCR &= ~_BV(TWEA);
@@ -100,23 +111,13 @@ SIGNAL (SIG_2WIRE_SERIAL)
/* DATA + NACK */
case TW_SR_DATA_NACK:
case TW_SR_GCALL_DATA_NACK:
- rs232_putc ('x');
+ TWI_DEBUG ('x');
buf_rcpt[twi_rcpt_tail++] = TWDR;
/* no break */
/* STOP */
case TW_SR_STOP:
- rs232_putc ('w');
+ TWI_DEBUG ('w');
data_ready = 1;
- if (state && send_switch) /* send */
- {
- volatile uint8_t *tmp;
- /* Thibault paye son coup */
- tmp = buf_send_user;
- buf_send_user = buf_send_sys;
- buf_send_sys = tmp;
- send_switch = 0;
- state = 0;
- }
break;
}
TWCR |= _BV(TWINT);
@@ -142,17 +143,10 @@ twi_poll (uint8_t buf[], uint8_t size)
void
twi_update (uint8_t buf[], uint8_t size)
{
- volatile uint8_t *tmp;
+ update = 1;
+ send_switch = 1;
while (size --)
buf_send_user[size] = buf[size];
- /* si pas occup on swap les pointeurs */
- if (!state)
- {
- tmp = buf_send_user;
- buf_send_user = buf_send_sys;
- buf_send_sys = tmp;
- }
- else
- send_switch = 1;
+ update = 0;
}