chore: Refactor build dependencies
This commit is contained in:
parent
b2c8a832cc
commit
9876edd6ef
|
@ -1,9 +1,6 @@
|
|||
# The following five lines of boilerplate have to be in your project's
|
||||
# CMakeLists in this exact order for cmake to work correctly
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
#set(COMPONENT_DIRS "${IDF_PATH}/components ${PROJECT_PATH}/components")
|
||||
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/main)
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
project(esp8266_dap)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
set(COMPONENT_ADD_INCLUDEDIRS "config include $ENV{IDF_PATH}/components/esp8266/include/esp8266/ $ENV{IDF_PATH}//components/esp_ringbuf/include/")
|
||||
set(COMPONENT_ADD_INCLUDEDIRS "config include $ENV{IDF_PATH}/components/esp8266/include/esp8266/ $ENV{IDF_PATH}/components/esp_ringbuf/include/")
|
||||
set(COMPONENT_SRCS "./source/DAP.c ./source/DAP_vendor.c ./source/JTAG_DP.c ./source/SW_DP.c ./source/SWO.c ./source/uart_modify.c ./source/spi_op.c ./source/spi_switch.c ./source/dap_utility.c")
|
||||
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -2,13 +2,13 @@
|
|||
#define __CMSIS_COMPILER_H__
|
||||
|
||||
#ifndef __STATIC_FORCEINLINE
|
||||
#define __STATIC_FORCEINLINE static inline __attribute__((always_inline))
|
||||
#define __STATIC_FORCEINLINE static inline __attribute__((always_inline))
|
||||
#endif
|
||||
#ifndef __STATIC_INLINE
|
||||
#define __STATIC_INLINE static inline __attribute__((always_inline))
|
||||
#endif
|
||||
#ifndef __FORCEINLINE
|
||||
#define __FORCEINLINE inline __attribute__((always_inline))
|
||||
#define __FORCEINLINE inline __attribute__((always_inline))
|
||||
#endif
|
||||
#ifndef __WEAK
|
||||
#define __WEAK __attribute__((weak))
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include <stdint.h>
|
||||
|
||||
#ifndef __STATIC_FORCEINLINE
|
||||
#define __STATIC_FORCEINLINE static inline __attribute__((always_inline))
|
||||
#define __STATIC_FORCEINLINE static inline __attribute__((always_inline))
|
||||
#endif
|
||||
#ifndef __STATIC_INLINE
|
||||
#define __STATIC_INLINE static inline __attribute__((always_inline))
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
#ifndef __GPIO_OP_H__
|
||||
#define __GPIO_OP_H__
|
||||
|
||||
#include "cmsis_compiler.h"
|
||||
#include "components/DAP/include/cmsis_compiler.h"
|
||||
|
||||
#include "gpio.h"
|
||||
#include "gpio_struct.h"
|
||||
#include "timer_struct.h"
|
||||
|
|
|
@ -27,6 +27,7 @@ extern "C" {
|
|||
|
||||
#include "esp_err.h"
|
||||
#include "esp_log.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/queue.h"
|
||||
#include "freertos/semphr.h"
|
||||
|
||||
|
|
|
@ -26,10 +26,10 @@
|
|||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#include <string.h>
|
||||
#include "DAP_config.h"
|
||||
#include "DAP.h"
|
||||
|
||||
#include "spi_switch.h"
|
||||
#include "components/DAP/config/DAP_config.h"
|
||||
#include "components/DAP/include/DAP.h"
|
||||
#include "components/DAP/include/spi_switch.h"
|
||||
|
||||
|
||||
#if (DAP_PACKET_SIZE < 64U)
|
||||
|
@ -388,6 +388,8 @@ static uint32_t DAP_SWJ_Clock(const uint8_t *request, uint8_t *response) {
|
|||
if (DAP_Data.debug_port != DAP_PORT_JTAG) {
|
||||
DAP_SPI_Init();
|
||||
SWD_TransferSpeed = kTransfer_SPI;
|
||||
} else {
|
||||
SWD_TransferSpeed = kTransfer_GPIO_fast;
|
||||
}
|
||||
DAP_Data.fast_clock = 1U;
|
||||
DAP_Data.clock_delay = 1U;
|
||||
|
|
|
@ -24,18 +24,18 @@
|
|||
* Title: DAP_vendor.c CMSIS-DAP Vendor Commands
|
||||
*
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "DAP_config.h"
|
||||
#include "DAP.h"
|
||||
|
||||
#include "components/DAP/config/DAP_config.h"
|
||||
#include "components/DAP/include/DAP.h"
|
||||
|
||||
//**************************************************************************************************
|
||||
/**
|
||||
/**
|
||||
\defgroup DAP_Vendor_Adapt_gr Adapt Vendor Commands
|
||||
\ingroup DAP_Vendor_gr
|
||||
\ingroup DAP_Vendor_gr
|
||||
@{
|
||||
|
||||
The file DAP_vendor.c provides template source code for extension of a Debug Unit with
|
||||
Vendor Commands. Copy this file to the project folder of the Debug Unit and add the
|
||||
The file DAP_vendor.c provides template source code for extension of a Debug Unit with
|
||||
Vendor Commands. Copy this file to the project folder of the Debug Unit and add the
|
||||
file to the MDK-ARM project under the file group Configuration.
|
||||
*/
|
||||
|
||||
|
|
|
@ -25,8 +25,8 @@
|
|||
*
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "DAP_config.h"
|
||||
#include "DAP.h"
|
||||
#include "components/DAP/config/DAP_config.h"
|
||||
#include "components/DAP/include/DAP.h"
|
||||
|
||||
|
||||
// JTAG Macros
|
||||
|
|
|
@ -38,16 +38,16 @@
|
|||
*
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "DAP_config.h"
|
||||
#include "DAP.h"
|
||||
#include "components/DAP/config/DAP_config.h"
|
||||
#include "components/DAP/include/DAP.h"
|
||||
#include "components/DAP/include/uart_modify.h"
|
||||
#include "components/DAP/include/swo.h"
|
||||
|
||||
#include "esp_err.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/event_groups.h"
|
||||
|
||||
#include "uart_modify.h"
|
||||
#include "swo.h"
|
||||
|
||||
EventGroupHandle_t kSwoThreadEventGroup;
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,6 +1,6 @@
|
|||
#include "dap_utility.h"
|
||||
#include "components/DAP/include/dap_utility.h"
|
||||
|
||||
const uint8_t kParityByteTable[256] =
|
||||
const uint8_t kParityByteTable[256] =
|
||||
{
|
||||
#define P2(n) n, n^1, n^1, n
|
||||
#define P4(n) P2(n), P2(n^1), P2(n^1), P2(n)
|
||||
|
|
|
@ -14,10 +14,13 @@
|
|||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "main/dap_configuration.h"
|
||||
|
||||
#include "components/DAP/include/cmsis_compiler.h"
|
||||
#include "components/DAP/include/spi_op.h"
|
||||
|
||||
#include "esp8266/spi_struct.h"
|
||||
#include "cmsis_compiler.h"
|
||||
#include "spi_op.h"
|
||||
#include "dap_configuration.h"
|
||||
|
||||
|
||||
#define DAP_SPI SPI1
|
||||
|
||||
|
|
|
@ -12,14 +12,13 @@
|
|||
*/
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "components/DAP/include/cmsis_compiler.h"
|
||||
#include "components/DAP/include/spi_switch.h"
|
||||
|
||||
#include "esp8266/spi_struct.h"
|
||||
#include "esp8266/pin_mux_register.h"
|
||||
#include "esp8266/gpio_struct.h"
|
||||
|
||||
#include "cmsis_compiler.h"
|
||||
#include "spi_switch.h"
|
||||
#include "dap_configuration.h"
|
||||
|
||||
|
||||
#define DAP_SPI SPI1
|
||||
|
||||
|
|
|
@ -19,6 +19,11 @@
|
|||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "components/DAP/config/DAP_config.h"
|
||||
#include "components/DAP/include/uart_modify.h"
|
||||
#include "components/DAP/include/swo.h"
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/queue.h"
|
||||
|
@ -26,12 +31,9 @@
|
|||
#include "freertos/ringbuf.h"
|
||||
#include "freertos/event_groups.h"
|
||||
|
||||
#include "esp_err.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_attr.h"
|
||||
|
||||
// SWO modify
|
||||
#include "DAP_config.h"
|
||||
#include "esp8266/uart_struct.h"
|
||||
#include "esp8266/uart_register.h"
|
||||
#include "esp8266/pin_mux_register.h"
|
||||
|
@ -39,9 +41,6 @@
|
|||
#include "esp8266/rom_functions.h"
|
||||
|
||||
#include "rom/ets_sys.h"
|
||||
|
||||
#include "uart_modify.h"
|
||||
#include "swo.h"
|
||||
#include "driver/uart_select.h"
|
||||
|
||||
#define portYIELD_FROM_ISR() taskYIELD()
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
set(COMPONENT_ADD_INCLUDEDIRS ". ../../main")
|
||||
set(COMPONENT_SRCS "MSOS20Descriptors.c USB_handle.c USBd_config.c")
|
||||
set(COMPONENT_SRCS "MSOS20_descriptor.c usb_handle.c usb_descriptor.c")
|
||||
|
||||
register_component()
|
|
@ -1,111 +1,112 @@
|
|||
/**
|
||||
* @file MSOS20Descriptors.c
|
||||
* @author windowsair
|
||||
* @brief Store related data of Microsoft OS 2.0 descriptor
|
||||
* @change: 2021-5-12 Add support for USB 3.0
|
||||
* @version 0.2
|
||||
* @date 2021-5-12
|
||||
*
|
||||
* @copyright Copyright (c) 2021
|
||||
*
|
||||
*/
|
||||
|
||||
////TODO: refactoring into structure
|
||||
|
||||
#include <stdint.h>
|
||||
#include "MSOS20Descriptors.h"
|
||||
|
||||
#define USBShort(ui16Value) ((ui16Value) & 0xff), ((ui16Value) >> 8) //((ui16Value) & 0xFF),(((ui16Value) >> 8) & 0xFF)
|
||||
|
||||
|
||||
|
||||
// Microsoft OS 2.0 descriptor set header
|
||||
const uint8_t msOs20DescriptorSetHeader[kLengthOfMsOS20] =
|
||||
{
|
||||
// Microsoft OS 2.0 Descriptor Set header (Table 10)
|
||||
0x0A, 0x00, // wLength (Shall be set to 0x0A)
|
||||
MS_OS_20_SET_HEADER_DESCRIPTOR, 0x00,
|
||||
0x00, 0x00, 0x03, 0x06, // dwWindowsVersion: Windows 8.1 (NTDDI_WINBLUE)
|
||||
USBShort(kLengthOfMsOS20), // wTotalLength
|
||||
|
||||
// Support WinUSB
|
||||
// See https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/automatic-installation-of-winusb
|
||||
|
||||
// Microsoft OS 2.0 compatible ID descriptor (Table 13)
|
||||
0x14, 0x00, // wLength
|
||||
USBShort(MS_OS_20_FEATURE_COMPATIBLE_ID), // wDescriptorType
|
||||
'W', 'I', 'N', 'U', 'S', 'B', 0x00, 0x00, // compatibleID
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // subCompatibleID
|
||||
|
||||
// Microsoft OS 2.0 registry property descriptor (Table 14)
|
||||
0x84, 0x00, // wLength
|
||||
USBShort(MS_OS_20_FEATURE_REG_PROPERTY),
|
||||
0x07, 0x00, // wPropertyDataType: REG_MULTI_SZ (Unicode Strings)
|
||||
0x2A, 0x00, // wPropertyNameLength
|
||||
'D',0,'e',0,'v',0,'i',0,'c',0,'e',0,'I',0,'n',0,'t',0,'e',0,'r',0,
|
||||
'f',0,'a',0,'c',0,'e',0,'G',0,'U',0,'I',0,'D',0,'s',0,0,0,
|
||||
// Set to "DeviceInterfaceGUID" to support WinUSB
|
||||
0x50, 0x00, // wPropertyDataLength
|
||||
// WinUSB GUID
|
||||
'{',0,'C',0,'D',0,'B',0,'3',0,'B',0,'5',0,'A',0,'D',0,'-',0,
|
||||
'2',0,'9',0,'3',0,'B',0,'-',0,'4',0,'6',0,'6',0,'3',0,'-',0,
|
||||
'A',0,'A',0,'3',0,'6',0,'-',0,'1',0,'A',0,'A',0,'E',0,'4',0,
|
||||
'6',0,'4',0,'6',0,'3',0,'7',0,'7',0,'6',0,'}',0,0,0,0,0,
|
||||
// identify a CMSIS-DAP V2 configuration,
|
||||
// must set to "{CDB3B5AD-293B-4663-AA36-1AAE46463776}"
|
||||
|
||||
};
|
||||
|
||||
const uint8_t bosDescriptor[kLengthOfBos] =
|
||||
{
|
||||
// USB 3.0 Specification, Table 9-9.
|
||||
0x05, // bLength of this descriptor
|
||||
USB_DESCRIPTOR_TYPE_BOS, // BOS Descriptor type(Constant)
|
||||
USBShort(kLengthOfBos), // wLength
|
||||
|
||||
|
||||
#if (USE_USB_3_0 == 1)
|
||||
0x03, // bNumDeviceCaps -> USB2.0 extension & SuperSpeed USB Device & OS2.0 descriptor
|
||||
#else
|
||||
0x01, // bNumDeviceCaps -> only 0x01 for OS2.0 descriptor
|
||||
#endif // USE_USB_3_0 == 1
|
||||
|
||||
#if (USE_USB_3_0 == 1)
|
||||
// USB 2.0 extension, USB 3.0 Specification, Table 9-12.
|
||||
0x07, // bLength of this descriptor
|
||||
USB_DESCRIPTOR_TYPE_DEVICE_CAPABILITY, // DEVICE CAPABILITY Descriptor type
|
||||
USB_DEVICE_CAPABILITY_TYPE_USB2_0_EXTENSION, // Capability type: USB 2.0 EXTENSION
|
||||
0x02, 0x00, 0x00, 0x00, // bmAttributes -> LPM Support
|
||||
|
||||
// SuperSpeed USB Device, USB 3.0 Specification, Table 9-13.
|
||||
0x0A, // bLength of this descriptor
|
||||
USB_DESCRIPTOR_TYPE_DEVICE_CAPABILITY, // DEVICE CAPABILITY Descriptor type
|
||||
USB_DEVICE_CAPABILITY_TYPE_SUPERSPEED_USB, // Capability type: SUPERSPEED_USB
|
||||
0x00, // bmAttributes -> LTM Capable
|
||||
0x08, 0x00, // wSpeedsSupported -> only support SuperSpeed
|
||||
0x03, // bFunctionalitySupport
|
||||
0x00, // bU1DevExitLat -> 0 may be ok
|
||||
0x00, 0x00, // wU2DevExitLat -> 0 may be ok
|
||||
#endif // USE_USB_3_0 == 1
|
||||
|
||||
|
||||
|
||||
// Microsoft OS 2.0 platform capability descriptor header (Table 4)
|
||||
// See also:
|
||||
// USB 3.0 Specification : Format of a Device Capability Descriptor, Table 9-10.
|
||||
|
||||
0x1C, // bLength of this first device capability descriptor
|
||||
// bLength -> The total length of the remaining arrays containing this field
|
||||
USB_DESCRIPTOR_TYPE_DEVICE_CAPABILITY, // bDescriptorType
|
||||
USB_DEVICE_CAPABILITY_TYPE_PLATFORM, // bDevCapabilityType
|
||||
|
||||
// Capability-Dependent (See USB 3.0 Specification Table 9-10.)
|
||||
0x00, // bReserved
|
||||
USB_DEVICE_CAPABILITY_UUID, // MS_OS_20_Platform_Capability_ID
|
||||
|
||||
0x00, 0x00, 0x03, 0x06, // dwWindowsVersion: Windows 8.1 (NTDDI_WINBLUE)
|
||||
USBShort(kLengthOfMsOS20), // wMSOSDescriptorSetTotalLength(length of descriptor set header)
|
||||
kValueOfbMS_VendorCode, // bMS_VendorCode (0x01 will be ok)
|
||||
////TODO:change this
|
||||
0, // bAltEnumCode
|
||||
/**
|
||||
* @file MSOS20_descriptor.c
|
||||
* @author windowsair
|
||||
* @brief Store related data of Microsoft OS 2.0 descriptor
|
||||
* @change: 2021-5-12 Add support for USB 3.0
|
||||
* @version 0.2
|
||||
* @date 2021-5-12
|
||||
*
|
||||
* @copyright Copyright (c) 2021
|
||||
*
|
||||
*/
|
||||
|
||||
////TODO: refactoring into structure
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "components/USBIP/MSOS20_descriptor.h"
|
||||
|
||||
#define USBShort(ui16Value) ((ui16Value) & 0xff), ((ui16Value) >> 8) //((ui16Value) & 0xFF),(((ui16Value) >> 8) & 0xFF)
|
||||
|
||||
|
||||
|
||||
// Microsoft OS 2.0 descriptor set header
|
||||
const uint8_t msOs20DescriptorSetHeader[kLengthOfMsOS20] =
|
||||
{
|
||||
// Microsoft OS 2.0 Descriptor Set header (Table 10)
|
||||
0x0A, 0x00, // wLength (Shall be set to 0x0A)
|
||||
MS_OS_20_SET_HEADER_DESCRIPTOR, 0x00,
|
||||
0x00, 0x00, 0x03, 0x06, // dwWindowsVersion: Windows 8.1 (NTDDI_WINBLUE)
|
||||
USBShort(kLengthOfMsOS20), // wTotalLength
|
||||
|
||||
// Support WinUSB
|
||||
// See https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/automatic-installation-of-winusb
|
||||
|
||||
// Microsoft OS 2.0 compatible ID descriptor (Table 13)
|
||||
0x14, 0x00, // wLength
|
||||
USBShort(MS_OS_20_FEATURE_COMPATIBLE_ID), // wDescriptorType
|
||||
'W', 'I', 'N', 'U', 'S', 'B', 0x00, 0x00, // compatibleID
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // subCompatibleID
|
||||
|
||||
// Microsoft OS 2.0 registry property descriptor (Table 14)
|
||||
0x84, 0x00, // wLength
|
||||
USBShort(MS_OS_20_FEATURE_REG_PROPERTY),
|
||||
0x07, 0x00, // wPropertyDataType: REG_MULTI_SZ (Unicode Strings)
|
||||
0x2A, 0x00, // wPropertyNameLength
|
||||
'D',0,'e',0,'v',0,'i',0,'c',0,'e',0,'I',0,'n',0,'t',0,'e',0,'r',0,
|
||||
'f',0,'a',0,'c',0,'e',0,'G',0,'U',0,'I',0,'D',0,'s',0,0,0,
|
||||
// Set to "DeviceInterfaceGUID" to support WinUSB
|
||||
0x50, 0x00, // wPropertyDataLength
|
||||
// WinUSB GUID
|
||||
'{',0,'C',0,'D',0,'B',0,'3',0,'B',0,'5',0,'A',0,'D',0,'-',0,
|
||||
'2',0,'9',0,'3',0,'B',0,'-',0,'4',0,'6',0,'6',0,'3',0,'-',0,
|
||||
'A',0,'A',0,'3',0,'6',0,'-',0,'1',0,'A',0,'A',0,'E',0,'4',0,
|
||||
'6',0,'4',0,'6',0,'3',0,'7',0,'7',0,'6',0,'}',0,0,0,0,0,
|
||||
// identify a CMSIS-DAP V2 configuration,
|
||||
// must set to "{CDB3B5AD-293B-4663-AA36-1AAE46463776}"
|
||||
|
||||
};
|
||||
|
||||
const uint8_t bosDescriptor[kLengthOfBos] =
|
||||
{
|
||||
// USB 3.0 Specification, Table 9-9.
|
||||
0x05, // bLength of this descriptor
|
||||
USB_DESCRIPTOR_TYPE_BOS, // BOS Descriptor type(Constant)
|
||||
USBShort(kLengthOfBos), // wLength
|
||||
|
||||
|
||||
#if (USE_USB_3_0 == 1)
|
||||
0x03, // bNumDeviceCaps -> USB2.0 extension & SuperSpeed USB Device & OS2.0 descriptor
|
||||
#else
|
||||
0x01, // bNumDeviceCaps -> only 0x01 for OS2.0 descriptor
|
||||
#endif // USE_USB_3_0 == 1
|
||||
|
||||
#if (USE_USB_3_0 == 1)
|
||||
// USB 2.0 extension, USB 3.0 Specification, Table 9-12.
|
||||
0x07, // bLength of this descriptor
|
||||
USB_DESCRIPTOR_TYPE_DEVICE_CAPABILITY, // DEVICE CAPABILITY Descriptor type
|
||||
USB_DEVICE_CAPABILITY_TYPE_USB2_0_EXTENSION, // Capability type: USB 2.0 EXTENSION
|
||||
0x02, 0x00, 0x00, 0x00, // bmAttributes -> LPM Support
|
||||
|
||||
// SuperSpeed USB Device, USB 3.0 Specification, Table 9-13.
|
||||
0x0A, // bLength of this descriptor
|
||||
USB_DESCRIPTOR_TYPE_DEVICE_CAPABILITY, // DEVICE CAPABILITY Descriptor type
|
||||
USB_DEVICE_CAPABILITY_TYPE_SUPERSPEED_USB, // Capability type: SUPERSPEED_USB
|
||||
0x00, // bmAttributes -> LTM Capable
|
||||
0x08, 0x00, // wSpeedsSupported -> only support SuperSpeed
|
||||
0x03, // bFunctionalitySupport
|
||||
0x00, // bU1DevExitLat -> 0 may be ok
|
||||
0x00, 0x00, // wU2DevExitLat -> 0 may be ok
|
||||
#endif // USE_USB_3_0 == 1
|
||||
|
||||
|
||||
|
||||
// Microsoft OS 2.0 platform capability descriptor header (Table 4)
|
||||
// See also:
|
||||
// USB 3.0 Specification : Format of a Device Capability Descriptor, Table 9-10.
|
||||
|
||||
0x1C, // bLength of this first device capability descriptor
|
||||
// bLength -> The total length of the remaining arrays containing this field
|
||||
USB_DESCRIPTOR_TYPE_DEVICE_CAPABILITY, // bDescriptorType
|
||||
USB_DEVICE_CAPABILITY_TYPE_PLATFORM, // bDevCapabilityType
|
||||
|
||||
// Capability-Dependent (See USB 3.0 Specification Table 9-10.)
|
||||
0x00, // bReserved
|
||||
USB_DEVICE_CAPABILITY_UUID, // MS_OS_20_Platform_Capability_ID
|
||||
|
||||
0x00, 0x00, 0x03, 0x06, // dwWindowsVersion: Windows 8.1 (NTDDI_WINBLUE)
|
||||
USBShort(kLengthOfMsOS20), // wMSOSDescriptorSetTotalLength(length of descriptor set header)
|
||||
kValueOfbMS_VendorCode, // bMS_VendorCode (0x01 will be ok)
|
||||
////TODO:change this
|
||||
0, // bAltEnumCode
|
||||
};
|
|
@ -1,94 +1,93 @@
|
|||
/**
|
||||
* @file MSOS20Descriptors.h
|
||||
* @author windowsair
|
||||
* @brief
|
||||
* @version 0.2
|
||||
* @date 2021-5-12
|
||||
*
|
||||
* @copyright Copyright (c) 2021
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __MSOS20DESCRIPTORS_H__
|
||||
#define __MSOS20DESCRIPTORS_H__
|
||||
|
||||
#include "dap_configuration.h"
|
||||
|
||||
#define kLengthOfMsOS20 0xA2
|
||||
|
||||
#if (USE_USB_3_0 == 1)
|
||||
#define kLengthOfBos 0x32
|
||||
#else
|
||||
#define kLengthOfBos 0x21
|
||||
#endif // USE_USB_3_0 == 1
|
||||
|
||||
#define kValueOfbMS_VendorCode 0x01// Just set to 0x01
|
||||
extern const uint8_t bosDescriptor[kLengthOfBos];
|
||||
extern const uint8_t msOs20DescriptorSetHeader[kLengthOfMsOS20];
|
||||
|
||||
/* Microsoft OS 2.0 Descriptors BEGIN */
|
||||
|
||||
// Platform capability BOS descriptor, Table 1.
|
||||
#define USB_DEVICE_CAPABILITY_TYPE_PLATFORM 5
|
||||
|
||||
// USB 2.0 Extension Descriptor, USB3.0 Specification Table 9-11
|
||||
#define USB_DEVICE_CAPABILITY_TYPE_USB2_0_EXTENSION 2
|
||||
// SuperSpeed USB specific device level capabilities, USB3.0 Specification Table 9-11
|
||||
#define USB_DEVICE_CAPABILITY_TYPE_SUPERSPEED_USB 3
|
||||
|
||||
// Platform capability UUID, Table 3.
|
||||
// {D8DD60DF-4589-4CC7-9CD2-659D9E648A9F}
|
||||
#define USB_DEVICE_CAPABILITY_UUID 0xDF, 0x60, 0xDD, 0xD8, 0x89, 0x45, 0xC7, 0x4C, 0x9C, 0xD2, 0x65, 0x9D, 0x9E, 0x64, 0x8A, 0x9F
|
||||
|
||||
|
||||
// Microsoft OS 2.0 descriptor wIndex values enum, Table 8.
|
||||
#define MS_OS_20_DESCRIPTOR_INDEX 7
|
||||
#define MS_OS_20_SET_ALT_ENUMERATION 8
|
||||
|
||||
|
||||
// Microsoft OS 2.0 descriptor types enum for wDescriptorType values, Table 9.
|
||||
#define MS_OS_20_SET_HEADER_DESCRIPTOR 0x00
|
||||
#define MS_OS_20_SUBSET_HEADER_CONFIGURATION 0x01
|
||||
#define MS_OS_20_SUBSET_HEADER_FUNCTION 0x02
|
||||
#define MS_OS_20_FEATURE_COMPATIBLE_ID 0x03
|
||||
#define MS_OS_20_FEATURE_REG_PROPERTY 0x04
|
||||
#define MS_OS_20_FEATURE_MIN_RESUME_TIME 0x05
|
||||
#define MS_OS_20_FEATURE_MODEL_ID 0x06
|
||||
#define MS_OS_20_FEATURE_CCGP_DEVICE 0x07
|
||||
|
||||
/* Microsoft OS 2.0 Descriptors END */
|
||||
|
||||
|
||||
|
||||
/* Wireless USB Standard Extension Descriptor Types BEGIN */
|
||||
|
||||
// Wireless USB Specification 1.1 revison 1.1, Table 7-21.
|
||||
#define USB_DESCRIPTOR_TYPE_SECURITY 12
|
||||
#define USB_DESCRIPTOR_TYPE_KEY 13
|
||||
#define USB_DESCRIPTOR_TYPE_ENCRYPTION_TYPE 14
|
||||
#define USB_DESCRIPTOR_TYPE_BOS 15
|
||||
#define USB_DESCRIPTOR_TYPE_DEVICE_CAPABILITY 16
|
||||
#define USB_DESCRIPTOR_TYPE_WIRELESS_ENDPOINT_COMPANION 17
|
||||
|
||||
/* Wireless USB Standard Extension Descriptor Types END */
|
||||
|
||||
|
||||
/* Microsoft Extended Compat ID OS Feature Descriptor BEGIN */
|
||||
|
||||
#define USB_MS_EXTENDED_COMPAT_ID_VERSION 0x0100
|
||||
#define USB_MS_EXTENDED_COMPAT_ID_TYPE 0x04
|
||||
|
||||
#define USB_COMPATID_NONE {0}
|
||||
#define USB_SUBCOMPATID_NONE {0}
|
||||
#define USB_COMPATID_WINUSB "WINUSB\0"
|
||||
#define USB_COMPATID_RNDIS "RNDIS\0\0"
|
||||
#define USB_COMPATID_PTP "PTP\0\0\0\0"
|
||||
#define USB_COMPATID_MTP "MTP\0\0\0\0"
|
||||
#define USB_COMPATID_BLUETOOTH "BLUTUTH"
|
||||
#define USB_SUBCOMPATID_BT_V11 "11\0\0\0\0\0"
|
||||
#define USB_SUBCOMPATID_BT_V12 "12\0\0\0\0\0"
|
||||
#define USB_SUBCOMPATID_BT_V20EDR "EDR\0\0\0\0"
|
||||
|
||||
/* Microsoft Extended Compat ID OS Feature Descriptor END */
|
||||
|
||||
/**
|
||||
* @file MSOS20_descriptor.h
|
||||
* @author windowsair
|
||||
* @brief
|
||||
* @version 0.2
|
||||
* @date 2021-5-12
|
||||
*
|
||||
* @copyright Copyright (c) 2021
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __MSOS20_DESCRIPTOR_H__
|
||||
#define __MSOS20_DESCRIPTOR_H__
|
||||
|
||||
|
||||
#define kLengthOfMsOS20 0xA2
|
||||
|
||||
#if (USE_USB_3_0 == 1)
|
||||
#define kLengthOfBos 0x32
|
||||
#else
|
||||
#define kLengthOfBos 0x21
|
||||
#endif // USE_USB_3_0 == 1
|
||||
|
||||
#define kValueOfbMS_VendorCode 0x01// Just set to 0x01
|
||||
extern const uint8_t bosDescriptor[kLengthOfBos];
|
||||
extern const uint8_t msOs20DescriptorSetHeader[kLengthOfMsOS20];
|
||||
|
||||
/* Microsoft OS 2.0 Descriptors BEGIN */
|
||||
|
||||
// Platform capability BOS descriptor, Table 1.
|
||||
#define USB_DEVICE_CAPABILITY_TYPE_PLATFORM 5
|
||||
|
||||
// USB 2.0 Extension Descriptor, USB3.0 Specification Table 9-11
|
||||
#define USB_DEVICE_CAPABILITY_TYPE_USB2_0_EXTENSION 2
|
||||
// SuperSpeed USB specific device level capabilities, USB3.0 Specification Table 9-11
|
||||
#define USB_DEVICE_CAPABILITY_TYPE_SUPERSPEED_USB 3
|
||||
|
||||
// Platform capability UUID, Table 3.
|
||||
// {D8DD60DF-4589-4CC7-9CD2-659D9E648A9F}
|
||||
#define USB_DEVICE_CAPABILITY_UUID 0xDF, 0x60, 0xDD, 0xD8, 0x89, 0x45, 0xC7, 0x4C, 0x9C, 0xD2, 0x65, 0x9D, 0x9E, 0x64, 0x8A, 0x9F
|
||||
|
||||
|
||||
// Microsoft OS 2.0 descriptor wIndex values enum, Table 8.
|
||||
#define MS_OS_20_DESCRIPTOR_INDEX 7
|
||||
#define MS_OS_20_SET_ALT_ENUMERATION 8
|
||||
|
||||
|
||||
// Microsoft OS 2.0 descriptor types enum for wDescriptorType values, Table 9.
|
||||
#define MS_OS_20_SET_HEADER_DESCRIPTOR 0x00
|
||||
#define MS_OS_20_SUBSET_HEADER_CONFIGURATION 0x01
|
||||
#define MS_OS_20_SUBSET_HEADER_FUNCTION 0x02
|
||||
#define MS_OS_20_FEATURE_COMPATIBLE_ID 0x03
|
||||
#define MS_OS_20_FEATURE_REG_PROPERTY 0x04
|
||||
#define MS_OS_20_FEATURE_MIN_RESUME_TIME 0x05
|
||||
#define MS_OS_20_FEATURE_MODEL_ID 0x06
|
||||
#define MS_OS_20_FEATURE_CCGP_DEVICE 0x07
|
||||
|
||||
/* Microsoft OS 2.0 Descriptors END */
|
||||
|
||||
|
||||
|
||||
/* Wireless USB Standard Extension Descriptor Types BEGIN */
|
||||
|
||||
// Wireless USB Specification 1.1 revison 1.1, Table 7-21.
|
||||
#define USB_DESCRIPTOR_TYPE_SECURITY 12
|
||||
#define USB_DESCRIPTOR_TYPE_KEY 13
|
||||
#define USB_DESCRIPTOR_TYPE_ENCRYPTION_TYPE 14
|
||||
#define USB_DESCRIPTOR_TYPE_BOS 15
|
||||
#define USB_DESCRIPTOR_TYPE_DEVICE_CAPABILITY 16
|
||||
#define USB_DESCRIPTOR_TYPE_WIRELESS_ENDPOINT_COMPANION 17
|
||||
|
||||
/* Wireless USB Standard Extension Descriptor Types END */
|
||||
|
||||
|
||||
/* Microsoft Extended Compat ID OS Feature Descriptor BEGIN */
|
||||
|
||||
#define USB_MS_EXTENDED_COMPAT_ID_VERSION 0x0100
|
||||
#define USB_MS_EXTENDED_COMPAT_ID_TYPE 0x04
|
||||
|
||||
#define USB_COMPATID_NONE {0}
|
||||
#define USB_SUBCOMPATID_NONE {0}
|
||||
#define USB_COMPATID_WINUSB "WINUSB\0"
|
||||
#define USB_COMPATID_RNDIS "RNDIS\0\0"
|
||||
#define USB_COMPATID_PTP "PTP\0\0\0\0"
|
||||
#define USB_COMPATID_MTP "MTP\0\0\0\0"
|
||||
#define USB_COMPATID_BLUETOOTH "BLUTUTH"
|
||||
#define USB_SUBCOMPATID_BT_V11 "11\0\0\0\0\0"
|
||||
#define USB_SUBCOMPATID_BT_V12 "12\0\0\0\0\0"
|
||||
#define USB_SUBCOMPATID_BT_V20EDR "EDR\0\0\0\0"
|
||||
|
||||
/* Microsoft Extended Compat ID OS Feature Descriptor END */
|
||||
|
||||
#endif
|
|
@ -1,6 +1,6 @@
|
|||
////TODO: refactoring into structure
|
||||
/**
|
||||
* @file USBd_config.c
|
||||
* @file usb_descriptor.c
|
||||
* @brief Standard USB Descriptor Definitions
|
||||
* @change: 2020-1-23 : fix bugs
|
||||
* 2021-5-12 : Add support for USB 3.0
|
||||
|
@ -11,8 +11,9 @@
|
|||
*/
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "USBd_config.h"
|
||||
#include "usb_defs.h"
|
||||
|
||||
#include "components/USBIP/usb_descriptor.h"
|
||||
#include "components/USBIP/usb_defs.h"
|
||||
|
||||
#define USBShort(ui16Value) ((ui16Value) & 0xff), ((ui16Value) >> 8)
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef __USBD_CONFIG_H__
|
||||
#define __USBD_CONFIG_H__
|
||||
#ifndef __USB_DESCRIPTOR_H__
|
||||
#define __USB_DESCRIPTOR_H__
|
||||
|
||||
#include "dap_configuration.h"
|
||||
#include "main/dap_configuration.h"
|
||||
|
||||
// Vendor ID assigned by USB-IF (idVendor).
|
||||
#define USBD0_DEV_DESC_IDVENDOR 0xC251
|
|
@ -3,21 +3,23 @@
|
|||
* @brief Handle all Standard Device Requests on endpoint 0
|
||||
* @version 0.1
|
||||
* @date 2020-01-23
|
||||
*
|
||||
*
|
||||
* @copyright Copyright (c) 2020
|
||||
*
|
||||
*
|
||||
*/
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "main/usbip_server.h"
|
||||
|
||||
#include "components/USBIP/usb_handle.h"
|
||||
#include "components/USBIP/usb_descriptor.h"
|
||||
#include "components/USBIP/MSOS20_descriptor.h"
|
||||
|
||||
#include "lwip/err.h"
|
||||
#include "lwip/sockets.h"
|
||||
#include "lwip/sys.h"
|
||||
#include <lwip/netdb.h>
|
||||
#include "USB_handle.h"
|
||||
#include "USBd_config.h"
|
||||
#include "usbip_server.h"
|
||||
#include "usb_defs.h"
|
||||
#include "MSOS20Descriptors.h"
|
||||
|
||||
|
||||
const char *strings_list[] = {
|
||||
|
@ -263,7 +265,7 @@ static void handleGetDescriptor(usbip_stage2_header *header)
|
|||
for (int i = 0; i < slen; i++)
|
||||
{
|
||||
desc->wData[i] = strings_list[header->u.cmd_submit.request.wValue.u8lo][i];
|
||||
|
||||
|
||||
}
|
||||
send_stage2_submit_data(header, 0, (uint8_t *)temp_buff, buff_len);
|
||||
}
|
|
@ -1,7 +1,8 @@
|
|||
#ifndef __USB_HANDLE_H__
|
||||
#define __USB_HANDLE_H__
|
||||
|
||||
#include "usbip_defs.h"
|
||||
#include "components/USBIP/usbip_defs.h"
|
||||
|
||||
void handleUSBControlRequest(usbip_stage2_header *header);
|
||||
|
||||
#endif
|
|
@ -3,9 +3,9 @@
|
|||
* @brief Simple modification
|
||||
* @version 0.1
|
||||
* @date 2020-01-22
|
||||
*
|
||||
*
|
||||
* @copyright Copyright (c) 2020
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
// Focus on the following structures in this file:
|
||||
|
@ -20,7 +20,8 @@
|
|||
#define __USBIP_DEFS_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include "usb_defs.h"
|
||||
|
||||
#include "components/USBIP/usb_defs.h"
|
||||
|
||||
#define USBIP_SYSFS_PATH_SIZE 256
|
||||
#define USBIP_BUSID_SIZE 32
|
||||
|
@ -33,7 +34,7 @@ enum usbip_stage1_command
|
|||
};
|
||||
|
||||
enum usbip_stager2_command
|
||||
{
|
||||
{
|
||||
//Offset 0
|
||||
USBIP_STAGE2_REQ_SUBMIT = 0x0001,
|
||||
USBIP_STAGE2_REQ_UNLINK = 0x0002,
|
||||
|
@ -106,7 +107,7 @@ typedef struct
|
|||
/**
|
||||
* struct usbip_header_basic - data pertinent to every URB request
|
||||
* RESPONSE & REQUEST
|
||||
*
|
||||
*
|
||||
* @command: the usbip request type
|
||||
* @seqnum: sequential number that identifies requests; incremented per
|
||||
* connection
|
||||
|
@ -127,7 +128,7 @@ typedef struct
|
|||
/**
|
||||
* struct usbip_header_cmd_submit - USBIP_CMD_SUBMIT packet header
|
||||
* >>>REQUEST
|
||||
*
|
||||
*
|
||||
* @transfer_flags: URB flags
|
||||
* @transfer_buffer_length: the data size for (in) or (out) transfer
|
||||
* @start_frame: initial frame for isochronous or interrupt transfers
|
||||
|
@ -154,7 +155,7 @@ typedef struct
|
|||
/**
|
||||
* struct usbip_header_ret_submit - USBIP_RET_SUBMIT packet header
|
||||
* <<<RESPONSE
|
||||
*
|
||||
*
|
||||
* @status: return status of a non-iso request
|
||||
* @actual_length: number of bytes transferred
|
||||
* @start_frame: initial frame for isochronous or interrupt transfers
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
set(COMPONENT_ADD_INCLUDEDIRS ". $ENV{IDF_PATH}/components/esp8266/include/esp8266/ ../components/USBIP")
|
||||
set(COMPONENT_ADD_INCLUDEDIRS "${PROJECT_PATH}")
|
||||
set(COMPONENT_SRCS "main.c timer.c tcp_server.c usbip_server.c DAP_handle.c")
|
||||
|
||||
register_component()
|
||||
|
|
|
@ -1,268 +1,268 @@
|
|||
/**
|
||||
* @file DAP_handle.c
|
||||
* @brief Handle DAP packets and transaction push
|
||||
* @version 0.4
|
||||
* @change: 2020.02.04 first version
|
||||
* 2020.11.11 support WinUSB mode
|
||||
* 2021.02.17 support SWO
|
||||
*
|
||||
* @copyright Copyright (c) 2021
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "usbip_server.h"
|
||||
#include "DAP_handle.h"
|
||||
#include "DAP.h"
|
||||
#include "esp_libc.h"
|
||||
#include "USBd_config.h"
|
||||
#include "swo.h"
|
||||
#include "dap_configuration.h"
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/ringbuf.h"
|
||||
#include "freertos/semphr.h"
|
||||
|
||||
#include "lwip/err.h"
|
||||
#include "lwip/sockets.h"
|
||||
#include "lwip/sys.h"
|
||||
#include <lwip/netdb.h>
|
||||
|
||||
#if (USE_WINUSB == 1)
|
||||
typedef struct
|
||||
{
|
||||
uint32_t length;
|
||||
uint8_t buf[DAP_PACKET_SIZE];
|
||||
} DapPacket_t;
|
||||
#else
|
||||
typedef struct
|
||||
{
|
||||
uint8_t buf[DAP_PACKET_SIZE];
|
||||
} DapPacket_t;
|
||||
#endif
|
||||
|
||||
#define DAP_HANDLE_SIZE (sizeof(DapPacket_t))
|
||||
|
||||
|
||||
extern int kSock;
|
||||
extern TaskHandle_t kDAPTaskHandle;
|
||||
|
||||
int kRestartDAPHandle = 0;
|
||||
|
||||
|
||||
static DapPacket_t DAPDataProcessed;
|
||||
static int dap_respond = 0;
|
||||
|
||||
// SWO Trace
|
||||
static uint8_t *swo_data_to_send = NULL;
|
||||
static uint32_t swo_data_num;
|
||||
|
||||
// DAP handle
|
||||
static RingbufHandle_t dap_dataIN_handle = NULL;
|
||||
static RingbufHandle_t dap_dataOUT_handle = NULL;
|
||||
static SemaphoreHandle_t data_response_mux = NULL;
|
||||
|
||||
|
||||
void handle_dap_data_request(usbip_stage2_header *header, uint32_t length)
|
||||
{
|
||||
uint8_t *data_in = (uint8_t *)header;
|
||||
data_in = &(data_in[sizeof(usbip_stage2_header)]);
|
||||
// Point to the beginning of the URB packet
|
||||
|
||||
#if (USE_WINUSB == 1)
|
||||
send_stage2_submit(header, 0, 0);
|
||||
|
||||
// always send constant size buf -> cuz we don't care about the IN packet size
|
||||
// and to unify the style, we set aside the length of the section
|
||||
xRingbufferSend(dap_dataIN_handle, data_in - sizeof(uint32_t), DAP_HANDLE_SIZE, portMAX_DELAY);
|
||||
xTaskNotifyGive(kDAPTaskHandle);
|
||||
|
||||
#else
|
||||
send_stage2_submit(header, 0, 0);
|
||||
|
||||
xRingbufferSend(dap_dataIN_handle, data_in, DAP_HANDLE_SIZE, portMAX_DELAY);
|
||||
xTaskNotifyGive(kDAPTaskHandle);
|
||||
|
||||
#endif
|
||||
|
||||
// dap_respond = DAP_ProcessCommand((uint8_t *)data_in, (uint8_t *)data_out);
|
||||
// //handle_dap_data_response(header);
|
||||
// send_stage2_submit(header, 0, 0);
|
||||
}
|
||||
|
||||
void handle_dap_data_response(usbip_stage2_header *header)
|
||||
{
|
||||
return;
|
||||
// int resLength = dap_respond & 0xFFFF;
|
||||
// if (resLength)
|
||||
// {
|
||||
|
||||
// send_stage2_submit_data(header, 0, (void *)DAPDataProcessed.buf, resLength);
|
||||
// dap_respond = 0;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// send_stage2_submit(header, 0, 0);
|
||||
// }
|
||||
}
|
||||
|
||||
void handle_swo_trace_response(usbip_stage2_header *header)
|
||||
{
|
||||
#if (SWO_FUNCTION_ENABLE == 1)
|
||||
if (kSwoTransferBusy)
|
||||
{
|
||||
// busy indicates that there is data to be send
|
||||
printf("swo use data\r\n");
|
||||
send_stage2_submit_data(header, 0, (void *)swo_data_to_send, swo_data_num);
|
||||
SWO_TransferComplete();
|
||||
}
|
||||
else
|
||||
{
|
||||
// nothing to send.
|
||||
send_stage2_submit(header, 0, 0);
|
||||
}
|
||||
#else
|
||||
send_stage2_submit(header, 0, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
// SWO Data Queue Transfer
|
||||
// buf: pointer to buffer with data
|
||||
// num: number of bytes to transfer
|
||||
void SWO_QueueTransfer(uint8_t *buf, uint32_t num)
|
||||
{
|
||||
swo_data_to_send = buf;
|
||||
swo_data_num = num;
|
||||
}
|
||||
|
||||
void DAP_Thread(void *argument)
|
||||
{
|
||||
dap_dataIN_handle = xRingbufferCreate(DAP_HANDLE_SIZE * 20, RINGBUF_TYPE_BYTEBUF);
|
||||
dap_dataOUT_handle = xRingbufferCreate(DAP_HANDLE_SIZE * 20, RINGBUF_TYPE_BYTEBUF);
|
||||
data_response_mux = xSemaphoreCreateMutex();
|
||||
size_t packetSize;
|
||||
int resLength;
|
||||
DapPacket_t *item;
|
||||
|
||||
if (dap_dataIN_handle == NULL || dap_dataIN_handle == NULL ||
|
||||
data_response_mux == NULL)
|
||||
{
|
||||
os_printf("Can not create DAP ringbuf/mux!\r\n");
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
for (;;)
|
||||
{
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (kRestartDAPHandle)
|
||||
{
|
||||
vRingbufferDelete(dap_dataIN_handle);
|
||||
vRingbufferDelete(dap_dataOUT_handle);
|
||||
dap_dataIN_handle = dap_dataOUT_handle = NULL;
|
||||
|
||||
dap_dataIN_handle = xRingbufferCreate(DAP_HANDLE_SIZE * 20, RINGBUF_TYPE_BYTEBUF);
|
||||
dap_dataOUT_handle = xRingbufferCreate(DAP_HANDLE_SIZE * 20, RINGBUF_TYPE_BYTEBUF);
|
||||
if (dap_dataIN_handle == NULL || dap_dataIN_handle == NULL)
|
||||
{
|
||||
os_printf("Can not create DAP ringbuf/mux!\r\n");
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
kRestartDAPHandle = 0;
|
||||
}
|
||||
|
||||
ulTaskNotifyTake(pdFALSE, portMAX_DELAY);
|
||||
packetSize = 0;
|
||||
item = (DapPacket_t *)xRingbufferReceiveUpTo(dap_dataIN_handle, &packetSize,
|
||||
pdMS_TO_TICKS(1), DAP_HANDLE_SIZE);
|
||||
if (packetSize == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
else if (packetSize < DAP_HANDLE_SIZE)
|
||||
{
|
||||
os_printf("Wrong data in packet size:%d , data in remain: %d\r\n", packetSize, (int)xRingbufferGetMaxItemSize(dap_dataIN_handle));
|
||||
vRingbufferReturnItem(dap_dataIN_handle, (void *)item);
|
||||
break;
|
||||
// This may not happen because there is a semaphore acquisition
|
||||
}
|
||||
|
||||
if (item->buf[0] == ID_DAP_QueueCommands)
|
||||
{
|
||||
item->buf[0] = ID_DAP_ExecuteCommands;
|
||||
}
|
||||
|
||||
resLength = DAP_ProcessCommand((uint8_t *)item->buf, (uint8_t *)DAPDataProcessed.buf); // use first 4 byte to save length
|
||||
resLength &= 0xFFFF; // res length in lower 16 bits
|
||||
|
||||
vRingbufferReturnItem(dap_dataIN_handle, (void *)item); // process done.
|
||||
|
||||
// now prepare to reply
|
||||
#if (USE_WINUSB == 1)
|
||||
DAPDataProcessed.length = resLength;
|
||||
#endif
|
||||
xRingbufferSend(dap_dataOUT_handle, (void *)&DAPDataProcessed, DAP_HANDLE_SIZE, portMAX_DELAY);
|
||||
|
||||
if (xSemaphoreTake(data_response_mux, portMAX_DELAY) == pdTRUE)
|
||||
{
|
||||
++dap_respond;
|
||||
xSemaphoreGive(data_response_mux);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int fast_reply(uint8_t *buf, uint32_t length)
|
||||
{
|
||||
usbip_stage2_header *buf_header = (usbip_stage2_header *)buf;
|
||||
if (length == 48 &&
|
||||
buf_header->base.command == PP_HTONL(USBIP_STAGE2_REQ_SUBMIT) &&
|
||||
buf_header->base.direction == PP_HTONL(USBIP_DIR_IN) &&
|
||||
buf_header->base.ep == PP_HTONL(1))
|
||||
{
|
||||
if (dap_respond > 0)
|
||||
{
|
||||
DapPacket_t *item;
|
||||
size_t packetSize = 0;
|
||||
item = (DapPacket_t *)xRingbufferReceiveUpTo(dap_dataOUT_handle, &packetSize,
|
||||
pdMS_TO_TICKS(10), DAP_HANDLE_SIZE);
|
||||
if (packetSize == DAP_HANDLE_SIZE)
|
||||
{
|
||||
#if (USE_WINUSB == 1)
|
||||
send_stage2_submit_data_fast((usbip_stage2_header *)buf, item->buf, item->length);
|
||||
#else
|
||||
send_stage2_submit_data_fast((usbip_stage2_header *)buf, item->buf, DAP_HANDLE_SIZE);
|
||||
#endif
|
||||
|
||||
if (xSemaphoreTake(data_response_mux, portMAX_DELAY) == pdTRUE)
|
||||
{
|
||||
--dap_respond;
|
||||
xSemaphoreGive(data_response_mux);
|
||||
}
|
||||
|
||||
vRingbufferReturnItem(dap_dataOUT_handle, (void *)item);
|
||||
return 1;
|
||||
}
|
||||
else if (packetSize > 0)
|
||||
{
|
||||
os_printf("Wrong data out packet size:%d!\r\n", packetSize);
|
||||
}
|
||||
////TODO: fast reply
|
||||
}
|
||||
else
|
||||
{
|
||||
buf_header->base.command = PP_HTONL(USBIP_STAGE2_RSP_SUBMIT);
|
||||
buf_header->base.direction = PP_HTONL(USBIP_DIR_OUT);
|
||||
buf_header->u.ret_submit.status = 0;
|
||||
buf_header->u.ret_submit.data_length = 0;
|
||||
buf_header->u.ret_submit.error_count = 0;
|
||||
send(kSock, buf, 48, 0);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/**
|
||||
* @file DAP_handle.c
|
||||
* @brief Handle DAP packets and transaction push
|
||||
* @version 0.4
|
||||
* @change: 2020.02.04 first version
|
||||
* 2020.11.11 support WinUSB mode
|
||||
* 2021.02.17 support SWO
|
||||
*
|
||||
* @copyright Copyright (c) 2021
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "main/usbip_server.h"
|
||||
#include "main/DAP_handle.h"
|
||||
#include "main/dap_configuration.h"
|
||||
|
||||
#include "components/USBIP/usb_descriptor.h"
|
||||
#include "components/DAP/include/DAP.h"
|
||||
#include "components/DAP/include/swo.h"
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/ringbuf.h"
|
||||
#include "freertos/semphr.h"
|
||||
|
||||
#include "lwip/err.h"
|
||||
#include "lwip/sockets.h"
|
||||
#include "lwip/sys.h"
|
||||
#include <lwip/netdb.h>
|
||||
|
||||
#if (USE_WINUSB == 1)
|
||||
typedef struct
|
||||
{
|
||||
uint32_t length;
|
||||
uint8_t buf[DAP_PACKET_SIZE];
|
||||
} DapPacket_t;
|
||||
#else
|
||||
typedef struct
|
||||
{
|
||||
uint8_t buf[DAP_PACKET_SIZE];
|
||||
} DapPacket_t;
|
||||
#endif
|
||||
|
||||
#define DAP_HANDLE_SIZE (sizeof(DapPacket_t))
|
||||
|
||||
|
||||
extern int kSock;
|
||||
extern TaskHandle_t kDAPTaskHandle;
|
||||
|
||||
int kRestartDAPHandle = 0;
|
||||
|
||||
|
||||
static DapPacket_t DAPDataProcessed;
|
||||
static int dap_respond = 0;
|
||||
|
||||
// SWO Trace
|
||||
static uint8_t *swo_data_to_send = NULL;
|
||||
static uint32_t swo_data_num;
|
||||
|
||||
// DAP handle
|
||||
static RingbufHandle_t dap_dataIN_handle = NULL;
|
||||
static RingbufHandle_t dap_dataOUT_handle = NULL;
|
||||
static SemaphoreHandle_t data_response_mux = NULL;
|
||||
|
||||
|
||||
void handle_dap_data_request(usbip_stage2_header *header, uint32_t length)
|
||||
{
|
||||
uint8_t *data_in = (uint8_t *)header;
|
||||
data_in = &(data_in[sizeof(usbip_stage2_header)]);
|
||||
// Point to the beginning of the URB packet
|
||||
|
||||
#if (USE_WINUSB == 1)
|
||||
send_stage2_submit(header, 0, 0);
|
||||
|
||||
// always send constant size buf -> cuz we don't care about the IN packet size
|
||||
// and to unify the style, we set aside the length of the section
|
||||
xRingbufferSend(dap_dataIN_handle, data_in - sizeof(uint32_t), DAP_HANDLE_SIZE, portMAX_DELAY);
|
||||
xTaskNotifyGive(kDAPTaskHandle);
|
||||
|
||||
#else
|
||||
send_stage2_submit(header, 0, 0);
|
||||
|
||||
xRingbufferSend(dap_dataIN_handle, data_in, DAP_HANDLE_SIZE, portMAX_DELAY);
|
||||
xTaskNotifyGive(kDAPTaskHandle);
|
||||
|
||||
#endif
|
||||
|
||||
// dap_respond = DAP_ProcessCommand((uint8_t *)data_in, (uint8_t *)data_out);
|
||||
// //handle_dap_data_response(header);
|
||||
// send_stage2_submit(header, 0, 0);
|
||||
}
|
||||
|
||||
void handle_dap_data_response(usbip_stage2_header *header)
|
||||
{
|
||||
return;
|
||||
// int resLength = dap_respond & 0xFFFF;
|
||||
// if (resLength)
|
||||
// {
|
||||
|
||||
// send_stage2_submit_data(header, 0, (void *)DAPDataProcessed.buf, resLength);
|
||||
// dap_respond = 0;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// send_stage2_submit(header, 0, 0);
|
||||
// }
|
||||
}
|
||||
|
||||
void handle_swo_trace_response(usbip_stage2_header *header)
|
||||
{
|
||||
#if (SWO_FUNCTION_ENABLE == 1)
|
||||
if (kSwoTransferBusy)
|
||||
{
|
||||
// busy indicates that there is data to be send
|
||||
printf("swo use data\r\n");
|
||||
send_stage2_submit_data(header, 0, (void *)swo_data_to_send, swo_data_num);
|
||||
SWO_TransferComplete();
|
||||
}
|
||||
else
|
||||
{
|
||||
// nothing to send.
|
||||
send_stage2_submit(header, 0, 0);
|
||||
}
|
||||
#else
|
||||
send_stage2_submit(header, 0, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
// SWO Data Queue Transfer
|
||||
// buf: pointer to buffer with data
|
||||
// num: number of bytes to transfer
|
||||
void SWO_QueueTransfer(uint8_t *buf, uint32_t num)
|
||||
{
|
||||
swo_data_to_send = buf;
|
||||
swo_data_num = num;
|
||||
}
|
||||
|
||||
void DAP_Thread(void *argument)
|
||||
{
|
||||
dap_dataIN_handle = xRingbufferCreate(DAP_HANDLE_SIZE * 20, RINGBUF_TYPE_BYTEBUF);
|
||||
dap_dataOUT_handle = xRingbufferCreate(DAP_HANDLE_SIZE * 20, RINGBUF_TYPE_BYTEBUF);
|
||||
data_response_mux = xSemaphoreCreateMutex();
|
||||
size_t packetSize;
|
||||
int resLength;
|
||||
DapPacket_t *item;
|
||||
|
||||
if (dap_dataIN_handle == NULL || dap_dataIN_handle == NULL ||
|
||||
data_response_mux == NULL)
|
||||
{
|
||||
os_printf("Can not create DAP ringbuf/mux!\r\n");
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
for (;;)
|
||||
{
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (kRestartDAPHandle)
|
||||
{
|
||||
vRingbufferDelete(dap_dataIN_handle);
|
||||
vRingbufferDelete(dap_dataOUT_handle);
|
||||
dap_dataIN_handle = dap_dataOUT_handle = NULL;
|
||||
|
||||
dap_dataIN_handle = xRingbufferCreate(DAP_HANDLE_SIZE * 20, RINGBUF_TYPE_BYTEBUF);
|
||||
dap_dataOUT_handle = xRingbufferCreate(DAP_HANDLE_SIZE * 20, RINGBUF_TYPE_BYTEBUF);
|
||||
if (dap_dataIN_handle == NULL || dap_dataIN_handle == NULL)
|
||||
{
|
||||
os_printf("Can not create DAP ringbuf/mux!\r\n");
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
kRestartDAPHandle = 0;
|
||||
}
|
||||
|
||||
ulTaskNotifyTake(pdFALSE, portMAX_DELAY);
|
||||
packetSize = 0;
|
||||
item = (DapPacket_t *)xRingbufferReceiveUpTo(dap_dataIN_handle, &packetSize,
|
||||
pdMS_TO_TICKS(1), DAP_HANDLE_SIZE);
|
||||
if (packetSize == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
else if (packetSize < DAP_HANDLE_SIZE)
|
||||
{
|
||||
os_printf("Wrong data in packet size:%d , data in remain: %d\r\n", packetSize, (int)xRingbufferGetMaxItemSize(dap_dataIN_handle));
|
||||
vRingbufferReturnItem(dap_dataIN_handle, (void *)item);
|
||||
break;
|
||||
// This may not happen because there is a semaphore acquisition
|
||||
}
|
||||
|
||||
if (item->buf[0] == ID_DAP_QueueCommands)
|
||||
{
|
||||
item->buf[0] = ID_DAP_ExecuteCommands;
|
||||
}
|
||||
|
||||
resLength = DAP_ProcessCommand((uint8_t *)item->buf, (uint8_t *)DAPDataProcessed.buf); // use first 4 byte to save length
|
||||
resLength &= 0xFFFF; // res length in lower 16 bits
|
||||
|
||||
vRingbufferReturnItem(dap_dataIN_handle, (void *)item); // process done.
|
||||
|
||||
// now prepare to reply
|
||||
#if (USE_WINUSB == 1)
|
||||
DAPDataProcessed.length = resLength;
|
||||
#endif
|
||||
xRingbufferSend(dap_dataOUT_handle, (void *)&DAPDataProcessed, DAP_HANDLE_SIZE, portMAX_DELAY);
|
||||
|
||||
if (xSemaphoreTake(data_response_mux, portMAX_DELAY) == pdTRUE)
|
||||
{
|
||||
++dap_respond;
|
||||
xSemaphoreGive(data_response_mux);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int fast_reply(uint8_t *buf, uint32_t length)
|
||||
{
|
||||
usbip_stage2_header *buf_header = (usbip_stage2_header *)buf;
|
||||
if (length == 48 &&
|
||||
buf_header->base.command == PP_HTONL(USBIP_STAGE2_REQ_SUBMIT) &&
|
||||
buf_header->base.direction == PP_HTONL(USBIP_DIR_IN) &&
|
||||
buf_header->base.ep == PP_HTONL(1))
|
||||
{
|
||||
if (dap_respond > 0)
|
||||
{
|
||||
DapPacket_t *item;
|
||||
size_t packetSize = 0;
|
||||
item = (DapPacket_t *)xRingbufferReceiveUpTo(dap_dataOUT_handle, &packetSize,
|
||||
pdMS_TO_TICKS(10), DAP_HANDLE_SIZE);
|
||||
if (packetSize == DAP_HANDLE_SIZE)
|
||||
{
|
||||
#if (USE_WINUSB == 1)
|
||||
send_stage2_submit_data_fast((usbip_stage2_header *)buf, item->buf, item->length);
|
||||
#else
|
||||
send_stage2_submit_data_fast((usbip_stage2_header *)buf, item->buf, DAP_HANDLE_SIZE);
|
||||
#endif
|
||||
|
||||
if (xSemaphoreTake(data_response_mux, portMAX_DELAY) == pdTRUE)
|
||||
{
|
||||
--dap_respond;
|
||||
xSemaphoreGive(data_response_mux);
|
||||
}
|
||||
|
||||
vRingbufferReturnItem(dap_dataOUT_handle, (void *)item);
|
||||
return 1;
|
||||
}
|
||||
else if (packetSize > 0)
|
||||
{
|
||||
os_printf("Wrong data out packet size:%d!\r\n", packetSize);
|
||||
}
|
||||
////TODO: fast reply
|
||||
}
|
||||
else
|
||||
{
|
||||
buf_header->base.command = PP_HTONL(USBIP_STAGE2_RSP_SUBMIT);
|
||||
buf_header->base.direction = PP_HTONL(USBIP_DIR_OUT);
|
||||
buf_header->u.ret_submit.status = 0;
|
||||
buf_header->u.ret_submit.data_length = 0;
|
||||
buf_header->u.ret_submit.error_count = 0;
|
||||
send(kSock, buf, 48, 0);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef __DAP_HANDLE_H__
|
||||
#define __DAP_HANDLE_H__
|
||||
|
||||
#include "usbip_defs.h"
|
||||
#include "components/USBIP/usbip_defs.h"
|
||||
|
||||
void handle_dap_data_request(usbip_stage2_header *header, uint32_t length);
|
||||
void handle_dap_data_response(usbip_stage2_header *header);
|
||||
|
|
362
main/main.c
362
main/main.c
|
@ -1,181 +1,181 @@
|
|||
/* BSD Socket API Example
|
||||
|
||||
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
||||
|
||||
Unless required by applicable law or agreed to in writing, this
|
||||
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
CONDITIONS OF ANY KIND, either express or implied.
|
||||
*/
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/param.h>
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/event_groups.h"
|
||||
#include "esp_system.h"
|
||||
#include "esp_wifi.h"
|
||||
#include "esp_event_loop.h"
|
||||
#include "esp_log.h"
|
||||
#include "nvs_flash.h"
|
||||
|
||||
#include "lwip/err.h"
|
||||
#include "lwip/sockets.h"
|
||||
#include "lwip/sys.h"
|
||||
#include <lwip/netdb.h>
|
||||
|
||||
#include "tcp_server.h"
|
||||
#include "timer.h"
|
||||
#include "wifi_configuration.h"
|
||||
#include "DAP_config.h"
|
||||
|
||||
|
||||
extern void DAP_Setup(void);
|
||||
extern void DAP_Thread(void *argument);
|
||||
extern void SWO_Thread();
|
||||
|
||||
TaskHandle_t kDAPTaskHandle = NULL;
|
||||
|
||||
|
||||
|
||||
/* FreeRTOS event group to signal when we are connected & ready to make a request */
|
||||
static EventGroupHandle_t wifi_event_group;
|
||||
|
||||
const int IPV4_GOTIP_BIT = BIT0;
|
||||
#ifdef CONFIG_EXAMPLE_IPV6
|
||||
const int IPV6_GOTIP_BIT = BIT1;
|
||||
#endif
|
||||
|
||||
|
||||
static esp_err_t event_handler(void *ctx, system_event_t *event)
|
||||
{
|
||||
/* For accessing reason codes in case of disconnection */
|
||||
system_event_info_t *info = &event->event_info;
|
||||
|
||||
switch (event->event_id)
|
||||
{
|
||||
case SYSTEM_EVENT_STA_START:
|
||||
esp_wifi_connect();
|
||||
os_printf("SYSTEM_EVENT_STA_START\r\n");
|
||||
break;
|
||||
case SYSTEM_EVENT_STA_CONNECTED:
|
||||
#ifdef CONFIG_EXAMPLE_IPV6
|
||||
/* enable ipv6 */
|
||||
tcpip_adapter_create_ip6_linklocal(TCPIP_ADAPTER_IF_STA);
|
||||
#endif
|
||||
break;
|
||||
case SYSTEM_EVENT_STA_GOT_IP:
|
||||
xEventGroupSetBits(wifi_event_group, IPV4_GOTIP_BIT);
|
||||
os_printf("SYSTEM EVENT STA GOT IP : %s\r\n", ip4addr_ntoa(&event->event_info.got_ip.ip_info.ip));
|
||||
break;
|
||||
case SYSTEM_EVENT_STA_DISCONNECTED:
|
||||
os_printf("Disconnect reason : %d\r\n", info->disconnected.reason);
|
||||
if (info->disconnected.reason == WIFI_REASON_BASIC_RATE_NOT_SUPPORT)
|
||||
{
|
||||
/*Switch to 802.11 bgn mode */
|
||||
esp_wifi_set_protocol(ESP_IF_WIFI_STA, WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G | WIFI_PROTOCOL_11N);
|
||||
}
|
||||
esp_wifi_connect();
|
||||
xEventGroupClearBits(wifi_event_group, IPV4_GOTIP_BIT);
|
||||
#ifdef CONFIG_EXAMPLE_IPV6
|
||||
xEventGroupClearBits(wifi_event_group, IPV6_GOTIP_BIT);
|
||||
#endif
|
||||
break;
|
||||
case SYSTEM_EVENT_AP_STA_GOT_IP6:
|
||||
#ifdef CONFIG_EXAMPLE_IPV6
|
||||
xEventGroupSetBits(wifi_event_group, IPV6_GOTIP_BIT);
|
||||
os_printf("SYSTEM_EVENT_STA_GOT_IP6\r\n");
|
||||
|
||||
char *ip6 = ip6addr_ntoa(&event->event_info.got_ip6.ip6_info.ip);
|
||||
os_printf("IPv6: %s\r\n", ip6);
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static void initialise_wifi(void)
|
||||
{
|
||||
tcpip_adapter_init();
|
||||
|
||||
#if (USE_STATIC_IP == 1)
|
||||
tcpip_adapter_dhcps_stop(TCPIP_ADAPTER_IF_STA);
|
||||
|
||||
tcpip_adapter_ip_info_t ip_info;
|
||||
|
||||
#define MY_IP4_ADDR(...) IP4_ADDR(__VA_ARGS__)
|
||||
MY_IP4_ADDR(&ip_info.ip, DAP_IP_ADDRESS);
|
||||
MY_IP4_ADDR(&ip_info.gw, DAP_IP_GATEWAY);
|
||||
MY_IP4_ADDR(&ip_info.netmask, DAP_IP_NETMASK);
|
||||
#undef MY_IP4_ADDR
|
||||
|
||||
tcpip_adapter_set_ip_info(TCPIP_ADAPTER_IF_STA, &ip_info);
|
||||
#endif // (USE_STATIC_IP == 1)
|
||||
|
||||
|
||||
wifi_event_group = xEventGroupCreate();
|
||||
|
||||
ESP_ERROR_CHECK(esp_event_loop_init(event_handler, NULL));
|
||||
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
|
||||
ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_RAM));
|
||||
wifi_config_t wifi_config = {
|
||||
.sta = {
|
||||
.ssid = WIFI_SSID,
|
||||
.password = WIFI_PASS,
|
||||
},
|
||||
};
|
||||
os_printf("Setting WiFi configuration SSID %s...\r\n", wifi_config.sta.ssid);
|
||||
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
|
||||
ESP_ERROR_CHECK(esp_wifi_set_config(ESP_IF_WIFI_STA, &wifi_config));
|
||||
ESP_ERROR_CHECK(esp_wifi_start());
|
||||
}
|
||||
|
||||
static void wait_for_ip()
|
||||
{
|
||||
#ifdef CONFIG_EXAMPLE_IPV6
|
||||
uint32_t bits = IPV4_GOTIP_BIT | IPV6_GOTIP_BIT;
|
||||
#else
|
||||
uint32_t bits = IPV4_GOTIP_BIT;
|
||||
#endif
|
||||
|
||||
os_printf("Waiting for AP connection...\r\n");
|
||||
xEventGroupWaitBits(wifi_event_group, bits, false, true, portMAX_DELAY);
|
||||
os_printf("Connected to AP\r\n");
|
||||
}
|
||||
|
||||
|
||||
void app_main()
|
||||
{
|
||||
// struct rst_info *rtc_info = system_get_rst_info();
|
||||
|
||||
// os_printf("reset reason: %x\n", rtc_info->reason);
|
||||
|
||||
// if (rtc_info->reason == REASON_WDT_RST ||
|
||||
// rtc_info->reason == REASON_EXCEPTION_RST ||
|
||||
// rtc_info->reason == REASON_SOFT_WDT_RST)
|
||||
// {
|
||||
// if (rtc_info->reason == REASON_EXCEPTION_RST)
|
||||
// {
|
||||
// os_printf("Fatal exception (%d):\n", rtc_info->exccause);
|
||||
// }
|
||||
// os_printf("epc1=0x%08x, epc2=0x%08x, epc3=0x%08x,excvaddr=0x%08x, depc=0x%08x\n",
|
||||
// rtc_info->epc1, rtc_info->epc2, rtc_info->epc3,
|
||||
// rtc_info->excvaddr, rtc_info->depc);
|
||||
// }
|
||||
|
||||
ESP_ERROR_CHECK(nvs_flash_init());
|
||||
initialise_wifi();
|
||||
wait_for_ip();
|
||||
DAP_Setup();
|
||||
timer_init();
|
||||
|
||||
|
||||
xTaskCreate(tcp_server_task, "tcp_server", 4096, NULL, 14, NULL);
|
||||
xTaskCreate(DAP_Thread, "DAP_Task", 2048, NULL, 10, &kDAPTaskHandle);
|
||||
// SWO Trace Task
|
||||
#if (SWO_FUNCTION_ENABLE == 1)
|
||||
xTaskCreate(SWO_Thread, "SWO_Task", 512, NULL, 10, NULL);
|
||||
#endif
|
||||
// It seems that the task is overly stressful...
|
||||
}
|
||||
/* BSD Socket API Example
|
||||
|
||||
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
||||
|
||||
Unless required by applicable law or agreed to in writing, this
|
||||
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
CONDITIONS OF ANY KIND, either express or implied.
|
||||
*/
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/param.h>
|
||||
|
||||
#include "main/tcp_server.h"
|
||||
#include "main/timer.h"
|
||||
#include "main/wifi_configuration.h"
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/event_groups.h"
|
||||
#include "esp_system.h"
|
||||
#include "esp_wifi.h"
|
||||
#include "esp_event_loop.h"
|
||||
#include "esp_log.h"
|
||||
#include "nvs_flash.h"
|
||||
|
||||
#include "lwip/err.h"
|
||||
#include "lwip/sockets.h"
|
||||
#include "lwip/sys.h"
|
||||
#include <lwip/netdb.h>
|
||||
|
||||
|
||||
extern void DAP_Setup(void);
|
||||
extern void DAP_Thread(void *argument);
|
||||
extern void SWO_Thread();
|
||||
|
||||
TaskHandle_t kDAPTaskHandle = NULL;
|
||||
|
||||
|
||||
|
||||
/* FreeRTOS event group to signal when we are connected & ready to make a request */
|
||||
static EventGroupHandle_t wifi_event_group;
|
||||
|
||||
const int IPV4_GOTIP_BIT = BIT0;
|
||||
#ifdef CONFIG_EXAMPLE_IPV6
|
||||
const int IPV6_GOTIP_BIT = BIT1;
|
||||
#endif
|
||||
|
||||
|
||||
static esp_err_t event_handler(void *ctx, system_event_t *event)
|
||||
{
|
||||
/* For accessing reason codes in case of disconnection */
|
||||
system_event_info_t *info = &event->event_info;
|
||||
|
||||
switch (event->event_id)
|
||||
{
|
||||
case SYSTEM_EVENT_STA_START:
|
||||
esp_wifi_connect();
|
||||
os_printf("SYSTEM_EVENT_STA_START\r\n");
|
||||
break;
|
||||
case SYSTEM_EVENT_STA_CONNECTED:
|
||||
#ifdef CONFIG_EXAMPLE_IPV6
|
||||
/* enable ipv6 */
|
||||
tcpip_adapter_create_ip6_linklocal(TCPIP_ADAPTER_IF_STA);
|
||||
#endif
|
||||
break;
|
||||
case SYSTEM_EVENT_STA_GOT_IP:
|
||||
xEventGroupSetBits(wifi_event_group, IPV4_GOTIP_BIT);
|
||||
os_printf("SYSTEM EVENT STA GOT IP : %s\r\n", ip4addr_ntoa(&event->event_info.got_ip.ip_info.ip));
|
||||
break;
|
||||
case SYSTEM_EVENT_STA_DISCONNECTED:
|
||||
os_printf("Disconnect reason : %d\r\n", info->disconnected.reason);
|
||||
if (info->disconnected.reason == WIFI_REASON_BASIC_RATE_NOT_SUPPORT)
|
||||
{
|
||||
/*Switch to 802.11 bgn mode */
|
||||
esp_wifi_set_protocol(ESP_IF_WIFI_STA, WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G | WIFI_PROTOCOL_11N);
|
||||
}
|
||||
esp_wifi_connect();
|
||||
xEventGroupClearBits(wifi_event_group, IPV4_GOTIP_BIT);
|
||||
#ifdef CONFIG_EXAMPLE_IPV6
|
||||
xEventGroupClearBits(wifi_event_group, IPV6_GOTIP_BIT);
|
||||
#endif
|
||||
break;
|
||||
case SYSTEM_EVENT_AP_STA_GOT_IP6:
|
||||
#ifdef CONFIG_EXAMPLE_IPV6
|
||||
xEventGroupSetBits(wifi_event_group, IPV6_GOTIP_BIT);
|
||||
os_printf("SYSTEM_EVENT_STA_GOT_IP6\r\n");
|
||||
|
||||
char *ip6 = ip6addr_ntoa(&event->event_info.got_ip6.ip6_info.ip);
|
||||
os_printf("IPv6: %s\r\n", ip6);
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static void initialise_wifi(void)
|
||||
{
|
||||
tcpip_adapter_init();
|
||||
|
||||
#if (USE_STATIC_IP == 1)
|
||||
tcpip_adapter_dhcps_stop(TCPIP_ADAPTER_IF_STA);
|
||||
|
||||
tcpip_adapter_ip_info_t ip_info;
|
||||
|
||||
#define MY_IP4_ADDR(...) IP4_ADDR(__VA_ARGS__)
|
||||
MY_IP4_ADDR(&ip_info.ip, DAP_IP_ADDRESS);
|
||||
MY_IP4_ADDR(&ip_info.gw, DAP_IP_GATEWAY);
|
||||
MY_IP4_ADDR(&ip_info.netmask, DAP_IP_NETMASK);
|
||||
#undef MY_IP4_ADDR
|
||||
|
||||
tcpip_adapter_set_ip_info(TCPIP_ADAPTER_IF_STA, &ip_info);
|
||||
#endif // (USE_STATIC_IP == 1)
|
||||
|
||||
|
||||
wifi_event_group = xEventGroupCreate();
|
||||
|
||||
ESP_ERROR_CHECK(esp_event_loop_init(event_handler, NULL));
|
||||
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
|
||||
ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_RAM));
|
||||
wifi_config_t wifi_config = {
|
||||
.sta = {
|
||||
.ssid = WIFI_SSID,
|
||||
.password = WIFI_PASS,
|
||||
},
|
||||
};
|
||||
os_printf("Setting WiFi configuration SSID %s...\r\n", wifi_config.sta.ssid);
|
||||
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
|
||||
ESP_ERROR_CHECK(esp_wifi_set_config(ESP_IF_WIFI_STA, &wifi_config));
|
||||
ESP_ERROR_CHECK(esp_wifi_start());
|
||||
}
|
||||
|
||||
static void wait_for_ip()
|
||||
{
|
||||
#ifdef CONFIG_EXAMPLE_IPV6
|
||||
uint32_t bits = IPV4_GOTIP_BIT | IPV6_GOTIP_BIT;
|
||||
#else
|
||||
uint32_t bits = IPV4_GOTIP_BIT;
|
||||
#endif
|
||||
|
||||
os_printf("Waiting for AP connection...\r\n");
|
||||
xEventGroupWaitBits(wifi_event_group, bits, false, true, portMAX_DELAY);
|
||||
os_printf("Connected to AP\r\n");
|
||||
}
|
||||
|
||||
|
||||
void app_main()
|
||||
{
|
||||
// struct rst_info *rtc_info = system_get_rst_info();
|
||||
|
||||
// os_printf("reset reason: %x\n", rtc_info->reason);
|
||||
|
||||
// if (rtc_info->reason == REASON_WDT_RST ||
|
||||
// rtc_info->reason == REASON_EXCEPTION_RST ||
|
||||
// rtc_info->reason == REASON_SOFT_WDT_RST)
|
||||
// {
|
||||
// if (rtc_info->reason == REASON_EXCEPTION_RST)
|
||||
// {
|
||||
// os_printf("Fatal exception (%d):\n", rtc_info->exccause);
|
||||
// }
|
||||
// os_printf("epc1=0x%08x, epc2=0x%08x, epc3=0x%08x,excvaddr=0x%08x, depc=0x%08x\n",
|
||||
// rtc_info->epc1, rtc_info->epc2, rtc_info->epc3,
|
||||
// rtc_info->excvaddr, rtc_info->depc);
|
||||
// }
|
||||
|
||||
ESP_ERROR_CHECK(nvs_flash_init());
|
||||
initialise_wifi();
|
||||
wait_for_ip();
|
||||
DAP_Setup();
|
||||
timer_init();
|
||||
|
||||
|
||||
xTaskCreate(tcp_server_task, "tcp_server", 4096, NULL, 14, NULL);
|
||||
xTaskCreate(DAP_Thread, "DAP_Task", 2048, NULL, 10, &kDAPTaskHandle);
|
||||
// SWO Trace Task
|
||||
#if (SWO_FUNCTION_ENABLE == 1)
|
||||
xTaskCreate(SWO_Thread, "SWO_Task", 512, NULL, 10, NULL);
|
||||
#endif
|
||||
// It seems that the task is overly stressful...
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "esp_system.h"
|
||||
|
|
|
@ -1,181 +1,182 @@
|
|||
/**
|
||||
* @file tcp_server.c
|
||||
* @brief Handle main tcp tasks
|
||||
* @version 0.1
|
||||
* @date 2020-01-22
|
||||
*
|
||||
* @copyright Copyright (c) 2020
|
||||
*
|
||||
*/
|
||||
#include "tcp_server.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/param.h>
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/event_groups.h"
|
||||
#include "esp_system.h"
|
||||
#include "esp_wifi.h"
|
||||
#include "esp_event_loop.h"
|
||||
#include "esp_log.h"
|
||||
#include "nvs_flash.h"
|
||||
|
||||
#include "lwip/err.h"
|
||||
#include "lwip/sockets.h"
|
||||
#include "lwip/sys.h"
|
||||
#include <lwip/netdb.h>
|
||||
|
||||
#include "wifi_configuration.h"
|
||||
#include "usbip_server.h"
|
||||
|
||||
extern TaskHandle_t kDAPTaskHandle;
|
||||
extern int kRestartDAPHandle;
|
||||
|
||||
uint8_t kState = ACCEPTING;
|
||||
int kSock = -1;
|
||||
|
||||
void tcp_server_task(void *pvParameters)
|
||||
{
|
||||
uint8_t tcp_rx_buffer[1500];
|
||||
char addr_str[128];
|
||||
int addr_family;
|
||||
int ip_protocol;
|
||||
|
||||
int on = 1;
|
||||
while (1)
|
||||
{
|
||||
|
||||
#ifdef CONFIG_EXAMPLE_IPV4
|
||||
struct sockaddr_in destAddr;
|
||||
destAddr.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
destAddr.sin_family = AF_INET;
|
||||
destAddr.sin_port = htons(PORT);
|
||||
addr_family = AF_INET;
|
||||
ip_protocol = IPPROTO_IP;
|
||||
inet_ntoa_r(destAddr.sin_addr, addr_str, sizeof(addr_str) - 1);
|
||||
#else // IPV6
|
||||
struct sockaddr_in6 destAddr;
|
||||
bzero(&destAddr.sin6_addr.un, sizeof(destAddr.sin6_addr.un));
|
||||
destAddr.sin6_family = AF_INET6;
|
||||
destAddr.sin6_port = htons(PORT);
|
||||
addr_family = AF_INET6;
|
||||
ip_protocol = IPPROTO_IPV6;
|
||||
inet6_ntoa_r(destAddr.sin6_addr, addr_str, sizeof(addr_str) - 1);
|
||||
#endif
|
||||
|
||||
int listen_sock = socket(addr_family, SOCK_STREAM, ip_protocol);
|
||||
if (listen_sock < 0)
|
||||
{
|
||||
os_printf("Unable to create socket: errno %d\r\n", errno);
|
||||
break;
|
||||
}
|
||||
os_printf("Socket created\r\n");
|
||||
|
||||
setsockopt(listen_sock, SOL_SOCKET, SO_KEEPALIVE, (void *)&on, sizeof(on));
|
||||
setsockopt(listen_sock, IPPROTO_TCP, TCP_NODELAY, (void *)&on, sizeof(on));
|
||||
|
||||
int err = bind(listen_sock, (struct sockaddr *)&destAddr, sizeof(destAddr));
|
||||
if (err != 0)
|
||||
{
|
||||
os_printf("Socket unable to bind: errno %d\r\n", errno);
|
||||
break;
|
||||
}
|
||||
os_printf("Socket binded\r\n");
|
||||
|
||||
err = listen(listen_sock, 1);
|
||||
if (err != 0)
|
||||
{
|
||||
os_printf("Error occured during listen: errno %d\r\n", errno);
|
||||
break;
|
||||
}
|
||||
os_printf("Socket listening\r\n");
|
||||
|
||||
#ifdef CONFIG_EXAMPLE_IPV6
|
||||
struct sockaddr_in6 sourceAddr; // Large enough for both IPv4 or IPv6
|
||||
#else
|
||||
struct sockaddr_in sourceAddr;
|
||||
#endif
|
||||
uint32_t addrLen = sizeof(sourceAddr);
|
||||
while (1)
|
||||
{
|
||||
kSock = accept(listen_sock, (struct sockaddr *)&sourceAddr, &addrLen);
|
||||
if (kSock < 0)
|
||||
{
|
||||
os_printf("Unable to accept connection: errno %d\r\n", errno);
|
||||
break;
|
||||
}
|
||||
setsockopt(kSock, SOL_SOCKET, SO_KEEPALIVE, (void *)&on, sizeof(on));
|
||||
setsockopt(kSock, IPPROTO_TCP, TCP_NODELAY, (void *)&on, sizeof(on));
|
||||
os_printf("Socket accepted\r\n");
|
||||
|
||||
while (1)
|
||||
{
|
||||
int len = recv(kSock, tcp_rx_buffer, sizeof(tcp_rx_buffer), 0);
|
||||
// Error occured during receiving
|
||||
if (len < 0)
|
||||
{
|
||||
os_printf("recv failed: errno %d\r\n", errno);
|
||||
break;
|
||||
}
|
||||
// Connection closed
|
||||
else if (len == 0)
|
||||
{
|
||||
os_printf("Connection closed\r\n");
|
||||
break;
|
||||
}
|
||||
// Data received
|
||||
else
|
||||
{
|
||||
// #ifdef CONFIG_EXAMPLE_IPV6
|
||||
// // Get the sender's ip address as string
|
||||
// if (sourceAddr.sin6_family == PF_INET)
|
||||
// {
|
||||
// inet_ntoa_r(((struct sockaddr_in *)&sourceAddr)->sin_addr.s_addr, addr_str, sizeof(addr_str) - 1);
|
||||
// }
|
||||
// else if (sourceAddr.sin6_family == PF_INET6)
|
||||
// {
|
||||
// inet6_ntoa_r(sourceAddr.sin6_addr, addr_str, sizeof(addr_str) - 1);
|
||||
// }
|
||||
// #else
|
||||
// inet_ntoa_r(((struct sockaddr_in *)&sourceAddr)->sin_addr.s_addr, addr_str, sizeof(addr_str) - 1);
|
||||
// #endif
|
||||
|
||||
switch (kState)
|
||||
{
|
||||
case ACCEPTING:
|
||||
kState = ATTACHING;
|
||||
|
||||
case ATTACHING:
|
||||
attach(tcp_rx_buffer, len);
|
||||
break;
|
||||
|
||||
case EMULATING:
|
||||
emulate(tcp_rx_buffer, len);
|
||||
break;
|
||||
default:
|
||||
os_printf("unkonw kstate!\r\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
// kState = ACCEPTING;
|
||||
if (kSock != -1)
|
||||
{
|
||||
os_printf("Shutting down socket and restarting...\r\n");
|
||||
//shutdown(kSock, 0);
|
||||
close(kSock);
|
||||
if (kState == EMULATING)
|
||||
kState = ACCEPTING;
|
||||
|
||||
// Restart DAP Handle
|
||||
kRestartDAPHandle = 1;
|
||||
xTaskNotifyGive(kDAPTaskHandle);
|
||||
|
||||
//shutdown(listen_sock, 0);
|
||||
//close(listen_sock);
|
||||
//vTaskDelay(5);
|
||||
}
|
||||
}
|
||||
}
|
||||
vTaskDelete(NULL);
|
||||
/**
|
||||
* @file tcp_server.c
|
||||
* @brief Handle main tcp tasks
|
||||
* @version 0.1
|
||||
* @date 2020-01-22
|
||||
*
|
||||
* @copyright Copyright (c) 2020
|
||||
*
|
||||
*/
|
||||
#include "tcp_server.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/param.h>
|
||||
|
||||
#include "main/wifi_configuration.h"
|
||||
#include "main/usbip_server.h"
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/event_groups.h"
|
||||
#include "esp_system.h"
|
||||
#include "esp_wifi.h"
|
||||
#include "esp_event_loop.h"
|
||||
#include "esp_log.h"
|
||||
#include "nvs_flash.h"
|
||||
|
||||
#include "lwip/err.h"
|
||||
#include "lwip/sockets.h"
|
||||
#include "lwip/sys.h"
|
||||
#include <lwip/netdb.h>
|
||||
|
||||
extern TaskHandle_t kDAPTaskHandle;
|
||||
extern int kRestartDAPHandle;
|
||||
|
||||
uint8_t kState = ACCEPTING;
|
||||
int kSock = -1;
|
||||
|
||||
void tcp_server_task(void *pvParameters)
|
||||
{
|
||||
uint8_t tcp_rx_buffer[1500];
|
||||
char addr_str[128];
|
||||
int addr_family;
|
||||
int ip_protocol;
|
||||
|
||||
int on = 1;
|
||||
while (1)
|
||||
{
|
||||
|
||||
#ifdef CONFIG_EXAMPLE_IPV4
|
||||
struct sockaddr_in destAddr;
|
||||
destAddr.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
destAddr.sin_family = AF_INET;
|
||||
destAddr.sin_port = htons(PORT);
|
||||
addr_family = AF_INET;
|
||||
ip_protocol = IPPROTO_IP;
|
||||
inet_ntoa_r(destAddr.sin_addr, addr_str, sizeof(addr_str) - 1);
|
||||
#else // IPV6
|
||||
struct sockaddr_in6 destAddr;
|
||||
bzero(&destAddr.sin6_addr.un, sizeof(destAddr.sin6_addr.un));
|
||||
destAddr.sin6_family = AF_INET6;
|
||||
destAddr.sin6_port = htons(PORT);
|
||||
addr_family = AF_INET6;
|
||||
ip_protocol = IPPROTO_IPV6;
|
||||
inet6_ntoa_r(destAddr.sin6_addr, addr_str, sizeof(addr_str) - 1);
|
||||
#endif
|
||||
|
||||
int listen_sock = socket(addr_family, SOCK_STREAM, ip_protocol);
|
||||
if (listen_sock < 0)
|
||||
{
|
||||
os_printf("Unable to create socket: errno %d\r\n", errno);
|
||||
break;
|
||||
}
|
||||
os_printf("Socket created\r\n");
|
||||
|
||||
setsockopt(listen_sock, SOL_SOCKET, SO_KEEPALIVE, (void *)&on, sizeof(on));
|
||||
setsockopt(listen_sock, IPPROTO_TCP, TCP_NODELAY, (void *)&on, sizeof(on));
|
||||
|
||||
int err = bind(listen_sock, (struct sockaddr *)&destAddr, sizeof(destAddr));
|
||||
if (err != 0)
|
||||
{
|
||||
os_printf("Socket unable to bind: errno %d\r\n", errno);
|
||||
break;
|
||||
}
|
||||
os_printf("Socket binded\r\n");
|
||||
|
||||
err = listen(listen_sock, 1);
|
||||
if (err != 0)
|
||||
{
|
||||
os_printf("Error occured during listen: errno %d\r\n", errno);
|
||||
break;
|
||||
}
|
||||
os_printf("Socket listening\r\n");
|
||||
|
||||
#ifdef CONFIG_EXAMPLE_IPV6
|
||||
struct sockaddr_in6 sourceAddr; // Large enough for both IPv4 or IPv6
|
||||
#else
|
||||
struct sockaddr_in sourceAddr;
|
||||
#endif
|
||||
uint32_t addrLen = sizeof(sourceAddr);
|
||||
while (1)
|
||||
{
|
||||
kSock = accept(listen_sock, (struct sockaddr *)&sourceAddr, &addrLen);
|
||||
if (kSock < 0)
|
||||
{
|
||||
os_printf("Unable to accept connection: errno %d\r\n", errno);
|
||||
break;
|
||||
}
|
||||
setsockopt(kSock, SOL_SOCKET, SO_KEEPALIVE, (void *)&on, sizeof(on));
|
||||
setsockopt(kSock, IPPROTO_TCP, TCP_NODELAY, (void *)&on, sizeof(on));
|
||||
os_printf("Socket accepted\r\n");
|
||||
|
||||
while (1)
|
||||
{
|
||||
int len = recv(kSock, tcp_rx_buffer, sizeof(tcp_rx_buffer), 0);
|
||||
// Error occured during receiving
|
||||
if (len < 0)
|
||||
{
|
||||
os_printf("recv failed: errno %d\r\n", errno);
|
||||
break;
|
||||
}
|
||||
// Connection closed
|
||||
else if (len == 0)
|
||||
{
|
||||
os_printf("Connection closed\r\n");
|
||||
break;
|
||||
}
|
||||
// Data received
|
||||
else
|
||||
{
|
||||
// #ifdef CONFIG_EXAMPLE_IPV6
|
||||
// // Get the sender's ip address as string
|
||||
// if (sourceAddr.sin6_family == PF_INET)
|
||||
// {
|
||||
// inet_ntoa_r(((struct sockaddr_in *)&sourceAddr)->sin_addr.s_addr, addr_str, sizeof(addr_str) - 1);
|
||||
// }
|
||||
// else if (sourceAddr.sin6_family == PF_INET6)
|
||||
// {
|
||||
// inet6_ntoa_r(sourceAddr.sin6_addr, addr_str, sizeof(addr_str) - 1);
|
||||
// }
|
||||
// #else
|
||||
// inet_ntoa_r(((struct sockaddr_in *)&sourceAddr)->sin_addr.s_addr, addr_str, sizeof(addr_str) - 1);
|
||||
// #endif
|
||||
|
||||
switch (kState)
|
||||
{
|
||||
case ACCEPTING:
|
||||
kState = ATTACHING;
|
||||
|
||||
case ATTACHING:
|
||||
attach(tcp_rx_buffer, len);
|
||||
break;
|
||||
|
||||
case EMULATING:
|
||||
emulate(tcp_rx_buffer, len);
|
||||
break;
|
||||
default:
|
||||
os_printf("unkonw kstate!\r\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
// kState = ACCEPTING;
|
||||
if (kSock != -1)
|
||||
{
|
||||
os_printf("Shutting down socket and restarting...\r\n");
|
||||
//shutdown(kSock, 0);
|
||||
close(kSock);
|
||||
if (kState == EMULATING)
|
||||
kState = ACCEPTING;
|
||||
|
||||
// Restart DAP Handle
|
||||
kRestartDAPHandle = 1;
|
||||
xTaskNotifyGive(kDAPTaskHandle);
|
||||
|
||||
//shutdown(listen_sock, 0);
|
||||
//close(listen_sock);
|
||||
//vTaskDelay(5);
|
||||
}
|
||||
}
|
||||
}
|
||||
vTaskDelete(NULL);
|
||||
}
|
|
@ -3,4 +3,4 @@
|
|||
|
||||
void tcp_server_task(void *pvParameters);
|
||||
|
||||
#endif
|
||||
#endif
|
|
@ -12,12 +12,9 @@
|
|||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "timer.h"
|
||||
#include "main/timer.h"
|
||||
|
||||
#include "hw_timer.h"
|
||||
#include "timer_struct.h"
|
||||
|
||||
#include "cmsis_compiler.h"
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/event_groups.h"
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "main/usbip_server.h"
|
||||
#include "main/DAP_handle.h"
|
||||
|
||||
#include "components/USBIP/usb_handle.h"
|
||||
#include "components/USBIP/usb_descriptor.h"
|
||||
|
||||
#include "lwip/err.h"
|
||||
#include "lwip/sockets.h"
|
||||
#include "lwip/sys.h"
|
||||
#include <lwip/netdb.h>
|
||||
|
||||
#include "usbip_server.h"
|
||||
#include "usbip_defs.h"
|
||||
#include "usb_defs.h"
|
||||
#include "USBd_config.h"
|
||||
#include "DAP_handle.h"
|
||||
#include "USB_handle.h"
|
||||
#include "USBd_config.h"
|
||||
|
||||
// attach helper function
|
||||
static int read_stage1_command(uint8_t *buffer, uint32_t length);
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
#ifndef __USBIP_SERVER_H__
|
||||
#define __USBIP_SERVER_H__
|
||||
#include <stdint.h>
|
||||
#include "usbip_defs.h"
|
||||
|
||||
#include "components/USBIP/usbip_defs.h"
|
||||
|
||||
enum state_t
|
||||
{
|
||||
ACCEPTING,
|
||||
|
|
Loading…
Reference in New Issue