create new proj
This commit is contained in:
147
Core/Src/can.c
147
Core/Src/can.c
@@ -22,29 +22,6 @@
|
||||
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
#include "gpio.h"
|
||||
#include "message.h"
|
||||
|
||||
void CAN_filterConfig(void);
|
||||
|
||||
CAN_TxHeaderTypeDef TxHeader;
|
||||
CAN_RxHeaderTypeDef RxHeader;
|
||||
|
||||
CAN_FilterTypeDef sFilterConfig;
|
||||
|
||||
CAN_TxHeaderTypeDef msgHeaderSend;
|
||||
uint8_t msgDataSend[8];
|
||||
uint32_t mailBoxNum = 0;
|
||||
|
||||
uint8_t TxData[8];
|
||||
uint8_t RxData[8];
|
||||
uint32_t TxMailbox;
|
||||
|
||||
uint32_t TX_box_ID = 0;
|
||||
uint32_t RX_box_ID = 0;
|
||||
uint32_t BC_box_ID = 0;
|
||||
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
CAN_HandleTypeDef hcan;
|
||||
@@ -61,7 +38,7 @@ void MX_CAN_Init(void)
|
||||
|
||||
/* USER CODE END CAN_Init 1 */
|
||||
hcan.Instance = CAN1;
|
||||
hcan.Init.Prescaler = 10;
|
||||
hcan.Init.Prescaler = 16;
|
||||
hcan.Init.Mode = CAN_MODE_NORMAL;
|
||||
hcan.Init.SyncJumpWidth = CAN_SJW_1TQ;
|
||||
hcan.Init.TimeSeg1 = CAN_BS1_13TQ;
|
||||
@@ -77,31 +54,6 @@ void MX_CAN_Init(void)
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN CAN_Init 2 */
|
||||
|
||||
CAN_filterConfig();
|
||||
|
||||
msgHeaderSend.StdId = 0x200;
|
||||
msgHeaderSend.ExtId = TX_box_ID;
|
||||
msgHeaderSend.DLC = 8;
|
||||
msgHeaderSend.TransmitGlobalTime = DISABLE;
|
||||
msgHeaderSend.RTR = CAN_RTR_DATA;
|
||||
msgHeaderSend.IDE = CAN_ID_EXT;
|
||||
|
||||
// CAN start
|
||||
if (HAL_CAN_Start(&hcan) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
// CAN notifications (interrupts)
|
||||
if (HAL_CAN_ActivateNotification(&hcan, CAN_IT_RX_FIFO0_MSG_PENDING | CAN_IT_TX_MAILBOX_EMPTY) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* USER CODE END CAN_Init 2 */
|
||||
|
||||
@@ -173,101 +125,4 @@ void HAL_CAN_MspDeInit(CAN_HandleTypeDef* canHandle)
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
void Setup_CAN_addr(uint8_t mode)
|
||||
{
|
||||
BC_box_ID = 0x9F<<20;
|
||||
RX_box_ID = (0x80+mode)<<20;
|
||||
TX_box_ID = RX_box_ID | (1L<<28);
|
||||
}
|
||||
|
||||
void CAN_filterConfig(void)
|
||||
{
|
||||
|
||||
sFilterConfig.FilterBank = 0;
|
||||
sFilterConfig.FilterMode = CAN_FILTERMODE_IDMASK;
|
||||
sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;
|
||||
sFilterConfig.FilterIdHigh = 0x0000;
|
||||
sFilterConfig.FilterIdLow = 0x0000;
|
||||
sFilterConfig.FilterMaskIdHigh = 0x0000;
|
||||
sFilterConfig.FilterMaskIdLow = 0x0000;
|
||||
sFilterConfig.FilterFIFOAssignment = CAN_RX_FIFO0;
|
||||
sFilterConfig.FilterActivation = ENABLE;
|
||||
sFilterConfig.SlaveStartFilterBank = 14;
|
||||
|
||||
if (HAL_CAN_ConfigFilter(&hcan, &sFilterConfig) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
} }
|
||||
|
||||
void HAL_CAN_TxMailbox0CompleteCallback(CAN_HandleTypeDef *hcan)
|
||||
{
|
||||
// HAL_GPIO_TogglePin(LED_2_GPIO_Port, LED_2_Pin);
|
||||
}
|
||||
|
||||
|
||||
void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan_i)
|
||||
{
|
||||
CAN_RxHeaderTypeDef msgHeader;
|
||||
uint8_t msgData[8];
|
||||
|
||||
unsigned int adr,qua;
|
||||
unsigned short Data[4];
|
||||
|
||||
if (HAL_CAN_GetRxMessage(hcan_i, CAN_RX_FIFO0, &msgHeader, msgData) != HAL_OK)
|
||||
{
|
||||
/* Reception Error */
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
if((msgHeader.ExtId & 0xFF00000) != RX_box_ID)
|
||||
if((msgHeader.ExtId & 0xFF00000) != BC_box_ID) return;
|
||||
|
||||
adr = msgHeader.ExtId & 0xFFFF;
|
||||
qua = msgHeader.DLC/2;
|
||||
|
||||
Data[0] = msgData[0]; Data[0] = (Data[0]<<8) | msgData[1];
|
||||
Data[1] = msgData[2]; Data[1] = (Data[1]<<8) | msgData[3];
|
||||
Data[2] = msgData[4]; Data[2] = (Data[2]<<8) | msgData[5];
|
||||
Data[3] = msgData[6]; Data[3] = (Data[3]<<8) | msgData[7];
|
||||
|
||||
if(qua ) if(adr < Modbus_LEN) modbus[adr] = Data[0]; adr++;
|
||||
if(qua>1) if(adr < Modbus_LEN) modbus[adr] = Data[1]; adr++;
|
||||
if(qua>2) if(adr < Modbus_LEN) modbus[adr] = Data[2]; adr++;
|
||||
if(qua>3) if(adr < Modbus_LEN) modbus[adr] = Data[3];
|
||||
|
||||
LED_1_TGL;
|
||||
}
|
||||
|
||||
int CAN_send(uint16_t data[], int Addr, int Qua)
|
||||
{
|
||||
int wait = 1000;
|
||||
|
||||
while(wait-- && (HAL_CAN_GetTxMailboxesFreeLevel(&hcan) == 0));
|
||||
|
||||
if (HAL_CAN_GetTxMailboxesFreeLevel(&hcan) != 0)
|
||||
{
|
||||
msgHeaderSend.ExtId = TX_box_ID | (Addr & 0xFFFF);
|
||||
msgHeaderSend.DLC = Qua*2;
|
||||
|
||||
msgDataSend[0] = (data[Addr ]>>8) & 0x00ff;
|
||||
msgDataSend[1] = (data[Addr ] ) & 0x00ff;
|
||||
msgDataSend[2] = (data[Addr+1]>>8) & 0x00ff;
|
||||
msgDataSend[3] = (data[Addr+1] ) & 0x00ff;
|
||||
msgDataSend[4] = (data[Addr+2]>>8) & 0x00ff;
|
||||
msgDataSend[5] = (data[Addr+2] ) & 0x00ff;
|
||||
msgDataSend[6] = (data[Addr+3]>>8) & 0x00ff;
|
||||
msgDataSend[7] = (data[Addr+3] ) & 0x00ff;
|
||||
|
||||
HAL_CAN_AddTxMessage(&hcan, &msgHeaderSend, msgDataSend, &mailBoxNum);
|
||||
|
||||
LED_0_TGL;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
HAL_CAN_Stop(&hcan);
|
||||
HAL_CAN_Start(&hcan);
|
||||
return 0;
|
||||
} }
|
||||
|
||||
/* USER CODE END 1 */
|
||||
|
||||
196
Core/Src/crc16.c
196
Core/Src/crc16.c
@@ -1,196 +0,0 @@
|
||||
#include "crc16.h"
|
||||
#define MAKE_TABS 0 /* Builds tables below */
|
||||
#define FAST_CRC 1 /* If fast CRC should be used */
|
||||
#define ONLY_CRC16 1
|
||||
|
||||
#define Poln 0xA001
|
||||
|
||||
|
||||
#if FAST_CRC & !MAKE_TABS
|
||||
|
||||
#if !ONLY_CRC16
|
||||
|
||||
static WORD crc_ccitt_tab[] = {
|
||||
0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7,
|
||||
0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef,
|
||||
0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6,
|
||||
0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de,
|
||||
0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485,
|
||||
0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d,
|
||||
0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4,
|
||||
0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc,
|
||||
0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823,
|
||||
0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b,
|
||||
0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12,
|
||||
0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a,
|
||||
0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41,
|
||||
0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49,
|
||||
0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70,
|
||||
0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78,
|
||||
0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f,
|
||||
0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067,
|
||||
0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e,
|
||||
0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256,
|
||||
0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d,
|
||||
0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
|
||||
0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c,
|
||||
0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634,
|
||||
0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab,
|
||||
0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3,
|
||||
0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a,
|
||||
0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92,
|
||||
0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9,
|
||||
0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1,
|
||||
0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8,
|
||||
0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0
|
||||
};
|
||||
#endif
|
||||
|
||||
WORD crc_16_tab[] = {
|
||||
0x0000, 0xc0c1, 0xc181, 0x0140, 0xc301, 0x03c0, 0x0280, 0xc241,
|
||||
0xc601, 0x06c0, 0x0780, 0xc741, 0x0500, 0xc5c1, 0xc481, 0x0440,
|
||||
0xcc01, 0x0cc0, 0x0d80, 0xcd41, 0x0f00, 0xcfc1, 0xce81, 0x0e40,
|
||||
0x0a00, 0xcac1, 0xcb81, 0x0b40, 0xc901, 0x09c0, 0x0880, 0xc841,
|
||||
0xd801, 0x18c0, 0x1980, 0xd941, 0x1b00, 0xdbc1, 0xda81, 0x1a40,
|
||||
0x1e00, 0xdec1, 0xdf81, 0x1f40, 0xdd01, 0x1dc0, 0x1c80, 0xdc41,
|
||||
0x1400, 0xd4c1, 0xd581, 0x1540, 0xd701, 0x17c0, 0x1680, 0xd641,
|
||||
0xd201, 0x12c0, 0x1380, 0xd341, 0x1100, 0xd1c1, 0xd081, 0x1040,
|
||||
0xf001, 0x30c0, 0x3180, 0xf141, 0x3300, 0xf3c1, 0xf281, 0x3240,
|
||||
0x3600, 0xf6c1, 0xf781, 0x3740, 0xf501, 0x35c0, 0x3480, 0xf441,
|
||||
0x3c00, 0xfcc1, 0xfd81, 0x3d40, 0xff01, 0x3fc0, 0x3e80, 0xfe41,
|
||||
0xfa01, 0x3ac0, 0x3b80, 0xfb41, 0x3900, 0xf9c1, 0xf881, 0x3840,
|
||||
0x2800, 0xe8c1, 0xe981, 0x2940, 0xeb01, 0x2bc0, 0x2a80, 0xea41,
|
||||
0xee01, 0x2ec0, 0x2f80, 0xef41, 0x2d00, 0xedc1, 0xec81, 0x2c40,
|
||||
0xe401, 0x24c0, 0x2580, 0xe541, 0x2700, 0xe7c1, 0xe681, 0x2640,
|
||||
0x2200, 0xe2c1, 0xe381, 0x2340, 0xe101, 0x21c0, 0x2080, 0xe041,
|
||||
0xa001, 0x60c0, 0x6180, 0xa141, 0x6300, 0xa3c1, 0xa281, 0x6240,
|
||||
0x6600, 0xa6c1, 0xa781, 0x6740, 0xa501, 0x65c0, 0x6480, 0xa441,
|
||||
0x6c00, 0xacc1, 0xad81, 0x6d40, 0xaf01, 0x6fc0, 0x6e80, 0xae41,
|
||||
0xaa01, 0x6ac0, 0x6b80, 0xab41, 0x6900, 0xa9c1, 0xa881, 0x6840,
|
||||
0x7800, 0xb8c1, 0xb981, 0x7940, 0xbb01, 0x7bc0, 0x7a80, 0xba41,
|
||||
0xbe01, 0x7ec0, 0x7f80, 0xbf41, 0x7d00, 0xbdc1, 0xbc81, 0x7c40,
|
||||
0xb401, 0x74c0, 0x7580, 0xb541, 0x7700, 0xb7c1, 0xb681, 0x7640,
|
||||
0x7200, 0xb2c1, 0xb381, 0x7340, 0xb101, 0x71c0, 0x7080, 0xb041,
|
||||
0x5000, 0x90c1, 0x9181, 0x5140, 0x9301, 0x53c0, 0x5280, 0x9241,
|
||||
0x9601, 0x56c0, 0x5780, 0x9741, 0x5500, 0x95c1, 0x9481, 0x5440,
|
||||
0x9c01, 0x5cc0, 0x5d80, 0x9d41, 0x5f00, 0x9fc1, 0x9e81, 0x5e40,
|
||||
0x5a00, 0x9ac1, 0x9b81, 0x5b40, 0x9901, 0x59c0, 0x5880, 0x9841,
|
||||
0x8801, 0x48c0, 0x4980, 0x8941, 0x4b00, 0x8bc1, 0x8a81, 0x4a40,
|
||||
0x4e00, 0x8ec1, 0x8f81, 0x4f40, 0x8d01, 0x4dc0, 0x4c80, 0x8c41,
|
||||
0x4400, 0x84c1, 0x8581, 0x4540, 0x8701, 0x47c0, 0x4680, 0x8641,
|
||||
0x8201, 0x42c0, 0x4380, 0x8341, 0x4100, 0x81c1, 0x8081, 0x4040
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
#if !ONLY_CRC16
|
||||
|
||||
/* CRC-CCITT is based on the polynomial x^16 + x^12 + x^5 + 1. Bits */
|
||||
/* are sent MSB to LSB. */
|
||||
unsigned int get_crc_ccitt(unsigned int crc,unsigned int *buf,unsigned long size )
|
||||
{
|
||||
#if !(FAST_CRC & !MAKE_TABS)
|
||||
register int i;
|
||||
#endif
|
||||
|
||||
while (size--) {
|
||||
#if FAST_CRC & !MAKE_TABS
|
||||
crc = (crc << 8) ^ crc_ccitt_tab[ (crc >> 8) ^ *buf++ ];
|
||||
#else
|
||||
crc ^= (WORD)(*buf++) << 8;
|
||||
for (i = 0; i < 8; i++) {
|
||||
if (crc & 0x8000)
|
||||
crc = (crc << 1) ^ 0x1021;
|
||||
else
|
||||
crc <<= 1;
|
||||
}
|
||||
#endif
|
||||
} return crc;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* CRC-16 is based on the polynomial x^16 + x^15 + x^2 + 1. Bits are */
|
||||
/* sent LSB to MSB. */
|
||||
unsigned int get_crc_16(unsigned int crc,unsigned int *buf,unsigned long size )
|
||||
{
|
||||
#if !(FAST_CRC & !MAKE_TABS)
|
||||
register unsigned int i;
|
||||
register unsigned int ch;
|
||||
#endif
|
||||
|
||||
while (size--) {
|
||||
#if FAST_CRC & !MAKE_TABS
|
||||
|
||||
crc = (crc >> 8) ^ crc_16_tab[ (crc ^ *buf++) & 0xff ];
|
||||
crc = crc & 0xffff;
|
||||
#else
|
||||
ch = *buf++;
|
||||
for (i = 0; i < 8; i++) {
|
||||
if ((crc ^ ch) & 1)
|
||||
crc = (crc >> 1) ^ 0xa001;
|
||||
else
|
||||
crc >>= 1;
|
||||
ch >>= 1;
|
||||
}
|
||||
#endif
|
||||
} return (crc & 0xffff);
|
||||
}
|
||||
|
||||
|
||||
|
||||
unsigned int get_crc_16b(unsigned int crc,unsigned int *buf,unsigned long size )
|
||||
{
|
||||
|
||||
unsigned int x, dword, byte;
|
||||
unsigned long i;
|
||||
|
||||
|
||||
|
||||
for (i = 0; i < size; i++)
|
||||
{
|
||||
x = i % 2;
|
||||
|
||||
dword = buf[i/2];
|
||||
// dword = *buf;
|
||||
|
||||
|
||||
if (x == 0)
|
||||
{
|
||||
byte = ((dword >> 8)&0xFF);
|
||||
}
|
||||
|
||||
if (x == 1)
|
||||
{
|
||||
byte = (dword & 0xFF);
|
||||
}
|
||||
|
||||
crc = (crc >> 8) ^ crc_16_tab[ (crc ^ (byte) ) & 0xff ];
|
||||
crc = crc & 0xffff;
|
||||
|
||||
// crc = crc + ((byte) & 0xff);
|
||||
|
||||
}
|
||||
|
||||
return (crc & 0xffff);
|
||||
}
|
||||
|
||||
int get_crc16(uint16_t *buf, int size )
|
||||
{
|
||||
int crc16,i,j;
|
||||
|
||||
crc16=0xFFFF;
|
||||
for(i=0;i<size;i++)
|
||||
{
|
||||
crc16=crc16^(buf[i]&0xFF);
|
||||
for (j=0;j<8;j++)
|
||||
if(crc16&1) crc16=(crc16>>1)^Poln;
|
||||
else crc16=crc16>>1;
|
||||
|
||||
crc16=crc16^((buf[i]>>8)&0xFF);
|
||||
for (j=0;j<8;j++)
|
||||
if(crc16&1) crc16=(crc16>>1)^Poln;
|
||||
else crc16=crc16>>1;
|
||||
}
|
||||
return crc16;
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
#include "eeprom.h"
|
||||
|
||||
|
||||
void putIntoEeprom(uint16_t lenght, uint16_t* param)
|
||||
{
|
||||
uint32_t adr = FLASH_EEPROM_BASE;
|
||||
//uint32_t p = FLASH_STARTO;
|
||||
HAL_StatusTypeDef flash_ok = HAL_ERROR;
|
||||
|
||||
while(flash_ok != HAL_OK)
|
||||
{flash_ok = HAL_FLASH_Unlock();}
|
||||
|
||||
FLASH_EraseInitTypeDef erase;
|
||||
uint32_t pageError = 0x0;
|
||||
erase.TypeErase = FLASH_TYPEERASE_PAGES;
|
||||
erase.PageAddress = FLASH_EEPROM_BASE;
|
||||
erase.NbPages = 0x01;
|
||||
flash_ok = HAL_FLASHEx_Erase(&erase, &pageError);
|
||||
|
||||
flash_ok = HAL_ERROR;
|
||||
while(flash_ok != HAL_OK)
|
||||
{flash_ok = HAL_FLASH_Lock();}
|
||||
|
||||
|
||||
flash_ok = HAL_ERROR;
|
||||
while(flash_ok != HAL_OK)
|
||||
{flash_ok = HAL_FLASH_Unlock();}
|
||||
|
||||
flash_ok = HAL_ERROR;
|
||||
while(flash_ok != HAL_OK)
|
||||
{
|
||||
for(int i=0; i<(lenght); i++)
|
||||
{
|
||||
flash_ok = HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD, adr, *param);
|
||||
param++;
|
||||
adr += 0x2;
|
||||
}
|
||||
}
|
||||
|
||||
flash_ok = HAL_ERROR;
|
||||
while(flash_ok != HAL_OK)
|
||||
{flash_ok = HAL_FLASH_Lock();}
|
||||
}
|
||||
|
||||
uint16_t watInTheFlash(uint32_t adress)
|
||||
{
|
||||
return (*(uint32_t*) adress);
|
||||
}
|
||||
|
||||
100
Core/Src/lampa.c
100
Core/Src/lampa.c
@@ -1,100 +0,0 @@
|
||||
|
||||
#include "gpio.h"
|
||||
#include "lampa.h"
|
||||
#include "struc.h"
|
||||
#include "message.h"
|
||||
#include "package.h"
|
||||
|
||||
void ReadEnteres(void)
|
||||
{
|
||||
WORDE input, alarm, error;
|
||||
|
||||
input.bit.bit0 = !IN_06; // Контроль ИП1 (питание управляющего контроллера)
|
||||
input.bit.bit1 = !IN_05; // Контроль ИП2 (питание периферийных устройств)
|
||||
input.bit.bit2 = !IN_04; // Контроль ИП3 (питание эл. замков, ламп освещения, УКСИ)
|
||||
input.bit.bit3 = !IN_03; // Контроль ИП4 (питание датчиков тока и напряжения +)
|
||||
input.bit.bit4 = !IN_02; // Контроль ИП5 (питание датчиков тока и напряжения –)
|
||||
input.bit.bit5 = !IN_01; // Контроль ИП6 (питание драйверов)
|
||||
|
||||
input.bit.bit6 = !IN_07; // Контроль 3х фазного 380 В
|
||||
input.bit.bit7 = !IN_08; // Заряд накопителя
|
||||
input.bit.bit8 = !IN_09; // Разряд накопителя
|
||||
input.bit.bit9 = IN_10; // Авария в сети 24 В
|
||||
|
||||
input.bit.bitD = (Squazh_U[3] > Squazh_L[3]);
|
||||
input.bit.bitC = (Squazh_U[2] > Squazh_L[2]);
|
||||
input.bit.bitB = (Squazh_U[1] > Squazh_L[1]);
|
||||
input.bit.bitA = (Squazh_U[0] > Squazh_L[0]);
|
||||
/*
|
||||
input.bit.bitA = !IN_11; // Контроль питания ЛСУ
|
||||
input.bit.bitB = !IN_12; // Контроль питания СВО
|
||||
input.bit.bitC = !IN_13; // резерв
|
||||
input.bit.bitD = !IN_14; // Контроль питания СКК
|
||||
*/
|
||||
Inputs.all = input.all;
|
||||
|
||||
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)
|
||||
{
|
||||
WORDE input;
|
||||
|
||||
input.all = 0;
|
||||
|
||||
input.bit.bit0 = !J0;
|
||||
input.bit.bit1 = !J1;
|
||||
input.bit.bit2 = !J2;
|
||||
input.bit.bit3 = !J3;
|
||||
|
||||
return input.all;
|
||||
}
|
||||
|
||||
uint16_t TestJumper(void)
|
||||
{
|
||||
return !Jselect;
|
||||
}
|
||||
|
||||
void ReadSeanus(void)
|
||||
{
|
||||
static uint32_t cownt=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;
|
||||
sum_u[3] += !IN_14;
|
||||
|
||||
if(++cownt>=10000)
|
||||
{
|
||||
cownt=0;
|
||||
|
||||
for(i=0;i<4;i++)
|
||||
{
|
||||
flt_u[i] +=((float)sum_u[i]-flt_u[i])/3+1;
|
||||
Squazh_U[i]=flt_u[i]/100;
|
||||
sum_u[i] = 0;
|
||||
} } }
|
||||
|
||||
|
||||
338
Core/Src/main.c
338
Core/Src/main.c
@@ -6,13 +6,12 @@
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© 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 */
|
||||
}
|
||||
|
||||
|
||||
@@ -1,492 +0,0 @@
|
||||
/* 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****/
|
||||
@@ -1,129 +0,0 @@
|
||||
#include "stm32f1xx_hal.h"
|
||||
|
||||
#include "struc.h"
|
||||
#include "crc16.h"
|
||||
#include "package.h"
|
||||
#include "message.h"
|
||||
#include "eeprom.h"
|
||||
|
||||
uint16_t params[Modbus_LEN+1],
|
||||
modbus[Modbus_LEN],
|
||||
archiv[Modbus_LEN],
|
||||
county[Modbus_LEN],
|
||||
espero[Modbus_LEN];
|
||||
|
||||
uint16_t Mode;
|
||||
|
||||
LONGE* outputs;
|
||||
|
||||
void Init_packMask(void);
|
||||
|
||||
uint16_t Maska[2][8];
|
||||
|
||||
|
||||
void Default_params()
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
for(i=0;i<Modbus_LEN;i++)
|
||||
{
|
||||
modbus[i] = 0;
|
||||
}
|
||||
|
||||
Alarm_mask.all = 0x3FFF;
|
||||
Alarm_mask.bit.bit7 = 0; // Заряд накопителя
|
||||
Alarm_mask.bit.bitC = 0; // резерв
|
||||
|
||||
Error_mask.all = 0;
|
||||
Error_mask.bit.bit9 = 1; // Авария в сети 24 В
|
||||
|
||||
for(i=0;i<4;i++)
|
||||
Squazh_L[i] = 90;
|
||||
|
||||
LastMode = Mode;
|
||||
|
||||
Sleep_time = 60; // минута чтобы отключиться
|
||||
|
||||
Cancount[m_FAST] = 5; // * 10msec, пауза между посылками CAN
|
||||
Cancount[m_SLOW] = 100; // * 10msec, пауза между посылками CAN
|
||||
|
||||
CanWait[m_FAST] = 1; // * 10msec, пауза после цикла
|
||||
CanWait[m_SLOW] = 1; // * 10msec, пауза после цикла
|
||||
|
||||
CanRestart[m_FAST] = 500; // * 10msec, перезапуск посылки
|
||||
CanRestart[m_SLOW] = 1000; // * 10msec, перезапуск посылки
|
||||
|
||||
CanRptVez = 3; // кол-во повторений посылки «keys»
|
||||
CanRptLen = 3; // длина повтораемой посылки «keys»
|
||||
|
||||
Brightness = 10;
|
||||
|
||||
Protokol = PROTOKOL;
|
||||
}
|
||||
|
||||
void Load_params()
|
||||
{
|
||||
unsigned int i,crc;
|
||||
unsigned int adr = FLASH_EEPROM_BASE;
|
||||
|
||||
for(int j=0; j<Modbus_LEN+1; j+=1)
|
||||
{
|
||||
params[j] = watInTheFlash(adr) & 0xFFFF;
|
||||
adr += 0x2;
|
||||
}
|
||||
crc = get_crc16(params,Modbus_LEN);
|
||||
if( (crc==params[Modbus_LEN]) &&
|
||||
(crc !=0xFFFF) &&
|
||||
(Mode == params[126]))
|
||||
{
|
||||
for(i=0;i<Modbus_LEN;i++) modbus[i] = params[i];
|
||||
Commands=0;
|
||||
}
|
||||
else
|
||||
{
|
||||
Default_params();
|
||||
Save_params();
|
||||
}
|
||||
|
||||
Init_packMask();
|
||||
}
|
||||
|
||||
void Save_params()
|
||||
{
|
||||
unsigned int i,dif=0;
|
||||
|
||||
for(i=0;i<Modbus_LEN;i++)
|
||||
if(params[i] != modbus[i])
|
||||
{
|
||||
params[i] = modbus[i];
|
||||
dif=1;
|
||||
}
|
||||
if(dif)
|
||||
{
|
||||
params[Modbus_LEN] = get_crc16(params,Modbus_LEN);
|
||||
putIntoEeprom(Modbus_LEN+1, params);
|
||||
} }
|
||||
|
||||
void Init_packMask()
|
||||
{
|
||||
int i;
|
||||
|
||||
for(i=0;i<8;i++)
|
||||
{
|
||||
Maska[m_FAST][i] = 0;
|
||||
Maska[m_SLOW][i] = 0;
|
||||
}
|
||||
|
||||
Maska[m_FAST][0]|= 0x0007; // Дискретные входы, неисправности и аварии
|
||||
Maska[m_SLOW][0]|= 0x0300; // Маски на неисправности и аварии
|
||||
Maska[m_SLOW][1]|= 0x0003; // Состояние джамперов
|
||||
Maska[m_SLOW][1]|= 0x0F00; // Скважность датчика напряжения
|
||||
Maska[m_SLOW][3]|= 0x000F; // Аварийная уставка скважности
|
||||
Maska[m_SLOW][4]|= 0x0100; // Время автоматического отключения
|
||||
Maska[m_SLOW][6]|= 0x05FF; // Яркость лампы и периоды посылок
|
||||
Maska[m_FAST][7]|= 0x0100; // Счетчик посылок
|
||||
Maska[m_SLOW][7]|= 0x0E00; // Счетчик посылок
|
||||
Maska[m_SLOW][7]|= 0xE000; // Протокол, адрес, команды
|
||||
}
|
||||
|
||||
|
||||
@@ -8,13 +8,12 @@
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
@@ -6,13 +6,12 @@
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
@@ -76,7 +75,7 @@ void NMI_Handler(void)
|
||||
|
||||
/* USER CODE END NonMaskableInt_IRQn 0 */
|
||||
/* USER CODE BEGIN NonMaskableInt_IRQn 1 */
|
||||
while (1)
|
||||
while (1)
|
||||
{
|
||||
}
|
||||
/* USER CODE END NonMaskableInt_IRQn 1 */
|
||||
@@ -254,7 +253,7 @@ void TIM8_UP_IRQHandler(void)
|
||||
/* 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 */
|
||||
}
|
||||
|
||||
|
||||
@@ -1,156 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file syscalls.c
|
||||
* @author Auto-generated by STM32CubeIDE
|
||||
* @brief STM32CubeIDE Minimal System calls file
|
||||
*
|
||||
* For more information about which c-functions
|
||||
* need which of these lowlevel functions
|
||||
* please consult the Newlib libc-manual
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2020 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 <sys/stat.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/times.h>
|
||||
|
||||
|
||||
/* Variables */
|
||||
extern int __io_putchar(int ch) __attribute__((weak));
|
||||
extern int __io_getchar(void) __attribute__((weak));
|
||||
|
||||
|
||||
char *__env[1] = { 0 };
|
||||
char **environ = __env;
|
||||
|
||||
|
||||
/* Functions */
|
||||
void initialise_monitor_handles()
|
||||
{
|
||||
}
|
||||
|
||||
int _getpid(void)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _kill(int pid, int sig)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
void _exit (int status)
|
||||
{
|
||||
_kill(status, -1);
|
||||
while (1) {} /* Make sure we hang here */
|
||||
}
|
||||
|
||||
__attribute__((weak)) int _read(int file, char *ptr, int len)
|
||||
{
|
||||
int DataIdx;
|
||||
|
||||
for (DataIdx = 0; DataIdx < len; DataIdx++)
|
||||
{
|
||||
*ptr++ = __io_getchar();
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
__attribute__((weak)) int _write(int file, char *ptr, int len)
|
||||
{
|
||||
int DataIdx;
|
||||
|
||||
for (DataIdx = 0; DataIdx < len; DataIdx++)
|
||||
{
|
||||
__io_putchar(*ptr++);
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
int _close(int file)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
int _fstat(int file, struct stat *st)
|
||||
{
|
||||
st->st_mode = S_IFCHR;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _isatty(int file)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _lseek(int file, int ptr, int dir)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _open(char *path, int flags, ...)
|
||||
{
|
||||
/* Pretend like we always fail */
|
||||
return -1;
|
||||
}
|
||||
|
||||
int _wait(int *status)
|
||||
{
|
||||
errno = ECHILD;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int _unlink(char *name)
|
||||
{
|
||||
errno = ENOENT;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int _times(struct tms *buf)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int _stat(char *file, struct stat *st)
|
||||
{
|
||||
st->st_mode = S_IFCHR;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _link(char *old, char *new)
|
||||
{
|
||||
errno = EMLINK;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int _fork(void)
|
||||
{
|
||||
errno = EAGAIN;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int _execve(char *name, char **argv, char **env)
|
||||
{
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file sysmem.c
|
||||
* @author Generated by STM32CubeIDE
|
||||
* @brief STM32CubeIDE System Memory calls file
|
||||
*
|
||||
* For more information about which C functions
|
||||
* need which of these lowlevel functions
|
||||
* please consult the newlib libc manual
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2020 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 <errno.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* Pointer to the current high watermark of the heap usage
|
||||
*/
|
||||
static uint8_t *__sbrk_heap_end = NULL;
|
||||
|
||||
/**
|
||||
* @brief _sbrk() allocates memory to the newlib heap and is used by malloc
|
||||
* and others from the C library
|
||||
*
|
||||
* @verbatim
|
||||
* ############################################################################
|
||||
* # .data # .bss # newlib heap # MSP stack #
|
||||
* # # # # Reserved by _Min_Stack_Size #
|
||||
* ############################################################################
|
||||
* ^-- RAM start ^-- _end _estack, RAM end --^
|
||||
* @endverbatim
|
||||
*
|
||||
* This implementation starts allocating at the '_end' linker symbol
|
||||
* The '_Min_Stack_Size' linker symbol reserves a memory for the MSP stack
|
||||
* The implementation considers '_estack' linker symbol to be RAM end
|
||||
* NOTE: If the MSP stack, at any point during execution, grows larger than the
|
||||
* reserved size, please increase the '_Min_Stack_Size'.
|
||||
*
|
||||
* @param incr Memory size
|
||||
* @return Pointer to allocated memory
|
||||
*/
|
||||
void *_sbrk(ptrdiff_t incr)
|
||||
{
|
||||
extern uint8_t _end; /* Symbol defined in the linker script */
|
||||
extern uint8_t _estack; /* Symbol defined in the linker script */
|
||||
extern uint32_t _Min_Stack_Size; /* Symbol defined in the linker script */
|
||||
const uint32_t stack_limit = (uint32_t)&_estack - (uint32_t)&_Min_Stack_Size;
|
||||
const uint8_t *max_heap = (uint8_t *)stack_limit;
|
||||
uint8_t *prev_heap_end;
|
||||
|
||||
/* Initialize heap end at first call */
|
||||
if (NULL == __sbrk_heap_end)
|
||||
{
|
||||
__sbrk_heap_end = &_end;
|
||||
}
|
||||
|
||||
/* Protect heap from growing into the reserved MSP stack */
|
||||
if (__sbrk_heap_end + incr > max_heap)
|
||||
{
|
||||
errno = ENOMEM;
|
||||
return (void *)-1;
|
||||
}
|
||||
|
||||
prev_heap_end = __sbrk_heap_end;
|
||||
__sbrk_heap_end += incr;
|
||||
|
||||
return (void *)prev_heap_end;
|
||||
}
|
||||
@@ -33,13 +33,12 @@
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2017 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
* Copyright (c) 2017-2021 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
@@ -139,7 +138,7 @@
|
||||
is no need to call the 2 first functions listed above, since SystemCoreClock
|
||||
variable is updated automatically.
|
||||
*/
|
||||
uint32_t SystemCoreClock = 16000000;
|
||||
uint32_t SystemCoreClock = 8000000;
|
||||
const uint8_t AHBPrescTable[16U] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9};
|
||||
const uint8_t APBPrescTable[8U] = {0, 0, 0, 0, 1, 2, 3, 4};
|
||||
|
||||
@@ -404,5 +403,4 @@ void SystemInit_ExtMemCtl(void)
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
*/
|
||||
|
||||
@@ -22,8 +22,6 @@
|
||||
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
#include "lampa.h"
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
TIM_HandleTypeDef htim4;
|
||||
@@ -64,11 +62,7 @@ void MX_TIM4_Init(void)
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN TIM4_Init 2 */
|
||||
|
||||
HAL_TIM_Base_MspInit(&htim4);
|
||||
|
||||
HAL_TIM_Base_Start_IT(&htim4);
|
||||
|
||||
|
||||
/* USER CODE END TIM4_Init 2 */
|
||||
|
||||
}
|
||||
@@ -114,14 +108,4 @@ void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* tim_baseHandle)
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
//void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
|
||||
//{
|
||||
|
||||
// if(htim->Instance == TIM4) //check if the interrupt comes from TIM1
|
||||
|
||||
// ReadSeanus();
|
||||
//
|
||||
//}
|
||||
|
||||
|
||||
/* USER CODE END 1 */
|
||||
|
||||
Reference in New Issue
Block a user