//----- (000025B8) -------------------------------------------------------- __myevic__ uint32_t hidFMCReadCmd( CMD_T *pCmd ) { uint32_t u32StartAddr; uint32_t u32ParamLen; u32StartAddr = pCmd->u32Arg1; u32ParamLen = pCmd->u32Arg2; myprintf( "FMC Read command - Start Addr: %d Param Len: %d\n", pCmd->u32Arg1, pCmd->u32Arg2 ); if ( ! u32ParamLen % EP2_MAX_PKT_SIZE ) { return -1; } if ( u32ParamLen ) { if ( u32ParamLen > FMC_FLASH_PAGE_SIZE ) { u32ParamLen = FMC_FLASH_PAGE_SIZE; } SYS_UnlockReg(); FMC_ENABLE_ISP(); for ( uint32_t i = 0 ; i < u32ParamLen ; i += 4 ) { uint32_t data; data = FMC_Read( u32StartAddr + i ); MemCpy( &hidData[i], &data, 4 ); } FMC_DISABLE_ISP(); SYS_LockReg(); hidDataIndex = u32ParamLen; pCmd->u32Signature = u32ParamLen; USBD_MemCopy( (uint8_t *)(USBD_BUF_BASE + USBD_GET_EP_BUF_ADDR(EP2)), hidData, EP2_MAX_PKT_SIZE ); USBD_SET_PAYLOAD_LEN( EP2, EP2_MAX_PKT_SIZE ); hidDataIndex -= EP2_MAX_PKT_SIZE; } return 0; }
/*---------------------------------------------------------------------------------------------------------*/ int FMC_Example(void) { uint32_t u32Data[3]; SYS_Init(); UART0_Init(); SYS_UnlockReg(); //中:解锁被保护的寄存器位,以便用户访问//en:Unlock protected register bits for user to access FMC_ENABLE_ISP(); printf("APROM access to LDROM\n"); LDROM_Erase(); LDROM_Erase_Verify(); LDROM_Program(0x55555555); LDROM_Program_Verify(0x55555555); FMC_ENABLE_AP_UPDATE(); printf("APROM access to APROM\n"); APROM_Erase(); APROM_Erase_Verify(); APROM_Program(0x33333333); APROM_Program_Verify(0x33333333); printf("config area Program\n"); CONFIG_Erase(); CONFIG0_Program(0xF8FFFFFF); CONFIG1_Program(0xEFFFFFFF); printf("Read UID\n"); DrvFMC_ReadUID(0, &u32Data[0]); DrvFMC_ReadUID(1, &u32Data[1]); DrvFMC_ReadUID(2, &u32Data[2]); printf("UID %x %x %x\n", u32Data[0], u32Data[1], u32Data[2]); FMC_DISABLE_ISP(); SYS_LockReg(); //中:重新锁被保护的寄存器位//en:Lock protected register bits again printf("ISP test is successful\n"); return 0; }
//----- (000025B8) -------------------------------------------------------- __myevic__ uint32_t hidFMCReadCmd( CMD_T *pCmd ) { uint32_t u32StartAddr; uint32_t u32ParamLen; u32StartAddr = pCmd->u32Arg1; u32ParamLen = pCmd->u32Arg2; myprintf( "FMC Read command - Start Addr: %d Param Len: %d\n", pCmd->u32Arg1, pCmd->u32Arg2 ); if ( ! u32ParamLen % EP2_MAX_PKT_SIZE ) { return -1; } if ( u32ParamLen ) { if ( u32ParamLen > FMC_FLASH_PAGE_SIZE ) { u32ParamLen = FMC_FLASH_PAGE_SIZE; } SYS_UnlockReg(); FMC_ENABLE_ISP(); for ( uint32_t i = 0 ; i < u32ParamLen ; i += 4 ) { uint32_t data; data = FMC_Read( u32StartAddr + i ); MemCpy( &hidData[i], &data, 4 ); } FMC_DISABLE_ISP(); SYS_LockReg(); hidInDataPtr = hidData; hidStartInReport( u32ParamLen ); } return 0; }
//----- (00002788) -------------------------------------------------------- __myevic__ void hidGetOutReport( uint8_t *pu8Buffer, uint32_t u32BufferLen ) { uint8_t u8Cmd; uint8_t *hidDataPtr; uint32_t u32StartAddr; uint32_t u32DataSize; uint32_t u32ByteCount; uint32_t u32Page; uint32_t sz; uint32_t veo; u8Cmd = hidCmd.u8Cmd; u32StartAddr = hidCmd.u32Arg1; u32DataSize = hidCmd.u32Arg2; u32ByteCount = hidCmd.u32Signature; hidDataPtr = &hidData[hidDataIndex]; switch ( hidCmd.u8Cmd ) { case HID_CMD_SETPARAMS: { USBD_MemCopy( hidDataPtr, pu8Buffer, EP3_MAX_PKT_SIZE ); hidDataIndex += EP3_MAX_PKT_SIZE; if ( hidDataIndex >= u32DataSize ) { u8Cmd = HID_CMD_NONE; if ( u32StartAddr + u32DataSize > FMC_FLASH_PAGE_SIZE ) { sz = FMC_FLASH_PAGE_SIZE - u32StartAddr; } else { sz = u32DataSize; } MemCpy( (uint8_t*)(&hidDFData) + u32StartAddr, hidData, sz ); myprintf( "Set Sys Param complete.\n" ); dfStruct_t * df = (dfStruct_t*)hidDFData; if ( Checksum( (uint8_t*)df->params, FMC_FLASH_PAGE_SIZE - 4 ) == df->Checksum ) { myprintf( "\tCompany ID ............................ [0x%08x]\n", df->i.fmcCID ); myprintf( "\tDevice ID ............................. [0x%08x]\n", df->i.fmcDID ); myprintf( "\tProduct ID ............................ [0x%08x]\n", df->i.fmcPID ); myprintf( "\tu8UpdateAPRom ......................... [0x%08x]\n", df->p.BootFlag ); MemCpy( DataFlash.params, df->params, DATAFLASH_PARAMS_SIZE ); DFCheckValuesValidity(); UpdateDataFlash(); if ( df->i.Year >= 2000 && df->i.Year <= 2099 ) { S_RTC_TIME_DATA_T rtd; rtd.u32Year = df->i.Year; rtd.u32Month = df->i.Month; rtd.u32Day = df->i.Day; rtd.u32DayOfWeek = 0; rtd.u32Hour = df->i.Hour; rtd.u32Minute = df->i.Minute; rtd.u32Second = df->i.Second; rtd.u32TimeScale = RTC_CLOCK_24; SetRTC( &rtd ); } gFlags.refresh_display = 1; } else { myprintf( "Sys Param Receive fail.\n" ); } hidDataIndex = 0; } break; } case HID_CMD_SETLOGO: { USBD_MemCopy( hidDataPtr, pu8Buffer, EP3_MAX_PKT_SIZE ); hidDataIndex += EP3_MAX_PKT_SIZE; if ( hidDataIndex < FMC_FLASH_PAGE_SIZE && hidDataIndex + u32ByteCount < u32DataSize ) { break; } u32Page = u32StartAddr + u32ByteCount; myprintf( "Writing page %d\n", u32Page ); SYS_UnlockReg(); FMC_ENABLE_ISP(); FMC_ENABLE_AP_UPDATE(); if ( FMCEraseWritePage( u32Page, (uint32_t*)hidData ) ) { myprintf( "Data Flash Erase error!\n" ); } veo = FMCVerifyPage( u32Page, (uint32_t*)hidData ); if ( veo ) { myprintf( "Data Flash Verify error! 0x%x\n", 4 * veo - 4 ); } MemClear( hidData, FMC_FLASH_PAGE_SIZE ); u32ByteCount += hidDataIndex; myprintf( "g_u32BytesInPageBuf %d, u32LenCnt 0x%x\n", hidDataIndex, u32ByteCount ); FMC_DISABLE_AP_UPDATE(); FMC_DISABLE_ISP(); SYS_LockReg(); if ( u32ByteCount < u32DataSize ) { hidDataIndex = 0; } else { u8Cmd = HID_CMD_NONE; myprintf( "set boot logo command complete.\n" ); } break; } case HID_CMD_LDUPDATE: { USBD_MemCopy( hidDataPtr, pu8Buffer, EP3_MAX_PKT_SIZE ); hidDataIndex += EP3_MAX_PKT_SIZE; if ( hidDataIndex < FMC_FLASH_PAGE_SIZE && hidDataIndex + u32ByteCount < u32DataSize ) { break; } u32Page = u32StartAddr + u32ByteCount; myprintf( "Writing page 0x%08X\n", u32Page ); SYS_UnlockReg(); FMC_ENABLE_ISP(); FMC_EnableLDUpdate(); if ( FMCEraseWritePage( u32Page, (uint32_t*)hidData ) ) { myprintf( "Data Flash Erase error!\n" ); } veo = FMCVerifyPage( u32Page, (uint32_t*)hidData ); if ( veo ) { myprintf( "Data Flash Verify error! 0x%x\n", 4 * veo - 4 ); } MemClear( hidData, FMC_FLASH_PAGE_SIZE ); u32ByteCount += hidDataIndex; hidDataIndex = 0; myprintf( "g_u32BytesInPageBuf %d, u32LenCnt 0x%x\n", hidDataIndex, u32ByteCount ); FMC_DisableLDUpdate(); FMC_DISABLE_ISP(); SYS_LockReg(); if ( u32ByteCount >= u32DataSize ) { u8Cmd = HID_CMD_NONE; myprintf( "Update LDROM command complete.\n" ); } break; } default: { if ( hidProcessCommand( pu8Buffer, u32BufferLen ) ) { myprintf( "Unknown HID command!\n" ); } return; } } hidCmd.u8Cmd = u8Cmd; hidCmd.u32Signature = u32ByteCount; }
//----- (00002C60) -------------------------------------------------------- __myevic__ void hidSetInReport() { uint8_t cmd = hidCmd.u8Cmd; switch ( cmd ) { case HID_CMD_GETINFO: case HID_CMD_SCREENSHOT: { if ( hidDataIndex ) { USBD_MemCopy( (uint8_t *)(USBD_BUF_BASE + USBD_GET_EP_BUF_ADDR(EP2)), &hidInDataPtr[hidCmd.u32Signature - hidDataIndex], EP2_MAX_PKT_SIZE ); USBD_SET_PAYLOAD_LEN( EP2, EP2_MAX_PKT_SIZE ); hidDataIndex -= EP2_MAX_PKT_SIZE; } else { cmd = HID_CMD_NONE; } break; } case HID_CMD_FMCREAD: { if ( !hidDataIndex ) { uint32_t u32Addr = hidCmd.u32Arg1 + hidCmd.u32Signature; int32_t u32Size = hidCmd.u32Arg2 - hidCmd.u32Signature; if ( u32Size > 0 ) { if ( u32Size > FMC_FLASH_PAGE_SIZE ) u32Size = FMC_FLASH_PAGE_SIZE; SYS_UnlockReg(); FMC_ENABLE_ISP(); for ( int i = 0 ; i < u32Size ; i += 4 ) { uint32_t data = FMC_Read( u32Addr + i ); MemCpy( &hidData[ FMC_FLASH_PAGE_SIZE - u32Size + i ], &data, 4 ); } FMC_DISABLE_ISP(); SYS_LockReg(); hidDataIndex = u32Size; hidCmd.u32Signature += u32Size; } } if ( hidDataIndex ) { USBD_MemCopy( (uint8_t *)(USBD_BUF_BASE + USBD_GET_EP_BUF_ADDR(EP2)), &hidData[ FMC_FLASH_PAGE_SIZE - hidDataIndex ], EP2_MAX_PKT_SIZE ); USBD_SET_PAYLOAD_LEN( EP2, EP2_MAX_PKT_SIZE ); hidDataIndex -= EP2_MAX_PKT_SIZE; } else { cmd = HID_CMD_NONE; } break; } default: cmd = HID_CMD_NONE; break; } hidCmd.u8Cmd = cmd; }