LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Embedded & Single-board computer (https://www.linuxquestions.org/questions/linux-embedded-and-single-board-computer-78/)
-   -   Simple Bit Bang Serial Driver Question (https://www.linuxquestions.org/questions/linux-embedded-and-single-board-computer-78/simple-bit-bang-serial-driver-question-660680/)

Gnu2Linux2 08-05-2008 02:27 PM

Simple Bit Bang Serial Driver Question
 
This is dirt simple, so please don't kill me.

I am new to linux drivers and want see if my approach is correct
here. I need to write a little bit banging device driver to a custom
CPLD 3-Wire serial interface. This is a one way communication meaning
we are only writing to the device over the serial interface.

So, I think what i need to do is write a character driver will
implement an open, release, and write methods and of course the init
and exit to setup the character driver. Is the correct approach?

In my write method in the driver, when i receive the 3 bytes of data
that I need to bit-bang over 3 gpios I will enable the chip select
gpio and start the clocking gpio and transmitting the the bits on the
data gpio.

Anyone have a sample driver of something similar? I just basically
want to see how the correct way to implement the timer for the clock
in the kernel. I am sure I can figure it out and will, but would like
to see an example from someone who is not as new to linux as I am.

i know the pseudo code is something like the following, but maybe a
timer (i assume there are timers in the kernel) is the better approach
which is the whole reason I am asking about this.

bbserial_write(....)
{
enable the chip select gpio (set low)
while (bits to write)
{
set clk gpio low
wait 1/2 bit time
set data gpio
wait 1/2 bit time
set clk gpio high
}
disable the chip select gpio (set high)
}

cramer-creek 08-06-2008 02:39 PM

bit time delay
 
use udelay(HALF_BIT_TIME)

see linux/drivers/i2c/algos/i2c-algo-bit.c
for a (complex and generic ) example of this.


All times are GMT -5. The time now is 10:01 AM.