Now that there are several C compilers working for P2, it seems like we should try to get consensus on some things. It'd be nice if code could be easily ported between compilers. It'll be very confusing and frustrating for users if there isn't at least a baseline commonality between C compilers on the platform (naturally each compiler will have its own particular features and advantages, but lots of code *should* be portable between them!)
It seems that we'll want a few common things at a minimum:
(1) A macro that identifies the platform as a Propeller 2. I've been using -D__P2__ in fastspin, but this may be too concise. Other reasonable options are -D__prop2__ or -D__propeller2__.
(2) A header file defining intrinsics that everyone can use. I've suggested <propeller2.h> as the name, but I'm open to variations on this.
(3) A commonly agreed upon set of intrinsics for things like pin manipulation, COG start/stop, timers, CORDIC access, and ??? (maybe the streamer).
One obvious choice for names (and functions) to implement is to more or less follow what Spin2 does. @cgracey
, do you have a preliminary list of the names for the Spin2 functions for these things? E.g. is there a Spin2 function that does what the "drvh" instruction does? We could adopt the same system for C, perhaps with an underscore prepended (to keep the functions from conflicting with user names -- the C standard says that global function names starting with an underscore are reserved for the system).
If there isn't already a Spin2 standard, we could just use the instruction names, e.g.:
extern void _drvh(unsigned p); // set pin p as output and drive it high
extern unsigned _testp(unsigned p); // test pin p for input
// and so on
Not every intrinsic will map to just one instruction, e.g. _coginit will have to do a "setq" for the parameter to pass to the COG. We'll probably also want accessor functions for things like the builtin COG registers, counter, and so forth.
, @Dave Hein
, does this sound reasonable for Catalina and p2gcc respectively? If we three can agree on a naming scheme we can have it implemented in Catalina, p2gcc, fastspin, and the Risc-V emulator.