stmhal: Update CC3000 driver to newer version.
Still not working properly.
This commit is contained in:
parent
50073ed5d6
commit
a7a1a38df4
|
@ -3,14 +3,6 @@
|
|||
* cc3000_common.c.c - CC3000 Host Driver Implementation.
|
||||
* Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
|
||||
*
|
||||
* Adapted for use with the Arduino/AVR by KTOWN (Kevin Townsend)
|
||||
* & Limor Fried for Adafruit Industries
|
||||
* This library works with the Adafruit CC3000 breakout
|
||||
* ----> https://www.adafruit.com/products/1469
|
||||
* Adafruit invests time and resources providing this open source code,
|
||||
* please support Adafruit and open-source hardware by purchasing
|
||||
* products from Adafruit!
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
|
@ -60,7 +52,6 @@
|
|||
#include "socket.h"
|
||||
#include "wlan.h"
|
||||
#include "evnt_handler.h"
|
||||
#include "ccdebug.h"
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
|
@ -96,12 +87,12 @@ __error__(char *pcFilename, unsigned long ulLine)
|
|||
//
|
||||
//*****************************************************************************
|
||||
|
||||
uint8_t* UINT32_TO_STREAM_f (uint8_t *p, uint32_t u32)
|
||||
unsigned char* UINT32_TO_STREAM_f (unsigned char *p, unsigned long u32)
|
||||
{
|
||||
*(p)++ = (uint8_t)(u32);
|
||||
*(p)++ = (uint8_t)((u32) >> 8);
|
||||
*(p)++ = (uint8_t)((u32) >> 16);
|
||||
*(p)++ = (uint8_t)((u32) >> 24);
|
||||
*(p)++ = (unsigned char)(u32);
|
||||
*(p)++ = (unsigned char)((u32) >> 8);
|
||||
*(p)++ = (unsigned char)((u32) >> 16);
|
||||
*(p)++ = (unsigned char)((u32) >> 24);
|
||||
return p;
|
||||
}
|
||||
|
||||
|
@ -119,10 +110,10 @@ uint8_t* UINT32_TO_STREAM_f (uint8_t *p, uint32_t u32)
|
|||
//
|
||||
//*****************************************************************************
|
||||
|
||||
uint8_t* UINT16_TO_STREAM_f (uint8_t *p, uint16_t u16)
|
||||
unsigned char* UINT16_TO_STREAM_f (unsigned char *p, unsigned short u16)
|
||||
{
|
||||
*(p)++ = (uint8_t)(u16);
|
||||
*(p)++ = (uint8_t)((u16) >> 8);
|
||||
*(p)++ = (unsigned char)(u16);
|
||||
*(p)++ = (unsigned char)((u16) >> 8);
|
||||
return p;
|
||||
}
|
||||
|
||||
|
@ -140,20 +131,10 @@ uint8_t* UINT16_TO_STREAM_f (uint8_t *p, uint16_t u16)
|
|||
//
|
||||
//*****************************************************************************
|
||||
|
||||
uint16_t STREAM_TO_UINT16_f(char* cp, uint16_t offset)
|
||||
unsigned short STREAM_TO_UINT16_f(char* p, unsigned short offset)
|
||||
{
|
||||
uint8_t *p = (uint8_t *)cp;
|
||||
/*
|
||||
DEBUGPRINT_F("Stream2u16: ");
|
||||
DEBUGPRINT_HEX(cp[offset+1]);
|
||||
DEBUGPRINT_F(" + ");
|
||||
DEBUGPRINT_HEX(cp[offset]);
|
||||
DEBUGPRINT_F("\n\r");
|
||||
*/
|
||||
|
||||
return (uint16_t)((uint16_t)
|
||||
((uint16_t)(*(p + offset + 1)) << 8) +
|
||||
(uint16_t)(*(p + offset)));
|
||||
return (unsigned short)((unsigned short)((unsigned short)
|
||||
(*(p + offset + 1)) << 8) + (unsigned short)(*(p + offset)));
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
|
@ -170,23 +151,12 @@ uint16_t STREAM_TO_UINT16_f(char* cp, uint16_t offset)
|
|||
//
|
||||
//*****************************************************************************
|
||||
|
||||
uint32_t STREAM_TO_UINT32_f(char * cp, uint16_t offset)
|
||||
unsigned long STREAM_TO_UINT32_f(char* p, unsigned short offset)
|
||||
{
|
||||
uint8_t *p = (uint8_t *)cp;
|
||||
|
||||
/*
|
||||
DEBUGPRINT_F("\tStream2u32: ");
|
||||
DEBUGPRINT_HEX(cp[offset+3]); DEBUGPRINT_F(" + ");
|
||||
DEBUGPRINT_HEX(cp[offset+2]); DEBUGPRINT_F(" + ");
|
||||
DEBUGPRINT_HEX(cp[offset+1]); DEBUGPRINT_F(" + ");
|
||||
DEBUGPRINT_HEX(cp[offset]);
|
||||
DEBUGPRINT_F("\n\r");
|
||||
*/
|
||||
|
||||
return (uint32_t)((uint32_t)((uint32_t)
|
||||
(*(p + offset + 3)) << 24) + (uint32_t)((uint32_t)
|
||||
(*(p + offset + 2)) << 16) + (uint32_t)((uint32_t)
|
||||
(*(p + offset + 1)) << 8) + (uint32_t)(*(p + offset)));
|
||||
return (unsigned long)((unsigned long)((unsigned long)
|
||||
(*(p + offset + 3)) << 24) + (unsigned long)((unsigned long)
|
||||
(*(p + offset + 2)) << 16) + (unsigned long)((unsigned long)
|
||||
(*(p + offset + 1)) << 8) + (unsigned long)(*(p + offset)));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -3,14 +3,6 @@
|
|||
* cc3000_common.h - CC3000 Host Driver Implementation.
|
||||
* Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
|
||||
*
|
||||
* Adapted for use with the Arduino/AVR by KTOWN (Kevin Townsend)
|
||||
* & Limor Fried for Adafruit Industries
|
||||
* This library works with the Adafruit CC3000 breakout
|
||||
* ----> https://www.adafruit.com/products/1469
|
||||
* Adafruit invests time and resources providing this open source code,
|
||||
* please support Adafruit and open-source hardware by purchasing
|
||||
* products from Adafruit!
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
|
@ -46,9 +38,6 @@
|
|||
//******************************************************************************
|
||||
// Include files
|
||||
//******************************************************************************
|
||||
//#include <stdlib.h>
|
||||
//#include <errno.h>
|
||||
//#include <stdint.h>
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
|
@ -167,11 +156,7 @@ extern "C" {
|
|||
//*****************************************************************************
|
||||
// Compound Types
|
||||
//*****************************************************************************
|
||||
#ifdef __AVR__
|
||||
typedef unsigned long time_t; /* KTown: Updated to be compatible with Arduino Time.h */
|
||||
#else
|
||||
typedef long time_t;
|
||||
#endif
|
||||
typedef unsigned long clock_t;
|
||||
typedef long suseconds_t;
|
||||
|
||||
|
@ -268,7 +253,7 @@ extern void SimpleLinkWaitEvent(unsigned short usOpcode, void *pRetParams);
|
|||
//
|
||||
//*****************************************************************************
|
||||
|
||||
extern void SimpleLinkWaitData(uint8_t *pBuf, uint8_t *from, uint8_t *fromlen);
|
||||
extern void SimpleLinkWaitData(unsigned char *pBuf, unsigned char *from, unsigned char *fromlen);
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
|
@ -284,7 +269,7 @@ extern void SimpleLinkWaitData(uint8_t *pBuf, uint8_t *from, uint8_t *fromlen);
|
|||
//
|
||||
//*****************************************************************************
|
||||
|
||||
extern uint8_t* UINT32_TO_STREAM_f (uint8_t *p, uint32_t u32);
|
||||
extern unsigned char* UINT32_TO_STREAM_f (unsigned char *p, unsigned long u32);
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
|
@ -300,7 +285,7 @@ extern uint8_t* UINT32_TO_STREAM_f (uint8_t *p, uint32_t u32);
|
|||
//
|
||||
//*****************************************************************************
|
||||
|
||||
extern uint8_t* UINT16_TO_STREAM_f (uint8_t *p, uint16_t u16);
|
||||
extern unsigned char* UINT16_TO_STREAM_f (unsigned char *p, unsigned short u16);
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
|
@ -316,7 +301,7 @@ extern uint8_t* UINT16_TO_STREAM_f (uint8_t *p, uint16_t u16);
|
|||
//
|
||||
//*****************************************************************************
|
||||
|
||||
extern uint16_t STREAM_TO_UINT16_f(char* p, uint16_t offset);
|
||||
extern unsigned short STREAM_TO_UINT16_f(char* p, unsigned short offset);
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
|
@ -332,7 +317,7 @@ extern uint16_t STREAM_TO_UINT16_f(char* p, uint16_t offset);
|
|||
//
|
||||
//*****************************************************************************
|
||||
|
||||
extern uint32_t STREAM_TO_UINT32_f(char* p, uint16_t offset);
|
||||
extern unsigned long STREAM_TO_UINT32_f(char* p, unsigned short offset);
|
||||
|
||||
|
||||
//*****************************************************************************
|
||||
|
@ -361,14 +346,14 @@ extern void cc3k_int_poll();
|
|||
//This macro is used for copying 32 bit to stream while converting to little endian format.
|
||||
#define UINT32_TO_STREAM(_p, _u32) (UINT32_TO_STREAM_f(_p, _u32))
|
||||
//This macro is used for copying a specified value length bits (l) to stream while converting to little endian format.
|
||||
#define ARRAY_TO_STREAM(p, a, l) {register short _i; for (_i = 0; _i < l; _i++) *(p)++ = ((uint8_t *) a)[_i];}
|
||||
#define ARRAY_TO_STREAM(p, a, l) {register short _i; for (_i = 0; _i < l; _i++) *(p)++ = ((unsigned char *) a)[_i];}
|
||||
//This macro is used for copying received stream to 8 bit in little endian format.
|
||||
#define STREAM_TO_UINT8(_p, _offset, _u8) {_u8 = (uint8_t)(*(_p + _offset));}
|
||||
#define STREAM_TO_UINT8(_p, _offset, _u8) {_u8 = (unsigned char)(*(_p + _offset));}
|
||||
//This macro is used for copying received stream to 16 bit in little endian format.
|
||||
#define STREAM_TO_UINT16(_p, _offset, _u16) {_u16 = STREAM_TO_UINT16_f(_p, _offset);}
|
||||
//This macro is used for copying received stream to 32 bit in little endian format.
|
||||
#define STREAM_TO_UINT32(_p, _offset, _u32) {_u32 = STREAM_TO_UINT32_f(_p, _offset);}
|
||||
#define STREAM_TO_STREAM(p, a, l) {register short _i; for (_i = 0; _i < l; _i++) *(a)++= ((uint8_t *) p)[_i];}
|
||||
#define STREAM_TO_STREAM(p, a, l) {register short _i; for (_i = 0; _i < l; _i++) *(a)++= ((unsigned char *) p)[_i];}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,56 +0,0 @@
|
|||
/**************************************************************************/
|
||||
/*!
|
||||
@file Adafruit_CC3000.cpp
|
||||
@author KTOWN (Kevin Townsend for Adafruit Industries)
|
||||
@license BSD (see license.txt)
|
||||
|
||||
This is a library for the Adafruit CC3000 WiFi breakout board
|
||||
This library works with the Adafruit CC3000 breakout
|
||||
----> https://www.adafruit.com/products/1469
|
||||
|
||||
Check out the links above for our tutorials and wiring diagrams
|
||||
These chips use SPI to communicate.
|
||||
|
||||
Adafruit invests time and resources providing this open source code,
|
||||
please support Adafruit and open-source hardware by purchasing
|
||||
products from Adafruit!
|
||||
|
||||
@section HISTORY
|
||||
|
||||
v1.0 - Initial release
|
||||
*/
|
||||
/**************************************************************************/
|
||||
|
||||
//#include <Arduino.h>
|
||||
|
||||
#ifndef _CC3000_DEBUG
|
||||
#define _CC3000_DEBUG
|
||||
|
||||
#define DEBUG_MODE (0)
|
||||
|
||||
#define PRINT_F(__s) DEBUGPRINT(FLASHIFY(__s))
|
||||
|
||||
#if (DEBUG_MODE != 0)
|
||||
#define DEBUGPRINT_F(__s) DEBUGPRINT(FLASHIFY(__s))
|
||||
#define DEBUGPRINT_DEC(x) printDec(x)
|
||||
#define DEBUGPRINT_DEC16(x) printDec16(x)
|
||||
#define DEBUGPRINT_HEX(x) printHex(x)
|
||||
#define DEBUGPRINT_HEX16(x) printHex16(x)
|
||||
#else
|
||||
#define DEBUGPRINT_F(__s) /* do nothing! */
|
||||
#define DEBUGPRINT_DEC(x)
|
||||
#define DEBUGPRINT_DEC16(x)
|
||||
#define DEBUGPRINT_HEX(x)
|
||||
#define DEBUGPRINT_HEX16(x)
|
||||
#endif
|
||||
|
||||
#if 1 // print debugging info
|
||||
#define DEBUG_PRINT (1)
|
||||
#define DEBUG_printf(args...) printf(args)
|
||||
#else // don't print debugging info
|
||||
#define DEBUG_printf(args...) (void)0
|
||||
#endif
|
||||
|
||||
int printf(const char *fmt, ...);
|
||||
|
||||
#endif
|
|
@ -51,9 +51,14 @@
|
|||
#include "netapp.h"
|
||||
#include "evnt_handler.h"
|
||||
#include "cc3000_common.h"
|
||||
#include "ccdebug.h"
|
||||
#include "pybcc3k.h"
|
||||
|
||||
#if 0 // print debugging info
|
||||
#define DEBUG_printf(args...) printf(args)
|
||||
#else // don't print debugging info
|
||||
#define DEBUG_printf(args...) (void)0
|
||||
#endif
|
||||
|
||||
#define READ (3)
|
||||
#define WRITE (1)
|
||||
#define HI(value) (((value) & 0xFF00) >> 8)
|
||||
|
@ -140,7 +145,7 @@ void SpiInit(void)
|
|||
/**************************************************************************/
|
||||
void SpiClose(void)
|
||||
{
|
||||
DEBUGPRINT_F("\tCC3000: SpiClose");
|
||||
DEBUG_printf("\tCC3000: SpiClose");
|
||||
|
||||
if (sSpiInformation.pRxPacket)
|
||||
{
|
||||
|
@ -158,7 +163,7 @@ void SpiClose(void)
|
|||
/**************************************************************************/
|
||||
void SpiOpen(gcSpiHandleRx pfRxHandler)
|
||||
{
|
||||
DEBUGPRINT_F("\tCC3000: SpiOpen");
|
||||
DEBUG_printf("\tCC3000: SpiOpen");
|
||||
|
||||
sSpiInformation.ulSpiState = eSPI_STATE_POWERUP;
|
||||
|
||||
|
@ -177,7 +182,7 @@ void SpiOpen(gcSpiHandleRx pfRxHandler)
|
|||
/* Enable interrupt on the GPIO pin of WLAN IRQ */
|
||||
tSLInformation.WlanInterruptEnable();
|
||||
|
||||
DEBUGPRINT_F("\tCC3000: Finished SpiOpen\n\r");
|
||||
DEBUG_printf("\tCC3000: Finished SpiOpen\n\r");
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
|
@ -191,7 +196,7 @@ extern uint8_t g_csPin, g_irqPin, g_vbatPin, g_IRQnum, g_SPIspeed;
|
|||
int init_spi(void)
|
||||
{
|
||||
|
||||
DEBUGPRINT_F("\tCC3000: init_spi\n\r");
|
||||
DEBUG_printf("\tCC3000: init_spi\n\r");
|
||||
|
||||
/* Set POWER_EN pin to output and disable the CC3000 by default */
|
||||
pinMode(g_vbatPin, OUTPUT);
|
||||
|
@ -222,7 +227,7 @@ int init_spi(void)
|
|||
|
||||
/* ToDo: Configure IRQ interrupt! */
|
||||
|
||||
DEBUGPRINT_F("\tCC3000: Finished init_spi\n\r");
|
||||
DEBUG_printf("\tCC3000: Finished init_spi\n\r");
|
||||
|
||||
return(ESUCCESS);
|
||||
}
|
||||
|
@ -235,7 +240,7 @@ int init_spi(void)
|
|||
/**************************************************************************/
|
||||
long SpiFirstWrite(unsigned char *ucBuf, unsigned short usLength)
|
||||
{
|
||||
DEBUGPRINT_F("\tCC3000: SpiWriteFirst\n\r");
|
||||
DEBUG_printf("\tCC3000: SpiWriteFirst\n\r");
|
||||
|
||||
/* Workaround for the first transaction */
|
||||
CC3000_ASSERT_CS();
|
||||
|
@ -267,7 +272,7 @@ long SpiWrite(unsigned char *pUserBuffer, unsigned short usLength)
|
|||
{
|
||||
unsigned char ucPad = 0;
|
||||
|
||||
DEBUGPRINT_F("\tCC3000: SpiWrite\n\r");
|
||||
DEBUG_printf("\tCC3000: SpiWrite\n\r");
|
||||
|
||||
/* Figure out the total length of the packet in order to figure out if there is padding or not */
|
||||
if(!(usLength & 0x0001))
|
||||
|
@ -288,7 +293,7 @@ long SpiWrite(unsigned char *pUserBuffer, unsigned short usLength)
|
|||
* occurred - and we will be stuck here forever! */
|
||||
if (wlan_tx_buffer[CC3000_TX_BUFFER_SIZE - 1] != CC3000_BUFFER_MAGIC_NUMBER)
|
||||
{
|
||||
DEBUGPRINT_F("\tCC3000: Error - No magic number found in SpiWrite\n\r");
|
||||
DEBUG_printf("\tCC3000: Error - No magic number found in SpiWrite\n\r");
|
||||
while (1);
|
||||
}
|
||||
|
||||
|
@ -383,7 +388,7 @@ void SpiReadDataSynchronous(unsigned char *data, unsigned short size)
|
|||
/**************************************************************************/
|
||||
void SpiReadHeader(void)
|
||||
{
|
||||
DEBUGPRINT_F("\tCC3000: SpiReadHeader\n\r");
|
||||
DEBUG_printf("\tCC3000: SpiReadHeader\n\r");
|
||||
|
||||
SpiReadDataSynchronous(sSpiInformation.pRxPacket, HEADERS_SIZE_EVNT);
|
||||
}
|
||||
|
@ -398,7 +403,7 @@ long SpiReadDataCont(void)
|
|||
long data_to_recv;
|
||||
unsigned char *evnt_buff, type;
|
||||
|
||||
DEBUGPRINT_F("\tCC3000: SpiReadDataCont\n\r");
|
||||
DEBUG_printf("\tCC3000: SpiReadDataCont\n\r");
|
||||
|
||||
/* Determine what type of packet we have */
|
||||
evnt_buff = sSpiInformation.pRxPacket;
|
||||
|
@ -454,7 +459,7 @@ long SpiReadDataCont(void)
|
|||
/**************************************************************************/
|
||||
void SpiPauseSpi(void)
|
||||
{
|
||||
DEBUGPRINT_F("\tCC3000: SpiPauseSpi\n\r");
|
||||
DEBUG_printf("\tCC3000: SpiPauseSpi\n\r");
|
||||
|
||||
ccspi_int_enabled = 0;
|
||||
pyb_cc3000_pause_spi();
|
||||
|
@ -467,7 +472,7 @@ void SpiPauseSpi(void)
|
|||
/**************************************************************************/
|
||||
void SpiResumeSpi(void)
|
||||
{
|
||||
DEBUGPRINT_F("\tCC3000: SpiResumeSpi\n\r");
|
||||
DEBUG_printf("\tCC3000: SpiResumeSpi\n\r");
|
||||
|
||||
ccspi_int_enabled = 1;
|
||||
pyb_cc3000_resume_spi();
|
||||
|
@ -480,24 +485,24 @@ void SpiResumeSpi(void)
|
|||
/**************************************************************************/
|
||||
void SpiTriggerRxProcessing(void)
|
||||
{
|
||||
DEBUGPRINT_F("\tCC3000: SpiTriggerRxProcessing\n\r");
|
||||
DEBUG_printf("\tCC3000: SpiTriggerRxProcessing\n\r");
|
||||
|
||||
/* Trigger Rx processing */
|
||||
SpiPauseSpi();
|
||||
CC3000_DEASSERT_CS();
|
||||
|
||||
//DEBUGPRINT_F("Magic?\n\r");
|
||||
//DEBUG_printf("Magic?\n\r");
|
||||
/* The magic number that resides at the end of the TX/RX buffer (1 byte after the allocated size)
|
||||
* for the purpose of detection of the overrun. If the magic number is overriten - buffer overrun
|
||||
* occurred - and we will stuck here forever! */
|
||||
if (sSpiInformation.pRxPacket[CC3000_RX_BUFFER_SIZE - 1] != CC3000_BUFFER_MAGIC_NUMBER)
|
||||
{
|
||||
/* You've got problems if you're here! */
|
||||
DEBUGPRINT_F("\tCC3000: ERROR - magic number missing!\n\r");
|
||||
DEBUG_printf("\tCC3000: ERROR - magic number missing!\n\r");
|
||||
while (1);
|
||||
}
|
||||
|
||||
//DEBUGPRINT_F("OK!\n\r");
|
||||
//DEBUG_printf("OK!\n\r");
|
||||
sSpiInformation.ulSpiState = eSPI_STATE_IDLE;
|
||||
sSpiInformation.SPIRxHandler(sSpiInformation.pRxPacket + SPI_HEADER_SIZE);
|
||||
}
|
||||
|
@ -509,14 +514,14 @@ void SpiTriggerRxProcessing(void)
|
|||
/**************************************************************************/
|
||||
void SSIContReadOperation(void)
|
||||
{
|
||||
DEBUGPRINT_F("\tCC3000: SpiContReadOperation\n\r");
|
||||
DEBUG_printf("\tCC3000: SpiContReadOperation\n\r");
|
||||
|
||||
/* The header was read - continue with the payload read */
|
||||
if (!SpiReadDataCont())
|
||||
{
|
||||
/* All the data was read - finalize handling by switching to teh task
|
||||
* and calling from task Event Handler */
|
||||
//DEBUGPRINT_F("SPItrig\n\r");
|
||||
//DEBUG_printf("SPItrig\n\r");
|
||||
SpiTriggerRxProcessing();
|
||||
}
|
||||
}
|
||||
|
@ -528,23 +533,6 @@ void SSIContReadOperation(void)
|
|||
/**************************************************************************/
|
||||
void WriteWlanPin( unsigned char val )
|
||||
{
|
||||
#if 0
|
||||
if (DEBUG_MODE)
|
||||
{
|
||||
DEBUGPRINT_F("\tCC3000: WriteWlanPin - ");
|
||||
DEBUGPRINT_DEC(val);
|
||||
DEBUGPRINT_F("\n\r");
|
||||
delay(1);
|
||||
}
|
||||
if (val)
|
||||
{
|
||||
digitalWrite(g_vbatPin, HIGH);
|
||||
}
|
||||
else
|
||||
{
|
||||
digitalWrite(g_vbatPin, LOW);
|
||||
}
|
||||
#endif
|
||||
pyb_cc3000_set_en(val == WLAN_ENABLE);
|
||||
}
|
||||
|
||||
|
@ -555,9 +543,7 @@ void WriteWlanPin( unsigned char val )
|
|||
/**************************************************************************/
|
||||
long ReadWlanInterruptPin(void)
|
||||
{
|
||||
DEBUGPRINT_F("\tCC3000: ReadWlanInterruptPin - ");
|
||||
DEBUGPRINT_DEC(digitalRead(g_irqPin));
|
||||
DEBUGPRINT_F("\n\r");
|
||||
DEBUG_printf("CC3000: ReadWlanInterruptPin\n");
|
||||
|
||||
return pyb_cc3000_get_irq();
|
||||
}
|
||||
|
@ -569,9 +555,9 @@ long ReadWlanInterruptPin(void)
|
|||
/**************************************************************************/
|
||||
void WlanInterruptEnable()
|
||||
{
|
||||
DEBUGPRINT_F("\tCC3000: WlanInterruptEnable.\n\r");
|
||||
// delay(100);
|
||||
ccspi_int_enabled = 1;
|
||||
DEBUG_printf("\tCC3000: WlanInterruptEnable.\n\r");
|
||||
// delay(100);
|
||||
ccspi_int_enabled = 1;
|
||||
pyb_cc3000_enable_irq();
|
||||
}
|
||||
|
||||
|
@ -582,7 +568,7 @@ void WlanInterruptEnable()
|
|||
/**************************************************************************/
|
||||
void WlanInterruptDisable()
|
||||
{
|
||||
DEBUGPRINT_F("\tCC3000: WlanInterruptDisable\n\r");
|
||||
DEBUG_printf("\tCC3000: WlanInterruptDisable\n\r");
|
||||
ccspi_int_enabled = 0;
|
||||
pyb_cc3000_disable_irq();
|
||||
}
|
||||
|
@ -687,7 +673,7 @@ void SPI_IRQ(void)
|
|||
{
|
||||
ccspi_is_in_irq = 1;
|
||||
|
||||
DEBUGPRINT_F("\tCC3000: Entering SPI_IRQ\n\r");
|
||||
DEBUG_printf("\tCC3000: Entering SPI_IRQ\n\r");
|
||||
|
||||
if (sSpiInformation.ulSpiState == eSPI_STATE_POWERUP)
|
||||
{
|
||||
|
@ -696,7 +682,7 @@ void SPI_IRQ(void)
|
|||
}
|
||||
else if (sSpiInformation.ulSpiState == eSPI_STATE_IDLE)
|
||||
{
|
||||
//DEBUGPRINT_F("IDLE\n\r");
|
||||
//DEBUG_printf("IDLE\n\r");
|
||||
sSpiInformation.ulSpiState = eSPI_STATE_READ_IRQ;
|
||||
/* IRQ line goes down - start reception */
|
||||
|
||||
|
@ -705,7 +691,7 @@ void SPI_IRQ(void)
|
|||
// Wait for TX/RX Compete which will come as DMA interrupt
|
||||
SpiReadHeader();
|
||||
sSpiInformation.ulSpiState = eSPI_STATE_READ_EOT;
|
||||
//DEBUGPRINT_F("SSICont\n\r");
|
||||
//DEBUG_printf("SSICont\n\r");
|
||||
SSIContReadOperation();
|
||||
}
|
||||
else if (sSpiInformation.ulSpiState == eSPI_STATE_WRITE_IRQ)
|
||||
|
@ -715,7 +701,7 @@ void SPI_IRQ(void)
|
|||
CC3000_DEASSERT_CS();
|
||||
}
|
||||
|
||||
DEBUGPRINT_F("\tCC3000: Leaving SPI_IRQ\n\r");
|
||||
DEBUG_printf("\tCC3000: Leaving SPI_IRQ\n\r");
|
||||
|
||||
ccspi_is_in_irq = 0;
|
||||
return;
|
||||
|
|
|
@ -3,14 +3,6 @@
|
|||
* evnt_handler.c - CC3000 Host Driver Implementation.
|
||||
* Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
|
||||
*
|
||||
* Adapted for use with the Arduino/AVR by KTOWN (Kevin Townsend)
|
||||
* & Limor Fried for Adafruit Industries
|
||||
* This library works with the Adafruit CC3000 breakout
|
||||
* ----> https://www.adafruit.com/products/1469
|
||||
* Adafruit invests time and resources providing this open source code,
|
||||
* please support Adafruit and open-source hardware by purchasing
|
||||
* products from Adafruit!
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
|
@ -64,7 +56,6 @@
|
|||
#include "socket.h"
|
||||
#include "netapp.h"
|
||||
#include "ccspi.h"
|
||||
#include "ccdebug.h"
|
||||
|
||||
|
||||
|
||||
|
@ -251,22 +242,17 @@ hci_event_handler(void *pRetParams, unsigned char *from, unsigned char *fromlen)
|
|||
|
||||
while (1)
|
||||
{
|
||||
cc3k_int_poll();
|
||||
|
||||
if (tSLInformation.usEventOrDataReceived != 0)
|
||||
{
|
||||
|
||||
pucReceivedData = (tSLInformation.pucReceivedData);
|
||||
|
||||
if (*pucReceivedData == HCI_TYPE_EVNT)
|
||||
{
|
||||
// Event Received
|
||||
STREAM_TO_UINT16((char *)pucReceivedData,
|
||||
HCI_EVENT_OPCODE_OFFSET,
|
||||
usReceivedEventOpcode);
|
||||
STREAM_TO_UINT16((char *)pucReceivedData, HCI_EVENT_OPCODE_OFFSET, usReceivedEventOpcode);
|
||||
pucReceivedParams = pucReceivedData + HCI_EVENT_HEADER_SIZE;
|
||||
RecvParams = pucReceivedParams;
|
||||
RetParams = (unsigned char *)pRetParams;
|
||||
RetParams = pRetParams;
|
||||
|
||||
// In case unsolicited event received - here the handling finished
|
||||
if (hci_unsol_event_handler((char *)pucReceivedData) == 0)
|
||||
|
@ -277,10 +263,8 @@ hci_event_handler(void *pRetParams, unsigned char *from, unsigned char *fromlen)
|
|||
{
|
||||
case HCI_CMND_READ_BUFFER_SIZE:
|
||||
{
|
||||
STREAM_TO_UINT8((char *)pucReceivedParams, 0,
|
||||
tSLInformation.usNumberOfFreeBuffers);
|
||||
STREAM_TO_UINT16((char *)pucReceivedParams, 1,
|
||||
tSLInformation.usSlBufferLength);
|
||||
STREAM_TO_UINT8((char *)pucReceivedParams, 0, tSLInformation.usNumberOfFreeBuffers);
|
||||
STREAM_TO_UINT16((char *)pucReceivedParams, 1, tSLInformation.usSlBufferLength);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -297,8 +281,7 @@ hci_event_handler(void *pRetParams, unsigned char *from, unsigned char *fromlen)
|
|||
case HCI_NETAPP_PING_REPORT:
|
||||
case HCI_EVNT_MDNS_ADVERTISE:
|
||||
|
||||
STREAM_TO_UINT8(pucReceivedData, HCI_EVENT_STATUS_OFFSET
|
||||
,*(unsigned char *)pRetParams);
|
||||
STREAM_TO_UINT8(pucReceivedData, HCI_EVENT_STATUS_OFFSET ,*(unsigned char *)pRetParams);
|
||||
break;
|
||||
|
||||
case HCI_CMND_SETSOCKOPT:
|
||||
|
@ -320,14 +303,12 @@ hci_event_handler(void *pRetParams, unsigned char *from, unsigned char *fromlen)
|
|||
case HCI_EVNT_CONNECT:
|
||||
case HCI_EVNT_NVMEM_WRITE:
|
||||
|
||||
STREAM_TO_UINT32((char *)pucReceivedParams,0
|
||||
,*(unsigned long *)pRetParams);
|
||||
STREAM_TO_UINT32((char *)pucReceivedParams,0 ,*(unsigned long *)pRetParams);
|
||||
break;
|
||||
|
||||
case HCI_EVNT_READ_SP_VERSION:
|
||||
|
||||
STREAM_TO_UINT8(pucReceivedData, HCI_EVENT_STATUS_OFFSET
|
||||
,*(unsigned char *)pRetParams);
|
||||
STREAM_TO_UINT8(pucReceivedData, HCI_EVENT_STATUS_OFFSET ,*(unsigned char *)pRetParams);
|
||||
pRetParams = ((char *)pRetParams) + 1;
|
||||
STREAM_TO_UINT32((char *)pucReceivedParams, 0, retValue32);
|
||||
UINT32_TO_STREAM((unsigned char *)pRetParams, retValue32);
|
||||
|
@ -360,17 +341,17 @@ hci_event_handler(void *pRetParams, unsigned char *from, unsigned char *fromlen)
|
|||
case HCI_EVNT_RECV:
|
||||
case HCI_EVNT_RECVFROM:
|
||||
{
|
||||
STREAM_TO_UINT32((char *)pucReceivedParams,SL_RECEIVE_SD_OFFSET ,*(unsigned long *)pRetParams);
|
||||
pRetParams = ((char *)pRetParams) + 4;
|
||||
STREAM_TO_UINT32((char *)pucReceivedParams,SL_RECEIVE_NUM_BYTES_OFFSET,*(unsigned long *)pRetParams);
|
||||
pRetParams = ((char *)pRetParams) + 4;
|
||||
STREAM_TO_UINT32((char *)pucReceivedParams,SL_RECEIVE__FLAGS__OFFSET,*(unsigned long *)pRetParams);
|
||||
//tBsdReadReturnParams *tread = (tBsdReadReturnParams *)pRetParams; // unused
|
||||
if(((tBsdReadReturnParams *)pRetParams)->iNumberOfBytes == ERROR_SOCKET_INACTIVE)
|
||||
{
|
||||
set_socket_active_status(((tBsdReadReturnParams *)pRetParams)->iSocketDescriptor,SOCKET_STATUS_INACTIVE);
|
||||
}
|
||||
break;
|
||||
STREAM_TO_UINT32((char *)pucReceivedParams,SL_RECEIVE_SD_OFFSET ,*(unsigned long *)pRetParams);
|
||||
pRetParams = ((char *)pRetParams) + 4;
|
||||
STREAM_TO_UINT32((char *)pucReceivedParams,SL_RECEIVE_NUM_BYTES_OFFSET,*(unsigned long *)pRetParams);
|
||||
pRetParams = ((char *)pRetParams) + 4;
|
||||
STREAM_TO_UINT32((char *)pucReceivedParams,SL_RECEIVE__FLAGS__OFFSET,*(unsigned long *)pRetParams);
|
||||
|
||||
if(((tBsdReadReturnParams *)pRetParams)->iNumberOfBytes == ERROR_SOCKET_INACTIVE)
|
||||
{
|
||||
set_socket_active_status(((tBsdReadReturnParams *)pRetParams)->iSocketDescriptor,SOCKET_STATUS_INACTIVE);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case HCI_EVNT_SEND:
|
||||
|
@ -447,7 +428,7 @@ hci_event_handler(void *pRetParams, unsigned char *from, unsigned char *fromlen)
|
|||
|
||||
//Read SSID
|
||||
STREAM_TO_STREAM(RecvParams,RetParams,NETAPP_IPCONFIG_SSID_LENGTH);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -520,9 +501,6 @@ hci_unsol_event_handler(char *event_hdr)
|
|||
|
||||
STREAM_TO_UINT16(event_hdr, HCI_EVENT_OPCODE_OFFSET,event_type);
|
||||
|
||||
DEBUGPRINT_F("\tHCI_UNSOL_EVT: ");
|
||||
DEBUGPRINT_HEX16(event_type);
|
||||
|
||||
if (event_type & HCI_EVNT_UNSOL_BASE)
|
||||
{
|
||||
switch(event_type)
|
||||
|
@ -614,23 +592,14 @@ hci_unsol_event_handler(char *event_hdr)
|
|||
break;
|
||||
case HCI_EVNT_BSD_TCP_CLOSE_WAIT:
|
||||
{
|
||||
DEBUGPRINT_F("\tTCP Close Wait\n\r");
|
||||
uint8_t socketnum;
|
||||
data = (char*)(event_hdr) + HCI_EVENT_HEADER_SIZE;
|
||||
/*
|
||||
printHex(data[0]); PRINT_F("\t");
|
||||
printHex(data[1]); PRINT_F("\t");
|
||||
printHex(data[2]); PRINT_F("\t");
|
||||
printHex(data[3]); PRINT_F("\t");
|
||||
printHex(data[4]); PRINT_F("\t");
|
||||
printHex(data[5]); PRINT_F("\t");
|
||||
*/
|
||||
socketnum = data[0];
|
||||
//STREAM_TO_UINT16(data, 0, socketnum);
|
||||
if( tSLInformation.sWlanCB )
|
||||
{
|
||||
tSLInformation.sWlanCB(event_type, (char *)&socketnum, 1);
|
||||
}
|
||||
data = (char *)(event_hdr) + HCI_EVENT_HEADER_SIZE;
|
||||
if( tSLInformation.sWlanCB )
|
||||
{
|
||||
//data[0] represents the socket id, for which FIN was received by remote.
|
||||
//Upon receiving this event, the user can close the socket, or else the
|
||||
//socket will be closded after inacvitity timeout (by default 60 seconds)
|
||||
tSLInformation.sWlanCB(event_type, data, 1);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -647,8 +616,6 @@ hci_unsol_event_handler(char *event_hdr)
|
|||
char *pArg;
|
||||
long status;
|
||||
|
||||
DEBUGPRINT_F("\tSEND event response\n\r");
|
||||
|
||||
pArg = M_BSD_RESP_PARAMS_OFFSET(event_hdr);
|
||||
STREAM_TO_UINT32(pArg, BSD_RSP_PARAMS_STATUS_OFFSET,status);
|
||||
|
||||
|
@ -666,6 +633,12 @@ hci_unsol_event_handler(char *event_hdr)
|
|||
return (0);
|
||||
}
|
||||
|
||||
//handle a case where unsolicited event arrived, but was not handled by any of the cases above
|
||||
if ((event_type != tSLInformation.usRxEventOpcode) && (event_type != HCI_EVNT_PATCHES_REQ))
|
||||
{
|
||||
return(1);
|
||||
}
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
|
|
@ -3,14 +3,6 @@
|
|||
* evnt_handler.h - CC3000 Host Driver Implementation.
|
||||
* Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
|
||||
*
|
||||
* Adapted for use with the Arduino/AVR by KTOWN (Kevin Townsend)
|
||||
* & Limor Fried for Adafruit Industries
|
||||
* This library works with the Adafruit CC3000 breakout
|
||||
* ----> https://www.adafruit.com/products/1469
|
||||
* Adafruit invests time and resources providing this open source code,
|
||||
* please support Adafruit and open-source hardware by purchasing
|
||||
* products from Adafruit!
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
|
@ -42,7 +34,6 @@
|
|||
*****************************************************************************/
|
||||
#ifndef __EVENT_HANDLER_H__
|
||||
#define __EVENT_HANDLER_H__
|
||||
|
||||
#include "hci.h"
|
||||
#include "socket.h"
|
||||
|
||||
|
|
|
@ -3,14 +3,6 @@
|
|||
* hci.c - CC3000 Host Driver Implementation.
|
||||
* Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
|
||||
*
|
||||
* Adapted for use with the Arduino/AVR by KTOWN (Kevin Townsend)
|
||||
* & Limor Fried for Adafruit Industries
|
||||
* This library works with the Adafruit CC3000 breakout
|
||||
* ----> https://www.adafruit.com/products/1469
|
||||
* Adafruit invests time and resources providing this open source code,
|
||||
* please support Adafruit and open-source hardware by purchasing
|
||||
* products from Adafruit!
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
|
@ -212,8 +204,6 @@ hci_patch_send(unsigned char ucOpcode, unsigned char *pucBuff, char *patch, unsi
|
|||
|
||||
while (usDataLength)
|
||||
{
|
||||
cc3k_int_poll();
|
||||
|
||||
if (usDataLength <= SL_PATCH_PORTION_SIZE)
|
||||
{
|
||||
usTransLength = usDataLength;
|
||||
|
|
|
@ -3,14 +3,6 @@
|
|||
* hci.h - CC3000 Host Driver Implementation.
|
||||
* Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
|
||||
*
|
||||
* Adapted for use with the Arduino/AVR by KTOWN (Kevin Townsend)
|
||||
* & Limor Fried for Adafruit Industries
|
||||
* This library works with the Adafruit CC3000 breakout
|
||||
* ----> https://www.adafruit.com/products/1469
|
||||
* Adafruit invests time and resources providing this open source code,
|
||||
* please support Adafruit and open-source hardware by purchasing
|
||||
* products from Adafruit!
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
#ifndef __HOST_DRIVER_VERSION_H__
|
||||
#define __HOST_DRIVER_VERSION_H__
|
||||
|
||||
#define DRIVER_VERSION_NUMBER 13
|
||||
#define DRIVER_VERSION_NUMBER 14
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -3,14 +3,6 @@
|
|||
* netapp.c - CC3000 Host Driver Implementation.
|
||||
* Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
|
||||
*
|
||||
* Adapted for use with the Arduino/AVR by KTOWN (Kevin Townsend)
|
||||
* & Limor Fried for Adafruit Industries
|
||||
* This library works with the Adafruit CC3000 breakout
|
||||
* ----> https://www.adafruit.com/products/1469
|
||||
* Adafruit invests time and resources providing this open source code,
|
||||
* please support Adafruit and open-source hardware by purchasing
|
||||
* products from Adafruit!
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
|
@ -244,7 +236,7 @@ netapp_timeout_values(unsigned long *aucDHCP, unsigned long *aucARP,unsigned lon
|
|||
|
||||
#ifndef CC3000_TINY_DRIVER
|
||||
long
|
||||
netapp_ping_send(uint32_t *ip, uint32_t ulPingAttempts, uint32_t ulPingSize, uint32_t ulPingTimeout)
|
||||
netapp_ping_send(unsigned long *ip, unsigned long ulPingAttempts, unsigned long ulPingSize, unsigned long ulPingTimeout)
|
||||
{
|
||||
signed char scRet;
|
||||
unsigned char *ptr, *args;
|
||||
|
@ -259,15 +251,6 @@ netapp_ping_send(uint32_t *ip, uint32_t ulPingAttempts, uint32_t ulPingSize, uin
|
|||
args = UINT32_TO_STREAM(args, ulPingSize);
|
||||
args = UINT32_TO_STREAM(args, ulPingTimeout);
|
||||
|
||||
/*
|
||||
if (CC3KPrinter != 0)
|
||||
{
|
||||
for(uint8_t i=0; i<4+4+4+4; i++) {
|
||||
CC3KPrinter->print(" 0x"); CC3KPrinter->( (ptr + HEADERS_SIZE_CMD)[i], HEX);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
// Initiate a HCI command
|
||||
hci_command_send(HCI_NETAPP_PING_SEND, ptr, NETAPP_PING_SEND_PARAMS_LEN);
|
||||
|
||||
|
|
|
@ -3,14 +3,6 @@
|
|||
* netapp.h - CC3000 Host Driver Implementation.
|
||||
* Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
|
||||
*
|
||||
* Adapted for use with the Arduino/AVR by KTOWN (Kevin Townsend)
|
||||
* & Limor Fried for Adafruit Industries
|
||||
* This library works with the Adafruit CC3000 breakout
|
||||
* ----> https://www.adafruit.com/products/1469
|
||||
* Adafruit invests time and resources providing this open source code,
|
||||
* please support Adafruit and open-source hardware by purchasing
|
||||
* products from Adafruit!
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
|
@ -43,6 +35,7 @@
|
|||
#ifndef __NETAPP_H__
|
||||
#define __NETAPP_H__
|
||||
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// If building with a C++ compiler, make all of the definitions in this header
|
||||
|
@ -213,7 +206,7 @@ extern long netapp_timeout_values(unsigned long *aucDHCP, unsigned long *aucARP,
|
|||
//*****************************************************************************
|
||||
|
||||
#ifndef CC3000_TINY_DRIVER
|
||||
extern long netapp_ping_send(uint32_t *ip, uint32_t ulPingAttempts, uint32_t ulPingSize, uint32_t ulPingTimeout);
|
||||
extern long netapp_ping_send(unsigned long *ip, unsigned long ulPingAttempts, unsigned long ulPingSize, unsigned long ulPingTimeout);
|
||||
#endif
|
||||
|
||||
//*****************************************************************************
|
||||
|
|
|
@ -3,14 +3,6 @@
|
|||
* nvmem.c - CC3000 Host Driver Implementation.
|
||||
* Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
|
||||
*
|
||||
* Adapted for use with the Arduino/AVR by KTOWN (Kevin Townsend)
|
||||
* & Limor Fried for Adafruit Industries
|
||||
* This library works with the Adafruit CC3000 breakout
|
||||
* ----> https://www.adafruit.com/products/1469
|
||||
* Adafruit invests time and resources providing this open source code,
|
||||
* please support Adafruit and open-source hardware by purchasing
|
||||
* products from Adafruit!
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
|
@ -58,7 +50,6 @@
|
|||
#include "hci.h"
|
||||
#include "socket.h"
|
||||
#include "evnt_handler.h"
|
||||
#include "ccdebug.h"
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
|
@ -167,15 +158,7 @@ nvmem_write(unsigned long ulFileId, unsigned long ulLength, unsigned long
|
|||
|
||||
memcpy((ptr + SPI_HEADER_SIZE + HCI_DATA_CMD_HEADER_SIZE +
|
||||
NVMEM_WRITE_PARAMS_LEN),buff,ulLength);
|
||||
#if (DEBUG_MODE == 1)
|
||||
PRINT_F("Writing:\t");
|
||||
for (uint8_t i=0; i<ulLength; i++) {
|
||||
PRINT_F("0x");
|
||||
printHex(buff[i]);
|
||||
PRINT_F(", ");
|
||||
}
|
||||
PRINT_F("\n\r");
|
||||
#endif
|
||||
|
||||
// Initiate a HCI command but it will come on data channel
|
||||
hci_data_command_send(HCI_CMND_NVMEM_WRITE, ptr, NVMEM_WRITE_PARAMS_LEN,
|
||||
ulLength);
|
||||
|
@ -240,7 +223,7 @@ unsigned char nvmem_get_mac_address(unsigned char *mac)
|
|||
//!
|
||||
//*****************************************************************************
|
||||
|
||||
unsigned char nvmem_write_patch(unsigned long ulFileId, unsigned long spLength, const uint8_t *spData)
|
||||
unsigned char nvmem_write_patch(unsigned long ulFileId, unsigned long spLength, const unsigned char *spData)
|
||||
{
|
||||
unsigned char status = 0;
|
||||
unsigned short offset = 0;
|
||||
|
@ -248,19 +231,10 @@ unsigned char nvmem_write_patch(unsigned long ulFileId, unsigned long spLength,
|
|||
|
||||
while ((status == 0) && (spLength >= SP_PORTION_SIZE))
|
||||
{
|
||||
#if (DEBUG_MODE == 1)
|
||||
PRINT_F("Writing: "); printDec16(offset); PRINT_F("\t");
|
||||
for (uint8_t i=0; i<SP_PORTION_SIZE; i++) {
|
||||
PRINT_F("0x");
|
||||
printHex(spDataPtr[i]);
|
||||
PRINT_F(", ");
|
||||
}
|
||||
PRINT_F("\n\r");
|
||||
#endif
|
||||
status = nvmem_write(ulFileId, SP_PORTION_SIZE, offset, spDataPtr);
|
||||
offset += SP_PORTION_SIZE;
|
||||
spLength -= SP_PORTION_SIZE;
|
||||
spDataPtr += SP_PORTION_SIZE;
|
||||
status = nvmem_write(ulFileId, SP_PORTION_SIZE, offset, spDataPtr);
|
||||
offset += SP_PORTION_SIZE;
|
||||
spLength -= SP_PORTION_SIZE;
|
||||
spDataPtr += SP_PORTION_SIZE;
|
||||
}
|
||||
|
||||
if (status !=0)
|
||||
|
@ -271,8 +245,8 @@ unsigned char nvmem_write_patch(unsigned long ulFileId, unsigned long spLength,
|
|||
|
||||
if (spLength != 0)
|
||||
{
|
||||
// if reached here, a reminder is left
|
||||
status = nvmem_write(ulFileId, spLength, offset, spDataPtr);
|
||||
// if reached here, a reminder is left
|
||||
status = nvmem_write(ulFileId, spLength, offset, spDataPtr);
|
||||
}
|
||||
|
||||
return status;
|
||||
|
@ -293,11 +267,11 @@ unsigned char nvmem_write_patch(unsigned long ulFileId, unsigned long spLength,
|
|||
//*****************************************************************************
|
||||
|
||||
#ifndef CC3000_TINY_DRIVER
|
||||
uint8_t nvmem_read_sp_version(uint8_t* patchVer)
|
||||
unsigned char nvmem_read_sp_version(unsigned char* patchVer)
|
||||
{
|
||||
uint8_t *ptr;
|
||||
unsigned char *ptr;
|
||||
// 1st byte is the status and the rest is the SP version
|
||||
uint8_t retBuf[5];
|
||||
unsigned char retBuf[5];
|
||||
|
||||
ptr = tSLInformation.pucTxCommandBuffer;
|
||||
|
||||
|
@ -337,12 +311,12 @@ uint8_t nvmem_read_sp_version(uint8_t* patchVer)
|
|||
//!
|
||||
//*****************************************************************************
|
||||
|
||||
int8_t
|
||||
signed long
|
||||
nvmem_create_entry(unsigned long ulFileId, unsigned long ulNewLen)
|
||||
{
|
||||
unsigned char *ptr;
|
||||
unsigned char *args;
|
||||
int8_t retval;
|
||||
unsigned short retval;
|
||||
|
||||
ptr = tSLInformation.pucTxCommandBuffer;
|
||||
args = (ptr + HEADERS_SIZE_CMD);
|
||||
|
@ -355,6 +329,7 @@ nvmem_create_entry(unsigned long ulFileId, unsigned long ulNewLen)
|
|||
hci_command_send(HCI_CMND_NVMEM_CREATE_ENTRY,ptr, NVMEM_CREATE_PARAMS_LEN);
|
||||
|
||||
SimpleLinkWaitEvent(HCI_CMND_NVMEM_CREATE_ENTRY, &retval);
|
||||
|
||||
return(retval);
|
||||
}
|
||||
|
||||
|
|
|
@ -3,14 +3,6 @@
|
|||
* nvmem.h - CC3000 Host Driver Implementation.
|
||||
* Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
|
||||
*
|
||||
* Adapted for use with the Arduino/AVR by KTOWN (Kevin Townsend)
|
||||
* & Limor Fried for Adafruit Industries
|
||||
* This library works with the Adafruit CC3000 breakout
|
||||
* ----> https://www.adafruit.com/products/1469
|
||||
* Adafruit invests time and resources providing this open source code,
|
||||
* please support Adafruit and open-source hardware by purchasing
|
||||
* products from Adafruit!
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
|
@ -231,7 +223,7 @@ extern unsigned char nvmem_read_sp_version(unsigned char* patchVer);
|
|||
//! set ulNewLen=0.
|
||||
//!
|
||||
//*****************************************************************************
|
||||
extern int8_t nvmem_create_entry(unsigned long file_id, unsigned long newlen);
|
||||
extern signed long nvmem_create_entry(unsigned long file_id, unsigned long newlen);
|
||||
|
||||
|
||||
//*****************************************************************************
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "stm32f4xx_hal.h"
|
||||
|
@ -14,11 +15,16 @@
|
|||
#include "extint.h"
|
||||
#include "spi.h"
|
||||
#include "ccspi.h"
|
||||
#include "ccdebug.h"
|
||||
#include "pybcc3k.h"
|
||||
|
||||
#if MICROPY_HW_ENABLE_CC3K
|
||||
|
||||
#if 1 // print debugging info
|
||||
#define DEBUG_printf(args...) printf(args)
|
||||
#else // don't print debugging info
|
||||
#define DEBUG_printf(args...) (void)0
|
||||
#endif
|
||||
|
||||
// IRQ on PA14, input, pulled up, active low
|
||||
// EN on PC7, output, active high
|
||||
// CS on PC6, output, active low
|
||||
|
@ -73,12 +79,13 @@ uint32_t exti14_missed = 0; // TODO hack; do it properly!
|
|||
void pyb_cc3000_enable_irq(void) {
|
||||
DEBUG_printf("pyb_cc3000_enable_irq: en=%lu miss=%lu\n", exti14_enabled, exti14_missed);
|
||||
if (exti14_missed) {
|
||||
/* doesn't look like this is needed
|
||||
// doesn't look like this is needed
|
||||
DEBUG_printf("pyb_cc3000_enable_irq: handling missed IRQ\n");
|
||||
/*
|
||||
// TODO hack if we have a pending IRQ
|
||||
extern void SpiIntGPIOHandler(void);
|
||||
SpiIntGPIOHandler();
|
||||
*/
|
||||
SpiIntGPIOHandler();
|
||||
exti14_missed = 0;
|
||||
}
|
||||
exti14_enabled = 1;
|
||||
|
|
|
@ -3,14 +3,6 @@
|
|||
* socket.c - CC3000 Host Driver Implementation.
|
||||
* Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
|
||||
*
|
||||
* Adapted for use with the Arduino/AVR by KTOWN (Kevin Townsend)
|
||||
* & Limor Fried for Adafruit Industries
|
||||
* This library works with the Adafruit CC3000 breakout
|
||||
* ----> https://www.adafruit.com/products/1469
|
||||
* Adafruit invests time and resources providing this open source code,
|
||||
* please support Adafruit and open-source hardware by purchasing
|
||||
* products from Adafruit!
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
|
@ -58,7 +50,6 @@
|
|||
#include "socket.h"
|
||||
#include "evnt_handler.h"
|
||||
#include "netapp.h"
|
||||
#include "ccdebug.h"
|
||||
|
||||
extern int errno;
|
||||
|
||||
|
@ -317,6 +308,7 @@ accept(long sd, sockaddr *addr, socklen_t *addrlen)
|
|||
tBsdReturnParams tAcceptReturnArguments;
|
||||
|
||||
ret = EFAIL;
|
||||
tAcceptReturnArguments.iStatus = EFAIL; // in case of timeout
|
||||
ptr = tSLInformation.pucTxCommandBuffer;
|
||||
args = (ptr + HEADERS_SIZE_CMD);
|
||||
|
||||
|
@ -472,7 +464,7 @@ listen(long sd, long backlog)
|
|||
|
||||
#ifndef CC3000_TINY_DRIVER
|
||||
int
|
||||
gethostbyname(const char * hostname, uint8_t usNameLen, uint32_t * out_ip_addr)
|
||||
gethostbyname(const char* hostname, unsigned short usNameLen, unsigned long* out_ip_addr)
|
||||
{
|
||||
tBsdGethostbynameParams ret;
|
||||
unsigned char *ptr, *args;
|
||||
|
@ -500,8 +492,8 @@ gethostbyname(const char * hostname, uint8_t usNameLen, uint32_t * out_ip_addr)
|
|||
SimpleLinkWaitEvent(HCI_EVNT_BSD_GETHOSTBYNAME, &ret);
|
||||
|
||||
errno = ret.retVal;
|
||||
//Dprinter->print("errno: "); Dprinter->println(errno);
|
||||
(*((uint32_t *)out_ip_addr)) = ret.outputAddress;
|
||||
|
||||
(*((long*)out_ip_addr)) = ret.outputAddress;
|
||||
|
||||
return (errno);
|
||||
|
||||
|
@ -734,7 +726,7 @@ int
|
|||
setsockopt(long sd, long level, long optname, const void *optval,
|
||||
socklen_t optlen)
|
||||
{
|
||||
long ret;
|
||||
int ret;
|
||||
unsigned char *ptr, *args;
|
||||
|
||||
ptr = tSLInformation.pucTxCommandBuffer;
|
||||
|
@ -762,7 +754,7 @@ setsockopt(long sd, long level, long optname, const void *optval,
|
|||
else
|
||||
{
|
||||
errno = ret;
|
||||
return (-1);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -844,7 +836,7 @@ getsockopt (long sd, long level, long optname, void *optval, socklen_t *optlen)
|
|||
else
|
||||
{
|
||||
errno = tRetParams.iStatus;
|
||||
return (-1);
|
||||
return errno;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -890,30 +882,18 @@ simple_link_recv(long sd, void *buf, long len, long flags, sockaddr *from,
|
|||
// Since we are in blocking state - wait for event complete
|
||||
SimpleLinkWaitEvent(opcode, &tSocketReadEvent);
|
||||
|
||||
DEBUGPRINT_F("\n\r\tRecv'd data... Socket #");
|
||||
DEBUGPRINT_DEC(tSocketReadEvent.iSocketDescriptor);
|
||||
DEBUGPRINT_F(" Bytes: 0x");
|
||||
DEBUGPRINT_HEX(tSocketReadEvent.iNumberOfBytes);
|
||||
DEBUGPRINT_F(" Flags: 0x");
|
||||
DEBUGPRINT_HEX(tSocketReadEvent.uiFlags);
|
||||
DEBUGPRINT_F("\n\r");
|
||||
|
||||
// In case the number of bytes is more then zero - read data
|
||||
if (tSocketReadEvent.iNumberOfBytes > 0)
|
||||
{
|
||||
// Wait for the data in a synchronous way. Here we assume that the bug is
|
||||
// big enough to store also parameters of receive from too....
|
||||
SimpleLinkWaitData((unsigned char *)buf, (unsigned char *)from, (unsigned char *)fromlen);
|
||||
SimpleLinkWaitData(buf, (unsigned char *)from, (unsigned char *)fromlen);
|
||||
}
|
||||
|
||||
|
||||
|
||||
errno = tSocketReadEvent.iNumberOfBytes;
|
||||
|
||||
#if (DEBUG_MODE == 1)
|
||||
for (uint8_t i=0; i<errno; i++) {
|
||||
putchar(((unsigned char *)buf)[i]);
|
||||
}
|
||||
#endif
|
||||
|
||||
return(tSocketReadEvent.iNumberOfBytes);
|
||||
}
|
||||
|
||||
|
@ -1165,7 +1145,7 @@ sendto(long sd, const void *buf, long len, long flags, const sockaddr *to,
|
|||
int
|
||||
mdnsAdvertiser(unsigned short mdnsEnabled, char * deviceServiceName, unsigned short deviceServiceNameLength)
|
||||
{
|
||||
char ret;
|
||||
int ret;
|
||||
unsigned char *pTxBuffer, *pArgs;
|
||||
|
||||
if (deviceServiceNameLength > MDNS_DEVICE_SERVICE_MAX_LENGTH)
|
||||
|
|
|
@ -3,14 +3,6 @@
|
|||
* socket.h - CC3000 Host Driver Implementation.
|
||||
* Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
|
||||
*
|
||||
* Adapted for use with the Arduino/AVR by KTOWN (Kevin Townsend)
|
||||
* & Limor Fried for Adafruit Industries
|
||||
* This library works with the Adafruit CC3000 breakout
|
||||
* ----> https://www.adafruit.com/products/1469
|
||||
* Adafruit invests time and resources providing this open source code,
|
||||
* please support Adafruit and open-source hardware by purchasing
|
||||
* products from Adafruit!
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
|
@ -102,9 +94,6 @@ extern "C" {
|
|||
#define SOCK_ON 0 // socket non-blocking mode is enabled
|
||||
#define SOCK_OFF 1 // socket blocking mode is enabled
|
||||
|
||||
#define TCP_NODELAY 0x0001
|
||||
#define TCP_BSDURGENT 0x7000
|
||||
|
||||
#define MAX_PACKET_SIZE 1500
|
||||
#define MAX_LISTEN_QUEUE 4
|
||||
|
||||
|
@ -373,7 +362,7 @@ extern long listen(long sd, long backlog);
|
|||
//
|
||||
//*****************************************************************************
|
||||
#ifndef CC3000_TINY_DRIVER
|
||||
extern int gethostbyname(const char * hostname, uint8_t usNameLen, uint32_t* out_ip_addr);
|
||||
extern int gethostbyname(const char* hostname, unsigned short usNameLen, unsigned long* out_ip_addr);
|
||||
#endif
|
||||
|
||||
|
||||
|
|
|
@ -3,14 +3,6 @@
|
|||
* wlan.c - CC3000 Host Driver Implementation.
|
||||
* Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
|
||||
*
|
||||
* Adapted for use with the Arduino/AVR by KTOWN (Kevin Townsend)
|
||||
* & Limor Fried for Adafruit Industries
|
||||
* This library works with the Adafruit CC3000 breakout
|
||||
* ----> https://www.adafruit.com/products/1469
|
||||
* Adafruit invests time and resources providing this open source code,
|
||||
* please support Adafruit and open-source hardware by purchasing
|
||||
* products from Adafruit!
|
||||
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
|
@ -60,7 +52,6 @@
|
|||
#include "nvmem.h"
|
||||
#include "security.h"
|
||||
#include "evnt_handler.h"
|
||||
#include "ccdebug.h"
|
||||
|
||||
extern int errno;
|
||||
|
||||
|
@ -133,13 +124,12 @@ static void SimpleLink_Init_Start(unsigned short usPatchesAvailableAtHost)
|
|||
|
||||
ptr = tSLInformation.pucTxCommandBuffer;
|
||||
args = (unsigned char *)(ptr + HEADERS_SIZE_CMD);
|
||||
if (usPatchesAvailableAtHost > 2)
|
||||
usPatchesAvailableAtHost = 2;
|
||||
|
||||
UINT8_TO_STREAM(args, usPatchesAvailableAtHost);
|
||||
UINT8_TO_STREAM(args, ((usPatchesAvailableAtHost) ? SL_PATCHES_REQUEST_FORCE_NONE : SL_PATCHES_REQUEST_DEFAULT));
|
||||
|
||||
// IRQ Line asserted - send HCI_CMND_SIMPLE_LINK_START to CC3000
|
||||
hci_command_send(HCI_CMND_SIMPLE_LINK_START, ptr, WLAN_SL_INIT_START_PARAMS_LEN);
|
||||
|
||||
SimpleLinkWaitEvent(HCI_CMND_SIMPLE_LINK_START, 0);
|
||||
}
|
||||
|
||||
|
@ -294,7 +284,7 @@ wlan_start(unsigned short usPatchesAvailableAtHost)
|
|||
// Check the IRQ line
|
||||
ulSpiIRQState = tSLInformation.ReadWlanInterruptPin();
|
||||
|
||||
// ASIC 1273 chip enable: toggle WLAN EN line
|
||||
// Chip enable: toggle WLAN EN line
|
||||
tSLInformation.WriteWlanPin( WLAN_ENABLE );
|
||||
|
||||
if (ulSpiIRQState)
|
||||
|
@ -315,11 +305,9 @@ wlan_start(unsigned short usPatchesAvailableAtHost)
|
|||
{
|
||||
}
|
||||
}
|
||||
DEBUGPRINT_F("SimpleLink start\n\r");
|
||||
SimpleLink_Init_Start(usPatchesAvailableAtHost);
|
||||
|
||||
// Read Buffer's size and finish
|
||||
DEBUGPRINT_F("Read buffer\n\r");
|
||||
hci_command_send(HCI_CMND_READ_BUFFER_SIZE, tSLInformation.pucTxCommandBuffer, 0);
|
||||
SimpleLinkWaitEvent(HCI_CMND_READ_BUFFER_SIZE, 0);
|
||||
}
|
||||
|
@ -342,7 +330,7 @@ wlan_start(unsigned short usPatchesAvailableAtHost)
|
|||
void
|
||||
wlan_stop(void)
|
||||
{
|
||||
// ASIC 1273 chip disable
|
||||
// Chip disable
|
||||
tSLInformation.WriteWlanPin( WLAN_DISABLE );
|
||||
|
||||
// Wait till IRQ line goes high...
|
||||
|
@ -371,7 +359,7 @@ wlan_stop(void)
|
|||
//! @param ssid up to 32 bytes and is ASCII SSID of the AP
|
||||
//! @param ssid_len length of the SSID
|
||||
//! @param bssid 6 bytes specified the AP bssid
|
||||
//! @param key up to 16 bytes specified the AP security key
|
||||
//! @param key up to 32 bytes specified the AP security key
|
||||
//! @param key_len key length
|
||||
//!
|
||||
//! @return On success, zero is returned. On error, negative is returned.
|
||||
|
@ -576,13 +564,17 @@ wlan_ioctl_set_connection_policy(unsigned long should_connect_to_open_ap,
|
|||
//! @param ulSsidLen ssid length
|
||||
//! @param ucBssid bssid 6 bytes
|
||||
//! @param ulPriority ulPriority profile priority. Lowest priority:0.
|
||||
//! Important Note: Smartconfig process (in unencrypted mode)
|
||||
//! stores the profile internally with priority 1, so changing
|
||||
//! priorities when adding new profiles should be done with extra care
|
||||
//! @param ulPairwiseCipher_Or_TxKeyLen key length for WEP security
|
||||
//! @param ulGroupCipher_TxKeyIndex key index
|
||||
//! @param ulKeyMgmt KEY management
|
||||
//! @param ucPf_OrKey security key
|
||||
//! @param ulPassPhraseLen security key length for WPA\WPA2
|
||||
//!
|
||||
//! @return On success, zero is returned. On error, -1 is returned
|
||||
//! @return On success, index (1-7) of the stored profile is returned.
|
||||
//! On error, -1 is returned.
|
||||
//!
|
||||
//! @brief When auto start is enabled, the device connects to
|
||||
//! station from the profiles table. Up to 7 profiles are supported.
|
||||
|
|
|
@ -3,14 +3,6 @@
|
|||
* wlan.h - CC3000 Host Driver Implementation.
|
||||
* Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
|
||||
*
|
||||
* Adapted for use with the Arduino/AVR by KTOWN (Kevin Townsend)
|
||||
* & Limor Fried for Adafruit Industries
|
||||
* This library works with the Adafruit CC3000 breakout
|
||||
* ----> https://www.adafruit.com/products/1469
|
||||
* Adafruit invests time and resources providing this open source code,
|
||||
* please support Adafruit and open-source hardware by purchasing
|
||||
* products from Adafruit!
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
|
@ -39,14 +31,6 @@
|
|||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
|
||||
Adapted for use with the Arduino/AVR by KTOWN for Adafruit Industries
|
||||
This library works with the Adafruit CC3000 breakout
|
||||
----> https://www.adafruit.com/products/1469
|
||||
Adafruit invests time and resources providing this open source code,
|
||||
please support Adafruit and open-source hardware by purchasing
|
||||
products from Adafruit!
|
||||
|
||||
*****************************************************************************/
|
||||
#ifndef __WLAN_H__
|
||||
#define __WLAN_H__
|
||||
|
@ -185,7 +169,7 @@ extern void wlan_stop(void);
|
|||
//! @param ssid up to 32 bytes and is ASCII SSID of the AP
|
||||
//! @param ssid_len length of the SSID
|
||||
//! @param bssid 6 bytes specified the AP bssid
|
||||
//! @param key up to 16 bytes specified the AP security key
|
||||
//! @param key up to 32 bytes specified the AP security key
|
||||
//! @param key_len key length
|
||||
//!
|
||||
//! @return On success, zero is returned. On error, negative is returned.
|
||||
|
|
|
@ -136,33 +136,42 @@ mp_obj_t pyb_wlan_get_host(mp_obj_t host_name) {
|
|||
}
|
||||
|
||||
mp_obj_t pyb_wlan_http_get(mp_obj_t host_name, mp_obj_t host_path) {
|
||||
if (host_name == mp_const_none) {
|
||||
last_ip = (192 << 24) | (168 << 16) | (0 << 8) | (3);
|
||||
int port;
|
||||
if (mp_obj_is_integer(host_name)) {
|
||||
last_ip = (192 << 24) | (168 << 16) | (0 << 8) | (mp_obj_get_int(host_name));
|
||||
port = 8080;
|
||||
} else {
|
||||
if (pyb_wlan_get_host(host_name) == mp_const_none) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "unknown host"));
|
||||
}
|
||||
port = 80;
|
||||
}
|
||||
int sd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
if (sd < 0) {
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "socket failed: %d", sd));
|
||||
}
|
||||
//printf("socket seemed to work\n");
|
||||
//HAL_Delay(200);
|
||||
|
||||
printf("socket seemed to work\n");
|
||||
|
||||
sockaddr_in remote;
|
||||
memset(&remote, 0, sizeof(sockaddr_in));
|
||||
remote.sin_family = AF_INET;
|
||||
remote.sin_port = htons(80);
|
||||
remote.sin_port = htons(port);
|
||||
remote.sin_addr.s_addr = htonl(last_ip);
|
||||
int ret = connect(sd, (sockaddr*)&remote, sizeof(sockaddr));
|
||||
if (ret != 0) {
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "connect failed: %d", ret));
|
||||
}
|
||||
//printf("connect seemed to work\n");
|
||||
//HAL_Delay(200);
|
||||
|
||||
printf("connect seemed to work\n");
|
||||
|
||||
vstr_t *vstr = vstr_new();
|
||||
vstr_printf(vstr, "GET %s HTTP/1.1\r\nHost: %s\r\nUser-Agent: PYBv2\r\n\r\n", mp_obj_str_get_str(host_path), mp_obj_str_get_qstr(host_name));
|
||||
//vstr_printf(vstr, "GET %s HTTP/1.1\r\nHost: %s\r\nUser-Agent: PYBv2\r\n\r\n", mp_obj_str_get_str(host_path), mp_obj_str_get_str(host_name));
|
||||
if (mp_obj_is_integer(host_name)) {
|
||||
vstr_printf(vstr, "GET %s HTTP/1.1\r\nHost: localhost\r\n\r\n", mp_obj_str_get_str(host_path));
|
||||
} else {
|
||||
vstr_printf(vstr, "GET %s HTTP/1.1\r\nHost: %s\r\n\r\n", mp_obj_str_get_str(host_path), mp_obj_str_get_str(host_name));
|
||||
}
|
||||
const char *query = vstr_str(vstr);
|
||||
|
||||
// send query
|
||||
|
@ -173,24 +182,49 @@ mp_obj_t pyb_wlan_http_get(mp_obj_t host_name, mp_obj_t host_path) {
|
|||
extern void SpiIntGPIOHandler(void);
|
||||
SpiIntGPIOHandler();
|
||||
*/
|
||||
//printf("sending %d bytes\n", strlen(query + sent));
|
||||
ret = send(sd, query + sent, strlen(query + sent), 0);
|
||||
//printf("sent %d bytes\n", ret);
|
||||
|
||||
// do a select() call on this socket
|
||||
timeval timeout;
|
||||
fd_set fd_write;
|
||||
|
||||
FD_ZERO(&fd_write);
|
||||
FD_SET(sd, &fd_write);
|
||||
|
||||
timeout.tv_sec = 1;
|
||||
timeout.tv_usec = 0;
|
||||
|
||||
printf("send select\n");
|
||||
int s = select(sd + 1, NULL, &fd_write, NULL, &timeout);
|
||||
printf("send select returned %d\n", s);
|
||||
if (s < 0) {
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "select failed %d", s));
|
||||
} else if (s == 0) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "send not ready"));
|
||||
}
|
||||
|
||||
printf("sending %d bytes\n", strlen(query + sent));
|
||||
int ret = send(sd, query + sent, strlen(query + sent), 0);
|
||||
printf("sent %d bytes\n", ret);
|
||||
if (ret < 0) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "send failed"));
|
||||
}
|
||||
|
||||
if (ret > strlen(query + sent)) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "send sent too much"));
|
||||
}
|
||||
sent += ret;
|
||||
|
||||
//HAL_Delay(200);
|
||||
}
|
||||
}
|
||||
|
||||
//printf("send seemed to work!\n");
|
||||
printf("send seemed to work!\n");
|
||||
//HAL_Delay(5000);
|
||||
|
||||
// receive reply
|
||||
mp_obj_t mp_ret = mp_const_none;
|
||||
{
|
||||
//printf("doing receive\n");
|
||||
printf("doing receive\n");
|
||||
char buf[64];
|
||||
vstr_reset(vstr);
|
||||
|
||||
|
@ -202,20 +236,26 @@ mp_obj_t pyb_wlan_http_get(mp_obj_t host_name, mp_obj_t host_path) {
|
|||
memset(&fd_read, 0, sizeof(fd_read));
|
||||
FD_SET(sd, &fd_read);
|
||||
|
||||
timeout.tv_sec = 0;
|
||||
timeout.tv_usec = 500000; // 500 millisec
|
||||
timeout.tv_sec = 1;
|
||||
timeout.tv_usec = 0;
|
||||
|
||||
int s = select(sd+1, &fd_read, NULL, NULL, &timeout);
|
||||
if (s == 0) {
|
||||
printf("recv select\n");
|
||||
int s = select(sd + 1, &fd_read, NULL, NULL, &timeout);
|
||||
printf("recv select done %d\n", s);
|
||||
if (s < 0) {
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "select failed %d", s));
|
||||
} else if (s == 0) {
|
||||
// no data available
|
||||
printf("no data!\n");
|
||||
break;
|
||||
}
|
||||
|
||||
// read data
|
||||
ret = recv(sd, buf, 64, 0);
|
||||
if (ret < 0) {
|
||||
if (ret <= 0) {
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "recv failed %d", ret));
|
||||
}
|
||||
printf("recv data: %.*s\n", ret, buf);
|
||||
vstr_add_strn(vstr, buf, ret);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue