iwdg correct
This commit is contained in:
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****/
|
||||
|
||||
Reference in New Issue
Block a user