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名称空间. ...
 
随机推荐
- flash wmode参数详解
			
在做web开发中可能会遇到flash遮挡页面中元素的情况,无论怎么设置flash容器和层的深度(z-index)也无济于事,现有的解决方案是在插入flash的embed或object标签中加入”wmo ...
 - sessionFactory.getCurrentSession()的引出
			
当业务逻辑中需要开启事务执行,业务逻辑也要调用底层操作数据库的函数,那函数也要开启事务操作. 如果用sessionFactory.openSession()的话会引起处理不在同一个事务中,会造成出错. ...
 - js画线
			
<body> <div id="main"> </div> <div id="fd" style="filt ...
 - inno setup详细使用教程
			
前段时间我完成了几个软件的汉化,想把它们打包起来,可是苦于我是一个很菜的鸟,很笨的瓜,只好上网找关于安装程序制作的文章.不幸我没能找到:-( 没法只好自己去华军软件园里找找制作安装程序的软件,并一把下 ...
 - pdm 中怎么修改表的Name值时使Code值不变
			
修改方法:PowerDesign中的选项菜单里修改,在[Tool]-->[General Options]->[Dialog]->[Operating modes]->[Nam ...
 - Redis 对String数据类型的操作
			
Redis的 Strings 数据结构是简单的key-value类型,value其实不仅是String,也可以是数字.使用Strings类型,你可以完全实现目前 Memcached 的功能,并且效率更 ...
 - hdu 5254 水题
			
纯暴力就能过的,可是题目描述真心不清楚,我看了好久好久才明白题目啥意思. 为了迅速打完,代码比较冗余. /* * Author : ben */ #include <cstdio> #in ...
 - python2.7系列安装失败的办法
			
在windows系统上安装python时出现"there is a problem with your Windows installer package. A program run as ...
 - Module ngx_http_index_module    nginx的首页模块
			
Example Configuration:例子配置文件Directives 指令 index 首页 The ngx_http_index_module module processes r ...
 - sql统计重复数据
			
sql代码如下: 统计重复的数据 select MingCheng from tabShouFeiGongShi group by MingCheng having count(MingCheng) ...