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_cpu2/] [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
  printf("CPU2: starts\n");
38
 
39
  while(1)
40
    {
41
      if(hpd_isr_fifo_size(hpd_isr_fifo))
42
        {
43
          Hpd_isr_info* info = hpd_isr_fifo_pop(hpd_isr_fifo);
44
 
45
          switch(info->isr_type)
46
            {
47
            case RX_READY:
48
 
49
              printf("CPU2: received %ith packet to channel %i\n",
50
                     ++n_received, info->rx_channel);
51
 
52
              if(channels[info->rx_channel] == 2)
53
                {
54
                  channels[info->rx_channel] = 0;
55
                  break;
56
                }
57
 
58
              memcpy((int*)rx_data, (int*)(HPD_REGISTERS_RX_BUFFER_START +
59
                                           info->rx_channel * rx_amount *
60
                                           sizeof(int)),
61
                     rx_amount*sizeof(int));
62
 
63
              printf("CPU2: read data from channel %i : %X %X %X %X %X "
64
                     "%X %X %X\n",
65
                     info->rx_channel, rx_data[0], rx_data[1], rx_data[2],
66
                     rx_data[3], rx_data[4], rx_data[5], rx_data[6],
67
                     rx_data[7]);
68
 
69
              channels[info->rx_channel] = 0;
70
 
71
              // Init rx chan half the time
72
              int src = (rand() % 2 == 0) ? 0x00 : 0x10;
73
 
74
              if(rand() % 2 == 0)
75
                {
76
                  int i = 0;
77
 
78
                  for(i = 0; i < 5; ++i)
79
                    {
80
                      if(channels[i] == 0)
81
                        {
82
                          channels[i] = 1;
83
                          hpd_init_rx(i, 8*i*sizeof(int), 8, 0x400 + i + src);
84
                          break;
85
                        }
86
                    }
87
                }
88
 
89
              send++;
90
 
91
              int fre = 0;
92
              int x = 0;
93
              for(; x < 8; ++x) {if(channels[x]== 0) fre++;}
94
              printf("CPU2: %i to send, %i in FIFO, %i channels free\n",
95
                     send, hpd_isr_fifo_size(hpd_isr_fifo), fre);
96
 
97
              break;
98
 
99
            case RX_UNKNOWN:
100
              {
101
                int cha = 0;
102
 
103
                for(cha = 0; cha < 8; ++cha)
104
                  {
105
                    if(channels[cha] == 0)
106
                      {
107
                        channels[cha] = (info->dst_address == 0x5FF) ? 2 : 1;
108
 
109
                        printf("CPU2: received data to unconfigured "
110
                               "address 0x%X, assigning to channel %i\n",
111
                       info->dst_address, cha);
112
 
113
                        if(!(0x400 <= info->dst_address &&
114
                             info->dst_address <= 0x5FF))
115
                          {
116
                            printf("CPU2: %i is invalid address, FAILURE\n",
117
                                   info->dst_address);
118
                          }
119
 
120
                        // Initialize some channel to receive
121
                        hpd_init_rx(cha, cha * rx_amount*sizeof(int), rx_amount,
122
                                    info->dst_address);
123
 
124
                        break;
125
                      }
126
                  }
127
                int fre = 0;
128
                int x = 0;
129
                for(; x < 8; ++x) {if(channels[x]== 0) fre++;}
130
                printf("CPU2: %i to send, %i in FIFO, %i channels free\n",
131
                       send, hpd_isr_fifo_size(hpd_isr_fifo), fre);
132
 
133
              }
134
              break;
135
 
136
              case TX_IGNORED:
137
              {
138
                printf("CPU2: A transfer was ignored because it overlapped"
139
                       " previous one\n");
140
 
141
                int fre = 0;
142
                int x = 0;
143
                for(; x < 8; ++x) {if(channels[x]== 0) fre++;}
144
                printf("CPU2: %i to send, %i in FIFO, %i channels free\n",
145
                       send, hpd_isr_fifo_size(hpd_isr_fifo), fre);
146
              }
147
              break;
148
 
149
            }
150
 
151
          // Free memory
152
          free(info); info = NULL;
153
        }
154
      else if(send > 0 && (((IORD(HIBI_PE_DMA_BASE, 4) >> 16) & 0x1) == 1))
155
        {
156
          // Sent packet to a random target's random address
157
          int target_addr;
158
          int tx_data[8];
159
          int tx_slot = (rand() % 8);
160
          int cha;
161
 
162
          if(rand() % 2 == 0)
163
            {
164
              target_addr = 0x020 + tx_slot;
165
            }
166
          else
167
            {
168
              target_addr = 0x220 + tx_slot;
169
            }
170
 
171
          for(cha = 0; cha < 8; ++cha)
172
            tx_data[cha] = 0x82000000 | ((cha+1) << 16) | target_addr;
173
 
174
          memcpy((int*)(HPD_REGISTERS_TX_BUFFER_START +
175
                        tx_slot*tx_amount*sizeof(int)),
176
                 (int*)tx_data, tx_amount*sizeof(int));
177
 
178
          printf("CPU2: sending packet to 0x%X\n", target_addr);
179
 
180
          hpd_send(HPD_REGISTERS_TX_BUFFER_START +
181
                   tx_slot*tx_amount*sizeof(int),
182
                   tx_amount, target_addr);
183
 
184
          send--;
185
 
186
          // Overlapping with previous one
187
          if((rand() % 100) < 50)
188
            {
189
              hpd_send(HPD_REGISTERS_TX_BUFFER_START +
190
                       tx_slot*tx_amount*sizeof(int),
191
                       tx_amount, 0x1FF);
192
              printf("CPU2: sending hazard packet\n");
193
            }
194
          int fre = 0;
195
          int x = 0;
196
          for(; x < 8; ++x) {if(channels[x]== 0) fre++;}
197
          printf("CPU2: %i to send, %i in FIFO, %i channels free\n",
198
                 send, hpd_isr_fifo_size(hpd_isr_fifo), fre);
199
        }
200
    }
201
 
202
  printf("CPU2: retires!\n");
203
  while(1); return 0;
204
}

powered by: WebSVN 2.1.0

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