Shop OBEX P1 Docs P2 Docs Learn Events
mstimer always zero with XMMC External Flash Code Main Ram Data — Parallax Forums

mstimer always zero with XMMC External Flash Code Main Ram Data

BlackSoldierBBlackSoldierB Posts: 45
edited 2014-04-23 04:45 in Propeller 1
I am trying to use the timer in combination with the XMMC memory. I use this memory, because my libaries require a lot of memory.

My timer outputs always zero. Is the timer supposed to work with the XMMC memory or am i missing something?
This is my test code:
#include "simpletools.h" 
#include "mstimer.h"
 

int main()
{
     low(26);
     low(27);

     mstime_start();
 
     print("Starting\n");

     high(26);
 
     //For loop to increase the time.

     for(int i = 0; i < 1000; i++)
     {
          print("%d", i);
     }
  
     print("\n");
 

     int time = mstime_get();
     mstime_stop();
     print("Total time= %d", time);
 
     high(27);
 
     return 0;
}

EDIT:
I thought i had read somewhere that cogstart cannot be used in the XMMC mode.
I looked in the "mstimer.c" file and saw that they where using the CNT variable.

This is my code with CNT, is this correct?
#include "simpletools.h"  

int main()
{
   low(26);
   low(27);
  
   print("Starting\n");
  
   high(26);
 

   unsigned int ticks = CNT;
   print("Tick %u\n", ticks);
  
   for(int i = 0; i < 1000; i++)
   {
       print("%d", i);
   }
  
   print("\n");
   
   unsigned int ticks2 = CNT;
   print("Total time= %u, ticks: %u", ticks2 - ticks, ticks2);
   
   high(27);
  
   return 0;
}
«1

