[fix] first adapt for lark-1s
This commit is contained in:
parent
74f37f854d
commit
c3363cfc36
@ -8,8 +8,6 @@
|
||||
#include "ms5611.h"
|
||||
#include "adc.h"
|
||||
#include "cali.h"
|
||||
#include "debug.h"
|
||||
#include "cli.h"
|
||||
#include "stm32f4xx_rcc.h"
|
||||
|
||||
uint32_t system_tick_cnt;
|
||||
@ -52,8 +50,6 @@ void system_init(void)
|
||||
filter_init();
|
||||
adc_init();
|
||||
cali_init();
|
||||
debug_init();
|
||||
cli_init();
|
||||
system_tick_init();
|
||||
device_init();
|
||||
ltc2640_init();
|
||||
@ -72,7 +68,6 @@ int main(void)
|
||||
filter_loop();
|
||||
concentration_loop();
|
||||
adc_loop();
|
||||
cli_loop();
|
||||
ltc2640_loop();
|
||||
ms5611_loop();
|
||||
}
|
||||
|
||||
@ -15,8 +15,6 @@ modbus.c
|
||||
adc.c
|
||||
cali.c
|
||||
cali_flash.c
|
||||
debug.c
|
||||
cli.c
|
||||
)
|
||||
|
||||
add_library(src STATIC ${FILELIST})
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
#include "adc.h"
|
||||
#include "device.h"
|
||||
#include "debug.h"
|
||||
#include "stm32f4xx_rcc.h"
|
||||
#include "stm32f4xx_gpio.h"
|
||||
#include "stm32f4xx_adc.h"
|
||||
@ -142,24 +141,20 @@ void adc_loop(void)
|
||||
}
|
||||
ms = system_tick_cnt;
|
||||
val = adc_read();
|
||||
debug_write_data(20 + ch, (float)val);
|
||||
adc_input_data(ch, val); /* input data from ADC to sort buffer */
|
||||
if (ch == 0) {
|
||||
val = adc_get_filter_data(ch);
|
||||
value = adc_rtot(val);
|
||||
debug_write_data(24 + ch, (float)value);
|
||||
device_data.detector_temperature = value;
|
||||
ch = 1;
|
||||
} else if (ch == 1) {
|
||||
val = adc_get_filter_data(ch);
|
||||
value = adc_rtot(val);
|
||||
debug_write_data(24 + ch, (float)value);
|
||||
device_data.lamp_temperature = value;
|
||||
ch = 3;
|
||||
} else if (ch == 3) {
|
||||
val = adc_get_filter_data(ch);
|
||||
value = (uint32_t)val * 6600 / 4096;
|
||||
debug_write_data(24 + ch, (float)value);
|
||||
device_data.lamp_voltage = value;
|
||||
ch = 0;
|
||||
} else {
|
||||
|
||||
@ -1,353 +0,0 @@
|
||||
#include "cli.h"
|
||||
#include "stm32f4xx_rcc.h"
|
||||
#include "stm32f4xx_gpio.h"
|
||||
#include "stm32f4xx_usart.h"
|
||||
#include "stm32f4xx_dma.h"
|
||||
|
||||
#define CLI_PRINTABLE_CHAR_SPACE (0x20)
|
||||
#define CLI_PRINTABLE_CHAR_MIN (0x21)
|
||||
#define CLI_PRINTABLE_CHAR_MAX (0x7E)
|
||||
|
||||
struct cli_data_s cli_data;
|
||||
struct cli_data_comb_s cli_data_comb;
|
||||
char cli_buff_tx[CLI_BUFF_TX_LEN] __attribute__((aligned(16)));
|
||||
char cli_buff_rx[CLI_BUFF_RX_LEN] __attribute__((aligned(16)));
|
||||
|
||||
char *cli_cmd_list[] = {
|
||||
"help",
|
||||
"force",
|
||||
"print",
|
||||
"invalid",
|
||||
};
|
||||
|
||||
uint16_t (*cli_cmd_process_arr[])(char *, uint16_t) = {
|
||||
cli_cmd_process_help,
|
||||
cli_cmd_process_force,
|
||||
cli_cmd_process_print,
|
||||
cli_cmd_process_invalid,
|
||||
};
|
||||
|
||||
void cli_init(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
USART_InitTypeDef USART_InitStructure;
|
||||
DMA_InitTypeDef DMA_InitStructure;
|
||||
NVIC_InitTypeDef NVIC_InitStructure;
|
||||
|
||||
/* init struct data */
|
||||
cli_data.rx_len = 0;
|
||||
cli_data.tx_len = 0;
|
||||
cli_data.buff_rx = cli_buff_rx;
|
||||
cli_data.buff_tx = cli_buff_tx;
|
||||
cli_data.frame_cnt = 0;
|
||||
|
||||
cli_data_comb.force_available = 0;
|
||||
|
||||
/* config cli uart pin */
|
||||
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
|
||||
GPIO_PinAFConfig(CLI_PORT, GPIO_PinSource10, GPIO_AF_USART3);
|
||||
GPIO_PinAFConfig(CLI_PORT, GPIO_PinSource11, GPIO_AF_USART3);
|
||||
GPIO_InitStructure.GPIO_Pin = CLI_PIN_TX | CLI_PIN_RX;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
|
||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
|
||||
GPIO_Init(CLI_PORT, &GPIO_InitStructure);
|
||||
/* config cli uart function */
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
|
||||
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1, ENABLE);
|
||||
USART_DeInit(USART3);
|
||||
USART_OverSampling8Cmd(USART3, ENABLE);
|
||||
USART_InitStructure.USART_BaudRate = CLI_BAUDRATE;
|
||||
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
|
||||
USART_InitStructure.USART_Parity = USART_Parity_No;
|
||||
USART_InitStructure.USART_StopBits = USART_StopBits_1;
|
||||
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
|
||||
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
|
||||
USART_Init(USART3, &USART_InitStructure);
|
||||
USART_DMACmd(USART3, USART_DMAReq_Tx, ENABLE);
|
||||
USART_DMACmd(USART3, USART_DMAReq_Rx, ENABLE);
|
||||
USART_Cmd(USART3, ENABLE);
|
||||
/* Configure DMA controller to manage USART TX request */
|
||||
DMA_InitStructure.DMA_BufferSize = CLI_BUFF_TX_LEN;
|
||||
DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;
|
||||
DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_1QuarterFull;
|
||||
DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
|
||||
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
|
||||
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
|
||||
DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
|
||||
DMA_InitStructure.DMA_PeripheralBaseAddr =(uint32_t)(&(USART3->DR));
|
||||
DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
|
||||
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
|
||||
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
|
||||
DMA_InitStructure.DMA_Priority = DMA_Priority_Low;
|
||||
DMA_InitStructure.DMA_Channel = DMA_Channel_4;
|
||||
DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral;
|
||||
DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)cli_buff_tx;
|
||||
DMA_Init(CLI_TX_STREAM, &DMA_InitStructure);
|
||||
/* Configure DMA controller to manage USART RX request */
|
||||
DMA_InitStructure.DMA_BufferSize = CLI_BUFF_RX_LEN;
|
||||
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
|
||||
DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)cli_buff_rx;
|
||||
DMA_Init(CLI_RX_STREAM, &DMA_InitStructure);
|
||||
/* Configure interrupt for USART3 RX */
|
||||
NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 12;
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||
NVIC_Init(&NVIC_InitStructure);
|
||||
USART_ITConfig(USART3, USART_IT_IDLE, ENABLE);
|
||||
USART_ITConfig(USART3, USART_IT_TC, ENABLE);
|
||||
/* clear IT flag */
|
||||
USART_GetITStatus(USART3, USART_IT_IDLE);
|
||||
USART_ReceiveData(USART3);
|
||||
USART_ClearITPendingBit(USART3, USART_IT_IDLE);
|
||||
USART_ClearITPendingBit(USART3, USART_IT_TC);
|
||||
}
|
||||
|
||||
void cli_send_data(uint16_t len)
|
||||
{
|
||||
USART_GetITStatus(USART3, USART_IT_IDLE);
|
||||
USART_ReceiveData(USART3);
|
||||
USART_ClearITPendingBit(USART3, USART_IT_IDLE);
|
||||
if (len == 0) {
|
||||
DMA_SetCurrDataCounter(CLI_RX_STREAM, CLI_BUFF_RX_LEN);
|
||||
DMA_Cmd(CLI_RX_STREAM, ENABLE);
|
||||
USART_ITConfig(USART3, USART_IT_IDLE, ENABLE);
|
||||
} else {
|
||||
DMA_SetCurrDataCounter(CLI_TX_STREAM, len);
|
||||
DMA_Cmd(CLI_TX_STREAM, ENABLE);
|
||||
}
|
||||
}
|
||||
|
||||
void USART3_IRQHandler(void)
|
||||
{
|
||||
uint16_t len;
|
||||
|
||||
if (USART_GetITStatus(USART3, USART_IT_TC) != RESET)
|
||||
{
|
||||
USART_ClearITPendingBit(USART3, USART_IT_TC);
|
||||
DMA_ClearFlag(CLI_TX_STREAM, DMA_FLAG_TCIF3 | DMA_FLAG_HTIF3 | DMA_FLAG_TEIF3 | DMA_FLAG_DMEIF3 | DMA_FLAG_FEIF3);
|
||||
DMA_Cmd(CLI_TX_STREAM, DISABLE);
|
||||
/* after cli tx complete, config cli rx */
|
||||
USART_ReceiveData(USART3);
|
||||
USART_ClearITPendingBit(USART3, USART_IT_IDLE);
|
||||
DMA_SetCurrDataCounter(CLI_RX_STREAM, CLI_BUFF_RX_LEN);
|
||||
DMA_Cmd(CLI_RX_STREAM, ENABLE);
|
||||
USART_ITConfig(USART3, USART_IT_IDLE, ENABLE);
|
||||
}
|
||||
if (USART_GetITStatus(USART3, USART_IT_IDLE) != RESET) {
|
||||
USART_ITConfig(USART3, USART_IT_IDLE, DISABLE);
|
||||
USART_ReceiveData(USART3);
|
||||
USART_ClearITPendingBit(USART3, USART_IT_IDLE);
|
||||
DMA_Cmd(CLI_RX_STREAM, DISABLE);
|
||||
DMA_ClearFlag(CLI_RX_STREAM, DMA_FLAG_TCIF1 | DMA_FLAG_HTIF1 | DMA_FLAG_TEIF1 | DMA_FLAG_DMEIF1 | DMA_FLAG_FEIF1);
|
||||
len = DMA_GetCurrDataCounter(CLI_RX_STREAM);
|
||||
cli_data.rx_len = CLI_BUFF_RX_LEN - len;
|
||||
cli_data.frame_cnt++;
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t cli_print_num10(char *buff, uint32_t num)
|
||||
{
|
||||
uint16_t i = 0;
|
||||
uint32_t div, result;
|
||||
uint8_t non_zero = 0;
|
||||
div = 1000000000;
|
||||
while (1) {
|
||||
result = num / div;
|
||||
num = num % div;
|
||||
if (result) {
|
||||
non_zero = 1;
|
||||
buff[i] = (char)result + '0';
|
||||
i++;
|
||||
} else {
|
||||
if (non_zero) {
|
||||
buff[i] = '0';
|
||||
i++;
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
div /= 10;
|
||||
if (div == 0) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t cli_scan_num10(char *buff, uint32_t *num)
|
||||
{
|
||||
uint32_t sum = 0;
|
||||
uint16_t i = 0;
|
||||
char c;
|
||||
|
||||
while (1) {
|
||||
c = buff[i];
|
||||
if ((c >= '0') && (c <= '9')) {
|
||||
sum *= 10;
|
||||
sum += (uint32_t)(c - '0');
|
||||
i++;
|
||||
} else {
|
||||
*num = sum;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t cli_string_copy(char *dst, char *src)
|
||||
{
|
||||
uint16_t len = 0;
|
||||
char c;
|
||||
|
||||
while(1) {
|
||||
c = src[len];
|
||||
if ((c >= CLI_PRINTABLE_CHAR_SPACE) && (c <= CLI_PRINTABLE_CHAR_MAX)) {
|
||||
dst[len] = c;
|
||||
len++;
|
||||
} else {
|
||||
return len;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t cli_string_copy_newline(char *dst, char *src)
|
||||
{
|
||||
uint16_t len = cli_string_copy(dst, src);
|
||||
dst[len++] = '\r';
|
||||
dst[len++] = '\n';
|
||||
return len;
|
||||
}
|
||||
|
||||
uint8_t cli_string_is_same(char *str1, char *str2, uint16_t *len)
|
||||
{
|
||||
uint16_t i = 0;
|
||||
|
||||
while (1) {
|
||||
if (str1[i] == str2[i]) {
|
||||
if ((str1[i] >= CLI_PRINTABLE_CHAR_MIN) && (str1[i] <= CLI_PRINTABLE_CHAR_MAX)) {
|
||||
i++;
|
||||
} else {
|
||||
*len = i;
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
if (((str1[i] >= CLI_PRINTABLE_CHAR_MIN) && (str1[i] <= CLI_PRINTABLE_CHAR_MAX)) || \
|
||||
((str2[i] >= CLI_PRINTABLE_CHAR_MIN) && (str2[i] <= CLI_PRINTABLE_CHAR_MAX))) {
|
||||
return 0;
|
||||
} else {
|
||||
*len = i;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* buff: is ready for check */
|
||||
/* if is an cmd, then cmd */
|
||||
uint8_t cli_is_cmd(char *buff, uint8_t *cmd_idx, uint16_t *len)
|
||||
{
|
||||
uint16_t length;
|
||||
uint16_t cmd_cnt;
|
||||
|
||||
cmd_cnt = sizeof(cli_cmd_list) / sizeof(cli_cmd_list[0]);
|
||||
for (uint8_t i = 0; i < cmd_cnt; i++) {
|
||||
if (cli_string_is_same(buff, cli_cmd_list[i], &length)) {
|
||||
*cmd_idx = i;
|
||||
*len = length;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint16_t cli_cmd_process_help(char *buff, uint16_t len)
|
||||
{
|
||||
uint16_t len_tx = cli_string_copy_newline(cli_data.buff_tx, "cmd data!");
|
||||
return len_tx;
|
||||
}
|
||||
|
||||
/* cmd example
|
||||
force sig1=force
|
||||
force sig2=free
|
||||
force sig4=6540926
|
||||
*/
|
||||
uint16_t cli_cmd_process_force_error(char *buff)
|
||||
{
|
||||
uint16_t len;
|
||||
|
||||
len = cli_string_copy_newline(buff, "example:");
|
||||
len += cli_string_copy_newline(buff + len, "force sig1=force");
|
||||
len += cli_string_copy_newline(buff + len, "force sig2=free");
|
||||
len += cli_string_copy_newline(buff + len, "force sig4=6540926");
|
||||
return len;
|
||||
}
|
||||
|
||||
uint16_t cli_cmd_process_force(char *buff, uint16_t len)
|
||||
{
|
||||
uint8_t ch = 0;
|
||||
|
||||
if ((buff[0] != ' ') || \
|
||||
(buff[1] != 's') || \
|
||||
(buff[2] != 'i') || \
|
||||
(buff[3] != 'g') || \
|
||||
((buff[4] < '1') || (buff[4] > '4')) || \
|
||||
(buff[5] != '=')) {
|
||||
return cli_cmd_process_force_error(cli_data.buff_tx);
|
||||
}
|
||||
ch = buff[4] - '1';
|
||||
buff += 6;
|
||||
if ((buff[0] == 'f') && (buff[1] == 'o') && (buff[2] == 'r') && (buff[3] == 'c') && (buff[4] == 'e')) {
|
||||
cli_data_comb.force_available |= (1 << (ch + CLI_FORCE_FILTER_INPUT1));
|
||||
return cli_string_copy_newline(cli_data.buff_tx, "force succeed!");
|
||||
} else if ((buff[0] == 'f') && (buff[1] == 'r') && (buff[2] == 'e') && (buff[3] == 'e')) {
|
||||
cli_data_comb.force_available &= ~(1 << (ch + CLI_FORCE_FILTER_INPUT1));
|
||||
return cli_string_copy_newline(cli_data.buff_tx, "free succeed!");
|
||||
} else {
|
||||
uint32_t num;
|
||||
if (0 == cli_scan_num10(buff, &num)) {
|
||||
return cli_cmd_process_force_error(cli_data.buff_tx);
|
||||
} else {
|
||||
cli_data_comb.force_data[ch + CLI_FORCE_FILTER_INPUT1] = num;
|
||||
return cli_string_copy_newline(cli_data.buff_tx, "force number succeed!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t cli_cmd_process_print(char *buff, uint16_t len)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint16_t cli_cmd_process_invalid(char *buff, uint16_t len)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint16_t cli_cmd_process(char *buff)
|
||||
{
|
||||
uint8_t is_cmd;
|
||||
uint8_t cmd_idx;
|
||||
uint16_t cmd_len;
|
||||
|
||||
is_cmd = cli_is_cmd(buff, &cmd_idx, &cmd_len);
|
||||
if (is_cmd == 0) {
|
||||
uint16_t len = cli_string_copy_newline(cli_data.buff_tx, "not support this cmd!");
|
||||
return len;
|
||||
} else {
|
||||
return cli_cmd_process_arr[cmd_idx](buff + cmd_len, cli_data.rx_len - cmd_len);
|
||||
}
|
||||
}
|
||||
|
||||
void cli_loop(void)
|
||||
{
|
||||
static uint32_t frame_cnt = 0;
|
||||
|
||||
if (cli_data.frame_cnt == frame_cnt) {
|
||||
return;
|
||||
}
|
||||
frame_cnt = cli_data.frame_cnt;
|
||||
cli_data.buff_rx[cli_data.rx_len] = 0;
|
||||
cli_data.tx_len = cli_cmd_process(cli_data.buff_rx);
|
||||
cli_send_data(cli_data.tx_len);
|
||||
}
|
||||
@ -1,65 +0,0 @@
|
||||
#ifndef __CLI_H__
|
||||
#define __CLI_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "stm32f4xx.h"
|
||||
|
||||
#define CLI_PORT (GPIOB)
|
||||
#define CLI_PIN_TX (GPIO_Pin_10)
|
||||
#define CLI_PIN_RX (GPIO_Pin_11)
|
||||
|
||||
#define CLI_BAUDRATE (9600)
|
||||
|
||||
#define CLI_BUFF_TX_LEN (4096)
|
||||
#define CLI_BUFF_RX_LEN (1024)
|
||||
|
||||
#define CLI_TX_STREAM DMA1_Stream3
|
||||
#define CLI_RX_STREAM DMA1_Stream1
|
||||
|
||||
#define CLI_FORCE_FILTER_INPUT1 (0)
|
||||
#define CLI_FORCE_FILTER_INPUT2 (1)
|
||||
#define CLI_FORCE_FILTER_INPUT3 (2)
|
||||
#define CLI_FORCE_FILTER_INPUT4 (3)
|
||||
|
||||
#define CLI_FORCE_FILTER_INPUT1_MASK (1 << CLI_FORCE_FILTER_INPUT1)
|
||||
#define CLI_FORCE_FILTER_INPUT2_MASK (1 << CLI_FORCE_FILTER_INPUT2)
|
||||
#define CLI_FORCE_FILTER_INPUT3_MASK (1 << CLI_FORCE_FILTER_INPUT3)
|
||||
#define CLI_FORCE_FILTER_INPUT4_MASK (1 << CLI_FORCE_FILTER_INPUT4)
|
||||
|
||||
struct cli_data_s {
|
||||
uint16_t rx_len;
|
||||
uint16_t tx_len;
|
||||
char *buff_rx;
|
||||
char *buff_tx;
|
||||
uint32_t frame_cnt;
|
||||
};
|
||||
|
||||
struct cli_data_comb_s {
|
||||
uint32_t force_available;
|
||||
uint32_t force_data[32];
|
||||
};
|
||||
|
||||
extern struct cli_data_s cli_data;
|
||||
extern struct cli_data_comb_s cli_data_comb;
|
||||
|
||||
void cli_init(void);
|
||||
void cli_send_data(uint16_t len);
|
||||
uint16_t cli_string_copy(char *dst, char *src);
|
||||
uint16_t cli_string_copy_newline(char *dst, char *src);
|
||||
uint8_t cli_string_is_same(char *str1, char *str2, uint16_t *len);
|
||||
uint8_t cli_is_cmd(char *buff, uint8_t *cmd_idx, uint16_t *len);
|
||||
uint16_t cli_cmd_process_help(char *buff, uint16_t len);
|
||||
uint16_t cli_cmd_process_force(char *buff, uint16_t len);
|
||||
uint16_t cli_cmd_process_print(char *buff, uint16_t len);
|
||||
uint16_t cli_cmd_process_invalid(char *buff, uint16_t len);
|
||||
uint16_t cli_cmd_process(char *buff);
|
||||
void cli_loop(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __CLI_H__ */
|
||||
@ -1,100 +0,0 @@
|
||||
#include "debug.h"
|
||||
#include "stm32f4xx_rcc.h"
|
||||
#include "stm32f4xx_gpio.h"
|
||||
#include "stm32f4xx_usart.h"
|
||||
#include "stm32f4xx_dma.h"
|
||||
|
||||
struct debug_data_s debug_data;
|
||||
float debug_buff[DEBUG_CHAN_MAX + 1] __attribute__((aligned(16)));
|
||||
|
||||
void debug_init(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
USART_InitTypeDef USART_InitStructure;
|
||||
DMA_InitTypeDef DMA_InitStructure;
|
||||
NVIC_InitTypeDef NVIC_InitStructure;
|
||||
|
||||
/* config debug uart pin */
|
||||
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
|
||||
GPIO_PinAFConfig(DEBUG_UART_PORT, GPIO_PinSource10, GPIO_AF_UART4);
|
||||
GPIO_InitStructure.GPIO_Pin = DEBUG_UART_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
|
||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
|
||||
GPIO_Init(DEBUG_UART_PORT, &GPIO_InitStructure);
|
||||
/* config debug uart function */
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, ENABLE);
|
||||
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1, ENABLE);
|
||||
USART_DeInit(UART4);
|
||||
USART_OverSampling8Cmd(UART4, DISABLE);
|
||||
USART_InitStructure.USART_BaudRate = DEBUG_UART_BAUDRATE;
|
||||
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
|
||||
USART_InitStructure.USART_Parity = USART_Parity_No;
|
||||
USART_InitStructure.USART_StopBits = USART_StopBits_1;
|
||||
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
|
||||
USART_InitStructure.USART_Mode = USART_Mode_Tx;
|
||||
USART_Init(UART4, &USART_InitStructure);
|
||||
USART_DMACmd(UART4, USART_DMAReq_Tx, ENABLE);
|
||||
USART_Cmd(UART4, ENABLE);
|
||||
/* Configure DMA controller to manage UART TX request */
|
||||
DMA_InitStructure.DMA_BufferSize = DEBUG_CHAN_MAX * 4 + 4;
|
||||
DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;
|
||||
DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_1QuarterFull;
|
||||
DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
|
||||
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
|
||||
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
|
||||
DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
|
||||
DMA_InitStructure.DMA_PeripheralBaseAddr =(uint32_t)(&(UART4->DR));
|
||||
DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
|
||||
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
|
||||
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
|
||||
DMA_InitStructure.DMA_Priority = DMA_Priority_Low;
|
||||
DMA_InitStructure.DMA_Channel = DMA_Channel_4;
|
||||
DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral;
|
||||
DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)debug_buff;
|
||||
DMA_Init(DMA1_Stream4, &DMA_InitStructure);
|
||||
/* Configure interrupt for UART4 TX */
|
||||
NVIC_InitStructure.NVIC_IRQChannel = UART4_IRQn;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 10;
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||
NVIC_Init(&NVIC_InitStructure);
|
||||
USART_ITConfig(UART4, USART_IT_TC, ENABLE);
|
||||
|
||||
/* debug data init */
|
||||
debug_data.enable = DEBUG_ENABLE;
|
||||
debug_data.busy = 0;
|
||||
}
|
||||
|
||||
void debug_send_frame(void)
|
||||
{
|
||||
if (debug_data.enable == 0 || debug_data.busy == 1) {
|
||||
return;
|
||||
}
|
||||
debug_data.busy = 1;
|
||||
*(uint32_t *)(debug_buff + DEBUG_CHAN_MAX) = 0x7F800000;
|
||||
DMA_SetCurrDataCounter(DMA1_Stream4, sizeof(debug_buff));
|
||||
USART_ClearITPendingBit(UART4, USART_IT_TC);
|
||||
DMA_Cmd(DMA1_Stream4, ENABLE);
|
||||
}
|
||||
|
||||
void debug_write_data(uint16_t ch, float data)
|
||||
{
|
||||
if (debug_data.enable == 0) {
|
||||
return;
|
||||
}
|
||||
if (ch >= DEBUG_CHAN_MAX) {
|
||||
while (1) {}
|
||||
}
|
||||
debug_buff[ch] = data;
|
||||
}
|
||||
|
||||
void UART4_IRQHandler(void)
|
||||
{
|
||||
if (USART_GetITStatus(UART4, USART_IT_TC) != RESET) {
|
||||
USART_ClearITPendingBit(UART4, USART_IT_TC);
|
||||
DMA_ClearFlag(DMA1_Stream4, DMA_FLAG_TCIF4);
|
||||
debug_data.busy = 0;
|
||||
}
|
||||
}
|
||||
@ -1,33 +0,0 @@
|
||||
#ifndef __DEBUG_H__
|
||||
#define __DEBUG_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "stm32f4xx.h"
|
||||
|
||||
#define DEBUG_ENABLE (1)
|
||||
|
||||
#define DEBUG_UART_PORT (GPIOC)
|
||||
#define DEBUG_UART_PIN (GPIO_Pin_6)
|
||||
#define DEBUG_UART_BAUDRATE (2 * 1000 * 1000)
|
||||
|
||||
#define DEBUG_CHAN_MAX (28)
|
||||
|
||||
struct debug_data_s {
|
||||
uint8_t enable;
|
||||
uint8_t busy;
|
||||
};
|
||||
|
||||
extern struct debug_data_s debug_data;
|
||||
|
||||
void debug_init(void);
|
||||
void debug_send_frame(void);
|
||||
void debug_write_data(uint16_t ch, float data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __DEBUG_H__ */
|
||||
@ -1,7 +1,6 @@
|
||||
#include "filter.h"
|
||||
#include "ltc1867.h"
|
||||
#include "device.h"
|
||||
#include "debug.h"
|
||||
#include "user_misc.h"
|
||||
|
||||
static uint32_t sum_gas1[FILTER_SUM_LEN_GAS1] __attribute__((section(".bss_ccm")));
|
||||
@ -105,12 +104,10 @@ void filter_sum_process(void)
|
||||
idx = data_filter[i].sum_idx;
|
||||
sum = data_filter[i].sum_sum;
|
||||
val = data_filter[i].input;
|
||||
debug_write_data(4 + i, (float)val);
|
||||
sum = sum - data_filter[i].sum_buff[idx];
|
||||
data_filter[i].sum_buff[idx] = val;
|
||||
sum = sum + val;
|
||||
data_filter[i].sum_sum = sum;
|
||||
debug_write_data(8 + i, (float)(data_filter[i].sum_sum));
|
||||
data_filter[i].sum_idx++;
|
||||
if (data_filter[i].sum_idx >= data_filter[i].sum_len) {
|
||||
data_filter[i].sum_idx = 0;
|
||||
@ -155,7 +152,6 @@ void filter_median_process(void)
|
||||
}
|
||||
/* calc median data */
|
||||
data_filter[i].median_output = (iter->data + iter->next->data) / 2;
|
||||
debug_write_data(12 + i, (float)(data_filter[i].median_output));
|
||||
/* iterate median_idx */
|
||||
data_filter[i].median_idx++;
|
||||
if (data_filter[i].median_idx >= data_filter[i].median_len) {
|
||||
@ -178,7 +174,6 @@ void filter_window_process(void)
|
||||
sum = sum + val;
|
||||
data_filter[i].window_sum = sum;
|
||||
data_filter[i].window_output = sum / data_filter[i].window_len;
|
||||
debug_write_data(16 + i, (float)(data_filter[i].window_output));
|
||||
data_filter[i].window_idx++;
|
||||
if (data_filter[i].window_idx >= data_filter[i].window_len) {
|
||||
data_filter[i].window_idx = 0;
|
||||
|
||||
@ -3,8 +3,6 @@
|
||||
#include "device.h"
|
||||
#include "cali.h"
|
||||
#include "cali_flash.h"
|
||||
#include "debug.h"
|
||||
#include "cli.h"
|
||||
#include "stm32f4xx_rcc.h"
|
||||
#include "stm32f4xx_gpio.h"
|
||||
#include "stm32f4xx_tim.h"
|
||||
@ -198,31 +196,14 @@ void TIM2_IRQHandler(void)
|
||||
/* split 2 for loop, because sample timing is strict, only place important code in sample duration */
|
||||
for (uint8_t i = 0; i < 4; i++) {
|
||||
data_ltc1867.sum[i] += diff32768(val[i]); /* add every channel original data for next process */
|
||||
debug_write_data(i, (float)val[i]); /* channel 1~4 for ltc1867 original sample data */
|
||||
}
|
||||
data_ltc1867.val_idx++;
|
||||
if ((data_ltc1867.val_idx >= CALC_CNT) && (data_ltc1867.locked != 0)) {
|
||||
data_ltc1867.val_idx = 0;
|
||||
if (cli_data_comb.force_available & CLI_FORCE_FILTER_INPUT1_MASK) {
|
||||
filter_input_data(0, cli_data_comb.force_data[CLI_FORCE_FILTER_INPUT1] / FILTER_SUM_LEN_GAS1);
|
||||
} else {
|
||||
filter_input_data(0, data_ltc1867.sum[0]);
|
||||
}
|
||||
if (cli_data_comb.force_available & CLI_FORCE_FILTER_INPUT2_MASK) {
|
||||
filter_input_data(1, cli_data_comb.force_data[CLI_FORCE_FILTER_INPUT2] / FILTER_SUM_LEN_GAS2);
|
||||
} else {
|
||||
filter_input_data(1, data_ltc1867.sum[1]);
|
||||
}
|
||||
if (cli_data_comb.force_available & CLI_FORCE_FILTER_INPUT3_MASK) {
|
||||
filter_input_data(2, cli_data_comb.force_data[CLI_FORCE_FILTER_INPUT3] / FILTER_SUM_LEN_GAS3);
|
||||
} else {
|
||||
filter_input_data(2, data_ltc1867.sum[2]);
|
||||
}
|
||||
if (cli_data_comb.force_available & CLI_FORCE_FILTER_INPUT4_MASK) {
|
||||
filter_input_data(3, cli_data_comb.force_data[CLI_FORCE_FILTER_INPUT4] / FILTER_SUM_LEN_GAS4);
|
||||
} else {
|
||||
filter_input_data(3, data_ltc1867.sum[3]);
|
||||
}
|
||||
filter_input_data(0, data_ltc1867.sum[0]);
|
||||
filter_input_data(1, data_ltc1867.sum[1]);
|
||||
filter_input_data(2, data_ltc1867.sum[2]);
|
||||
filter_input_data(3, data_ltc1867.sum[3]);
|
||||
data_ltc1867.sum[0] = 0;
|
||||
data_ltc1867.sum[1] = 0;
|
||||
data_ltc1867.sum[2] = 0;
|
||||
@ -255,5 +236,4 @@ void TIM2_IRQHandler(void)
|
||||
}
|
||||
}
|
||||
cali_flash_write();
|
||||
debug_send_frame();
|
||||
}
|
||||
|
||||
@ -121,7 +121,7 @@ void ltc2640_init(void)
|
||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
||||
GPIO_Init(GPIOA, &GPIO_InitStructure);
|
||||
GPIO_Init(GPIOB, &GPIO_InitStructure);
|
||||
GPIO_InitStructure.GPIO_Pin = LTC2640_PIN_SCK | LTC2640_PIN_SDI;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
|
||||
GPIO_Init(GPIOB, &GPIO_InitStructure);
|
||||
@ -187,9 +187,9 @@ void ltc2640_loop(void)
|
||||
if (system_tick_cnt < (ms + 50)) {
|
||||
return;
|
||||
}
|
||||
GPIO_SetBits(GPIOA, LTC2640_PIN_CS);
|
||||
GPIO_SetBits(GPIOB, LTC2640_PIN_CS);
|
||||
ms = system_tick_cnt;
|
||||
ret = ltc2640_data_process();
|
||||
GPIO_ResetBits(GPIOA, LTC2640_PIN_CS);
|
||||
GPIO_ResetBits(GPIOB, LTC2640_PIN_CS);
|
||||
ltc2640_send_data((uint16_t)ret);
|
||||
}
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
#include "stm32f4xx.h"
|
||||
|
||||
#define LTC2640_PIN_CLR (GPIO_Pin_7)
|
||||
#define LTC2640_PIN_CS (GPIO_Pin_15)
|
||||
#define LTC2640_PIN_CS (GPIO_Pin_6)
|
||||
#define LTC2640_PIN_SCK (GPIO_Pin_3)
|
||||
#define LTC2640_PIN_SDI (GPIO_Pin_5)
|
||||
|
||||
|
||||
@ -15,7 +15,7 @@ void led_init(uint16_t led)
|
||||
.GPIO_PuPd = GPIO_PuPd_NOPULL,
|
||||
};
|
||||
|
||||
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
|
||||
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
|
||||
GPIO_Init(PORT_LED, &GPIO_InitStructure);
|
||||
led_off(led);
|
||||
}
|
||||
|
||||
@ -7,9 +7,9 @@
|
||||
|
||||
#include "stm32f4xx.h"
|
||||
|
||||
#define PORT_LED (GPIOC)
|
||||
#define LED1 (GPIO_Pin_4)
|
||||
#define LED2 (GPIO_Pin_5)
|
||||
#define PORT_LED (GPIOB)
|
||||
#define LED1 (GPIO_Pin_12)
|
||||
#define LED2 (GPIO_Pin_13)
|
||||
|
||||
#define PORT_HEAT (GPIOB)
|
||||
#define PIN_HEAT (GPIO_Pin_1)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user