create new proj

This commit is contained in:
2025-08-22 14:51:02 +03:00
parent 3c669a811a
commit 4bf3fcd9ce
105 changed files with 4543 additions and 27334 deletions

View File

@@ -6,13 +6,12 @@
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2022 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.
*
******************************************************************************
*/
@@ -27,19 +26,16 @@
/* 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 */
FLAG flag;
/* USER CODE END PTD */
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */
/* Private macro -------------------------------------------------------------*/
@@ -51,9 +47,6 @@ FLAG flag;
/* USER CODE BEGIN PV */
static long Falling_asleep;
uint8_t CanGO=0, timGo=0;
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
@@ -65,24 +58,6 @@ void SystemClock_Config(void);
/* 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 */
/**
@@ -94,11 +69,6 @@ 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--------------------------------------------------------*/
@@ -107,7 +77,7 @@ int main(void)
HAL_Init();
/* USER CODE BEGIN Init */
MX_IWDG_Init();
/* USER CODE END Init */
/* Configure the system clock */
@@ -124,302 +94,16 @@ int main(void)
MX_IWDG_Init();
/* USER CODE BEGIN 2 */
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 */
/* Infinite loop */
/* 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;
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;
}
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;
} } }
while (1)
{
/* 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)
IWDG->KR = 0xAAAA;//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 =!blink_over;
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 */
}