Ejemplo n.º 1
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;
}
Ejemplo n.º 2
0
int main()
{
    uint32_t    i, u32Data;

    /* Init System, IP clock and multi-function I/O */
    SYS_Init();
    /* Init UART0 for printf */
    UART0_Init();

    /*---------------------------------------------------------------------------------------------------------*/
    /* SAMPLE CODE                                                                                             */
    /*---------------------------------------------------------------------------------------------------------*/

    printf("\n\nCPU @ %dHz\n", SystemCoreClock);

    SYS_UnlockReg();

    /* Enable FMC ISP function */
    FMC_Open();

    if (set_data_flash_base(DATA_FLASH_TEST_BASE) < 0)
    {
        printf("Failed to set Data Flash base address!\n");
        goto lexit;
    }

    /* Read BS */
    printf("  Boot Mode ............................. ");
    if (FMC_GetBootSource() == 0)
        printf("[APROM]\n");
    else
    {
        printf("[LDROM]\n");
        printf("  WARNING: The driver sample code must execute in AP mode!\n");
        goto lexit;
    }

    u32Data = FMC_ReadCID();
    printf("  Company ID ............................ [0x%08x]\n", u32Data);

    u32Data = FMC_ReadPID();
    printf("  Product ID ............................ [0x%08x]\n", u32Data);

    for (i = 0; i < 3; i++)
    {
        u32Data = FMC_ReadUID(i);
        printf("  Unique ID %d ........................... [0x%08x]\n", i, u32Data);
    }

    for (i = 0; i < 4; i++)
    {
        u32Data = FMC_ReadUCID(i);
        printf("  Unique Customer ID %d .................. [0x%08x]\n", i, u32Data);
    }

    /* Read User Configuration */
    printf("  User Config 0 ......................... [0x%08x]\n", FMC_Read(FMC_CONFIG_BASE));
    printf("  User Config 1 ......................... [0x%08x]\n", FMC_Read(FMC_CONFIG_BASE+4));

    /* Read Data Flash base address */
    u32Data = FMC_ReadDataFlashBaseAddr();
    printf("  Data Flash Base Address ............... [0x%08x]\n", u32Data);

    printf("\n\nLDROM test =>\n");
    FMC_ENABLE_LD_UPDATE();
    if (flash_test(FMC_LDROM_BASE, FMC_LDROM_END, TEST_PATTERN) < 0)
    {
        printf("\n\nLDROM test failed!\n");
        goto lexit;
    }
    FMC_DISABLE_LD_UPDATE();

    printf("\n\nAPROM test =>\n");
    FMC_ENABLE_AP_UPDATE();
    if (flash_test(APROM_TEST_BASE, DATA_FLASH_TEST_BASE, TEST_PATTERN) < 0)
    {
        printf("\n\nAPROM test failed!\n");
        goto lexit;
    }
    FMC_DISABLE_AP_UPDATE();

    printf("\n\nData Flash test =>\n");
    if (flash_test(DATA_FLASH_TEST_BASE, DATA_FLASH_TEST_END, TEST_PATTERN) < 0)
    {
        printf("\n\nUHB test failed!\n");
        goto lexit;
    }

lexit:

    /* Disable FMC ISP function */
    FMC_Close();

    /* Lock protected registers */
    SYS_LockReg();

    printf("\nFMC Sample Code Completed.\n");

    while (1);
}