How to write DSP device drivers.docx
- 文档编号:10180057
- 上传时间:2023-02-09
- 格式:DOCX
- 页数:15
- 大小:89.79KB
How to write DSP device drivers.docx
《How to write DSP device drivers.docx》由会员分享,可在线阅读,更多相关《How to write DSP device drivers.docx(15页珍藏版)》请在冰豆网上搜索。
HowtowriteDSPdevicedrivers
HowtowriteDSPdevicedrivers
NickLethabyandDavidFriedland
12/15/20035:
00PMEST
Asdigitalsignalprocessorspickupperipherals,you'llneedtowritenewdevicedrivers.Herearesometime-savingtipsforwritingthemforplatformsbasedonDSPs.
Digitalsignalprocessors(DSPs)arenowoftenintegratedon-chipwithnumerousperipheraldevices,suchasserialports,UARTs,PCI,orUSBports.Asaresult,developingdevicedriversforDSPsrequiressignificantlymoretimeandeffortthaneverbefore.
Inthisarticle,we'llshowyouaDSPdevice-driverarchitecturethatreducesoveralldriverdevelopmenttimebyreusingcodeacrossmultipledevices.We'llalsolookin-depthatanaudiocodecdrivercreatedusingthisarchitecture.ThedesignandcodeexamplesarebasedondriversdevelopedfortheTexasInstruments'DSP/BIOSoperatingsystem,thoughthesameapproachwillworkinanysystem.
HowDSPsdiffer
Whereasmicroprocessorsaremainlyusedforgeneralpurposecontrol,DSPsalmostinvariablydohardreal-timedata-pathprocessing,wheredatasamplesareinputinacontinuousstream.DSPsareoptimizedtomovedataquicklyfromaperipheraltotheDSPcore,leadingtoseveralarchitecturaldifferencesfrommicroprocessors.
Somemicroprocessorsexecuteallcodefromexternalmemoryviaaninstructioncache(I-cache).I/Operipheralregistersarememory-mappedandaccessedlikeanyotherprogramdata.Incontrast,manyDSPsdon'tprovideI-cache,butdoincludehigh-speed,on-chipmemorythatsupportsefficientprogramexecution.EvenwiththelatestDSPsthatdoprovideI-cache,thememoryisconfigurableaseitheracacheordirectlyaddressablememoryoracombinationofthetwo.It'sacommonpracticetodedicatesomeofthismemorytoreal-timeI/O,criticalcodeloops,anddatatoavoidpotentialnondeterministicbehaviorcausedbycachemisses.
Tomeetreal-timeI/Oneeds,DSPsprovidededicatedserialportsthatconnecttostreamingperipherals,suchascodecsandotherdataconverters.Theinteractionbetweenthecodecandtheserialportissynchronousandhandledentirelyinhardware,thoughinitialconfigurationoftheframesync,transferrate,samplerate,andsamplesizemustbedonebytheDSP.
AlthoughtheserialportscaninteractdirectlywiththeDSPcore,softwaredevelopersavoidthisapproachforreal-timeI/Obecauseofthefrequencyofinterrupts.DSPsgenerallyprovideoneormoredirectmemoryaccess(DMA)controllers,thechannelsofwhichcanbeusedtobuffermultiplesamplesfromtheserialportandthentransferthefullbufferintotheon-chipmemorywithoutDSPinvolvement.TheDSPisonlyinterruptedoncethebufferisfullratherthanoneverydatasample.AfterinitialconfigurationbytheDSP,theDMAandserialportinteractwithoutanyprocessorintervention.Becauseoftheefficiencygains,driversformostDSPperipheralsuseDMA.
WritingacodecdriverforaDSPactuallyinvolvesprogrammingthreedifferentperipherals—thecodecitself,theserialport,andtheDMAcontroller.Figure1showsthedataflowbetweenthedifferentperipherals,theDSP,andtheDSP'sinternalmemory.Later,we'llshowamuchmoredetailedimplementationofaDSPcodecdriver,butfirstlet'sdiscusssomedriver-architecturalissuesthatenablebettercodereusebothattheapplicationanddriverlevels.
Figure1:
ADSPcodecdriverofteninvolvesconfiguringmorethanjustthecodec
Device-driverarchitecture
Adevicedriverperformstwomainfunctions:
∙deviceconfigurationandinitialization
∙datamovement
Deviceconfigurationis,bydefinition,specifictoaparticulardevice.Datamovement,ontheotherhand,ismoregeneric.Inthecaseofastreamingdataperipherallikeacodec,theapplicationultimatelyexpectstosendorreceiveastreamofbuffers.Theapplicationshouldn'thavetoworryabouthowthebuffersaremanagedorwhattypeofcodecisbeingused,beyondissuessuchasdataprecision(numberofbitsinthesample).
Classdrivers
Byprovidingaclearabstractionbetweenthedriverandtheapplication,youcanessentiallyfreetheapplicationofthespecificsofacertainperipheralandportitmoreeasilytonewhardware.Youcanfurtherapplytheseconceptsofabstractionandreusetothedriveritself.Anumberofdriverfunctionsareindependentoftheunderlyingdevice,suchassynchronizationbetweenthedriverandtheapplication.Youcanprovidetheseservicesinadrivermodulethat'sspecifictoaparticularclassofdevicesbutindependentofanyindividualdevice.Suchamoduleisoftenreferredtoasthe"upperhalf"ofadriver.Forconvenience,we'llusethetermclassdrivertodescribethismodule.
AsFigure2illustrates,anydrivercanbedividedintotwoparts:
aclassdriverthathandlestheapplicationinterfaceandOS-specificsandamini-driverthataddressesthehardwarespecificsofaparticulardevice.
Figure2:
Anydrivercanbedividedintotwoparts:
aclassdriverandamini-driver
BecauseoflargedifferencesbetweendeviceslikecodecsandUARTs,you'lltypicallyneedtoimplementseveralclassdriverstosupportalltheperipheralsusedwithaDSP.WhendesigningthedrivermodelforDSP/BIOS,twooftheclassdriversweimplementedwere:
∙AnSIOclassdriverforframe-orientedstreamingdevicessuchascodecsanddataconvertersthattransmitfixed-sizedframesofdata.
∙AGIOclassdriverprovidesbasicread/writeoperationsfordevicessuchasUARTs.
Ascanbeseenfromthesedefinitions,theclassdriversdefinetheI/Omodelsusedbytheapplication.Sincetheclassdriverisresponsibleforsynchronizationbetweentheapplicationanddriver,itwilldeterminewhethertheI/Oissynchronous(wheretheapplicationthreadblocksonanI/Otransactionsothatanotherthreadcanrun)orasynchronous(wheretheapplicationthreadcontinuestorunandreliesonanotificationmechanismthatwillinformtheapplicationwhentheI/Otransactioniscomplete).Althoughclassdriversaredevice-independent,they'reintimatelyassociatedwiththeoperatingsystemsincetheyuseoperatingsystemservices,suchassemaphores.
Mini-drivers
Thespecificsofaperipheralareaddressedinthelowerhalfofthedriver,forwhichwe'llusethetermmini-driver.Themini-driverisresponsibleforalldevice-specificinitializationandcontrolandforpassingabufferofdatato(orreceivingabufferfrom)theclassdriver.Themini-drivermustdefineastandardinterfacetotheclassdriversinceitenablesaclassdrivertoworkwithmultiplemini-driversorviceversa.Forexample,inasystemwithmultiplecodecsofdifferenttypes,youcansavecodespacebyhavingjustoneinstanceoftheclassdrivercodeworkwithallthedifferentcodecmini-drivers.
Themostdevice-specificroutinesarethosethatinitializedevicecontrolregisters.Theseoperationsrequirethecalculationofspecificbitpatternstosettheappropriateflagvaluesineachcontrolregister.Althoughthedeviceinitializationroutineswillneverbeportable,implementationandmaintenancecanbemademuchsimplerbythedevelopmentofabasichardwareabstractionlayer(HAL)forthedeviceregisters.
Example:
Codecdriver
ToillustratethisDSPdevice-driverarchitecture,let'slookatanexamplethatrevealsthedesigndecisionsandimplementationoftheclassdriverandthemini-driver.We'llusethecodecdevicedriverforTexasInstruments'TMS320C5402DSPstarterkitboard.ThecodeissimilartootherDSP/codeccombinations,soyoucanadaptitasnecessary.
ToavoidgettinglostintheDMAsetupcode,we'lldemonstratesomeofthedriverconceptsusingasimplesample-by-sampleaudiocodecdriverthatprocessessamplesonceperinterrupt.Thistypeofdriverissomewhatsimplisticbecauseyou'dalmostalwaysuseaDMAtoenabletheDSPtoprocessonframesofdataratherthanhavingtoserviceaninterruptforeverydatapoint.
Thecodec'sclassdriver
OurexampleusestheSIOclassdriver.Likemostsoftwaremodules,thebestwaytounderstandtheSIOclassdriveristolookatsomeactualcode.Theexample,showninListing1,simplyreadssounddatafromtheaudiocodecdevicedriver,copiesthedatatoanotherbuffer,andthentransmitsitbackouttothecodecsothatitcanbeheardthroughaspeaker.
Listing1:
Applicationstartup
voidmain()
{
void*buf0,buf1,buf2,buf3;
/*
*AllocatebuffersfortheSIObufferexchange
*/
buf0=(void*)MEM_calloc(0,BUFSIZE,BUFALIGN);
buf1=(void*)MEM_calloc(0,BUFSIZE,BUFALIGN);
buf2=(void*)MEM_calloc(0, BUFSIZE,BUFALIGN);
buf3 = (void*) MEM_calloc(0, BUFSIZE,BUFALIGN);
/*
*CreatethetaskandopentheI/Ostreams
*/
TSK_create(echo);
inStream = SIO_create("/codec",SIO_INPUT,BUFSIZE);
outStream = SIO_create("/codec",SIO_OUTPUT,BUFSIZE);
/*
* Start the DSP/BIOS scheduler when main () exits
*/
}
Thecodestarts,asallCprogramsdo,inmain().TheapplicationusestheDSP/BIOSmemorymanagertoallocatefourbuffersfromthesystem'sheapspaceandthentwoSIOobjectsarecreatedtostreamdatatoandfromthedevicedriver.
TheapplicationusestheSIO_create()calltocreatethechannels.TheSIO_create()functionargumentsindicatesomeofthedesigndecisionstobemadewhenimplementingthisclassdriver.Forinstance,we'lldecideherethatanSIOstreamcanbeopenedforeitherreadingorwriting,butnotboth.Ifbidirectionalcommunicationisrequired,theapplicationsimplyopenstwochannels(asinthisexample).Thisunidirectionalchannelimplementationismoreefficient,andmanydataconvertersoperateinonlyonedirection.
Inaddition,becausemostcodecsoperateonfixed-sized
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- How to write DSP device drivers