aboutsummaryrefslogtreecommitdiffstats
path: root/libmaple/usb/usb.c
diff options
context:
space:
mode:
authorMarti Bolivar <mbolivar@leaflabs.com>2011-06-15 17:11:41 -0400
committerMarti Bolivar <mbolivar@leaflabs.com>2011-10-18 13:30:17 -0400
commitd85462d0517baac39f3c316924162cca3d9c785a (patch)
tree08a3417acacbae3f4666f0ee0cad893cfe3f8a8c /libmaple/usb/usb.c
parentc6c959682084c8493a0c39754374e7dbe6cf1708 (diff)
downloadlibrambutan-d85462d0517baac39f3c316924162cca3d9c785a.tar.gz
librambutan-d85462d0517baac39f3c316924162cca3d9c785a.zip
usb: Replace duplicated code with nvic.h API.
Replace calls to usbEnbISR()/usbDsbISR() with nvic_irq_enable()/nvic_irq_disable(). Remove ST-style code. Use nvic_sys_reset() instead of systemHardReset(). Rename some conflicting #defines that including nvic.h created. Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
Diffstat (limited to 'libmaple/usb/usb.c')
-rw-r--r--libmaple/usb/usb.c30
1 files changed, 5 insertions, 25 deletions
diff --git a/libmaple/usb/usb.c b/libmaple/usb/usb.c
index 5c4c35a..173673e 100644
--- a/libmaple/usb/usb.c
+++ b/libmaple/usb/usb.c
@@ -36,6 +36,7 @@
#include "gpio.h"
#include "usb_hardware.h"
#include "delay.h"
+#include "nvic.h"
#include "usb_config.h"
#include "usb_callbacks.h"
@@ -111,9 +112,9 @@ void usb_cdcacm_enable(gpio_dev *disc_dev, uint8 disc_bit) {
}
void usb_cdcacm_disable(gpio_dev *disc_dev, uint8 disc_bit) {
- // These are just guesses about how to do this
- // TODO: real disable function
- usbDsbISR();
+ // These are just guesses about how to do this, but it seems to work.
+ // TODO: verify this with USB spec
+ nvic_irq_disable(NVIC_USB_LP_CAN_RX0);
gpio_write_bit(disc_dev, disc_bit, 1);
}
@@ -218,27 +219,6 @@ RESULT usbPowerOff(void) {
return USB_SUCCESS;
}
-
-// These two functions (usbEnbISR/usbDsbISR) are implementented in ST style,
-// and at least the DsbISR doesn't seem to work?
-void usbEnbISR(void) {
- NVIC_InitTypeDef NVIC_InitStructure;
- NVIC_InitStructure.NVIC_IRQChannel = USB_LP_IRQ;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
- NVIC_InitStructure.NVIC_IRQChannelCmd = TRUE;
- nvicInit(&NVIC_InitStructure);
-}
-
-void usbDsbISR(void) {
- NVIC_InitTypeDef NVIC_InitStructure;
- NVIC_InitStructure.NVIC_IRQChannel = USB_LP_IRQ;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
- NVIC_InitStructure.NVIC_IRQChannelCmd = FALSE;
- nvicInit(&NVIC_InitStructure);
-}
-
/* overloaded ISR routine, this is the main usb ISR */
void __irq_usb_lp_can_rx0(void) {
wIstr = _GetISTR();
@@ -321,7 +301,7 @@ if (wIstr & ISTR_CTR & wInterrupt_Mask) {
void usbWaitReset(void) {
delay_us(RESET_DELAY);
- systemHardReset();
+ nvic_sys_reset();
}
/* This low-level send bytes function is NON-BLOCKING; blocking behavior, with