Re: writing integers to the char device driver

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi!

On 13:29 Wed 18 Feb     , Troy, Willis wrote:
> Howdy,
> 
> I am fairly new to device drivers and this list, but I'm sure someone in here can help me.
> 
> First, some background.  I am working on device drivers for a FPGA that is currently running kernel 2.6.28, because it is an FPGA I can add custom hardware.  The custom hardware I currently have is very simple- just a multiplier- for a proof of concept.  Currently I have a char device driver written for it that will take in ascii and multiply its ascii value by another ascii value.  Eg. 0x0=char(0)*char(0)=48*48.  This isn't really what I want, I want a device driver that can read in two 32 bit numbers and return a 32 bit number.
> 
> So,  can I write integers/longs to a character device driver?  Is there a better way to do this?

1) Convert the number to little/big endian
2) cast the int to a "char *" using the addressof operator+typecast
3) call write(fd, "your casted int", 4)

When reading the result:
1) declare an int
2) cast this int to a char *
3) call read
4) convert from little/big endian to mashine byte order

DO NOT DECLARE "char[4]" AND CAST THIS TO AN "int *". THIS WILL FUNCTION ON
SOME MACHINES, BUT NOT ALL.

	-Michi
-- 
programing a layer 3+4 network protocol for mesh networks
see http://michaelblizek.twilightparadox.com


--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux