Victor Modamio
Victor Modamio

Reputation: 65

How to clear the receive buffer in a serial bus (SERDEV) kernel driver

I'm writing a very simple linux kernel driver for my serial keyboard, employing serdev. The driver works and the function

static size_t serdev_keyboard_recv(struct serdev_device *serdev, 
                             const unsigned char *buffer, size_t count) {
        printk("serdev_keyboard: Received byte %d, count %ld \n", buffer[count-1], count);
        return 0;
    }

shows the count and last byte sent (each message is only one byte from the keyboard). The function is invoked as the receive_buf as:

static const struct serdev_device_ops serdev_keyboard_ops = {
    .receive_buf = serdev_keyboard_recv,
};

But it seems like the buffer saturates at 512 bytes. How can I tell the driver to drain the buffer when it's full, or just simply every time the receive_buf callback is executed?

Upvotes: 2

Views: 138

Answers (1)

Victor Modamio
Victor Modamio

Reputation: 65

Ok, now it is working as expected. Following the hints from @Oandriy, the callback .receive_buf is set now to return the size of the data received. So the next interrupt is starting the buffer from zero.

I would probably need to implement a return more elaborated, checking if the callback data size is larger than the buffer size... but considering that my keyboard is simply sending 1 byte is not that important.

Thanks!

Upvotes: 0

Related Questions