Root/atusb/fw2/atusb.c

Source at commit dcfa689936afb14fd0fdf804ba0aad08fa03f8f9 created 9 years 7 months ago.
By Werner Almesberger, atusb/fw2/: assigned hardware revision code point; some cleanup
1#include <stdint.h>
2
3#include <avr/io.h>
4
5#define F_CPU 8000000UL
6#include <util/delay.h>
7
8#include "freakusb.h"
9
10#include "at86rf230.h"
11#include "board.h"
12#include "spi.h"
13#include "atusb/ep0.h"
14
15
16int main(void)
17{
18    /* We start with a 1 MHz/8 clock. Disable the prescaler. */
19
20    CLKPR = 1 << CLKPCE;
21    CLKPR = 0;
22
23    /* set up all the outputs; default port value is 0 */
24
25    OUT(LED);
26    OUT(nRST_RF); /* resets the transceiver */
27    OUT(SLP_TR);
28
29    spi_init();
30
31    reset_rf();
32
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
48    /* now we should be at 8 MHz */
49
50    SET(LED);
51    _delay_ms(100);
52    CLR(LED);
53
54    usb_init();
55    ep0_init();
56    hw_init();
57
58    while (1)
59        usb_poll();
60}
61

Archive Download this file



interactive