从0开始创建FX3工程之一
来源:互联网 发布:linux vncserver 安装 编辑:程序博客网 时间:2024/05/18 18:55
我们一般都是在已有的工程上修改,添加新的功能,现在从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 :
#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;voidThread1_Entry ( uint32_t input){ for (;;) { CyU3PThreadSleep (100); }}voidThread2_Entry ( uint32_t input){ for (;;) { CyU3PThreadSleep (100); }}/* Application define function which creates the application threads. */voidCyFxApplicationDefine ( 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);}intmain (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 单步调试会发现程序在两个线程之间循环执行。
阅读全文
1 0
- 从0开始创建FX3工程之一
- 从0开始创建FX3工程之二
- 从0开始创建FX3工程之三
- 从0开始创建FX3工程之四
- 从0开始创建FX3工程之五
- FX3/CX3 Thread创建
- Qt构建工具QBS之一 ——从一个简单的工程开始
- 【Android入门日记】二、从最开始开始---创建android工程
- 从0开始,创建 AWS EC2 实例
- 【tensorflow-C++之一】Beginner开始工程化
- 从create-android-project.bat开始创建eclipse下可调试的cocos2dx c++工程
- 【芝山物联】LM3S811自学笔记-2(从点亮LED灯开始之创建一个空白工程)
- FX3学习笔记1-创建线程
- Linux 学习之一GCC 从这开始
- Spring深入理解之一,从概念开始
- 如何从源文件创建工程
- 从零创建MAVEN工程
- 从零创建maven工程
- 第一章JavaScript的基础语法
- 【Hololens开发】Holograms 101: Introduction with Device(使用Hololens)
- Kibana(一):编译源码
- Toolbar 开发实践总结
- java ArrayList按照同一属性进行分组
- 从0开始创建FX3工程之一
- hdu 1846 Brave Game hdu 1847 Good Luck in CET-4 Everybody! (简单的巴什博奕)
- POJ 2763 Housewife Wind 树链剖分裸题
- 网页下载器的三种方式
- Android中View转换为Bitmap
- 使用 position:sticky 实现粘性布局
- 深入探讨 CSS 特性检测 @supports 与 Modernizr
- WEEX 使用navigator跳转Android系统出现ActivityNotFoundException报错
- 一道面试题引发的对javascript类型转换的思考