Microdevt - Interrupt-based Drivers

Thread Starter

wchris777

Joined Dec 1, 2018
13
Hi there!
Does anybody known how to code an interrupt driven driver using Microdevt toolkit (www.kw-net.com) ?
I am trying to develop a simple driver on my atmega328 that enqueues a bitstream from an other uC. The bitstream is read on an input pin and then processed if a certain amount of data has been read. The length of the stream is in the first byte.
The interrupt driven approach proposed in their user guide seems like the perfect solution: if there is data available I read it, if not I sleep. And if there is too much data then it is enqueued for later processing. In Microdevt, they compare this method of doing to the top/bottom halves of an interrupt like in a linux driver. So my problem is that I don't know where exactly I should free the ring buffer entries used to write/read data. If I do it in the interrupt handler is crashes badly...
Thanks!
 

Pawel7712

Joined Dec 17, 2020
1
Hi,
The Microdevt on the www.kw-net.com documentation web page documents this use case very well.
When you say "where I should free the ring buffer", you actually mean "where I should do ring_getc()" right? Freeing the ring buffer can be done anywhere as we assume no more data will be added to it...

Basically, the method is quite simple: the ring buffer is like a pipe, there are two ends of it and data goes only in one direction.
We use ring buffers to safely transfer data from an interruptible function to an interrupt handler and vice versa.
So you do ring_add() in the interrupt handler where you get new data and you do ring_get() in your application function.
I hope that makes things clearer. Let me know if you need any more help with that. I know, ring buffers can be quite confusing when used the first time.
Have also a look on the documentation example: https://www.kw-net.com/static/website/documentation/Quick-Start-Guide.html#interrupt-based-drivers

Cheers
Pawel
 

Thread Starter

wchris777

Joined Dec 1, 2018
13
Thank you Pawel for your reply. Indeed the Microdevt documentation covers the interrupt based drivers. I was a bit confused about the usage of the ring buffers but thanks to you it's now much clearer.
And yes I didn't mean to free the whole ring buffer but get data from it...
So I implemented an interrupt handler to get data from the input PIN. That data is stored in the ring buffer and when all data has been read (according to its size), I schedule a task that handles it outsize of the interrupt. Everything is working smoothly now. Thank you again for your help.
 
Top