新闻中心

必威体育手机端ProgrammingwithNanoJ

作者:必威体育手机端   |   时间:2020-04-01 23:51   |   浏览:152   

必威体育手机端ANanoJprogrammakesaprotectedruntimeenvironmentavailablewithinthefirmware.Here,theusercancreatehisownprocesses.Thesecanthentriggerfunctionsinthecontrollerby,forexample,readingorwritingentriesintheobjectdictionary.Throughtheuseofprotectivemechanisms,aNanoJprogramispreventedfromcrashingthefirmware.Intheworstcase,theexecutionisinterruptedwithanerrorcodestoredintheobjectdictionary.IftheNanoJprogramwasloadedonthecontroller,itisautomaticallyexecutedafterthecontrollerisswitchedonorrestarted.

ANanoJprogramreceivescomputingtimecyclicallyina1msclock(seefollowingfigure).Becausecomputingtimeislostthroughinterruptsandsystemfunctionsofthefirmware,onlyapprox.30%–50%ofcomputingtimeisavailabletotheuserprogram(dependingonoperatingmodeandapplication).Inthistime,theuserprogrammustrunthroughthecycleandeithercompletethecycleoryieldthecomputingtimebycallingtheyield()function.Intheformercase,theuserprogramisrestartedwiththestartofthenext1mscycle;thelatterresultsintheprogrambeingcontinuedonthenext1mscyclewiththecommandthatfollowstheyield()function.

Whendevelopinguserprograms,theruntimebehaviormustbecarefullyexamined,especiallyformoretime-intensivetasks.Forexample,itisthereforerecommendedthattablesbeusedinsteadofcalculatingasinevalueusingasinfunction.

IftheNanoJprogramdoesnotyieldthecomputingtimeaftertoolongatime,itisendedbytheoperatingsystem.Inthiscase,thenumber4isenteredinthestatuswordforobject2301h;intheerrorregisterforobject2302h,thenumber5(timeout)isnoted,see2301hNanoJStatusand2302hNanoJErrorCode.

Usingprocessor-specificfeatures,aso-calledsandboxisgenerated.Whenusedinthesandbox,auserprogramcanonlyaccessspeciallyassignedmemoryareasandsystemresources.Forexample,anattempttodirectlywritetoaprocessorIOregisterisacknowledgedwithanMPUFaultandtheuserprogramterminatedwiththecorrespondingerrorcodeintheobjectdictionary.

TheODvaluesoftheuserprogramaremadeavailableintheformofvariablesviaPDOmapping.Beforeauserprogramreceivesthe1mstimeslot,thefirmwaretransfersthevaluesfromtheobjectdictionarytothevariablesoftheuserprogram.Assoonastheuserprogramreceivescomputingtime,itcanmanipulatethesevariablesasregularCvariables.Attheendofthetimeslot,thenewvaluesarethenautomaticallycopiedbythefirmwarebacktotherespectiveODentries.Tooptimizetheperformance,threetypesofmappingaredefined:input,output,andinput/output(In,Out,InOut).

ThesetmappingscanbereadandcheckedviatheGUIforobjects2310h,2320h,and2330h.Upto16entriesareallowedforeachmapping.Whetheravariableisstoredintheinput,outputordatarangeiscontrolledinNanoJEasyviathespecificationofthelinkersection

必威体育手机端Whenexecutingacycle,theNanoJprogramessentiallyconsistsofthefollowingthreestepswithrespecttothePDOmapping:

TheconfigurationofthecopyprocessesisbasedontheCANopenstandard.Inaddition,valuesoftheobjectdictionarycanbeaccessedviasystemcalls.Thisisgenerallyslower;mappingsarethereforetobepreferred.Thenumberofmappingsislimited(16entrieseachinIn/Out/InOut).

Nanotecrecommends:MapODentriesthatareusedandchangedfrequentlyandusesystemcallstoaccessODentriesthatareusedlessfrequently.

NanotecrecommendsaccessingagivenODvalueeitherbymappingorusingasystemcallwithod_write().Ifbothareusedsimultaneously,thesystemcallhasnoeffect.

Example:TostarttheTEST1.USRuserprogram,thefollowingsequencecan,forexample,beused:•Checkentry2302hforerrorcode.•Ifnoerror:StarttheNanoJprogrambywritingobject2300h,bit0="1".

