这是USB3.0开发的第一个程序,也是最简单的一个。通过对SDK提供的cyfxgpioapp进行分析,主要达到以下目的:
1、理解CYPRESS提供的框架程序,此框架程序是建立在ARM9和ThreadX实时操作系统的基础之上,可能会与CY7C68013A的框架程序大不样,但也不是很难理解的。
2、分析CYUSB3014的GPIO的控制,包括输入输出,中断控制等应用。
3、操作系统提供的创建线程、延时函数等的理解。
下面从头进行分析:
1、cyfxgpioapp例程在目录下:C:\Cypress\FX3 SDK\firmware\serialif_examples\cyfxgpioapp
2、如何从Eclipse导入这个例程、编绎例程,请查看我以前的帖子:http://www.eefocus.com/liangziusb/blog/11-11/234395_33da2.html
3、主程序分析。程序界面如下,
先看一下主程序的结构,
main (void)
{
CyU3PReturnStatus_t status;
CyU3PIoMatrixConfig_t io_cfg;
/* Initialize the device */
status = CyU3PDeviceInit (0);
if (status != CY_U3P_SUCCESS)
{
goto handle_fatal_error;
}
/* Configure the IO matrix for the device. */
/* On the FX3 DVK board UART lines would be routed to the COM port only
* when 32 bit GPIF mode is selected */
/* Select 32 bit GPIF mode by setting isDQ32Bit to True */
io_cfg.isDQ32Bit = CyTrue;
/* GPIO 21 is a GPIF control signal and is configured using GPIO Override API */
io_cfg.gpioSimpleEn[0] = 0;
io_cfg.gpioSimpleEn[1] = (1 << 13); /* Enable GPIO 45 */
io_cfg.gpioComplexEn[0] = 0;
io_cfg.gpioComplexEn[1] = 0;
io_cfg.useUart = CyTrue;
io_cfg.useI2C = CyFalse;
io_cfg.useI2S = CyFalse;
io_cfg.useSpi = CyFalse;
status = CyU3PDeviceConfigureIOMatrix (&io_cfg);
if (status != CY_U3P_SUCCESS)
{
goto handle_fatal_error;
}
/* This is a non returnable call for initializing the RTOS kernel */
CyU3PKernelEntry ();
/* Dummy return to make the compiler happy */
return 0;
handle_fatal_error:
/* Cannot recover from this error. */
while (1);
}
程序主要做了三件事情,一是CYUSB3014芯片的初始化,由函数CyU3PDeviceInit (0)完成;二是对IO进行配置,由函数CyU3PDeviceConfigureIOMatrix (&io_cfg)完成,三是进入操作系统的入口函数,由CyU3PKernelEntry ()完成。这些代码只执行一次。
void
CyFxApplicationDefine (
void)
{
void *ptr1, *ptr2;
uint32_t retThrdCreate;
/* Allocate the memory for the threads */
ptr1 = CyU3PMemAlloc (CY_FX_GPIOAPP_THREAD_STACK);
/* Create the thread for the application */
retThrdCreate = CyU3PThreadCreate (&GpioAppThread1, /* GPIO Example App Thread structure */
"21:GPIO Example", /* Thread ID and Thread name */
GpioAppThread1_Entry, /* GPIO Example App Thread Entry function */
0, /* No input parameter to thread */
ptr1, /* Pointer to the allocated thread stack */
CY_FX_GPIOAPP_THREAD_STACK, /* GPIO Example App Thread stack size */
CY_FX_GPIOAPP_THREAD_PRIORITY, /* GPIO Example App Thread priority */
CY_FX_GPIOAPP_THREAD_PRIORITY, /* GPIO Example App Thread priority */
CYU3P_NO_TIME_SLICE, /* No time slice for the application thread */
CYU3P_AUTO_START /* Start the Thread immediately */
);
/* Check the return code */
if (retThrdCreate != 0)
{
入口函数CyU3PKernelEntry ()执行后,直接开始执行上面的CyFxApplicationDefine ( void),其功能就是CyU3PThreadCreate()创建了两个线程,分别是GpioAppThread1和GpioAppThread2。
再来看一下线程GpioAppThread1主要做了些什么?且听下回分解。
更多文章请访问:
我的博客1:http://bbs.ednchina.com/BLOG_liangziusb_440752.HTM
我的博客2: http://www.eefocus.com/liangziusb/blog/
EDN小组http://group.ednchina.com/GROUP_GRO_14600_3466.HTM
LZ3684 USB2.0开发板(CY7C68013A), 请访问我的淘宝http://shop64171919.taobao.com
LZ3014 USB3.0开发板(CYUSB3014),请访问我的淘宝http://shop64171919.taobao.com
实体店铺:北京新中发电子市场2557号
良子.2011年
沈阳市东陵区白塔街龙盛家园
欢迎交流:liangziusb@163.com
QQ:2687652834
文章评论(0条评论)
登录后参与讨论