1 |
3 |
iztok |
###############################################################################
|
2 |
|
|
# #
|
3 |
|
|
# Minimalistic 1-wire (onewire) master with Avalon MM bus interface #
|
4 |
|
|
# #
|
5 |
|
|
# Copyright (C) 2010 Iztok Jeras #
|
6 |
|
|
# #
|
7 |
|
|
###############################################################################
|
8 |
|
|
# #
|
9 |
|
|
# This script is free hardware: you can redistribute it and/or modify #
|
10 |
|
|
# it under the terms of the GNU Lesser General Public License #
|
11 |
|
|
# as published by the Free Software Foundation, either #
|
12 |
|
|
# version 3 of the License, or (at your option) any later version. #
|
13 |
|
|
# #
|
14 |
|
|
# This RTL is distributed in the hope that it will be useful, #
|
15 |
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
|
16 |
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
|
17 |
|
|
# GNU General Public License for more details. #
|
18 |
|
|
# #
|
19 |
|
|
# You should have received a copy of the GNU General Public License #
|
20 |
|
|
# along with this program. If not, see <http:#www.gnu.org/licenses/>. #
|
21 |
|
|
# #
|
22 |
|
|
###############################################################################
|
23 |
2 |
iztok |
|
24 |
3 |
iztok |
# request TCL package from Altera tools version 10.0
|
25 |
|
|
package require -exact sopc 10.0
|
26 |
2 |
iztok |
|
27 |
|
|
# module sockit_owm
|
28 |
3 |
iztok |
set_module_property NAME sockit_owm
|
29 |
|
|
set_module_property VERSION 1.3
|
30 |
|
|
set_module_property GROUP "Interface Protocols/Serial"
|
31 |
|
|
set_module_property DISPLAY_NAME "1-wire (onewire) master"
|
32 |
|
|
set_module_property DESCRIPTION "1-wire (onewire) master"
|
33 |
|
|
set_module_property AUTHOR "Iztok Jeras"
|
34 |
|
|
|
35 |
5 |
iztok |
set_module_property TOP_LEVEL_HDL_FILE hdl/sockit_owm.v
|
36 |
3 |
iztok |
set_module_property TOP_LEVEL_HDL_MODULE sockit_owm
|
37 |
2 |
iztok |
set_module_property INSTANTIATE_IN_SYSTEM_MODULE true
|
38 |
3 |
iztok |
set_module_property EDITABLE true
|
39 |
2 |
iztok |
|
40 |
3 |
iztok |
# callbacks
|
41 |
2 |
iztok |
set_module_property VALIDATION_CALLBACK validation_callback
|
42 |
|
|
set_module_property ELABORATION_CALLBACK elaboration_callback
|
43 |
|
|
|
44 |
3 |
iztok |
# documentation links and files
|
45 |
|
|
add_documentation_link WEBLINK https://github.com/jeras/sockit_owm
|
46 |
|
|
add_documentation_link WEBLINK http://opencores.org/project,sockit_owm
|
47 |
|
|
add_documentation_link DATASHEET doc/sockit_owm.pdf
|
48 |
2 |
iztok |
|
49 |
|
|
# RTL files
|
50 |
3 |
iztok |
add_file hdl/sockit_owm.v {SYNTHESIS SIMULATION}
|
51 |
2 |
iztok |
|
52 |
|
|
# parameters
|
53 |
3 |
iztok |
add_parameter OVD_E BOOLEAN
|
54 |
|
|
set_parameter_property OVD_E DESCRIPTION "Implementation of overdrive enable, disabling it can spare a small amount of logic."
|
55 |
|
|
set_parameter_property OVD_E DEFAULT_VALUE 1
|
56 |
|
|
set_parameter_property OVD_E UNITS None
|
57 |
|
|
set_parameter_property OVD_E AFFECTS_GENERATION false
|
58 |
|
|
set_parameter_property OVD_E HDL_PARAMETER true
|
59 |
|
|
|
60 |
|
|
add_parameter CDR_E BOOLEAN
|
61 |
|
|
set_parameter_property CDR_E DESCRIPTION "Implementation of clock divider ratio registers, disabling it can spare a small amount of logic."
|
62 |
|
|
set_parameter_property CDR_E DEFAULT_VALUE 0
|
63 |
|
|
set_parameter_property CDR_E UNITS None
|
64 |
|
|
set_parameter_property CDR_E AFFECTS_GENERATION false
|
65 |
|
|
set_parameter_property CDR_E HDL_PARAMETER true
|
66 |
|
|
|
67 |
2 |
iztok |
add_parameter BDW INTEGER
|
68 |
|
|
set_parameter_property BDW DESCRIPTION "CPU interface data bus width"
|
69 |
3 |
iztok |
set_parameter_property BDW VISIBLE false
|
70 |
2 |
iztok |
set_parameter_property BDW DEFAULT_VALUE 32
|
71 |
|
|
set_parameter_property BDW ALLOWED_RANGES {8 32}
|
72 |
|
|
set_parameter_property BDW UNITS bits
|
73 |
|
|
set_parameter_property BDW ENABLED false
|
74 |
|
|
set_parameter_property BDW AFFECTS_GENERATION false
|
75 |
|
|
set_parameter_property BDW HDL_PARAMETER true
|
76 |
|
|
|
77 |
3 |
iztok |
add_parameter BAW INTEGER
|
78 |
|
|
set_parameter_property BAW DESCRIPTION "CPU interface address bus width"
|
79 |
|
|
set_parameter_property BAW VISIBLE false
|
80 |
|
|
set_parameter_property BAW DEFAULT_VALUE 1
|
81 |
|
|
set_parameter_property BAW ALLOWED_RANGES {1 2}
|
82 |
|
|
set_parameter_property BAW UNITS bits
|
83 |
|
|
set_parameter_property BAW ENABLED false
|
84 |
|
|
set_parameter_property BAW AFFECTS_GENERATION false
|
85 |
|
|
set_parameter_property BAW HDL_PARAMETER true
|
86 |
2 |
iztok |
|
87 |
|
|
add_parameter OWN INTEGER
|
88 |
|
|
set_parameter_property OWN DESCRIPTION "Nummber of 1-wire channels"
|
89 |
|
|
#set_parameter_property OWN DISPLAY_NAME OWN
|
90 |
|
|
set_parameter_property OWN DEFAULT_VALUE 1
|
91 |
|
|
set_parameter_property OWN ALLOWED_RANGES {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16}
|
92 |
|
|
set_parameter_property OWN AFFECTS_GENERATION false
|
93 |
|
|
set_parameter_property OWN AFFECTS_ELABORATION true
|
94 |
|
|
set_parameter_property OWN HDL_PARAMETER true
|
95 |
|
|
|
96 |
|
|
add_parameter BTP_N STRING
|
97 |
|
|
set_parameter_property BTP_N DESCRIPTION "Base time period for normal mode"
|
98 |
|
|
#set_parameter_property BTP_N DISPLAY_NAME BTP_N
|
99 |
|
|
set_parameter_property BTP_N DISPLAY_HINT "radio"
|
100 |
|
|
set_parameter_property BTP_N DEFAULT_VALUE "5.0"
|
101 |
|
|
set_parameter_property BTP_N ALLOWED_RANGES {"5.0:5.0us (preferred)" "7.5:7.5us" "6.0:6.0us - 7.5us"}
|
102 |
|
|
set_parameter_property BTP_N AFFECTS_GENERATION false
|
103 |
|
|
set_parameter_property BTP_N HDL_PARAMETER true
|
104 |
|
|
|
105 |
|
|
add_parameter BTP_O STRING
|
106 |
|
|
set_parameter_property BTP_O DESCRIPTION "Base time period for overdrive mode"
|
107 |
|
|
#set_parameter_property BTP_O DISPLAY_NAME BTP_N
|
108 |
|
|
set_parameter_property BTP_O DISPLAY_HINT "radio"
|
109 |
|
|
set_parameter_property BTP_O DEFAULT_VALUE "1.0"
|
110 |
|
|
set_parameter_property BTP_O ALLOWED_RANGES {"1.0:1.0us (preferred)" "0.5:0.5us - 0.66us"}
|
111 |
|
|
set_parameter_property BTP_O AFFECTS_GENERATION false
|
112 |
|
|
set_parameter_property BTP_O HDL_PARAMETER true
|
113 |
|
|
|
114 |
|
|
add_parameter F_CLK INTEGER
|
115 |
|
|
set_parameter_property F_CLK SYSTEM_INFO {CLOCK_RATE clock_reset}
|
116 |
|
|
set_parameter_property F_CLK DISPLAY_NAME F_CLK
|
117 |
|
|
set_parameter_property F_CLK DESCRIPTION "System clock frequency"
|
118 |
|
|
set_parameter_property F_CLK UNITS megahertz
|
119 |
|
|
|
120 |
3 |
iztok |
add_parameter CDR_N NATURAL
|
121 |
2 |
iztok |
set_parameter_property CDR_N DERIVED true
|
122 |
|
|
set_parameter_property CDR_N DESCRIPTION "Clock divider ratio for normal mode"
|
123 |
|
|
set_parameter_property CDR_N DISPLAY_NAME CDR_N
|
124 |
|
|
set_parameter_property CDR_N DEFAULT_VALUE 5
|
125 |
|
|
set_parameter_property CDR_N AFFECTS_GENERATION false
|
126 |
|
|
set_parameter_property CDR_N HDL_PARAMETER true
|
127 |
|
|
|
128 |
3 |
iztok |
add_parameter CDR_O NATURAL
|
129 |
2 |
iztok |
set_parameter_property CDR_O DERIVED true
|
130 |
|
|
set_parameter_property CDR_O DESCRIPTION "Clock divider ratio for overdrive mode"
|
131 |
|
|
set_parameter_property CDR_O DISPLAY_NAME CDR_O
|
132 |
|
|
set_parameter_property CDR_O DEFAULT_VALUE 1
|
133 |
|
|
set_parameter_property CDR_O AFFECTS_GENERATION false
|
134 |
|
|
set_parameter_property CDR_O HDL_PARAMETER true
|
135 |
|
|
|
136 |
|
|
add_display_item "Base time period options" BTP_N parameter
|
137 |
|
|
add_display_item "Base time period options" BTP_O parameter
|
138 |
3 |
iztok |
add_display_item "Clock dividers" F_CLK parameter
|
139 |
|
|
add_display_item "Clock dividers" CDR_N parameter
|
140 |
|
|
add_display_item "Clock dividers" CDR_O parameter
|
141 |
2 |
iztok |
|
142 |
|
|
# connection point clock_reset
|
143 |
|
|
add_interface clock_reset clock end
|
144 |
|
|
|
145 |
|
|
set_interface_property clock_reset ENABLED true
|
146 |
|
|
|
147 |
3 |
iztok |
add_interface_port clock_reset clk clk Input 1
|
148 |
2 |
iztok |
add_interface_port clock_reset rst reset Input 1
|
149 |
|
|
|
150 |
|
|
# connection point s1
|
151 |
|
|
add_interface s1 avalon end
|
152 |
|
|
set_interface_property s1 addressAlignment DYNAMIC
|
153 |
|
|
set_interface_property s1 associatedClock clock_reset
|
154 |
|
|
set_interface_property s1 burstOnBurstBoundariesOnly false
|
155 |
|
|
set_interface_property s1 explicitAddressSpan 0
|
156 |
|
|
set_interface_property s1 holdTime 0
|
157 |
|
|
set_interface_property s1 isMemoryDevice false
|
158 |
|
|
set_interface_property s1 isNonVolatileStorage false
|
159 |
|
|
set_interface_property s1 linewrapBursts false
|
160 |
|
|
set_interface_property s1 maximumPendingReadTransactions 0
|
161 |
|
|
set_interface_property s1 printableDevice false
|
162 |
|
|
set_interface_property s1 readLatency 0
|
163 |
|
|
set_interface_property s1 readWaitStates 0
|
164 |
|
|
set_interface_property s1 readWaitTime 0
|
165 |
|
|
set_interface_property s1 setupTime 0
|
166 |
|
|
set_interface_property s1 timingUnits Cycles
|
167 |
|
|
set_interface_property s1 writeWaitTime 0
|
168 |
|
|
|
169 |
|
|
set_interface_property s1 ASSOCIATED_CLOCK clock_reset
|
170 |
|
|
set_interface_property s1 ENABLED true
|
171 |
|
|
|
172 |
3 |
iztok |
add_interface_port s1 bus_ren read Input 1
|
173 |
|
|
add_interface_port s1 bus_wen write Input 1
|
174 |
|
|
add_interface_port s1 bus_adr address Input BAW
|
175 |
|
|
add_interface_port s1 bus_wdt writedata Input BDW
|
176 |
|
|
add_interface_port s1 bus_rdt readdata Output BDW
|
177 |
2 |
iztok |
|
178 |
|
|
# connection point irq
|
179 |
|
|
add_interface irq interrupt end
|
180 |
|
|
set_interface_property irq associatedClock clock_reset
|
181 |
|
|
set_interface_property irq associatedAddressablePoint s1
|
182 |
|
|
|
183 |
|
|
set_interface_property irq ASSOCIATED_CLOCK clock_reset
|
184 |
|
|
set_interface_property irq ENABLED true
|
185 |
|
|
|
186 |
3 |
iztok |
add_interface_port irq bus_irq irq Output 1
|
187 |
2 |
iztok |
|
188 |
|
|
# connection point conduit
|
189 |
|
|
add_interface ext conduit end
|
190 |
|
|
|
191 |
|
|
set_interface_property ext ENABLED true
|
192 |
|
|
|
193 |
3 |
iztok |
add_interface_port ext owr_p export Output OWN
|
194 |
|
|
add_interface_port ext owr_e export Output OWN
|
195 |
|
|
add_interface_port ext owr_i export Input OWN
|
196 |
2 |
iztok |
|
197 |
|
|
proc validation_callback {} {
|
198 |
|
|
# check if overdrive is enabled
|
199 |
3 |
iztok |
set ovd_e [get_parameter_value OVD_E]
|
200 |
2 |
iztok |
# get clock frequency in Hz
|
201 |
3 |
iztok |
set f [get_parameter_value F_CLK]
|
202 |
2 |
iztok |
# get base time periods
|
203 |
|
|
set btp_n [get_parameter_value BTP_N]
|
204 |
|
|
set btp_o [get_parameter_value BTP_O]
|
205 |
3 |
iztok |
# enable/disable editing of overdrive divider
|
206 |
|
|
set_parameter_property BTP_O ENABLED [expr {$ovd_e ? "true" : "false"}]
|
207 |
2 |
iztok |
# compute normal mode divider
|
208 |
|
|
if {$btp_n=="5.0"} {
|
209 |
|
|
set d_n [expr {$f/200000}]
|
210 |
|
|
set t_n [expr {1000000.0/($f/$d_n)}]
|
211 |
|
|
set e_n [expr {$t_n/5.0-1}]
|
212 |
|
|
} elseif {$btp_n=="7.5"} {
|
213 |
|
|
set d_n [expr {$f/133333}]
|
214 |
|
|
set t_n [expr {1000000.0/($f/$d_n)}]
|
215 |
|
|
set e_n [expr {$t_n/7.5-1}]
|
216 |
|
|
} elseif {$btp_n=="6.0"} {
|
217 |
|
|
set d_n [expr {$f/133333}]
|
218 |
3 |
iztok |
set t_n [expr {$d_n*1000000.0/$f}]
|
219 |
|
|
if {$t_n>7.5} {
|
220 |
|
|
set e_n [expr {$t_n/7.5-1}]
|
221 |
|
|
} elseif {6.0>$t_n} {
|
222 |
|
|
set e_n [expr {$t_n/6.0-1}]
|
223 |
|
|
} else {
|
224 |
2 |
iztok |
set e_n 0.0
|
225 |
|
|
}
|
226 |
|
|
}
|
227 |
|
|
# compute overdrive mode divider
|
228 |
|
|
if {$btp_o=="1.0"} {
|
229 |
|
|
set d_o [expr {$f/1000000}]
|
230 |
|
|
set t_o [expr {1000000.0/($f/$d_o)}]
|
231 |
|
|
set e_o [expr {$t_o/1.0-1}]
|
232 |
|
|
} elseif {$btp_o=="0.5"} {
|
233 |
|
|
set d_o [expr {$f/1500000}]
|
234 |
3 |
iztok |
set t_o [expr {$d_o*1000000.0/$f}]
|
235 |
|
|
if {$t_o>(2.0/3)} {
|
236 |
|
|
set e_o [expr {$t_o/(2.0/3)-1}]
|
237 |
|
|
} elseif {0.5>$t_o} {
|
238 |
|
|
set e_o [expr {$t_o/0.5-1}]
|
239 |
|
|
} else {
|
240 |
2 |
iztok |
set e_o 0.0
|
241 |
|
|
}
|
242 |
|
|
}
|
243 |
|
|
# set divider values
|
244 |
3 |
iztok |
set_parameter_value CDR_N [expr {$d_n-1}]
|
245 |
|
|
if {$ovd_e} {set_parameter_value CDR_O [expr {$d_o-1}]}
|
246 |
2 |
iztok |
# report BTP values and relative errors
|
247 |
|
|
send_message info "BTP_N (normal mode 'base time period') is [format %.2f $t_n], relative error is [format %.1f [expr {$e_n*100}]]%."
|
248 |
|
|
send_message info "BTP_O (overdrive mode 'base time period') is [format %.2f $t_o], relative error is [format %.1f [expr {$e_o*100}]]%."
|
249 |
|
|
# repport validatio errors if relative error are outside accepted bounds (2%)
|
250 |
|
|
if {abs($e_n)>0.02} {send_message error "BTP_N is outside accepted bounds (relative error > 2%). Use a different 'base time period' or system frequency."}
|
251 |
|
|
if {abs($e_o)>0.02} {send_message error "BTP_O is outside accepted bounds (relative error > 2%). Use a different 'base time period' or system frequency."}
|
252 |
|
|
}
|
253 |
|
|
|
254 |
|
|
proc elaboration_callback {} {
|
255 |
|
|
# add software defines
|
256 |
|
|
set_module_assignment embeddedsw.CMacro.OWN [get_parameter_value OWN ]
|
257 |
3 |
iztok |
set_module_assignment embeddedsw.CMacro.CDR_E [expr {[get_parameter_value CDR_E]?1:0}]
|
258 |
2 |
iztok |
set_module_assignment embeddedsw.CMacro.OVD_E [expr {[get_parameter_value OVD_E]?1:0}]
|
259 |
3 |
iztok |
set_module_assignment embeddedsw.CMacro.BTP_N \"[get_parameter_value BTP_N]\"
|
260 |
|
|
set_module_assignment embeddedsw.CMacro.BTP_O \"[get_parameter_value BTP_O]\"
|
261 |
|
|
set_module_assignment embeddedsw.CMacro.CDR_N [get_parameter_value CDR_N]
|
262 |
|
|
set_module_assignment embeddedsw.CMacro.CDR_O [get_parameter_value CDR_O]
|
263 |
|
|
# get clock frequency in Hz
|
264 |
|
|
set f [get_parameter_value F_CLK]
|
265 |
|
|
# get base time period
|
266 |
|
|
set btp_n [get_parameter_value BTP_N]
|
267 |
|
|
# get clock divider ratio
|
268 |
|
|
set cdr_n [get_parameter_value CDR_N]
|
269 |
|
|
# compute delay time in seconds [s]
|
270 |
|
|
if {$btp_n=="5.0"} {
|
271 |
|
|
set t_dly [expr {200.*($cdr_n+1)/$f}]
|
272 |
|
|
} elseif {$btp_n=="7.5"} {
|
273 |
|
|
set t_dly [expr {128.*($cdr_n+1)/$f}]
|
274 |
|
|
} elseif {$btp_n=="6.0"} {
|
275 |
|
|
set t_dly [expr {160.*($cdr_n+1)/$f}]
|
276 |
|
|
}
|
277 |
|
|
# give the software a u16.16 representation of delay frequency in kilo hertz [kHz]
|
278 |
|
|
set_module_assignment embeddedsw.CMacro.F_DLY [format %.0f [expr {pow(2,16) / (1000*$t_dly)}]]
|
279 |
2 |
iztok |
}
|