mayuresh bharmoria / Mbed OS mbed-os-example-wifi
Committer:
mayur098
Date:
Thu Jun 21 17:50:21 2018 +0000
Revision:
0:8f8e8f3cbd1c
first commit;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mayur098 0:8f8e8f3cbd1c 1 /* SPWFSAxx Devices
mayur098 0:8f8e8f3cbd1c 2 * Copyright (c) 2015 ARM Limited
mayur098 0:8f8e8f3cbd1c 3 *
mayur098 0:8f8e8f3cbd1c 4 * Licensed under the Apache License, Version 2.0 (the "License");
mayur098 0:8f8e8f3cbd1c 5 * you may not use this file except in compliance with the License.
mayur098 0:8f8e8f3cbd1c 6 * You may obtain a copy of the License at
mayur098 0:8f8e8f3cbd1c 7 *
mayur098 0:8f8e8f3cbd1c 8 * http://www.apache.org/licenses/LICENSE-2.0
mayur098 0:8f8e8f3cbd1c 9 *
mayur098 0:8f8e8f3cbd1c 10 * Unless required by applicable law or agreed to in writing, software
mayur098 0:8f8e8f3cbd1c 11 * distributed under the License is distributed on an "AS IS" BASIS,
mayur098 0:8f8e8f3cbd1c 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
mayur098 0:8f8e8f3cbd1c 13 * See the License for the specific language governing permissions and
mayur098 0:8f8e8f3cbd1c 14 * limitations under the License.
mayur098 0:8f8e8f3cbd1c 15 */
mayur098 0:8f8e8f3cbd1c 16
mayur098 0:8f8e8f3cbd1c 17 #ifndef SPWFSAXX_H
mayur098 0:8f8e8f3cbd1c 18 #define SPWFSAXX_H
mayur098 0:8f8e8f3cbd1c 19
mayur098 0:8f8e8f3cbd1c 20 #include "mbed.h"
mayur098 0:8f8e8f3cbd1c 21 #include "ATCmdParser.h"
mayur098 0:8f8e8f3cbd1c 22 #include "BlockExecuter.h"
mayur098 0:8f8e8f3cbd1c 23
mayur098 0:8f8e8f3cbd1c 24 /* Common SPWFSAxx macros */
mayur098 0:8f8e8f3cbd1c 25 #define SPWFXX_WINDS_LOW_ON "0x00000000"
mayur098 0:8f8e8f3cbd1c 26 #define SPWFXX_DEFAULT_BAUD_RATE 115200
mayur098 0:8f8e8f3cbd1c 27 #define SPWFXX_MAX_TRIALS 3
mayur098 0:8f8e8f3cbd1c 28
mayur098 0:8f8e8f3cbd1c 29 #if !defined(SPWFSAXX_RTS_PIN)
mayur098 0:8f8e8f3cbd1c 30 #define SPWFSAXX_RTS_PIN NC
mayur098 0:8f8e8f3cbd1c 31 #endif // !defined(SPWFSAXX_RTS_PIN)
mayur098 0:8f8e8f3cbd1c 32 #if !defined(SPWFSAXX_CTS_PIN)
mayur098 0:8f8e8f3cbd1c 33 #define SPWFSAXX_CTS_PIN NC
mayur098 0:8f8e8f3cbd1c 34 #endif // !defined(SPWFSAXX_CTS_PIN)
mayur098 0:8f8e8f3cbd1c 35
mayur098 0:8f8e8f3cbd1c 36 #define SPWFXX_ERR_OK (+1)
mayur098 0:8f8e8f3cbd1c 37 #define SPWFXX_ERR_OOM (-1)
mayur098 0:8f8e8f3cbd1c 38 #define SPWFXX_ERR_READ (-2)
mayur098 0:8f8e8f3cbd1c 39 #define SPWFXX_ERR_LEN (-3)
mayur098 0:8f8e8f3cbd1c 40
mayur098 0:8f8e8f3cbd1c 41
mayur098 0:8f8e8f3cbd1c 42 /* Max number of sockets & packets */
mayur098 0:8f8e8f3cbd1c 43 #define SPWFSA_SOCKET_COUNT (8)
mayur098 0:8f8e8f3cbd1c 44 #define SPWFSA_MAX_PACKETS (4)
mayur098 0:8f8e8f3cbd1c 45
mayur098 0:8f8e8f3cbd1c 46 #define PENDING_DATA_SLOTS (13)
mayur098 0:8f8e8f3cbd1c 47
mayur098 0:8f8e8f3cbd1c 48 /* Pending data packets size buffer */
mayur098 0:8f8e8f3cbd1c 49 class SpwfRealPendingPackets {
mayur098 0:8f8e8f3cbd1c 50 public:
mayur098 0:8f8e8f3cbd1c 51 SpwfRealPendingPackets() {
mayur098 0:8f8e8f3cbd1c 52 reset();
mayur098 0:8f8e8f3cbd1c 53 }
mayur098 0:8f8e8f3cbd1c 54
mayur098 0:8f8e8f3cbd1c 55 void add(uint32_t new_cum_size) {
mayur098 0:8f8e8f3cbd1c 56 MBED_ASSERT(new_cum_size >= cumulative_size);
mayur098 0:8f8e8f3cbd1c 57
mayur098 0:8f8e8f3cbd1c 58 if(new_cum_size == cumulative_size) {
mayur098 0:8f8e8f3cbd1c 59 /* nothing to do */
mayur098 0:8f8e8f3cbd1c 60 return;
mayur098 0:8f8e8f3cbd1c 61 }
mayur098 0:8f8e8f3cbd1c 62
mayur098 0:8f8e8f3cbd1c 63 /* => `new_cum_size > cumulative_size` */
mayur098 0:8f8e8f3cbd1c 64 real_pkt_sizes[last_pkt_ptr] = (uint16_t)(new_cum_size - cumulative_size);
mayur098 0:8f8e8f3cbd1c 65 cumulative_size = new_cum_size;
mayur098 0:8f8e8f3cbd1c 66
mayur098 0:8f8e8f3cbd1c 67 last_pkt_ptr = (last_pkt_ptr + 1) % PENDING_DATA_SLOTS;
mayur098 0:8f8e8f3cbd1c 68
mayur098 0:8f8e8f3cbd1c 69 MBED_ASSERT(first_pkt_ptr != last_pkt_ptr);
mayur098 0:8f8e8f3cbd1c 70 }
mayur098 0:8f8e8f3cbd1c 71
mayur098 0:8f8e8f3cbd1c 72 uint32_t get(void) {
mayur098 0:8f8e8f3cbd1c 73 if(empty()) return 0;
mayur098 0:8f8e8f3cbd1c 74
mayur098 0:8f8e8f3cbd1c 75 return real_pkt_sizes[first_pkt_ptr];
mayur098 0:8f8e8f3cbd1c 76 }
mayur098 0:8f8e8f3cbd1c 77
mayur098 0:8f8e8f3cbd1c 78 uint32_t cumulative(void) {
mayur098 0:8f8e8f3cbd1c 79 return cumulative_size;
mayur098 0:8f8e8f3cbd1c 80 }
mayur098 0:8f8e8f3cbd1c 81
mayur098 0:8f8e8f3cbd1c 82 uint32_t remove(uint32_t size) {
mayur098 0:8f8e8f3cbd1c 83 MBED_ASSERT(!empty());
mayur098 0:8f8e8f3cbd1c 84
mayur098 0:8f8e8f3cbd1c 85 uint32_t ret = real_pkt_sizes[first_pkt_ptr];
mayur098 0:8f8e8f3cbd1c 86 first_pkt_ptr = (first_pkt_ptr + 1) % PENDING_DATA_SLOTS;
mayur098 0:8f8e8f3cbd1c 87
mayur098 0:8f8e8f3cbd1c 88 MBED_ASSERT(ret == size);
mayur098 0:8f8e8f3cbd1c 89 MBED_ASSERT(ret <= cumulative_size);
mayur098 0:8f8e8f3cbd1c 90 cumulative_size -= ret;
mayur098 0:8f8e8f3cbd1c 91
mayur098 0:8f8e8f3cbd1c 92 return ret;
mayur098 0:8f8e8f3cbd1c 93 }
mayur098 0:8f8e8f3cbd1c 94
mayur098 0:8f8e8f3cbd1c 95 void reset(void) {
mayur098 0:8f8e8f3cbd1c 96 memset(this, 0, sizeof(*this));
mayur098 0:8f8e8f3cbd1c 97 }
mayur098 0:8f8e8f3cbd1c 98
mayur098 0:8f8e8f3cbd1c 99 private:
mayur098 0:8f8e8f3cbd1c 100 bool empty(void) {
mayur098 0:8f8e8f3cbd1c 101 if(first_pkt_ptr == last_pkt_ptr) {
mayur098 0:8f8e8f3cbd1c 102 MBED_ASSERT(cumulative_size == 0);
mayur098 0:8f8e8f3cbd1c 103 return true;
mayur098 0:8f8e8f3cbd1c 104 }
mayur098 0:8f8e8f3cbd1c 105 return false;
mayur098 0:8f8e8f3cbd1c 106 }
mayur098 0:8f8e8f3cbd1c 107
mayur098 0:8f8e8f3cbd1c 108 uint16_t real_pkt_sizes[PENDING_DATA_SLOTS];
mayur098 0:8f8e8f3cbd1c 109 uint8_t first_pkt_ptr;
mayur098 0:8f8e8f3cbd1c 110 uint8_t last_pkt_ptr;
mayur098 0:8f8e8f3cbd1c 111 uint32_t cumulative_size;
mayur098 0:8f8e8f3cbd1c 112 };
mayur098 0:8f8e8f3cbd1c 113
mayur098 0:8f8e8f3cbd1c 114 class SpwfSAInterface;
mayur098 0:8f8e8f3cbd1c 115
mayur098 0:8f8e8f3cbd1c 116 /** SPWFSAxx Interface class.
mayur098 0:8f8e8f3cbd1c 117 This is an interface to a SPWFSAxx module.
mayur098 0:8f8e8f3cbd1c 118 */
mayur098 0:8f8e8f3cbd1c 119 class SPWFSAxx
mayur098 0:8f8e8f3cbd1c 120 {
mayur098 0:8f8e8f3cbd1c 121 private:
mayur098 0:8f8e8f3cbd1c 122 /* abstract class*/
mayur098 0:8f8e8f3cbd1c 123 SPWFSAxx(PinName tx, PinName rx, PinName rts, PinName cts,
mayur098 0:8f8e8f3cbd1c 124 SpwfSAInterface &ifce, bool debug,
mayur098 0:8f8e8f3cbd1c 125 PinName wakeup, PinName reset);
mayur098 0:8f8e8f3cbd1c 126
mayur098 0:8f8e8f3cbd1c 127 public:
mayur098 0:8f8e8f3cbd1c 128 /**
mayur098 0:8f8e8f3cbd1c 129 * Init the SPWFSAxx
mayur098 0:8f8e8f3cbd1c 130 *
mayur098 0:8f8e8f3cbd1c 131 * @param mode mode in which to startup
mayur098 0:8f8e8f3cbd1c 132 * @return true only if SPWFSAxx has started up correctly
mayur098 0:8f8e8f3cbd1c 133 */
mayur098 0:8f8e8f3cbd1c 134 bool startup(int mode);
mayur098 0:8f8e8f3cbd1c 135
mayur098 0:8f8e8f3cbd1c 136 /**
mayur098 0:8f8e8f3cbd1c 137 * Connect SPWFSAxx to AP
mayur098 0:8f8e8f3cbd1c 138 *
mayur098 0:8f8e8f3cbd1c 139 * @param ap the name of the AP
mayur098 0:8f8e8f3cbd1c 140 * @param passPhrase the password of AP
mayur098 0:8f8e8f3cbd1c 141 * @param securityMode the security mode of AP (WPA/WPA2, WEP, Open)
mayur098 0:8f8e8f3cbd1c 142 * @return true only if SPWFSAxx is connected successfully
mayur098 0:8f8e8f3cbd1c 143 */
mayur098 0:8f8e8f3cbd1c 144 bool connect(const char *ap, const char *passPhrase, int securityMode);
mayur098 0:8f8e8f3cbd1c 145
mayur098 0:8f8e8f3cbd1c 146 /**
mayur098 0:8f8e8f3cbd1c 147 * Disconnect SPWFSAxx from AP
mayur098 0:8f8e8f3cbd1c 148 *
mayur098 0:8f8e8f3cbd1c 149 * @return true only if SPWFSAxx is disconnected successfully
mayur098 0:8f8e8f3cbd1c 150 */
mayur098 0:8f8e8f3cbd1c 151 bool disconnect(void);
mayur098 0:8f8e8f3cbd1c 152
mayur098 0:8f8e8f3cbd1c 153 /**
mayur098 0:8f8e8f3cbd1c 154 * Get the IP address of SPWFSAxx
mayur098 0:8f8e8f3cbd1c 155 *
mayur098 0:8f8e8f3cbd1c 156 * @return null-terminated IP address or null if no IP address is assigned
mayur098 0:8f8e8f3cbd1c 157 */
mayur098 0:8f8e8f3cbd1c 158 const char *getIPAddress(void);
mayur098 0:8f8e8f3cbd1c 159
mayur098 0:8f8e8f3cbd1c 160 /**
mayur098 0:8f8e8f3cbd1c 161 * Get the MAC address of SPWFSAxx
mayur098 0:8f8e8f3cbd1c 162 *
mayur098 0:8f8e8f3cbd1c 163 * @return null-terminated MAC address or null if no MAC address is assigned
mayur098 0:8f8e8f3cbd1c 164 */
mayur098 0:8f8e8f3cbd1c 165 const char *getMACAddress(void);
mayur098 0:8f8e8f3cbd1c 166
mayur098 0:8f8e8f3cbd1c 167 /** Get the local gateway
mayur098 0:8f8e8f3cbd1c 168 *
mayur098 0:8f8e8f3cbd1c 169 * @return Null-terminated representation of the local gateway
mayur098 0:8f8e8f3cbd1c 170 * or null if no network mask has been received
mayur098 0:8f8e8f3cbd1c 171 */
mayur098 0:8f8e8f3cbd1c 172 const char *getGateway(void);
mayur098 0:8f8e8f3cbd1c 173
mayur098 0:8f8e8f3cbd1c 174 /** Get the local network mask
mayur098 0:8f8e8f3cbd1c 175 *
mayur098 0:8f8e8f3cbd1c 176 * @return Null-terminated representation of the local network mask
mayur098 0:8f8e8f3cbd1c 177 * or null if no network mask has been received
mayur098 0:8f8e8f3cbd1c 178 */
mayur098 0:8f8e8f3cbd1c 179 const char *getNetmask(void);
mayur098 0:8f8e8f3cbd1c 180
mayur098 0:8f8e8f3cbd1c 181 /** Gets the current radio signal strength for active connection
mayur098 0:8f8e8f3cbd1c 182 *
mayur098 0:8f8e8f3cbd1c 183 * @return Connection strength in dBm (negative value)
mayur098 0:8f8e8f3cbd1c 184 */
mayur098 0:8f8e8f3cbd1c 185 int8_t getRssi();
mayur098 0:8f8e8f3cbd1c 186
mayur098 0:8f8e8f3cbd1c 187 /**
mayur098 0:8f8e8f3cbd1c 188 * Sends data to an open socket
mayur098 0:8f8e8f3cbd1c 189 *
mayur098 0:8f8e8f3cbd1c 190 * @param id id of socket to send to
mayur098 0:8f8e8f3cbd1c 191 * @param data data to be sent
mayur098 0:8f8e8f3cbd1c 192 * @param amount amount of data to be sent - max 1024
mayur098 0:8f8e8f3cbd1c 193 * @return true only if data sent successfully
mayur098 0:8f8e8f3cbd1c 194 */
mayur098 0:8f8e8f3cbd1c 195 bool send(int id, const void *data, uint32_t amount);
mayur098 0:8f8e8f3cbd1c 196
mayur098 0:8f8e8f3cbd1c 197 /**
mayur098 0:8f8e8f3cbd1c 198 * Receives data from an open socket
mayur098 0:8f8e8f3cbd1c 199 *
mayur098 0:8f8e8f3cbd1c 200 * @param id id to receive from
mayur098 0:8f8e8f3cbd1c 201 * @param data placeholder for returned information
mayur098 0:8f8e8f3cbd1c 202 * @param amount number of bytes to be received
mayur098 0:8f8e8f3cbd1c 203 * @param datagram receive a datagram packet
mayur098 0:8f8e8f3cbd1c 204 * @return the number of bytes received
mayur098 0:8f8e8f3cbd1c 205 */
mayur098 0:8f8e8f3cbd1c 206 int32_t recv(int id, void *data, uint32_t amount, bool datagram);
mayur098 0:8f8e8f3cbd1c 207
mayur098 0:8f8e8f3cbd1c 208 /**
mayur098 0:8f8e8f3cbd1c 209 * Closes a socket
mayur098 0:8f8e8f3cbd1c 210 *
mayur098 0:8f8e8f3cbd1c 211 * @param id id of socket to close, valid only 0-4
mayur098 0:8f8e8f3cbd1c 212 * @return true only if socket is closed successfully
mayur098 0:8f8e8f3cbd1c 213 */
mayur098 0:8f8e8f3cbd1c 214 bool close(int id);
mayur098 0:8f8e8f3cbd1c 215
mayur098 0:8f8e8f3cbd1c 216 /**
mayur098 0:8f8e8f3cbd1c 217 * Allows timeout to be changed between commands
mayur098 0:8f8e8f3cbd1c 218 *
mayur098 0:8f8e8f3cbd1c 219 * @param timeout_ms timeout of the connection
mayur098 0:8f8e8f3cbd1c 220 */
mayur098 0:8f8e8f3cbd1c 221 void setTimeout(uint32_t timeout_ms);
mayur098 0:8f8e8f3cbd1c 222
mayur098 0:8f8e8f3cbd1c 223 /**
mayur098 0:8f8e8f3cbd1c 224 * Attach a function to call whenever network state has changed
mayur098 0:8f8e8f3cbd1c 225 *
mayur098 0:8f8e8f3cbd1c 226 * @param func A pointer to a void function, or 0 to set as none
mayur098 0:8f8e8f3cbd1c 227 */
mayur098 0:8f8e8f3cbd1c 228 void attach(Callback<void()> func);
mayur098 0:8f8e8f3cbd1c 229
mayur098 0:8f8e8f3cbd1c 230 /**
mayur098 0:8f8e8f3cbd1c 231 * Attach a function to call whenever network state has changed
mayur098 0:8f8e8f3cbd1c 232 *
mayur098 0:8f8e8f3cbd1c 233 * @param obj pointer to the object to call the member function on
mayur098 0:8f8e8f3cbd1c 234 * @param method pointer to the member function to call
mayur098 0:8f8e8f3cbd1c 235 */
mayur098 0:8f8e8f3cbd1c 236 template <typename T, typename M>
mayur098 0:8f8e8f3cbd1c 237 void attach(T *obj, M method) {
mayur098 0:8f8e8f3cbd1c 238 attach(Callback<void()>(obj, method));
mayur098 0:8f8e8f3cbd1c 239 }
mayur098 0:8f8e8f3cbd1c 240
mayur098 0:8f8e8f3cbd1c 241 static const char _cr_ = '\x0d'; // '\r' carriage return
mayur098 0:8f8e8f3cbd1c 242 static const char _lf_ = '\x0a'; // '\n' line feed
mayur098 0:8f8e8f3cbd1c 243
mayur098 0:8f8e8f3cbd1c 244 private:
mayur098 0:8f8e8f3cbd1c 245 UARTSerial _serial;
mayur098 0:8f8e8f3cbd1c 246 ATCmdParser _parser;
mayur098 0:8f8e8f3cbd1c 247
mayur098 0:8f8e8f3cbd1c 248 DigitalOut _wakeup;
mayur098 0:8f8e8f3cbd1c 249 DigitalOut _reset;
mayur098 0:8f8e8f3cbd1c 250 PinName _rts;
mayur098 0:8f8e8f3cbd1c 251 PinName _cts;
mayur098 0:8f8e8f3cbd1c 252
mayur098 0:8f8e8f3cbd1c 253 int _timeout;
mayur098 0:8f8e8f3cbd1c 254 bool _dbg_on;
mayur098 0:8f8e8f3cbd1c 255
mayur098 0:8f8e8f3cbd1c 256 int _pending_sockets_bitmap;
mayur098 0:8f8e8f3cbd1c 257 SpwfRealPendingPackets _pending_pkt_sizes[SPWFSA_SOCKET_COUNT];
mayur098 0:8f8e8f3cbd1c 258
mayur098 0:8f8e8f3cbd1c 259 bool _network_lost_flag;
mayur098 0:8f8e8f3cbd1c 260 SpwfSAInterface &_associated_interface;
mayur098 0:8f8e8f3cbd1c 261
mayur098 0:8f8e8f3cbd1c 262 /**
mayur098 0:8f8e8f3cbd1c 263 * Reset SPWFSAxx
mayur098 0:8f8e8f3cbd1c 264 *
mayur098 0:8f8e8f3cbd1c 265 * @return true only if SPWFSAxx resets successfully
mayur098 0:8f8e8f3cbd1c 266 */
mayur098 0:8f8e8f3cbd1c 267 bool hw_reset(void);
mayur098 0:8f8e8f3cbd1c 268 bool reset(void);
mayur098 0:8f8e8f3cbd1c 269
mayur098 0:8f8e8f3cbd1c 270 /**
mayur098 0:8f8e8f3cbd1c 271 * Check if SPWFSAxx is connected
mayur098 0:8f8e8f3cbd1c 272 *
mayur098 0:8f8e8f3cbd1c 273 * @return true only if the chip has an IP address
mayur098 0:8f8e8f3cbd1c 274 */
mayur098 0:8f8e8f3cbd1c 275 bool isConnected(void);
mayur098 0:8f8e8f3cbd1c 276
mayur098 0:8f8e8f3cbd1c 277 /**
mayur098 0:8f8e8f3cbd1c 278 * Checks if data is available
mayur098 0:8f8e8f3cbd1c 279 */
mayur098 0:8f8e8f3cbd1c 280 bool readable(void) {
mayur098 0:8f8e8f3cbd1c 281 return _serial.FileHandle::readable();
mayur098 0:8f8e8f3cbd1c 282 }
mayur098 0:8f8e8f3cbd1c 283
mayur098 0:8f8e8f3cbd1c 284 /**
mayur098 0:8f8e8f3cbd1c 285 * Checks if data can be written
mayur098 0:8f8e8f3cbd1c 286 */
mayur098 0:8f8e8f3cbd1c 287 bool writeable(void) {
mayur098 0:8f8e8f3cbd1c 288 return _serial.FileHandle::writable();
mayur098 0:8f8e8f3cbd1c 289 }
mayur098 0:8f8e8f3cbd1c 290
mayur098 0:8f8e8f3cbd1c 291 /**
mayur098 0:8f8e8f3cbd1c 292 * Try to empty RX buffer
mayur098 0:8f8e8f3cbd1c 293 * Can be used when commands fail receiving expected response to try to recover situation
mayur098 0:8f8e8f3cbd1c 294 * @note Gives no guarantee that situation improves
mayur098 0:8f8e8f3cbd1c 295 */
mayur098 0:8f8e8f3cbd1c 296 void empty_rx_buffer(void) {
mayur098 0:8f8e8f3cbd1c 297 while(readable()) _parser.getc();
mayur098 0:8f8e8f3cbd1c 298 }
mayur098 0:8f8e8f3cbd1c 299
mayur098 0:8f8e8f3cbd1c 300 /* call (external) callback only while not receiving */
mayur098 0:8f8e8f3cbd1c 301 volatile bool _call_event_callback_blocked;
mayur098 0:8f8e8f3cbd1c 302 Callback<void()> _callback_func;
mayur098 0:8f8e8f3cbd1c 303
mayur098 0:8f8e8f3cbd1c 304 struct packet {
mayur098 0:8f8e8f3cbd1c 305 struct packet *next;
mayur098 0:8f8e8f3cbd1c 306 int id;
mayur098 0:8f8e8f3cbd1c 307 uint32_t len;
mayur098 0:8f8e8f3cbd1c 308 // data follows
mayur098 0:8f8e8f3cbd1c 309 } *_packets, **_packets_end;
mayur098 0:8f8e8f3cbd1c 310
mayur098 0:8f8e8f3cbd1c 311 void _packet_handler_th(void);
mayur098 0:8f8e8f3cbd1c 312 void _execute_bottom_halves(void);
mayur098 0:8f8e8f3cbd1c 313 void _network_lost_handler_th(void);
mayur098 0:8f8e8f3cbd1c 314 void _network_lost_handler_bh(void);
mayur098 0:8f8e8f3cbd1c 315 void _hard_fault_handler(void);
mayur098 0:8f8e8f3cbd1c 316 void _wifi_hwfault_handler(void);
mayur098 0:8f8e8f3cbd1c 317 void _server_gone_handler(void);
mayur098 0:8f8e8f3cbd1c 318 #if MBED_CONF_IDW0XX1_EXPANSION_BOARD == IDW04A1
mayur098 0:8f8e8f3cbd1c 319 void _skip_oob(void);
mayur098 0:8f8e8f3cbd1c 320 #endif
mayur098 0:8f8e8f3cbd1c 321 bool _wait_wifi_hw_started(void);
mayur098 0:8f8e8f3cbd1c 322 bool _wait_console_active(void);
mayur098 0:8f8e8f3cbd1c 323 int _read_len(int);
mayur098 0:8f8e8f3cbd1c 324 int _flush_in(char*, int);
mayur098 0:8f8e8f3cbd1c 325 bool _winds_off(void);
mayur098 0:8f8e8f3cbd1c 326 void _winds_on(void);
mayur098 0:8f8e8f3cbd1c 327 void _read_in_pending(void);
mayur098 0:8f8e8f3cbd1c 328 int _read_in_pkt(int spwf_id, bool close);
mayur098 0:8f8e8f3cbd1c 329 int _read_in_packet(int spwf_id, uint32_t amount);
mayur098 0:8f8e8f3cbd1c 330 void _recover_from_hard_faults(void);
mayur098 0:8f8e8f3cbd1c 331 void _free_packets(int spwf_id);
mayur098 0:8f8e8f3cbd1c 332 void _free_all_packets(void);
mayur098 0:8f8e8f3cbd1c 333 void _process_winds();
mayur098 0:8f8e8f3cbd1c 334
mayur098 0:8f8e8f3cbd1c 335 virtual int _read_in(char*, int, uint32_t) = 0;
mayur098 0:8f8e8f3cbd1c 336
mayur098 0:8f8e8f3cbd1c 337 bool _recv_delim_lf(void) {
mayur098 0:8f8e8f3cbd1c 338 return (_parser.getc() == _lf_);
mayur098 0:8f8e8f3cbd1c 339 }
mayur098 0:8f8e8f3cbd1c 340
mayur098 0:8f8e8f3cbd1c 341 bool _recv_delim_cr(void) {
mayur098 0:8f8e8f3cbd1c 342 return (_parser.getc() == _cr_);
mayur098 0:8f8e8f3cbd1c 343 }
mayur098 0:8f8e8f3cbd1c 344
mayur098 0:8f8e8f3cbd1c 345 bool _recv_delim_cr_lf(void) {
mayur098 0:8f8e8f3cbd1c 346 return _recv_delim_cr() && _recv_delim_lf();
mayur098 0:8f8e8f3cbd1c 347 }
mayur098 0:8f8e8f3cbd1c 348
mayur098 0:8f8e8f3cbd1c 349 bool _recv_ok(void) {
mayur098 0:8f8e8f3cbd1c 350 return _parser.recv(SPWFXX_RECV_OK) && _recv_delim_lf();
mayur098 0:8f8e8f3cbd1c 351 }
mayur098 0:8f8e8f3cbd1c 352
mayur098 0:8f8e8f3cbd1c 353 void _add_pending_packet_sz(int spwf_id, uint32_t size);
mayur098 0:8f8e8f3cbd1c 354 void _add_pending_pkt_size(int spwf_id, uint32_t size) {
mayur098 0:8f8e8f3cbd1c 355 _pending_pkt_sizes[spwf_id].add(size);
mayur098 0:8f8e8f3cbd1c 356 }
mayur098 0:8f8e8f3cbd1c 357
mayur098 0:8f8e8f3cbd1c 358 uint32_t _get_cumulative_size(int spwf_id) {
mayur098 0:8f8e8f3cbd1c 359 return _pending_pkt_sizes[spwf_id].cumulative();
mayur098 0:8f8e8f3cbd1c 360 }
mayur098 0:8f8e8f3cbd1c 361
mayur098 0:8f8e8f3cbd1c 362 uint32_t _remove_pending_pkt_size(int spwf_id, uint32_t size) {
mayur098 0:8f8e8f3cbd1c 363 return _pending_pkt_sizes[spwf_id].remove(size);
mayur098 0:8f8e8f3cbd1c 364 }
mayur098 0:8f8e8f3cbd1c 365
mayur098 0:8f8e8f3cbd1c 366 uint32_t _get_pending_pkt_size(int spwf_id) {
mayur098 0:8f8e8f3cbd1c 367 return _pending_pkt_sizes[spwf_id].get();
mayur098 0:8f8e8f3cbd1c 368 }
mayur098 0:8f8e8f3cbd1c 369
mayur098 0:8f8e8f3cbd1c 370 void _reset_pending_pkt_sizes(int spwf_id) {
mayur098 0:8f8e8f3cbd1c 371 _pending_pkt_sizes[spwf_id].reset();
mayur098 0:8f8e8f3cbd1c 372 }
mayur098 0:8f8e8f3cbd1c 373
mayur098 0:8f8e8f3cbd1c 374 void _set_pending_data(int spwf_id) {
mayur098 0:8f8e8f3cbd1c 375 _pending_sockets_bitmap |= (1 << spwf_id);
mayur098 0:8f8e8f3cbd1c 376 }
mayur098 0:8f8e8f3cbd1c 377
mayur098 0:8f8e8f3cbd1c 378 void _clear_pending_data(int spwf_id) {
mayur098 0:8f8e8f3cbd1c 379 _pending_sockets_bitmap &= ~(1 << spwf_id);
mayur098 0:8f8e8f3cbd1c 380 }
mayur098 0:8f8e8f3cbd1c 381
mayur098 0:8f8e8f3cbd1c 382 bool _is_data_pending(int spwf_id) {
mayur098 0:8f8e8f3cbd1c 383 return (_pending_sockets_bitmap & (1 << spwf_id)) ? true : false;
mayur098 0:8f8e8f3cbd1c 384 }
mayur098 0:8f8e8f3cbd1c 385
mayur098 0:8f8e8f3cbd1c 386 bool _is_data_pending(void) {
mayur098 0:8f8e8f3cbd1c 387 if(_pending_sockets_bitmap != 0) return true;
mayur098 0:8f8e8f3cbd1c 388 else return false;
mayur098 0:8f8e8f3cbd1c 389 }
mayur098 0:8f8e8f3cbd1c 390
mayur098 0:8f8e8f3cbd1c 391 void _packet_handler_bh(void) {
mayur098 0:8f8e8f3cbd1c 392 /* read in other eventually pending packages */
mayur098 0:8f8e8f3cbd1c 393 _read_in_pending();
mayur098 0:8f8e8f3cbd1c 394 }
mayur098 0:8f8e8f3cbd1c 395
mayur098 0:8f8e8f3cbd1c 396 /* call (external) callback only while not receiving */
mayur098 0:8f8e8f3cbd1c 397 void _event_handler(void);
mayur098 0:8f8e8f3cbd1c 398
mayur098 0:8f8e8f3cbd1c 399 void _error_handler(void);
mayur098 0:8f8e8f3cbd1c 400
mayur098 0:8f8e8f3cbd1c 401 void _call_callback(void) {
mayur098 0:8f8e8f3cbd1c 402 if((bool)_callback_func) {
mayur098 0:8f8e8f3cbd1c 403 _callback_func();
mayur098 0:8f8e8f3cbd1c 404 }
mayur098 0:8f8e8f3cbd1c 405 }
mayur098 0:8f8e8f3cbd1c 406
mayur098 0:8f8e8f3cbd1c 407 bool _is_event_callback_blocked(void) {
mayur098 0:8f8e8f3cbd1c 408 return _call_event_callback_blocked;
mayur098 0:8f8e8f3cbd1c 409 }
mayur098 0:8f8e8f3cbd1c 410
mayur098 0:8f8e8f3cbd1c 411 void _block_event_callback(void) {
mayur098 0:8f8e8f3cbd1c 412 MBED_ASSERT(!_call_event_callback_blocked);
mayur098 0:8f8e8f3cbd1c 413 _call_event_callback_blocked = true;
mayur098 0:8f8e8f3cbd1c 414 }
mayur098 0:8f8e8f3cbd1c 415
mayur098 0:8f8e8f3cbd1c 416 void _unblock_event_callback(void) {
mayur098 0:8f8e8f3cbd1c 417 MBED_ASSERT(_call_event_callback_blocked);
mayur098 0:8f8e8f3cbd1c 418 _call_event_callback_blocked = false;
mayur098 0:8f8e8f3cbd1c 419 _trigger_event_callback();
mayur098 0:8f8e8f3cbd1c 420 }
mayur098 0:8f8e8f3cbd1c 421
mayur098 0:8f8e8f3cbd1c 422 /* unblock & force call of (external) callback */
mayur098 0:8f8e8f3cbd1c 423 void _unblock_and_callback(void) {
mayur098 0:8f8e8f3cbd1c 424 MBED_ASSERT(_call_event_callback_blocked);
mayur098 0:8f8e8f3cbd1c 425 _call_event_callback_blocked = false;
mayur098 0:8f8e8f3cbd1c 426 _call_callback();
mayur098 0:8f8e8f3cbd1c 427 }
mayur098 0:8f8e8f3cbd1c 428
mayur098 0:8f8e8f3cbd1c 429 /* trigger call of (external) callback in case there is still data */
mayur098 0:8f8e8f3cbd1c 430 void _trigger_event_callback(void) {
mayur098 0:8f8e8f3cbd1c 431 MBED_ASSERT(!_call_event_callback_blocked);
mayur098 0:8f8e8f3cbd1c 432 /* if still data available */
mayur098 0:8f8e8f3cbd1c 433 if(readable()) {
mayur098 0:8f8e8f3cbd1c 434 _call_callback();
mayur098 0:8f8e8f3cbd1c 435 }
mayur098 0:8f8e8f3cbd1c 436 }
mayur098 0:8f8e8f3cbd1c 437
mayur098 0:8f8e8f3cbd1c 438 char _ip_buffer[16];
mayur098 0:8f8e8f3cbd1c 439 char _gateway_buffer[16];
mayur098 0:8f8e8f3cbd1c 440 char _netmask_buffer[16];
mayur098 0:8f8e8f3cbd1c 441 char _mac_buffer[18];
mayur098 0:8f8e8f3cbd1c 442
mayur098 0:8f8e8f3cbd1c 443 char ssid_buf[256]; /* required to handle not 802.11 compliant ssid's */
mayur098 0:8f8e8f3cbd1c 444 char *_msg_buffer;
mayur098 0:8f8e8f3cbd1c 445
mayur098 0:8f8e8f3cbd1c 446 private:
mayur098 0:8f8e8f3cbd1c 447 friend class SPWFSA01;
mayur098 0:8f8e8f3cbd1c 448 friend class SPWFSA04;
mayur098 0:8f8e8f3cbd1c 449 friend class SpwfSAInterface;
mayur098 0:8f8e8f3cbd1c 450 };
mayur098 0:8f8e8f3cbd1c 451
mayur098 0:8f8e8f3cbd1c 452 #endif // SPWFSAXX_H