/**
**************************************************************************
* @file stm32f4xx_matlab_conf.c
* @brief Исходный код для конфигурации симулятора МК.
**************************************************************************
@details
Данный файл настраивает структуры для симуляции периферий, которые выбраны
дефайнами в stm32f4xx_matlab_conf.h.
**************************************************************************/

#include "mcu_wrapper_conf.h"

MCU_MemoryTypeDef MCU_MEM;
MCU_CortexMemoryTypeDef MCU_CORTEX_MEM;
DBGMCU_TypeDef DEBUG_MCU;

//-----------------------------------------------------------------------//
/*------------------------------FUNCTIONS--------------------------------*/
/**
  * @brief    Инициализация периферии симулятора МК.
  * @details  Эта функция вызывает функции инициализации периферии для симуляции
  */
void Initialize_Periph_Sim(void)
{
	Init_TIM_SIM();
}
/**
  * @brief    Деинициализация периферии симулятора МК.
  * @details  Эта функция вызывает функции деинициализации периферии для последующей симуляции
  */
void deInitialize_Periph_Sim(void)
{
	TIM_SIM_DEINIT();
}
/**
  * @brief    Деинициализация симулятора МК.
  * @details  Эта функция очищает память симулятора МК, чтобы в 
			  следующей симуляции он запускался как в первый раз.
  */
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));
	memset(&DEBUG_MCU, 0, sizeof(DEBUG_MCU));
}


/*------------------------------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

/**
  * @brief    Инициализация таймеров симулятора МК.
  * @details  Эта функция инициализирует структуры для симуляции таймеров.
  *			  Таймеры для симуляции выбираются дефайнами в stm32f4xx_matlab_conf.h.
  */
