I've got an general question.
Is there a official guideline regarding syntax, Hierarchie or procedure for adding new microcontroller functions.
No, there is not official guideline.
About sintax:For sintax, you can just have a look to the source code.
My main concern is readability, keeping the code compact, but first it must be as easily readable as possible.
For example this is more readable and more compact at the same time:
- Code:
void AvrTimer800::configureClock()
{
if( m_prIndex > 5 ) AvrTimer::configureExtClock();
else AvrTimer::configureClock();
}
Than this
- Code:
void AvrTimer800::configureClock(){
if (m_prIndex > 5){
AvrTimer::configureExtClock();
}
else{
AvrTimer::configureClock();
}
}
In general brackects "{" open in next line, so funtion name or whatever is easily readable.
Spaces inside parenthesis, not outside, so the content is readable, not the "if" or "for" or "while" (those I already know so are readable).
Brackets "{ }" only if needed.
Aligning things helps readability.
Another thing: Names are not full descriptions.
Names should be as short as possible while keeping some meaning.
For example the above: configureExtClock() is already too long.
It could be: configExtClock()
About hierarchy and procedure:New microcontroller simulation is not yet fully defined, I'm still doing changes to fit new features as they are needed.
If you wish to add new things, just let me know and I can give you some idea, then we can discuss the better aproach.
A general description:
There are some base classes for all microntrollers: core and perifericals.
And different variants are built on top of that.
For example, there is a base class "McuCore" with data structures and methods common to all microcontrollers.
Then the is a subclass "AvrCore" with the instruction decoder and little more.
For Pics the structure is more complex, there is "PicMrCore" subclassing "McuCore" for all Pic Mid Range devices, with instrunction decoder and some other stuff.
Then there is "Pic14Core" subclassing "PicMrCore" with just a few things, and "Pic14eCore" also subclassing "PicMrCore" with the extended intructions for enhanced devices.
Pics 16 bits is not yet implemented, but it will probably derive directly from "McuCore", or maybe a new common class for all Pics is needed, I will see when I get into it.
Similar thing for perifericals, for example there is a common class for all Timers.
Then for AVRs the structure is like this:
McuTimer
--------AvrTimer
----------------AvrTimer8bit
------------------------AvrTimer800
------------------------AvrTimer801
------------------------AvrTimer810
------------------------AvrTimer820
----------------AvrTimer16bit
By now there is only one variant for AVR 16 bit Timer, but if some other variant needs to be implemented, then AvrTimer16bit class will keep everything that is common and new subclasses will be added with the new variants.
General rule is never write the same code 2 times: reuse, subclass, override.
But there are special cases, if reusing increases the complexity too much, then better write the same few lines in 2 places.