aboutsummaryrefslogtreecommitdiffstats
path: root/libmaple
diff options
context:
space:
mode:
Diffstat (limited to 'libmaple')
-rw-r--r--libmaple/usb/usb.c37
-rw-r--r--libmaple/usb/usb.h3
2 files changed, 18 insertions, 22 deletions
diff --git a/libmaple/usb/usb.c b/libmaple/usb/usb.c
index 6a22cdf..ec189d6 100644
--- a/libmaple/usb/usb.c
+++ b/libmaple/usb/usb.c
@@ -49,7 +49,6 @@ static void dispatch_ctr_lp(void);
* usb_lib/ globals
*/
-volatile uint16 wIstr = 0; /* most recently read value of wIstr */
uint16 SaveTState; /* caches TX status for later use */
uint16 SaveRState; /* caches RX status for later use */
@@ -57,8 +56,6 @@ uint16 SaveRState; /* caches RX status for later use */
* Other state
*/
-volatile uint32 bIntPackSOF = 0;
-
struct {
volatile RESUME_STATE eState;
volatile uint8 bESOFcnt;
@@ -168,38 +165,38 @@ void usbResume(RESUME_STATE eResumeSetVal) {
#define SUSPEND_ENABLED 1
void __irq_usb_lp_can_rx0(void) {
- wIstr = USB_BASE->ISTR;
+ uint16 istr = USB_BASE->ISTR;
/* Use USB_ISR_MSK to only include code for bits we care about. */
#if (USB_ISR_MSK & USB_ISTR_RESET)
- if (wIstr & USB_ISTR_RESET & USBLIB->irq_mask) {
+ if (istr & USB_ISTR_RESET & USBLIB->irq_mask) {
USB_BASE->ISTR = ~USB_ISTR_RESET;
pProperty->Reset();
}
#endif
#if (USB_ISR_MSK & USB_ISTR_PMAOVR)
- if (wIstr & ISTR_PMAOVR & USBLIB->irq_mask) {
+ if (istr & ISTR_PMAOVR & USBLIB->irq_mask) {
USB_BASE->ISTR = ~USB_ISTR_PMAOVR;
}
#endif
#if (USB_ISR_MSK & USB_ISTR_ERR)
- if (wIstr & USB_ISTR_ERR & USBLIB->irq_mask) {
+ if (istr & USB_ISTR_ERR & USBLIB->irq_mask) {
USB_BASE->ISTR = ~USB_ISTR_ERR;
}
#endif
#if (USB_ISR_MSK & USB_ISTR_WKUP)
- if (wIstr & USB_ISTR_WKUP & USBLIB->irq_mask) {
+ if (istr & USB_ISTR_WKUP & USBLIB->irq_mask) {
USB_BASE->ISTR = ~USB_ISTR_WKUP;
usbResume(RESUME_EXTERNAL);
}
#endif
#if (USB_ISR_MSK & USB_ISTR_SUSP)
- if (wIstr & USB_ISTR_SUSP & USBLIB->irq_mask) {
+ if (istr & USB_ISTR_SUSP & USBLIB->irq_mask) {
/* check if SUSPEND is possible */
if (SUSPEND_ENABLED) {
usbSuspend();
@@ -213,14 +210,13 @@ void __irq_usb_lp_can_rx0(void) {
#endif
#if (USB_ISR_MSK & USB_ISTR_SOF)
- if (wIstr & USB_ISTR_SOF & USBLIB->irq_mask) {
+ if (istr & USB_ISTR_SOF & USBLIB->irq_mask) {
USB_BASE->ISTR = ~USB_ISTR_SOF;
- bIntPackSOF++;
}
#endif
#if (USB_ISR_MSK & USB_ISTR_ESOF)
- if (wIstr & USB_ISTR_ESOF & USBLIB->irq_mask) {
+ if (istr & USB_ISTR_ESOF & USBLIB->irq_mask) {
USB_BASE->ISTR = ~USB_ISTR_ESOF;
/* resume handling timing is made with ESOFs */
usbResume(RESUME_ESOF); /* request without change of the machine state */
@@ -232,7 +228,7 @@ void __irq_usb_lp_can_rx0(void) {
*/
#if (USB_ISR_MSK & USB_ISTR_CTR)
- if (wIstr & USB_ISTR_CTR & USBLIB->irq_mask) {
+ if (istr & USB_ISTR_CTR & USBLIB->irq_mask) {
dispatch_ctr_lp();
}
#endif
@@ -256,7 +252,7 @@ uint8 usbIsConnected() {
* Auxiliary routines
*/
-static inline uint8 dispatch_endpt_zero(void);
+static inline uint8 dispatch_endpt_zero(uint16 istr_dir);
static inline void dispatch_endpt(uint8 ep);
static inline void set_rx_tx_status0(uint16 rx, uint16 tx);
@@ -264,19 +260,20 @@ static void handle_setup0(void);
static void handle_in0(void);
static void handle_out0(void);
-static void dispatch_ctr_lp(void) {
- while (((wIstr = USB_BASE->ISTR) & USB_ISTR_CTR) != 0) {
+static void dispatch_ctr_lp() {
+ uint16 istr;
+ while (((istr = USB_BASE->ISTR) & USB_ISTR_CTR) != 0) {
/* TODO WTF, figure this out: RM0008 says CTR is read-only,
* but ST's firmware claims it's clear-only, and emphasizes
* the importance of clearing it in more than one place. */
USB_BASE->ISTR = ~USB_ISTR_CTR;
- uint8 ep_id = wIstr & USB_ISTR_EP_ID;
+ uint8 ep_id = istr & USB_ISTR_EP_ID;
if (ep_id == 0) {
/* TODO figure out why it's OK to break out of the loop
* once we're done serving endpoint zero, but not okay if
* there are multiple nonzero endpoint transfers to
* handle. */
- if (dispatch_endpt_zero())
+ if (dispatch_endpt_zero(istr & USB_ISTR_DIR))
return;
} else {
dispatch_endpt(ep_id);
@@ -288,7 +285,7 @@ static void dispatch_ctr_lp(void) {
* code, and is ugly/confusing in its use of SaveRState/SaveTState.
* Fixing this requires filling in handle_in0(), handle_setup0(),
* handle_out0(). */
-static inline uint8 dispatch_endpt_zero(void) {
+static inline uint8 dispatch_endpt_zero(uint16 istr_dir) {
uint32 epr = (uint16)USB_BASE->EP[0];
if (!(epr & (USB_EP_CTR_TX | USB_EP_SETUP | USB_EP_CTR_RX))) {
@@ -304,7 +301,7 @@ static inline uint8 dispatch_endpt_zero(void) {
/* Set actual RX/TX statuses to NAK while we're thinking */
set_rx_tx_status0(USB_EP_STAT_RX_NAK, USB_EP_STAT_TX_NAK);
- if ((wIstr & USB_ISTR_DIR) == 0) {
+ if (istr_dir == 0) {
/* ST RM0008: "If DIR bit=0, CTR_TX bit is set in the USB_EPnR
* register related to the interrupting endpoint. The
* interrupting transaction is of IN type (data transmitted by
diff --git a/libmaple/usb/usb.h b/libmaple/usb/usb.h
index b073156..107ea77 100644
--- a/libmaple/usb/usb.h
+++ b/libmaple/usb/usb.h
@@ -27,8 +27,7 @@
#ifndef _USB_H_
#define _USB_H_
-#include "libmaple.h"
-#include "gpio.h"
+#include "libmaple_types.h"
#ifdef __cplusplus
extern "C" {