Pinscape Controller version 1 fork. This is a fork to allow for ongoing bug fixes to the original controller version, from before the major changes for the expansion board project.

Dependencies:   FastIO FastPWM SimpleDMA mbed

Fork of Pinscape_Controller by Mike R

Files at this revision

API Documentation at this revision

Comitter:
mjr
Date:
Thu Feb 11 22:47:51 2016 +0000
Parent:
58:480c2c786c71
Child:
60:f6e32a36f6ee
Commit message:
ISR ISTAT bit mask operation fixes and busy/suspend bit clears

Changed in this revision

USBDevice/USBDevice/USBHAL_KL25Z.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/USBDevice/USBDevice/USBHAL_KL25Z.cpp	Thu Feb 11 22:39:30 2016 +0000
+++ b/USBDevice/USBDevice/USBHAL_KL25Z.cpp	Thu Feb 11 22:47:51 2016 +0000
@@ -543,28 +543,38 @@
 }
 
 
-void USBHAL::_usbisr(void) {
+void USBHAL::_usbisr(void) 
+{
+    inIRQ = true;
     instance->usbisr();
+    inIRQ = false;
 }
 
 
-void USBHAL::usbisr(void) {
+void USBHAL::usbisr(void) 
+{
     uint8_t i;
     uint8_t istat = USB0->ISTAT;
 
     // reset interrupt
-    if (istat & USB_ISTAT_USBRST_MASK) {
-        
-        // disable all endpt
-        for(i = 0; i < 16; i++) {
+    if (istat & USB_ISTAT_USBRST_MASK) 
+    {    
+        // disable all endpoints
+        for (i = 0 ; i < 16 ; i++)
             USB0->ENDPOINT[i].ENDPT = 0x00;
-        }
 
         // enable control endpoint
         realiseEndpoint(EP0OUT, MAX_PACKET_SIZE_EP0, 0);
         realiseEndpoint(EP0IN, MAX_PACKET_SIZE_EP0, 0);
 
+        // reset DATA0/1 state
         Data1 = 0x55555555;
+        
+        // reset endpoint completeion status
+        epComplete = 0;
+        
+        // reset EVEN/ODD state (and keep it permanently on EVEN -
+        // this disables the hardware double-buffering system)
         USB0->CTL |=  USB_CTL_ODDRST_MASK;
 
         USB0->ISTAT   =  0xFF;  // clear all interrupt status flags
@@ -578,31 +588,39 @@
         // we're not suspended
         suspendStateChanged(0);
 
+        // do ONLY the reset processing on a RESET interrupt
         return;
     }
 
     // resume interrupt
     if (istat & USB_ISTAT_RESUME_MASK) {
+        suspendStateChanged(0);
         USB0->ISTAT = USB_ISTAT_RESUME_MASK;
-        suspendStateChanged(0);
     }
 
     // SOF interrupt
     if (istat & USB_ISTAT_SOFTOK_MASK) {
+        SOF(frameNumber());
         USB0->ISTAT = USB_ISTAT_SOFTOK_MASK;
-        // SOF event, read frame number
-        SOF(frameNumber());
     }
 
     // stall interrupt
-    if (istat & 1<<7) {
+    if (istat & USB_ISTAT_STALL_MASK) 
+    {
+        // if endpoint 0 is stalled, explicitly un-stall it
         if (USB0->ENDPOINT[0].ENDPT & USB_ENDPT_EPSTALL_MASK)
             USB0->ENDPOINT[0].ENDPT &= ~USB_ENDPT_EPSTALL_MASK;
-        USB0->ISTAT |= USB_ISTAT_STALL_MASK;
+            
+        // clear the busy-suspend bit to resume token processing
+        USB0->CTL &= ~USB_CTL_TXSUSPENDTOKENBUSY_MASK;
+        
+        // clear the interrupt status bit for STALL
+        USB0->ISTAT = USB_ISTAT_STALL_MASK;
     }
 
     // token interrupt
-    if (istat & 1<<3) {
+    if (istat & USB_ISTAT_TOKDNE_MASK) 
+    {
         uint32_t num  = (USB0->STAT >> 4) & 0x0F;
         uint32_t dir  = (USB0->STAT >> 3) & 0x01;
         uint32_t ev_odd = (USB0->STAT >> 2) & 0x01;
@@ -651,15 +669,16 @@
     }
 
     // sleep interrupt
-    if (istat & 1<<4) {
-        USB0->ISTAT |= USB_ISTAT_SLEEP_MASK;
+    if (istat & USB_ISTAT_SLEEP_MASK) {
         suspendStateChanged(1);
+        USB0->ISTAT = USB_ISTAT_SLEEP_MASK;
     }
 
     // error interrupt
     if (istat & USB_ISTAT_ERROR_MASK) {
         USB0->ERRSTAT = 0xFF;
-        USB0->ISTAT |= USB_ISTAT_ERROR_MASK;
+        USB0->CTL &= ~USB_CTL_TXSUSPENDTOKENBUSY_MASK;
+        USB0->ISTAT = USB_ISTAT_ERROR_MASK;
     }
 }