代码备份,通讯协议
This commit is contained in:
parent
338fb61743
commit
55e91c55ca
|
@ -38,6 +38,9 @@
|
|||
"freertos.h": "c",
|
||||
"tcp.h": "c",
|
||||
"cmsis_os.h": "c",
|
||||
"freertosconfig.h": "c"
|
||||
"freertosconfig.h": "c",
|
||||
"communication_protocol.h": "c",
|
||||
"user_gpio.h": "c",
|
||||
"user_lib.h": "c"
|
||||
}
|
||||
}
|
|
@ -22,17 +22,18 @@
|
|||
#define __GPIO_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "main.h"
|
||||
|
||||
/* USER CODE BEGIN Includes */
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
/* USER CODE END Includes */
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* USER CODE BEGIN Private defines */
|
||||
/* USER CODE BEGIN Private defines */
|
||||
typedef enum
|
||||
{
|
||||
DI_1,
|
||||
|
@ -46,17 +47,16 @@ extern "C" {
|
|||
DO_EN,
|
||||
DI_DO_MAX,
|
||||
} gpio_e;
|
||||
/* USER CODE END Private defines */
|
||||
/* USER CODE END Private defines */
|
||||
|
||||
void MX_GPIO_Init(void);
|
||||
void MX_GPIO_Init(void);
|
||||
|
||||
/* USER CODE BEGIN Prototypes */
|
||||
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 */
|
||||
/* 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);
|
||||
/* USER CODE END Prototypes */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /*__ GPIO_H__ */
|
||||
|
||||
|
|
|
@ -37,29 +37,29 @@ extern "C"
|
|||
#include "tcpserverc.h"
|
||||
#include "leds.h"
|
||||
#include <string.h>
|
||||
/* USER CODE END Includes */
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* 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_ble1;
|
||||
extern uint8_t tcp_echo_flags_ble2;
|
||||
extern uint8_t tcp_echo_flags_control;
|
||||
/* 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_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];
|
||||
} uart_t;
|
||||
typedef struct
|
||||
{
|
||||
uint16_t rx_num;
|
||||
uint8_t rx_data[512];
|
||||
uint8_t rx_data_temp[512];
|
||||
uint8_t tx_data[512];
|
||||
} uart_t;
|
||||
|
||||
extern uart_t lcd_uart4;
|
||||
extern uart_t ble2_uart3;
|
||||
extern uart_t ble1_uart6;
|
||||
extern uart_t hart1_uart5;
|
||||
extern uart_t hart2_uart2;
|
||||
extern uart_t lcd_uart4;
|
||||
extern uart_t ble2_uart3;
|
||||
extern uart_t ble1_uart6;
|
||||
extern uart_t hart1_uart5;
|
||||
extern uart_t hart2_uart2;
|
||||
#define DEST_IP_ADDR0 192
|
||||
#define DEST_IP_ADDR1 168
|
||||
#define DEST_IP_ADDR2 1
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include "dac161s997.h"
|
||||
#include "ad7124.h"
|
||||
#include "usart.h"
|
||||
#include "communication_protocol.h"
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
|
@ -56,7 +57,7 @@ osThreadId adc_taskHandle;
|
|||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* USER CODE BEGIN FunctionPrototypes */
|
||||
|
||||
extern float current_buff[2];
|
||||
/* USER CODE END FunctionPrototypes */
|
||||
|
||||
void start_tcp_task(void const *argument);
|
||||
|
@ -199,8 +200,9 @@ void start_dac_task(void const *argument)
|
|||
/* Infinite loop */
|
||||
for (;;)
|
||||
{
|
||||
dac161s997_output(DAC161S997_1, 12.0f);
|
||||
dac161s997_output(DAC161S997_2, 12.0f);
|
||||
dac161s997_output(DAC161S997_1, current_buff[0]);
|
||||
dac161s997_output(DAC161S997_2, current_buff[1]);
|
||||
|
||||
vTaskDelay(100);
|
||||
}
|
||||
/* USER CODE END start_dac_task */
|
||||
|
|
|
@ -33,12 +33,12 @@
|
|||
/* USER CODE END 1 */
|
||||
|
||||
/** Configure pins as
|
||||
* Analog
|
||||
* Input
|
||||
* Output
|
||||
* EVENT_OUT
|
||||
* EXTI
|
||||
*/
|
||||
* Analog
|
||||
* Input
|
||||
* Output
|
||||
* EVENT_OUT
|
||||
* EXTI
|
||||
*/
|
||||
void MX_GPIO_Init(void)
|
||||
{
|
||||
|
||||
|
@ -56,15 +56,13 @@ void MX_GPIO_Init(void)
|
|||
HAL_GPIO_WritePin(ETH_RESET_GPIO_Port, ETH_RESET_Pin, GPIO_PIN_SET);
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(GPIOB, LED3_R_Pin|LED3_G_Pin|DAC1_CS_Pin|DAC2_CS_Pin, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(GPIOB, LED3_R_Pin | LED3_G_Pin | DAC1_CS_Pin | DAC2_CS_Pin, GPIO_PIN_SET);
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(GPIOE, LED3_Y_Pin|LED2_R_Pin|LED2_G_Pin|LED2_Y_Pin
|
||||
|ADC_CS_Pin|AD7124_SYNC_Pin, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(GPIOE, LED3_Y_Pin | LED2_R_Pin | LED2_G_Pin | LED2_Y_Pin | ADC_CS_Pin | AD7124_SYNC_Pin, GPIO_PIN_SET);
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(GPIOD, DO_CH4_Pin|DO_CH3_Pin|DO_CH1_Pin|DO_CH2_Pin
|
||||
|DO_EN_Pin|HART1_RTS_Pin|HART2_RTS_Pin, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(GPIOD, DO_CH4_Pin | DO_CH3_Pin | DO_CH1_Pin | DO_CH2_Pin | DO_EN_Pin | HART1_RTS_Pin | HART2_RTS_Pin, GPIO_PIN_SET);
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(HART1_RST_GPIO_Port, HART1_RST_Pin, GPIO_PIN_SET);
|
||||
|
@ -80,35 +78,35 @@ void MX_GPIO_Init(void)
|
|||
HAL_GPIO_Init(ETH_RESET_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pins : PBPin PBPin */
|
||||
GPIO_InitStruct.Pin = LED3_R_Pin|LED3_G_Pin;
|
||||
GPIO_InitStruct.Pin = LED3_R_Pin | LED3_G_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM;
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pins : PEPin PEPin PEPin PEPin */
|
||||
GPIO_InitStruct.Pin = LED3_Y_Pin|LED2_R_Pin|LED2_G_Pin|LED2_Y_Pin;
|
||||
GPIO_InitStruct.Pin = LED3_Y_Pin | LED2_R_Pin | LED2_G_Pin | LED2_Y_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM;
|
||||
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pins : PDPin PDPin PDPin PDPin */
|
||||
GPIO_InitStruct.Pin = DO_CH4_Pin|DO_CH3_Pin|DO_CH1_Pin|DO_CH2_Pin;
|
||||
GPIO_InitStruct.Pin = DO_CH4_Pin | DO_CH3_Pin | DO_CH1_Pin | DO_CH2_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
||||
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pins : PDPin PDPin PDPin PDPin */
|
||||
GPIO_InitStruct.Pin = DO_EN_Pin|HART1_RTS_Pin|HART2_RTS_Pin|HART2_RST_Pin;
|
||||
GPIO_InitStruct.Pin = DO_EN_Pin | HART1_RTS_Pin | HART2_RTS_Pin | HART2_RST_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
||||
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pins : PCPin PCPin */
|
||||
GPIO_InitStruct.Pin = DI_CH1_Pin|DI_CH2_Pin;
|
||||
GPIO_InitStruct.Pin = DI_CH1_Pin | DI_CH2_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
||||
|
@ -121,19 +119,19 @@ void MX_GPIO_Init(void)
|
|||
HAL_GPIO_Init(HART1_RST_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pins : PAPin PAPin */
|
||||
GPIO_InitStruct.Pin = DI_CH3_Pin|DI_CH4_Pin;
|
||||
GPIO_InitStruct.Pin = DI_CH3_Pin | DI_CH4_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pins : PDPin PDPin */
|
||||
GPIO_InitStruct.Pin = HART1_OCD_Pin|HART2_OCD_Pin;
|
||||
GPIO_InitStruct.Pin = HART1_OCD_Pin | HART2_OCD_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pins : PBPin PBPin */
|
||||
GPIO_InitStruct.Pin = DAC1_CS_Pin|DAC2_CS_Pin;
|
||||
GPIO_InitStruct.Pin = DAC1_CS_Pin | DAC2_CS_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
||||
|
@ -159,11 +157,10 @@ void MX_GPIO_Init(void)
|
|||
|
||||
HAL_NVIC_SetPriority(EXTI3_IRQn, 5, 0);
|
||||
HAL_NVIC_EnableIRQ(EXTI3_IRQn);
|
||||
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 2 */
|
||||
void gpio_do_test(gpio_e gpio_num, GPIO_PinState state)
|
||||
void gpio_do_test(uint8_t gpio_num, GPIO_PinState state)
|
||||
{
|
||||
HAL_GPIO_WritePin(DO_EN_GPIO_Port, DO_EN_Pin, GPIO_PIN_RESET);
|
||||
switch (gpio_num)
|
||||
|
@ -185,7 +182,7 @@ void gpio_do_test(gpio_e gpio_num, GPIO_PinState state)
|
|||
}
|
||||
}
|
||||
|
||||
GPIO_PinState gpio_di_test(gpio_e gpio_num)
|
||||
GPIO_PinState gpio_di_test(uint8_t gpio_num)
|
||||
{
|
||||
GPIO_PinState state;
|
||||
switch (gpio_num)
|
||||
|
|
|
@ -148,7 +148,24 @@
|
|||
<Name>-UB -O2254 -SF1800 -C0 -A0 -I0 -HNlocalhost -HP7184 -P1 -N00("ARM CoreSight SW-DP (ARM Core") -D00(2BA01477) -L00(0) -TO131090 -TC10000000 -TT10000000 -TP21 -TDS8000 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO7 -FD20000000 -FC800 -FN1 -FF0STM32F4xx_1024.FLM -FS08000000 -FL0100000 -FP0($$Device:STM32F407VGTx$CMSIS\Flash\STM32F4xx_1024.FLM)</Name>
|
||||
</SetRegEntry>
|
||||
</TargetDriverDllRegistry>
|
||||
<Breakpoint/>
|
||||
<Breakpoint>
|
||||
<Bp>
|
||||
<Number>0</Number>
|
||||
<Type>0</Type>
|
||||
<LineNumber>4</LineNumber>
|
||||
<EnabledFlag>1</EnabledFlag>
|
||||
<Address>0</Address>
|
||||
<ByteObject>0</ByteObject>
|
||||
<HtxType>0</HtxType>
|
||||
<ManyObjects>0</ManyObjects>
|
||||
<SizeOfObject>0</SizeOfObject>
|
||||
<BreakByAccess>0</BreakByAccess>
|
||||
<BreakIfRCount>0</BreakIfRCount>
|
||||
<Filename>../User/application/inc/communication_protocol.h</Filename>
|
||||
<ExecCommand></ExecCommand>
|
||||
<Expression></Expression>
|
||||
</Bp>
|
||||
</Breakpoint>
|
||||
<WatchWindow1>
|
||||
<Ww>
|
||||
<count>0</count>
|
||||
|
@ -213,7 +230,7 @@
|
|||
<Ww>
|
||||
<count>12</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>ad7124_analog,0x10</ItemText>
|
||||
<ItemText>ad7124_analog,0x0A</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>13</count>
|
||||
|
@ -501,7 +518,7 @@
|
|||
|
||||
<Group>
|
||||
<GroupName>Drivers/STM32F4xx_HAL_Driver</GroupName>
|
||||
<tvExp>1</tvExp>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<cbSel>0</cbSel>
|
||||
<RteFlg>0</RteFlg>
|
||||
|
@ -1773,6 +1790,30 @@
|
|||
<RteFlg>0</RteFlg>
|
||||
<bShared>0</bShared>
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>10</GroupNumber>
|
||||
<FileNumber>118</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>1</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\User\application\src\communication_protocol.c</PathWithFileName>
|
||||
<FilenameWithoutPath>communication_protocol.c</FilenameWithoutPath>
|
||||
<RteFlg>0</RteFlg>
|
||||
<bShared>0</bShared>
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>10</GroupNumber>
|
||||
<FileNumber>119</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\User\application\src\user_lib.c</PathWithFileName>
|
||||
<FilenameWithoutPath>user_lib.c</FilenameWithoutPath>
|
||||
<RteFlg>0</RteFlg>
|
||||
<bShared>0</bShared>
|
||||
</File>
|
||||
</Group>
|
||||
|
||||
<Group>
|
||||
|
@ -1783,7 +1824,7 @@
|
|||
<RteFlg>0</RteFlg>
|
||||
<File>
|
||||
<GroupNumber>11</GroupNumber>
|
||||
<FileNumber>118</FileNumber>
|
||||
<FileNumber>120</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -1795,7 +1836,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>11</GroupNumber>
|
||||
<FileNumber>119</FileNumber>
|
||||
<FileNumber>121</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -1807,7 +1848,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>11</GroupNumber>
|
||||
<FileNumber>120</FileNumber>
|
||||
<FileNumber>122</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -1821,13 +1862,13 @@
|
|||
|
||||
<Group>
|
||||
<GroupName>User/system</GroupName>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExp>1</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<cbSel>0</cbSel>
|
||||
<RteFlg>0</RteFlg>
|
||||
<File>
|
||||
<GroupNumber>12</GroupNumber>
|
||||
<FileNumber>121</FileNumber>
|
||||
<FileNumber>123</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -1837,6 +1878,18 @@
|
|||
<RteFlg>0</RteFlg>
|
||||
<bShared>0</bShared>
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>12</GroupNumber>
|
||||
<FileNumber>124</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\User\system\user_gpio.c</PathWithFileName>
|
||||
<FilenameWithoutPath>user_gpio.c</FilenameWithoutPath>
|
||||
<RteFlg>0</RteFlg>
|
||||
<bShared>0</bShared>
|
||||
</File>
|
||||
</Group>
|
||||
|
||||
<Group>
|
||||
|
@ -1847,7 +1900,7 @@
|
|||
<RteFlg>0</RteFlg>
|
||||
<File>
|
||||
<GroupNumber>13</GroupNumber>
|
||||
<FileNumber>122</FileNumber>
|
||||
<FileNumber>125</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -1859,7 +1912,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>13</GroupNumber>
|
||||
<FileNumber>123</FileNumber>
|
||||
<FileNumber>126</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -1871,7 +1924,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>13</GroupNumber>
|
||||
<FileNumber>124</FileNumber>
|
||||
<FileNumber>127</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -1883,7 +1936,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>13</GroupNumber>
|
||||
<FileNumber>125</FileNumber>
|
||||
<FileNumber>128</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -1895,7 +1948,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>13</GroupNumber>
|
||||
<FileNumber>126</FileNumber>
|
||||
<FileNumber>129</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -1907,7 +1960,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>13</GroupNumber>
|
||||
<FileNumber>127</FileNumber>
|
||||
<FileNumber>130</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -1919,7 +1972,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>13</GroupNumber>
|
||||
<FileNumber>128</FileNumber>
|
||||
<FileNumber>131</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -1931,7 +1984,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>13</GroupNumber>
|
||||
<FileNumber>129</FileNumber>
|
||||
<FileNumber>132</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -1943,7 +1996,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>13</GroupNumber>
|
||||
<FileNumber>130</FileNumber>
|
||||
<FileNumber>133</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@ -1955,7 +2008,7 @@
|
|||
</File>
|
||||
<File>
|
||||
<GroupNumber>13</GroupNumber>
|
||||
<FileNumber>131</FileNumber>
|
||||
<FileNumber>134</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
|
|
@ -1523,6 +1523,16 @@
|
|||
<FileType>1</FileType>
|
||||
<FilePath>..\User\application\src\tcpserverc.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>communication_protocol.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\User\application\src\communication_protocol.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>user_lib.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\User\application\src\user_lib.c</FilePath>
|
||||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
<Group>
|
||||
|
@ -1553,6 +1563,11 @@
|
|||
<FileType>1</FileType>
|
||||
<FilePath>..\User\system\user_spi.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>user_gpio.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\User\system\user_gpio.c</FilePath>
|
||||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
<Group>
|
||||
|
|
|
@ -1,190 +0,0 @@
|
|||
<html>
|
||||
<body>
|
||||
<pre>
|
||||
<h1>µVision Build Log</h1>
|
||||
<h2>Tool Versions:</h2>
|
||||
IDE-Version: ¦ÌVision V5.36.0.0
|
||||
Copyright (C) 2021 ARM Ltd and ARM Germany GmbH. All rights reserved.
|
||||
License Information: aaa Administrator, aaa, LIC=6XJT4-F8J98-8YUVV-P833R-DBAKX-Y8EU6
|
||||
|
||||
Tool Versions:
|
||||
Toolchain: MDK-ARM Professional Version: 5.36.0.0
|
||||
Toolchain Path: C:\Keil_v5\ARM\ARMCC\Bin
|
||||
C Compiler: Armcc.exe V5.06 update 7 (build 960)
|
||||
Assembler: Armasm.exe V5.06 update 7 (build 960)
|
||||
Linker/Locator: ArmLink.exe V5.06 update 7 (build 960)
|
||||
Library Manager: ArmAr.exe V5.06 update 7 (build 960)
|
||||
Hex Converter: FromElf.exe V5.06 update 7 (build 960)
|
||||
CPU DLL: SARMCM3.DLL V5.36.0.0
|
||||
Dialog DLL: DCM.DLL V1.17.3.0
|
||||
Target DLL: STLink\ST-LINKIII-KEIL_SWO.dll V3.0.9.0
|
||||
Dialog DLL: TCM.DLL V1.53.0.0
|
||||
|
||||
<h2>Project:</h2>
|
||||
D:\WORK\TEST1\TEST2\MDK-ARM\TEST2.uvprojx
|
||||
Project File Date: 02/10/2025
|
||||
|
||||
<h2>Output:</h2>
|
||||
*** Using Compiler 'V5.06 update 7 (build 960)', folder: 'C:\Keil_v5\ARM\ARMCC\Bin'
|
||||
Build target 'TEST2'
|
||||
assembling startup_stm32f407xx.s...
|
||||
compiling lan8742.c...
|
||||
compiling main.c...
|
||||
compiling stm32f4xx_it.c...
|
||||
compiling spi.c...
|
||||
compiling stm32f4xx_hal_msp.c...
|
||||
compiling stm32f4xx_hal_timebase_tim.c...
|
||||
compiling dma.c...
|
||||
compiling freertos.c...
|
||||
compiling gpio.c...
|
||||
compiling usart.c...
|
||||
compiling tim.c...
|
||||
compiling stm32f4xx_hal_rcc.c...
|
||||
compiling lwip.c...
|
||||
compiling ethernetif.c...
|
||||
compiling stm32f4xx_hal_rcc_ex.c...
|
||||
compiling stm32f4xx_hal_flash.c...
|
||||
compiling stm32f4xx_hal_flash_ramfunc.c...
|
||||
compiling stm32f4xx_hal_flash_ex.c...
|
||||
compiling stm32f4xx_hal_gpio.c...
|
||||
compiling stm32f4xx_hal_pwr.c...
|
||||
compiling stm32f4xx_hal_dma.c...
|
||||
compiling stm32f4xx_hal_dma_ex.c...
|
||||
compiling stm32f4xx_hal_pwr_ex.c...
|
||||
compiling stm32f4xx_hal.c...
|
||||
compiling stm32f4xx_hal_cortex.c...
|
||||
compiling stm32f4xx_hal_exti.c...
|
||||
compiling stm32f4xx_hal_spi.c...
|
||||
compiling stm32f4xx_hal_eth.c...
|
||||
compiling stm32f4xx_hal_tim_ex.c...
|
||||
compiling stm32f4xx_hal_tim.c...
|
||||
compiling stm32f4xx_hal_uart.c...
|
||||
compiling system_stm32f4xx.c...
|
||||
compiling ccp.c...
|
||||
compiling chap_ms.c...
|
||||
compiling auth.c...
|
||||
compiling chap-md5.c...
|
||||
compiling chap-new.c...
|
||||
compiling demand.c...
|
||||
compiling eui64.c...
|
||||
compiling eap.c...
|
||||
compiling fsm.c...
|
||||
compiling ipcp.c...
|
||||
compiling ipv6cp.c...
|
||||
compiling lcp.c...
|
||||
compiling magic.c...
|
||||
compiling mppe.c...
|
||||
compiling ppp.c...
|
||||
compiling multilink.c...
|
||||
compiling pppapi.c...
|
||||
compiling pppoe.c...
|
||||
compiling pppol2tp.c...
|
||||
compiling pppcrypt.c...
|
||||
compiling pppos.c...
|
||||
compiling upap.c...
|
||||
compiling utils.c...
|
||||
compiling vj.c...
|
||||
compiling bridgeif.c...
|
||||
compiling ethernet.c...
|
||||
compiling bridgeif_fdb.c...
|
||||
compiling lowpan6.c...
|
||||
compiling lowpan6_ble.c...
|
||||
compiling lowpan6_common.c...
|
||||
compiling slipif.c...
|
||||
compiling zepif.c...
|
||||
compiling ecp.c...
|
||||
compiling err.c...
|
||||
compiling api_lib.c...
|
||||
compiling netdb.c...
|
||||
compiling api_msg.c...
|
||||
compiling if_api.c...
|
||||
compiling netifapi.c...
|
||||
compiling altcp.c...
|
||||
compiling netbuf.c...
|
||||
compiling tcpip.c...
|
||||
compiling altcp_alloc.c...
|
||||
compiling sockets.c...
|
||||
compiling altcp_tcp.c...
|
||||
compiling def.c...
|
||||
compiling dns.c...
|
||||
compiling init.c...
|
||||
compiling ip.c...
|
||||
compiling inet_chksum.c...
|
||||
compiling memp.c...
|
||||
compiling mem.c...
|
||||
compiling netif.c...
|
||||
compiling raw.c...
|
||||
compiling stats.c...
|
||||
compiling sys.c...
|
||||
compiling pbuf.c...
|
||||
compiling tcp.c...
|
||||
compiling tcp_in.c...
|
||||
compiling timeouts.c...
|
||||
compiling tcp_out.c...
|
||||
compiling udp.c...
|
||||
compiling autoip.c...
|
||||
compiling dhcp.c...
|
||||
compiling igmp.c...
|
||||
compiling etharp.c...
|
||||
compiling icmp.c...
|
||||
compiling ip4.c...
|
||||
compiling ip4_addr.c...
|
||||
compiling dhcp6.c...
|
||||
compiling ip4_frag.c...
|
||||
compiling ethip6.c...
|
||||
compiling icmp6.c...
|
||||
compiling inet6.c...
|
||||
compiling ip6.c...
|
||||
compiling croutine.c...
|
||||
compiling ip6_addr.c...
|
||||
compiling ip6_frag.c...
|
||||
compiling mld6.c...
|
||||
compiling nd6.c...
|
||||
compiling sys_arch.c...
|
||||
compiling leds.c...
|
||||
compiling event_groups.c...
|
||||
compiling tcpclient.c...
|
||||
compiling tcpserverc.c...
|
||||
compiling list.c...
|
||||
compiling dac161s997.c...
|
||||
compiling mqtt.c...
|
||||
compiling stream_buffer.c...
|
||||
compiling queue.c...
|
||||
compiling ht1200m.c...
|
||||
compiling user_spi.c...
|
||||
compiling ad7124.c...
|
||||
compiling timers.c...
|
||||
compiling tasks.c...
|
||||
compiling heap_4.c...
|
||||
compiling cmsis_os.c...
|
||||
compiling port.c...
|
||||
linking...
|
||||
Program Size: Code=85896 RO-data=1388 RW-data=1508 ZI-data=61092
|
||||
"TEST2\TEST2.axf" - 0 Error(s), 0 Warning(s).
|
||||
|
||||
<h2>Software Packages used:</h2>
|
||||
|
||||
Package Vendor: ARM
|
||||
http://www.keil.com/pack/ARM.CMSIS.5.8.0.pack
|
||||
ARM.CMSIS.5.8.0
|
||||
CMSIS (Common Microcontroller Software Interface Standard)
|
||||
* Component: CORE Version: 5.5.0
|
||||
|
||||
Package Vendor: Keil
|
||||
http://www.keil.com/pack/Keil.STM32F4xx_DFP.2.12.0.pack
|
||||
Keil.STM32F4xx_DFP.2.12.0
|
||||
STMicroelectronics STM32F4 Series Device Support, Drivers and Examples
|
||||
|
||||
<h2>Collection of Component include folders:</h2>
|
||||
.\RTE\_TEST2
|
||||
C:\Users\Administrator\AppData\Local\Arm\Packs\ARM\CMSIS\5.8.0\CMSIS\Core\Include
|
||||
C:\Users\Administrator\AppData\Local\Arm\Packs\Keil\STM32F4xx_DFP\2.12.0\Drivers\CMSIS\Device\ST\STM32F4xx\Include
|
||||
|
||||
<h2>Collection of Component Files used:</h2>
|
||||
|
||||
* Component: ARM::CMSIS:CORE:5.5.0
|
||||
Include file: CMSIS\Core\Include\tz_context.h
|
||||
Build Time Elapsed: 00:00:13
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,56 @@
|
|||
#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;
|
||||
|
||||
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;
|
||||
|
||||
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
|
|
@ -0,0 +1,41 @@
|
|||
#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
|
|
@ -0,0 +1,49 @@
|
|||
#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);
|
||||
}
|
|
@ -11,11 +11,21 @@
|
|||
#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;
|
||||
|
@ -117,25 +127,81 @@ static err_t tcpecho_recv_ble2(void *arg, struct tcp_pcb *tpcb, struct pbuf *p,
|
|||
}
|
||||
|
||||
static err_t tcpecho_recv_control(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err)
|
||||
{
|
||||
{
|
||||
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_echo_flags_control = 1;
|
||||
|
||||
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. 对接收的数据做异或校验、帧头帧尾判断,校验失败返回信息,校验通过继续下一步、校验数据从帧头后面到校验位结束*/
|
||||
/*2. 判断所要执行的操作 读或写指令*/
|
||||
/*3. 对要发送的数据进行校验,组包,返回数据*/
|
||||
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);
|
||||
}
|
||||
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) // 读数字量指令
|
||||
{
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
pbuf_free(p);
|
||||
/*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类型的
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
#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;
|
||||
}
|
|
@ -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, 0x960000, AD7124_SIZE_3, AD7124_RW}, /* AD7124_Filter_0 */
|
||||
{AD7124_FILTER_0, 0x060080, 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 */
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
#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(uint8_t *const tx_data, uint8_t *const rx_data, uint16_t length)
|
||||
{
|
||||
uint8_t i = 0;
|
||||
uint8_t start_addr = rx_data[0]; // 读输入的起始地址
|
||||
uint8_t leng = rx_data[1]; // 读输入的数量
|
||||
for (i = 0; i < leng; i++)
|
||||
{
|
||||
tx_data[i] = gpio_di_test(DI_1 + start_addr + i);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
#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(uint8_t *const tx_data, uint8_t *const rx_data, uint16_t length);
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue