From 6f27863ae5c4cda1b587b67c30364fa5700e7d95 Mon Sep 17 00:00:00 2001 From: Mimmo La Fauci Date: Fri, 8 Jun 2012 18:56:47 +0200 Subject: [PATCH] Added function to get firmware version --- WiFi/WiFi.cpp | 5 +++++ WiFi/WiFi.h | 6 ++++++ WiFi/utility/spi_drv.cpp | 13 ++++++++----- WiFi/utility/wifi_drv.cpp | 21 +++++++++++++++++++++ WiFi/utility/wifi_drv.h | 11 +++++++++++ WiFi/utility/wifi_spi.h | 1 + 6 files changed, 52 insertions(+), 5 deletions(-) diff --git a/WiFi/WiFi.cpp b/WiFi/WiFi.cpp index fd45e9689..c0cb0016d 100755 --- a/WiFi/WiFi.cpp +++ b/WiFi/WiFi.cpp @@ -34,6 +34,11 @@ uint8_t WiFiClass::getSocket() return NO_SOCKET_AVAIL; } +char* WiFiClass::firmwareVersion() +{ + return WiFiDrv::getFwVersion(); +} + int WiFiClass::begin(char* ssid) { uint8_t status = WL_IDLE_STATUS; diff --git a/WiFi/WiFi.h b/WiFi/WiFi.h index 501780b3f..9a86701a0 100755 --- a/WiFi/WiFi.h +++ b/WiFi/WiFi.h @@ -28,6 +28,12 @@ public: */ static uint8_t getSocket(); + /* + * Get firmware version + */ + static char* firmwareVersion(); + + /* Start Wifi connection for OPEN networks * * param ssid: Pointer to the SSID string. diff --git a/WiFi/utility/spi_drv.cpp b/WiFi/utility/spi_drv.cpp index ceef832c0..fb792bcd1 100644 --- a/WiFi/utility/spi_drv.cpp +++ b/WiFi/utility/spi_drv.cpp @@ -7,11 +7,12 @@ extern "C" { #include "debug.h" } -#define DATAOUT 11//MOSI -#define DATAIN 12//MISO -#define SPICLOCK 13//sck -#define SLAVESELECT 10//ss -#define SLAVEREADY 3 +#define DATAOUT 11 // MOSI +#define DATAIN 12 // MISO +#define SPICLOCK 13 // sck +#define SLAVESELECT 10 // ss +#define SLAVEREADY 3 // handshake pin +#define WIFILED 9 // led on wifi shield #define DELAY_100NS do { asm volatile("nop"); }while(0); #define DELAY_SPI(X) { int ii=0; do { asm volatile("nop"); }while(++ii0); } +char* WiFiDrv::getFwVersion() +{ + WAIT_FOR_SLAVE_SELECT(); + // Send Command + SpiDrv::sendCmd(GET_FW_VERSION_CMD, PARAM_NUMS_0); + + //Wait the reply elaboration + SpiDrv::waitForSlaveReady(); + + // Wait for reply + uint8_t _dataLen = 0; + if (!SpiDrv::waitResponseCmd(GET_FW_VERSION_CMD, PARAM_NUMS_1, (uint8_t*)fwVersion, &_dataLen)) + { + WARN("error waitResponse"); + } + SpiDrv::spiSlaveDeselect(); + return fwVersion; +} + WiFiDrv wiFiDrv; diff --git a/WiFi/utility/wifi_drv.h b/WiFi/utility/wifi_drv.h index 37563cba6..c4f04dbe7 100644 --- a/WiFi/utility/wifi_drv.h +++ b/WiFi/utility/wifi_drv.h @@ -9,6 +9,8 @@ #define KEY_IDX_LEN 1 // 5 secs of delay to have the connection established #define WL_DELAY_START_CONNECTION 5000 +// firmware version string length +#define WL_FW_VER_LENGTH 6 class WiFiDrv { @@ -18,6 +20,9 @@ private: static int32_t _networkRssi[WL_NETWORKS_LIST_MAXNUM]; static uint8_t _networkEncr[WL_NETWORKS_LIST_MAXNUM]; + // firmware version string in the format a.b.c + static char fwVersion[WL_FW_VER_LENGTH]; + // settings of current selected network static char _ssid[WL_SSID_MAX_LENGTH]; static uint8_t _bssid[WL_MAC_ADDR_LENGTH]; @@ -201,6 +206,12 @@ public: */ static int getHostByName(const char* aHostname, IPAddress& aResult); + /* + * Get the firmware version + * result: version as string with this format a.b.c + */ + static char* getFwVersion(); + }; extern WiFiDrv wiFiDrv; diff --git a/WiFi/utility/wifi_spi.h b/WiFi/utility/wifi_spi.h index cd3fab7ce..bf479e2ec 100644 --- a/WiFi/utility/wifi_spi.h +++ b/WiFi/utility/wifi_spi.h @@ -48,6 +48,7 @@ enum { REQ_HOST_BY_NAME_CMD= 0x34, GET_HOST_BY_NAME_CMD= 0x35, START_SCAN_NETWORKS = 0x36, + GET_FW_VERSION_CMD = 0x37, // All command with DATA_FLAG 0x40 send a 16bit Len