From 43758d1a674b39ed6b68e20238821c688f8c43a8 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Sat, 5 Jul 2014 03:39:01 +0200 Subject: [PATCH] Make wlan_start timeout --- src/cc3k/include/wlan.h | 2 +- src/cc3k/src/wlan.c | 26 +++++++++++++++++++------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/cc3k/include/wlan.h b/src/cc3k/include/wlan.h index ec5f7674e..87fb059af 100644 --- a/src/cc3k/include/wlan.h +++ b/src/cc3k/include/wlan.h @@ -141,7 +141,7 @@ extern void wlan_init( tWlanCB sWlanCB, //! // //***************************************************************************** -extern void wlan_start(unsigned short usPatchesAvailableAtHost); +extern int wlan_start(unsigned short usPatchesAvailableAtHost); //***************************************************************************** // diff --git a/src/cc3k/src/wlan.c b/src/cc3k/src/wlan.c index b63875d66..279454d08 100644 --- a/src/cc3k/src/wlan.c +++ b/src/cc3k/src/wlan.c @@ -251,12 +251,13 @@ void SpiReceiveHandler(void *pvBuffer) //! // //***************************************************************************** - -void +#define TIMEOUT (500000) +int wlan_start(unsigned short usPatchesAvailableAtHost) { unsigned long ulSpiIRQState; + unsigned long volatile timeout; tSLInformation.NumberOfSentPackets = 0; tSLInformation.NumberOfReleasedPackets = 0; @@ -281,30 +282,41 @@ wlan_start(unsigned short usPatchesAvailableAtHost) // ASIC 1273 chip enable: toggle WLAN EN line tSLInformation.WriteWlanPin( WLAN_ENABLE ); + timeout = TIMEOUT; if (ulSpiIRQState) { // wait till the IRQ line goes low - while(tSLInformation.ReadWlanInterruptPin() != 0) + while(tSLInformation.ReadWlanInterruptPin() != 0 && --timeout) { } } else { // wait till the IRQ line goes high and than low - while(tSLInformation.ReadWlanInterruptPin() == 0) + while(tSLInformation.ReadWlanInterruptPin() == 0 && --timeout) { } - - while(tSLInformation.ReadWlanInterruptPin() != 0) + + if (timeout == 0) { + return -1; + } + + timeout = TIMEOUT; + while(tSLInformation.ReadWlanInterruptPin() != 0 && --timeout) { } } - + + if (timeout ==0) { + return -1; + } + SimpleLink_Init_Start(usPatchesAvailableAtHost); // Read Buffer's size and finish hci_command_send(HCI_CMND_READ_BUFFER_SIZE, tSLInformation.pucTxCommandBuffer, 0); SimpleLinkWaitEvent(HCI_CMND_READ_BUFFER_SIZE, 0); + return 0; }