Update to Chopstx 0.12
This commit is contained in:
20
ChangeLog
20
ChangeLog
@@ -1,3 +1,23 @@
|
|||||||
|
2016-05-31 NIIBE Yutaka <gniibe@fsij.org>
|
||||||
|
|
||||||
|
* src/usb-ccid.c (ccid_thread): Handle RESET->CONFIGURE process
|
||||||
|
correctly.
|
||||||
|
|
||||||
|
* polarssl/library/aes.c (FT0, FT1, FT2): Add "weak" flag.
|
||||||
|
|
||||||
|
* src/neug.c: Update from NeuG.
|
||||||
|
|
||||||
|
* src/usb_desc.c (usb_cb_get_descriptor): Only valid if USE_SYS3.
|
||||||
|
|
||||||
|
* src/Makefile.in (USE_SYS, USE_USB, USE_ADC): Enabled.
|
||||||
|
(CHIP): Add.
|
||||||
|
|
||||||
|
* src/sys.c, src/sys.h: Remove.
|
||||||
|
* src/usb_stm32f103.c, src/usb_lld.h: Remove.
|
||||||
|
* src/adc_stm32f103.c, src/adc.h: Remove.
|
||||||
|
|
||||||
|
* chopstx: Update to 0.12.
|
||||||
|
|
||||||
2016-05-21 Niibe Yutaka <gniibe@fsij.org>
|
2016-05-21 Niibe Yutaka <gniibe@fsij.org>
|
||||||
|
|
||||||
* src/main.c (led_blink, main): Fix LED blink protocol.
|
* src/main.c (led_blink, main): Fix LED blink protocol.
|
||||||
|
|||||||
2
chopstx
2
chopstx
Submodule chopstx updated: 5458b77d36...c79a41870a
@@ -179,15 +179,15 @@ static const unsigned char FSb[256] =
|
|||||||
V(CB,B0,B0,7B), V(FC,54,54,A8), V(D6,BB,BB,6D), V(3A,16,16,2C)
|
V(CB,B0,B0,7B), V(FC,54,54,A8), V(D6,BB,BB,6D), V(3A,16,16,2C)
|
||||||
|
|
||||||
#define V(a,b,c,d) 0x##a##b##c##d
|
#define V(a,b,c,d) 0x##a##b##c##d
|
||||||
const uint32_t FT0[256] __attribute__((section(".sys.0"))) = { FT };
|
const uint32_t FT0[256] __attribute__((weak,section(".sys.0"))) = { FT };
|
||||||
#undef V
|
#undef V
|
||||||
|
|
||||||
#define V(a,b,c,d) 0x##b##c##d##a
|
#define V(a,b,c,d) 0x##b##c##d##a
|
||||||
const uint32_t FT1[256] __attribute__((section(".sys.1"))) = { FT };
|
const uint32_t FT1[256] __attribute__((weak,section(".sys.1"))) = { FT };
|
||||||
#undef V
|
#undef V
|
||||||
|
|
||||||
#define V(a,b,c,d) 0x##c##d##a##b
|
#define V(a,b,c,d) 0x##c##d##a##b
|
||||||
const uint32_t FT2[256] __attribute__((section(".sys.2"))) = { FT };
|
const uint32_t FT2[256] __attribute__((weak,section(".sys.2"))) = { FT };
|
||||||
#undef V
|
#undef V
|
||||||
|
|
||||||
#define V(a,b,c,d) 0x##d##a##b##c
|
#define V(a,b,c,d) 0x##d##a##b##c
|
||||||
|
|||||||
@@ -8,15 +8,14 @@ CHOPSTX = ../chopstx
|
|||||||
# Define linker script file here
|
# Define linker script file here
|
||||||
LDSCRIPT= gnuk.ld
|
LDSCRIPT= gnuk.ld
|
||||||
|
|
||||||
CSRC = main.c usb_stm32f103.c adc_stm32f103.c \
|
CSRC = main.c usb_desc.c usb_ctrl.c \
|
||||||
usb_desc.c usb_ctrl.c \
|
|
||||||
call-rsa.c \
|
call-rsa.c \
|
||||||
usb-ccid.c openpgp.c ac.c openpgp-do.c flash.c \
|
usb-ccid.c openpgp.c ac.c openpgp-do.c flash.c \
|
||||||
bn.c mod.c \
|
bn.c mod.c \
|
||||||
modp256r1.c jpc_p256r1.c ec_p256r1.c call-ec_p256r1.c \
|
modp256r1.c jpc_p256r1.c ec_p256r1.c call-ec_p256r1.c \
|
||||||
modp256k1.c jpc_p256k1.c ec_p256k1.c call-ec_p256k1.c \
|
modp256k1.c jpc_p256k1.c ec_p256k1.c call-ec_p256k1.c \
|
||||||
mod25638.c ecc-edwards.c ecc-mont.c sha512.c \
|
mod25638.c ecc-edwards.c ecc-mont.c sha512.c \
|
||||||
random.c neug.c sha256.c sys.c
|
random.c neug.c sha256.c
|
||||||
|
|
||||||
INCDIR =
|
INCDIR =
|
||||||
|
|
||||||
@@ -46,6 +45,11 @@ ifeq ($(ENABLE_PINPAD),dnd)
|
|||||||
CSRC += usb-msc.c
|
CSRC += usb-msc.c
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
CHIP=stm32f103
|
||||||
|
USE_SYS = yes
|
||||||
|
USE_USB = yes
|
||||||
|
USE_ADC = yes
|
||||||
|
|
||||||
###################################
|
###################################
|
||||||
CROSS = arm-none-eabi-
|
CROSS = arm-none-eabi-
|
||||||
CC = $(CROSS)gcc
|
CC = $(CROSS)gcc
|
||||||
@@ -55,7 +59,7 @@ OBJCOPY = $(CROSS)objcopy
|
|||||||
MCU = cortex-m3
|
MCU = cortex-m3
|
||||||
CWARN = -Wall -Wextra -Wstrict-prototypes
|
CWARN = -Wall -Wextra -Wstrict-prototypes
|
||||||
# DEFS: Add
|
# DEFS: Add
|
||||||
DEFS = @HAVE_SYS_H@
|
DEFS = @USE_SYS3@
|
||||||
OPT = -O3 -Os -g
|
OPT = -O3 -Os -g
|
||||||
LIBS =
|
LIBS =
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
void adc_init (void);
|
|
||||||
void adc_start (void);
|
|
||||||
void adc_stop (void);
|
|
||||||
|
|
||||||
extern uint32_t adc_buf[64];
|
|
||||||
|
|
||||||
void adc_start_conversion (int offset, int count);
|
|
||||||
int adc_wait_completion (chopstx_intr_t *intr);
|
|
||||||
15
src/configure
vendored
15
src/configure
vendored
@@ -332,17 +332,18 @@ then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if test "$sys1_compat" = "no"; then
|
if test "$sys1_compat" = "no"; then
|
||||||
# Disable when you are sure that it's sys version 2.1.
|
# Disable when you are sure that it's sys version 3.0 or later.
|
||||||
# Note that Gnuk 1.0 and NeuG (until 0.06) uses sys version 1.0.
|
# Note that Gnuk 1.0 and NeuG (until 0.06) uses sys version 1.0.
|
||||||
# Disabling the compatibility, executable will be target independent,
|
# Disabling the compatibility, executable will be target independent,
|
||||||
# assuming the clock initialization will be done by SYS (before entry).
|
# assuming the clock initialization will be done by clock_init in
|
||||||
have_sys_h="-DHAVE_SYS_H"
|
# SYS.
|
||||||
|
use_sys3="-DUSE_SYS3"
|
||||||
else
|
else
|
||||||
have_sys_h=""
|
use_sys3=""
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
sed -e "s%@HAVE_SYS_H@%$have_sys_h%" \
|
sed -e "s%@USE_SYS3@%$use_sys3%" \
|
||||||
-e "s%@DEBUG_MAKE_OPTION@%$DEBUG_MAKE_OPTION%" \
|
-e "s%@DEBUG_MAKE_OPTION@%$DEBUG_MAKE_OPTION%" \
|
||||||
-e "s%@PINPAD_MAKE_OPTION@%$PINPAD_MAKE_OPTION%" \
|
-e "s%@PINPAD_MAKE_OPTION@%$PINPAD_MAKE_OPTION%" \
|
||||||
-e "s%@HEXOUTPUT_MAKE_OPTION@%$HEXOUTPUT_MAKE_OPTION%" \
|
-e "s%@HEXOUTPUT_MAKE_OPTION@%$HEXOUTPUT_MAKE_OPTION%" \
|
||||||
|
|||||||
@@ -34,10 +34,10 @@ SECTIONS
|
|||||||
KEEP(*(.sys.version))
|
KEEP(*(.sys.version))
|
||||||
KEEP(*(.sys.board_id))
|
KEEP(*(.sys.board_id))
|
||||||
KEEP(*(.sys.board_name))
|
KEEP(*(.sys.board_name))
|
||||||
build/sys.o(.text)
|
build/sys-*.o(.text)
|
||||||
build/sys.o(.text.*)
|
build/sys-*.o(.text.*)
|
||||||
build/sys.o(.rodata)
|
build/sys-*.o(.rodata)
|
||||||
build/sys.o(.rodata.*)
|
build/sys-*.o(.rodata.*)
|
||||||
. = ALIGN(1024);
|
. = ALIGN(1024);
|
||||||
*(.sys.0)
|
*(.sys.0)
|
||||||
*(.sys.1)
|
*(.sys.1)
|
||||||
|
|||||||
@@ -35,7 +35,7 @@
|
|||||||
#include "usb_lld.h"
|
#include "usb_lld.h"
|
||||||
#include "usb-cdc.h"
|
#include "usb-cdc.h"
|
||||||
#include "random.h"
|
#include "random.h"
|
||||||
#include "stm32f103.h"
|
#include "mcu/stm32f103.h"
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
15
src/neug.c
15
src/neug.c
@@ -1,7 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* neug.c - true random number generation
|
* neug.c - true random number generation
|
||||||
*
|
*
|
||||||
* Copyright (C) 2011, 2012, 2013 Free Software Initiative of Japan
|
* Copyright (C) 2011, 2012, 2013, 2016
|
||||||
|
* Free Software Initiative of Japan
|
||||||
* Author: NIIBE Yutaka <gniibe@fsij.org>
|
* Author: NIIBE Yutaka <gniibe@fsij.org>
|
||||||
*
|
*
|
||||||
* This file is a part of NeuG, a True Random Number Generator
|
* This file is a part of NeuG, a True Random Number Generator
|
||||||
@@ -28,19 +29,13 @@
|
|||||||
|
|
||||||
#include "sys.h"
|
#include "sys.h"
|
||||||
#include "neug.h"
|
#include "neug.h"
|
||||||
#include "stm32f103.h"
|
#include "mcu/stm32f103.h"
|
||||||
#include "adc.h"
|
#include "adc.h"
|
||||||
#include "sha256.h"
|
#include "sha256.h"
|
||||||
|
|
||||||
static chopstx_mutex_t mode_mtx;
|
static chopstx_mutex_t mode_mtx;
|
||||||
static chopstx_cond_t mode_cond;
|
static chopstx_cond_t mode_cond;
|
||||||
|
|
||||||
/*
|
|
||||||
* ADC finish interrupt
|
|
||||||
*/
|
|
||||||
#define INTR_REQ_DMA1_Channel1 11
|
|
||||||
|
|
||||||
|
|
||||||
static sha256_context sha256_ctx_data;
|
static sha256_context sha256_ctx_data;
|
||||||
static uint32_t sha256_output[SHA256_DIGEST_SIZE/sizeof (uint32_t)];
|
static uint32_t sha256_output[SHA256_DIGEST_SIZE/sizeof (uint32_t)];
|
||||||
|
|
||||||
@@ -574,7 +569,6 @@ static void *
|
|||||||
rng (void *arg)
|
rng (void *arg)
|
||||||
{
|
{
|
||||||
struct rng_rb *rb = (struct rng_rb *)arg;
|
struct rng_rb *rb = (struct rng_rb *)arg;
|
||||||
chopstx_intr_t adc_intr;
|
|
||||||
int mode = neug_mode;
|
int mode = neug_mode;
|
||||||
|
|
||||||
rng_should_terminate = 0;
|
rng_should_terminate = 0;
|
||||||
@@ -582,7 +576,6 @@ rng (void *arg)
|
|||||||
chopstx_cond_init (&mode_cond);
|
chopstx_cond_init (&mode_cond);
|
||||||
|
|
||||||
/* Enable ADCs */
|
/* Enable ADCs */
|
||||||
chopstx_claim_irq (&adc_intr, INTR_REQ_DMA1_Channel1);
|
|
||||||
adc_start ();
|
adc_start ();
|
||||||
|
|
||||||
ep_init (mode);
|
ep_init (mode);
|
||||||
@@ -591,7 +584,7 @@ rng (void *arg)
|
|||||||
int err;
|
int err;
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
err = adc_wait_completion (&adc_intr);
|
err = adc_wait_completion ();
|
||||||
|
|
||||||
chopstx_mutex_lock (&mode_mtx);
|
chopstx_mutex_lock (&mode_mtx);
|
||||||
if (err || mode != neug_mode)
|
if (err || mode != neug_mode)
|
||||||
|
|||||||
130
src/sys.h
130
src/sys.h
@@ -1,130 +0,0 @@
|
|||||||
#define BOARD_ID_CQ_STARM 0xc5480875
|
|
||||||
#define BOARD_ID_FST_01_00 0x613870a9
|
|
||||||
#define BOARD_ID_FST_01 0x696886af
|
|
||||||
#define BOARD_ID_MAPLE_MINI 0x7a445272
|
|
||||||
#define BOARD_ID_OLIMEX_STM32_H103 0xf92bb594
|
|
||||||
#define BOARD_ID_STBEE_MINI 0x1f341961
|
|
||||||
#define BOARD_ID_STBEE 0x945c37e8
|
|
||||||
#define BOARD_ID_STM32_PRIMER2 0x21e5798d
|
|
||||||
#define BOARD_ID_STM8S_DISCOVERY 0x2f0976bb
|
|
||||||
#define BOARD_ID_ST_DONGLE 0x2cd4e471
|
|
||||||
#define BOARD_ID_ST_NUCLEO_F103 0x9b87c16d
|
|
||||||
#define BOARD_ID_NITROKEY_START 0xad1e7ebd
|
|
||||||
|
|
||||||
extern const uint8_t sys_version[8];
|
|
||||||
extern const uint32_t sys_board_id;
|
|
||||||
extern const uint8_t sys_board_name[];
|
|
||||||
|
|
||||||
typedef void (*handler)(void);
|
|
||||||
extern handler vector[16];
|
|
||||||
|
|
||||||
static inline const uint8_t *
|
|
||||||
unique_device_id (void)
|
|
||||||
{
|
|
||||||
/* STM32F103 has 96-bit unique device identifier */
|
|
||||||
const uint8_t *addr = (const uint8_t *)0x1ffff7e8;
|
|
||||||
|
|
||||||
return addr;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void
|
|
||||||
set_led (int on)
|
|
||||||
{
|
|
||||||
void (*func) (int) = (void (*)(int))vector[2];
|
|
||||||
|
|
||||||
return (*func) (on);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void
|
|
||||||
flash_unlock (void)
|
|
||||||
{
|
|
||||||
(*vector[3]) ();
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline int
|
|
||||||
flash_program_halfword (uint32_t addr, uint16_t data)
|
|
||||||
{
|
|
||||||
int (*func) (uint32_t, uint16_t) = (int (*)(uint32_t, uint16_t))vector[4];
|
|
||||||
|
|
||||||
return (*func) (addr, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline int
|
|
||||||
flash_erase_page (uint32_t addr)
|
|
||||||
{
|
|
||||||
int (*func) (uint32_t) = (int (*)(uint32_t))vector[5];
|
|
||||||
|
|
||||||
return (*func) (addr);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline int
|
|
||||||
flash_check_blank (const uint8_t *p_start, size_t size)
|
|
||||||
{
|
|
||||||
int (*func) (const uint8_t *, int) = (int (*)(const uint8_t *, int))vector[6];
|
|
||||||
|
|
||||||
return (*func) (p_start, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline int
|
|
||||||
flash_write (uint32_t dst_addr, const uint8_t *src, size_t len)
|
|
||||||
{
|
|
||||||
int (*func) (uint32_t, const uint8_t *, size_t)
|
|
||||||
= (int (*)(uint32_t, const uint8_t *, size_t))vector[7];
|
|
||||||
|
|
||||||
return (*func) (dst_addr, src, len);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline int
|
|
||||||
flash_protect (void)
|
|
||||||
{
|
|
||||||
int (*func) (void) = (int (*)(void))vector[8];
|
|
||||||
|
|
||||||
return (*func) ();
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void __attribute__((noreturn))
|
|
||||||
flash_erase_all_and_exec (void (*entry)(void))
|
|
||||||
{
|
|
||||||
void (*func) (void (*)(void)) = (void (*)(void (*)(void)))vector[9];
|
|
||||||
|
|
||||||
(*func) (entry);
|
|
||||||
for (;;);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void
|
|
||||||
usb_lld_sys_init (void)
|
|
||||||
{
|
|
||||||
(*vector[10]) ();
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void
|
|
||||||
usb_lld_sys_shutdown (void)
|
|
||||||
{
|
|
||||||
(*vector[11]) ();
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void
|
|
||||||
nvic_system_reset (void)
|
|
||||||
{
|
|
||||||
(*vector[12]) ();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Users can override INLINE by 'attribute((used))' to have an
|
|
||||||
* implementation defined.
|
|
||||||
*/
|
|
||||||
#if !defined(INLINE)
|
|
||||||
#define INLINE __inline__
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static INLINE void
|
|
||||||
clock_init (void)
|
|
||||||
{
|
|
||||||
(*vector[13]) ();
|
|
||||||
}
|
|
||||||
|
|
||||||
static INLINE void
|
|
||||||
gpio_init (void)
|
|
||||||
{
|
|
||||||
(*vector[14]) ();
|
|
||||||
}
|
|
||||||
@@ -693,8 +693,9 @@ usb_cb_rx_ready (uint8_t ep_num)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
usb_cb_tx_done (uint8_t ep_num)
|
usb_cb_tx_done (uint8_t ep_num, uint32_t len)
|
||||||
{
|
{
|
||||||
|
(void)len;
|
||||||
if (ep_num == ENDP1)
|
if (ep_num == ENDP1)
|
||||||
EP1_IN_Callback ();
|
EP1_IN_Callback ();
|
||||||
else if (ep_num == ENDP2)
|
else if (ep_num == ENDP2)
|
||||||
@@ -1395,6 +1396,13 @@ ccid_thread (void *arg)
|
|||||||
apdu_init (a);
|
apdu_init (a);
|
||||||
ccid_init (c, epi, epo, a);
|
ccid_init (c, epi, epo, a);
|
||||||
|
|
||||||
|
while (bDeviceState != CONFIGURED)
|
||||||
|
{
|
||||||
|
chopstx_poll (NULL, 1, &interrupt);
|
||||||
|
usb_interrupt_handler ();
|
||||||
|
}
|
||||||
|
|
||||||
|
ccid.ccid_comm.flags = 0;
|
||||||
timeout = USB_ICC_TIMEOUT;
|
timeout = USB_ICC_TIMEOUT;
|
||||||
icc_prepare_receive (c);
|
icc_prepare_receive (c);
|
||||||
while (1)
|
while (1)
|
||||||
|
|||||||
@@ -38,7 +38,7 @@
|
|||||||
#include "usb_lld.h"
|
#include "usb_lld.h"
|
||||||
#include "usb_conf.h"
|
#include "usb_conf.h"
|
||||||
#include "gnuk.h"
|
#include "gnuk.h"
|
||||||
#include "stm32f103.h"
|
#include "mcu/stm32f103.h"
|
||||||
|
|
||||||
#ifdef ENABLE_VIRTUAL_COM_PORT
|
#ifdef ENABLE_VIRTUAL_COM_PORT
|
||||||
#include "usb-cdc.h"
|
#include "usb-cdc.h"
|
||||||
|
|||||||
@@ -360,6 +360,7 @@ usb_cb_get_descriptor (uint8_t rcp, uint8_t desc_type, uint8_t desc_index,
|
|||||||
return usb_lld_reply_request (string_descriptors[desc_index].desc,
|
return usb_lld_reply_request (string_descriptors[desc_index].desc,
|
||||||
string_descriptors[desc_index].size,
|
string_descriptors[desc_index].size,
|
||||||
arg);
|
arg);
|
||||||
|
#ifdef USE_SYS3
|
||||||
else if (desc_index == NUM_STRING_DESC)
|
else if (desc_index == NUM_STRING_DESC)
|
||||||
{
|
{
|
||||||
uint8_t usbbuf[64];
|
uint8_t usbbuf[64];
|
||||||
@@ -378,6 +379,7 @@ usb_cb_get_descriptor (uint8_t rcp, uint8_t desc_type, uint8_t desc_index,
|
|||||||
usbbuf[1] = STRING_DESCRIPTOR;
|
usbbuf[1] = STRING_DESCRIPTOR;
|
||||||
return usb_lld_reply_request (usbbuf, len, arg);
|
return usb_lld_reply_request (usbbuf, len, arg);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifdef HID_CARD_CHANGE_SUPPORT
|
#ifdef HID_CARD_CHANGE_SUPPORT
|
||||||
|
|||||||
118
src/usb_lld.h
118
src/usb_lld.h
@@ -1,118 +0,0 @@
|
|||||||
#define STANDARD_ENDPOINT_DESC_SIZE 0x09
|
|
||||||
|
|
||||||
/* endpoints enumeration */
|
|
||||||
#define ENDP0 ((uint8_t)0)
|
|
||||||
#define ENDP1 ((uint8_t)1)
|
|
||||||
#define ENDP2 ((uint8_t)2)
|
|
||||||
#define ENDP3 ((uint8_t)3)
|
|
||||||
#define ENDP4 ((uint8_t)4)
|
|
||||||
#define ENDP5 ((uint8_t)5)
|
|
||||||
#define ENDP6 ((uint8_t)6)
|
|
||||||
#define ENDP7 ((uint8_t)7)
|
|
||||||
|
|
||||||
/* EP_TYPE[1:0] EndPoint TYPE */
|
|
||||||
#define EP_BULK (0x0000) /* EndPoint BULK */
|
|
||||||
#define EP_CONTROL (0x0200) /* EndPoint CONTROL */
|
|
||||||
#define EP_ISOCHRONOUS (0x0400) /* EndPoint ISOCHRONOUS */
|
|
||||||
#define EP_INTERRUPT (0x0600) /* EndPoint INTERRUPT */
|
|
||||||
|
|
||||||
enum RECIPIENT_TYPE
|
|
||||||
{
|
|
||||||
DEVICE_RECIPIENT = 0, /* Recipient device */
|
|
||||||
INTERFACE_RECIPIENT, /* Recipient interface */
|
|
||||||
ENDPOINT_RECIPIENT, /* Recipient endpoint */
|
|
||||||
OTHER_RECIPIENT
|
|
||||||
};
|
|
||||||
|
|
||||||
enum DESCRIPTOR_TYPE
|
|
||||||
{
|
|
||||||
DEVICE_DESCRIPTOR = 1,
|
|
||||||
CONFIG_DESCRIPTOR,
|
|
||||||
STRING_DESCRIPTOR,
|
|
||||||
INTERFACE_DESCRIPTOR,
|
|
||||||
ENDPOINT_DESCRIPTOR
|
|
||||||
};
|
|
||||||
|
|
||||||
#define REQUEST_DIR 0x80 /* Mask to get request dir */
|
|
||||||
#define REQUEST_TYPE 0x60 /* Mask to get request type */
|
|
||||||
#define STANDARD_REQUEST 0x00 /* Standard request */
|
|
||||||
#define CLASS_REQUEST 0x20 /* Class request */
|
|
||||||
#define VENDOR_REQUEST 0x40 /* Vendor request */
|
|
||||||
#define RECIPIENT 0x1F /* Mask to get recipient */
|
|
||||||
|
|
||||||
#define USB_SETUP_SET(req) ((req & REQUEST_DIR) == 0)
|
|
||||||
#define USB_SETUP_GET(req) ((req & REQUEST_DIR) != 0)
|
|
||||||
|
|
||||||
enum
|
|
||||||
{
|
|
||||||
USB_UNSUPPORT = 0,
|
|
||||||
USB_SUCCESS = 1,
|
|
||||||
};
|
|
||||||
|
|
||||||
struct req_args {
|
|
||||||
uint16_t value;
|
|
||||||
uint16_t index;
|
|
||||||
uint16_t len;
|
|
||||||
};
|
|
||||||
|
|
||||||
void usb_cb_device_reset (void);
|
|
||||||
int usb_cb_setup (uint8_t req, uint8_t req_no, struct req_args *arg);
|
|
||||||
int usb_cb_interface (uint8_t cmd, struct req_args *arg);
|
|
||||||
int usb_cb_get_descriptor (uint8_t rcp, uint8_t desc_type, uint8_t desc_index,
|
|
||||||
struct req_args *arg);
|
|
||||||
int usb_cb_handle_event (uint8_t event_type, uint16_t value);
|
|
||||||
void usb_cb_ctrl_write_finish (uint8_t req, uint8_t req_no,
|
|
||||||
struct req_args *arg);
|
|
||||||
void usb_cb_tx_done (uint8_t ep_num);
|
|
||||||
void usb_cb_rx_ready (uint8_t ep_num);
|
|
||||||
|
|
||||||
enum {
|
|
||||||
USB_EVENT_ADDRESS,
|
|
||||||
USB_EVENT_CONFIG,
|
|
||||||
USB_EVENT_SUSPEND,
|
|
||||||
USB_EVENT_WAKEUP,
|
|
||||||
USB_EVENT_STALL,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum {
|
|
||||||
USB_SET_INTERFACE,
|
|
||||||
USB_GET_INTERFACE,
|
|
||||||
USB_QUERY_INTERFACE,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum DEVICE_STATE
|
|
||||||
{
|
|
||||||
UNCONNECTED,
|
|
||||||
ATTACHED,
|
|
||||||
POWERED,
|
|
||||||
SUSPENDED,
|
|
||||||
ADDRESSED,
|
|
||||||
CONFIGURED
|
|
||||||
};
|
|
||||||
|
|
||||||
void usb_lld_init (uint8_t feature);
|
|
||||||
void usb_lld_to_pmabuf (const void *src, uint16_t addr, size_t n);
|
|
||||||
void usb_lld_from_pmabuf (void *dst, uint16_t addr, size_t n);
|
|
||||||
void usb_lld_stall_tx (int ep_num);
|
|
||||||
void usb_lld_stall_rx (int ep_num);
|
|
||||||
int usb_lld_tx_data_len (int ep_num);
|
|
||||||
void usb_lld_txcpy (const void *src, int ep_num, int offset, size_t len);
|
|
||||||
void usb_lld_tx_enable (int ep_num, size_t len);
|
|
||||||
void usb_lld_write (uint8_t ep_num, const void *buf, size_t len);
|
|
||||||
int usb_lld_reply_request (const void *buf, size_t buflen,
|
|
||||||
struct req_args *arg);
|
|
||||||
void usb_lld_rx_enable (int ep_num);
|
|
||||||
int usb_lld_rx_data_len (int ep_num);
|
|
||||||
void usb_lld_rxcpy (uint8_t *dst, int ep_num, int offset, size_t len);
|
|
||||||
void usb_lld_reset (uint8_t feature);
|
|
||||||
void usb_lld_setup_endpoint (int ep_num, int ep_type, int ep_kind,
|
|
||||||
int ep_rx_addr, int ep_tx_addr,
|
|
||||||
int ep_rx_memory_size);
|
|
||||||
void usb_lld_set_configuration (uint8_t config);
|
|
||||||
uint8_t usb_lld_current_configuration (void);
|
|
||||||
void usb_lld_set_data_to_recv (void *p, size_t len);
|
|
||||||
|
|
||||||
void usb_lld_prepare_shutdown (void);
|
|
||||||
void usb_lld_shutdown (void);
|
|
||||||
|
|
||||||
void usb_interrupt_handler (void);
|
|
||||||
Reference in New Issue
Block a user