-
Notifications
You must be signed in to change notification settings - Fork 0
/
onewiremaster.vhd
1358 lines (1286 loc) · 57.1 KB
/
onewiremaster.vhd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
----------------------------------------------------------------------------
-- --
-- OneWireMaster --
-- A synthesizable 1-wire master peripheral --
-- Copyright 1999-2007 Dallas Semiconductor Corporation --
-- --
----------------------------------------------------------------------------
-- --
-- Purpose: Provides timing and control of Dallas 1-wire bus --
-- through a memory-mapped peripheral --
-- File: onewiremaster.vhd --
-- Date: January 17, 2007 --
-- Version: v1.10 --
-- Authors: Eric Hereford, --
-- Dallas Semiconductor Corporation --
-- --
-- Note: This source code is available for use without license. --
-- Dallas Semiconductor is not responsible for the --
-- functionality or utility of this product. --
-- --
-- REV: Initial port based on v2.200 Verilog - EAH --
-- --
-- v1.2 - Jan 28, 2007 --
-- Changd value of bit_ts_end_od from 9 to 10 - EAH --
----------------------------------------------------------------------------
library IEEE;
use IEEE.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity onewiremaster is
port(
BIT_CTL : in std_logic;
clk_1us : in std_logic;
clr_activate_intr : in std_logic;
DQ_IN : in std_logic;
EN_FOW : in std_logic;
EOWL : in std_logic;
EOWSH : in std_logic;
epd : in std_logic;
erbf : in std_logic;
ersf : in std_logic;
etbe : in std_logic;
etmt : in std_logic;
FOW : in std_logic;
ias : in std_logic;
LLM : in std_logic;
MR : in std_logic;
OD : in std_logic;
owr : in std_logic;
pd : in std_logic;
PPM : in std_logic;
rbf_reset : in std_logic;
sr_a : in std_logic;
STP_SPLY : in std_logic;
STPEN : in std_logic;
tbe : in std_logic;
xmit_buffer : in std_logic_vector (7 downto 0);
clear_interrupts : out std_logic;
DQ_CONTROL : out std_logic;
FSM_CLK : out std_logic;
INTR : out std_logic;
OneWireIO_eq_Load : out std_logic;
OW_LOW : out std_logic;
OW_SHORT : out std_logic;
pdr : out std_logic;
rbf : out std_logic;
rcvr_buffer : out std_logic_vector (7 downto 0);
reset_owr : out std_logic;
rsrf : out std_logic;
STPZ : out std_logic;
temt : out std_logic);
end entity onewiremaster;
architecture rtl_onewiremaster of onewiremaster is
--
-- Define the states
--
constant Idle : std_logic_vector(2 DOWNTO 0) := b"000"; -- Idle
constant CheckOWR : std_logic_vector(2 DOWNTO 0) := b"001"; -- Check for shorted OW
constant Reset_Low : std_logic_vector(2 DOWNTO 0) := b"010"; -- Start reset
constant PD_Wait : std_logic_vector(2 DOWNTO 0) := b"011"; -- release line for 1T
constant PD_Sample : std_logic_vector(2 DOWNTO 0) := b"100"; -- sample line after slowest 1T over
constant Reset_High : std_logic_vector(2 DOWNTO 0) := b"101"; -- recover OW line leve
constant PD_Force : std_logic_vector(2 DOWNTO 0) := b"110"; -- mask the presence pulse
constant PD_Release : std_logic_vector(2 DOWNTO 0) := b"111"; -- recover OW line level
constant IdleS : std_logic_vector(4 DOWNTO 0) := b"0_0000"; -- Idle stat
constant Load : std_logic_vector(4 DOWNTO 0) := b"0_0001"; -- Load byte
constant CheckOW : std_logic_vector(4 DOWNTO 0) := b"0_0010"; -- Check for shorted line
constant DQLOW : std_logic_vector(4 DOWNTO 0) := b"0_0011"; -- Start of timeslot
constant WriteZero : std_logic_vector(4 DOWNTO 0) := b"0_0100"; -- Write a zero to the 1-wire
constant WriteOne : std_logic_vector(4 DOWNTO 0) := b"0_0101"; -- Wrte a one to the 1-wire
constant ReadBit : std_logic_vector(4 DOWNTO 0) := b"0_0110"; -- Search Rom Accelerator read bit
constant FirstPassSR: std_logic_vector(4 DOWNTO 0) := b"0_0111"; -- Used by SRA
constant WriteBitSR : std_logic_vector(4 DOWNTO 0) := b"0_1000"; -- Decide what bit value to write in SRA
constant WriteBit : std_logic_vector(4 DOWNTO 0) := b"0_1001"; -- Writes the chosen bit in SRA
constant WaitTS : std_logic_vector(4 DOWNTO 0) := b"0_1010"; -- Wait for end of time slot
constant IndexInc : std_logic_vector(4 DOWNTO 0) := b"0_1011"; -- Increments bit index
constant UpdateBuff : std_logic_vector(4 DOWNTO 0) := b"0_1100"; -- Updates states of rbf
constant ODWriteZero: std_logic_vector(4 DOWNTO 0) := b"0_1101"; -- Write a zero @ OD speed to OW
constant ODWriteOne : std_logic_vector(4 DOWNTO 0) := b"0_1110"; -- Write a one @ OD speed to OW
constant ClrLowDone : std_logic_vector(4 DOWNTO 0) := b"0_1111"; -- disable stupz before pulldown
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-- micro-second count for bit transitions and sample
-- Standard Speed
constant bit_ts_writeone_high : std_logic_vector(6 DOWNTO 0) := b"000_0110"; -- release-1 @6 us
constant bit_ts_writeone_high_ll : std_logic_vector(6 DOWNTO 0) := b"000_1000"; -- rel-1-LLM @8 us
constant bit_ts_sample : std_logic_vector(6 DOWNTO 0) := b"000_1111"; -- sample @15 us
constant bit_ts_sample_ll : std_logic_vector(6 DOWNTO 0) := b"001_1000"; -- sample/llm @24 us
constant bit_ts_writezero_high : std_logic_vector(6 DOWNTO 0) := b"011_1100"; -- release-0 @60 us
constant bit_ts_end : std_logic_vector(6 DOWNTO 0) := b"100_0110"; -- end @70 us
constant bit_ts_end_ll : std_logic_vector(6 DOWNTO 0) := b"101_0000"; -- end @80 us
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-- Overdrive speed
-- note that due to the state machine architecture, the
-- writeone_high_od and sample_od must be 1 and 2 us.
-- writezero_high_od and end_od are adjustable, so long
-- as writezero_high_od does not exceed a particular
-- 1-Wire device max low time.
constant bit_ts_writeone_high_od : std_logic_vector(6 DOWNTO 0) := b"000_0001"; -- release-1 @1 us
constant bit_ts_sample_od : std_logic_vector(6 DOWNTO 0) := b"000_0010"; -- sample @2 us
constant bit_ts_writezero_high_od : std_logic_vector(6 DOWNTO 0) := b"000_1000"; -- release-0 @8 us
constant bit_ts_end_od : std_logic_vector(6 DOWNTO 0) := b"000_1010"; -- end @10 us -- Eric Hereford changed from 9 to 10 - 01-28-2007
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-- micro-second count for reset transitions
-- Standard Speed
constant reset_ts_release : std_logic_vector(10 DOWNTO 0) := b"010_0101_1000"; -- release @600 us
constant reset_ts_no_stpz : std_logic_vector(10 DOWNTO 0) := b"010_0110_0010"; -- stpz=1 @610 us
constant reset_ts_ppm : std_logic_vector(10 DOWNTO 0) := b"010_0110_1100"; -- pp-mask @620 us
constant reset_ts_sample : std_logic_vector(10 DOWNTO 0) := b"010_1001_1110"; -- sample @670 us
constant reset_ts_llsample : std_logic_vector(10 DOWNTO 0) := b"010_1010_1101"; -- sample @685 us
constant reset_ts_ppm_end : std_logic_vector(10 DOWNTO 0) := b"010_1011_0010"; -- ppm-end @690 us
constant reset_ts_stpz : std_logic_vector(10 DOWNTO 0) := b"011_1011_0110"; -- stpz @950 us
constant reset_ts_recover : std_logic_vector(10 DOWNTO 0) := b"011_1100_0000"; -- recover @960 us
constant reset_ts_end : std_logic_vector(10 DOWNTO 0) := b"100_0011_1000"; -- end @1080 us
-- Overdrive Speed
constant reset_ts_release_od : std_logic_vector(10 DOWNTO 0) := b"000_0100_0110"; -- release @70 us
constant reset_ts_no_stpz_od : std_logic_vector(10 DOWNTO 0) := b"000_0100_1011"; -- stpz=1 @75 us
constant reset_ts_sample_od : std_logic_vector(10 DOWNTO 0) := b"000_0100_1111"; -- sample @79 us
constant reset_ts_stpz_od : std_logic_vector(10 DOWNTO 0) := b"000_0110_1001"; -- stpz @105 us
constant reset_ts_recover_od : std_logic_vector(10 DOWNTO 0) := b"000_0111_0011"; -- recover @115 us
constant reset_ts_end_od : std_logic_vector(10 DOWNTO 0) := b"000_1000_0000"; -- end @128 us
constant s0 : std_logic_vector(3 DOWNTO 0) := b"0000";
constant s1 : std_logic_vector(3 DOWNTO 0) := b"0001";
constant s2 : std_logic_vector(3 DOWNTO 0) := b"0010";
constant s3 : std_logic_vector(3 DOWNTO 0) := b"0011";
constant s4 : std_logic_vector(3 DOWNTO 0) := b"0100";
constant s5 : std_logic_vector(3 DOWNTO 0) := b"0101";
constant s6 : std_logic_vector(3 DOWNTO 0) := b"0110";
constant s7 : std_logic_vector(3 DOWNTO 0) := b"0111";
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-- Internal Signals
signal temt_ext : std_logic; -- temt extended flag
signal set_rbf : std_logic; -- set signal for rbf
signal activate_intr : std_logic;
signal dly_clr_activate_intr : std_logic;
signal SET_RSHRT : std_logic; -- set ow_short prior to ow reset
signal SET_IOSHRT : std_logic; -- set ow_short prior to tx a bit
signal xmit_shiftreg : std_logic_vector(7 downto 0); -- transmit shift register
signal rcvr_shiftreg : std_logic_vector(7 downto 0); -- receive shift register
signal last_rcvr_bit : std_logic; -- active on index = 7 to begin shift to rbe
signal byte_done : std_logic;
signal byte_done_flag : std_logic; -- signal to stretch byte_done
signal bdext1 : std_logic; -- signal to stretch byte_done
signal First : std_logic; -- for Search ROM accelerator
signal BitRead1 : std_logic;
signal BitRead2 : std_logic;
signal BitWrite : std_logic;
signal OneWireReset : std_logic_vector(2 downto 0);
signal OneWireIO : std_logic_vector(4 downto 0);
signal count : std_logic_vector(10 downto 0);
signal index : std_logic_vector(3 downto 0);
signal TimeSlotCnt : std_logic_vector(6 downto 0);
signal PD_READ : std_logic;
signal LOW_DONE : std_logic;
signal DQ_CONTROL_F : std_logic;
signal DQ_IN_HIGH : std_logic;
signal OD_DQH : std_logic;
signal rbf_set : std_logic;
signal rsrf_reset : std_logic;
signal ROW : std_logic;
signal SPLY : std_logic;
signal acint_reset : std_logic;
signal activate_intr_concat_ias : std_logic_vector(1 downto 0);
signal BitRead1_concat_BitRead2 : std_logic_vector(1 downto 0);
-- VHDL does not allow Outputs to be used within the architecture,
-- therefore internal signals were created to maintain consistency
-- with Verilog code version
signal FSM_CLK_int : std_logic;
signal DQ_CONTROL_int : std_logic;
signal rsrf_int : std_logic;
signal rbf_int : std_logic;
signal OW_SHORT_int : std_logic;
signal OW_LOW_int : std_logic;
signal temt_int : std_logic;
begin
FSM_CLK <= FSM_CLK_int;
DQ_CONTROL <= DQ_CONTROL_int;
rsrf <= rsrf_int;
rbf <= rbf_int;
OW_SHORT <= OW_SHORT_int;
OW_LOW <= OW_LOW_int;
temt <= temt_int;
activate_intr_concat_ias <= (activate_intr & ias);
BitRead1_concat_BitRead2 <= (BitRead1 & BitRead2);
-- Continuous assignments
FSM_CLK_int <= clk_1us;
DQ_CONTROL_int <= '1' when (MR = '1') else DQ_CONTROL_F;
OneWireIO_eq_Load <= '1' when (OneWireIO = Load) else '0';
SPLY <= '1' when ((STP_SPLY='1' and (OneWireReset=Idle)) and (OneWireIO=IdleS)) else '0';
STPZ <= '0' when ((STPEN and DQ_CONTROL_int and
((DQ_IN_HIGH and STP_SPLY and (PD_READ or LOW_DONE or SPLY)) or
(DQ_IN_HIGH and (not STP_SPLY) and (PD_READ or LOW_DONE))))='1') else '1';
acint_reset <= '1' when (MR='1' or clr_activate_intr='1') else '0';
temt_ext <= '1' when ((temt_int and byte_done_flag)='1') else '0';
--
-- 1 wire control
--
process(FSM_CLK_int)
begin
if (FSM_CLK_int='1' and FSM_CLK_int'event) then
if(EN_FOW='1' and FOW='1') then
DQ_CONTROL_F <= '0';
elsif(OneWireReset = Reset_Low) then
DQ_CONTROL_F <= '0';
elsif(OneWireReset = PD_Wait) then
DQ_CONTROL_F <= '1';
elsif(OneWireReset = PD_Force) then
DQ_CONTROL_F <= '0';
elsif(OneWireIO = DQLOW) then
DQ_CONTROL_F <= '0';
elsif(OneWireIO = WriteZero) then
DQ_CONTROL_F <= '0';
elsif(OneWireIO = ODWriteZero) then
DQ_CONTROL_F <= '0';
elsif(OneWireIO = WriteBit) then
DQ_CONTROL_F <= '0';
else
DQ_CONTROL_F <= '1';
end if;
end if;
end process;
--
-- Strong Pullup control section - GAG
-- not pulling line low, not checking for pres detect, and
-- OW has recovered from read
-- SPLY is only for enabling STP when a slave requires high current
-- and STP_SPLY is enabled
--
process(MR, FSM_CLK_int)
begin
if (MR='1') then
DQ_IN_HIGH <= '0';
elsif (FSM_CLK_int='1' and FSM_CLK_int'event) then
if((DQ_IN='1' or DQ_IN='H') and ((not DQ_IN_HIGH)='1')) then -- EAH
DQ_IN_HIGH <= '1';
elsif((DQ_IN='1' or DQ_IN='H') and (DQ_IN_HIGH='1')) then -- EAH
DQ_IN_HIGH <= DQ_IN_HIGH;
else
DQ_IN_HIGH <= '0';
end if;
end if;
end process;
--
-- Update receive buffer and the rsrf_int and rbf_int int flags
--
process(MR, rbf_reset, rbf_set)
begin
if (MR='1') then
rbf_int <= '0';
elsif (rbf_reset='1') then
rbf_int <= '0';
elsif (rbf_set='1' and rbf_set'event) then
rbf_int <= '1';
end if;
end process;
process(MR, FSM_CLK_int)
begin
if (MR='1') then
rsrf_int <= '0';
elsif (FSM_CLK_int='1' and FSM_CLK_int'event) then
if((last_rcvr_bit or BIT_CTL)='1') then
if(OneWireIO = IndexInc) then
rsrf_int <= '1';
elsif (rsrf_reset = '1') then
rsrf_int <= '0';
end if;
elsif(rsrf_reset='1' or (OneWireIO=DQLOW)) then
rsrf_int <= '0';
end if;
end if;
end process;
process(FSM_CLK_int, MR)
begin
if (MR='1') then
rcvr_buffer <= x"00";
rbf_set <= '0';
elsif (FSM_CLK_int='1' and FSM_CLK_int'event) then
if((rsrf_int and (not rbf_int))='1') then
rcvr_buffer <= rcvr_shiftreg;
rbf_set <= '1';
rsrf_reset <= '1';
else
rbf_set <= '0';
if(((not rsrf_int))='1') then
rsrf_reset <= '0';
end if;
end if;
end if;
end process;
--
-- Update OW shorted interrupt
--
process(MR, FSM_CLK_int)
begin
if (MR='1') then
OW_SHORT_int <= '0';
elsif (FSM_CLK_int='1' and FSM_CLK_int'event) then
if((SET_RSHRT or SET_IOSHRT) = '1') then
OW_SHORT_int <= '1';
elsif(clr_activate_intr = '1') then
OW_SHORT_int <= '0';
else
OW_SHORT_int <= OW_SHORT_int;
end if;
end if;
end process;
--
-- Update OW bus low interrupt
--
process(MR, FSM_CLK_int)
begin
if (MR='1') then
OW_LOW_int <= '0';
elsif (FSM_CLK_int='1' and FSM_CLK_int'event) then
if((DQ_IN='0') and (OneWireReset=Idle) and (OneWireIO=IdleS)) then
OW_LOW_int <= '1';
elsif(clr_activate_intr='1') then
OW_LOW_int <= '0';
else
OW_LOW_int <= OW_LOW_int;
end if;
end if;
end process;
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --/
-- The following section handles the interrupt itself
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --/
--
-- Create clear interrupts
--
process(MR, FSM_CLK_int)
begin
if (MR='1') then
clear_interrupts <= '0';
elsif (FSM_CLK_int='1' and FSM_CLK_int'event) then
clear_interrupts <= clr_activate_intr;
end if;
end process;
--
-- Check for active interrupt
--
process(acint_reset, FSM_CLK_int)
begin
if (acint_reset='1') then
activate_intr <= '0';
elsif (FSM_CLK_int='1' and FSM_CLK_int'event) then
if((pd and epd)='1') then
activate_intr <= '1';
elsif ((tbe and etbe and (not temt_int))='1') then
activate_intr <= '1';
elsif ((temt_ext and etmt)='1') then
activate_intr <= '1';
elsif ((rbf_int and erbf)='1') then
activate_intr <= '1';
elsif ((rsrf_int and ersf)='1') then
activate_intr <= '1';
elsif ((OW_LOW_int and EOWL)='1') then
activate_intr <= '1';
elsif ((OW_SHORT_int and EOWSH)='1') then
activate_intr <= '1';
end if;
end if;
end process;
--
-- Create INTR signal by checking for active interrupt and active
-- state of INTR
--
INTR <= '1' when (activate_intr='1' and ias='1') else
'0' when (activate_intr='0' and ias='1') else
'0' when (activate_intr='1' and ias='0') else '1'; -- EAH - DOES NOT MATCH CURRENT VERILOG VERSION!!!
----------------------------------------------------------------------------
--
-- OneWireReset
--
-- this state machine performs the 1-wire reset and presence detect
-- - Added OD for overdrive speed presence detect
-- - Added PD_LOW bit for strong pullup control
--
-- Idle : OW high - waiting to issue a PD
-- CheckOWR : OW high - checks for shorted OW line
-- Reset_Low : OW low - held down for GT8 OW osc periods
-- PD_Wait : OW high - released and waits for 1T
-- PD_Sample : OW high - checks to see if a slave is out there pulling
-- OW low for 4T
-- Reset_High : OW high - slave, if any, release OW and host lets it recover
----------------------------------------------------------------------------
process(FSM_CLK_int, MR)
begin
if (MR='1') then
pdr <= '1'; -- Added default state to conform to spec - SDS
OneWireReset <= Idle;
count <= b"000_0000_0000";
PD_READ <= '0'; -- Added PD_READ - GAG
reset_owr <= '0';
SET_RSHRT <= '0';
ROW <= '0';
elsif (FSM_CLK_int='1' and FSM_CLK_int'event) then
if(( not owr)='1') then
count <= b"000_0000_0000";
ROW <= '0';
reset_owr <= '0';
OneWireReset <= Idle;
else
case (OneWireReset) is
when Idle =>
if(ROW='1') then
reset_owr <= '1';
else
count <= b"000_0000_0000";
SET_RSHRT <= '0';
reset_owr <= '0';
OneWireReset <= CheckOWR;
end if;
when CheckOWR =>
OneWireReset <= Reset_Low;
if(DQ_IN='0') then
SET_RSHRT <= '1';
end if;
when Reset_Low =>
count <= count + b"000_0000_0001";
PD_READ <= '0';
if(OD='1') then
if(count = reset_ts_release_od) then
OneWireReset <= PD_Wait;
PD_READ <= '1';
end if;
elsif(count = reset_ts_release) then
OneWireReset <= PD_Wait;
PD_READ <= '1';
end if;
when PD_Wait =>
SET_RSHRT <= '0';
count <= count + b"000_0000_0001";
if((DQ_IN='0') and (DQ_CONTROL_F='1')) then
OneWireReset <= PD_Sample;
elsif (OD='1') then
if(count=reset_ts_no_stpz_od) then
PD_READ <= '0';
elsif(count=reset_ts_sample_od) then
OneWireReset <= PD_Sample;
end if;
elsif(count=reset_ts_no_stpz) then
PD_READ <= '0';
elsif((count=reset_ts_ppm) and PPM='1') then
OneWireReset <= PD_Force;
elsif((count=reset_ts_llsample) and ((not LLM)='1')) then
OneWireReset <= PD_Sample;
elsif((count=reset_ts_sample) and (LLM='1')) then
OneWireReset <= PD_Sample;
end if;
when PD_Sample =>
PD_READ <= '0';
count <= count + b"000_0000_0001";
if(DQ_IN='1' or DQ_IN='H') then
pdr <= '1';
else
pdr <= '0';
end if;
OneWireReset <= Reset_High;
when Reset_High =>
count <= count + b"000_0000_0001";
if(OD='1') then
if(count=reset_ts_stpz_od) then
if(DQ_IN='1' or DQ_IN='H') then
PD_READ <= '1';
end if;
elsif(count=reset_ts_recover_od) then
PD_READ <= '0';
elsif(count=reset_ts_end_od) then
PD_READ <= '0';
OneWireReset <= Idle;
ROW <= '1';
end if;
else
if(count=reset_ts_stpz) then
if((DQ_IN='1' or DQ_IN='H')) then
PD_READ <= '1';
end if;
elsif(count=reset_ts_recover) then
PD_READ <= '0';
elsif(count=reset_ts_end) then
PD_READ <= '0';
OneWireReset <= Idle;
ROW <= '1';
end if;
end if;
when PD_Force =>
count <= count + b"000_0000_0001";
if(count=reset_ts_ppm_end) then
OneWireReset <= PD_Release;
end if;
when PD_Release =>
count <= count + b"000_0000_0001";
pdr <= '0';
if(count=reset_ts_stpz) then
if((DQ_IN='1' or DQ_IN='H')) then
PD_READ <= '1';
end if;
elsif(count=reset_ts_recover) then
PD_READ <= '0';
elsif(count=reset_ts_end) then
PD_READ <= '0';
OneWireReset <= Idle;
ROW <= '1';
end if;
when others =>
OneWireReset <= Idle;
end case;
end if;
end if;
end process;
----------------------------------------------------------------------------
--
-- OneWireIO
--
-- this state machine performs the 1-wire writing and reading
-- - Added ODWriteZero and ODWriteOne for overdrive timing
--
-- IdleS : Waiting for transmit byte to be loaded
-- ClrLowDone : Disables strong pullup before pulldown turns on
-- Load : Loads byte to shift reg
-- CheckOW : Checks for OW short
-- DQLOW : Starts time slot with OW = 0
-- ODWriteZero : Completes write of 0 bit / read bit in OD speed
-- ODWriteOne : Completes write of 1 bit / read bit in OD speed
-- WriteZero : Completes write of 0 bit / read bit in standard speed
-- WriteOne : Completes write of 1 bit / read bit in standard speed
-- ReadBit : AutoSearchRom : Reads the first bit value
-- FirstPassSR : AutoSearchRom : Decides to do another read or the write
-- WriteBitSR : AutoSearchRom : Determines the bit to write
-- WriteBit : AutoSearchRom : Writes the bit
-- WatiTS : Allows OW to recover for the remainder of the time slot
-- IndexInc : Increment the index to send out next bit (in byte)
-- UpdateBuff : Allows other signals to update following finished byte/bit
----------------------------------------------------------------------------
-- The following 2 registers are to stretch the temt_int signal to catch the
-- temt_int interrupt source - SDS
process(MR, FSM_CLK_int)
begin
if (MR='1') then
bdext1 <= '0';
elsif (FSM_CLK_int='1' and FSM_CLK_int'event) then
bdext1 <= byte_done;
end if;
end process;
process(MR, FSM_CLK_int)
begin
if (MR='1') then
byte_done_flag <= '0';
elsif (FSM_CLK_int='1' and FSM_CLK_int'event) then
byte_done_flag <= bdext1;
end if;
end process;
-- The index variable has been decoded explicitly in this state machine
-- so that the code would compile on the Cypress warp compiler - SDS
process(MR, FSM_CLK_int)
begin
if (MR='1') then
index <= b"0000";
TimeSlotCnt <= b"000_0000";
temt_int <= '1';
last_rcvr_bit <= '0';
rcvr_shiftreg <= b"0000_0000";
OneWireIO <= IdleS;
BitRead1 <= '0';
BitRead2 <= '0';
BitWrite <= '0';
First <= '0';
byte_done <= '0';
xmit_shiftreg <= b"0000_0000";
LOW_DONE <= '0';
SET_IOSHRT <= '0';
elsif (FSM_CLK_int='1' and FSM_CLK_int'event) then
case (OneWireIO) is
-- IdleS state clears variables and waits for something to be
-- deposited in the transmit buffer. When something is there,
-- the next state is Load.
when IdleS =>
byte_done <= '0';
index <= b"0000";
last_rcvr_bit <= '0';
First <= '0';
TimeSlotCnt <= b"000_0000";
LOW_DONE <= '0';
SET_IOSHRT <= '0';
temt_int <= '1';
if((not tbe)='1') then
if(STPEN='1') then
OneWireIO <= ClrLowDone;
else
OneWireIO <= Load;
end if;
else
OneWireIO <= IdleS;
end if;
-- New state added to be sure the strong pullup will be disabled
-- before the OW pulldown turns on
when ClrLowDone =>
LOW_DONE <= '0';
if(LOW_DONE='0') then
OneWireIO <= Load;
end if;
-- Load transfers the transmit buffer to the transmit shift register,
-- then clears the transmit shift register empty interrupt. The next
-- state is then DQLOW.
when Load =>
xmit_shiftreg <= xmit_buffer;
rcvr_shiftreg <= b"0000_0000";
temt_int <= '0';
LOW_DONE <= '0';
OneWireIO <= CheckOW;
-- Checks OW value before sending out every bit to see if line
-- was forced low by some other means at an incorrect time
when CheckOw =>
OneWireIO <= DQLOW;
if(DQ_IN='0') then
SET_IOSHRT <= '1';
end if;
-- DQLOW pulls the DQ line low for 1us, beginning a timeslot.
-- If sr_a is 0, it is a normal write/read operation. If sr_a
-- is a 1, then you must go into Search ROM accelerator mode.
-- If OD is 1, the part is in overdrive and must perform
-- ODWrites instead of normal Writes while OD is 0.
when DQLOW =>
TimeSlotCnt <= TimeSlotCnt + b"000_0001";
LOW_DONE <= '0';
if(OD='1') then
if((not sr_a)='1') then
case (index) is
when s0 =>
if(( not xmit_shiftreg(0))='1') then
OneWireIO <= ODWriteZero;
else
OneWireIO <= ODWriteOne;
end if;
when s1 =>
if((not xmit_shiftreg(1))='1') then
OneWireIO <= ODWriteZero;
else
OneWireIO <= ODWriteOne;
end if;
when s2 =>
if((not xmit_shiftreg(2))='1') then
OneWireIO <= ODWriteZero;
else
OneWireIO <= ODWriteOne;
end if;
when s3 =>
if((not xmit_shiftreg(3))='1') then
OneWireIO <= ODWriteZero;
else
OneWireIO <= ODWriteOne;
end if;
when s4 =>
if((not xmit_shiftreg(4))='1') then
OneWireIO <= ODWriteZero;
else
OneWireIO <= ODWriteOne;
end if;
when s5 =>
if((not xmit_shiftreg(5))='1') then
OneWireIO <= ODWriteZero;
else
OneWireIO <= ODWriteOne;
end if;
when s6 =>
if((not xmit_shiftreg(6))='1') then
OneWireIO <= ODWriteZero;
else
OneWireIO <= ODWriteOne;
end if;
when s7 =>
if((not xmit_shiftreg(7))='1') then
OneWireIO <= ODWriteZero;
else
OneWireIO <= ODWriteOne;
end if;
when others => null;
end case;
else -- Search Rom Accelerator mode
OneWireIO <= Readbit;
end if;
elsif(((TimeSlotCnt=bit_ts_writeone_high)and((not LLM)='1')) or
((TimeSlotCnt=bit_ts_writeone_high_ll)and(LLM='1'))) then
if((not sr_a)='1') then
case (index) is
when s0 =>
if((not xmit_shiftreg(0))='1') then
OneWireIO <= WriteZero;
else
OneWireIO <= WriteOne;
end if;
when s1 =>
if(( not xmit_shiftreg(1))='1') then
OneWireIO <= WriteZero;
else
OneWireIO <= WriteOne;
end if;
when s2 =>
if((not xmit_shiftreg(2))='1') then
OneWireIO <= WriteZero;
else
OneWireIO <= WriteOne;
end if;
when s3 =>
if((not xmit_shiftreg(3))='1') then
OneWireIO <= WriteZero;
else
OneWireIO <= WriteOne;
end if;
when s4 =>
if((not xmit_shiftreg(4))='1') then
OneWireIO <= WriteZero;
else
OneWireIO <= WriteOne;
end if;
when s5 =>
if((not xmit_shiftreg(5))='1') then
OneWireIO <= WriteZero;
else
OneWireIO <= WriteOne;
end if;
when s6 =>
if((not xmit_shiftreg(6))='1') then
OneWireIO <= WriteZero;
else
OneWireIO <= WriteOne;
end if;
when s7 =>
if((not xmit_shiftreg(7))='1') then
OneWireIO <= WriteZero;
else
OneWireIO <= WriteOne;
end if;
when others => null;
end case;
else
OneWireIO <= ReadBit;
end if;
end if;
-- WriteZero and WriteOne are identical, except for what they do to
-- DQ (assigned in concurrent assignments). They both read DQ after
-- 15us, then move on to wait for the end of the timeslot, unless
-- running in Long Line mode which extends the sample time out to 22
when WriteZero =>
TimeSlotCnt <= TimeSlotCnt + b"000_0001";
if(((TimeSlotCnt=bit_ts_sample) and ((not sr_a)='1') and ((not LLM)='1')) or
((TimeSlotCnt=bit_ts_sample_ll) and ((not sr_a)='1') and (LLM='1'))) then
case (index) is
when s0 =>
if(DQ_IN='1' or DQ_IN='H') then
rcvr_shiftreg(0) <= '1';
else
rcvr_shiftreg(0) <= '0';
end if;
when s1 =>
if(DQ_IN='1' or DQ_IN='H') then
rcvr_shiftreg(1) <= '1';
else
rcvr_shiftreg(1) <= '0';
end if;
when s2 =>
if(DQ_IN='1' or DQ_IN='H') then
rcvr_shiftreg(2) <= '1';
else
rcvr_shiftreg(2) <= '0';
end if;
when s3 =>
if(DQ_IN='1' or DQ_IN='H') then
rcvr_shiftreg(3) <= '1';
else
rcvr_shiftreg(3) <= '0';
end if;
when s4 =>
if(DQ_IN='1' or DQ_IN='H') then
rcvr_shiftreg(4) <= '1';
else
rcvr_shiftreg(4) <= '0';
end if;
when s5 =>
if(DQ_IN='1' or DQ_IN='H') then
rcvr_shiftreg(5) <= '1';
else
rcvr_shiftreg(5) <= '0';
end if;
when s6 =>
if(DQ_IN='1' or DQ_IN='H') then
rcvr_shiftreg(6) <= '1';
else
rcvr_shiftreg(6) <= '0';
end if;
when s7 =>
if(DQ_IN='1' or DQ_IN='H') then
rcvr_shiftreg(7) <= '1';
else
rcvr_shiftreg(7) <= '0';
end if;
when others =>
null;
end case;
end if;
if(TimeSlotCnt=bit_ts_writezero_high) then
OneWireIO <= WaitTS;
end if;
if((DQ_IN='1' or DQ_IN='H')) then
LOW_DONE <= '1';
end if;
when WriteOne =>
TimeSlotCnt <= TimeSlotCnt + b"000_0001";
if(((TimeSlotCnt=bit_ts_sample) and ((not sr_a)='1') and ((not LLM)='1')) or
((TimeSlotCnt=bit_ts_sample_ll) and ((not sr_a)='1') and (LLM='1'))) then
case (index) is
when s0 =>
if(DQ_IN='1' or DQ_IN='H') then
rcvr_shiftreg(0) <= '1';
else
rcvr_shiftreg(0) <= '0';
end if;
when s1 =>
if(DQ_IN='1' or DQ_IN='H') then
rcvr_shiftreg(1) <= '1';
else
rcvr_shiftreg(1) <= '0';
end if;
when s2 =>
if(DQ_IN='1' or DQ_IN='H') then
rcvr_shiftreg(2) <= '1';
else
rcvr_shiftreg(2) <= '0';
end if;
when s3 =>
if(DQ_IN='1' or DQ_IN='H') then
rcvr_shiftreg(3) <= '1';
else
rcvr_shiftreg(3) <= '0';
end if;
when s4 =>
if(DQ_IN='1' or DQ_IN='H') then
rcvr_shiftreg(4) <= '1';
else
rcvr_shiftreg(4) <= '0';
end if;
when s5 =>
if(DQ_IN='1' or DQ_IN='H') then
rcvr_shiftreg(5) <= '1';
else
rcvr_shiftreg(5) <= '0';
end if;
when s6 =>
if(DQ_IN='1' or DQ_IN='H') then
rcvr_shiftreg(6) <= '1';
else
rcvr_shiftreg(6) <= '0';
end if;
when s7 =>
if(DQ_IN='1' or DQ_IN='H') then
rcvr_shiftreg(7) <= '1';
else
rcvr_shiftreg(7) <= '0';
end if;
when others =>
null;
end case;
end if;
if(TimeSlotCnt=bit_ts_writezero_high) then
OneWireIO <= WaitTS;
end if;
if((DQ_IN='1' or DQ_IN='H')) then
LOW_DONE <= '1';
end if;
-- ADDED ODWRITE states here GAG
-- ODWriteZero and ODWriteOne are identical, except for what they
-- do to DQ (assigned in concurrent assignments). They both read
-- DQ after 3us, then move on to wait for the end of the timeslot.
when ODWriteZero =>
TimeSlotCnt <= TimeSlotCnt + b"000_0001";
if((TimeSlotCnt=bit_ts_sample_od) and ((not sr_a)='1')) then
case (index) is
when s0 =>
if(DQ_IN='1' or DQ_IN='H') then
rcvr_shiftreg(0) <= '1';
else
rcvr_shiftreg(0) <= '0';
end if;
when s1 =>
if(DQ_IN='1' or DQ_IN='H') then
rcvr_shiftreg(1) <= '1';
else
rcvr_shiftreg(1) <= '0';
end if;
when s2 =>
if(DQ_IN='1' or DQ_IN='H') then
rcvr_shiftreg(2) <= '1';
else
rcvr_shiftreg(2) <= '0';
end if;
when s3 =>
if(DQ_IN='1' or DQ_IN='H') then
rcvr_shiftreg(3) <= '1';
else
rcvr_shiftreg(3) <= '0';
end if;
when s4 =>
if(DQ_IN='1' or DQ_IN='H') then
rcvr_shiftreg(4) <= '1';
else
rcvr_shiftreg(4) <= '0';
end if;
when s5 =>
if(DQ_IN='1' or DQ_IN='H') then
rcvr_shiftreg(5) <= '1';
else
rcvr_shiftreg(5) <= '0';
end if;
when s6 =>
if(DQ_IN='1' or DQ_IN='H') then
rcvr_shiftreg(6) <= '1';
else
rcvr_shiftreg(6) <= '0';
end if;
when s7 =>
if(DQ_IN='1' or DQ_IN='H') then
rcvr_shiftreg(7) <= '1';
else
rcvr_shiftreg(7) <= '0';