diff options
author | Vegard Storheil Eriksen <zyp@jvnv.net> | 2012-03-25 03:42:55 +0200 |
---|---|---|
committer | Vegard Storheil Eriksen <zyp@jvnv.net> | 2012-03-25 03:42:55 +0200 |
commit | 5ba138138c818f3faa4c78f86ae4f7d4507ff2b6 (patch) | |
tree | 49a826203e9b28dd846ebd0669d9ba6c7feb4bae | |
parent | 0d9b1a8d77ef83080d56959c9369a75859bc7289 (diff) |
Went from interrupt-based to threaded model.
-rw-r--r-- | main.cpp | 28 |
1 files changed, 22 insertions, 6 deletions
@@ -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); |