Shop OBEX P1 Docs P2 Docs Learn Events
need some advice on how to make the code smaller — Parallax Forums

need some advice on how to make the code smaller

AnubispodAnubispod Posts: 42
edited 2013-03-31 16:59 in Propeller 1
Hi ,
i need some advice on how to get my code smaller but not slower.

My settings are LMM with -Os size and my stabilizer runs at round 450 loops per sec and thats what i need to keep.
i use some PASM what starts in a new cog and some c loops what run also on other cogs.

Is there a way to mix LMM and CMM like not time important cogs as CMM and Important ones as LMM
or are there any other way to get more space.

extra hardware is out of the question since cmm brings my stbilizer loop down to 70 lps and thats not good enoughf for the pal sized Quad im building.

Here is my code what i have till now , im close to finish but need some more space.

If its not possible then i would go with 2 props on the quad, and share workload and firmware size.

Best regards
Oliver.R

Comments

  • ersmithersmith Posts: 6,054
    edited 2013-03-30 08:07
    Try using CMM with -O2 instead of -Os. -O2 says to optimize for speed, and will allow CMM loops to go into fcache.
  • AnubispodAnubispod Posts: 42
    edited 2013-03-30 08:19
    Sorry that i tried before and i only get 47 lps from my stabilizer instead of 500 lps

    Best regards Oliver. R
  • jazzedjazzed Posts: 11,803
    edited 2013-03-30 08:50
    I can make it fit with #undef DEBUG if that helps.
  • AnubispodAnubispod Posts: 42
    edited 2013-03-30 09:50
    jazzed wrote: »
    I can make it fit with #undef DEBUG if that helps.

    I got a few bytes back, does it matter if i decleare a 32 bit ot 8 in size or do they all get anay way stored in 32 bit space ??
  • jazzedjazzed Posts: 11,803
    edited 2013-03-30 10:30
    Anubispod wrote: »
    I got a few bytes back, does it matter if i decleare a 32 bit ot 8 in size or do they all get anay way stored in 32 bit space ??

    I doubt it would make enough of a difference. The FullDuplex driver and the debug calls eats up almost 5000 bytes without modifications. I was able to save 1400 bytes by reorganizing that code a bit. A simple string / char debug function which doesn't use a cog would be pretty simple. I thing we have one laying around.
  • David BetzDavid Betz Posts: 14,516
    edited 2013-03-30 10:37
    jazzed wrote: »
    I doubt it would make enough of a difference. The FullDuplex driver and the debug calls eats up almost 5000 bytes without modifications. I was able to save 1400 bytes by reorganizing that code a bit. A simple string / char debug function which doesn't use a cog would be pretty simple. I thing we have one laying around.
    Maybe this is an opportunity to use the EEPROM COG loader? If you have lots of drivers that are hogging hub memory even after they've been loaded into a COG then that might help. If you don't use threads then even the LMM kernel COG image space could be recovered. This would require some work on our part but maybe not all that much.
  • jazzedjazzed Posts: 11,803
    edited 2013-03-30 10:47
    David Betz wrote: »
    Maybe this is an opportunity to use the EEPROM COG loader? If you have lots of drivers that are hogging hub memory even after they've been loaded into a COG then that might help. If you don't use threads then even the LMM kernel COG image space could be recovered. This would require some work on our part but maybe not all that much.

    I looked at that. The program uses cogstart [ i.e. _start_cog_thread ], and there are only two PASM sections.
  • David BetzDavid Betz Posts: 14,516
    edited 2013-03-30 11:00
    jazzed wrote: »
    I looked at that. The program uses cogstart [ i.e. _start_cog_thread ], and there are only two PASM sections.
    Well, there is a version of cogstart that can load COGs from EEPROM. I guess with only two PASM sections the most space you'd recover is 2K*2=4K bytes but you could get an additional 2K from putting the LMM kernel in EEPROM. Of course, you need a 2K buffer to load COGs from EEPROM. That buffer can be reused after you're done loading the COGs but it might be difficult to use that 2K chunk of memory if your application needs larger buffers than that.
  • jazzedjazzed Posts: 11,803
    edited 2013-03-30 11:04
    David Betz wrote: »
    .... but you could get an additional 2K from putting the LMM kernel in EEPROM.

    That's a fair idea. More work of course and at least a 64KB eeprom is necessary. Maybe you could compress the whole image ... Steve runs ducking for cover.
  • David BetzDavid Betz Posts: 14,516
    edited 2013-03-30 11:46
    Anubispod wrote: »
    Hi ,
    i need some advice on how to get my code smaller but not slower.

    My settings are LMM with -Os size and my stabilizer runs at round 450 loops per sec and thats what i need to keep.
    i use some PASM what starts in a new cog and some c loops what run also on other cogs.

    Is there a way to mix LMM and CMM like not time important cogs as CMM and Important ones as LMM
    or are there any other way to get more space.

    extra hardware is out of the question since cmm brings my stbilizer loop down to 70 lps and thats not good enoughf for the pal sized Quad im building.

    Here is my code what i have till now , im close to finish but need some more space.

    If its not possible then i would go with 2 props on the quad, and share workload and firmware size.

    Best regards
    Oliver.R
    Hi Oliver,

    Could you post your code as a .zip file? I don't have a program for the Mac that understands .rar files.

    Thanks!
    David
  • AnubispodAnubispod Posts: 42
    edited 2013-03-30 12:13
    the idea with the cog loader from epprom sound prommisiing
    i have 64k epprom on my protoboard so i would just need a smale of how its done nad how i get the code in the epprom upper partbevore progarming the main prog
    i hope i understand that right ??

    4k sound good to me to get them back

    I already made some changes and got back down, i have thrown all out what is not needed like cog stop calls and functions.

    Im not shure how much more i will need but
    it looks promissing so far

    RC PPM reciver needs to be implemented 1 cog hope PASM
    And some ADC for the batt voltage monitor in the Failsafe loop

    Best regards
    Oliver R.
  • AnubispodAnubispod Posts: 42
    edited 2013-03-30 12:24
    BTW i try to figure out how to setup an array what has alread values applied to it so i save my self this loop
      int  I = 0;   {
         int32_t _idx__0000;
         for(_idx__0000 = 1; _idx__0000 <= 5; (_idx__0000 = (_idx__0000 + 1))) {
           thisobj.Rxaddress[I] = 231;
           thisobj.Txaddress[(I++)] = 231;
         }
       }
    
    

    I tied where i have them declared uint8_t Txaddress[5] = {231};

    but with no luck
  • David BetzDavid Betz Posts: 14,516
    edited 2013-03-30 12:31
    Anubispod wrote: »
    the idea with the cog loader from epprom sound prommisiing
    i have 64k epprom on my protoboard so i would just need a smale of how its done nad how i get the code in the epprom upper partbevore progarming the main prog
    i hope i understand that right ??

    4k sound good to me to get them back

    I already made some changes and got back down, i have thrown all out what is not needed like cog stop calls and functions.

    Im not shure how much more i will need but
    it looks promissing so far

    RC PPM reciver needs to be implemented 1 cog hope PASM
    And some ADC for the batt voltage monitor in the Failsafe loop

    Best regards
    Oliver R.
    Thanks for the zip file.
  • David BetzDavid Betz Posts: 14,516
    edited 2013-03-30 12:32
    Anubispod wrote: »
    BTW i try to figure out how to setup an array what has alread values applied to it so i save my self this loop
      int  I = 0;   {
         int32_t _idx__0000;
         for(_idx__0000 = 1; _idx__0000 <= 5; (_idx__0000 = (_idx__0000 + 1))) {
           thisobj.Rxaddress[I] = 231;
           thisobj.Txaddress[(I++)] = 231;
         }
       }
    
    

    I tied where i have them declared uint8_t Txaddress[5] = {231};

    but with no luck
    That will only initialize the first element of the array. You'll need an initializer inside of the braces for each array element.
  • AnubispodAnubispod Posts: 42
    edited 2013-03-30 12:43
    I guess you mean like this :
    uint8_t Txaddress[5] = {231,231,231,231,231};

    that gives me a error on compile
    Nordic_Demo.h:36:27: error: expected ':', ',', ';', '}' or '__attribute__' before '=' token
  • David BetzDavid Betz Posts: 14,516
    edited 2013-03-30 13:01
    Anubispod wrote: »
    I guess you mean like this :
    uint8_t Txaddress[5] = {231,231,231,231,231};

    that gives me a error on compile
    Nordic_Demo.h:36:27: error: expected ':', ',', ';', '}' or '__attribute__' before '=' token
    That's odd. It should work.
  • David BetzDavid Betz Posts: 14,516
    edited 2013-03-30 13:10
    Anubispod wrote: »
    I guess you mean like this :
    uint8_t Txaddress[5] = {231,231,231,231,231};

    that gives me a error on compile
    Nordic_Demo.h:36:27: error: expected ':', ',', ';', '}' or '__attribute__' before '=' token
    Something else must be wrong. I just compiled this and got no errors. Here's the code I tried:
    #include <stdio.h>
    #include <stdint.h>
    
    uint8_t Txaddress[5] = {231,231,231,231,231};
    
    int main(void)
    {
    int i;
    for (i = 0; i < 5; ++i)
      printf("%d\n", Txaddress[i]);
    return 0;
    }
    
  • David BetzDavid Betz Posts: 14,516
    edited 2013-03-30 13:12
    Okay, I see the problem. You can't initialize the elements of an array that is part of a structure in the typedef for the structure. You have to do the initialization when you create an instance of the structure.
  • jazzedjazzed Posts: 11,803
    edited 2013-03-31 11:17
    David Betz wrote: »
    Okay, I see the problem. You can't initialize the elements of an array that is part of a structure in the typedef for the structure. You have to do the initialization when you create an instance of the structure.

    Create an initialized array separately and add a reference to it in the struct.
  • David BetzDavid Betz Posts: 14,516
    edited 2013-03-31 16:59
    jazzed wrote: »
    Create an initialized array separately and add a reference to it in the struct.
    You could do that but it is also possible to create an initialized structure. You wouldn't do it in the header file that contains the typedef though. You'd do it at the location where you define a variable using that type.
Sign In or Register to comment.