avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-gcc-list] template library for c++


From: Nils Springob
Subject: [avr-gcc-list] template library for c++
Date: Mon, 19 Sep 2005 13:06:48 +0200
User-agent: Mozilla Thunderbird 1.0.2 (X11/20050317)

Hi,

I started to work on a c++ template library for (avr) microcontrollers,
which should extend the c++ low level support for microcontroller
environments. The ATmega16 is the only supported mcu at the moment. I
post on this newsgroup, because the templating and inlining mechanism of
this library heavily depends on the optimization process of the c++
compiler.

The abstraction of the library is done in 3 levels (at the moment by 3
files):
- registers.h: definition of abstract 8 and 16 bit registers and single
  bits inside these registers.
- avr.h: definition of avr hardware abstraction such as ioports, usarts,
  timers.
- mega16.h: definition of the machine registers, bits and the concrete
  hardware devices of this microcontroller.

The library consists of template definitions and type definitions, the
methods are designed to be collapsed by the optimizer, and will(should
;-)) result in nearly the same code as a classical pre-processor based
approach.


The advantages are:
- namespaces for all definitions
- aggregation of interrelated registers and bits (ioport, usart, timer)
- simplified access to special registers (shared address of UCSRC/UBRRH
  on ATmega16)

An open point is:
- integration of interrupt-handlers


some code examples:

// port pin with LED
  typedef IOPin<system::IOPortB, 0, true> LedRed;
  LedRed::enable(); // set DDR bit
  LedRed::set(); // set PORT bit

// access to timer2
  system::Timer2::enableAsync();
  system::Timer2::waitBusy();
  system::Timer2::setClockSource(0x01); // PS=1
  system::Timer2::overflowInterrupt::enable();

// access to the usart 0
  typedef system::Usart0 myUsart;
  myUsart::setBaudRate(25); // 19.2kBaud @ 8MHz
  myUsart::enableTransmitter();
  myUsart::enableReceiver();
  myUsart::receiveInterrupt::enable();
  myUsart::transmit('*');


a first approach can be downloaded here:
http://www.nicai-systems.de/files/ucpptl.tgz


I would appreciate any feedback to my approach.
Regards,
Nils

--
Nils Springob
http://www.nicai-systems.de







reply via email to

[Prev in Thread] Current Thread [Next in Thread]