文档库 最新最全的文档下载
当前位置:文档库 › TheApplicationof_省略_ipComputerSystem_a34

TheApplicationof_省略_ipComputerSystem_a34

WuhanUniversityJournalof NaturalSciences Vol.4 No.1 1999,57~60


The Application of Multitasking

Mechanism in Single Chip

Computer SystemX

YuJin, HuangJiwu, YuanLanying

CollegeofElectronicInformation,WuhanUniversity,Wuhan430072,China


Abstract Developedanewprogramstructureusinginsinglechipcomputersystem,whichbasedonmulti-

taskingmechanism.Discussedthespecificmethodforrealizationofthenewstructure.Theappliedsampleis

alsoprovided.

Keywords multitaskingmechanism, singlechipcomputersystem,interruptionmechanism


0 tasking mechanism in single chip computer sys-

Introduction

tems. However, Thelimitedcomputationpowerof

, singlechipcomputerrequiresthatthemultitasking

Generally the single chip computer system

[2].

- schedulingalgorithmmustbeconcise

monitoring program is based on the singletask

mechanism, which leadsto a simple andeasy to

controlprogramstructure. Whileunderthisstruc- 1 The comparison of two mecha-ture, theprogramcanonly beexecutedinafixed

nisms

orderandislessofflexibility, whichcausesunfit-

nessforcomplicatedsystems. Itisofgreatnecessi-

A typical monitoring system basedon singlety toimprovethetraditional structureinorderto chipcomputer isusually composedof input, out-applysinglechipcomputersysteminwiderfields. put, data processing, displaying and keyboard

Themultitasking mechanism istheoutstand- . - ,

management Under the singletask mechanismingvirtueofmodernoperatingsystems. Underthe

theprogramworksinaloopmode, theflowchartmechanism, therunningtimeofCPU isdividedin- isshowedinFig.1.

to manytimeslices, whichareassignedtoseveral

application programs by some scheduling algo-

rithm, according to their priorities. Thus more

thanoneprogramcanbeexecutedat onetimeand

thesystem canschedulestheprogramsflexibly if

needed[1].

Using the multitasking mechanism in single

chip system can improve the program structure

greatly andmeet therequirementsof complicated

. Fig.1 Theflowchartofsingletaskstructuresystem Allkindsofmultitaskingmethodsdepend

on the interruption mechanism. Generally single

Fromtheflowchartwecanseethat, underthechip computers can work in interruption mode, - ,

whichensuresthepossibilityofrealizingthemulti- singletaskmechanism allfunctionblocksexistasX ReceivedOct.8,1998. YuJin:bornin1975,Masterstudent

58 WuhanUniversityJournalof NaturalSciences Vol.4anintegrationandruninafixedsequence. Infact, understand, facilelydebugging, andallowsmodifi-the frequency of execution which each block re- cationtobemademoreconveniently. It?susuallyquiresisusuallynot thesame. For example, the worth paying a price in computation time andsamplingfrequencyofinputinanapplicationmight memoryspaceinordertoachievegreatermodulari-beveryhigh,

whilethekeyboarddetectingtimesin ty. Modularconstructionisespeciallyimportant inunit timeneededrelatively less. Suchcomplicated largeprograms, whichcanreducethecomplexity

ofthesystemgreatly.

timing requirements of application system are

hardly met in thesingletaskstructure- . What is

more, oncetheprogramisestablished, theexecu- 2 The realization of multitaskingtionorderof allblocksisdetermined. Lotsofse- mechanism

lection structures and branches are needed when

theprogramwantstochangetheexecutionstruc- Usingtheinnertimerinterruptionwhichsin-turedynamically, whichincresesthecomplexityof

gle chip computers usually have, we can conve-the program greatly. Another problem appears .

niently realize the multitasking structure Asanwhen debugging and testing the program. We example, the following will discuss the specificwouldfindthat errordetectionbecomeverydiffi- way to apply themultitasking structure in singlecult. chip computer MCS51, which isusually used in

