leakage
This commit is contained in:
113
calib_board/usr/bsp/bsp_74HC4067.c
Normal file
113
calib_board/usr/bsp/bsp_74HC4067.c
Normal file
@@ -0,0 +1,113 @@
|
||||
#include "bsp_74HC4067.h"
|
||||
#include "os_timer.h"
|
||||
|
||||
/*<2A><>Ƭ74HC4067<36><37>һƬTX һƬRX ÿƬ16ͨ<36><CDA8>*/
|
||||
|
||||
#define BSP_74HC4067_CH_MAX 16
|
||||
|
||||
/*TX*/
|
||||
#define TX_EN_ENABLE HAL_GPIO_WritePin (TX_EN_GPIO_Port, TX_EN_Pin, GPIO_PIN_RESET)
|
||||
#define TX_EN_DISENABLE HAL_GPIO_WritePin (TX_EN_GPIO_Port, TX_EN_Pin, GPIO_PIN_SET)
|
||||
|
||||
/*RX*/
|
||||
#define RX_EN_ENABLE HAL_GPIO_WritePin (RX_EN_GPIO_Port, RX_EN_Pin, GPIO_PIN_RESET)
|
||||
#define RX_EN_DISENABLE HAL_GPIO_WritePin (RX_EN_GPIO_Port, RX_EN_Pin, GPIO_PIN_SET)
|
||||
|
||||
|
||||
/*LEDͨ<44><CDA8>ָʾ*/
|
||||
#define LED_CH0_ON HAL_GPIO_WritePin (RX_S3_GPIO_Port, RX_S3_Pin, GPIO_PIN_RESET)
|
||||
#define LED_CH0_OFF HAL_GPIO_WritePin (RX_S3_GPIO_Port, RX_S3_Pin, GPIO_PIN_SET)
|
||||
|
||||
#define BSP_LOW GPIO_PIN_RESET
|
||||
#define BSP_HIG GPIO_PIN_SET
|
||||
|
||||
#define BSP_LED_ON GPIO_PIN_RESET
|
||||
#define BSP_LED_OFF GPIO_PIN_SET
|
||||
|
||||
static GPIO_TypeDef* bsp_74HC4067_TX_SW_GPIO[4] = {TX_S0_GPIO_Port,TX_S1_GPIO_Port,TX_S2_GPIO_Port,TX_S3_GPIO_Port};
|
||||
static uint16_t bsp_74HC4067_TX_SW_Pin[4] = {TX_S0_Pin, TX_S1_Pin, TX_S2_Pin, TX_S3_Pin};
|
||||
|
||||
static GPIO_TypeDef* bsp_74HC4067_RX_SW_GPIO[4] = {RX_S0_GPIO_Port,RX_S1_GPIO_Port,RX_S2_GPIO_Port,RX_S3_GPIO_Port};
|
||||
static uint16_t bsp_74HC4067_RX_SW_Pin[4] = {RX_S0_Pin, RX_S1_Pin, RX_S2_Pin, RX_S3_Pin};
|
||||
|
||||
static GPIO_TypeDef* bsp_74HC4067_LED_CH_GPIO[BSP_74HC4067_CH_MAX] = {LED_CH1_GPIO_Port, LED_CH2_GPIO_Port, LED_CH3_GPIO_Port, LED_CH4_GPIO_Port, LED_CH5_GPIO_Port, LED_CH6_GPIO_Port, LED_CH7_GPIO_Port, LED_CH8_GPIO_Port, LED_CH9_GPIO_Port, LED_CH10_GPIO_Port, LED_CH11_GPIO_Port, LED_CH12_GPIO_Port, LED_CH13_GPIO_Port, LED_CH14_GPIO_Port, LED_CH15_GPIO_Port, LED_CH16_GPIO_Port};
|
||||
static uint16_t bsp_74HC4067_LED_CH_Pin[BSP_74HC4067_CH_MAX] = {LED_CH1_Pin, LED_CH2_Pin, LED_CH3_Pin, LED_CH4_Pin, LED_CH5_Pin, LED_CH6_Pin, LED_CH7_Pin, LED_CH8_Pin, LED_CH9_Pin, LED_CH10_Pin, LED_CH11_Pin, LED_CH12_Pin, LED_CH13_Pin, LED_CH14_Pin, LED_CH15_Pin, LED_CH16_Pin};
|
||||
|
||||
/*ͨ<><CDA8>ת<EFBFBD><D7AA><EFBFBD><EFBFBD>Ӳ<EFBFBD><D3B2>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD>оƬ<D0BE><C6AC><EFBFBD><EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>*/
|
||||
static u8 bsp_74HC4067_TX_CH_Conv[BSP_74HC4067_CH_MAX] = {13,14,15,12,11,10,9, 8, 7, 4, 3, 2, 1, 0, 6, 5};
|
||||
static u8 bsp_74HC4067_RX_CH_Conv[BSP_74HC4067_CH_MAX] = {13,14,15,8, 9, 10,11,12,0, 1, 2, 3, 4, 5, 6, 7};
|
||||
|
||||
|
||||
static void bsp_74HC4067_Init(void);
|
||||
static void bsp_74HC4067_Set_CH(u8 CH);
|
||||
static u8 bsp_74HC4067_Get_CH(void);
|
||||
|
||||
static u8 bsp_74HC4067_CH;
|
||||
|
||||
bsp_74HC4067_t UartCH_Config =
|
||||
{
|
||||
.init = bsp_74HC4067_Init,
|
||||
.ch_set = bsp_74HC4067_Set_CH,
|
||||
.ch_get = bsp_74HC4067_Get_CH,
|
||||
};
|
||||
/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˸<EFBFBD><CBB8><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
||||
static void bsp_74HC4067_Init(void)
|
||||
{
|
||||
bsp_74HC4067_CH = 0;
|
||||
TX_EN_ENABLE;
|
||||
RX_EN_ENABLE;
|
||||
bsp_74HC4067_Set_CH(0);
|
||||
}
|
||||
|
||||
|
||||
//static u8 CH;
|
||||
static void bsp_74HC4067_Set_CH(u8 CH1)
|
||||
{
|
||||
u8 CH = 0;
|
||||
if(CH >= BSP_74HC4067_CH_MAX)
|
||||
{
|
||||
return ;
|
||||
}
|
||||
u8 i,TX_CH,RX_CH;
|
||||
bsp_74HC4067_CH = CH;
|
||||
TX_CH = bsp_74HC4067_TX_CH_Conv[CH];
|
||||
RX_CH = bsp_74HC4067_RX_CH_Conv[CH];
|
||||
/*ѡ<><D1A1><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
||||
for(i=0;i<4;i++)
|
||||
{
|
||||
if((TX_CH >> i) & 0x01)
|
||||
{
|
||||
HAL_GPIO_WritePin(bsp_74HC4067_TX_SW_GPIO[i],bsp_74HC4067_TX_SW_Pin[i],BSP_HIG);
|
||||
}
|
||||
else
|
||||
{
|
||||
HAL_GPIO_WritePin(bsp_74HC4067_TX_SW_GPIO[i],bsp_74HC4067_TX_SW_Pin[i],BSP_LOW);
|
||||
}
|
||||
if((RX_CH >> i) & 0x01)
|
||||
{
|
||||
HAL_GPIO_WritePin(bsp_74HC4067_RX_SW_GPIO[i],bsp_74HC4067_RX_SW_Pin[i],BSP_HIG);
|
||||
}
|
||||
else
|
||||
{
|
||||
HAL_GPIO_WritePin(bsp_74HC4067_RX_SW_GPIO[i],bsp_74HC4067_RX_SW_Pin[i],BSP_LOW);
|
||||
}
|
||||
}
|
||||
/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧָʾ<D6B8><CABE>*/
|
||||
for(i=0;i<BSP_74HC4067_CH_MAX;i++)
|
||||
{
|
||||
if(i == CH)
|
||||
{
|
||||
HAL_GPIO_WritePin(bsp_74HC4067_LED_CH_GPIO[i],bsp_74HC4067_LED_CH_Pin[i],BSP_LED_ON);
|
||||
}
|
||||
else
|
||||
{
|
||||
HAL_GPIO_WritePin(bsp_74HC4067_LED_CH_GPIO[i],bsp_74HC4067_LED_CH_Pin[i],BSP_LED_OFF);
|
||||
}
|
||||
}
|
||||
// HAL_Delay(20);
|
||||
}
|
||||
|
||||
static u8 bsp_74HC4067_Get_CH(void)
|
||||
{
|
||||
return bsp_74HC4067_CH;
|
||||
}
|
||||
15
calib_board/usr/bsp/bsp_74HC4067.h
Normal file
15
calib_board/usr/bsp/bsp_74HC4067.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef _BSP_74HC4067_H_
|
||||
#define _BSP_74HC4067_H_
|
||||
|
||||
#include "main.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
void (*init)(void);
|
||||
void (*ch_set)(u8);
|
||||
u8 (*ch_get)(void);
|
||||
}bsp_74HC4067_t;
|
||||
|
||||
extern bsp_74HC4067_t UartCH_Config;
|
||||
|
||||
#endif
|
||||
1
calib_board/usr/bsp/bsp_Delay.c
Normal file
1
calib_board/usr/bsp/bsp_Delay.c
Normal file
@@ -0,0 +1 @@
|
||||
#include "bsp_Delay.h"
|
||||
6
calib_board/usr/bsp/bsp_Delay.h
Normal file
6
calib_board/usr/bsp/bsp_Delay.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#ifndef _BSP_DELAY_H_
|
||||
#define _BSP_DELAY_H_
|
||||
|
||||
#include "main.h"
|
||||
|
||||
#endif
|
||||
186
calib_board/usr/bsp/bsp_Flash.c
Normal file
186
calib_board/usr/bsp/bsp_Flash.c
Normal file
@@ -0,0 +1,186 @@
|
||||
#include "bsp_Flash.h"
|
||||
#include "string.h"
|
||||
#include "bsp_Wdg.h"
|
||||
#include "gas_data.h"
|
||||
/* FLASH Memory Definitions */
|
||||
//#define BSP_FLASH_SIZE (0x100000UL)
|
||||
//#define BSP_FLASH_PAGE_SIZE (PAGESIZE)
|
||||
//#define BSP_FLASH_PAGE_NUM (BSP_FLASH_SIZE/BSP_FLASH_PAGE_SIZE)
|
||||
|
||||
//#define BSP_FLASH_ADDR_RW(n) ((uint32_t)(FLASH_BASE + (BSP_FLASH_PAGE_NUM - (n)) * BSP_FLASH_PAGE_SIZE))
|
||||
//#define BSP_FLASH_DATASAVE_ADDR BSP_FLASH_ADDR_RW(1)
|
||||
|
||||
//FLASH<53><48>ַ
|
||||
#define BSP_FLASH_SECTION_0_ADDR ((u32)0x08000000) //16k
|
||||
#define BSP_FLASH_SECTION_1_ADDR ((u32)0x08004000) //16k
|
||||
#define BSP_FLASH_SECTION_2_ADDR ((u32)0x08008000) //16k
|
||||
#define BSP_FLASH_SECTION_3_ADDR ((u32)0x0800C000) //16k
|
||||
#define BSP_FLASH_SECTION_4_ADDR ((u32)0x08010000) //64k
|
||||
#define BSP_FLASH_SECTION_5_ADDR ((u32)0x08020000) //128k
|
||||
#define BSP_FLASH_SECTION_6_ADDR ((u32)0x08040000) //128k
|
||||
#define BSP_FLASH_SECTION_7_ADDR ((u32)0x08060000) //128k
|
||||
#define BSP_FLASH_SECTION_8_ADDR ((u32)0x08080000) //128k
|
||||
#define BSP_FLASH_SECTION_9_ADDR ((u32)0x080A0000) //128k
|
||||
#define BSP_FLASH_SECTION_10_ADDR ((u32)0x080C0000) //128k
|
||||
#define BSP_FLASH_SECTION_11_ADDR ((u32)0x080E0000) //128k
|
||||
|
||||
#define BSP_FLASH_DATASAVE_ADDR BSP_FLASH_SECTION_11_ADDR//<2F><><EFBFBD><EFBFBD>һƬ<D2BB><C6AC><EFBFBD><EFBFBD> 128k
|
||||
|
||||
static void bsp_Flash_Init(void);
|
||||
static void bsp_FlashDataWrite(void);
|
||||
static void bsp_FlashDataRead(void);
|
||||
static void bsp_FlashReset(void);
|
||||
|
||||
bsp_Flash_t Usr_Flash =
|
||||
{
|
||||
.Init = bsp_Flash_Init,
|
||||
.Write = bsp_FlashDataWrite,
|
||||
.Read = bsp_FlashDataRead,
|
||||
.Reset = bsp_FlashReset,
|
||||
};
|
||||
|
||||
bsp_Flash_t *p_Usr_Flash = &Usr_Flash;
|
||||
|
||||
// <20><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>ҳ
|
||||
static HAL_StatusTypeDef bsp_FLASH_ErasePage(uint32_t PageAddress)
|
||||
{
|
||||
//<2F><>ʼ<EFBFBD><CABC>FLASH_EraseInitTypeDef
|
||||
FLASH_EraseInitTypeDef f;
|
||||
|
||||
f.TypeErase = FLASH_TYPEERASE_SECTORS;
|
||||
f.Sector = FLASH_SECTOR_11;
|
||||
f.NbSectors = 1;
|
||||
f.VoltageRange = VOLTAGE_RANGE_3;
|
||||
//<2F><><EFBFBD><EFBFBD>PageError
|
||||
uint32_t PageError = 0;
|
||||
//<2F><><EFBFBD>ò<EFBFBD><C3B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
return HAL_FLASHEx_Erase(&f, &PageError);
|
||||
}
|
||||
|
||||
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD> - <20><>32λ<32><CEBB>ȡ
|
||||
static void bsp_Flash_STMFLASH_Read(uint32_t ReadAddr, void *pBuffer, uint32_t size)
|
||||
{
|
||||
uint8_t *pBuf = (uint8_t*)pBuffer;
|
||||
uint32_t *addr = (uint32_t*)ReadAddr;
|
||||
uint32_t words = size / 4;
|
||||
uint32_t bytes_remaining = size % 4;
|
||||
|
||||
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>32λ<32><CEBB>
|
||||
for(uint32_t i = 0; i < words; i++)
|
||||
{
|
||||
*((uint32_t*)pBuf) = addr[i];
|
||||
pBuf += 4;
|
||||
}
|
||||
|
||||
// <20><>ȡʣ<C8A1><CAA3><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD>
|
||||
if(bytes_remaining > 0)
|
||||
{
|
||||
uint32_t last_word = addr[words];
|
||||
uint8_t *last_bytes = (uint8_t*)&last_word;
|
||||
|
||||
for(uint32_t i = 0; i < bytes_remaining; i++)
|
||||
{
|
||||
pBuf[i] = last_bytes[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// д<><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD> - <20><>32λд<CEBB><D0B4>
|
||||
static HAL_StatusTypeDef bsp_Flash_STMFLASH_Write(uint32_t WriteAddr, void *pBuffer, uint32_t size)
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
uint8_t *pBuf = (uint8_t*)pBuffer;
|
||||
uint32_t words = size / 4;
|
||||
uint32_t bytes_remaining = size % 4;
|
||||
uint32_t current_addr = WriteAddr;
|
||||
|
||||
HAL_FLASH_Unlock();
|
||||
|
||||
// <20><><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF>ҳ
|
||||
status = bsp_FLASH_ErasePage(WriteAddr);
|
||||
if(status != HAL_OK)
|
||||
{
|
||||
HAL_FLASH_Lock();
|
||||
return status;
|
||||
}
|
||||
|
||||
// д<><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>32λ<32><CEBB>
|
||||
for(uint32_t i = 0; i < words; i++)
|
||||
{
|
||||
status = HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD,
|
||||
current_addr,
|
||||
*((uint32_t*)pBuf));
|
||||
if(status != HAL_OK) break;
|
||||
|
||||
current_addr += 4;
|
||||
pBuf += 4;
|
||||
}
|
||||
|
||||
// д<><D0B4>ʣ<EFBFBD><CAA3><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD>
|
||||
if(status == HAL_OK && bytes_remaining > 0)
|
||||
{
|
||||
uint32_t last_word = 0xFFFFFFFF; // Ĭ<><C4AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0xFF
|
||||
uint8_t *last_bytes = (uint8_t*)&last_word;
|
||||
|
||||
// <20><><EFBFBD><EFBFBD>ʣ<EFBFBD><CAA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
for(uint32_t i = 0; i < bytes_remaining; i++)
|
||||
{
|
||||
last_bytes[i] = pBuf[i];
|
||||
}
|
||||
|
||||
status = HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, current_addr, last_word);
|
||||
}
|
||||
|
||||
HAL_FLASH_Lock();
|
||||
return status;
|
||||
}
|
||||
|
||||
static void bsp_FlashReset(void)
|
||||
{
|
||||
|
||||
bsp_FlashDataWrite();
|
||||
}
|
||||
|
||||
static void bsp_Flash_Init(void)
|
||||
{
|
||||
|
||||
bsp_FlashDataRead();
|
||||
if(p_Usr_Flash->FlashData.modbus_read_reg_num > 1000)
|
||||
p_Usr_Flash->FlashData.modbus_read_reg_num = sizeof(gas_data_t)/2;
|
||||
if(p_Usr_Flash->FlashData.modbus_read_sensor_num > SENSOR_NUM)
|
||||
p_Usr_Flash->FlashData.modbus_read_sensor_num = SENSOR_NUM;
|
||||
memcpy(&Usr_Flash.TempFlashData, &Usr_Flash.FlashData, sizeof(bsp_FlashData_t));
|
||||
}
|
||||
|
||||
static void bsp_FlashDataWrite(void)
|
||||
{
|
||||
/*<2A><>ֹ<EFBFBD>ظ<EFBFBD><D8B8><EFBFBD>д<EFBFBD><D0B4>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD>*/
|
||||
if(memcmp(&Usr_Flash.TempFlashData, &Usr_Flash.FlashData, sizeof(bsp_FlashData_t)) != 0)
|
||||
{
|
||||
Wdg.Feed();
|
||||
|
||||
__disable_irq(); // <20><><EFBFBD><EFBFBD>ȫ<EFBFBD><C8AB><EFBFBD>ж<EFBFBD>
|
||||
|
||||
HAL_StatusTypeDef status = bsp_Flash_STMFLASH_Write(BSP_FLASH_DATASAVE_ADDR,&Usr_Flash.FlashData,sizeof(bsp_FlashData_t));
|
||||
if(status == HAL_OK)
|
||||
{
|
||||
// д<><D0B4><EFBFBD>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>
|
||||
memcpy(&Usr_Flash.TempFlashData, &Usr_Flash.FlashData, sizeof(bsp_FlashData_t));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
__enable_irq(); // <20>ָ<EFBFBD><D6B8>ж<EFBFBD>
|
||||
Wdg.Feed();
|
||||
}
|
||||
}
|
||||
|
||||
static void bsp_FlashDataRead(void)
|
||||
{
|
||||
Wdg.Feed();
|
||||
bsp_Flash_STMFLASH_Read(BSP_FLASH_DATASAVE_ADDR,
|
||||
&Usr_Flash.FlashData,
|
||||
sizeof(bsp_FlashData_t));
|
||||
Wdg.Feed();
|
||||
}
|
||||
31
calib_board/usr/bsp/bsp_Flash.h
Normal file
31
calib_board/usr/bsp/bsp_Flash.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#ifndef _BSP_FLASH_H_
|
||||
#define _BSP_FLASH_H_
|
||||
|
||||
#include "main.h"
|
||||
#include "stdio.h"
|
||||
#include "string.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
/*<2A><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD>һ<EFBFBD><D2BB>*/
|
||||
u16 sn[5];
|
||||
u8 modbus_id;
|
||||
u16 modbus_read_reg_num;
|
||||
u16 modbus_read_sensor_num;
|
||||
} bsp_FlashData_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
bsp_FlashData_t TempFlashData;
|
||||
bsp_FlashData_t FlashData;
|
||||
void (*Init)(void);
|
||||
void (*Write)(void);
|
||||
void (*Read)(void);
|
||||
void (*Reset)(void);
|
||||
} bsp_Flash_t;
|
||||
|
||||
|
||||
|
||||
extern bsp_Flash_t Usr_Flash;
|
||||
|
||||
#endif
|
||||
38
calib_board/usr/bsp/bsp_Led.c
Normal file
38
calib_board/usr/bsp/bsp_Led.c
Normal file
@@ -0,0 +1,38 @@
|
||||
#include "bsp_Led.h"
|
||||
#include "os_timer.h"
|
||||
|
||||
#define LED1_ON HAL_GPIO_WritePin (LED1_GPIO_Port, LED1_Pin, GPIO_PIN_RESET)
|
||||
#define LED1_OFF HAL_GPIO_WritePin (LED1_GPIO_Port, LED1_Pin, GPIO_PIN_SET)
|
||||
#define LED1_TOGGLE HAL_GPIO_TogglePin(LED1_GPIO_Port, LED1_Pin)
|
||||
|
||||
#define LED2_ON HAL_GPIO_WritePin (LED2_GPIO_Port, LED2_Pin, GPIO_PIN_RESET)
|
||||
#define LED2_OFF HAL_GPIO_WritePin (LED2_GPIO_Port, LED2_Pin, GPIO_PIN_SET)
|
||||
#define LED2_TOGGLE HAL_GPIO_TogglePin(LED2_GPIO_Port, LED2_Pin)
|
||||
|
||||
#define LED3_ON HAL_GPIO_WritePin (LED3_GPIO_Port, LED3_Pin, GPIO_PIN_RESET)
|
||||
#define LED3_OFF HAL_GPIO_WritePin (LED3_GPIO_Port, LED3_Pin, GPIO_PIN_SET)
|
||||
#define LED3_TOGGLE HAL_GPIO_TogglePin(LED3_GPIO_Port, LED3_Pin)
|
||||
|
||||
|
||||
static void bsp_Led_Init(void);
|
||||
static void bsp_Led_Flash(void);
|
||||
|
||||
bsp_Led_t Led =
|
||||
{
|
||||
.Init = bsp_Led_Init,
|
||||
.Flash = bsp_Led_Flash,
|
||||
};
|
||||
/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˸<EFBFBD><CBB8><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
||||
static void bsp_Led_Init(void)
|
||||
{
|
||||
for(u8 i = 0;i < 20;i++)
|
||||
{
|
||||
Delay_ms(50);
|
||||
HAL_GPIO_TogglePin(LED1_GPIO_Port, LED1_Pin);
|
||||
}
|
||||
}
|
||||
|
||||
static void bsp_Led_Flash(void)
|
||||
{
|
||||
HAL_GPIO_TogglePin(LED1_GPIO_Port, LED1_Pin);
|
||||
}
|
||||
15
calib_board/usr/bsp/bsp_Led.h
Normal file
15
calib_board/usr/bsp/bsp_Led.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef _BSP_LED_H_
|
||||
#define _BSP_LED_H_
|
||||
|
||||
#include "main.h"
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
void (*Init)(void);
|
||||
void (*Flash)(void);
|
||||
}bsp_Led_t;
|
||||
|
||||
extern bsp_Led_t Led;
|
||||
|
||||
#endif
|
||||
396
calib_board/usr/bsp/bsp_Uart.c
Normal file
396
calib_board/usr/bsp/bsp_Uart.c
Normal file
@@ -0,0 +1,396 @@
|
||||
#include "bsp_Uart.h"
|
||||
|
||||
#include "string.h"
|
||||
|
||||
//#define RS485_RX HAL_GPIO_WritePin(RS485_EN_GPIO_Port, RS485_EN_Pin, GPIO_PIN_RESET)
|
||||
#define RS485_RX HAL_GPIO_WritePin(RS485_EN_GPIO_Port, RS485_EN_Pin, GPIO_PIN_SET)
|
||||
#define RS485_TX HAL_GPIO_WritePin(RS485_EN_GPIO_Port, RS485_EN_Pin, GPIO_PIN_SET)
|
||||
|
||||
/*<2A><><EFBFBD><EFBFBD><EFBFBD>շ<EFBFBD><D5B7><EFBFBD>*/
|
||||
#define RX_TEMP_BUFF_NUM (3000U)
|
||||
u8 Rx_Temp_Buff[RX_TEMP_BUFF_NUM];
|
||||
|
||||
#define UART1_TX_LEN (3000U)
|
||||
#define UART1_RX_LEN (3000U)
|
||||
|
||||
#define UART2_TX_LEN (3000U)
|
||||
#define UART2_RX_LEN (3000U)
|
||||
|
||||
#define UART4_TX_LEN (3000U)
|
||||
#define UART4_RX_LEN (3000U)
|
||||
|
||||
u8 Uart1_TX_Buff[UART1_TX_LEN];
|
||||
u8 Uart1_Rx_Buff[UART1_RX_LEN];
|
||||
|
||||
u8 Uart2_TX_Buff[UART2_TX_LEN];
|
||||
u8 Uart2_Rx_Buff[UART2_RX_LEN];
|
||||
|
||||
u8 Uart4_TX_Buff[UART4_TX_LEN];
|
||||
u8 Uart4_Rx_Buff[UART4_RX_LEN];
|
||||
|
||||
static void bsp_Uart_Init(bsp_Uart_t *p_Uart);
|
||||
static void bsp_Uart_Send(bsp_Uart_t *p_Uart,u8 *pData, u16 Len);
|
||||
static void bsp_Uart_Rx_IdleInt(bsp_Uart_t *p_Uart);
|
||||
static void bsp_Uart_Rx_TimeIncrement(bsp_Uart_t *p_Uart,u16 Time);
|
||||
static void bsp_Uart_Rx_Task(bsp_Uart_t *p_Uart);
|
||||
static void bsp_Uart_Rx_TimeStart(bsp_Uart_t *p_Uart);
|
||||
static void bsp_Uart_Tx_DMA_TCInt(bsp_Uart_t *p_Uart);
|
||||
|
||||
extern UART_HandleTypeDef huart1;
|
||||
extern UART_HandleTypeDef huart2;
|
||||
extern UART_HandleTypeDef huart4;
|
||||
|
||||
extern DMA_HandleTypeDef hdma_usart1_rx;
|
||||
extern DMA_HandleTypeDef hdma_usart1_tx;
|
||||
extern DMA_HandleTypeDef hdma_usart2_rx;
|
||||
extern DMA_HandleTypeDef hdma_usart2_tx;
|
||||
extern DMA_HandleTypeDef hdma_uart4_rx;
|
||||
extern DMA_HandleTypeDef hdma_uart4_tx;
|
||||
|
||||
bsp_Uart_t COM_Uart1 =
|
||||
{
|
||||
.RxQueue = queue(u8,UART1_RX_LEN),
|
||||
.Uart =&huart1,
|
||||
|
||||
.Tx_DMA = &hdma_usart1_tx,
|
||||
.Rx_DMA = &hdma_usart1_rx,
|
||||
|
||||
.Tx_DMA_Len = UART1_TX_LEN,
|
||||
.Rx_DMA_Len = UART1_RX_LEN,
|
||||
|
||||
.Tx_Addr = &Uart1_TX_Buff[0],
|
||||
.Rx_Addr = &Uart1_Rx_Buff[0],
|
||||
|
||||
.Tx_DMA_CompleteFlag = 1,
|
||||
.Rx_TimeOver = 0,
|
||||
|
||||
.relay.uart = NULL,
|
||||
|
||||
.Init = bsp_Uart_Init,
|
||||
.Send = bsp_Uart_Send,
|
||||
|
||||
.Tx_DMA_TCInt = bsp_Uart_Tx_DMA_TCInt,
|
||||
.Rx_IdleInt = bsp_Uart_Rx_IdleInt,
|
||||
.Rx_TimeIncrementInt = bsp_Uart_Rx_TimeIncrement,
|
||||
.Rx_DataAnalysis = NULL,
|
||||
.Rx_Task = bsp_Uart_Rx_Task,
|
||||
};
|
||||
|
||||
bsp_Uart_t COM_Uart2 =
|
||||
{
|
||||
.RxQueue = queue(u8,UART2_RX_LEN),
|
||||
.Uart =&huart2,
|
||||
|
||||
.Tx_DMA = &hdma_usart2_tx,
|
||||
.Rx_DMA = &hdma_usart2_rx,
|
||||
|
||||
.Tx_DMA_Len = UART2_TX_LEN,
|
||||
.Rx_DMA_Len = UART2_RX_LEN,
|
||||
|
||||
.Tx_Addr = &Uart2_TX_Buff[0],
|
||||
.Rx_Addr = &Uart2_Rx_Buff[0],
|
||||
|
||||
.Tx_DMA_CompleteFlag = 1,
|
||||
.Rx_TimeOver = 0,
|
||||
|
||||
.relay.uart = &COM_Uart4,
|
||||
|
||||
.Init = bsp_Uart_Init,
|
||||
.Send = bsp_Uart_Send,
|
||||
.Tx_DMA_TCInt = bsp_Uart_Tx_DMA_TCInt,
|
||||
.Rx_IdleInt = bsp_Uart_Rx_IdleInt,
|
||||
.Rx_TimeIncrementInt = bsp_Uart_Rx_TimeIncrement,
|
||||
.Rx_DataAnalysis = NULL,
|
||||
.Rx_Task = bsp_Uart_Rx_Task,
|
||||
};
|
||||
|
||||
bsp_Uart_t COM_Uart4 =
|
||||
{
|
||||
.RxQueue = queue(u8,UART4_RX_LEN),
|
||||
.Uart =&huart4,
|
||||
|
||||
.Tx_DMA = &hdma_uart4_tx,
|
||||
.Rx_DMA = &hdma_uart4_rx,
|
||||
|
||||
.Tx_DMA_Len = UART4_TX_LEN,
|
||||
.Rx_DMA_Len = UART4_RX_LEN,
|
||||
|
||||
.Tx_Addr = &Uart4_TX_Buff[0],
|
||||
.Rx_Addr = &Uart4_Rx_Buff[0],
|
||||
|
||||
.Tx_DMA_CompleteFlag = 1,
|
||||
.Rx_TimeOver = 0,
|
||||
|
||||
.relay.uart = NULL,
|
||||
|
||||
.Init = bsp_Uart_Init,
|
||||
.Send = bsp_Uart_Send,
|
||||
.Tx_DMA_TCInt = bsp_Uart_Tx_DMA_TCInt,
|
||||
.Rx_IdleInt = bsp_Uart_Rx_IdleInt,
|
||||
.Rx_TimeIncrementInt = bsp_Uart_Rx_TimeIncrement,
|
||||
.Rx_DataAnalysis = NULL,
|
||||
.Rx_Task = bsp_Uart_Rx_Task,
|
||||
};
|
||||
|
||||
|
||||
/* <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
static void bsp_Uart_Init(bsp_Uart_t *p_Uart)
|
||||
{
|
||||
/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݽ<EFBFBD><DDBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
||||
//p_Uart->Rx_DataAnalysis = NULL;
|
||||
|
||||
/* <20><><EFBFBD>ÿ<EFBFBD><C3BF><EFBFBD><EFBFBD>ж<EFBFBD> */
|
||||
__HAL_UART_ENABLE_IT(p_Uart->Uart, UART_IT_IDLE);
|
||||
|
||||
/* <20><><EFBFBD><EFBFBD>DMA<4D><41><EFBFBD><EFBFBD> */
|
||||
//HAL_UART_Receive_DMA(p_Uart->Uart, p_Uart->Rx_Addr, p_Uart->Rx_DMA_Len);
|
||||
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
HAL_UARTEx_ReceiveToIdle_DMA(p_Uart->Uart, p_Uart->Rx_Addr, p_Uart->Rx_DMA_Len);
|
||||
}
|
||||
|
||||
|
||||
static void bsp_Uart_DMASend(bsp_Uart_t *p_Uart,u8 *pData, u16 Len)
|
||||
{
|
||||
u32 tickstart,tick;
|
||||
p_Uart->Tx_DMA_CompleteFlag = 0;
|
||||
if(p_Uart->Tx_DMA_Len < Len)
|
||||
Len = p_Uart->Tx_DMA_Len;
|
||||
memcpy(p_Uart->Tx_Addr, pData, Len); /*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD><DDB5><EFBFBD><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD>*/
|
||||
|
||||
// /*<2A><><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD><EFBFBD>ͣ<EFBFBD><CDA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD><EFBFBD>ͣ<EFBFBD><CDA3>ᵼ<EFBFBD><E1B5BC><EFBFBD>շ<EFBFBD><D5B7><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD>л<EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
||||
// HAL_UART_Transmit(p_Uart->Uart,p_Uart->Tx_Addr,Len,500);
|
||||
|
||||
|
||||
HAL_UART_Transmit_DMA(p_Uart->Uart,p_Uart->Tx_Addr,Len);
|
||||
tickstart = HAL_GetTick();
|
||||
while( !p_Uart->Tx_DMA_CompleteFlag)
|
||||
{
|
||||
tick = HAL_GetTick();
|
||||
if((tick - tickstart) > 200) // 1000ms <20><>ʱ
|
||||
{
|
||||
p_Uart->Tx_DMA_CompleteFlag = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
||||
static void bsp_Uart_Send(bsp_Uart_t *p_Uart,u8 *pData, u16 Len)
|
||||
{
|
||||
u16 i,SendNum;
|
||||
|
||||
if(p_Uart == &COM_Uart4)
|
||||
RS485_TX;
|
||||
SendNum = Len / p_Uart->Tx_DMA_Len;
|
||||
for(i=0;i<SendNum;i++)
|
||||
{
|
||||
bsp_Uart_DMASend(p_Uart,&pData[p_Uart->Tx_DMA_Len * i], p_Uart->Tx_DMA_Len);
|
||||
}
|
||||
|
||||
/*<2A><><EFBFBD><EFBFBD>ʣ<EFBFBD><CAA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
||||
Len -= p_Uart->Tx_DMA_Len * i;
|
||||
if(0 == Len)
|
||||
{
|
||||
return ;
|
||||
}
|
||||
else
|
||||
{
|
||||
bsp_Uart_DMASend(p_Uart,&pData[p_Uart->Tx_DMA_Len * i],Len);
|
||||
}
|
||||
}
|
||||
|
||||
static void bsp_Uart_Tx_DMA_TCInt(bsp_Uart_t *p_Uart)
|
||||
{
|
||||
p_Uart->Tx_DMA_CompleteFlag = 1;
|
||||
}
|
||||
|
||||
/*<2A><><EFBFBD>н<EFBFBD><D0BD><EFBFBD><EFBFBD>ж<EFBFBD>*/
|
||||
static void bsp_Uart_Rx_IdleInt(bsp_Uart_t *p_Uart)
|
||||
{
|
||||
u16 Rx_Length, i;
|
||||
/*ֹͣ<CDA3><D6B9><EFBFBD><EFBFBD>*/
|
||||
HAL_UART_DMAStop(p_Uart->Uart);
|
||||
|
||||
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD> */
|
||||
Rx_Length = p_Uart->Rx_DMA_Len - __HAL_DMA_GET_COUNTER(p_Uart->Rx_DMA);
|
||||
|
||||
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ0<CEAA><30>ֱ<EFBFBD>ӷ<EFBFBD><D3B7><EFBFBD> */
|
||||
if (Rx_Length == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* <20><><EFBFBD><EFBFBD> */
|
||||
for (i = 0; i < Rx_Length; i++)
|
||||
{
|
||||
queue_push_back(p_Uart->RxQueue, (void *)&p_Uart->Rx_Addr[i]);
|
||||
}
|
||||
/* <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD> */
|
||||
bsp_Uart_Rx_TimeStart(p_Uart);
|
||||
// HAL_UART_Receive_DMA(p_Uart->Uart, p_Uart->Rx_Addr, p_Uart->Rx_DMA_Len);
|
||||
HAL_UARTEx_ReceiveToIdle_DMA(p_Uart->Uart, p_Uart->Rx_Addr, p_Uart->Rx_DMA_Len);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*<2A>жϼ<D0B6><CFBC><EFBFBD>*/
|
||||
static void bsp_Uart_Rx_TimeIncrement(bsp_Uart_t *p_Uart,u16 Time)
|
||||
{
|
||||
/*<2A><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>*/
|
||||
if(1 == p_Uart->Rx_StartFlag)
|
||||
{
|
||||
p_Uart->Rx_TimeCount += Time;
|
||||
}
|
||||
}
|
||||
|
||||
/*<2A><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>*/
|
||||
static void bsp_Uart_Rx_TimeStart(bsp_Uart_t *p_Uart)
|
||||
{
|
||||
p_Uart->Rx_StartFlag = 1;
|
||||
p_Uart->Rx_TimeCount = 0;
|
||||
}
|
||||
|
||||
/*ֹͣ<CDA3><D6B9><EFBFBD><EFBFBD>*/
|
||||
static void bsp_Uart_Rx_TimeStop(bsp_Uart_t *p_Uart)
|
||||
{
|
||||
p_Uart->Rx_StartFlag = 0;
|
||||
p_Uart->Rx_TimeCount = 0;
|
||||
}
|
||||
|
||||
static void bsp_Uart_Rx_Task(bsp_Uart_t *p_Uart)
|
||||
{
|
||||
/*<2A><>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɣ<EFBFBD><C9A3><EFBFBD><EFBFBD>յ<EFBFBD>һ֡<D2BB><D6A1><EFBFBD><EFBFBD>*/
|
||||
if(p_Uart->Rx_TimeOver < p_Uart->Rx_TimeCount)
|
||||
{
|
||||
p_Uart->Rx_Len = queue_size(p_Uart->RxQueue);
|
||||
/*ֹͣ<CDA3><D6B9><EFBFBD><EFBFBD>*/
|
||||
bsp_Uart_Rx_TimeStop(p_Uart);
|
||||
if(p_Uart->Rx_Len <= p_Uart->Rx_DMA_Len && (0 != p_Uart->Rx_Len))
|
||||
{
|
||||
if(RX_TEMP_BUFF_NUM < p_Uart->Rx_Len)
|
||||
{
|
||||
queue_clear(p_Uart->RxQueue);
|
||||
}
|
||||
else
|
||||
{
|
||||
for(u16 i = 0;i < p_Uart->Rx_Len;i++)
|
||||
{
|
||||
queue_pop(p_Uart->RxQueue,&Rx_Temp_Buff[i]);
|
||||
}
|
||||
if(NULL != p_Uart->Rx_DataAnalysis)
|
||||
{
|
||||
p_Uart->Rx_DataAnalysis(Rx_Temp_Buff,p_Uart->Rx_Len,p_Uart); /*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
||||
}
|
||||
// p_Uart->Send(p_Uart,Rx_Temp_Buff,p_Uart->Rx_Len);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD>ORE
|
||||
void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart)
|
||||
{
|
||||
bsp_Uart_t *p_Uart = NULL;
|
||||
if (huart->Instance == USART1)
|
||||
{
|
||||
p_Uart = &COM_Uart1;
|
||||
}
|
||||
else if (huart->Instance == USART2)
|
||||
{
|
||||
p_Uart = &COM_Uart2;
|
||||
}
|
||||
else if (huart->Instance == UART4)
|
||||
{
|
||||
p_Uart = &COM_Uart4;
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if(huart->ErrorCode & HAL_UART_ERROR_NE)
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
__HAL_UART_CLEAR_NEFLAG(huart);
|
||||
}
|
||||
if(huart->ErrorCode & HAL_UART_ERROR_FE)
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD>֡<EFBFBD><D6A1><EFBFBD><EFBFBD>
|
||||
__HAL_UART_CLEAR_FEFLAG(huart);
|
||||
}
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>...
|
||||
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_ORE) != RESET)
|
||||
{
|
||||
__HAL_UART_CLEAR_OREFLAG(huart); // <20><><EFBFBD><EFBFBD>ORE<52><45>־
|
||||
}
|
||||
if (__HAL_UART_GET_FLAG(huart, UART_FLAG_FE) != RESET)
|
||||
{
|
||||
__HAL_UART_CLEAR_FEFLAG(huart); // <20><><EFBFBD><EFBFBD>ORE<52><45>־
|
||||
}
|
||||
|
||||
//
|
||||
if(p_Uart != NULL)
|
||||
{
|
||||
// HAL_UART_DeInit(huart);
|
||||
// HAL_UART_Init(huart);
|
||||
// HAL_UART_DMAStop(p_Uart->Uart);
|
||||
HAL_UARTEx_ReceiveToIdle_DMA(p_Uart->Uart, p_Uart->Rx_Addr, p_Uart->Rx_DMA_Len);
|
||||
}
|
||||
}
|
||||
|
||||
// ʵ<>ֿ<EFBFBD><D6BF><EFBFBD><EFBFBD>жϻص<CFBB>
|
||||
void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size)
|
||||
{
|
||||
if (huart->Instance == USART1)
|
||||
{
|
||||
bsp_Uart_Rx_IdleInt(&COM_Uart1);
|
||||
}
|
||||
else if (huart->Instance == USART2)
|
||||
{
|
||||
bsp_Uart_Rx_IdleInt(&COM_Uart2);
|
||||
}
|
||||
else if (huart->Instance == UART4)
|
||||
{
|
||||
bsp_Uart_Rx_IdleInt(&COM_Uart4);
|
||||
}
|
||||
}
|
||||
|
||||
/* <20><><EFBFBD>ڽ<EFBFBD><DABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɻص<C9BB><D8B5><EFBFBD><EFBFBD><EFBFBD> - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD> */
|
||||
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
|
||||
{
|
||||
// if (__HAL_UART_GET_FLAG(huart, UART_FLAG_IDLE))
|
||||
// {
|
||||
// __HAL_UART_CLEAR_IDLEFLAG(huart);
|
||||
|
||||
// if (huart->Instance == USART1)
|
||||
// {
|
||||
// bsp_Uart_Rx_IdleInt(&COM_Uart1);
|
||||
// }
|
||||
// else if (huart->Instance == USART2)
|
||||
// {
|
||||
// bsp_Uart_Rx_IdleInt(&COM_Uart2);
|
||||
// }
|
||||
// else if (huart->Instance == UART4)
|
||||
// {
|
||||
// bsp_Uart_Rx_IdleInt(&COM_Uart4);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
|
||||
{
|
||||
if (huart->Instance == USART1)
|
||||
{
|
||||
COM_Uart1.Tx_DMA_TCInt(&COM_Uart1);
|
||||
}
|
||||
else if (huart->Instance == USART2)
|
||||
{
|
||||
COM_Uart2.Tx_DMA_TCInt(&COM_Uart2);
|
||||
}
|
||||
else if (huart->Instance == UART4)
|
||||
{
|
||||
RS485_RX;
|
||||
COM_Uart4.Tx_DMA_TCInt(&COM_Uart4);
|
||||
}
|
||||
}
|
||||
|
||||
59
calib_board/usr/bsp/bsp_Uart.h
Normal file
59
calib_board/usr/bsp/bsp_Uart.h
Normal file
@@ -0,0 +1,59 @@
|
||||
#ifndef _BSP_UART_H_
|
||||
#define _BSP_UART_H_
|
||||
|
||||
#include "main.h"
|
||||
#include "algo_Queue.h"
|
||||
|
||||
typedef struct bsp_Uart_t bsp_Uart_t;
|
||||
|
||||
|
||||
#define usart_type UART_HandleTypeDef
|
||||
#define dma_type DMA_HandleTypeDef
|
||||
|
||||
/*<2A><><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>*/
|
||||
typedef struct
|
||||
{
|
||||
u8 flag; /*<2A><><EFBFBD><EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD>־λ*/
|
||||
bsp_Uart_t *uart; /*ת<><D7AA><EFBFBD><EFBFBD>ȥ<EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD>*/
|
||||
u16 time_out; /*ת<><D7AA><EFBFBD><EFBFBD>ʱʱ<CAB1><CAB1>*/
|
||||
}bsp_uart_relay_t;
|
||||
|
||||
struct bsp_Uart_t
|
||||
{
|
||||
queue RxQueue; /*<2A><><EFBFBD>ݽ<EFBFBD><DDBD>ն<EFBFBD><D5B6><EFBFBD>*/
|
||||
usart_type *Uart; /*<2A><><EFBFBD><EFBFBD>*/
|
||||
|
||||
dma_type *Tx_DMA; /*DMA*/
|
||||
dma_type *Rx_DMA;
|
||||
|
||||
u8 Tx_DMA_CH;
|
||||
u8 Rx_DMA_CH;
|
||||
vu8 Tx_DMA_CompleteFlag; /*DMA<4D><41><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɱ<EFBFBD>־λ*/
|
||||
|
||||
u8 *Tx_Addr; /*DMA<4D><41><EFBFBD>˻<EFBFBD><CBBB><EFBFBD>*/
|
||||
u8 *Rx_Addr;
|
||||
u16 Tx_DMA_Len;
|
||||
u16 Rx_DMA_Len;
|
||||
|
||||
u16 Rx_Len; /*<2A><><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>*/
|
||||
u16 Rx_TimeCount; /*<2A><>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>*/
|
||||
u16 Rx_TimeOver; /*<2A><>ʱʱ<CAB1><CAB1>*/
|
||||
u8 Rx_StartFlag; /*<2A><>ʼ<EFBFBD><CABC>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־λ*/
|
||||
|
||||
|
||||
bsp_uart_relay_t relay; /*<2A><><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>*/
|
||||
void (*Init)(bsp_Uart_t *); /*<2A><>ʼ<EFBFBD><CABC>*/
|
||||
void (*Send)(bsp_Uart_t *,u8 *,u16); /*<2A><><EFBFBD>ڷ<EFBFBD><DAB7>ͺ<EFBFBD><CDBA><EFBFBD>*/
|
||||
|
||||
void (*Tx_DMA_TCInt)(bsp_Uart_t *); /*DMA<4D><41><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>*/
|
||||
|
||||
void (*Rx_IdleInt)(bsp_Uart_t *); /*<2A><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>*/
|
||||
void (*Rx_TimeIncrementInt)(bsp_Uart_t *,u16); /*<2A>жϼ<D0B6><CFBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
||||
void (*Rx_DataAnalysis)(u8 *,u16,void *); /*<2A><><EFBFBD>ݽ<EFBFBD><DDBD><EFBFBD>*/
|
||||
void (*Rx_Task)(bsp_Uart_t *); /*<2A><><EFBFBD>ڽ<EFBFBD><DABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
||||
};
|
||||
|
||||
extern bsp_Uart_t COM_Uart1;
|
||||
extern bsp_Uart_t COM_Uart2;
|
||||
extern bsp_Uart_t COM_Uart4;
|
||||
#endif
|
||||
25
calib_board/usr/bsp/bsp_Wdg.c
Normal file
25
calib_board/usr/bsp/bsp_Wdg.c
Normal file
@@ -0,0 +1,25 @@
|
||||
#include "bsp_Wdg.h"
|
||||
|
||||
//#include "iwdg.h"
|
||||
|
||||
static void bsp_Wdg_Init(void);
|
||||
static void bsp_Wdg_Feed(void);
|
||||
|
||||
bsp_Wdg_t Wdg =
|
||||
{
|
||||
.Init = bsp_Wdg_Init,
|
||||
.Feed = bsp_Wdg_Feed,
|
||||
};
|
||||
|
||||
bsp_Wdg_t *pWdg = &Wdg;
|
||||
|
||||
static void bsp_Wdg_Init(void)
|
||||
{
|
||||
// __HAL_DBGMCU_FREEZE_IWDG(); //<2F><><EFBFBD><EFBFBD>ģʽ<C4A3>£<EFBFBD><C2A3><EFBFBD><EFBFBD>ῴ<EFBFBD>Ź<EFBFBD><C5B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
||||
}
|
||||
|
||||
static void bsp_Wdg_Feed(void)
|
||||
{
|
||||
// HAL_IWDG_Refresh(&hiwdg);
|
||||
}
|
||||
|
||||
13
calib_board/usr/bsp/bsp_Wdg.h
Normal file
13
calib_board/usr/bsp/bsp_Wdg.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#ifndef _BSP_WDG_H_
|
||||
#define _BSP_WDG_H_
|
||||
|
||||
#include "main.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
void (*Init)(void);
|
||||
void (*Feed)(void);
|
||||
}bsp_Wdg_t;
|
||||
|
||||
extern bsp_Wdg_t Wdg;
|
||||
#endif
|
||||
104
calib_board/usr/bsp/sys.h
Normal file
104
calib_board/usr/bsp/sys.h
Normal file
@@ -0,0 +1,104 @@
|
||||
#ifndef _SYS_H_
|
||||
#define _SYS_H_
|
||||
|
||||
#include "stm32f4xx.h"
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>һЩ<D2BB><D0A9><EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͷ̹ؼ<CCB9><D8BC><EFBFBD>
|
||||
typedef int32_t s32;
|
||||
typedef int16_t s16;
|
||||
typedef int8_t s8;
|
||||
|
||||
typedef const int32_t sc32;
|
||||
typedef const int16_t sc16;
|
||||
typedef const int8_t sc8;
|
||||
|
||||
typedef __IO int32_t vs32;
|
||||
typedef __IO int16_t vs16;
|
||||
typedef __IO int8_t vs8;
|
||||
|
||||
typedef __I int32_t vsc32;
|
||||
typedef __I int16_t vsc16;
|
||||
typedef __I int8_t vsc8;
|
||||
|
||||
typedef uint32_t u32;
|
||||
typedef uint16_t u16;
|
||||
typedef uint8_t u8;
|
||||
|
||||
typedef const uint32_t uc32;
|
||||
typedef const uint16_t uc16;
|
||||
typedef const uint8_t uc8;
|
||||
|
||||
typedef __IO uint32_t vu32;
|
||||
typedef __IO uint16_t vu16;
|
||||
typedef __IO uint8_t vu8;
|
||||
|
||||
typedef __I uint32_t vuc32;
|
||||
typedef __I uint16_t vuc16;
|
||||
typedef __I uint8_t vuc8;
|
||||
|
||||
|
||||
#define BITBAND(addr, bitnum) ((addr & 0xF0000000)+0x2000000+((addr &0xFFFFF)<<5)+(bitnum<<2))
|
||||
#define MEM_ADDR(addr) *((volatile unsigned long *)(addr))
|
||||
#define BIT_ADDR(addr, bitnum) MEM_ADDR(BITBAND(addr, bitnum))
|
||||
//IO<49>ڵ<EFBFBD>ַӳ<D6B7><D3B3>
|
||||
#define GPIOA_ODR_Addr (GPIOA_BASE+12) //0x4001080C
|
||||
#define GPIOB_ODR_Addr (GPIOB_BASE+12) //0x40010C0C
|
||||
#define GPIOC_ODR_Addr (GPIOC_BASE+12) //0x4001100C
|
||||
#define GPIOD_ODR_Addr (GPIOD_BASE+12) //0x4001140C
|
||||
#define GPIOE_ODR_Addr (GPIOE_BASE+12) //0x4001180C
|
||||
#define GPIOF_ODR_Addr (GPIOF_BASE+12) //0x40011A0C
|
||||
#define GPIOG_ODR_Addr (GPIOG_BASE+12) //0x40011E0C
|
||||
|
||||
#define GPIOA_IDR_Addr (GPIOA_BASE+8) //0x40010808
|
||||
#define GPIOB_IDR_Addr (GPIOB_BASE+8) //0x40010C08
|
||||
#define GPIOC_IDR_Addr (GPIOC_BASE+8) //0x40011008
|
||||
#define GPIOD_IDR_Addr (GPIOD_BASE+8) //0x40011408
|
||||
#define GPIOE_IDR_Addr (GPIOE_BASE+8) //0x40011808
|
||||
#define GPIOF_IDR_Addr (GPIOF_BASE+8) //0x40011A08
|
||||
#define GPIOG_IDR_Addr (GPIOG_BASE+8) //0x40011E08
|
||||
|
||||
//IO<49>ڲ<EFBFBD><DAB2><EFBFBD>,ֻ<>Ե<EFBFBD>һ<EFBFBD><D2BB>IO<49><4F>!
|
||||
//ȷ<><C8B7>n<EFBFBD><6E>ֵС<D6B5><D0A1>16!
|
||||
#define PAout(n) BIT_ADDR(GPIOA_ODR_Addr,n) //<2F><><EFBFBD><EFBFBD>
|
||||
#define PAin(n) BIT_ADDR(GPIOA_IDR_Addr,n) //<2F><><EFBFBD><EFBFBD>
|
||||
|
||||
#define PBout(n) BIT_ADDR(GPIOB_ODR_Addr,n) //<2F><><EFBFBD><EFBFBD>
|
||||
#define PBin(n) BIT_ADDR(GPIOB_IDR_Addr,n) //<2F><><EFBFBD><EFBFBD>
|
||||
|
||||
#define PCout(n) BIT_ADDR(GPIOC_ODR_Addr,n) //<2F><><EFBFBD><EFBFBD>
|
||||
#define PCin(n) BIT_ADDR(GPIOC_IDR_Addr,n) //<2F><><EFBFBD><EFBFBD>
|
||||
|
||||
#define PDout(n) BIT_ADDR(GPIOD_ODR_Addr,n) //<2F><><EFBFBD><EFBFBD>
|
||||
#define PDin(n) BIT_ADDR(GPIOD_IDR_Addr,n) //<2F><><EFBFBD><EFBFBD>
|
||||
|
||||
#define PEout(n) BIT_ADDR(GPIOE_ODR_Addr,n) //<2F><><EFBFBD><EFBFBD>
|
||||
#define PEin(n) BIT_ADDR(GPIOE_IDR_Addr,n) //<2F><><EFBFBD><EFBFBD>
|
||||
|
||||
#define PFout(n) BIT_ADDR(GPIOF_ODR_Addr,n) //<2F><><EFBFBD><EFBFBD>
|
||||
#define PFin(n) BIT_ADDR(GPIOF_IDR_Addr,n) //<2F><><EFBFBD><EFBFBD>
|
||||
|
||||
#define PGout(n) BIT_ADDR(GPIOG_ODR_Addr,n) //<2F><><EFBFBD><EFBFBD>
|
||||
#define PGin(n) BIT_ADDR(GPIOG_IDR_Addr,n) //<2F><><EFBFBD><EFBFBD>
|
||||
/////////////////////////////////////////////////////////////////
|
||||
//Ex_NVIC_Configר<67>ö<EFBFBD><C3B6><EFBFBD>
|
||||
#define GPIO_A 0
|
||||
#define GPIO_B 1
|
||||
#define GPIO_C 2
|
||||
#define GPIO_D 3
|
||||
#define GPIO_E 4
|
||||
#define GPIO_F 5
|
||||
#define GPIO_G 6
|
||||
#define FTIR 1 //<2F>½<EFBFBD><C2BD>ش<EFBFBD><D8B4><EFBFBD>
|
||||
#define RTIR 2 //<2F><><EFBFBD><EFBFBD><EFBFBD>ش<EFBFBD><D8B4><EFBFBD>
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
1320
calib_board/usr/bsp/tjc_usart_hmi.c
Normal file
1320
calib_board/usr/bsp/tjc_usart_hmi.c
Normal file
File diff suppressed because it is too large
Load Diff
155
calib_board/usr/bsp/tjc_usart_hmi.h
Normal file
155
calib_board/usr/bsp/tjc_usart_hmi.h
Normal file
@@ -0,0 +1,155 @@
|
||||
#ifndef __TJCUSARTHMI_H_
|
||||
#define __TJCUSARTHMI_H_
|
||||
|
||||
#include "stm32f4xx.h"
|
||||
#include "main.h" // <20><><EFBFBD><EFBFBD> HAL <20><>ͷ<EFBFBD>ļ<EFBFBD>
|
||||
#include "bsp_Uart.h"
|
||||
#include "bsp_Flash.h" // <20><><EFBFBD><EFBFBD>Flash<73><68><EFBFBD><EFBFBD>֧<EFBFBD><D6A7>
|
||||
|
||||
// <20><><EFBFBD><EFBFBD>ʹ<EFBFBD>õĴ<C3B5><C4B4>ھ<EFBFBD><DABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>main.c<>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD>huart2<74><32>
|
||||
extern UART_HandleTypeDef huart2;
|
||||
|
||||
// <20><><EFBFBD>崮<EFBFBD><E5B4AE><EFBFBD><EFBFBD>ʹ<EFBFBD>õĴ<C3B5><C4B4><EFBFBD>
|
||||
#define TJC_UART huart2
|
||||
|
||||
// <20><><EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
#define RINGBUFF_LEN (500)
|
||||
|
||||
// ָ<><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>TJC<4A><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Э<EFBFBD>飩
|
||||
#define TJC_END_BYTES 0xFF
|
||||
|
||||
// <20><><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EEB3A4>
|
||||
#define MAX_COMMAND_LEN 200 // <20><><EFBFBD>ӳ<EFBFBD><D3B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD>豸<EFBFBD><E8B1B8>Ϣ
|
||||
|
||||
// <20>Զ<EFBFBD><D4B6><EFBFBD>ָ<EFBFBD><EFBFBD><EEB6A8>
|
||||
#define CUSTOM_CMD_HEADER_0 0xAA
|
||||
#define CUSTOM_CMD_HEADER_1 0x55
|
||||
|
||||
// ָ<><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
#define CMD_DISPLAY_DATA 0x02 // <20><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>
|
||||
#define CMD_ALARM 0x03 // <20><><EFBFBD><EFBFBD>
|
||||
#define CMD_DELETE_DEVICE 0x04 // ɾ<><C9BE><EFBFBD>豸
|
||||
|
||||
// <20><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
#define SUB_CMD_SHOW_DEVICES 0x01 // <20><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD><D3B5>豸
|
||||
#define SUB_CMD_REGION_STATS 0x02 // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ
|
||||
#define SUB_CMD_REGION1_DEVICES 0x03 // <20><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>豸
|
||||
#define SUB_CMD_REGION2_DEVICES 0x04 // <20>ڶ<EFBFBD><DAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>豸
|
||||
#define SUB_CMD_REGION3_DEVICES 0x05 // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>豸
|
||||
#define SUB_CMD_REGION4_DEVICES 0x06 // <20><><EFBFBD>ĸ<EFBFBD><C4B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>豸
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
#define SUB_CMD_HISTORY_ALARM 0x01 // <20><>ʷ<EFBFBD><CAB7><EFBFBD><EFBFBD>
|
||||
#define SUB_CMD_REALTIME_ALARM 0x02 // ʵʱ<CAB5><CAB1><EFBFBD><EFBFBD>
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>豸ָ<E8B1B8><D6B8>ʶ<EFBFBD><CAB6>
|
||||
#define ADD_DEVICE_CMD_BYTE 0x43 // 'C'<27><>ASCII<49><49>
|
||||
|
||||
// <20>ָ<EFBFBD><D6B8><EFBFBD>
|
||||
#define DATA_SEPARATOR 0xAA
|
||||
|
||||
// ͨ<><CDA8>״̬ö<CCAC><C3B6>
|
||||
typedef enum {
|
||||
COMM_STATUS_NORMAL = 0, // <20><><EFBFBD><EFBFBD>
|
||||
COMM_STATUS_ABNORMAL // <20>쳣
|
||||
} CommStatus;
|
||||
|
||||
// ©Һ״̬ö<CCAC><C3B6>
|
||||
typedef enum {
|
||||
LEAK_NORMAL = 0, // <20><><EFBFBD><EFBFBD>
|
||||
LEAK_ABNORMAL // ©Һ
|
||||
} LeakStatus;
|
||||
|
||||
// <20>ϴ<EFBFBD>״̬ö<CCAC><C3B6>
|
||||
typedef enum {
|
||||
BREAK_NORMAL = 0, // <20><><EFBFBD><EFBFBD>
|
||||
BREAK_ABNORMAL // <20>ϴ<EFBFBD>
|
||||
} BreakStatus;
|
||||
|
||||
// ͨ<><CDA8>״̬<D7B4>ṹ<EFBFBD><E1B9B9>
|
||||
typedef struct {
|
||||
LeakStatus leak_status; // ©Һ״̬
|
||||
BreakStatus break_status; // <20>ϴ<EFBFBD>״̬
|
||||
int leak_meter; // ©Һ<C2A9><D2BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>©Һ״̬Ϊ©Һ<C2A9><D2BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ0<CABE><30>
|
||||
} ChannelStatus;
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ö<EFBFBD><C3B6>
|
||||
typedef enum {
|
||||
ALARM_LEAK = 0, // ©Һ
|
||||
ALARM_BREAK, // <20>ϴ<EFBFBD>
|
||||
ALARM_COMM // ͨ<><CDA8><EFBFBD>쳣
|
||||
} AlarmType;
|
||||
|
||||
// <20>豸<EFBFBD><E8B1B8>Ϣ<EFBFBD>ṹ<EFBFBD><E1B9B9>
|
||||
typedef struct {
|
||||
uint8_t port; // <20>˿ں<CBBF>
|
||||
char region[20]; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӣ<EFBFBD>ģ<EFBFBD>
|
||||
uint8_t device_id; // <20>豸ID (1-254)
|
||||
char device_name[20]; // <20>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD>Ӣ<EFBFBD>ģ<EFBFBD>
|
||||
LeakStatus leak_status; // ©Һ״̬
|
||||
BreakStatus break_status; // <20>ϴ<EFBFBD>״̬
|
||||
CommStatus comm_status; // ͨ<><CDA8>״̬
|
||||
ChannelStatus channels[4]; // <20>ĸ<EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD>״̬
|
||||
} DeviceInfo;
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD>ṹ<EFBFBD><E1B9B9>
|
||||
typedef struct {
|
||||
char region[20]; // <20>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD>
|
||||
uint8_t device_id; // <20>豸ID
|
||||
char device_name[20]; // <20>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD>
|
||||
AlarmType alarm_type; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
char start_time[20]; // <20><>ʼʱ<CABC><CAB1>
|
||||
char end_time[20]; // <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
||||
} AlarmInfo;
|
||||
|
||||
// <20><><EFBFBD><EFBFBD>ͳ<EFBFBD>ƽṹ<C6BD><E1B9B9>
|
||||
typedef struct {
|
||||
char region_name[20]; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
uint8_t total_devices; // <20><><EFBFBD>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD>
|
||||
uint8_t leak_devices; // ©Һ<C2A9>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD>
|
||||
uint8_t break_devices; // <20>ϴ<EFBFBD><CFB4>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD>
|
||||
uint8_t comm_devices; // ͨ<><CDA8><EFBFBD>쳣<EFBFBD>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD>
|
||||
} RegionStats;
|
||||
|
||||
// <20>ⲿ<EFBFBD>ɵ<EFBFBD><C9B5>ú<EFBFBD><C3BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
void TJC_Init(bsp_Uart_t *pUart);
|
||||
void TJC_SendData(uint8_t *data, uint16_t len);
|
||||
void TJCPrintf(const char *cmd, ...);
|
||||
|
||||
// <20><><EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>غ<EFBFBD><D8BA><EFBFBD>
|
||||
uint16_t TJC_CleanBufferFromInvalidPatterns(void);
|
||||
void initRingBuffer(void);
|
||||
void writeRingBuff(uint8_t data);
|
||||
void deleteRingBuff(uint16_t size);
|
||||
uint16_t getRingBuffLength(void);
|
||||
uint8_t read1BFromRingBuff(uint16_t position);
|
||||
uint8_t isRingBuffOverflow(void);
|
||||
|
||||
// ָ<><EFBFBD><EEB4A6><EFBFBD><EFBFBD><EFBFBD>غ<EFBFBD><D8BA><EFBFBD>
|
||||
void TJC_ProcessCommand(uint8_t *cmd, uint16_t len);
|
||||
uint8_t TJC_CheckEndBytes(uint8_t *data, uint16_t len, uint16_t *end_pos);
|
||||
void TJC_SendResponse(const char *response);
|
||||
void TJC_ProcessSerialData(u8 *data, u16 len, void *p_arg);
|
||||
void TJC_DeleteDevices(uint8_t *delete_flags, uint8_t flag_count);
|
||||
void TJC_ProcessDeleteCommand(uint8_t *cmd, uint16_t len);
|
||||
|
||||
/*<2A><><EFBFBD>Է<EFBFBD><D4B7><EFBFBD><EFBFBD><EFBFBD>ʷ<EFBFBD><CAB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
||||
void TJC_SendInitCommands(void);
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
uint16_t CalculateCRC16(uint8_t *data, uint16_t length);
|
||||
void TJC_ProcessCustomCommand(uint8_t *cmd, uint16_t len);
|
||||
void TJC_SendAlarmHistory(void);
|
||||
void TJC_SendRealtimeAlarms(void);
|
||||
void TJC_SendDeviceList(void);
|
||||
uint8_t TJC_AddDeviceToFlash(uint8_t *data, uint16_t len);
|
||||
void TJC_SendRegionStats(void); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͳ<EFBFBD><CDB3>
|
||||
void TJC_SendRegionDeviceDetails(uint8_t region_index);
|
||||
|
||||
// <20>궨<EFBFBD><EAB6A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
#define usize getRingBuffLength()
|
||||
#define code_c() initRingBuffer()
|
||||
#define udelete(x) deleteRingBuff(x)
|
||||
#define u(x) read1BFromRingBuff(x)
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user