FreeRTOS学习笔记——任务间使用队列同步数据
1.前言
2.参考代码
/* Standard includes. */
#include <stdio.h>
#include <stdint.h>
/* Scheduler includes. */
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
/* Library includes. */
#include "stm32f10x.h"
#define LED0_ON() GPIO_SetBits(GPIOB,GPIO_Pin_5);
#define LED0_OFF() GPIO_ResetBits(GPIOB,GPIO_Pin_5);
/* 队列句柄 */
xQueueHandle MsgQueue;
static void prvSetupHardware( void );
void TaskA( void *pvParameters );
void TaskB( void *pvParameters );
void LedInit(void);
void UART1Init( void );
int main( void )
{
/* 初始化硬件平台 */
prvSetupHardware(); /* 建立队列 */
MsgQueue = xQueueCreate( 5 , sizeof( int16_t ) );
/* 建立任务 */
xTaskCreate( TaskA, ( signed portCHAR * ) "TaskA", configMINIMAL_STACK_SIZE,
NULL, tskIDLE_PRIORITY+3, NULL );
xTaskCreate( TaskB, ( signed portCHAR * ) "TaskB", configMINIMAL_STACK_SIZE,
NULL, tskIDLE_PRIORITY+4, NULL );
/* 启动OS */
vTaskStartScheduler(); return 0;
}
/*-----------------------------------------------------------*/
void TaskA( void *pvParameters )
{
int16_t SendNum = 1;
for( ;; )
{
vTaskDelay( 2000/portTICK_RATE_MS );
/* 向队列中填充内容 */
xQueueSend( MsgQueue, ( void* )&SendNum, 0 );
SendNum++;
}
}
void TaskB( void *pvParameters )
{
int16_t ReceiveNum = 0;
for( ;; )
{
/* 从队列中获取内容 */
if( xQueueReceive( MsgQueue, &ReceiveNum, 100/portTICK_RATE_MS ) == pdPASS)
{
printf("ReceiveNum:%d\r\n",ReceiveNum);
}
}
}
static void prvSetupHardware( void )
{
LedInit();
UART1Init();
}
void LedInit( void )
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB, ENABLE );
/*LED0 @ GPIOB.5*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init( GPIOB, &GPIO_InitStructure );
}
void UART1Init( void )
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure; /* 第1步:打开GPIO和USART时钟 */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_USART1, ENABLE); /* 第2步:将USART1 Tx@PA9的GPIO配置为推挽复用模式 */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure); /* 第3步:将USART1 Rx@PA10的GPIO配置为浮空输入模式 */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure); /* 第4步:配置USART1参数 */
USART_InitStructure.USART_BaudRate = 9600;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART1, &USART_InitStructure); /* 第5步:使能 USART1, 配置完毕 */
USART_Cmd(USART1, ENABLE);
}
int fputc(int ch, FILE *f)
{
/* 写一个字节到USART1 */
USART_SendData(USART1, (uint8_t) ch);
/* 等待发送结束 */
while (USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET)
{}
return ch;
}

