#include "core.h"
#include "clocks.h"
#include "memory.h"

void mcu_init(void)
{
	// nvm init
	mem_nvm_init();
	// osc32k init
	clock_osc32k_init();

	// osc init
	clock_osc_init();

	clock_dfll_init();

	clock_dpll_init();

	// master clock init
	clock_mclk_init();

	// generators init
	clock_gclk_init();

	// dma init
	mem_dma_init();

	// port event init

	// cache init
	mem_cache_init();
}

void atomic_enter_critical(uint32_t volatile* atomic)
{
	*atomic = __get_PRIMASK();
	__disable_irq();
	__DMB();
}

void atomic_leave_critical(uint32_t volatile* atomic)
{
	__DMB();
	__set_PRIMASK(*atomic);
}
