From 5ba138138c818f3faa4c78f86ae4f7d4507ff2b6 Mon Sep 17 00:00:00 2001 From: Vegard Storheil Eriksen Date: Sun, 25 Mar 2012 03:42:55 +0200 Subject: Went from interrupt-based to threaded model. --- main.cpp | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/main.cpp b/main.cpp index 59fa5bf..54bc4a6 100644 --- a/main.cpp +++ b/main.cpp @@ -123,6 +123,7 @@ void handle_setup(const uint32_t* bufp) { static uint32_t buf[16]; void handle_rxfifo() { + led_status.toggle(); uint32_t status = OTG_HS.reg.GRXSTSP; @@ -139,10 +140,7 @@ void handle_rxfifo() { } } -template<> -void interrupt<(Interrupt::IRQ)77>() { - led_status.toggle(); - +void usb_process() { // USB reset. if(OTG_HS.reg.GINTSTS & (1 << 12)) { //led_yellow.toggle(); @@ -170,6 +168,22 @@ void interrupt<(Interrupt::IRQ)77>() { OTG_HS.reg.GINTSTS = 0xffffffff; } +template<> +void interrupt<(Interrupt::IRQ)77>() { + usb_process(); +} + +void usb_main() { + while(1) { + usb_process(); + Thread::yield(); + } +} + +uint32_t usb_stack[1024]; + +Thread usb_thread(usb_stack, sizeof(usb_stack), usb_main); + int main() { // Initialize system timer. STK.LOAD = 168000000 / 8 / 1000; // 1000 Hz. @@ -199,7 +213,7 @@ int main() { usb_dp.set_af(12); RCC.enable(RCC.OTGHS); - Interrupt::enable((Interrupt::IRQ)77); + //Interrupt::enable((Interrupt::IRQ)77); // Set PHYSEL. OTG_HS.reg.GUSBCFG |= (1 << 6); @@ -210,7 +224,7 @@ int main() { OTG_HS.reg.GRSTCTL |= 1; while(OTG_HS.reg.GRSTCTL & 1); - OTG_HS.reg.GAHBCFG = 1; + OTG_HS.reg.GAHBCFG = 0; // USB configuration OTG_HS.reg.GUSBCFG = (1 << 30) | (0xf << 10) | (0 << 9) | (0 << 8) | (1 << 6); @@ -228,6 +242,8 @@ int main() { OTG_HS.reg.GCCFG = (1 << 19) | (1 << 16); // VBUSBSEN PWRDWN + usb_thread.start(); + while(1) { led_error.toggle(); Time::sleep(100); -- cgit v1.2.3