热度 14
2011-12-22 21:07
2456 次阅读|
2 个评论
接上篇文章。线程GpioAppThread1代码如下, /* Entry function for the GpioAppThread1 */ void GpioAppThread1_Entry (uint32_t input) { CyU3PGpioClock_t gpioClock; CyU3PGpioSimpleConfig_t gpioConfig; CyU3PReturnStatus_t apiRetStatus; /* Initialize Debug module */ CyFxGpioApplnDebugInit(); /* Init the GPIO module */ gpioClock.fastClkDiv = 2; gpioClock.slowClkDiv = 0; gpioClock.simpleDiv = CY_U3P_GPIO_SIMPLE_DIV_BY_2; gpioClock.clkSrc = CY_U3P_SYS_CLK; gpioClock.halfDiv = 0; /* Initialize Gpio interface */ apiRetStatus = CyU3PGpioInit(gpioClock, CyFxGpioIntrCb); if (apiRetStatus != 0) { /* Error Handling */ CyU3PDebugPrint (4, "GPIO Init failed, Error Code = %d\n",apiRetStatus); CyFxAppErrorHandler(apiRetStatus); } /* Override GPIO 21 as this pin is associated with GPIF Control signal */ apiRetStatus = CyU3PDeviceGpioOverride (21, CyTrue); if (apiRetStatus != 0) { /* Error Handling */ CyU3PDebugPrint (4, "GPIO Override failed, Error Code = %d\n",apiRetStatus); CyFxAppErrorHandler(apiRetStatus); } /* Configure GPIO 21 as output */ gpioConfig.outValue = CyFalse; gpioConfig.driveLowEn = CyTrue; gpioConfig.driveHighEn = CyTrue; gpioConfig.inputEn = CyFalse; gpioConfig.intrMode = CY_U3P_GPIO_NO_INTR; apiRetStatus = CyU3PGpioSetSimpleConfig(21, gpioConfig); if (apiRetStatus != CY_U3P_SUCCESS) { /* Error handling */ CyU3PDebugPrint (4, "GPIO Set Config Error, Error Code = %d\n",apiRetStatus); CyFxAppErrorHandler(apiRetStatus); } /* Configure GPIO 45 as input */ /* Configure interrupt on Both edges */ gpioConfig.outValue = CyTrue; gpioConfig.inputEn = CyTrue; gpioConfig.driveLowEn = CyFalse; gpioConfig.driveHighEn = CyFalse; gpioConfig.intrMode = CY_U3P_GPIO_INTR_BOTH_EDGE; apiRetStatus = CyU3PGpioSetSimpleConfig(45, gpioConfig); if (apiRetStatus != CY_U3P_SUCCESS) { /* Error handling */ CyU3PDebugPrint (4, "GPIO Set Config Error, Error Code = %d\n",apiRetStatus); CyFxAppErrorHandler(apiRetStatus); } for (;;) { /* Set the GPIO 21 to High */ apiRetStatus = CyU3PGpioSetValue (21, CyTrue); if (apiRetStatus != CY_U3P_SUCCESS) { /* Error handling */ CyU3PDebugPrint (4, "GPIO Set Value Error, Error Code = %d\n",apiRetStatus); CyFxAppErrorHandler(apiRetStatus); } /* Wait for some time */ CyU3PThreadSleep(2000); /* Set the GPIO 21 to Low */ apiRetStatus = CyU3PGpioSetValue (21, CyFalse); if (apiRetStatus != CY_U3P_SUCCESS) { /* Error handling */ CyU3PDebugPrint (4, "GPIO Set Value Error, Error Code = %d\n",apiRetStatus); CyFxAppErrorHandler(apiRetStatus); } /* Wait for some time */ CyU3PThreadSleep(2000); } } 上面的代码主要是A:初始化时钟相关的操作,由函数CyU3PGpioInit()完成;重载当作输出IO的GPIO21引脚,这个引脚初始化是与GPIF II的控制信号线,由函数CyU3PDeviceGpioOverride()完成,再由函数CyU3PGpioSetSimpleConfig()配置成普通输出引脚;在for(;;)循环中,设置GPIO21引脚为高电平,由函数CyU3PGpioSetValue (21, CyTrue)完成;延时两秒,由函数CyU3PThreadSleep(2000)完成;再设置GPIO21引脚为低电平,也是由函数CyU3PGpioSetValue (21, CyFalse)完成;再延时两秒,又设置GPIO21引脚为高电平,程序进入无限循环中。 另外一个线程GpioAppThread2设置GPIO45引脚为输入引脚,程序很简单,这里不再复述。 4、下载程序,实际运行 将LZ3014 USB3.0开发板与电脑相连,启动控制面板程序,如下, 如果你的开发板显示的不是“Cypress USB BootLoader”,这也没有关系,有可能是PID,VID与我的不一样,当然这与安装时的驱动相关。 如何下载固件程序,且听下回分解。