OpenCores
URL https://opencores.org/ocsvn/plb2wbbridge/plb2wbbridge/trunk

Subversion Repositories plb2wbbridge

[/] [plb2wbbridge/] [trunk/] [systems/] [EDK_Libs/] [WishboneIPLib/] [drivers/] [plb2wb_bridge_v1_00_a/] [src/] [plb2wb_bridge.c] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 feddischso
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  PLB2WB-Bridge                                               ////
4
////                                                              ////
5
////  This file is part of the PLB-to-WB-Bridge project           ////
6
////  http://opencores.org/project,plb2wbbridge                   ////
7
////                                                              ////
8
////  Description                                                 ////
9
////  Implementation of a PLB-to-WB-Bridge according to           ////
10
////  PLB-to-WB Bridge specification document.                    ////
11
////                                                              ////
12
////  To Do:                                                      ////
13
////   Nothing                                                    ////
14
////                                                              ////
15
////  Author(s):                                                  ////
16
////      - Christian Haettich                                    ////
17
////        feddischson@opencores.org                             ////
18
////                                                              ////
19
//////////////////////////////////////////////////////////////////////
20
////                                                              ////
21
//// Copyright (C) 2010 Authors                                   ////
22
////                                                              ////
23
//// This source file may be used and distributed without         ////
24
//// restriction provided that this copyright statement is not    ////
25
//// removed from the file and that any derivative work contains  ////
26
//// the original copyright notice and the associated disclaimer. ////
27
////                                                              ////
28
//// This source file is free software; you can redistribute it   ////
29
//// and/or modify it under the terms of the GNU Lesser General   ////
30
//// Public License as published by the Free Software Foundation; ////
31
//// either version 2.1 of the License, or (at your option) any   ////
32
//// later version.                                               ////
33
////                                                              ////
34
//// This source is distributed in the hope that it will be       ////
35
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
36
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
37
//// PURPOSE.  See the GNU Lesser General Public License for more ////
38
//// details.                                                     ////
39
////                                                              ////
40
//// You should have received a copy of the GNU Lesser General    ////
41
//// Public License along with this source; if not, download it   ////
42
//// from http://www.opencores.org/lgpl.shtml                     ////
43
////                                                              ////
44
//////////////////////////////////////////////////////////////////////
45
 
46
#include "plb2wb_bridge.h"
47
#include "xstatus.h"
48
#include "xparameters.h"
49
#include "xio.h"
50
 
51
 
52
 
53
static void WBResetStubHandler( void *CallBackRef )
54
{
55
   XASSERT_VOID( FALSE );
56
}
57
 
58
 
59
static void StubHandler( void *CallBackRef )
60
{
61
 
62
        XASSERT_VOID(CallBackRef != NULL);
63
 
64
        ( (PLB2WB_Bridge *) CallBackRef )->UnhandledInterrupts++;
65
}
66
 
67
 
68
 
69
//
70
//  Note,  this handlers MUST be implemented.
71
//  If no handler is implemented and interrupt is rised,
72
//  this stubs never return!!
73
//
74
//
75
static void StubWBRstHandler( void *CallBackRef )
76
{
77
        XASSERT_VOID( FALSE );
78
 
79
}
80
 
81
static void StubWBWrHandler( void *CallBackRef )
82
{
83
        XASSERT_VOID( FALSE );
84
}
85
 
86
 
