static uint32_t EchoNewDataToHost(tUSBDBulkDevice *psDevice, uint8_t *pui8Data, uint32_t ui32NumBytes) { uint32_t ui32Loop, ui32Space, ui32Count; uint32_t ui32ReadIndex; uint32_t ui32WriteIndex; tUSBRingBufObject sTxRing; unsigned char Data_Merge_flag=0,Data_count=0,Addr_shift_Cnt=8,Rx_Arr_Index=0,EEPROM_Buff_Index=0,Addr_Flag=0,Error_Data_Index=0; uint32_t pui32eprom = 0x00, addrdata=0x00; uint32_t pui32Weprom[64]={0x00}; USBBufferInfoGet(&g_sTxBuffer, &sTxRing); ui32Space = USBBufferSpaceAvailable(&g_sTxBuffer); ui32Loop = (ui32Space < ui32NumBytes) ? ui32Space : ui32NumBytes; ui32Count = ui32Loop; g_ui32RxCount += ui32NumBytes; ui32ReadIndex = (uint32_t)(pui8Data - g_pui8USBRxBuffer); ui32WriteIndex = sTxRing.ui32WriteIndex; for(Rx_Arr_Index=0x00;Rx_Arr_Index 0xfff)) { goto error; } if((addrdata >= 0x000) && (addrdata <= 0x0f0)) Addr_Flag = 1; } } if(Rx_Arr_Index==0x04) { Data_count = (Ascii_To_Num(pui32Data[Rx_Arr_Index-1]) << 4) | Ascii_To_Num(pui32Data[Rx_Arr_Index]); if(Addr_Flag == 1) { Data_count = (Data_count * 0x02)+0x04; } else { Data_count = Data_count +0x04; } } if((Rx_Arr_Index>=0x05)&&(Rx_Arr_Index<=Data_count)) { if( Addr_Flag == 1) { if(Data_Merge_flag == 0) { pui32eprom = (Ascii_To_Num(pui32Data[Rx_Arr_Index]) << 4); Data_Merge_flag=1; } else { pui32eprom = pui32eprom | Ascii_To_Num(pui32Data[Rx_Arr_Index]); if(pui32eprom > 0x59) { error: for(Error_Data_Index=0;Error_Data_Index<5;Error_Data_Index++,ui32WriteIndex++) { g_pui8USBTxBuffer[ui32WriteIndex] = Error_data[Error_Data_Index]; } goto end; } pui32Data[Rx_Arr_Index] = pui32eprom; Data_Merge_flag=0; goto write; } } if((Rx_Arr_Index>Data_count) || (Addr_Flag == 0)) { write: pui32Weprom[EEPROM_Buff_Index++]=pui32Data[Rx_Arr_Index]; pui32eprom = 0x00; } if((Rx_Arr_Index>Data_count) && (Addr_Flag == 0)) break; } } EEPROMProgram(pui32Weprom, addrdata, sizeof(pui32Weprom)); end: USBBufferDataWritten(&g_sTxBuffer, ui32Count); return(ui32Count); } int Ascii_To_Num(int Rx_Data) { if((Rx_Data >= 0x30) && (Rx_Data <= 0x39)) { Rx_Data = Rx_Data - 0x30; } else if((Rx_Data >= 0x61) && (Rx_Data <= 0x66 )) { switch(Rx_Data) { case 0x61 : Rx_Data = 0x0A; break; case 0x62 : Rx_Data = 0x0B; break; case 0x63 : Rx_Data = 0x0C; break; case 0x64 : Rx_Data = 0x0D; break; case 0x65 : Rx_Data = 0x0E; break; case 0x66 : Rx_Data = 0x0F; break; } } return Rx_Data; } main and rest all are almost same...