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

Subversion Repositories funbase_ip_library

[/] [funbase_ip_library/] [trunk/] [TUT/] [ip.hwp.interface/] [udp2hibi/] [1.0/] [drv/] [udp2hibi.c] - Blame information for rev 183

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 145 lanttu
/*
2
 * Driver functions for UDP2HIBI block.
3
 *
4
 * These are more like examples, so modify if you see it necessary
5
 *
6
 * Original author: Jussi Nieminen
7
 * Last update: 7.1.2010
8
 * History:
9
 *  7.1.2010: created
10
 */
11
 
12
#include "udp2hibi.h"
13 183 lanttu
#include "system.h"
14 145 lanttu
 
15 183 lanttu
 
16 145 lanttu
 
17
 
18
int udp2hibi_rx_conf( int ip_addr, int dest_port, int source_port, int receiving_haddr, int udp2hibi_haddr ) {
19
 
20
    // todo: check that ip and ports are valid
21
 
22
    // wait tx to finish
23 183 lanttu
    while ( !HPD_TX_DONE( (int*)N2H_REGISTERS_BASE_ADDRESS )) {}
24 145 lanttu
 
25
    // set up n2h2 to receive ack/nack sent to receiving_haddr
26
    N2H_CHAN_CONF( 0, N2H_REGISTERS_RX_BUFFER_START, receiving_haddr, 1, N2H_REGISTERS_BASE_ADDRESS);
27
 
28
    // set n2h2 to send udp2hibi's rx_conf command to addr 0x01000000, responding to 03000000
29
    *((int*)N2H_REGISTERS_TX_BUFFER_START + 0) = 0x30000000;
30
    *((int*)N2H_REGISTERS_TX_BUFFER_START + 1) = ip_addr;
31
    *((int*)N2H_REGISTERS_TX_BUFFER_START + 2) = (dest_port << 16) | source_port;
32
    *((int*)N2H_REGISTERS_TX_BUFFER_START + 3) = receiving_haddr;
33
 
34
    N2H_SEND( N2H_REGISTERS_TX_BUFFER_START, 4, udp2hibi_haddr, N2H_REGISTERS_BASE_ADDRESS );
35
 
36
    return 1;
37
}
38
 
39
 
40
int udp2hibi_tx_conf( unsigned int timeout, int ip_addr, int dest_port, int source_port, int receiving_haddr, int udp2hibi_haddr ) {
41
 
42
    // todo: other info
43
 
44
    // timeout must be under 2^28, so that 4 first bits of tx will be zeros (tx conf header)
45
    if ( timeout > 0x0FFFFFFF ) {
46
        return 0;
47
    }
48
 
49
    // wait tx to finish
50
    while ( !N2H_TX_DONE( (int*)N2H_REGISTERS_BASE_ADDRESS )) {}
51
 
52
    // set n2h2 to wait for an ack
53
    N2H_CHAN_CONF( 0, N2H_REGISTERS_RX_BUFFER_START, receiving_haddr, 1, N2H_REGISTERS_BASE_ADDRESS);
54
 
55
    // tx conf
56
    *((int*)N2H_REGISTERS_TX_BUFFER_START + 0) = timeout;
57
    *((int*)N2H_REGISTERS_TX_BUFFER_START + 1) = ip_addr;
58
    *((int*)N2H_REGISTERS_TX_BUFFER_START + 2) = (dest_port << 16) | source_port;
59
    *((int*)N2H_REGISTERS_TX_BUFFER_START + 3) = receiving_haddr;
60
 
61
    N2H_SEND( N2H_REGISTERS_TX_BUFFER_START, 4, udp2hibi_haddr, N2H_REGISTERS_BASE_ADDRESS );
62
 
63
    return 1;
64
}
65
 
66
 
67
 
68
int udp2hibi_check_tx_ack( unsigned int received_header ) {
69
 
70
    // an ack starts with 0x5, and if bit 27 is '1', it's a tx ack
71
    // so header >> 27 should be 0b01011 = 11 
72
    if ( (received_header >> 27) == 11 ) {
73
        // success
74
        return 1;
75
    }
76
    return 0;
77
}
78
 
79
 
80
int udp2hibi_check_rx_ack( unsigned int received_header ) {
81
 
82
    // an ack starts with 0x5, and if bit 27 is '0', it's a rx ack
83
    // so header >> 27 should be 0b01010 = 10 
84
    if ( (received_header >> 27) == 10 ) {
85
        // success
86
        return 1;
87
    }
88
    return 0;
89
}
90
 
91
 
92
 
93
void udp2hibi_write_data_header( int* mem_addr, int tx_length ) {
94
 
95
    // check that length is correct ( 0 < len <= ethernet packet size - headers )
96
    // (ethernet pkt - eth headers/checksum - ip headers - udp headers
97
    //  = 1518 - 18 - 20 - 8 = 1472) 
98
    if ( tx_length < 1 || tx_length > 1472 ) {
99
        return 0;
100
    }
101
    // if correct, write the header
102
    *mem_addr = (1 << 28) | (tx_length << 17);
103
    return 1;
104
}
105
 
106
 
107
 
108
void udp2hibi_release_lock( int udp2hibi_haddr ) {
109
 
110
    // wait tx to finish
111
    while (!N2H_TX_DONE( (int*)N2H_REGISTERS_BASE_ADDRESS ) ){}
112
 
113
    // write the release header to memory
114
    *(int*)N2H_REGISTERS_TX_BUFFER_START = 0x20000000;
115
    // send
116
    N2H_SEND( N2H_REGISTERS_TX_BUFFER_START, 1, udp2hibi_haddr, N2H_REGISTERS_BASE_ADDRESS );
117
}
118
 
119
 
120
 
121
 
122
 
123
 
124
 
125
 
126
 
127
 
128
 
129
 
130
 
131
 

powered by: WebSVN 2.1.0

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