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/] [scr_cpu0/] [support.c] - Blame information for rev 145

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 145 lanttu
/*
2
 *
3
 * Author            : Lasse Lehtonen
4
 * Last modification : 29.03.2011
5
 *
6
 * HPD support functions
7
 *
8
 */
9
 
10
#include <stdio.h>
11
#include <string.h>
12
#include <io.h>
13
#include <unistd.h>
14
#include <sys/alt_irq.h>
15
#include <stdlib.h>
16
 
17
#include "support.h"
18
 
19
 
20
void hpd_send(int data_src_addr, int words, int hibi_addr)
21
{
22
  // Poll HPD, until it's not sending previous tx anymore
23
  //while(((IORD(hpd_CHAN_BASE, 4) >> 16) & 0x1) == 0) { }
24
 
25
  // Set data source address
26
  HPD_TX_MEM_ADDR(data_src_addr, HIBI_PE_DMA_BASE);
27
  //IOWR(HPD_CHAN_BASE, 8, data_src_addr);
28
 
29
  // Set how many words to send
30
  HPD_TX_WORDS(words, HIBI_PE_DMA_BASE);
31
  //IOWR(HPD_CHAN_BASE, 9, words);
32
 
33
  // Set target hibi command
34
  HPD_TX_CMD_WRITE(HIBI_PE_DMA_BASE);
35
  //IOWR(HPD_CHAN_BASE, 10, 2);
36
 
37
  // Set target hibi address
38
  HPD_TX_HIBI_ADDR(hibi_addr, HIBI_PE_DMA_BASE);
39
  //IOWR(HPD_CHAN_BASE, 11, hibi_addr);
40
 
41
  // Start the transfer
42
  HPD_TX_START(HIBI_PE_DMA_BASE);
43
  //IOWR(HPD_CHAN_BASE, 4, (0x1 | (IORD(HPD_CHAN_BASE,4))));
44
}
45
 
46
 
47
void hpd_init_rx(int rx_channel, int rx_addr, int rx_words, int hibi_addr)
48
{
49
  // Set receive mem address for incoming data
50
  IOWR(HIBI_PE_DMA_BASE, (rx_channel << 4), HPD_REGISTERS_RX_BUFFER_START +
51
       rx_addr);
52
  // Set amount to receive
53
  IOWR(HIBI_PE_DMA_BASE, (rx_channel << 4) + 2, rx_words);
54
  // Set hibi address to receive data
55
  IOWR(HIBI_PE_DMA_BASE, (rx_channel << 4) + 1, hibi_addr);
56
  // Initialize receiving
57
  IOWR(HIBI_PE_DMA_BASE, 5 , 1 << rx_channel);
58
}
59
 
60
 
61
 
62
int onehot2int(int num)
63
{
64
  int i = 0;
65
  for(; i < 31; ++i)
66
    {
67
      if(num & (1 << i))
68
        {
69
          return i;
70
        }
71
    }
72
  return -1;
73
}
74
 
75
 
76
void hpd_isr(void* context)
77
{
78
  Hpd_isr_fifo* fifo = (Hpd_isr_fifo*) context;
79
 
80
  // Read the cause of the interrupt
81
  int interrupter = IORD(HIBI_PE_DMA_BASE, 7);
82
 
83
 
84
  if((0x80000000 & interrupter) != 0)
85
    {
86
      Hpd_isr_info* info = (Hpd_isr_info*) malloc(sizeof(Hpd_isr_info));
87
      info->isr_type = RX_UNKNOWN;
88
 
89
      // Read in incoming hibi address
90
      info->dst_address = IORD(HIBI_PE_DMA_BASE, 12);
91
      // Clear IRQ
92
      IOWR(HIBI_PE_DMA_BASE, 7, 0x80000000);
93
 
94
      // Store interrupt information to fifo
95
      hpd_isr_fifo_push(fifo, info);
96
    }
97
 
98
  if((0x40000000 & interrupter) != 0)
99
    {
100
      Hpd_isr_info* info = (Hpd_isr_info*) malloc(sizeof(Hpd_isr_info));
101
      info->isr_type = TX_IGNORED;
102
 
103
      // Clear IRQ
104
      IOWR(HIBI_PE_DMA_BASE, 7, 0x40000000);
105
 
106
      // Store interrupt information to fifo
107
      hpd_isr_fifo_push(fifo, info);
108
    }
109
 
110
  while((0x3FFFFFFF & interrupter) != 0)
111
    {
112
      Hpd_isr_info* info = (Hpd_isr_info*) malloc(sizeof(Hpd_isr_info));
113
      info->isr_type = RX_READY;
114
 
115
      // Store interrupted channel
116
      info->rx_channel = onehot2int(interrupter);
117
      // Clear IRQ
118
      IOWR(HIBI_PE_DMA_BASE, 7, (1 << info->rx_channel));
119
 
120
      interrupter = interrupter & ~(1 << info->rx_channel);
121
 
122
      // Store interrupt information to fifo
123
      hpd_isr_fifo_push(fifo, info);
124
    }
125
}
126
 
127
 
128
// Init interrupt
129
void hpd_isr_init(Hpd_isr_fifo* hpd_isr_fifo)
130
{
131
  // Register hpd ISR
132
  if(alt_ic_isr_register(HIBI_PE_DMA_IRQ_INTERRUPT_CONTROLLER_ID,
133
                  HIBI_PE_DMA_IRQ, hpd_isr, (void*)hpd_isr_fifo, 0)
134
     != 0)
135
    {
136
      printf("CPU0: registering n2h2_isr failed!\n");
137
    }
138
  // Enable interrupt on CPU side     
139
  if(alt_ic_irq_enable(HIBI_PE_DMA_IRQ_INTERRUPT_CONTROLLER_ID,
140
                  HIBI_PE_DMA_IRQ) != 0)
141
    {
142
      printf("CPU0: enabling n2h2 interrupt failed!\n");
143
    }
144
  // Enable interrupts on hpd side
145
  IOWR(HIBI_PE_DMA_BASE, 4, (2 | (IORD(HIBI_PE_DMA_BASE,4))));
146
}
147
 

powered by: WebSVN 2.1.0

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