Software Synthesis for Energy-Constrained Hard Real-Time Systems: A Petri net-based approach