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

powered by: WebSVN 2.1.0

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