at this point pretty sure the reason something like
CV 6 CV 5 locks in Metro script is because it executes
op_CV_get which writes to and reads from i2c immediately, then it executes
op_CV_set which queues an i2c event. so it's possible that the next
op_CV_get (triggered by the clock interrupt handler) tries to execute while there is a transmission in progress initiated by the i2c event handler, so it ends up corrupting it and leaving TT hanging.
this is confirmed by the fact that if i add
if (i2c_waiting_count) return; to
tele_ii_rx it doesn't freeze anymore (but it never seems to read either).
with the current architecture i can't think of a way to queue reads since it can't proceed until a read is completed, so the only option seems to make any i2c communications atomic. so i think @ngwese's solution to disable interrupts while i2c transmission is in progress is probably the only way to handle it. either that or any interrupts should just create events and the actual execution should happen within
edit: another option is to cache CV values, have
op_CV_get return cached values, queue reads as i2c events and have the event handler update the cache. this means that the values are not guaranteed to be up to date - more of an issue for TXi though, since for ansible TT can update its cache when it writes to ansible (unless CVs can change outside of TT - like maybe reading CV values produced by, say, Cycles?). either way, it'll likely be a tug war between how accurate you want CV reads to be vs the timing accuracy of TT.