更新通讯协议,完善灯丝控制
This commit is contained in:
+3
-1
@@ -48,7 +48,7 @@ extern "C" {
|
||||
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN EM */
|
||||
#define VERSION_STR "V8.5.0"
|
||||
#define VERSION_STR "V1.0.0"
|
||||
#ifdef BOOTLOADER
|
||||
#define SW_VER "BL for " VERSION_STR
|
||||
#else
|
||||
@@ -69,6 +69,8 @@ void Error_Handler(void);
|
||||
/* Private defines -----------------------------------------------------------*/
|
||||
#define LED_Pin GPIO_PIN_2
|
||||
#define LED_GPIO_Port GPIOE
|
||||
#define WORK_CMD_Pin GPIO_PIN_3
|
||||
#define WORK_CMD_GPIO_Port GPIOE
|
||||
#define I_FILA_Pin GPIO_PIN_5
|
||||
#define I_FILA_GPIO_Port GPIOC
|
||||
#define V_FILA_Pin GPIO_PIN_0
|
||||
|
||||
@@ -900,6 +900,12 @@ static void MX_GPIO_Init(void)
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(LED_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pin : WORK_CMD_Pin */
|
||||
GPIO_InitStruct.Pin = WORK_CMD_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(WORK_CMD_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pin : WDI_Pin */
|
||||
GPIO_InitStruct.Pin = WDI_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include "cmsis_os.h"
|
||||
#include "cpy_prot.h"
|
||||
#include "Param/param.h"
|
||||
#include "ADS8321/ads8321.h"
|
||||
#include "Filament/filament.h"
|
||||
#include "IAP/iap.h"
|
||||
|
||||
char gacVersionBuf[32];
|
||||
@@ -14,14 +14,13 @@ extern UART_HandleTypeDef huart4;
|
||||
static uint16_t gusMaxDataLen = 16 * 1024;
|
||||
|
||||
|
||||
static daq_packet_t *tx_packet_buf = NULL;
|
||||
static daq_packet_t *rx_packet_buf = NULL;
|
||||
static cpy_prot_packet_t *tx_packet_buf = NULL;
|
||||
static cpy_prot_packet_t *rx_packet_buf = NULL;
|
||||
static int rx_packet_ready = 0;
|
||||
static int tx_packet_busy = 0;
|
||||
|
||||
//函数声明
|
||||
static int daq_recv_packet(uint16_t data_len);
|
||||
|
||||
static int cpy_prot_recv_packet(uint16_t data_len);
|
||||
|
||||
static uint16_t crc16(const uint8_t *data, uint16_t len) {
|
||||
uint16_t crc = 0xFFFF;
|
||||
@@ -39,8 +38,8 @@ static uint16_t crc16(const uint8_t *data, uint16_t len) {
|
||||
return crc;
|
||||
}
|
||||
|
||||
static int check_packet(daq_packet_t *packet) {
|
||||
if (packet->header != DAQ_HEADER) {
|
||||
static int check_packet(cpy_prot_packet_t *packet) {
|
||||
if (packet->header != CPY_PROT_HEADER) {
|
||||
printf("header error, 0x%04X\r\n", packet->header);
|
||||
return 0;
|
||||
}
|
||||
@@ -94,12 +93,12 @@ void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
|
||||
}
|
||||
}
|
||||
|
||||
static int daq_send(const char *data, size_t len) {
|
||||
static int start_send(const char *data, size_t len) {
|
||||
//SCB_CleanDCache_by_Addr((volatile void *)data, len);
|
||||
return HAL_UART_Transmit_DMA(&huart4, (uint8_t *)data, len);
|
||||
}
|
||||
|
||||
static int daq_recv(char *data, size_t len) {
|
||||
static int start_recv(char *data, size_t len) {
|
||||
if (huart4.gState != HAL_UART_STATE_READY) {
|
||||
HAL_UART_AbortReceive(&huart4);
|
||||
}
|
||||
@@ -108,10 +107,10 @@ static int daq_recv(char *data, size_t len) {
|
||||
}
|
||||
|
||||
|
||||
int daq_send_packet(uint8_t cmd, const uint8_t *data, uint16_t len) {
|
||||
int cpy_prot_send_packet(uint8_t cmd, const uint8_t *data, uint16_t len) {
|
||||
uint16_t packet_len = DATA_LEN_2_PACKET_LEN(len);
|
||||
daq_packet_t *packet = tx_packet_buf;
|
||||
packet->header = DAQ_HEADER;
|
||||
cpy_prot_packet_t *packet = tx_packet_buf;
|
||||
packet->header = CPY_PROT_HEADER;
|
||||
packet->cmd = cmd;
|
||||
packet->len = len;
|
||||
if (data) {
|
||||
@@ -123,19 +122,16 @@ int daq_send_packet(uint8_t cmd, const uint8_t *data, uint16_t len) {
|
||||
uint16_t *pcrc = (uint16_t *)((uint8_t *)packet + packet_len - CRC_LEN);
|
||||
*pcrc = crc;
|
||||
|
||||
int ret = daq_send((const char *)packet, packet_len);
|
||||
int ret = start_send((const char *)packet, packet_len);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int cpy_prot_recv_packet(uint16_t data_len) {
|
||||
cpy_prot_packet_t *rx_packet = rx_packet_buf;
|
||||
|
||||
static int daq_recv_packet(uint16_t data_len) {
|
||||
daq_packet_t *rx_packet = rx_packet_buf;
|
||||
|
||||
return daq_recv((char *)rx_packet, DATA_LEN_2_PACKET_LEN(data_len));
|
||||
return start_recv((char *)rx_packet, DATA_LEN_2_PACKET_LEN(data_len));
|
||||
}
|
||||
|
||||
|
||||
|
||||
int cpyProtPacketHandle(uint8_t cmd, const uint8_t *data, uint16_t len) {
|
||||
// 处理接收到的数据包
|
||||
// printf("recv packet: cmd=0x%02X, len=%d\r\n", cmd, len);
|
||||
@@ -145,31 +141,35 @@ int cpyProtPacketHandle(uint8_t cmd, const uint8_t *data, uint16_t len) {
|
||||
case CPY_PROT_CMD_HEARTBEAT:
|
||||
{
|
||||
extern uint16_t gusTempVal;
|
||||
uint8_t aucRspData[10];
|
||||
uint8_t aucRspData[13];
|
||||
*((uint32_t *)&aucRspData[0]) = osKernelGetTickCount();
|
||||
*((uint16_t *)&aucRspData[4]) = gusTempVal;
|
||||
daq_send_packet(cmd | CPY_PROT_CMD_ACK, aucRspData, sizeof(aucRspData));
|
||||
*((uint16_t *)&aucRspData[6]) = gusFilamentCurrent;
|
||||
*((uint16_t *)&aucRspData[8]) = gusFilamentVoltage;
|
||||
*((uint16_t *)&aucRspData[10]) = gusXrayCurrent;
|
||||
aucRspData[12] = gucWorkState;
|
||||
cpy_prot_send_packet(cmd | CPY_PROT_CMD_ACK, aucRspData, sizeof(aucRspData));
|
||||
}
|
||||
break;
|
||||
|
||||
case CPY_PROT_CMD_VERSION:
|
||||
daq_send_packet(cmd | CPY_PROT_CMD_ACK, (const uint8_t *)gacVersionBuf, strlen(gacVersionBuf));
|
||||
cpy_prot_send_packet(cmd | CPY_PROT_CMD_ACK, (const uint8_t *)gacVersionBuf, strlen(gacVersionBuf));
|
||||
break;
|
||||
|
||||
case CPY_PROT_CMD_PARAM_READ:
|
||||
|
||||
daq_send_packet(cmd | CPY_PROT_CMD_ACK, (const uint8_t *)gptSysParam, sizeof(sysParamDef));
|
||||
cpy_prot_send_packet(cmd | CPY_PROT_CMD_ACK, (const uint8_t *)gptSysParam, sizeof(sysParamDef));
|
||||
break;
|
||||
|
||||
case CPY_PROT_CMD_PARAM_WRITE:
|
||||
if (len != sizeof(sysParamDef)) {
|
||||
const char *err_msg = "param write len error";
|
||||
daq_send_packet(cmd | CPY_PROT_CMD_ACK, (const uint8_t *)err_msg, strlen(err_msg));
|
||||
cpy_prot_send_packet(cmd | CPY_PROT_CMD_ACK, (const uint8_t *)err_msg, strlen(err_msg));
|
||||
break;
|
||||
}
|
||||
memcpy(gptSysParam, data, sizeof(sysParamDef));
|
||||
saveSysParam();
|
||||
daq_send_packet(cmd | CPY_PROT_CMD_ACK, (const uint8_t *)gptSysParam, sizeof(sysParamDef));
|
||||
cpy_prot_send_packet(cmd | CPY_PROT_CMD_ACK, (const uint8_t *)gptSysParam, sizeof(sysParamDef));
|
||||
break;
|
||||
|
||||
case CPY_PROT_CMD_IAP:
|
||||
@@ -178,31 +178,31 @@ int cpyProtPacketHandle(uint8_t cmd, const uint8_t *data, uint16_t len) {
|
||||
#ifdef BOOTLOADER
|
||||
case CPY_PROT_CMD_BOOT_BLOCKING:
|
||||
blockInBootloader(data[0]);
|
||||
daq_send_packet(cmd | CPY_PROT_CMD_ACK, NULL, 0);
|
||||
cpy_prot_send_packet(cmd | CPY_PROT_CMD_ACK, NULL, 0);
|
||||
printf("CPY_PROT_CMD_BOOT_BLOCKING\r\n");
|
||||
break;
|
||||
case CPY_PROT_CMD_JUMP_APP:
|
||||
daq_send_packet(cmd | CPY_PROT_CMD_ACK, NULL, 0);
|
||||
cpy_prot_send_packet(cmd | CPY_PROT_CMD_ACK, NULL, 0);
|
||||
osDelay(100);
|
||||
blockInBootloader(0);
|
||||
break;
|
||||
#endif
|
||||
case CPY_PROT_CMD_RESET:
|
||||
daq_send_packet(cmd | CPY_PROT_CMD_ACK, NULL, 0);
|
||||
cpy_prot_send_packet(cmd | CPY_PROT_CMD_ACK, NULL, 0);
|
||||
osDelay(100);
|
||||
systemReboot();
|
||||
break;
|
||||
case CPY_PROT_CMD_OTP_READ:
|
||||
{
|
||||
const sysOtpInfoDef *otpInfo = loadOtpInfo();
|
||||
daq_send_packet(cmd | CPY_PROT_CMD_ACK, (const uint8_t *)otpInfo, sizeof(sysOtpInfoDef));
|
||||
cpy_prot_send_packet(cmd | CPY_PROT_CMD_ACK, (const uint8_t *)otpInfo, sizeof(sysOtpInfoDef));
|
||||
}
|
||||
break;
|
||||
case CPY_PROT_CMD_OTP_WRITE:
|
||||
{
|
||||
if (len != sizeof(sysOtpInfoDef)) {
|
||||
const char *err_msg = "otp write len error";
|
||||
daq_send_packet(cmd | CPY_PROT_CMD_ERROR, (const uint8_t *)err_msg, strlen(err_msg));
|
||||
cpy_prot_send_packet(cmd | CPY_PROT_CMD_ERROR, (const uint8_t *)err_msg, strlen(err_msg));
|
||||
break;
|
||||
}
|
||||
const sysOtpInfoDef *otpInfo = (const sysOtpInfoDef *)data;
|
||||
@@ -210,25 +210,41 @@ int cpyProtPacketHandle(uint8_t cmd, const uint8_t *data, uint16_t len) {
|
||||
if (ret < 0) {
|
||||
char err_msg[64];
|
||||
sprintf(err_msg, "otp write failed: %d", ret);
|
||||
daq_send_packet(cmd | CPY_PROT_CMD_ERROR, (const uint8_t *)err_msg, strlen(err_msg));
|
||||
cpy_prot_send_packet(cmd | CPY_PROT_CMD_ERROR, (const uint8_t *)err_msg, strlen(err_msg));
|
||||
break;
|
||||
}
|
||||
otpInfo = loadOtpInfo();
|
||||
daq_send_packet(cmd | CPY_PROT_CMD_ACK, (const uint8_t *)otpInfo, sizeof(sysOtpInfoDef));
|
||||
cpy_prot_send_packet(cmd | CPY_PROT_CMD_ACK, (const uint8_t *)otpInfo, sizeof(sysOtpInfoDef));
|
||||
}
|
||||
break;
|
||||
case CPY_PROT_CMD_RESET_FACTORY:
|
||||
{
|
||||
systemResetFactory();
|
||||
const char *err_msg = "reset factory ok";
|
||||
daq_send_packet(cmd | CPY_PROT_CMD_ACK, (const uint8_t *)err_msg, strlen(err_msg));
|
||||
cpy_prot_send_packet(cmd | CPY_PROT_CMD_ACK, (const uint8_t *)err_msg, strlen(err_msg));
|
||||
}
|
||||
break;
|
||||
case CPY_PROT_CMD_START:
|
||||
{
|
||||
if (gucWorkState == 0) {
|
||||
gucWorkState = 1;
|
||||
}
|
||||
const char *err_msg = "start ok";
|
||||
cpy_prot_send_packet(cmd | CPY_PROT_CMD_ACK, (const uint8_t *)err_msg, strlen(err_msg));
|
||||
}
|
||||
break;
|
||||
case CPY_PROT_CMD_STOP:
|
||||
{
|
||||
gucWorkState = 0;
|
||||
const char *err_msg = "stop ok";
|
||||
cpy_prot_send_packet(cmd | CPY_PROT_CMD_ACK, (const uint8_t *)err_msg, strlen(err_msg));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
const char *err_msg = "unknown cmd";
|
||||
printf("%s\n", err_msg);
|
||||
daq_send_packet(cmd | CPY_PROT_CMD_ACK, (const uint8_t *)err_msg, strlen(err_msg));
|
||||
cpy_prot_send_packet(cmd | CPY_PROT_CMD_ACK, (const uint8_t *)err_msg, strlen(err_msg));
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -257,7 +273,7 @@ static void ioCheck(void)
|
||||
static void cpyProtThread(void *arg)
|
||||
{
|
||||
int iCnt = 0;
|
||||
daq_recv_packet(gusMaxDataLen);
|
||||
cpy_prot_recv_packet(gusMaxDataLen);
|
||||
|
||||
while (1) {
|
||||
iCnt++;
|
||||
@@ -271,10 +287,10 @@ static void cpyProtThread(void *arg)
|
||||
// printf("wait tx complete timeout\n");
|
||||
// }
|
||||
// tx_packet_busy = 0;
|
||||
daq_recv_packet(gusMaxDataLen);
|
||||
cpy_prot_recv_packet(gusMaxDataLen);
|
||||
} else if (rx_packet_ready == -1) {
|
||||
rx_packet_ready = 0;
|
||||
daq_recv_packet(gusMaxDataLen);
|
||||
cpy_prot_recv_packet(gusMaxDataLen);
|
||||
}
|
||||
|
||||
ioCheck();
|
||||
@@ -282,7 +298,6 @@ static void cpyProtThread(void *arg)
|
||||
osDelay(1);
|
||||
if (iCnt > 1000) {
|
||||
iCnt = 0;
|
||||
// daq_send("hello", 5);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,9 +6,9 @@
|
||||
#include "main.h"
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
|
||||
#define DAQ_HEADER 0x55AA
|
||||
#define DAQ_DATA_MIN_LEN 10
|
||||
#define CRC_LEN 2
|
||||
#define CPY_PROT_HEADER 0x55CC
|
||||
#define CPY_PROT_DATA_MIN_LEN 10
|
||||
#define CRC_LEN 2
|
||||
|
||||
|
||||
typedef enum {
|
||||
@@ -26,6 +26,9 @@ typedef enum {
|
||||
CPY_PROT_CMD_OTP_WRITE,
|
||||
CPY_PROT_CMD_RESET_FACTORY,
|
||||
|
||||
CPY_PROT_CMD_START = 0x10,
|
||||
CPY_PROT_CMD_STOP,
|
||||
|
||||
CPY_PROT_CMD_ACK = 0x80,
|
||||
CPY_PROT_CMD_ERROR = 0xC0,
|
||||
} cpy_prot_cmd_t;
|
||||
@@ -36,15 +39,14 @@ typedef struct {
|
||||
uint16_t header;
|
||||
uint8_t cmd;
|
||||
uint16_t len;
|
||||
uint8_t data[DAQ_DATA_MIN_LEN];
|
||||
} daq_packet_t;
|
||||
uint8_t data[CPY_PROT_DATA_MIN_LEN];
|
||||
} cpy_prot_packet_t;
|
||||
#pragma pack()
|
||||
|
||||
#define DATA_LEN_2_PACKET_LEN(data_len) ((data_len) < DAQ_DATA_MIN_LEN ? (sizeof(daq_packet_t) + CRC_LEN) : ((data_len) + sizeof(daq_packet_t) - DAQ_DATA_MIN_LEN + CRC_LEN))
|
||||
|
||||
#define DATA_LEN_2_PACKET_LEN(data_len) ((data_len) < CPY_PROT_DATA_MIN_LEN ? (sizeof(cpy_prot_packet_t) + CRC_LEN) : ((data_len) + sizeof(cpy_prot_packet_t) - CPY_PROT_DATA_MIN_LEN + CRC_LEN))
|
||||
|
||||
void cpyProtInit(void);
|
||||
int daq_send_packet(uint8_t cmd, const uint8_t *data, uint16_t len);
|
||||
int cpy_prot_send_packet(uint8_t cmd, const uint8_t *data, uint16_t len);
|
||||
|
||||
|
||||
#endif // CPY_PROT_H
|
||||
|
||||
@@ -1,34 +1,26 @@
|
||||
#include "main.h"
|
||||
#include "cmsis_os.h"
|
||||
#include "filament.h"
|
||||
|
||||
#include "CPY_PROT/cpy_prot.h"
|
||||
#include "Param/param.h"
|
||||
|
||||
extern TIM_HandleTypeDef htim1;
|
||||
extern ADC_HandleTypeDef hadc1;
|
||||
extern DMA_HandleTypeDef hdma_adc1;
|
||||
|
||||
uint16_t gausAdcBuf[ADC_CHNL_NUM];
|
||||
static uint16_t gausAdcBuf[ADC_CHNL_NUM];
|
||||
static uint16_t gusDuty = 0;
|
||||
static uint16_t gusPreheatDuty = 0;
|
||||
static uint16_t gusNormalDuty = 0;
|
||||
|
||||
void ifilaAdust(void)
|
||||
{
|
||||
static uint32_t ulLastTick = 0;
|
||||
uint32_t ulTick = osKernelGetTickCount();
|
||||
if (ulTick - ulLastTick < 5000) {
|
||||
return;
|
||||
}
|
||||
ulLastTick = ulTick;
|
||||
uint8_t gucWorkState = 0;
|
||||
|
||||
if (gusDuty == 0) {
|
||||
gusDuty = 300;
|
||||
} else if (gusDuty == 300) {
|
||||
gusDuty = 600;
|
||||
} else if (gusDuty == 600) {
|
||||
gusDuty = 300;
|
||||
}
|
||||
static uint16_t gusPreheatCurrent = 0;
|
||||
static uint16_t gusLimitCurrent = 0;
|
||||
|
||||
__HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, gusDuty);
|
||||
}
|
||||
uint16_t gusFilamentCurrent = 0;
|
||||
uint16_t gusFilamentVoltage = 0;
|
||||
uint16_t gusXrayCurrent = 0;
|
||||
|
||||
uint16_t adc2voltage(uint16_t adcVal)
|
||||
{
|
||||
@@ -45,11 +37,67 @@ uint16_t adc2Vflla(uint16_t adcVal)
|
||||
return adc2voltage(adcVal) * 3;
|
||||
}
|
||||
|
||||
uint16_t adc2Xray(uint16_t adcVal)
|
||||
{
|
||||
return adc2voltage(adcVal) * 1000 / 3 / 250;
|
||||
}
|
||||
|
||||
void currentUpdate(void)
|
||||
{
|
||||
int iCurrent = gusFilamentCurrent;
|
||||
int iXrayCurrent = gusXrayCurrent;
|
||||
|
||||
if (gucWorkState == 1) {
|
||||
uint16_t usAimCurrent = gusPreheatCurrent;
|
||||
if (iCurrent > usAimCurrent + 500) {
|
||||
gusPreheatDuty -= 10;
|
||||
} else if (iCurrent > usAimCurrent + 300) {
|
||||
gusPreheatDuty -= 5;
|
||||
} else if (iCurrent > usAimCurrent + 100) {
|
||||
gusPreheatDuty -= 2;
|
||||
} else if (iCurrent > usAimCurrent + 10) {
|
||||
gusPreheatDuty -= 1;
|
||||
} else if (iCurrent < usAimCurrent - 500) {
|
||||
gusPreheatDuty += 10;
|
||||
} else if (iCurrent < usAimCurrent - 300) {
|
||||
gusPreheatDuty += 5;
|
||||
} else if (iCurrent < usAimCurrent - 100) {
|
||||
gusPreheatDuty += 2;
|
||||
} else if (iCurrent < usAimCurrent - 10) {
|
||||
gusPreheatDuty += 1;
|
||||
}
|
||||
gusDuty = gusPreheatDuty;
|
||||
} else if (gucWorkState == 2) {
|
||||
if (iCurrent > gusLimitCurrent + 200) {
|
||||
gusNormalDuty -= 5;
|
||||
} else if (iCurrent > gusLimitCurrent + 100) {
|
||||
gusNormalDuty -= 2;
|
||||
} else if (iCurrent > gusLimitCurrent) {
|
||||
gusNormalDuty -= 1;
|
||||
}
|
||||
gusDuty = gusNormalDuty;
|
||||
}
|
||||
|
||||
__HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, gusDuty);
|
||||
}
|
||||
|
||||
static void filamentThread(void *arg)
|
||||
{
|
||||
int iWorkCmd = 0;
|
||||
int iCnt = 0;
|
||||
|
||||
loadSysParam();
|
||||
if ((gptSysParam->usPreheatCurrent < 100) || (gptSysParam->usPreheatCurrent > 5000)) {
|
||||
gusPreheatCurrent = 2000;
|
||||
} else {
|
||||
gusPreheatCurrent = gptSysParam->usPreheatCurrent;
|
||||
}
|
||||
if ((gptSysParam->usLimitCurrent < 100) || (gptSysParam->usLimitCurrent > 5000)) {
|
||||
gusLimitCurrent = 3500;
|
||||
} else {
|
||||
gusLimitCurrent = gptSysParam->usLimitCurrent;
|
||||
}
|
||||
|
||||
HAL_ADCEx_Calibration_Start(&hadc1, ADC_CALIB_OFFSET, ADC_SINGLE_ENDED);
|
||||
|
||||
HAL_ADCEx_MultiModeStart_DMA(&hadc1, (uint32_t *)gausAdcBuf, ADC_CHNL_NUM);
|
||||
@@ -62,21 +110,56 @@ static void filamentThread(void *arg)
|
||||
|
||||
HAL_TIMEx_PWMN_Start(&htim1, TIM_CHANNEL_1);
|
||||
|
||||
ifilaAdust();
|
||||
while (1) {
|
||||
osDelay(10);
|
||||
// ifilaAdust();
|
||||
osDelay(1);
|
||||
SCB_InvalidateDCache_by_Addr(gausAdcBuf, ADC_CHNL_NUM * sizeof(gausAdcBuf[0]));
|
||||
|
||||
gusXrayCurrent = adc2Xray(gausAdcBuf[0]);
|
||||
gusFilamentCurrent = adc2Iflla(gausAdcBuf[1]);
|
||||
gusFilamentVoltage = adc2Vflla(gausAdcBuf[2]);
|
||||
|
||||
if (gucWorkState != 0) {
|
||||
if (HAL_GPIO_ReadPin(WORK_CMD_GPIO_Port, WORK_CMD_Pin) == GPIO_PIN_RESET) {
|
||||
iWorkCmd++;
|
||||
if (iWorkCmd > 3) {
|
||||
iWorkCmd = 3;
|
||||
if (gucWorkState == 1) {
|
||||
gucWorkState = 2;
|
||||
if (gusNormalDuty == 0) {
|
||||
gusNormalDuty = gusPreheatDuty * 2;
|
||||
}
|
||||
gusDuty = gusNormalDuty;
|
||||
__HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, gusDuty);
|
||||
osDelay(3);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
iWorkCmd--;
|
||||
if (iWorkCmd < 0) {
|
||||
iWorkCmd = 0;
|
||||
if (gucWorkState == 2) {
|
||||
gucWorkState = 1;
|
||||
gusDuty = gusPreheatDuty;
|
||||
__HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, gusDuty);
|
||||
osDelay(3);
|
||||
}
|
||||
}
|
||||
}
|
||||
currentUpdate();
|
||||
} else {
|
||||
gusDuty = 0;
|
||||
__HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, gusDuty);
|
||||
}
|
||||
|
||||
iCnt++;
|
||||
|
||||
if (iCnt < 100) {
|
||||
if (iCnt < 1000) {
|
||||
continue;
|
||||
}
|
||||
iCnt = 0;
|
||||
|
||||
SCB_InvalidateDCache_by_Addr(gausAdcBuf, ADC_CHNL_NUM * sizeof(gausAdcBuf[0]));
|
||||
printf("ADC: %d,%d,%d\n", gausAdcBuf[0], gausAdcBuf[1], gausAdcBuf[2]);
|
||||
printf("duty:%d%%,I:%.2fA,V:%.2fV\n", gusDuty*100/2400, adc2Iflla(gausAdcBuf[1]) / 1000.0, adc2Vflla(gausAdcBuf[2])/1000.0);
|
||||
printf("duty:%d%%,I:%.3fA,V:%.2fV\n", gusDuty, gusFilamentCurrent/1000.0, gusFilamentVoltage/1000.0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,10 @@
|
||||
#include "main.h"
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
|
||||
extern uint8_t gucWorkState;
|
||||
extern uint16_t gusFilamentCurrent;
|
||||
extern uint16_t gusFilamentVoltage;
|
||||
extern uint16_t gusXrayCurrent;
|
||||
void filamentInit(void);
|
||||
|
||||
|
||||
|
||||
@@ -33,8 +33,6 @@ typedef struct __iapPacketDef {
|
||||
|
||||
#pragma pack()
|
||||
|
||||
static int init_ok = 0;
|
||||
|
||||
|
||||
uint16_t getBoardTemp(void);
|
||||
|
||||
@@ -213,10 +211,10 @@ int iapPacketHandler(const uint8_t *packet)
|
||||
if (len > 0) {
|
||||
FLASH_If_Erase(len);
|
||||
char *str = "erase success";
|
||||
daq_send_packet( CPY_PROT_CMD_IAP | CPY_PROT_CMD_ACK, (uint8_t *)str, strlen(str));
|
||||
cpy_prot_send_packet( CPY_PROT_CMD_IAP | CPY_PROT_CMD_ACK, (uint8_t *)str, strlen(str));
|
||||
} else {
|
||||
char *str = "erase failed";
|
||||
daq_send_packet( CPY_PROT_CMD_IAP | CPY_PROT_CMD_ERROR, (uint8_t *)str, strlen(str));
|
||||
cpy_prot_send_packet( CPY_PROT_CMD_IAP | CPY_PROT_CMD_ERROR, (uint8_t *)str, strlen(str));
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -229,11 +227,11 @@ int iapPacketHandler(const uint8_t *packet)
|
||||
if (ret == 0) {
|
||||
printf("write success at %d\n", addr);
|
||||
char *str = "write success";
|
||||
daq_send_packet( CPY_PROT_CMD_IAP | CPY_PROT_CMD_ACK, (uint8_t *)str, strlen(str));
|
||||
cpy_prot_send_packet( CPY_PROT_CMD_IAP | CPY_PROT_CMD_ACK, (uint8_t *)str, strlen(str));
|
||||
} else {
|
||||
printf("write failed at %d\n", addr);
|
||||
char *str = "write failed";
|
||||
daq_send_packet( CPY_PROT_CMD_IAP | CPY_PROT_CMD_ERROR, (uint8_t *)str, strlen(str));
|
||||
cpy_prot_send_packet( CPY_PROT_CMD_IAP | CPY_PROT_CMD_ERROR, (uint8_t *)str, strlen(str));
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -8,6 +8,7 @@ sysOtpInfoDef _gtOtpInfo;
|
||||
sysParamDef *gptSysParam = &_gtSystemParam;
|
||||
sysOtpInfoDef *gptOtpInfo = &_gtOtpInfo;
|
||||
|
||||
|
||||
int loadSysParam(void)
|
||||
{
|
||||
debug("load param");
|
||||
|
||||
@@ -5,10 +5,9 @@
|
||||
#pragma pack(1)
|
||||
typedef struct __sysParamDef
|
||||
{
|
||||
uint16_t usAdcPeriod; ///< 定时采样周期 微秒
|
||||
uint16_t usAdcinterval; ///< 定距采样间隔 微米
|
||||
uint8_t ucUseEncoder; ///< 启用编码器
|
||||
uint8_t ucAverageCount; ///< 平均次数
|
||||
uint16_t usPreheatCurrent; ///< 预热电流 单位:毫安
|
||||
uint16_t usLimitCurrent; ///< 电流限制 单位:毫安
|
||||
uint16_t usXrayCurrent; ///< X射线电流 单位:微安
|
||||
} sysParamDef;
|
||||
|
||||
typedef struct __sysOtpInfoDef
|
||||
|
||||
+36
-31
@@ -203,37 +203,38 @@ Mcu.IPNb=16
|
||||
Mcu.Name=STM32H750VBTx
|
||||
Mcu.Package=LQFP100
|
||||
Mcu.Pin0=PE2
|
||||
Mcu.Pin1=PH0-OSC_IN (PH0)
|
||||
Mcu.Pin10=PB11
|
||||
Mcu.Pin11=PB14
|
||||
Mcu.Pin12=PD8
|
||||
Mcu.Pin13=PD9
|
||||
Mcu.Pin14=PD12
|
||||
Mcu.Pin15=PD13
|
||||
Mcu.Pin16=PA9
|
||||
Mcu.Pin17=PA10
|
||||
Mcu.Pin18=PA15 (JTDI)
|
||||
Mcu.Pin19=PD0
|
||||
Mcu.Pin2=PH1-OSC_OUT (PH1)
|
||||
Mcu.Pin20=PD1
|
||||
Mcu.Pin21=PD7
|
||||
Mcu.Pin22=PB3 (JTDO/TRACESWO)
|
||||
Mcu.Pin23=PB4 (NJTRST)
|
||||
Mcu.Pin24=PB6
|
||||
Mcu.Pin25=VP_FREERTOS_VS_CMSIS_V2
|
||||
Mcu.Pin26=VP_IWDG1_VS_IWDG
|
||||
Mcu.Pin27=VP_SYS_VS_tim13
|
||||
Mcu.Pin28=VP_TIM1_VS_ClockSourceINT
|
||||
Mcu.Pin29=VP_TIM3_VS_ClockSourceINT
|
||||
Mcu.Pin3=PA6
|
||||
Mcu.Pin30=VP_MEMORYMAP_VS_MEMORYMAP
|
||||
Mcu.Pin4=PA7
|
||||
Mcu.Pin5=PC5
|
||||
Mcu.Pin6=PB0
|
||||
Mcu.Pin7=PB1
|
||||
Mcu.Pin8=PE9
|
||||
Mcu.Pin9=PB10
|
||||
Mcu.PinsNb=31
|
||||
Mcu.Pin1=PE3
|
||||
Mcu.Pin10=PB10
|
||||
Mcu.Pin11=PB11
|
||||
Mcu.Pin12=PB14
|
||||
Mcu.Pin13=PD8
|
||||
Mcu.Pin14=PD9
|
||||
Mcu.Pin15=PD12
|
||||
Mcu.Pin16=PD13
|
||||
Mcu.Pin17=PA9
|
||||
Mcu.Pin18=PA10
|
||||
Mcu.Pin19=PA15 (JTDI)
|
||||
Mcu.Pin2=PH0-OSC_IN (PH0)
|
||||
Mcu.Pin20=PD0
|
||||
Mcu.Pin21=PD1
|
||||
Mcu.Pin22=PD7
|
||||
Mcu.Pin23=PB3 (JTDO/TRACESWO)
|
||||
Mcu.Pin24=PB4 (NJTRST)
|
||||
Mcu.Pin25=PB6
|
||||
Mcu.Pin26=VP_FREERTOS_VS_CMSIS_V2
|
||||
Mcu.Pin27=VP_IWDG1_VS_IWDG
|
||||
Mcu.Pin28=VP_SYS_VS_tim13
|
||||
Mcu.Pin29=VP_TIM1_VS_ClockSourceINT
|
||||
Mcu.Pin3=PH1-OSC_OUT (PH1)
|
||||
Mcu.Pin30=VP_TIM3_VS_ClockSourceINT
|
||||
Mcu.Pin31=VP_MEMORYMAP_VS_MEMORYMAP
|
||||
Mcu.Pin4=PA6
|
||||
Mcu.Pin5=PA7
|
||||
Mcu.Pin6=PC5
|
||||
Mcu.Pin7=PB0
|
||||
Mcu.Pin8=PB1
|
||||
Mcu.Pin9=PE9
|
||||
Mcu.PinsNb=32
|
||||
Mcu.ThirdPartyNb=0
|
||||
Mcu.UserConstants=
|
||||
Mcu.UserName=STM32H750VBTx
|
||||
@@ -346,6 +347,10 @@ PE2.GPIOParameters=GPIO_Label
|
||||
PE2.GPIO_Label=LED
|
||||
PE2.Locked=true
|
||||
PE2.Signal=GPIO_Output
|
||||
PE3.GPIOParameters=GPIO_Label
|
||||
PE3.GPIO_Label=WORK_CMD
|
||||
PE3.Locked=true
|
||||
PE3.Signal=GPIO_Input
|
||||
PE9.Signal=S_TIM1_CH1
|
||||
PH0-OSC_IN\ (PH0).Mode=HSE-External-Oscillator
|
||||
PH0-OSC_IN\ (PH0).Signal=RCC_OSC_IN
|
||||
|
||||
Reference in New Issue
Block a user