CMSIS Example - Mail and Message

  1 /*----------------------------------------------------------------------------
  2  *      RL-ARM - RTX
  3  *----------------------------------------------------------------------------
  4  *      Name:    MAIL.C
  5  *      Purpose: 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 <stdio.h>
 35 #include "cmsis_os.h"
 36
 37 /* Thread IDs */
 38 osThreadId tid_thread1;               /* assigned ID for thread 1            */
 39 osThreadId tid_thread2;               /* assigned ID for thread 2            */
 40
 41 typedef struct {                      /* Mail object structure               */
 42   float    voltage;                   /* AD result of measured voltage       */
 43   float    current;                   /* AD result of measured current       */
 44   uint32_t counter;                   /* A counter value                     */
 45 } T_MEAS;
 46
 47 osMailQDef(mail, 16, T_MEAS);         /* Define mail queue                   */
 48 osMailQId  mail;
 49
 50 /* Forward reference */
 51 void send_thread (void const *argument);
 52 void recv_thread (void const *argument);
 53
 54 /* Thread definitions */
 55 osThreadDef(send_thread, osPriorityNormal, 1, 0);
 56 osThreadDef(recv_thread, osPriorityNormal, 1, 2000);
 57
 58
 59 /*----------------------------------------------------------------------------
 60  *  Thread 1: Send thread
 61  *---------------------------------------------------------------------------*/
 62 void send_thread (void const *argument) {
 63   T_MEAS *mptr;
 64
 65   mptr = osMailAlloc(mail, osWaitForever);           /* Allocate memory      */
 66   mptr->voltage = 223.72;             /* Set the mail content                */
 67   mptr->current = 17.54;
 68   mptr->counter = 120786;
 69   osMailPut(mail, mptr);              /* Send Mail                           */
 70   osDelay(100);
 71
 72   mptr = osMailAlloc(mail, osWaitForever);           /* Allocate memory      */
 73   mptr->voltage = 227.23;             /* Prepare 2nd mail                    */
 74   mptr->current = 12.41;
 75   mptr->counter = 170823;
 76   osMailPut(mail, mptr);              /* Send Mail                           */
 77   osThreadYield();                    /* Cooperative multitasking            */
 78   osDelay(100);
 79
 80   mptr = osMailAlloc(mail, osWaitForever);           /* Allocate memory      */
 81   mptr->voltage = 229.44;             /* Prepare 3rd mail                    */
 82   mptr->current = 11.89;
 83   mptr->counter = 237178;
 84   osMailPut(mail, mptr);              /* Send Mail                           */
 85   osDelay(100);
 86                                       /* We are done here, exit this thread  */
 87 }
 88
 89 /*----------------------------------------------------------------------------
 90  *  Thread 2: Receive thread
 91  *---------------------------------------------------------------------------*/
 92 void recv_thread (void const *argument) {
 93   T_MEAS  *rptr;
 94   osEvent  evt;
 95
 96   for (;;) {
 97     evt = osMailGet(mail, osWaitForever);  /* wait for mail                  */
 98     if (evt.status == osEventMail) {
 99       rptr = evt.value.p;
100       printf ("\nVoltage: %.2f V\n",rptr->voltage);
101       printf ("Current: %.2f A\n",rptr->current);
102       printf ("Number of cycles: %d\n",(int)rptr->counter);
103       #ifdef __USE_FFLUSH
104       fflush (stdout);
105       #endif
106       osMailFree(mail, rptr);         /* free memory allocated for mail      */
107     }
108   }
109 }
110
111 /*----------------------------------------------------------------------------
112  *   Main:
113  *---------------------------------------------------------------------------*/
114 int main (void) {                     /* program execution starts here       */
115
116   mail = osMailCreate(osMailQ(mail), NULL);  /* create mail queue            */
117
118   tid_thread1 = osThreadCreate(osThread(send_thread), NULL);
119   tid_thread2 = osThreadCreate(osThread(recv_thread), NULL);
120
121   osDelay(osWaitForever);
122   for (;;);
123 }
124
125 /*----------------------------------------------------------------------------
126  * end of file
127  *---------------------------------------------------------------------------*/
  1 /*----------------------------------------------------------------------------
  2  *      RL-ARM - RTX
  3  *----------------------------------------------------------------------------
  4  *      Name:    MESSAGE.C
  5  *      Purpose: 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 <stdio.h>
 35 #include "cmsis_os.h"
 36
 37 /* Thread IDs */
 38 osThreadId tid_thread1;               /* assigned ID for thread 1            */
 39 osThreadId tid_thread2;               /* assigned ID for thread 2            */
 40
 41 typedef struct {                      /* Message object structure            */
 42   float    voltage;                   /* AD result of measured voltage       */
 43   float    current;                   /* AD result of measured current       */
 44   uint32_t counter;                   /* A counter value                     */
 45 } T_MEAS;
 46
 47 osPoolDef(mpool, 16, T_MEAS);             /* Define memory pool              */
 48 osPoolId  mpool;
 49 osMessageQDef(MsgBox, 16, T_MEAS);        /* Define message queue            */
 50 osMessageQId  MsgBox;
 51
 52 /* Forward reference */
 53 void send_thread (void const *argument);
 54 void recv_thread (void const *argument);
 55
 56 /* Thread definitions */
 57 osThreadDef(send_thread, osPriorityNormal, 1, 0);
 58 osThreadDef(recv_thread, osPriorityNormal, 1, 2000);
 59
 60
 61 /*----------------------------------------------------------------------------
 62  *  Thread 1: Send thread
 63  *---------------------------------------------------------------------------*/
 64 void send_thread (void const *argument) {
 65   T_MEAS    *mptr;
 66
 67   mptr = osPoolAlloc(mpool);          /* Allocate memory for the message     */
 68   mptr->voltage = 223.72;             /* Set the message content             */
 69   mptr->current = 17.54;
 70   mptr->counter = 120786;
 71   osMessagePut(MsgBox, (uint32_t)mptr, osWaitForever);  /* Send Message      */
 72   osDelay(100);
 73
 74   mptr = osPoolAlloc(mpool);          /* Allocate memory for the message     */
 75   mptr->voltage = 227.23;             /* Prepare a 2nd message               */
 76   mptr->current = 12.41;
 77   mptr->counter = 170823;
 78   osMessagePut(MsgBox, (uint32_t)mptr, osWaitForever);  /* Send Message      */
 79   osThreadYield();                    /* Cooperative multitasking            */
 80   osDelay(100);
 81
 82   mptr = osPoolAlloc(mpool);          /* Allocate memory for the message     */
 83   mptr->voltage = 229.44;             /* Prepare a 3rd message               */
 84   mptr->current = 11.89;
 85   mptr->counter = 237178;
 86   osMessagePut(MsgBox, (uint32_t)mptr, osWaitForever);  /* Send Message      */
 87   osDelay(100);
 88                                       /* We are done here, exit this thread  */
 89 }
 90
 91 /*----------------------------------------------------------------------------
 92  *  Thread 2: Receive thread
 93  *---------------------------------------------------------------------------*/
 94 void recv_thread (void const *argument) {
 95   T_MEAS  *rptr;
 96   osEvent  evt;
 97
 98   for (;;) {
 99     evt = osMessageGet(MsgBox, osWaitForever);  /* wait for message          */
100     if (evt.status == osEventMessage) {
101       rptr = evt.value.p;
102       printf ("\nVoltage: %.2f V\n",rptr->voltage);
103       printf ("Current: %.2f A\n",rptr->current);
104       printf ("Number of cycles: %d\n",(int)rptr->counter);
105       #ifdef __USE_FFLUSH
106       fflush (stdout);
107       #endif
108       osPoolFree(mpool,rptr);         /* free memory allocated for message   */
109     }
110   }
111 }
112
113 /*----------------------------------------------------------------------------
114  *   Main:
115  *---------------------------------------------------------------------------*/
116 int main (void) {                     /* program execution starts here       */
117
118   mpool = osPoolCreate(osPool(mpool));  /* create memory pool                */
119   MsgBox = osMessageCreate(osMessageQ(MsgBox), NULL);  /* create msg queue   */
120
121   tid_thread1 = osThreadCreate(osThread(send_thread), NULL);
122   tid_thread2 = osThreadCreate(osThread(recv_thread), NULL);
123
124   osDelay(osWaitForever);
125   for (;;);
126 }
127
128 /*----------------------------------------------------------------------------
129  * end of file
130  *---------------------------------------------------------------------------*/

