An energy aware variation-tolerant writing termination control for STT-based non volatile flip-flops