iwdg correct
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file can.c
|
||||
@@ -6,17 +7,16 @@
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2025 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
* Copyright (c) 2025 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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
|
||||
* 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 "can.h"
|
||||
|
||||
@@ -175,8 +175,8 @@ void HAL_CAN_MspDeInit(CAN_HandleTypeDef* canHandle)
|
||||
|
||||
void Setup_CAN_addr(uint8_t mode)
|
||||
{
|
||||
BC_box_ID = 0x1F<<20;
|
||||
RX_box_ID = mode<<20;
|
||||
BC_box_ID = 0x9F<<20;
|
||||
RX_box_ID = (0x80+mode)<<20;
|
||||
TX_box_ID = RX_box_ID | (1L<<28);
|
||||
}
|
||||
|
||||
@@ -271,5 +271,3 @@ int CAN_send(uint16_t data[], int Addr, int Qua)
|
||||
} }
|
||||
|
||||
/* USER CODE END 1 */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file gpio.c
|
||||
@@ -6,16 +7,16 @@
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2025 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
* Copyright (c) 2025 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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
|
||||
* 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 "gpio.h"
|
||||
@@ -45,38 +46,51 @@ void MX_GPIO_Init(void)
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
|
||||
// INPUT C
|
||||
GPIO_InitStruct.Pin = IN_06_Pin|Jselect_Pin|IN_05_Pin|J2_Pin|J3_Pin;
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(GPIOC, LED1_Pin|LED2_Pin|PVT4_Pin|PVT3_Pin
|
||||
|PVT2_Pin|PVT1_Pin, GPIO_PIN_RESET);
|
||||
|
||||
/*Configure GPIO pins : PCPin PCPin PCPin PC0
|
||||
PC1 PCPin PCPin */
|
||||
GPIO_InitStruct.Pin = IN_06_Pin|SELEKT_PCH_Pin|IN_05_Pin|GPIO_PIN_0
|
||||
|GPIO_PIN_1|J1_Pin|J2_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
||||
|
||||
// OUTPUT C
|
||||
GPIO_InitStruct.Pin = LED2_Pin|LED3_Pin|PVT4_Pin|PVT3_Pin|PVT2_Pin|PVT1_Pin;
|
||||
/*Configure GPIO pins : PD0 PD1 */
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pins : PCPin PCPin PCPin PCPin
|
||||
PCPin PCPin */
|
||||
GPIO_InitStruct.Pin = LED1_Pin|LED2_Pin|PVT4_Pin|PVT3_Pin
|
||||
|PVT2_Pin|PVT1_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
||||
|
||||
// INPUT A
|
||||
GPIO_InitStruct.Pin = IN_04_Pin|IN_03_Pin|IN_02_Pin|IN_01_Pin|IN_14_Pin|IN_13_Pin|J0_Pin|J1_Pin;
|
||||
/*Configure GPIO pins : PAPin PAPin PAPin PAPin
|
||||
PAPin PAPin PA6 PAPin */
|
||||
GPIO_InitStruct.Pin = IN_04_Pin|IN_03_Pin|IN_02_Pin|IN_01_Pin
|
||||
|IN_14_Pin|IN_13_Pin|GPIO_PIN_6|J0_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
// INPUT B
|
||||
GPIO_InitStruct.Pin = IN_12_Pin|IN_11_Pin|IN_10_Pin|IN_09_Pin|IN_08_Pin|IN_07_Pin;
|
||||
/*Configure GPIO pins : PBPin PBPin PBPin PBPin
|
||||
PB11 PBPin PBPin PBPin
|
||||
PBPin */
|
||||
GPIO_InitStruct.Pin = J3_Pin|IN_12_Pin|BOOT1_Pin|IN_11_Pin
|
||||
|GPIO_PIN_11|IN_10_Pin|IN_09_Pin|IN_08_Pin
|
||||
|IN_07_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
|
||||
// OUTPUT B
|
||||
GPIO_InitStruct.Pin = LED0_Pin|LED1_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pin : PA8 */
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_8;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
@@ -91,5 +105,3 @@ void MX_GPIO_Init(void)
|
||||
/* USER CODE BEGIN 2 */
|
||||
|
||||
/* USER CODE END 2 */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
55
Core/Src/iwdg.c
Normal file
55
Core/Src/iwdg.c
Normal file
@@ -0,0 +1,55 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file iwdg.c
|
||||
* @brief This file provides code for the configuration
|
||||
* of the IWDG instances.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2025 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 "iwdg.h"
|
||||
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
IWDG_HandleTypeDef hiwdg;
|
||||
|
||||
/* IWDG init function */
|
||||
void MX_IWDG_Init(void)
|
||||
{
|
||||
|
||||
/* USER CODE BEGIN IWDG_Init 0 */
|
||||
|
||||
/* USER CODE END IWDG_Init 0 */
|
||||
|
||||
/* USER CODE BEGIN IWDG_Init 1 */
|
||||
|
||||
/* USER CODE END IWDG_Init 1 */
|
||||
hiwdg.Instance = IWDG;
|
||||
hiwdg.Init.Prescaler = IWDG_PRESCALER_4;
|
||||
hiwdg.Init.Reload = 4095;
|
||||
if (HAL_IWDG_Init(&hiwdg) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN IWDG_Init 2 */
|
||||
|
||||
/* USER CODE END IWDG_Init 2 */
|
||||
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
void ReadEnteres(void)
|
||||
{
|
||||
WORDE input;
|
||||
WORDE input, alarm, error;
|
||||
|
||||
input.bit.bit0 = !IN_06; // Контроль ИП1 (питание управляющего контроллера)
|
||||
input.bit.bit1 = !IN_05; // Контроль ИП2 (питание периферийных устройств)
|
||||
@@ -32,12 +32,16 @@ void ReadEnteres(void)
|
||||
input.bit.bitD = !IN_14; // Контроль питания СКК
|
||||
*/
|
||||
Inputs.all = input.all;
|
||||
Alarms.all = ~Inputs.all & Alarm_mask.all;
|
||||
Alarms.bit.bit7 = 0; // Заряд накопителя
|
||||
Alarms.bit.bit8 = Inputs.bit.bit8; // Разряд накопителя
|
||||
Alarms.bit.bit9 = Inputs.bit.bit9; // Авария в сети 24 В
|
||||
Errors.all = ~Inputs.all & Error_mask.all;
|
||||
Errors.bit.bit9 = Inputs.bit.bit9; // Авария в сети 24 В
|
||||
|
||||
alarm.all = ~Inputs.all & Alarm_mask.all;
|
||||
alarm.bit.bit7 = 0; // Заряд накопителя
|
||||
alarm.bit.bit8 = Inputs.bit.bit8; // Разряд накопителя
|
||||
alarm.bit.bit9 = Inputs.bit.bit9; // Авария в сети 24 В
|
||||
Alarms = alarm;
|
||||
|
||||
error.all = ~Inputs.all & Error_mask.all;
|
||||
error.bit.bit9 = Inputs.bit.bit9; // Авария в сети 24 В
|
||||
Errors = error;
|
||||
}
|
||||
|
||||
uint16_t ReadJumpers(void)
|
||||
@@ -62,10 +66,21 @@ uint16_t TestJumper(void)
|
||||
void ReadSeanus(void)
|
||||
{
|
||||
static uint32_t cownt=0;
|
||||
static uint32_t sum_u[4]={0,0,0,0};
|
||||
// static float flt_u[4]={0,0,0,0};
|
||||
static uint32_t sum_u[4];
|
||||
static float flt_u[4];
|
||||
static uint8_t Ist=1;
|
||||
uint8_t i;
|
||||
|
||||
if(Ist)
|
||||
{
|
||||
Ist=0;
|
||||
for(i=0;i<4;i++)
|
||||
{
|
||||
Squazh_U[i]=100;
|
||||
flt_u[i]=10000.0;
|
||||
sum_u[i]=0;
|
||||
} }
|
||||
|
||||
sum_u[0] += !IN_11;
|
||||
sum_u[1] += !IN_12;
|
||||
sum_u[2] += !IN_13;
|
||||
@@ -77,8 +92,8 @@ void ReadSeanus(void)
|
||||
|
||||
for(i=0;i<4;i++)
|
||||
{
|
||||
// flt_u[i] +=((float)sum_u[i]-flt_u[i])/10+1;
|
||||
Squazh_U[i]=sum_u[i]/100;
|
||||
flt_u[i] +=((float)sum_u[i]-flt_u[i])/3+1;
|
||||
Squazh_U[i]=flt_u[i]/100;
|
||||
sum_u[i] = 0;
|
||||
} } }
|
||||
|
||||
|
||||
263
Core/Src/main.c
263
Core/Src/main.c
@@ -20,6 +20,7 @@
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "main.h"
|
||||
#include "can.h"
|
||||
#include "iwdg.h"
|
||||
#include "tim.h"
|
||||
#include "gpio.h"
|
||||
|
||||
@@ -34,7 +35,7 @@
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PTD */
|
||||
|
||||
FLAG flag;
|
||||
/* USER CODE END PTD */
|
||||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
@@ -51,7 +52,7 @@
|
||||
/* USER CODE BEGIN PV */
|
||||
|
||||
static long Falling_asleep;
|
||||
int CanGO=0;
|
||||
uint8_t CanGO=0, timGo=0;
|
||||
|
||||
/* USER CODE END PV */
|
||||
|
||||
@@ -64,17 +65,20 @@ void SystemClock_Config(void);
|
||||
/* Private user code ---------------------------------------------------------*/
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
int Isit(int num, int i)
|
||||
int Isit(int num, int i, int z)
|
||||
{
|
||||
int res, pls;
|
||||
|
||||
if((num<0)||(num>=0x80)) return 0;
|
||||
res = Maska[0][num/0x10]; if(i)
|
||||
res|= Maska[1][num/0x10];
|
||||
res = Maska[i][num/0x10];
|
||||
res &= (1<<(num&0x0F));
|
||||
pls = (espero[num]>CanRestart[i]/3);
|
||||
pls = pls || county[num];
|
||||
res = res && pls;
|
||||
|
||||
if(z)
|
||||
{
|
||||
pls = (espero[num]>CanRestart[i]/2);
|
||||
pls = pls || county[num];
|
||||
res = res && pls;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
@@ -87,12 +91,14 @@ int Isit(int num, int i)
|
||||
*/
|
||||
int main(void)
|
||||
{
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
int i,j,n,mask,qua;
|
||||
static int i,j,n,z,mask,qua;
|
||||
static int cancount[2]={1,2},cancell[2]={0,0},candid[2]={0,0};
|
||||
static unsigned int masca[8];
|
||||
|
||||
static uint16_t precom=0;
|
||||
|
||||
/* USER CODE END 1 */
|
||||
|
||||
/* MCU Configuration--------------------------------------------------------*/
|
||||
@@ -101,7 +107,7 @@ int main(void)
|
||||
HAL_Init();
|
||||
|
||||
/* USER CODE BEGIN Init */
|
||||
|
||||
MX_IWDG_Init();
|
||||
/* USER CODE END Init */
|
||||
|
||||
/* Configure the system clock */
|
||||
@@ -115,12 +121,39 @@ int main(void)
|
||||
MX_GPIO_Init();
|
||||
MX_CAN_Init();
|
||||
MX_TIM4_Init();
|
||||
// MX_IWDG_Init();
|
||||
/* USER CODE BEGIN 2 */
|
||||
|
||||
Mode = ReadJumpers();
|
||||
Setup_CAN_addr(Mode);
|
||||
LastMode = Mode;
|
||||
|
||||
LED_0_ON;
|
||||
LED_1_OFF;
|
||||
LED_2_ON;
|
||||
LED_3_OFF;
|
||||
|
||||
for(i=0;i<10;i++)
|
||||
{
|
||||
LED_0_TGL;
|
||||
LED_1_TGL;
|
||||
LED_2_TGL;
|
||||
LED_3_TGL; HAL_Delay(50);
|
||||
}
|
||||
|
||||
Mode = ReadJumpers()+1;
|
||||
Setup_CAN_addr(Mode-1);
|
||||
Load_params();
|
||||
LastMode = Mode;
|
||||
Protokol = PROTOKOL;
|
||||
|
||||
command=0;
|
||||
|
||||
for(i=0;i<0x80;i++)
|
||||
county[i]=1;
|
||||
for(i=0;i<8;i++)
|
||||
masca[i]=0;
|
||||
for(i=0;i<2;i++)
|
||||
CanRound[i]=
|
||||
CanCycle[i]=0;
|
||||
|
||||
timGo=1;
|
||||
|
||||
/* USER CODE END 2 */
|
||||
|
||||
@@ -128,6 +161,13 @@ int main(void)
|
||||
/* USER CODE BEGIN WHILE */
|
||||
while (1)
|
||||
{
|
||||
if (flag.force_pause)
|
||||
{
|
||||
__disable_irq();
|
||||
for(int i=0;i<flag.pause;i++);
|
||||
__enable_irq();
|
||||
}
|
||||
|
||||
if( CanGO)
|
||||
{ CanGO=0;
|
||||
|
||||
@@ -136,6 +176,7 @@ int main(void)
|
||||
|
||||
for(i=0;i<2;i++)
|
||||
if(cancount[i]) cancount[i]--;
|
||||
else cancell[i] = 0;
|
||||
}
|
||||
|
||||
for(i=0;i<2;i++)
|
||||
@@ -151,9 +192,9 @@ int main(void)
|
||||
{ candid[i]=0;
|
||||
CanCycle[i]++;
|
||||
cancount[i] = CanWait[i];
|
||||
continue;
|
||||
} }
|
||||
|
||||
goto Next;
|
||||
} }
|
||||
|
||||
mask = Maska[i][cancell[i]/0x10] >> (cancell[i]&0x0F);
|
||||
if(!mask) cancell[i] = (cancell[i] + 0x10) & 0xFFF0 ;
|
||||
else
|
||||
@@ -165,18 +206,26 @@ int main(void)
|
||||
break;
|
||||
} }
|
||||
|
||||
|
||||
z=1;
|
||||
if(espero[cancell[i]]>CanRestart[i])
|
||||
county[cancell[i]]=1;
|
||||
|
||||
{
|
||||
county[cancell[i]]=1;
|
||||
z=0;
|
||||
}
|
||||
|
||||
if(modbus[cancell[i]] != archiv[cancell[i]])
|
||||
|
||||
county[cancell[i]] = (cancell[i]==keys) ? CanRepeat:1;
|
||||
{
|
||||
if(cancell[i]==keys)
|
||||
for(j=0;j<CanRptLen;j++)
|
||||
county[cancell[i]+j] = CanRptVez;
|
||||
else
|
||||
county[cancell[i]] = 1;
|
||||
}
|
||||
|
||||
if (county[cancell[i]])
|
||||
{
|
||||
for(j= 3; j>0 && !Isit(cancell[i]+j,i); j--);
|
||||
for(n=j-3; n<0 && !Isit(cancell[i]+n,i); n++);
|
||||
for(j= 3; j>0 && !Isit(cancell[i]+j,i,z); j--);
|
||||
for(n=j-3; n<0 && !Isit(cancell[i]+n,i,1); n++);
|
||||
|
||||
qua = 1 + j - n;
|
||||
cancell[i]+= n;
|
||||
@@ -184,8 +233,9 @@ int main(void)
|
||||
for(j=0;j<qua;j++)
|
||||
{
|
||||
n=cancell[i]+j;
|
||||
|
||||
archiv[n]= modbus[n]; espero[n]= 0;
|
||||
archiv[n]= modbus[n];
|
||||
espero[n]= 0;
|
||||
|
||||
if( county[n])
|
||||
{ county[n]--;
|
||||
if(!county[n] && n != cancyclo+i) candid[i]=1;
|
||||
@@ -206,29 +256,35 @@ int main(void)
|
||||
CanRound[i]++;
|
||||
}
|
||||
|
||||
if( Cancount[i]>1)
|
||||
if(!cancount[!i])
|
||||
cancount[!i]=1; // ????? ?? ?????
|
||||
cancount[!i]=1;
|
||||
}
|
||||
else cancell[i]++;
|
||||
}
|
||||
else
|
||||
cancell[i]++;
|
||||
}
|
||||
|
||||
Next:
|
||||
|
||||
ReadEnteres();
|
||||
|
||||
// ReadSeanus();
|
||||
|
||||
if(Alarms.all) Pvt4_OFF; // ñèãíàë "Ñèñòåìà ÂÝÏ â íîðìå"
|
||||
else Pvt4_ON;
|
||||
if(Errors.all|Alarms.all)
|
||||
Pvt4_OFF;
|
||||
else Pvt4_ON; // ñèãíàë "Ñèñòåìà ÂÝÏ â íîðìå"
|
||||
|
||||
if(Errors.all) Pvt3_ON; // ñèãíàë "Àâàðèÿ ñèñòåìû ÂÝÏ"
|
||||
else Pvt3_OFF;
|
||||
|
||||
if(Inputs.bit.bit9) Pvt2_OFF; // ?????? ? ???? 24 ?
|
||||
else Pvt2_ON; // ?????? "?????????? ????? 24?"
|
||||
|
||||
if (Falling_asleep) Pvt2_ON; // Ïîêà íå ñïèì, ýòî çàìêíóòî
|
||||
if(Falling_asleep) Pvt2_ON; // Ïîêà íå ñïèì, ýòî çàìêíóòî
|
||||
else Pvt2_OFF; // ñèãíàë "Óïðàâëåíèå ñåòüþ 24Â"
|
||||
|
||||
|
||||
|
||||
if(Commands!=precom)
|
||||
{
|
||||
command= (~precom|command) & Commands;
|
||||
}
|
||||
precom = Commands;
|
||||
|
||||
if(cDefParam)
|
||||
{
|
||||
cDefParam=0;
|
||||
@@ -245,6 +301,21 @@ int main(void)
|
||||
{
|
||||
cLoadParam=0;
|
||||
Load_params();
|
||||
}
|
||||
|
||||
if(cCanReset)
|
||||
{
|
||||
cCanReset=0;
|
||||
|
||||
for(i=0;i<0x80;i++)
|
||||
county[i]=1;
|
||||
for(i=0;i<2;i++)
|
||||
CanCycle[i]=
|
||||
CanRound[i]=
|
||||
cancount[i]=
|
||||
cancell[i]=0;
|
||||
for(i=0;i<8;i++)
|
||||
masca[i]=0;
|
||||
} } }
|
||||
|
||||
/* USER CODE END WHILE */
|
||||
@@ -263,11 +334,14 @@ void Millisecond()
|
||||
|
||||
#define CANPOWSE 10 // 10 msec
|
||||
#define BLINK_TIME 250 // .25 sec
|
||||
|
||||
if(!cReset)
|
||||
IWDG->KR = 0xAAAA;//HAL_IWDG_Refresh(&hiwdg);
|
||||
|
||||
// ReadSeanus();
|
||||
|
||||
if(!timGo) return;
|
||||
|
||||
Jumpers.byt.byte_1 = ReadJumpers();
|
||||
Jumpers.bit.bit0 = TestJumper();
|
||||
Jumpers.bit.bit0 =
|
||||
Buttons.bit.bit0 = TestJumper();
|
||||
|
||||
if(++CanPowse >= CANPOWSE)
|
||||
@@ -281,24 +355,8 @@ void Millisecond()
|
||||
}
|
||||
else Falling_asleep = 1000L * Sleep_time;
|
||||
|
||||
if(work_diod) LED_2_ON;
|
||||
else LED_2_OFF;
|
||||
|
||||
if(norm_diod) LED_3_ON;
|
||||
else LED_3_OFF;
|
||||
|
||||
TST = TestJumper() | cTestLamp;
|
||||
|
||||
if(++count_bright == 10) //maximum_bright
|
||||
{ count_bright = 0 ;
|
||||
|
||||
if(power_lamp) Pvt1_ON;
|
||||
else Pvt1_OFF;
|
||||
}
|
||||
|
||||
if(count_bright >= Brightness)
|
||||
if(!TST) Pvt1_OFF; //îòêëþ÷åíèå ëàìïî÷êè
|
||||
|
||||
if(TST & !preTest)
|
||||
{
|
||||
count_blink = BLINK_TIME;
|
||||
@@ -315,27 +373,53 @@ void Millisecond()
|
||||
}
|
||||
|
||||
power_lamp= 1;
|
||||
norm_diod= 1;
|
||||
work_diod = 1;
|
||||
norm_diod = 1;
|
||||
work_diod =!blink_over;
|
||||
|
||||
if(TST)
|
||||
{
|
||||
power_lamp= blink_over;
|
||||
norm_diod= blink_over;
|
||||
work_diod= !blink_over;
|
||||
power_lamp = blink_over;
|
||||
norm_diod = blink_over;
|
||||
work_diod = blink_over;
|
||||
}
|
||||
else
|
||||
if(Lightness)
|
||||
{
|
||||
if(Alarms.all)
|
||||
{
|
||||
norm_diod= blink_alarm;
|
||||
power_lamp=blink_alarm;
|
||||
}
|
||||
if(Errors.all)
|
||||
{
|
||||
power_lamp= blink_over;
|
||||
norm_diod= blink_over;
|
||||
} }
|
||||
power_lamp = norm_diod = 0;
|
||||
if(Lightness==2) power_lamp = norm_diod = 1;
|
||||
if(Lightness==3) power_lamp = norm_diod = blink_over;
|
||||
if(Lightness==4) power_lamp = norm_diod = blink_alarm;
|
||||
if(Lightness==5) power_lamp = norm_diod = !blink_alarm;
|
||||
}
|
||||
else
|
||||
if(Errors.all)
|
||||
{
|
||||
power_lamp = blink_over;
|
||||
norm_diod = blink_over;
|
||||
}
|
||||
else
|
||||
if(Alarms.all)
|
||||
{
|
||||
power_lamp = blink_alarm;
|
||||
norm_diod = blink_alarm;
|
||||
}
|
||||
|
||||
if(++count_bright == 10) //maximum_bright
|
||||
{ count_bright = 0 ;
|
||||
|
||||
if(power_lamp) Pvt1_ON;
|
||||
else Pvt1_OFF;
|
||||
}
|
||||
|
||||
if(count_bright == Brightness)
|
||||
if(!TST) Pvt1_OFF; //îòêëþ÷åíèå ëàìïî÷êè
|
||||
|
||||
if(work_diod) LED_2_ON;
|
||||
else LED_2_OFF;
|
||||
|
||||
if(norm_diod) LED_3_ON;
|
||||
else LED_3_OFF;
|
||||
|
||||
/* USER CODE END 3 */
|
||||
}
|
||||
|
||||
@@ -351,16 +435,18 @@ void SystemClock_Config(void)
|
||||
/** Initializes the RCC Oscillators according to the specified parameters
|
||||
* in the RCC_OscInitTypeDef structure.
|
||||
*/
|
||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
|
||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_LSI;
|
||||
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
||||
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
|
||||
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
|
||||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
||||
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI_DIV2;
|
||||
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL10;
|
||||
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL16;
|
||||
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
/** Initializes the CPU, AHB and APB buses clocks
|
||||
*/
|
||||
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
||||
@@ -370,17 +456,38 @@ void SystemClock_Config(void)
|
||||
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
|
||||
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
|
||||
|
||||
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)
|
||||
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
HAL_RCC_MCOConfig(RCC_MCO, RCC_MCO1SOURCE_SYSCLK, RCC_MCODIV_1);
|
||||
HAL_RCC_MCOConfig(RCC_MCO, RCC_MCO1SOURCE_HSI, RCC_MCODIV_1);
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 4 */
|
||||
|
||||
/* USER CODE END 4 */
|
||||
|
||||
/**
|
||||
* @brief Period elapsed callback in non blocking mode
|
||||
* @note This function is called when TIM8 interrupt took place, inside
|
||||
* HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment
|
||||
* a global variable "uwTick" used as application time base.
|
||||
* @param htim : TIM handle
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
|
||||
{
|
||||
/* USER CODE BEGIN Callback 0 */
|
||||
|
||||
/* USER CODE END Callback 0 */
|
||||
if (htim->Instance == TIM8) {
|
||||
HAL_IncTick();
|
||||
}
|
||||
/* USER CODE BEGIN Callback 1 */
|
||||
|
||||
/* USER CODE END Callback 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function is executed in case of error occurrence.
|
||||
* @retval None
|
||||
@@ -412,5 +519,3 @@ void assert_failed(uint8_t *file, uint32_t line)
|
||||
/* USER CODE END 6 */
|
||||
}
|
||||
#endif /* USE_FULL_ASSERT */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
492
Core/Src/main.c.bak
Normal file
492
Core/Src/main.c.bak
Normal file
@@ -0,0 +1,492 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : main.c
|
||||
* @brief : Main program body
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2022 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
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "main.h"
|
||||
#include "can.h"
|
||||
#include "iwdg.h"
|
||||
#include "tim.h"
|
||||
#include "gpio.h"
|
||||
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
#include "package.h"
|
||||
#include "message.h"
|
||||
#include "lampa.h"
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PTD */
|
||||
|
||||
/* USER CODE END PTD */
|
||||
|
||||
/* 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 */
|
||||
|
||||
static long Falling_asleep;
|
||||
uint8_t CanGO=0, timGo=0;
|
||||
|
||||
/* USER CODE END PV */
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
void SystemClock_Config(void);
|
||||
/* USER CODE BEGIN PFP */
|
||||
|
||||
/* USER CODE END PFP */
|
||||
|
||||
/* Private user code ---------------------------------------------------------*/
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
int Isit(int num, int i, int z)
|
||||
{
|
||||
int res, pls;
|
||||
|
||||
if((num<0)||(num>=0x80)) return 0;
|
||||
res = Maska[i][num/0x10];
|
||||
res &= (1<<(num&0x0F));
|
||||
|
||||
if(z)
|
||||
{
|
||||
pls = (espero[num]>CanRestart[i]/2);
|
||||
pls = pls || county[num];
|
||||
res = res && pls;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
/**
|
||||
* @brief The application entry point.
|
||||
* @retval int
|
||||
*/
|
||||
int main(void)
|
||||
{
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
static int i,j,n,z,mask,qua;
|
||||
static int cancount[2]={1,2},cancell[2]={0,0},candid[2]={0,0};
|
||||
static unsigned int masca[8];
|
||||
static uint16_t precom=0;
|
||||
|
||||
/* USER CODE END 1 */
|
||||
|
||||
/* MCU Configuration--------------------------------------------------------*/
|
||||
|
||||
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
|
||||
HAL_Init();
|
||||
|
||||
/* USER CODE BEGIN Init */
|
||||
|
||||
/* USER CODE END Init */
|
||||
|
||||
/* Configure the system clock */
|
||||
SystemClock_Config();
|
||||
|
||||
/* USER CODE BEGIN SysInit */
|
||||
|
||||
/* USER CODE END SysInit */
|
||||
|
||||
/* Initialize all configured peripherals */
|
||||
MX_GPIO_Init();
|
||||
MX_CAN_Init();
|
||||
MX_TIM4_Init();
|
||||
/* USER CODE BEGIN 2 */
|
||||
|
||||
LED_0_OFF;
|
||||
LED_1_OFF;
|
||||
LED_2_OFF;
|
||||
LED_3_OFF;
|
||||
|
||||
for(i=0;i<10;i++)
|
||||
{
|
||||
LED_0_TGL; HAL_Delay(15);
|
||||
LED_1_TGL; HAL_Delay(15);
|
||||
LED_2_TGL; HAL_Delay(15);
|
||||
LED_3_TGL; HAL_Delay(15);
|
||||
}
|
||||
|
||||
Mode = ReadJumpers()+1;
|
||||
Setup_CAN_addr(Mode-1);
|
||||
Load_params();
|
||||
LastMode = Mode;
|
||||
Protokol = PROTOKOL;
|
||||
|
||||
command=0;
|
||||
|
||||
for(i=0;i<0x80;i++)
|
||||
county[i]=1;
|
||||
for(i=0;i<8;i++)
|
||||
masca[i]=0;
|
||||
for(i=0;i<2;i++)
|
||||
CanRound[i]=
|
||||
CanCycle[i]=0;
|
||||
|
||||
timGo=1;
|
||||
|
||||
/* USER CODE END 2 */
|
||||
|
||||
/* Infinite loop */
|
||||
/* USER CODE BEGIN WHILE */
|
||||
while (1)
|
||||
{
|
||||
if( CanGO)
|
||||
{ CanGO=0;
|
||||
|
||||
for(i=0;i<0x80;i++)
|
||||
if(espero[i]<30000) espero[i]++;
|
||||
|
||||
for(i=0;i<2;i++)
|
||||
if(cancount[i]) cancount[i]--;
|
||||
else cancell[i] = 0;
|
||||
}
|
||||
|
||||
for(i=0;i<2;i++)
|
||||
if( Cancount[i])
|
||||
if(!cancount[i])
|
||||
{
|
||||
while(1)
|
||||
{
|
||||
if( cancell[i]>= 0x80)
|
||||
{ cancell[i]=0;
|
||||
|
||||
if( candid[i])
|
||||
{ candid[i]=0;
|
||||
CanCycle[i]++;
|
||||
cancount[i] = CanWait[i];
|
||||
goto Next;
|
||||
} }
|
||||
|
||||
mask = Maska[i][cancell[i]/0x10] >> (cancell[i]&0x0F);
|
||||
if(!mask) cancell[i] = (cancell[i] + 0x10) & 0xFFF0 ;
|
||||
else
|
||||
{
|
||||
while(!(mask & 1))
|
||||
{
|
||||
cancell[i]++; mask >>= 1;
|
||||
}
|
||||
break;
|
||||
} }
|
||||
|
||||
z=1;
|
||||
if(espero[cancell[i]]>CanRestart[i])
|
||||
{
|
||||
county[cancell[i]]=1;
|
||||
z=0;
|
||||
}
|
||||
|
||||
if(modbus[cancell[i]] != archiv[cancell[i]])
|
||||
{
|
||||
if(cancell[i]==keys)
|
||||
for(j=0;j<CanRptLen;j++)
|
||||
county[cancell[i]+j] = CanRptVez;
|
||||
else
|
||||
county[cancell[i]] = 1;
|
||||
}
|
||||
|
||||
if (county[cancell[i]])
|
||||
{
|
||||
for(j= 3; j>0 && !Isit(cancell[i]+j,i,z); j--);
|
||||
for(n=j-3; n<0 && !Isit(cancell[i]+n,i,1); n++);
|
||||
|
||||
qua = 1 + j - n;
|
||||
cancell[i]+= n;
|
||||
|
||||
for(j=0;j<qua;j++)
|
||||
{
|
||||
n=cancell[i]+j;
|
||||
archiv[n]= modbus[n];
|
||||
espero[n]= 0;
|
||||
|
||||
if( county[n])
|
||||
{ county[n]--;
|
||||
if(!county[n] && n != cancyclo+i) candid[i]=1;
|
||||
}
|
||||
if(!county[n]) masca[n/0x10] |= (1<<(n&0x0F));
|
||||
}
|
||||
|
||||
CAN_send(archiv,cancell[i],qua);
|
||||
|
||||
cancount[i] = Cancount[i];
|
||||
cancell[i]+=qua;
|
||||
|
||||
for(j=0;j<8;j++)
|
||||
if((masca[j] & Maska[i][j]) != Maska[i][j]) break;
|
||||
if(j==8)
|
||||
{
|
||||
for(j=0;j<8;j++) masca[j]&=~Maska[i][j];
|
||||
CanRound[i]++;
|
||||
}
|
||||
|
||||
if( Cancount[i]>1)
|
||||
if(!cancount[!i])
|
||||
cancount[!i]=1;
|
||||
}
|
||||
else
|
||||
cancell[i]++;
|
||||
}
|
||||
|
||||
Next:
|
||||
|
||||
ReadEnteres();
|
||||
|
||||
if(Errors.all|Alarms.all)
|
||||
Pvt4_OFF;
|
||||
else Pvt4_ON; // ñèãíàë "Ñèñòåìà ÂÝÏ â íîðìå"
|
||||
|
||||
if(Errors.all) Pvt3_ON; // ñèãíàë "Àâàðèÿ ñèñòåìû ÂÝÏ"
|
||||
else Pvt3_OFF;
|
||||
|
||||
if(Falling_asleep) Pvt2_ON; // Ïîêà íå ñïèì, ýòî çàìêíóòî
|
||||
else Pvt2_OFF; // ñèãíàë "Óïðàâëåíèå ñåòüþ 24Â"
|
||||
|
||||
|
||||
if(Commands!=precom)
|
||||
{
|
||||
command= (~precom|command) & Commands;
|
||||
modbus[23]=command;
|
||||
}
|
||||
precom = Commands;
|
||||
|
||||
if(cDefParam)
|
||||
{
|
||||
cDefParam=0;
|
||||
Default_params();
|
||||
}
|
||||
|
||||
if(cSaveParam)
|
||||
{
|
||||
cSaveParam=0;
|
||||
Save_params();
|
||||
}
|
||||
|
||||
if(cLoadParam)
|
||||
{
|
||||
cLoadParam=0;
|
||||
Load_params();
|
||||
}
|
||||
|
||||
if(cCanReset)
|
||||
{
|
||||
cCanReset=0;
|
||||
|
||||
for(i=0;i<0x80;i++)
|
||||
county[i]=1;
|
||||
for(i=0;i<2;i++)
|
||||
CanCycle[i]=
|
||||
CanRound[i]=
|
||||
cancount[i]=
|
||||
cancell[i]=0;
|
||||
for(i=0;i<8;i++)
|
||||
masca[i]=0;
|
||||
} } }
|
||||
|
||||
/* USER CODE END WHILE */
|
||||
|
||||
/* USER CODE BEGIN 3 */
|
||||
|
||||
void Millisecond()
|
||||
{
|
||||
static int CanPowse;
|
||||
|
||||
static unsigned int
|
||||
count_blink=0, count_bright=0, count_mode,
|
||||
blink_over, blink_alarm, power_lamp, work_diod, norm_diod;
|
||||
static int preTest;
|
||||
int TST;
|
||||
|
||||
#define CANPOWSE 10 // 10 msec
|
||||
#define BLINK_TIME 250 // .25 sec
|
||||
|
||||
if(!cReset)
|
||||
HAL_IWDG_Refresh(&hiwdg);
|
||||
|
||||
if(!timGo) return;
|
||||
|
||||
Jumpers.byt.byte_1 = ReadJumpers();
|
||||
Jumpers.bit.bit0 =
|
||||
Buttons.bit.bit0 = TestJumper();
|
||||
|
||||
if(++CanPowse >= CANPOWSE)
|
||||
{
|
||||
CanPowse = 0; CanGO = 1;
|
||||
}
|
||||
|
||||
if(Alarms.bit.bit8) // Ðàçðÿä áàòàðåè
|
||||
{
|
||||
if (Falling_asleep) Falling_asleep--;
|
||||
}
|
||||
else Falling_asleep = 1000L * Sleep_time;
|
||||
|
||||
TST = TestJumper() | cTestLamp;
|
||||
|
||||
if(TST & !preTest)
|
||||
{
|
||||
count_blink = BLINK_TIME;
|
||||
count_mode = 0;
|
||||
}
|
||||
preTest = TST;
|
||||
|
||||
if(++count_blink >= BLINK_TIME)
|
||||
{
|
||||
count_blink=0;
|
||||
count_mode++;
|
||||
blink_over = (count_mode & 1)?1:0;
|
||||
blink_alarm = (count_mode & 7)?1:0;
|
||||
}
|
||||
|
||||
power_lamp= 1;
|
||||
norm_diod= 1;
|
||||
work_diod = 1;
|
||||
|
||||
if(TST)
|
||||
{
|
||||
power_lamp = blink_over;
|
||||
norm_diod = blink_over;
|
||||
work_diod =!blink_over;
|
||||
}
|
||||
else
|
||||
if(Lightness)
|
||||
{
|
||||
power_lamp = norm_diod = 0;
|
||||
if(Lightness==2) power_lamp = norm_diod = 1;
|
||||
if(Lightness==3) power_lamp = norm_diod = blink_over;
|
||||
if(Lightness==4) power_lamp = norm_diod = blink_alarm;
|
||||
if(Lightness==5) power_lamp = norm_diod = !blink_alarm;
|
||||
}
|
||||
else
|
||||
if(Errors.all)
|
||||
{
|
||||
power_lamp = blink_over;
|
||||
norm_diod = blink_over;
|
||||
}
|
||||
else
|
||||
if(Alarms.all)
|
||||
{
|
||||
power_lamp = blink_alarm;
|
||||
norm_diod = blink_alarm;
|
||||
}
|
||||
|
||||
if(++count_bright == 10) //maximum_bright
|
||||
{ count_bright = 0 ;
|
||||
|
||||
if(power_lamp) Pvt1_ON;
|
||||
else Pvt1_OFF;
|
||||
}
|
||||
|
||||
if(count_bright == Brightness)
|
||||
if(!TST) Pvt1_OFF; //îòêëþ÷åíèå ëàìïî÷êè
|
||||
|
||||
if(work_diod) LED_2_ON;
|
||||
else LED_2_OFF;
|
||||
|
||||
if(norm_diod) LED_3_ON;
|
||||
else LED_3_OFF;
|
||||
|
||||
/* USER CODE END 3 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief System Clock Configuration
|
||||
* @retval None
|
||||
*/
|
||||
void SystemClock_Config(void)
|
||||
{
|
||||
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
||||
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
||||
|
||||
/** Initializes the RCC Oscillators according to the specified parameters
|
||||
* in the RCC_OscInitTypeDef structure.
|
||||
*/
|
||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
|
||||
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
||||
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
|
||||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
||||
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI_DIV2;
|
||||
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL10;
|
||||
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/** Initializes the CPU, AHB and APB buses clocks
|
||||
*/
|
||||
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
||||
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
|
||||
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
||||
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
||||
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
|
||||
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
|
||||
|
||||
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
HAL_RCC_MCOConfig(RCC_MCO, RCC_MCO1SOURCE_SYSCLK, RCC_MCODIV_1);
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 4 */
|
||||
|
||||
/* USER CODE END 4 */
|
||||
|
||||
/**
|
||||
* @brief This function is executed in case of error occurrence.
|
||||
* @retval None
|
||||
*/
|
||||
void Error_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN Error_Handler_Debug */
|
||||
/* User can add his own implementation to report the HAL error return state */
|
||||
__disable_irq();
|
||||
while (1)
|
||||
{
|
||||
}
|
||||
/* USER CODE END Error_Handler_Debug */
|
||||
}
|
||||
|
||||
#ifdef USE_FULL_ASSERT
|
||||
/**
|
||||
* @brief Reports the name of the source file and the source line number
|
||||
* where the assert_param error has occurred.
|
||||
* @param file: pointer to the source file name
|
||||
* @param line: assert_param error line source number
|
||||
* @retval None
|
||||
*/
|
||||
void assert_failed(uint8_t *file, uint32_t line)
|
||||
{
|
||||
/* USER CODE BEGIN 6 */
|
||||
/* User can add his own implementation to report the file name and line number,
|
||||
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
||||
/* USER CODE END 6 */
|
||||
}
|
||||
#endif /* USE_FULL_ASSERT */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
@@ -20,6 +20,7 @@ void Init_packMask(void);
|
||||
|
||||
uint16_t Maska[2][8];
|
||||
|
||||
|
||||
void Default_params()
|
||||
{
|
||||
unsigned int i;
|
||||
@@ -41,7 +42,7 @@ void Default_params()
|
||||
|
||||
LastMode = Mode;
|
||||
|
||||
Sleep_time = 60; // минута чтобы отклюиться
|
||||
Sleep_time = 60; // минута чтобы отключиться
|
||||
|
||||
Cancount[m_FAST] = 5; // * 10msec, пауза между посылками CAN
|
||||
Cancount[m_SLOW] = 100; // * 10msec, пауза между посылками CAN
|
||||
@@ -52,9 +53,10 @@ void Default_params()
|
||||
CanRestart[m_FAST] = 500; // * 10msec, перезапуск посылки
|
||||
CanRestart[m_SLOW] = 1000; // * 10msec, перезапуск посылки
|
||||
|
||||
CanRepeat = 3; // сколько раз повторять надо
|
||||
|
||||
Brightness = 9;
|
||||
CanRptVez = 3; // кол-во повторений посылки «keys»
|
||||
CanRptLen = 3; // длина повтораемой посылки «keys»
|
||||
|
||||
Brightness = 10;
|
||||
|
||||
Protokol = PROTOKOL;
|
||||
}
|
||||
@@ -113,17 +115,12 @@ void Init_packMask()
|
||||
}
|
||||
|
||||
Maska[m_FAST][0]|= 0x0007; // Дискретные входы, неисправности и аварии
|
||||
|
||||
Maska[m_SLOW][0]|= 0x0300; // Маски на неисправности и аварии
|
||||
Maska[m_SLOW][1]|= 0x0003; // Состояние джамперов
|
||||
Maska[m_SLOW][2]|= 0x000F; // Скважность датчика напряжения
|
||||
Maska[m_SLOW][1]|= 0x0F00; // Скважность датчика напряжения
|
||||
Maska[m_SLOW][3]|= 0x000F; // Аварийная уставка скважности
|
||||
Maska[m_SLOW][4]|= 0x0100; // Время автоматического отключения
|
||||
|
||||
Maska[m_SLOW][6]|= 0x0007; // Яркость ламп и периоды посылок
|
||||
Maska[m_SLOW][7]|= 0xE000; // Адрес, команды, и чтоб не вылазило
|
||||
|
||||
Maska[m_SLOW][6]|= 0x017F; // Яркость лампы и периоды посылок
|
||||
Maska[m_SLOW][6]|= 0x05FF; // Яркость лампы и периоды посылок
|
||||
Maska[m_FAST][7]|= 0x0100; // Счетчик посылок
|
||||
Maska[m_SLOW][7]|= 0x0E00; // Счетчик посылок
|
||||
Maska[m_SLOW][7]|= 0xE000; // Протокол, адрес, команды
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
@@ -63,6 +64,7 @@
|
||||
*/
|
||||
void HAL_MspInit(void)
|
||||
{
|
||||
|
||||
/* USER CODE BEGIN MspInit 0 */
|
||||
|
||||
/* USER CODE END MspInit 0 */
|
||||
@@ -72,9 +74,9 @@ void HAL_MspInit(void)
|
||||
|
||||
/* System interrupt init*/
|
||||
|
||||
/** ENABLE: Full SWJ (JTAG-DP + SW-DP): Reset State
|
||||
/** NONJTRST: Full SWJ (JTAG-DP + SW-DP) but without NJTRST
|
||||
*/
|
||||
__HAL_AFIO_REMAP_SWJ_ENABLE();
|
||||
__HAL_AFIO_REMAP_SWJ_NONJTRST();
|
||||
|
||||
/* USER CODE BEGIN MspInit 1 */
|
||||
|
||||
@@ -84,5 +86,3 @@ void HAL_MspInit(void)
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
127
Core/Src/stm32f1xx_hal_timebase_tim.c
Normal file
127
Core/Src/stm32f1xx_hal_timebase_tim.c
Normal file
@@ -0,0 +1,127 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32f1xx_hal_timebase_tim.c
|
||||
* @brief HAL time base based on the hardware TIM.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2025 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 "stm32f1xx_hal.h"
|
||||
#include "stm32f1xx_hal_tim.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
TIM_HandleTypeDef htim8;
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
void TIM8_IRQHandler(void);
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @brief This function configures the TIM8 as a time base source.
|
||||
* The time source is configured to have 1ms time base with a dedicated
|
||||
* Tick interrupt priority.
|
||||
* @note This function is called automatically at the beginning of program after
|
||||
* reset by HAL_Init() or at any time when clock is configured, by HAL_RCC_ClockConfig().
|
||||
* @param TickPriority: Tick interrupt priority.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
|
||||
{
|
||||
RCC_ClkInitTypeDef clkconfig;
|
||||
uint32_t uwTimclock = 0U;
|
||||
|
||||
uint32_t uwPrescalerValue = 0U;
|
||||
uint32_t pFLatency;
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
|
||||
/* Enable TIM8 clock */
|
||||
__HAL_RCC_TIM8_CLK_ENABLE();
|
||||
/* Get clock configuration */
|
||||
HAL_RCC_GetClockConfig(&clkconfig, &pFLatency);
|
||||
/* Compute TIM8 clock */
|
||||
uwTimclock = 2*HAL_RCC_GetPCLK2Freq();
|
||||
|
||||
/* Compute the prescaler value to have TIM8 counter clock equal to 1MHz */
|
||||
uwPrescalerValue = (uint32_t) ((uwTimclock / 1000000U) - 1U);
|
||||
|
||||
/* Initialize TIM8 */
|
||||
htim8.Instance = TIM8;
|
||||
|
||||
/* Initialize TIMx peripheral as follow:
|
||||
|
||||
+ Period = [(TIM8CLK/1000) - 1]. to have a (1/1000) s time base.
|
||||
+ Prescaler = (uwTimclock/1000000 - 1) to have a 1MHz counter clock.
|
||||
+ ClockDivision = 0
|
||||
+ Counter direction = Up
|
||||
*/
|
||||
htim8.Init.Period = (1000000U / 1000U) - 1U;
|
||||
htim8.Init.Prescaler = uwPrescalerValue;
|
||||
htim8.Init.ClockDivision = 0;
|
||||
htim8.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||
htim8.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
||||
|
||||
status = HAL_TIM_Base_Init(&htim8);
|
||||
if (status == HAL_OK)
|
||||
{
|
||||
/* Start the TIM time Base generation in interrupt mode */
|
||||
status = HAL_TIM_Base_Start_IT(&htim8);
|
||||
if (status == HAL_OK)
|
||||
{
|
||||
/* Enable the TIM8 global Interrupt */
|
||||
HAL_NVIC_EnableIRQ(TIM8_UP_IRQn);
|
||||
/* Configure the SysTick IRQ priority */
|
||||
if (TickPriority < (1UL << __NVIC_PRIO_BITS))
|
||||
{
|
||||
/* Configure the TIM IRQ priority */
|
||||
HAL_NVIC_SetPriority(TIM8_UP_IRQn, TickPriority, 0U);
|
||||
uwTickPrio = TickPriority;
|
||||
}
|
||||
else
|
||||
{
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Return function status */
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Suspend Tick increment.
|
||||
* @note Disable the tick increment by disabling TIM8 update interrupt.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_SuspendTick(void)
|
||||
{
|
||||
/* Disable TIM8 update Interrupt */
|
||||
__HAL_TIM_DISABLE_IT(&htim8, TIM_IT_UPDATE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Resume Tick increment.
|
||||
* @note Enable the tick increment by Enabling TIM8 update interrupt.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_ResumeTick(void)
|
||||
{
|
||||
/* Enable TIM8 Update interrupt */
|
||||
__HAL_TIM_ENABLE_IT(&htim8, TIM_IT_UPDATE);
|
||||
}
|
||||
|
||||
@@ -58,6 +58,8 @@
|
||||
/* External variables --------------------------------------------------------*/
|
||||
extern CAN_HandleTypeDef hcan;
|
||||
extern TIM_HandleTypeDef htim4;
|
||||
extern TIM_HandleTypeDef htim8;
|
||||
|
||||
/* USER CODE BEGIN EV */
|
||||
|
||||
/* USER CODE END EV */
|
||||
@@ -187,9 +189,9 @@ void SysTick_Handler(void)
|
||||
/* USER CODE BEGIN SysTick_IRQn 0 */
|
||||
|
||||
/* USER CODE END SysTick_IRQn 0 */
|
||||
HAL_IncTick();
|
||||
|
||||
/* USER CODE BEGIN SysTick_IRQn 1 */
|
||||
Millisecond();
|
||||
|
||||
/* USER CODE END SysTick_IRQn 1 */
|
||||
}
|
||||
|
||||
@@ -242,7 +244,20 @@ void TIM4_IRQHandler(void)
|
||||
/* USER CODE END TIM4_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles TIM8 update interrupt.
|
||||
*/
|
||||
void TIM8_UP_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN TIM8_UP_IRQn 0 */
|
||||
|
||||
/* USER CODE END TIM8_UP_IRQn 0 */
|
||||
HAL_TIM_IRQHandler(&htim8);
|
||||
/* USER CODE BEGIN TIM8_UP_IRQn 1 */
|
||||
Millisecond();
|
||||
/* USER CODE END TIM8_UP_IRQn 1 */
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file tim.c
|
||||
@@ -6,17 +7,16 @@
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2025 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
* Copyright (c) 2025 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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
|
||||
* 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 "tim.h"
|
||||
|
||||
@@ -45,9 +45,9 @@ void MX_TIM4_Init(void)
|
||||
htim4.Instance = TIM4;
|
||||
htim4.Init.Prescaler = 0;
|
||||
htim4.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||
htim4.Init.Period = 799;
|
||||
htim4.Init.Period = 4000;
|
||||
htim4.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||
htim4.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
|
||||
htim4.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
||||
if (HAL_TIM_Base_Init(&htim4) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
@@ -114,16 +114,14 @@ void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* tim_baseHandle)
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
|
||||
{
|
||||
//void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
|
||||
//{
|
||||
|
||||
if(htim->Instance == TIM4) //check if the interrupt comes from TIM1
|
||||
// if(htim->Instance == TIM4) //check if the interrupt comes from TIM1
|
||||
|
||||
ReadSeanus();
|
||||
|
||||
}
|
||||
// ReadSeanus();
|
||||
//
|
||||
//}
|
||||
|
||||
|
||||
/* USER CODE END 1 */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
Reference in New Issue
Block a user