完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
main.c [C] 纯文本查看 复制代码 /**/#include "main.h"#include "sys.h"#include "delay.h"#include "FreeRTOS.h"#include "task.h"#define START_TASK_PRIO 1 /*ÈÎÎñÓÅÏȼ¶*/#define START_STK_SIZE 128 /*ÈÎÎñ¶ÑÕ»´óС*/TaskHandle_t StartTask_Handle; /*ÈÎÎñ¾ä±ú*/void StartTask(void *pvParameters); /*ÈÎÎñº¯Êý*/#define TEST1_TASK_PRIO 2#define TEST1_STK_SIZE 50TaskHandle_t TEST1Task_Handle;void Test1Task(void *pvParameters);#define TEST2_TASK_PRIO 3#define TEST2_STK_SIZE 50TaskHandle_t TEST2Task_Handle;void Test2Task(void *pvParameters);uint8_t test1, test2, test3;/***** ÉùÃ÷ *****/static void SystemInitial(void);void StartTask(void *pvParameters){ taskENTER_CRITICAL(); /*½øÈëÁÙ½çÇø*/ xTaskCreate((TaskFunction_t )Test1Task, /*ÈÎÎñº¯Êý*/(const char * )"Test1Task", /*ÈÎÎñÃû³Æ*/(uint16_t )TEST1_STK_SIZE, /*ÈÎÎñ¶ÑÕ»´óС*/(void * )NULL, /*´«µÝ¸øÈÎÎñº¯ÊýµÄ²ÎÊý*/(UBaseType_t )TEST1_TASK_PRIO, /*ÈÎÎñÓÅÏȼ¶*/(TaskHandle_t )&TEST1Task_Handle); /*ÈÎÎñ¾ä±ú*/ xTaskCreate((TaskFunction_t )Test2Task,(const char * )"Test2Task",(uint16_t )TEST2_STK_SIZE,(void * )NULL,(UBaseType_t )TEST2_TASK_PRIO,(TaskHandle_t )&TEST2Task_Handle); vTaskDelete(StartTask_Handle); /*ɾ³ý¿ªÊ¼ÈÎÎñ*/ taskEXIT_CRITICAL(); /*ÍƳöÁÙ½çÇø*/} void Test1Task(void *pvParameters){ while (1) { test1 = ~test1; vTaskDelay(2);// DelayNms(2); }} void Test2Task(void *pvParameters){ while (1) { test2 = ~test2; vTaskDelay(5); }} static void SystemInitial(void){ DelayInitial();}int main(void){ SystemInitial(); /*´´½¨¿ªÊ¼ÈÎÎñ*/ xTaskCreate((TaskFunction_t )StartTask, /*ÈÎÎñº¯Êý*/(const char * )"StartTask", /*ÈÎÎñÃû³Æ*/(uint16_t )START_STK_SIZE, /*ÈÎÎñ¶ÑÕ»´óС*/(void * )NULL, /*´«µÝ¸øÈÎÎñº¯ÊýµÄ²ÎÊý*/(UBaseType_t )START_TASK_PRIO, /*ÈÎÎñÓÅÏȼ¶*/(TaskHandle_t )&StartTask_Handle); /*ÈÎÎñ¾ä±ú*/ /*¿ªÆôÈÎÎñµ÷¶È*/ vTaskStartScheduler();}/***************************END OF FILE***************************/ delay.c [C] 纯文本查看 复制代码 /**/#include "delay.h"#include "STM32f10x.h"#include "sys.h"#if SYSTEM_SUPPORT_OS #include "FreeRTOS.h" #include "task.h"#endifstatic uint8_t fac_us=0;//usÑÓʱ±¶³ËÊý static uint16_t fac_ms=0;//msÑÓʱ±¶³ËÊý,ÔÚucosÏÂ,´ú±íÿ¸ö½ÚÅĵÄmsÊý__IO uint32_t TimingDelay; extern void xPortSysTickHandler(void);extern void TimingDelayDecrement(void);//systickÖжϷþÎñº¯Êý,ʹÓÃFreeRTOSʱÓõ½void SysTick_Handler(void){ if(xTaskGetSchedulerState()!=taskSCHEDULER_NOT_STARTED)//ϵͳÒѾÔËÐÐ { xPortSysTickHandler(); } TimingDelayDecrement();} //³õʼ»¯ÑÓ³Ùº¯Êý//SYSTICKµÄʱÖӹ̶¨ÎªAHBʱÖÓ£¬»ù´¡Àý³ÌÀïÃæSYSTICKʱÖÓƵÂÊΪAHB/8//ÕâÀïΪÁ˼æÈÝFreeRTOS£¬ËùÒÔ½«SYSTICKµÄʱÖÓƵÂʸÄΪAHBµÄƵÂÊ£¡//SYSCLK:ϵͳʱÖÓƵÂÊvoid DelayInitial(void){/* uint32_t reload;SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK); //Ñ¡ÔñÍⲿʱÖÓ HCLKfac_us=SystemCoreClock/1000000; //²»ÂÛÊÇ·ñʹÓÃOS,fac_us¶¼ÐèҪʹÓÃreload=SystemCoreClock/1000000; //ÿÃëÖӵļÆÊý´ÎÊý µ¥Î»ÎªM reload*=1000000/configTICK_RATE_HZ; //¸ù¾ÝconfigTICK_RATE_HZÉ趨Òç³öʱ¼ä //reloadΪ24λ¼Ä´æÆ÷,×î´óÖµ:16777216,ÔÚ72MÏÂ,Ô¼ºÏ0.233s×óÓÒfac_ms=1000/configTICK_RATE_HZ; //´ú±íOS¿ÉÒÔÑÓʱµÄ×îÉÙµ¥Î» SysTick->CTRL|=SysTick_CTRL_TICKINT_Msk; //¿ªÆôSYSTICKÖжÏSysTick->LOAD=reload; //ÿ1/configTICK_RATE_HZÃëÖжÏÒ»´ÎSysTick->CTRL|=SysTick_CTRL_ENABLE_Msk; //¿ªÆôSYSTICK */ fac_us=SystemCoreClock/1000000; //²»ÂÛÊÇ·ñʹÓÃOS,fac_us¶¼ÐèҪʹÓà fac_ms=1000/configTICK_RATE_HZ; //´ú±íOS¿ÉÒÔÑÓʱµÄ×îÉÙµ¥Î» /* * SystemCoreClock / 1000 1msÖжÏÒ»´Î * SystemCoreClock / 100000 10usÖжÏÒ»´Î * SystemCoreClock / 1000000 1usÖжÏÒ»´Î */ if (SysTick_Config(SystemCoreClock / 1000)) { while (1); } /*¹Ø±Õsystick timer¶¨Ê±Æ÷*/ /*SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;*/ /*ʹÄܵδð¶¨Ê±Æ÷*/ SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk; } //ÑÓʱnus//nus:ÒªÑÓʱµÄusÊý.//nus:0~204522252(×î´óÖµ¼´2^32/fac_us@fac_us=168) void DelayNus(uint32_t nus){uint32_t ticks;uint32_t told,tnow,tcnt=0;uint32_t reload=SysTick->LOAD;//LOADµÄÖµ ticks=nus*fac_us; //ÐèÒªµÄ½ÚÅÄÊý told=SysTick->VAL; //¸Õ½øÈëʱµÄ¼ÆÊýÆ÷Öµwhile(1){tnow=SysTick->VAL;if(tnow!=told){ if(tnow [C] 纯文本查看 复制代码 /* FreeRTOS V9.0.0 - Copyright (C) 2016 Real Time Engineers Ltd. All rights reserved VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. This file is part of the FreeRTOS distribution. FreeRTOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (version 2) as published by the Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception. *************************************************************************** >>! NOTE: The modification to the GPL is included to allow you to !<< >>! distribute a combined work that includes FreeRTOS without being !<< >>! obliged to provide the source code for proprietary components !<< >>! outside of the FreeRTOS kernel. !<< *************************************************************************** FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Full license text is available on the following link: http://www.freertos.org/a00114.html *************************************************************************** * * * FreeRTOS provides completely free yet professionally developed, * * robust, strictly quality controlled, supported, and cross * * platform software that is more than just the market leader, it * * is the industry's de facto standard. * * * * Help yourself get started quickly while simultaneously helping * * to support the FreeRTOS project by purchasing a FreeRTOS * * tutorial book, reference manual, or both: * * http://www.FreeRTOS.org/Documentation * * * *************************************************************************** http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading the FAQ page "My application does not run, what could be wrong?". Have you defined configASSERT()? http://www.FreeRTOS.org/support - In return for receiving this top quality embedded software for free we request you assist our global community by participating in the support forum. http://www.FreeRTOS.org/training - Investing in training allows your team to be as productive as possible as early as possible. Now you can receive FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers Ltd, and the world's leading authority on the world's leading RTOS. http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, including FreeRTOS+Trace - an indispensable productivity tool, a DOS compatible FAT file system, and our tiny thread aware UDP/IP stack. http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate. Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS. http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS licenses offer ticketed support, indemnification and commercial middleware. http://www.SafeRTOS.com - High Integrity Systems also provide a safety engineered and independently SIL3 certified version for use in safety and mission critical applications that require provable dependability. 1 tab == 4 spaces!*/#ifndef FREERTOS_CONFIG_H#define FREERTOS_CONFIG_H#include "sys.h"//#include "usart.h"//Õë¶Ô²»Í¬µÄ±àÒëÆ÷µ÷Óò»Í¬µÄstdint.hÎļþ#if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__) #include |
|
相关推荐
4个回答
|
|
麻烦直接用示波器测试!!!不要看MDK的这啥软件仿真
|
|
|
|
|
|
|
|
|
|
|
|
只有小组成员才能发言,加入小组>>
800 浏览 0 评论
1156 浏览 1 评论
2531 浏览 5 评论
2863 浏览 9 评论
移植了freeRTOS到STMf103之后显示没有定义的原因?
2714 浏览 6 评论
keil5中manage run-time environment怎么是灰色,不可以操作吗?
1092浏览 3评论
197浏览 2评论
463浏览 2评论
376浏览 2评论
M0518 PWM的电压输出只有2V左右,没有3.3V是怎么回事?
458浏览 1评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-25 04:42 , Processed in 0.879463 second(s), Total 52, Slave 44 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号