clean up USB API

This commit is contained in:
NIIBE Yutaka
2012-01-16 12:17:45 +09:00
parent 27277e56ee
commit 00541d7627
6 changed files with 78 additions and 23 deletions

View File

@@ -1,3 +1,24 @@
2012-01-16 Niibe Yutaka <gniibe@fsij.org>
Adopt new API.
* src/usb-icc.c (EP1_IN_Callback, icc_error, icc_power_on)
(icc_send_status, icc_send_data_block, icc_send_params): Use
usb_lld_write (was: USB_SIL_Write).
(EP2_OUT_Callback): Use usb_lld_get_data_len, usb_lld_rxcpy,
and usb_lld_rx_enable (was: USB_SIL_Read and SetEPRxValid).
(icc_prepare_receive): Use usb_lld_rx_enable.
* src/stmusb.mk (STMUSBSRC): Dont' include usb_sil.c.
* src/usb_lld.h (usb_lld_txcpy, usb_lld_tx_enable)
(usb_lld_write, usb_lld_rx_enable, usb_lld_get_data_len)
(usb_lld_rxcpy): New.
* src/usb_prop.c (SetEPRxCount_allocated_size): Fix the
implementation. (ST's SetEPRxCount is actually meant to
setup allocated size, which is confusing).
(gnuk_device_init): Don't call USB_SIL_Init.
2012-01-10 Niibe Yutaka <gniibe@fsij.org>
* src/openpgp.c (GPGthread): Allow INS_RESET_RETRY_COUNTER and

View File

@@ -1,7 +1,7 @@
STMUSBDIR = ../STM32_USB-FS-Device_Driver
STMUSBSRCDIR = $(STMUSBDIR)/src
STMUSBINCDIR = $(STMUSBDIR)/inc
STMUSBSRC= $(STMUSBSRCDIR)/usb_sil.c \
STMUSBSRC= \
$(STMUSBSRCDIR)/usb_init.c $(STMUSBSRCDIR)/usb_int.c \
$(STMUSBSRCDIR)/usb_mem.c $(STMUSBSRCDIR)/usb_core.c \
$(STMUSBSRCDIR)/usb_regs.c

View File

