当前位置:网站首页>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”.

边栏推荐
- [implemented] server jar package startup script and shell script
- 编写并运行第一个Go语言程序
- 【申博攻略】五.专家推荐信模板
- What if I don't know what to do after graduating from university?
- Can introduction
- Linu foundation - zoning planning and use
- Linux服务器安装Redis
- vs2019和sql
- 03 - programming framework: Division of application layer, middle layer and driver layer in bare metal programming
- Utilisation de la commande grep
猜你喜欢
![[most complete] install MySQL on a Linux server](/img/5d/8d95033fe577c161dfaedd2accc533.png)
[most complete] install MySQL on a Linux server

MAX6675 usage notes

The class imported by idea import clearly exists, but it is red?

Mysql5.7 compressed version installation tutorial

Resolution: div failed to get keyboard event

【最全】linux服务器上安装Mysql

Basic knowledge of system software development

halcon:读取摄像头并二值化

安装Go语言开发工具

Keil plug-in Usage Summary
随机推荐
What if I don't know what to do after graduating from university?
The most convenient serial port screen chip scheme designed at the charging pile in China
Write and run the first go language program
June 29, 2022 -- take the first step with C # -- add decision logic to the code using the "if", "else" and "else if" statements in C #
The class imported by idea import clearly exists, but it is red?
Record common problems: spaces in encodeuricomponent decoding and the use of Schema in third-party apps to invoke apps
The maximum expression in Oracle database message list is 1000 error
What does the real name free domain name mean?
神经网络计算量及参数量
Stm32g0 Tim interrupt use
Grep command usage
SQL Server2005中SUM函数内嵌套IF语句
Vs2019 and SQL
【最全】linux服务器上安装Mysql
Deploying web projects using idea
02 - bare metal and RTOS development modes: five development modes of bare metal and the introduction of RTOS
对占用多字节和位的报文信号解析详解
Resolution: div failed to get keyboard event
grep命令用法
Four great happenings on earth