152 lines
3.5 KiB
C
152 lines
3.5 KiB
C
|
/**
|
|||
|
******************************************************************************
|
|||
|
* @file tim.c
|
|||
|
* @brief This file provides code for the configuration
|
|||
|
* of the TIM instances.
|
|||
|
******************************************************************************
|
|||
|
* @attention
|
|||
|
*
|
|||
|
* <h2><center>© Copyright (c) 2021 STMicroelectronics.
|
|||
|
* All rights reserved.</center></h2>
|
|||
|
*
|
|||
|
* This software component is licensed by ST under BSD 3-Clause license,
|
|||
|
* the "License"; You may not use this file except in compliance with the
|
|||
|
* License. You may obtain a copy of the License at:
|
|||
|
* opensource.org/licenses/BSD-3-Clause
|
|||
|
*
|
|||
|
******************************************************************************
|
|||
|
*/
|
|||
|
|
|||
|
/* Includes ------------------------------------------------------------------*/
|
|||
|
#include "tim.h"
|
|||
|
#include "my.h"
|
|||
|
#include "main.h"
|
|||
|
|
|||
|
/* USER CODE BEGIN 0 */
|
|||
|
__IO uint16_t AMP_STATUS = 0;
|
|||
|
|
|||
|
__IO uint16_t timerUPER = 0;
|
|||
|
__IO uint16_t timerOP = 0;
|
|||
|
__IO uint16_t timerKZ = 0;
|
|||
|
/* USER CODE END 0 */
|
|||
|
|
|||
|
TIM_HandleTypeDef htim7;
|
|||
|
#define TIM7_SOURCE ((uint32_t) TIM7)
|
|||
|
|
|||
|
extern uint8_t timeout; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
extern uint8_t iolen;
|
|||
|
extern bool sendreq;
|
|||
|
extern bool send;
|
|||
|
|
|||
|
extern __IO UserData_TypeDef pardata;
|
|||
|
extern __IO uint16_t CorrWord[2][20];
|
|||
|
|
|||
|
|
|||
|
|
|||
|
/* TIM7 init function */
|
|||
|
void MX_TIM7_Init(void)
|
|||
|
{
|
|||
|
TIM_MasterConfigTypeDef sMasterConfig = {0};
|
|||
|
|
|||
|
htim7.Instance = TIM7;
|
|||
|
htim7.Init.Prescaler = 0;
|
|||
|
htim7.Init.CounterMode = TIM_COUNTERMODE_UP;
|
|||
|
htim7.Init.Period = 7999; // Irq's 1ms
|
|||
|
htim7.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
|||
|
if (HAL_TIM_Base_Init(&htim7) != HAL_OK)
|
|||
|
{
|
|||
|
Error_Handler();
|
|||
|
}
|
|||
|
sMasterConfig.MasterOutputTrigger = TIM_TRGO_UPDATE;
|
|||
|
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
|
|||
|
if (HAL_TIMEx_MasterConfigSynchronization(&htim7, &sMasterConfig) != HAL_OK)
|
|||
|
{
|
|||
|
Error_Handler();
|
|||
|
}
|
|||
|
/* USER CODE BEGIN TIM7_Init 2 */
|
|||
|
HAL_TIM_Base_Start_IT(&htim7);
|
|||
|
/* USER CODE END TIM7_Init 2 */
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle)
|
|||
|
{
|
|||
|
|
|||
|
if(tim_baseHandle->Instance==TIM7)
|
|||
|
{
|
|||
|
/* USER CODE BEGIN TIM7_MspInit 0 */
|
|||
|
|
|||
|
/* USER CODE END TIM7_MspInit 0 */
|
|||
|
/* TIM7 clock enable */
|
|||
|
__HAL_RCC_TIM7_CLK_ENABLE();
|
|||
|
|
|||
|
/* TIM7 interrupt Init */
|
|||
|
HAL_NVIC_SetPriority(TIM7_IRQn, 2, 0);
|
|||
|
HAL_NVIC_EnableIRQ(TIM7_IRQn);
|
|||
|
/* USER CODE BEGIN TIM7_MspInit 1 */
|
|||
|
|
|||
|
/* USER CODE END TIM7_MspInit 1 */
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* tim_baseHandle)
|
|||
|
{
|
|||
|
|
|||
|
if(tim_baseHandle->Instance==TIM7)
|
|||
|
{
|
|||
|
/* USER CODE BEGIN TIM7_MspDeInit 0 */
|
|||
|
|
|||
|
/* USER CODE END TIM7_MspDeInit 0 */
|
|||
|
/* Peripheral clock disable */
|
|||
|
__HAL_RCC_TIM7_CLK_DISABLE();
|
|||
|
|
|||
|
/* TIM7 interrupt Deinit */
|
|||
|
HAL_NVIC_DisableIRQ(TIM7_IRQn);
|
|||
|
/* USER CODE BEGIN TIM7_MspDeInit 1 */
|
|||
|
|
|||
|
/* USER CODE END TIM7_MspDeInit 1 */
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
/* USER CODE BEGIN 1 */
|
|||
|
/* USER CODE BEGIN 1 */
|
|||
|
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
|
|||
|
{
|
|||
|
if((uint32_t) htim->Instance == TIM7_SOURCE) //TIM2_IRQs every 1024 Hz
|
|||
|
{
|
|||
|
__HAL_TIM_CLEAR_IT(htim, TIM_IT_UPDATE);
|
|||
|
|
|||
|
|
|||
|
/* if(timerUPER)
|
|||
|
{
|
|||
|
timerUPER--;
|
|||
|
if(!timerUPER)
|
|||
|
{
|
|||
|
HAL_GPIO_WritePin(GPIOA, PER_Pin, GPIO_PIN_RESET);
|
|||
|
AMP_STATUS &= ~UPER_Pin;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
if(timerOP)
|
|||
|
{
|
|||
|
timerOP--;
|
|||
|
if(!timerOP)
|
|||
|
AMP_STATUS &= ~OP_Pin;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
if(timerKZ)
|
|||
|
{
|
|||
|
timerKZ--;
|
|||
|
if(!timerKZ)
|
|||
|
AMP_STATUS &= ~KZ_Pin;
|
|||
|
}*/
|
|||
|
}
|
|||
|
}
|
|||
|
/* USER CODE END 1 */
|
|||
|
|
|||
|
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|