2011-02-09 00:32:15 +02:00
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include <avr/io.h>
|
|
|
|
|
|
|
|
#define F_CPU 8000000UL
|
|
|
|
#include <util/delay.h>
|
|
|
|
|
|
|
|
#include "freakusb.h"
|
|
|
|
|
|
|
|
#include "at86rf230.h"
|
2011-02-09 02:32:24 +02:00
|
|
|
#include "io.h"
|
|
|
|
#include "spi.h"
|
2011-02-09 00:32:15 +02:00
|
|
|
|
|
|
|
|
2011-02-09 02:32:24 +02:00
|
|
|
void reset_rf(void);
|
2011-02-09 04:53:25 +02:00
|
|
|
void ep0_init(void);
|
2011-02-09 00:32:15 +02:00
|
|
|
|
|
|
|
|
2011-02-09 02:32:24 +02:00
|
|
|
void reset_rf(void)
|
2011-02-09 00:32:15 +02:00
|
|
|
{
|
2011-02-09 02:32:24 +02:00
|
|
|
/* AT86RF231 data sheet, 12.4.13, reset pulse width: 625 ns (min) */
|
2011-02-09 00:32:15 +02:00
|
|
|
|
2011-02-09 02:32:24 +02:00
|
|
|
CLR(nRST_RF);
|
|
|
|
_delay_us(1);
|
|
|
|
SET(nRST_RF);
|
2011-02-09 00:32:15 +02:00
|
|
|
|
2011-02-09 02:32:24 +02:00
|
|
|
/* 12.4.14: SPI access latency after reset: 625 ns (min) */
|
|
|
|
|
|
|
|
_delay_us(1);
|
2011-02-09 00:32:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
/* We start with a 1 MHz/8 clock. Disable the prescaler. */
|
|
|
|
|
|
|
|
CLKPR = 1 << CLKPCE;
|
|
|
|
CLKPR = 0;
|
|
|
|
|
|
|
|
/* set up all the outputs; default port value is 0 */
|
|
|
|
|
|
|
|
OUT(LED);
|
2011-02-09 02:32:24 +02:00
|
|
|
OUT(nRST_RF); /* resets the transceiver */
|
2011-02-09 00:32:15 +02:00
|
|
|
OUT(SLP_TR);
|
|
|
|
|
2011-02-09 02:32:24 +02:00
|
|
|
spi_init();
|
2011-02-09 00:32:15 +02:00
|
|
|
|
2011-02-09 02:32:24 +02:00
|
|
|
reset_rf();
|
2011-02-09 00:32:15 +02:00
|
|
|
|
|
|
|
/* switch CLKM to 8 MHz */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @@@ Note: Atmel advise against changing the external clock in
|
|
|
|
* mid-flight. We should therefore switch to the RC clock first, then
|
|
|
|
* crank up the external clock, and finally switch back to the external
|
|
|
|
* clock. The clock switching procedure is described in the ATmega32U2
|
|
|
|
* data sheet in secton 8.2.2.
|
|
|
|
*/
|
|
|
|
|
|
|
|
spi_begin();
|
2011-02-09 02:32:24 +02:00
|
|
|
spi_send(AT86RF230_REG_WRITE | REG_TRX_CTRL_0);
|
|
|
|
spi_send(CLKM_CTRL_8MHz);
|
2011-02-09 00:32:15 +02:00
|
|
|
spi_end();
|
|
|
|
|
|
|
|
/* now we should be at 8 MHz */
|
|
|
|
|
|
|
|
SET(LED);
|
|
|
|
_delay_ms(100);
|
|
|
|
CLR(LED);
|
|
|
|
|
|
|
|
usb_init();
|
2011-02-09 04:53:25 +02:00
|
|
|
ep0_init();
|
2011-02-09 00:32:15 +02:00
|
|
|
hw_init();
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
usb_poll();
|
|
|
|
}
|