THE CHINESE New Year will come to end soon, and today is the last day. Being busy in enjoy the happy festival, I have not updated my blog for 7 days. Also, I am digging into Linux Driver Design these days as I said in my last blog.
My first simplest driver for NiosII is constant LED Drive too, it takes my 2 days on it. Eventually, it works very well this morning. Ha, what's a big surprise. Look back my two day's work course, I reach some conclusions. As follows,
The general rules to design a char driver are introduced in Linux Device Driver and you can trust it completely. New and obsolete means are said respectively, certainly, you should use the latest manners.
IO Port Access
As introduced in the LDD, IO address separately (Only for X86 serials), whereas IO address just like conventional Memory(ARM, NiosII, almost all processors currently). For the first kind, you should use Outb, Outw, Outl , Inb, Inw, Inl and for the other you should use writeb, writew, writel , readb, readw, readl .(These are old manners and not atomic, the latest are iowrite8, iowrite16, iowtite32 etc. But the NiosII only support the old manners.) For convenience, NiosII also implement the manners Outb and so on, but they are same as writeb and so on. You can refer uClinux-dist/linux-2.6.x/include/asm/io.h for more details
After finishing the code of char driver, you can dispatch the driver in the uClinux-dist, but I think it is not convenient and complex, meanwhile, the compile process will take you a lot of time. So I choose the better method that compile the driver out of the uClinux-dist. It only need you code a Makefile and you can refer LDD's Makefile, however, you must care about some difference, or you will fail.
$(MAKE) ARCH=nios2nommu CROSS_COMPILE=nios2-linux-uclibc- -C $(KERNELDIR) M=$(PWD) modules
Then you can copy the *.ko module in the directory of romfs/lib and usually you need some application routine to test the driver if can work. Here, the most notable thing is that when you compile the application routine, you must add the parameter -elf2flt, or the kernel will crash, then also copy the executable file to the romfs/usr/bin directory. More details, you should look at NiosII wiki Web set.
In the uClinux-dist directory, execute the commad “ make linux image” and
add the driver the same as convention Linux , insmod, mknod. In the end, you must can not wait to run your application to verify it. Have fun!

