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名称空间. ...
随机推荐
- Codeforces Round #217 (Div. 2) c题
C. Mittens time limit per test 1 second memory limit per test 256 megabytes input standard input out ...
- [Everyday Mathematics]20150222
设 $$\bex a_0=1,\quad a_1=\frac{1}{2},\quad a_{n+1}=\frac{na_n^2}{1+(n+1)a_n}\ (n\geq 1). \eex$$ 试证: ...
- Visual Studio 2005 移植 - WINVER,warning C4996, error LINK1104
Visual Studio 2005 移植 - WINVER,warning C4996, error LINK1104 一.WINVER Compile result: WINVER not d ...
- c/c++工程中外部头文件及库添加方法
在VS工程中,添加c/c++工程中外部头文件及库的基本步骤: 1.添加工程的头文件目录:工程---属性---配置属性---c/c++---常规---附加包含目录:加上头文件存放目录. 2.添加文件引用 ...
- c#中格式化导出Excel数据
在项目开发过程中经常会遇到数据导出Excel.如果只是导出数据就好办了.但往往用户会有各种格式要求.加粗.边框.合并单元格.汇总等功能. 以下的方法是基于Excel模版方式写入数据导出的功能.可以最大 ...
- 更改VS的运行主窗体
Program.cs中Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefa ...
- Python的16个“坑”
1. 不要使用可变对象作为函数默认值 代码如下: In [1]: def append_to_list(value, def_list=[]): ...: def_list.append(value) ...
- 耳机jack构造及在应用时可能出现的问题
目前市场上耳机分为4环耳机(图1所示,iphone型)和3环耳机(图2所示).4环耳机称为headset,3环耳机称为headphone,两者之间的区别就是4环耳机比3环耳机多个micphone.而J ...
- hadoop2.5.2学习及实践笔记(二)—— 编译源代码及导入源码至eclipse
生产环境中hadoop一般会选择64位版本,官方下载的hadoop安装包中的native库是32位的,因此运行64位版本时,需要自己编译64位的native库,并替换掉自带native库. 源码包下的 ...
- Linux配置静态IP
在一块SSD的CentOS配置静态IP 1. 配置静态IP #vi /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE="eth0" ...