]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/net/lwip_tcpip/v2_0/tests/sys_timeout.c
unified MX27, MX25, MX37 trees
[karo-tx-redboot.git] / packages / net / lwip_tcpip / v2_0 / tests / sys_timeout.c
1 //==========================================================================
2 //####ECOSGPLCOPYRIGHTBEGIN####
3 // -------------------------------------------
4 // This file is part of eCos, the Embedded Configurable Operating System.
5 // Copyright (C) 2004 eCosCentric
6 //
7 // eCos is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU General Public License as published by the Free
9 // Software Foundation; either version 2 or (at your option) any later version.
10 //
11 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
12 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 // for more details.
15 //
16 // You should have received a copy of the GNU General Public License along
17 // with eCos; if not, write to the Free Software Foundation, Inc.,
18 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19 //
20 // As a special exception, if other files instantiate templates or use macros
21 // or inline functions from this file, or you compile this file and link it
22 // with other works to produce a work based on this file, this file does not
23 // by itself cause the resulting work to be covered by the GNU General Public
24 // License. However the source code for this file must still be made available
25 // in accordance with section (3) of the GNU General Public License.
26 //
27 // This exception does not invalidate any other reasons why a work based on
28 // this file might be covered by the GNU General Public License.
29 // -------------------------------------------
30 //####ECOSGPLCOPYRIGHTEND####
31 //==========================================================================
32
33 /* Simple test-case for the lwip system timeout functionality  */
34
35 #include "lwip/sys.h"
36
37 #define TIMERS 100
38 sys_timeout_handler timers[TIMERS];
39 int intervals[TIMERS];
40
41 static void
42 timeout_fn ( void * arg)
43 {
44         int i, j = (int)arg;
45 //      diag_printf("Timeout #%d called\n", (int)arg);
46         for (i = 0; i < j; i++)
47                 diag_printf(" ");
48         diag_printf("%d\n", j);
49 //      sys_timeout( intervals[j], timers[j], arg);     
50         sys_timeout( 1000, timers[j], arg);     
51 }
52
53 static void
54 timeout_thread(void *arg)
55 {
56   int i;
57   
58   for (i = 0; i < TIMERS; i++) {
59           diag_printf("Adding timer #%d\n", i);
60           timers[i] = timeout_fn;
61           intervals[i] = (i+1)*1000;    
62           sys_timeout(intervals[i],  timers[i], (void *)i);
63   }
64   sys_msleep(0); 
65   diag_printf("Done\n");
66 }
67
68 void
69 tmain(cyg_addrword_t p)
70 {
71   lwip_init();  
72   sys_thread_new(timeout_thread, (void*)"timeout",7);
73 }
74
75 #define STACK_SIZE 0x1000
76 static char stack[STACK_SIZE];
77 static cyg_thread thread_data;
78 static cyg_handle_t thread_handle;
79
80 void
81 cyg_user_start(void)
82 {
83     // Create a main thread, so we can run the scheduler and have time 'pass'
84     cyg_thread_create(10,                // Priority - just a number
85                       tmain,          // entry
86                       0,                 // entry parameter
87                       "timeout test",        // Name
88                       &stack[0],         // Stack
89                       STACK_SIZE,        // Size
90                       &thread_handle,    // Handle
91                       &thread_data       // Thread data structure
92             );
93     cyg_thread_resume(thread_handle);  // Start it
94 }
95