3.若干说明
4.总结
FreeRTOS学习笔记——任务间使用队列同步数据的更多相关文章
- muduo网络库学习笔记(三)TimerQueue定时器队列
目录 muduo网络库学习笔记(三)TimerQueue定时器队列 Linux中的时间函数 timerfd简单使用介绍 timerfd示例 muduo中对timerfd的封装 TimerQueue的结 ...
- ASP.NET MVC 学习笔记-7.自定义配置信息 ASP.NET MVC 学习笔记-6.异步控制器 ASP.NET MVC 学习笔记-5.Controller与View的数据传递 ASP.NET MVC 学习笔记-4.ASP.NET MVC中Ajax的应用 ASP.NET MVC 学习笔记-3.面向对象设计原则
ASP.NET MVC 学习笔记-7.自定义配置信息 ASP.NET程序中的web.config文件中,在appSettings这个配置节中能够保存一些配置,比如, 1 <appSettin ...
- VSTO学习笔记(十四)Excel数据透视表与PowerPivot
原文:VSTO学习笔记(十四)Excel数据透视表与PowerPivot 近期公司内部在做一种通用查询报表,方便人力资源分析.统计数据.由于之前公司系统中有一个类似的查询使用Excel数据透视表完成的 ...
- Spring MVC 学习笔记11 —— 后端返回json格式数据
Spring MVC 学习笔记11 -- 后端返回json格式数据 我们常常听说json数据,首先,什么是json数据,总结起来,有以下几点: 1. JSON的全称是"JavaScript ...
- 【Spring学习笔记-MVC-4】SpringMVC返回Json数据-方式2
<Spring学习笔记-MVC>系列文章,讲解返回json数据的文章共有3篇,分别为: [Spring学习笔记-MVC-3]SpringMVC返回Json数据-方式1:http://www ...
- 【Spring学习笔记-MVC-3】SpringMVC返回Json数据-方式1
<Spring学习笔记-MVC>系列文章,讲解返回json数据的文章共有3篇,分别为: [Spring学习笔记-MVC-3]SpringMVC返回Json数据-方式1:http://www ...
- Caffe学习笔记(三):Caffe数据是如何输入和输出的?
Caffe学习笔记(三):Caffe数据是如何输入和输出的? Caffe中的数据流以Blobs进行传输,在<Caffe学习笔记(一):Caffe架构及其模型解析>中已经对Blobs进行了简 ...
- Java学习笔记:基本输入、输出数据操作实例分析
Java学习笔记:基本输入.输出数据操作.分享给大家供大家参考,具体如下: 相关内容: 输出数据: print println printf 输入数据: Scanner 输出数据: JAVA中在屏幕中 ...
- python学习笔记六——堆栈和队列
4.2.3 列表的查找.排序.反转 list列表可以进行添加.删除操作,此外List列表还提供了查找元素的方法.list列表的查找提供了两种方式,一种是使用index方法返回元素在列表中的位置,另一种 ...
随机推荐
- 自己制作精美的App Store 软件截屏
当用户搜索到App的时候,一般都会先看截图,如果截图效果不好,可能用户就不会下载. 不想自己辛苦写的认为还不错的软件,因为截图的原因,而降低了很多下载量吧. 轻轻松松做出这样高大上的截屏效果来. Sc ...
- amf0解释一下
就简单记录一下省了以后忘了,amf0其实就几种数据格式的网络传输格式,比如数字,字符串,这些格式在传输的时候他给单独序列化了一下,主要支持以下这些: #define AMF0_NUMBER ((uin ...
- Android 视图切换库的使用 - SwitichLayout
要点: 1. SwitichLayout 原理和基本特效展示 - 设计上和基本特效 2. SwitchLayout 的用法 - SwitchLayout 的基本配置和用法 3. SwithLayout ...
- TatukGIS-TGIS_LayerVector-LocateEx
方法原型: function LocateEx(const _ptg: TGIS_Point; const _prec: Double; const _uid: Integer; var _dist: ...
- Python爬虫常用模块,BeautifulSoup笔记
import urllib import urllib.request as request import re from bs4 import * #url = 'http://zh.house.q ...
- Python Tutorial 学习(十)-- Brief Tour of the Standard Library
10.1. Operating System Interface os库 import os os.getcwd() # Return the current working directory 'C ...
- tableview 编辑状态设置
#pragma mark - tableview 编辑状态设置 -(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSI ...
- EasyUI篇のico
所有图标位置: /themes/icons css引用位置: /themes/icon.css 可自行添加16*16的小图片放在icons中,icon.css代码添加即可 例如: .icon-logo ...
- bt种子文件文件结构
估计80%以上接触互联网的人都知道bt是什么东西,任何一个用bt下载的人都知道这样一个概念,种子.bt种子就是记录了p2p对等网络中tracker, nodes, files等信息,也就是说,这个 ...
- 概率质量函数:怀孕周期的PMF
__author__ = 'dell' import surveyimport Pmfimport matplotlib.pyplot as pyplot table = survey.Pregnan ...