Hi, I am developing a firmware for EZUSB FX based board. I am facing a small problem. I am not able to initialize a Global variable in my firmware. Even though I assign the global variable with 0 initial value, But the variable does not take that value. I am using SMALL memory model for my development. my declerations looks like this :- BYTE GlobalCount = 0; and in my sof() I am using this variable and updating it and reusing it again in next sof(). Please advise .. Rahul Gupta
here is the code ..
//FW.C #include "ezusb.h" #include "ezregs.h" //----------------------------------------------------------------------------- // Global Variables /----------------------------------------------------------------------------- volatile BOOL GotSUD; BOOL Rwuen; BOOL Selfpwr; volatile BOOL Sleep; WORD pDeviceDscr; // Pointer to Device Descriptor; Descriptors may be moved WORD pConfigDscr; WORD pStringDscr; extern BYTE glbCntW; // Code -- // Task dispatcher void main(void) { DWORD i; WORD offset; DWORD DevDescrLen; DWORD j=0; WORD IntDescrAddr; WORD ExtDescrAddr; Sleep = FALSE; Rwuen = FALSE; Selfpwr = FALSE; GotSUD = FALSE; // Initialize user device TD_Init(); pDeviceDscr = (WORD)&DeviceDscr; pConfigDscr = (WORD)&ConfigDscr; pStringDscr = (WORD)&StringDscr; if ((WORD)&DeviceDscr & 0xe000) { IntDescrAddr = INTERNAL_DSCR_ADDR; ExtDescrAddr = (WORD)&DeviceDscr; DevDescrLen = (WORD)&UserDscr - (WORD)&DeviceDscr + 2; for (i = 0; i < DevDescrLen; i++) *((BYTE xdata *)IntDescrAddr+i) = 0xCD; for (i = 0; i < DevDescrLen; i++) *((BYTE xdata *)IntDescrAddr+i) = *((BYTE xdata *)ExtDescrAddr+i); pDeviceDscr = IntDescrAddr; offset = (WORD)&DeviceDscr - INTERNAL_DSCR_ADDR; pConfigDscr -= offset; pStringDscr -= offset; } EZUSB_IRQ_ENABLE(); // Enable USB interrupt (INT2) EZUSB_ENABLE_RSMIRQ(); PORTCCFG |= 0xc0; USBBAV = USBBAV | 1 & ~bmBREAK; USBIEN |= bmSUDAV | bmSUTOK | bmSUSP | bmURES; EA = 1; #ifndef NO_RENUM EZUSB_Discon(TRUE); // Renumerate #endif CKCON = (CKCON&(~bmSTRETCH)) | FW_STRETCH_VALUE; // Set stretch to 0 (after renumeration) // Task Dispatcher while(TRUE) // Main Loop { if(GotSUD) // Wait for SUDAV { SetupCommand(); // Implement setup command GotSUD = FALSE; // Clear SUDAV flag } if (Sleep) { if(TD_Suspend()) { Sleep = FALSE; do { EZUSB_Susp(); } while(!Rwuen && EZUSB_EXTWAKEUP()); EZUSB_Resume(); // If source is the Wakeup# pin, signal the host to Resume. TD_Resume(); } } TD_Poll(); } } void SetupCommand(void) { void *dscr_ptr; DWORD i; switch(SETUPDAT[1]) { case SC_GET_DESCRIPTOR: if(DR_GetDescriptor()) switch(SETUPDAT[3]) { case GD_DEVICE: SUDPTRH = MSB(pDeviceDscr); SUDPTRL = LSB(pDeviceDscr); break; case GD_CONFIGURATION: // Configuration if(dscr_ptr = (void *)EZUSB_GetConfigDscr(SETUPDAT[2])) { SUDPTRH = MSB(dscr_ptr); SUDPTRL = LSB(dscr_ptr); } else EZUSB_STALL_EP0(); // Stall End Point 0 break; case GD_STRING: // String if(dscr_ptr = (void *)EZUSB_GetStringDscr(SETUPDAT[2])) { STRINGDSCR *sdp; BYTE len; sdp = dscr_ptr; len = sdp->length; if (len > SETUPDAT[6]) len = SETUPDAT[6]; //limit to the requested length while (len) { for(i=0; i<min(len,64); i++) *(IN0BUF+i) = *((BYTE xdata *)sdp+i); //set length and arm Endpoint EZUSB_SET_EP_BYTES(IN0BUF_ID,min(len,64)); len -= min(len,64); (BYTE *)sdp += 64; // Wait for it to go out (Rev C and above) while(EP0CS & 0x04) ; } EZUSB_SET_EP_BYTES(IN0BUF_ID,0); EP0CS = bmHS; } else EZUSB_STALL_EP0(); // Stall End Point 0 break; default: // Invalid request EZUSB_STALL_EP0(); // Stall End Point 0 } break; case SC_GET_INTERFACE: // *** Get Interface DR_GetInterface(); break; case SC_SET_INTERFACE: // *** Set Interface DR_SetInterface(); break; case SC_SET_CONFIGURATION: // *** Set Configuration DR_SetConfiguration(); break; case SC_GET_CONFIGURATION: // *** Get Configuration DR_GetConfiguration(); break; case SC_GET_STATUS: // *** Get Status if(DR_GetStatus()) switch(SETUPDAT[0]) { case GS_DEVICE: // Device IN0BUF[0] = ((BYTE)Rwuen << 1) | (BYTE)Selfpwr; IN0BUF[1] = 0; EZUSB_SET_EP_BYTES(IN0BUF_ID,2); break; case GS_INTERFACE: // Interface IN0BUF[0] = 0; IN0BUF[1] = 0; EZUSB_SET_EP_BYTES(IN0BUF_ID,2); break; case GS_ENDPOINT: // End Point IN0BUF[0] = EPIO[EPID(SETUPDAT[4])].cntrl & bmEPSTALL; IN0BUF[1] = 0; EZUSB_SET_EP_BYTES(IN0BUF_ID,2); break; default: // Invalid Command EZUSB_STALL_EP0(); // Stall End Point 0 } break; case SC_CLEAR_FEATURE: // *** Clear Feature if(DR_ClearFeature()) switch(SETUPDAT[0]) { case FT_DEVICE: // Device if(SETUPDAT[2] == 1) Rwuen = FALSE; // Disable Remote Wakeup else EZUSB_STALL_EP0(); // Stall End Point 0 break; case FT_ENDPOINT: // End Point if(SETUPDAT[2] == 0) { EZUSB_UNSTALL_EP( EPID(SETUPDAT[4]) ); EZUSB_RESET_DATA_TOGGLE( SETUPDAT[4] ); } else EZUSB_STALL_EP0(); // Stall End Point 0 break; } break; case SC_SET_FEATURE: // *** Set Feature if(DR_SetFeature()) switch(SETUPDAT[0]) { case FT_DEVICE: // Device if(SETUPDAT[2] == 1) Rwuen = TRUE; // Enable Remote Wakeup else EZUSB_STALL_EP0(); // Stall End Point 0 break; case FT_ENDPOINT: // End Point if(SETUPDAT[2] == 0) EZUSB_STALL_EP( EPID(SETUPDAT[4]) ); else EZUSB_STALL_EP0(); // Stall End Point 0 break; } break; default: if(DR_VendorCmnd()) EZUSB_STALL_EP0(); } // Acknowledge handshake phase of device request // Required for rev C does not effect rev B EP0CS |= bmBIT1; } void resume_isr(void) interrupt WKUP_VECT { EZUSB_CLEAR_RSMIRQ(); }