87
void PLB2WB_Bridge_DeviceInterruptHandler( void* ptr )
88
{
89
 
90
   u32 status_reg;
91
   u32 irq_reg;
92
   u32 addr_reg;
93
   u32 datum_reg;
94
   u8  i;
95
   PLB2WB_Bridge_VectorTableEntry *entry;
96
 
97
   PLB2WB_Bridge* InstancePtr = (PLB2WB_Bridge*) ptr;
98
 
99
 
100
   status_reg = XIo_In32( InstancePtr->StatusBaseAddress + PLB2WB_STATUS );
101
 
102
 
103
 
104
   // call write-error handler
105
   if ( status_reg & PLB2WB_STATUS_WERR )
106
   {
107
      entry = &InstancePtr->WBWrErrorHandler;
108
      entry->Handler( entry->CallBackRef );
109
   }
110
 
111
 
112
   // call irq-handler
113
   if ( status_reg & PLB2WB_STATUS_WBIRQ )
114
   {
115
      irq_reg = XIo_In32( InstancePtr->StatusBaseAddress + PLB2WB_STATUS_IRQ  );
116
      for( i=0; i<32; i++ )
117
      {
118
         if( irq_reg & ( 1 << ( 31 - i ) ) )
119
         {
120
            entry = &InstancePtr->HandlerTable[i];
121
            entry->Handler( entry->CallBackRef );
122
         }
123
      }
124
   }
125
 
126
 
127
   // call reset handler
128
   if ( status_reg & PLB2WB_STATUS_WBRST )
129
   {
130
      entry = &InstancePtr->WBRstHandler;
131
      entry->Handler( entry->CallBackRef );
132
   }
133
 
134
   // clear bridge-irq
135
   XIo_Out32( InstancePtr->StatusBaseAddress + PLB2WB_STATUS, 0 );
136
 
137
   // clear mb-irq
138
   XIntc_Acknowledge( InstancePtr->xintcInstancePtr, InstancePtr->irqID );
139
}
140
 
141
 
142
 
143
 
144
 
145
PLB2WB_Bridge_Config *PLB2WB_Bridge_LookupConfig( u16 DeviceId )
146
{
147
        PLB2WB_Bridge_Config *CfgPtr = NULL;
148
 
149
        int i;
150
        for ( i = 0; i < XPAR_PLB2WB_BRIDGE_NUM_INSTANCES; i++ )
151
   {
152
                if ( PLB2WB_Bridge_ConfigTable[i].DeviceId == DeviceId )
153
      {
154
                        CfgPtr = &PLB2WB_Bridge_ConfigTable[i];
155
                        break;
156
                }
157
        }
158
 
159
        return CfgPtr;
160
}
161
 
162
 
163
 
164
int PLB2WB_Bridge_Initialize( PLB2WB_Bridge * InstancePtr, u16 DeviceId, XIntc* xintcInstancePtr, u8 irqID )
165
{
166
   u8 i;
167
 
168
   PLB2WB_Bridge_Config *ConfigPtr;
169
 
170
   XASSERT_NONVOID( InstancePtr != NULL );
171
 
172
   ConfigPtr = PLB2WB_Bridge_LookupConfig( DeviceId );
173
 
174
   if ( ConfigPtr == ( PLB2WB_Bridge_Config * ) NULL )
175
   {
176
        InstancePtr->IsReady = 0;
177
        return ( XST_DEVICE_NOT_FOUND );
178
   }
179
 
180
 
181
   InstancePtr->StatusBaseAddress   = ConfigPtr->StatusBaseAddress;
182
   InstancePtr->BaseAddress         = ConfigPtr->BaseAddress;
183
   InstancePtr->CfgPtr              = ConfigPtr;
184
 
185
   for( i=0; i < XPAR_PLB2WB_BRIDGE_0_WB_PIC_INTS; i++ )
186
   {
187
      InstancePtr->HandlerTable[i].Handler = StubHandler;
188
                InstancePtr->HandlerTable[i].CallBackRef = InstancePtr;
189
   }
190
 
191
   InstancePtr->WBWrErrorHandler.Handler = StubWBWrHandler;
192
   InstancePtr->WBWrErrorHandler.CallBackRef = StubWBWrHandler;
193
 
194
   InstancePtr->WBRstHandler.Handler = StubWBRstHandler;
195
   InstancePtr->WBRstHandler.CallBackRef = InstancePtr;
196
 
197
 
198
 
199
   InstancePtr->xintcInstancePtr = xintcInstancePtr;
200
   InstancePtr->irqID            = irqID;
201
        InstancePtr->IsReady          = XCOMPONENT_IS_READY;
202
 
203
   return XST_SUCCESS;
204
}
205
 
