This commit is contained in:
shimniok@gmail.com 2014-09-24 15:39:14 -06:00
commit 67d47db6fb

View File

@ -39,6 +39,12 @@
#include "spi.h" #include "spi.h"
#include "evnt_handler.h" #include "evnt_handler.h"
#include "mpconfig.h"
#include "misc.h"
typedef mp_uint_t qstr;
#include "obj.h"
#include "runtime.h"
#define READ 3 #define READ 3
#define WRITE 1 #define WRITE 1
@ -83,6 +89,12 @@ static SPI_HandleTypeDef SPIHandle;
void SpiWriteDataSynchronous(unsigned char *data, unsigned short size); void SpiWriteDataSynchronous(unsigned char *data, unsigned short size);
void SpiReadDataSynchronous(unsigned char *data, unsigned short size); void SpiReadDataSynchronous(unsigned char *data, unsigned short size);
//WLAN IRQ callback object
static mp_obj_t wlan_irq_callback(mp_obj_t line);
STATIC MP_DEFINE_CONST_FUN_OBJ_1(wlan_irq_callback_obj, wlan_irq_callback);
extern void gpio_init_exti(const gpio_t *gpio, mp_obj_t cb, uint32_t preempt_priority, uint32_t sub_priority);
void SpiClose(void) void SpiClose(void)
{ {
if (sSpiInformation.pRxPacket) { if (sSpiInformation.pRxPacket) {
@ -129,11 +141,8 @@ void SpiOpen(gcSpiHandleRx pfRxHandler)
uint8_t buf[1]; uint8_t buf[1];
HAL_SPI_Receive(&SPIHandle, buf, sizeof(buf), SPI_TIMEOUT); HAL_SPI_Receive(&SPIHandle, buf, sizeof(buf), SPI_TIMEOUT);
/* Configure and enable IRQ Channel */ gpio_init_exti(&gpio_pins[GPIO_PB11], (mp_obj_t)&wlan_irq_callback_obj, 5, 0);
HAL_NVIC_SetPriority(WLAN_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(WLAN_IRQn);
HAL_Delay(500); HAL_Delay(500);
tSLInformation.WlanInterruptEnable(); tSLInformation.WlanInterruptEnable();
} }
@ -373,38 +382,34 @@ void SSIContReadOperation(void)
} }
} }
//void WLAN_IRQHandler(void) static mp_obj_t wlan_irq_callback(mp_obj_t line)
void wlan_irqhandler(void)
{ {
if (__HAL_GPIO_EXTI_GET_FLAG(WLAN_EXTI_LINE)) { switch (sSpiInformation.ulSpiState) {
/* Clear the EXTI pending bit */ case eSPI_STATE_POWERUP:
__HAL_GPIO_EXTI_CLEAR_FLAG(WLAN_EXTI_LINE); //FIX EXTI_LINE /* This means IRQ line was low call a callback of HCI Layer to inform on event */
sSpiInformation.ulSpiState = eSPI_STATE_INITIALIZED;
break;
case eSPI_STATE_IDLE:
sSpiInformation.ulSpiState = eSPI_STATE_READ_IRQ;
switch (sSpiInformation.ulSpiState) { /* IRQ line goes down - we are start reception */
case eSPI_STATE_POWERUP: WLAN_SELECT();
/* This means IRQ line was low call a callback of HCI Layer to inform on event */
sSpiInformation.ulSpiState = eSPI_STATE_INITIALIZED;
break;
case eSPI_STATE_IDLE:
sSpiInformation.ulSpiState = eSPI_STATE_READ_IRQ;
/* IRQ line goes down - we are start reception */ // Wait for TX/RX Compete which will come as DMA interrupt
WLAN_SELECT(); SpiReadHeader();
// Wait for TX/RX Compete which will come as DMA interrupt sSpiInformation.ulSpiState = eSPI_STATE_READ_EOT;
SpiReadHeader();
sSpiInformation.ulSpiState = eSPI_STATE_READ_EOT; SSIContReadOperation();
break;
case eSPI_STATE_WRITE_IRQ:
SpiWriteDataSynchronous(sSpiInformation.pTxPacket, sSpiInformation.usTxPacketLength);
SSIContReadOperation(); sSpiInformation.ulSpiState = eSPI_STATE_IDLE;
break;
case eSPI_STATE_WRITE_IRQ:
SpiWriteDataSynchronous(sSpiInformation.pTxPacket, sSpiInformation.usTxPacketLength);
sSpiInformation.ulSpiState = eSPI_STATE_IDLE; WLAN_DESELECT();
break;
WLAN_DESELECT();
break;
}
} }
return mp_const_none;
} }