By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,159 Members | 888 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,159 IT Pros & Developers. It's quick & easy.

Challenge: Device Register Model in C++

P: n/a
Be a hero and show me a good model of a hardware device register :-O

This might seem like an absurd challenge; after all, the C++ language has
been around for donkeys years now. It's a mature language and we have
powerful design patterns to simplify complex problems. However, I've never
seen, and have never been able to produce, a satisfactory model of a
register! It's not that I'm thick nor inexperienced; I just expect a lot :-)

Traditionally, and still today, you'll see most device drivers using
#defines, enums, bit-fields, global constants, structs of integer types and
so on. The resultant code is inevitably difficult to follow or error prone
or
unsafe or volumous or endian-dependent... or, often, all of the above.
Surely, it must be possible to create a model of something as fundamental as
a device register that results in simple, safe, understandable and close to,
or identical to, the efficiency of these simple minded solutions...
shouldn't it?

Consider the CSR (configuration and status register) architecture, used in
numerous busses and bus devices that we all use daily (PCI, FireWire, SCI
etc.); it's all about
registers... lots and lots of registers; read-only registers, read-write
registers, registers that have one meaning if read and another meaning if
written to, registers with reserved bits, registers with read-only bits and
bit-fields etc. etc.

Most embedded compilers these days support all of the modern features of C++
(namespaces, templates...); the code generation is usually extremely good
too. Obviously, we would want to avoid features that have run-time overhead
and/or non-deterministic behaviour down at the device driver level, but the
tools I've seen and used all support leaving out these features. Some
compilers for embedded development support the very latest standards and
allow trick like template metaprogramming (in fact until Visual Studio.net,
many had better support for templates than Microsoft's desktop efforts).

So, we have the capability to use C++, templates and design patterns in
embedded/driver development; a register model would be a great starting
place to exploit these. Have you ever seen a satisfactory class for
modelling a device register?
Tim Clacy
Jul 19 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Tim Clacy wrote:
extremely good too. Obviously, we would want to avoid features that
have run-time overhead and/or non-deterministic behaviour down at the
device driver level, but the tools I've seen and used all support
leaving out these features.


Specifically, I had in mind RTTI and C++ exceptions
Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.