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.communication/] [hibi_pe_dma/] [1.0/] [tb/] [system/] [src_cpu1/] [main.c] - Blame information for rev 145

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 145 lanttu
/*
2
 * main.c
3
 *
4
 *  Created on: 22.2.2011
5
 *      Author: lehton87
6
 */
7
 
8
#include <stdio.h>
9
#include <stdlib.h>
10
#include <string.h>
11
#include <io.h>
12
#include <unistd.h>
13
 
14
#include "system.h"
15
#include "hpd_registers_conf.h"
16
#include "hpd_macros.h"
17
#include "hpd_isr_fifo.h"
18
 
19
#include "support.h"
20
 
21
 
22
int main()
23
{
24
  int n_received = 0;
25
  int rx_data[20];
26
  int rx_amount = 8;
27
  int tx_amount = 8;
28
  int send      = 0;
29
 
30
  int channels[8] = {0, 0, 0, 0, 0, 0, 0, 0};
31
 
32
  Hpd_isr_fifo* hpd_isr_fifo = hpd_isr_fifo_create();
33
 
34
  // Init HIBI PE DMA interrupt
35
  hpd_isr_init(hpd_isr_fifo);
36
 
37
  int tx_data1[] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
38
  int tx_data2[] = {0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18};
39
  int tx_data3[] = {0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28};
40
  int tx_data4[] = {0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38};
41
 
42
  usleep(20);
43
 
44
  printf("CPU1: starts\n");
45
 
46
  memcpy((int*)HPD_REGISTERS_TX_BUFFER_START, (int*)tx_data1,
47
         tx_amount*sizeof(int));
48
 
49
  memcpy((int*)(HPD_REGISTERS_TX_BUFFER_START + tx_amount*sizeof(int)),
50
         (int*)tx_data2, tx_amount*sizeof(int));
51
 
52
  memcpy((int*)(HPD_REGISTERS_TX_BUFFER_START + 2*tx_amount*sizeof(int)),
53
         (int*)tx_data3, tx_amount*sizeof(int));
54
 
55
  memcpy((int*)(HPD_REGISTERS_TX_BUFFER_START + 3*tx_amount*sizeof(int)),
56
         (int*)tx_data4, tx_amount*sizeof(int));
57
 
58
 
59
  //
60
  // Add/remove some sends if you want more/less traffic
61
  //
62
 
63
  // poll until tx is empty and then send
64
  while(((IORD(HIBI_PE_DMA_BASE, 4) >> 16) & 0x1) == 0) {/* idle */}
65
  hpd_send(HPD_REGISTERS_TX_BUFFER_START, tx_amount, 0x001);
66
 
67
  //
68
 
69
  while(1)
70
    {
71
      // Handle info from interrupts if any
72
      if(hpd_isr_fifo_size(hpd_isr_fifo))
73
        {
74
          Hpd_isr_info* info = hpd_isr_fifo_pop(hpd_isr_fifo);
75
 
76
          switch(info->isr_type)
77
            {
78
            case RX_READY:
79
 
80
              printf("CPU1: received %ith packet to channel %i\n",
81
                     ++n_received, info->rx_channel);
82
 
83
 
84
              if(channels[info->rx_channel] == 2)
85
                {
86
                  channels[info->rx_channel] = 0;
87
                  break;
88
                }
89
 
90
              memcpy((int*)rx_data, (int*)(HPD_REGISTERS_RX_BUFFER_START +
91
                                           info->rx_channel * rx_amount*
92
                                           sizeof(int)),
93
                     rx_amount*sizeof(int));
94
 
95
              printf("CPU1: read data from channel %i : %X %X %X %X %X "
96
                     "%X %X %X\n",
97
                     info->rx_channel, rx_data[0], rx_data[1], rx_data[2],
98
                     rx_data[3], rx_data[4], rx_data[5], rx_data[6],
99
                     rx_data[7]);
100
 
101
              channels[info->rx_channel] = 0;
102
 
103
              // Init rx chan half the time
104
              int src = (rand() % 2 == 0) ? 0x00 : 0x20;
105
              if(rand() % 2 == 0)
106
                {
107
                  int i = 0;
108
 
109
                  for(i = 0; i < 5; ++i)
110
                    {
111
                      if(channels[i] == 0)
112
                        {
113
                          channels[i] = 1;
114
                          hpd_init_rx(i, 8*i*sizeof(int), 8, 0x200 + i + src);
115
                          break;
116
                        }
117
                    }
118
                }
119
 
120
              send++;
121
 
122
              int fre = 0;
123
              int x = 0;
124
              for(; x < 8; ++x) {if(channels[x]== 0) fre++;}
125
              printf("CPU1: %i to send, %i in FIFO, %i channels free\n",
126
                     send, hpd_isr_fifo_size(hpd_isr_fifo), fre);
127
 
128
              break;
129
 
130
            case RX_UNKNOWN:
131
              {
132
                int cha = 0;
133
 
134
                for(cha = 0; cha < 8; ++cha)
135
                  {
136
                    if(channels[cha] == 0)
137
                      {
138
                        channels[cha] = (info->dst_address == 0x3FF) ? 2 : 1;
139
 
140
                        printf("CPU1: received data to unconfigured "
141
                               "address 0x%X, assigning to channel %i\n",
142
                       info->dst_address, cha);
143
 
144
                        if(!(0x200 <= info->dst_address &&
145
                             info->dst_address <= 0x3FF))
146
                          {
147
                            printf("CPU1: %i is invalid address, FAILURE\n",
148
                                   info->dst_address);
149
                          }
150
 
151
                        // Initialize some channel to receive
152
                        hpd_init_rx(cha, cha * rx_amount*sizeof(int), rx_amount,
153
                                    info->dst_address);
154
 
155
                        break;
156
                      }
157
                  }
158
 
159
                int fre = 0;
160
                int x = 0;
161
                for(; x < 8; ++x) {if(channels[x]== 0) fre++;}
162
                printf("CPU1: %i to send, %i in FIFO, %i channels free\n",
163
                       send, hpd_isr_fifo_size(hpd_isr_fifo), fre);
164
 
165
              }
166
              break;
167
 
168
            case TX_IGNORED:
169
              {
170
                printf("CPU1: A transfer was ignored because it overlapped"
171
                       " previous one\n");
172
 
173
                int fre = 0;
174
                int x = 0;
175
                for(; x < 8; ++x) {if(channels[x]== 0) fre++;}
176
                printf("CPU1: %i to send, %i in FIFO, %i channels free\n",
177
                       send, hpd_isr_fifo_size(hpd_isr_fifo), fre);
178
              }
179
              break;
180
 
181
            }
182
 
183
          // Free memory
184
          free(info); info = NULL;
185
        }
186
      else if(send > 0 && (((IORD(HIBI_PE_DMA_BASE, 4) >> 16) & 0x1) == 1))
187
        {
188
          // Send packet to a random target's random address
189
          int target_addr;
190
          int tx_data[8];
191
          int tx_slot = (rand() % 8);
192
          int cha;
193
 
194
          if(rand() % 2 == 0)
195
            {
196
              target_addr = 0x010 + tx_slot;
197
            }
198
          else
199
            {
200
              target_addr = 0x410 + tx_slot;
201
            }
202
 
203
          for(cha = 0; cha < 8; ++cha)
204
            tx_data[cha] = 0x81000000 | ((cha+1) << 16) | target_addr;
205
 
206
          memcpy((int*)(HPD_REGISTERS_TX_BUFFER_START +
207
                        tx_slot*tx_amount*sizeof(int)),
208
                 (int*)tx_data, tx_amount*sizeof(int));
209
 
210
          printf("CPU1: sending packet to 0x%X\n", target_addr);
211
 
212
          hpd_send(HPD_REGISTERS_TX_BUFFER_START +
213
                   tx_slot*tx_amount*sizeof(int),
214
                   tx_amount, target_addr);
215
 
216
          send--;
217
 
218
 
219
          // Overlapping with previous one hopefully
220
          if((rand() % 100) < 50)
221
            {
222
              hpd_send(HPD_REGISTERS_TX_BUFFER_START +
223
                       tx_slot*tx_amount*sizeof(int),
224
                       tx_amount, 0x5FF);
225
              printf("CPU1: sending hazard packet\n");
226
            }
227
          int fre = 0;
228
          int x = 0;
229
          for(; x < 8; ++x) {if(channels[x]== 0) fre++;}
230
          printf("CPU1: %i to send, %i in FIFO, %i channels free\n",
231
                 send, hpd_isr_fifo_size(hpd_isr_fifo), fre);
232
        }
233
    }
234
 
235
  //
236
 
237
  printf("CPU1: retires!\n");
238
  while(1); return 0;
239
}

powered by: WebSVN 2.1.0

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