Comments

  • jazzedjazzed Posts: 11,803
    edited 2014-03-17 08:23
    Hi.

    Function mstime_start() uses cogstart(). As you mentioned, XMMC in the Propeller C release does not allow using cogstart().

    There are some alternatives of course. Maybe you application doesn't need a separate COG. What are you trying to time?
  • BlackSoldierBBlackSoldierB Posts: 45
    edited 2014-03-17 08:51
    I am just trying to time the duration of my program.

    This also means that i can't use the abdrive libary right?
    I am planning to use the drive_goto function but that also uses the cogstart function. Is for this problem a workaround?
  • jazzedjazzed Posts: 11,803
    edited 2014-03-17 09:31
    We have an alpha version of Propeller-GCC that will run cogstart in XMMC mode. We haven't started a test program for qualifying it yet, but there are some people using it. What OS do you use?

    The board types have changed significantly. Which board type are you using? What is your XMM code storage device?
  • trancefreaktrancefreak Posts: 186
    edited 2014-03-17 11:22
    I am just trying to time the duration of my program.

    This also means that i can't use the abdrive libary right?
    I am planning to use the drive_goto function but that also uses the cogstart function. Is for this problem a workaround?
    I can confirm that the development branch supports xmmc with cogstart which works really well.
    If you want to try it out, in this thread is a link to windows binaries:
    http://forums.parallax.com/showthread.php/154283-problem-when-using-propeller-load-with-xmmc-or-xmm-single-(propgcc-default-branch)/page2

    You have to go to message #34. With this version you can use libraries which use cogstart. Maybe you have to change the stack size in the source code.
  • BlackSoldierBBlackSoldierB Posts: 45
    edited 2014-03-18 01:47
    jazzed wrote: »
    We have an alpha version of Propeller-GCC that will run cogstart in XMMC mode. We haven't started a test program for qualifying it yet, but there are some people using it. What OS do you use?

    The board types have changed significantly. Which board type are you using? What is your XMM code storage device?

    I am using windows and i have a ActivityBot with a SD Card.
    How do i know if the data and/or stack is stored on the SD Card or in the EEPROM?
    I can confirm that the development branch supports xmmc with cogstart which works really well.
    If you want to try it out, in this thread is a link to windows binaries:
    http://forums.parallax.com/showthread.php/154283-problem-when-using-propeller-load-with-xmmc-or-xmm-single-(propgcc-default-branch)/page2

    You have to go to message #34. With this version you can use libraries which use cogstart. Maybe you have to change the stack size in the source code.

    Awesome! :lol: I will download it and try to get it working.

    EDIT:
    Is it true that the boardtype "ActivityBot" stores the data/stack in the EEPROM and the boardtype "ActivtyBot -SDXMMC" on the SD Card?
    I am currently using the boardtype "ActivityBot".

    EDIT2:
    Can i just replace compiler location in the Simple IDE or will that introduce complications?

    One final question, when do i have to use "Load EEPROM & Run", "Load RAM & Run" and "Run with terminal"?
  • jazzedjazzed Posts: 11,803
    edited 2014-03-18 10:02
    I am using windows and i have a ActivityBot with a SD Card.
    How do i know if the data and/or stack is stored on the SD Card or in the EEPROM?
    There is no support for SDXMMC in the alpha development code. It has not been ported yet and it is too slow to be worth-while.

    The only thing stored in the external device is code and initial values of data. It is read-only. Everything else is in HUB RAM.

    Is it true that the boardtype "ActivityBot" stores the data/stack in the EEPROM and the boardtype "ActivtyBot -SDXMMC" on the SD Card?
    I am currently using the boardtype "ActivityBot".

    No. See my response above.
    Can i just replace compiler location in the Simple IDE or will that introduce complications?

    Yes. That is the main reason for having that in the Properties window.
    One final question, when do i have to use "Load EEPROM & Run", "Load RAM & Run" and "Run with terminal"?

    "Load RAM & Run" and "Run with terminal" will not write startup code to EEPROM. So, your program will not boot if you reset the board. Using "Load EEPROM & Run" will make it so that your program will boot reset or power-cycle.
  • BlackSoldierBBlackSoldierB Posts: 45
    edited 2014-03-19 08:33
    Thanks, that makes things more clear.

    Do i need to recompile the libaries with the "new" compiler in order to make the "cogstart" work? Or is recompiling my own project sufficient?

    EDIT:
    The compiler settings (from the properties screen) change back to default when i restart the SimpleIDE. Is this a bug or a feature?

    I recompiled all the libaries that are required by the first code i posted, but the timer still outputs 0.
  • jazzedjazzed Posts: 11,803
    edited 2014-03-19 09:34
    Thanks, that makes things more clear.

    Do i need to recompile the libaries with the "new" compiler in order to make the "cogstart" work? Or is recompiling my own project sufficient?

    EDIT:
    The compiler settings (from the properties screen) change back to default when i restart the SimpleIDE. Is this a bug or a feature?

    I recompiled all the libaries that are required by the first code i posted, but the timer still outputs 0.
    Yes, it is necessary to recompile the libraries you plan to use with xmmc.

    The compiler settings reverting is a bug - we haven't had a good reason to test that in a long time. As long as you have it set after restarting the IDE, your compile should work.

    Did you compile libraries with the compiler set properly?
  • BlackSoldierBBlackSoldierB Posts: 45
    edited 2014-03-20 01:53
    I am quitte sure i selected the right compiler. Can you see in the logs what compiler version is used?

    And is there an easy way to compile all the libaries with different settings?

    Edit:
    The log of the SimpleIDE produces "propeller-elf-gcc.exe -v GCC 4.6.1 (propellergcc_v1_0_0_2162)" while the new compiler produces this with the -v option "gcc version 4.6.1 (propellergcc-alpha_v1_9_0_2365)".
    So i quess it is compiling with the default compiler.

    This is my settings screen:
    SimpleIDE Settings.PNG


    What am i doing wrong?
    516 x 349 - 25K
  • trancefreaktrancefreak Posts: 186
    edited 2014-03-20 04:23
    I had the same issues. Rename your propgcc folder within the SimpleIDE directory (the on in ProgramFiles\SimpleIDE) and copy the new "default branch" propgcc directory into the SimpleIDE directory.
    Leave the path settings untouched (default values).
  • BlackSoldierBBlackSoldierB Posts: 45
    edited 2014-03-20 04:26
    I had the same issues. Rename your propgcc folder within the SimpleIDE directory (the on in ProgramFiles\SimpleIDE) and copy the new "default branch" propgcc directory into the SimpleIDE directory.
    Leave the path settings untouched (default values).

    So you did more or less an overwrite?

    EDIT:
    The compilation worked, but the timer and multicore led exmples are still not working. Any tips or "working" examples?
  • jazzedjazzed Posts: 11,803
    edited 2014-03-20 18:53
    So you did more or less an overwrite?

    EDIT:
    The compilation worked, but the timer and multicore led exmples are still not working. Any tips or "working" examples?
    I was thinking about trying an example yesterday, but I can barely breathe with the things I have going on right now. I'll look at it some tonight.

    @trancefreak is right about replacing the propgcc folder. I totally forgot about the GCC toolchain relying on the PATH environment variable. Sorry about that.
  • BlackSoldierBBlackSoldierB Posts: 45
    edited 2014-03-21 08:05
    Thanks, that is the explanation behind the compiler problem.
  • jazzedjazzed Posts: 11,803
    edited 2014-03-21 20:01
    Ok, this is an answer for now until we get some confirmation from Eric.

    Anytime you use cogstart in XMMC mode, you need to pass a big stack so that the function will have some space for running.

    In addition to that, there is a bug in Andy's ms_timer.c code that causes "52 second counter miss delay" because XMMC can be slower than CMM/LMM.

    Below is a corrected ms_timer.c ... you will need to build the library for CMM, LMM, and XMMC. Please don't use XMM-SINGLE and XMM-SPLIT.

    After building my mstimer library I was able to run the code from the first post no problems with the default branch.

    --Steve
    /**
    * @file mstimer.c
    *
    * @author Andy Lindsay
    *
    * @copyright
    * Copyright (C) Parallax, Inc. 2013. All Rights MIT Licensed.
    *
    * Bug fix by Steve after consulting with David.
    * 
    * @brief Code for tracking milliseconds elapsed in another cog.  This is part of
    * a tutorial on adding a Simple Library to the project.
    */
    
    
    #include "simpletools.h"                      // Include simpletools
    #include "mstimer.h"
    
    
    #ifdef __PROPELLER_USE_XMM__
    #define STACK_LONGS (1024+128+32+sizeof(_thread_state_t))/4
    #else
    #define STACK_LONGS (16+sizeof(_thread_state_t))/4
    #endif
    
    static volatile int t, cog;                   // Global var for cogs to share
    static int stack[STACK_LONGS+25];  // Stack vars for other cog
    
    void ms_timer(void *par);                 
    
    int mstime_start()
    {
      mstime_stop();
      cog = 1 + cogstart(&ms_timer, NULL, stack, sizeof(stack));
    }
    
    void mstime_stop()
    {
      if(cog)
      {
        cogstop(cog -1);
        cog = 0;
      }    
    }
    
    int mstime_get()
    {
      return t;
    }
    
    void mstime_reset()
    {
      t = 0;
    }
    
    void mstime_set(int newTime)
    {
      t = newTime;
    }
    
    // Function runs in another cog
    void ms_timer(void *par)                      
    {
      while(1) {
        waitcnt(CLKFREQ/1000+CNT);                              
        t++;                                     
      }                            
    }
    
    /**
     * TERMS OF USE: MIT License
     *
     * Permission is hereby granted, free of charge, to any person obtaining a
     * copy of this software and associated documentation files (the "Software"),
     * to deal in the Software without restriction, including without limitation
     * the rights to use, copy, modify, merge, publish, distribute, sublicense,
     * and/or sell copies of the Software, and to permit persons to whom the
     * Software is furnished to do so, subject to the following conditions:
     *
     * The above copyright notice and this permission notice shall be included in
     * all copies or substantial portions of the Software.
     *
     * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
     * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
     * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
     * DEALINGS IN THE SOFTWARE.
     */
    
  • ersmithersmith Posts: 6,054
    edited 2014-03-22 16:53
    jazzed wrote: »
    Anytime you use cogstart in XMMC mode, you need to pass a big stack so that the function will have some space for running.
    Right, the cache space is taken from the stack passed to cogstart, so you need to add another 1K + 128 for cache lines. I wonder if there's some way we can hide that in the size of the thread structure in XMMC mode? Probably not, because the main thread also gets a thread structure and we don't want that extra size allocated there, but perhaps we can think of some clever work-around.
  • David BetzDavid Betz Posts: 14,516
    edited 2014-03-22 19:23
    ersmith wrote: »
    Right, the cache space is taken from the stack passed to cogstart, so you need to add another 1K + 128 for cache lines. I wonder if there's some way we can hide that in the size of the thread structure in XMMC mode? Probably not, because the main thread also gets a thread structure and we don't want that extra size allocated there, but perhaps we can think of some clever work-around.
    I've pushed an update to the default branch code that defines the constant EXTRA_STACK_LONGS that you can use to make your stack big enough no matter which memory model you're using. It includes the size of the cache in XMM mode as well as the size of the thread structure in all modes as well as the extra space needed to guarantee that the cache is aligned on a 16 byte boundary as required by the external memory driver interface. This means you can just define your stack as follows:
    long my_stack[EXTRA_STACK_LONGS + <what-i-need>];
    
    Where <what-i-need> is replaced by the number of longs actually required by the function you're passing to cogstart. This should simplify things and make it possible to write code that works in all memory models. However, you still have to be aware that the timing will be different with each memory model so code that is dependent on exact timing will have to be adjusted when going from one model to another.
  • BlackSoldierBBlackSoldierB Posts: 45
    edited 2014-03-24 02:29
    Thanks guys, the timer is working now.
    I've pushed an update to the default branch code that defines the constant EXTRA_STACK_LONGS that you can use to make your stack big enough no matter which memory model you're using.

    What do you mean with the default branch? Is that the compiler or library branch?

    To get the abdrive library i need to also add the extra stack size.
    Is this correct?
    static unsigned int stack[EXTRA_STACK_LONGS + (160 + (125 * 4)) / 4];
    

    I do get 'EXTRA_STACK_LONGS' undeclared here (not in a function). This is probably because i don't the latest branch.
  • David BetzDavid Betz Posts: 14,516
    edited 2014-03-24 03:39
    Thanks guys, the timer is working now.



    What do you mean with the default branch? Is that the compiler or library branch?
    I do get 'EXTRA_STACK_LONGS' undeclared here (not in a function). This is probably because i don't the latest branch.[/QUOTE]
    The default branch of the Google Code propgcc project. There isn't a separate branch for the propgcc library. Maybe you're talking about the Simple Libraries? They are not part of propgcc at the present. When I say "library", I'm talking about the propgcc library not Simple Libraries.
    To get the abdrive library i need to also add the extra stack size.
    Is this correct?
    static unsigned int stack[EXTRA_STACK_LONGS + (160 + (125 * 4)) / 4];
    
    I'm not sure where those magic numbers come from. The "125 * 4" expression looks like it's trying to convert longs to bytes but since this is an int array that isn't necessary. I also don't know where the 160 comes from. If that's an estimate of the size of the thread structure then it can be removed leaving just this:
    static unsigned int stack[EXTRA_STACK_LONGS + 125];
    
  • BlackSoldierBBlackSoldierB Posts: 45
    edited 2014-03-24 04:51
    How do i get the latest version of the propgcc? Do i need to build it myself or can i download it somewhere?

    EDIT: I am currently installing debian on a virtualbox machine.
  • David BetzDavid Betz Posts: 14,516
    edited 2014-03-24 06:40
    How do i get the latest version of the propgcc? Do i need to build it myself or can i download it somewhere?

    EDIT: I am currently installing debian on a virtualbox machine.
    The version that I use is the default branch from Google Code which I build myself on a Macintosh. I don't think anyone is posting already built versions of the default branch. Unfortunately, you will probably need to clone the Google Code repository and build it yourself. Sorry!

    https://code.google.com/p/propgcc/
  • jazzedjazzed Posts: 11,803
    edited 2014-03-24 07:57
    To be clear about PropellerGCC and libraries:

    1. PropellerGCC has a standard libraries (different from Simple Libraries). David pushes code to the "default branch" that has PropellerGCC and the standard library.

    2. SimpleIDE normally uses PropellerGCC "release_1_0 branch", and a separate Simple Library (includes ms_timer) which Parallax developed for it's educational program.

    A default branch package for windows is posted here:propellergcc-alpha-1_9_0-i686-windows


    If you must build PropellerGCC from scratch (deep end of the pool):

    Configuring a system to build PropellerGC can be painful. The prerequisites here. Updated build instructions are here.
  • BlackSoldierBBlackSoldierB Posts: 45
    edited 2014-03-24 08:37
    I got this error while building the propgcc. I was following the README.cross instructions.
    propeller-elf-gcc: Command not found
    

    EDIT: The propeller-elf.gcc is availible in the /opt/parallax/bin/ directory. Maybe a PATH variable that is not correct?
  • jazzedjazzed Posts: 11,803
    edited 2014-03-24 08:39
    I got this error while following the README.cross
    propeller-elf-gcc: Command not found
    
    Did you read the notes on prerequisites and build instructions below?

    Seems I may have forgotten a step.

    It should say:

    For default branch cross-compile to Windows
    $ make clean-all
    $ make
    $ make CROSS=win32
    $ Go eat lunch.
  • BlackSoldierBBlackSoldierB Posts: 45
    edited 2014-03-25 01:27
    Ah, i used the README.cross instead of the "Updated build instructions". I will see if it's working now.

    EDIT: Arg, not enough disk space. Resizing it now.
    EDIT2: The linux build is done, building for Windows now.
  • BlackSoldierBBlackSoldierB Posts: 45
    edited 2014-03-25 05:21
    Now i am getting the following errors when cross compiling for windows.
    /home/<user>/propgcc/gcc/libgcc/configure: line 2232: propeller-elf-cc: command not found
    
    Shouldn't this be propeller-elf-gcc?

    And
    checking for suffix of object files... configure: error: in `/home/<user>/build-win32/gcc/propeller-elf/libgcc':
    configure: error: cannot compute suffix of object files: cannot compile
    See `config.log' for more details.
    make[1]: *** [configure-target-libgcc] Error 1
    

    Do i need to do this steps?

    Linux/Mac
    1. Set a GROUP variable.
    2. su root (or use sudo for the following commands through "exit root")
    3. $ export GROUP="your group"
    4. $ rm -rf /opt/parallax
    5. $ mkdir /opt/parallax
    6. $ chown ${USER}.${GROUP} /opt/parallax
    7. $ chmod g+w /opt/parallax
    8. exit root
    For release_1_0 branch
    1. $ ./jbuild.sh 6 rm-all
    2. Go have a cup of coffee (build takes 15 minutes on I7 3.3MHz).
  • BlackSoldierBBlackSoldierB Posts: 45
    edited 2014-03-27 07:11
    I have done the above commands. It doesn't seem to help.
    Any tips for this problem?
  • jazzedjazzed Posts: 11,803
    edited 2014-03-27 08:41
    Do i need to do this steps?

    Linux/Mac
    1. Set a GROUP variable.
    2. su root (or use sudo for the following commands through "exit root")
    3. $ export GROUP="your group"
    4. $ rm -rf /opt/parallax
    5. $ mkdir /opt/parallax
    6. $ chown ${USER}.${GROUP} /opt/parallax
    7. $ chmod g+w /opt/parallax
    8. exit root
    Yes. The main idea is that you end up with a folder called /opt/parallax where you have write permissions.

    I'm sorry I didn't see your post earlier. I've been away from my computer a lot over the last 5 days.
  • BlackSoldierBBlackSoldierB Posts: 45
    edited 2014-03-27 09:07
    I did set the rights with chmod -R a+wr /opt/parallax, but i am still getting the same errors.
  • jazzedjazzed Posts: 11,803
    edited 2014-03-27 09:23
    I did set the rights with chmod -R a+wr /opt/parallax, but i am still getting the same errors.

    Set your path? export PATH=/opt/parallax/bin

    It may be useful to check your repository for diffs. $ hg diff
    If you have diffs, do this $ hg revert all

    Assuming you are building the default branch
    $ make clean-all
    $ make
  • BlackSoldierBBlackSoldierB Posts: 45
    edited 2014-03-28 05:34
    jazzed wrote: »
    Set your path? export PATH=/opt/parallax/bin

    It may be useful to check your repository for diffs. $ hg diff
    If you have diffs, do this $ hg revert all

    Assuming you are building the default branch
    $ make clean-all
    $ make

    I took the following actions with root rights.
    1. I deleted the /opt/parallax and /opt/parallax-win32 folders.
    2. I deleted the build and build-win32 folder.
    3. I did the "hg diff" and "hg revert --all" commands
    4. Created /opt/parallax/
    5. chmod 777 /opt/parallax/
    6. PATH=${PATH}:/opt/parallax/bin and export PATH=/opt/parallax/bin:${PATH}
    7. make -clean
    8. make
    9. make CROSS=win32

    The linux variant was build without errors.
    For the windows variant i got:" undefined reference to `_usleep'".
    The other error seem to be solved.

    Do i have to do chmod 777 /opt/parallax-win32/ aswell? Or do i need to add /opt/parallax-win32/ to the $PATH variable?
Sign In or Register to comment.