CMSIS Example - Mail and Message

时间: 2024-10-24 09:53:59

CMSIS Example - Mail and Message的相关文章

CMSIS Example - Mail and Timer

1 2 #include <stdint.h> 3 4 #include "bsp-fifisdr.h" 5 6 #include "lpclib.h" 7 #include "task-gui.h" 8 9 10 #define GUI_QUEUE_LENGTH (4) 11 12 13 typedef struct { 14 uint8_t opcode; 15 } GUI_Message; 16 17 18 /** Messag

.net active up mail 邮件发送

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using ActiveUp.Net.Mail; namespace ConsoleApplication1{    class Program    {        static void Main(string[] args)        {            Se

用PHP Email发送表单内容(9)- Buliding the message body

这一节只有一个内容,就是用用户填写的内容自动生产我们的邮件内容,当然还要进行一系列的判定. 邮件主题的内容,是由下面这段代码实现的,看里面的注释就可以理解了: 1 if(!$suspect && !$missing && !$errors){//如果出现以上情况,我们不希望这个程序运行: 2 $message = ''; //先建立$message以后再慢慢的往里面加内容; 3 foreach($expected as $item){ //谨慎起见,我只希望希望的内容出现在

SSIS Send Mail

在SSIS中Send Mail的方法主要有三种,使用Send Mail Task,使用Script Task和使用存储过程msdb.dbo.sp_send_dbmail. 一,使用Send Mail Task Send Mail Task 是SSIS提供的Task,使用非常简单,但有限制: 只能发送普通的文本格式的邮件,不支持 HTML 格式的邮件. 链接到SMTP Server有两种验证方式,在域中使用 Windows 方式验证,或使用匿名验证. SMTP Server 使用默认的端口号25

各种中文乱码

为什么说乱码是中国程序员无法避免的话题呢?这个首先要从编码机制上说起,大家都是中文和英文的编码格式不是一样,解码也是不一样的!如果中国的程序员不会遇到乱码,那么只有使用汉语编程.汉语编程是怎么回事我也不大清楚,应该是前年吧,我一朋友给我介绍汉语编程,怎么不错不错?当时因为学习忙没去关注这个,等我闲了,那个朋友不弄这个,问他他也不说不大清楚,最后自己对这个学习也不了了之了.    今天我写这个不是讲解中英文之间的差距,解码等,我是将我在这几年工作遇到各种各样的乱码的解决方法,总结一样,也希望大家能

asp.net 发送邮件

protected void Button1_Click(object sender, EventArgs e) { SendSMTPEMail("smtp.qq.com", "[email protected]", "XX密码XXXX", "[email protected]", "123", "用asp.net发送邮件,用qq的smtp.qq.com服务器,测试成功"); } pub

Centos下安装mailx

[[email protected] /]# mail -s "Message"  [email protected] < /tmp/info.message 系统默认以"[email protected]主机名" 发送邮件,收到邮件直接被过虑成垃圾邮件了,那可不可以自定义邮箱发送邮件呢? 答案肯定可以的. 下载mailx包 mailx官方站点 http://heirloom.sourceforge.net/ 下载最新版本mailx-12.4.tar.bz2

zabbix3.0微信邮件报警

Zabbix 邮件微信报警 分2大部分: 1.Zabbix服务器端配置 邮件服务安装配置 2.Web端服务配置 服务器端的设置: 系统 cenots 6.5   2.6.32-431.el6.x86_64 安装邮件发送服务: [[email protected] ~]# wget http://sourceforge.net/projects/heirloom/files/latest/download?source=files [[email protected] ~]# mv downloa

07_面向对象

1. 初识面向对象 1. python支持 函数式+面向对象 两种编程 2. 函数式编程,面向对象编程实现:发邮件的功能 函数式: def mail(email, message): print(“去发吧”) return True # 调用函数 mail("[email protected]", "好人") 面向对象:先创建类,再创建对象 # 创建类 class Foo: # 方法(函数放在类里) def mail(self, email, message): p