/*
 * platform.c
 *
 *  Created on: 29.09.2022
 *      Author: jonas
 */

#include "platform.h"
#include "McuLib.h"
#include "McuWait.h"
#include "McuLED.h"
#include "McuGPIO.h"
#include "McuULN2003.h"
#include "splitflap.h"
#include "McuRTOS.h"
#include "McuRTT.h"
#include "McuShell.h"
#include "shell.h"
#include "McuShellUart.h"
#include "McuLog.h"
#if PL_CONFIG_USE_NVMC
  #include "nvmc.h"
#endif
#if PL_CONFIG_USE_MININI
  #include "MinIni/McuMinINI.h"
  #include "minIni/McuFlash.h"
#endif

void PL_Init(void){

	/* Enable clock for used PORTS */
    CLOCK_EnableClock(kCLOCK_PortA);
    CLOCK_EnableClock(kCLOCK_PortB);
    CLOCK_EnableClock(kCLOCK_PortC);

    /* NVMC init */
#if PL_CONFIG_USE_NVMC
    NVMC_Init();
#endif
#if PL_CONFIG_USE_MININI
	McuMinINI_Init();
	McuFlash_Init();
	McuFlash_RegisterMemory((const void*)McuMinINI_CONFIG_FLASH_NVM_ADDR_START, 1*McuMinINI_CONFIG_FLASH_NVM_BLOCK_SIZE);
#endif

	McuLib_Init();
	McuRTOS_Init();
	McuWait_Init();
	McuGPIO_Init();
	McuLED_Init();
	McuULN2003_Init();
	McuRTT_Init();
	McuShell_Init();
	McuShellUart_Init();
	McuLog_Init();
	McuLog_set_console(McuRTT_GetStdio(), 0);
	SHELL_Init();
	McuRTOS_Init();
}


void PL_Deinit(void){
	McuRTOS_Deinit();
	SHELL_Deinit();
	McuLog_Deinit();
	McuShellUart_Deinit();
	McuShell_Deinit();
	McuRTT_Deinit();
	McuULN2003_Deinit();
	McuLED_Deinit();
	McuGPIO_Deinit();
	McuWait_Deinit();
	McuRTOS_Deinit();
	McuLib_Deinit();

    /* NVMC deinit */
#if PL_CONFIG_USE_MININI
	McuMinINI_Deinit();
	McuFlash_Deinit();
#endif
#if PL_CONFIG_USE_NVMC
    NVMC_Deinit();
#endif
}
