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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [net/] [common/] [v2_0/] [tests/] [tftp_client_test.c] - Blame information for rev 174

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
//==========================================================================
2
//
3
//      tests/tftp_client_test.c
4
//
5
//      Simple TFTP client test
6
//
7
//==========================================================================
8
//####BSDCOPYRIGHTBEGIN####
9
//
10
// -------------------------------------------
11
//
12
// Portions of this software may have been derived from OpenBSD or other sources,
13
// and are covered by the appropriate copyright disclaimers included herein.
14
//
15
// -------------------------------------------
16
//
17
//####BSDCOPYRIGHTEND####
18
//==========================================================================
19
//#####DESCRIPTIONBEGIN####
20
//
21
// Author(s):    gthomas
22
// Contributors: gthomas
23
// Date:         2000-04-07
24
// Purpose:      
25
// Description:  
26
//              
27
//
28
//####DESCRIPTIONEND####
29
//
30
//==========================================================================
31
// TFTP test code
32
 
33
#include <network.h>
34
#include <tftp_support.h>
35
 
36
// Note: the TFTP client calls need at least (SEGSIZE==512)+4
37
// additional bytes of workspace, thus the padding.
38
#define STACK_SIZE (CYGNUM_HAL_STACK_SIZE_TYPICAL+0x1000)
39
static char stack[STACK_SIZE];
40
static cyg_thread thread_data;
41
static cyg_handle_t thread_handle;
42
 
43
#define min(x,y) (x<y ? x : y)
44
 
45
extern void
46
cyg_test_exit(void);
47
 
48
void
49
pexit(char *s)
50
{
51
    perror(s);
52
    cyg_test_exit();
53
}
54
 
55
static char buf[32*1024];
56
 
57
#define GETFILE "/tftpboot/tftp_get"
58
#define PUTFILE "/tftpboot/tftp_put"
59
 
60
static void
61
tftp_test(struct bootp *bp)
62
{
63
    int res, err, len;
64
    struct sockaddr_in host;
65
 
66
    memset((char *)&host, 0, sizeof(host));
67
    host.sin_len = sizeof(host);
68
    host.sin_family = AF_INET;
69
    host.sin_addr = bp->bp_siaddr;
70
    host.sin_port = 0;
71
    diag_printf("Trying tftp_get %s %16s...\n", GETFILE, inet_ntoa(host.sin_addr));
72
    res = tftp_get( GETFILE, &host, buf, sizeof(buf), TFTP_OCTET, &err);
73
    diag_printf("res = %d, err = %d\n", res, err);
74
    if (res > 0) {
75
        diag_dump_buf(buf, min(res,1024));
76
    }
77
    len = res;
78
    diag_printf("Trying tftp_put %d %16s, length %d\n",
79
                PUTFILE, inet_ntoa(host.sin_addr), len);
80
    res = tftp_put( PUTFILE, &host, buf, len, TFTP_OCTET, &err);
81
    diag_printf("put - res: %d\n", res);
82
}
83
 
84
void
85
net_test(cyg_addrword_t param)
86
{
87
    diag_printf("Start TFTP test\n");
88
    init_all_network_interfaces();
89
#ifdef CYGHWR_NET_DRIVER_ETH0
90
    if (eth0_up) {
91
        tftp_test(&eth0_bootp_data);
92
    }
93
#endif
94
#ifdef CYGHWR_NET_DRIVER_ETH1
95
    if (eth1_up) {
96
        tftp_test(&eth1_bootp_data);
97
    }
98
#endif
99
    cyg_test_exit();
100
}
101
 
102
void
103
cyg_start(void)
104
{
105
    // Create a main thread, so we can run the scheduler and have time 'pass'
106
    cyg_thread_create(10,                // Priority - just a number
107
                      net_test,          // entry
108
                      0,                 // entry parameter
109
                      "Network test",    // Name
110
                      &stack[0],         // Stack
111
                      STACK_SIZE,        // Size
112
                      &thread_handle,    // Handle
113
                      &thread_data       // Thread data structure
114
            );
115
    cyg_thread_resume(thread_handle);  // Start it
116
    cyg_scheduler_start();
117
}

powered by: WebSVN 2.1.0

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