int findValidSync(unsigned char ** offset, int * bytes) { int ret; while(UnpackFrameHeader((MP3DecInfo *)mdecoder, *offset)<0) { // search for another syncword findsync: *offset +=2; *bytes -=2; // we did enough this mp3 is likely corrupt if((ret=MP3FindSyncWord(*offset, *bytes))<0) { return -1; } *offset += ret; *bytes -=ret; } // eh we're decoding mp3, get back! if(((MP3DecInfo *)mdecoder)->layer!=3) { goto findsync; } return 0; }
int OtpWriter_Process_Command() { u8 key = 0; #ifndef OTPWriter_IAP HS_PacketInfo PacketInfo; key = g_KEY.IsReleased(); if(key==1) { OTP_write_from_SD(); } if (USB_ReceiveFlg == SET) { g_LED.On(); UnpackFrameHeader(&PacketInfo, Receive_Buffer); switch (PacketInfo.PacketPID) { case HS__MEM: switch (PacketInfo.Cmd) { case HS__MEM__ENTER: if(NULL != Support_Device_Table[GetIndex(g_Chip_Type)].SPIDev_callback_Init) exec_mem_Init(&PacketInfo); else Send_Refuse_Packet(&PacketInfo); break; case HS__MEM__EXIT: if(NULL != Support_Device_Table[GetIndex(g_Chip_Type)].SPIDev_callback_DeInit) exec_mem_Reset(&PacketInfo); else Send_Refuse_Packet(&PacketInfo); break; case HS__MEM__READ: if(NULL != Support_Device_Table[GetIndex(g_Chip_Type)].SPIDev_callback_Read) exec_mem_read(&PacketInfo); else Send_Refuse_Packet(&PacketInfo); break; case HS__MEM__WRITE: if(NULL != Support_Device_Table[GetIndex(g_Chip_Type)].SPIDev_callback_Write) exec_mem_write(&PacketInfo); else Send_Refuse_Packet(&PacketInfo); break; case HS__MEM__BLKCHK: if(NULL != Support_Device_Table[GetIndex(g_Chip_Type)].SPIDev_callback_CheckBlank) exec_mem_BlackCheck(&PacketInfo); else Send_Refuse_Packet(&PacketInfo); break; case HS__MEM__RESET: if(NULL != Support_Device_Table[GetIndex(g_Chip_Type)].SPIDev_callback_DeInit) exec_mem_Reset(&PacketInfo); else Send_Refuse_Packet(&PacketInfo); break; case HS__MEM__TEST_BLKCHK: if(NULL != Support_Device_Table[GetIndex(g_Chip_Type)].SPIDev_callback_ProductTest) exec_mem_ProductTest(&PacketInfo); else Send_Refuse_Packet(&PacketInfo); break; case HS__MEM__TEST_DEC: if(NULL != Support_Device_Table[GetIndex(g_Chip_Type)].SPIDev_callback_ProductTest) exec_mem_ProductTest(&PacketInfo); else Send_Refuse_Packet(&PacketInfo); break; case HS__MEM__TEST_WR: if(NULL != Support_Device_Table[GetIndex(g_Chip_Type)].SPIDev_callback_ProductTest) exec_mem_ProductTest(&PacketInfo); else Send_Refuse_Packet(&PacketInfo); break; case HS__MEM__ERASE_PAGE: if(NULL != Support_Device_Table[GetIndex(g_Chip_Type)].SPIDev_callback_ErasePage) exec_mem_ErasePage(&PacketInfo); else Send_Refuse_Packet(&PacketInfo); break; case HS__MEM__ERASE_ALL: if(NULL != Support_Device_Table[GetIndex(g_Chip_Type)].SPIDev_callback_EraseAll) exec_mem_EraseAll(&PacketInfo); else Send_Refuse_Packet(&PacketInfo); break; case HS__MEM__ACCESS_DISABLE: if(NULL != Support_Device_Table[GetIndex(g_Chip_Type)].SPIDev_callback_WriteProtect) { exec_mem_WriteProtection(&PacketInfo); } else Send_Refuse_Packet(&PacketInfo); break; default: printf("Undefine PacketCMD: %x\n", PacketInfo.Cmd); Send_Refuse_Packet(&PacketInfo); break; } break; case HS__CMD: switch (PacketInfo.Cmd) { case HS__CMD__SET__CHIP_TYPE: exec_set_chip_type(&PacketInfo); g_Chip_Type = (HS_CHIP_TYPE_t)Receive_Buffer[4]; if (g_Chip_Type == HS__CMD__CHIP_TYPE__OTP__HS6206) { g_DUT.otp.Open(); } else if (g_Chip_Type == HS__CMD__CHIP_TYPE__FLASH__EN25780) { g_SF.Open(); } break; case HS__CMD__GET__CHIP_TYPE: exec_get_chip_type(&PacketInfo); break; case HS__CMD__GET__FIRMWARE_VERSION: exec_get_firmware_version(&PacketInfo); break; default: printf("Undefine PacketCMD: %x\n", PacketInfo.Cmd); break; } break; case HS__ERR: break; case HS__DBG: break; default: break; } g_LED.Off(); USB_ReceiveFlg = 0x00; } #endif //#ifndef OTPWriter_IAP return 0; }