void Init_TIM_SIM(void)
{
#ifdef USE_TIM1    
	tim1s.tx_cnt = TIM1->CNT;
	tim1s.tx_step = hmcu.SIM_Sample_Time * ABP2_TIMS_Value;

	tim1s.Channels.OC1_GPIOx = GPIOE;
	tim1s.Channels.OC1_PIN_SHIFT = 9;
	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;
	tim1s.Channels.OC1REF = 0;
	tim1s.Channels.OC2REF = 0;
	tim1s.Channels.OC3REF = 0;
	tim1s.Channels.OC4REF = 0;
#endif
#ifdef USE_TIM2
	tim2s.tx_cnt = TIM2->CNT;
	tim2s.tx_step = hmcu.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;
	tim2s.Channels.OC1REF = 0;
	tim2s.Channels.OC2REF = 0;
	tim2s.Channels.OC3REF = 0;
	tim2s.Channels.OC4REF = 0;
#endif
#ifdef USE_TIM3
	tim3s.tx_cnt = TIM3->CNT;
	tim3s.tx_step = hmcu.SIM_Sample_Time * ABP1_TIMS_Value;

	tim3s.Channels.OC1_GPIOx = GPIOA;
	tim3s.Channels.OC1_PIN_SHIFT = 6;
	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;
	tim3s.Channels.OC1REF = 0;
	tim3s.Channels.OC2REF = 0;
	tim3s.Channels.OC3REF = 0;
	tim3s.Channels.OC4REF = 0;
#endif
#ifdef USE_TIM4	
	tim4s.tx_cnt = TIM4->CNT;
	tim4s.tx_step = hmcu.SIM_Sample_Time * ABP1_TIMS_Value;

	tim4s.Channels.OC1_GPIOx = GPIOD;
	tim4s.Channels.OC1_PIN_SHIFT = 12;
	tim4s.Channels.OC2_GPIOx = GPIOD;
	tim4s.Channels.OC2_PIN_SHIFT = 13;
	tim4s.Channels.OC3_GPIOx = GPIOD;
	tim4s.Channels.OC3_PIN_SHIFT = 14;
	tim4s.Channels.OC4_GPIOx = GPIOD;
	tim4s.Channels.OC4_PIN_SHIFT = 15;
	tim4s.Channels.OC1REF = 0;
	tim4s.Channels.OC2REF = 0;
	tim4s.Channels.OC3REF = 0;
	tim4s.Channels.OC4REF = 0;
#endif
#ifdef USE_TIM5
	tim5s.tx_cnt = TIM5->CNT;
	tim5s.tx_step = hmcu.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;
	tim5s.Channels.OC1REF = 0;
	tim5s.Channels.OC2REF = 0;
	tim5s.Channels.OC3REF = 0;
	tim5s.Channels.OC4REF = 0;
#endif
#ifdef USE_TIM6
	tim6s.tx_cnt = TIM6->CNT;
	tim6s.tx_step = hmcu.SIM_Sample_Time * ABP1_TIMS_Value;

	tim6s.Channels.OC1_GPIOx = GPIOA;
	tim6s.Channels.OC1_PIN_SHIFT = 6;
	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;
	tim6s.Channels.OC1REF = 0;
	tim6s.Channels.OC2REF = 0;
	tim6s.Channels.OC3REF = 0;
	tim6s.Channels.OC4REF = 0;
#endif
#ifdef USE_TIM7
	tim7s.tx_cnt = TIM7->CNT;
	tim7s.tx_step = hmcu.SIM_Sample_Time * ABP1_TIMS_Value;

	tim7s.Channels.OC1_GPIOx = GPIOA;
	tim7s.Channels.OC1_PIN_SHIFT = 6;
	tim7s.Channels.OC2_GPIOx = GPIOA;
	tim7s.Channels.OC2_PIN_SHIFT = 0;
	tim7s.Channels.OC3_GPIOx = GPIOA;
	tim7s.Channels.OC3_PIN_SHIFT = 0;
	tim7s.Channels.OC4_GPIOx = GPIOA;
	tim7s.Channels.OC4_PIN_SHIFT = 0;
	tim7s.Channels.OC1REF = 0;
	tim7s.Channels.OC2REF = 0;
	tim7s.Channels.OC3REF = 0;
	tim7s.Channels.OC4REF = 0;
#endif
#ifdef USE_TIM8
	tim8s.tx_cnt = TIM8->CNT;
	tim8s.tx_step = hmcu.SIM_Sample_Time * ABP2_TIMS_Value;

	tim8s.Channels.OC1_GPIOx = GPIOA;
	tim8s.Channels.OC1_PIN_SHIFT = 6;
	tim8s.Channels.OC2_GPIOx = GPIOA;
	tim8s.Channels.OC2_PIN_SHIFT = 0;
	tim8s.Channels.OC3_GPIOx = GPIOA;
	tim8s.Channels.OC3_PIN_SHIFT = 0;
	tim8s.Channels.OC4_GPIOx = GPIOA;
	tim8s.Channels.OC4_PIN_SHIFT = 0;
	tim8s.Channels.OC1REF = 0;
	tim8s.Channels.OC2REF = 0;
	tim8s.Channels.OC3REF = 0;
	tim8s.Channels.OC4REF = 0;
#endif
#ifdef USE_TIM9
	tim9s.tx_cnt = TIM9->CNT;
	tim9s.tx_step = hmcu.SIM_Sample_Time * ABP2_TIMS_Value;

	tim9s.Channels.OC1_GPIOx = GPIOA;
	tim9s.Channels.OC1_PIN_SHIFT = 6;
	tim9s.Channels.OC2_GPIOx = GPIOA;
	tim9s.Channels.OC2_PIN_SHIFT = 0;
	tim9s.Channels.OC3_GPIOx = GPIOA;
	tim9s.Channels.OC3_PIN_SHIFT = 0;
	tim9s.Channels.OC4_GPIOx = GPIOA;
	tim9s.Channels.OC4_PIN_SHIFT = 0;
	tim9s.Channels.OC1REF = 0;
	tim9s.Channels.OC2REF = 0;
	tim9s.Channels.OC3REF = 0;
	tim9s.Channels.OC4REF = 0;
#endif
#ifdef USE_TIM10
	tim10s.tx_cnt = TIM10->CNT;
	tim10s.tx_step = hmcu.SIM_Sample_Time * ABP2_TIMS_Value;

	tim10s.Channels.OC1_GPIOx = GPIOA;
	tim10s.Channels.OC1_PIN_SHIFT = 6;
	tim10s.Channels.OC2_GPIOx = GPIOA;
	tim10s.Channels.OC2_PIN_SHIFT = 0;
	tim10s.Channels.OC3_GPIOx = GPIOA;
	tim10s.Channels.OC3_PIN_SHIFT = 0;
	tim10s.Channels.OC4_GPIOx = GPIOA;
	tim10s.Channels.OC4_PIN_SHIFT = 0;
	tim10s.Channels.OC1REF = 0;
	tim10s.Channels.OC2REF = 0;
	tim10s.Channels.OC3REF = 0;
	tim10s.Channels.OC4REF = 0;
#endif
#ifdef USE_TIM11
	tim11s.tx_cnt = TIM11->CNT;
	tim11s.tx_step = hmcu.SIM_Sample_Time * ABP2_TIMS_Value;

	tim11s.Channels.OC1_GPIOx = GPIOA;
	tim11s.Channels.OC1_PIN_SHIFT = 6;
	tim11s.Channels.OC2_GPIOx = GPIOA;
	tim11s.Channels.OC2_PIN_SHIFT = 0;
	tim11s.Channels.OC3_GPIOx = GPIOA;
	tim11s.Channels.OC3_PIN_SHIFT = 0;
	tim11s.Channels.OC4_GPIOx = GPIOA;
	tim11s.Channels.OC4_PIN_SHIFT = 0;
	tim11s.Channels.OC1REF = 0;
	tim11s.Channels.OC2REF = 0;
	tim11s.Channels.OC3REF = 0;
	tim11s.Channels.OC4REF = 0;
#endif
#ifdef USE_TIM12
	tim12s.tx_cnt = TIM12->CNT;
	tim12s.tx_step = hmcu.SIM_Sample_Time * ABP1_TIMS_Value;

	tim12s.Channels.OC1_GPIOx = GPIOA;
	tim12s.Channels.OC1_PIN_SHIFT = 6;
	tim12s.Channels.OC2_GPIOx = GPIOA;
	tim12s.Channels.OC2_PIN_SHIFT = 0;
	tim12s.Channels.OC3_GPIOx = GPIOA;
	tim12s.Channels.OC3_PIN_SHIFT = 0;
	tim12s.Channels.OC4_GPIOx = GPIOA;
	tim12s.Channels.OC4_PIN_SHIFT = 0;
	tim12s.Channels.OC1REF = 0;
	tim12s.Channels.OC2REF = 0;
	tim12s.Channels.OC3REF = 0;
	tim12s.Channels.OC4REF = 0;
#endif
#ifdef USE_TIM13
	tim13s.tx_cnt = TIM13->CNT;
	tim13s.tx_step = hmcu.SIM_Sample_Time * ABP1_TIMS_Value;

	tim13s.Channels.OC1_GPIOx = GPIOA;
	tim13s.Channels.OC1_PIN_SHIFT = 6;
	tim13s.Channels.OC2_GPIOx = GPIOA;
	tim13s.Channels.OC2_PIN_SHIFT = 0;
	tim13s.Channels.OC3_GPIOx = GPIOA;
	tim13s.Channels.OC3_PIN_SHIFT = 0;
	tim13s.Channels.OC4_GPIOx = GPIOA;
	tim13s.Channels.OC4_PIN_SHIFT = 0;
	tim13s.Channels.OC1REF = 0;
	tim13s.Channels.OC2REF = 0;
	tim13s.Channels.OC3REF = 0;
	tim13s.Channels.OC4REF = 0;
#endif
#ifdef USE_TIM14
	tim14s.tx_cnt = TIM14->CNT;
	tim14s.tx_step = hmcu.SIM_Sample_Time * ABP1_TIMS_Value;

	tim14s.Channels.OC1_GPIOx = GPIOA;
	tim14s.Channels.OC1_PIN_SHIFT = 6;
	tim14s.Channels.OC2_GPIOx = GPIOA;
	tim14s.Channels.OC2_PIN_SHIFT = 0;
	tim14s.Channels.OC3_GPIOx = GPIOA;
	tim14s.Channels.OC3_PIN_SHIFT = 0;
	tim14s.Channels.OC4_GPIOx = GPIOA;
	tim14s.Channels.OC4_PIN_SHIFT = 0;
	tim14s.Channels.OC1REF = 0;
	tim14s.Channels.OC2REF = 0;
	tim14s.Channels.OC3REF = 0;
	tim14s.Channels.OC4REF = 0;
#endif
}
/*-------------------------------TIMERS----------------------------------*/
//-----------------------------------------------------------------------//
