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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [net/] [lwip_tcpip/] [current/] [tests/] [udpecho.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
//      udpecho.c
4
//
5
//      Simple test-case for the netconn UDP API: echo on UDP 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 UDP API: echo on UDP 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_UDP
60
 
61
#define UDP_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 udpecho_stack[STACK_SIZE];
70
 
71
static char buffer[100];
72
 
73
void
74
udpecho_thread_entry(void *arg)
75
{
76
    struct netconn *conn;
77
    struct netbuf *buf;
78
    struct ip_addr *addr;
79
    unsigned short port;
80
 
81
    conn = netconn_new(NETCONN_UDP);
82
    netconn_bind(conn, NULL, UDP_PORT);
83
 
84
    while (1) {
85
        buf = netconn_recv(conn);
86
        addr = netbuf_fromaddr(buf);
87
        port = netbuf_fromport(buf);
88
        netconn_connect(conn, addr, port);
89
        netconn_send(conn, buf);
90
        netbuf_copy(buf, buffer, sizeof(buffer));
91
        netbuf_delete(buf);
92
    }
93
}
94
 
95
void
96
main_thread_entry(cyg_addrword_t p)
97
{
98
    cyg_lwip_sequential_init();
99
    cyg_lwip_thread_new("udpecho", udpecho_thread_entry, NULL,
100
                        udpecho_stack, STACK_SIZE, 7);
101
}
102
 
103
void
104
udpecho_main(void)
105
{
106
    CYG_TEST_INIT();
107
    CYG_TEST_INFO("Testing UDP");
108
    diag_printf("This test will echo UDP packets on local port %d\n", UDP_PORT);
109
 
110
    // Create a main thread, so we can run the scheduler and have time 'pass'
111
    cyg_thread_create(
112
        10,                 // Priority - just a number
113
        main_thread_entry,  // Entry
114
        0,                  // Entry parameter
115
        "main",             // Name
116
        main_stack,         // Stack
117
        STACK_SIZE,         // Size
118
        &main_handle,       // Handle
119
        &main_thread        // Thread data structure
120
    );
121
    cyg_thread_resume(main_handle);
122
    cyg_scheduler_start();
123
 
124
    CYG_TEST_FAIL_FINISH("Not reached");
125
}
126
 
127
externC void
128
cyg_start( void )
129
{
130
    udpecho_main();
131
}
132
 
133
#else // LWIP_UDP
134
#define N_A_MSG "UDP support disabled"
135
#endif // LWIP_UDP
136
 
137
#else // LWIP_NETCONN
138
#define N_A_MSG "NETCONN support disabled"
139
#endif // LWIP_NETCONN
140
 
141
#else // CYGFUN_LWIP_MODE_SEQUENTIAL
142
#define N_A_MSG "Not configured in 'Sequential' mode"
143
#endif // CYGFUN_LWIP_MODE_SEQUENTIAL
144
 
145
#ifdef N_A_MSG
146
externC void
147
cyg_start(void)
148
{
149
    CYG_TEST_INIT();
150
    CYG_TEST_NA(N_A_MSG);
151
}
152
#endif // N_A_MSG

powered by: WebSVN 2.1.0

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