NordicSemiconductor / ble-sdk-arduino

MIT License
249 stars 97 forks source link

Handling of data credits in the application #18

Open broddo opened 9 years ago

broddo commented 9 years ago

Hi all,

More of a comment than an issue. I noticed that you tend to keep track of data credits higher up in the user application. This is fine, but I'm wondering if it would be better to let the driver handle credits and take that burden away from the user? For example, you have a queue system implemented that has 4 slots for transmitting commands to the nRF8001. In the current implementation, the queue would never be able to queue more than 2 commands that rely on credits. Therefore, it's up to the higher application to track the credits and wait for credits to free up if none are available. But there's no reason why these

Instead, you could have the queue track the credits. Then the higher application only needs to concerned about whether or not there is room in the queue and anything that is in the queue that relies on credits can wait until credits are available.

This is what I've done in my implementation and it works very well. Any events that arrive that increase the number of available credits are not added to the rx queue. Instead, they are handled immediately to ensure that the tx queue doesn't get jammed up.

awneil commented 8 years ago

I agree - it would seem far more sensible to have the "Credits" managed within the driver than by the Application.