This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Runtime / Simulation Specific Code

Hello everyone,

So, I am working with an 8051W core processor (with OTP, once again, that's a whole other discussion) and I'm pretty maxed out on code space and looking to trim it down a bit. I need to check the functionality of some of my interrupts so I've had to create code that looks like this:

void main (void)
{
        DiagMode = 0;

        /* Loop for standard/hardware diagnostics mode */
        if ((DiagMode == 0) || (DiagMode == 2))
        {
                while (1)
                {
                        // Insert code here
                }; /* Loop forever */
        }
        /* Loop for simulation/software diagnostic mode */
        else if (DiagMode == 1)
        {
                while(1)
                {
                        decimator2_ISR();
                        // Insert code here
                };      /* Loop forever */
        }

}

So if I wanted to use the code in simulation mode, I set DiagMode = 1. When I go to burn the chip, I set it equal to 0 (or 2 if I'm doing some hardware diagnostics, I have various case statements throughout the code that run only if DiagMode = 1 or 2).

Currently, if I want to cut down the code I have, I can comment out any unnecessary code portions (anything with DiagMode = 1, etc). I was wondering if there was a way to set my code to build the code differently if it is being used in simulation mode and when I compile it to hex (or set DiagMode to 0), the portions in code with DiagMode set to 1 are not built into the hex code, saving space.

I apologize if what I'm asking for is confusing. Realistically, it probably isn't possible but I figure if anyone would know how to do something along these lines (or has a better alternative), this would be the place to go.

Let me know when you get the chance. Thanks!

Parents
  • I actually wondered if that was the case and should have mentioned I had it on optimization 8 (which is very high).

    Unfortunately, it's a custom ASIC with only 8k of code space and we're at 7.4k already WITH the optimizer already set to 8. Ideally, I'd like to drop it down but we don't have the space for it (and we haven't even added the I2C or SPI code to it yet).

    Thanks for your help, that makes a lot more sense. In future projects when we have more available code space, I'll be sure to set the #if statements correctly. At least now I understand why it's acting in the way it is.

    Oh, and please use the appropriate tags when posting code! Heh . . .

Reply
  • I actually wondered if that was the case and should have mentioned I had it on optimization 8 (which is very high).

    Unfortunately, it's a custom ASIC with only 8k of code space and we're at 7.4k already WITH the optimizer already set to 8. Ideally, I'd like to drop it down but we don't have the space for it (and we haven't even added the I2C or SPI code to it yet).

    Thanks for your help, that makes a lot more sense. In future projects when we have more available code space, I'll be sure to set the #if statements correctly. At least now I understand why it's acting in the way it is.

    Oh, and please use the appropriate tags when posting code! Heh . . .

Children
  • Unfortunately, it's a custom ASIC with only 8k of code space and we're at 7.4k already WITH the optimizer already set to 8. Ideally, I'd like to drop it down but we don't have the space for it (and we haven't even added the I2C or SPI code to it yet).
    OH, what fun fitting I²C and SPI (and the code that uses it) into 600 bytes. I hope your costom chip has it in hardware,
    NOW, beware - if you need delay routine(a) you need to do it) in assembly, that high optimization will simply drop routines that "do nothing'

    Erik

  • Yeah, to be honest with you, I might have to look at compiling separate code for digital output code because I doubt it's going to fit (then maybe we can reduce the optimization).

    Thanks for the heads up regarding delay routines, that will probably save me a lot of headaches.

    I wish OUR company had the NASA attitude . . . "Well, it may be expensive, but we need it." Oh well, not much I can do about it except make the most of the situation. Brings up new challenges and I develop new skills, I guess.

  • some things I have a problem with with, when doing huge projects, is inactive code showing up as active on global scans and, sometimes, getting lost studying inactive code when the problem is elsewhere.

    in such cases I, sometimes do the following (which seems silly in an example this small)

    #ifdef TEST
    #define TESTCODE
    #endif
    
    then the following
    var47 = ADCinput;
    #ifdef TEST
    TESTCODE if var47 > 222
    TESTCODE {
    TESTCODE    var47 = 222;
    TESTCODE }
    #endif
    vr47 =/ 10;
    

    Erik