当前位置:网站首页>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”.
边栏推荐
- Linu foundation - zoning planning and use
- 【已解决】ERROR 1290 (HY000): Unknown error 1290
- 踩坑记录:supervisor 日志返回信息:redis扩展未安装
- Idea running run and services
- Stm32g0 porting FreeRTOS
- Can introduction
- Linu基础-分区规划与使用
- Double click the idea to solve the problem of downloading again
- 15 minutes learn to use JWT
- Realization of dissolve effect in unity and its principle analysis
猜你喜欢
How to use string branches for switch case
1285_ Expand macros defined by AUTOSAR functions and variables with scripts to improve readability
The first up Master of station B paid to watch the video still came! Price "Persuading" netizens
Deploying web projects using idea
Introduction to go project directory structure
编写并运行第一个Go语言程序
Mysql5.7 compressed version installation tutorial
Can introduction
系统软件开发基础知识
Minecraft 1.16.5模组开发(五十) 书籍词典 (Guide Book)
随机推荐
Qtcreator debug code after configuring CDB debugger view variable value display card
Stm32g0 Tim interrupt use
Thread network
Four great happenings on earth
Can introduction
网络安全-抓包和IP包头分析
Unity中实现溶解(Dissolve)特效及其原理解析
神经网络计算量及参数量
QT signal slot alarm QObject:: connect:cannot connect (null)
对占用多字节和位的报文信号解析详解
Introduction to go project directory structure
Linu基础-分区规划与使用
[semidrive source code analysis] [x9 chip startup process] 33 - Analysis of related concepts of display module
Minecraft 1.16.5模组开发(五十) 书籍词典 (Guide Book)
nRF52832 GPIO LED
Basic knowledge of system software development
Keil serial port redirection
Merge: extension click the El table table data to expand
【申博攻略】五.专家推荐信模板
Resolution: div failed to get keyboard event