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 ...
随机推荐
- 【转】VMware 11安装Mac OS X 10.10
VM11安装Mac OS X 10.10 网上竟没有搜到相似的内容,所以拿出来大家分享 工具/原料 1.VMware Workstation 11 2.unlocker 203(for OS X 插件 ...
- AsciiDoc
AsciiDoc Text based document generation AsciiDoc Home Page Table of Contents Introduction Overview a ...
- Visual Assist的破解与安装
转载[PYG成员作品] [2016-09-26更新]Visual Assist X10.9.2112-Cracked.By.PiaoYun/P.Y.G 近期的一个稳定版本的破解方式: VA原版, VA ...
- cocos2dx+lua中cc.EventListenerMouse:create()的bug
今天在调试项目的时候用到了鼠标事件的监听 在创建事件监听器的时候出了问题 cc.EventListenerMouse:create() 这句返回值为nil 原来这是cocos2dx引擎的一个bug,t ...
- Delphi Val函数
在这里Val和iif都是你所用的数据库中的函数在delphi中Val是一个将字符串转换为数字的函数,Val(S; var V; var Code: Integer)第一个参数是要转换的字符串,第二个参 ...
- inno setup详细使用教程
前段时间我完成了几个软件的汉化,想把它们打包起来,可是苦于我是一个很菜的鸟,很笨的瓜,只好上网找关于安装程序制作的文章.不幸我没能找到:-( 没法只好自己去华军软件园里找找制作安装程序的软件,并一把下 ...
- Window nginx+tomcat+https部署方案 支持ios9
客户端和 Nginx 之间走的 HTTPS 通讯,而 Nginx 到 Tomcat 通过 proxy_pass 走的是普通 HTTP 连接. 下面是详细的配置(Nginx 端口 80/443,Tomc ...
- 【Python学习笔记】with语句与上下文管理器
with语句 上下文管理器 contextlib模块 参考引用 with语句 with语句时在Python2.6中出现的新语句.在Python2.6以前,要正确的处理涉及到异常的资源管理时,需要使用t ...
- Android Audio遇到播放无声时的分析
在Android Audio开发过程中,有遇到播放ringtone时无声,但播放Music可以听到声音,关于无声问题的分析,在此做个笔记,方便以后回顾. 分析方向: 1:在音量控制面板中确认该音频流对 ...
- 【开源项目之路】jquery的build问题
在刚开始clone了jquery到本地build的时候,就遇到了问题. “ENORESTARGET No tag found that was able to satisfy ...” 提示为bowe ...