Serial Driver Input Queue Reset

Discussions and support about ChibiOS/HAL, the MCU Hardware Abstraction Layer.
Post Reply
Tabulous
Posts: 518
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 18 times

Serial Driver Input Queue Reset

Post by Tabulous »

Is it possible to reset the serial driver input queue, directly ?
Tabulous
Posts: 518
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 18 times

Re: Serial Driver Input Queue Reset

Post by Tabulous »

doing this works just not sure if its safe ?

iqResetI( &SD2.iqueue );
User avatar
RoccoMarco
Posts: 655
Joined: Wed Apr 24, 2013 4:11 pm
Has thanked: 83 times
Been thanked: 67 times

Re: Serial Driver Input Queue Reset

Post 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
User avatar
RoccoMarco
Posts: 655
Joined: Wed Apr 24, 2013 4:11 pm
Has thanked: 83 times
Been thanked: 67 times

Re: Serial Driver Input Queue Reset

Post by RoccoMarco »

Ok,
so quoting documentation

API 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 state


so your code should be

Code: Select all

chSysLock();
iqResetI(&SD2.iqueue);
chSysUnlock();
Tabulous
Posts: 518
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 18 times

Re: Serial Driver Input Queue Reset

Post by Tabulous »

RoccoMarco wrote:Ok,
so quoting documentation

API 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 state


so 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.
User avatar
RoccoMarco
Posts: 655
Joined: Wed Apr 24, 2013 4:11 pm
Has thanked: 83 times
Been thanked: 67 times

Re: Serial Driver Input Queue Reset

Post 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.
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Serial Driver Input Queue Reset

Post 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
Tabulous
Posts: 518
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 18 times

Re: Serial Driver Input Queue Reset

Post 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.
Post Reply