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 ...
随机推荐
- 基于CentOS与VmwareStation10搭建Oracle11G RAC 64集群环境:2.搭建环境-2.3配置共享磁盘
2.3.配置共享磁盘 2.3.1.创建共享磁盘 在cmd中进入WMware Workstation 10.0 安装目录: 1.创建存储Oracle Clusterware文件 (Oracle Clu ...
- Linux下停用和启用用户帐号
有时候某个用户不乖,但是还不想删除他的帐号只是想给他点儿颜色看看,或者出于某种权限管理不想让他/她使用这个帐号,那么冻结帐号就是最好的方法了,linux中的帐号密码保存在/etc/shadow文件里面 ...
- hdu 3572 Task Schedule(最大流)2010 ACM-ICPC Multi-University Training Contest(13)——Host by UESTC
题意: 告诉我们有m个任务和k个机器.第i个任务需要ci天完成,最早从第ai天开始,最晚在第bi天结束.每台机器每天可以执行一个任务.问,是否可以将所有的任务都按时完成? 输入: 首行输入一个整数t, ...
- Delphi中实现MDI子窗体(转)
Delphi中实现MDI子窗体 用MDI实现浏览子窗口,具有窗口管理功能,同屏观看多个网页的内容 ① 多文档窗体(MDI) MDI窗体是一种具有主子结构的窗体体系,微软的Word便是其中的一 ...
- HDU3333 Turing Tree 离线树状数组
题意:统计一段区间内不同的数的和 分析:排序查询区间,离线树状数组 #include <cstdio> #include <cmath> #include <cstrin ...
- loadrunner之C语言编程
一.常量定义 #define COUNT 100 //定义全局常量#define SALARY 4000 Action(){ int total; total = C ...
- Selenium2Library系列 keywords 之 _SelectElementKeywords 之 unselect_from_list_by_value(self, locator, *values)
def unselect_from_list_by_value(self, locator, *values): """Unselects `*values` from ...
- 自己写了一个类似百度空间自动保存草稿的程序 php+jquery
可以异步加载mysql中的草稿~,异步更新草稿列表~ 下载地址:http://download.csdn.net/source/3479156 代码: demo.php <?php mysql_ ...
- C# 保留2位小数
1.只要求保留N位不四舍5入 float f = 0.55555f; int i =(int)(f * 100); ...
- 20+富有创意的BuddyPress网站
如果你想构建自己的社区网站,如果你熟悉WordPress,那么用BuddyPress构建它吧!它确实太强大了,本文整理了20个富有创意的BuddyPress网站,看看它们,你也能拥有! 原文地址:ht ...