Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
dominicgs committed Aug 13, 2014
2 parents 10ef5bd + 7a0903a commit 77bda32
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions firmware/bluetooth_rxtx/bluetooth_le.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ typedef struct _le_state_t {

u8 target[6]; // target MAC for connection following (byte order reversed)
int target_set; // whether a target has been set (default: false)
u32 last_packet; // when was the last packet received
} le_state_t;

static const u8 advertising_channels[] = {0, 12, 39};
Expand Down
21 changes: 21 additions & 0 deletions firmware/bluetooth_rxtx/bluetooth_rxtx.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ le_state_t le = {
.crc_verify = 1,
.connected = 0,
.target_set = 0,
.last_packet = 0,
};

typedef void (*data_cb_t)(char *);
Expand Down Expand Up @@ -123,6 +124,7 @@ volatile u8 requested_mode = MODE_IDLE;
volatile u8 modulation = MOD_BT_BASIC_RATE;
volatile u16 channel = 2441;
volatile u16 requested_channel = 0;
volatile u16 saved_request = 0;
volatile u16 low_freq = 2400;
volatile u16 high_freq = 2483;
volatile int8_t rssi_threshold = -30; // -54dBm - 30 = -84dBm
Expand Down Expand Up @@ -1604,6 +1606,7 @@ void reset_le() {
le.crc_verify = 1;
le.connected = 0;
le.target_set = 0;
le.last_packet = 0;

le_hop_after = 0;
do_hop = 0;
Expand Down Expand Up @@ -1794,6 +1797,7 @@ void bt_le_sync(u8 active_mode)
/* RX mode */
cc2400_strobe(SRX);

saved_request = requested_channel;
requested_channel = 0;
}

Expand Down Expand Up @@ -1869,6 +1873,7 @@ void bt_le_sync(u8 active_mode)

RXLED_SET;
packet_cb((uint8_t *)packet);
le.last_packet = CLK100NS;

rx_flush:
cc2400_strobe(SFSON);
Expand All @@ -1880,6 +1885,22 @@ void bt_le_sync(u8 active_mode)
u8 tmp = (u8)DIO_SSP_DR;
}

// timeout - FIXME this is an ugly hack
if (le.connected && (CLK100NS - le.last_packet) > 50000000) {
reset_le();

cc2400_strobe(SRFOFF);
while ((cc2400_status() & FS_LOCK));

/* Retune */
channel = saved_request != 0 ? saved_request : 2402;
cc2400_set(FSDIV, channel - 1);

/* Wait for lock */
cc2400_strobe(SFSON);
while (!(cc2400_status() & FS_LOCK));
}

cc2400_set(SYNCL, le.syncl);
cc2400_set(SYNCH, le.synch);

Expand Down
3 changes: 2 additions & 1 deletion host/libubertooth/src/ubertooth_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,12 @@ enum ubertooth_usb_commands {
UBERTOOTH_POLL = 49,
UBERTOOTH_BTLE_PROMISC = 50,
UBERTOOTH_SET_AFHMAP = 51,
UBERTOOTH_CLEAR_AFHMAP = 52,
UBERTOOTH_CLEAR_AFHMAP = 52,
UBERTOOTH_READ_REGISTER = 53,
UBERTOOTH_BTLE_SLAVE = 54,
UBERTOOTH_GET_COMPILE_INFO = 55,
UBERTOOTH_BTLE_SET_TARGET = 56,
UBERTOOTH_BTLE_PHY = 57,
};

enum modulations {
Expand Down

0 comments on commit 77bda32

Please sign in to comment.