Customized SNICInterface

Fork of NySNICInterface by Ryo Iizuka

Committer:
kishino
Date:
Fri Nov 14 00:52:31 2014 +0000
Revision:
43:d80bbb12ffe6
Parent:
41:1c1b5ad4d491
It was reviewed and modified the Receive logic of socket communication(TCP and UDP).

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kishino 39:a1233ca02edf 1 /* Copyright (C) 2014 Murata Manufacturing Co.,Ltd., MIT License
kishino 41:1c1b5ad4d491 2 * muRata, SWITCH SCIENCE Wi-FI module TypeYD SNIC-UART.
kishino 20:dd736d328de6 3 *
kishino 39:a1233ca02edf 4 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
kishino 39:a1233ca02edf 5 * and associated documentation files (the "Software"), to deal in the Software without restriction,
kishino 39:a1233ca02edf 6 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
kishino 39:a1233ca02edf 7 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
kishino 39:a1233ca02edf 8 * furnished to do so, subject to the following conditions:
kishino 20:dd736d328de6 9 *
kishino 39:a1233ca02edf 10 * The above copyright notice and this permission notice shall be included in all copies or
kishino 39:a1233ca02edf 11 * substantial portions of the Software.
kishino 20:dd736d328de6 12 *
kishino 39:a1233ca02edf 13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
kishino 39:a1233ca02edf 14 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
kishino 39:a1233ca02edf 15 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
kishino 39:a1233ca02edf 16 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
kishino 39:a1233ca02edf 17 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
kishino 39:a1233ca02edf 18 */
kishino 20:dd736d328de6 19 #ifndef _SNIC_CORE_H_
kishino 20:dd736d328de6 20 #define _SNIC_CORE_H_
kishino 20:dd736d328de6 21
kishino 25:67183ed15708 22 #include "MurataObject.h"
kishino 20:dd736d328de6 23 #include "mbed.h"
kishino 20:dd736d328de6 24 #include "rtos.h"
kishino 20:dd736d328de6 25 #include "RawSerial.h"
kishino 20:dd736d328de6 26 #include "CBuffer.h"
kishino 20:dd736d328de6 27
kishino 20:dd736d328de6 28 #include "SNIC_UartCommandManager.h"
kishino 20:dd736d328de6 29
kishino 36:f33fcf5975ab 30 #define UART_REQUEST_PAYLOAD_MAX 2048
kishino 20:dd736d328de6 31
kishino 20:dd736d328de6 32 #define MEMPOOL_BLOCK_SIZE 2048
kishino 20:dd736d328de6 33 #define MEMPOOL_PAYLOAD_NUM 1
kishino 20:dd736d328de6 34 #define MAX_SOCKET_ID 5
kishino 20:dd736d328de6 35
kishino 43:d80bbb12ffe6 36 #define MEMPOOL_UART_RECV_NUM 6
kishino 32:ae95309643aa 37 #define SNIC_UART_RECVBUF_SIZE 2048
kishino 29:6a0ba999597d 38
kishino 20:dd736d328de6 39 /** Wi-Fi security
kishino 20:dd736d328de6 40 */
kishino 20:dd736d328de6 41 typedef enum SECURITY {
kishino 20:dd736d328de6 42 /** Securiry Open */
kishino 20:dd736d328de6 43 e_SEC_OPEN = 0x00,
kishino 20:dd736d328de6 44 /** Securiry WEP */
kishino 20:dd736d328de6 45 e_SEC_WEP = 0x01,
kishino 20:dd736d328de6 46 /** Securiry WPA-PSK(TKIP) */
kishino 20:dd736d328de6 47 e_SEC_WPA_TKIP = 0x02,
kishino 20:dd736d328de6 48 /** Securiry WPA2-PSK(AES) */
kishino 20:dd736d328de6 49 e_SEC_WPA2_AES = 0x04,
kishino 20:dd736d328de6 50 /** Securiry WPA2-PSK(TKIP/AES) */
kishino 20:dd736d328de6 51 e_SEC_WPA2_MIXED = 0x06,
kishino 20:dd736d328de6 52 /** Securiry WPA-PSK(AES) */
kishino 20:dd736d328de6 53 e_SEC_WPA_AES = 0x07
kishino 20:dd736d328de6 54 }E_SECURITY;
kishino 20:dd736d328de6 55
kishino 20:dd736d328de6 56 /** Wi-Fi status
kishino 20:dd736d328de6 57 */
kishino 20:dd736d328de6 58 typedef enum WIFI_STATUS {
kishino 20:dd736d328de6 59 /** Wi-Fi OFF */
kishino 20:dd736d328de6 60 e_STATUS_OFF = 0,
kishino 20:dd736d328de6 61 /** No network */
kishino 20:dd736d328de6 62 e_NO_NETWORK,
kishino 20:dd736d328de6 63 /** Connected to AP (STA mode) */
kishino 20:dd736d328de6 64 e_STA_JOINED,
kishino 20:dd736d328de6 65 /** Started on AP mode */
kishino 20:dd736d328de6 66 e_AP_STARTED
kishino 20:dd736d328de6 67 }E_WIFI_STATUS;
kishino 20:dd736d328de6 68
kishino 29:6a0ba999597d 69 /** Memorypool
kishino 29:6a0ba999597d 70 */
kishino 29:6a0ba999597d 71 typedef struct
kishino 29:6a0ba999597d 72 {
kishino 29:6a0ba999597d 73 unsigned int size;
kishino 36:f33fcf5975ab 74 unsigned int demand_size;
kishino 29:6a0ba999597d 75 unsigned char buf[MEMPOOL_BLOCK_SIZE];
kishino 29:6a0ba999597d 76 }tagMEMPOOL_BLOCK_T;
kishino 29:6a0ba999597d 77
kishino 23:4ff2231ff9ba 78 /** Internal class used by any other classes. This class is singleton.
kishino 20:dd736d328de6 79 */
kishino 25:67183ed15708 80 class C_SNIC_Core: public C_MurataObject
kishino 20:dd736d328de6 81 {
kishino 21:dda155fe5048 82 friend class C_SNIC_UartCommandManager;
kishino 21:dda155fe5048 83 friend class C_SNIC_WifiInterface;
kishino 21:dda155fe5048 84 friend class TCPSocketConnection;
kishino 33:33f1bc919486 85 friend class TCPSocketServer;
kishino 33:33f1bc919486 86 friend class UDPSocket;
kishino 21:dda155fe5048 87 friend class Socket;
kishino 21:dda155fe5048 88
kishino 21:dda155fe5048 89 private:
kishino 22:a9ec0cad4f84 90 /** Wi-Fi Network type
kishino 22:a9ec0cad4f84 91 */
kishino 22:a9ec0cad4f84 92 typedef enum NETWORK_TYPE {
kishino 22:a9ec0cad4f84 93 /** Infrastructure */
kishino 22:a9ec0cad4f84 94 e_INFRA = 0,
kishino 22:a9ec0cad4f84 95 /** Adhoc */
kishino 22:a9ec0cad4f84 96 e_ADHOC = 1
kishino 22:a9ec0cad4f84 97 }E_NETWORK_TYPE;
kishino 22:a9ec0cad4f84 98
kishino 22:a9ec0cad4f84 99 /** Connection information
kishino 22:a9ec0cad4f84 100 */
kishino 22:a9ec0cad4f84 101 typedef struct {
kishino 29:6a0ba999597d 102 CircBuffer<char> *recvbuf_p;
kishino 22:a9ec0cad4f84 103 bool is_connected;
kishino 22:a9ec0cad4f84 104 bool is_received;
kishino 43:d80bbb12ffe6 105 bool is_receive_complete;
kishino 32:ae95309643aa 106 int parent_socket;
kishino 43:d80bbb12ffe6 107 int from_ip;
kishino 43:d80bbb12ffe6 108 short from_port;
kishino 32:ae95309643aa 109 bool is_accept;
kishino 39:a1233ca02edf 110 Mutex mutex;
kishino 22:a9ec0cad4f84 111 }tagCONNECT_INFO_T;
kishino 22:a9ec0cad4f84 112
kishino 33:33f1bc919486 113 /** UDP Recv information
kishino 33:33f1bc919486 114 */
kishino 33:33f1bc919486 115 typedef struct {
kishino 33:33f1bc919486 116 CircBuffer<char> *recvbuf_p;
kishino 33:33f1bc919486 117 int from_ip;
kishino 33:33f1bc919486 118 short from_port;
kishino 33:33f1bc919486 119 int parent_socket;
kishino 33:33f1bc919486 120 bool is_received;
kishino 39:a1233ca02edf 121 Mutex mutex;
kishino 33:33f1bc919486 122 }tagUDP_RECVINFO_T;
kishino 33:33f1bc919486 123
kishino 22:a9ec0cad4f84 124 /** GEN_FW_VER_GET_REQ Command */
kishino 22:a9ec0cad4f84 125 typedef struct
kishino 22:a9ec0cad4f84 126 {
kishino 22:a9ec0cad4f84 127 unsigned char cmd_sid;
kishino 22:a9ec0cad4f84 128 unsigned char seq;
kishino 22:a9ec0cad4f84 129 }tagGEN_FW_VER_GET_REQ_T;
kishino 22:a9ec0cad4f84 130
kishino 22:a9ec0cad4f84 131 /** SNIC_INIT_REQ */
kishino 22:a9ec0cad4f84 132 typedef struct
kishino 22:a9ec0cad4f84 133 {
kishino 28:b796031f6519 134 unsigned char cmd_sid;
kishino 28:b796031f6519 135 unsigned char seq;
kishino 28:b796031f6519 136 unsigned char buf_size[2];
kishino 22:a9ec0cad4f84 137 }tagSNIC_INIT_REQ_T;
kishino 22:a9ec0cad4f84 138
kishino 31:15c22824cc46 139 /** SNIC_IP_CONFIG_REQ */
kishino 31:15c22824cc46 140 typedef struct
kishino 31:15c22824cc46 141 {
kishino 31:15c22824cc46 142 unsigned char cmd_sid;
kishino 31:15c22824cc46 143 unsigned char seq;
kishino 31:15c22824cc46 144 unsigned char interface;
kishino 31:15c22824cc46 145 unsigned char dhcp;
kishino 31:15c22824cc46 146 }tagSNIC_IP_CONFIG_REQ_DHCP_T;
kishino 31:15c22824cc46 147
kishino 31:15c22824cc46 148 /** SNIC_IP_CONFIG_REQ */
kishino 31:15c22824cc46 149 typedef struct
kishino 31:15c22824cc46 150 {
kishino 31:15c22824cc46 151 unsigned char cmd_sid;
kishino 31:15c22824cc46 152 unsigned char seq;
kishino 31:15c22824cc46 153 unsigned char interface;
kishino 31:15c22824cc46 154 unsigned char dhcp;
kishino 31:15c22824cc46 155 unsigned char ip_addr[4];
kishino 31:15c22824cc46 156 unsigned char netmask[4];
kishino 31:15c22824cc46 157 unsigned char gateway[4];
kishino 31:15c22824cc46 158 }tagSNIC_IP_CONFIG_REQ_STATIC_T;
kishino 31:15c22824cc46 159
kishino 22:a9ec0cad4f84 160 /** SNIC_TCP_CREATE_SOCKET_REQ */
kishino 22:a9ec0cad4f84 161 typedef struct
kishino 22:a9ec0cad4f84 162 {
kishino 22:a9ec0cad4f84 163 unsigned char cmd_sid;
kishino 22:a9ec0cad4f84 164 unsigned char seq;
kishino 22:a9ec0cad4f84 165 unsigned char bind;
kishino 22:a9ec0cad4f84 166 unsigned char local_addr[4];
kishino 22:a9ec0cad4f84 167 unsigned char local_port[2];
kishino 22:a9ec0cad4f84 168 }tagSNIC_TCP_CREATE_SOCKET_REQ_T;
kishino 27:dcc4f34448f0 169
kishino 27:dcc4f34448f0 170 /** SNIC_CLOSE_SOCKET_REQ */
kishino 27:dcc4f34448f0 171 typedef struct
kishino 27:dcc4f34448f0 172 {
kishino 27:dcc4f34448f0 173 unsigned char cmd_sid;
kishino 27:dcc4f34448f0 174 unsigned char seq;
kishino 27:dcc4f34448f0 175 unsigned char socket_id;
kishino 27:dcc4f34448f0 176 }tagSNIC_CLOSE_SOCKET_REQ_T;
kishino 22:a9ec0cad4f84 177
kishino 22:a9ec0cad4f84 178 /** SNIC_TCP_SEND_FROM_SOCKET_REQ */
kishino 22:a9ec0cad4f84 179 typedef struct
kishino 22:a9ec0cad4f84 180 {
kishino 22:a9ec0cad4f84 181 unsigned char cmd_sid;
kishino 22:a9ec0cad4f84 182 unsigned char seq;
kishino 22:a9ec0cad4f84 183 unsigned char socket_id;
kishino 22:a9ec0cad4f84 184 unsigned char option;
kishino 22:a9ec0cad4f84 185 unsigned char payload_len[2];
kishino 22:a9ec0cad4f84 186 }tagSNIC_TCP_SEND_FROM_SOCKET_REQ_T;
kishino 22:a9ec0cad4f84 187
kishino 32:ae95309643aa 188 /** SNIC_TCP_CREATE_CONNECTION_REQ */
kishino 32:ae95309643aa 189 typedef struct
kishino 32:ae95309643aa 190 {
kishino 32:ae95309643aa 191 unsigned char cmd_sid;
kishino 32:ae95309643aa 192 unsigned char seq;
kishino 32:ae95309643aa 193 unsigned char socket_id;
kishino 32:ae95309643aa 194 unsigned char recv_bufsize[2];
kishino 32:ae95309643aa 195 unsigned char max_client;
kishino 32:ae95309643aa 196 }tagSNIC_TCP_CREATE_CONNECTION_REQ_T;
kishino 32:ae95309643aa 197
kishino 22:a9ec0cad4f84 198 /** SNIC_TCP_CONNECT_TO_SERVER_REQ */
kishino 22:a9ec0cad4f84 199 typedef struct
kishino 22:a9ec0cad4f84 200 {
kishino 22:a9ec0cad4f84 201 unsigned char cmd_sid;
kishino 22:a9ec0cad4f84 202 unsigned char seq;
kishino 22:a9ec0cad4f84 203 unsigned char socket_id;
kishino 22:a9ec0cad4f84 204 unsigned char remote_addr[4];
kishino 22:a9ec0cad4f84 205 unsigned char remote_port[2];
kishino 22:a9ec0cad4f84 206 unsigned char recv_bufsize[2];
kishino 22:a9ec0cad4f84 207 unsigned char timeout;
kishino 22:a9ec0cad4f84 208 }tagSNIC_TCP_CONNECT_TO_SERVER_REQ_T;
kishino 22:a9ec0cad4f84 209
kishino 33:33f1bc919486 210 /** SNIC_UDP_SIMPLE_SEND_REQ */
kishino 33:33f1bc919486 211 typedef struct
kishino 33:33f1bc919486 212 {
kishino 33:33f1bc919486 213 unsigned char cmd_sid;
kishino 33:33f1bc919486 214 unsigned char seq;
kishino 33:33f1bc919486 215 unsigned char remote_ip[4];
kishino 33:33f1bc919486 216 unsigned char remote_port[2];
kishino 33:33f1bc919486 217 unsigned char payload_len[2];
kishino 33:33f1bc919486 218 }tagSNIC_UDP_SIMPLE_SEND_REQ_T;
kishino 33:33f1bc919486 219
kishino 33:33f1bc919486 220 /** SNIC_UDP_CREATE_SOCKET_REQ */
kishino 33:33f1bc919486 221 typedef struct
kishino 33:33f1bc919486 222 {
kishino 33:33f1bc919486 223 unsigned char cmd_sid;
kishino 33:33f1bc919486 224 unsigned char seq;
kishino 33:33f1bc919486 225 unsigned char bind;
kishino 33:33f1bc919486 226 unsigned char local_addr[4];
kishino 33:33f1bc919486 227 unsigned char local_port[2];
kishino 33:33f1bc919486 228 }tagSNIC_UDP_CREATE_SOCKET_REQ_T;
kishino 33:33f1bc919486 229
kishino 43:d80bbb12ffe6 230 /** SNIC_UDP_CREATE_SOCKET_REQ */
kishino 43:d80bbb12ffe6 231 typedef struct
kishino 43:d80bbb12ffe6 232 {
kishino 43:d80bbb12ffe6 233 unsigned char cmd_sid;
kishino 43:d80bbb12ffe6 234 unsigned char seq;
kishino 43:d80bbb12ffe6 235 unsigned char bind;
kishino 43:d80bbb12ffe6 236 }tagSNIC_UDP_CREATE_SOCKET_REQ_CLIENT_T;
kishino 43:d80bbb12ffe6 237
kishino 43:d80bbb12ffe6 238 /** SNIC_UDP_SEND_FROM_SOCKET_REQ */
kishino 43:d80bbb12ffe6 239 typedef struct
kishino 43:d80bbb12ffe6 240 {
kishino 43:d80bbb12ffe6 241 unsigned char cmd_sid;
kishino 43:d80bbb12ffe6 242 unsigned char seq;
kishino 43:d80bbb12ffe6 243 unsigned char remote_ip[4];
kishino 43:d80bbb12ffe6 244 unsigned char remote_port[2];
kishino 43:d80bbb12ffe6 245 unsigned char socket_id;
kishino 43:d80bbb12ffe6 246 unsigned char connection_mode;
kishino 43:d80bbb12ffe6 247 unsigned char payload_len[2];
kishino 43:d80bbb12ffe6 248 }tagSNIC_UDP_SEND_FROM_SOCKET_REQ_T;
kishino 43:d80bbb12ffe6 249
kishino 33:33f1bc919486 250 /** SNIC_UDP_START_RECV_REQ */
kishino 33:33f1bc919486 251 typedef struct
kishino 33:33f1bc919486 252 {
kishino 33:33f1bc919486 253 unsigned char cmd_sid;
kishino 33:33f1bc919486 254 unsigned char seq;
kishino 33:33f1bc919486 255 unsigned char socket_id;
kishino 33:33f1bc919486 256 unsigned char recv_bufsize[2];
kishino 33:33f1bc919486 257 }tagSNIC_UDP_START_RECV_REQ_T;
kishino 33:33f1bc919486 258
kishino 32:ae95309643aa 259 /** SNIC_GET_DHCP_INFO_REQ */
kishino 32:ae95309643aa 260 typedef struct
kishino 32:ae95309643aa 261 {
kishino 32:ae95309643aa 262 unsigned char cmd_sid;
kishino 32:ae95309643aa 263 unsigned char seq;
kishino 32:ae95309643aa 264 unsigned char interface;
kishino 32:ae95309643aa 265 }tagSNIC_GET_DHCP_INFO_REQ_T;
kishino 32:ae95309643aa 266
kishino 22:a9ec0cad4f84 267 /** WIFI_ON_REQ Command */
kishino 22:a9ec0cad4f84 268 typedef struct
kishino 22:a9ec0cad4f84 269 {
kishino 22:a9ec0cad4f84 270 unsigned char cmd_sid;
kishino 22:a9ec0cad4f84 271 unsigned char seq;
kishino 22:a9ec0cad4f84 272 char country[COUNTRYC_CODE_LENTH];
kishino 22:a9ec0cad4f84 273 }tagWIFI_ON_REQ_T;
kishino 22:a9ec0cad4f84 274
kishino 22:a9ec0cad4f84 275 /** WIFI_OFF_REQ Command */
kishino 22:a9ec0cad4f84 276 typedef struct
kishino 22:a9ec0cad4f84 277 {
kishino 22:a9ec0cad4f84 278 unsigned char cmd_sid;
kishino 22:a9ec0cad4f84 279 unsigned char seq;
kishino 22:a9ec0cad4f84 280 }tagWIFI_OFF_REQ_T;
kishino 22:a9ec0cad4f84 281
kishino 22:a9ec0cad4f84 282 /** WIFI_DISCONNECT_REQ Command */
kishino 22:a9ec0cad4f84 283 typedef struct
kishino 22:a9ec0cad4f84 284 {
kishino 22:a9ec0cad4f84 285 unsigned char cmd_sid;
kishino 22:a9ec0cad4f84 286 unsigned char seq;
kishino 22:a9ec0cad4f84 287 }tagWIFI_DISCONNECT_REQ_T;
kishino 22:a9ec0cad4f84 288
kishino 22:a9ec0cad4f84 289 /** WIFI_GET_STA_RSSI_REQ Command */
kishino 22:a9ec0cad4f84 290 typedef struct
kishino 22:a9ec0cad4f84 291 {
kishino 22:a9ec0cad4f84 292 unsigned char cmd_sid;
kishino 22:a9ec0cad4f84 293 unsigned char seq;
kishino 22:a9ec0cad4f84 294 }tagWIFI_GET_STA_RSSI_REQ_T;
kishino 22:a9ec0cad4f84 295
kishino 22:a9ec0cad4f84 296 /** WIFI_SCAN_REQ Command */
kishino 22:a9ec0cad4f84 297 typedef struct
kishino 22:a9ec0cad4f84 298 {
kishino 22:a9ec0cad4f84 299 unsigned char cmd_sid;
kishino 22:a9ec0cad4f84 300 unsigned char seq;
kishino 22:a9ec0cad4f84 301 unsigned char scan_type;
kishino 22:a9ec0cad4f84 302 unsigned char bss_type;
kishino 22:a9ec0cad4f84 303 unsigned char bssid[BSSID_MAC_LENTH];
kishino 22:a9ec0cad4f84 304 unsigned char chan_list;
kishino 22:a9ec0cad4f84 305 unsigned char ssid[SSID_MAX_LENGTH+1];
kishino 22:a9ec0cad4f84 306 }tagWIFI_SCAN_REQ_T;
kishino 22:a9ec0cad4f84 307
kishino 29:6a0ba999597d 308 /** WIFI_GET_STATUS_REQ Command */
kishino 29:6a0ba999597d 309 typedef struct
kishino 29:6a0ba999597d 310 {
kishino 29:6a0ba999597d 311 unsigned char cmd_sid;
kishino 29:6a0ba999597d 312 unsigned char seq;
kishino 29:6a0ba999597d 313 unsigned char interface;
kishino 29:6a0ba999597d 314 }tagWIFI_GET_STATUS_REQ_T;
kishino 29:6a0ba999597d 315
kishino 20:dd736d328de6 316 /** Get buffer for command from memory pool.
kishino 20:dd736d328de6 317 @return Pointer of buffer
kishino 20:dd736d328de6 318 */
kishino 29:6a0ba999597d 319 tagMEMPOOL_BLOCK_T *allocCmdBuf();
kishino 20:dd736d328de6 320
kishino 20:dd736d328de6 321 /** Release buffer to memory pool.
kishino 20:dd736d328de6 322 @param buf_p Pointer of buffer
kishino 20:dd736d328de6 323 */
kishino 20:dd736d328de6 324 void freeCmdBuf( tagMEMPOOL_BLOCK_T *buf_p );
kishino 20:dd736d328de6 325
kishino 29:6a0ba999597d 326 /** Get buffer for command from memory pool.
kishino 29:6a0ba999597d 327 @return Pointer of buffer
kishino 29:6a0ba999597d 328 */
kishino 29:6a0ba999597d 329 tagMEMPOOL_BLOCK_T *allocUartRcvBuf();
kishino 29:6a0ba999597d 330
kishino 29:6a0ba999597d 331 /** Release buffer to memory pool.
kishino 29:6a0ba999597d 332 @param buf_p Pointer of buffer
kishino 29:6a0ba999597d 333 */
kishino 29:6a0ba999597d 334 void freeUartRecvBuf( tagMEMPOOL_BLOCK_T *buf_p );
kishino 29:6a0ba999597d 335
kishino 29:6a0ba999597d 336 /** Module Reset
kishino 29:6a0ba999597d 337 */
kishino 29:6a0ba999597d 338 int resetModule( PinName reset );
kishino 29:6a0ba999597d 339
kishino 29:6a0ba999597d 340 /** Initialize UART
kishino 20:dd736d328de6 341 */
kishino 20:dd736d328de6 342 int initUart( PinName tx, PinName rx, int baud );
kishino 20:dd736d328de6 343
kishino 20:dd736d328de6 344 /** Send data to UART
kishino 20:dd736d328de6 345 @param len Length of send data
kishino 20:dd736d328de6 346 @param data Pointer of send data
kishino 20:dd736d328de6 347 @return 0:success/other:fail
kishino 20:dd736d328de6 348 */
kishino 20:dd736d328de6 349 int sendUart( unsigned int len, unsigned char *data );
kishino 20:dd736d328de6 350
kishino 20:dd736d328de6 351 /** Preparation of the UART command
kishino 20:dd736d328de6 352 @param cmd_id UART Command ID
kishino 20:dd736d328de6 353 @param cmd_sid UART Command SubID
kishino 20:dd736d328de6 354 @param req_buf_p Pointer of UART request buffer
kishino 20:dd736d328de6 355 @param req_buf_len Length of UART request buffer
kishino 20:dd736d328de6 356 @param response_buf_p Pointer of UART response buffer
kishino 20:dd736d328de6 357 @param command_p Pointer of UART command[output]
kishino 20:dd736d328de6 358 @return Length of UART command.
kishino 20:dd736d328de6 359 */
kishino 20:dd736d328de6 360 unsigned int preparationSendCommand( unsigned char cmd_id, unsigned char cmd_sid
kishino 20:dd736d328de6 361 , unsigned char *req_buf_p, unsigned int req_buf_len
kishino 20:dd736d328de6 362 , unsigned char *response_buf_p, unsigned char *command_p );
kishino 20:dd736d328de6 363
kishino 20:dd736d328de6 364 /**
kishino 20:dd736d328de6 365 Get pointer of connection information.
kishino 20:dd736d328de6 366 @param socket_id Socket ID
kishino 20:dd736d328de6 367 @return The pointer of connection information
kishino 20:dd736d328de6 368 */
kishino 22:a9ec0cad4f84 369 C_SNIC_Core::tagCONNECT_INFO_T *getConnectInfo( int socket_id );
kishino 20:dd736d328de6 370
kishino 33:33f1bc919486 371 /**
kishino 33:33f1bc919486 372 Get pointer of UDP Recv information.
kishino 33:33f1bc919486 373 @param socket_id Socket ID
kishino 33:33f1bc919486 374 @return The pointer of UDP Recv information
kishino 33:33f1bc919486 375 */
kishino 33:33f1bc919486 376 C_SNIC_Core::tagUDP_RECVINFO_T *getUdpRecvInfo( int socket_id );
kishino 33:33f1bc919486 377
kishino 33:33f1bc919486 378 /**
kishino 20:dd736d328de6 379 Get pointer of the instance of C_SNIC_UartCommandManager.
kishino 20:dd736d328de6 380 @return The pointer of the instance of C_SNIC_UartCommandManager.
kishino 20:dd736d328de6 381 */
kishino 20:dd736d328de6 382 C_SNIC_UartCommandManager *getUartCommand();
kishino 20:dd736d328de6 383
kishino 29:6a0ba999597d 384 unsigned char *getCommandBuf();
kishino 29:6a0ba999597d 385
kishino 20:dd736d328de6 386 /** Get an instance of the C_SNIC_Core class.
kishino 20:dd736d328de6 387 @return Instance of the C_SNIC_Core class
kishino 20:dd736d328de6 388 @note Please do not create an instance in the default constructor this class.
kishino 20:dd736d328de6 389 Please use this method when you want to get an instance.
kishino 20:dd736d328de6 390 */
kishino 20:dd736d328de6 391 static C_SNIC_Core *getInstance();
kishino 20:dd736d328de6 392
kishino 43:d80bbb12ffe6 393 /** Mutex lock of API calls
kishino 43:d80bbb12ffe6 394 */
kishino 43:d80bbb12ffe6 395 void lockAPI( void );
kishino 43:d80bbb12ffe6 396
kishino 43:d80bbb12ffe6 397 /** Mutex unlock of API calls
kishino 43:d80bbb12ffe6 398 */
kishino 43:d80bbb12ffe6 399 void unlockAPI( void );
kishino 43:d80bbb12ffe6 400
kishino 20:dd736d328de6 401 private:
kishino 20:dd736d328de6 402 static C_SNIC_Core *mInstance_p;
kishino 20:dd736d328de6 403 Thread *mUartRecvThread_p;
kishino 29:6a0ba999597d 404 Thread *mUartRecvDispatchThread_p;
kishino 20:dd736d328de6 405 RawSerial *mUart_p;
kishino 20:dd736d328de6 406 Mutex mUartMutex;
kishino 43:d80bbb12ffe6 407 Mutex mAPIMutex;
kishino 29:6a0ba999597d 408
kishino 20:dd736d328de6 409 // DigitalInOut mModuleReset;
kishino 20:dd736d328de6 410 C_SNIC_UartCommandManager *mUartCommand_p;
kishino 29:6a0ba999597d 411
kishino 29:6a0ba999597d 412 CircBuffer<char> *mUartRecvBuf_p; // UART RecvBuffer
kishino 29:6a0ba999597d 413
kishino 20:dd736d328de6 414 /** Socket buffer */
kishino 20:dd736d328de6 415 tagCONNECT_INFO_T mConnectInfo[MAX_SOCKET_ID+1];
kishino 20:dd736d328de6 416
kishino 33:33f1bc919486 417 /** UDP Information */
kishino 33:33f1bc919486 418 tagUDP_RECVINFO_T mUdpRecvInfo[MAX_SOCKET_ID+1];
kishino 33:33f1bc919486 419
kishino 36:f33fcf5975ab 420 /** Constructor
kishino 20:dd736d328de6 421 */
kishino 20:dd736d328de6 422 C_SNIC_Core();
kishino 20:dd736d328de6 423
kishino 26:f2e1030964e4 424 virtual ~C_SNIC_Core();
kishino 29:6a0ba999597d 425
kishino 29:6a0ba999597d 426 static void uartRecvCallback( void );
kishino 20:dd736d328de6 427 /** Receiving thread of UART
kishino 20:dd736d328de6 428 */
kishino 29:6a0ba999597d 429 static void uartRecvDispatchThread( void const *args_p );
kishino 20:dd736d328de6 430 };
kishino 20:dd736d328de6 431
kishino 43:d80bbb12ffe6 432 #endif