Page 2 of 2

Re: piSerial prints wrong information

Posted: 31 Jan 2021, 19:34
by Wulf
Hello!

The chip goes to sleep after 10 seconds (or 1.3 seconds if so configured, ChipMode bit 2) after it last woke.
So even if you do subsequent requests, it will enter sleep mode eventually.
This is intentionally by design for security reasons.

There are three situations:
* Chip is awake. piSerial will succeed.
* Chip is asleep. piSerial will succeed too.
* Chip is about to go to sleep. piSerial will fail.

You can confirm this by running piSerial and then running it again right away. Or by waiting >10 seconds after first run.
To get the error, you kind of need to get "lucky".

So, what could Kunbus do about it?
A long running program can maintain its own timer and track the state of the chip. It can then send the chip to idle or sleep mode before it goes to sleep automatically, and wake it up again.
But piSerial is running on demand and cannot know the current state.

To synchronize it, send the chip to sleep and then wake it again. Then try reading the "After Wake" token until it works. Reading from the chip wakes it up too.
Only then send the read command and read its result. At the end, send the chip to sleep or idle mode.

Why are you executing piSerial in a loop anyway? It's not like the output will change. Call it once and cache the value. Then use only the cached value.

Re: piSerial prints wrong information

Posted: 01 Feb 2021, 09:01
by jenskastensson
Thank you Wulf !
This is exactly the information we needed to understand and decide what needs to be done on our side!
Very important info "Chip is asleep. piSerial will succeed too.", it is a key
We do not call piSerial in a loop, but we call piSerial asynchronously from various modules. Given your explanations, I think it is a low risk that we will have the problematic edge case.
Jens

Re: piSerial prints wrong information

Posted: 08 Feb 2021, 15:00
by p.rosenberger
Hi Wulf,

you've identified the issue correctly. I'm currently rewriting the piSerial program. For a rather trivial program the code was pretty messed up. And as we need to extend it for upcoming h/w I decided a rewrite would be the best. The current fix is just that. A fast fix for a really unbearable bug. I hope with this fix everybody is fine for now. And with a future version also the remaining issues will get fixed.

Best Regards
Philipp

Re: piSerial prints wrong information

Posted: 08 Feb 2021, 15:23
by p.rosenberger
jenskastensson wrote: 01 Feb 2021, 09:01 Thank you Wulf !
This is exactly the information we needed to understand and decide what needs to be done on our side!
Very important info "Chip is asleep. piSerial will succeed too.", it is a key
We do not call piSerial in a loop, but we call piSerial asynchronously from various modules. Given your explanations, I think it is a low risk that we will have the problematic edge case.
Jens
Hi Jens,

if piSerial returns with an error you can just retry. Or even better sleep for a few milliseconds and then retry. If you executing piSerial asynchronous you should make sure you don't call it concurrently. As piSerial doesn't do any locking you might get errors or other strange behavior.
I will think about locking for the rewrite.

Best Regards
Philipp

Re: piSerial prints wrong information

Posted: 08 Feb 2021, 15:36
by jenskastensson
Thank you Philipp, appreciated.
Jens