206
 
207
 
208
int PLB2WB_Bridge_Connect_WBRstHandler( PLB2WB_Bridge* InstancePtr,
209
                                        XInterruptHandler Handler, void* CallBackRef )
210
{
211
   XASSERT_NONVOID( InstancePtr != NULL );
212
   XASSERT_NONVOID( Handler != NULL );
213
   XASSERT_NONVOID( InstancePtr->IsReady == XCOMPONENT_IS_READY );
214
 
215
   InstancePtr->WBRstHandler.Handler = Handler;
216
   InstancePtr->WBRstHandler.CallBackRef = CallBackRef;
217
 
218
   return XST_SUCCESS;
219
}
220
 
221
int PLB2WB_Bridge_Connect_WBWrErrHandler( PLB2WB_Bridge* InstancePtr, XInterruptHandler Handler, void* CallBackRef )
222
{
223
   XASSERT_NONVOID( InstancePtr != NULL );
224
   XASSERT_NONVOID( Handler != NULL );
225
   XASSERT_NONVOID( InstancePtr->IsReady == XCOMPONENT_IS_READY );
226
 
227
   InstancePtr->WBWrErrorHandler.Handler = Handler;
228
   InstancePtr->WBWrErrorHandler.CallBackRef = CallBackRef;
229
 
230
   return XST_SUCCESS;
231
}
232
 
233
 
234
int PLB2WB_Bridge_Connect( PLB2WB_Bridge* InstancePtr, u8 Id,
235
                           XInterruptHandler Handler, void* CallBackRef )
236
{
237
   XASSERT_NONVOID( InstancePtr != NULL );
238
   XASSERT_NONVOID( Id < XPAR_PLB2WB_BRIDGE_0_WB_PIC_INTS );
239
   XASSERT_NONVOID( Handler != NULL );
240
   XASSERT_NONVOID( InstancePtr->IsReady == XCOMPONENT_IS_READY );
241
 
242
   InstancePtr->HandlerTable[Id].Handler = Handler;
243
   InstancePtr->HandlerTable[Id].CallBackRef = CallBackRef;
244
 
245
   return XST_SUCCESS;
246
}
247
 
248
 
249
 
250
void PLB2WB_Bridge_Disconnect( PLB2WB_Bridge * InstancePtr, u8 Id )
251
{
252
   u32 CurrentIER;
253
   u32 Mask;
254
 
255
   XASSERT_VOID(InstancePtr != NULL);
256
   XASSERT_VOID(Id < XPAR_PLB2WB_BRIDGE_0_WB_PIC_INTS );
257
   XASSERT_VOID(InstancePtr->IsReady == XCOMPONENT_IS_READY);
258
 
259
   InstancePtr->HandlerTable[Id].Handler = StubHandler;
260
   InstancePtr->HandlerTable[Id].CallBackRef = InstancePtr;
261
}
262
 
263
 
264
 
265
void  PLB2WB_Bridge_WBContinue            ( PLB2WB_Bridge* InstancePtr )
266
{
267
   XASSERT_VOID(InstancePtr != NULL);
268
 
269
   XIo_Out32( InstancePtr->StatusBaseAddress + PLB2WB_STATUS_CON, 0 );
270
}
271
 
272
 
273
 
274
void  PLB2WB_Bridge_WBAbort               ( PLB2WB_Bridge* InstancePtr )
275
{
276
   XASSERT_VOID(InstancePtr != NULL);
277
 
278
   XIo_Out32( InstancePtr->StatusBaseAddress + PLB2WB_STATUS_ABO, 0 );
279
}
280
 
281
 
282
void  PLB2WB_Bridge_SoftReset             ( PLB2WB_Bridge* InstancePtr )
283
{
284
   XASSERT_VOID(InstancePtr != NULL);
285
 
286
   XIo_Out32( InstancePtr->StatusBaseAddress + PLB2WB_STATUS_RST, 0 );
287
}
288
 
289
 

powered by: WebSVN 2.1.0

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