Move all init code into a thread context

FreeRTOS suggests only working with semaphores/mutex in a thread context
and not before the scheduler starts (this includes creation and
acquiring locks).