DuetolimitationsintheUSBimplementation,file"VMMCODE.USR"is,followingarestartofthecontroller,settoasizeof16kBandthecreationdatesetto13.03.2012.

Thefilenamesoftheuserprogramsmustnotbelongerthaneightcharactersplusthreecharactersinthesuffix;filenamemain.cppispermissible,filenameaLongFileName.cppisnotpermissible

 Withthismethod,avariableintheNanoJprogramislinkeddirectlywithanentryintheobjectdictionary.Thecreationofthemappingmustbelocatedatthestartofthefilehere,evenbeforethe#include"wrapper.h"instruction.Acommentispermittedabovethemapping.

•Usemappingifyouneedtoaccessanobjectintheobjectdictionaryfrequently,e.g.,controlword6040horstatusword6041h.

•Theod_write()andod_read()functionsarebettersuitedforaccessingobjectsasingletime,seeAccessingtheobjectdictionary.

•<TYPEThedatatypeofthevariable;U32,U16,U08,S32,S16orS08.•<NAMEThenameofthevariableasitisusedintheuserprogram.•<input|output|inoutThereadandwritepermissionofavariable:avariablecanbedeclaredasaninput,outputorinout.Thisdefineswhetheravariableisreadable(input),writable(output)orboth(inout)andthestructurebymeansofwhichitmustbeaddressedintheprogram.•<INDEX:<SUBINDEXIndexandsubindexoftheobjecttobemappedintheobjectdictionary.

Eachdeclaredvariableisaddressedintheuserprogramviaoneofthethreestructures:In,OutorInOutdependingonthedefinedwriteandreaddirection.

Apossiblesourceoferrorsisawriteaccesswiththeod_write()function(seeSystemcallsinaNanoJprogram)ofanobjectintheobjectdictionarythatwassimultaneouslycreatedasmapping.Thecodelistedinthefollowingisincorrect:

Thelinewiththeod_write(0x6040,0x00,5);commandhasnoeffect.Asdescribedintheintroduction,allmappingsarecopiedtotheobjectdictionaryattheendofeachmillisecond.Thisresultsinthefollowingsequence:1.Theod_writefunctionwritesthevalue5inobject6040h:00h.2.Attheendofthe1mscycle,themappingiswrittenthatalsospecifiesobject6040h:00h,however,withthevalue1.3.Fromtheperspectiveoftheuser,theod_writecommandthusservesnopurpose.

Withsystemcalls,itispossibletocallupfunctionsintegratedinthefirmwaredirectlyfromauserprogram.Becausedirectcodeexecutionisonlypossibleintheprotectedareaofthesandbox,thisisimplementedviaso-calledCortex-Supervisor-Calls(SvcCalls).Aninterruptistriggeredwhenthefunctioniscalled.Thefirmwarethushasthepossibilityoftemporarilyallowingcodeexecutionoutsideofthesandbox.Developersofuserprogramsdonotneedtoworryaboutthismechanism–forthem,thesystemcallscanbecalleduplikenormalCfunctions.Onlythewrapper.hfileneedstobeintegratedasusual.

voidod_write(U32index,U32subindex,U32value)Thisfunctionwritesthetransferredvaluetothespecifiedlocationintheobjectdictionary.indexIndexoftheobjecttobewrittenintheobjectdictionarysubindexSubindexoftheobjecttobewrittenintheobjectdictionaryvalueValuetobewrittenNote

Itishighlyrecommendedthattheprocessortimebepassedonwithyield()aftercallingaod_write().ThevalueisimmediatelywrittentotheOD.Forthefirmwaretobeabletotriggeractionsthataredependentonthis,however,itmustreceivecomputingtime.This,inturn,meansthattheuserprogrammusteitherbeendedorinterruptedwithyield().

Thisfunctionreturnstheprocessortimetotheoperatingsystem.Inthenexttimeslot,theprogramcontinuesatthelocationafterthecall.

voidsleep(U32ms)Thisfunctionreturnstheprocessortimetotheoperatingsystemforthespecifiednumberofmilliseconds.Theuserprogramisthencontinuedatthelocationafterthecall.