Make all flash routines wait for completion of op

This is so that we cannot enter a state where the controller goes to
sleep and powers down the memory before a write operation has finished.
Add callback for deciding when to sleep

This lets users of task_manager decide programmatically when
they can sleep based on information that task_manager should
not know about.
Update to use new task_manager flags API
Add sleep handler callback