Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/ShepardSiegel/ocpi
Browse files Browse the repository at this point in the history
  • Loading branch information
ShepardSiegel committed Feb 4, 2014
2 parents 63e12a1 + 9ea730a commit fd35937
Show file tree
Hide file tree
Showing 68 changed files with 132,144 additions and 8,494 deletions.
94 changes: 94 additions & 0 deletions bsv/axi/AXBLUART.bsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// AXBLUART - An AXI wrapper around a BSV UART
// Copyright (c) 2014 Atomic Rules LLC - ALL RIGHTS RESERVED

import ARAXI4L ::*;
import BLUART ::*;

import FIFO ::*;
import GetPut ::*;
import Vector ::*;

interface AXBLUARTIfc;
interface A4L_Es s_axi; // Slave AXI Ifc
interface UART_pads upads; // UART pads
endinterface

(* synthesize, default_clock_osc="s_axi_aclk", default_reset="s_axi_aresetn" *)
module mkAXBLUART (AXBLUARTIfc);
A4LSlaveIfc a4l <- mkA4LSlave; // The AXI4-Lite Slave Interface
Reg#(Bit#(32)) r0 <- mkReg(0); // Some regsiters for testing...
Reg#(Bit#(32)) r4 <- mkReg(0);
Reg#(Bit#(32)) r8 <- mkReg(0);
Reg#(Bit#(32)) rC <- mkReg(0);
BLUARTIfc bluart <- mkBLUART; // BLUART
Reg#(Bool) uartInited <- mkReg(False);
Reg#(UInt#(6)) uartTxtP <- mkReg(0);

function Vector#(40,Bit#(8)) uartLine(String s);
Integer n = primStringToInteger(s);
Integer l = stringLength(s) - 1;
Vector#(40,Bit#(8)) text;
for (Integer i = 0; i < 40; i = i + 1) begin
Bit#(8) ch = fromInteger(n % 256);
n = n / 256;
if (ch == 0) text[i] = 8'h20; // blank space
else text[l-i] = ch;
end
return text;
endfunction

