First thing is that I don't have any OCM unit in megax8pb_perif, at least not in the files you shared.
How I get the outputvalues from Timer3 and Timer4 I still have to look.
OC units have their own modules.
You already have pointers to them in your code (btw: second one should be "OC4B"?):
- Code:
m_OC3B = m_timer3->getOcUnit("OC3B");
m_OC4B = m_timer4->getOcUnit("OC3B");
This OCM module is complex (and it will require some modifications in other modules).
I don't know this module very well, so please correct me if I'm wrong in something.
Lets go by parts:
1- This functionality enabled/disabled when both OC3B and OC4B try to control the same pin.
You need to find a way to detect this condition.
Currently I don't see an easy way to do it.
The simplest way that comes to my mind is that Each OC unit checks if the pin is already controlled.
If the pin is already controlled, the it calls OCM unit.
But by now OC units don't know about OCM.
2- You need a way to inhibit OC units to control their pins while OCM is activated.
This needs a flag or something that can be set/cleared and then used in
McuOcUnit::runEvent() to inhibit
drivePin()You already have pointers to OC units in your code.
Now you need to inplement a flag or whatever in the OCunits.
3- The mode of operation is determined by PORTD2.
So you need a way to detect changes in this bit.
This can be letf for later...
4- Once OCM is in control it needs to be called when any OC unit tries to change their pin.
If OC units kew about OCM, then each OC unit could call OCM instead driving it's pin.
You can solve 1 and 4 by giving OC units a pointer to OCM.
OCM itself already knows OC3B and OC4B, so it could call them and pass a pointer to "this".
As I see the situation, not sure if better a new variant for AVR OC units.
By now I think we can take it easy, and add this to existing AvrOcUnit:
- A flag to inhibit pin control with a setter.
- A pointer to OCM unit with setter.
- A mechanism to drive pin or call OCM depending on the flag.
I added a funtion in McuOcunit that makes this easier at Rev 939.
So you can override
McuOcUnit::setPinSate() to set the pin state or call OCM unit depending on the flag.
- In
AvrOcUnit::configure() detect if the pin is already controlled (needs implementation in McuPin) and call OCM if needed.
With this aproach you don't even need callbacks.
Still pending how to get PORTD2 changes to configure mode.
This is how I see the situation in relation to what is already implemented in simulide.