Some quick code to use UDP-only (no TCP) with mBed. Echos received packets and sends packets when a button is pressed
Core/lwIP/include/lwip/sio.h@0:a548a085de55, 2010-03-14 (annotated)
- Committer:
- pehrhovey
- Date:
- Sun Mar 14 00:54:12 2010 +0000
- Revision:
- 0:a548a085de55
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pehrhovey | 0:a548a085de55 | 1 | /* |
pehrhovey | 0:a548a085de55 | 2 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science. |
pehrhovey | 0:a548a085de55 | 3 | * All rights reserved. |
pehrhovey | 0:a548a085de55 | 4 | * |
pehrhovey | 0:a548a085de55 | 5 | * Redistribution and use in source and binary forms, with or without modification, |
pehrhovey | 0:a548a085de55 | 6 | * are permitted provided that the following conditions are met: |
pehrhovey | 0:a548a085de55 | 7 | * |
pehrhovey | 0:a548a085de55 | 8 | * 1. Redistributions of source code must retain the above copyright notice, |
pehrhovey | 0:a548a085de55 | 9 | * this list of conditions and the following disclaimer. |
pehrhovey | 0:a548a085de55 | 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
pehrhovey | 0:a548a085de55 | 11 | * this list of conditions and the following disclaimer in the documentation |
pehrhovey | 0:a548a085de55 | 12 | * and/or other materials provided with the distribution. |
pehrhovey | 0:a548a085de55 | 13 | * 3. The name of the author may not be used to endorse or promote products |
pehrhovey | 0:a548a085de55 | 14 | * derived from this software without specific prior written permission. |
pehrhovey | 0:a548a085de55 | 15 | * |
pehrhovey | 0:a548a085de55 | 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
pehrhovey | 0:a548a085de55 | 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
pehrhovey | 0:a548a085de55 | 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT |
pehrhovey | 0:a548a085de55 | 19 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
pehrhovey | 0:a548a085de55 | 20 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT |
pehrhovey | 0:a548a085de55 | 21 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
pehrhovey | 0:a548a085de55 | 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
pehrhovey | 0:a548a085de55 | 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
pehrhovey | 0:a548a085de55 | 24 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY |
pehrhovey | 0:a548a085de55 | 25 | * OF SUCH DAMAGE. |
pehrhovey | 0:a548a085de55 | 26 | * |
pehrhovey | 0:a548a085de55 | 27 | * This file is part of the lwIP TCP/IP stack. |
pehrhovey | 0:a548a085de55 | 28 | */ |
pehrhovey | 0:a548a085de55 | 29 | |
pehrhovey | 0:a548a085de55 | 30 | /* |
pehrhovey | 0:a548a085de55 | 31 | * This is the interface to the platform specific serial IO module |
pehrhovey | 0:a548a085de55 | 32 | * It needs to be implemented by those platforms which need SLIP or PPP |
pehrhovey | 0:a548a085de55 | 33 | */ |
pehrhovey | 0:a548a085de55 | 34 | |
pehrhovey | 0:a548a085de55 | 35 | #ifndef __SIO_H__ |
pehrhovey | 0:a548a085de55 | 36 | #define __SIO_H__ |
pehrhovey | 0:a548a085de55 | 37 | |
pehrhovey | 0:a548a085de55 | 38 | #include "lwip/arch.h" |
pehrhovey | 0:a548a085de55 | 39 | |
pehrhovey | 0:a548a085de55 | 40 | #ifdef __cplusplus |
pehrhovey | 0:a548a085de55 | 41 | extern "C" { |
pehrhovey | 0:a548a085de55 | 42 | #endif |
pehrhovey | 0:a548a085de55 | 43 | |
pehrhovey | 0:a548a085de55 | 44 | /* If you want to define sio_fd_t elsewhere or differently, |
pehrhovey | 0:a548a085de55 | 45 | define this in your cc.h file. */ |
pehrhovey | 0:a548a085de55 | 46 | #ifndef __sio_fd_t_defined |
pehrhovey | 0:a548a085de55 | 47 | typedef void * sio_fd_t; |
pehrhovey | 0:a548a085de55 | 48 | #endif |
pehrhovey | 0:a548a085de55 | 49 | |
pehrhovey | 0:a548a085de55 | 50 | /* The following functions can be defined to something else in your cc.h file |
pehrhovey | 0:a548a085de55 | 51 | or be implemented in your custom sio.c file. */ |
pehrhovey | 0:a548a085de55 | 52 | |
pehrhovey | 0:a548a085de55 | 53 | #ifndef sio_open |
pehrhovey | 0:a548a085de55 | 54 | /** |
pehrhovey | 0:a548a085de55 | 55 | * Opens a serial device for communication. |
pehrhovey | 0:a548a085de55 | 56 | * |
pehrhovey | 0:a548a085de55 | 57 | * @param devnum device number |
pehrhovey | 0:a548a085de55 | 58 | * @return handle to serial device if successful, NULL otherwise |
pehrhovey | 0:a548a085de55 | 59 | */ |
pehrhovey | 0:a548a085de55 | 60 | sio_fd_t sio_open(u8_t devnum); |
pehrhovey | 0:a548a085de55 | 61 | #endif |
pehrhovey | 0:a548a085de55 | 62 | |
pehrhovey | 0:a548a085de55 | 63 | #ifndef sio_send |
pehrhovey | 0:a548a085de55 | 64 | /** |
pehrhovey | 0:a548a085de55 | 65 | * Sends a single character to the serial device. |
pehrhovey | 0:a548a085de55 | 66 | * |
pehrhovey | 0:a548a085de55 | 67 | * @param c character to send |
pehrhovey | 0:a548a085de55 | 68 | * @param fd serial device handle |
pehrhovey | 0:a548a085de55 | 69 | * |
pehrhovey | 0:a548a085de55 | 70 | * @note This function will block until the character can be sent. |
pehrhovey | 0:a548a085de55 | 71 | */ |
pehrhovey | 0:a548a085de55 | 72 | void sio_send(u8_t c, sio_fd_t fd); |
pehrhovey | 0:a548a085de55 | 73 | #endif |
pehrhovey | 0:a548a085de55 | 74 | |
pehrhovey | 0:a548a085de55 | 75 | #ifndef sio_recv |
pehrhovey | 0:a548a085de55 | 76 | /** |
pehrhovey | 0:a548a085de55 | 77 | * Receives a single character from the serial device. |
pehrhovey | 0:a548a085de55 | 78 | * |
pehrhovey | 0:a548a085de55 | 79 | * @param fd serial device handle |
pehrhovey | 0:a548a085de55 | 80 | * |
pehrhovey | 0:a548a085de55 | 81 | * @note This function will block until a character is received. |
pehrhovey | 0:a548a085de55 | 82 | */ |
pehrhovey | 0:a548a085de55 | 83 | u8_t sio_recv(sio_fd_t fd); |
pehrhovey | 0:a548a085de55 | 84 | #endif |
pehrhovey | 0:a548a085de55 | 85 | |
pehrhovey | 0:a548a085de55 | 86 | #ifndef sio_read |
pehrhovey | 0:a548a085de55 | 87 | /** |
pehrhovey | 0:a548a085de55 | 88 | * Reads from the serial device. |
pehrhovey | 0:a548a085de55 | 89 | * |
pehrhovey | 0:a548a085de55 | 90 | * @param fd serial device handle |
pehrhovey | 0:a548a085de55 | 91 | * @param data pointer to data buffer for receiving |
pehrhovey | 0:a548a085de55 | 92 | * @param len maximum length (in bytes) of data to receive |
pehrhovey | 0:a548a085de55 | 93 | * @return number of bytes actually received - may be 0 if aborted by sio_read_abort |
pehrhovey | 0:a548a085de55 | 94 | * |
pehrhovey | 0:a548a085de55 | 95 | * @note This function will block until data can be received. The blocking |
pehrhovey | 0:a548a085de55 | 96 | * can be cancelled by calling sio_read_abort(). |
pehrhovey | 0:a548a085de55 | 97 | */ |
pehrhovey | 0:a548a085de55 | 98 | u32_t sio_read(sio_fd_t fd, u8_t *data, u32_t len); |
pehrhovey | 0:a548a085de55 | 99 | #endif |
pehrhovey | 0:a548a085de55 | 100 | |
pehrhovey | 0:a548a085de55 | 101 | #ifndef sio_tryread |
pehrhovey | 0:a548a085de55 | 102 | /** |
pehrhovey | 0:a548a085de55 | 103 | * Tries to read from the serial device. Same as sio_read but returns |
pehrhovey | 0:a548a085de55 | 104 | * immediately if no data is available and never blocks. |
pehrhovey | 0:a548a085de55 | 105 | * |
pehrhovey | 0:a548a085de55 | 106 | * @param fd serial device handle |
pehrhovey | 0:a548a085de55 | 107 | * @param data pointer to data buffer for receiving |
pehrhovey | 0:a548a085de55 | 108 | * @param len maximum length (in bytes) of data to receive |
pehrhovey | 0:a548a085de55 | 109 | * @return number of bytes actually received |
pehrhovey | 0:a548a085de55 | 110 | */ |
pehrhovey | 0:a548a085de55 | 111 | u32_t sio_tryread(sio_fd_t fd, u8_t *data, u32_t len); |
pehrhovey | 0:a548a085de55 | 112 | #endif |
pehrhovey | 0:a548a085de55 | 113 | |
pehrhovey | 0:a548a085de55 | 114 | #ifndef sio_write |
pehrhovey | 0:a548a085de55 | 115 | /** |
pehrhovey | 0:a548a085de55 | 116 | * Writes to the serial device. |
pehrhovey | 0:a548a085de55 | 117 | * |
pehrhovey | 0:a548a085de55 | 118 | * @param fd serial device handle |
pehrhovey | 0:a548a085de55 | 119 | * @param data pointer to data to send |
pehrhovey | 0:a548a085de55 | 120 | * @param len length (in bytes) of data to send |
pehrhovey | 0:a548a085de55 | 121 | * @return number of bytes actually sent |
pehrhovey | 0:a548a085de55 | 122 | * |
pehrhovey | 0:a548a085de55 | 123 | * @note This function will block until all data can be sent. |
pehrhovey | 0:a548a085de55 | 124 | */ |
pehrhovey | 0:a548a085de55 | 125 | u32_t sio_write(sio_fd_t fd, u8_t *data, u32_t len); |
pehrhovey | 0:a548a085de55 | 126 | #endif |
pehrhovey | 0:a548a085de55 | 127 | |
pehrhovey | 0:a548a085de55 | 128 | #ifndef sio_read_abort |
pehrhovey | 0:a548a085de55 | 129 | /** |
pehrhovey | 0:a548a085de55 | 130 | * Aborts a blocking sio_read() call. |
pehrhovey | 0:a548a085de55 | 131 | * |
pehrhovey | 0:a548a085de55 | 132 | * @param fd serial device handle |
pehrhovey | 0:a548a085de55 | 133 | */ |
pehrhovey | 0:a548a085de55 | 134 | void sio_read_abort(sio_fd_t fd); |
pehrhovey | 0:a548a085de55 | 135 | #endif |
pehrhovey | 0:a548a085de55 | 136 | |
pehrhovey | 0:a548a085de55 | 137 | #ifdef __cplusplus |
pehrhovey | 0:a548a085de55 | 138 | } |
pehrhovey | 0:a548a085de55 | 139 | #endif |
pehrhovey | 0:a548a085de55 | 140 | |
pehrhovey | 0:a548a085de55 | 141 | #endif /* __SIO_H__ */ |