Development mbed library for MAX32630FTHR

Dependents:   blinky_max32630fthr

Committer:
switches
Date:
Fri Dec 16 16:27:57 2016 +0000
Revision:
3:1198227e6421
Parent:
0:5c4d7b2438d3
Changed ADC scale for MAX32625 platforms to 1.2V full scale to match MAX32630 platforms

Who changed what in which revision?

UserRevisionLine numberNew contents of line
switches 0:5c4d7b2438d3 1
switches 0:5c4d7b2438d3 2 /** \addtogroup netsocket */
switches 0:5c4d7b2438d3 3 /** @{*/
switches 0:5c4d7b2438d3 4 /* TCPSocket
switches 0:5c4d7b2438d3 5 * Copyright (c) 2015 ARM Limited
switches 0:5c4d7b2438d3 6 *
switches 0:5c4d7b2438d3 7 * Licensed under the Apache License, Version 2.0 (the "License");
switches 0:5c4d7b2438d3 8 * you may not use this file except in compliance with the License.
switches 0:5c4d7b2438d3 9 * You may obtain a copy of the License at
switches 0:5c4d7b2438d3 10 *
switches 0:5c4d7b2438d3 11 * http://www.apache.org/licenses/LICENSE-2.0
switches 0:5c4d7b2438d3 12 *
switches 0:5c4d7b2438d3 13 * Unless required by applicable law or agreed to in writing, software
switches 0:5c4d7b2438d3 14 * distributed under the License is distributed on an "AS IS" BASIS,
switches 0:5c4d7b2438d3 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
switches 0:5c4d7b2438d3 16 * See the License for the specific language governing permissions and
switches 0:5c4d7b2438d3 17 * limitations under the License.
switches 0:5c4d7b2438d3 18 */
switches 0:5c4d7b2438d3 19
switches 0:5c4d7b2438d3 20 #ifndef TCPSOCKET_H
switches 0:5c4d7b2438d3 21 #define TCPSOCKET_H
switches 0:5c4d7b2438d3 22
switches 0:5c4d7b2438d3 23 #include "netsocket/Socket.h"
switches 0:5c4d7b2438d3 24 #include "netsocket/NetworkStack.h"
switches 0:5c4d7b2438d3 25 #include "netsocket/NetworkInterface.h"
switches 0:5c4d7b2438d3 26 #include "rtos/Semaphore.h"
switches 0:5c4d7b2438d3 27
switches 0:5c4d7b2438d3 28
switches 0:5c4d7b2438d3 29 /** TCP socket connection
switches 0:5c4d7b2438d3 30 */
switches 0:5c4d7b2438d3 31 class TCPSocket : public Socket {
switches 0:5c4d7b2438d3 32 public:
switches 0:5c4d7b2438d3 33 /** Create an uninitialized socket
switches 0:5c4d7b2438d3 34 *
switches 0:5c4d7b2438d3 35 * Must call open to initialize the socket on a network stack.
switches 0:5c4d7b2438d3 36 */
switches 0:5c4d7b2438d3 37 TCPSocket();
switches 0:5c4d7b2438d3 38
switches 0:5c4d7b2438d3 39 /** Create a socket on a network interface
switches 0:5c4d7b2438d3 40 *
switches 0:5c4d7b2438d3 41 * Creates and opens a socket on the network stack of the given
switches 0:5c4d7b2438d3 42 * network interface.
switches 0:5c4d7b2438d3 43 *
switches 0:5c4d7b2438d3 44 * @param stack Network stack as target for socket
switches 0:5c4d7b2438d3 45 */
switches 0:5c4d7b2438d3 46 template <typename S>
switches 0:5c4d7b2438d3 47 TCPSocket(S *stack)
switches 0:5c4d7b2438d3 48 : _pending(0), _read_sem(0), _write_sem(0),
switches 0:5c4d7b2438d3 49 _read_in_progress(false), _write_in_progress(false)
switches 0:5c4d7b2438d3 50 {
switches 0:5c4d7b2438d3 51 open(stack);
switches 0:5c4d7b2438d3 52 }
switches 0:5c4d7b2438d3 53
switches 0:5c4d7b2438d3 54 /** Destroy a socket
switches 0:5c4d7b2438d3 55 *
switches 0:5c4d7b2438d3 56 * Closes socket if the socket is still open
switches 0:5c4d7b2438d3 57 */
switches 0:5c4d7b2438d3 58 virtual ~TCPSocket();
switches 0:5c4d7b2438d3 59
switches 0:5c4d7b2438d3 60 /** Connects TCP socket to a remote host
switches 0:5c4d7b2438d3 61 *
switches 0:5c4d7b2438d3 62 * Initiates a connection to a remote server specified by either
switches 0:5c4d7b2438d3 63 * a domain name or an IP address and a port.
switches 0:5c4d7b2438d3 64 *
switches 0:5c4d7b2438d3 65 * @param host Hostname of the remote host
switches 0:5c4d7b2438d3 66 * @param port Port of the remote host
switches 0:5c4d7b2438d3 67 * @return 0 on success, negative error code on failure
switches 0:5c4d7b2438d3 68 */
switches 0:5c4d7b2438d3 69 nsapi_error_t connect(const char *host, uint16_t port);
switches 0:5c4d7b2438d3 70
switches 0:5c4d7b2438d3 71 /** Connects TCP socket to a remote host
switches 0:5c4d7b2438d3 72 *
switches 0:5c4d7b2438d3 73 * Initiates a connection to a remote server specified by the
switches 0:5c4d7b2438d3 74 * indicated address.
switches 0:5c4d7b2438d3 75 *
switches 0:5c4d7b2438d3 76 * @param address The SocketAddress of the remote host
switches 0:5c4d7b2438d3 77 * @return 0 on success, negative error code on failure
switches 0:5c4d7b2438d3 78 */
switches 0:5c4d7b2438d3 79 nsapi_error_t connect(const SocketAddress &address);
switches 0:5c4d7b2438d3 80
switches 0:5c4d7b2438d3 81 /** Send data over a TCP socket
switches 0:5c4d7b2438d3 82 *
switches 0:5c4d7b2438d3 83 * The socket must be connected to a remote host. Returns the number of
switches 0:5c4d7b2438d3 84 * bytes sent from the buffer.
switches 0:5c4d7b2438d3 85 *
switches 0:5c4d7b2438d3 86 * By default, send blocks until data is sent. If socket is set to
switches 0:5c4d7b2438d3 87 * non-blocking or times out, NSAPI_ERROR_WOULD_BLOCK is returned
switches 0:5c4d7b2438d3 88 * immediately.
switches 0:5c4d7b2438d3 89 *
switches 0:5c4d7b2438d3 90 * @param data Buffer of data to send to the host
switches 0:5c4d7b2438d3 91 * @param size Size of the buffer in bytes
switches 0:5c4d7b2438d3 92 * @return Number of sent bytes on success, negative error
switches 0:5c4d7b2438d3 93 * code on failure
switches 0:5c4d7b2438d3 94 */
switches 0:5c4d7b2438d3 95 nsapi_size_or_error_t send(const void *data, nsapi_size_t size);
switches 0:5c4d7b2438d3 96
switches 0:5c4d7b2438d3 97 /** Receive data over a TCP socket
switches 0:5c4d7b2438d3 98 *
switches 0:5c4d7b2438d3 99 * The socket must be connected to a remote host. Returns the number of
switches 0:5c4d7b2438d3 100 * bytes received into the buffer.
switches 0:5c4d7b2438d3 101 *
switches 0:5c4d7b2438d3 102 * By default, recv blocks until data is sent. If socket is set to
switches 0:5c4d7b2438d3 103 * non-blocking or times out, NSAPI_ERROR_WOULD_BLOCK is returned
switches 0:5c4d7b2438d3 104 * immediately.
switches 0:5c4d7b2438d3 105 *
switches 0:5c4d7b2438d3 106 * @param data Destination buffer for data received from the host
switches 0:5c4d7b2438d3 107 * @param size Size of the buffer in bytes
switches 0:5c4d7b2438d3 108 * @return Number of received bytes on success, negative error
switches 0:5c4d7b2438d3 109 * code on failure
switches 0:5c4d7b2438d3 110 */
switches 0:5c4d7b2438d3 111 nsapi_size_or_error_t recv(void *data, nsapi_size_t size);
switches 0:5c4d7b2438d3 112
switches 0:5c4d7b2438d3 113 protected:
switches 0:5c4d7b2438d3 114 friend class TCPServer;
switches 0:5c4d7b2438d3 115
switches 0:5c4d7b2438d3 116 virtual nsapi_protocol_t get_proto();
switches 0:5c4d7b2438d3 117 virtual void event();
switches 0:5c4d7b2438d3 118
switches 0:5c4d7b2438d3 119 volatile unsigned _pending;
switches 0:5c4d7b2438d3 120 rtos::Semaphore _read_sem;
switches 0:5c4d7b2438d3 121 rtos::Semaphore _write_sem;
switches 0:5c4d7b2438d3 122 bool _read_in_progress;
switches 0:5c4d7b2438d3 123 bool _write_in_progress;
switches 0:5c4d7b2438d3 124 };
switches 0:5c4d7b2438d3 125
switches 0:5c4d7b2438d3 126
switches 0:5c4d7b2438d3 127 #endif
switches 0:5c4d7b2438d3 128
switches 0:5c4d7b2438d3 129 /** @}*/