mirror of
git://projects.qi-hardware.com/ben-wpan.git
synced 2024-11-29 11:04:59 +02:00
atusb/fw2: moved board-specific functions (SPI, RF reset) out of main()
- Makefile (OBJS): added spi.o - spi.h, spi.c, atusb.c: moved SPI functions to new file - spi.h (spi), spi.c (spi), atusb.c (main): renamed function "spi" to "spi_io" - atusb.c (reset_rf, main): moved transceiver reset to separate function
This commit is contained in:
parent
259400fdb8
commit
1c004ee2d2
@ -16,7 +16,7 @@ USB_OBJS = $(FreakUSB)/usb/usb.o $(FreakUSB)/usb/ctrl.o \
|
||||
$(FreakUSB)/usb/usb_buf.o \
|
||||
$(FreakUSB)/hw/at90usbxx2/ep.o $(FreakUSB)/hw/at90usbxx2/hw.o \
|
||||
$(FreakUSB)/hw/at90usbxx2/isr.o
|
||||
OBJS = atusb.o descr.o $(USB_OBJS)
|
||||
OBJS = atusb.o spi.o descr.o $(USB_OBJS)
|
||||
|
||||
CFLAGS += -I../fw/include \
|
||||
-I$(FreakUSB)/usb -I$(FreakUSB)/hw/at90usbxx2 \
|
||||
|
@ -7,29 +7,25 @@
|
||||
|
||||
#include "freakusb.h"
|
||||
|
||||
#include "io.h"
|
||||
#include "at86rf230.h"
|
||||
#include "io.h"
|
||||
#include "spi.h"
|
||||
|
||||
|
||||
static void spi_begin(void)
|
||||
void reset_rf(void);
|
||||
|
||||
|
||||
void reset_rf(void)
|
||||
{
|
||||
CLR(nSS);
|
||||
}
|
||||
/* AT86RF231 data sheet, 12.4.13, reset pulse width: 625 ns (min) */
|
||||
|
||||
CLR(nRST_RF);
|
||||
_delay_us(1);
|
||||
SET(nRST_RF);
|
||||
|
||||
static uint8_t spi(uint8_t v)
|
||||
{
|
||||
// while (!(UCSR1A & 1 << UDRE1));
|
||||
UDR1 = v;
|
||||
while (!(UCSR1A & 1 << RXC1));
|
||||
return UDR1;
|
||||
}
|
||||
/* 12.4.14: SPI access latency after reset: 625 ns (min) */
|
||||
|
||||
|
||||
static void spi_end(void)
|
||||
{
|
||||
// while (!(UCSR1A & 1 << TXC1));
|
||||
SET(nSS);
|
||||
_delay_us(1);
|
||||
}
|
||||
|
||||
|
||||
@ -43,32 +39,12 @@ int main(void)
|
||||
/* set up all the outputs; default port value is 0 */
|
||||
|
||||
OUT(LED);
|
||||
OUT(nRST_RF); /* reset the transceiver */
|
||||
OUT(nRST_RF); /* resets the transceiver */
|
||||
OUT(SLP_TR);
|
||||
OUT(SCLK);
|
||||
OUT(MOSI);
|
||||
OUT(nSS);
|
||||
|
||||
/* set up UART-SPI */
|
||||
spi_init();
|
||||
|
||||
UCSR1C = 1 << UMSEL11 | 1 << UMSEL10;
|
||||
/* set MSPI, MSB first, SPI data mode 0 */
|
||||
UCSR1B = 1 << RXEN1 | 1 << TXEN1;
|
||||
/* enable receiver and transmitter */
|
||||
UBRR1 = 0; /* reconfirm the bit rate */
|
||||
|
||||
/* bring the transceiver out of reset */
|
||||
|
||||
/*
|
||||
* AT86RF231 data sheet, 12.4.13, reset pulse with: 625 ns (min).
|
||||
* We spend a lot more time getting here, so no extra wait is needed.
|
||||
*/
|
||||
SET(nRST_RF);
|
||||
|
||||
/*
|
||||
* 12.4.14: SPI access latency after reset: 625 ns
|
||||
*/
|
||||
_delay_us(1);
|
||||
reset_rf();
|
||||
|
||||
/* switch CLKM to 8 MHz */
|
||||
|
||||
@ -81,8 +57,8 @@ int main(void)
|
||||
*/
|
||||
|
||||
spi_begin();
|
||||
spi(AT86RF230_REG_WRITE | REG_TRX_CTRL_0);
|
||||
spi(CLKM_CTRL_8MHz);
|
||||
spi_send(AT86RF230_REG_WRITE | REG_TRX_CTRL_0);
|
||||
spi_send(CLKM_CTRL_8MHz);
|
||||
spi_end();
|
||||
|
||||
/* now we should be at 8 MHz */
|
||||
|
44
atusb/fw2/spi.c
Normal file
44
atusb/fw2/spi.c
Normal file
@ -0,0 +1,44 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include <avr/io.h>
|
||||
|
||||
#include "io.h"
|
||||
#include "spi.h"
|
||||
|
||||
|
||||
void spi_begin(void)
|
||||
{
|
||||
CLR(nSS);
|
||||
}
|
||||
|
||||
|
||||
uint8_t spi_io(uint8_t v)
|
||||
{
|
||||
// while (!(UCSR1A & 1 << UDRE1));
|
||||
UDR1 = v;
|
||||
while (!(UCSR1A & 1 << RXC1));
|
||||
return UDR1;
|
||||
}
|
||||
|
||||
|
||||
void spi_end(void)
|
||||
{
|
||||
// while (!(UCSR1A & 1 << TXC1));
|
||||
SET(nSS);
|
||||
}
|
||||
|
||||
|
||||
void spi_init(void)
|
||||
{
|
||||
OUT(SCLK);
|
||||
OUT(MOSI);
|
||||
OUT(nSS);
|
||||
IN(MISO);
|
||||
|
||||
UBRR1 = 0; /* set bit rate to zero to begin */
|
||||
UCSR1C = 1 << UMSEL11 | 1 << UMSEL10;
|
||||
/* set MSPI, MSB first, SPI data mode 0 */
|
||||
UCSR1B = 1 << RXEN1 | 1 << TXEN1;
|
||||
/* enable receiver and transmitter */
|
||||
UBRR1 = 0; /* reconfirm the bit rate */
|
||||
}
|
14
atusb/fw2/spi.h
Normal file
14
atusb/fw2/spi.h
Normal file
@ -0,0 +1,14 @@
|
||||
#ifndef SPI_H
|
||||
#define SPI_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
void spi_begin(void);
|
||||
uint8_t spi_io(uint8_t v);
|
||||
void spi_end(void);
|
||||
void spi_init(void);
|
||||
|
||||
#define spi_send(v) (void) spi_io(v)
|
||||
#define spi_recv(v) spi_io(0)
|
||||
|
||||
#endif /* !SPI_H */
|
Loading…
Reference in New Issue
Block a user