1
0
mirror of git://projects.qi-hardware.com/ben-wpan.git synced 2024-11-22 07:51:55 +02:00

atusb/fw/: add SPI block reception

This decreases the retrieval time for a frame of 102 bytes from
660 us to 384 us, corresponding to a speed change from about
1.26 Mbps to 2.17 Mbps (102 bytes plus 2 bytes overhead).
This commit is contained in:
Werner Almesberger 2013-07-30 19:46:55 -03:00
parent d1b65cb058
commit 7fd9044d94
3 changed files with 21 additions and 5 deletions

View File

@ -113,7 +113,7 @@ static void rx_done(void *user)
static void receive_frame(void)
{
uint8_t size, i;
uint8_t size;
uint8_t *buf;
spi_begin();
@ -128,8 +128,7 @@ static void receive_frame(void)
}
buf = rx_buf[rx_in];
for (i = 0; i != size+1; i++)
buf[i+1] = spi_recv();
spi_recv_block(buf+1, size+1);
spi_end();
buf[0] = size;

View File

@ -47,6 +47,21 @@ void spi_end(void)
}
void spi_recv_block(uint8_t *buf, uint8_t n)
{
if (!n)
return;
UDR1 = 0;
while (--n) {
while (!(UCSR1A & 1 << RXC1));
*buf++ = UDR1;
UDR1 = 0;
}
while (!(UCSR1A & 1 << RXC1));
*buf++ = UDR1;
}
void spi_off(void)
{
spi_initialized = 0;

View File

@ -1,8 +1,8 @@
/*
* fw/spi.h - ATmega8 family SPI I/O
*
* Written 2011 by Werner Almesberger
* Copyright 2011 Werner Almesberger
* Written 2011, 2013 by Werner Almesberger
* Copyright 2011, 2013 Werner Almesberger
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -25,4 +25,6 @@ void spi_init(void);
#define spi_send(v) (void) spi_io(v)
#define spi_recv(v) spi_io(0)
void spi_recv_block(uint8_t *buf, uint8_t n);
#endif /* !SPI_H */