@@ -29,6 +29,7 @@
#include "usb_mem.h"
#include "hw_config.h"
#include "usb_istr.h"
#include "usb_lld.h"
#define ICC_SET_PARAMS 0x61 /* non-ICCD command */
#define ICC_POWER_ON 0x62
@@ -131,8 +132,7 @@ EP1_IN_Callback (void)
{
/* Send the last 0-DATA transcation of Bulk-IN in the transactions */
icc_next_p = NULL;
USB_SIL_Write (EP1_IN, icc_buffer, 0);
SetEPTxValid (ENDP1);
usb_lld_write (ENDP1, icc_buffer, 0);
}
else
{
@@ -146,8 +146,7 @@ EP1_IN_Callback (void)
tx_size = &icc_buffer[icc_tx_size] - p;
}
USB_SIL_Write (EP1_IN, p, tx_size);
SetEPTxValid (ENDP1);
usb_lld_write (ENDP1, p, tx_size);
}
}
@@ -159,7 +158,7 @@ icc_prepare_receive (int chain)
else
icc_next_p = icc_buffer;
SetEPRxValid (ENDP2);
usb_lld_rx_enable (ENDP2);
}
/*
@@ -173,10 +172,11 @@ EP2_OUT_Callback (void)
int data_len_so_far;
int data_len;
len = USB_SIL_Read (EP2_OUT, icc_next_p);
len = usb_lld_get_data_len (ENDP2);
usb_lld_rxcpy (icc_next_p, ENDP2, 0, len);
if (len == 0)
{ /* Just ignore Zero Length Packet (ZLP), if any */
SetEPRxValid (ENDP2);
usb_lld_rx_enable (ENDP2);
return;
}
@@ -194,7 +194,7 @@ EP2_OUT_Callback (void)
&& data_len != data_len_so_far)
/* The sequence of transactions continues */
{
SetEPRxValid (ENDP2);
usb_lld_rx_enable (ENDP2);
if ((icc_next_p - icc_buffer) >= USB_BUF_SIZE)
/* No room to receive any more */
{
@@ -298,8 +298,7 @@ icc_error (int offset)
icc_next_p = NULL; /* This is a single transaction Bulk-IN */
icc_tx_size = ICC_MSG_HEADER_SIZE;
USB_SIL_Write (EP1_IN, icc_reply, icc_tx_size);
SetEPTxValid (ENDP1);
usb_lld_write (ENDP1, icc_reply, icc_tx_size);
}
static Thread *gpg_thread;
@@ -332,8 +331,7 @@ icc_power_on (void)
icc_next_p = NULL; /* This is a single transaction Bulk-IN */
icc_tx_size = ICC_MSG_HEADER_SIZE + size_atr;
USB_SIL_Write (EP1_IN, icc_buffer, icc_tx_size);
SetEPTxValid (ENDP1);
usb_lld_write (ENDP1, icc_buffer, icc_tx_size);
DEBUG_INFO ("ON\r\n");
return ICC_STATE_WAIT;
@@ -367,8 +365,7 @@ icc_send_status (void)
icc_next_p = NULL; /* This is a single transaction Bulk-IN */
icc_tx_size = ICC_MSG_HEADER_SIZE;
USB_SIL_Write (EP1_IN, icc_reply, icc_tx_size);
SetEPTxValid (ENDP1);
usb_lld_write (ENDP1, icc_reply, icc_tx_size);
#ifdef DEBUG_MORE
DEBUG_INFO ("St\r\n");
@@ -428,8 +425,7 @@ icc_send_data_block (int len, uint8_t status, uint8_t chain)
else
icc_next_p = p + USB_LL_BUF_SIZE;
USB_SIL_Write (EP1_IN, p, tx_size);
SetEPTxValid (ENDP1);
usb_lld_write (ENDP1, p, tx_size);
#ifdef DEBUG_MORE
DEBUG_INFO ("DATA\r\n");
#endif
@@ -458,8 +454,7 @@ icc_send_params (void)
icc_next_p = NULL; /* This is a single transaction Bulk-IN */
icc_tx_size = ICC_MSG_HEADER_SIZE + 7;
USB_SIL_Write (EP1_IN, icc_buffer, icc_tx_size);
SetEPTxValid (ENDP1);
usb_lld_write (ENDP1, icc_buffer, icc_tx_size);
#ifdef DEBUG_MORE
DEBUG_INFO ("DATA\r\n");
#endif

View File

@@ -1,5 +1,6 @@
#include "ch.h"
#include "hal.h"
#include "usb_lib.h"
#include "usb_lld.h"
extern void USB_Istr (void);

View File

@@ -1,2 +1,37 @@
#define STM32_USB_IRQ_PRIORITY 11
void usb_lld_init (void);
extern inline void usb_lld_txcpy (const uint8_t *src,
int ep_num, int offset, size_t len)
{
UserToPMABufferCopy ((uint8_t *)src, GetEPTxAddr (ep_num) + offset, len);
}
extern inline void usb_lld_tx_enable (int ep_num, size_t len)
{
SetEPTxCount (ep_num, len);
SetEPTxValid (ep_num);
}
extern inline void usb_lld_write (uint8_t ep_num, void *buf, size_t len)
{
UserToPMABufferCopy (buf, GetEPTxAddr (ep_num), len);
SetEPTxCount (ep_num, len);
SetEPTxValid (ep_num);
}
extern inline void usb_lld_rx_enable (int ep_num)
{
SetEPRxValid (ep_num);
}
extern inline int usb_lld_get_data_len (int ep_num)
{
return GetEPRxCount (ep_num);
}
extern inline void usb_lld_rxcpy (uint8_t *dst,
int ep_num, int offset, size_t len)
{
PMAToUserBufferCopy (dst, GetEPRxAddr (ep_num) + offset, len);
}

View File

@@ -41,17 +41,18 @@
#endif
void
static void
SetEPRxCount_allocated_size (uint8_t bEpNum, uint16_t wCount)
{ /* Assume wCount is even */
uint32_t *pdwReg = _pEPRxCount (bEpNum);
uint16_t value;
if (wCount < 62)
if (wCount <= 62)
value = (wCount & 0x3e) << 9;
else
value = 0x8000 | (((wCount >> 5) - 1) << 10);
SetEPRxCount (bEpNum, value);
*pdwReg = (uint32_t)value;
}
static void
@@ -63,7 +64,9 @@ gnuk_device_init (void)
PowerOn ();
/* Perform basic device initialization operations */
USB_SIL_Init ();
_SetISTR (0);
wInterrupt_Mask = IMR_MSK;
_SetCNTR (wInterrupt_Mask);
bDeviceState = UNCONNECTED;
}