environment:
Host: WIN8
Development environment: MDK4.72
ucgui version: 3.90
ucos version: ucos-ii
mcu: stm32f103VE
illustrate:
In this example, task2 requests a memory partition, writes data to the partition, and then sends the data to task1 via email.
Effect picture:
Source code:
#define TASK_STK_SIZE 512
/*********************************************************************
* Static functions
**********************************************************************/
static void task_start(void *pdata);
static void task1(void *pdata);
static void task2(void *pdata);
/*********************************************************************
* Static variables
**********************************************************************/
/*********************************************************************
* Task stack space
**********************************************************************/
static OS_STK Task_Start_Stk[TASK_STK_SIZE];
static OS_STK Task1_Stk[TASK_STK_SIZE];
static OS_STK Task2_Stk[TASK_STK_SIZE];
/*********************************************************************
* signal
**********************************************************************/
OS_EVENT *Semaphore;
/*********************************************************************
* Message queue array
**********************************************************************/
void *Msg_Group[10];
char Msg_Arr[10][30];
uint8_t Index_Msg_Arr = 0;
/*********************************************************************
* Memory partition
**********************************************************************/
OS_MEM *Buffer_Ptr;
uint8_t Buffer[10][30];
/*********************************************************************
* Functions
**********************************************************************/
int main(void)
{
// Initialize the kernel
OSInit();
//Create a task
OSTaskCreate(task_start,(void *)0,Task_Start_Stk + TASK_STK_SIZE - 1,10);
//Start the task
OSStart();
}
/*********************************************************************
* Task function
**********************************************************************/
static void task_start(void *pdata)
{
uint8_t err = 0;
//Load the world
world_load();
//Set the background color
GUI_SetBkColor(0xb07c17);
GUI_Clear();
GUI_SetColor(GUI_BLACK);
//Create a new mailbox
Semaphore = OSMboxCreate((void *)0);
//Create memory partition
Buffer_Ptr = OSMemCreate(Buffer,10,30,&err);
//Create a new task
OSTaskCreate(task1,(void *)0,Task1_Stk + TASK_STK_SIZE - 1,11);
OSTaskCreate(task2,(void *)0,Task2_Stk + TASK_STK_SIZE - 1,12);
while(1)
{
OSTimeDlyHMSM(0,0,3,0);
}
}
static void task1(void *pdata)
{
char str[30] = {0};
uint8_t err = 0;
uint8_t *mail;
while(1)
{
//Request semaphore
mail = OSMboxPend(Semaphore,0,&err);
//show
sprintf(str,"task1 receive:%d,%d,%d",mail[0],mail[1],mail[2]);
GUI_DispStringHCenterAt(str, 120, 40);
//show
sprintf(str,"task1 time:%ds",OSTimeGet());
GUI_DispStringHCenterAt(str, 120, 5);
WM_Exec();
OSTimeDlyHMSM(0,0,1,0);
}
}
static void task2(void *pdata)
{
char str[30] = {0};
uint8_t err = 0;
uint8_t *ptr;
static uint8_t a = 0;
while(1)
{
// Request memory partition
ptr = OSMemGet(Buffer_Ptr,&err);
//Assignment
ptr[0] = a++;
ptr[1] = a++;
ptr[2] = a++;
//Send via email
OSMboxPost(Semaphore,ptr);
//Release the memory partition
OSMemPut(Buffer_Ptr,ptr);
//show
sprintf(str,"task2 time:%ds",OSTimeGet());
GUI_DispStringHCenterAt(str, 120, 20);
WM_Exec();
OSTimeDlyHMSM(0,0,3,0);
}
}
Previous article:Porting emwin on STM32F407
Next article:ucos-ii example 6: message volume set test
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
- Brief Analysis of Automotive Ethernet Test Content and Test Methods
- How haptic technology can enhance driving safety
- Let’s talk about the “Three Musketeers” of radar in autonomous driving
- Why software-defined vehicles transform cars from tools into living spaces
- How Lucid is overtaking Tesla with smaller motors
- Wi-Fi 8 specification is on the way: 2.4/5/6GHz triple-band operation
- Wi-Fi 8 specification is on the way: 2.4/5/6GHz triple-band operation
- Vietnam's chip packaging and testing business is growing, and supply-side fragmentation is splitting the market
- Vietnam's chip packaging and testing business is growing, and supply-side fragmentation is splitting the market
- Help, DC motor driver chip selection
- LSM6DS3TR-C related information
- Strengthen physical exercise after work
- Please advise, does connecting a 102 capacitor in parallel with a button really have the effect of eliminating jitter?
- OLED display driver
- Espressif ESP8685 Technical Specification
- How to migrate FreeRTOS applications to secure SAFERTOS
- MSP430G2 LaunchPad, how to play music with buzzer
- Disassemble a WSN node device and see how to select materials?
- Allwinner V853 heterogeneous multi-core AI intelligent vision development board review - V853 YOLO V3 test