forked from M-Labs/artiq
grabber: add frequency counter
Cameras are a bit obscure about what they output, this can help with troubleshooting.
This commit is contained in:
parent
29c35ee553
commit
82def6b535
|
@ -76,6 +76,13 @@ fn get_last_pixels(g: usize) -> (u16, u16) {
|
||||||
(csr::GRABBER[g].last_y_read)()) }
|
(csr::GRABBER[g].last_y_read)()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_video_clock(g: usize) -> u32 {
|
||||||
|
let freq_count = unsafe {
|
||||||
|
(csr::GRABBER[g].freq_count_read)()
|
||||||
|
} as u32;
|
||||||
|
2*freq_count*(csr::CONFIG_CLOCK_FREQUENCY/1000000)/255
|
||||||
|
}
|
||||||
|
|
||||||
pub fn tick() {
|
pub fn tick() {
|
||||||
for g in 0..csr::GRABBER.len() {
|
for g in 0..csr::GRABBER.len() {
|
||||||
if unsafe { GRABBER_STATE[g] != State::Down } {
|
if unsafe { GRABBER_STATE[g] != State::Down } {
|
||||||
|
@ -86,8 +93,9 @@ pub fn tick() {
|
||||||
}
|
}
|
||||||
if unsafe { GRABBER_STATE[g] == State::WaitResolution } {
|
if unsafe { GRABBER_STATE[g] == State::WaitResolution } {
|
||||||
let (last_x, last_y) = get_last_pixels(g);
|
let (last_x, last_y) = get_last_pixels(g);
|
||||||
info!("grabber{} detected frame size: {}x{}",
|
info!("grabber{} frame size: {}x{}",
|
||||||
g, last_x + 1, last_y + 1);
|
g, last_x + 1, last_y + 1);
|
||||||
|
info!("grabber{} video clock: {}MHz", g, get_video_clock(g));
|
||||||
unsafe { GRABBER_STATE[g] = State::Up; }
|
unsafe { GRABBER_STATE[g] = State::Up; }
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -3,6 +3,34 @@ from migen.genlib.cdc import MultiReg
|
||||||
from misoc.interconnect.csr import *
|
from misoc.interconnect.csr import *
|
||||||
|
|
||||||
|
|
||||||
|
class FrequencyCounter(Module, AutoCSR):
|
||||||
|
def __init__(self, width=8):
|
||||||
|
self.freq_count = CSRStatus(width)
|
||||||
|
|
||||||
|
# # #
|
||||||
|
|
||||||
|
toggle = Signal(reset_less=True)
|
||||||
|
toggle_sys = Signal()
|
||||||
|
toggle.attr.add("no_retiming")
|
||||||
|
self.sync.cl += toggle.eq(~toggle)
|
||||||
|
self.specials += MultiReg(toggle, toggle_sys)
|
||||||
|
|
||||||
|
timer = Signal(width+1)
|
||||||
|
tick = Signal(reset=1)
|
||||||
|
count = Signal(width)
|
||||||
|
toggle_sys_r = Signal()
|
||||||
|
self.sync += [
|
||||||
|
Cat(timer, tick).eq(timer + 1),
|
||||||
|
toggle_sys_r.eq(toggle_sys),
|
||||||
|
If(tick,
|
||||||
|
self.freq_count.status.eq(count),
|
||||||
|
count.eq(0)
|
||||||
|
).Else(
|
||||||
|
If(toggle_sys & ~toggle_sys_r, count.eq(count + 1))
|
||||||
|
)
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
bitseq = [
|
bitseq = [
|
||||||
# 0 1 2 3 4 5 6
|
# 0 1 2 3 4 5 6
|
||||||
6, 5, 4, 3, 2, 1, 27,
|
6, 5, 4, 3, 2, 1, 27,
|
||||||
|
|
|
@ -12,8 +12,12 @@ class Grabber(Module):
|
||||||
rtlink.IInterface(10))
|
rtlink.IInterface(10))
|
||||||
|
|
||||||
self.submodules.deserializer = deserializer_7series.Deserializer(pins)
|
self.submodules.deserializer = deserializer_7series.Deserializer(pins)
|
||||||
|
self.submodules.frequency_counter = FrequencyCounter()
|
||||||
self.submodules.parser = Parser()
|
self.submodules.parser = Parser()
|
||||||
self.comb += self.parser.cl.eq(self.deserializer.q)
|
self.comb += self.parser.cl.eq(self.deserializer.q)
|
||||||
|
|
||||||
def get_csrs(self):
|
def get_csrs(self):
|
||||||
return self.deserializer.get_csrs() + self.parser.get_csrs()
|
return (
|
||||||
|
self.deserializer.get_csrs() +
|
||||||
|
self.frequency_counter.get_csrs() +
|
||||||
|
self.parser.get_csrs())
|
||||||
|
|
Loading…
Reference in New Issue