How to specify offset into SPI device

Thomas Doerfler Thomas.Doerfler at imd-systems.de
Tue Mar 11 15:11:35 UTC 2008


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello Robert,

wow, you made a long way :-) Sorry for not answering, you were still on
my "TODO" List.

The RTEMS I/O system will pack the offset required into the "args"
structure passed to the memory driver.

So the write call just has to use the elements of arg.

I still did not submit the SPI memory driver, but I have packed it
together and attached to this mail, maybe it is of some use to you! You
can either get some info about hte interfacing, or (which should work
aswell) simply write adapt the modules to you FRAM.

wkr,
Thomas.





Robert S. Grimes schrieb:
| Okay, I've got most of this figured out.  This code works, in that it
| invokes the correct driver calls:
|
|   int fd = open("/dev/spi.fram", O_RDWR);
|   printf("open returned %d\n", fd);
|   if (fd >= 0) {
|     char buffer[32];
|     char rbuffer[32];
|
|     strcpy(buffer,  "Hello world");
|     strcpy(rbuffer, "Uh, oh.....");
|     printf("ioctl returned %d\n", ioctl(fd, SEEK_SET, 0x200));
|     printf("write returned %d\n", write(fd, buffer, 4));
|     printf("ioctl returned %d\n", ioctl(fd, SEEK_SET, 0x200));
|     printf("read returned %d\n", read(fd, rbuffer, 4));
|     printf("rbuffer = [%s]\n", rbuffer);
|     close(fd);
|   }
|
| This gives the following output:
|
|   open returned 4
|   ioctl returned -1
|     fram write
|     bsp_spi_send_start_dummy: Implement me!
|     bsp_spi_sel_addr: Implement me!
|     bsp_spi_send_stop: Implement me!
|     bsp_spi_send_start_dummy: Implement me!
|     bsp_spi_sel_addr: Implement me!
|     bsp_spi_send_stop: Implement me!
|   write returned 4
|   ioctl returned -1
|     fram read
|     bsp_spi_send_start_dummy: Implement me!
|     bsp_spi_sel_addr: Implement me!
|     bsp_spi_send_stop: Implement me!
|   read returned 0
|   rbuffer = [Uh, oh.....]
|
| The lines starting with "fram" or "bsp_spi_XXX" are debugging outputs
| from the drivers I'm working on.  So, everything is set up to actually
| access the device!  Yes!
|
| The next question is this: how do I specify the offset into the FRAM?  I
| guessed it's in an ioctl call, as suggested in libi2c.h, but as you can
| see, that doesn't work.  Stepping through, it seems ioctl is not
| implemented for the libi2c driver.
|
| So, I do I specify the offset into the FRAM device???
|
| Thanks,
| -Bob
|
|
| Robert S. Grimes wrote:
|> Hi Thomas,
|>
|> I've got most of the pieces together, in the form of stubs right now,
|> for the low-level SPI driver.  I've also got stubs for a Fram driver.
|> I'm building these as part of my application, and everything builds
|> fine.  But I don't know how to "use" this all, from an application's
|> viewpoint.
|>
|> Here's what I have now, in my main application:
|>
|>   printf("Starting SPI...\n");
|>   err = bsp_register_spi();      // This returns okay
|>
|> This results in the tracking output I've instrumented the spi_init code
|> with, so I can see the SPI driver (and of course, the i2c library) is
|> being initialized.  But I don't know what's next.
|>
|> I've tried this:
|>
|>   rtems_driver_name_t framInfo;
|>   rtems_status_code result = rtems_io_lookup_name(name, &framInfo);
|>   if (result) {
|>     printf("Can't find %s, error %d\n", name, result);
|>   } else {
|>     printf("Found %s device\n", name);
|>     printf("  name:  %s\n", framInfo.device_name);
|>     printf("  major: %u\n", framInfo.major);
|>     printf("  minor: %u\n\nOpening...\n", framInfo.minor);
|>
|>     result = rtems_io_open(framInfo.major, framInfo.minor, 0);   /* Is 0
|> correct here? */
|>     if (result) {
|>       printf("Can't open %s, error %d\n", name, result);
|>     }
|>   }
|>
|>
|> This all works, in the sense that no errors are returned, but I'm not
|> sure it is correct.  The next step, for example writing, seems way to
|> complex - the call to rtems_io_write requires an args pointer, which is
|> cast to an rtems_libio_rw_args_t struct, which requires a rtems_libio_t
|> struct.  Clearly I'm not going about this in the write way!
|>
|> So, what do I do to, for example, write and read something simple to the
|> Fram device?  Simple pseudo-code is all I need, though I would
|> appreciate actual function names.  Obviously, my Fram device driver is
|> different from the spi-flash-m25p40 driver, but I can extrapolate
|> answers expressed in terms of the spi-flash-m25p40.
|>
|> This is a long email for what I expect is actually a pretty simple
|> answer - I'm sure I'm just missing something!
|>
|> Thanks, and take care,
|> -Bob
|>
|> _______________________________________________
|> rtems-users mailing list
|> rtems-users at rtems.com
|> http://rtems.rtems.org/mailman/listinfo/rtems-users
|>
|
| _______________________________________________
| rtems-users mailing list
| rtems-users at rtems.com
| http://rtems.rtems.org/mailman/listinfo/rtems-users


- --
- --------------------------------------------
IMD Ingenieurbuero fuer Microcomputertechnik
Thomas Doerfler           Herbststrasse 8
D-82178 Puchheim          Germany
email:    Thomas.Doerfler at imd-systems.de
PGP public key available at:
~     http://www.imd-systems.de/pgpkey_en.html
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFH1qEkwHyg4bDtfjQRAtJHAJ9wZ4jHEUgpFgeZR2nlzyZFWMU13QCfb/66
kdOS4N2DbZCa6/0RftXmtgw=
=ispO
-----END PGP SIGNATURE-----
-------------- next part --------------
A non-text attachment was scrubbed...
Name: rtems_spimemdrv.tgz
Type: application/octet-stream
Size: 3721 bytes
Desc: not available
URL: <http://lists.rtems.org/pipermail/users/attachments/20080311/0efba337/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: rtems_spimemdrv.tgz.sig
Type: application/octet-stream
Size: 65 bytes
Desc: not available
URL: <http://lists.rtems.org/pipermail/users/attachments/20080311/0efba337/attachment-0001.obj>


More information about the users mailing list