/*----------------------------------------------------------------------------
* 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的更多相关文章

  1. CMSIS Example - Signal

    /*---------------------------------------------------------------------------- * RL-ARM - RTX *----- ...

  2. Python yield与实现

    Python yield与实现  yield的功能类似于return,但是不同之处在于它返回的是生成器. 生成器 生成器是通过一个或多个yield表达式构成的函数,每一个生成器都是一个迭代器(但是迭 ...

  3. Unity StrangeIoc框架 (三)signal信号方式

    先创建TestRoot using UnityEngine; using System.Collections; using strange.extensions.context.impl; publ ...

  4. Java并发编程之线程生命周期、守护线程、优先级、关闭和join、sleep、yield、interrupt

    Java并发编程中,其中一个难点是对线程生命周期的理解,和多种线程控制方法.线程沟通方法的灵活运用.这些方法和概念之间彼此联系紧密,共同构成了Java并发编程基石之一. Java线程的生命周期 Jav ...

  5. sleep(),wait(),yield()和join()方法的区别

    sleep() sleep()方法需要指定等待的时间,它可以让当前正在执行的线程在指定的时间内暂停执行,进入阻塞状态,该方法既可以让其他同优先级或者高优先级 的线程得到执行的机会,也可以让低优先级的线 ...

  6. yield 与生成器

    yield的功能类似于return,但是不同之处在于它返回的是生成器. 生成器 生成器是通过一个或多个yield表达式构成的函数,每一个生成器都是一个迭代器(但是迭代器不一定是生成器). 如果一个函数 ...

  7. Java并发学习 & Executor学习 & 异常逃逸 & 同步互斥Best Practice & wait/notify, conditon#await/signal

    看了这篇文章:http://www.ciaoshen.com/2016/10/28/tij4-21/ 有一些Java并发的内容,另外查了一些资料. 朴素的Thread 首先,Java中关于线程Thre ...

  8. python yield学习

    yield的功能类似于return,但是不同之处在于它返回的是生成器. 生成器生成器是通过一个或多个yield表达式构成的函数,每一个生成器都是一个迭代器(但是迭代器不一定是生成器). 如果一个函数包 ...

  9. Python3基础 yield StopIteration.value获取函数的返回值

             Python : 3.7.3          OS : Ubuntu 18.04.2 LTS         IDE : pycharm-community-2019.1.3    ...

随机推荐

  1. api-ms-win-crt-runtime-l1-1-0.dll丢失问题

    笔者是在安装python 3.5 后,启动时提示该文件丢失的问题的,如下所示.

  2. 浅谈Android五大布局——LinearLayout、FrameLayout、AbsoulteLayout、RelativeLayout和TableLayout

    Android的界面是有布局和组件协同完成的,布局好比是建筑里的框架,而组件则相当于建 筑里的砖瓦.组件按照布局的要求依次排列,就组成了用户所看见的界面.Android的五大布局分别是LinearLa ...

  3. 组合 z

    输入a b c d e以及它们对应的数字 比如 a-->1 2 3  b-->2 3 c-->1 d-->3 4 5 e-->1 3 5 输出a b c d e的可用组合 ...

  4. 转:使用 JMeter 完成常用的压力测试

    使用 JMeter 完成常用的压力测试 就目前 Java EE 的平台下开发的软件来说,这种节点通常可能是:Web 服务器.数据库服务器和 JMS 服务器.它们都是请求主要发生的地点,请求频率较其它的 ...

  5. Linux 通过YUM安装rzsz

    yum自动安装: yum install lrzsz

  6. java中的Switch case语句

    java中的Switch case 语句 在Switch语句中有4个关键字:switch,case break,default. 在switch(变量),变量只能是整型或者字符型,程序先读出这个变量的 ...

  7. CreateProcess error=206, The filename or extension is too long"的一个解决方案

    在实际项目中我使用antrun 和 closure-compiler压缩JS项目.然后我就使用如下代码: 首先加入依赖. <dependency> <groupId>com.g ...

  8. ipc.Client: Retrying connect to server: h1/192.168.1.61:9000. Already tried 0 time(s);解决方法

    1.检查namenode服务器的是否运行正常,我的问题是没有开启hadoop集群出现的. 2.检查namenode服务器的防火墙是否开放的响应端口,一般内网建议关闭.

  9. 给一已经排序数组A和x,求A中是否包含两个元素之和为x

    亲爱的大神老爷们,这是小渣第一次写blog,欢迎大家来喷(批评指正),算法渣因为面试中连这道题都不会写就自己琢磨了一下,也参考了网上大家的做法 解法一: 思路:从首尾向目的靠拢,因为已经排序,[假设存 ...

  10. java 常用concurrent类

    1.CountDownLatch 它的作用主要是当多个(数量等于初始化CountDownLatch时count参数的值)线程到达了预期状态或完成预期工作时触发事件,其他线程可以等待这个事件来触发自己后 ...