wifi8 2.0.0.0
wifi8.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2020 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
28#ifndef WIFI8_H
29#define WIFI8_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_spi_master.h"
52#include "wifi8_types.h"
53
74#define WIFI8_MAP_MIKROBUS(cfg, mikrobus) \
75 cfg.miso = MIKROBUS(mikrobus, MIKROBUS_MISO); \
76 cfg.mosi = MIKROBUS(mikrobus, MIKROBUS_MOSI); \
77 cfg.sck = MIKROBUS(mikrobus, MIKROBUS_SCK); \
78 cfg.cs = MIKROBUS(mikrobus, MIKROBUS_CS); \
79 cfg.en = MIKROBUS(mikrobus, MIKROBUS_AN); \
80 cfg.rst = MIKROBUS(mikrobus, MIKROBUS_RST); \
81 cfg.wkp = MIKROBUS(mikrobus, MIKROBUS_PWM); \
82 cfg.int_pin = MIKROBUS(mikrobus, MIKROBUS_INT)
83
84 // wifi8_map
85 // wifi8
86
91typedef struct
92{
93 // Output pins
94 digital_out_t en;
95 digital_out_t rst;
96 digital_out_t wkp;
98 // Input pins
99 digital_in_t int_pin;
101 // Modules
102 spi_master_t spi;
104 pin_name_t chip_select;
108 uint8_t ch_num;
109 uint32_t hs_flags;
111 uint8_t root_sha1[20];
112 uint16_t session_id;
113 uint8_t socket_init;
114 uint32_t ping_id;
119
120} wifi8_t;
121
126typedef struct
127{
128 // Communication gpio pins
129 pin_name_t miso;
130 pin_name_t mosi;
131 pin_name_t sck;
132 pin_name_t cs;
134 // Additional gpio pins
135 pin_name_t en;
136 pin_name_t rst;
137 pin_name_t wkp;
138 pin_name_t int_pin;
140 // static variable
141 uint32_t spi_speed;
142 spi_master_mode_t spi_mode;
143 spi_master_chip_select_polarity_t cs_polarity;
146
147typedef void (*wifi8_hif_call_back_t)(wifi8_t *ctx, uint8_t u8_op_code, uint16_t u16_data_size, uint32_t u32_addr);
149
167
184
199
214
229err_t wifi8_generic_write(wifi8_t *ctx, uint8_t *data_in, uint8_t len);
230
245err_t wifi8_generic_read(wifi8_t *ctx, uint8_t *data_out, uint8_t len);
246
261err_t wifi8_reg_write(wifi8_t *ctx, uint32_t addr, uint32_t data_in);
262
277err_t wifi8_reg_read(wifi8_t *ctx, uint32_t addr, uint32_t *data_out);
278
294err_t wifi8_block_read(wifi8_t *ctx, uint32_t addr, uint8_t *data_buf, uint16_t buf_len);
295
311err_t wifi8_block_write(wifi8_t *ctx, uint32_t addr, uint8_t *data_buf, uint16_t buf_len);
312
328
336uint32_t wifi8_chip_id(wifi8_t *ctx);
337
350
364
380err_t wifi8_connect(wifi8_t *ctx, char *pc_ssid, uint8_t u8_ssid_len, wifi8_m2m_sec_type_t u8_sec_type, void *pv_auth_info, uint16_t u16_ch);
381
396
410err_t wifi8_start_ap(wifi8_t *ctx, wifi8_m2m_ap_config_t *pstr_m2m_ap_config);
411
428err_t wifi8_req_scan_result(wifi8_t *ctx, uint8_t scan_request_index);
429
444err_t wifi8_request_scan(wifi8_t *ctx, uint8_t channel);
445
459
472err_t wifi8_ble_api_send(wifi8_t *ctx, uint8_t *msg, uint32_t len);
473
489
504err_t wifi8_socket_create(wifi8_t *ctx, uint16_t u16_domain, uint8_t u8_type, uint8_t u8_flags);
505
521err_t wifi8_socket_bind(wifi8_t *ctx, int8_t sock, wifi8_sockaddr_t *pstr_addr, uint8_t u8_addr_len);
522
539int8_t wifi8_socket_listen(wifi8_t *ctx, int8_t sock, uint8_t backlog);
540
557err_t wifi8_socket_connect(wifi8_t *ctx, int8_t sock, wifi8_sockaddr_t *pstr_addr, uint8_t u8_addr_len);
558
574err_t wifi8_socket_send(wifi8_t *ctx, int8_t sock, void *pv_send_buffer, uint16_t u16_send_length);
575
593err_t wifi8_socket_send_to(wifi8_t *ctx, int8_t sock, void *pv_send_buffer, uint16_t u16_send_length, wifi8_sockaddr_t *pstr_dest_addr, uint8_t u8_addr_len);
594
613err_t wifi8_socket_receive(wifi8_t *ctx, int8_t sock, void *pv_recv_buf, uint16_t u16_buf_len, uint32_t u32_timeoutmsec);
614
631err_t wifi8_socket_receive_from(wifi8_t *ctx, int8_t sock, void *pv_recv_buf, uint16_t u16_buf_len, uint32_t u32_timeoutmsec);
632
644err_t wifi8_socket_close(wifi8_t *ctx, int8_t sock);
645
646#ifdef __cplusplus
647}
648#endif
649#endif // WIFI8_H
650
651 // wifi8
652
653// ------------------------------------------------------------------------ END
err_t wifi8_socket_receive(wifi8_t *ctx, int8_t sock, void *pv_recv_buf, uint16_t u16_buf_len, uint32_t u32_timeoutmsec)
Asynchronous receive function.
err_t wifi8_get_ota_firmware_version(wifi8_t *ctx, wifi8_m2m_rev_t *fw_version)
Synchronous API to obtain the firmware version of the device.
err_t wifi8_request_scan(wifi8_t *ctx, uint8_t channel)
Asynchronous API to request the WINC to scan for networks.
int8_t wifi8_socket_listen(wifi8_t *ctx, int8_t sock, uint8_t backlog)
Asynchronous listen function.
err_t wifi8_start_ap(wifi8_t *ctx, wifi8_m2m_ap_config_t *pstr_m2m_ap_config)
Asynchronous API to enable access point (AKA "hot-spot") mode on the device.
err_t wifi8_socket_connect(wifi8_t *ctx, int8_t sock, wifi8_sockaddr_t *pstr_addr, uint8_t u8_addr_len)
Asynchronous connect function.
uint32_t wifi8_chip_id(wifi8_t *ctx)
Get device ID.
err_t wifi8_socket_receive_from(wifi8_t *ctx, int8_t sock, void *pv_recv_buf, uint16_t u16_buf_len, uint32_t u32_timeoutmsec)
Asynchronous receive function.
err_t wifi8_block_read(wifi8_t *ctx, uint32_t addr, uint8_t *data_buf, uint16_t buf_len)
Read blocks of data from register address.
err_t wifi8_get_connection_info(wifi8_t *ctx)
err_t wifi8_connect(wifi8_t *ctx, char *pc_ssid, uint8_t u8_ssid_len, wifi8_m2m_sec_type_t u8_sec_type, void *pv_auth_info, uint16_t u16_ch)
err_t wifi8_init(wifi8_t *ctx, wifi8_cfg_t *cfg)
WiFi 8 initialization function.
err_t wifi8_req_scan_result(wifi8_t *ctx, uint8_t scan_request_index)
Asynchronous API to request the information of an access point discovered via scanning.
err_t wifi8_default_cfg(wifi8_t *ctx)
WiFi 8 default configuration function.
err_t wifi8_handle_events(wifi8_t *ctx)
Synchronous event handler function.
err_t wifi8_socket_send_to(wifi8_t *ctx, int8_t sock, void *pv_send_buffer, uint16_t u16_send_length, wifi8_sockaddr_t *pstr_dest_addr, uint8_t u8_addr_len)
Asynchronous sending function.
err_t wifi8_socket_close(wifi8_t *ctx, int8_t sock)
Synchronous close function.
err_t wifi8_reg_read(wifi8_t *ctx, uint32_t addr, uint32_t *data_out)
Read data from register address.
err_t wifi8_socket_create(wifi8_t *ctx, uint16_t u16_domain, uint8_t u8_type, uint8_t u8_flags)
Synchronous socket allocation function based on the specified socket type.
err_t wifi8_socket_send(wifi8_t *ctx, int8_t sock, void *pv_send_buffer, uint16_t u16_send_length)
Asynchronous sending function.
err_t wifi8_get_full_firmware_version(wifi8_t *ctx, wifi8_m2m_rev_t *fw_version)
Synchronous API to obtain the firmware version currently running on the device.
err_t wifi8_generic_write(wifi8_t *ctx, uint8_t *data_in, uint8_t len)
Generic writing function.
err_t wifi8_reg_write(wifi8_t *ctx, uint32_t addr, uint32_t data_in)
Write data to register address.
void wifi8_cfg_setup(wifi8_cfg_t *cfg)
WiFi 8 configuration object setup function.
err_t wifi8_init_drv(wifi8_t *ctx)
Synchronous API to initialize the device driver.
err_t wifi8_socket_bind(wifi8_t *ctx, int8_t sock, wifi8_sockaddr_t *pstr_addr, uint8_t u8_addr_len)
Asynchronous bind function associates the provided address and local port to the socket.
err_t wifi8_block_write(wifi8_t *ctx, uint32_t addr, uint8_t *data_buf, uint16_t buf_len)
Write blocks of data to register address.
void wifi8_socket_init(wifi8_t *ctx)
The function performs the necessary initializations for the socket library.
err_t wifi8_ble_api_send(wifi8_t *ctx, uint8_t *msg, uint32_t len)
Asynchronous API to send an encapsulated BLE message.
err_t wifi8_generic_read(wifi8_t *ctx, uint8_t *data_out, uint8_t len)
Generic reading function.
wifi8_sockaddr_in_t addr
Definition main.c:62
WiFi 8 Click configuration object.
Definition wifi8.h:127
pin_name_t wkp
Definition wifi8.h:137
spi_master_chip_select_polarity_t cs_polarity
Definition wifi8.h:143
pin_name_t sck
Definition wifi8.h:131
spi_master_mode_t spi_mode
Definition wifi8.h:142
pin_name_t mosi
Definition wifi8.h:130
uint32_t spi_speed
Definition wifi8.h:141
pin_name_t en
Definition wifi8.h:135
pin_name_t int_pin
Definition wifi8.h:138
pin_name_t miso
Definition wifi8.h:129
pin_name_t rst
Definition wifi8.h:136
pin_name_t cs
Definition wifi8.h:132
Definition wifi8.h:151
uint32_t u32_rx_size
Definition wifi8.h:158
uint8_t u8_hif_rx_done
Definition wifi8.h:154
uint8_t u8_chip_mode
Definition wifi8.h:152
wifi8_hif_call_back_t pf_ota_cb
Definition wifi8.h:161
uint8_t u8_yield
Definition wifi8.h:156
wifi8_hif_call_back_t pf_ip_cb
Definition wifi8.h:160
wifi8_hif_call_back_t pf_sigma_cb
Definition wifi8.h:162
uint8_t u8_chip_sleep
Definition wifi8.h:153
wifi8_hif_call_back_t pf_wifi_cb
Definition wifi8.h:159
wifi8_hif_call_back_t pf_ssl_cb
Definition wifi8.h:165
wifi8_hif_call_back_t pf_crypto_cb
Definition wifi8.h:164
uint8_t u8_interrupt
Definition wifi8.h:155
wifi8_hif_call_back_t pf_hif_cb
Definition wifi8.h:163
uint32_t u32_rx_addr
Definition wifi8.h:157
Definition wifi8_types.h:816
Definition wifi8_types.h:837
Definition wifi8_types.h:848
Definition wifi8_types.h:772
Definition wifi8_types.h:975
WiFi 8 Click context object.
Definition wifi8.h:92
uint32_t ping_id
Definition wifi8.h:114
uint8_t socket_init
Definition wifi8.h:113
spi_master_t spi
Definition wifi8.h:102
uint8_t hif_bl_offset
Definition wifi8.h:106
uint32_t hs_flags
Definition wifi8.h:109
wifi8_ping_cb_t ping_cb
Definition wifi8.h:118
wifi8_app_resolve_cb_t app_resolve_cb
Definition wifi8.h:117
uint8_t ch_num
Definition wifi8.h:108
wifi8_app_socket_cb_t app_socket_cb
Definition wifi8.h:116
digital_in_t int_pin
Definition wifi8.h:99
uint16_t session_id
Definition wifi8.h:112
wifi8_nm_state_t device_state
Definition wifi8.h:107
digital_out_t wkp
Definition wifi8.h:96
digital_out_t en
Definition wifi8.h:94
digital_out_t rst
Definition wifi8.h:95
pin_name_t chip_select
Definition wifi8.h:104
wifi8_app_wifi_cb_t app_wifi_cb
Definition wifi8.h:115
void(* wifi8_hif_call_back_t)(wifi8_t *ctx, uint8_t u8_op_code, uint16_t u16_data_size, uint32_t u32_addr)
Definition wifi8.h:147
wifi8_sock_addr_t wifi8_uip_sock_addr_t
Definition wifi8.h:148
void(* wifi8_ping_cb_t)(uint32_t u32ip_addr, uint32_t u32rtt, uint8_t u8_error_code)
Definition wifi8_types.h:1335
void(* wifi8_app_resolve_cb_t)(uint8_t *pu8_domain_name, uint32_t u32_server_ip)
Definition wifi8_types.h:1334
void(* wifi8_app_socket_cb_t)(int8_t sock, uint8_t u8_msg, void *pv_msg)
Definition wifi8_types.h:1333
wifi8_nm_state_t
Definition wifi8_types.h:618
wifi8_m2m_sec_type_t
Definition wifi8_types.h:430
#define MAX_SOCKET
Definition wifi8_types.h:179
void(* wifi8_app_wifi_cb_t)(uint8_t u8_msg_type, void *pv_msg)
Definition wifi8_types.h:1331