Date:2011-02-10 14:05:38 (8 years 7 months ago)
Author:Werner Almesberger
Commit:e8b68041a5f8eac8f443e22363a41f7a4aa57780
Message:atusb/fw2: autonomously restore the clock output settings after an RF reset

- atusb.c (main), board.c (set_clkm): moved CLKM initialization to
board.c
- board.c (reset_rf): initialize the CLKM after each transceiver reset
Files: atusb/fw2/atusb.c (2 diffs)
atusb/fw2/board.c (2 diffs)

Change Details

atusb/fw2/atusb.c
77
88#include "freakusb.h"
99
10#include "at86rf230.h"
1110#include "board.h"
1211#include "spi.h"
1312#include "atusb/ep0.h"
...... 
3029
3130    reset_rf();
3231
33    /* switch CLKM to 8 MHz */
34
35    /*
36     * @@@ Note: Atmel advise against changing the external clock in
37     * mid-flight. We should therefore switch to the RC clock first, then
38     * crank up the external clock, and finally switch back to the external
39     * clock. The clock switching procedure is described in the ATmega32U2
40     * data sheet in secton 8.2.2.
41     */
42
43    spi_begin();
44    spi_send(AT86RF230_REG_WRITE | REG_TRX_CTRL_0);
45    spi_send(CLKM_CTRL_8MHz);
46    spi_end();
47
4832    /* now we should be at 8 MHz */
4933
5034    SET(LED);
atusb/fw2/board.c
55#define F_CPU 8000000UL
66#include <util/delay.h>
77
8#include "at86rf230.h"
89#include "board.h"
10#include "spi.h"
11
12
13static void set_clkm(void)
14{
15    /* switch CLKM to 8 MHz */
16
17    /*
18     * @@@ Note: Atmel advise against changing the external clock in
19     * mid-flight. We should therefore switch to the RC clock first, then
20     * crank up the external clock, and finally switch back to the external
21     * clock. The clock switching procedure is described in the ATmega32U2
22     * data sheet in secton 8.2.2.
23     */
24
25    spi_begin();
26    spi_send(AT86RF230_REG_WRITE | REG_TRX_CTRL_0);
27    spi_send(CLKM_CTRL_8MHz);
28    spi_end();
29}
930
1031
1132void reset_rf(void)
...... 
1940    /* 12.4.14: SPI access latency after reset: 625 ns (min) */
2041
2142    _delay_us(1);
43
44    /* we must restore TRX_CTRL_0 after each reset (9.6.4) */
45
46    set_clkm();
2247}
2348
2449

Archive Download the corresponding diff file



interactive