Code: Select all
if (locked > 1 && ((duration < low_sr) || (duration > high_sr))) {
Code: Select all
if (locked > 1 && ((duration < low_sr) || (duration > high_sr))) {
Code: Select all
// Calculating new port time
pt = port_time + transport_bit_width;
// Calculate new timeout
t :> time;
time += WCLK_WAIT_TIMEOUT;
while (true) {
[[ordered]]
select {
// When a word was received
//
// can you explain the operation of the next line?
// p_wclk is read @ pt time (where pt is calculated above)
// the read contents of p_wclk is copied into the var value
// then the current port counter value is stored into the var pt?
//
case p_wclk @ pt :> value @ pt :
// Check sample rate
t :> time;
last_time = time;
//
// now last_time and time are of the same value
//
// so duration will always be zero - correct?
//
unsigned duration = time - last_time;
@akp: The delta is not 32 but -32 (negative). I suppose the real delta is something like (n*2¹⁶ -32). Why? I can't explain.I wonder if the 32 clocks delta between pt and pt1 is due to being 32 clocks to clock the 32 bit shift register?
"pt" is calculated inside the function "i2s_slave_rx_task" (have a look inside my zip). It's the port's counter timestamp, when wclk switches to 1 or 0. "i2s_slave_rx_task" contains an endless loop. It tries to detect a valid i2s signal, by watching the wclk port state. When the port switches between 1 and 0 in a defined time interval (function "wait_until_wclk_level"), the signal is locked, the port's counter timestamp is taken as parameter for the function "process_data", you already know. The function "process_data" is called from i2s_slave_rx_task, when the signal is locked.// can you explain the operation of the next line?
// p_wclk is read @ pt time (where pt is calculated above)
// the read contents of p_wclk is copied into the var value
// then the current port counter value is stored into the var pt?
I expect, that the value is always greater zero, because "case p_wclk @ pt" will take a while until it is triggered (some nano seconds). But in the first iteration, the calculated duration will be lower than "low_sr", because the timestamp isn't taken at port state change but a little bit later. Therefore I have introduced "locked", to ignore the duration the 1st and 2nd iteration (and indirectly time and last_time).case p_wclk @ pt :> value @ pt :
// Check sample rate
t :> time;
last_time = time;
// now last_time and time are of the same value
//
// so duration will always be zero - correct?
//