Compare commits

..

No commits in common. "48df3f951230fd41c5b0082fa7b6328500b8d104" and "aa93ff2508a14ac47b62aac19d9b3ec72fb73d4d" have entirely different histories.

25 changed files with 2971 additions and 2275 deletions

View File

@ -38,9 +38,6 @@
"freertos.h": "c",
"tcp.h": "c",
"cmsis_os.h": "c",
"freertosconfig.h": "c",
"communication_protocol.h": "c",
"user_gpio.h": "c",
"user_lib.h": "c"
"freertosconfig.h": "c"
}
}

View File

@ -1,7 +1,7 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file gpio.h
* @file gpio.h
* @brief This file contains all the function prototypes for
* the gpio.c file
******************************************************************************
@ -39,26 +39,20 @@ extern "C" {
DI_2,
DI_3,
DI_4,
DI_5,
DI_6,
DI_MAX,
} gpio_di_e;
typedef enum
{
DO_1,
DO_2,
DO_3,
DO_4,
DO_EN,
DO_MAX,
} gpio_do_e;
DI_DO_MAX,
} gpio_e;
/* USER CODE END Private defines */
void MX_GPIO_Init(void);
/* USER CODE BEGIN Prototypes */
extern void gpio_do_test(uint8_t gpio_num, GPIO_PinState state);
extern GPIO_PinState gpio_di_test(uint8_t gpio_num);
extern void gpio_do_test(gpio_e gpio_num, GPIO_PinState state);
extern GPIO_PinState gpio_di_test(gpio_e gpio_num);
/* USER CODE END Prototypes */
#ifdef __cplusplus

View File

