[En-Nut-Discussion] Table driven routines (was Re: Using boost::preprocessor (preprocessor metaprogramming))

Harald Kipp harald.kipp at egnite.de
Fri Feb 13 14:17:21 CET 2009


Duane,

There is one unique feature of the AVR, which you may not be aware of.

duane ellis wrote:

> Why is this not table driven? or parameterized, maybe pass a pointer to 
> a structure with this sort of information in the structure, or something 
> like that?.
> 
> Instead of 5 functions:   uart1_write()  through write5_write(),
> 
> int
> uartX_write( int who, int c )
> {
>      UART_REGS  *p_uart = uart_pointer_table[ who ];
>    ..... code .....
> }

A subset of powerful machine instructions of the AVR are limited to I/O
address space, specifically bit modifications. Naturally, the compiler
can detect I/O space access only, if the address is a constant. It can
then replace read-modify-write by a single set-bit or clear-bit
instruction. While initially the dev_base member in the driver control
block was intended to serve as the parameter for specifying the port,
this had been abandoned late in favor of constants.

While this was a benefit for the AVR, the ARM port simply inherited the
layout. Drivers for the ARM need a partial redesign to make use of the
advanced address indexing provided by this architecture.

Harald





More information about the En-Nut-Discussion mailing list