note: - модбас не моделируется, в s-function просто передаются константы режимов. - лишние файлы убраны в outdate. - два канала одной фазы переключаются немного криво: на один такт симуляции проскакивает высокий уровень предыдущего канала и только потом включается текущий канал
300 lines
6.9 KiB
C
300 lines
6.9 KiB
C
/* USER CODE BEGIN Header */
|
|
/**
|
|
******************************************************************************
|
|
* @file stm32f1xx_it.c
|
|
* @brief Interrupt Service Routines.
|
|
******************************************************************************
|
|
* @attention
|
|
*
|
|
* Copyright (c) 2024 STMicroelectronics.
|
|
* All rights reserved.
|
|
*
|
|
* This software is licensed under terms that can be found in the LICENSE file
|
|
* in the root directory of this software component.
|
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
|
*
|
|
******************************************************************************
|
|
*/
|
|
/* USER CODE END Header */
|
|
|
|
/* Includes ------------------------------------------------------------------*/
|
|
#include "main.h"
|
|
#include "stm32f1xx_it.h"
|
|
/* Private includes ----------------------------------------------------------*/
|
|
/* USER CODE BEGIN Includes */
|
|
#include "ClockPackTransf.h"
|
|
/* USER CODE END Includes */
|
|
|
|
/* Private typedef -----------------------------------------------------------*/
|
|
/* USER CODE BEGIN TD */
|
|
extern void Trans_bus(void);
|
|
|
|
//uint8_t adr = 0;
|
|
//uint8_t data = 67;
|
|
//uint8_t TIM3_CNTR = 0;
|
|
/* USER CODE END TD */
|
|
|
|
/* Private define ------------------------------------------------------------*/
|
|
/* USER CODE BEGIN PD */
|
|
|
|
/* USER CODE END PD */
|
|
|
|
/* Private macro -------------------------------------------------------------*/
|
|
/* USER CODE BEGIN PM */
|
|
|
|
/* USER CODE END PM */
|
|
|
|
/* Private variables ---------------------------------------------------------*/
|
|
/* USER CODE BEGIN PV */
|
|
|
|
/* USER CODE END PV */
|
|
|
|
/* Private function prototypes -----------------------------------------------*/
|
|
/* USER CODE BEGIN PFP */
|
|
int cnt_rx_bytes = 0;
|
|
/* USER CODE END PFP */
|
|
|
|
/* Private user code ---------------------------------------------------------*/
|
|
/* USER CODE BEGIN 0 */
|
|
extern int freq_coef;
|
|
extern int cnt_tim;
|
|
int cnt_sens=0;
|
|
extern int tim_press;
|
|
extern int cnt_press;
|
|
extern int Duty_PWM;
|
|
|
|
int cnt_bytes;
|
|
int cnt_pwm = 0;
|
|
int cnt_period = 0;
|
|
int Period_PWM = 100;
|
|
int Direct = 0;
|
|
int stub;
|
|
/* USER CODE END 0 */
|
|
|
|
/* External variables --------------------------------------------------------*/
|
|
extern TIM_HandleTypeDef htim1;
|
|
extern TIM_HandleTypeDef htim2;
|
|
extern TIM_HandleTypeDef htim3;
|
|
/* USER CODE BEGIN EV */
|
|
|
|
/* USER CODE END EV */
|
|
|
|
/******************************************************************************/
|
|
/* Cortex-M3 Processor Interruption and Exception Handlers */
|
|
/******************************************************************************/
|
|
/**
|
|
* @brief This function handles Non maskable interrupt.
|
|
*/
|
|
void NMI_Handler(void)
|
|
{
|
|
/* USER CODE BEGIN NonMaskableInt_IRQn 0 */
|
|
|
|
/* USER CODE END NonMaskableInt_IRQn 0 */
|
|
/* USER CODE BEGIN NonMaskableInt_IRQn 1 */
|
|
while (1)
|
|
{
|
|
}
|
|
/* USER CODE END NonMaskableInt_IRQn 1 */
|
|
}
|
|
|
|
/**
|
|
* @brief This function handles Hard fault interrupt.
|
|
*/
|
|
void HardFault_Handler(void)
|
|
{
|
|
/* USER CODE BEGIN HardFault_IRQn 0 */
|
|
|
|
/* USER CODE END HardFault_IRQn 0 */
|
|
while (1)
|
|
{
|
|
/* USER CODE BEGIN W1_HardFault_IRQn 0 */
|
|
/* USER CODE END W1_HardFault_IRQn 0 */
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @brief This function handles Memory management fault.
|
|
*/
|
|
void MemManage_Handler(void)
|
|
{
|
|
/* USER CODE BEGIN MemoryManagement_IRQn 0 */
|
|
|
|
/* USER CODE END MemoryManagement_IRQn 0 */
|
|
while (1)
|
|
{
|
|
/* USER CODE BEGIN W1_MemoryManagement_IRQn 0 */
|
|
/* USER CODE END W1_MemoryManagement_IRQn 0 */
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @brief This function handles Prefetch fault, memory access fault.
|
|
*/
|
|
void BusFault_Handler(void)
|
|
{
|
|
/* USER CODE BEGIN BusFault_IRQn 0 */
|
|
|
|
/* USER CODE END BusFault_IRQn 0 */
|
|
while (1)
|
|
{
|
|
/* USER CODE BEGIN W1_BusFault_IRQn 0 */
|
|
/* USER CODE END W1_BusFault_IRQn 0 */
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @brief This function handles Undefined instruction or illegal state.
|
|
*/
|
|
void UsageFault_Handler(void)
|
|
{
|
|
/* USER CODE BEGIN UsageFault_IRQn 0 */
|
|
|
|
/* USER CODE END UsageFault_IRQn 0 */
|
|
while (1)
|
|
{
|
|
/* USER CODE BEGIN W1_UsageFault_IRQn 0 */
|
|
/* USER CODE END W1_UsageFault_IRQn 0 */
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @brief This function handles System service call via SWI instruction.
|
|
*/
|
|
void SVC_Handler(void)
|
|
{
|
|
/* USER CODE BEGIN SVCall_IRQn 0 */
|
|
|
|
/* USER CODE END SVCall_IRQn 0 */
|
|
/* USER CODE BEGIN SVCall_IRQn 1 */
|
|
|
|
/* USER CODE END SVCall_IRQn 1 */
|
|
}
|
|
|
|
/**
|
|
* @brief This function handles Debug monitor.
|
|
*/
|
|
void DebugMon_Handler(void)
|
|
{
|
|
/* USER CODE BEGIN DebugMonitor_IRQn 0 */
|
|
|
|
/* USER CODE END DebugMonitor_IRQn 0 */
|
|
/* USER CODE BEGIN DebugMonitor_IRQn 1 */
|
|
|
|
/* USER CODE END DebugMonitor_IRQn 1 */
|
|
}
|
|
|
|
/**
|
|
* @brief This function handles Pendable request for system service.
|
|
*/
|
|
void PendSV_Handler(void)
|
|
{
|
|
/* USER CODE BEGIN PendSV_IRQn 0 */
|
|
|
|
/* USER CODE END PendSV_IRQn 0 */
|
|
/* USER CODE BEGIN PendSV_IRQn 1 */
|
|
|
|
/* USER CODE END PendSV_IRQn 1 */
|
|
}
|
|
|
|
/**
|
|
* @brief This function handles System tick timer.
|
|
*/
|
|
void SysTick_Handler(void)
|
|
{
|
|
/* USER CODE BEGIN SysTick_IRQn 0 */
|
|
|
|
/* USER CODE END SysTick_IRQn 0 */
|
|
HAL_IncTick();
|
|
/* USER CODE BEGIN SysTick_IRQn 1 */
|
|
|
|
/* USER CODE END SysTick_IRQn 1 */
|
|
}
|
|
|
|
/******************************************************************************/
|
|
/* STM32F1xx Peripheral Interrupt Handlers */
|
|
/* Add here the Interrupt Handlers for the used peripherals. */
|
|
/* For the available peripheral interrupt handler names, */
|
|
/* please refer to the startup file (startup_stm32f1xx.s). */
|
|
/******************************************************************************/
|
|
|
|
/**
|
|
* @brief This function handles TIM1 update interrupt.
|
|
*/
|
|
void TIM1_UP_IRQHandler(void)
|
|
{
|
|
/* USER CODE BEGIN TIM1_UP_IRQn 0 */
|
|
if ((TIM1->SR)&0x01)
|
|
{
|
|
Trans_bus();
|
|
}
|
|
/* USER CODE END TIM1_UP_IRQn 0 */
|
|
HAL_TIM_IRQHandler(&htim1);
|
|
/* USER CODE BEGIN TIM1_UP_IRQn 1 */
|
|
// static uint8_t FirstTry = 0;
|
|
// if (FirstTry == 0) { HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1); FirstTry = 1;}
|
|
|
|
|
|
|
|
//stub++;
|
|
// if (stub > freq_coef) // flicking
|
|
// {
|
|
// if (freq_coef != 10 || freq_coef != 20) HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_13);
|
|
// stub = 0;
|
|
// }
|
|
//
|
|
//
|
|
// if (cnt_tim > 16000) {cnt_tim = 0; stub = 0;}
|
|
|
|
// cnt_tim++;
|
|
/* USER CODE END TIM1_UP_IRQn 1 */
|
|
}
|
|
|
|
/**
|
|
* @brief This function handles TIM2 global interrupt.
|
|
*/
|
|
void TIM2_IRQHandler(void)
|
|
{
|
|
/* USER CODE BEGIN TIM2_IRQn 0 */
|
|
|
|
/* USER CODE END TIM2_IRQn 0 */
|
|
HAL_TIM_IRQHandler(&htim2);
|
|
/* USER CODE BEGIN TIM2_IRQn 1 */
|
|
|
|
|
|
|
|
|
|
/* USER CODE END TIM2_IRQn 1 */
|
|
}
|
|
|
|
/**
|
|
* @brief This function handles TIM3 global interrupt.
|
|
*/
|
|
void TIM3_IRQHandler(void)
|
|
{
|
|
/* USER CODE BEGIN TIM3_IRQn 0 */
|
|
|
|
/* USER CODE END TIM3_IRQn 0 */
|
|
HAL_TIM_IRQHandler(&htim3);
|
|
/* USER CODE BEGIN TIM3_IRQn 1 */
|
|
|
|
// if(TIM3_CNTR==0)
|
|
// {
|
|
// Trans_bus(adr, 8);
|
|
// adr++;
|
|
// if (adr > 7) adr = 0;
|
|
// TIM3_CNTR++;
|
|
// }
|
|
// else
|
|
// {
|
|
// Trans_bus(data, 0);
|
|
// TIM3_CNTR=0;
|
|
// data++;
|
|
// }
|
|
// TIM3_CNTR = ~TIM3_CNTR;
|
|
/* USER CODE END TIM3_IRQn 1 */
|
|
}
|
|
|
|
/* USER CODE BEGIN 1 */
|
|
|
|
/* USER CODE END 1 */
|