Gnuk change to support reGNUal
This commit is contained in:
15
ChangeLog
15
ChangeLog
@@ -1,3 +1,18 @@
|
|||||||
|
2012-05-22 Niibe Yutaka <gniibe@fsij.org>
|
||||||
|
|
||||||
|
* src/usb_lld.c: Support FREE_STANDING environment as well as
|
||||||
|
under ChibiOS/RT.
|
||||||
|
(usb_lld_init): Call usb_lld_sys_init. Don't call user defined
|
||||||
|
method. Call usb_lld_set_configuration.
|
||||||
|
(usb_lld_shutdown): Call usb_lld_sys_shutdown.
|
||||||
|
(Vector90): Move to usb_lld_sys.c.
|
||||||
|
(usb_interrupt_handler): Export to global.
|
||||||
|
|
||||||
|
* src/usb_lld_sys.c: New.
|
||||||
|
|
||||||
|
* src/usb_prop.c (Device_Method): Remove gnuk_device_init.
|
||||||
|
(gnuk_device_init): Remove.
|
||||||
|
|
||||||
2012-05-19 Niibe Yutaka <gniibe@fsij.org>
|
2012-05-19 Niibe Yutaka <gniibe@fsij.org>
|
||||||
|
|
||||||
* src/usb_lld.c (handle_datastage_in): Bug fix, erable RX when
|
* src/usb_lld.c (handle_datastage_in): Bug fix, erable RX when
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ CSRC = $(PORTSRC) \
|
|||||||
$(CHIBIOS)/os/various/evtimer.c \
|
$(CHIBIOS)/os/various/evtimer.c \
|
||||||
$(CHIBIOS)/os/various/syscalls.c \
|
$(CHIBIOS)/os/various/syscalls.c \
|
||||||
$(CRYPTSRC) \
|
$(CRYPTSRC) \
|
||||||
main.c usb_lld.c \
|
main.c usb_lld.c usb_lld_sys.c \
|
||||||
usb_desc.c usb_prop.c \
|
usb_desc.c usb_prop.c \
|
||||||
usb-icc.c openpgp.c ac.c openpgp-do.c flash.c \
|
usb-icc.c openpgp.c ac.c openpgp-do.c flash.c \
|
||||||
random.c neug.c
|
random.c neug.c
|
||||||
|
|||||||
122
src/usb_lld.c
122
src/usb_lld.c
@@ -1,5 +1,10 @@
|
|||||||
|
#ifdef FREE_STANDING
|
||||||
|
#include "types.h"
|
||||||
|
#else
|
||||||
#include "ch.h"
|
#include "ch.h"
|
||||||
#include "hal.h"
|
#include "hal.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "usb_lld.h"
|
#include "usb_lld.h"
|
||||||
|
|
||||||
#define USB_MAX_PACKET_SIZE 64 /* For FS device */
|
#define USB_MAX_PACKET_SIZE 64 /* For FS device */
|
||||||
@@ -66,9 +71,15 @@ struct DEVICE_INFO
|
|||||||
uint8_t state;
|
uint8_t state;
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct CONTROL_INFO *ctrl_p;
|
static struct CONTROL_INFO control_info;
|
||||||
static struct DEVICE_INFO *dev_p;
|
static struct DEVICE_INFO device_info;
|
||||||
static struct DATA_INFO *data_p;
|
static struct DATA_INFO data_info;
|
||||||
|
extern const struct usb_device_method Device_Method;
|
||||||
|
|
||||||
|
static struct CONTROL_INFO *const ctrl_p = &control_info;
|
||||||
|
static struct DEVICE_INFO *const dev_p = &device_info;
|
||||||
|
static struct DATA_INFO *const data_p = &data_info;
|
||||||
|
static const struct usb_device_method *const method_p = &Device_Method;
|
||||||
|
|
||||||
#define REG_BASE (0x40005C00UL) /* USB_IP Peripheral Registers base address */
|
#define REG_BASE (0x40005C00UL) /* USB_IP Peripheral Registers base address */
|
||||||
#define PMA_ADDR (0x40006000UL) /* USB_IP Packet Memory Area base address */
|
#define PMA_ADDR (0x40006000UL) /* USB_IP Packet Memory Area base address */
|
||||||
@@ -347,9 +358,36 @@ static void st103_ep_clear_dtog_tx (uint8_t ep_num)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct usb_device_method* method_p;
|
void usb_lld_init (void)
|
||||||
|
{
|
||||||
|
usb_lld_sys_init ();
|
||||||
|
|
||||||
static void
|
dev_p->state = IN_DATA;
|
||||||
|
|
||||||
|
usb_lld_set_configuration (0);
|
||||||
|
|
||||||
|
/* Reset USB */
|
||||||
|
st103_set_cntr (CNTR_FRES);
|
||||||
|
st103_set_cntr (0);
|
||||||
|
|
||||||
|
/* Clear Interrupt Status Register, and enable interrupt for USB */
|
||||||
|
st103_set_istr (0);
|
||||||
|
st103_set_cntr (CNTR_CTRM | CNTR_RESETM);
|
||||||
|
}
|
||||||
|
|
||||||
|
void usb_lld_prepare_shutdown (void)
|
||||||
|
{
|
||||||
|
st103_set_istr (0);
|
||||||
|
st103_set_cntr (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void usb_lld_shutdown (void)
|
||||||
|
{
|
||||||
|
st103_set_cntr (CNTR_PDWN);
|
||||||
|
usb_lld_sys_shutdown ();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
usb_interrupt_handler (void)
|
usb_interrupt_handler (void)
|
||||||
{
|
{
|
||||||
uint16_t istr_value = st103_get_istr ();
|
uint16_t istr_value = st103_get_istr ();
|
||||||
@@ -370,16 +408,6 @@ usb_interrupt_handler (void)
|
|||||||
st103_set_istr (CLR_ERR);
|
st103_set_istr (CLR_ERR);
|
||||||
}
|
}
|
||||||
|
|
||||||
CH_IRQ_HANDLER (Vector90) {
|
|
||||||
CH_IRQ_PROLOGUE();
|
|
||||||
chSysLockFromIsr();
|
|
||||||
|
|
||||||
usb_interrupt_handler ();
|
|
||||||
|
|
||||||
chSysUnlockFromIsr();
|
|
||||||
CH_IRQ_EPILOGUE();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void handle_datastage_out (void)
|
static void handle_datastage_out (void)
|
||||||
{
|
{
|
||||||
if (data_p->addr && data_p->len)
|
if (data_p->addr && data_p->len)
|
||||||
@@ -903,7 +931,7 @@ static void nop_proc (void)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
#define WEAK __attribute__ ((weak))
|
#define WEAK __attribute__ ((weak, alias ("nop_proc")))
|
||||||
void WEAK EP1_IN_Callback (void);
|
void WEAK EP1_IN_Callback (void);
|
||||||
void WEAK EP2_IN_Callback (void);
|
void WEAK EP2_IN_Callback (void);
|
||||||
void WEAK EP3_IN_Callback (void);
|
void WEAK EP3_IN_Callback (void);
|
||||||
@@ -920,22 +948,6 @@ void WEAK EP5_OUT_Callback (void);
|
|||||||
void WEAK EP6_OUT_Callback (void);
|
void WEAK EP6_OUT_Callback (void);
|
||||||
void WEAK EP7_OUT_Callback (void);
|
void WEAK EP7_OUT_Callback (void);
|
||||||
|
|
||||||
#pragma weak EP1_IN_Callback = nop_proc
|
|
||||||
#pragma weak EP2_IN_Callback = nop_proc
|
|
||||||
#pragma weak EP3_IN_Callback = nop_proc
|
|
||||||
#pragma weak EP4_IN_Callback = nop_proc
|
|
||||||
#pragma weak EP5_IN_Callback = nop_proc
|
|
||||||
#pragma weak EP6_IN_Callback = nop_proc
|
|
||||||
#pragma weak EP7_IN_Callback = nop_proc
|
|
||||||
|
|
||||||
#pragma weak EP1_OUT_Callback = nop_proc
|
|
||||||
#pragma weak EP2_OUT_Callback = nop_proc
|
|
||||||
#pragma weak EP3_OUT_Callback = nop_proc
|
|
||||||
#pragma weak EP4_OUT_Callback = nop_proc
|
|
||||||
#pragma weak EP5_OUT_Callback = nop_proc
|
|
||||||
#pragma weak EP6_OUT_Callback = nop_proc
|
|
||||||
#pragma weak EP7_OUT_Callback = nop_proc
|
|
||||||
|
|
||||||
void (*const ep_intr_handler_IN[7]) (void) = {
|
void (*const ep_intr_handler_IN[7]) (void) = {
|
||||||
EP1_IN_Callback,
|
EP1_IN_Callback,
|
||||||
EP2_IN_Callback,
|
EP2_IN_Callback,
|
||||||
@@ -1018,58 +1030,12 @@ usb_handle_transfer (void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct CONTROL_INFO Control_Info;
|
|
||||||
static struct DEVICE_INFO Device_Info;
|
|
||||||
static struct DATA_INFO Data_Info;
|
|
||||||
|
|
||||||
void usb_lld_reset (void)
|
void usb_lld_reset (void)
|
||||||
{
|
{
|
||||||
st103_set_btable ();
|
st103_set_btable ();
|
||||||
st103_set_daddr (0);
|
st103_set_daddr (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void usb_lld_init (void)
|
|
||||||
{
|
|
||||||
RCC->APB1ENR |= RCC_APB1ENR_USBEN;
|
|
||||||
NVICEnableVector (USB_LP_CAN1_RX0_IRQn,
|
|
||||||
CORTEX_PRIORITY_MASK (STM32_USB_IRQ_PRIORITY));
|
|
||||||
/*
|
|
||||||
* Note that we also have other IRQ(s):
|
|
||||||
* USB_HP_CAN1_TX_IRQn (for double-buffered or isochronous)
|
|
||||||
* USBWakeUp_IRQn (suspend/resume)
|
|
||||||
*/
|
|
||||||
RCC->APB1RSTR = RCC_APB1RSTR_USBRST;
|
|
||||||
RCC->APB1RSTR = 0;
|
|
||||||
|
|
||||||
dev_p = &Device_Info;
|
|
||||||
ctrl_p = &Control_Info;
|
|
||||||
data_p = &Data_Info;
|
|
||||||
dev_p->state = IN_DATA;
|
|
||||||
method_p = &Device_Method;
|
|
||||||
|
|
||||||
method_p->init();
|
|
||||||
|
|
||||||
/* Reset USB */
|
|
||||||
st103_set_cntr (CNTR_FRES);
|
|
||||||
st103_set_cntr (0);
|
|
||||||
|
|
||||||
/* Clear Interrupt Status Register, and enable interrupt for USB */
|
|
||||||
st103_set_istr (0);
|
|
||||||
st103_set_cntr (CNTR_CTRM | CNTR_RESETM);
|
|
||||||
}
|
|
||||||
|
|
||||||
void usb_lld_prepare_shutdown (void)
|
|
||||||
{
|
|
||||||
st103_set_istr (0);
|
|
||||||
st103_set_cntr (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void usb_lld_shutdown (void)
|
|
||||||
{
|
|
||||||
st103_set_cntr (CNTR_PDWN);
|
|
||||||
RCC->APB1ENR &= ~RCC_APB1ENR_USBEN;
|
|
||||||
}
|
|
||||||
|
|
||||||
void usb_lld_txcpy (const void *src,
|
void usb_lld_txcpy (const void *src,
|
||||||
int ep_num, int offset, size_t len)
|
int ep_num, int offset, size_t len)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -63,7 +63,6 @@ enum
|
|||||||
|
|
||||||
struct usb_device_method
|
struct usb_device_method
|
||||||
{
|
{
|
||||||
void (*init) (void);
|
|
||||||
void (*reset) (void);
|
void (*reset) (void);
|
||||||
void (*ctrl_write_finish) (uint8_t req, uint8_t req_no,
|
void (*ctrl_write_finish) (uint8_t req, uint8_t req_no,
|
||||||
uint16_t value, uint16_t index, uint16_t len);
|
uint16_t value, uint16_t index, uint16_t len);
|
||||||
@@ -155,3 +154,8 @@ extern inline void usb_lld_set_data_to_recv (void *p, size_t len)
|
|||||||
|
|
||||||
extern void usb_lld_prepare_shutdown (void);
|
extern void usb_lld_prepare_shutdown (void);
|
||||||
extern void usb_lld_shutdown (void);
|
extern void usb_lld_shutdown (void);
|
||||||
|
|
||||||
|
extern void usb_interrupt_handler (void);
|
||||||
|
|
||||||
|
extern void usb_lld_sys_init (void);
|
||||||
|
extern void usb_lld_sys_shutdown (void);
|
||||||
|
|||||||
34
src/usb_lld_sys.c
Normal file
34
src/usb_lld_sys.c
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
#include "ch.h"
|
||||||
|
#include "hal.h"
|
||||||
|
#include "usb_lld.h"
|
||||||
|
|
||||||
|
CH_IRQ_HANDLER (Vector90) {
|
||||||
|
CH_IRQ_PROLOGUE();
|
||||||
|
chSysLockFromIsr();
|
||||||
|
|
||||||
|
usb_interrupt_handler ();
|
||||||
|
|
||||||
|
chSysUnlockFromIsr();
|
||||||
|
CH_IRQ_EPILOGUE();
|
||||||
|
}
|
||||||
|
|
||||||
|
void usb_lld_sys_init (void)
|
||||||
|
{
|
||||||
|
RCC->APB1ENR |= RCC_APB1ENR_USBEN;
|
||||||
|
NVICEnableVector (USB_LP_CAN1_RX0_IRQn,
|
||||||
|
CORTEX_PRIORITY_MASK (STM32_USB_IRQ_PRIORITY));
|
||||||
|
/*
|
||||||
|
* Note that we also have other IRQ(s):
|
||||||
|
* USB_HP_CAN1_TX_IRQn (for double-buffered or isochronous)
|
||||||
|
* USBWakeUp_IRQn (suspend/resume)
|
||||||
|
*/
|
||||||
|
RCC->APB1RSTR = RCC_APB1RSTR_USBRST;
|
||||||
|
RCC->APB1RSTR = 0;
|
||||||
|
|
||||||
|
USB_Cable_Config (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void usb_lld_sys_shutdown (void)
|
||||||
|
{
|
||||||
|
RCC->APB1ENR &= ~RCC_APB1ENR_USBEN;
|
||||||
|
}
|
||||||
@@ -91,14 +91,6 @@ vcom_port_data_setup (uint8_t req, uint8_t req_no)
|
|||||||
|
|
||||||
uint32_t bDeviceState = UNCONNECTED; /* USB device status */
|
uint32_t bDeviceState = UNCONNECTED; /* USB device status */
|
||||||
|
|
||||||
static void
|
|
||||||
gnuk_device_init (void)
|
|
||||||
{
|
|
||||||
usb_lld_set_configuration (0);
|
|
||||||
USB_Cable_Config (1);
|
|
||||||
bDeviceState = UNCONNECTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gnuk_setup_endpoints_for_interface (uint16_t interface, int stop)
|
gnuk_setup_endpoints_for_interface (uint16_t interface, int stop)
|
||||||
{
|
{
|
||||||
@@ -423,7 +415,6 @@ static int gnuk_interface (uint8_t cmd, uint16_t interface, uint16_t alt)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
const struct usb_device_method Device_Method = {
|
const struct usb_device_method Device_Method = {
|
||||||
gnuk_device_init,
|
|
||||||
gnuk_device_reset,
|
gnuk_device_reset,
|
||||||
gnuk_ctrl_write_finish,
|
gnuk_ctrl_write_finish,
|
||||||
gnuk_setup,
|
gnuk_setup,
|
||||||
|
|||||||
Reference in New Issue
Block a user