当前位置:网站首页>Mailbox application routine of running wild fire RT thread
Mailbox application routine of running wild fire RT thread
2022-06-30 07:18:00 【liwuxing】
run RT-Thread Mailbox application routines for
《RT-Thread Actual combat of Kernel Implementation and application development 》 In detail RT-Thread Mailbox application for .https://doc.embedfire.com/rtos/rtthread/zh/latest/application/mailbox.html The principle and application of mailbox are introduced in detail .
Supporting engineering files with example programs are stored in the supporting program folder :ebf_rtthread_base_code_stm32f103_zhinanzhe-master\23, mailbox . Open folder 23, mailbox \Project\RVMDK(uv4) Project files under folder : Fire_RT-Thread.uvprojx
If direct simulation runs , There will be errors :
*** error 65: access violation at 0x40021000 : no 'read' permission
Need modification :

That is, the project configuration Debug There is a problem with the settings in the options :
Dialog DLL The default is DCM3.DLL
Parameter The default is -pCM3
Should be changed to
Dialog DLL yes DARMSTM.DLL
Parameter yes -pSTM32F103VC
You can run the simulation , Open the serial port window 、 And the periphery GPIOA、GPIOC, The effect of operation :


This code is in Wildfire “ Development board RT-Thread 3.0 + STM32 mailbox ” On the routine of . The original code is 2 Threads , Here instead 3 Threads , And press key2 Send messages continuously when , Cause email sending error .
/**
*********************************************************************
* @file main.c
* @author fire
* @version V1.0
* @date 2018-xx-xx
* @brief RT-Thread 3.0 + STM32 mailbox
*********************************************************************
* @attention
*
* The experiment platform : Wildfire F103- Guider STM32 Development board
* Forum :http://www.firebbs.cn
* TaoBao :https://fire-stm32.taobao.com
*
**********************************************************************
*/
/*
*************************************************************************
* Included header file
*************************************************************************
*/
#include "board.h"
#include "rtthread.h"
/*
******************************************************************
* Variable
******************************************************************
*/
/* Define thread control blocks */
static rt_thread_t receive_thread = RT_NULL;
static rt_thread_t send_thread = RT_NULL;
/* Define mailbox control block */
static rt_mailbox_t test_mail = RT_NULL;
/************************* Global variable declaration ****************************/
/*
* When we are writing applications , You may need to use some global variables .
*/
char test_str1[] = "this is a mail test 1";/* Mailbox message test1 */
char test_str2[] = "this is a mail test 2";/* Mailbox message test2 */
/*
*************************************************************************
* Function declaration
*************************************************************************
*/
static void receive_thread_entry(void* parameter);
static void key1_send_thread_entry(void* parameter);
static void key2_send_thread_entry(void* parameter);
/*
*************************************************************************
* main function
*************************************************************************
*/
/**
* @brief The main function
* @param nothing
* @retval nothing
*/
int main(void)
{
/*
* Hardware initialization of development board ,RTT System initialization is already in main Complete before function ,
* That is to say component.c In the document rtthread_startup() Function .
* So in main Function , Just create and start threads .
*/
rt_kprintf(" This is a [ Wildfire ]-STM32F103- Guider -RTT Mailbox message experiment !\n");
rt_kprintf(" Press down K1 | K2 Conduct mailbox experiment test !\n");
/* Create a mailbox */
test_mail = rt_mb_create("test_mail", /* Email name */
10,
RT_IPC_FLAG_FIFO);/* Semaphore mode FIFO(0x00)*/
if (test_mail != RT_NULL)
rt_kprintf(" Mailbox created successfully !\n\n");
receive_thread = /* Thread control block pointer */
rt_thread_create( "receive", /* Thread name */
receive_thread_entry, /* Thread entry function */
RT_NULL, /* Thread entry function parameters */
512, /* Thread stack size */
3, /* Thread priority */
20); /* Thread timeslice */
/* Start thread , Turn on scheduling */
if (receive_thread != RT_NULL)
rt_thread_startup(receive_thread);
else
return -1;
send_thread = /* Thread control block pointer */
rt_thread_create( "send", /* Thread name */
key1_send_thread_entry, /* Thread entry function */
RT_NULL, /* Thread entry function parameters */
512, /* Thread stack size */
2, /* Thread priority */
20); /* Thread timeslice */
/* Start thread , Turn on scheduling */
if (send_thread != RT_NULL)
rt_thread_startup(send_thread);
else
return -1;
send_thread = /* Thread control block pointer */
rt_thread_create( "send", /* Thread name */
key2_send_thread_entry, /* Thread entry function */
RT_NULL, /* Thread entry function parameters */
512, /* Thread stack size */
2, /* Thread priority */
20); /* Thread timeslice */
/* Start thread , Turn on scheduling */
if (send_thread != RT_NULL)
rt_thread_startup(send_thread);
else
return -1;
}
/*
*************************************************************************
* Thread definition
*************************************************************************
*/
static void receive_thread_entry(void* parameter)
{
rt_err_t uwRet = RT_EOK;
char *r_str;
/* The task is an infinite loop , Can't return */
while(1)
{
/* Waiting for email messages */
uwRet = rt_mb_recv(test_mail, /* Mailbox object handle */
(rt_uint32_t*)&r_str, /* Receive email messages */
RT_WAITING_FOREVER);/* Specifies the timeout event , Keep waiting */
if(RT_EOK == uwRet) /* If the reception is complete and correct */
{
rt_kprintf ( " The content of the email is :%s\n\n",r_str);
LED1_TOGGLE; //LED1 reverse
}
else
rt_kprintf ( " Email receiving error ! The error code is 0x%x\n",uwRet);
rt_thread_delay(100); //100ms Then receive
}
}
static void key1_send_thread_entry(void* parameter)
{
rt_err_t uwRet = RT_EOK;
/* The task is an infinite loop , Can't return */
while (1)
{ // If KEY1 Clicked
if( Key_Scan(KEY1_GPIO_PORT,KEY1_GPIO_PIN) == KEY_ON )
{
rt_kprintf ( "KEY1 Clicked \n" );
/* Send a mailbox message 1 */
do
{
uwRet = rt_mb_send(test_mail,(rt_uint32_t)&test_str1);
rt_thread_delay(10); // Release CPU control
}while(uwRet!=RT_EOK); // Until the transmission is successful
rt_kprintf ( " Email message sent successfully \n" );
}
rt_thread_delay(20); // Every time 20ms Scan once
}
}
static void key2_send_thread_entry(void* parameter)
{
rt_err_t uwRet = RT_EOK;
/* The task is an infinite loop , Can't return */
while (1)
{
// If KEY2 Clicked
if( Key_Scan(KEY2_GPIO_PORT,KEY2_GPIO_PIN) == KEY_ON )
{
rt_kprintf ( "KEY2 Clicked \n" );
/* Continuous transmission 15 Secondary mailbox message 2 */
for(int i=0;i<15;i++)
{
do
{
uwRet = rt_mb_send(test_mail,(rt_uint32_t)&test_str2);
rt_thread_delay(10); // Release CPU control
}while(uwRet!=RT_EOK); // Until the transmission is successful
rt_kprintf ( " Email message sent successfully \n" );
}
}
rt_thread_delay(20); // Every time 20ms Scan once
}
}
/********************************END OF FILE****************************/
stay GPIOA Window Pins Check and cancel the check ( Equivalent to pressing Key1), The message will be sent by email :
On the sending thread , Printout “KEY1 Clicked ”“ Email message sent successfully ”.
In the receiving thread , Print out the contents of the mailbox “ The content of the email is :this is a mail test 1”.

