Shop OBEX P1 Docs P2 Docs Learn Events
Help with propeller C and Spin — Parallax Forums

Help with propeller C and Spin

tdahburatdahbura Posts: 6
edited 2011-06-20 19:42 in Propeller 1
Is there a way to compile a c program to a library and then call it from SPIN?

I am using the ICCV 7.04 tool, but am not sure how to compile a routine and then include it as part of my spin code to be called...

Any help would be appreciated on the steps or docs to do this...


Thanks,
Tony

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2011-06-17 17:19
    No, it doesn't work that way. Spin programs can only call Spin routines. Spin programs can start up new cogs (using COGNEW or COGINIT) that run a Spin interpreter or the LMM (Large Memory Model) interpreter used by ImageCraft's C or your own assembly program, but there's no return to the Spin program.
  • Cluso99Cluso99 Posts: 18,069
    edited 2011-06-17 21:43
    Drac could be the closest to getting Catalina programs to run this way. He can dynamically load all sorts of programs & drivers now.
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2011-06-18 01:33
    Is there a way to compile a c program to a library and then call it from SPIN?

    No, sorry. You have to choose either spin or C.

    But what you can do from either is to load up cogs and interface with them in the same way. We have been taking a number of obex objects and splitting them into separate spin and pasm components. Then translating the spin part into C. So these 'cogjects' can be loaded from arrays on an sd card, and hence don't take up hub ram after they have been loaded. There are display, mouse, keyboard drivers using this method.

    But I think there might be one cunning thing you can do in Catalina, and that is to treat the spin interpreter as a 'cogject', load it up, run it and then use it to run spin programs. Reload the cog with other code once it has finished. I have not done this but it could be possible.

    What is the program you need to write?
  • RossHRossH Posts: 5,519
    edited 2011-06-18 02:31
    Dr_Acula wrote: »
    No, sorry. You have to choose either spin or C.

    But I think there might be one cunning thing you can do in Catalina, and that is to treat the spin interpreter as a 'cogject', load it up, run it and then use it to run spin programs. Reload the cog with other code once it has finished. I have not done this but it could be possible.

    Hi Tony,

    Dr_A is correct - there are several ways you can execute a Spin method in parallel with a C program - but making C callable from Spin (or vice-versa) is not currently possible (at least not without so much messing about that it is not really worth the effort).

    Ross.
  • Dave HeinDave Hein Posts: 6,347
    edited 2011-06-18 05:31
    tdahbura,

    If you are developing on a Windows platform you could try CSPIN http://forums.parallax.com/showthread.php?119342-CSPIN-A-C-to-Spin-Converter&highlight=cspin . It will convert from C to Spin so you can interface to the objects in the OBEX. It does have some restrictions, which are documented in the README file. I've attached the latest version to this post.

    Dave
  • tdahburatdahbura Posts: 6
    edited 2011-06-20 18:31
    I have some existing c code which has been ported and running on the propeller. I wanted to take advantage of some xbee programming and found the spin obex for xbee communications. I am not sure how to get that code to run in C so I was hoping to be able to use both. The C code is way too convoluted to try to port to anything....

    Tony

    Dr_Acula wrote: »
    No, sorry. You have to choose either spin or C.

    But what you can do from either is to load up cogs and interface with them in the same way. We have been taking a number of obex objects and splitting them into separate spin and pasm components. Then translating the spin part into C. So these 'cogjects' can be loaded from arrays on an sd card, and hence don't take up hub ram after they have been loaded. There are display, mouse, keyboard drivers using this method.

    But I think there might be one cunning thing you can do in Catalina, and that is to treat the spin interpreter as a 'cogject', load it up, run it and then use it to run spin programs. Reload the cog with other code once it has finished. I have not done this but it could be possible.

    What is the program you need to write?
  • tdahburatdahbura Posts: 6
    edited 2011-06-20 18:40
    Dave:
    I am going to try your cspin out. Never fear I am not afraid of the command line!

    I would second other comments though to focus on the tool and not worry about the GUI right now. BTW I am a mac user with a vmware window running to running some of these gui based tools to talk with my propeller.

    Tony
  • Dave HeinDave Hein Posts: 6,347
    edited 2011-06-20 19:42
    Tony,

    I hope cspin works OK for you. Let me know if you run into any problems, and I'd be happy to take a look at it.

    Dave
Sign In or Register to comment.