Consideringthefactthatthesystemfunctions manyapplications.

usuallycanbedividedintoseveralrelativelyinde- Firstly, asystemclockmustbeprovided. Ac-pendent moduleswhichwecantranslateintosub- cording to the system clock, therunning timeoftasks, multitaskingmechanismcanbeemployedto CPU isdividedintomanytimeslices, whichcanbemanage the subtasks, and then a new program assigned to each subtask module by the systemstructureappears, asshowedinFig.2. scheduling program. The inner timer of MCS51

canbeemployedtodothejob. Thetimingparame-

tersmust becarefully selectedtomeet all timing

requirementsofthesystem.

Secondly, to realize the multitasking struc-

ture, a task scheduling table and a task pointer

shouldbeconstructed. Eachtaskmodulepossesses

oneiteminthetaskschedulingtableandeachitem

uses 4 bytes to keep entry address and visiting

counter of the task module. A default task

Fig.2 Theflowchartofmultitaskingstructure scheduling tableshouldbeestablished andstored

inprogramstorage, whichcanbeloadedintosys-

Underthemultitaskingstructure, allsubtask

temRAM duringinitialization. At runningtime,modulesare calledby thesystem scheduling pro- thesystemcaneasilymodify thescheduling tablegramandreturntoitwhenfinished. Theschedul- ,

insystemRAM soastoregulatetheexecutionse-ingprogramcaneasilyregulateeachsubtaskmod- quenceandprioritiesofsubtaskmodules. Thesys-uleandmodify theirexecutionordersdynamically 1- ,

temtaskpointerisa byteinteger whichalwayswhen the system is running. The execution fre-

pointtothepositionofcurrenttaskmoduleintaskquency which each subtask module demands de- schedulingtable. Accordingtothetaskpointerandpendsonthepriorityofthemodule. Eachsubtask ,

thetaskscheduling table therelevant taskentrymodulerunsinitsowntimeslices, whichcanbe canbeaccessed.

w

elldesignedtomeetthecomplextimingrequire- Thirdly, thereshouldbeasystem schedulingmentsofapplicationsystemnaturally. program, whichgainscontrolat thebeginning of

Anotherhighlightof multitaskingstructureis everytimeslice. Theschedulingprogramadds4toitshighmodularity. Modulardesignof programis thetaskpointer, makesitpoint to thenext mod-important becauseit makestheprogrameasierto ule. Accordingtothenew pointer, thescheduling No.1 YuJinetalTheApplicationofMultitasking: … 59program looksupthetasktable, andsubtracts1 ms. ThekeyboardmoduleiswrittenasK.fromthevisitingcounterofcurrenttaskmodule. If Two printer driving modules are needed forthevisitingcounterisdecreasedtozero, therele- printing management, theexecution frequency ofvant entryaddressisreadintotheregisterDPTR, bothis1/10s. Wecanwritethetwoprinterdriv-andcurrent taskmodulegainsthesystemcontrol. ingmodulesasP1, P2.

Ifnotzerothenitreturns. Thetaskmoduleresets Except forthis, someother modulessuch asthe visiting counter to initial value whenfinished dataconversionmodulemay beneeded. For thesefor next use. When reaching the end of the ,

function modules have no timing constraint wescheduling table, thetask pointerisreset by the ,

canput themintothemainprocedure whichcan-scheduling program andpointstotheheadof the not bescheduledby the subtask scheduling pro-scheduling table again, which meansa new pro-

gram.

gramcycle. Fromthediscussionwecanseethat: thesys-

Muchmoreattentionshouldbepaidtothede- temneedsto schedule 5modules. Therefore, thecompositionof system function, which meansdi-

scheduling tableshouldbedesignedwith5items.viding thesystem functioninto subtaskmodules. Thehighestexecutionfrequencyis1/2ms,accord-A welldesignedmoduleshouldbeefficient, inde-

