从0开始创建FX3工程之一 - 框架
2017-07-05 10:57
941 查看
我们一般都是在已有的工程上修改,添加新的功能,现在从0开始创建一个新的工程。
1. 创建工程 菜单栏,File-new-project- Cypress
点击next,进入下图:
输入项目名,点击finish即可。(有三个模板可供选择,此处我们不需要勾选)
2. 而后我们看到项目有三个文件,mekefile先不管,里面很多问题。
cyfxtx.c :This file provides the application specific exception handlers and memory allocation routines. 了解即可。不需要更改此文件。
cyfx_gcc_startup.S 是启动汇编代码,作用是初始化bss和堆栈等,最够跳入main函数(b main)。不需要更改此文件。
2. 下一步我们要做的就是创建main函数,并添加我们的功能代码了。
我们添加两个文件main.c main.h .
main函数的框架cypress已经给我们规定好了.
main.h :
main.c :
此程序很简单,只是创建2个线程,线程里sleep。分别在两个线程的 CyU3PThreadSleep (100);添加断点,F6 单步调试会发现程序在两个线程之间循环执行。
1. 创建工程 菜单栏,File-new-project- Cypress
点击next,进入下图:
输入项目名,点击finish即可。(有三个模板可供选择,此处我们不需要勾选)
2. 而后我们看到项目有三个文件,mekefile先不管,里面很多问题。
cyfxtx.c :This file provides the application specific exception handlers and memory allocation routines. 了解即可。不需要更改此文件。
cyfx_gcc_startup.S 是启动汇编代码,作用是初始化bss和堆栈等,最够跳入main函数(b main)。不需要更改此文件。
2. 下一步我们要做的就是创建main函数,并添加我们的功能代码了。
我们添加两个文件main.c main.h .
main函数的框架cypress已经给我们规定好了.
main.h :
#ifndef MAIN_H_ #define MAIN_H_ #include "cyu3types.h" #define THREAD_STACK (0x0200) /* App thread stack size */ #define THREAD_PRIORITY (8) /* App thread priority */ #endif /* MAIN_H_ */
main.c :
#include "cyu3system.h" #include "cyu3os.h" #include "cyu3error.h" #include "cyu3gpio.h" #include "cyu3uart.h" #include "cyu3utils.h" #include "main.h" CyU3PThread Thread1; CyU3PThread Thread2; void Thread1_Entry ( uint32_t input) { for (;;) { CyU3PThreadSleep (100); } } void Thread2_Entry ( uint32_t input) { for (;;) { CyU3PThreadSleep (100); } } /* Application define function which creates the application threads. */ void CyFxApplicationDefine ( void) {//CyFxApplicationDefine用来创建线程的。此处我们创建2个线程 void *ptr = NULL; uint32_t ret = CY_U3P_ERROR_MEMORY_ERROR; // Create thread1 ptr = CyU3PMemAlloc (THREAD_STACK); if (ptr != NULL) { ret = CyU3PThreadCreate ( &Thread1, /* Thread structure. */ "Thread 1", /* Thread ID and name. */ Thread1_Entry, /* Thread entry function. */ 0, /* Thread input parameter. */ ptr, /* Pointer to the allocated thread stack. */ THREAD_STACK, /* Allocated thread stack size. */ THREAD_PRIORITY, /* Thread priority. */ THREAD_PRIORITY, /* Thread pre-emption threshold: No preemption. */ CYU3P_NO_TIME_SLICE, /* No time slice. */ CYU3P_AUTO_START /* Start the thread immediately. */ ); } else { ret = CY_U3P_ERROR_MEMORY_ERROR; } if (ret != CY_U3P_SUCCESS) { goto InitFail; } // Create thread2 ptr = CyU3PMemAlloc (THREAD_STACK); if (ptr != NULL) { ret = CyU3PThreadCreate ( &Thread2, /* Thread structure. */ "Thread 2", /* Thread ID and name. */ Thread2_Entry, /* Thread entry function. */ 0, /* Thread input parameter. */ ptr, /* Pointer to the allocated thread stack. */ THREAD_STACK, /* Allocated thread stack size. */ THREAD_PRIORITY, /* Thread priority. */ THREAD_PRIORITY, /* Thread pre-emption threshold: No preemption. */ CYU3P_NO_TIME_SLICE, /* No time slice. */ CYU3P_AUTO_START /* Start the thread immediately. */ ); } else { ret = CY_U3P_ERROR_MEMORY_ERROR; } if (ret != CY_U3P_SUCCESS) { goto InitFail; } return; InitFail: /* As the initialization failed, there is nothing much we can do. Just reset the device * so that we go back to the boot-loader. */ CyU3PDeviceReset (CyFalse); } int main (void) { CyU3PIoMatrixConfig_t io_cfg; CyU3PReturnStatus_t status = CY_U3P_SUCCESS; /* Initialize the device */ //CPU时钟设置、VIC(向量中断控制器)初始化、设置PLLs(锁相环) //input clk = 19.2 M;SYS_CLK_PLL = 384M,/2.... // Start with the default clock at 384 MHz /* Initialize the device */ /* For default configuration, pass in NULL as parameter. This will set CPU divider * to 2 (~200MHz), DMA and MMIO dividers to 2 (~100MHz); and assume 32KHz standby * clock is supplied */ status = CyU3PDeviceInit (NULL); if (status != CY_U3P_SUCCESS) { goto handle_fatal_error; } /* Initialize the caches. Enable both Instruction and Data caches. */ //一般在有大数据处理的时候才会打开数据cache,如果是简单的处理打开了cache可能会降低整个系统的效率!cache size:8k. status = CyU3PDeviceCacheControl (CyTrue, CyTrue, CyTrue); if (status != CY_U3P_SUCCESS) { goto handle_fatal_error; } /* Configure the IO matrix for the device. */ CyU3PMemSet ((uint8_t *)&io_cfg, 0, sizeof(io_cfg)); io_cfg.isDQ32Bit = CyFalse; io_cfg.s0Mode = CY_U3P_SPORT_INACTIVE; io_cfg.s1Mode = CY_U3P_SPORT_INACTIVE; io_cfg.useUart = CyTrue; io_cfg.useI2C = CyFalse; io_cfg.useI2S = CyFalse; io_cfg.useSpi = CyFalse; io_cfg.lppMode = CY_U3P_IO_MATRIX_LPP_UART_ONLY; /* No GPIOs are enabled. */ io_cfg.gpioSimpleEn[0] = 0; io_cfg.gpioSimpleEn[1] = 0; io_cfg.gpioComplexEn[0] = 0; io_cfg.gpioComplexEn[1] = 0; 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 ();//执行到此会跳入: CyFxApplicationDefine(). /* Dummy return to make the compiler happy */ return 0; handle_fatal_error: /* Cannot recover from this error. */ while (1); }
此程序很简单,只是创建2个线程,线程里sleep。分别在两个线程的 CyU3PThreadSleep (100);添加断点,F6 单步调试会发现程序在两个线程之间循环执行。
相关文章推荐
- 从0开始创建FX3工程之二 - UART
- 从0开始创建FX3工程之四 - I2C
- 从0开始创建FX3工程之五 - SPI
- 从0开始创建FX3工程之三 - GPIO
- html基础 frameset框架 中 创建 返回最开始的页面 的超链接 <a> target="_top"
- 使用idea14.1.4创建maven多项目工程搭建jfinal框架报错
- html基础 frameset框架 中 创建 返回最开始的页面 的超链接 <a> target="_top"
- 安卓训练-开始-开发你的第一个应用-创建安卓工程
- Yii框架官方教程增补篇3——开始:创建第一个Yii应用
- [Sciter系列] MFC下的Sciter–1.创建工程框架
- 【python爬虫】scrapy框架笔记(一):创建工程,使用scrapy shell,xpath
- 用Nancy和Simple.Data创建一个图片博客 第一部分:开始一个工程
- cxxtest单元测试框架应用(二):如何创建单工程的测试框架
- Maven创建一个聚合工程(框架)
- 创建 工程和myworkspace工作空间、静态库和框架之间的关系
- 如何通过Eclipse创建Web工程、正确配置Tomcat及Shiro安全框架入门
- Git参考手册(2)-开始创建工程
- 使用Zend Framework的zf.bat创建工程【创建zf框架】
- iOS7章节—创建基于SpriteKit框架的游戏工程
- 从create-android-project.bat开始创建eclipse下可调试的cocos2dx c++工程