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


边栏推荐
猜你喜欢

Okaleido tiger is about to log in to binance NFT in the second round, which has aroused heated discussion in the community

Talk about the metrics of automated testing

动态设置小程序swiper的高度

#博客大赛# 斗胆尝试浅入门之BAC

Uni app wechat applet search keywords are displayed in red

C language program compilation (preprocessing)

c语言:深度学习递归

聊聊连接池和线程

static关键字

Rust Web(一)—— 自建TCP Server
随机推荐
听说你们面试都跪在了接口测试上?
Time module: acquisition and mutual transformation of timestamp, structured time and formatted time
中断、信号、系统调用
小程序utils
Quick sort
Leetcode- > binary search clock in
平成千字文(へいせいせんじもん) (平成12年9月10日 石渡 明 作) 宇宙広遠 銀河永久 日月運行 不乱無休 地球公転 季節変移 黄道星座 太陽年周 故郷群島 南熱北冷 海洋温暖 気候順良 青空飛雲 諸野深緑 湖泉静息 谷川清流 春桜一面 新芽
[Li Kou] 1859. Sort sentences
Rust Web(一)—— 自建TCP Server
Tabbar of customized wechat applet on uni app
「软件测试」包装简历从这几点出发,直接提升通过率
Plato farm is expected to further expand its ecosystem through elephant swap
com.fasterxml.jackson.databind.exc.InvalidDefinitionException
Shell 分析日志文件命令全面总结
JS 数组去重(含简单数组去重、对象数组去重)
Database read-write separation and database and table segmentation
Why do people like to rank things
Go language slow start -- go operator
无效的目标发行版:17 的解决办法
线程和进程