Mercurial > pygar
diff modules/bluespec/Pygar/lab4/GetPutExt.bsv @ 8:74716e9a81cc pygar svn.9
[svn r9] Pygar now has the proper directory structure to play nicely with awb. Also, the apm file for audio-core willcompile successfully.
author | rlm |
---|---|
date | Fri, 23 Apr 2010 02:32:05 -0400 |
parents | |
children |
line wrap: on
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/modules/bluespec/Pygar/lab4/GetPutExt.bsv Fri Apr 23 02:32:05 2010 -0400 1.3 @@ -0,0 +1,108 @@ 1.4 +import FIFOF::*; 1.5 +import RWire::*; 1.6 +import GetPut::*; 1.7 + 1.8 +// Convert a FIFOF into a put interface 1.9 + 1.10 +function Put#(item_t) fifofToPut( FIFOF#(item_t) f ) provisos ( ); 1.11 + return 1.12 + ( 1.13 + interface Put 1.14 + method Action put( item_t item ); 1.15 + f.enq(item); 1.16 + endmethod 1.17 + endinterface 1.18 + ); 1.19 +endfunction 1.20 + 1.21 +// Convert a FIFOF into a get interface 1.22 + 1.23 +function Get#(item_t) fifofToGet( FIFOF#(item_t) f ) provisos ( ); 1.24 + return 1.25 + ( 1.26 + interface Get 1.27 + method ActionValue#(item_t) get(); 1.28 + f.deq(); 1.29 + return f.first(); 1.30 + endmethod 1.31 + endinterface 1.32 + ); 1.33 +endfunction 1.34 + 1.35 +// Convert a register into an (always ready) put interface 1.36 + 1.37 +function Put#(item_t) regToPut( Reg#(item_t) r ) provisos ( ); 1.38 + return 1.39 + ( 1.40 + interface Put 1.41 + method Action put( item_t item ); 1.42 + r <= item; 1.43 + endmethod 1.44 + endinterface 1.45 + ); 1.46 +endfunction 1.47 + 1.48 +// Convert a register into an (always ready) get interface 1.49 + 1.50 +function Get#(item_t) regToGet( Reg#(item_t) r ) provisos ( ); 1.51 + return 1.52 + ( 1.53 + interface Get 1.54 + method ActionValue#(item_t) get(); 1.55 + return r; 1.56 + endmethod 1.57 + endinterface 1.58 + ); 1.59 +endfunction 1.60 + 1.61 +// Convert a Wire into a put interface 1.62 + 1.63 +function Put#(item_t) wireToPut( Wire#(item_t) w ) provisos ( ); 1.64 + return 1.65 + ( 1.66 + interface Put 1.67 + method Action put( item_t item ); 1.68 + w._write(item); 1.69 + endmethod 1.70 + endinterface 1.71 + ); 1.72 +endfunction 1.73 + 1.74 +// Convert a WIREF into a get interface 1.75 + 1.76 +function Get#(item_t) wireToGet( Wire#(item_t) w ) provisos ( ); 1.77 + return 1.78 + ( 1.79 + interface Get 1.80 + method ActionValue#(item_t) get(); 1.81 + return w._read(); 1.82 + endmethod 1.83 + endinterface 1.84 + ); 1.85 +endfunction 1.86 + 1.87 +// Convert a RWire into a put interface 1.88 + 1.89 +function Put#(item_t) rwireToPut( RWire#(item_t) w ) provisos ( ); 1.90 + return 1.91 + ( 1.92 + interface Put 1.93 + method Action put( item_t item ); 1.94 + w.wset(item); 1.95 + endmethod 1.96 + endinterface 1.97 + ); 1.98 +endfunction 1.99 + 1.100 +// Convert a RWire into a get interface 1.101 + 1.102 +function Get#(item_t) rwireToGet( RWire#(item_t) w ) provisos ( ); 1.103 + return 1.104 + ( 1.105 + interface Get 1.106 + method ActionValue#(item_t) get() if ( isValid(w.wget()) ); 1.107 + return unJust(w.wget()); 1.108 + endmethod 1.109 + endinterface 1.110 + ); 1.111 +endfunction