embOS实时操作系统 任务通讯

摘要:
1.轮询全局变量2.使用事件驱动的信号量(1)二进制信号量<mutex(Mutualexception)>信号量只有二进制0或1OS_Use()其他任务的资源和块sOS_Uuse()Releasesasemaphor当前在任务中。OS_需求

1. 轮询全局变量

2. 使用事件驱动

A. 信号量

(1) 二进制信号量(resource/binary semaphore)< 互斥锁 Mutex( Mutual exclusion ) >

信号量只有二进制的0或1

OS_Use() Claims a resource and blocks it for other tasks

OS_Unuse() Releases a semaphore currently in use by a task.

OS_Request()  Requests a specified semaphore, blocks it for other tasks if it is available. Continues execution in any case.

embOS实时操作系统 任务通讯第1张

Claims a resource and blocks it for other tasks.

embOS实时操作系统 任务通讯第2张

Requests a specified semaphore and blocks it for other tasks if it is available.

Continues execution in any case

embOS实时操作系统 任务通讯第3张

(2) 计数信号量(counting/general semaphore)

信号量是一个任意的整数

OS_SignalCSema() Increments the counter of a semaphore

OS_WaitCSema() Decrements the counter of a semaphore.

OS_CSemaRequest() Decrements the counter of a semaphore, if available.

B. 消息

(1) 邮箱 - 1..127 字节的消息 ( 消息字节数 -- 固定的)

OS_PutMail() Stores a new message of a predefined size in a mailbox.

OS_WaitMail() Waits until a mail is available, but does not retrieve the message from the mailbox.

OS_GetMail() Retrieves a message of a predefined size from a mailbox.

OS_PeekMail() Reads a mail from a mailbox without removing it

(2) 队列 - 大于 127 字节的消息 ( 消息字节数 -- 可变的 )

OS_Q_Put() Stores a new message of given size in a queue.

OS_Q_PutBlocked() Stores a new message of given size in a queue. Blocks the calling task when queue is full.

OS_Q_GetPtr() Retrieves a message from a queue.

OS_Q_GetPtrCond() Retrieves a message from a queue, if one message is available or returns without suspension.

OS_Q_GetPtrTimed() Retrieves a message from a queue within a specified time, if one message is available.

OS_Q_Purge() Deletes the last retrieved message in a queue.

C. 事件

(1) 任务事件 - 每一个任务有 1 字节 事件掩码 ( 8 个事件 )

OS_SignalEvent() Signals event(s) to a specified task.

OS_WaitEvent() Waits for one of the events specified in the bitmask and clears the event memory after an event occurs.

OS_WaitSingleEvent() Waits for one of the events specified as bitmask and clears only that event after it occurs.

OS_WaitEvent_Timed() Waits for the specified events for a given time, and clears the event memory after an event occurs.

OS_WaitSingleEventTimed() Waits for the specified events for a given time; after an event occurs, only that event is cleared.

(2) 事件对象 - the signaling function does not need to know which task is waiting for the event to occur

OS_EVENT_Wait() Waits for an event. 
OS_EVENT_WaitTimed() Waits for an event with timeout and resets the event after it occurs. 
OS_EVENT_Set() Sets the events, or resumes waiting tasks. 
OS_EVENT_Reset() Resets the event to none-signaled state.
OS_EVENT_Pulse() Sets the event, resumes waiting tasks, if any,and then resets the event.
OS_EVENT_Get() Returns the state of an event object.

免责声明:文章转载自《embOS实时操作系统 任务通讯》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇有趣的一行 Python 代码socket网络编程(一)——初识socket下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

12.手机端如何拖动组件--从零起步实现基于Html5的WEB设计器Jquery插件(含源码)

 前面示例都只是展示在桌面浏览器显示,当用手机浏览器打开时发现无法拖动元素,虽然实际业务上,手机也只是用来查看的,但为了论证手机上的触摸事件,我还是在本节做个演示。 手机上触控有三个重要事件touchstart,touchmove,touchend,分别表示开始触摸,移动,及结束,与鼠标的mousedown,mousemove,mouseup对应。 基于...

input type = number 去除上下箭头,禁用滚轮事件(默认的自带滚轮加减数字)

<style type="text/css"> /*盒子大小从边框开始计算*/html * {box-sizing:border-box; } /*解决模态框抖动*/html {overflow-y:scroll;-ms-overflow-style:none; } /*隐藏滚动条 */html::-we...

前端视频播放组件 vue-video-player

1 安装 2 cnpm install vue-video-player -S 3 cnpm install 'video.js' -S 4 5 在main.js中导入 6 import VueVideoPlayer from 'vue-video-player'; 7 import 'video.js/dist/video-js.css'; 8 Vue...

libevent编程疑难解答

http://blog.csdn.net/luotuo44/article/details/39547391 转载请注明出处:http://blog.csdn.net/luotuo44/article/details/39547391 正常情况下应该在libevent的回调中调用event_add函数, 如果想下其他的线程中调用event_add,是线程不...

LMAX Disruptor—多生产者多消费者中,消息复制分发的高性能实现

解决的问题 当我们有多个消息的生产者线程,一个消费者线程时,他们之间如何进行高并发、线程安全的协调? 很简单,用一个队列。 当我们有多个消息的生产者线程,多个消费者线程,并且每一条消息需要被所有的消费者都消费一次(这就不是一般队列,只消费一次的语义了),该怎么做? 这时仍然需要一个队列。但是: 1. 每个消费者需要自己维护一个指针,知道自己消费了队列中多少...

深入Android开发之--理解View#onTouchEvent

一:前言 View是Android中最基本的UI单元. 当一个View接收到了触碰事件时,会调用其onTouchEvent方法.方法声明如下: ? 1 2 3 4 5 6 7 /** * Implement this method to handle touch screen motion events. * * @param even...