/**************************************************************************
Данный файл настраивает структуры для симуляции периферий, которые выбраны 
дефайнами в stm32f4xx_matlab_conf.h.

**************************************************************************/
#include "mcu_wrapper_conf.h"

MCU_MemoryTypeDef MCU_MEM;
MCU_CortexMemoryTypeDef MCU_CORTEX_MEM;

//-----------------------------------------------------------------------//
/*------------------------------FUNCTIONS--------------------------------*/
// MCU PERIPH INIT
void Initialize_Periph_Sim(void)
{
	Init_TIM_SIM();
}
// MCU PERIPH DEINIT
void deInitialize_Periph_Sim(void)
{
	TIM_SIM_DEINIT();
}
// MCU DEINIT
void deInitialize_MCU(void)
{
	// обнуление структуры, управляющей программой МК
	memset(&hmcu, 0, sizeof(hmcu));
	// обнуление структур, симулирующих память МК
	memset(&MCU_MEM, 0, sizeof(MCU_MEM));
	memset(&MCU_CORTEX_MEM, 0, sizeof(MCU_CORTEX_MEM));
}


/*------------------------------FUNCTIONS--------------------------------*/
//-----------------------------------------------------------------------//

//-----------------------------------------------------------------------//
/*-------------------------------TIMERS----------------------------------*/
// defines structure for simulate
#ifdef USE_TIM1
struct TIM_Sim tim1s;
#endif
#ifdef USE_TIM2
struct TIM_Sim tim2s;
#endif
#ifdef USE_TIM3
struct TIM_Sim tim3s;
#endif
#ifdef USE_TIM4
struct TIM_Sim tim4s;
#endif
#ifdef USE_TIM5
struct TIM_Sim tim5s;
#endif
#ifdef USE_TIM6
struct TIM_Sim tim6s;
#endif
#ifdef USE_TIM7
struct TIM_Sim tim7s;
#endif
#ifdef USE_TIM8
struct TIM_Sim tim8s;
#endif
#ifdef USE_TIM9
struct TIM_Sim tim9s;
#endif
#ifdef USE_TIM10
struct TIM_Sim tim10s;
#endif
#ifdef USE_TIM11
struct TIM_Sim tim11s;
#endif
#ifdef USE_TIM12
struct TIM_Sim tim12s;
#endif
#ifdef USE_TIM13
struct TIM_Sim tim13s;
#endif
#ifdef USE_TIM14
struct TIM_Sim tim14s;
#endif

// defines function for filling structure for simulate
void Init_TIM_SIM(void)
{
#ifdef USE_TIM1    
	tim1s.tx_cnt = TIM1->CNT;
	tim1s.tx_step = SIM_Sample_Time * ABP2_TIMS_Value;

	tim1s.Channels.OC1_GPIOx = GPIOA;
	tim1s.Channels.OC1_PIN_SHIFT = 8;
	tim1s.Channels.OC2_GPIOx = GPIOE;
	tim1s.Channels.OC2_PIN_SHIFT = 11;
	tim1s.Channels.OC3_GPIOx = GPIOE;
	tim1s.Channels.OC3_PIN_SHIFT = 13;
	tim1s.Channels.OC4_GPIOx = GPIOE;
	tim1s.Channels.OC4_PIN_SHIFT = 14;
#endif
#ifdef USE_TIM2
	tim2s.tx_cnt = TIM2->CNT;
	tim2s.tx_step = SIM_Sample_Time * ABP1_TIMS_Value;

	tim2s.Channels.OC1_GPIOx = GPIOA;
	tim2s.Channels.OC1_PIN_SHIFT = 5;
	tim2s.Channels.OC2_GPIOx = GPIOA;
	tim2s.Channels.OC2_PIN_SHIFT = 1;
	tim2s.Channels.OC3_GPIOx = GPIOA;
	tim2s.Channels.OC3_PIN_SHIFT = 2;
	tim2s.Channels.OC4_GPIOx = GPIOA;
	tim2s.Channels.OC4_PIN_SHIFT = 3;
#endif
#ifdef USE_TIM3
	tim3s.tx_cnt = TIM3->CNT;
	tim3s.tx_step = SIM_Sample_Time * ABP1_TIMS_Value;

	tim3s.Channels.OC1_GPIOx = GPIOB;
	tim3s.Channels.OC1_PIN_SHIFT = 4;
	tim3s.Channels.OC2_GPIOx = GPIOA;
	tim3s.Channels.OC2_PIN_SHIFT = 7;
	tim3s.Channels.OC3_GPIOx = GPIOB;
	tim3s.Channels.OC3_PIN_SHIFT = 0;
	tim3s.Channels.OC4_GPIOx = GPIOB;
	tim3s.Channels.OC4_PIN_SHIFT = 1;
#endif
#ifdef USE_TIM4	
	tim4s.tx_cnt = TIM4->CNT;
	tim4s.tx_step = SIM_Sample_Time * ABP1_TIMS_Value;

	tim4s.Channels.OC1_GPIOx = GPIOD;
	tim4s.Channels.OC1_PIN_SHIFT = 12;
	tim4s.Channels.OC2_GPIOx = GPIOB;
	tim4s.Channels.OC2_PIN_SHIFT = 7;
	tim4s.Channels.OC3_GPIOx = GPIOB;
	tim4s.Channels.OC3_PIN_SHIFT = 8;
	tim4s.Channels.OC4_GPIOx = GPIOB;
	tim4s.Channels.OC4_PIN_SHIFT = 9;
#endif
#ifdef USE_TIM5
	tim5s.tx_cnt = TIM5->CNT;
	tim5s.tx_step = SIM_Sample_Time * ABP1_TIMS_Value;

	tim5s.Channels.OC1_GPIOx = GPIOA;
	tim5s.Channels.OC1_PIN_SHIFT = 0;
	tim5s.Channels.OC2_GPIOx = GPIOA;
	tim5s.Channels.OC2_PIN_SHIFT = 1;
	tim5s.Channels.OC3_GPIOx = GPIOA;
	tim5s.Channels.OC3_PIN_SHIFT = 2;
	tim5s.Channels.OC4_GPIOx = GPIOA;
	tim5s.Channels.OC4_PIN_SHIFT = 3;
#endif
#ifdef USE_TIMx
	tim6s.tx_cnt = TIMx->CNT;
	tim6s.tx_step = SIM_Sample_Time * ABP1_TIMS_Value;

	tim6s.Channels.OC1_GPIOx = GPIOA;
	tim6s.Channels.OC1_PIN_SHIFT = 0;
	tim6s.Channels.OC2_GPIOx = GPIOA;
	tim6s.Channels.OC2_PIN_SHIFT = 0;
	tim6s.Channels.OC3_GPIOx = GPIOA;
	tim6s.Channels.OC3_PIN_SHIFT = 0;
	tim6s.Channels.OC4_GPIOx = GPIOA;
	tim6s.Channels.OC4_PIN_SHIFT = 0;
#endif
}
/*-------------------------------TIMERS----------------------------------*/
//-----------------------------------------------------------------------//
