当前位置:网站首页>Play a parallel multithreaded mcu-mc3172
Play a parallel multithreaded mcu-mc3172
2022-07-27 02:58:00 【Embedded Linux,】
Hello, everyone, forward an article of hotchpotch King , Chowder Jun is my fellow villager in the same high school , The embedded knowledge he usually shares is very good .
——————
Hello everyone , I'm Mr. hodgepodge .
lately , My friend gave me a small board , On the board MCU It's a very interesting thing —— Parallel multithreaded processor MC3172 .
In layman's terms , The star MCU The internal implementation of is similar RTOS Multithreading function . however MC3172 Programming with RTOS The biggest difference in programming is :
MC3172 Multithreading runs in absolute parallel , No switching jitter and overhead .
MC3172 Radio priority 、 Priority reversal 、 Deadlock and other concepts .
MC3172 All interrupts can be handled by special threads , No interrupt nesting and latency .
MC3172 Each thread runs synchronously and in parallel , They don't block each other , Mutual interference .
MC3172 The certainty of thread response is relative to RTOS More accurate .
MC3172 brief introduction
MC3172 It is a product of Xiamen Ganxin Technology 32 position RISC Parallel multithreaded real-time processor . be based on RISC-V RV32IMC Instruction set , 100% Single cycle instruction , The highest 200MHz Main frequency , 3.37coremark/MHz. It can replace the real-time operating system , Realize the modularity and reusability of the program .
Relevant information can be downloaded from the official website of Ganxin . link :
http://www.gxchip.cn/
MC3172 characteristic :

MC3172 practice
MC3172 Our development environment uses domestic software ——MounRiver Studio.

MounRiver Studio Download link :
http://www.mounriver.com/download
Let's look at it briefly MC3172 Of demo engineering :

1、MC3172 Folder
MC3172 Deposit MC3172 Programming core file .
The thread configuration tool can configure each thread :

Thread clock source can be configured 、 frequency 、 Stack space 、 Memory allocation and other information .
MC3172 Support 64 The route runs synchronously and in parallel , It's divided into 4 A thread group , Each thread group 16 Threads , The thread number in each thread group is shown in the figure above . among , Unused threads can be set as idle threads , Idle threads are not running at all , No power consumption .
Each thread has its own stack space , It can be allocated freely within the allowable range of data space , However, it is necessary to ensure that the data space occupied by all non idle threads does not exceed the size of the data space .
MC3172.h Store macro definitions related to peripheral addresses and their configuration macros , Such as :

Be similar to ST Of stm32fxxx.h.
thread_config.h Configure files for threads , Generated by thread configuration tool :

MC3172.lds For link scripts , Generated by thread configuration tool

thread_start.c The source file related to the starting thread :
#ifndef THREAD_START_C
#define THREAD_START_C
#include "./MC3172.h"
#include "./thread_config.h"
void thread1_initial(void)
{
#ifdef ROTHD_THREAD1_VALID
extern void thread1_main(void);
rothd_set_sp_const(ROTHD_THREAD1_STACKCFG_VALUE|0x20000000);
thread1_main();
#endif
}
void thread2_initial(void)
{
#ifdef ROTHD_THREAD2_VALID
extern void thread2_main(void);
rothd_set_sp_const(ROTHD_THREAD2_STACKCFG_VALUE|0x20000000);
thread2_main();
#endif
}
// Omitted code ......
void (*thread_initial_pointer[64]) (void)={
&thread0_initial,
&thread1_initial,
&thread2_initial
// Omitted code ......
}
void thread_start(void)
{
(*thread_initial_pointer[THREAD_ID])();
} The entry function of the program is :thread_start , You can know from the link script :

thread_start Inside THREAD_ID For threads ID value , Directly from 0x50000000 Read in the address :
#define THREAD_ID (*(volatile u8*)(0x50000000))guess :0x50000000 In the address ID The value is constantly changing , Jump through some mechanism , Traverse the execution thread_initial_pointer Each thread function in the function pointer array .
threadx_initial Initialize the thread stack , And execute the thread body , Such as
void thread_end(void)
{
while(1);
}
void thread1_main(void)
{
while(1){
//user code section
}
thread_end();
}This is the user code , We can write our application code in each thread body function .
2、Release Folder
Release The firmware program generated by compilation is stored in the folder , adopt Development board program download tool Available for download :


3、USER_CODE Folder
USER_CODE The folder stores the user code :

