How to specify offset into SPI device (was: Re: How to use spi-flash-m25p40 driver?)

Robert S. Grimes rsg at alum.mit.edu
Tue Mar 11 14:52:50 UTC 2008


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
>




More information about the users mailing list