View Full Version : Porting propeller code to C language
12-29-2009, 07:34 PM
I am currently using visual studio 2005, and I am thinking of using some of propeller objects such as fullduplexserial, and quadrovercontrol...Is there any reference about porting propeller code to C language?
I've done some searching but I don't find any reference about it..
Help would be really appreciated~thank you very much~
12-29-2009, 08:09 PM
If these are SPIN objects then you will probably get a speed improvement by translating them to C, but if they are PASM objects then there is no point in translating them - they will undoubtedly run better left as PASM.
With the Prop, parallel processing is quite easy, and you can run PASM objects in parallel with your C code (on a separate cog). Catalina defines an interface between C code and PASM objects for this purpose (you will find PASM objects that use this interface called 'plugins' in the Catalina documentation).
Converting an existing PASM object to a Catalina plugin is fairly straightforward - nearly all the Catalina drivers (screen, keyboard, mouse, serial, SD card drivers, floating point libraries, real-time clock) are derived from Parallax PASM equivalents. There is some documentation on doing this in the Catalina reference manual, but the best method is to look at some of the existing plugins and compare them to the original versions.
But with translating SPIN objects you are on your own. I believe someone started work on a tool to translate between C and SPIN, but I think they were only supporting C -> SPIN, not SPIN -> C. However, SPIN -> C is actually easier, since SPIN is a simpler language - so if your SPIN code base is not too large you could probably do it manually.
Catalina - a FREE C compiler for the Propeller - see Catalina (http://forums.parallax.com/showthread.php?p=844004)
12-29-2009, 11:34 PM
Is your target platform a propeller or a PC?· If you are using Visual Studio 2005 then you are developing apps for a PC, correct?· Many of the routines in fullduplexserial can be easily duplicated with C functions or macros.· I don't know anything about quadrovercontrol, so I don't know how difficult it would be to translate that to C.
I started working on a Spin-to-C converter, but I've switched over to working on a C-to-Spin converter instead.· I'll look at the Spn-to-C program I developed to see if it's in a useable state.· I'll post it if it looks OK for others to use.
The Spin-to-C converter has turned into a fairly big project.· It started out as a simple translator, but has become more of a C compiler that produces Spin code as its output.· I am trying to support a minimum set of C functionality before I post the Spin-to-C converter for public consumption.
12-30-2009, 05:24 PM
Thank you for the reply Rossh and Dave,
@Dave: Yes, my target platform is PC, and actually I just need to use some of the fullduplexserial routine such as rx, and tx. But, since I am new to propeller chip and assembly programming, I don't quite understand about what you say as duplicating routines with C functions or macros. Is there any tutorial that I can refer to for translating some of the simple spin routines to C?
12-30-2009, 06:06 PM
I don't think you will find any "how to" document on porting Spin to C. It's just not something people do, especially going from Prop to PC. By the way I don't think "porting" is quite the right term here. What you want to do is achieve the same functionality by rewriting the thing in C. Basically you need to understand Spin and understand C and then rewrite whatever it is in C.
Now taking FullDuplexSerial as an example. I would totally forget the idea of porting or rewriting that in C for Windows. There is no point. Windows already has drivers for serial ports, just use those. Besides the important parts of FullDuplexSerial are written in PASM for driving bits out and receiving bits in from the Prop pins with the right timing. All of this is very Propeller hardware dependent. There is no use for this code on a PC.
I suspect this is true of 90% of Propeller code. It is very hardware dependent. The PC does not have such hardware so porting is not an option.
There may be some standalone, generally useful algorithms people have created in SPIN. Say a Fast Fourier Transform but again most of these things exist in C already somewhere or are not so hard to create. Perhaps taking the original Spin code as a basis.
Perhaps if you have some other functionality that exists on the Prop as Spin or PASM that you want to have on the PC you could tell us what it is. Then someone will come up with ideas on how to achieve it on the PC.
For me, the past is not over yet.