Date:2013-07-31 00:46:55 (6 years 3 months ago)
Author:Werner Almesberger
Commit:7fd9044d94da8d8baede5a290efc7fb759b6e857
Message: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).
Files: atusb/fw/mac.c (2 diffs)
atusb/fw/spi.c (1 diff)
atusb/fw/spi.h (2 diffs)

Change Details

atusb/fw/mac.c
113113
114114static void receive_frame(void)
115115{
116    uint8_t size, i;
116    uint8_t size;
117117    uint8_t *buf;
118118
119119    spi_begin();
...... 
128128    }
129129
130130    buf = rx_buf[rx_in];
131    for (i = 0; i != size+1; i++)
132        buf[i+1] = spi_recv();
131    spi_recv_block(buf+1, size+1);
133132    spi_end();
134133
135134    buf[0] = size;
atusb/fw/spi.c
4747}
4848
4949
50void spi_recv_block(uint8_t *buf, uint8_t n)
51{
52    if (!n)
53        return;
54        UDR1 = 0;
55    while (--n) {
56        while (!(UCSR1A & 1 << RXC1));
57        *buf++ = UDR1;
58        UDR1 = 0;
59    }
60    while (!(UCSR1A & 1 << RXC1));
61    *buf++ = UDR1;
62}
63
64
5065void spi_off(void)
5166{
5267    spi_initialized = 0;
atusb/fw/spi.h
11/*
22 * fw/spi.h - ATmega8 family SPI I/O
33 *
4 * Written 2011 by Werner Almesberger
5 * Copyright 2011 Werner Almesberger
4 * Written 2011, 2013 by Werner Almesberger
5 * Copyright 2011, 2013 Werner Almesberger
66 *
77 * This program is free software; you can redistribute it and/or modify
88 * it under the terms of the GNU General Public License as published by
...... 
2525#define spi_send(v) (void) spi_io(v)
2626#define spi_recv(v) spi_io(0)
2727
28void spi_recv_block(uint8_t *buf, uint8_t n);
29
2830#endif /* !SPI_H */

Archive Download the corresponding diff file



interactive