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

Subversion Repositories bluespec_md6

[/] [bluespec_md6/] [trunk/] [lib/] [bsv/] [RegisterMapper/] [src/] [RegisterMapper.bsv] - Blame information for rev 7

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 kfleming
/*
2
Copyright (c) 2008 MIT
3
 
4
Permission is hereby granted, free of charge, to any person
5
obtaining a copy of this software and associated documentation
6
files (the "Software"), to deal in the Software without
7
restriction, including without limitation the rights to use,
8
copy, modify, merge, publish, distribute, sublicense, and/or sell
9
copies of the Software, and to permit persons to whom the
10
Software is furnished to do so, subject to the following
11
conditions:
12
 
13
The above copyright notice and this permission notice shall be
14
included in all copies or substantial portions of the Software.
15
 
16
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23
OTHER DEALINGS IN THE SOFTWARE.
24
 
25
Author: Kermin Fleming
26
*/
27
 
28
import GetPut::*;
29
import List::*;
30
import Vector::*;
31
import FIFO::*;
32
 
33
 
34
import Register::*;
35
 
36
/*******
37
 *
38
 * This file serves as an adapter between a register interface and another
39
 * communication interface, perhaps a bus.  We should probably put bus conversion
40
 * shims in here, and maybe use something split phase - that is aligned with get-put
41
 *
42
 *******/
43
 
44
 
45
interface RegisterMapper#(type response, type request);
46
  method Action registerRequest(request req);
47
  method ActionValue#(response) registerResponse();
48
endinterface
49
 
50
typedef enum {
51
  Read = 0,
52
  Write = 1
53
} MapperCommand deriving (Bits,Eq);
54
 
55
typedef struct {
56
  MapperCommand command;
57
  Bit#(TLog#(mapSize)) location;
58
  payloadType payload;
59
} MapperRequest#(numeric type mapSize, type payloadType) deriving (Bits,Eq);
60
 
61
 
62
module mkRegisterMapper#(function (MapperRequest#(registerMapSize,registerType)) mapperRequestExtract(request req),
63
                         function response responseExtract(registerType resp),
64
                         Vector#(registerMapSize,Reg#(registerType)) registers) (RegisterMapper#(response, request))
65
  provisos (Bits#(registerType, xxx));
66
 
67
  FIFO#(registerType) respFIFO <- mkFIFO;
68
 
69
  method Action registerRequest(request req);
70
 
71
    MapperRequest#(registerMapSize,registerType) mapReq = mapperRequestExtract(req);
72
    //$display("register request called, Regs number: %d, Reg touched: %d payload: %h", valueof(registerMapSize), mapReq.location, mapReq.payload);
73
    if(mapReq.command == Read)
74
      begin
75
        respFIFO.enq(registers[mapReq.location]);
76
      end
77
    else
78
      begin
79
        registers[mapReq.location] <= mapReq.payload;
80
      end
81
  endmethod
82
 
83
  method ActionValue#(response) registerResponse();
84
    respFIFO.deq;
85
    return responseExtract(respFIFO.first);
86
  endmethod
87
 
88
endmodule

powered by: WebSVN 2.1.0

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