FAQ answer

What are the design principles behind Ddr-ArdMeg?

It's the same principles that were used when developing Ddr-Z8e - a device driver library for the Zilog Z8Encore® MCU. However, C++11 allows a more refined approach. Some basic principles are:

  • Static definitions
  • Constant folding / propagation
  • Type safe constructs using C++11 enums
  • Code inlining
  • Offset addressing

Static definitions

Registers, bits, parameters, special values, etc. are to a great length predefined, static constants (not macros!!!). This improves type safety and aids constant folding / propagation (see below).

Constant folding / propagation

Since most of the MCU is statically defined, constant folding and propagation can make huge impact on the size (and efficiency) of generated code. A prof of this is that the size optimization compiler flag (-Os) generates the smallest and fastest code for the Ddr-ArdMeg modules.

Type safe constructs

In addition to defining real constant variables (as opposed to macros), C++11 also allows definition of strongly typed enums. These are used to define type safe bit patterns such as available baude rates (RS232), clock polarity & phase modes (SPI), programing mode (EEPROM), etc. In other words, much of the data validation can be done during compilation as opposed to during time of execution (or not at all ...). The result is less code, reduced probability for bugs and higher efficiency.

Code inlining

Goes without saying. Using real C++ inlining, as opposed to macros, adds type checking without impacting the size of generated code.

Offset addressing

Using offset addressing (or relative addressing) is a simple way of reducing the amount of written code and at the same time, reduce the probablility for typos. For example, all IO-ports have their Data Out register 2 bytes above the base address of the specific IO port controller. By defining the Data Out register as an offset address (in this case 0x02) the register address for any Data Out port can be calculated (at compile time) as:

IOPortA_Base + DataOutRegOffset (0x20 + 0x02)

IOPortB_Base + DataOutRegOffset (0x23 + 0x02)

In this example it's only necessary to define 3 static constants 0x02, 0x20 and 0x23 in order to let the compiler generate 4 absolute addresses (0x20, 0x22, 0x23, 0x25).

... and then

One final design principle, that for some reason seems to be frequently forgotten by developers of embedded software, is to try to use descriptive names for everything.

Back to FAQ

Events

April 10th, 2017
Beta release 1.00 goes live.

March 15, 2017
Site goes live. Beta release is in the making.