Shop OBEX P1 Docs P2 Docs Learn Events
What about C++? - Page 3 — Parallax Forums

What about C++?

13»

Comments

  • RsadeikaRsadeika Posts: 3,837
    edited 2012-09-11 02:12
    Trying to change compiler types within the same .side, is a big no no. Best thing to do is to start from scratch with a new project.

    While trying to get filetest.c to work in C++, I came across the first big problem. C++ simply does not know how to deal with "extern _Driver _FileDriver;", or at least I do not know how to deal with the error. I thought it was a header problem, but I could not find one that would make the error go away. I tried doing a spin2cpp conversion on FSRW that did not work, I reported the problem in the spin2cpp thread. So far I am having no luck trying to implement filetest in a C++ format. Maybe I will think of something different this morning.

    Ray
  • Heater.Heater. Posts: 21,230
    edited 2012-09-11 06:32
    Ray,

    What is that "extern _Driver _FileDriver" tthing and where did it come from?

    Firstly as posted it has a space in it which is a definite no no.
    Secondly it does not specify a type, what is this external thing?

    If it is a function it should look like one;

    extern int _Driver_FileDriver();

    or whatever.

    If it's a function defined in a C module and you are using it from a C++ module you may be up against the "name mangling" problem. Then you will need something like:
    extern "C" {
        extern  int _Driver _FileDriver();
    }
    

    That extern "C" thing tells C++ to use C style linkage to that function.




  • Dave HeinDave Hein Posts: 6,347
    edited 2012-09-11 06:49
    Rsadeika wrote: »
    Actually all those errors are from a C compile, I am not doing it in C++. I switched from a C++, to C .side, that is why I do not understand what is going on, I can not compile it in C.
    Ray, even if SIDE is in the C mode, I think propeller-elf-gcc will compile the file in C++ mode because of the .cpp extension. There is probably a flag to force it to use the C mode, or you can just change the extension to .c.
  • RsadeikaRsadeika Posts: 3,837
    edited 2012-09-11 08:34
    Heater.
    What is that "extern _Driver _FileDriver" thing and where did it come from?

    It comes from filetest.c, a Dave Hine program for working the SD card. It seems like a necessary part for that program, so I was trying to figure out how to implement it in C++, and have it work correctly. Did not have any luck.

    Dave Hine
    ... or you can just change the extension to .c.
    I went to the folder where the file was, and changed it. When I tried to get it to show in SimpleIDE, it would not appear. So, rather than go through the hassle, I just created a new project.

    I looked in the folders for PropGCC C++, and I did not see a "sys/SD" header, I am thinking there is no built in stuff (lib) for working with the SD reader in C++, yet. I tried doing a spin2cc on FSRW, but it came up with errors.

    For now I am going to work on the filetest.c program, finish it off, and then come back to the C++ version.

    Ray
  • Dave HeinDave Hein Posts: 6,347
    edited 2012-09-11 10:39
    Ray Rsadikea,

    There is no sys/SD header file, but there is a sys/sd.h header file. BTW, LoadSDDriver is no longer used. It has been incorporated into dfs_mount, and you need to pass the pin description in a struct to dfs_mount.

    You need to start with the latest version of filetest.c. I have attached it below. It compiles fine under the CMM model. I also tried changing the name from filetest.c to filetest.cpp, and I get lots of errors.

    Dave Hein
    c
  • David BetzDavid Betz Posts: 14,516
    edited 2012-09-11 10:42
    Dave Hein wrote: »
    Ray Rsadikea,

    There is no sys/SD header file, but there is a sys/sd.h header file. BTW, LoadSDDriver is no longer used. It has been incorporated into dfs_mount, and you need to pass the pin description in a struct to dfs_mount.

    You need to start with the latest version of filetest.c. I have attached it below. It compiles fine under the CMM model. I also tried changing the name from filetest.c to filetest.cpp, and I get lots of errors.

    Dave Hein
    Ummm... Didn't I modify the FS support in the library to use the SD pin definitions from the .cfg files a while back or did that get undone?
  • RsadeikaRsadeika Posts: 3,837
    edited 2012-09-11 11:32
    I made an addition to the function below, for a DNA board, I still get mount error:6. When I change the #define to a C3 board, that seems to work fine. I am not sure what else has to be done to support a DNA board.

    Ray
    void mount()
    {
        printf("Load and mount SD: ");
        _SD_Params* mountParams = (_SD_Params*)-1;
    
    // Important: This code assumes you're using a C3 card.
    // If you're using different hardware, make sure you
    // change the following initialization to match your card!
    
    #ifdef SPINNERET_CARD
    
        static _SD_Params params =
        {
            AttachmentType: _SDA_SingleSPI,
            pins:
            {
                SingleSPI:
                {
                    MISO: 16,   // The pin attached to the SD card's MISO or DO output
                    CLK:  21,   // The pin attached to the SD card's CLK or SCLK input
                    MOSI: 20,   // The pin attached to the SD card's MOSI or DI input
                    CS:   19    // The pin attached to the SD card's CS input
                }
            }
        };
        mountParams = &params;
    #endif
    
    
    #ifdef PROP_BOE /* Board of Education */
        static _SD_Params params =
        {
            AttachmentType: _SDA_SingleSPI,
            pins:
            {
                SingleSPI:
                {
                    MISO: 22,   // The pin attached to the SD card's MISO or DO output
                    CLK:  23,   // The pin attached to the SD card's CLK or SCLK input
                    MOSI: 24,   // The pin attached to the SD card's MOSI or DI input
                    CS:   25    // The pin attached to the SD card's CS input
                }
            }
        };
        mountParams = &params;
    #endif
    
    //#define C3_CARD
    #ifdef C3_CARD
        static _SD_Params params =
        {
            AttachmentType: _SDA_SerialDeMUX,
            pins:
            {
                SerialDeMUX:
                {
                    MISO: 10,    // The pin attached to the SD card's MISO or DO output
                    CLK:  11,    // The pin attached to the SD card's CLK or SCLK input
                    MOSI: 9,     // The pin attached to the SD card's MOSI or DI input
                    CLR:  25,    // The pin attached to the counter's reset/clear pin
                    INC:  8,     // The pin attached to the counter's clock/count pin
                    ADDR: 5,     // The SD card's demux address (the counter's count)
                }
            }
        };
        mountParams = &params;
    #endif
    
    #ifdef PARALLEL_SPI /* This is a hypothetical example - modify to suit your needs */
        static _SD_Params params =
        {
            AttachmentType: _SDA_ParallelDeMUX,
            pins:
            {
                ParallelDeMUX:
                {
                    MISO: 4,    // The pin attached to the SD card's MISO or DO output
                    CLK:  5,    // The pin attached to the SD card's CLK or SCLK input
                    MOSI: 6,    // The pin attached to the SD card's MOSI or DI input
                    CS:   0,    // The pin attached to the counter's reset/clear pin
                    START: 2,   // The start bit of the pin mask to set when selecting the SD card's deMUX address
                    WIDTH: 3,   // The width of the pin mask for all pins attached to the deMUX address
            ADDR: 5     // The value to write to the select field when selecting the SD card's deMUX address
                }
            }
        };
        mountParams = &params;
    #endif
    
    #if defined(__PROPELLER_XMMC__) && defined(SD_IS_USING_SD_CACHE_DRIVER)
        // Pass NULL as the params. In this case, we'll use the SD Cache driver.
        // Beware: This only works if you're running your program
        // cached off of the SD card (i.e. propeller-load -z).
        mountParams = 0;
    #endif
    
    #define DNA
    #ifdef DNA
        static _SD_Params params =
        {
            AttachmentType: _SDA_SingleSPI,
            pins:
            {
                SingleSPI:
                {
                    MISO: 0,   // The pin attached to the SD card's MISO or DO output
                    CLK:  1,   // The pin attached to the SD card's CLK or SCLK input
                    MOSI: 2,   // The pin attached to the SD card's MOSI or DI input
                    CS:   3    // The pin attached to the SD card's CS input
                }
            }
        };
        mountParams = &params;
    #endif
    
        if (mountParams == (_SD_Params*)-1)
        {
            printf("You must specify the SD paramters in the filetest.c\n");
            exit(1);
        }
    
        uint32_t mountErr = dfs_mount(mountParams);
        if (mountErr)
        {
            printf("Mount error: %d\n", mountErr);
            exit(1);
        }
    
        printf("done.\n\n");
    }
    
  • RsadeikaRsadeika Posts: 3,837
    edited 2012-09-11 12:03
    I got the above mount function to work with a DNA board, the program works better with an SD card in the reader. I noticed that it shows a mount error:6 when there is no card inserted. Maybe the next batch of new boards, that have an SD reader, should use the card detect signal. It would be nice to see a message that prompts you to insert a card if one is not present.

    I noticed that the Code Size is 21,232 bytes (22,120 total), does this mean I have about 10,000 bytes left to work with? Maybe an editor of some sort will fit?

    I just noticed something interesting, I switched the Memory Model to LMM, and I get an error: "Your program is too big for the memory model selected in the project." So it runs fine in CMM, but it does not run in LMM. So, for the filetest.c program we can only run it in CMM or XMM.

    Ray
  • Dave HeinDave Hein Posts: 6,347
    edited 2012-09-11 12:24
    The filetest program fits in LMM mode if you use the attached printf.c file instead of printf in the library. I also had to disable the mkdir and rmdir commands for LMM.
    c
    c
  • jazzedjazzed Posts: 11,803
    edited 2012-09-11 12:48
    Rsadeika wrote: »
    I made an addition to the function below, for a DNA board, I still get mount error:6. When I change the #define to a C3 board, that seems to work fine. I am not sure what else has to be done to support a DNA board.

    A more flexible option might be to use the filetest/filetest.side project in the demos package: https://propgcc.googlecode.com/files/propellergcc_v0_3_5_demos.zip

    Most propeller-gcc demos now have .side project files.

    It is unclear why we need two separate filetest demos such as demos/c3files/ and demos/filetest/ except that c3files was first and nobody wants to step on any toes.

    Project demos/filetest/filetest.side uses parameters defined in the board type configuration file and is smaller than the demos/c3files/src/filetest.side . There is no board specific code in the demos/filetest/filetest.side . There is no mount function; that is done automatically for the board type.

    For some reason the demo doesn't include the demos/c3files/src/printf.c file, so you need to "Add File Copy". The demos/filetest/filetest.side demo with printf.c compiled in CMM with all features is 17256 bytes of code (about 400 bytes smaller than demos/c3files/src/filetest.side in CMM) and compiles/runs built with LMM with code 30504 bytes with all original features.
    > help
    Commands are help, cat, rm, ls, ll, echo, cd, pwd, mkdir and rmdir
    
    > ls
    mydir         abe.txt       autorun.pex
    
    > cat abe.txt
    Everthing you read on the internet is true. - Abraham Lincoln
    
    > cd mydir
    
    > ls
    stuff
    
    > cat stuff
    a file of stuff
    
    > ls
    stuff
    
    > 
    
  • Dave HeinDave Hein Posts: 6,347
    edited 2012-09-11 14:01
    We should delete the c3files directory under propgcc/demos and replace it with a filetest directory. The mount code that is in c3files/src/filetest.c could be moved to a file called mount.c so that it is available to people who want to do an explicit call to dfs_mount instead of relying on the loader to configure it. I was waiting until the CMM branch is merged into the default branch, but I can go ahead and make the changes before then.
  • jazzedjazzed Posts: 11,803
    edited 2012-09-11 14:21
    Dave Hein wrote: »
    We should delete the c3files directory under propgcc/demos and replace it with a filetest directory. The mount code that is in c3files/src/filetest.c could be moved to a file called mount.c so that it is available to people who want to do an explicit call to dfs_mount instead of relying on the loader to configure it. I was waiting until the CMM branch is merged into the default branch, but I can go ahead and make the changes before then.

    Thanks Dave.

    Can you make changes in compressedcode so when we merge-back, it will be automatically put in the default branch?
  • Dave HeinDave Hein Posts: 6,347
    edited 2012-09-11 14:29
    OK, I'll see if I can figure out how to get the compressedcode branch.
  • jazzedjazzed Posts: 11,803
    edited 2012-09-11 22:31
    Dave Hein wrote: »
    OK, I'll see if I can figure out how to get the compressedcode branch.

    # pull changes
    $ hg pull

    # switch to branch
    $ hg update compressedcode

    # show current branch
    $ hg branch
    compressedcode

    # switch back to default if necessary
    $ hg update default
  • Dave HeinDave Hein Posts: 6,347
    edited 2012-09-12 10:13
    I moved the files in demos/c3files to demos/filetest, and removed the duplicate Makefile and filetest.c that were originally in demos/filetest. I modified filetest.c to use a CALL_MOUNT flag to determine if the mount routine would be included and called. I also added some comments in filetest.c to describe when mount should be used, and when it is not necessary. I also added a cmm directory.
  • David BetzDavid Betz Posts: 14,516
    edited 2012-09-12 10:15
    Dave Hein wrote: »
    I moved the files in demos/c3files to demos/filetest, and removed the duplicate Makefile and filetest.c that were originally in demos/filetest. I modified filetest.c to use a CALL_MOUNT flag to determine if the mount routine would be included and called. I also added some comments in filetest.c to describe when mount should be used, and when it is not necessary. I also added a cmm directory.
    That sounds great! Thanks Dave!
  • jazzedjazzed Posts: 11,803
    edited 2012-09-12 10:17
    Dave Hein wrote: »
    I also added a cmm directory.

    Do we need different directories? We can just do something this? $ make clean; make MODEL=cmm
  • Dave HeinDave Hein Posts: 6,347
    edited 2012-09-12 10:34
    We don't need different directories, but I was just following the method we had used early on where we did use different directories for each model. It can be done either way. I also noticed that there are a couple of .side files -- one in the filetest directory and one in the filetest/src directory. The side file should be in the same directory as the source, so I should either get rid of the src directory or remove the side file that is above the src directory.

    Overall, it's probably cleaner to get rid of the all the subdirectories and use the MODEL parameter as you suggested. Do you want me to do that?
  • jazzedjazzed Posts: 11,803
    edited 2012-09-12 11:04
    Dave Hein wrote: »
    Overall, it's probably cleaner to get rid of the all the subdirectories and use the MODEL parameter as you suggested. Do you want me to do that?

    Sounds good to me. Thanks Dave.
  • Dave HeinDave Hein Posts: 6,347
    edited 2012-09-12 11:42
    I removed all the subdirectories under demos/filetest and put the Makefile and source files all together in the filetest directory along with the filetest.side and README.txt files. That does look a lot neater that way. I updated the README.txt file to describe how to build the different models using make.
Sign In or Register to comment.