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

Subversion Repositories openrisc

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

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

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//      sys_timeout.c
4
//
5
//      Simple test-case for the lwip system timeout functionality.
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 lwip system timeout functionality.
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
 
54
#include <pkgconf/net_lwip.h>
55
 
56
#include <lwip.h>
57
 
58
#define TIMERS 10
59
 
60
#ifdef CYGFUN_LWIP_MODE_SEQUENTIAL
61
#if MEMP_NUM_SYS_TIMEOUT >= (TIMERS + 6)
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 timeout_stack[STACK_SIZE];
70
 
71
static int timeouts = 0;
72
 
73
static void timeout_fn(void * arg)
74
{
75
    int i = (int) arg;
76
 
77
    diag_printf("Timeout timer #%d\n", i);
78
 
79
    if (i != timeouts++)
80
        CYG_TEST_FAIL_EXIT("Timeout out of order");
81
 
82
    if (timeouts == TIMERS)
83
        CYG_TEST_FINISH("Test successful");
84
}
85
 
86
static void timeout_thread_entry(void *arg)
87
{
88
    int i;
89
 
90
    for (i = 0; i < TIMERS; i++) {
91
        diag_printf("Adding timer #%d\n", i);
92
        sys_timeout((i + 1) * 100, timeout_fn, (void *) i);
93
    }
94
    sys_msleep(0);
95
}
96
 
97
void main_thread_entry(cyg_addrword_t p)
98
{
99
    cyg_lwip_sequential_init();
100
    cyg_lwip_thread_new("timeout", timeout_thread_entry, NULL,
101
                        timeout_stack, STACK_SIZE, 7);
102
}
103
 
104
externC void
105
cyg_start(void)
106
{
107
    CYG_TEST_INIT();
108
    CYG_TEST_INFO("Testing timeouts");
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
#else // MEMP_NUM_SYS_TIMEOUT >= (TIMERS + 6)
128
#define N_A_MSG "Timeout memory pool is too small"
129
#endif // MEMP_NUM_SYS_TIMEOUT >= (TIMERS + 6)
130
 
131
#else // CYGFUN_LWIP_MODE_SEQUENTIAL
132
#define N_A_MSG "Not configured in 'Sequential' mode"
133
#endif // CYGFUN_LWIP_MODE_SEQUENTIAL
134
 
135
#ifdef N_A_MSG
136
externC void
137
cyg_start(void)
138
{
139
    CYG_TEST_INIT();
140
    CYG_TEST_NA(N_A_MSG);
141
}
142
#endif // N_A_MSG

powered by: WebSVN 2.1.0

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