ing to whichwe canchoose thelengthof systempendent and suitable for running in interruption 400 . ,

time slice as Ls Consequently the visitingprocedures. Inactualapplications, theremightbe ?

counters valueof everytaskmodulecanbecalcu-somefunctionblockswhichhavenoorlittletiming latedasfollowed:

constraint. Theseblockscanbeput into themain Table1 thevisitingcounter?svalueoftaskmodulesprocedure other than interruption procedure, modulename decimalvalue hexadecimalvaluewhichcanimprovetheprogramefficiencygreatly.

I1 5 00053 Application example I2 1 0001

D 1 0001

K 25 0019

Designanapplicationsystemusingsinglechip 1, 2 5000 1388

P P

computer AT89C51. The system demands two

channelsfordatainput. Onechannelrequiressam- 1

If the module P is selected as the defaultplingevery10ms, whileanotherchannelneedsto ,

printermanager thedefault taskschedulingtablesampleevery2ms. LEDdisplayerisemployedfor

canbedesignedasfollowed:

. Table2 thede

faultschedulingtablesystem displaying Theoutputsof system should

beprintedevery10s. Theprinterdrivingprogram I1entry I2entry Dentry Kentry P1entrymust bedesignedtosupporttwotypesofprinter,

0005 0001 0001 0019 1388whichcanbechosenbykeyboardduringrunning.

Accordingtothemethoddiscussedbefore, the Thetaskschedulingprogramisdevisedasthis:subtaskmodulescanbedesignedasfollowed:

At first, two input sampling modulesshould ... ...

mova, pointer ;pointeriscurrenttaskpointerbeprovided, Whichdemandtheexecutionfrequen- adda, # tasktbl;tasktblistheheadof

cy of 1/10msand1/2ms. Thetwomodulescan ;schedulingtable

bewrittenasI1andI2. adda, # 02h;point tothevisitingcounter

Display modulecanbedesignedasdisplaying movr0, a

mova, @r0 ;decthevisitingcounteronebit at onetime. Tokeepthestableofdisplay,

2 ms?delay is needed between two bits, which clrc

subba, # 01h

means the display frequency should be 1/2ms. movb, a

ThedisplaymodulecanbewrittenasD.

The anti-fluctuation time of keyboard isde- incr0

mova, @r0

signedfor50ms. Therefore, thekeyboardmanag- subba, # 00h

ermodulerequirestheexecutionfrequencyof1/50 jnzexit;ifnotzero,thereturn

60 WuhanUniversityJournalof NaturalSciences Vol.4cjneb, #00h,exit

decr0;visitingcouteriszero 4

decr0 Conclusion

movdph, @r0; Byintroducingthemultitaskingmechanismofreadthetaskentryintodptr modernoperatingsystemintosinglechipcomputerdec r0

, @ 0 system, thearticlecomesupwithanew programmovdpl r

, #00 structure. Applicationsprovedthat: thestructuremova h

jmp@a+dptr; ,

has the virtues of high modularity flexiblyjumptothetaskentry scheduling andeasymaintenance, which speciallyexit:mov@r0, a; .

modifythevisitingcounter fitforcomplexandlargesystems

dec r0 References

mov @r0, b

reti ;interruptionreturn 1 ZhangBo,HangJiwu,DaiShaowei.Theapplicationof

When the system receives commands from time-drivemethodinsinglechiptimingsystem.Journal

of WuhanUnivesity(NaturalScienceEdition),1998,44usersduring running to chooseP2moduleasthe (1):130-132(Ch)

2 Cheng Guangdong, Zhao Xingcu. ThePrinciples andprinter manager, only the following modification

InterfaceTechnologyof SingleChip Computer.Wuhan:totheschedulingtableisneeded:

Table3 themodifiedschedulingtable ThePressofHuazhongUniversityofScienceandTech-

nology, 1995.10-16, 28-30

I1entry I2entry Dentry Kentry P2entry

0005 0001 0001 0019 1388


相关文档
相关文档 最新文档