mirror of
git://projects.qi-hardware.com/ben-wpan.git
synced 2024-11-23 10:36:17 +02:00
2337557a8c
- common/io.h: TST is connected to P0_7 - include/at86rf230.h: added test mode registers REG_CONT_TX_0 (0x36) and REG_CONT_TX_1 (0x3d), with their values - atspi/atspi.c (set_test_mode): set or reset TST and the LED - atspi/atspi.c (reset_rf): leave test mode - atspi/atspi.c (test_mode): enter test mode - atspi/atspi.c (main): flash the LED when in test mode - include/atspi/ep0.h (enum atspi_requests), atspi/ep0.c (my_setup): new command ATSPI_TEST to enter test mode - include/atspi/ep0.h (EP0ATSPI_MINOR): bumped protocol to version 0.1 - include/at86rf230.h: corrected comment before TRX_CMD field to indicate that the register is called TRX_STATE
142 lines
2.3 KiB
C
142 lines
2.3 KiB
C
/*
|
|
* atspi/atspi.c - ATSPI initialization and main loop
|
|
*
|
|
* Written 2008-2010 by Werner Almesberger
|
|
* Copyright 2008-2010 Werner Almesberger
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*/
|
|
|
|
|
|
#include "regs.h"
|
|
#include "io.h"
|
|
#include "usb.h"
|
|
#include "atspi/ep0.h"
|
|
#include "version.h"
|
|
|
|
|
|
static int in_test_mode = 0;
|
|
|
|
|
|
static void set_test_mode(int on)
|
|
{
|
|
in_test_mode = on;
|
|
if (on) {
|
|
TST_MODE |= 1 << TST_BIT;
|
|
TST = 1;
|
|
LED_MODE |= 1 << LED_BIT;
|
|
} else {
|
|
TST = 0;
|
|
TST_MODE &= ~(1 << TST_BIT);
|
|
LED_MODE &= ~(1 << LED_BIT);
|
|
LED = 0;
|
|
}
|
|
}
|
|
|
|
|
|
void reset_rf(void)
|
|
{
|
|
int i;
|
|
|
|
set_test_mode(0);
|
|
|
|
nRST_RF = 0;
|
|
/*
|
|
* 11.4.12: min 625 ns.
|
|
* The pulse we generate is slightly longer than 4 us.
|
|
*/
|
|
for (i = 0; i != 10; i++);
|
|
nRST_RF = 1;
|
|
}
|
|
|
|
|
|
void test_mode(void)
|
|
{
|
|
set_test_mode(1);
|
|
}
|
|
|
|
|
|
static void init_io(void)
|
|
{
|
|
/*
|
|
* Signal Mode Value
|
|
*
|
|
* MOSI push-pull 0
|
|
* MISO open drain 1 (input)
|
|
* SCLK push-pull 0
|
|
* nSS push-pull 1
|
|
* nRST_RF push-pull 1
|
|
* IRQ_RF open drain 1 (input)
|
|
* SLP_TR push-pull 0
|
|
* TST open drain 0
|
|
*
|
|
* LED push-pull 0 (set up by boot loader)
|
|
*
|
|
* all unused open drain 0
|
|
*/
|
|
|
|
MOSI = 0;
|
|
MOSI_MODE |= 1 << MOSI_BIT;
|
|
|
|
SCLK = 0;
|
|
SCLK_MODE |= 1 << SCLK_BIT;
|
|
|
|
nSS_MODE |= 1 << nSS_BIT;
|
|
|
|
nRST_RF_MODE |= 1 << nRST_RF_BIT;
|
|
|
|
SLP_TR = 0;
|
|
SLP_TR_MODE |= 1 << SLP_TR_BIT;
|
|
|
|
P0 = 1; /* IRQ_RF = 1; LED = 0; TST = Z; the rest is unused */
|
|
P3 = 0;
|
|
|
|
#if 0
|
|
/*
|
|
* We can *almost* disable the pull-ups. The only obstacle is that
|
|
* MISO is not driven when not in use. So we either need an external
|
|
* pull-up/down or keep all the pull-ups on.
|
|
*/
|
|
|
|
/*
|
|
* Disable pull-ups
|
|
*/
|
|
GPIOCN |= WEAKPUD;
|
|
#endif
|
|
|
|
/*
|
|
* The manual says the reset is optional, but reality disagrees with
|
|
* this optimistic assessment quite violently.
|
|
*/
|
|
|
|
reset_rf();
|
|
}
|
|
|
|
|
|
void main(void)
|
|
{
|
|
int i;
|
|
|
|
init_io();
|
|
|
|
/*
|
|
* Make sure the host has enough time (2.5 us) to detect that we reset
|
|
* our USB stack.
|
|
*/
|
|
for (i = 0; i != 10; i++);
|
|
|
|
usb_init();
|
|
ep0_init();
|
|
|
|
while (1) {
|
|
if (in_test_mode) {
|
|
i++;
|
|
LED = !(i >> 13);
|
|
}
|
|
usb_poll();
|
|
}
|
|
}
|