Shop OBEX P1 Docs P2 Docs Learn Events
Pico C — Parallax Forums

Pico C

Dave HeinDave Hein Posts: 6,347
edited 2014-05-13 18:02 in Propeller 1
Someone had asked about Pico C in another thread. I ported Pico C to the Prop about 9 months ago when I was looking into Forth. Pico C is an interactive C interpreter. C statements can be entered interactively and executed immediately. I played around with it a little bit, but I didn't pursue it very far. However, I thought I would post the code here in case someone else is interested in it. I modified the makefile that came with Pico C, and I built it from the command line. It may be possible to build it under SimpleIDE, but I didn't try that. It has to be built with the XMMC model. Check out the Pico C site at http://code.google.com/p/picoc/ if you're interested in trying it. There is a Wiki there with some information on how to use it.

Comments

  • KeithEKeithE Posts: 957
    edited 2013-06-06 22:16
    Thanks Dave - I'll take a look over the next few days.
  • KeithEKeithE Posts: 957
    edited 2013-06-07 22:01
    Dave,

    I'm on an OS X machine, and was able to run make after adding /opt/parallax/bin/ to my path. picoc was generated and appears to be an elf file.

    Should I be able to run this on a Quickstart board? I tried to load it with the following command (and some variations):

    propeller-load -Dreset=dtr -I /opt/parallax/propeller-load/ -b QUICKSTART -p /dev/cu.usbserial-AH00OLRA picoc -r -e -t -D baudrate=115200

    I just a few bytes of garbage in the terminal after using the above.

    I don't know if the baud rate is correct, or if the eeprom on the Quickstart is sufficiently large. I can setup an SD card if necessary.

    For fun I tried building the DDS BASIC Interpreter V1.0(a) from IOCCC in SimpleIDE and that came right up. (I just changed some numbers to reduce the memory requirements.)

    Thanks,
    Keith
  • jazzedjazzed Posts: 11,803
    edited 2013-06-08 10:53
    KeithE wrote: »
    Should I be able to run this on a Quickstart board? I tried to load it with the following command (and some variations):

    No. As you suspect the EEPROM is too small. I've run the demo using SDXMMC, but it's quite slow.

    The best XMMC solution for most people seems to be a DIP8 Flash on a bread-board. There are other possibilites though.
  • KeithEKeithE Posts: 957
    edited 2013-06-08 18:09
    jazzed wrote: »
    No. As you suspect the EEPROM is too small. I've run the demo using SDXMMC, but it's quite slow.

    The best XMMC solution for most people seems to be a DIP8 Flash on a bread-board. There are other possibilites though.

    Is there a list of supported parts? The only flash reference I saw on the learn.parallax.com was to the C3 board. I would rather pick something that's already working. If I can pickup one in a DIP package then I'll do that just to have it as an option.

    I'm assuming that Parallax doesn't think that this will be a common usage model, otherwise the Propeller Activity board would have one since it's being suggested as a good C platform? If a stock Activity board can't support Pico C well, then it's probably of little interest since there wouldn't be critical mass. I'll give it a go with an SD card and see how bad it is.

    -Keith
  • jazzedjazzed Posts: 11,803
    edited 2013-06-08 19:05
    There is a generic description of off the shelf memory chips in the propeller-load document here. We should update the devices supported in the Memory Model Board Matrix ....

    The W25Q80 Winbond flash is the one most often used because it works in SingleBit and QuadBit SPI modes. The best performance so far is by adding two QuadSPI devices in parallel, but that uses 10 pins and the performance gain on average is only about 33% over single bit SPI which uses 4 pins.
  • KeithEKeithE Posts: 957
    edited 2013-06-08 20:25
    Thanks for the pointer. I see you live in Silicon Valley. Do you know if any shops in the area carry these Winbond parts? Anchor, Halted, Frys, Jameco,... I'm down near Guitar Showcase.

    Thanks,
    Keith
  • jazzedjazzed Posts: 11,803
    edited 2013-06-08 21:01
    KeithE wrote: »
    I'm down near Guitar Showcase.

    My second favorite place in the valley :)

    Don't know of any retail suppliers with SPI Flash in the Bay Area. I usually get parts through mouser or digikey - all I have now is SMD for the SSF PCB's.
  • KeithEKeithE Posts: 957
    edited 2013-06-08 21:28
    Hmm - what's your favorite? Gryphon Stringed Instruments? There's a place down in Los Gatos "Keith Holland's Guitar Hospital" that is small, but has a little performance space called "The Woodshed". They have a large shop area - I was just there today to have them install a railroad spike on a banjo ;-)

    Could you let me know what you did to run Pico C in SDXMMC mode? Did you have to change anything in the Makefile? Could you paste what loader options you used? I just unpacked my Activity Board so I can give this a shot.

    Regards,
    Keith
  • jazzedjazzed Posts: 11,803
    edited 2013-06-09 09:27
    My favorite valley place is not a music shop ;)

    I've attached a SimpleIDE Picoc package to use for board type ACTIVITYBOARD-SDXMMC . It takes about 10 seconds to start up with SDXMMC. For comparison, it starts up in a few seconds on board type C3F and less than a second on SSF (dual QuadSPI).
  • KeithEKeithE Posts: 957
    edited 2013-06-09 19:54
    Thanks for putting that together. The startup time doesn't seem too bad, but the execution speed is quite slow.

    I was wondering, should the Propeller loader be able to detect when you attempt to load an image that won't fit? It would seem that it could figure this out from the board type. e.g. when I tried to load this into an eeprom? Maybe something for the kanban queue?
  • jazzedjazzed Posts: 11,803
    edited 2013-06-10 06:57
    KeithE wrote: »
    Thanks for putting that together. The startup time doesn't seem too bad, but the execution speed is quite slow.

    I was wondering, should the Propeller loader be able to detect when you attempt to load an image that won't fit? It would seem that it could figure this out from the board type. e.g. when I tried to load this into an eeprom? Maybe something for the kanban queue?

    Yes, we can put size tags in the board config file. Will check with David.
    Normally size is checked in the linker, but we don't use board info in the build.

    Thanks.
  • jazzedjazzed Posts: 11,803
    edited 2014-05-12 12:43
    Hi.

    Here is a version of PicoC that will run from a 64KB EEPROM (most hardware except SpinStamp, PropellerMini, Demoboard which have 32KB EEPROMS).

    File access is disabled.

    Since the code is running from EEPROM, there is about 24KB of RAM available for user programs.

    It is not possible to use #include in this example. It is also not possible as far as I can tell to access propeller hardware features (yet).
  • jazzedjazzed Posts: 11,803
    edited 2014-05-12 13:29
    Ok,

    Now for adding Propeller hardware access ....

    Replace library_unix.c with the code below and "Run with Terminal".

    Then enter these lines on the picoc terminal to make P27 LED on the ActivityBoard blink once per second.
    frqa(0x40);
    ctra((4<<26)|27);
    output(27);
    

    New contents of library_unix.c adds these library functions:

    void high(int);
    void low(int);
    void output(int);
    void input(int);
    int pin(int);
    void ctra(int);
    void frqa(int);
    void phsa(int);
    void ctrb(int);
    void frqb(int);
    void phsb(int);

    Other functions can be added following the examples given in the code.

    #include "interpreter.h"
    
    
    /*
    #define dprintf
    
    
    void UnixSetupFunc()
    {    
    }
    
    
    void Ctest (struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) 
    {
        dprintf("test(%d)\n", Param[0]->Val->Integer);
        Param[0]->Val->Integer = 1234;
    }
    
    
    void Clineno (struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) 
    {
        ReturnValue->Val->Integer = Parser->Line;
    }
    */
    
    
    #include <propeller.h>
    
    
    void PropellerSetupFunc()
    {    
    }
    
    
    void CHigh (struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) 
    {
        ReturnValue->Val->Integer = 0;
        OUTA |= 1 << Param[0]->Val->Integer;
    }
    
    
    void CLow (struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) 
    {
        ReturnValue->Val->Integer = 0;
        OUTA &= ~(1 << Param[0]->Val->Integer);
    }
    
    
    void COutput (struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) 
    {
        ReturnValue->Val->Integer = 0;
        DIRA |= 1 << Param[0]->Val->Integer;
    }
    
    
    void CInput (struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) 
    {
        ReturnValue->Val->Integer = 0;
        DIRA &= ~(1 << Param[0]->Val->Integer);
    }
    
    
    void CPin (struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) 
    {
        int pin = Param[0]->Val->Integer;
        ReturnValue->Val->Integer = (INA & (1 << pin)) >> pin;
    }
    
    
    void CCtra (struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) 
    {
        CTRA = Param[0]->Val->Integer;
    }
    
    
    void CFrqa (struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) 
    {
        FRQA = Param[0]->Val->Integer;
    }
    
    
    void CPhsa (struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) 
    {
        PHSA = Param[0]->Val->Integer;
    }
    
    
    void CCtrb (struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) 
    {
        CTRB = Param[0]->Val->Integer;
    }
    
    
    void CFrqb (struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) 
    {
        FRQB = Param[0]->Val->Integer;
    }
    
    
    void CPhsb (struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) 
    {
        PHSB = Param[0]->Val->Integer;
    }
    
    
    /* list of all library functions and their prototypes */
    struct LibraryFunction PropellerFunctions[] =
    {
    /*  
        { Ctest,        "void test(int);" },
        { Clineno,      "int lineno();" },
    */    
        { CHigh,        "void high(int);" },
        { CLow,         "void low(int);" },
        { COutput,      "void output(int);" },
        { CInput,       "void input(int);" },
        { CPin,         "int  pin(int);" },
        { CCtra,        "void ctra(int);" },
        { CFrqa,        "void frqa(int);" },
        { CPhsa,        "void phsa(int);" },
        { CCtrb,        "void ctrb(int);" },
        { CFrqb,        "void frqb(int);" },
        { CPhsb,        "void phsb(int);" },
        
        { NULL,         NULL }
    };
    
    
    void PlatformLibraryInit()
    {
        IncludeRegister("propeller.h", &PropellerSetupFunc, &PropellerFunctions[0], NULL);
    }
    
  • David BetzDavid Betz Posts: 14,516
    edited 2014-05-12 15:10
    jazzed wrote: »
    No. As you suspect the EEPROM is too small. I've run the demo using SDXMMC, but it's quite slow.

    The best XMMC solution for most people seems to be a DIP8 Flash on a bread-board. There are other possibilites though.
    One off the shelf board that can handle all of the XMM modes is the C3. It's chip select counter makes it a little slower than solutions with a dedicated pin for each chip select but it performs pretty well anyway and it works out of the box with no add-on boards or chips on a breadboard.
  • jazzedjazzed Posts: 11,803
    edited 2014-05-12 15:16
    Ok,

    Here is a version with all Propeller features for running on 64KB EEPROM.

    Propeller features are accessible using the following library functions:

    /*
    * get the current CNT value.
    */
    int cnt();
    /*
    * get the system clock frequency value.
    */
    int clkfreq();
    /*
    * set outa pin high. use output(pin) to set dira so that outa appears on pin.
    */
    void high(int pin);
    /*
    * set outa pin low. use output(pin) to set dira so that outa appears on pin.
    */
    void low(int pin);
    /*
    * set dira pin high for output.
    */
    void output(int pin);
    /*
    * set dira pin low for input.
    */
    void input(int pin);
    /*
    * get value of pin(num).
    */
    int pin(int num);
    /*
    * get value of all pins.
    */
    int pins();
    /*
    * set ctra value.
    */
    void ctra(int value);
    /*
    * set ctrb value.
    */
    void ctrb(int value);
    /*
    * set frqa value.
    */
    void frqa(int value);
    /*
    * set frqb value.
    */
    void frqb(int value);
    /*
    * set phsa value.
    */
    void phsa(int value);
    /*
    * set phsb value.
    */
    void phsb(int value);
    /*
    * set vcfg value.
    */
    void vcfg(int value);
    /*
    * set vscl value.
    */
    void vscl(int value);
    /*
    * wait for cnt to be value. return value+adjust.
    */
    int waitcnt(int value, int adjust);
    /*
    * wait for pins & mask to equal value.
    */
    void waitpeq(int value, int mask);
    /*
    * wait for pins & mask to not equal value.
    */
    void waitpne(int value, int mask);
    /*
    * wait for video generator.
    */
    void waitvid(int value1, int value2);

    Everything seems to work. It's a bit slow though.

    There isn't much room for new user functions.
  • frank freedmanfrank freedman Posts: 1,983
    edited 2014-05-13 09:25
    Anchor Electronics is still there? I used to get parts from them back in high school mid '70s when finding things at Quement was iffy and Fry's was where you went for groceries and not much else.

    major flashback......
    KeithE wrote: »
    Thanks for the pointer. I see you live in Silicon Valley. Do you know if any shops in the area carry these Winbond parts? Anchor, Halted, Frys, Jameco,... I'm down near Guitar Showcase.

    Thanks,
    Keith
  • KeithEKeithE Posts: 957
    edited 2014-05-13 13:28
    Anchor Electronics is still there? I used to get parts from them back in high school mid '70s when finding things at Quement was iffy and Fry's was where you went for groceries and not much else.

    major flashback......

    Yep - Anchor is right across from the Nvidia headquarters. (Not too far from the new football stadium)

    I forget where the first Fry's w/ electronics in the area was - somewhere near Lakeshore drive? That was a funny blend - I first went in the mid-to-late 80's. Too bad the the dot com days blew up the Computer Literacy bookstore. There's a digital guru bookshop close to where that used to be, but it's not quite the same. St John's Bar and Grill is still there ;-)
  • jazzedjazzed Posts: 11,803
    edited 2014-05-13 13:40
    KeithE wrote: »
    Yep - Anchor is right across from the Nvidia headquarters. (Not too far from the new football stadium)

    I forget where the first Fry's w/ electronics in the area was - somewhere near Lakeshore drive? That was a funny blend - I first went in the mid-to-late 80's. Too bad the the dot com days blew up the Computer Literacy bookstore. There's a digital guru bookshop close to where that used to be, but it's not quite the same. St John's Bar and Grill is still there ;-)
    Yes, Fry's Electronics was just behind what is now Round Table Pizza at Oakmead and Lakeside Drive (nearest Lakeside). St John's is my all-time favorite burger place (5 Guys is good, but no beer there). Computer Literacy was great. There used to be some incredible shows down Arques near the latest Sunnyvale Frys ;-)
  • frank freedmanfrank freedman Posts: 1,983
    edited 2014-05-13 17:37
    Football stadium? Gosh, I remember finding Computer Literacy while home on leave in 1980(?) and the Togo's shop right next to it. Come to think of it that was where I bought Tanenbaum's minix book among others. Still have it.

    Blossom Hill Rd. was a two laner between San Jose and the rest of Los Gatos. Used to beat the derailuers off of my Raleigh with the loop Almaden expwy dead end to calero-anderson-guadalupe dam ending near by the little IBM / 9hole golf course next to home. Probably could not find my anymore even if there was a map pasted to it with pictures. Miss what it was, likely could not stand what it has become though........
  • KeithEKeithE Posts: 957
    edited 2014-05-13 17:41
    jazzed wrote: »
    Yes, Fry's Electronics was just behind what is now Round Table Pizza at Oakmead and Lakeside Drive (nearest Lakeside). St John's is my all-time favorite burger place (5 Guys is good, but no beer there). Computer Literacy was great. There used to be some incredible shows down Arques near the latest Sunnyvale Frys ;-)

    If I understand what you're referring to, I used to work at Weitek on Arques and my boss would take certain out of the country visitors there for business negotiations ;-)

    Edited to add - Frank there's now an NFL football stadium "Levi's (tm)" in what used to be the Great America overflow parking lot right next to the 49er headquarters. It will be interesting to see how it messes up things this fall.
  • jazzedjazzed Posts: 11,803
    edited 2014-05-13 18:02
    KeithE wrote: »
    If I understand what you're referring to, I used to work at Weitek on Arques and my boss would take certain out of the country visitors there for business negotiations ;-)

    Probably made them feel at home. I ate lunch there once ... barf.
    KeithE wrote: »
    Edited to add - Frank there's now an NFL football stadium "Levi's (tm)" in what used to be the Great America overflow parking lot right next to the 49er headquarters. It will be interesting to see how it messes up things this fall.

    Yup, right across from David's and Santa Clara Muni Golf. There is a small-ish garage and a light-rail stop. I heard Cisco sold real-estate around Vista Montanya (my old stomping grounds) to facilitate building more parking structures ... parking will be tight regardless.

    Blossom Hill road has been supplemented by Interstate 85.
Sign In or Register to comment.