Пример #1
0
/**
 * @brief This function used to read the saved IO status or register default IO settings
 * @param None
 * @return None
 */
void IO_status_init(void)
{
	uint8_t i;
	read_IOstorage(&IOdata, sizeof(IOdata));

	// IO Status & Alias Initialization
	// Initialize for WIZ550web Baseboard Configuration
	if(!((IOdata.io_statuscode[0] == 0xAA) && (IOdata.io_statuscode[1] == 0x01)))
	{
#ifdef _WEB_DEBUG_
		printf("\r\nIO Status Detection code: [%.02x][%.02x]\r\n", IOdata.io_statuscode[0], IOdata.io_statuscode[1]);
#endif
		// IO Status Detection code Initialize
		IOdata.io_statuscode[0] = 0xAA;
		IOdata.io_statuscode[1] = 0x01;

		// IO Direction Initialize
		IOdata.io[D0] = Output;
		IOdata.io[D1] = Output;
		IOdata.io[D2] = Output;
		IOdata.io[D3] = Output;
		IOdata.io[D4] = Output;
		IOdata.io[D5] = Output;
		IOdata.io[D6] = Output;
		IOdata.io[D7] = Output;
		IOdata.io[D8] = Input;
		IOdata.io[D9] = Input;
		IOdata.io[D10] = Input;
		IOdata.io[D11] = Input;
		IOdata.io[D12] = Input;
		IOdata.io[D13] = Input;
		IOdata.io[D14] = Input;
		IOdata.io[D15] = Input;

		// Each IO Status Initialize
		for(i = 0; i < IOn; i++)
		{
			IOdata.ios[i] = Off;
		}

		// IO Alias fields Initialize
		for(i = 0; i < IOn; i++)
		{
			memset(IOdata.io_alias[i], 0x00, 25);
			sprintf((char *)IOdata.io_alias[i], "Digital IO #%d", i);
		}

		write_IOstorage(&IOdata, sizeof(IOdata));

#ifdef _WEB_DEBUG_
		printf(">> Default IO Status / Alias Initialize Success\r\n\r\n");
#endif
	}
#ifdef _WEB_DEBUG_
	else
	{
		printf(">> IO Status / Alias Load Success\r\n\r\n");
	}
#endif

	GPIO_PinRemapConfig (GPIO_Remap_SWJ_Disable, ENABLE);

	// IO Direction setting after load or set default
	for(i = 0; i < IOn; i++)
	{
		if((IOdata.io[i] != NotUsed) && (IOdata.io[i] != 0xFF))
		{
			IO_Init(i);
		}
	}

	// Each IO Status Initialize
	for(i = 0; i < IOn; i++)
	{
		if(IOdata.io[i] == Output)
		{
			if(IOdata.ios[i] == Off)	IO_Off(i);
			else						IO_On(i);
		}
	}
}
void factory_test_2nd (void)
{
	int i;
	//uint16 adc_val = 0;
	int fail_count;
    EXTI_InitTypeDef EXTI_InitStructure;

    EXTI_InitStructure.EXTI_Line = EXTI_Line12 | EXTI_Line2 | EXTI_Line3 | EXTI_Line4;
    EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
    EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling;//EXTI_Trigger_Falling;
    EXTI_InitStructure.EXTI_LineCmd = DISABLE;
    EXTI_Init(&EXTI_InitStructure);

	// check D0~D7(output/off) D8~15 input/off
	if (teststep == 3)
	{
		//delay_ms(100);
		fail_count = 0;
		for(i = 0; i < IOn; i++)
		{
			if (get_IO_Status(i) == Off)
			{
				if(i < 8)
				{
					delay_ms(1);
					//printf("########## D%d output/off OK.\r\n", i);
				}
				else
				{
					delay_ms(1);
					//printf("########## D%d input/off OK.\r\n", i);
				}
			}
			else
			{
				if(i < 8)
				{
					fail_count += 1;
					printf("########## D%d output/off Fail.\r\n", i);
				}
				else
				{
					printf("########## D%d input/off Fail.\r\n", i);
					fail_count += 1;
				}
			}
		}

		if(fail_count == 0)
		{
			printf("########## D0~D7[output/off] D8~D15[input/off] OK.\r\n");
		}

		teststep = 4;
	}

	// check D0~D7(output/on) D8~15 input/on
	if (teststep == 4)
	{
		fail_count = 0;
		for(i = 0; i < 8/*IOn*/; i++)
		{
			IOdata.ios[i] = On;
		}

	   	for(i = 0; i < 8/*IOn*/; i++)
	   	{
	   		if(IOdata.io[i] == Output)
	   		{
	   			if(IOdata.ios[i] == Off)	IO_Off(i);
	   			else						IO_On(i);
	   		}
	   	}

		for(i = 0; i < IOn; i++)
		{
			if (get_IO_Status(i) == On)
			{
				if(i < 8)
				{
					delay_ms(1);
					//printf("########## D%d output/on OK.\r\n", i);
				}
				else
				{
					delay_ms(1);
					//printf("########## D%d input/on OK.\r\n", i);
				}
			}
			else
			{
				if(i < 8)
				{
					fail_count += 1;
					printf("########## D%d output/on Fail.\r\n", i);
				}
				else
				{
					fail_count += 1;
					printf("########## D%d input/on Fail.\r\n", i);
				}
			}
		}

		if(fail_count == 0)
		{
			printf("########## D0~D7[output/on] D8~D15[input/on] OK.\r\n");
		}

		teststep = 5;
	}

	// check A0~A3
	if (teststep == 5)
	{
		fail_count = 0;
#if 0
		for(i = 0; i < 4; i++)
		{
			adc_val = ADC_DualConvertedValueTab[i];
			if (adc_val > 100) //TODO
			{
				delay_ms(1);
		    	//printf("########## A%d[%d] OK.\r\n", i, adc_val);
			}
			else
			{
				fail_count += 1;
		    	printf("########## A%d[%d] Fail.\r\n", i, adc_val);
			}
		}
#endif
		if(fail_count == 0)
		{
			printf("########## A0 = %d || A1 = %d || A2 = %d || A3 = %d\r\n", ADC_DualConvertedValueTab[0]
			                                                                , ADC_DualConvertedValueTab[1]
			                                                                , ADC_DualConvertedValueTab[2]
			                                                                , ADC_DualConvertedValueTab[3]);
		}

		teststep = 6;
	}

	printf("########## Test Completed.\r\n");
	//check_factory_uart1();
}