Beispiel #1
0
int CodeTest(int codeid)
{
	if (codeid == 1)
	{
		/* test SearchDefine.json */
		//ReadSearchDefine("SearchDefine.json", Search);
		//printf("\n\n");
	} else if (codeid == 2)
	{
		/* test DeviceDefine.json */
		//ReadDeviceDefine("DeviceDefine.json", Device);
		//printf("\n\n");
	} else if (codeid == 3)
	{
		// GPIO test
		GPIO_Init(0xFFFFFFFF);
		BOOL bState = FALSE;
		while (TRUE)
		{
			bState = !bState;
			printf("\nSet GPIO 0 state: %d\tGPIO 1 state: %d", bState, !bState);
			GPIO_Out((1 << 0), bState);
			GPIO_Out((1 << 1), bState);
			sleep(5);
		}
		GPIO_Close();
	} else if (codeid == 4)
	{
		// alive test
		SendData(CreateAlivePacket(Search->DepartmentID, Search->SwitchgearID, GC.AliveMessage));
	}

	return 0;
}
Beispiel #2
0
int main(int argc, char ** argv)
{
	if (argc >= 2)
	{
		pthread_t network_thread;

		printf("\nCode testing...");

		InitGlobalConfig(&GC);
		Init();
		InitSearch();
		GPIO_Init(0xFFFFFFFF);

		pthread_create(&network_thread, NULL, thread_network, NULL);
		CodeTest(atoi(argv[1]));

		GPIO_Close();
	} else
	{
		pthread_t network_thread;

		printf("\n电力电压和开关状态上传");

		InitGlobalConfig(&GC);
		Init();
		InitSearch();

		GPIO_Init(0xFFFFFFFF);

		pthread_create(&network_thread, NULL, thread_network, NULL);

		thread_CommonSearch(Search);

		GPIO_Close();
	}

	return 0;
}
Beispiel #3
0
int main(void)
{
    int32_t i32Err;

    sysDisableCache();
    sysFlushCache(I_D_CACHE);
    sysEnableCache(CACHE_WRITE_BACK);
    sysInitializeUART();

    sysprintf("+-------------------------------------------------+\n");
    sysprintf("|                 GPIO Sample Code                |\n");
    sysprintf("+-------------------------------------------------+\n\n");

    /* Configure Port C to input mode and pull-up */
    GPIO_Open(GPIOC, DIR_INPUT, PULL_UP);
   
    /* Set Port C output data to 0xFFF */
    GPIO_Set(GPIOC, 0xFFF);

    /* Set Port C output data to 0x000 */
    GPIO_Clr(GPIOC, 0xFFF);

    /* Configure Port C to default value */
    GPIO_Close(GPIOC);

    i32Err = 0;
    sysprintf("GPIO PD.3(output mode) connect to PD.4(input mode) ......");

    /* Configure PD3 to output mode */
    GPIO_OpenBit(GPIOD, BIT3, DIR_OUTPUT, NO_PULL_UP);

    /* Configure PD4 to output mode */
    GPIO_OpenBit(GPIOD, BIT4, DIR_INPUT, NO_PULL_UP);

    /* Use Pin Data Input/Output Control to pull specified I/O or get I/O pin status */
    /* Pull PD.3 to High and check PD.4 status */
    GPIO_SetBit(GPIOD, BIT3);

    if(GPIO_ReadBit(GPIOD,BIT4)==0)  
      i32Err = 1;

    /* Pull PD.3 to Low and check PD.4 status */
    GPIO_ClrBit(GPIOD, BIT3);

    if(GPIO_ReadBit(GPIOD,BIT4)==1)  
      i32Err = 1;

    if(i32Err)
    {
        sysprintf("  [FAIL].\n");
    }
    else
    {
        sysprintf("  [OK].\n");
    }

    /* Configure PD3 to default value */
    GPIO_CloseBit(GPIOD, BIT3);

    /* Configure PD4 to default value */
    GPIO_CloseBit(GPIOD, BIT3);

    /* Set MFP_GPF11 to EINT0 */
    outpw(REG_SYS_GPF_MFPH,(inpw(REG_SYS_GPF_MFPH) & ~(0xF<<12)) | (0xF<<12));

    /* Configure PF11 to input mode and pull-up */
    GPIO_OpenBit(GPIOF, BIT11, DIR_INPUT, PULL_UP);

    /* Confingure PF11 to rising-edge trigger */
    GPIO_EnableTriggerType(GPIOF, BIT11,RISING);

    /* Enable external 0 interrupt */
    GPIO_EnableEINT(NIRQ0, (GPIO_CALLBACK)EINT0Callback, 0);

    /* waiting for external 0 interrupt */
    sysprintf("waiting for PF11 rsing-edge trigger...");
    while(!eint_complete);

    /* Disable PF11 trigger type */
    GPIO_DisableTriggerType(GPIOF, BIT11);

    /* Enable external 0 interrupt */
    GPIO_DisableEINT(NIRQ0);

    sysprintf("  [OK].\n");

    /* Configure PF11 to default value */
    GPIO_CloseBit(GPIOF, BIT11);


    /* Configure PE3 to output mode */
    GPIO_OpenBit(GPIOE, BIT3, DIR_INPUT, NO_PULL_UP);

    /* Confingure PE3 to falling-edge trigger */
    GPIO_EnableTriggerType(GPIOE, BIT3,FALLING);

    /* Enable GPIOE interrupt */
    GPIO_EnableInt(GPIOE, (GPIO_CALLBACK)GPIOECallback, 0);

    /* waiting for external 0 interrupt */
    sysprintf("waiting for PE3 falling-edge trigger...");
    while(!gpio_complete);

    /* Disable PE3 to trigger type */
    GPIO_DisableTriggerType(GPIOE, BIT3);

    /* Disable GPIOE interrupt */
    GPIO_DisableInt(GPIOE);

    /* Configure PE0 to default value */
    GPIO_CloseBit(GPIOE, BIT3);

    sysprintf("  [OK].\n");

    while(1);
}