Embedded Freaks..

June 15, 2010

How to be a read_proc function

Filed under: linux-device-driver — kunilkuda @ 3:44 pm

From comments on fs/proc/generic.c:73

/*
 * How to be a proc read function
 * ------------------------------
 * Prototype:
 *    int f(char *buffer, char **start, off_t offset, int count, int *peof, void *dat)
 *
 * Assume that the buffer is "count" bytes in size.
 *
 * If you know you have supplied all the data you have, set *peof.
 *
 * You have three ways to return data:
 * 0) Leave *start = NULL.  (This is the default.)
 *    Put the data of the requested offset at that offset within the buffer.  Return the number (n)
 *    of bytes there are from the beginning of the buffer up to the last byte of data.  If the
 *    number of supplied bytes (= n - offset) is greater than zero and you didn't signal eof
 *    and the reader is prepared to take more data you will be called again with the requested
 *    offset advanced by the number of bytes absorbed.  This interface is useful for files
 *    no larger than the buffer.
 *
 * 1) Set *start = an unsigned long value less than  the buffer address but greater than zero.
 *    Put the data of the requested offset at the beginning of the buffer.  Return the number of
 *    bytes of data placed there.  If this number is greater than zero and you didn't signal eof
 *    and the reader is prepared to take more data you will be called again with the requested
 *    offset advanced by *start.  This interface is useful when you have a large file consisting
 *    of a series of blocks which you want to count and return as wholes.
 *    (Hack by Paul.Russell@rustcorp.com.au)
 *
 * 2) Set *start = an address within the buffer.
 *    Put the data of the requested offset at *start. Return the number of bytes of data placed there.
 *    If this number is greater than zero and you didn't signal eof and the reader is prepared to
 *    take more data you will be called again with the requested offset advanced by the number of bytes
 *    absorbed.
 */
Advertisements

February 5, 2009

Linux Device Driver Programming for Java Programmer

Filed under: linux-device-driver — Tags: — kunilkuda @ 11:08 am

If you have used Java Swing Framework before (or any OOP framework for Java), learning linux device driver programming is not that difficult. Linux already has its device drivers framework. What you need to do is just overriding the ‘methods’ that you like, and registers your ‘class’ into the framework. It’s very easy, right ?

Here’s my experience with simple character device from Linux Kernel Module Programming Guide. (more…)

February 3, 2009

Hello World Module for TS-7260

Filed under: ARM9, linux-device-driver — Tags: , — kunilkuda @ 12:14 pm

Actually this post is based on Linux Device Driver 3rd book (you can buy its hardcopy here, or view its softcopy here).  I only port it into TS-7260 platform.

The hello module consist of hello.c and the Makefile. Here’s the hello.c file: (more…)

Older Posts »