Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
eswifi.h
Go to the documentation of this file.
1
7#ifndef ZEPHYR_DRIVERS_WIFI_ESWIFI_ESWIFI_H_
8#define ZEPHYR_DRIVERS_WIFI_ESWIFI_ESWIFI_H_
9
10#include <zephyr.h>
11#include <kernel.h>
12#include <stdio.h>
13#include <kernel_structs.h>
14
15#include <net/wifi_mgmt.h>
16
17#include "eswifi_offload.h"
18
19#define MAX_DATA_SIZE 1600
20
21#define AT_OK_STR "\r\nOK\r\n> "
22#define AT_OK_STR_LEN 8
23#define AT_RSP_DELIMITER "\r\n"
24#define AT_RSP_DELIMITER_LEN 2
25
27 const struct device *dev;
28 unsigned int pin;
29};
30
38};
39
45};
46
50};
51
52struct eswifi_sta {
55 char pass[65];
58};
59
60struct eswifi_bus_ops;
61
62struct eswifi_dev {
63 struct net_if *iface;
75 struct k_mutex mutex;
77 unsigned int mutex_depth;
78 void *bus_data;
80};
81
83 int (*init)(struct eswifi_dev *eswifi);
84 int (*request)(struct eswifi_dev *eswifi, char *cmd, size_t clen,
85 char *rsp, size_t rlen);
86};
87
88static inline int eswifi_request(struct eswifi_dev *eswifi, char *cmd,
89 size_t clen, char *rsp, size_t rlen)
90{
91 return eswifi->bus->request(eswifi, cmd, clen, rsp, rlen);
92}
93
94static inline void eswifi_lock(struct eswifi_dev *eswifi)
95{
96 /* Nested locking */
97 if (atomic_get(&eswifi->mutex_owner) != (atomic_t)(uintptr_t)_current) {
100 eswifi->mutex_depth = 1;
101 } else {
103 }
104}
105
106static inline void eswifi_unlock(struct eswifi_dev *eswifi)
107{
108 if (!--eswifi->mutex_depth) {
111 }
112}
113
114int eswifi_at_cmd(struct eswifi_dev *eswifi, char *cmd);
115static inline int __select_socket(struct eswifi_dev *eswifi, uint8_t idx)
116{
117 snprintk(eswifi->buf, sizeof(eswifi->buf), "P0=%d\r", idx);
118 return eswifi_at_cmd(eswifi, eswifi->buf);
119}
120
121static inline
123{
124 return CONTAINER_OF(socket - socket->index, struct eswifi_dev, socket);
125}
126
127struct eswifi_bus_ops *eswifi_get_bus(void);
130int eswifi_at_cmd_rsp(struct eswifi_dev *eswifi, char *cmd, char **rsp);
131void eswifi_async_msg(struct eswifi_dev *eswifi, char *msg, size_t len);
132void eswifi_offload_async_msg(struct eswifi_dev *eswifi, char *msg, size_t len);
133
134int __eswifi_socket_free(struct eswifi_dev *eswifi,
135 struct eswifi_off_socket *socket);
136int __eswifi_socket_new(struct eswifi_dev *eswifi, int family, int type,
137 int proto, void *context);
138int __eswifi_off_start_client(struct eswifi_dev *eswifi,
139 struct eswifi_off_socket *socket);
140int __eswifi_accept(struct eswifi_dev *eswifi, struct eswifi_off_socket *socket);
141int __eswifi_bind(struct eswifi_dev *eswifi, struct eswifi_off_socket *socket,
142 const struct sockaddr *addr, socklen_t addrlen);
143#if defined(CONFIG_NET_SOCKETS_OFFLOAD)
144int eswifi_socket_offload_init(struct eswifi_dev *leswifi);
145#endif
146
147#if defined(CONFIG_WIFI_ESWIFI_SHELL)
148void eswifi_shell_register(struct eswifi_dev *dev);
149#else
150#define eswifi_shell_register(dev)
151#endif
152
153#endif
atomic_t atomic_val_t
Definition: atomic.h:22
int atomic_t
Definition: atomic.h:21
static ALWAYS_INLINE atomic_val_t atomic_set(atomic_t *target, atomic_val_t value)
Definition: atomic_xtensa.h:70
static ALWAYS_INLINE atomic_val_t atomic_get(const atomic_t *target)
Definition: atomic_xtensa.h:16
static void eswifi_lock(struct eswifi_dev *eswifi)
Definition: eswifi.h:94
struct eswifi_bus_ops * eswifi_get_bus(void)
Definition: eswifi_bus_spi.c:280
int eswifi_at_cmd_rsp(struct eswifi_dev *eswifi, char *cmd, char **rsp)
Definition: eswifi_core.c:127
static struct eswifi_dev * eswifi_socket_to_dev(struct eswifi_off_socket *socket)
Definition: eswifi.h:122
#define eswifi_shell_register(dev)
Definition: eswifi.h:150
void eswifi_async_msg(struct eswifi_dev *eswifi, char *msg, size_t len)
Definition: eswifi_core.c:502
struct eswifi_dev * eswifi_by_iface_idx(uint8_t iface)
Definition: eswifi_core.c:175
void eswifi_offload_async_msg(struct eswifi_dev *eswifi, char *msg, size_t len)
Definition: eswifi_offload.c:444
#define MAX_DATA_SIZE
Definition: eswifi.h:19
eswifi_role
Definition: eswifi.h:47
@ ESWIFI_ROLE_AP
Definition: eswifi.h:49
@ ESWIFI_ROLE_CLIENT
Definition: eswifi.h:48
eswifi_security_type
Definition: eswifi.h:31
@ ESWIFI_SEC_WPA2_AES
Definition: eswifi.h:35
@ ESWIFI_SEC_WPA2_MIXED
Definition: eswifi.h:36
@ ESWIFI_SEC_WEP
Definition: eswifi.h:33
@ ESWIFI_SEC_MAX
Definition: eswifi.h:37
@ ESWIFI_SEC_OPEN
Definition: eswifi.h:32
@ ESWIFI_SEC_WPA
Definition: eswifi.h:34
static void eswifi_unlock(struct eswifi_dev *eswifi)
Definition: eswifi.h:106
int eswifi_at_cmd(struct eswifi_dev *eswifi, char *cmd)
Definition: eswifi_core.c:170
int eswifi_offload_init(struct eswifi_dev *eswifi)
Definition: eswifi_offload.c:560
eswifi_request
Definition: eswifi.h:40
@ ESWIFI_REQ_SCAN
Definition: eswifi.h:41
@ ESWIFI_REQ_NONE
Definition: eswifi.h:44
@ ESWIFI_REQ_CONNECT
Definition: eswifi.h:42
@ ESWIFI_REQ_DISCONNECT
Definition: eswifi.h:43
#define ESWIFI_OFFLOAD_MAX_SOCKETS
Definition: eswifi_offload.h:13
static struct eswifi_dev * eswifi
Definition: eswifi_shell.c:12
int eswifi_socket_offload_init(struct eswifi_dev *leswifi)
Definition: eswifi_socket_offload.c:669
#define K_FOREVER
Generate infinite timeout delay.
Definition: kernel.h:1186
static void cmd(uint32_t command)
Execute a display list command by co-processor engine.
Definition: ft8xx_reference_api.h:153
size_t socklen_t
Definition: net_ip.h:161
int k_mutex_unlock(struct k_mutex *mutex)
Unlock a mutex.
int k_mutex_lock(struct k_mutex *mutex, k_timeout_t timeout)
Lock a mutex.
#define CONTAINER_OF(ptr, type, field)
Get a pointer to a container structure from an element.
Definition: util.h:131
int snprintk(char *str, size_t size, const char *fmt,...)
__UINT8_TYPE__ uint8_t
Definition: stdint.h:58
__UINTPTR_TYPE__ uintptr_t
Definition: stdint.h:75
Runtime device structure (in ROM) per driver instance.
Definition: device.h:367
Definition: eswifi.h:82
int(* request)(struct eswifi_dev *eswifi, char *cmd, size_t clen, char *rsp, size_t rlen)
Definition: eswifi.h:84
int(* init)(struct eswifi_dev *eswifi)
Definition: eswifi.h:83
Definition: eswifi.h:62
struct eswifi_gpio resetn
Definition: eswifi.h:65
void * bus_data
Definition: eswifi.h:78
enum eswifi_role role
Definition: eswifi.h:72
struct net_if * iface
Definition: eswifi.h:63
struct eswifi_gpio wakeup
Definition: eswifi.h:66
char buf[1600]
Definition: eswifi.h:74
struct eswifi_bus_ops * bus
Definition: eswifi.h:64
uint8_t mac[6]
Definition: eswifi.h:73
struct eswifi_off_socket socket[4]
Definition: eswifi.h:79
enum eswifi_request req
Definition: eswifi.h:71
scan_result_cb_t scan_cb
Definition: eswifi.h:67
atomic_val_t mutex_owner
Definition: eswifi.h:76
struct eswifi_sta sta
Definition: eswifi.h:70
struct k_work request_work
Definition: eswifi.h:69
unsigned int mutex_depth
Definition: eswifi.h:77
struct k_mutex mutex
Definition: eswifi.h:75
struct k_work_q work_q
Definition: eswifi.h:68
Definition: eswifi.h:26
const struct device * dev
Definition: eswifi.h:27
unsigned int pin
Definition: eswifi.h:28
Definition: eswifi_offload.h:29
Definition: eswifi.h:52
enum eswifi_security_type security
Definition: eswifi.h:54
uint8_t channel
Definition: eswifi.h:57
char pass[65]
Definition: eswifi.h:55
char ssid[WIFI_SSID_MAX_LEN+1]
Definition: eswifi.h:53
bool connected
Definition: eswifi.h:56
Definition: kernel.h:2680
A structure used to hold work until it can be processed.
Definition: kernel.h:3770
A structure used to submit work.
Definition: kernel.h:3623
Network Interface structure.
Definition: net_if.h:468
Definition: net_ip.h:335
#define WIFI_SSID_MAX_LEN
Definition: wifi.h:20
WiFi L2 stack public header.
void(* scan_result_cb_t)(struct net_if *iface, int status, struct wifi_scan_result *entry)
Definition: wifi_mgmt.h:113
NMI_API SOCKET socket(uint16 u16Domain, uint8 u8Type, uint8 u8Flags)