URL
https://opencores.org/ocsvn/sdhc-sc-core/sdhc-sc-core/trunk
Subversion Repositories sdhc-sc-core
Compare Revisions
- This comparison shows the changes necessary to convert path
/sdhc-sc-core/trunk
- from Rev 53 to Rev 54
- ↔ Reverse comparison
Rev 53 → Rev 54
/src/grpSd/unitSdCardModel/src/SdCardModel.sv
116,32 → 116,32
task automatic send(virtual ISdCmd.Card ICmd); |
calcCrc(); |
|
@ICmd.cbCard; |
ICmd.cbCard.Cmd <= startbit; |
@ICmd.cb; |
ICmd.cb.Cmd <= startbit; |
|
@ICmd.cbCard; |
ICmd.cbCard.Cmd <= transbit; |
@ICmd.cb; |
ICmd.cb.Cmd <= transbit; |
|
for(int i = 5; i >= 0; i--) begin |
@ICmd.cbCard; |
ICmd.cbCard.Cmd <= id[i]; |
@ICmd.cb; |
ICmd.cb.Cmd <= id[i]; |
end |
|
for (int i = 31; i>= 0; i--) begin |
@ICmd.cbCard; |
ICmd.cbCard.Cmd <= arg[i]; |
@ICmd.cb; |
ICmd.cb.Cmd <= arg[i]; |
end |
|
for (int i = 5; i >= 0; i--) begin |
@ICmd.cbCard; |
ICmd.cbCard.Cmd <= crc[i]; |
@ICmd.cb; |
ICmd.cb.Cmd <= crc[i]; |
end |
|
@ICmd.cbCard; |
ICmd.cbCard.Cmd <= endbit; |
@ICmd.cb; |
ICmd.cb.Cmd <= endbit; |
|
@ICmd.cbCard; |
ICmd.cbCard.Cmd <= 'z; |
@ICmd.cb; |
ICmd.cb.Cmd <= 'z; |
endtask |
endclass |
|
179,37 → 179,37
// Receive a command token and handle it |
task recv(); |
recvcmd = new(); |
ICmd.cbCard.Cmd <= 'z; |
ICmd.cb.Cmd <= 'z; |
|
wait(ICmd.cbCard.Cmd == 0); |
wait(ICmd.cb.Cmd == 0); |
// Startbit |
recvcmd.startbit = ICmd.cbCard.Cmd; |
recvcmd.startbit = ICmd.cb.Cmd; |
|
@ICmd.cbCard; |
@ICmd.cb; |
// Transbit |
recvcmd.transbit = ICmd.cbCard.Cmd; |
recvcmd.transbit = ICmd.cb.Cmd; |
|
// CmdID |
for (int i = 5; i >= 0; i--) begin |
@ICmd.cbCard; |
recvcmd.id[i] = ICmd.cbCard.Cmd; |
@ICmd.cb; |
recvcmd.id[i] = ICmd.cb.Cmd; |
end |
|
// Arg |
for (int i = 31; i >= 0; i--) begin |
@ICmd.cbCard; |
recvcmd.arg[i] = ICmd.cbCard.Cmd; |
@ICmd.cb; |
recvcmd.arg[i] = ICmd.cb.Cmd; |
end |
|
// CRC |
for (int i = 6; i >= 0; i--) begin |
@ICmd.cbCard; |
recvcmd.crc7[i] = ICmd.cbCard.Cmd; |
@ICmd.cb; |
recvcmd.crc7[i] = ICmd.cb.Cmd; |
end |
|
// Endbit |
@ICmd.cbCard; |
recvcmd.endbit = ICmd.cbCard.Cmd; |
@ICmd.cb; |
recvcmd.endbit = ICmd.cb.Cmd; |
|
recvcmd.checkFromHost(); |
-> CmdReceived; |
/src/grpSd/pkgSd/src/Sd-p.vhdl
12,11 → 12,13
|
package Sd is |
|
-- CMD transfer: constants |
constant cSdStartBit : std_ulogic := '0'; |
constant cSdEndBit : std_ulogic := '1'; |
constant cSdTransBitHost : std_ulogic := '1'; |
constant cSdTransBitSlave : std_ulogic := '0'; |
|
-- CMD transfer: types |
constant cSdCmdIdHigh : natural := 6; |
subtype aSdCmdId is std_ulogic_vector(cSdCmdIdHigh-1 downto 0); |
subtype aSdCmdArg is std_ulogic_vector(31 downto 0); |
33,7 → 35,19
crc7 : std_ulogic_vector(6 downto 0); -- CRC of content |
endbit : std_ulogic; --cSdEndBit |
end record aSdCmdToken; |
|
-- Types for entities |
type aSdCmdFromController is record |
Content : aSdCmdContent; |
Valid : std_ulogic; |
end record aSdCmdFromController; |
|
type aSdCmdToController is record |
Ack : std_ulogic; -- Gets asserted when crc was sent, but endbit was |
-- not. This way we can minimize the wait time between sending 2 cmds. |
Receiving : std_ulogic; |
end record aSdCmdToController; |
|
-- command ids |
-- abbreviations: |
-- RCA: relative card address |
56,9 → 70,18
constant cSdCmdDeselCard : aSdCmdId := cSdCmdSelCard; -- [31:16] RCA |
|
constant cSdCmdSendIfCond : aSdCmdId := std_ulogic_vector(to_unsigned(8, |
cSdCmdIdHigh)); -- [31:12] reserved, [11:8] supply voltage, [7:0] check |
-- pattern |
cSdCmdIdHigh)); |
|
constant cSdDefaultVoltage : std_ulogic_vector(3 downto 0) := "0001"; -- 2.7 |
-- - 3.6 V |
constant cCheckpattern : std_ulogic_vector(7 downto 0) := "10101010"; |
-- recommended |
|
constant cSdArgVoltage : aSdCmdArg := |
"00000000000000000000" & -- reserved |
cSdDefaultVoltage & -- supply voltage |
cCheckPattern; |
|
constant cSdCmdSendCSD : aSdCmdId := std_ulogic_vector(to_unsigned(9, |
cSdCmdIdHigh)); -- [31:16] RCA |
|
71,14 → 94,5
constant cSdCmdSendStatus : aSdCmdId := std_ulogic_vector(to_unsigned(13, |
cSdCmdIdHigh)); -- [31:16] RCA |
|
type aSdCmdFromController is record |
Content : aSdCmdContent; |
Valid : std_ulogic; |
end record aSdCmdFromController; |
|
type aSdCmdToController is record |
Receiving : std_ulogic; |
end record aSdCmdToController; |
|
end package Sd; |
|
/src/grpSd/unitSdVerificationTestbench/src/SdVerificationTestbench.sv
16,7 → 16,6
initial begin |
SDCard card = new(ICmd, $root.Testbed.CmdReceived, $root.Testbed.InitDone); |
SDCommandToken recvCmd, sendCmd; |
bit done = 0; |
int c = 0; |
|
ICmd.Clk <= 0; |
29,49 → 28,11
|
fork |
begin // generator |
// init |
sendCmd = new(); |
|
@ICmd.cb; |
sendCmd.id = cSdCmdGoIdleState; |
sendCmd.arg = 0; |
-> $root.Testbed.ApplyCommand; |
@$root.Testbed.CmdReceived; |
|
sendCmd.id = cSdCmdSendIfCond; |
sendCmd.arg[31:12] = 0; // Reserved |
sendCmd.arg[11:8] = cSdStandardVoltage; // 2.7 - 3.6V |
sendCmd.arg[7:0] = 'b10101010; // Check pattern, recommended value |
-> $root.Testbed.ApplyCommand; |
@$root.Testbed.CmdReceived; |
|
ICmd.Valid <= 0; |
@$root.Testbed.InitDone; |
|
for (int i = 0; i < `cCmdCount; i++) begin |
$display("generator: %0d", i); |
sendCmd = new(); |
sendCmd.randomize(); |
-> $root.Testbed.ApplyCommand; |
@$root.Testbed.GenCmd; |
end |
end |
|
begin // monitor |
end |
|
begin // driver for SdCmd |
for (int i = 0; i < `cCmdCount + 2; i++) begin |
@$root.Testbed.ApplyCommand; |
|
$display("driver: %0d", i); |
ICmd.CmdId <= sendCmd.id; |
ICmd.Arg <= sendCmd.arg; |
ICmd.Valid <= 1; |
-> $root.Testbed.CardRecv; |
end |
end |
|
begin // driver for SdCardModel |
card.init(); |
|
107,9 → 68,7
module Testbed(); |
ISdCmd CmdInterface(); |
|
SdCmdWrapper CmdWrapper(CmdInterface.Clk, CmdInterface.nResetAsync, |
CmdInterface.CmdId, CmdInterface.Arg, CmdInterface.Valid, |
CmdInterface.Receiving, CmdInterface.Cmd); |
SdTop top(CmdInterface.Clk, CmdInterface.nResetAsync, CmdInterface.Cmd); |
|
always #10 CmdInterface.Clk <= ~CmdInterface.Clk; |
|
/src/grpSd/unitSdVerificationTestbench/src/SdCmdInterface.sv
8,33 → 8,19
interface ISdCmd; |
logic Clk; |
logic nResetAsync; |
logic[5:0] CmdId; |
SDCommandArg Arg; |
logic Valid; |
logic Receiving; |
wire Cmd; |
|
clocking cb @(posedge Clk); |
input Receiving; |
output CmdId, Arg, Valid; |
inout Cmd; |
endclocking |
|
modport Controller ( |
input Clk, clocking cb |
modport Testbench ( |
input Clk, nResetAsync, clocking cb |
); |
|
clocking cbCard @(posedge Clk); |
inout Cmd; |
endclocking |
modport Card ( |
clocking cbCard |
clocking cb |
); |
|
modport SdCmd ( |
input Clk, nResetAsync, CmdId, Arg, Valid, |
inout Cmd, |
output Receiving |
); |
|
endinterface |
|
/src/grpSd/unitSdVerificationTestbench/sim/wave.do
2,24 → 2,28
quietly WaveActivateNextPane {} 0 |
add wave -noupdate -format Logic /Testbed/CmdInterface/Clk |
add wave -noupdate -format Logic /Testbed/CmdInterface/nResetAsync |
add wave -noupdate -format Literal /Testbed/CmdInterface/CmdId |
add wave -noupdate -format Literal /Testbed/CmdInterface/Arg |
add wave -noupdate -format Logic /Testbed/CmdInterface/Valid |
add wave -noupdate -format Logic /Testbed/CmdInterface/Receiving |
add wave -noupdate -format Logic /Testbed/CmdInterface/Cmd |
add wave -noupdate -format Logic /Testbed/CmdWrapper/sdcmd/iocmd |
add wave -noupdate -format Literal /Testbed/CmdWrapper/sdcmd/state |
add wave -noupdate -format Literal /Testbed/CmdWrapper/sdcmd/nextstate |
add wave -noupdate -format Logic /Testbed/CmdWrapper/sdcmd/serialcrc |
add wave -noupdate -format Literal /Testbed/CmdWrapper/sdcmd/counter |
add wave -noupdate -format Literal /Testbed/CmdWrapper/sdcmd/nextcounter |
add wave -noupdate -format Literal /Testbed/CmdWrapper/sdcmd/output |
add wave -noupdate -format Literal /Testbed/CmdWrapper/sdcmd/otocontroller |
add wave -noupdate -format Literal /Testbed/CmdWrapper/sdcmd/ifromcontroller |
add wave -noupdate -format Logic /Testbed/CmdWrapper/sdcmd/inresetasync |
add wave -noupdate -format Logic /Testbed/CmdWrapper/sdcmd/iclk |
add wave -noupdate -divider Controller |
add wave -noupdate -format Literal /Testbed/top/sdcontroller_inst/state |
add wave -noupdate -format Literal /Testbed/top/sdcontroller_inst/nextstate |
add wave -noupdate -format Literal /Testbed/top/sdcontroller_inst/osdcmd |
add wave -noupdate -format Literal /Testbed/top/sdcontroller_inst/isdcmd |
add wave -noupdate -format Logic /Testbed/top/sdcontroller_inst/inresetasync |
add wave -noupdate -format Logic /Testbed/top/sdcontroller_inst/iclk |
add wave -noupdate -divider Cmd |
add wave -noupdate -format Literal /Testbed/top/sdcmd_inst/state |
add wave -noupdate -format Literal /Testbed/top/sdcmd_inst/nextstate |
add wave -noupdate -format Logic /Testbed/top/sdcmd_inst/serialcrc |
add wave -noupdate -format Literal /Testbed/top/sdcmd_inst/counter |
add wave -noupdate -format Literal /Testbed/top/sdcmd_inst/nextcounter |
add wave -noupdate -format Literal /Testbed/top/sdcmd_inst/output |
add wave -noupdate -format Logic /Testbed/top/sdcmd_inst/iocmd |
add wave -noupdate -format Literal /Testbed/top/sdcmd_inst/otocontroller |
add wave -noupdate -format Literal /Testbed/top/sdcmd_inst/ifromcontroller |
add wave -noupdate -format Logic /Testbed/top/sdcmd_inst/inresetasync |
add wave -noupdate -format Logic /Testbed/top/sdcmd_inst/iclk |
TreeUpdate [SetDefaultTree] |
WaveRestoreCursors {{Cursor 1} {0 ns} 0} |
WaveRestoreCursors {{Cursor 1} {365 ns} 0} |
configure wave -namecolwidth 150 |
configure wave -valuecolwidth 100 |
configure wave -justifyvalue left |
34,4 → 38,4
configure wave -timeline 0 |
configure wave -timelineunits ns |
update |
WaveRestoreZoom {0 ns} {1913 ns} |
WaveRestoreZoom {20068053 ns} {20069966 ns} |
/src/grpSd/unitSdVerificationTestbench/sim/SdVerificationTestbench.tcl
1,5 → 1,5
set pkgs {Global Global Sd Sd Crc CRCs} |
set units {Crc Crc {Rtl} Sd SdCmd {Rtl} Sd SdCmdWrapper {Rtl}} |
set units {Crc Crc {Rtl} Sd SdCmd {Rtl} Sd SdController {Rtl} Sd SdTop {Rtl}} |
set svunits {Sd SdCardModel Sd SdVerificationTestbench} |
#set tb |
#set tbarch |
/src/grpSd/unitSdTop/src/SdTop-Rtl-ea.vhdl
0,0 → 1,46
------------------------------------------------- |
-- file: ../../unitSdTop/src/SdTop-Rtl-ea.vhdl |
-- author: Rainer Kastl |
-- |
-- Top level entity for a SD Controller |
------------------------------------------------- |
|
library ieee; |
use ieee.std_logic_1164.all; |
use ieee.numeric_std.all; |
use work.Global.all; |
use work.Sd.all; |
|
entity SdTop is |
port ( |
iClk : in std_ulogic; |
inResetAsync : in std_ulogic; |
|
-- SD Card |
ioCmd : inout std_logic -- Cmd line to and from card |
); |
end entity SdTop; |
|
architecture Rtl of SdTop is |
|
signal ToController : aSdCmdToController; |
signal FromController : aSdCmdFromController; |
|
begin |
|
SdController_inst: entity work.SdController(Rtl) |
port map (iClk => iClk, |
inResetAsync => inResetAsync, |
iSdCmd => ToController, |
oSdCmd => FromController); |
|
|
SdCmd_inst: entity work.SdCmd(Rtl) |
port map (iClk => iClk, |
inResetAsync => inResetAsync, |
iFromController => FromController, |
oToController => ToController, |
ioCmd => ioCmd); |
|
end architecture Rtl; |
|
/src/grpSd/unitSdCmd/src/SdCmd-Rtl-ea.vhdl
49,12 → 49,12
signal Output : aSdCmdOut; |
|
constant cDefaultOut : aSdCmdOut := ((cInactivated, cInactivated, |
cInactivated), (Receiving => cInactivated), 'Z'); |
cInactivated), (Ack => cInactivated, Receiving => cInactivated), 'Z'); |
|
begin |
|
ioCmd <= Output.Cmd; |
oToController.Receiving <= cInactivated; |
oToController <= Output.Controller; |
|
-- State register |
CmdStateReg : process (iClk, inResetAsync) |
128,7 → 128,12
|
when crc => |
Output.Cmd <= SerialCrc; |
NextStateWhenAllSent(0, endbit); |
if (Counter > 0) then |
NextCounter <= Counter - 1; |
else |
NextState <= endbit; |
Output.Controller.Ack <= cActivated; |
end if; |
|
when endbit => |
Output.Cmd <= cSdEndBit; |
/src/grpSd/unitSdController/src/SdController-e.vhdl
File deleted
/src/grpSd/unitSdController/src/SdController-Rtl-ea.vhdl
0,0 → 1,85
------------------------------------------------- |
-- file: SdController-Rtl-ea.vhdl |
-- author: Rainer Kastl |
-- |
-- Main statemachine for a SDHC compatible SD Controller |
-- Simplified Physical Layer Spec. 2.00 |
------------------------------------------------- |
|
library ieee; |
use ieee.std_logic_1164.all; |
use ieee.numeric_std.all; |
use work.Global.all; |
use work.Sd.all; |
|
entity SdController is |
port ( |
iClk : in std_ulogic; -- rising edge |
inResetAsync : in std_ulogic; |
|
-- SDCmd |
iSdCmd : in aSdCmdToController; |
oSdCmd : out aSdCmdFromController |
); |
end entity SdController; |
|
architecture Rtl of SdController is |
|
type aSdControllerState is (CMD0, CMD8Ws, CMD8, CMD8Response, idle); |
constant cDefaultControllerState : aSdControllerState := CMD0; |
constant cDefaultoSdCmd : aSdCmdFromController := ((id => (others => '0'), |
arg => (others => '0')), Valid => cInactivated); |
|
signal State, NextState : aSdControllerState; |
|
begin |
|
Regs : process (iClk, inResetAsync) |
begin |
if (inResetAsync = cnActivated) then |
State <= cDefaultControllerState; |
elsif (iClk'event and iClk = cActivated) then |
State <= NextState; |
end if; |
end process Regs; |
|
Comb : process (iSdCmd, State) |
begin |
-- default assignments |
oSdCmd <= cDefaultoSdCmd; |
|
case State is |
when idle => null; |
|
when CMD0 => |
oSdCmd.Content.id <= cSdCmdGoIdleState; |
oSdCmd.Valid <= cActivated; |
if (iSdCmd.Ack = cActivated) then |
NextState <= CMD8Ws; |
end if; |
|
when CMD8Ws => |
if (iSdCmd.Ack = cInactivated) then |
NextState <= CMD8; |
end if; |
|
when CMD8 => |
oSdCmd.Content.id <= cSdCmdSendIfCond; |
oSdCmd.Content.arg <= cSdArgVoltage; |
oSdCmd.Valid <= cActivated; |
if (iSdCmd.Ack = cActivated) then |
NextState <= CMD8Response; |
end if; |
|
when CMD8Response => |
null; |
|
when others => |
report "SdController: State not handled" severity error; |
end case; |
end process Comb; |
|
|
|
end architecture Rtl; |
|