1
1
/*
2
- * Copyright 2015 Forest Crossman
2
+ * This code is mostly mine - some of it was adapted from here:
3
+ * https://github.com/deanjerkovich/avr-glitch-101
4
+ *
5
+ * But the concept now is different - we want controllable glitches,
6
+ * that we can drive through, say, and python script using PySerial.
7
+ * This means that we take a value, and then use that (multiplied by
8
+ * 512) as our glitch time value
9
+ *
10
+ * So, yeah - most of this is written/hacked together by me on a Sunday
11
+ * afternoon...
12
+ * Released under MIT License:
13
+ *
14
+ * Permission is hereby granted, free of charge, to any person obtaining
15
+ * a copy of this software and associated documentation files (the
16
+ * "Software"), to deal in the Software without restriction, including
17
+ * without limitation the rights to use, copy, modify, merge, publish,
18
+ * distribute, sublicense, and/or sell copies of the Software, and to
19
+ * permit persons to whom the Software is furnished to do so, subject to
20
+ * the following conditions:
3
21
*
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
22
+ * The above copyright notice and this permission notice shall be
23
+ * included in all copies or substantial portions of the Software.
15
24
*
16
25
*/
17
26
18
27
`include "cores/osdvu/uart.v"
19
28
`include "pll-72.v"
20
29
30
+
31
+ // These I set and then didn't really use...
32
+ // I've left them here as example artefacts in case someone wants
33
+ // to use them in some re-implementation... just reference them
34
+ // including a preceeding backtick... e.g.
35
+ // if (counter == `WAIT_TIME) begin...
36
+ // as a quick example line. :-P
21
37
`define GLITCH_DURATION 26000
22
38
`define GLITCH_MULTIPLIER 100
23
39
`define WAIT_TIME 72000000
@@ -36,7 +52,6 @@ module top(
36
52
);
37
53
38
54
assign LED0 = outreg;
39
- // assign LED1 = ~outreg;
40
55
assign LED1 = ~ outreg;
41
56
assign J1_1 = outreg;
42
57
@@ -68,7 +83,7 @@ module top(
68
83
assign {LED3, LED2} = rx_byte[7 :6 ];
69
84
70
85
uart #(
71
- .baud_rate(9600 ), // The baud rate in kilobits/s
86
+ .baud_rate(115200 ), // The baud rate in kilobits/s
72
87
.sys_clk_freq(12000000 ) // The master clock frequency
73
88
)
74
89
uart0 (
@@ -101,8 +116,9 @@ module top(
101
116
end
102
117
always @(posedge iCE_CLK) begin
103
118
// dirty reset of glitch signal if it is set - saves on
104
- // waiting for UART to change mode NB - our other clock is a lot
105
- // faster, so will certainly see this signal
119
+ // waiting for UART to change mode
120
+ // NB - our other clock is a lot faster, so will certainly
121
+ // see this signal most of the time #DirtyHax
106
122
if (glitch_signal) begin
107
123
glitch_signal <= 0 ;
108
124
end
@@ -126,7 +142,10 @@ module top(
126
142
// check if glitch_signal is on, and if yes,
127
143
// reset counter and set glitch flag
128
144
if (glitch_signal && ! glitch) begin
129
- // turns out we don't know the interface register uart_var1...
145
+ // turns out we don't know the interface register
146
+ // uart_var1... take rx_byte and multiply it by 512 - this
147
+ // gives us roughly +7 microsecond increase in glitch time
148
+ // for every +1 increase in UART byte value... ish...
130
149
var1 <= rx_byte << 8 ;
131
150
glitch <= 1 ;
132
151
counter <= 0 ;
0 commit comments