Page 1 of 1
Serial Driver Input Queue Reset
Posted: Thu Nov 17, 2016 5:35 pm
by Tabulous
Is it possible to reset the serial driver input queue, directly ?
Re: Serial Driver Input Queue Reset
Posted: Thu Nov 17, 2016 6:12 pm
by Tabulous
doing this works just not sure if its safe ?
iqResetI( &SD2.iqueue );
Re: Serial Driver Input Queue Reset
Posted: Thu Nov 17, 2016 6:19 pm
by RoccoMarco
iqResetI must be called from an interrupt context. Enabling state checker in chconf.h system should halts itself.
Check for a function without I. I am from mobile. I'll provide a better answer later.
Ciao
Re: Serial Driver Input Queue Reset
Posted: Thu Nov 17, 2016 9:24 pm
by RoccoMarco
Ok,
so quoting
documentationAPI Name Suffixes
The suffix can be one of the following:
None, APIs without any suffix can be invoked only from the user code in the Normal state unless differently specified. See System States.
"I", I-Class APIs are invokable only from the I-Locked or S-Locked states. See System States.
"S", S-Class APIs are invokable only from the S-Locked state. See System States.
This mean, unless you are in an interrupt context, you have to enter in
S-Locked stateso your code should be
Code: Select all
chSysLock();
iqResetI(&SD2.iqueue);
chSysUnlock();
Re: Serial Driver Input Queue Reset
Posted: Fri Nov 18, 2016 10:10 am
by Tabulous
RoccoMarco wrote:Ok,
so quoting
documentationAPI Name Suffixes
The suffix can be one of the following:
None, APIs without any suffix can be invoked only from the user code in the Normal state unless differently specified. See System States.
"I", I-Class APIs are invokable only from the I-Locked or S-Locked states. See System States.
"S", S-Class APIs are invokable only from the S-Locked state. See System States.
This mean, unless you are in an interrupt context, you have to enter in
S-Locked stateso your code should be
Code: Select all
chSysLock();
iqResetI(&SD2.iqueue);
chSysUnlock();
Thanks for the response, did do the same with the locks.
Might be nice to add this feature to the sd driver ?
I dont mind doing the changes, and submitting it to you.
Re: Serial Driver Input Queue Reset
Posted: Fri Nov 18, 2016 10:17 am
by RoccoMarco
For me, hard to tell. The APIs design is up to Giovanni.
Maybe it could be helpful to propose a scenario in which this API could be useful.
Re: Serial Driver Input Queue Reset
Posted: Fri Nov 18, 2016 10:19 am
by Giovanni
Resetting a queue is usually done from ISR context, this is why there is only the I function. I will add it as an inline function.
Giovanni
Re: Serial Driver Input Queue Reset
Posted: Sun Nov 20, 2016 10:27 am
by Tabulous
RoccoMarco wrote:For me, hard to tell. The APIs design is up to Giovanni.
Maybe it could be helpful to propose a scenario in which this API could be useful.
If you start a serial driver with say gps reciever connected, but dont start the thread that removes data from the queue for some seconds after the start of the driver, you will end up with buffer overruns as the queue if full. Hence why reseting the input queue was needed.
This happens as I use 1 uart for two things
1 the tx is used for debug ouput and thus I need this running right at the start of the application.
2 the rx is used to receive the gps nmea stings. This is done in a thread but starts maybe a second after the application debug is started.
Normally I would not have this situation, but hardware constraints dictated.