/*----------------------------------------------------------------------------
* 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. bootstrap-datepicker 插件修改为默认中文

    bootstrap-datepicker 是一个非常优秀的时间选择插件,默认是英文显示日期的,通过下面几个小修改让其支持默认中文 1.首先将 bootstrap-datepicker.js 另存为 u ...

  2. 实用js+css多级树形展开效果导航菜单

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  3. Apache PHP 安装问题 (SUSE Linux)

    1. SUSE Linux配置命令如下: './configure' '--with-apxs2=/usr/local/apache2/bin/apxs' '--with-mysql' 2. 接下来 ...

  4. centos mysq table is read only

    1.进入mysql数据库目录,使用命令"chown -R mysql <数据库文件夹名称>" 2. "chgrp -R mysql <数据库文件夹名称& ...

  5. [再寄小读者之数学篇](2014-11-26 广义 Schur 分解定理)

    设 $A,B\in \bbR^{n\times n}$ 的特征值都是实数, 则存在正交阵 $P,Q$ 使得 $PAQ$, $PBQ$ 为上三角阵.

  6. 组合 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的可用组合 ...

  7. 生产环境服务CPU高问题分析

    问题描述: 现网个别时候会出现CPU突然飙高的现象,飙高后不能恢复正常. 分析过程: CPU飙高后抓dump,最好本机看,其它机器看dump可能需要下载服务运行机器的sos,clr     0:000 ...

  8. oracle 查看表的相关信息

    1.查看当前用户的表 SELECT * FROM user_tables; 2.查看指定用户的表 SELECT * FROM all_tables WHERE owner = 'SYS';

  9. html --- ajax --- javascript --- 简单的封装

    Ajax的简单封装 Ajax的全称是AsynchronousJavaScriptAndXML 如有疑问请参考:http://zh.wikipedia.org/zh-cn/AJAX 以及传智播客的视频教 ...

  10. python中隐式的内存共享

    在python中,基本上使用的是引用,那么就会造成一个隐式的内存共享,特别是在容器对象中,例如list,dictionary 对于不可变对象,是不会造成隐式的内存共享情况,如下所示: >> ...