Serial Driver Input Queue Reset

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

Serial Driver Input Queue Reset

Postby Tabulous » Thu Nov 17, 2016 5:35 pm

Is it possible to reset the serial driver input queue, directly ?

Tabulous
Posts: 509
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 17 times

Re: Serial Driver Input Queue Reset

Postby Tabulous » Thu Nov 17, 2016 6:12 pm

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
Location: Munich (Germany)
Has thanked: 83 times
Been thanked: 67 times
Contact:

Re: Serial Driver Input Queue Reset

Postby RoccoMarco » Thu Nov 17, 2016 6:19 pm

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
Ciao,
RM

User avatar
RoccoMarco
Posts: 655
Joined: Wed Apr 24, 2013 4:11 pm
Location: Munich (Germany)
Has thanked: 83 times
Been thanked: 67 times
Contact:

Re: Serial Driver Input Queue Reset

Postby RoccoMarco » Thu Nov 17, 2016 9:24 pm

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();
Ciao,
RM

Tabulous
Posts: 509
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 17 times

Re: Serial Driver Input Queue Reset

Postby Tabulous » Fri Nov 18, 2016 10:10 am

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
Location: Munich (Germany)
Has thanked: 83 times
Been thanked: 67 times
Contact:

Re: Serial Driver Input Queue Reset

Postby RoccoMarco » Fri Nov 18, 2016 10:17 am

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.
Ciao,
RM

User avatar
Giovanni
Site Admin
Posts: 14457
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: Serial Driver Input Queue Reset

Postby Giovanni » Fri Nov 18, 2016 10:19 am

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: 509
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 17 times

Re: Serial Driver Input Queue Reset

Postby Tabulous » Sun Nov 20, 2016 10:27 am

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.


Return to “ChibiOS/HAL”

Who is online

Users browsing this forum: No registered users and 29 guests