OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [net/] [lwip_tcpip/] [current/] [tests/] [tcpecho.c] - Blame information for rev 865

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//      tcpecho.c
4
//
5
//      Simple test-case for the netconn TCP API: echo on TCP port 7.
6
//
7
//==========================================================================
8
//####ECOSGPLCOPYRIGHTBEGIN####
9
// -------------------------------------------
10
// This file is part of eCos, the Embedded Configurable Operating System.
11
// Copyright (C) 2009 Free Software Foundation
12
//
13
// eCos is free software; you can redistribute it and/or modify it under
14
// the terms of the GNU General Public License as published by the Free
15
// Software Foundation; either version 2 or (at your option) any later version.
16
//
17
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
18
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
19
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
20
// for more details.
21
//
22
// You should have received a copy of the GNU General Public License along
23
// with eCos; if not, write to the Free Software Foundation, Inc.,
24
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
25
//
26
// As a special exception, if other files instantiate templates or use macros
27
// or inline functions from this file, or you compile this file and link it
28
// with other works to produce a work based on this file, this file does not
29
// by itself cause the resulting work to be covered by the GNU General Public
30
// License. However the source code for this file must still be made available
31
// in accordance with section (3) of the GNU General Public License.
32
//
33
// This exception does not invalidate any other reasons why a work based on
34
// this file might be covered by the GNU General Public License.
35
// -------------------------------------------
36
//####ECOSGPLCOPYRIGHTEND####
37
//==========================================================================
38
//#####DESCRIPTIONBEGIN####
39
//
40
// Author(s):    Simon Kallweit
41
// Contributors:
42
// Date:         2009-05-18
43
// Purpose:
44
// Description:  Simple test-case for the netconn TCP API: echo on TCP port 7.
45
//
46
//####DESCRIPTIONEND####
47
//
48
//==========================================================================
49
 
50
#include <cyg/hal/hal_arch.h>
51
#include <cyg/infra/diag.h>
52
#include <cyg/infra/testcase.h>
53
#include <cyg/kernel/kapi.h>
54
 
55
#include <lwip.h>
56
 
57
#ifdef CYGFUN_LWIP_MODE_SEQUENTIAL
58
#if LWIP_NETCONN
59
#if LWIP_TCP
60
 
61
#define TCP_PORT 7
62
 
63
#define STACK_SIZE CYGNUM_HAL_STACK_SIZE_TYPICAL
64
 
65
static char main_stack[STACK_SIZE];
66
static cyg_thread main_thread;
67
static cyg_handle_t main_handle;
68
 
69
static char tcpecho_stack[STACK_SIZE];
70
 
71
static void tcpecho_thread_entry(void *arg)
72
{
73
    struct netconn *conn, *newconn;
74
    err_t err;
75
 
76
    // Create a new connection identifier
77
    conn = netconn_new(NETCONN_TCP);
78
 
79
    // Bind connection to well known port number 7
80
    netconn_bind(conn, NULL, 7);
81
 
82
    // Tell connection to go into listening mode
83
    netconn_listen(conn);
84
 
85
    while (1) {
86
        // Accept new connection
87
        newconn = netconn_accept(conn);
88
 
89
        // Process new connection
90
        if (newconn != NULL) {
91
            struct netbuf *buf;
92
            void *data;
93
            u16_t len;
94
 
95
            while ((buf = netconn_recv(newconn)) != NULL) {
96
                do {
97
                    netbuf_data(buf, &data, &len);
98
                    err = netconn_write(newconn, data, len, NETCONN_COPY);
99
                    if (err != ERR_OK) {
100
                    }
101
                } while (netbuf_next(buf) >= 0);
102
                netbuf_delete(buf);
103
            }
104
 
105
            // Close connection and discard connection identifier
106
            netconn_delete(newconn);
107
        }
108
    }
109
}
110
 
111
void main_thread_entry(cyg_addrword_t p)
112
{
113
    cyg_lwip_sequential_init();
114
    cyg_lwip_thread_new("tcpecho", tcpecho_thread_entry, NULL,
115
                        tcpecho_stack, STACK_SIZE, 7);
116
}
117
 
118
void tcpecho_main(void)
119
{
120
    CYG_TEST_INIT();
121
    CYG_TEST_INFO("Testing TCP");
122
    diag_printf("This test will echo TCP packets on local port %d\n", TCP_PORT);
123
 
124
    // Create a main thread, so we can run the scheduler and have time 'pass'
125
    cyg_thread_create(
126
        10,                 // Priority - just a number
127
        main_thread_entry,  // Entry
128
        0,                  // Entry parameter
129
        "main",             // Name
130
        main_stack,         // Stack
131
        STACK_SIZE,         // Size
132
        &main_handle,       // Handle
133
        &main_thread        // Thread data structure
134
    );
135
    cyg_thread_resume(main_handle);
136
    cyg_scheduler_start();
137
 
138
    CYG_TEST_FAIL_FINISH("Not reached");
139
}
140
 
141
externC void cyg_start(void)
142
{
143
    tcpecho_main();
144
}
145
 
146
#else // LWIP_TCP
147
#define N_A_MSG "TCP support disabled"
148
#endif // LWIP_TCP
149
 
150
#else // LWIP_NETCONN
151
#define N_A_MSG "NETCONN support disabled"
152
#endif // LWIP_NETCONN
153
 
154
#else // CYGFUN_LWIP_MODE_SEQUENTIAL
155
#define N_A_MSG "Not configured in 'Sequential' mode"
156
#endif // CYGFUN_LWIP_MODE_SEQUENTIAL
157
 
158
#ifdef N_A_MSG
159
externC void
160
cyg_start(void)
161
{
162
    CYG_TEST_INIT();
163
    CYG_TEST_NA(N_A_MSG);
164
}
165
#endif // N_A_MSG

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.