CMSIS Example - Mail and Message
/*----------------------------------------------------------------------------
* RL-ARM - RTX
*----------------------------------------------------------------------------
* Name: MAIL.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 <stdio.h>
#include "cmsis_os.h" /* Thread IDs */
osThreadId tid_thread1; /* assigned ID for thread 1 */
osThreadId tid_thread2; /* assigned ID for thread 2 */ typedef struct { /* Mail object structure */
float voltage; /* AD result of measured voltage */
float current; /* AD result of measured current */
uint32_t counter; /* A counter value */
} T_MEAS; osMailQDef(mail, , T_MEAS); /* Define mail queue */
osMailQId mail; /* Forward reference */
void send_thread (void const *argument);
void recv_thread (void const *argument); /* Thread definitions */
osThreadDef(send_thread, osPriorityNormal, , );
osThreadDef(recv_thread, osPriorityNormal, , ); /*----------------------------------------------------------------------------
* Thread 1: Send thread
*---------------------------------------------------------------------------*/
void send_thread (void const *argument) {
T_MEAS *mptr; mptr = osMailAlloc(mail, osWaitForever); /* Allocate memory */
mptr->voltage = 223.72; /* Set the mail content */
mptr->current = 17.54;
mptr->counter = ;
osMailPut(mail, mptr); /* Send Mail */
osDelay(); mptr = osMailAlloc(mail, osWaitForever); /* Allocate memory */
mptr->voltage = 227.23; /* Prepare 2nd mail */
mptr->current = 12.41;
mptr->counter = ;
osMailPut(mail, mptr); /* Send Mail */
osThreadYield(); /* Cooperative multitasking */
osDelay(); mptr = osMailAlloc(mail, osWaitForever); /* Allocate memory */
mptr->voltage = 229.44; /* Prepare 3rd mail */
mptr->current = 11.89;
mptr->counter = ;
osMailPut(mail, mptr); /* Send Mail */
osDelay();
/* We are done here, exit this thread */
} /*----------------------------------------------------------------------------
* Thread 2: Receive thread
*---------------------------------------------------------------------------*/
void recv_thread (void const *argument) {
T_MEAS *rptr;
osEvent evt; for (;;) {
evt = osMailGet(mail, osWaitForever); /* wait for mail */
if (evt.status == osEventMail) {
rptr = evt.value.p;
printf ("\nVoltage: %.2f V\n",rptr->voltage);
printf ("Current: %.2f A\n",rptr->current);
printf ("Number of cycles: %d\n",(int)rptr->counter);
#ifdef __USE_FFLUSH
fflush (stdout);
#endif
osMailFree(mail, rptr); /* free memory allocated for mail */
}
}
} /*----------------------------------------------------------------------------
* Main:
*---------------------------------------------------------------------------*/
int main (void) { /* program execution starts here */ mail = osMailCreate(osMailQ(mail), NULL); /* create mail queue */ tid_thread1 = osThreadCreate(osThread(send_thread), NULL);
tid_thread2 = osThreadCreate(osThread(recv_thread), NULL); osDelay(osWaitForever);
for (;;);
} /*----------------------------------------------------------------------------
* end of file
*---------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------
* RL-ARM - RTX
*----------------------------------------------------------------------------
* Name: MESSAGE.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 <stdio.h>
#include "cmsis_os.h" /* Thread IDs */
osThreadId tid_thread1; /* assigned ID for thread 1 */
osThreadId tid_thread2; /* assigned ID for thread 2 */ typedef struct { /* Message object structure */
float voltage; /* AD result of measured voltage */
float current; /* AD result of measured current */
uint32_t counter; /* A counter value */
} T_MEAS; osPoolDef(mpool, , T_MEAS); /* Define memory pool */
osPoolId mpool;
osMessageQDef(MsgBox, , T_MEAS); /* Define message queue */
osMessageQId MsgBox; /* Forward reference */
void send_thread (void const *argument);
void recv_thread (void const *argument); /* Thread definitions */
osThreadDef(send_thread, osPriorityNormal, , );
osThreadDef(recv_thread, osPriorityNormal, , ); /*----------------------------------------------------------------------------
* Thread 1: Send thread
*---------------------------------------------------------------------------*/
void send_thread (void const *argument) {
T_MEAS *mptr; mptr = osPoolAlloc(mpool); /* Allocate memory for the message */
mptr->voltage = 223.72; /* Set the message content */
mptr->current = 17.54;
mptr->counter = ;
osMessagePut(MsgBox, (uint32_t)mptr, osWaitForever); /* Send Message */
osDelay(); mptr = osPoolAlloc(mpool); /* Allocate memory for the message */
mptr->voltage = 227.23; /* Prepare a 2nd message */
mptr->current = 12.41;
mptr->counter = ;
osMessagePut(MsgBox, (uint32_t)mptr, osWaitForever); /* Send Message */
osThreadYield(); /* Cooperative multitasking */
osDelay(); mptr = osPoolAlloc(mpool); /* Allocate memory for the message */
mptr->voltage = 229.44; /* Prepare a 3rd message */
mptr->current = 11.89;
mptr->counter = ;
osMessagePut(MsgBox, (uint32_t)mptr, osWaitForever); /* Send Message */
osDelay();
/* We are done here, exit this thread */
} /*----------------------------------------------------------------------------
* Thread 2: Receive thread
*---------------------------------------------------------------------------*/
void recv_thread (void const *argument) {
T_MEAS *rptr;
osEvent evt; for (;;) {
evt = osMessageGet(MsgBox, osWaitForever); /* wait for message */
if (evt.status == osEventMessage) {
rptr = evt.value.p;
printf ("\nVoltage: %.2f V\n",rptr->voltage);
printf ("Current: %.2f A\n",rptr->current);
printf ("Number of cycles: %d\n",(int)rptr->counter);
#ifdef __USE_FFLUSH
fflush (stdout);
#endif
osPoolFree(mpool,rptr); /* free memory allocated for message */
}
}
} /*----------------------------------------------------------------------------
* Main:
*---------------------------------------------------------------------------*/
int main (void) { /* program execution starts here */ mpool = osPoolCreate(osPool(mpool)); /* create memory pool */
MsgBox = osMessageCreate(osMessageQ(MsgBox), NULL); /* create msg queue */ tid_thread1 = osThreadCreate(osThread(send_thread), NULL);
tid_thread2 = osThreadCreate(osThread(recv_thread), NULL); osDelay(osWaitForever);
for (;;);
} /*----------------------------------------------------------------------------
* end of file
*---------------------------------------------------------------------------*/
CMSIS Example - Mail and Message的更多相关文章
- CMSIS Example - Mail and Timer
#include <stdint.h> #include "bsp-fifisdr.h" #include "lpclib.h" #include ...
- SSIS Send Mail
在SSIS中Send Mail的方法主要有三种,使用Send Mail Task,使用Script Task和使用存储过程msdb.dbo.sp_send_dbmail. 一,使用Send Mail ...
- java mail 接收邮件
package com.mw.utils; import com.mw.bean.SmsAlarmLogBean; import javax.mail.*; import javax.mail.int ...
- .net active up mail 邮件发送
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ...
- [Python] Send emails to the recepients specified in Message["CC"]
Recently, I'm working on a small program which needs to send emails to specific accounts. When I wan ...
- javaMail
JavaMail概述: JavaMail是由Sun定义的一套收发电子邮件的API,不同的厂商可以提供自己的实现类.但它并没有包含在JDK中,而是作为JavaEE的一部分. javaMai ...
- JavaMail发送邮件第一版
首先,我们先来了解一个基本的知识点,用什么工具来发邮件? 简单的说一下,目前用的比较多的客户端:OutLook,Foxmail等 顺便了解一下POP3.SMTP协议的区别: POP3,全名为" ...
- 如何用qq代理发送邮件
今天我想写一篇服务器发送验证邮件的的文章,我查阅过其他博客里面写的文章,都是可以实现的,但是对于初学者来说是一个很痛苦的事情,很多代码看不懂,原因有多种,写的多,写的乱,然后就不想往下看了.我今天详细 ...
- [UWP]UWP中获取联系人/邮件发送/SMS消息发送操作
这篇博客将介绍如何在UWP程序中获取联系人/邮件发送/SMS发送的基础操作. 1. 获取联系人 UWP中联系人获取需要引入Windows.ApplicationModel.Contacts名称空间. ...
随机推荐
- mysql (master/slave)复制原理及配置
1 复制概述 Mysql内建的复制功能是构建大型,高性能应用程序的基础.将Mysql的数据分布到多个系统上去,这种分布的机制,是通过将Mysql的某一台主机的数据复制到其它主机(slaves)上,并重 ...
- vector 释放内存 swap
相 信大家看到swap这个词都一定不会感到陌生,甚至会有这样想法:这不就是简单的元素交换嘛.的确,swap交换函数是仅次于Hello word这样老得不能老的词,然而,泛型算法东风,这个小小的玩意儿却 ...
- hdu 3951(博弈规律)
题意:给定围成一个圈的硬币n枚,然后每次可以取出连续的1-k枚,谁取完最后一枚谁就获胜. 分析:对于第二个人当第一个人取完后,他可以取成对称的形式,所以第二个人必胜. 代码: #include< ...
- poj 3270(置换群)
题意:给定n头母牛的脾气大小,然后让你通过交换任意两头母牛的位置使得最后的母牛序列的脾气值从小到大,交换两头母牛的代价是两个脾气之和,使得代价最小. 分析:以前做过一道题,只有一个地方和这道题不同,但 ...
- Drupal配置文件settings.php搜索规则
Drupal的配置文件搜索是通过bootstrap.inc的conf_path()函数实现的: function conf_path($require_settings = TRUE, $reset ...
- LoadRunner中常见参数和变量
1.参数和字符串变量的交换 ①lr_save_string(“hello world”,“param”) 将hello world 保存在参数 param中 ②lr_eval_stri ...
- [转]Linux文件和目录操作命令
转自:http://www.linuxdiyf.com/bbs/thread-416176-1-1.html 一.文件操作命令1.1 查看文件 Linux下查看文件的命令有很多,下面列出的几个是几乎所 ...
- Cocos2d-android (05) 渐变动画(颜色,淡入淡出。。。)
淡入淡出.颜色渐变及动作重复执行 import org.cocos2d.actions.base.CCRepeatForever; import org.cocos2d.actions.interva ...
- 总结调用Flash的几种方法
一.Adobe 提供的方法 <object width="200" height="200" classid="clsid:D27CDB6E-A ...
- INTEL XDK 真机调试
需要安装 1.google服务框架 2.google play 3.app preview