Serial Driver Buffer Management

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
enly1
Posts: 38
Joined: Wed Oct 09, 2013 10:21 pm

Serial Driver Buffer Management

Post by enly1 »

Hi,

I have a need for a project to utilise 3 serialdrivers,but I have varying needs for the RX/TX Buffer sizes that will be used for them and don't have enough memory to just set the buffer size to be large for all SerialDriver objects.

Taking a look at the source code, I see the default buffer size for RX and TX are managed by a single #define variable, so in the current model there is no real way of setting these independently for RX/TX and/or on a SerialDriver by SerialDriver basis.

So this is a quick question as to what would be the recommended approach for adding this capability ?

Thought on options that come to mind:

1. Swap out SERIAL_BUFFERS_SIZE and make it SERIAL_BUFFERS_SIZE_RX & SERIAL_BUFFERS_SIZE_TX to save some memory - simple option.
2. Set buffer size to 1 and then replace dynamically after initialisation the input/output queue respectively and update variables indicating size within the SerialDriver SD1/SD2/SD3 objects as needed. Wastes a few bytes for the Queues that are no longer used, but allows for granular per driver configuration.

Recommendations ?
enly1
Posts: 38
Joined: Wed Oct 09, 2013 10:21 pm

Re: Serial Driver Buffer Management

Post by enly1 »

Just realised that option 2 may not be an option - thought that the buffers were pointers, but they are just array data blocks within the structure, so can't just swap them out at runtime :-(
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Serial Driver Buffer Management

Post by Giovanni »

You could make a customized driver, just clone the low level drivers in your project and put the arrays outside the driver structure.

Giovanni
enly1
Posts: 38
Joined: Wed Oct 09, 2013 10:21 pm

Re: Serial Driver Buffer Management

Post by enly1 »

Yeah - was trying to find a way to do it without cloning a driver, so that Chibios version upgrades / driver patches didn't need rework etc.

All good.
Post Reply