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

powered by: WebSVN 2.1.0

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