Real Time Systems Inc. provides a wide range of industries with professional embedded controller design services. We offer:
  • systems specification and design
  • network architecture design
  • real-time software design
  • analog and digital hardware design.
We use a variety of technologies to solve our customers' problems:
  • 8-bit, 16-bit, and 32-bit microcontrollers
  • C, C++, assembly language, and various scripting languages
  • Linux and NetBSD for larger embedded systems and for desktop front-ends for smaller systems
  • Our own multitasking kernel for smaller embedded systems
  • TCP/UDP/IP communications, including custom protocols, over Ethernet, serial line, and radio
  • Custom analog and digital circuit designs.

A Flexible EEPROM Manager in C++

Many embedded controllers contain EEPROM to support field configuration. Designers favor EEPROM because it can be erased and programmed in-circuit, yet it retains its contents when power fails. Like RAM (and unlike Flash ROM), EEPROM can be both erased and programmed byte-by-byte.

We can simply store field configuration variables directly in EEPROM, but adding a bit of record structure yields some advantages:

  • corruption of EEPROM contents can be detected and perhaps repaired if we add checksums
  • program upgrades can be eased if we can locate variables by name, rather than by numerical address alone.

This article shows how to use C++ to create a simple EEPROM manager with these features:

  • supports any byte-erasable EEPROM or EEPROM-like device without modifying the manager
  • checksums detect corruption of data in EEPROM
  • named records allow program upgrades without maintaining a fixed record ordering
  • EEPROM variables are mirrored to RAM for ease of use and speed
  • RAM and EEPROM versions of the variables are synchronized automatically.

Included is a completely worked-out example of an EEPROM manager in about 300 lines of code along with some suggestions for extensions. It shows real-world use of several major C++ techniques, such as abstract base classes, operator overloading, and templates.

Building Endian-Independent Code With C++

In most computers, each byte has its own unique address. Because the address refers to all eight bits of the byte, it's not useful to talk about the order of the bits within the byte. We can discuss the significance of the bits, but not their order.

Since the bytes of multi-byte numbers are individually addressable, we do need to consider the order of their bytes in memory. Two reasonable possibilities exist: big-endian and little-endian byte order.

Big-endian machines store the most-significant byte of a multi-byte number at the lowest-numbered address, with the other bytes following in decreasing order of significance. Little-endian machines store multi-byte numbers in the opposite order: from least-significant to most-significant.

Within a single computer, the byte order doesn't matter because the processor does all its memory loads and stores in the correct order, whichever that may be. The problem arises when we need to move data between machines with different endianness.

We could convert all multi-byte numbers to ASCII representations and transmit those, but that would require extra bandwidth and would complicate generating and parsing the messages. To avoid these costs, most low-level protocols use fixed-size binary fields. If these fields are larger than one byte then their endianness becomes an issue.

This article shows how to use C++ to deal with such mixed-endian systems in a simple and reliable way.

Syndicate content