//! Add a new error void err_add(enum err_type type, enum uwrt_err status, const char* details) { if(!_err_initd) _init_err(); /* Make sure we're not exceeding the active error count limit */ if( _num_errs + _num_warns >= MAX_ERRS ) { // Handle this as an out-of-memory _handle_nomem(); return; } // Out-of-memory errors use a special statically-allocated descriptor if( status == UWRT_NOMEM ) _handle_nomem(); /* Allocate an error descriptor */ err_desc_t * desc = 0; if( (status!=UWRT_SUCCESS) && (status!=UWRT_ERRNO) && (_err_counts[status]) ) { /* If this has a uwrt_err that isn't ERRNO or SUCCESS, and we've seen this * error before, we just need to record the additional occurrence, since * we don't store replicas */ if( _err_counts[status]+1 != 0 ) ++_err_counts[status]; return; } else { desc = malloc(sizeof(err_desc_t)); if( !desc ) { _handle_nomem(); return; } } /* Trip appropriate LED, update appropriate count */ switch(type) { case ERROR: mLED_3_On(); ++_num_errs; break; case WARNING: default: mLED_4_On(); ++_num_warns; break; } /* Fill descriptor */ desc->errno = errno; desc->type = type; desc->status = status; desc->details = details; desc->next = 0; // Record occurrence if(_err_counts[status]+1 != 0) ++_err_counts[status]; /* Add descriptor to error list */ if( !_err_list ) { // Special case: empty list _err_list = desc; _err_tail = desc; } else { _err_tail->next = desc; _err_tail = desc; } }
/****************************************************************************** * Function: void ServiceRequests(void) * * PreCondition: None * * Input: None * * Output: None * * Side Effects: USB traffic can be generated * * Overview: This function takes in the commands from the PC from the * application and executes the commands requested * * Note: None *****************************************************************************/ void ServiceRequests(void) { BYTE index; //Check to see if data has arrived if(!USBHandleBusy(USBGenericOutHandle)) { //if the handle is no longer busy then the last //transmission is complete counter = 0; INPacket.CMD=OUTPacket.CMD; INPacket.len=OUTPacket.len; //process the command switch(OUTPacket.CMD) { case READ_VERSION: //dataPacket._byte[1] is len INPacket._byte[2] = MINOR_VERSION; INPacket._byte[3] = MAJOR_VERSION; counter=0x04; break; case ID_BOARD: counter = 0x01; if(OUTPacket.ID == 0) { mLED_3_Off();mLED_4_Off(); } else if(OUTPacket.ID == 1) { mLED_3_Off();mLED_4_On(); } else if(OUTPacket.ID == 2) { mLED_3_On();mLED_4_Off(); } else if(OUTPacket.ID == 3) { mLED_3_On();mLED_4_On(); } else counter = 0x00; break; case UPDATE_LED: #if defined(PIC18F87J50_PIM) || defined(PIC18F46J50_PIM) || defined(PIC18F47J53_PIM) blinkStatusValid = FALSE; #endif // LED1 & LED2 are used as USB event indicators. if(OUTPacket.led_num == 3) { if(OUTPacket.led_status) { mLED_3_On(); } else { mLED_3_Off(); } counter = 0x01; }//end if else if(OUTPacket.led_num == 4) { if(OUTPacket.led_status) { mLED_4_On(); } else { mLED_4_Off(); } counter = 0x01; }//end if else break; case SET_TEMP_REAL: temp_mode = TEMP_REAL_TIME; ResetTempLog(); counter = 0x01; break; case RD_TEMP: if(AcquireTemperature()) { INPacket._byte[1] = temperature.v[0]; INPacket._byte[2] = temperature.v[1]; counter=0x03; }//end if break; case SET_TEMP_LOGGING: temp_mode = TEMP_LOGGING; ResetTempLog(); counter=0x01; break; case RD_TEMP_LOGGING: counter = (valid_temp<<1)+2; // Update count in byte INPacket.len = (valid_temp<<1); for(index = valid_temp; index > 0; index--) { if(pTemp == 0) pTemp = 29; else pTemp--; INPacket._word[index] = temp_data[pTemp]; }//end for ResetTempLog(); // Once read, log will restart break; case RD_POT: { WORD_VAL w; mInitPOT(); w = ReadPOT(); INPacket._byte[1] = w.v[0]; INPacket._byte[2] = w.v[1]; counter=0x03; } break; case RESET: Reset(); break; default: break; }//end switch() if(counter != 0) { if(!USBHandleBusy(USBGenericInHandle)) { USBGenericInHandle = USBGenWrite(USBGEN_EP_NUM,(BYTE*)&INPacket,counter); } }//end if //Re-arm the OUT endpoint for the next packet USBGenericOutHandle = USBGenRead(USBGEN_EP_NUM,(BYTE*)&OUTPacket,USBGEN_EP_SIZE); }//end if }//end ServiceRequests