CMSIS Example - Signal and Yield
/*----------------------------------------------------------------------------
* RL-ARM - RTX
*----------------------------------------------------------------------------
* Name: RTX_EX2.C
* Purpose: RTX example program
*----------------------------------------------------------------------------
*
* Copyright (c) 1999-2009 KEIL, 2009-2012 ARM Germany GmbH
* All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of ARM nor the names of its contributors may be used
* to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*---------------------------------------------------------------------------*/ #include "cmsis_os.h" volatile uint16_t counter; /* counter for main thread */
volatile uint16_t counter1; /* counter for thread 1 */
volatile uint16_t counter2; /* counter for thread 2 */
volatile uint16_t counter3; /* counter for thread 3 */ /* Thread IDs */
osThreadId thread1_id;
osThreadId thread2_id;
osThreadId thread3_id; /* Forward reference */
void job1 (void const *argument);
void job2 (void const *argument);
void job3 (void const *argument); /* Thread definitions */
osThreadDef(job1, osPriorityAboveNormal, , );
osThreadDef(job2, osPriorityNormal, , );
osThreadDef(job3, osPriorityNormal, , ); /*----------------------------------------------------------------------------
* Thread 1: 'job1'
*---------------------------------------------------------------------------*/
void job1 (void const *argument) { /* higher priority to preempt job2 */
while () { /* endless loop */
counter1++; /* increment counter 1 */
osDelay(); /* wait for timeout: 10ms */
}
} /*----------------------------------------------------------------------------
* Thread 2: 'job2'
*---------------------------------------------------------------------------*/
void job2 (void const *argument) {
while () { /* endless loop */
counter2++; /* increment counter 2 */
if (counter2 == ) { /* signal overflow of counter 2 */
osSignalSet(thread3_id, 0x0001);/* to thread 3 */
osThreadYield();
}
}
} /*----------------------------------------------------------------------------
* Thread 3: 'job3'
*---------------------------------------------------------------------------*/
void job3 (void const *argument) {
while () { /* endless loop */
osSignalWait(0x0001, osWaitForever); /* wait for signal event */
counter3++; /* process overflow from counter 2 */
}
} /*----------------------------------------------------------------------------
* Main Thread
*---------------------------------------------------------------------------*/
int main (void) { /* program execution starts here */ /* Set higher priority of main thread to preempt job2 */
osThreadSetPriority(osThreadGetId(), osPriorityAboveNormal); thread1_id = osThreadCreate(osThread(job1),NULL); /* create thread1 */
thread2_id = osThreadCreate(osThread(job2),NULL); /* create thread2 */
thread3_id = osThreadCreate(osThread(job3),NULL); /* create thread3 */ while () { /* endless loop */
counter++; /* increment counter */
osDelay(); /* wait for timeout: 5ms */
}
} /*----------------------------------------------------------------------------
* end of file
*---------------------------------------------------------------------------*/
CMSIS Example - Signal and Yield的更多相关文章
- CMSIS Example - Signal
/*---------------------------------------------------------------------------- * RL-ARM - RTX *----- ...
- Python yield与实现
Python yield与实现 yield的功能类似于return,但是不同之处在于它返回的是生成器. 生成器 生成器是通过一个或多个yield表达式构成的函数,每一个生成器都是一个迭代器(但是迭 ...
- Unity StrangeIoc框架 (三)signal信号方式
先创建TestRoot using UnityEngine; using System.Collections; using strange.extensions.context.impl; publ ...
- Java并发编程之线程生命周期、守护线程、优先级、关闭和join、sleep、yield、interrupt
Java并发编程中,其中一个难点是对线程生命周期的理解,和多种线程控制方法.线程沟通方法的灵活运用.这些方法和概念之间彼此联系紧密,共同构成了Java并发编程基石之一. Java线程的生命周期 Jav ...
- sleep(),wait(),yield()和join()方法的区别
sleep() sleep()方法需要指定等待的时间,它可以让当前正在执行的线程在指定的时间内暂停执行,进入阻塞状态,该方法既可以让其他同优先级或者高优先级 的线程得到执行的机会,也可以让低优先级的线 ...
- yield 与生成器
yield的功能类似于return,但是不同之处在于它返回的是生成器. 生成器 生成器是通过一个或多个yield表达式构成的函数,每一个生成器都是一个迭代器(但是迭代器不一定是生成器). 如果一个函数 ...
- Java并发学习 & Executor学习 & 异常逃逸 & 同步互斥Best Practice & wait/notify, conditon#await/signal
看了这篇文章:http://www.ciaoshen.com/2016/10/28/tij4-21/ 有一些Java并发的内容,另外查了一些资料. 朴素的Thread 首先,Java中关于线程Thre ...
- python yield学习
yield的功能类似于return,但是不同之处在于它返回的是生成器. 生成器生成器是通过一个或多个yield表达式构成的函数,每一个生成器都是一个迭代器(但是迭代器不一定是生成器). 如果一个函数包 ...
- Python3基础 yield StopIteration.value获取函数的返回值
Python : 3.7.3 OS : Ubuntu 18.04.2 LTS IDE : pycharm-community-2019.1.3 ...
随机推荐
- 关于nginx upstream的几种配置方式
平时一直依赖硬件来作load blance,最近研究Nginx来做负载设备,记录下upstream的几种配置方式. 第一种:轮询 upstream test{ server 192.168.0 ...
- AFNetWorking 使用记录
1.从一个URL GET数据 方法1: NSURL * url = [NSURL URLWithString:@"http://www.weather.com.cn/data/sk/101 ...
- PDF数据提取------2.相关类介绍
1.简介 构造数据类型PdfString封装Rect类,PdfAnalyzer类中定义一些PDF解析方法. 2.PdfString类与Rect类 public class PdfString : IC ...
- ansible中文手册-基础模块使用
此篇文章主要是翻译ansible官网文档而来,在里面讲述了如何使用ansible的基础模块,总体感觉比较晦涩,但是后面会写出自己相关实践的文档,从而更加通俗易懂,官网的东西拿来当手册偶尔翻翻也是很不错 ...
- Win7+VS2013初试Thrift
win7环境下VS2013编译boost_1_58_0步骤: 官网下载boost_1_58_0(直接下载),解压 cmd窗口cd到boost_1_58_0,执行bootstrap.bat cmd窗口获 ...
- Windows 下命令行修改文件夹的控制权限 Cacls
设置用户访问权限:我们经常要修改目录和文件的访问权限,使用Cacls命令就很容易做到.下面要赋予本机用户testuser对d盘下 test目录及其所有子目录中的文件有完全控制权限.在命令提示符对话框中 ...
- NET知识大纲
第一部分 C#编程基础 1.(30)变量.运算符(+.-.*./.++.--.括号.==.!=.>.<.>=.<=.&&.||).流程控制(if.while.f ...
- 设计模式 命令-Command
命令-Command 当要向不同类的对象发出相同的请求时,可以将接收者和他的动作封装进一个命令对象.这样调用者只和命令产生依赖.而不会和众多的接收者发生依赖. Head First例子 要设计一款遥控 ...
- C++中cin、cin.get()、cin.getline()、getline()、gets()等函数的用法----细节决定成败 (sort用法)
C++中cin.cin.get().cin.getline().getline().gets()等函数的用法 学C++的时候,这几个输入函数弄的有点迷糊:这里做个小结,为了自己复习,也希望对后来者能有 ...
- python日志模块logging
python日志模块logging 1. 基础用法 python提供了一个标准的日志接口,就是logging模块.日志级别有DEBUG.INFO.WARNING.ERROR.CRITICAL五种( ...