边栏推荐
- 网络安全-VLAN和Tunk方法详解
- app quits unexpectedly
- 我今年毕业,但我不知道我要做什么
- [docsify basic use]
- TC397 QSPI(CPU)
- FreeRTOS timer group
- Xshell transfer file
- Mysql5.7 compressed version installation tutorial
- 02 - bare metal and RTOS development modes: five development modes of bare metal and the introduction of RTOS
- Merge: extension click the El table table data to expand
猜你喜欢

Network security - routing principle

Qtcreator debug code after configuring CDB debugger view variable value display card

Can introduction

Install go language development tools

社招两年半10个公司28轮面试面经

I graduated this year, but I don't know what I want to do

Daemon and user threads

Basic knowledge of system software development
![[datawhale team learning] task02: mathematical operation, string and text, list](/img/3e/c9c984d7576a2e410da7f81a8c0aa6.jpg)
[datawhale team learning] task02: mathematical operation, string and text, list

Go语言指针介绍
随机推荐
Resolved: initialize specified but the data directory has files in it Aborting
MAX6675 usage notes
Network security - layer 3 switching technology and internal network planning
1.someip introduction
【已实现】服务器jar包启动脚本、shell脚本
JS create PDF file
Write about your feelings about love and express your emotions
The class imported by idea import clearly exists, but it is red?
Can introduction
[most complete] install MySQL on a Linux server
Ad usage notes
Starting MySQL ERROR! Couldn‘t find MySQL server (/usr/local/mysql/bin/mysqld_safe)
Realization of dissolve effect in unity and its principle analysis
免实名域名是什么意思?
神经网络计算量及参数量
Detailed methods for copying local computer files to virtual machine system
QT signal slot alarm QObject:: connect:cannot connect (null)
28 rounds of interviews with 10 companies in two and a half years
将本地电脑文件复制到虚拟机系统中详细方法
Linux服务器安装Redis