Skip to content

Commit

Permalink
[USB] 取消XDATA绝对地址,微调接受UART数据时候的校验流程
Browse files Browse the repository at this point in the history
  • Loading branch information
jim-kirisame committed Mar 16, 2020
1 parent 9a1c632 commit d8c2fb9
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 33 deletions.
8 changes: 4 additions & 4 deletions usb/endpoints.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,25 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
* 0x80-0xBF 端点4 IN
*
*/
uint8_t __XDATA_AT(0x00) Ep0Buffer[MAX_PACKET_SIZE * 3];
volatile uint8_t __XDATA Ep0Buffer[MAX_PACKET_SIZE * 3];
/**
* @brief 端点1缓冲区,用于键盘报文
*
* 地址0x88-0xC7为端点1OUT缓冲区 (实际使用1byte)
* 地址0xC8-0xCF为端点1IN缓冲区 (8byte)
*
*/
uint8_t __XDATA_AT(0xC0) Ep1Buffer[MAX_PACKET_SIZE * 2]; //端点1 IN缓冲区,必须是偶地址
volatile uint8_t __XDATA Ep1Buffer[MAX_PACKET_SIZE * 2]; //端点1 IN缓冲区,必须是偶地址
/**
* @brief 端点2IN缓冲区,用于System包和Consumer包的发送
*
*/
uint8_t __XDATA_AT(0x140) Ep2Buffer[MAX_PACKET_SIZE];
volatile uint8_t __XDATA Ep2Buffer[MAX_PACKET_SIZE];
/**
* @brief 端点3IN&OUT缓冲区,用于传递配置
*
*/
uint8_t __XDATA_AT(0x180) Ep3Buffer[MAX_PACKET_SIZE * 2]; //端点3 IN缓冲区,必须是偶地址
volatile uint8_t __XDATA Ep3Buffer[MAX_PACKET_SIZE * 2]; //端点3 IN缓冲区,必须是偶地址

static uint8_t DataInLen, UsbConfig, UsbAddr;
static uint8_t* pDataIn;
Expand Down
8 changes: 4 additions & 4 deletions usb/endpoints.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
#include <stdbool.h>
#include <stdint.h>

extern uint8_t __XDATA_AT(0x00) Ep0Buffer[];
extern uint8_t __XDATA_AT(0xc0) Ep1Buffer[];
extern uint8_t __XDATA_AT(0x140) Ep2Buffer[];
extern uint8_t __XDATA_AT(0x180) Ep3Buffer[];
extern volatile uint8_t __XDATA Ep0Buffer[];
extern volatile uint8_t __XDATA Ep1Buffer[];
extern volatile uint8_t __XDATA Ep2Buffer[];
extern volatile uint8_t __XDATA Ep3Buffer[];

enum UsbSetupState {
SETUP_IDLE, // 当前处于空闲状态
Expand Down
43 changes: 20 additions & 23 deletions usb/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.

uart_state uart_rx_state;
static uint8_t recv_len, pos;
static uint8_t __XDATA recv_buff[64];
static uint8_t __XDATA keyboard_buffer[8];
static uint8_t __XDATA volatile recv_buff[64];

static bool uart_arrive_flag, last_success;
static uint8_t last_pos;
Expand Down Expand Up @@ -97,31 +96,29 @@ void uart_init()
*/
static void uart_data_parser(void)
{
if (checksum(recv_buff, recv_len - 1) != recv_buff[recv_len - 1]) {
// 不做任何事情,等待下次重发
return;
}

uint8_t command = recv_buff[0];
if (command >= 0x80) {
if (checksum(recv_buff, recv_len - 1) == recv_buff[recv_len - 1]) {
// 通信响应数据包
uint8_t datalen = command & 0x7F;
ResponseConfigurePacket(&recv_buff[1], datalen);
last_success = true;
}
// 通信响应数据包
uint8_t datalen = command & 0x7F;
ResponseConfigurePacket(&recv_buff[1], datalen);
last_success = true;
} else if (command >= 0x40) {
uint8_t index = recv_buff[1];
uint8_t kplen = (command & 0x3F);
if (checksum(recv_buff, recv_len - 1) == recv_buff[recv_len - 1]) {
if (index == 0) {
// 通常键盘数据包
memcpy(keyboard_buffer, &recv_buff[2], 8);
KeyboardGenericUpload(keyboard_buffer, kplen);
last_success = true;
} else if (index == 1 || index == 2 || index == 3 || index == 0x80) {
// system, consumer, mouse数据包
// 发过来的包的id和reportID一致,不用处理
KeyboardExtraUpload(&recv_buff[1], kplen + 1);
last_success = true;
}
} else {
// 不做任何事情,等待下次重发
if (index == 0) {
// 通常键盘数据包
KeyboardGenericUpload(&recv_buff[2], kplen);
last_success = true;
} else if (index == 1 || index == 2 || index == 3 || index == 0x80) {
// system, consumer, mouse数据包
// 发过来的包的id和reportID一致,不用处理
KeyboardExtraUpload(&recv_buff[1], kplen + 1);
last_success = true;
}
}
}
Expand All @@ -144,7 +141,7 @@ static void uart_send_status()
uart_tx(data);
}

static uint8_t __XDATA send_buff[64];
static uint8_t volatile __XDATA send_buff[64];
static uint8_t send_len = 0;

/**
Expand Down
4 changes: 2 additions & 2 deletions usb/usb.mk
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ endif

SDCC := sdcc
SDCC_CFLAGS += -mmcs51 --model-small --stack-auto --std-c11 -o $(OBJ_DIR)/ --opt-code-size -I .
SDCC_LDFLAGS := --xram-size 1024 --iram-size 256 --code-size 14336 --out-fmt-ihx
SDCC_LDFLAGS := --xram-size 1024 --iram-size 256 --code-size 14336 --out-fmt-ihx --xram-loc 0

USB_SOURCES := $(USB_SOURCE_DIR)/main.c \
$(USB_SOURCE_DIR)/endpoints.c \
$(USB_SOURCE_DIR)/system.c \
$(USB_SOURCE_DIR)/uart.c \
$(USB_SOURCE_DIR)/interrupt.c \
$(USB_SOURCE_DIR)/endpoints.c \
$(USB_SOURCE_DIR)/descriptor.c \

ifeq (yes,$(strip $(ONBOARD_CMSIS_DAP)))
Expand Down

0 comments on commit d8c2fb9

Please sign in to comment.