Embedded Insight Archives

/*------------------------------------------------------------------*\

Embedded Insight

The Monthly Newsletter for Embedded Systems Professionals

Published by Base2 Software Design, Inc.
    http://www.base2software.com
    mailto:info@base2software.com


March, 2002


Contents

* Embedded Systems Conference San Francisco
* New Base2 Website
* Infineon C166 16-bit Microcontroller Family
* Programmer's Corner - Declaring Variables

\*------------------------------------------------------------------*/


EMBEDDED SYSTEMS CONFERENCE SAN FRANCISCO

The Embedded Systems Conference San Francisco is almost upon us! It is being held at the Moscone Center on March 12-16. The exhibits are open on March 13-16. You can still get free passes to the exhibit halls at http://www.esconline.com/sf/freepass.htm. There is an attendee reception on March 15 at the Sony Metreon from 7pm to 10:30pm. Hope to see you there!

 

NEW BASE2 WEBSITE

We are proud to announce the launch of our updated website! In it you'll find more information about our services and some of the projects we've worked on. Take a look at our resources page at http://www.base2software.com/techinfo.htm. You'll find links to some embedded systems websites and more! Check back often since we'll be incorporating your feedback into this page to make it as useful as possible for everyone.

 

INFINEON C166 16-BIT MICROCONTROLLER FAMILY

The C166 Family is a 16-bit microcontroller family from Infineon Technologies. Formerly Siemens Semiconductors, Infineon's 16-bit micros are also resold by ST Microelectronics as their ST10 Family. These processors have some very nice features including:

* clock speeds up to 40 MHz
* 16 16-bit general purpose registers
* 8 external interrupts
* instructions with single-cycle execution times
* internal ROM to 256 KB
* internal RAM to 11 KB
* internal Flash to 128 KB
* addressing space up to 16 MB
* PWM outputs
* analog-to-digital converters
* power down modes (Idle and Power Down)
* RTOS support
* 16-bit timers
* USART, SCC, I2C, CAN, and other serial interfaces

Some models provide an external memory interface of 24 bits allowing a 16 MB addressing range. This is implemented using an 8-bit code segment register and an addressing scheme similar to the Intel X86. The interrupt controller is extremely flexible. Any interrupt source can be given any of 16 interrupt priority levels. Each level also has 4 groups which provides arbitration for interrupts at the same priority level.

The external bus interface is also very flexible. The processor has 4 chip selects which may be assigned address ranges into the C166 linear memory space. This provides memory-mapped I/O without external logic. There are also provisions to select multiplexed and non-multiplexed bus modes for each address range. Be careful when designing hardware to these external bus cycles. The old Siemens documentation isn't crystal clear on all setup and hold times. Check out their latest errata on their website.

The C166 family is a good choice for applications where power consumption is not an issue. Most of the members of this family use a 5-volt supply; not a good match for hand-held portable electronics, but fine for use in control applications such as automotive electronics, medical devices, and industrial control. For more information on this family of processors, go to their website at http://www.infineon.com/cgi/ecrm.dll/ecrm/scripts/prod_cat.jsp?oid=-8137.

 

PROGRAMMER'S CORNER - DECLARING VARIABLES

In this article, we'll explore several common (and uncommon) thoughts on ANSI C variable declarations. Understanding how a compiler allocates variables and how programming can alter that allocation can help you maximize RAM and ROM usage in your embedded design.

LOCAL VARIABLES

    void func( void )
{ int x; }

When you open a scope in ANSI C, any variables defined within that scope are created on the stack. The number of variables is limited to the size of the stack, and there is potential for stack overflow especially in recursive programming situations. Access to local variables may be slower than global variables depending upon your CPU and compiler.

STATIC AND GLOBAL VARIABLES

    void func( void )
    {
        static int x;
    }

Declaring a variable static or making it global causes it to be allocated to a fixed place in RAM instead of being temporarily instantiated on the stack. This relieves the stack a bit and can reduce variable access cost. Note also that a STATIC local is global to all iterations in recursive calls.

REGISTER VARIABLES

    void func( void )
    {
        register int x;
        for ( x = 0; x < 100; x++ ) ;
    }

The REGISTER keyword requests that the compiler attempt to use a register to hold a variable. This is ideal since it requires no space in RAM and executes much faster. The compiler may however ignore this if a register is not available.

FUNCTION PARAMETERS

    void func( int x, int y, int q, int z )
    {

Most compilers will attempt to pass function arguments though registers if possible. The details of this are usually stated in compiler documentation for the CPU. What the compiler cannot pass through will then be pushed onto the stack. Oftentimes, programmers will not use parameter list variables in their functions other than for reference. Use them as much as you can! You'll get tighter code with less memory usage.

CONST QUALIFIER

    const int z = 100;

    void func( void )
    {
        register int x;
for (x = 0; x < z; x++) ;
}

CONST is great way of pushing storage out the RAM pool into the ROM pool. Often overlooked, this declaration qualifier tells the compiler to point all references directly into the ROM (.text) segment of memory. Note that this is just a hint to the compiler and the variable may be placed in RAM anyway.

#PRAGMA DIRECTIVE

    // For TI TMS320 Series
    #pragma DATA_SECTION( buf, "section_name" )
    char buf[100];

Most compilers provide #pragmas which instruct the compiler to do processor specific things. This is one method which may be used to place variables in very specific locations or memory segments without having to delve into assembly. This is especially useful for mapping variables to internal RAM, I/O ports, or Flash at special memory locations.

FINAL THOUGHTS

* Try to keep function argument lists small. If many parameters are needed, consider sending down a pointer to a structure.

* Allocate only what you need. Instead of using an int for a flag, consider using a char or a bit field.

* If functions do not overlap, consider recycling scratch variables by making them global. e.g. glb_tmp_x, glb_tmp_y, glb_tmp_z.

* Try to identify all CONST variables and declare them as such or use #defines.

* Condense strings of similar data and recycle. e.g.:
{
    printf( "error %d", x );
    printf( "error %d", y );
}

{
    const char strErr[] = "error %d"; printf( strErr, x );
    printf( strErr, y );
}

 

======================================================================

Base2 Software Design, Inc.
39510 Paseo Padre Parkway, Suite 270
Fremont, CA 94538-4741

Phone: 510/745-7773                    mailto:info@base2software.com
FAX: 800/883-4495 http://www.base2software.com

======================================================================

If you know anyone who would like to receive this informative newsletter, please forward this to them. They can sign up by sending an e-mail to mailto:info@base2software.com?Subject=Subscribe.

======================================================================

If this newsletter was sent to you in error or if you'd like to unsubscribe to our newsletter, simply reply to mailto:info@base2software.com?Subject=Unsubscribe.

======================================================================

Copyright 2002, Base2 Software Design, Inc. You may use the contents of Embedded Insight in whole or in part if you include this complete copyright notice and the following links: http://www.base2software.com. mailto:info@base2software.com.





© 2002-2009, base2 software design, inc.