add P4 & P5
This commit is contained in:
372
P5_SETR2/LibWIFI/Inc/es_wifi.h
Normal file
372
P5_SETR2/LibWIFI/Inc/es_wifi.h
Normal file
@@ -0,0 +1,372 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file es-wifi.h
|
||||
* @author MCD Application Team
|
||||
* @brief header file for the es-wifi module.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2017 STMicroelectronics International N.V.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted, provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistribution of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of other
|
||||
* contributors to this software may be used to endorse or promote products
|
||||
* derived from this software without specific written permission.
|
||||
* 4. This software, including modifications and/or derivative works of this
|
||||
* software, must execute solely and exclusively on microcontroller or
|
||||
* microprocessor devices manufactured by or for STMicroelectronics.
|
||||
* 5. Redistribution and use of this software other than as permitted under
|
||||
* this license is void and will automatically terminate your rights under
|
||||
* this license.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
|
||||
* RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
|
||||
* SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __ES_WIFI_H
|
||||
#define __ES_WIFI_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stdint.h"
|
||||
#include "string.h"
|
||||
#include "stdbool.h"
|
||||
#include "stdio.h"
|
||||
#include "es_wifi_conf.h"
|
||||
|
||||
/* Exported Constants --------------------------------------------------------*/
|
||||
#define ES_WIFI_PAYLOAD_SIZE 1200
|
||||
/* Exported macro-------------------------------------------------------------*/
|
||||
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||
|
||||
typedef int8_t (*IO_Init_Func)(uint16_t );
|
||||
typedef int8_t (*IO_DeInit_Func)( void);
|
||||
typedef void (*IO_Delay_Func)(uint32_t);
|
||||
typedef int16_t (*IO_Send_Func)( uint8_t *, uint16_t len, uint32_t);
|
||||
typedef int16_t (*IO_Receive_Func)(uint8_t *, uint16_t len, uint32_t);
|
||||
|
||||
|
||||
/* Exported typedef ----------------------------------------------------------*/
|
||||
typedef enum {
|
||||
ES_WIFI_INIT = 0,
|
||||
ES_WIFI_RESET = 1
|
||||
}
|
||||
ES_WIFI_InitMode_t;
|
||||
|
||||
|
||||
typedef enum {
|
||||
ES_WIFI_STATUS_OK = 0,
|
||||
ES_WIFI_STATUS_REQ_DATA_STAGE = 1,
|
||||
ES_WIFI_STATUS_ERROR = 2,
|
||||
ES_WIFI_STATUS_TIMEOUT = 3,
|
||||
ES_WIFI_STATUS_IO_ERROR = 4,
|
||||
ES_WIFI_STATUS_UNEXPECTED_CLOSED_SOCKET = 5,
|
||||
ES_WIFI_STATUS_MODULE_CRASH = 6
|
||||
} ES_WIFI_Status_t;
|
||||
|
||||
#define ES_WIFI_ERROR_SPI_FAILED -1
|
||||
#define ES_WIFI_ERROR_WAITING_DRDY_RISING -2
|
||||
#define ES_WIFI_ERROR_WAITING_DRDY_FALLING -3
|
||||
#define ES_WIFI_ERROR_STUFFING_FOREVER -4
|
||||
#define ES_WIFI_ERROR_SPI_INIT -5
|
||||
|
||||
typedef enum {
|
||||
ES_WIFI_MODE_SINGLE = 0,
|
||||
ES_WIFI_MODE_MULTI = 1,
|
||||
} ES_WIFI_ConnMode_t;
|
||||
|
||||
typedef enum {
|
||||
ES_WIFI_TCP_CONNECTION = 0,
|
||||
ES_WIFI_UDP_CONNECTION = 1,
|
||||
ES_WIFI_UDP_LITE_CONNECTION = 2,
|
||||
ES_WIFI_TCP_SSL_CONNECTION = 3,
|
||||
ES_WIFI_MQTT_CONNECTION = 4,
|
||||
} ES_WIFI_ConnType_t;
|
||||
|
||||
/* Security settings for wifi network */
|
||||
typedef enum {
|
||||
ES_WIFI_SEC_OPEN = 0x00, /*!< Wifi is open */
|
||||
ES_WIFI_SEC_WEP = 0x01, /*!< Wired Equivalent Privacy option for wifi security. \note This mode can't be used when setting up ES_WIFI wifi */
|
||||
ES_WIFI_SEC_WPA = 0x02, /*!< Wi-Fi Protected Access */
|
||||
ES_WIFI_SEC_WPA2 = 0x03, /*!< Wi-Fi Protected Access 2 */
|
||||
ES_WIFI_SEC_WPA_WPA2= 0x04, /*!< Wi-Fi Protected Access with both modes */
|
||||
ES_WIFI_SEC_WPA2_TKIP= 0x05, /*!< Wi-Fi Protected Access with both modes */
|
||||
ES_WIFI_SEC_UNKNOWN = 0xFF, /*!< Wi-Fi Unknown Security mode */
|
||||
} ES_WIFI_SecurityType_t;
|
||||
|
||||
typedef enum {
|
||||
ES_WIFI_IPV4 = 0x00,
|
||||
ES_WIFI_IPV6 = 0x01,
|
||||
} ES_WIFI_IPVer_t;
|
||||
|
||||
typedef enum {
|
||||
ES_WIFI_AP_NONE = 0x00,
|
||||
ES_WIFI_AP_ASSIGNED = 0x01,
|
||||
ES_WIFI_AP_JOINED = 0x02,
|
||||
ES_WIFI_AP_ERROR = 0xFF,
|
||||
} ES_WIFI_APState_t;
|
||||
|
||||
typedef enum {
|
||||
ES_WIFI_FUNCTION_TLS = 0x00,
|
||||
ES_WIFI_FUNCTION_AWS = 0x01,
|
||||
} ES_WIFI_CredsFunction_t;
|
||||
|
||||
//FIXME should be the multiple read/write slot ??
|
||||
#define ES_WIFI_TLS_MULTIPLE_WRITE_SLOT 0
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t Port;
|
||||
uint32_t BaudRate;
|
||||
uint32_t DataWidth;
|
||||
uint32_t Parity;
|
||||
uint32_t StopBits;
|
||||
uint32_t Mode;
|
||||
} ES_WIFI_UARTConfig_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t Configuration;
|
||||
uint32_t WPSPin;
|
||||
uint32_t VID;
|
||||
uint32_t PID;
|
||||
uint8_t MAC[6];
|
||||
uint8_t AP_IPAddress[4];
|
||||
uint32_t PS_Mode;
|
||||
uint32_t RadioMode;
|
||||
uint32_t CurrentBeacon;
|
||||
uint32_t PrevBeacon;
|
||||
uint32_t ProductName;
|
||||
} ES_WIFI_SystemConfig_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t* Address; /*!< Pointer to domain or IP to ping */
|
||||
uint32_t Time; /*!< Time in milliseconds needed for pinging */
|
||||
uint8_t Success; /*!< Status indicates if ping was successful */
|
||||
} ES_WIFI_Ping_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t SSID[ES_WIFI_MAX_SSID_NAME_SIZE + 1]; /*!< Service Set Identifier value.Wi-Fi spot name */
|
||||
ES_WIFI_SecurityType_t Security; /*!< Security of Wi-Fi spot. */
|
||||
int16_t RSSI; /*!< Signal strength of Wi-Fi spot */
|
||||
uint8_t MAC[6]; /*!< MAC address of spot */
|
||||
uint8_t Channel; /*!< Wi-Fi channel */
|
||||
} ES_WIFI_AP_t;
|
||||
|
||||
/* Access point configuration */
|
||||
typedef struct {
|
||||
uint8_t SSID[ES_WIFI_MAX_SSID_NAME_SIZE + 1]; /*!< Network public name for ESP AP mode */
|
||||
uint8_t Pass[ES_WIFI_MAX_PSWD_NAME_SIZE + 1]; /*!< Network password for ESP AP mode */
|
||||
ES_WIFI_SecurityType_t Security; /*!< Security of Wi-Fi spot. This parameter can be a value of \ref ESP8266_Ecn_t enumeration */
|
||||
uint8_t Channel; /*!< Channel Wi-Fi is operating at */
|
||||
uint8_t MaxConnections; /*!< Max number of stations that are allowed to connect to ESP AP, between 1 and 4 */
|
||||
uint8_t Hidden; /*!< Set to 1 if network is hidden (not broadcast) or zero if noz */
|
||||
} ES_WIFI_APConfig_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t SSID[ES_WIFI_MAX_SSID_NAME_SIZE + 1]; /*!< Network public name for ESP AP mode */
|
||||
uint8_t IP_Addr[4]; /*!< IP Address */
|
||||
uint8_t MAC_Addr[6]; /*!< MAC address */
|
||||
} ES_WIFI_APSettings_t;
|
||||
|
||||
typedef struct {
|
||||
ES_WIFI_AP_t AP[ES_WIFI_MAX_DETECTED_AP];
|
||||
uint8_t nbr;
|
||||
} ES_WIFI_APs_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t SSID[ES_WIFI_MAX_SSID_NAME_SIZE + 1];
|
||||
uint8_t pswd[ES_WIFI_MAX_PSWD_NAME_SIZE + 1];
|
||||
ES_WIFI_SecurityType_t Security;
|
||||
uint8_t DHCP_IsEnabled;
|
||||
uint8_t JoinRetries;
|
||||
uint8_t IsConnected;
|
||||
uint8_t AutoConnect;
|
||||
ES_WIFI_IPVer_t IP_Ver;
|
||||
uint8_t IP_Addr[4];
|
||||
uint8_t IP_Mask[4];
|
||||
uint8_t Gateway_Addr[4];
|
||||
uint8_t DNS1[4];
|
||||
uint8_t DNS2[4];
|
||||
} ES_WIFI_Network_t;
|
||||
|
||||
typedef struct {
|
||||
ES_WIFI_ConnType_t Protocol;
|
||||
uint8_t Local_IP_Addr[4];
|
||||
uint16_t Local_Port;
|
||||
uint8_t Remote_IP_Addr[4];
|
||||
uint16_t Remote_Port;
|
||||
uint8_t TCP_Server;
|
||||
uint8_t UDP_Server;
|
||||
uint8_t TCP_Backlogs;
|
||||
uint8_t Accept_Loop;
|
||||
uint8_t Read_Mode;
|
||||
} ES_WIFI_Transport_t;
|
||||
|
||||
#if (ES_WIFI_USE_AWS == 1)
|
||||
typedef struct {
|
||||
ES_WIFI_ConnType_t Type;
|
||||
uint8_t Number;
|
||||
uint16_t RemotePort;
|
||||
uint8_t RemoteIP[4];
|
||||
uint8_t *PublishTopic;
|
||||
uint8_t *SubscribeTopic;
|
||||
uint8_t *ClientID;
|
||||
uint8_t MQTTMode;
|
||||
} ES_WIFI_AWS_Conn_t;
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
ES_WIFI_ConnType_t Type;
|
||||
uint8_t Number;
|
||||
uint16_t RemotePort;
|
||||
uint16_t LocalPort;
|
||||
uint8_t RemoteIP[4];
|
||||
char* Name;
|
||||
uint8_t Backlog;
|
||||
} ES_WIFI_Conn_t;
|
||||
|
||||
typedef struct {
|
||||
IO_Init_Func IO_Init;
|
||||
IO_DeInit_Func IO_DeInit;
|
||||
IO_Delay_Func IO_Delay;
|
||||
IO_Send_Func IO_Send;
|
||||
IO_Receive_Func IO_Receive;
|
||||
} ES_WIFI_IO_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t Product_ID[ES_WIFI_PRODUCT_ID_SIZE];
|
||||
uint8_t FW_Rev[ES_WIFI_FW_REV_SIZE];
|
||||
uint8_t API_Rev[ES_WIFI_API_REV_SIZE];
|
||||
uint8_t Stack_Rev[ES_WIFI_STACK_REV_SIZE];
|
||||
uint8_t RTOS_Rev[ES_WIFI_RTOS_REV_SIZE];
|
||||
uint8_t Product_Name[ES_WIFI_PRODUCT_NAME_SIZE];
|
||||
uint32_t CPU_Clock;
|
||||
ES_WIFI_SecurityType_t Security;
|
||||
ES_WIFI_Network_t NetSettings;
|
||||
ES_WIFI_APSettings_t APSettings;
|
||||
ES_WIFI_IO_t fops;
|
||||
uint8_t CmdData[ES_WIFI_DATA_SIZE];
|
||||
uint32_t Timeout;
|
||||
uint32_t BufferSize;
|
||||
} ES_WIFIObject_t;
|
||||
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
ES_WIFI_Status_t ES_WIFI_Init(ES_WIFIObject_t *Obj);
|
||||
ES_WIFI_Status_t ES_WIFI_SetTimeout(ES_WIFIObject_t *Obj, uint32_t Timeout);
|
||||
ES_WIFI_Status_t ES_WIFI_ListAccessPoints(ES_WIFIObject_t *Obj, ES_WIFI_APs_t *APs);
|
||||
ES_WIFI_Status_t ES_WIFI_Connect(ES_WIFIObject_t *Obj, const char* SSID, const char* Password,
|
||||
ES_WIFI_SecurityType_t SecType);
|
||||
ES_WIFI_Status_t ES_WIFI_Disconnect(ES_WIFIObject_t *Obj);
|
||||
uint8_t ES_WIFI_IsConnected(ES_WIFIObject_t *Obj);
|
||||
ES_WIFI_Status_t ES_WIFI_GetNetworkSettings(ES_WIFIObject_t *Obj);
|
||||
ES_WIFI_Status_t ES_WIFI_GetMACAddress(ES_WIFIObject_t *Obj, uint8_t *mac);
|
||||
ES_WIFI_Status_t ES_WIFI_GetIPAddress(ES_WIFIObject_t *Obj, uint8_t *ipaddr);
|
||||
ES_WIFI_Status_t ES_WIFI_GetProductID(ES_WIFIObject_t *Obj, uint8_t *productID);
|
||||
ES_WIFI_Status_t ES_WIFI_GetFWRevID(ES_WIFIObject_t *Obj, uint8_t *FWRev);
|
||||
ES_WIFI_Status_t ES_WIFI_GetRTOSRev(ES_WIFIObject_t *Obj, uint8_t *RTOSRev);
|
||||
ES_WIFI_Status_t ES_WIFI_GetProductName(ES_WIFIObject_t *Obj, uint8_t *productName);
|
||||
ES_WIFI_Status_t ES_WIFI_GetAPIRev(ES_WIFIObject_t *Obj, uint8_t *APIRev);
|
||||
ES_WIFI_Status_t ES_WIFI_GetStackRev(ES_WIFIObject_t *Obj, uint8_t *StackRev);
|
||||
|
||||
|
||||
ES_WIFI_Status_t ES_WIFI_SetMACAddress(ES_WIFIObject_t *Obj, uint8_t *mac);
|
||||
ES_WIFI_Status_t ES_WIFI_ResetToFactoryDefault(ES_WIFIObject_t *Obj);
|
||||
ES_WIFI_Status_t ES_WIFI_ResetModule(ES_WIFIObject_t *Obj);
|
||||
ES_WIFI_Status_t ES_WIFI_HardResetModule(ES_WIFIObject_t *Obj);
|
||||
ES_WIFI_Status_t ES_WIFI_SetProductName(ES_WIFIObject_t *Obj, uint8_t *ProductName);
|
||||
#if (ES_WIFI_USE_PING == 1)
|
||||
ES_WIFI_Status_t ES_WIFI_Ping(ES_WIFIObject_t *Obj, uint8_t *address, uint16_t count, uint16_t interval_ms, int32_t res[]);
|
||||
#endif
|
||||
ES_WIFI_Status_t ES_WIFI_DNS_LookUp(ES_WIFIObject_t *Obj, const char *url, uint8_t *ipaddress);
|
||||
ES_WIFI_Status_t ES_WIFI_StartClientConnection(ES_WIFIObject_t *Obj, ES_WIFI_Conn_t *conn);
|
||||
ES_WIFI_Status_t ES_WIFI_StopClientConnection(ES_WIFIObject_t *Obj, ES_WIFI_Conn_t *conn);
|
||||
#if (ES_WIFI_USE_AWS == 1)
|
||||
ES_WIFI_Status_t ES_WIFI_StartAWSClientConnection(ES_WIFIObject_t *Obj, ES_WIFI_AWS_Conn_t *conn);
|
||||
#endif
|
||||
ES_WIFI_Status_t ES_WIFI_StartServerSingleConn(ES_WIFIObject_t *Obj, ES_WIFI_Conn_t *conn);
|
||||
ES_WIFI_Status_t ES_WIFI_WaitServerConnection(ES_WIFIObject_t *Obj,uint32_t Timeout,ES_WIFI_Conn_t *);
|
||||
ES_WIFI_Status_t ES_WIFI_CloseServerConnection(ES_WIFIObject_t *Obj,int socket);
|
||||
ES_WIFI_Status_t ES_WIFI_StopServerSingleConn(ES_WIFIObject_t *Obj, int socket);
|
||||
|
||||
|
||||
ES_WIFI_Status_t ES_WIFI_StartServerMultiConn(ES_WIFIObject_t *Obj, ES_WIFI_Conn_t *conn);
|
||||
ES_WIFI_Status_t ES_WIFI_StopServerMultiConn(ES_WIFIObject_t *Obj,ES_WIFI_Conn_t *conn);
|
||||
ES_WIFI_Status_t ES_WIFI_SendData(ES_WIFIObject_t *Obj, uint8_t Socket, uint8_t *pdata, uint16_t Reqlen , uint16_t *SentLen, uint32_t Timeout);
|
||||
ES_WIFI_Status_t ES_WIFI_SendDataTo(ES_WIFIObject_t *Obj, uint8_t Socket, uint8_t *pdata, uint16_t Reqlen , uint16_t *SentLen, uint32_t Timeout, uint8_t *IPaddr, uint16_t Port);
|
||||
ES_WIFI_Status_t ES_WIFI_ReceiveData(ES_WIFIObject_t *Obj, uint8_t Socket, uint8_t *pdata, uint16_t Reqlen, uint16_t *Receivedlen, uint32_t Timeout);
|
||||
ES_WIFI_Status_t ES_WIFI_ReceiveDataFrom(ES_WIFIObject_t *Obj, uint8_t Socket, uint8_t *pdata, uint16_t Reqlen, uint16_t *Receivedlen, uint32_t Timeout, uint8_t *IPaddr, uint16_t *pPort);
|
||||
ES_WIFI_Status_t ES_WIFI_ActivateAP(ES_WIFIObject_t *Obj, ES_WIFI_APConfig_t *ApConfig);
|
||||
ES_WIFI_APState_t ES_WIFI_WaitAPStateChange(ES_WIFIObject_t *Obj);
|
||||
|
||||
#if (ES_WIFI_USE_FIRMWAREUPDATE == 1)
|
||||
ES_WIFI_Status_t ES_WIFI_OTA_Upgrade(ES_WIFIObject_t *Obj, uint8_t *link);
|
||||
#endif
|
||||
|
||||
#if (ES_WIFI_USE_UART == 1)
|
||||
ES_WIFI_Status_t ES_WIFI_SetUARTBaudRate(ES_WIFIObject_t *Obj, uint16_t BaudRate);
|
||||
ES_WIFI_Status_t ES_WIFI_GetUARTConfig(ES_WIFIObject_t *Obj, ES_WIFI_UARTConfig_t *pconf);
|
||||
#endif
|
||||
|
||||
ES_WIFI_Status_t ES_WIFI_GetSystemConfig(ES_WIFIObject_t *Obj, ES_WIFI_SystemConfig_t *pconf);
|
||||
|
||||
ES_WIFI_Status_t ES_WIFI_RegisterBusIO(ES_WIFIObject_t *Obj, IO_Init_Func IO_Init,
|
||||
IO_DeInit_Func IO_DeInit,
|
||||
IO_Delay_Func IO_Delay,
|
||||
IO_Send_Func IO_Send,
|
||||
IO_Receive_Func IO_Receive);
|
||||
|
||||
ES_WIFI_Status_t ES_WIFI_StoreCreds( ES_WIFIObject_t *Obj,
|
||||
ES_WIFI_CredsFunction_t credsFunction, uint8_t credSet,
|
||||
uint8_t* ca, uint16_t caLength,
|
||||
uint8_t* certificate, uint16_t certificateLength,
|
||||
uint8_t* key, uint16_t keyLength );
|
||||
|
||||
ES_WIFI_Status_t ES_WIFI_StoreCA( ES_WIFIObject_t *Obj,
|
||||
ES_WIFI_CredsFunction_t credsFunction,
|
||||
uint8_t credSet,
|
||||
uint8_t* ca,
|
||||
uint16_t caLength );
|
||||
|
||||
ES_WIFI_Status_t ES_WIFI_StoreCertificate( ES_WIFIObject_t *Obj,
|
||||
ES_WIFI_CredsFunction_t credsFunction,
|
||||
uint8_t credSet,
|
||||
uint8_t* certificate,
|
||||
uint16_t certificateLength );
|
||||
|
||||
ES_WIFI_Status_t ES_WIFI_StoreKey( ES_WIFIObject_t *Obj,
|
||||
ES_WIFI_CredsFunction_t credsFunction,
|
||||
uint8_t credSet,
|
||||
uint8_t* key,
|
||||
uint16_t keyLength );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /*__ES_WIFI_H*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
80
P5_SETR2/LibWIFI/Inc/es_wifi_conf.h
Normal file
80
P5_SETR2/LibWIFI/Inc/es_wifi_conf.h
Normal file
@@ -0,0 +1,80 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file es_wifi_conf.h
|
||||
* @author MCD Application Team
|
||||
* @brief ES-WIFI configuration.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2017 STMicroelectronics International N.V.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef ES_WIFI_CONF_H
|
||||
#define ES_WIFI_CONF_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//#define WIFI_USE_CMSIS_OS
|
||||
|
||||
#ifdef WIFI_USE_CMSIS_OS
|
||||
#include "cmsis_os.h"
|
||||
|
||||
extern osMutexId es_wifi_mutex;
|
||||
|
||||
#define LOCK_SPI() osMutexWait(spi_mutex, 0)
|
||||
#define UNLOCK_SPI() osMutexRelease(spi_mutex)
|
||||
#define LOCK_WIFI() osMutexWait(es_wifi_mutex, 0)
|
||||
#define UNLOCK_WIFI() osMutexRelease(es_wifi_mutex)
|
||||
#define SEM_SIGNAL(a) osSemaphoreRelease(a)
|
||||
#define SEM_WAIT(a,timeout) osSemaphoreWait(a,timeout)
|
||||
#define SPI_INTERFACE_PRIO configMAX_SYSCALL_INTERRUPT_PRIORITY
|
||||
#else
|
||||
|
||||
#define LOCK_WIFI()
|
||||
#define UNLOCK_WIFI()
|
||||
#define LOCK_SPI()
|
||||
#define UNLOCK_SPI()
|
||||
#define SEM_SIGNAL(a)
|
||||
#define SPI_INTERFACE_PRIO 0
|
||||
#endif
|
||||
|
||||
#define ES_WIFI_MAX_SSID_NAME_SIZE 32
|
||||
#define ES_WIFI_MAX_PSWD_NAME_SIZE 32
|
||||
#define ES_WIFI_PRODUCT_ID_SIZE 32
|
||||
#define ES_WIFI_PRODUCT_NAME_SIZE 32
|
||||
#define ES_WIFI_FW_REV_SIZE 24
|
||||
#define ES_WIFI_API_REV_SIZE 16
|
||||
#define ES_WIFI_STACK_REV_SIZE 16
|
||||
#define ES_WIFI_RTOS_REV_SIZE 16
|
||||
|
||||
#define ES_WIFI_DATA_SIZE 2000 /*Increased from 1400 to fit scan result.*/
|
||||
#define ES_WIFI_MAX_DETECTED_AP 10
|
||||
|
||||
#define ES_WIFI_TIMEOUT 30000
|
||||
|
||||
#define ES_WIFI_USE_PING 1
|
||||
#define ES_WIFI_USE_AWS 0
|
||||
#define ES_WIFI_USE_FIRMWAREUPDATE 0
|
||||
#define ES_WIFI_USE_WPS 0
|
||||
|
||||
#define ES_WIFI_USE_SPI 1
|
||||
#define ES_WIFI_USE_UART (!ES_WIFI_USE_SPI)
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* ES_WIFI_CONF_H */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
67
P5_SETR2/LibWIFI/Inc/es_wifi_io.h
Normal file
67
P5_SETR2/LibWIFI/Inc/es_wifi_io.h
Normal file
@@ -0,0 +1,67 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file es_wifi_io.h
|
||||
* @author MCD Application Team
|
||||
* @brief This file contains the functions prototypes for es_wifi IO operations.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2017 STMicroelectronics International N.V.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef WIFI_IO_H
|
||||
#define WIFI_IO_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32l4xx_hal.h"
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
#define WIFI_RESET_MODULE() do{\
|
||||
HAL_GPIO_WritePin(GPIOE, GPIO_PIN_8, GPIO_PIN_RESET);\
|
||||
HAL_Delay(10);\
|
||||
HAL_GPIO_WritePin(GPIOE, GPIO_PIN_8, GPIO_PIN_SET);\
|
||||
HAL_Delay(500);\
|
||||
}while(0);
|
||||
|
||||
|
||||
#define WIFI_ENABLE_NSS() do{ \
|
||||
HAL_GPIO_WritePin( GPIOE, GPIO_PIN_0, GPIO_PIN_RESET );\
|
||||
}while(0);
|
||||
|
||||
#define WIFI_DISABLE_NSS() do{ \
|
||||
HAL_GPIO_WritePin( GPIOE, GPIO_PIN_0, GPIO_PIN_SET );\
|
||||
}while(0);
|
||||
|
||||
#define WIFI_IS_CMDDATA_READY() (HAL_GPIO_ReadPin(GPIOE, GPIO_PIN_1) == GPIO_PIN_SET)
|
||||
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
void SPI_WIFI_MspInit(SPI_HandleTypeDef* hspi);
|
||||
int8_t SPI_WIFI_DeInit(void);
|
||||
int8_t SPI_WIFI_Init(uint16_t mode);
|
||||
int8_t SPI_WIFI_ResetModule(void);
|
||||
int16_t SPI_WIFI_ReceiveData(uint8_t *pData, uint16_t len, uint32_t timeout);
|
||||
int16_t SPI_WIFI_SendData( uint8_t *pData, uint16_t len, uint32_t timeout);
|
||||
void SPI_WIFI_Delay(uint32_t Delay);
|
||||
void SPI_WIFI_ISR(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* WIFI_IO_H */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
168
P5_SETR2/LibWIFI/Inc/wifi.h
Normal file
168
P5_SETR2/LibWIFI/Inc/wifi.h
Normal file
@@ -0,0 +1,168 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file wifi.h
|
||||
* @author MCD Application Team
|
||||
* @brief This file contains the different WiFi core resources definitions.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2017 STMicroelectronics International N.V.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
#ifndef WIFI_H
|
||||
#define WIFI_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "es_wifi.h"
|
||||
#include "es_wifi_io.h"
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
#define WIFI_MAX_SSID_NAME 100
|
||||
#define WIFI_MAX_PSWD_NAME 100
|
||||
#define WIFI_MAX_APS 20
|
||||
#define WIFI_MAX_CONNECTIONS 4
|
||||
#define WIFI_MAX_MODULE_NAME 100
|
||||
#define WIFI_MAX_CONNECTED_STATIONS 2
|
||||
#define WIFI_MSG_JOINED 1
|
||||
#define WIFI_MSG_ASSIGNED 2
|
||||
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
typedef enum {
|
||||
WIFI_ECN_OPEN = 0x00,
|
||||
WIFI_ECN_WEP = 0x01,
|
||||
WIFI_ECN_WPA_PSK = 0x02,
|
||||
WIFI_ECN_WPA2_PSK = 0x03,
|
||||
WIFI_ECN_WPA_WPA2_PSK = 0x04,
|
||||
}WIFI_Ecn_t;
|
||||
|
||||
typedef enum {
|
||||
WIFI_TCP_PROTOCOL = 0,
|
||||
WIFI_UDP_PROTOCOL = 1,
|
||||
}WIFI_Protocol_t;
|
||||
|
||||
typedef enum {
|
||||
WIFI_SERVER = 0,
|
||||
WIFI_CLIENT = 1,
|
||||
}WIFI_Type_t;
|
||||
|
||||
typedef enum {
|
||||
WIFI_STATUS_OK = 0,
|
||||
WIFI_STATUS_ERROR = 1,
|
||||
WIFI_STATUS_NOT_SUPPORTED = 2,
|
||||
WIFI_STATUS_JOINED = 3,
|
||||
WIFI_STATUS_ASSIGNED = 4,
|
||||
WIFI_STATUS_TIMEOUT = 5,
|
||||
}WIFI_Status_t;
|
||||
|
||||
typedef struct {
|
||||
WIFI_Ecn_t Ecn; /*!< Security of Wi-Fi spot. This parameter has a value of \ref WIFI_Ecn_t enumeration */
|
||||
char SSID[WIFI_MAX_SSID_NAME + 1]; /*!< Service Set Identifier value. Wi-Fi spot name */
|
||||
int16_t RSSI; /*!< Signal strength of Wi-Fi spot */
|
||||
uint8_t MAC[6]; /*!< MAC address of spot */
|
||||
uint8_t Channel; /*!< Wi-Fi channel */
|
||||
uint8_t Offset; /*!< Frequency offset from base 2.4GHz in kHz */
|
||||
uint8_t Calibration; /*!< Frequency offset calibration */
|
||||
}WIFI_AP_t;
|
||||
|
||||
typedef struct {
|
||||
WIFI_AP_t ap[WIFI_MAX_APS];
|
||||
uint8_t count;
|
||||
} WIFI_APs_t;
|
||||
|
||||
|
||||
typedef struct {
|
||||
uint8_t Number; /*!< Connection number */
|
||||
uint16_t RemotePort; /*!< Remote PORT number */
|
||||
uint16_t LocalPort;
|
||||
uint8_t RemoteIP[4]; /*!< IP address of device */
|
||||
WIFI_Protocol_t Protocol; /*!< Connection type. Parameter is valid only if connection is made as client */
|
||||
uint32_t TotalBytesReceived; /*!< Number of bytes received in entire connection lifecycle */
|
||||
uint32_t TotalBytesSent; /*!< Number of bytes sent in entire connection lifecycle */
|
||||
uint8_t Active; /*!< Status if connection is active */
|
||||
uint8_t Client; /*!< Set to 1 if connection was made as client */
|
||||
} WIFI_Socket_t;
|
||||
|
||||
|
||||
typedef struct {
|
||||
uint8_t SSID[WIFI_MAX_SSID_NAME + 1];
|
||||
uint8_t PSWD[WIFI_MAX_PSWD_NAME + 1];
|
||||
uint8_t channel;
|
||||
WIFI_Ecn_t Ecn;
|
||||
} WIFI_APConfig_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t SSID[WIFI_MAX_SSID_NAME + 1]; /*!< Network public name for ESP AP mode */
|
||||
uint8_t IP_Addr[4]; /*!< IP Address */
|
||||
uint8_t MAC_Addr[6]; /*!< MAC address */
|
||||
} WIFI_APSettings_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t IsConnected;
|
||||
uint8_t IP_Addr[4];
|
||||
uint8_t IP_Mask[4];
|
||||
uint8_t Gateway_Addr[4];
|
||||
} WIFI_Conn_t;
|
||||
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
WIFI_Status_t WIFI_Init(void);
|
||||
WIFI_Status_t WIFI_ListAccessPoints(WIFI_APs_t *APs, uint8_t AP_MaxNbr);
|
||||
WIFI_Status_t WIFI_Connect(
|
||||
const char* SSID,
|
||||
const char* Password,
|
||||
WIFI_Ecn_t ecn);
|
||||
WIFI_Status_t WIFI_GetIP_Address(uint8_t *ipaddr);
|
||||
WIFI_Status_t WIFI_GetMAC_Address(uint8_t *mac);
|
||||
|
||||
WIFI_Status_t WIFI_Disconnect(void);
|
||||
WIFI_Status_t WIFI_ConfigureAP(
|
||||
uint8_t *ssid,
|
||||
uint8_t *pass,
|
||||
WIFI_Ecn_t ecn,
|
||||
uint8_t channel,
|
||||
uint8_t max_conn);
|
||||
|
||||
WIFI_Status_t WIFI_HandleAPEvents(WIFI_APSettings_t *setting);
|
||||
WIFI_Status_t WIFI_Ping(uint8_t *ipaddr, uint16_t count, uint16_t interval_ms,int32_t result[]);
|
||||
WIFI_Status_t WIFI_GetHostAddress(const char *location, uint8_t *ipaddr);
|
||||
WIFI_Status_t WIFI_OpenClientConnection(uint32_t socket, WIFI_Protocol_t type, const char *name, uint8_t *ipaddr, uint16_t port, uint16_t local_port);
|
||||
WIFI_Status_t WIFI_CloseClientConnection(uint32_t socket);
|
||||
|
||||
WIFI_Status_t WIFI_StartServer(uint32_t socket, WIFI_Protocol_t type, uint16_t backlog, const char *name, uint16_t port);
|
||||
WIFI_Status_t WIFI_WaitServerConnection(int socket,uint32_t Timeout,uint8_t *remoteipaddr, uint16_t *remoteport);
|
||||
WIFI_Status_t WIFI_CloseServerConnection(int socket);
|
||||
WIFI_Status_t WIFI_StopServer(uint32_t socket);
|
||||
|
||||
WIFI_Status_t WIFI_SendData(uint8_t socket, uint8_t *pdata, uint16_t Reqlen, uint16_t *SentDatalen, uint32_t Timeout);
|
||||
WIFI_Status_t WIFI_SendDataTo(uint8_t socket, uint8_t *pdata, uint16_t Reqlen, uint16_t *SentDatalen, uint32_t Timeout, uint8_t *ipaddr, uint16_t port);
|
||||
WIFI_Status_t WIFI_ReceiveData(uint8_t socket, uint8_t *pdata, uint16_t Reqlen, uint16_t *RcvDatalen, uint32_t Timeout);
|
||||
WIFI_Status_t WIFI_ReceiveDataFrom(uint8_t socket, uint8_t *pdata, uint16_t Reqlen, uint16_t *RcvDatalen, uint32_t Timeout, uint8_t *ipaddr, uint16_t *port);
|
||||
WIFI_Status_t WIFI_StartClient(void);
|
||||
WIFI_Status_t WIFI_StopClient(void);
|
||||
|
||||
WIFI_Status_t WIFI_SetOEMProperties(const char *name, uint8_t *Mac);
|
||||
WIFI_Status_t WIFI_ResetModule(void);
|
||||
WIFI_Status_t WIFI_SetModuleDefault(void);
|
||||
WIFI_Status_t WIFI_ModuleFirmwareUpdate(const char *url);
|
||||
WIFI_Status_t WIFI_GetModuleID(char *Id);
|
||||
WIFI_Status_t WIFI_GetModuleFwRevision(char *rev);
|
||||
WIFI_Status_t WIFI_GetModuleName(char *ModuleName);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* WIFI_H */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
2526
P5_SETR2/LibWIFI/Src/es_wifi.c
Normal file
2526
P5_SETR2/LibWIFI/Src/es_wifi.c
Normal file
File diff suppressed because it is too large
Load Diff
532
P5_SETR2/LibWIFI/Src/es_wifi_io.c
Normal file
532
P5_SETR2/LibWIFI/Src/es_wifi_io.c
Normal file
@@ -0,0 +1,532 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file es_wifi_io.c
|
||||
* @author MCD Application Team
|
||||
* @brief This file implements the IO operations to deal with the es-wifi
|
||||
* module. It mainly Inits and Deinits the SPI interface. Send and
|
||||
* receive data over it.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2017 STMicroelectronics International N.V.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "es_wifi.h"
|
||||
#include "es_wifi_io.h"
|
||||
#include <string.h>
|
||||
#include "es_wifi_conf.h"
|
||||
#include <core_cm4.h>
|
||||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
SPI_HandleTypeDef hspi;
|
||||
static int volatile spi_rx_event = 0;
|
||||
static int volatile spi_tx_event = 0;
|
||||
static int volatile cmddata_rdy_rising_event = 0;
|
||||
|
||||
#ifdef WIFI_USE_CMSIS_OS
|
||||
osMutexId es_wifi_mutex;
|
||||
osMutexDef(es_wifi_mutex);
|
||||
|
||||
static osMutexId spi_mutex;
|
||||
osMutexDef(spi_mutex);
|
||||
|
||||
static osSemaphoreId spi_rx_sem;
|
||||
osSemaphoreDef(spi_rx_sem);
|
||||
|
||||
static osSemaphoreId spi_tx_sem;
|
||||
osSemaphoreDef(spi_tx_sem);
|
||||
|
||||
static osSemaphoreId cmddata_rdy_rising_sem;
|
||||
osSemaphoreDef(cmddata_rdy_rising_sem);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
static int wait_cmddata_rdy_high(int timeout);
|
||||
static int wait_cmddata_rdy_rising_event(int timeout);
|
||||
static int wait_spi_tx_event(int timeout);
|
||||
static int wait_spi_rx_event(int timeout);
|
||||
static void SPI_WIFI_DelayUs(uint32_t);
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
/*******************************************************************************
|
||||
COM Driver Interface (SPI)
|
||||
*******************************************************************************/
|
||||
/**
|
||||
* @brief Initialize SPI MSP
|
||||
* @param hspi: SPI handle
|
||||
* @retval None
|
||||
*/
|
||||
void SPI_WIFI_MspInit(SPI_HandleTypeDef* hspi)
|
||||
{
|
||||
|
||||
GPIO_InitTypeDef GPIO_Init;
|
||||
|
||||
__HAL_RCC_SPI3_CLK_ENABLE();
|
||||
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOC_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOE_CLK_ENABLE();
|
||||
|
||||
/* configure Wake up pin */
|
||||
HAL_GPIO_WritePin(GPIOB,GPIO_PIN_13, GPIO_PIN_RESET );
|
||||
GPIO_Init.Pin = GPIO_PIN_13;
|
||||
GPIO_Init.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_Init.Pull = GPIO_NOPULL;
|
||||
GPIO_Init.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_Init );
|
||||
|
||||
/* configure Data ready pin */
|
||||
GPIO_Init.Pin = GPIO_PIN_1;
|
||||
GPIO_Init.Mode = GPIO_MODE_IT_RISING;
|
||||
GPIO_Init.Pull = GPIO_NOPULL;
|
||||
GPIO_Init.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(GPIOE, &GPIO_Init );
|
||||
|
||||
/* configure Reset pin */
|
||||
GPIO_Init.Pin = GPIO_PIN_8;
|
||||
GPIO_Init.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_Init.Pull = GPIO_NOPULL;
|
||||
GPIO_Init.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
GPIO_Init.Alternate = 0;
|
||||
HAL_GPIO_Init(GPIOE, &GPIO_Init );
|
||||
|
||||
/* configure SPI NSS pin pin */
|
||||
HAL_GPIO_WritePin( GPIOE , GPIO_PIN_0, GPIO_PIN_SET );
|
||||
GPIO_Init.Pin = GPIO_PIN_0;
|
||||
GPIO_Init.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_Init.Pull = GPIO_NOPULL;
|
||||
GPIO_Init.Speed = GPIO_SPEED_FREQ_MEDIUM;
|
||||
HAL_GPIO_Init( GPIOE, &GPIO_Init );
|
||||
|
||||
/* configure SPI CLK pin */
|
||||
GPIO_Init.Pin = GPIO_PIN_10;
|
||||
GPIO_Init.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_Init.Pull = GPIO_NOPULL;
|
||||
GPIO_Init.Speed = GPIO_SPEED_FREQ_MEDIUM;
|
||||
GPIO_Init.Alternate = GPIO_AF6_SPI3;
|
||||
HAL_GPIO_Init(GPIOC, &GPIO_Init );
|
||||
|
||||
/* configure SPI MOSI pin */
|
||||
GPIO_Init.Pin = GPIO_PIN_12;
|
||||
GPIO_Init.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_Init.Pull = GPIO_NOPULL;
|
||||
GPIO_Init.Speed = GPIO_SPEED_FREQ_MEDIUM;
|
||||
GPIO_Init.Alternate = GPIO_AF6_SPI3;
|
||||
HAL_GPIO_Init( GPIOC, &GPIO_Init );
|
||||
|
||||
/* configure SPI MISO pin */
|
||||
GPIO_Init.Pin = GPIO_PIN_11;
|
||||
GPIO_Init.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_Init.Pull = GPIO_PULLUP;
|
||||
GPIO_Init.Speed = GPIO_SPEED_FREQ_MEDIUM;
|
||||
GPIO_Init.Alternate = GPIO_AF6_SPI3;
|
||||
HAL_GPIO_Init( GPIOC,&GPIO_Init );
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initialize the SPI3
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
int8_t SPI_WIFI_Init(uint16_t mode)
|
||||
{
|
||||
int8_t rc=0;
|
||||
|
||||
if (mode == ES_WIFI_INIT)
|
||||
{
|
||||
hspi.Instance = SPI3;
|
||||
SPI_WIFI_MspInit(&hspi);
|
||||
|
||||
hspi.Init.Mode = SPI_MODE_MASTER;
|
||||
hspi.Init.Direction = SPI_DIRECTION_2LINES;
|
||||
hspi.Init.DataSize = SPI_DATASIZE_16BIT;
|
||||
hspi.Init.CLKPolarity = SPI_POLARITY_LOW;
|
||||
hspi.Init.CLKPhase = SPI_PHASE_1EDGE;
|
||||
hspi.Init.NSS = SPI_NSS_SOFT;
|
||||
hspi.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8; /* 80/8= 10MHz (Inventek WIFI module supports up to 20MHz)*/
|
||||
hspi.Init.FirstBit = SPI_FIRSTBIT_MSB;
|
||||
hspi.Init.TIMode = SPI_TIMODE_DISABLE;
|
||||
hspi.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
|
||||
hspi.Init.CRCPolynomial = 0;
|
||||
|
||||
if(HAL_SPI_Init( &hspi ) != HAL_OK)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Enable Interrupt for Data Ready pin , GPIO_PIN1 */
|
||||
HAL_NVIC_SetPriority((IRQn_Type)EXTI1_IRQn, SPI_INTERFACE_PRIO, 0x00);
|
||||
HAL_NVIC_EnableIRQ((IRQn_Type)EXTI1_IRQn);
|
||||
|
||||
/* Enable Interrupt for SPI tx and rx */
|
||||
HAL_NVIC_SetPriority((IRQn_Type)SPI3_IRQn, SPI_INTERFACE_PRIO, 0);
|
||||
HAL_NVIC_EnableIRQ((IRQn_Type)SPI3_IRQn);
|
||||
|
||||
#ifdef WIFI_USE_CMSIS_OS
|
||||
cmddata_rdy_rising_event=0;
|
||||
es_wifi_mutex = osMutexCreate(osMutex(es_wifi_mutex));
|
||||
spi_mutex = osMutexCreate(osMutex(spi_mutex));
|
||||
spi_rx_sem = osSemaphoreCreate(osSemaphore(spi_rx_sem) , 1 );
|
||||
spi_tx_sem = osSemaphoreCreate(osSemaphore(spi_tx_sem) , 1 );
|
||||
cmddata_rdy_rising_sem = osSemaphoreCreate(osSemaphore(cmddata_rdy_rising_sem) , 1 );
|
||||
/* take semaphore */
|
||||
SEM_WAIT(cmddata_rdy_rising_sem, 1);
|
||||
SEM_WAIT(spi_rx_sem, 1);
|
||||
SEM_WAIT(spi_tx_sem, 1);
|
||||
|
||||
#endif
|
||||
/* first call used for calibration */
|
||||
SPI_WIFI_DelayUs(10);
|
||||
}
|
||||
|
||||
rc= SPI_WIFI_ResetModule();
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
int8_t SPI_WIFI_ResetModule(void)
|
||||
{
|
||||
uint32_t tickstart = HAL_GetTick();
|
||||
uint8_t Prompt[6];
|
||||
uint8_t count = 0;
|
||||
HAL_StatusTypeDef Status;
|
||||
|
||||
WIFI_RESET_MODULE();
|
||||
WIFI_ENABLE_NSS();
|
||||
SPI_WIFI_DelayUs(15);
|
||||
|
||||
while (WIFI_IS_CMDDATA_READY())
|
||||
{
|
||||
Status = HAL_SPI_Receive(&hspi , &Prompt[count], 1, 0xFFFF);
|
||||
count += 2;
|
||||
if(((HAL_GetTick() - tickstart ) > 0xFFFF) || (Status != HAL_OK))
|
||||
{
|
||||
WIFI_DISABLE_NSS();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
WIFI_DISABLE_NSS();
|
||||
if((Prompt[0] != 0x15) ||(Prompt[1] != 0x15) ||(Prompt[2] != '\r')||
|
||||
(Prompt[3] != '\n') ||(Prompt[4] != '>') ||(Prompt[5] != ' '))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DeInitialize the SPI
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
int8_t SPI_WIFI_DeInit(void)
|
||||
{
|
||||
HAL_SPI_DeInit( &hspi );
|
||||
#ifdef WIFI_USE_CMSIS_OS
|
||||
osMutexDelete(spi_mutex);
|
||||
osMutexDelete(es_wifi_mutex);
|
||||
osSemaphoreDelete(spi_tx_sem);
|
||||
osSemaphoreDelete(spi_rx_sem);
|
||||
osSemaphoreDelete(cmddata_rdy_rising_sem);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Receive wifi Data from SPI
|
||||
* @param pdata : pointer to data
|
||||
* @param len : Data length
|
||||
* @param timeout : send timeout in mS
|
||||
* @retval Length of received data (payload)
|
||||
*/
|
||||
|
||||
int wait_cmddata_rdy_high(int timeout)
|
||||
{
|
||||
int tickstart = HAL_GetTick();
|
||||
while (WIFI_IS_CMDDATA_READY()==0)
|
||||
{
|
||||
if((HAL_GetTick() - tickstart ) > timeout)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int wait_cmddata_rdy_rising_event(int timeout)
|
||||
{
|
||||
#ifdef SEM_WAIT
|
||||
return SEM_WAIT(cmddata_rdy_rising_sem, timeout);
|
||||
#else
|
||||
int tickstart = HAL_GetTick();
|
||||
while (cmddata_rdy_rising_event==1)
|
||||
{
|
||||
if((HAL_GetTick() - tickstart ) > timeout)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
int wait_spi_rx_event(int timeout)
|
||||
{
|
||||
#ifdef SEM_WAIT
|
||||
return SEM_WAIT(spi_rx_sem, timeout);
|
||||
#else
|
||||
int tickstart = HAL_GetTick();
|
||||
while (spi_rx_event==1)
|
||||
{
|
||||
if((HAL_GetTick() - tickstart ) > timeout)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
int wait_spi_tx_event(int timeout)
|
||||
{
|
||||
#ifdef SEM_WAIT
|
||||
return SEM_WAIT(spi_tx_sem, timeout);
|
||||
#else
|
||||
int tickstart = HAL_GetTick();
|
||||
while (spi_tx_event==1)
|
||||
{
|
||||
if((HAL_GetTick() - tickstart ) > timeout)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
int16_t SPI_WIFI_ReceiveData(uint8_t *pData, uint16_t len, uint32_t timeout)
|
||||
{
|
||||
int16_t length = 0;
|
||||
uint8_t tmp[2];
|
||||
|
||||
WIFI_DISABLE_NSS();
|
||||
UNLOCK_SPI();
|
||||
SPI_WIFI_DelayUs(3);
|
||||
|
||||
|
||||
if (wait_cmddata_rdy_rising_event(timeout)<0)
|
||||
{
|
||||
return ES_WIFI_ERROR_WAITING_DRDY_FALLING;
|
||||
}
|
||||
|
||||
LOCK_SPI();
|
||||
WIFI_ENABLE_NSS();
|
||||
SPI_WIFI_DelayUs(15);
|
||||
while (WIFI_IS_CMDDATA_READY())
|
||||
{
|
||||
if((length < len) || (!len))
|
||||
{
|
||||
spi_rx_event=1;
|
||||
if (HAL_SPI_Receive_IT(&hspi, tmp, 1) != HAL_OK) {
|
||||
WIFI_DISABLE_NSS();
|
||||
UNLOCK_SPI();
|
||||
return ES_WIFI_ERROR_SPI_FAILED;
|
||||
}
|
||||
|
||||
wait_spi_rx_event(timeout);
|
||||
|
||||
pData[0] = tmp[0];
|
||||
pData[1] = tmp[1];
|
||||
length += 2;
|
||||
pData += 2;
|
||||
|
||||
if (length >= ES_WIFI_DATA_SIZE) {
|
||||
WIFI_DISABLE_NSS();
|
||||
SPI_WIFI_ResetModule();
|
||||
UNLOCK_SPI();
|
||||
return ES_WIFI_ERROR_STUFFING_FOREVER;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
WIFI_DISABLE_NSS();
|
||||
UNLOCK_SPI();
|
||||
return length;
|
||||
}
|
||||
/**
|
||||
* @brief Send wifi Data thru SPI
|
||||
* @param pdata : pointer to data
|
||||
* @param len : Data length
|
||||
* @param timeout : send timeout in mS
|
||||
* @retval Length of sent data
|
||||
*/
|
||||
int16_t SPI_WIFI_SendData( uint8_t *pdata, uint16_t len, uint32_t timeout)
|
||||
{
|
||||
uint8_t Padding[2];
|
||||
|
||||
if (wait_cmddata_rdy_high(timeout)<0)
|
||||
{
|
||||
return ES_WIFI_ERROR_SPI_FAILED;
|
||||
}
|
||||
|
||||
/* arm to detect rising event */
|
||||
cmddata_rdy_rising_event=1;
|
||||
LOCK_SPI();
|
||||
WIFI_ENABLE_NSS();
|
||||
SPI_WIFI_DelayUs(15);
|
||||
if (len > 1)
|
||||
{
|
||||
spi_tx_event=1;
|
||||
if( HAL_SPI_Transmit_IT(&hspi, (uint8_t *)pdata , len/2) != HAL_OK)
|
||||
{
|
||||
WIFI_DISABLE_NSS();
|
||||
UNLOCK_SPI();
|
||||
return ES_WIFI_ERROR_SPI_FAILED;
|
||||
}
|
||||
wait_spi_tx_event(timeout);
|
||||
}
|
||||
|
||||
if ( len & 1)
|
||||
{
|
||||
Padding[0] = pdata[len-1];
|
||||
Padding[1] = '\n';
|
||||
|
||||
spi_tx_event=1;
|
||||
if( HAL_SPI_Transmit_IT(&hspi, Padding, 1) != HAL_OK)
|
||||
{
|
||||
WIFI_DISABLE_NSS();
|
||||
UNLOCK_SPI();
|
||||
return ES_WIFI_ERROR_SPI_FAILED;
|
||||
}
|
||||
wait_spi_tx_event(timeout);
|
||||
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Delay
|
||||
* @param Delay in ms
|
||||
* @retval None
|
||||
*/
|
||||
void SPI_WIFI_Delay(uint32_t Delay)
|
||||
{
|
||||
HAL_Delay(Delay);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Delay
|
||||
* @param Delay in us
|
||||
* @retval None
|
||||
*/
|
||||
void SPI_WIFI_DelayUs(uint32_t n)
|
||||
{
|
||||
volatile uint32_t ct = 0;
|
||||
uint32_t loop_per_us = 0;
|
||||
static uint32_t cycle_per_loop = 0;
|
||||
|
||||
/* calibration happen on first call for a duration of 1 ms * nbcycle per loop */
|
||||
/* 10 cycle for STM32L4 */
|
||||
if (cycle_per_loop == 0 )
|
||||
{
|
||||
uint32_t cycle_per_ms = (SystemCoreClock/1000UL);
|
||||
uint32_t t = 0;
|
||||
ct = cycle_per_ms;
|
||||
t = HAL_GetTick();
|
||||
while(ct) ct--;
|
||||
cycle_per_loop = HAL_GetTick()-t;
|
||||
if (cycle_per_loop == 0) cycle_per_loop = 1;
|
||||
}
|
||||
|
||||
loop_per_us = SystemCoreClock/1000000UL/cycle_per_loop;
|
||||
ct = n * loop_per_us;
|
||||
while(ct) ct--;
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Rx Transfer completed callback.
|
||||
* @param hspi: pointer to a SPI_HandleTypeDef structure that contains
|
||||
* the configuration information for SPI module.
|
||||
* @retval None
|
||||
*/
|
||||
|
||||
void HAL_SPI_RxCpltCallback(SPI_HandleTypeDef *hspi)
|
||||
{
|
||||
if (spi_rx_event)
|
||||
{
|
||||
SEM_SIGNAL(spi_rx_sem);
|
||||
spi_rx_event = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Tx Transfer completed callback.
|
||||
* @param hspi: pointer to a SPI_HandleTypeDef structure that contains
|
||||
* the configuration information for SPI module.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_SPI_TxCpltCallback(SPI_HandleTypeDef *hspi)
|
||||
{
|
||||
if (spi_tx_event)
|
||||
{
|
||||
SEM_SIGNAL(spi_tx_sem);
|
||||
spi_tx_event = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Interrupt handler for Data RDY signal
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void SPI_WIFI_ISR(void)
|
||||
{
|
||||
if (cmddata_rdy_rising_event==1)
|
||||
{
|
||||
SEM_SIGNAL(cmddata_rdy_rising_sem);
|
||||
cmddata_rdy_rising_event = 0;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
583
P5_SETR2/LibWIFI/Src/wifi.c
Normal file
583
P5_SETR2/LibWIFI/Src/wifi.c
Normal file
@@ -0,0 +1,583 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file wifi.c
|
||||
* @author MCD Application Team
|
||||
* @brief WIFI interface file.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2017 STMicroelectronics International N.V.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "wifi.h"
|
||||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
ES_WIFIObject_t EsWifiObj;
|
||||
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
/**
|
||||
* @brief Initialize the WIFI core
|
||||
* @param None
|
||||
* @retval Operation status
|
||||
*/
|
||||
WIFI_Status_t WIFI_Init(void)
|
||||
{
|
||||
WIFI_Status_t ret = WIFI_STATUS_ERROR;
|
||||
|
||||
if(ES_WIFI_RegisterBusIO(&EsWifiObj,
|
||||
SPI_WIFI_Init,
|
||||
SPI_WIFI_DeInit,
|
||||
SPI_WIFI_Delay,
|
||||
SPI_WIFI_SendData,
|
||||
SPI_WIFI_ReceiveData) == ES_WIFI_STATUS_OK)
|
||||
{
|
||||
if(ES_WIFI_Init(&EsWifiObj) == ES_WIFI_STATUS_OK)
|
||||
{
|
||||
ret = WIFI_STATUS_OK;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief List a defined number of available access points
|
||||
* @param APs : pointer to APs structure
|
||||
* @param AP_MaxNbr : Max APs number to be listed
|
||||
* @retval Operation status
|
||||
*/
|
||||
WIFI_Status_t WIFI_ListAccessPoints(WIFI_APs_t *APs, uint8_t AP_MaxNbr)
|
||||
{
|
||||
uint8_t APCount;
|
||||
WIFI_Status_t ret = WIFI_STATUS_ERROR;
|
||||
ES_WIFI_APs_t esWifiAPs;
|
||||
|
||||
if(ES_WIFI_ListAccessPoints(&EsWifiObj, &esWifiAPs) == ES_WIFI_STATUS_OK)
|
||||
{
|
||||
if(esWifiAPs.nbr > 0)
|
||||
{
|
||||
APs->count = MIN(esWifiAPs.nbr, AP_MaxNbr);
|
||||
for(APCount = 0; APCount < APs->count; APCount++)
|
||||
{
|
||||
APs->ap[APCount].Ecn = (WIFI_Ecn_t)esWifiAPs.AP[APCount].Security;
|
||||
strncpy( (char *)APs->ap[APCount].SSID, (char *)esWifiAPs.AP[APCount].SSID, MIN (WIFI_MAX_SSID_NAME, WIFI_MAX_SSID_NAME));
|
||||
APs->ap[APCount].RSSI = esWifiAPs.AP[APCount].RSSI;
|
||||
memcpy(APs->ap[APCount].MAC, esWifiAPs.AP[APCount].MAC, 6);
|
||||
APs->ap[APCount].Channel = esWifiAPs.AP[APCount].Channel;
|
||||
}
|
||||
}
|
||||
ret = WIFI_STATUS_OK;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Join an Access Point
|
||||
* @param SSID : SSID string
|
||||
* @param Password : Password string
|
||||
* @param ecn : Encryption type
|
||||
* @param IP_Addr : Got IP Address
|
||||
* @param IP_Mask : Network IP mask
|
||||
* @param Gateway_Addr : Gateway IP address
|
||||
* @param MAC : pointer to MAC Address
|
||||
* @retval Operation status
|
||||
*/
|
||||
WIFI_Status_t WIFI_Connect(
|
||||
const char* SSID,
|
||||
const char* Password,
|
||||
WIFI_Ecn_t ecn)
|
||||
{
|
||||
WIFI_Status_t ret = WIFI_STATUS_ERROR;
|
||||
|
||||
if(ES_WIFI_Connect(&EsWifiObj, SSID, Password, (ES_WIFI_SecurityType_t) ecn) == ES_WIFI_STATUS_OK)
|
||||
{
|
||||
if(ES_WIFI_GetNetworkSettings(&EsWifiObj) == ES_WIFI_STATUS_OK)
|
||||
{
|
||||
ret = WIFI_STATUS_OK;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function retrieves the WiFi interface's MAC address.
|
||||
* @retval Operation Status.
|
||||
*/
|
||||
WIFI_Status_t WIFI_GetMAC_Address(uint8_t *mac)
|
||||
{
|
||||
WIFI_Status_t ret = WIFI_STATUS_ERROR;
|
||||
|
||||
if(ES_WIFI_GetMACAddress(&EsWifiObj, mac) == ES_WIFI_STATUS_OK)
|
||||
{
|
||||
ret = WIFI_STATUS_OK;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function retrieves the WiFi interface's IP address.
|
||||
* @retval Operation Status.
|
||||
*/
|
||||
WIFI_Status_t WIFI_GetIP_Address (uint8_t *ipaddr)
|
||||
{
|
||||
WIFI_Status_t ret = WIFI_STATUS_ERROR;
|
||||
|
||||
if (ES_WIFI_IsConnected(&EsWifiObj) == 1)
|
||||
{
|
||||
memcpy(ipaddr, EsWifiObj.NetSettings.IP_Addr, 4);
|
||||
ret = WIFI_STATUS_OK;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disconnect from a network
|
||||
* @param None
|
||||
* @retval Operation status
|
||||
*/
|
||||
WIFI_Status_t WIFI_Disconnect(void)
|
||||
{
|
||||
WIFI_Status_t ret = WIFI_STATUS_ERROR;
|
||||
if( ES_WIFI_Disconnect(&EsWifiObj)== ES_WIFI_STATUS_OK)
|
||||
{
|
||||
ret = WIFI_STATUS_OK;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configure an Access Point
|
||||
|
||||
* @param ssid : SSID string
|
||||
* @param pass : Password string
|
||||
* @param ecn : Encryption type
|
||||
* @param channel : channel number
|
||||
* @param max_conn : Max allowed connections
|
||||
* @retval Operation status
|
||||
*/
|
||||
WIFI_Status_t WIFI_ConfigureAP(uint8_t *ssid, uint8_t *pass, WIFI_Ecn_t ecn, uint8_t channel, uint8_t max_conn)
|
||||
{
|
||||
WIFI_Status_t ret = WIFI_STATUS_ERROR;
|
||||
ES_WIFI_APConfig_t ApConfig;
|
||||
|
||||
strncpy((char*)ApConfig.SSID, (char*)ssid, ES_WIFI_MAX_SSID_NAME_SIZE);
|
||||
strncpy((char*)ApConfig.Pass, (char*)pass, ES_WIFI_MAX_PSWD_NAME_SIZE);
|
||||
ApConfig.Channel = channel;
|
||||
ApConfig.MaxConnections = WIFI_MAX_CONNECTED_STATIONS;
|
||||
ApConfig.Security = (ES_WIFI_SecurityType_t)ecn;
|
||||
|
||||
if(ES_WIFI_ActivateAP(&EsWifiObj, &ApConfig) == ES_WIFI_STATUS_OK)
|
||||
{
|
||||
ret = WIFI_STATUS_OK;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Handle the background events of the wifi module
|
||||
|
||||
* @retval None
|
||||
*/
|
||||
WIFI_Status_t WIFI_HandleAPEvents(WIFI_APSettings_t *setting)
|
||||
{
|
||||
WIFI_Status_t ret = WIFI_STATUS_OK;
|
||||
ES_WIFI_APState_t State;
|
||||
|
||||
State= ES_WIFI_WaitAPStateChange(&EsWifiObj);
|
||||
|
||||
switch (State)
|
||||
{
|
||||
case ES_WIFI_AP_ASSIGNED:
|
||||
memcpy(setting->IP_Addr, EsWifiObj.APSettings.IP_Addr, 4);
|
||||
memcpy(setting->MAC_Addr, EsWifiObj.APSettings.MAC_Addr, 6);
|
||||
ret = WIFI_STATUS_ASSIGNED;
|
||||
break;
|
||||
|
||||
case ES_WIFI_AP_JOINED:
|
||||
strncpy((char *)setting->SSID, (char *)EsWifiObj.APSettings.SSID, WIFI_MAX_SSID_NAME);
|
||||
memcpy(setting->IP_Addr, EsWifiObj.APSettings.IP_Addr, 4);
|
||||
ret = WIFI_STATUS_JOINED;
|
||||
break;
|
||||
|
||||
case ES_WIFI_AP_ERROR:
|
||||
ret = WIFI_STATUS_ERROR;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Ping an IP address in the network
|
||||
* @param ipaddr : array of the IP address
|
||||
* @retval Operation status
|
||||
*/
|
||||
WIFI_Status_t WIFI_Ping(uint8_t *ipaddr, uint16_t count, uint16_t interval_ms, int32_t result[])
|
||||
{
|
||||
WIFI_Status_t ret = WIFI_STATUS_ERROR;
|
||||
|
||||
if(ES_WIFI_Ping(&EsWifiObj, ipaddr, count, interval_ms, result) == ES_WIFI_STATUS_OK)
|
||||
{
|
||||
ret = WIFI_STATUS_OK;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get IP address from URL using DNS
|
||||
* @param location : Host URL
|
||||
* @param ipaddr : array of the IP address
|
||||
* @retval Operation status
|
||||
*/
|
||||
WIFI_Status_t WIFI_GetHostAddress(const char *location, uint8_t *ipaddr)
|
||||
{
|
||||
WIFI_Status_t ret = WIFI_STATUS_ERROR;
|
||||
|
||||
if (ES_WIFI_DNS_LookUp(&EsWifiObj, location, ipaddr) == ES_WIFI_STATUS_OK)
|
||||
{
|
||||
return WIFI_STATUS_OK;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
/**
|
||||
* @brief Configure and start a client connection
|
||||
* @param type : Connection type TCP/UDP
|
||||
* @param name : name of the connection
|
||||
* @param ipaddr : IP address of the remote host
|
||||
* @param port : Remote port
|
||||
* @param local_port : Local port
|
||||
* @retval Operation status
|
||||
*/
|
||||
WIFI_Status_t WIFI_OpenClientConnection(uint32_t socket, WIFI_Protocol_t type, const char *name, uint8_t *ipaddr, uint16_t port, uint16_t local_port)
|
||||
{
|
||||
WIFI_Status_t ret = WIFI_STATUS_ERROR;
|
||||
ES_WIFI_Conn_t conn;
|
||||
|
||||
conn.Number = socket;
|
||||
conn.RemotePort = port;
|
||||
conn.LocalPort = local_port;
|
||||
conn.Type = (type == WIFI_TCP_PROTOCOL)? ES_WIFI_TCP_CONNECTION : ES_WIFI_UDP_CONNECTION;
|
||||
conn.RemoteIP[0] = ipaddr[0];
|
||||
conn.RemoteIP[1] = ipaddr[1];
|
||||
conn.RemoteIP[2] = ipaddr[2];
|
||||
conn.RemoteIP[3] = ipaddr[3];
|
||||
if(ES_WIFI_StartClientConnection(&EsWifiObj, &conn)== ES_WIFI_STATUS_OK)
|
||||
{
|
||||
ret = WIFI_STATUS_OK;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Close client connection
|
||||
* @retval Operation status
|
||||
*/
|
||||
WIFI_Status_t WIFI_CloseClientConnection(uint32_t socket)
|
||||
{
|
||||
WIFI_Status_t ret = WIFI_STATUS_ERROR;
|
||||
ES_WIFI_Conn_t conn;
|
||||
conn.Number = socket;
|
||||
|
||||
if(ES_WIFI_StopClientConnection(&EsWifiObj, &conn)== ES_WIFI_STATUS_OK)
|
||||
{
|
||||
ret = WIFI_STATUS_OK;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configure and start a Server
|
||||
* @param type : Connection type TCP/UDP
|
||||
* @param name : name of the connection
|
||||
* @param port : Remote port
|
||||
* @retval Operation status
|
||||
*/
|
||||
WIFI_Status_t WIFI_StartServer(uint32_t socket, WIFI_Protocol_t protocol, uint16_t backlog ,const char *name, uint16_t port)
|
||||
{
|
||||
WIFI_Status_t ret = WIFI_STATUS_ERROR;
|
||||
ES_WIFI_Conn_t conn;
|
||||
conn.Number = socket;
|
||||
conn.LocalPort = port;
|
||||
conn.Type = (protocol == WIFI_TCP_PROTOCOL)? ES_WIFI_TCP_CONNECTION : ES_WIFI_UDP_CONNECTION;
|
||||
conn.Backlog = backlog;
|
||||
if(ES_WIFI_StartServerSingleConn(&EsWifiObj, &conn)== ES_WIFI_STATUS_OK)
|
||||
{
|
||||
ret = WIFI_STATUS_OK;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Wait for a client connection to the server
|
||||
* @param socket : socket
|
||||
* @retval Operation status
|
||||
*/
|
||||
WIFI_Status_t WIFI_WaitServerConnection(int socket,uint32_t Timeout,uint8_t *RemoteIp,uint16_t *RemotePort)
|
||||
{
|
||||
ES_WIFI_Conn_t conn;
|
||||
ES_WIFI_Status_t ret;
|
||||
|
||||
conn.Number = socket;
|
||||
|
||||
ret = ES_WIFI_WaitServerConnection(&EsWifiObj,Timeout,&conn);
|
||||
|
||||
if (ES_WIFI_STATUS_OK == ret)
|
||||
{
|
||||
if (RemotePort) *RemotePort=conn.RemotePort;
|
||||
if (RemoteIp)
|
||||
{
|
||||
memcpy(RemoteIp,conn.RemoteIP,sizeof(conn.RemoteIP));
|
||||
}
|
||||
return WIFI_STATUS_OK;
|
||||
}
|
||||
|
||||
if (ES_WIFI_STATUS_TIMEOUT ==ret)
|
||||
{
|
||||
if (RemotePort) *RemotePort=0;
|
||||
if (RemoteIp)
|
||||
{
|
||||
memset(RemoteIp,0,sizeof(conn.RemoteIP));
|
||||
}
|
||||
return WIFI_STATUS_TIMEOUT;
|
||||
}
|
||||
|
||||
return WIFI_STATUS_ERROR;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Close current connection from a client to the server
|
||||
* @retval Operation status
|
||||
*/
|
||||
WIFI_Status_t WIFI_CloseServerConnection(int socket)
|
||||
{
|
||||
WIFI_Status_t ret = WIFI_STATUS_ERROR;
|
||||
if (ES_WIFI_STATUS_OK == ES_WIFI_CloseServerConnection(&EsWifiObj,socket))
|
||||
{
|
||||
ret = WIFI_STATUS_OK;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Stop a server
|
||||
* @param socket : socket
|
||||
* @retval Operation status
|
||||
*/
|
||||
WIFI_Status_t WIFI_StopServer(uint32_t socket)
|
||||
{
|
||||
WIFI_Status_t ret = WIFI_STATUS_ERROR;
|
||||
|
||||
if(ES_WIFI_StopServerSingleConn(&EsWifiObj,socket)== ES_WIFI_STATUS_OK)
|
||||
{
|
||||
ret = WIFI_STATUS_OK;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Send Data on a socket
|
||||
* @param pdata : pointer to data to be sent
|
||||
* @param Reqlen : length of data to be sent
|
||||
* @param SentDatalen : (OUT) length actually sent
|
||||
* @param Timeout : Socket write timeout (ms)
|
||||
* @retval Operation status
|
||||
*/
|
||||
WIFI_Status_t WIFI_SendData(uint8_t socket, uint8_t *pdata, uint16_t Reqlen, uint16_t *SentDatalen, uint32_t Timeout)
|
||||
{
|
||||
WIFI_Status_t ret = WIFI_STATUS_ERROR;
|
||||
|
||||
if(ES_WIFI_SendData(&EsWifiObj, socket, pdata, Reqlen, SentDatalen, Timeout) == ES_WIFI_STATUS_OK)
|
||||
{
|
||||
ret = WIFI_STATUS_OK;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Send Data on a socket
|
||||
* @param pdata : pointer to data to be sent
|
||||
* @param Reqlen : length of data to be sent
|
||||
* @param SentDatalen : (OUT) length actually sent
|
||||
* @param Timeout : Socket write timeout (ms)
|
||||
* @param ipaddr : (IN) 4-byte array containing the IP address of the remote host
|
||||
* @param port : (IN) port number of the remote host
|
||||
* @retval Operation status
|
||||
*/
|
||||
WIFI_Status_t WIFI_SendDataTo(uint8_t socket, uint8_t *pdata, uint16_t Reqlen, uint16_t *SentDatalen, uint32_t Timeout, uint8_t *ipaddr, uint16_t port)
|
||||
{
|
||||
WIFI_Status_t ret = WIFI_STATUS_ERROR;
|
||||
|
||||
if(ES_WIFI_SendDataTo(&EsWifiObj, socket, pdata, Reqlen, SentDatalen, Timeout, ipaddr, port) == ES_WIFI_STATUS_OK)
|
||||
{
|
||||
ret = WIFI_STATUS_OK;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Receive Data from a socket
|
||||
* @param pdata : pointer to Rx buffer
|
||||
* @param Reqlen : maximum length of the data to be received
|
||||
* @param RcvDatalen : (OUT) length of the data actually received
|
||||
* @param Timeout : Socket read timeout (ms)
|
||||
* @retval Operation status
|
||||
*/
|
||||
WIFI_Status_t WIFI_ReceiveData(uint8_t socket, uint8_t *pdata, uint16_t Reqlen, uint16_t *RcvDatalen, uint32_t Timeout)
|
||||
{
|
||||
WIFI_Status_t ret = WIFI_STATUS_ERROR;
|
||||
|
||||
if(ES_WIFI_ReceiveData(&EsWifiObj, socket, pdata, Reqlen, RcvDatalen, Timeout) == ES_WIFI_STATUS_OK)
|
||||
{
|
||||
ret = WIFI_STATUS_OK;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Receive Data from a socket
|
||||
* @param pdata : pointer to Rx buffer
|
||||
* @param Reqlen : maximum length of the data to be received
|
||||
* @param RcvDatalen : (OUT) length of the data actually received
|
||||
* @param Timeout : Socket read timeout (ms)
|
||||
* @param ipaddr : (OUT) 4-byte array containing the IP address of the remote host
|
||||
* @param port : (OUT) port number of the remote host
|
||||
* @retval Operation status
|
||||
*/
|
||||
WIFI_Status_t WIFI_ReceiveDataFrom(uint8_t socket, uint8_t *pdata, uint16_t Reqlen, uint16_t *RcvDatalen, uint32_t Timeout, uint8_t *ipaddr, uint16_t *port)
|
||||
{
|
||||
WIFI_Status_t ret = WIFI_STATUS_ERROR;
|
||||
|
||||
if(ES_WIFI_ReceiveDataFrom(&EsWifiObj, socket, pdata, Reqlen, RcvDatalen, Timeout, ipaddr, port) == ES_WIFI_STATUS_OK)
|
||||
{
|
||||
ret = WIFI_STATUS_OK;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Customize module data
|
||||
* @param name : MFC name
|
||||
* @param Mac : Mac Address
|
||||
* @retval Operation status
|
||||
*/
|
||||
WIFI_Status_t WIFI_SetOEMProperties(const char *name, uint8_t *Mac)
|
||||
{
|
||||
WIFI_Status_t ret = WIFI_STATUS_ERROR;
|
||||
|
||||
if(ES_WIFI_SetProductName(&EsWifiObj, (uint8_t *)name) == ES_WIFI_STATUS_OK)
|
||||
{
|
||||
if(ES_WIFI_SetMACAddress(&EsWifiObj, Mac) == ES_WIFI_STATUS_OK)
|
||||
{
|
||||
ret = WIFI_STATUS_OK;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reset the WIFI module
|
||||
* @retval Operation status
|
||||
*/
|
||||
WIFI_Status_t WIFI_ResetModule(void)
|
||||
{
|
||||
WIFI_Status_t ret = WIFI_STATUS_ERROR;
|
||||
|
||||
if(ES_WIFI_ResetModule(&EsWifiObj) == ES_WIFI_STATUS_OK)
|
||||
{
|
||||
ret = WIFI_STATUS_OK;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Restore module default configuration
|
||||
* @retval Operation status
|
||||
*/
|
||||
WIFI_Status_t WIFI_SetModuleDefault(void)
|
||||
{
|
||||
WIFI_Status_t ret = WIFI_STATUS_ERROR;
|
||||
|
||||
if(ES_WIFI_ResetToFactoryDefault(&EsWifiObj) == ES_WIFI_STATUS_OK)
|
||||
{
|
||||
ret = WIFI_STATUS_OK;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Update module firmware
|
||||
* @param location : Binary Location IP address
|
||||
* @retval Operation status
|
||||
*/
|
||||
WIFI_Status_t WIFI_ModuleFirmwareUpdate(const char *location)
|
||||
{
|
||||
return WIFI_STATUS_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Return Module firmware revision
|
||||
* @param rev : revision string
|
||||
* @retval Operation status
|
||||
*/
|
||||
WIFI_Status_t WIFI_GetModuleFwRevision(char *rev)
|
||||
{
|
||||
WIFI_Status_t ret = WIFI_STATUS_ERROR;
|
||||
|
||||
if(EsWifiObj.FW_Rev != NULL)
|
||||
{
|
||||
strncpy(rev, (char *)EsWifiObj.FW_Rev, ES_WIFI_FW_REV_SIZE);
|
||||
ret = WIFI_STATUS_OK;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Return Module ID
|
||||
* @param Info : Module ID string
|
||||
* @retval Operation status
|
||||
*/
|
||||
WIFI_Status_t WIFI_GetModuleID(char *Id)
|
||||
{
|
||||
WIFI_Status_t ret = WIFI_STATUS_ERROR;
|
||||
|
||||
if(EsWifiObj.Product_ID != NULL)
|
||||
{
|
||||
strncpy(Id, (char *)EsWifiObj.Product_ID, ES_WIFI_PRODUCT_ID_SIZE);
|
||||
ret = WIFI_STATUS_OK;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Return Module Name
|
||||
* @param Info : Module Name string
|
||||
* @retval Operation status
|
||||
*/
|
||||
WIFI_Status_t WIFI_GetModuleName(char *ModuleName)
|
||||
{
|
||||
WIFI_Status_t ret = WIFI_STATUS_ERROR;
|
||||
|
||||
if(EsWifiObj.Product_Name != NULL)
|
||||
{
|
||||
strncpy(ModuleName, (char *)EsWifiObj.Product_Name, ES_WIFI_PRODUCT_NAME_SIZE);
|
||||
ret = WIFI_STATUS_OK;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
Reference in New Issue
Block a user