@ -40,18 +40,17 @@ extern "C" {
/* Exported types ------------------------------------------------------------*/
/* USER CODE BEGIN ET */
extern uint8_t tcp_echo_flags_hart1;
extern uint8_t tcp_echo_flags_hart2;
extern uint8_t tcp_echo_flags_hart1; // 标志ä½<C3A4>,连接æˆ<C3A6>功ç½?1
extern uint8_t tcp_echo_flags_hart2; // 标志ä½<C3A4>,连接æˆ<C3A6>功ç½?1
extern uint8_t tcp_echo_flags_ble1;
extern uint8_t tcp_echo_flags_ble2;
extern uint8_t tcp_echo_flags_control;
#define ARRAY_LEN(arr) (sizeof(arr)) / (sizeof(arr[0]))
typedef struct
{
uint16_t rx_num;
uint8_t rx_data[512];
uint8_t rx_data_temp[512];
uint8_t tx_data[512];
uint16_t rx_num; // 接收到数æ<C2B0>®ä¸ªæ•?
uint8_t rx_data[512]; // 接收到数æ<C2B0>®åŒº
uint8_t rx_data_temp[512]; // 接收到数æ<C2B0>®ç¼“冲区
uint8_t tx_data[512]; // å<>é?<3F>æ•°æ<C2B0>®åŒº
} uart_t;
extern uart_t lcd_uart4;
@ -91,10 +90,6 @@ void Error_Handler(void);
/* USER CODE END EFP */
/* Private defines -----------------------------------------------------------*/
#define DI_CH5_Pin GPIO_PIN_2
#define DI_CH5_GPIO_Port GPIOE
#define DI_CH6_Pin GPIO_PIN_3
#define DI_CH6_GPIO_Port GPIOE
#define ETH_RESET_Pin GPIO_PIN_0
#define ETH_RESET_GPIO_Port GPIOC
#define LED3_R_Pin GPIO_PIN_1

View File

@ -27,8 +27,6 @@
/* USER CODE BEGIN Includes */
#include "dac161s997.h"
#include "ad7124.h"
#include "usart.h"
#include "communication_protocol.h"
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
@ -38,7 +36,7 @@
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
// extern UART_HandleTypeDef huart5;
/* USER CODE END PD */
/* Private macro -------------------------------------------------------------*/
@ -54,24 +52,22 @@ osThreadId lwip_taskHandle;
osThreadId led_taskHandle;
osThreadId dac_taskHandle;
osThreadId adc_taskHandle;
osThreadId gpio_di_do_taskHandle;
/* Private function prototypes -----------------------------------------------*/
/* USER CODE BEGIN FunctionPrototypes */
extern float current_buff[2];
/* USER CODE END FunctionPrototypes */
void start_tcp_task(void const * argument);
void start_led_toggle_task(void const * argument);
void start_dac_task(void const * argument);
void start_adc_task(void const * argument);
void start_gpio_di_do_task(void const * argument);
void start_tcp_task(void const *argument);
void start_led_toggle_task(void const *argument);
void start_dac_task(void const *argument);
void start_adc_task(void const *argument);
extern void MX_LWIP_Init(void);
void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */
/* GetIdleTaskMemory prototype (linked to static allocation support) */
void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize );
void vApplicationGetIdleTaskMemory(StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize);
/* USER CODE BEGIN GET_IDLE_TASK_MEMORY */
static StaticTask_t xIdleTaskTCBBuffer;
@ -87,11 +83,12 @@ void vApplicationGetIdleTaskMemory(StaticTask_t **ppxIdleTaskTCBBuffer, StackTyp
/* USER CODE END GET_IDLE_TASK_MEMORY */
/**
* @brief FreeRTOS initialization
* @param None
* @retval None
*/
void MX_FREERTOS_Init(void) {
* @brief FreeRTOS initialization
* @param None
* @retval None
*/
void MX_FREERTOS_Init(void)
{
/* USER CODE BEGIN Init */
/* USER CODE END Init */
@ -129,14 +126,9 @@ void MX_FREERTOS_Init(void) {
osThreadDef(adc_task, start_adc_task, osPriorityBelowNormal, 0, 128);
adc_taskHandle = osThreadCreate(osThread(adc_task), NULL);
/* definition and creation of gpio_di_do_task */
osThreadDef(gpio_di_do_task, start_gpio_di_do_task, osPriorityNormal, 0, 128);
gpio_di_do_taskHandle = osThreadCreate(osThread(gpio_di_do_task), NULL);
/* USER CODE BEGIN RTOS_THREADS */
/* add threads, ... */
/* USER CODE END RTOS_THREADS */
}
/* USER CODE BEGIN Header_start_tcp_task */
@ -146,7 +138,7 @@ void MX_FREERTOS_Init(void) {
* @retval None
*/
/* USER CODE END Header_start_tcp_task */
void start_tcp_task(void const * argument)
void start_tcp_task(void const *argument)
{
/* init code for LWIP */
MX_LWIP_Init();
@ -155,20 +147,8 @@ void start_tcp_task(void const * argument)
/* Infinite loop */
for (;;)
{
// osThreadTerminate(NULL);
// if (tcp_send_flags_hart1 == 1)
// {
// user_send_data_hart1(hart1_uart5.rx_data, hart1_uart5.rx_num);
// tcp_send_flags_hart1 = 0;
// }
// if (tcp_send_flags_hart2 == 1)
// {
// user_send_data_hart2(hart2_uart2.rx_data, hart2_uart2.rx_num);
// tcp_send_flags_hart2 = 0;
// }
vTaskDelay(1);
// osDelay(1);
osThreadTerminate(NULL);
osDelay(1);
}
/* USER CODE END start_tcp_task */
}
@ -180,14 +160,14 @@ void start_tcp_task(void const * argument)
* @retval None
*/
/* USER CODE END Header_start_led_toggle_task */
void start_led_toggle_task(void const * argument)
void start_led_toggle_task(void const *argument)
{
/* USER CODE BEGIN start_led_toggle_task */
/* Infinite loop */
for (;;)
{
// HAL_GPIO_TogglePin(LED2_G_GPIO_Port, LED2_G_Pin);
vTaskDelay(500);
HAL_GPIO_TogglePin(LED2_G_GPIO_Port, LED2_G_Pin);
vTaskDelay(1000);
}
/* USER CODE END start_led_toggle_task */
}
@ -199,17 +179,16 @@ void start_led_toggle_task(void const * argument)
* @retval None
*/
/* USER CODE END Header_start_dac_task */
void start_dac_task(void const * argument)
void start_dac_task(void const *argument)
{
/* USER CODE BEGIN start_dac_task */
dac161s997_init();
/* Infinite loop */
for (;;)
{
dac161s997_output(DAC161S997_1, current_buff[0]);
dac161s997_output(DAC161S997_2, current_buff[1]);
vTaskDelay(100);
dac161s997_output(DAC161S997_1, 12.0f);
dac161s997_output(DAC161S997_2, 12.0f);
vTaskDelay(200);
}
/* USER CODE END start_dac_task */
}
@ -221,49 +200,19 @@ void start_dac_task(void const * argument)
* @retval None
*/
/* USER CODE END Header_start_adc_task */
void start_adc_task(void const * argument)
void start_adc_task(void const *argument)
{
/* USER CODE BEGIN start_adc_task */
ad7124_setup();
/* Infinite loop */
for (;;)
{
uint8_t ch = 0;
for (ch = STOP_NC_ADC; ch < AD7124_CHANNEL_EN_MAX; ch++)
{
ad7124_get_analog(ch);
}
HAL_GPIO_TogglePin(LED2_G_GPIO_Port, LED2_G_Pin);
if (huart5.RxState == HAL_UART_STATE_READY)
{
HAL_UARTEx_ReceiveToIdle_DMA(&huart5, hart1_uart5.rx_data_temp, ARRAY_LEN(hart1_uart5.rx_data_temp));
}
if (huart2.RxState == HAL_UART_STATE_READY)
{
HAL_UARTEx_ReceiveToIdle_DMA(&huart2, hart2_uart2.rx_data_temp, ARRAY_LEN(hart2_uart2.rx_data_temp));
}
ad7124_get_analog(STOP_NC_ADC);
vTaskDelay(1000);
}
/* USER CODE END start_adc_task */
}
/* USER CODE BEGIN Header_start_gpio_di_do_task */
/**
* @brief Function implementing the gpio_di_do_task thread.
* @param argument: Not used
* @retval None
*/
/* USER CODE END Header_start_gpio_di_do_task */
void start_gpio_di_do_task(void const * argument)
{
/* USER CODE BEGIN start_gpio_di_do_task */
/* Infinite loop */
for (;;)
{
osDelay(1);
}
/* USER CODE END start_gpio_di_do_task */
}
/* Private application code --------------------------------------------------*/
/* USER CODE BEGIN Application */

View File

@ -45,11 +45,11 @@ void MX_GPIO_Init(void)
GPIO_InitTypeDef GPIO_InitStruct = {0};
/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOE_CLK_ENABLE();
__HAL_RCC_GPIOH_CLK_ENABLE();
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
__HAL_RCC_GPIOE_CLK_ENABLE();
__HAL_RCC_GPIOD_CLK_ENABLE();
/*Configure GPIO pin Output Level */
@ -72,12 +72,6 @@ void MX_GPIO_Init(void)
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(HART2_RST_GPIO_Port, HART2_RST_Pin, GPIO_PIN_RESET);
/*Configure GPIO pins : PEPin PEPin */
GPIO_InitStruct.Pin = DI_CH5_Pin|DI_CH6_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_PULLUP;
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
/*Configure GPIO pin : PtPin */
GPIO_InitStruct.Pin = ETH_RESET_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
@ -169,7 +163,7 @@ void MX_GPIO_Init(void)
}
/* USER CODE BEGIN 2 */
void gpio_do_test(uint8_t gpio_num, GPIO_PinState state)
void gpio_do_test(gpio_e gpio_num, GPIO_PinState state)
{
HAL_GPIO_WritePin(DO_EN_GPIO_Port, DO_EN_Pin, GPIO_PIN_RESET);
switch (gpio_num)
@ -191,7 +185,7 @@ void gpio_do_test(uint8_t gpio_num, GPIO_PinState state)
}
}
GPIO_PinState gpio_di_test(uint8_t gpio_num)
GPIO_PinState gpio_di_test(gpio_e gpio_num)
{
GPIO_PinState state;
switch (gpio_num)
@ -208,12 +202,6 @@ GPIO_PinState gpio_di_test(uint8_t gpio_num)
case DI_4:
state = HAL_GPIO_ReadPin(DI_CH4_GPIO_Port, DI_CH4_Pin);
break;
case DI_5:
state = HAL_GPIO_ReadPin(DI_CH5_GPIO_Port, DI_CH5_Pin);
break;
case DI_6:
state = HAL_GPIO_ReadPin(DI_CH6_GPIO_Port, DI_CH6_Pin);
break;
default:
state = GPIO_PIN_RESET;
break;

View File

@ -71,18 +71,16 @@ uart_t ble2_uart3 = {0};
uart_t hart2_uart2 = {0};
uart_t hart1_uart5 = {0};
float current_buff[2] = {12.0f, 12.0f};
uint8_t tcp_echo_flags_hart1 = 0;
uint8_t tcp_echo_flags_hart2 = 0;
uint8_t tcp_echo_flags_ble1 = 0;
uint8_t tcp_echo_flags_ble2 = 0;
uint8_t tcp_echo_flags_control = 0;
/* USER CODE END 0 */
/**
* @brief The application entry point.
* @retval int
*/
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* USER CODE BEGIN 1 */
@ -124,8 +122,8 @@ int main(void)
HAL_UARTEx_ReceiveToIdle_DMA(&huart3, ble2_uart3.rx_data_temp, ARRAY_LEN(ble2_uart3.rx_data_temp));
HAL_UARTEx_ReceiveToIdle_DMA(&huart5, hart1_uart5.rx_data_temp, ARRAY_LEN(hart1_uart5.rx_data_temp));
HAL_UARTEx_ReceiveToIdle_DMA(&huart2, hart2_uart2.rx_data_temp, ARRAY_LEN(hart2_uart2.rx_data_temp));
hart_ht1200m_reset(); // 初始化HT1200M模块
HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_1); // PWM输出用于驱动HT1200M模块
hart_ht1200m_reset(); // 夝佝HT1200M模块
HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_1); // 坯动PWM输出用于驱动HT1200M模块
/* USER CODE END 2 */
/* Call init function for freertos objects (in freertos.c) */
@ -141,27 +139,28 @@ int main(void)
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
// ad7124_get_analog(STOP_NC_ADC);
}
/* USER CODE END 3 */
}
/**
* @brief System Clock Configuration
* @retval None
*/
* @brief System Clock Configuration
* @retval None
*/
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
/** Configure the main internal regulator output voltage
*/
*/
__HAL_RCC_PWR_CLK_ENABLE();
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
/** Initializes the RCC Oscillators according to the specified parameters
* in the RCC_OscInitTypeDef structure.
*/
* in the RCC_OscInitTypeDef structure.
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
@ -176,9 +175,8 @@ void SystemClock_Config(void)
}
/** Initializes the CPU, AHB and APB buses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
@ -257,19 +255,20 @@ void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
/* USER CODE END 4 */
/**
* @brief Period elapsed callback in non blocking mode
* @note This function is called when TIM1 interrupt took place, inside
* HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment
* a global variable "uwTick" used as application time base.
* @param htim : TIM handle
* @retval None
*/
* @brief Period elapsed callback in non blocking mode
* @note This function is called when TIM1 interrupt took place, inside
* HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment
* a global variable "uwTick" used as application time base.
* @param htim : TIM handle
* @retval None
*/
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
/* USER CODE BEGIN Callback 0 */
/* USER CODE END Callback 0 */
if (htim->Instance == TIM1) {
if (htim->Instance == TIM1)
{
HAL_IncTick();
}
/* USER CODE BEGIN Callback 1 */
@ -278,9 +277,9 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
}
/**
* @brief This function is executed in case of error occurrence.
* @retval None
*/
* @brief This function is executed in case of error occurrence.
* @retval None
*/
void Error_Handler(void)
{
/* USER CODE BEGIN Error_Handler_Debug */
@ -292,14 +291,14 @@ void Error_Handler(void)
/* USER CODE END Error_Handler_Debug */
}
#ifdef USE_FULL_ASSERT
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t *file, uint32_t line)
{
/* USER CODE BEGIN 6 */

View File

@ -88,8 +88,8 @@ extern TIM_HandleTypeDef htim1;
/* Cortex-M4 Processor Interruption and Exception Handlers */
/******************************************************************************/
/**
* @brief This function handles Non maskable interrupt.
*/
* @brief This function handles Non maskable interrupt.
*/
void NMI_Handler(void)
{
/* USER CODE BEGIN NonMaskableInt_IRQn 0 */
@ -103,8 +103,8 @@ void NMI_Handler(void)
}
/**
* @brief This function handles Hard fault interrupt.
*/
* @brief This function handles Hard fault interrupt.
*/
void HardFault_Handler(void)
{
/* USER CODE BEGIN HardFault_IRQn 0 */
@ -118,8 +118,8 @@ void HardFault_Handler(void)
}
/**
* @brief This function handles Memory management fault.
*/
* @brief This function handles Memory management fault.
*/
void MemManage_Handler(void)
{
/* USER CODE BEGIN MemoryManagement_IRQn 0 */
@ -133,8 +133,8 @@ void MemManage_Handler(void)
}
/**
* @brief This function handles Pre-fetch fault, memory access fault.
*/
* @brief This function handles Pre-fetch fault, memory access fault.
*/
void BusFault_Handler(void)
{
/* USER CODE BEGIN BusFault_IRQn 0 */
@ -148,8 +148,8 @@ void BusFault_Handler(void)
}
/**
* @brief This function handles Undefined instruction or illegal state.
*/
* @brief This function handles Undefined instruction or illegal state.
*/
void UsageFault_Handler(void)
{
/* USER CODE BEGIN UsageFault_IRQn 0 */
@ -163,8 +163,8 @@ void UsageFault_Handler(void)
}
/**
* @brief This function handles Debug monitor.
*/
* @brief This function handles Debug monitor.
*/
void DebugMon_Handler(void)
{
/* USER CODE BEGIN DebugMonitor_IRQn 0 */
@ -183,8 +183,8 @@ void DebugMon_Handler(void)
/******************************************************************************/
/**
* @brief This function handles EXTI line1 interrupt.
*/
* @brief This function handles EXTI line1 interrupt.
*/
void EXTI1_IRQHandler(void)
{
/* USER CODE BEGIN EXTI1_IRQn 0 */
@ -197,8 +197,8 @@ void EXTI1_IRQHandler(void)
}
/**
* @brief This function handles EXTI line3 interrupt.
*/
* @brief This function handles EXTI line3 interrupt.
*/
void EXTI3_IRQHandler(void)
{
/* USER CODE BEGIN EXTI3_IRQn 0 */
@ -211,8 +211,8 @@ void EXTI3_IRQHandler(void)
}
/**
* @brief This function handles DMA1 stream0 global interrupt.
*/
* @brief This function handles DMA1 stream0 global interrupt.
*/
void DMA1_Stream0_IRQHandler(void)
{
/* USER CODE BEGIN DMA1_Stream0_IRQn 0 */
@ -225,8 +225,8 @@ void DMA1_Stream0_IRQHandler(void)
}
/**
* @brief This function handles DMA1 stream1 global interrupt.
*/
* @brief This function handles DMA1 stream1 global interrupt.
*/
void DMA1_Stream1_IRQHandler(void)
{
/* USER CODE BEGIN DMA1_Stream1_IRQn 0 */
@ -239,8 +239,8 @@ void DMA1_Stream1_IRQHandler(void)
}
/**
* @brief This function handles DMA1 stream2 global interrupt.
*/
* @brief This function handles DMA1 stream2 global interrupt.
*/
void DMA1_Stream2_IRQHandler(void)
{
/* USER CODE BEGIN DMA1_Stream2_IRQn 0 */
@ -253,8 +253,8 @@ void DMA1_Stream2_IRQHandler(void)
}
/**
* @brief This function handles DMA1 stream3 global interrupt.
*/
* @brief This function handles DMA1 stream3 global interrupt.
*/
void DMA1_Stream3_IRQHandler(void)
{
/* USER CODE BEGIN DMA1_Stream3_IRQn 0 */
@ -267,8 +267,8 @@ void DMA1_Stream3_IRQHandler(void)
}
/**
* @brief This function handles DMA1 stream4 global interrupt.
*/
* @brief This function handles DMA1 stream4 global interrupt.
*/
void DMA1_Stream4_IRQHandler(void)
{
/* USER CODE BEGIN DMA1_Stream4_IRQn 0 */
@ -281,8 +281,8 @@ void DMA1_Stream4_IRQHandler(void)
}
/**
* @brief This function handles DMA1 stream5 global interrupt.
*/
* @brief This function handles DMA1 stream5 global interrupt.
*/
void DMA1_Stream5_IRQHandler(void)
{
/* USER CODE BEGIN DMA1_Stream5_IRQn 0 */
@ -295,8 +295,8 @@ void DMA1_Stream5_IRQHandler(void)
}
/**
* @brief This function handles DMA1 stream6 global interrupt.
*/
* @brief This function handles DMA1 stream6 global interrupt.
*/
void DMA1_Stream6_IRQHandler(void)
{
/* USER CODE BEGIN DMA1_Stream6_IRQn 0 */
@ -309,8 +309,8 @@ void DMA1_Stream6_IRQHandler(void)
}
/**
* @brief This function handles TIM1 update interrupt and TIM10 global interrupt.
*/
* @brief This function handles TIM1 update interrupt and TIM10 global interrupt.
*/
void TIM1_UP_TIM10_IRQHandler(void)
{
/* USER CODE BEGIN TIM1_UP_TIM10_IRQn 0 */
@ -323,8 +323,8 @@ void TIM1_UP_TIM10_IRQHandler(void)
}
/**
* @brief This function handles TIM3 global interrupt.
*/
* @brief This function handles TIM3 global interrupt.
*/
void TIM3_IRQHandler(void)
{
/* USER CODE BEGIN TIM3_IRQn 0 */
@ -337,8 +337,8 @@ void TIM3_IRQHandler(void)
}
/**
* @brief This function handles USART2 global interrupt.
*/
* @brief This function handles USART2 global interrupt.
*/
void USART2_IRQHandler(void)
{
/* USER CODE BEGIN USART2_IRQn 0 */
@ -368,8 +368,8 @@ void USART2_IRQHandler(void)
}
/**
* @brief This function handles USART3 global interrupt.
*/
* @brief This function handles USART3 global interrupt.
*/
void USART3_IRQHandler(void)
{
/* USER CODE BEGIN USART3_IRQn 0 */
@ -382,8 +382,8 @@ void USART3_IRQHandler(void)
}
/**
* @brief This function handles DMA1 stream7 global interrupt.
*/
* @brief This function handles DMA1 stream7 global interrupt.
*/
void DMA1_Stream7_IRQHandler(void)
{
/* USER CODE BEGIN DMA1_Stream7_IRQn 0 */
@ -404,8 +404,8 @@ void DMA1_Stream7_IRQHandler(void)
}
/**
* @brief This function handles UART4 global interrupt.
*/
* @brief This function handles UART4 global interrupt.
*/
void UART4_IRQHandler(void)
{
/* USER CODE BEGIN UART4_IRQn 0 */
@ -417,8 +417,8 @@ void UART4_IRQHandler(void)
}
/**
* @brief This function handles UART5 global interrupt.
*/
* @brief This function handles UART5 global interrupt.
*/
void UART5_IRQHandler(void)
{
/* USER CODE BEGIN UART5_IRQn 0 */
@ -447,8 +447,8 @@ void UART5_IRQHandler(void)
}
/**
* @brief This function handles DMA2 stream1 global interrupt.
*/
* @brief This function handles DMA2 stream1 global interrupt.
*/
void DMA2_Stream1_IRQHandler(void)
{
/* USER CODE BEGIN DMA2_Stream1_IRQn 0 */
@ -461,8 +461,8 @@ void DMA2_Stream1_IRQHandler(void)
}
/**
* @brief This function handles Ethernet global interrupt.
*/
* @brief This function handles Ethernet global interrupt.
*/
void ETH_IRQHandler(void)
{
/* USER CODE BEGIN ETH_IRQn 0 */
@ -475,8 +475,8 @@ void ETH_IRQHandler(void)
}
/**
* @brief This function handles DMA2 stream6 global interrupt.
*/
* @brief This function handles DMA2 stream6 global interrupt.
*/
void DMA2_Stream6_IRQHandler(void)
{
/* USER CODE BEGIN DMA2_Stream6_IRQn 0 */
@ -489,8 +489,8 @@ void DMA2_Stream6_IRQHandler(void)
}
/**
* @brief This function handles USART6 global interrupt.
*/
* @brief This function handles USART6 global interrupt.
*/
void USART6_IRQHandler(void)
{
/* USER CODE BEGIN USART6_IRQn 0 */

View File

@ -21,6 +21,7 @@
#include "usart.h"
/* USER CODE BEGIN 0 */
#include "ht1200m.h"
/* USER CODE END 0 */
UART_HandleTypeDef huart4;
@ -91,8 +92,8 @@ void MX_UART5_Init(void)
Error_Handler();
}
/* USER CODE BEGIN UART5_Init 2 */
// __HAL_UART_ENABLE_IT(&huart5, UART_IT_RXNE); // 接收中断
// __HAL_UART_ENABLE_IT(&huart5, UART_IT_IDLE); // 空闲中断
__HAL_UART_ENABLE_IT(&huart5, UART_IT_RXNE); // 接收中断
__HAL_UART_ENABLE_IT(&huart5, UART_IT_IDLE); // 空闲中断
/* USER CODE END UART5_Init 2 */
}
@ -121,8 +122,8 @@ void MX_USART2_UART_Init(void)
Error_Handler();
}
/* USER CODE BEGIN USART2_Init 2 */
// __HAL_UART_ENABLE_IT(&huart2, UART_IT_RXNE); // 接收中断
// __HAL_UART_ENABLE_IT(&huart2, UART_IT_IDLE); // 使能IDLE中æ­
__HAL_UART_ENABLE_IT(&huart2, UART_IT_RXNE); // 接收中断
__HAL_UART_ENABLE_IT(&huart2, UART_IT_IDLE); // 使能IDLE中æ­
/* USER CODE END USART2_Init 2 */
}
@ -647,21 +648,15 @@ void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle)
}
/* USER CODE BEGIN 1 */
/**
* @brief 使ç¨DMAæ¹å¼<EFBFBD>éšè¿ä¸²å<EFBFBD>£å<EFBFBD>é?<EFBFBD>æ°æ<EFBFBD>?
*
* è¯¥å½æ°ä½¿ç¨DMAæ¹å¼<EFBFBD>éšè¿æŒå®šçšä¸²å<EFBFBD>£å<EFBFBD>é<EFBFBD>æŒå®šé¿åº¦çšæ°æ<EFBFBD>®ã?
*
* @param huart UART_HandleTypeDefç»æžä½æŒéˆï¼ŒæŒå<EFBFBD>éœ?è¦<EFBFBD>使ç¨çšä¸²å<EFBFBD>£å<EFBFBD>¥æŸ
* @param buf æŒå<EFBFBD>éœ?è¦<EFBFBD>å<EFBFBD>é<EFBFBD>çšæ°æ<EFBFBD>®ç¼å²åŒºçšæŒéˆ
* @param len éœ?è¦<EFBFBD>å<EFBFBD>é<EFBFBD>çšæ°æ<EFBFBD>®é¿åº¦
*
* @return æ è¿åžå??
*
* @note 妿žœå<EFBFBD>é?<EFBFBD>è¿ç¨ä¸­åºçްé误,会调ç¨Error_Handler彿°å¤ç<EFBFBD>é误
*/
void dma_usart_send(UART_HandleTypeDef *huart, uint8_t *buf, uint8_t len)
/*
*********************************************************************************************************
* å? æ? å<EFBFBD>?: dma_usart_send
* 功能说明: 串å<EFBFBD>£å<EFBFBD>é?<EFBFBD>åŠŸèƒ½å½æ?
* å½? å<EFBFBD>?: buf,len
* è¿? å? å?: æ?
*********************************************************************************************************
*/
void dma_usart_send(UART_HandleTypeDef *huart, uint8_t *buf, uint8_t len) // 串å<C2B2>£å<C2A3>é?<3F>å°<C3A5>è£?
{
if (HAL_UART_Transmit_DMA(huart, buf, len) != HAL_OK) // åˆ¤æ­æ˜¯å<C2AF>¦å<C2A6>é?<3F>æ­£å¸¸ï¼Œå¦æžœå‡ºçްå¼å¸¸åˆ™è¿å…¥å¼å¸¸ä¸­æ­å‡½æ•?
{

View File

@ -1,21 +0,0 @@
/*
* Auto generated Run-Time-Environment Configuration File
* *** Do not modify ! ***
*
* Project: 'semi-finished_product_testing'
* Target: 'semi-finished_product_testing'
*/
#ifndef RTE_COMPONENTS_H
#define RTE_COMPONENTS_H
/*
* Define the Device Header File:
*/
#define CMSIS_device_header "stm32f4xx.h"
#endif /* RTE_COMPONENTS_H */

2221
MDK-ARM/TEST2.uvprojx Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,19 +0,0 @@
; *************************************************************
; *** Scatter-Loading Description File generated by uVision ***
; *************************************************************
LR_IROM1 0x08000000 0x00100000 { ; load region size_region
ER_IROM1 0x08000000 0x00100000 { ; load address = execution address
*.o (RESET, +First)
*(InRoot$$Sections)
.ANY (+RO)
.ANY (+XO)
}
RW_IRAM1 0x20000000 0x0001C000 { ; RW data
.ANY (+RW +ZI)
}
RW_IRAM2 0x2001C000 0x00004000 {
.ANY (+RW +ZI)
}
}

View File

@ -117,7 +117,7 @@ ETH.IPParameters=MediaInterface
ETH.MediaInterface=HAL_ETH_RMII_MODE
FREERTOS.FootprintOK=true
FREERTOS.IPParameters=Tasks01,configMAX_TASK_NAME_LEN,configENABLE_FPU,configMAX_PRIORITIES,FootprintOK
FREERTOS.Tasks01=lwip_task,2,512,start_tcp_task,Default,NULL,Dynamic,NULL,NULL;led_task,-2,128,start_led_toggle_task,Default,NULL,Dynamic,NULL,NULL;dac_task,0,512,start_dac_task,Default,NULL,Dynamic,NULL,NULL;adc_task,-1,128,start_adc_task,Default,NULL,Dynamic,NULL,NULL;gpio_di_do_task,0,128,start_gpio_di_do_task,Default,NULL,Dynamic,NULL,NULL
FREERTOS.Tasks01=lwip_task,2,512,start_tcp_task,Default,NULL,Dynamic,NULL,NULL;led_task,-2,128,start_led_toggle_task,Default,NULL,Dynamic,NULL,NULL;dac_task,0,512,start_dac_task,Default,NULL,Dynamic,NULL,NULL;adc_task,-1,128,start_adc_task,Default,NULL,Dynamic,NULL,NULL
FREERTOS.configENABLE_FPU=1
FREERTOS.configMAX_PRIORITIES=32
FREERTOS.configMAX_TASK_NAME_LEN=24
@ -163,67 +163,65 @@ Mcu.IP9=TIM3
Mcu.IPNb=15
Mcu.Name=STM32F407V(E-G)Tx
Mcu.Package=LQFP100
Mcu.Pin0=PE2
Mcu.Pin1=PE3
Mcu.Pin10=PC5
Mcu.Pin11=PB1
Mcu.Pin12=PB2
Mcu.Pin13=PE7
Mcu.Pin14=PE12
Mcu.Pin15=PE13
Mcu.Pin16=PE14
Mcu.Pin17=PB11
Mcu.Pin18=PB12
Mcu.Pin19=PB13
Mcu.Pin2=PH0-OSC_IN
Mcu.Pin20=PD8
Mcu.Pin21=PD9
Mcu.Pin22=PD11
Mcu.Pin23=PD12
Mcu.Pin24=PD13
Mcu.Pin25=PD14
Mcu.Pin26=PD15
Mcu.Pin27=PC6
Mcu.Pin28=PC7
Mcu.Pin29=PC8
Mcu.Pin3=PH1-OSC_OUT
Mcu.Pin30=PC9
Mcu.Pin31=PA8
Mcu.Pin32=PA11
Mcu.Pin33=PA12
Mcu.Pin34=PA13
Mcu.Pin35=PA14
Mcu.Pin36=PA15
Mcu.Pin37=PC10
Mcu.Pin38=PC11
Mcu.Pin39=PC12
Mcu.Pin4=PC0
Mcu.Pin40=PD0
Mcu.Pin41=PD1
Mcu.Pin42=PD2
Mcu.Pin43=PD3
Mcu.Pin44=PD4
Mcu.Pin45=PD5
Mcu.Pin46=PD6
Mcu.Pin47=PD7
Mcu.Pin48=PB3
Mcu.Pin49=PB4
Mcu.Pin5=PC1
Mcu.Pin50=PB5
Mcu.Pin51=PB6
Mcu.Pin52=PB7
Mcu.Pin53=PE0
Mcu.Pin54=PE1
Mcu.Pin55=VP_FREERTOS_VS_CMSIS_V1
Mcu.Pin56=VP_LWIP_VS_Enabled
Mcu.Pin57=VP_SYS_VS_tim1
Mcu.Pin58=VP_TIM2_VS_ClockSourceINT
Mcu.Pin59=VP_TIM3_VS_ClockSourceINT
Mcu.Pin6=PA1
Mcu.Pin7=PA2
Mcu.Pin8=PA7
Mcu.Pin9=PC4
Mcu.PinsNb=60
Mcu.Pin0=PH0-OSC_IN
Mcu.Pin1=PH1-OSC_OUT
Mcu.Pin10=PB2
Mcu.Pin11=PE7
Mcu.Pin12=PE12
Mcu.Pin13=PE13
Mcu.Pin14=PE14
Mcu.Pin15=PB11
Mcu.Pin16=PB12
Mcu.Pin17=PB13
Mcu.Pin18=PD8
Mcu.Pin19=PD9
Mcu.Pin2=PC0
Mcu.Pin20=PD11
Mcu.Pin21=PD12
Mcu.Pin22=PD13
Mcu.Pin23=PD14
Mcu.Pin24=PD15
Mcu.Pin25=PC6
Mcu.Pin26=PC7
Mcu.Pin27=PC8
Mcu.Pin28=PC9
Mcu.Pin29=PA8
Mcu.Pin3=PC1
Mcu.Pin30=PA11
Mcu.Pin31=PA12
Mcu.Pin32=PA13
Mcu.Pin33=PA14
Mcu.Pin34=PA15
Mcu.Pin35=PC10
Mcu.Pin36=PC11
Mcu.Pin37=PC12
Mcu.Pin38=PD0
Mcu.Pin39=PD1
Mcu.Pin4=PA1
Mcu.Pin40=PD2
Mcu.Pin41=PD3
Mcu.Pin42=PD4
Mcu.Pin43=PD5
Mcu.Pin44=PD6
Mcu.Pin45=PD7
Mcu.Pin46=PB3
Mcu.Pin47=PB4
Mcu.Pin48=PB5
Mcu.Pin49=PB6
Mcu.Pin5=PA2
Mcu.Pin50=PB7
Mcu.Pin51=PE0
Mcu.Pin52=PE1
Mcu.Pin53=VP_FREERTOS_VS_CMSIS_V1
Mcu.Pin54=VP_LWIP_VS_Enabled
Mcu.Pin55=VP_SYS_VS_tim1
Mcu.Pin56=VP_TIM2_VS_ClockSourceINT
Mcu.Pin57=VP_TIM3_VS_ClockSourceINT
Mcu.Pin6=PA7
Mcu.Pin7=PC4
Mcu.Pin8=PC5
Mcu.Pin9=PB1
Mcu.PinsNb=58
Mcu.ThirdPartyNb=0
Mcu.UserConstants=
Mcu.UserName=STM32F407VGTx
@ -510,16 +508,6 @@ PE14.GPIO_Speed=GPIO_SPEED_FREQ_MEDIUM
PE14.Locked=true
PE14.PinState=GPIO_PIN_SET
PE14.Signal=GPIO_Output
PE2.GPIOParameters=GPIO_PuPd,GPIO_Label
PE2.GPIO_Label=DI_CH5
PE2.GPIO_PuPd=GPIO_PULLUP
PE2.Locked=true
PE2.Signal=GPIO_Input
PE3.GPIOParameters=GPIO_PuPd,GPIO_Label
PE3.GPIO_Label=DI_CH6
PE3.GPIO_PuPd=GPIO_PULLUP
PE3.Locked=true
PE3.Signal=GPIO_Input
PE7.GPIOParameters=GPIO_Speed,PinState,GPIO_PuPd,GPIO_Label
PE7.GPIO_Label=LED3_Y
PE7.GPIO_PuPd=GPIO_PULLUP
@ -552,8 +540,8 @@ ProjectManager.MainLocation=Core/Src
ProjectManager.NoMain=false
ProjectManager.PreviousToolchain=
ProjectManager.ProjectBuild=false
ProjectManager.ProjectFileName=semi-finished_product_testing.ioc
ProjectManager.ProjectName=semi-finished_product_testing
ProjectManager.ProjectFileName=TEST2.ioc
ProjectManager.ProjectName=TEST2
ProjectManager.ProjectStructure=
ProjectManager.RegisterCallBack=
ProjectManager.StackSize=0x400

View File

@ -1,57 +0,0 @@
#ifndef _COMMUNICATION_PROTOCOL_H_
#define _COMMUNICATION_PROTOCOL_H_
#include "user_lib.h"
#define COM_ERROR_CODE_SIZE 7 // 通信错误返回帧长度
#define COM_AI_DATA_SIZE 11 // 模拟量数据返回帧长度
#define FRAME_HEAD 0xAA // 帧头
#define FRAME_TAIL 0x3C // 帧尾
typedef enum
{
COM_OK = 0,
FRAMING_ERROR,
CHECK_ERROR,
COMMAND_ERROR,
DEVICE_ERROR,
} communication_error_e;
#pragma pack(1)
typedef struct
{
uint8_t start_addr;
uint8_t num;
uint8_t data[16];
} communication_do_t;
typedef struct
{
uint8_t start_addr;
uint8_t num;
} communication_di_t;
typedef struct
{
uint8_t channel;
float32_u data;
} communication_ao_t;
typedef struct
{
uint8_t channel;
} communication_ai_t;
typedef union
{
uint8_t data[50];
communication_do_t do_data;
communication_di_t di_data;
communication_ao_t ao_data;
communication_ai_t ai_data;
} communication_data_u;
#pragma pack()
void communication_exception(uint8_t *tx_data, const uint8_t *const rx_data, communication_error_e error_code);
void communication_get_ai(communication_ai_t *ai_data, uint8_t *tx_data, const uint8_t *const rx_data);
void communication_set_ao(communication_ao_t *ao_data);
#endif

View File

@ -5,9 +5,8 @@
#define TCP_PORT_HART1 5001
#define TCP_PORT_HART2 5002
#define TCP_PORT_BLE1 6001
#define TCP_PORT_BLE2 6002
#define TCP_PORT_CONTROL 5003
#define TCP_PORT_BLE1 5003
#define TCP_PORT_BLE2 5004
extern void tcp_echo_init(void);
extern void user_send_data_hart1(uint8_t *data, uint16_t len);

View File

@ -1,41 +0,0 @@
#ifndef _USER_LIB_H_
#define _USER_LIB_H_
#include <stdint.h>
typedef union
{
float f;
int32_t c;
} float32_u; // 浮点数共用体
// uint32小端转大端
#define S2B_UINT32(a) \
(((uint32_t)(a) & 0xFF000000) >> 24) + (((uint32_t)(a) & 0x00FF0000) >> 8) + (((uint32_t)(a) & 0x0000FF00) << 8) + (((uint32_t)(a) & 0x000000FF) << 24)
// uint32大端转小端
#define B2S_UINT32(a) S2B_UINT32(a)
// uint16小端转大端
#define S2B_UINT16(a) ((((uint16_t)(a) & 0xFF00) >> 8) + (((uint16_t)(a) & 0x00FF) << 8))
// uint16大端转小端
#define B2S_UINT16(a) S2B_UINT16(a)
#define BUILD_UINT16(loByte, hiByte) \
((uint16_t)(((loByte) & 0x00FF) + (((hiByte) & 0x00FF) << 8)))
// float32小端转大端
static inline float S2B_FLOAT32(float fv)
{
float32_u _f;
_f.f = fv;
_f.c = S2B_UINT32(_f.c);
return _f.f;
}
// float32大端转小端
#define B2S_FLOAT32(a) S2B_FLOAT32(a)
uint8_t xor_compute(const uint8_t *const data, uint16_t length);
#endif

View File

@ -1,49 +0,0 @@
#include "communication_protocol.h"
#include "user_lib.h"
#include "ad7124.h"
extern float current_buff[2];
extern ad7124_analog_t ad7124_analog[AD7124_CHANNEL_EN_MAX];
/**
* @brief
*
* TCP数据包
*
* @param tx_data
* @param rx_data
* @param error_code
*/
void communication_exception(uint8_t *tx_data, const uint8_t *const rx_data, communication_error_e error_code)
{
uint8_t tx_data_len = COM_ERROR_CODE_SIZE;
tx_data[0] = FRAME_HEAD; // 帧头
tx_data[1] = error_code; // 状态
tx_data[2] = rx_data[2]; // 设备号
tx_data[3] = rx_data[3]; // 命令号
tx_data[4] = 0x00; // 数据长度
tx_data[5] = xor_compute(tx_data + 1, tx_data_len - 3); // 异或校验
tx_data[6] = FRAME_TAIL; // 帧尾
}
void communication_get_ai(communication_ai_t *ai_data, uint8_t *tx_data, const uint8_t *const rx_data)
{
float32_u analog_data;
uint8_t tx_data_len = COM_AI_DATA_SIZE;
analog_data.f = S2B_FLOAT32(ad7124_analog[ai_data->channel].current);
tx_data[0] = FRAME_HEAD; // 帧头
tx_data[1] = COM_OK; // 状态
tx_data[2] = rx_data[2]; // 设备号
tx_data[3] = rx_data[3]; // 命令号
tx_data[4] = 4; // 数据长度
tx_data[5] = analog_data.c; // 数据
tx_data[6] = analog_data.c >> 8; // 数据
tx_data[7] = analog_data.c >> 16; // 数据
tx_data[8] = analog_data.c >> 24; // 数据
tx_data[9] = xor_compute(tx_data + 1, tx_data_len - 3); // 异或校验
tx_data[10] = FRAME_TAIL; // 帧尾
}
void communication_set_ao(communication_ao_t *ao_data)
{
current_buff[ao_data->channel] = B2S_FLOAT32(ao_data->data.f);
}

View File

@ -11,45 +11,51 @@
#include "usart.h"
#include "main.h"
#include "ht1200m.h"
#include "user_lib.h"
#include "communication_protocol.h"
#include "user_gpio.h"
struct tcp_pcb *server_pcb_hart1 = NULL;
struct tcp_pcb *server_pcb_hart2 = NULL;
struct tcp_pcb *server_pcb_ble1 = NULL;
struct tcp_pcb *server_pcb_ble2 = NULL;
struct tcp_pcb *server_pcb_control = NULL;
communication_di_t *user_communication_di = NULL;
communication_do_t *user_communication_do = NULL;
communication_ai_t *user_communication_ai = NULL;
communication_ao_t *user_communication_ao = NULL;
extern uint8_t tcp_echo_flags_hart1;
extern uint8_t tcp_echo_flags_hart2;
extern uint8_t tcp_echo_flags_ble1;
extern uint8_t tcp_echo_flags_ble2;
extern uint8_t tcp_echo_flags_control;
/*接收回调函数*/
/*接收回调函数*/
static err_t tcpecho_recv_hart1(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err)
{ // 对应接收数据连接的控制块 接收到的数据
{ // 对应接收数据连接的控制块 接收到的数据
if (p != NULL)
{
/* 更新窗口*/
/* 更新窗口*/
tcp_echo_flags_hart1 = 1;
tcp_recved(tpcb, p->tot_len); // 读取数据的控制块 得到所有数据的长度
server_pcb_hart1 = tpcb; // 直接赋值
tcp_recved(tpcb, p->tot_len); // 读取数据的控制块 得到所有数据的长度
memcpy(&server_pcb_hart1, &tpcb, sizeof(struct tcp_pcb *));
#if 0
memcpy(hart2_uart2.tx_data, (int *)p->payload, p->tot_len);
HART2_RTS_SEND;
HAL_UART_Transmit(&huart2, hart2_uart2.tx_data, p->tot_len, 1000);
HART2_RTS_RECEIVE;
#endif
#if 1
memcpy(hart1_uart5.tx_data, (int *)p->payload, p->tot_len);
if (huart5.gState == HAL_UART_STATE_READY)
{
HART1_RTS_SEND;
dma_usart_send(&huart5, hart1_uart5.tx_data, p->tot_len);
}
HART1_RTS_SEND;
dma_usart_send(&huart5, hart1_uart5.tx_data, p->tot_len);
// HART1_RTS_RECEIVE;
#endif
#if 0
memcpy(ble1_uart6.tx_data, (int *)p->payload, p->tot_len);
dma_usart_send(&huart6, ble1_uart6.tx_data, p->tot_len);
#endif
#if 0
memcpy(ble2_uart3.tx_data, (int *)p->payload, p->tot_len);
dma_usart_send(&huart3, ble2_uart3.tx_data, p->tot_len);
#endif
#if 0
memcpy(lcd_uart4.tx_data, (int *)p->payload, p->tot_len);
dma_usart_send(&huart4, lcd_uart4.tx_data, p->tot_len);
#endif
memset(p->payload, 0, p->tot_len);
pbuf_free(p);
}
else if (err == ERR_OK) // 检测到对方主动关闭连接时也会调用recv函数此时p为空
else if (err == ERR_OK) // 检测到对方主动关闭连接时也会调用recv函数此时p为空
{
return tcp_close(tpcb);
}
@ -57,23 +63,40 @@ static err_t tcpecho_recv_hart1(void *arg, struct tcp_pcb *tpcb, struct pbuf *p,
}
static err_t tcpecho_recv_hart2(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err)
{ // 对应接收数据连接的控制块 接收到的数据
{ // 对应接收数据连接的控制块 接收到的数据
if (p != NULL)
{
/* 更新窗口*/
/* 更新窗口*/
tcp_echo_flags_hart2 = 1;
tcp_recved(tpcb, p->tot_len); // 读取数据的控制块 得到所有数据的长度
server_pcb_hart2 = tpcb; // 直接赋值
tcp_recved(tpcb, p->tot_len); // 读取数据的控制块 得到所有数据的长度
memcpy(&server_pcb_hart2, &tpcb, sizeof(struct tcp_pcb *));
#if 1
memcpy(hart2_uart2.tx_data, (int *)p->payload, p->tot_len);
if (huart2.gState == HAL_UART_STATE_READY)
{
HART2_RTS_SEND;
dma_usart_send(&huart2, hart2_uart2.tx_data, p->tot_len);
}
HART2_RTS_SEND;
dma_usart_send(&huart2, hart2_uart2.tx_data, p->tot_len);
#endif
#if 0
memcpy(hart1_uart5.tx_data, (int *)p->payload, p->tot_len);
HART1_RTS_SEND;
HAL_UART_Transmit(&huart5, hart1_uart5.tx_data, p->tot_len, 100);
HART1_RTS_RECEIVE;
#endif
#if 0
memcpy(ble1_uart6.tx_data, (int *)p->payload, p->tot_len);
dma_usart_send(&huart6, ble1_uart6.tx_data, p->tot_len);
#endif
#if 0
memcpy(ble2_uart3.tx_data, (int *)p->payload, p->tot_len);
dma_usart_send(&huart3, ble2_uart3.tx_data, p->tot_len);
#endif
#if 0
memcpy(lcd_uart4.tx_data, (int *)p->payload, p->tot_len);
dma_usart_send(&huart4, lcd_uart4.tx_data, p->tot_len);
#endif
memset(p->payload, 0, p->tot_len);
pbuf_free(p);
}
else if (err == ERR_OK) // 检测到对方主动关闭连接时也会调用recv函数此时p为空
else if (err == ERR_OK) // 检测到对方主动关闭连接时也会调用recv函数此时p为空
{
return tcp_close(tpcb);
}
@ -81,23 +104,21 @@ static err_t tcpecho_recv_hart2(void *arg, struct tcp_pcb *tpcb, struct pbuf *p,
}
static err_t tcpecho_recv_ble1(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err)
{ // 对应接收数据连接的控制块 接收到的数据
{ // 对应接收数据连接的控制块 接收到的数据
if (p != NULL)
{
/* 更新窗口*/
/* 更新窗口*/
tcp_echo_flags_ble1 = 1;
tcp_recved(tpcb, p->tot_len); // 读取数据的控制块 得到所有数据的长度
server_pcb_ble1 = tpcb; // 直接赋值
tcp_recved(tpcb, p->tot_len); // 读取数据的控制块 得到所有数据的长度
memcpy(&server_pcb_ble1, &tpcb, sizeof(struct tcp_pcb *));
memcpy(ble1_uart6.tx_data, (int *)p->payload, p->tot_len);
if (huart6.gState == HAL_UART_STATE_READY)
{
dma_usart_send(&huart6, ble1_uart6.tx_data, p->tot_len);
}
dma_usart_send(&huart6, ble1_uart6.tx_data, p->tot_len);
memset(p->payload, 0, p->tot_len);
pbuf_free(p);
}
else if (err == ERR_OK) // 检测到对方主动关闭连接时也会调用recv函数此时p为空
else if (err == ERR_OK) // 检测到对方主动关闭连接时也会调用recv函数此时p为空
{
return tcp_close(tpcb);
}
@ -105,144 +126,50 @@ static err_t tcpecho_recv_ble1(void *arg, struct tcp_pcb *tpcb, struct pbuf *p,
}
static err_t tcpecho_recv_ble2(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err)
{ // 对应接收数据连接的控制块 接收到的数据
{ // 对应接收数据连接的控制块 接收到的数据
if (p != NULL)
{
/* 更新窗口*/
/* 更新窗口*/
tcp_echo_flags_ble2 = 1;
tcp_recved(tpcb, p->tot_len); // 读取数据的控制块 得到所有数据的长度
server_pcb_ble2 = tpcb; // 直接赋值
tcp_recved(tpcb, p->tot_len); // 读取数据的控制块 得到所有数据的长度
memcpy(&server_pcb_ble2, &tpcb, sizeof(struct tcp_pcb *));
memcpy(ble2_uart3.tx_data, (int *)p->payload, p->tot_len);
if (huart3.gState == HAL_UART_STATE_READY)
{
dma_usart_send(&huart3, ble2_uart3.tx_data, p->tot_len);
}
dma_usart_send(&huart3, ble2_uart3.tx_data, p->tot_len);
memset(p->payload, 0, p->tot_len);
pbuf_free(p);
}
else if (err == ERR_OK) // 检测到对方主动关闭连接时也会调用recv函数此时p为空
else if (err == ERR_OK) // 检测到对方主动关闭连接时也会调用recv函数此时p为空
{
return tcp_close(tpcb);
}
return ERR_OK;
}
static err_t tcpecho_recv_control(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err)
static err_t tcpecho_accept_hart1(void *arg, struct tcp_pcb *newpcb, err_t err) // 由于这个函数是*tcp_accept_fn类型的
// 形参的数量和类型必须一致
{
uint8_t tcp_rx_data[128] = {0}; // 接受数据缓存区
uint8_t tcp_tx_data[128] = {0}; // 发送数据缓存区
uint8_t rx_data_len = 0;
uint8_t tx_data_len = 0;
communication_data_u communication_data;
if (p != NULL)
{
/* 更新窗口*/
tcp_recved(tpcb, p->tot_len); // 读取数据的控制块 得到所有数据的长度
server_pcb_control = tpcb; // 直接赋值
memcpy(tcp_rx_data, (int *)p->payload, p->tot_len);
rx_data_len = p->tot_len;
/*1. 对接收的数据做异或校验、帧头帧尾判断,校验失败返回信息,校验通过继续下一步、校验数据从帧头后面到校验位结束*/
if (tcp_rx_data[0] != 0xAA || tcp_rx_data[rx_data_len - 1] != 0x3C) // 帧头帧尾判断
{
tx_data_len = COM_ERROR_CODE_SIZE;
communication_exception(tcp_tx_data, tcp_rx_data, FRAMING_ERROR);
tcp_write(tpcb, tcp_tx_data, tx_data_len, 1);
}
else
{
if (tcp_rx_data[rx_data_len - 2] != xor_compute(tcp_rx_data + 1, rx_data_len - 3)) // 异或校验
{
tx_data_len = COM_ERROR_CODE_SIZE;
communication_exception(tcp_tx_data, tcp_rx_data, CHECK_ERROR);
tcp_write(tpcb, tcp_tx_data, tx_data_len, 1);
}
else
{
memcpy(communication_data.data, tcp_rx_data + 5, tcp_rx_data[4]);
if (tcp_rx_data[3] == 0x00) // 读模拟量指令
{
/*读操作,从寄存器读取数据,组包返回*/
tx_data_len = COM_AI_DATA_SIZE;
user_communication_ai = &communication_data.ai_data;
communication_get_ai(user_communication_ai, tcp_tx_data, tcp_rx_data);
tcp_write(tpcb, tcp_tx_data, tx_data_len, 1);
}
else if (tcp_rx_data[3] == 0x01) // 写模拟量指令
{
/*写操作,将数据写入寄存器,组包返回*/
tcp_echo_flags_control = 1;
user_communication_ao = &communication_data.ao_data;
communication_set_ao(user_communication_ao);
tcp_write(tpcb, tcp_rx_data, rx_data_len, 1);
}
else if (tcp_rx_data[3] == 0x02) // 读数字量指令
{
/*读操作,从寄存器读取数据,组包返回*/
user_communication_di = &communication_data.di_data;
tx_data_len = 7 + user_communication_di->num;
user_read_gpio(user_communication_di, tcp_tx_data, tcp_rx_data);
tcp_write(tpcb, tcp_tx_data, tx_data_len, 1);
}
else if (tcp_rx_data[3] == 0x03) // 写数字量指令
{
/*写操作,将数据写入寄存器,组包返回*/
user_communication_do = &communication_data.do_data;
user_write_gpio(user_communication_do);
tcp_write(tpcb, tcp_rx_data, rx_data_len, 1);
}
else
{
// 返回命令号错误
tx_data_len = COM_ERROR_CODE_SIZE;
communication_exception(tcp_tx_data, tcp_rx_data, COMMAND_ERROR);
tcp_write(tpcb, tcp_tx_data, tx_data_len, 1);
}
}
/*2. 判断所要执行的操作 读或写指令*/
/*3. 对要发送的数据进行校验,组包,返回数据*/
pbuf_free(p);
}
}
else if (err == ERR_OK) // 检测到对方主动关闭连接时也会调用recv函数此时p为空
{
return tcp_close(tpcb);
}
return ERR_OK;
}
static err_t tcpecho_accept_hart1(void *arg, struct tcp_pcb *newpcb, err_t err) // 由于这个函数是*tcp_accept_fn类型的
// 形参的数量和类型必须一致
{
tcp_recv(newpcb, tcpecho_recv_hart1); // 当收到数据时回调用户自己写的tcpecho_recv
tcp_recv(newpcb, tcpecho_recv_hart1); // 当收到数据时回调用户自己写的tcpecho_recv
return ERR_OK;
}
static err_t tcpecho_accept_hart2(void *arg, struct tcp_pcb *newpcb, err_t err) // 由于这个函数是*tcp_accept_fn类型的
static err_t tcpecho_accept_hart2(void *arg, struct tcp_pcb *newpcb, err_t err) // 由于这个函数是*tcp_accept_fn类型的
{
tcp_recv(newpcb, tcpecho_recv_hart2); // 当收到数据时回调用户自己写的tcpecho_recv
tcp_recv(newpcb, tcpecho_recv_hart2); // 当收到数据时回调用户自己写的tcpecho_recv
return ERR_OK;
}
static err_t tcpecho_accept_ble1(void *arg, struct tcp_pcb *newpcb, err_t err) // 由于这个函数是*tcp_accept_fn类型的
static err_t tcpecho_accept_ble1(void *arg, struct tcp_pcb *newpcb, err_t err) // 由于这个函数是*tcp_accept_fn类型的
{
tcp_recv(newpcb, tcpecho_recv_ble1); // 当收到数据时回调用户自己写的tcpecho_recv
tcp_recv(newpcb, tcpecho_recv_ble1); // 当收到数据时回调用户自己写的tcpecho_recv
return ERR_OK;
}
static err_t tcpecho_accept_ble2(void *arg, struct tcp_pcb *newpcb, err_t err) // 由于这个函数是*tcp_accept_fn类型的
static err_t tcpecho_accept_ble2(void *arg, struct tcp_pcb *newpcb, err_t err) // 由于这个函数是*tcp_accept_fn类型的
{
tcp_recv(newpcb, tcpecho_recv_ble2); // 当收到数据时回调用户自己写的tcpecho_recv
return ERR_OK;
}
static err_t tcpecho_accept_control(void *arg, struct tcp_pcb *newpcb, err_t err) // 由于这个函数是*tcp_accept_fn类型的
{
tcp_recv(newpcb, tcpecho_recv_control); // 当收到数据时回调用户自己写的tcpecho_recv
tcp_recv(newpcb, tcpecho_recv_ble2); // 当收到数据时回调用户自己写的tcpecho_recv
return ERR_OK;
}
@ -252,87 +179,82 @@ void tcp_echo_init(void)
struct tcp_pcb *server_hart2 = NULL;
struct tcp_pcb *server_ble1 = NULL;
struct tcp_pcb *server_ble2 = NULL;
struct tcp_pcb *server_control = NULL;
/* 创建一路HART */
/* 创建一个TCP控制块 */
server_hart1 = tcp_new();
/* 绑定TCP控制块 */
/* 绑定TCP控制块 */
tcp_bind(server_hart1, IP_ADDR_ANY, TCP_PORT_HART1);
/* 进入监听状态 */
/* 进入监听状态 */
server_hart1 = tcp_listen(server_hart1);
/* 处理连接 注册函数,侦听到连接时被注册的函数被回调 */
tcp_accept(server_hart1, tcpecho_accept_hart1); // 侦听到连接后回调用户编写的tcpecho_accept
/* 处理连接 注册函数,侦听到连接时被注册的函数被回调 */
tcp_accept(server_hart1, tcpecho_accept_hart1); // 侦听到连接后回调用户编写的tcpecho_accept
/* 创建二路HART */
/* 创建一个TCP控制块 */
server_hart2 = tcp_new();
/* 绑定TCP控制块 */
/* 绑定TCP控制块 */
tcp_bind(server_hart2, IP_ADDR_ANY, TCP_PORT_HART2);
/* 进入监听状态 */
/* 进入监听状态 */
server_hart2 = tcp_listen(server_hart2);
/* 处理连接 注册函数,侦听到连接时被注册的函数被回调 */
tcp_accept(server_hart2, tcpecho_accept_hart2); // 侦听到连接后回调用户编写的tcpecho_accept
/* 处理连接 注册函数,侦听到连接时被注册的函数被回调 */
tcp_accept(server_hart2, tcpecho_accept_hart2); // 侦听到连接后回调用户编写的tcpecho_accept
/* 创建一路蓝牙 */
/* 创建一个TCP控制块 */
server_ble1 = tcp_new();
/* 绑定TCP控制块 */
/* 绑定TCP控制块 */
tcp_bind(server_ble1, IP_ADDR_ANY, TCP_PORT_BLE1);
/* 进入监听状态 */
/* 进入监听状态 */
server_ble1 = tcp_listen(server_ble1);
/* 处理连接 注册函数,侦听到连接时被注册的函数被回调 */
tcp_accept(server_ble1, tcpecho_accept_ble1); // 侦听到连接后回调用户编写的tcpecho_accept
/* 处理连接 注册函数,侦听到连接时被注册的函数被回调 */
tcp_accept(server_ble1, tcpecho_accept_ble1); // 侦听到连接后回调用户编写的tcpecho_accept
/* 创建二路蓝牙 */
/* 创建一个TCP控制块 */
server_ble2 = tcp_new();
/* 绑定TCP控制块 */
/* 绑定TCP控制块 */
tcp_bind(server_ble2, IP_ADDR_ANY, TCP_PORT_BLE2);
/* 进入监听状态 */
/* 进入监听状态 */
server_ble2 = tcp_listen(server_ble2);
/* 处理连接 注册函数,侦听到连接时被注册的函数被回调 */
tcp_accept(server_ble2, tcpecho_accept_ble2); // 侦听到连接后回调用户编写的tcpecho_accept
/* 创建控制块 */
server_control = tcp_new();
/* 绑定TCP控制块 */
tcp_bind(server_control, IP_ADDR_ANY, TCP_PORT_CONTROL);
/* 进入监听状态 */
server_control = tcp_listen(server_control);
/* 处理连接 注册函数,侦听到连接时被注册的函数被回调 */
tcp_accept(server_control, tcpecho_accept_control); // 侦听到连接后回调用户编写的tcpecho_accept
/* 处理连接 注册函数,侦听到连接时被注册的函数被回调 */
tcp_accept(server_ble2, tcpecho_accept_ble2); // 侦听到连接后回调用户编写的tcpecho_accept
}
void user_send_data_hart1(uint8_t *data, uint16_t len)
{
tcp_write(server_pcb_hart1, data, len, 1);
if (tcp_echo_flags_hart1 == 1)
{
tcp_write(server_pcb_hart1, data, len, 1);
}
}
void user_send_data_hart2(uint8_t *data, uint16_t len)
{
tcp_write(server_pcb_hart2, data, len, 1);
if (tcp_echo_flags_hart2 == 1)
{
tcp_write(server_pcb_hart2, data, len, 1);
}
}
void user_send_data_ble1(uint8_t *data, uint16_t len)
{
tcp_write(server_pcb_ble1, data, len, 1);
if (tcp_echo_flags_ble1 == 1)
{
tcp_write(server_pcb_ble1, data, len, 1);
}
}
void user_send_data_ble2(uint8_t *data, uint16_t len)
{
tcp_write(server_pcb_ble2, data, len, 1);
if (tcp_echo_flags_ble2 == 1)
{
tcp_write(server_pcb_ble2, data, len, 1);
}
}

View File

@ -1,22 +0,0 @@
#include "user_lib.h"
/**
*
*
* @param data:
* @param length:
*
* @return
*/
uint8_t xor_compute(const uint8_t *const data, uint16_t length)
{
uint16_t i;
const uint8_t *ptr = data;
uint8_t xor = 0;
for (i = 0; i < length; i++)
{
xor ^= *ptr;
ptr++;
}
return xor;
}

View File

@ -39,7 +39,7 @@ static ad7124_st_reg_t ad7124_regs[AD7124_REG_NO] = {
{AD7124_CONFIG_5, 0x0860, AD7124_SIZE_2, AD7124_RW}, /* AD7124_Config_5 */
{AD7124_CONFIG_6, 0x0860, AD7124_SIZE_2, AD7124_RW}, /* AD7124_Config_6 */
{AD7124_CONFIG_7, 0x0860, AD7124_SIZE_2, AD7124_RW}, /* AD7124_Config_7 */
{AD7124_FILTER_0, 0x060080, AD7124_SIZE_3, AD7124_RW}, /* AD7124_Filter_0 */
{AD7124_FILTER_0, 0x060180, AD7124_SIZE_3, AD7124_RW}, /* AD7124_Filter_0 */
{AD7124_FILTER_1, 0x060180, AD7124_SIZE_3, AD7124_RW}, /* AD7124_Filter_1 */
{AD7124_FILTER_2, 0x060180, AD7124_SIZE_3, AD7124_RW}, /* AD7124_Filter_2 */
{AD7124_FILTER_3, 0x060180, AD7124_SIZE_3, AD7124_RW}, /* AD7124_Filter_3 */

View File

@ -1,37 +0,0 @@
#include "user_gpio.h"
void user_write_gpio(communication_do_t *do_data)
{
uint8_t i = 0;
uint8_t start_addr = do_data->start_addr; // 写输出的起始地址
uint8_t length = do_data->num; // 写输出的数量
for (i = 0; i < length; i++)
{
if (do_data->data[i] == 0x01)
{
gpio_do_test(DO_1 + start_addr + i, GPIO_PIN_SET);
}
else
{
gpio_do_test(DO_1 + start_addr + i, GPIO_PIN_RESET);
}
}
}
void user_read_gpio(communication_di_t *di_data, uint8_t *tx_data, const uint8_t *const rx_data)
{
uint8_t i = 0;
uint8_t start_addr = di_data->start_addr; // 读输入的起始地址
uint8_t length = di_data->num; // 读输入的数量
uint8_t tx_data_len = 7 + length; // 数据长度
tx_data[0] = FRAME_HEAD; // 帧头
tx_data[1] = COM_OK; // 状态
tx_data[2] = rx_data[2]; // 设备号
tx_data[3] = rx_data[3]; // 命令号
tx_data[4] = length; // 数据长度
for (i = 0; i < length; i++)
{
tx_data[5 + i] = gpio_di_test(DI_1 + i + start_addr);
}
tx_data[5 + length] = xor_compute(tx_data + 1, tx_data_len - 3); // 异或校验
tx_data[6 + length] = FRAME_TAIL; // 帧尾
}

View File

@ -1,10 +0,0 @@
#ifndef __USER_GPIO_H__
#define __USER_GPIO_H__
#include "gpio.h"
#include "main.h"
#include "communication_protocol.h"
void user_write_gpio(communication_do_t *do_data);
void user_read_gpio(communication_di_t *di_data, uint8_t *tx_data, const uint8_t *const rx_data);
#endif