嵌入式操作系統(tǒng) /
service /
1544
編輯
刪除
SCM also be known as micro-controller (Microcontroler), SCM only by the CPU chip, developed from a dedicated processor. The first design concept is by and large number of peripheral devices integrated in a CPU chip, the computer system is smaller, more easily integrated.
Early SCM are eight or the four. One of the most successful is the 8031 INTEL, because simple and reliable and good performance was praised. Since then in 8031 on the development of a series MCS51 SCM system. Based on this system until now the SCM system is still widely used. As the field of industrial control requirements of the increase, began to appear in 16-bit microcontrollers. As the 1990s after the big consumer electronics product development, SCM technology got a huge raise. With the emergence of INTEL i960 series, especially the later ARM wide range of applications, 32-bit microcontroller quickly replaced by 16 high-end MCU status and enter the mainstream market. And the traditional 8-bit microcontrollers performance has been improving rapidly, the capacity increase compared with the 1980s a few hundred times. At present, high-speed 32-bit microcontroller has exceeded 300 MHz, catching up performance of the mid-1990s, dedicated processors.
Contemporary SCM system is no longer only barebone environment in the development and use of a large number of dedicated embedded operating system is widely used in the SCM. As handheld computers and mobile phones with high-end microcontroller core can even direct the use of a dedicated Windows and Linux operating systems. SCM processor for more than suitable for embedded systems. In fact SCM is the world's largest number of computers. Modern human life used in almost every electronic and machinery products will integrate a microcontroller. Cell phone, telephone, calculator, household appliances, electronic toys, handheld computers and computer accessories such as a mouse with a 1-2 in both the Department of SCM. And personal computers will also have a large number of SCM at work. General vehicle equipped with more than 40 of the microcontroller, complex industrial control systems may have even hundreds of SCM at the same time work! SCM is not only far exceeded the number of PC and other integrated computing, or even than the number of human beings more. In SCM applications, the MCU anti-jamming system software debugging and MCU programming has been troubled for beginners. This article brief introduction of these two issues.
SCM system software interference methods
In improving the ability of anti-jamming system hardware, software interference with its flexible design, save hardware resources, more and more attention to reliability. Below the MCS-51 SCM system as an example, the computer system software interference methods for research.
In engineering practice, anti-jamming software on the content of the main ones being: 1, analog input signal to eliminate the noise (such as digital filter technology); two, is running the program when the chaos back to the right track approach. In this paper, which made several effective methods of anti-jamming software.
1. redundant directives
CPU process is to take instructions from operating code, and then take a few operators. When the PC interference errors, procedures will be from the normal track "flying", when flying to a double-byte instructions, if the instructions for a few moments landed on the operation, as the number-up operation operation code, procedural error will be . If the "fly" to the three-byte instructions, a greater probability of error.
In some key areas were inserted into single-byte instructions, or to be effective single-byte command rewrite directive known as redundancy. Is usually double-byte instructions and orders three bytes inserted after more than two bytes of the NOP. This flew to operate even if the number of flying procedures, the air operations of NOP because of the existence of the directive to avoid being behind the operation as a number of implementation, automatically into the right track.
In addition, the system flows to play an important role in the directive such as RET, RETI, LCALL, LJMP, JC, and other instructions inserted before the two NOP, also could be flying into the right track procedures to ensure that the implementation of these important directives.
2. interception technology
The so-called blocking, is flying the procedure will lead the specified location and then an error handling. Traps are usually software used to block flying procedures. Therefore must be reasonably designed trap, trap in the second to the appropriate location.
1) The design software trap
When flying into the non-process procedures, redundant command will not work. By software traps, interceptors flying procedures, to lead the specified location and then an error handling. Software trap is used to capture the flying process toward reduction of import address 0000 H instructions. Its native code for the 0000020000.
2) the arrangements for traps
Usually in the process of the unused space filled EPROM 0000020000. Finally one should fill 020,000, when flying procedures fell on the area, to automatically orbit. In the user program, and various modules in the margins between the unit can also fill traps command. When using the interference and interruption due to open, in the corresponding interrupt service procedures set up software trap, caught the wrong time can be interrupted. Top of instruction available "RETI", can also be used "LJMP 0000H". If the fault diagnosis procedures and systems since the restoration of the design process reliable, complete with "LJMP 0000H" for the return instructions directly into the fault diagnosis procedures, as soon as possible to deal with failure and recovery procedures of the operation.
Taking into account the capacity of program memory, software trap 1 K space in the general 2-3 can be effectively blocked.
3. the software "watchdog" technology
If out-of-control process into the "cycle of death", usually a "watchdog" technology to process from the "death cycle." By constantly testing procedures cycle running time, if the process cycle time exceeds the maximum running time cycle, the system that a "cycle of death", the need for error handling.
"Watchdog" technology can be hardware, software can be. In industrial applications, serious interference may sometimes be interrupted damage control word, closure of interruption. The system can not regularly, hardware watchdog circuit failure. The software watchdog to be effective in solving such problems.
In practical applications, using ring interrupted surveillance systems. T0 Watchdog timer with T1, with timer T1 surveillance main program, the main program Watchdog T0. This ring used the software "watchdog" has a good anti-jamming performance, greatly improving the system reliability. The need for frequent use of T1 timer serial communications monitoring and control system, the timer T1 can not be interrupted, may be diverted from the serial port to monitor the interruption. Such software "watchdog" monitoring principle is: the main program, T0 interrupted service program, T1 service interruption in the process to establish a running observation variables, assumed to be MWatch, T0Watch, T1Watch, each cycle of a main program, MWatch plus 1 , The same T0, T1 procedures for the implementation of a service interruption, T0Watch, T1Watch plus 1. T0 interruption in the service of process in T1Watch by detecting changes in the determination of whether the normal operation of T1, T1 interruption in the service of process in the detection of changes in the MWatch determine whether the normal operation of the main program, in the main program in T0Watch by detecting changes in normal circumstances determine whether T0 work. If an observation detected abnormal changes in variables, such as an increase should not increase 1, to the error handling procedures for dealing with troubleshooting. Of course, most of the main program cycle, the timer T0 and T1 timing cycle should be completely reasonable to consider.
中文譯文
單片機(jī)也被稱為微控制器(Microcontroler),單片機(jī)由芯片內(nèi)僅有CPU的專用處理器發(fā)展而來(lái)。最早的設(shè)計(jì)理念是通過(guò)將大量外圍設(shè)備和CPU集成在一個(gè)芯片中,使計(jì)算機(jī)系統(tǒng)更小,更容易集成。
早期的單片機(jī)都是8位或4位的。其中最成功的是INTEL的8031,因?yàn)楹?jiǎn)單可靠而性能不錯(cuò)獲得了好評(píng)。此后在8031上發(fā)展出了MCS51系列單片機(jī)系統(tǒng)?;谶@一系統(tǒng)的單片機(jī)系統(tǒng)直到現(xiàn)在還在廣泛使用。隨著工業(yè)控制領(lǐng)域要求的提高,開(kāi)始出現(xiàn)了16位單片機(jī)。90年代后隨著消費(fèi)電子產(chǎn)品大發(fā)展,單片機(jī)技術(shù)得到了巨大的提高。隨著INTEL i960系列的出現(xiàn),特別是后來(lái)的ARM系列的廣泛應(yīng)用,32位單片機(jī)迅速取代16位單片機(jī)的高端地位,并且進(jìn)入主流市場(chǎng)。而傳統(tǒng)的8位單片機(jī)的性能也得到了飛速提高,處理能力比起80年代提高了數(shù)百倍。目前,高端的32位單片機(jī)主頻已經(jīng)超過(guò)300MHz,性能直追90年代中期的專用處理器。
當(dāng)代單片機(jī)系統(tǒng)已經(jīng)不再只在裸機(jī)環(huán)境下開(kāi)發(fā)和使用,大量專用的嵌入式操作系統(tǒng)被廣泛應(yīng)用在單片機(jī)上。作為掌上電腦和手機(jī)核心處理的高端單片機(jī)甚至可以直接使用專用的Windows和Linux操作系統(tǒng)。 單片機(jī)比專用處理器更適合應(yīng)用于嵌入式系統(tǒng)。事實(shí)上單片機(jī)是世界上數(shù)量最多的計(jì)算機(jī)?,F(xiàn)代人類生活中所用的幾乎每件電子和機(jī)械產(chǎn)品中都會(huì)集成有單片機(jī)。手機(jī)、電話、計(jì)算器、家用電器、電子玩具、掌上電腦以及鼠標(biāo)等電腦配件中都配有1-2部單片機(jī)。而個(gè)人電腦中也會(huì)有為數(shù)不少的單片機(jī)在工作。汽車上一般配備40多部單片機(jī),復(fù)雜的工業(yè)控制系統(tǒng)上甚至可能有數(shù)百臺(tái)單片機(jī)在同時(shí)工作!單片機(jī)的數(shù)量不僅遠(yuǎn)超過(guò)PC機(jī)和其他計(jì)算的綜合,甚至比人類的數(shù)量還要多。在單片機(jī)應(yīng)用中,單片機(jī)的系統(tǒng)軟件抗干擾和單片機(jī)的編程調(diào)試一直困擾著初學(xué)者。本文就簡(jiǎn)單的介紹這兩個(gè)問(wèn)題。
單片機(jī)系統(tǒng)軟件抗干擾方法
在提高硬件系統(tǒng)抗干擾能力的同時(shí),軟件抗干擾以其設(shè)計(jì)靈活、節(jié)省硬件資源、可靠性好越來(lái)越受到重視。下面以MCS-51單片機(jī)系統(tǒng)為例,對(duì)微機(jī)系統(tǒng)軟件抗干擾方法進(jìn)行研究。
在工程實(shí)踐中,軟件抗干擾研究的內(nèi)容主要是: 一、消除模擬輸入信號(hào)的噪聲(如數(shù)字濾波技術(shù));二、程序運(yùn)行混亂時(shí)使程序重入正軌的方法。本文針對(duì)后者提出了幾種有效的軟件抗干擾方法。
1.指令冗余
CPU取指令過(guò)程是先取操作碼,再取操作數(shù)。當(dāng)PC受干擾出現(xiàn)錯(cuò)誤,程序便脫離正常軌道“亂飛”,當(dāng)亂飛到某雙字節(jié)指令,若取指令時(shí)刻落在操作數(shù)上,誤將操作數(shù)當(dāng)作操作碼,程序?qū)⒊鲥e(cuò)。若“飛” 到了三字節(jié)指令,出錯(cuò)機(jī)率更大。
在關(guān)鍵地方人為插入一些單字節(jié)指令,或?qū)⒂行巫止?jié)指令重寫稱為指令冗余。通常是在雙字節(jié)指令和三字節(jié)指令后插入兩個(gè)字節(jié)以上的NOP。這樣即使亂飛程序飛到操作數(shù)上,由于空操作指令NOP的存在,避免了后面的指令被當(dāng)作操作數(shù)執(zhí)行,程序自動(dòng)納入正軌。
此外,對(duì)系統(tǒng)流向起重要作用的指令如RET、 RETI、LCALL、LJMP、JC等指令之前插入兩條NOP,也可將亂飛程序納入正軌,確保這些重要指令的執(zhí)行。
2.攔截技術(shù)
所謂攔截,是指將亂飛的程序引向指定位置,再進(jìn)行出錯(cuò)處理。通常用軟件陷阱來(lái)攔截亂飛的程序。因此先要合理設(shè)計(jì)陷阱,其次要將陷阱安排在適當(dāng)?shù)奈恢谩?/span>
1)軟件陷阱的設(shè)計(jì)
當(dāng)亂飛程序進(jìn)入非程序區(qū),冗余指令便無(wú)法起作用。通過(guò)軟件陷阱,攔截亂飛程序,將其引向指定位置,再進(jìn)行出錯(cuò)處理。軟件陷阱是指用來(lái)將捕獲的亂飛程序引向復(fù)位入口地址0000H的指令。其機(jī)器碼為0000020000。
2)陷阱的安排
通常在程序中未使用的EPROM空間填0000020000。最后一條應(yīng)填入020000,當(dāng)亂飛程序 落到此區(qū),即可自動(dòng)入軌。在用戶程序區(qū)各模塊之間的空余單元也可填入陷阱指令。當(dāng)使用的中斷因干擾而開(kāi)放時(shí),在對(duì)應(yīng)的中斷服務(wù)程序中設(shè)置軟件陷阱,能及時(shí)捕獲錯(cuò)誤的中斷。返回指令可用“RETI”,也可用“LJMP 0000H”。如果故障診斷程序與系統(tǒng)自恢復(fù)程序的設(shè)計(jì)可靠、 完善,用“LJMP 0000H”作返回指令可直接進(jìn)入故障診斷程序,盡早地處理故障并恢復(fù)程序的運(yùn)行。
考慮到程序存貯器的容量,軟件陷阱一般1K空間有2-3個(gè)就可以進(jìn)行有效攔截。
3.軟件“看門狗”技術(shù)
若失控的程序進(jìn)入“死循環(huán)”,通常采用“看門狗”技術(shù)使程序脫離“死循環(huán)”。通過(guò)不斷檢測(cè)程序循環(huán)運(yùn)行時(shí)間,若發(fā)現(xiàn)程序循環(huán)時(shí)間超過(guò)最大循環(huán)運(yùn)行時(shí)間,則認(rèn)為系統(tǒng)陷入“死循環(huán)”,需進(jìn)行出錯(cuò)處理。
“看門狗”技術(shù)可由硬件實(shí)現(xiàn),也可由軟件實(shí)現(xiàn)。 在工業(yè)應(yīng)用中,嚴(yán)重的干擾有時(shí)會(huì)破壞中斷方式控制字,關(guān)閉中斷。則系統(tǒng)無(wú)法定時(shí),硬件看門狗電路失效。而軟件看門狗可有效地解決這類問(wèn)題。
在實(shí)際應(yīng)用中,采用環(huán)形中斷監(jiān)視系統(tǒng)。用定時(shí)器T0監(jiān)視定時(shí)器T1,用定時(shí)器T1監(jiān)視主程序,主程序監(jiān)視定時(shí)器T0。采用這種環(huán)形結(jié)構(gòu)的軟件“看門狗”具有良好的抗干擾性能,大大提高了系統(tǒng)可靠性。對(duì)于需經(jīng)常使用T1定時(shí)器進(jìn)行串口通訊的測(cè)控系統(tǒng),則定時(shí)器T1不能進(jìn)行中斷,可改由串口中斷進(jìn)行監(jiān)控。這種軟件“看門狗”監(jiān)視原理是:在主程序、T0中斷服務(wù)程序、T1中斷服務(wù)程序中各設(shè)一運(yùn)行觀測(cè)變量,假設(shè)為MWatch、T0Watch 、T1Watch,主程序每循環(huán)一次,MWatch加1,同樣T0、T1中斷服務(wù)程序執(zhí)行一次,T0Watch、 T1Watch加1。在T0中斷服務(wù)程序中通過(guò)檢測(cè)T1Watch的變化情況判定T1運(yùn)行是否正常,在T1中斷服務(wù)程序中檢測(cè)MWatch的變化情況判定主程序是否正常運(yùn)行,在主程序中通過(guò)檢測(cè)T0Watch的變化情況判別T0是否正常工作。若檢測(cè)到某觀測(cè)變量變化不正常,比如應(yīng)當(dāng)加1而未加1,則轉(zhuǎn)到出錯(cuò)處理程序作排除故障處理。當(dāng)然,對(duì)主程序最大循環(huán)周期、定時(shí)器T0和T1定時(shí)周期應(yīng)予以全盤合理考慮。
評(píng)論