1 |
2 |
trurl |
-------------------------------------------------------------------
|
2 |
|
|
--!
|
3 |
|
|
--! PDP-8 Processor
|
4 |
|
|
--!
|
5 |
|
|
--! \brief
|
6 |
|
|
--! RK8E Secure Digital Interface Type Definitions
|
7 |
|
|
--!
|
8 |
|
|
--! \details
|
9 |
|
|
--! This package contains all the type information that is
|
10 |
|
|
--! required to use the Secure Digital Disk Interface
|
11 |
|
|
--!
|
12 |
|
|
--! \file
|
13 |
|
|
--! sd_types.vhd
|
14 |
|
|
--!
|
15 |
|
|
--! \author
|
16 |
|
|
--! Rob Doyle - doyle (at) cox (dot) net
|
17 |
|
|
--!
|
18 |
|
|
--------------------------------------------------------------------
|
19 |
|
|
--
|
20 |
|
|
-- Copyright (C) 2012 Rob Doyle
|
21 |
|
|
--
|
22 |
|
|
-- This source file may be used and distributed without
|
23 |
|
|
-- restriction provided that this copyright statement is not
|
24 |
|
|
-- removed from the file and that any derivative work contains
|
25 |
|
|
-- the original copyright notice and the associated disclaimer.
|
26 |
|
|
--
|
27 |
|
|
-- This source file is free software; you can redistribute it
|
28 |
|
|
-- and/or modify it under the terms of the GNU Lesser General
|
29 |
|
|
-- Public License as published by the Free Software Foundation;
|
30 |
|
|
-- version 2.1 of the License.
|
31 |
|
|
--
|
32 |
|
|
-- This source is distributed in the hope that it will be
|
33 |
|
|
-- useful, but WITHOUT ANY WARRANTY; without even the implied
|
34 |
|
|
-- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
35 |
|
|
-- PURPOSE. See the GNU Lesser General Public License for more
|
36 |
|
|
-- details.
|
37 |
|
|
--
|
38 |
|
|
-- You should have received a copy of the GNU Lesser General
|
39 |
|
|
-- Public License along with this source; if not, download it
|
40 |
|
|
-- from http://www.gnu.org/licenses/lgpl.txt
|
41 |
|
|
--
|
42 |
|
|
--------------------------------------------------------------------
|
43 |
|
|
--
|
44 |
|
|
-- Comments are formatted for doxygen
|
45 |
|
|
--
|
46 |
|
|
|
47 |
|
|
library ieee; --! IEEE Library
|
48 |
|
|
use ieee.std_logic_1164.all; --! IEEE 1164
|
49 |
|
|
use work.cpu_types.all; --! CPU types
|
50 |
|
|
|
51 |
|
|
--
|
52 |
|
|
--! RK8E Secure Digital Interface Type Definition Package
|
53 |
|
|
--
|
54 |
|
|
|
55 |
|
|
package sd_types is
|
56 |
|
|
|
57 |
|
|
--
|
58 |
|
|
--! Types
|
59 |
|
|
--
|
60 |
|
|
|
61 |
|
|
subtype sdBYTE_t is std_logic_vector(0 to 7); --! Byte
|
62 |
|
|
type sdCMD_t is array (0 to 5) of sdBYTE_t;--! SD Commands
|
63 |
|
|
subtype sdLEN_t is std_logic; --! Read/Write Length
|
64 |
|
|
subtype sdDISKaddr_t is std_logic_vector(0 to 31); --! SD Sector Address
|
65 |
|
|
subtype sdCCRC_t is std_logic_vector(0 to 6); --! Command CRC
|
66 |
|
|
subtype sdDCRC_t is std_logic_vector(0 to 15); --! Data CRC
|
67 |
|
|
type sdOP_t is (sdopNOP, --! SD NOP
|
68 |
|
|
sdopABORT, --! Abort Read or Write
|
69 |
|
|
sdopRD, --! Read SD disk
|
70 |
|
|
sdopWR); --! Write SD disk
|
71 |
|
|
type sdSTATE_t is (sdstateINIT, --! SD Initializing
|
72 |
|
|
sdstateREADY, --! SD Ready for commands
|
73 |
|
|
sdstateREAD, --! SD Reading
|
74 |
|
|
sdstateWRITE, --! SD Writing
|
75 |
|
|
sdstateDONE, --! SD Done
|
76 |
|
|
sdstateINFAIL, --! SD Initialization Failed
|
77 |
|
|
sdstateRWFAIL); --! SD Read/Write Failed
|
78 |
|
|
type sdSTAT_t is record
|
79 |
|
|
state : sdSTATE_t; --! SD Status
|
80 |
|
|
err : sdBYTE_t; --! Error Status
|
81 |
|
|
val : sdBYTE_t; --! Value Status
|
82 |
|
|
rdCNT : sdBYTE_t; --! Read Count Status
|
83 |
|
|
wrCNT : sdBYTE_t; --! Write Count Status
|
84 |
|
|
debug : sdBYTE_t; --! Debug State
|
85 |
|
|
end record;
|
86 |
|
|
|
87 |
|
|
--
|
88 |
|
|
--! Functions
|
89 |
|
|
--
|
90 |
|
|
|
91 |
|
|
function crc7 (indat : sdBYTE_t; crc : sdCCRC_t) return sdCCRC_t;
|
92 |
|
|
function crc16(indat : sdBYTE_t; crc : sdDCRC_t) return sdDCRC_t;
|
93 |
|
|
|
94 |
|
|
end sd_types;
|
95 |
|
|
|
96 |
|
|
--
|
97 |
|
|
--! RK8E Secure Digital Interface Type Definition Package Body
|
98 |
|
|
--
|
99 |
|
|
|
100 |
|
|
package body sd_types is
|
101 |
|
|
|
102 |
|
|
--
|
103 |
|
|
--! CRC7: Used for Command CRC
|
104 |
|
|
--
|
105 |
|
|
|
106 |
|
|
function crc7(indat : sdBYTE_t; crc : sdCCRC_t) return sdCCRC_t is
|
107 |
|
|
variable outdat : sdCCRC_t;
|
108 |
|
|
begin
|
109 |
|
|
outdat( 0) := crc( 4) xor crc( 1) xor crc( 0) xor indat( 4) xor indat( 1) xor indat( 0);
|
110 |
|
|
outdat( 1) := crc( 5) xor crc( 2) xor crc( 1) xor indat( 5) xor indat( 2) xor indat( 1);
|
111 |
|
|
outdat( 2) := crc( 6) xor crc( 3) xor crc( 2) xor indat( 6) xor indat( 3) xor indat( 2);
|
112 |
|
|
outdat( 3) := crc( 4) xor crc( 3) xor indat( 7) xor indat( 4) xor indat( 3);
|
113 |
|
|
outdat( 4) := crc( 5) xor crc( 1) xor indat( 5) xor indat( 1);
|
114 |
|
|
outdat( 5) := crc( 6) xor crc( 2) xor indat( 6) xor indat( 2);
|
115 |
|
|
outdat( 6) := crc( 3) xor crc( 0) xor indat( 7) xor indat( 3) xor indat( 0);
|
116 |
|
|
return outdat;
|
117 |
|
|
end crc7;
|
118 |
|
|
|
119 |
|
|
--
|
120 |
|
|
--! CRC16: Used for Data CRC
|
121 |
|
|
--
|
122 |
|
|
|
123 |
|
|
function crc16(indat : sdBYTE_t; crc : sdDCRC_t) return sdDCRC_t is
|
124 |
|
|
variable outdat : sdDCRC_t;
|
125 |
|
|
begin
|
126 |
|
|
outdat( 0) := crc( 8) xor crc( 4) xor crc( 0) xor indat( 4) xor indat( 0);
|
127 |
|
|
outdat( 1) := crc( 9) xor crc( 5) xor crc( 1) xor indat( 5) xor indat( 1);
|
128 |
|
|
outdat( 2) := crc(10) xor crc( 6) xor crc( 2) xor indat( 6) xor indat( 2);
|
129 |
|
|
outdat( 3) := crc(11) xor crc( 7) xor crc( 3) xor crc( 0) xor indat( 7) xor indat( 3) xor indat( 0);
|
130 |
|
|
outdat( 4) := crc(12) xor crc( 1) xor indat( 1);
|
131 |
|
|
outdat( 5) := crc(13) xor crc( 2) xor indat( 2);
|
132 |
|
|
outdat( 6) := crc(14) xor crc( 3) xor indat( 3);
|
133 |
|
|
outdat( 7) := crc(15) xor crc( 4) xor crc( 0) xor indat( 3) xor indat( 0);
|
134 |
|
|
outdat( 8) := crc( 5) xor crc( 1) xor crc( 0) xor indat( 5) xor indat( 1) xor indat( 0);
|
135 |
|
|
outdat( 9) := crc( 6) xor crc( 2) xor crc( 1) xor indat( 6) xor indat( 2) xor indat( 1);
|
136 |
|
|
outdat(10) := crc( 7) xor crc( 3) xor crc( 2) xor indat( 7) xor indat( 3) xor indat( 2);
|
137 |
|
|
outdat(11) := crc( 3) xor indat( 3);
|
138 |
|
|
outdat(12) := crc( 4) xor crc( 0) xor indat( 4) xor indat( 0);
|
139 |
|
|
outdat(13) := crc( 5) xor crc( 1) xor indat( 5) xor indat( 1);
|
140 |
|
|
outdat(14) := crc( 6) xor crc( 2) xor indat( 6) xor indat( 2);
|
141 |
|
|
outdat(15) := crc( 7) xor crc( 3) xor indat( 7) xor indat( 3);
|
142 |
|
|
return outdat;
|
143 |
|
|
end crc16;
|
144 |
|
|
|
145 |
|
|
end package body;
|
146 |
|
|
|