rule init_uart_text (!uartInited);
Vector#(40,Bit#(8)) initText = uartLine("AXBLUART.bsv - Atomic Rules LLC (c) 2014");
case (uartTxtP)
0,42 : bluart.txChar.put(8'h0d); // CR
1,43 : bluart.txChar.put(8'h0a); // LF
default: bluart.txChar.put(initText[uartTxtP-2]);
endcase
uartTxtP <= uartTxtP + 1;
if (uartTxtP==43) uartInited <= True;
endrule

rule a4l_cfwr; // AXI4-Lite Configuration Property Writes...
let wa = a4l.f.wrAddr.first; a4l.f.wrAddr.deq; // Get the write address
let wd = a4l.f.wrData.first; a4l.f.wrData.deq; // Get the write data
case (wa.addr[7:0]) matches // Take some action with it...
'h00 : r0 <= unpack(wd.data);
'h04 : r4 <= unpack(wd.data);
'h08 : r8 <= unpack(wd.data);
'h0C : rC <= unpack(wd.data);
'h20 : bluart.setClkDiv.put(truncate(unpack(wd.data)));
'h2C : bluart.txChar.put (truncate(unpack(wd.data)));
endcase
a4l.f.wrResp.enq(A4LWrResp{resp:OKAY}); // Acknowledge the write
$display("[%0d]: %m: AXI4-LITE CONFIG WRITE Addr:%0x BE:%0x Data:%0x", $time, wa.addr, wd.strb, wd.data);
endrule

rule a4l_cfrd; // AXI4-Lite Configuration Property Reads...
let ra = a4l.f.rdAddr.first; a4l.f.rdAddr.deq; // Get the read address
Bit#(32) rdat = ?;
case (ra.addr[7:0]) matches
'h00 : rdat = pack(r0); // return r0
'h04 : rdat = pack(r4); // return r4
'h08 : rdat = pack(r8); // return r8
'h0C : rdat = pack(rC); // return rC
'h10 : rdat = 32'hDEADBEEF; // return a constant
'h14 : rdat = 32'hBABECAFE; // return a constant
'h18 : rdat = 32'hF00DFACE; // return a constant
'h1C : rdat = 32'hFEEDC0DE; // return a constant
'h24 : rdat = extend(pack(bluart.txLevel));
'h28 : rdat = extend(pack(bluart.rxLevel));
'h30 : action
let d <- bluart.rxChar.get();
rdat = extend(unpack(d));
endaction
endcase
a4l.f.rdResp.enq(A4LRdResp{data:rdat,resp:OKAY}); // Return the read data
$display("[%0d]: %m: AXI4-LITE CONFIG READ Addr:%0x",$time, ra.addr);
$display("[%0d]: %m: AXI4-LITE CONFIG READ RESPOSNE Data:%0x",$time, rdat);
endrule

A4L_Es a4ls <- mkA4StoEs(a4l.a4ls); // return the expanded interface...
//return(a4ls);
interface A4L_Es s_axi = a4ls; // prepend "s_axi"
interface UART_pads upads = bluart.pads;
endmodule
57 changes: 25 additions & 32 deletions bsv/dev/BLUART.bsv
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// BLUART.bsv - A Bluespec SystemVerilog (BSV) UART
// Copyright (c) 2014 Atomic Rules LLC - ALL RIGHTS RESERVED
//
// Default Configuration: 115200 baud, 8 bits, 1 stop bit, no parity
// Baud rate may be set at runtime by the setClkDiv method

package BLUART;

Expand All @@ -20,12 +23,12 @@ interface UART_pads;
endinterface: UART_pads

interface BLUARTIfc;
interface Put#(UInt#(16)) setClkDiv; // clkDiv = module clock / desired baudrate
method UInt#(16) txLevel;
method UInt#(16) rxLevel;
interface Put#(Bit#(8)) txChar;
interface Get#(Bit#(8)) rxChar;
interface UART_pads pads;
interface Put#(UInt#(16)) setClkDiv; // clkDiv = module clock freq / desired baudrate
method UInt#(8) txLevel; // 0=Nothing to send; 1=Sending TX data
method UInt#(8) rxLevel; // 0=Nothing to receive; 1=One or more Bytes in rxF
interface Put#(Bit#(8)) txChar; // Method to Put() TX data
interface Get#(Bit#(8)) rxChar; // Method to Get() RX data
interface UART_pads pads; // Interface to UART pads
endinterface


Expand All @@ -40,7 +43,7 @@ module mkBLUART (BLUARTIfc);

Reg#(UInt#(16)) rxBaudCnt <- mkReg(0);
Reg#(UInt#(4)) rxBitCnt <- mkReg(0);
FIFOF#(Bit#(8)) rxF <- mkFIFOF;
FIFOF#(Bit#(8)) rxF <- mkSizedFIFOF(4);
Reg#(Bit#(1)) rxInReg <- mkReg(1);
Reg#(Bit#(1)) rxCtsReg <- mkReg(1);
Reg#(Vector#(2,Bit#(1))) rxD <- mkReg(unpack('1));
Expand All @@ -59,18 +62,8 @@ module mkBLUART (BLUARTIfc);
endrule

rule tx_DataMux;
case (txBitCnt)
0 : txData <= 1;
1 : txData <= 0; // 1 stop bit
2 : txData <= txF.first[0];
3 : txData <= txF.first[1];
4 : txData <= txF.first[2];
5 : txData <= txF.first[3];
6 : txData <= txF.first[4];
7 : txData <= txF.first[5];
8 : txData <= txF.first[6];
9 : txData <= txF.first[7];
endcase
Bit#(10) txa = {txF.first, 2'b01}; // 1 stop bit, then data
txData <= txa[txBitCnt]; // LS first, parallel to serial
endrule

// Rx Logic...
Expand All @@ -83,13 +76,13 @@ module mkBLUART (BLUARTIfc);
(* fire_when_enabled, no_implicit_conditions *)
rule update_rxCnts;
rxD <= shiftInAt0(rxD, rxInReg);
if (rxGo) rxBaudCnt <= 1; // Start baud counter on new bit falling edge
else if (rxStop) rxBaudCnt <= 0; // Clear when done
else if (rxBaudCnt>=clkDiv) rxBaudCnt <= 1; // Hold at clkDic
if (rxGo) rxBaudCnt <= 1; // Start baud counter
else if (rxStop) rxBaudCnt <= 0; // Clear when done
else if (rxBaudCnt>=clkDiv) rxBaudCnt <= 1; // Hold at clkDiv
else if (rxBaudCnt!=0) rxBaudCnt <= rxBaudCnt + 1; // Inc rxBaudCnt
if (rxGo) rxBitCnt <= 1;
else if (rxStop) rxBitCnt <= 0;
else if (rxBaudCnt==clkDiv) rxBitCnt <= rxBitCnt + 1;
if (rxGo) rxBitCnt <= 1; // Start bit counter
else if (rxStop) rxBitCnt <= 0; // Stop bit counter
else if (rxBaudCnt==clkDiv) rxBitCnt <= rxBitCnt + 1; // Inc rxBitCnt
endrule

rule rx_d_shift (rxShift);
Expand All @@ -100,14 +93,14 @@ module mkBLUART (BLUARTIfc);
rxF.enq(pack(rxV));
endrule

method UInt#(16) txLevel = (txF.notEmpty) ? 1 : 0;
method UInt#(16) rxLevel = (rxF.notEmpty) ? 1 : 0;
interface Put txChar = toPut(txF);
interface Put setClkDiv = toPut(asReg(clkDiv));
interface Get rxChar = toGet(rxF);
interface Put txChar = toPut(txF);
interface Get rxChar = toGet(rxF);
interface Put setClkDiv = toPut(asReg(clkDiv));
method UInt#(8) txLevel = (txF.notEmpty) ? 1 : 0;
method UInt#(8) rxLevel = (rxF.notEmpty) ? 1 : 0;
interface UART_pads pads;
method Bool rts = True; // connect to CTS
method Bool tx = unpack(txData); // connect to RX
method Bool rts = True; // connect to CTS
method Bool tx = unpack(txData); // connect to RX
method Action cts (Bool arg) = rxCtsReg._write(pack(arg)); // connect to RTS
method Action rx (Bool arg) = rxInReg._write(pack(arg)); // connect to TX
endinterface
Expand Down
6 changes: 3 additions & 3 deletions bsv/inf/CTop.bsv
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

package CTop;

import BLUART ::*;
//import BLUART ::*;
import OCInf ::*;
import OCApp ::*;
import TLPMF ::*;
Expand Down Expand Up @@ -33,7 +33,7 @@ interface CTopIfc#(numeric type ndw);
interface Wsi_Em#(12,TMul#(ndw,32),TMul#(ndw,4),8,0) wsi_m_dac;
interface WmemiEM16B wmemiM0;
interface GPSIfc gps;
interface UART_pads upads;
// interface UART_pads upads;
endinterface

module mkCTop#(PciId pciDevice, Clock sys0_clk, Reset sys0_rst) (CTopIfc#(ndw))
Expand Down Expand Up @@ -130,7 +130,7 @@ module mkCTop#(PciId pciDevice, Clock sys0_clk, Reset sys0_rst) (CTopIfc#(ndw))
//interface Wsi_s wsi_s_adc = app.wsi_s_adc; // The ADC device-worker to the application // FIXME Poly Width
//interface Wsi_m wsi_m_dac = app.wsi_m_dac; // The DAC device-worker to the application // FIXME Poly Width
interface WmemiEM16B wmemiM0 = app.wmemiM0;
interface UART_pads upads = inf.upads;
// interface UART_pads upads = inf.upads;
endmodule : mkCTop

// Synthesizeable, non-polymorphic modules that use the poly module above...
Expand Down
48 changes: 24 additions & 24 deletions bsv/inf/OCCP.bsv
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

package OCCP;

import BLUART ::*;
//import BLUART ::*;
import CPDefs ::*;
import OCWip ::*;
import TimeService ::*;
Expand Down Expand Up @@ -48,7 +48,7 @@ interface OCCPIfc#(numeric type nWci);
(* always_ready *) method Bit#(2) led;
(* always_ready, always_enabled *) method Action switch (Bit#(3) x);
(* always_ready, always_enabled *) method Action uuid (Bit#(512) arg);
interface UART_pads upads;
// interface UART_pads upads;
endinterface

typedef union tagged {
Expand Down Expand Up @@ -98,9 +98,9 @@ module mkOCCP#(PciId pciDevice, Clock time_clk, Reset time_rst) (OCCPIfc#(Nwcit)
FIFOF#(DWordM) adminResp4F <- mkFIFOF1; // Admin region read-response FIFO - region 4
FIFO#(DWordM) adminRespF <- mkFIFO1; // Admin region read-response FIFO - aggregate

BLUARTIfc bluart <- mkBLUART; // Instance our tiny UART
Reg#(Bool) uartInited <- mkReg(False);
Reg#(UInt#(6)) uartTxtP <- mkReg(0);
//BLUARTIfc bluart <- mkBLUART; // Instance our tiny UART
//Reg#(Bool) uartInited <- mkReg(False);
//Reg#(UInt#(6)) uartTxtP <- mkReg(0);

BRAM_Configure cfg = defaultValue;
cfg.memorySize = 1024; // Number of DWORD entries in 4KB ROM
Expand Down Expand Up @@ -133,16 +133,16 @@ module mkOCCP#(PciId pciDevice, Clock time_clk, Reset time_rst) (OCCPIfc#(Nwcit)
return text;
endfunction

rule init_uart_text (!uartInited);
Vector#(40,Bit#(8)) initText = uartLine("OpenCPI USB-UART v0.01 2014-01-26 *good*");
case (uartTxtP)
0,42 : bluart.txChar.put(8'h0d); // CR
1,43 : bluart.txChar.put(8'h0a); // LF
default: bluart.txChar.put(initText[uartTxtP-2]);
endcase
uartTxtP <= uartTxtP + 1;
if (uartTxtP==43) uartInited <= True;
endrule
// rule init_uart_text (!uartInited);
// Vector#(40,Bit#(8)) initText = uartLine("OpenCPI USB-UART v0.01 2014-01-24 *safe*");
// case (uartTxtP)
// 0,42 : bluart.txChar.put(8'h0d); // CR
// 1,43 : bluart.txChar.put(8'h0a); // LF
// default: bluart.txChar.put(initText[uartTxtP-2]);
// endcase
// uartTxtP <= uartTxtP + 1;
// if (uartTxtP==43) uartInited <= True;
// endrule

function makeWciMaster (Integer i);
//return (i<5||i>12) ? mkWciMaster : mkWciMasterNull; // only instance the 7 (0:4,13:14) we need
Expand Down Expand Up @@ -187,8 +187,8 @@ module mkOCCP#(PciId pciDevice, Clock time_clk, Reset time_rst) (OCCPIfc#(Nwcit)

'h4C : readCntReg <= unpack(wd);

'h6C : bluart.setClkDiv.put(truncate(unpack(wd)));
'h70 : bluart.txChar.put(truncate(unpack(wd)));
// 'h6C : bluart.setClkDiv.put(truncate(unpack(wd)));
// 'h70 : bluart.txChar.put(truncate(unpack(wd)));

endcase
cpReq <= tagged Idle;
Expand Down Expand Up @@ -248,12 +248,12 @@ module mkOCCP#(PciId pciDevice, Clock time_clk, Reset time_rst) (OCCPIfc#(Nwcit)
'h50 : rv = Valid(pack(devDNAV[0])); // LSBs of devDNA
'h54 : rv = Valid(pack(devDNAV[1])); // MSBs of devDNA

'h60 : rv = Valid(extend(pack(bluart.txLevel)));
'h64 : rv = Valid(extend(pack(bluart.rxLevel)));
'h68 : action
let d <- bluart.rxChar.get();
rv = Valid(extend(unpack(d)));
endaction
// 'h60 : rv = Valid(extend(pack(bluart.txLevel)));
// 'h64 : rv = Valid(extend(pack(bluart.rxLevel)));
// 'h68 : action
// let d <- bluart.rxChar.get();
// rv = Valid(extend(unpack(d)));
// endaction

'h7C : rv = Valid(32'd2); // DP Mem Region Descriptors...
'h80 : rv = Valid(pack(dpMemRegion0));
Expand Down Expand Up @@ -389,7 +389,7 @@ module mkOCCP#(PciId pciDevice, Clock time_clk, Reset time_rst) (OCCPIfc#(Nwcit)
method led = scratch24[1:0];
method Action switch (Bit#(3) x); switch_d <= x; endmethod
method Action uuid (Bit#(512) arg); uuidV <= unpack(arg); endmethod
interface UART_pads upads = bluart.pads;
// interface UART_pads upads = bluart.pads;

endmodule: mkOCCP
endpackage: OCCP
6 changes: 3 additions & 3 deletions bsv/inf/OCInf.bsv
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

package OCInf;

import BLUART ::*;
//import BLUART ::*;
import Config ::*;
import OCWip ::*;
import CPMux ::*;
Expand Down Expand Up @@ -48,7 +48,7 @@ interface OCInfIfc#(numeric type nWci_ctop, numeric type ndw);
method GPS64_t cpNow;
interface GPSIfc gps;
method Action uuid (Bit#(512) arg);
interface UART_pads upads;
// interface UART_pads upads;
endinterface

module mkOCInf_poly#(PciId pciDevice, Clock sys0_clk, Reset sys0_rst) (OCInfIfc#(Nwci_ctop,ndw))
Expand Down Expand Up @@ -134,7 +134,7 @@ module mkOCInf_poly#(PciId pciDevice, Clock sys0_clk, Reset sys0_rst) (OCInfIfc#
interface wmiDP0 = dp0.wmiS0;
interface wmiDP1 = dp1.wmiS0;
method Action uuid (Bit#(512) arg) = cp.uuid(arg); // Pass the UUID from the infrastrucrture down to the control plane
interface UART_pads upads = cp.upads;
// interface UART_pads upads = cp.upads;

endmodule : mkOCInf_poly

Expand Down
Loading

0 comments on commit fd35937

Please sign in to comment.