MC3172 It is a parallel multithreaded real-time processor , Let's take a look at its multi-threaded parallel execution features .
We write two threads , Threads are configured the same , Two threads are for two IO Flip , Test code such as :
void LED0_GPIOA_PIN0_TEST(void)
{
// start-up GPIOA And set the privilege group and clock frequency
INTDEV_SET_CLK_RST(GPIOA_BASE_ADDR,(INTDEV_RUN|INTDEV_IS_GROUP0|INTDEV_CLK_IS_CORECLK_DIV2));
// Can make GPIOA PIN0 Pin
GPIO_SET_OUTPUT_EN_VALUE(GPIOA_BASE_ADDR, GPIO_PIN0, GPIO_SET_ENABLE);
while(1)
{
// GPIOA PIN0 Output 1
GPIO_SET_OUTPUT_PIN_TO_1(GPIOA_BASE_ADDR, GPIO_PIN0);
// Time delay
for (u32 var = 0; var < 5000; ++var)
{
NOP();
}
// GPIOA PIN0 Output 0
GPIO_SET_OUTPUT_PIN_TO_0(GPIOA_BASE_ADDR, GPIO_PIN0);
// Time delay
for (u32 var = 0; var < 5000; ++var)
{
NOP();
}
}
}
void LED1_GPIOA_PIN1_TEST(void)
{
// start-up GPIOA And set the privilege group and clock frequency
INTDEV_SET_CLK_RST(GPIOA_BASE_ADDR,(INTDEV_RUN|INTDEV_IS_GROUP0|INTDEV_CLK_IS_CORECLK_DIV2));
// Can make GPIOA PIN1 Pin
GPIO_SET_OUTPUT_EN_VALUE(GPIOA_BASE_ADDR, GPIO_PIN1, GPIO_SET_ENABLE);
while(1)
{
// GPIOA PIN1 Output 1
GPIO_SET_OUTPUT_PIN_TO_1(GPIOA_BASE_ADDR, GPIO_PIN1);
// Time delay
for (u32 var = 0; var < 5000; ++var)
{
NOP();
}
// GPIOA PIN1 Output 0
GPIO_SET_OUTPUT_PIN_TO_0(GPIOA_BASE_ADDR, GPIO_PIN1);
// Time delay
for (u32 var = 0; var < 5000; ++var)
{
NOP();
}
}
}
void thread_end(void)
{
while(1);
}
void thread0_main(void)
{
while(1){
//user code section
}
thread_end();
}
void thread1_main(void)
{
while(1){
//user code section
LED0_GPIOA_PIN0_TEST();
}
thread_end();
}
void thread2_main(void)
{
while(1){
//user code section
LED1_GPIOA_PIN1_TEST();
}
thread_end();
}Burn program , Use the logic analyzer to grab GPIOA_PIN0 And GPIOA_PIN1 Pin level changes, such as :

so , These two waveforms are completely synchronized ,CPU Doing two things at the same time , Realized and RTOS Multithreading has the same effect .
Experience and summary
Embedded development , It's software + Hardware combination , The two complement each other . If the hardware is powerful , Then the software may be designed to be relatively simple ; If the hardware function is limited , Then the software may have to consider many aspects .
such as :
Some software algorithms , Multi sensor data input is required for fusion , Then the function implementation may be relatively simple , But in fact, it may be to reduce costs , Reduce some sensors , At this time, it is necessary to realize stable and reliable functions , Then the software algorithm needs to work harder .
For some less complex digital signal processing , In general MCU Can handle , But for some complex digital signal processing , You may use some with DSP The processor MCU.
Special , For the inside of the chip IC In terms of circuits , If there are relevant modules inside that can realize some functions , The corresponding software programming will be much simpler , And the efficiency of hardware implementation is higher than that of software implementation .
Hardware implementation of multithreaded programming is indeed better than RTOS Programming , However, in the actual development, the software and hardware architecture of the product needs to consider many aspects , For example, chip stability and software ecology .
Parallel multithreaded real-time processors are a good thing , But the parallel multithreaded real-time processor is still in its infancy , There is still much to be perfected , We need more support and communication , Only ecological , Only in the future will we have a chance to use .
That's what we're sharing , If you find the article helpful , Please forward it , thank you !


边栏推荐
- Arduino UNO +74hc164 water lamp example
- The XML format of labelimg annotation is converted to yolov5
- Talk about connection pools and threads
- C语言程序的编译上
- 数据资产管理的概念
- 「软件测试」包装简历从这几点出发,直接提升通过率
- C language: deep learning recursion
- Graduated and entered HW, from test engineer to project manager. Now I earn millions in goose factory every year. My suggestions to you
- static关键字
- Okaleido tiger is about to log in to binance NFT in the second round, which has aroused heated discussion in the community
猜你喜欢

【力扣】1859.将句子排序

Time module: acquisition and mutual transformation of timestamp, structured time and formatted time

Database read-write separation and database and table segmentation

Blog competition dare to try BAC for beginners

Rust web (I) -- self built TCP server

Uni app wechat applet search keywords are displayed in red

After ten years of testing, I want to say to my friends who are still confused: one thing is to do a good job in personal planning

Concept of data asset management

万字长文,带你搞懂 Kubernetes 网络模型

OD-Paper【3】:Faster R-CNN: Towards Real-Time Object Detection with Region Proposal Networks
随机推荐
想要彻底搞的性能优化,得先从底层逻辑开始了解~
Knowledge points of test questions related to software testing
软件测试基础理论知识—概念篇
Towhee 每周模型
C language program compilation (preprocessing)
【力扣】1859.将句子排序
文章主要内容提取软件[基于NLP技术]
【无标题】
f8抓交通、f9抓兔子、f10turtle
砺夏行动|源启数字化:既有模式,还是开源创新?
图书馆和档案馆的职能
I was fired at the age of 30. I want to understand a few things
Kubeadmin到底做了什么?
函数栈帧详解
[redis] quick start
Basic theoretical knowledge of software testing - concept
Rust Web(一)—— 自建TCP Server
If you want to thoroughly optimize the performance, you must first understand the underlying logic~
It has been established for 3 years, and now goose factory has an annual income of millions +. As some suggestions of software testing predecessors
JS 数组去重(含简单数组去重、对象数组去重)