CMSIS Example - Signal
1 /*---------------------------------------------------------------------------- 2 * RL-ARM - RTX 3 *---------------------------------------------------------------------------- 4 * Name: RTX_EX1.C 5 * Purpose: Your First RTX example program 6 *---------------------------------------------------------------------------- 7 * 8 * Copyright (c) 1999-2009 KEIL, 2009-2012 ARM Germany GmbH 9 * All rights reserved. 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions are met: 12 * - Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * - Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * - Neither the name of ARM nor the names of its contributors may be used 18 * to endorse or promote products derived from this software without 19 * specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 * ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE 25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 * POSSIBILITY OF SUCH DAMAGE. 32 *---------------------------------------------------------------------------*/ 33 34 #include "cmsis_os.h" 35 36 /* Forward reference */ 37 void threadX (void const *argument); 38 39 /* Thread IDs */ 40 osThreadId main_id; 41 osThreadId threadX_id; 42 43 /* Thread definitions */ 44 osThreadDef(threadX, osPriorityNormal, 1, 0); 45 46 /*---------------------------------------------------------------------------- 47 * Thread X 48 *---------------------------------------------------------------------------*/ 49 void threadX (void const *argument) { 50 for (;;) { 51 /* Wait for completion of do-this */ 52 osSignalWait(0x0004, osWaitForever); /* do-that */ 53 /* Pause for 20 ms until signaling event to main thread */ 54 osDelay(20); 55 /* Indicate to main thread completion of do-that */ 56 osSignalSet(main_id, 0x0004); 57 } 58 } 59 60 /*---------------------------------------------------------------------------- 61 * Main Thread 62 *---------------------------------------------------------------------------*/ 63 int main (void) { 64 65 /* Get main thread ID */ 66 main_id = osThreadGetId(); 67 /* Create thread X */ 68 threadX_id = osThreadCreate(osThread(threadX), NULL); 69 for (;;) { /* do-this */ 70 /* Indicate to thread X completion of do-this */ 71 osSignalSet(threadX_id, 0x0004); 72 /* Wait for completion of do-that */ 73 osSignalWait(0x0004, osWaitForever); 74 /* Wait now for 50 ms */ 75 osDelay(50); 76 } 77 } 78 79 /*---------------------------------------------------------------------------- 80 * end of file 81 *---------------------------------------------------------------------------*/
分类:
RTOS
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
2013-07-18 Bus Blaster