rtt.patch 603 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373
  1. From 3d7fabf23eeae26b7d739fbb649090aa590dcf3b Mon Sep 17 00:00:00 2001
  2. From: supperthomas <78900636@qq.com>
  3. Date: Fri, 6 May 2022 23:06:28 +0800
  4. Subject: [PATCH 1/4] add the config of RTTHREAD
  5. add the init link file
  6. ---
  7. Kconfig | 4 +
  8. .../esp_system/ld/esp32c3/sections.ld.in | 26 +++
  9. components/freertos/port/port_common.c | 5 +
  10. components/freertos/port/port_systick.c | 3 +
  11. components/riscv/vectors.S | 220 ++++++++++++++++--
  12. 5 files changed, 239 insertions(+), 19 deletions(-)
  13. diff --git a/Kconfig b/Kconfig
  14. index 928d274106..d368adaa37 100644
  15. --- a/Kconfig
  16. +++ b/Kconfig
  17. @@ -61,6 +61,10 @@ mainmenu "Espressif IoT Development Framework Configuration"
  18. bool
  19. default "y" if IDF_TARGET="linux"
  20. + config IDF_RTOS_RTTHREAD
  21. + bool "RT-THREAD SELECT"
  22. + default "n"
  23. +
  24. config IDF_FIRMWARE_CHIP_ID
  25. hex
  26. default 0x0000 if IDF_TARGET_ESP32
  27. diff --git a/components/esp_system/ld/esp32c3/sections.ld.in b/components/esp_system/ld/esp32c3/sections.ld.in
  28. index 0ebeda06c1..8215237fff 100644
  29. --- a/components/esp_system/ld/esp32c3/sections.ld.in
  30. +++ b/components/esp_system/ld/esp32c3/sections.ld.in
  31. @@ -183,6 +183,32 @@ SECTIONS
  32. _noinit_end = ABSOLUTE(.);
  33. } > dram0_0_seg
  34. + .stack_dummy (COPY):
  35. + {
  36. + . = ALIGN(8);
  37. + __STACKSIZE__ = 40960;
  38. + __stack_start__ = .;
  39. + *(.stack*)
  40. + . += __STACKSIZE__;
  41. + __stack_cpu0 = .;
  42. + __stack_end__ = .;
  43. + } > dram0_0_seg
  44. +
  45. + .stack_dummy (COPY):
  46. + {
  47. + . = ALIGN(8);
  48. + __HEAPSIZE__ = 40960;
  49. + __heap_start__ = .;
  50. + . += __STACKSIZE__;
  51. + __heap_end__ = .;
  52. + /* section information for initial. */
  53. + . = ALIGN(4);
  54. + __rt_init_start = .;
  55. + KEEP(*(SORT(.rti_fn*)))
  56. + __rt_init_end = .;
  57. +
  58. + . = ALIGN(4);
  59. + } > dram0_0_seg
  60. /* Shared RAM */
  61. .dram0.bss (NOLOAD) :
  62. {
  63. diff --git a/components/freertos/port/port_common.c b/components/freertos/port/port_common.c
  64. index ffca3d5429..9d8159f588 100644
  65. --- a/components/freertos/port/port_common.c
  66. +++ b/components/freertos/port/port_common.c
  67. @@ -74,11 +74,16 @@ void esp_startup_start_app_common(void)
  68. esp_gdbstub_init();
  69. #endif // CONFIG_ESP_SYSTEM_GDBSTUB_RUNTIME
  70. +#ifdef CONFIG_IDF_RTOS_RTTHREAD
  71. + app_main();
  72. +#else
  73. portBASE_TYPE res = xTaskCreatePinnedToCore(&main_task, "main",
  74. ESP_TASK_MAIN_STACK, NULL,
  75. ESP_TASK_MAIN_PRIO, NULL, ESP_TASK_MAIN_CORE);
  76. assert(res == pdTRUE);
  77. (void)res;
  78. +#endif
  79. +
  80. }
  81. static void main_task(void* args)
  82. diff --git a/components/freertos/port/port_systick.c b/components/freertos/port/port_systick.c
  83. index 0c14a155a1..0fa203574b 100644
  84. --- a/components/freertos/port/port_systick.c
  85. +++ b/components/freertos/port/port_systick.c
  86. @@ -116,6 +116,8 @@ void vPortSetupTimer(void)
  87. */
  88. IRAM_ATTR void SysTickIsrHandler(void *arg)
  89. {
  90. +#ifdef CONFIG_IDF_RTOS_RTTHREAD
  91. +#else
  92. uint32_t cpuid = xPortGetCoreID();
  93. systimer_hal_context_t *systimer_hal = (systimer_hal_context_t *)arg;
  94. #ifdef CONFIG_PM_TRACE
  95. @@ -144,6 +146,7 @@ IRAM_ATTR void SysTickIsrHandler(void *arg)
  96. #ifdef CONFIG_PM_TRACE
  97. ESP_PM_TRACE_EXIT(TICK, cpuid);
  98. #endif
  99. +#endif
  100. }
  101. #endif // CONFIG_FREERTOS_SYSTICK_USES_CCOUNT
  102. diff --git a/components/riscv/vectors.S b/components/riscv/vectors.S
  103. index 1006d5bea5..963494fcb3 100644
  104. --- a/components/riscv/vectors.S
  105. +++ b/components/riscv/vectors.S
  106. @@ -17,6 +17,9 @@
  107. #include "soc/soc_caps.h"
  108. #include "sdkconfig.h"
  109. +#define STORE sw
  110. +#define LOAD lw
  111. +#define REGBYTES 4
  112. .equ SAVE_REGS, 32
  113. .equ CONTEXT_SIZE, (SAVE_REGS * 4)
  114. @@ -218,25 +221,27 @@ _call_panic_handler:
  115. */
  116. .global _interrupt_handler
  117. .type _interrupt_handler, @function
  118. +#ifndef CONFIG_IDF_RTOS_RTTHREAD
  119. +
  120. _interrupt_handler:
  121. /* entry */
  122. - save_regs
  123. - save_mepc
  124. + save_regs /* 保存寄存器 */
  125. + save_mepc /* 保存MEPC */
  126. /* Before doing anythig preserve the stack pointer */
  127. /* It will be saved in current TCB, if needed */
  128. - mv a0, sp
  129. + mv a0, sp /* 保存SP a0 = sp */
  130. call rtos_int_enter
  131. /* Before dispatch c handler, restore interrupt to enable nested intr */
  132. - csrr s1, mcause
  133. - csrr s2, mstatus
  134. + csrr s1, mcause /* 保存mcause s1 = mcause */
  135. + csrr s2, mstatus /* 保存mstatus s2 = mstatus */
  136. - /* Save the interrupt threshold level */
  137. - la t0, INTERRUPT_CORE0_CPU_INT_THRESH_REG
  138. - lw s3, 0(t0)
  139. + /* Save the interrupt threshold level 保存中断嵌套层数? */
  140. + la t0, INTERRUPT_CORE0_CPU_INT_THRESH_REG /* 保存mstatus t0 = &INTERRUPT_CORE0_CPU_INT_THRESH_REG */
  141. + lw s3, 0(t0) /* s3 = mstatus */
  142. - /* Increase interrupt threshold level */
  143. + /* Increase interrupt threshold level 增加中断嵌套层数*/
  144. li t2, 0x7fffffff
  145. and t1, s1, t2 /* t1 = mcause & mask */
  146. slli t1, t1, 2 /* t1 = mcause * 4 */
  147. @@ -247,8 +252,8 @@ _interrupt_handler:
  148. sw t2, 0(t0) /* INTERRUPT_CORE0_CPU_INT_THRESH_REG = t2 */
  149. fence
  150. - li t0, 0x8
  151. - csrrs t0, mstatus, t0
  152. + li t0, 0x8 /* t0 = 8 */
  153. + csrrs t0, mstatus, t0 /*设置状态MIE寄存器,开总中断*/
  154. #ifdef CONFIG_PM_TRACE
  155. li a0, 0 /* = ESP_PM_TRACE_IDLE */
  156. @@ -269,34 +274,211 @@ _interrupt_handler:
  157. /* call the C dispatcher */
  158. mv a0, sp /* argument 1, stack pointer */
  159. mv a1, s1 /* argument 2, interrupt number (mcause) */
  160. - /* mask off the interrupt flag of mcause */
  161. + /* mask off the interrupt flag of mcause 屏幕异常中断*/
  162. li t0, 0x7fffffff
  163. and a1, a1, t0
  164. jal _global_interrupt_handler
  165. - /* After dispatch c handler, disable interrupt to make freertos make context switch */
  166. + /* After dispatch c handler, disable interrupt to make freertos make context switch
  167. + 在调用c函数之后,disable 中断让freertos能够做内容切换
  168. + */
  169. li t0, 0x8
  170. - csrrc t0, mstatus, t0
  171. + csrrc t0, mstatus, t0 /*清状态MIE寄存器 关总中断*/
  172. - /* restore the interrupt threshold level */
  173. +
  174. + /* restore the interrupt threshold level 中断嵌套 */
  175. la t0, INTERRUPT_CORE0_CPU_INT_THRESH_REG
  176. sw s3, 0(t0)
  177. fence
  178. /* Yield to the next task is needed: */
  179. - mv a0, sp
  180. + mv a0, sp /* a0 = sp*/
  181. call rtos_int_exit
  182. /* The next (or current) stack pointer is returned in a0 */
  183. - mv sp, a0
  184. + mv sp, a0 /* sp = a0*/
  185. /* restore the rest of the registers */
  186. - csrw mcause, s1
  187. - csrw mstatus, s2
  188. + csrw mcause, s1 /* mcause = s1 */
  189. + csrw mstatus, s2 /* mstatus = s2 */
  190. restore_mepc
  191. restore_regs
  192. /* exit, this will also re-enable the interrupts */
  193. mret
  194. .size _interrupt_handler, .-_interrupt_handler
  195. +#else
  196. +_interrupt_handler:
  197. + /* 此时CPU的sp = from_thread->sp */
  198. + /* 注意: 在这里,并没有将mepc的值赋值为from_thread栈中的epc,但后面会赋值 */
  199. + addi sp, sp, -32 * REGBYTES /* sp = sp - 32 * 4 栈指针向下偏移32个寄存器长度,用来将CPU的寄存器保存到from_thread的栈中*/
  200. + STORE x1, 1 * REGBYTES(sp) /* 将CPU的x1寄存器,即ra寄存器,保存到from_thread->栈中 */
  201. +
  202. + li t0, 0x80 /* t0 = 0x80 */
  203. + STORE t0, 2 * REGBYTES(sp) /* mstatus = t0, 即关闭全局中断 */
  204. +
  205. + /* 将 CPU 的其他寄存器的值,保存到from_thread的任务栈中 */
  206. + STORE x4, 4 * REGBYTES(sp)
  207. + STORE x5, 5 * REGBYTES(sp)
  208. + STORE x6, 6 * REGBYTES(sp)
  209. + STORE x7, 7 * REGBYTES(sp)
  210. + STORE x8, 8 * REGBYTES(sp)
  211. + STORE x9, 9 * REGBYTES(sp)
  212. + STORE x10, 10 * REGBYTES(sp)
  213. + STORE x11, 11 * REGBYTES(sp)
  214. + STORE x12, 12 * REGBYTES(sp)
  215. + STORE x13, 13 * REGBYTES(sp)
  216. + STORE x14, 14 * REGBYTES(sp)
  217. + STORE x15, 15 * REGBYTES(sp)
  218. + STORE x16, 16 * REGBYTES(sp)
  219. + STORE x17, 17 * REGBYTES(sp)
  220. + STORE x18, 18 * REGBYTES(sp)
  221. + STORE x19, 19 * REGBYTES(sp)
  222. + STORE x20, 20 * REGBYTES(sp)
  223. + STORE x21, 21 * REGBYTES(sp)
  224. + STORE x22, 22 * REGBYTES(sp)
  225. + STORE x23, 23 * REGBYTES(sp)
  226. + STORE x24, 24 * REGBYTES(sp)
  227. + STORE x25, 25 * REGBYTES(sp)
  228. + STORE x26, 26 * REGBYTES(sp)
  229. + STORE x27, 27 * REGBYTES(sp)
  230. + STORE x28, 28 * REGBYTES(sp)
  231. + STORE x29, 29 * REGBYTES(sp)
  232. + STORE x30, 30 * REGBYTES(sp)
  233. + STORE x31, 31 * REGBYTES(sp)
  234. +
  235. + /* 备份 CPU 的 sp (这时,CPU的sp其实就是from thread的sp指针) 寄存器的值到 s0 寄存器中,下面会使用s0,恢复 CPU 的寄存器 */
  236. + move s0, sp /* s0 = sp */
  237. +
  238. + /* 在中断函数中,中断函数中调用的C函数,需要使用 sp, 这里,在中断函数中,使用的 sp 为,系统的栈资源 */
  239. + /* switch to interrupt stack */
  240. + la sp, __stack_end__ /* sp = _sp */
  241. +
  242. + /* interrupt handle */
  243. + /* 注意: 在调用C函数之前,比如sp的值为0x30001000, 在执行完C函数后,sp的值还是会变成 0x30001000 */
  244. + call rt_interrupt_enter /* 执行所有的中断函数前,调用该函数 */
  245. +
  246. + csrr s1, mcause
  247. + csrr s2, mstatus
  248. +
  249. + /* Save the interrupt threshold level */
  250. + la t0, INTERRUPT_CORE0_CPU_INT_THRESH_REG
  251. + lw s3, 0(t0)
  252. +
  253. + li t2, 0x7fffffff
  254. + and t1, s1, t2 /* t1 = mcause & mask */
  255. + slli t1, t1, 2 /* t1 = mcause * 4 */
  256. + la t2, INTC_INT_PRIO_REG(0)
  257. + add t1, t2, t1 /* t1 = INTC_INT_PRIO_REG + 4 * mcause */
  258. + lw t2, 0(t1) /* t2 = INTC_INT_PRIO_REG[mcause] */
  259. + addi t2, t2, 1 /* t2 = t2 +1 */
  260. + sw t2, 0(t0) /* INTERRUPT_CORE0_CPU_INT_THRESH_REG = t2 */
  261. + fence
  262. +
  263. + li t0, 0x8
  264. + csrrs t0, mstatus, t0
  265. +
  266. + /* call the C dispatcher */
  267. + mv a0, sp /* argument 1, stack pointer */
  268. + mv a1, s1 /* argument 2, interrupt number (mcause) */
  269. + /* mask off the interrupt flag of mcause */
  270. + li t0, 0x7fffffff
  271. + and a1, a1, t0
  272. + jal _global_interrupt_handler
  273. +
  274. + li t0, 0x8
  275. + csrrc t0, mstatus, t0
  276. +
  277. + /* restore the interrupt threshold level */
  278. + la t0, INTERRUPT_CORE0_CPU_INT_THRESH_REG
  279. + sw s3, 0(t0)
  280. + fence
  281. +
  282. + call rt_interrupt_leave /* 执行所有的中断函数后,调用该函数 */
  283. +
  284. + /* 上面,将保存执行中断服务函数之前的CPU的sp寄存器到了s0所指向的位置处,当执行完中断服务函数,需要将之前的CPU寄存器,恢复一下,此时sp又变成了from thread的sp了 */
  285. + move sp, s0 /* sp = s0 */
  286. +
  287. + /* 下面两句话,相当于将 rt_thread_switch_interrupt_flag 值,赋值给了s2 */
  288. + /* 将 rt_thread_switch_interrupt_flag 的地址值,赋值给 s0 寄存器*/
  289. + la s0, rt_thread_switch_interrupt_flag /* s0 = &rt_thread_switch_interrupt_flag */
  290. + /* 将 s0 所指向的地址处的内容,取出来,赋值给 s2 寄存器,其实就是将 rt_thread_switch_interrupt_flag 的值,赋值给了 s2 寄存器*/
  291. + lw s2, 0(s0) /* s2 = *s0 = rt_thread_switch_interrupt_flag */
  292. +
  293. + /* 如果 s2的值,即 rt_thread_switch_interrupt_flag 值,如果不为0,则需要继续执行下一条指令,如果为0,则需要跳转到 spurious_interrupt 标号处 执行 */
  294. + /* 如果 s2的值等于0,rt_thread_switch_interrupt_flag等于0, 则不需要在中断处理函数中,进行上下文切换,反之则需要 */
  295. + /* 如果不需要上下文切换, */
  296. +
  297. + /* 在这里,跳转到 spurious_interrupt的话,是不会进行上下文切换的,因为,此时CPU的sp指针还是from线程的*/
  298. + beqz s2, spurious_interrupt /* if (s2 == 0) goto spurious_interrupt; else 执行下一条语句*/
  299. +
  300. + /* 需要上下文切换: 主要目的是将CPU的sp指针,赋值为to_thread的sp */
  301. +
  302. + /* 将 s0 所执向的地址的内容设置为0, 也就是,将变量 rt_thread_switch_interrupt_flag 赋值为了 0 */
  303. + /* s0存放的值是 rt_thread_switch_interrupt_flag 变量的地址*/
  304. + sw zero, 0(s0) /* *s0 = 0; 也就是 rt_thread_switch_interrupt_flag = 0 */
  305. + /* 将 mepc 的值,赋值给 a0 寄存器,mepc 的值是,跳转到中断函数执行之前的 PC 指针 */
  306. + /* 这时的mpec其实,还是from线程,在跳转到中断执行前的一个PC地址 */
  307. + csrr a0, mepc /* a0 = mepc */
  308. +
  309. + /* 将 mpec 的值写回到freom thread任务栈中的 epc 中,待后续,恢复from线程时,使用 */
  310. + STORE a0, 0 * REGBYTES(sp) /* from_thread->sp->epc = a0 ,中断入口处*/
  311. +
  312. + /* 将from_thread的sp指针,赋值为CPU的sp指针 */
  313. + la s0, rt_interrupt_from_thread /* s0 = &rt_interrupt_from_thread 注意: rt_interrupt_from_thread = &(from_thread->sp) */
  314. + LOAD s1, 0(s0) /* s1 = rt_interrupt_from_thread,也就是s1 = &(from_thread->sp) */
  315. + STORE sp, 0(s1) /* from_thread->sp = sp*/
  316. +
  317. + /* 接下来,需要开始恢复CPU的sp为to_thread的sp了 */
  318. + la s0, rt_interrupt_to_thread /* s0 = &rt_interrupt_to_thread 注意: rt_interrupt_to_thread = &(to_thred->sp)*/
  319. + LOAD s1, 0(s0) /* s1 = rt_interrupt_to_thread, 也就是s1 = &(to_thred->sp) */
  320. + LOAD sp, 0(s1) /* sp = (to_thred->sp)*/
  321. +
  322. + /* 将CPU的 mepc设置为to_thred的mepc,待中断退出,执行mret指令后,将从该地址开始执行 */
  323. + LOAD a0, 0 * REGBYTES(sp) /* a0 = to_thread的mepc的值*/
  324. + csrw mepc, a0 /* mepc = a0 */
  325. +
  326. +
  327. +spurious_interrupt:
  328. + LOAD x1, 1 * REGBYTES(sp)
  329. +
  330. + /* Remain in M-mode after mret */
  331. + li t0, 0x00001800
  332. + csrs mstatus, t0
  333. + LOAD t0, 2 * REGBYTES(sp)
  334. + csrs mstatus, t0
  335. +
  336. + LOAD x4, 4 * REGBYTES(sp)
  337. + LOAD x5, 5 * REGBYTES(sp)
  338. + LOAD x6, 6 * REGBYTES(sp)
  339. + LOAD x7, 7 * REGBYTES(sp)
  340. + LOAD x8, 8 * REGBYTES(sp)
  341. + LOAD x9, 9 * REGBYTES(sp)
  342. + LOAD x10, 10 * REGBYTES(sp)
  343. + LOAD x11, 11 * REGBYTES(sp)
  344. + LOAD x12, 12 * REGBYTES(sp)
  345. + LOAD x13, 13 * REGBYTES(sp)
  346. + LOAD x14, 14 * REGBYTES(sp)
  347. + LOAD x15, 15 * REGBYTES(sp)
  348. + LOAD x16, 16 * REGBYTES(sp)
  349. + LOAD x17, 17 * REGBYTES(sp)
  350. + LOAD x18, 18 * REGBYTES(sp)
  351. + LOAD x19, 19 * REGBYTES(sp)
  352. + LOAD x20, 20 * REGBYTES(sp)
  353. + LOAD x21, 21 * REGBYTES(sp)
  354. + LOAD x22, 22 * REGBYTES(sp)
  355. + LOAD x23, 23 * REGBYTES(sp)
  356. + LOAD x24, 24 * REGBYTES(sp)
  357. + LOAD x25, 25 * REGBYTES(sp)
  358. + LOAD x26, 26 * REGBYTES(sp)
  359. + LOAD x27, 27 * REGBYTES(sp)
  360. + LOAD x28, 28 * REGBYTES(sp)
  361. + LOAD x29, 29 * REGBYTES(sp)
  362. + LOAD x30, 30 * REGBYTES(sp)
  363. + LOAD x31, 31 * REGBYTES(sp)
  364. +
  365. + addi sp, sp, 32 * REGBYTES
  366. + mret
  367. + .size _interrupt_handler, .-_interrupt_handler
  368. +#endif
  369. --
  370. 2.32.0 (Apple Git-132)
  371. From d0d1f625543282df462af56cc18abaa5a47d4f40 Mon Sep 17 00:00:00 2001
  372. From: supperthomas <78900636@qq.com>
  373. Date: Sat, 9 Jul 2022 21:37:53 +0800
  374. Subject: [PATCH 2/4] remove submodule
  375. remove submodule
  376. ---
  377. .gitmodules | 111 ----------------------------------------------------
  378. 1 file changed, 111 deletions(-)
  379. diff --git a/.gitmodules b/.gitmodules
  380. index 49edc68e10..8b13789179 100644
  381. --- a/.gitmodules
  382. +++ b/.gitmodules
  383. @@ -1,112 +1 @@
  384. -#
  385. -# All the relative URL paths are intended to be GitHub ones
  386. -# For Espressif's public projects please use '../../espressif/proj', not a '../proj'
  387. -#
  388. -[submodule "components/esptool_py/esptool"]
  389. - path = components/esptool_py/esptool
  390. - url = ../../espressif/esptool.git
  391. -
  392. -[submodule "components/bt/controller/lib_esp32"]
  393. - path = components/bt/controller/lib_esp32
  394. - url = ../../espressif/esp32-bt-lib.git
  395. -
  396. -[submodule "components/bootloader/subproject/components/micro-ecc/micro-ecc"]
  397. - path = components/bootloader/subproject/components/micro-ecc/micro-ecc
  398. - url = ../../kmackay/micro-ecc.git
  399. -
  400. -[submodule "components/coap/libcoap"]
  401. - path = components/coap/libcoap
  402. - url = ../../obgm/libcoap.git
  403. -
  404. -[submodule "components/nghttp/nghttp2"]
  405. - path = components/nghttp/nghttp2
  406. - url = ../../nghttp2/nghttp2.git
  407. -
  408. -[submodule "components/libsodium/libsodium"]
  409. - path = components/libsodium/libsodium
  410. - url = ../../jedisct1/libsodium.git
  411. -
  412. -[submodule "components/spiffs/spiffs"]
  413. - path = components/spiffs/spiffs
  414. - url = ../../pellepl/spiffs.git
  415. -
  416. -[submodule "components/json/cJSON"]
  417. - path = components/json/cJSON
  418. - url = ../../DaveGamble/cJSON.git
  419. -
  420. -[submodule "components/mbedtls/mbedtls"]
  421. - path = components/mbedtls/mbedtls
  422. - url = ../../espressif/mbedtls.git
  423. -
  424. -[submodule "components/asio/asio"]
  425. - path = components/asio/asio
  426. - url = ../../espressif/asio.git
  427. -
  428. -[submodule "components/expat/expat"]
  429. - path = components/expat/expat
  430. - url = ../../libexpat/libexpat.git
  431. -
  432. -[submodule "components/lwip/lwip"]
  433. - path = components/lwip/lwip
  434. - url = ../../espressif/esp-lwip.git
  435. -
  436. -[submodule "components/mqtt/esp-mqtt"]
  437. - path = components/mqtt/esp-mqtt
  438. - url = ../../espressif/esp-mqtt.git
  439. -
  440. -[submodule "components/protobuf-c/protobuf-c"]
  441. - path = components/protobuf-c/protobuf-c
  442. - url = ../../protobuf-c/protobuf-c.git
  443. -
  444. -[submodule "components/unity/unity"]
  445. - path = components/unity/unity
  446. - url = ../../ThrowTheSwitch/Unity.git
  447. -
  448. -[submodule "examples/build_system/cmake/import_lib/main/lib/tinyxml2"]
  449. - path = examples/build_system/cmake/import_lib/main/lib/tinyxml2
  450. - url = ../../leethomason/tinyxml2.git
  451. -
  452. -[submodule "components/bt/host/nimble/nimble"]
  453. - path = components/bt/host/nimble/nimble
  454. - url = ../../espressif/esp-nimble.git
  455. -
  456. -[submodule "components/cbor/tinycbor"]
  457. - path = components/cbor/tinycbor
  458. - url = ../../intel/tinycbor.git
  459. -
  460. -[submodule "components/esp_wifi/lib"]
  461. - path = components/esp_wifi/lib
  462. - url = ../../espressif/esp32-wifi-lib.git
  463. -
  464. -[submodule "components/tinyusb/tinyusb"]
  465. - path = components/tinyusb/tinyusb
  466. - url = ../../espressif/tinyusb.git
  467. -
  468. -[submodule "examples/peripherals/secure_element/atecc608_ecdsa/components/esp-cryptoauthlib"]
  469. - path = examples/peripherals/secure_element/atecc608_ecdsa/components/esp-cryptoauthlib
  470. - url = ../../espressif/esp-cryptoauthlib.git
  471. -
  472. -[submodule "components/cmock/CMock"]
  473. - path = components/cmock/CMock
  474. - url = ../../ThrowTheSwitch/CMock.git
  475. -
  476. -[submodule "components/openthread/openthread"]
  477. - path = components/openthread/openthread
  478. - url = ../../espressif/openthread.git
  479. -
  480. -[submodule "components/bt/controller/lib_esp32c3_family"]
  481. - path = components/bt/controller/lib_esp32c3_family
  482. - url = ../../espressif/esp32c3-bt-lib.git
  483. -
  484. -[submodule "components/esp_phy/lib"]
  485. - path = components/esp_phy/lib
  486. - url = ../../espressif/esp-phy-lib.git
  487. -
  488. -[submodule "components/openthread/lib"]
  489. - path = components/openthread/lib
  490. - url = ../../espressif/esp-thread-lib.git
  491. -
  492. -[submodule "components/ieee802154/lib"]
  493. - path = components/ieee802154/lib
  494. - url = ../../espressif/esp-ieee802154-lib.git
  495. --
  496. 2.32.0 (Apple Git-132)
  497. From 29b9d1ebe7fe1c817428b856e208561ae0dc574b Mon Sep 17 00:00:00 2001
  498. From: tangzz98 <tangz98@outlook.com>
  499. Date: Sat, 30 Jul 2022 15:08:12 +0800
  500. Subject: [PATCH 3/4] Add FreeRTOS wrapper
  501. ---
  502. .../include/esp_serial_slave_link/essl.h | 2 +-
  503. .../port/arch/riscv/expression_with_stack.c | 6 +
  504. components/esp_system/startup.c | 12 +
  505. components/freertos/CMakeLists.txt | 73 +-
  506. .../FreeRTOS/esp_additions/task_snapshot.c | 212 ++
  507. .../FreeRTOS/event_groups.c | 225 ++
  508. .../FreeRTOS/freertos_v8_compat.c | 33 +
  509. .../esp_additions/freertos/FreeRTOSConfig.h | 326 +++
  510. .../esp_additions/freertos/task_snapshot.h | 90 +
  511. .../FreeRTOS/include/freertos/FreeRTOS.h | 1198 +++++++++
  512. .../FreeRTOS/include/freertos/event_groups.h | 621 +++++
  513. .../FreeRTOS/include/freertos/list.h | 416 +++
  514. .../FreeRTOS/include/freertos/portable.h | 141 +
  515. .../FreeRTOS/include/freertos/projdefs.h | 64 +
  516. .../FreeRTOS/include/freertos/queue.h | 1188 +++++++++
  517. .../FreeRTOS/include/freertos/semphr.h | 1188 +++++++++
  518. .../FreeRTOS/include/freertos/task.h | 2265 +++++++++++++++++
  519. .../FreeRTOS/include/freertos/timers.h | 1185 +++++++++
  520. .../FreeRTOS/list.c | 213 ++
  521. .../FreeRTOS/port/MemMang/heap_1.c | 145 ++
  522. .../FreeRTOS/port/MemMang/heap_2.c | 277 ++
  523. .../FreeRTOS/port/MemMang/heap_3.c | 78 +
  524. .../FreeRTOS/port/MemMang/heap_4.c | 447 ++++
  525. .../FreeRTOS/port/MemMang/heap_5.c | 506 ++++
  526. .../FreeRTOS/port/port_common.c | 203 ++
  527. .../include/freertos/FreeRTOSConfig_arch.h | 105 +
  528. .../rt-thread/include/freertos/portmacro.h | 107 +
  529. .../include/freertos/portmacro_deprecated.h | 94 +
  530. .../include/freertos/portmacro_esp32c3.h | 424 +++
  531. .../FreeRTOS/port/rt-thread/port.c | 44 +
  532. .../FreeRTOS/port/rt-thread/port_esp32c3.c | 197 ++
  533. .../FreeRTOS/queue.c | 787 ++++++
  534. .../FreeRTOS/tasks.c | 1254 +++++++++
  535. .../FreeRTOS/timers.c | 328 +++
  536. .../RT-Thread-wrapper-of-FreeRTOS/readme.md | 3 +
  537. 35 files changed, 14436 insertions(+), 21 deletions(-)
  538. create mode 100644 components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/esp_additions/task_snapshot.c
  539. create mode 100644 components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/event_groups.c
  540. create mode 100644 components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/freertos_v8_compat.c
  541. create mode 100644 components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/include/esp_additions/freertos/FreeRTOSConfig.h
  542. create mode 100644 components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/include/esp_additions/freertos/task_snapshot.h
  543. create mode 100644 components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/include/freertos/FreeRTOS.h
  544. create mode 100644 components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/include/freertos/event_groups.h
  545. create mode 100644 components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/include/freertos/list.h
  546. create mode 100644 components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/include/freertos/portable.h
  547. create mode 100644 components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/include/freertos/projdefs.h
  548. create mode 100644 components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/include/freertos/queue.h
  549. create mode 100644 components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/include/freertos/semphr.h
  550. create mode 100644 components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/include/freertos/task.h
  551. create mode 100644 components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/include/freertos/timers.h
  552. create mode 100644 components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/list.c
  553. create mode 100644 components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/port/MemMang/heap_1.c
  554. create mode 100644 components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/port/MemMang/heap_2.c
  555. create mode 100644 components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/port/MemMang/heap_3.c
  556. create mode 100644 components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/port/MemMang/heap_4.c
  557. create mode 100644 components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/port/MemMang/heap_5.c
  558. create mode 100644 components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/port/port_common.c
  559. create mode 100644 components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/port/rt-thread/include/freertos/FreeRTOSConfig_arch.h
  560. create mode 100644 components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/port/rt-thread/include/freertos/portmacro.h
  561. create mode 100644 components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/port/rt-thread/include/freertos/portmacro_deprecated.h
  562. create mode 100644 components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/port/rt-thread/include/freertos/portmacro_esp32c3.h
  563. create mode 100644 components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/port/rt-thread/port.c
  564. create mode 100644 components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/port/rt-thread/port_esp32c3.c
  565. create mode 100644 components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/queue.c
  566. create mode 100644 components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/tasks.c
  567. create mode 100644 components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/timers.c
  568. create mode 100644 components/freertos/RT-Thread-wrapper-of-FreeRTOS/readme.md
  569. diff --git a/components/esp_serial_slave_link/include/esp_serial_slave_link/essl.h b/components/esp_serial_slave_link/include/esp_serial_slave_link/essl.h
  570. index f03274a401..e9bc4939c0 100644
  571. --- a/components/esp_serial_slave_link/include/esp_serial_slave_link/essl.h
  572. +++ b/components/esp_serial_slave_link/include/esp_serial_slave_link/essl.h
  573. @@ -160,7 +160,7 @@ esp_err_t essl_read_reg(essl_handle_t handle, uint8_t add, uint8_t *value_o, uin
  574. * - ESP_ERR_NOT_SUPPORTED: Current device does not support this function.
  575. * - ESP_ERR_TIMEOUT: No interrupts before timeout.
  576. */
  577. -esp_err_t essl_wait_int(essl_handle_t handle, uint32_t wait_ms);
  578. +esp_err_t essl_wait_int(essl_handle_t handle, TickType_t wait_ms);
  579. /** Clear interrupt bits of ESSL slave. All the bits set in the mask will be cleared, while other bits will stay the same.
  580. *
  581. diff --git a/components/esp_system/port/arch/riscv/expression_with_stack.c b/components/esp_system/port/arch/riscv/expression_with_stack.c
  582. index 07d22bf3aa..64c1e0689d 100644
  583. --- a/components/esp_system/port/arch/riscv/expression_with_stack.c
  584. +++ b/components/esp_system/port/arch/riscv/expression_with_stack.c
  585. @@ -18,6 +18,7 @@
  586. #include "freertos/FreeRTOS.h"
  587. #include "freertos/portmacro.h"
  588. +#if !defined CONFIG_IDF_RTOS_RTTHREAD
  589. static portMUX_TYPE shared_stack_spinlock = portMUX_INITIALIZER_UNLOCKED;
  590. static void *current_task_stack = NULL;
  591. @@ -45,10 +46,12 @@ static StackType_t *esp_switch_stack_setup(StackType_t *stack, size_t stack_size
  592. #endif
  593. return ((StackType_t *)adjusted_top_of_stack);
  594. }
  595. +#endif
  596. void esp_execute_shared_stack_function(SemaphoreHandle_t lock, void *stack, size_t stack_size, shared_stack_function function)
  597. {
  598. +#if !defined CONFIG_IDF_RTOS_RTTHREAD
  599. assert(lock);
  600. assert(stack);
  601. assert(stack_size > 0 && stack_size >= CONFIG_ESP_MINIMAL_SHARED_STACK_SIZE);
  602. @@ -70,4 +73,7 @@ void esp_execute_shared_stack_function(SemaphoreHandle_t lock, void *stack, size
  603. portEXIT_CRITICAL(&shared_stack_spinlock);
  604. xSemaphoreGive(lock);
  605. +#else
  606. + function();
  607. +#endif
  608. }
  609. diff --git a/components/esp_system/startup.c b/components/esp_system/startup.c
  610. index 139ae8b6a2..6c6acdf575 100644
  611. --- a/components/esp_system/startup.c
  612. +++ b/components/esp_system/startup.c
  613. @@ -56,6 +56,10 @@
  614. #include "esp_rom_sys.h"
  615. +#if CONFIG_IDF_RTOS_RTTHREAD
  616. +#include "rtthread.h"
  617. +#endif
  618. +
  619. // [refactor-todo] make this file completely target-independent
  620. #if CONFIG_IDF_TARGET_ESP32
  621. #include "esp32/clk.h"
  622. @@ -235,6 +239,14 @@ static void do_core_init(void)
  623. app CPU, and when that is not up yet, the memory will be inaccessible and heap_caps_init may
  624. fail initializing it properly. */
  625. heap_caps_init();
  626. +#if CONFIG_IDF_RTOS_RTTHREAD
  627. +#if defined RT_USING_HEAP
  628. + extern int __heap_start__;
  629. + extern int __heap_end__;
  630. + rt_system_heap_init((void *)&__heap_start__, (void *)&__heap_end__);
  631. +#endif
  632. + rt_system_scheduler_init();
  633. +#endif
  634. // When apptrace module is enabled, there will be SEGGER_SYSVIEW calls in the newlib init.
  635. // SEGGER_SYSVIEW relies on apptrace module
  636. diff --git a/components/freertos/CMakeLists.txt b/components/freertos/CMakeLists.txt
  637. index bd5acf5a2f..8db7883df6 100644
  638. --- a/components/freertos/CMakeLists.txt
  639. +++ b/components/freertos/CMakeLists.txt
  640. @@ -6,7 +6,29 @@ endif()
  641. idf_build_get_property(target IDF_TARGET)
  642. -if(CONFIG_IDF_TARGET_ARCH_XTENSA)
  643. +if(CONFIG_IDF_RTOS_RTTHREAD)
  644. + set(freertos_root "RT-Thread-wrapper-of-FreeRTOS/FreeRTOS")
  645. +else()
  646. + set(freertos_root ".")
  647. +endif()
  648. +
  649. +if(CONFIG_IDF_RTOS_RTTHREAD)
  650. + set(srcs
  651. + "${freertos_root}/port/rt-thread/port.c"
  652. + "${freertos_root}/port/rt-thread/port_esp32c3.c")
  653. +
  654. + set(include_dirs
  655. + "${freertos_root}/include"
  656. + "${freertos_root}/include/esp_additions/freertos" # For files with #include "FreeRTOSConfig.h"
  657. + "${freertos_root}/port/rt-thread/include" # For including arch-specific FreeRTOSConfig_arch.h in port/<arch>/include
  658. + "${freertos_root}/include/esp_additions") # For files with #include "freertos/FreeRTOSConfig.h"
  659. +
  660. + set(private_include_dirs
  661. + "${freertos_root}/port/rt-thread/include/freertos"
  662. + "${freertos_root}/port/rt-thread"
  663. + "${freertos_root}")
  664. +
  665. +elseif(CONFIG_IDF_TARGET_ARCH_XTENSA)
  666. set(srcs
  667. "port/xtensa/port.c"
  668. "port/xtensa/portasm.S"
  669. @@ -48,21 +70,25 @@ elseif(CONFIG_IDF_TARGET_ARCH_RISCV)
  670. endif()
  671. list(APPEND srcs
  672. - "esp_additions/task_snapshot.c"
  673. - "port/port_common.c"
  674. - "port/port_systick.c"
  675. - "croutine.c"
  676. - "event_groups.c"
  677. - "list.c"
  678. - "queue.c"
  679. - "tasks.c"
  680. - "timers.c"
  681. - "stream_buffer.c"
  682. - "FreeRTOS-openocd.c"
  683. - "freertos_v8_compat.c")
  684. + "${freertos_root}/port/port_common.c"
  685. + "${freertos_root}/event_groups.c"
  686. + "${freertos_root}/queue.c"
  687. + "${freertos_root}/tasks.c"
  688. + "${freertos_root}/timers.c"
  689. + "${freertos_root}/list.c"
  690. + "${freertos_root}/freertos_v8_compat.c"
  691. + "${freertos_root}/esp_additions/task_snapshot.c")
  692. +
  693. +if(NOT CONFIG_IDF_RTOS_RTTHREAD)
  694. + list(APPEND srcs
  695. + "port/port_systick.c"
  696. + "croutine.c"
  697. + "stream_buffer.c"
  698. + "freertos_v8_compat.c")
  699. +endif()
  700. list(APPEND private_include_dirs
  701. - "include/freertos")
  702. + "${freertos_root}/include/freertos")
  703. if(CONFIG_ESP32_IRAM_AS_8BIT_ACCESSIBLE_MEMORY)
  704. list(APPEND srcs "port/xtensa/xtensa_loadstore_handler.S")
  705. @@ -71,7 +97,7 @@ endif()
  706. # esp_timer is required by FreeRTOS because we use esp_tiemr_get_time() to do profiling
  707. # app_trace is required by FreeRTOS headers only when CONFIG_APPTRACE_SV_ENABLE=y,
  708. # REQUIRES can't depend on config options, so always require it.
  709. -set(required_components app_trace esp_timer)
  710. +set(required_components app_trace esp_timer main)
  711. idf_component_register(SRCS "${srcs}"
  712. INCLUDE_DIRS ${include_dirs}
  713. @@ -88,15 +114,22 @@ if(CONFIG_FREERTOS_DEBUG_OCDAWARE)
  714. endif()
  715. set_source_files_properties(
  716. - tasks.c
  717. - event_groups.c
  718. - timers.c
  719. - queue.c
  720. - stream_buffer.c
  721. + "${freertos_root}/tasks.c"
  722. + "${freertos_root}/event_groups.c"
  723. + "${freertos_root}/timers.c"
  724. + "${freertos_root}/queue.c"
  725. PROPERTIES COMPILE_DEFINITIONS
  726. _ESP_FREERTOS_INTERNAL
  727. )
  728. +if(NOT CONFIG_IDF_RTOS_RTTHREAD)
  729. + set_source_files_properties(
  730. + stream_buffer.c
  731. + PROPERTIES COMPILE_DEFINITIONS
  732. + _ESP_FREERTOS_INTERNAL
  733. + )
  734. +endif()
  735. +
  736. # The freertos component provides the `start_app` and `start_app_other_cores`
  737. # if it is included in the build. It then calls `app_main`
  738. # from the main task created, which must be provided by the user.
  739. diff --git a/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/esp_additions/task_snapshot.c b/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/esp_additions/task_snapshot.c
  740. new file mode 100644
  741. index 0000000000..1244118b60
  742. --- /dev/null
  743. +++ b/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/esp_additions/task_snapshot.c
  744. @@ -0,0 +1,212 @@
  745. +/*
  746. + * SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
  747. + *
  748. + * SPDX-License-Identifier: Apache-2.0
  749. + */
  750. +
  751. +#include "freertos/FreeRTOS.h"
  752. +#include "freertos/task_snapshot.h"
  753. +
  754. +#ifndef DIM
  755. +#define DIM(t) (sizeof(t)/ sizeof(*(t)))
  756. +#endif
  757. +
  758. +#if ( configENABLE_TASK_SNAPSHOT == 1 )
  759. +
  760. + static void prvTaskGetSnapshot( TaskSnapshot_t *pxTaskSnapshotArray, UBaseType_t *uxTask, void *pxTCB )
  761. + {
  762. + if (pxTCB == NULL) {
  763. + return;
  764. + }
  765. + pxTaskSnapshotArray[ *uxTask ].pxTCB = pxTCB;
  766. + pxTaskSnapshotArray[ *uxTask ].pxTopOfStack = (StackType_t *) pxTCBGetTopOfStack(pxTCB);
  767. + #if( portSTACK_GROWTH < 0 )
  768. + {
  769. + pxTaskSnapshotArray[ *uxTask ].pxEndOfStack = pxTCBGetEndOfStack(pxTCB);
  770. + }
  771. + #else
  772. + {
  773. + pxTaskSnapshotArray[ *uxTask ].pxEndOfStack = pxTCBGetStartOfStack(pxTCB);
  774. + }
  775. + #endif
  776. + (*uxTask)++;
  777. + }
  778. +
  779. + static void prvTaskGetSnapshotsFromList( TaskSnapshot_t *pxTaskSnapshotArray, UBaseType_t *uxTask, const UBaseType_t uxArraySize, List_t *pxList )
  780. + {
  781. + void *pxNextTCB = NULL;
  782. + void *pxFirstTCB = NULL;
  783. +
  784. + if( listCURRENT_LIST_LENGTH( pxList ) > ( UBaseType_t ) 0 )
  785. + {
  786. + listGET_OWNER_OF_NEXT_ENTRY( pxFirstTCB, pxList );
  787. + do
  788. + {
  789. + if( *uxTask >= uxArraySize ) {
  790. + break;
  791. + }
  792. +
  793. + listGET_OWNER_OF_NEXT_ENTRY( pxNextTCB, pxList );
  794. + prvTaskGetSnapshot( pxTaskSnapshotArray, uxTask, pxNextTCB );
  795. + } while( pxNextTCB != pxFirstTCB );
  796. + }
  797. + else
  798. + {
  799. + mtCOVERAGE_TEST_MARKER();
  800. + }
  801. + }
  802. +
  803. + UBaseType_t uxTaskGetSnapshotAll( TaskSnapshot_t * const pxTaskSnapshotArray, const UBaseType_t uxArraySize, UBaseType_t * const pxTcbSz )
  804. + {
  805. + UBaseType_t uxTask = 0;
  806. + UBaseType_t i = 0;
  807. +
  808. +
  809. + *pxTcbSz = pxTCBGetSize();
  810. + /* Fill in an TaskStatus_t structure with information on each
  811. + task in the Ready state. */
  812. + i = configMAX_PRIORITIES;
  813. + do
  814. + {
  815. + i--;
  816. + prvTaskGetSnapshotsFromList( pxTaskSnapshotArray, &uxTask, uxArraySize, pxListGetReadyTask(i) );
  817. + } while( i > ( UBaseType_t ) tskIDLE_PRIORITY ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */
  818. +
  819. + /* Fill in an TaskStatus_t structure with information on each
  820. + task in the Blocked state. */
  821. + prvTaskGetSnapshotsFromList( pxTaskSnapshotArray, &uxTask, uxArraySize, pxGetDelayedTaskList() );
  822. + prvTaskGetSnapshotsFromList( pxTaskSnapshotArray, &uxTask, uxArraySize, pxGetOverflowDelayedTaskList() );
  823. + for (i = 0; i < configNUM_CORES; i++) {
  824. + if( uxTask >= uxArraySize ) {
  825. + break;
  826. + }
  827. + prvTaskGetSnapshotsFromList( pxTaskSnapshotArray, &uxTask, uxArraySize, pxListGetReadyPendingTask(i) );
  828. + }
  829. +
  830. + #if( INCLUDE_vTaskDelete == 1 )
  831. + {
  832. + prvTaskGetSnapshotsFromList( pxTaskSnapshotArray, &uxTask, uxArraySize, pxGetTasksWaitingTermination() );
  833. + }
  834. + #endif
  835. +
  836. + #if ( INCLUDE_vTaskSuspend == 1 )
  837. + {
  838. + prvTaskGetSnapshotsFromList( pxTaskSnapshotArray, &uxTask, uxArraySize, pxGetSuspendedTaskList() );
  839. + }
  840. + #endif
  841. + return uxTask;
  842. + }
  843. +
  844. + static void *prvFirstTaskGet( List_t *pxList )
  845. + {
  846. + ListItem_t *pxListItem = listGET_HEAD_ENTRY( pxList );
  847. + if( pxListItem != listGET_END_MARKER( pxList ) ) {
  848. + return listGET_LIST_ITEM_OWNER( pxListItem );
  849. + }
  850. + return NULL;
  851. + }
  852. +
  853. + static void *prvNextTaskGet( void *pxTCB )
  854. + {
  855. + List_t *pxList = listLIST_ITEM_CONTAINER( pxTCBGetStateListItem(pxTCB) );
  856. + ListItem_t *pxListItem = listGET_NEXT( pxTCBGetStateListItem(pxTCB) );
  857. + if( pxListItem != listGET_END_MARKER( pxList ) ) {
  858. + return listGET_LIST_ITEM_OWNER( pxListItem );
  859. + }
  860. + return NULL;
  861. + }
  862. +
  863. + void vTaskGetSnapshot( TaskHandle_t pxTask, TaskSnapshot_t *pxTaskSnapshot )
  864. + {
  865. + configASSERT( portVALID_TCB_MEM(pxTask) );
  866. + configASSERT( pxTaskSnapshot != NULL );
  867. + pxTaskSnapshot->pxTCB = (void*) pxTask;
  868. + pxTaskSnapshot->pxTopOfStack = pxTCBGetTopOfStack((void*) pxTask);
  869. + pxTaskSnapshot->pxEndOfStack = pxTCBGetEndOfStack((void*) pxTask);
  870. + }
  871. +
  872. + TaskHandle_t pxTaskGetNext( TaskHandle_t pxTask )
  873. + {
  874. + void *pxTCB = pxTask;
  875. + List_t *pxTaskList = NULL;
  876. + UBaseType_t i = configMAX_PRIORITIES;
  877. + UBaseType_t bCurTaskListFound = pdFALSE;
  878. + List_t *task_lists[] = {
  879. + pxGetDelayedTaskList(),
  880. + pxGetOverflowDelayedTaskList(),
  881. + #if( INCLUDE_vTaskDelete == 1 )
  882. + pxGetTasksWaitingTermination(),
  883. + #endif
  884. + #if( INCLUDE_vTaskSuspend == 1 )
  885. + pxGetSuspendedTaskList()
  886. + #endif
  887. + };
  888. +
  889. + if( pxTask != NULL && !portVALID_TCB_MEM(pxTask) ) {
  890. + return NULL;
  891. + }
  892. +
  893. + if( pxTCB != NULL ) {
  894. + pxTCB = prvNextTaskGet( pxTCB );
  895. + if( pxTCB != NULL ) {
  896. + // take care not to return garbage
  897. + return portVALID_TCB_MEM(pxTCB) ? pxTCB : NULL;
  898. + }
  899. + pxTaskList = listLIST_ITEM_CONTAINER( pxTCBGetStateListItem(pxTask) );
  900. + }
  901. + /* ready tasks lists */
  902. + do
  903. + {
  904. + i--;
  905. + List_t *pxList = pxListGetReadyTask(i);
  906. + if( bCurTaskListFound == pdFALSE && pxTaskList != NULL ) {
  907. + /* need to find list the current task item from */
  908. + if( pxTaskList == pxList ) {
  909. + bCurTaskListFound = pdTRUE;
  910. + }
  911. + continue; /* go to the next 'ready list' */
  912. + }
  913. + pxTCB = prvFirstTaskGet( pxList );
  914. + if( pxTCB != NULL ) {
  915. + // take care not to return garbage
  916. + return portVALID_TCB_MEM(pxTCB) ? pxTCB : NULL;
  917. + }
  918. + }
  919. + while( i > tskIDLE_PRIORITY );
  920. + /* pending ready tasks lists */
  921. + for (i = 0; i < configNUM_CORES; i++) {
  922. + List_t *pxList = pxListGetReadyPendingTask(i);
  923. + if( bCurTaskListFound == pdFALSE && pxTaskList != NULL ) {
  924. + /* need to find list the current task item from */
  925. + if( pxTaskList == pxList ) {
  926. + bCurTaskListFound = pdTRUE;
  927. + }
  928. + continue; /* go to the next 'ready list' */
  929. + }
  930. + pxTCB = prvFirstTaskGet( pxList );
  931. + if( pxTCB != NULL ) {
  932. + // take care not to return garbage
  933. + return portVALID_TCB_MEM(pxTCB) ? pxTCB : NULL;
  934. + }
  935. + }
  936. + /* other tasks lists */
  937. + for (i = 0; i < DIM(task_lists); i++) {
  938. + List_t *pxList = task_lists[ i ];
  939. + if( bCurTaskListFound == pdFALSE && pxTaskList != NULL ) {
  940. + /* need to find list the current task item from */
  941. + if( pxTaskList == pxList ) {
  942. + bCurTaskListFound = pdTRUE;
  943. + }
  944. + continue; /* go to the next 'ready list' */
  945. + }
  946. + pxTCB = prvFirstTaskGet( pxList );
  947. + if( pxTCB != NULL ) {
  948. + // take care not to return garbage
  949. + return portVALID_TCB_MEM(pxTCB) ? pxTCB : NULL;
  950. + }
  951. + }
  952. +
  953. + return NULL;
  954. + }
  955. +
  956. +#endif
  957. diff --git a/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/event_groups.c b/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/event_groups.c
  958. new file mode 100644
  959. index 0000000000..1b708564ed
  960. --- /dev/null
  961. +++ b/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/event_groups.c
  962. @@ -0,0 +1,225 @@
  963. +/*
  964. + * FreeRTOS Kernel V10.4.6
  965. + * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  966. + *
  967. + * SPDX-License-Identifier: MIT
  968. + *
  969. + * Permission is hereby granted, free of charge, to any person obtaining a copy of
  970. + * this software and associated documentation files (the "Software"), to deal in
  971. + * the Software without restriction, including without limitation the rights to
  972. + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  973. + * the Software, and to permit persons to whom the Software is furnished to do so,
  974. + * subject to the following conditions:
  975. + *
  976. + * The above copyright notice and this permission notice shall be included in all
  977. + * copies or substantial portions of the Software.
  978. + *
  979. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  980. + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  981. + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  982. + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  983. + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  984. + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  985. + *
  986. + * https://www.FreeRTOS.org
  987. + * https://github.com/FreeRTOS
  988. + *
  989. + */
  990. +
  991. +/* Standard includes. */
  992. +#include <stdlib.h>
  993. +
  994. +/* FreeRTOS includes. */
  995. +#include "FreeRTOS.h"
  996. +#include "task.h"
  997. +#include "event_groups.h"
  998. +
  999. +typedef struct EventGroupDef_t
  1000. +{
  1001. + struct rt_event event;
  1002. +} EventGroup_t;
  1003. +
  1004. +static volatile rt_uint8_t event_index = 0;
  1005. +
  1006. +/*-----------------------------------------------------------*/
  1007. +
  1008. +#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
  1009. +
  1010. + EventGroupHandle_t xEventGroupCreateStatic( StaticEventGroup_t * pxEventGroupBuffer )
  1011. + {
  1012. + char name[RT_NAME_MAX] = {0};
  1013. +
  1014. + /* A StaticEventGroup_t object must be provided. */
  1015. + configASSERT( pxEventGroupBuffer );
  1016. +
  1017. + rt_snprintf( name, RT_NAME_MAX, "event%02d", event_index++ );
  1018. + rt_event_init( ( rt_event_t ) pxEventGroupBuffer, name, RT_IPC_FLAG_PRIO );
  1019. +
  1020. + return ( EventGroupHandle_t ) pxEventGroupBuffer;
  1021. + }
  1022. +
  1023. +#endif /* configSUPPORT_STATIC_ALLOCATION */
  1024. +/*-----------------------------------------------------------*/
  1025. +
  1026. +#if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
  1027. +
  1028. + EventGroupHandle_t xEventGroupCreate( void )
  1029. + {
  1030. + EventGroup_t * pxEventBits;
  1031. + char name[RT_NAME_MAX] = {0};
  1032. +
  1033. + rt_snprintf( name, RT_NAME_MAX, "event%02d", event_index++ );
  1034. + pxEventBits = ( EventGroup_t * ) rt_event_create( name, RT_IPC_FLAG_PRIO );
  1035. +
  1036. + return pxEventBits;
  1037. + }
  1038. +
  1039. +#endif /* configSUPPORT_DYNAMIC_ALLOCATION */
  1040. +/*-----------------------------------------------------------*/
  1041. +
  1042. +EventBits_t xEventGroupWaitBits( EventGroupHandle_t xEventGroup,
  1043. + const EventBits_t uxBitsToWaitFor,
  1044. + const BaseType_t xClearOnExit,
  1045. + const BaseType_t xWaitForAllBits,
  1046. + TickType_t xTicksToWait )
  1047. +{
  1048. + rt_event_t event = ( rt_event_t ) xEventGroup;
  1049. + rt_uint8_t option = 0;
  1050. + rt_uint32_t recved;
  1051. + rt_base_t level;
  1052. + rt_err_t err;
  1053. +
  1054. + /* Check the user is not attempting to wait on the bits used by the kernel
  1055. + * itself, and that at least one bit is being requested. */
  1056. + configASSERT( xEventGroup );
  1057. + configASSERT( uxBitsToWaitFor != 0 );
  1058. + #if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )
  1059. + {
  1060. + configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) );
  1061. + }
  1062. + #endif
  1063. +
  1064. + if ( xWaitForAllBits != pdFALSE )
  1065. + {
  1066. + option |= RT_EVENT_FLAG_AND;
  1067. + }
  1068. + else
  1069. + {
  1070. + option |= RT_EVENT_FLAG_OR;
  1071. + }
  1072. + if ( xClearOnExit != pdFALSE )
  1073. + {
  1074. + option |= RT_EVENT_FLAG_CLEAR;
  1075. + }
  1076. + err = rt_event_recv( event, ( rt_uint32_t ) uxBitsToWaitFor, option, ( rt_int32_t ) xTicksToWait, &recved );
  1077. +
  1078. + if ( err != RT_EOK )
  1079. + {
  1080. + level = rt_hw_interrupt_disable();
  1081. + recved = event->set;
  1082. + rt_hw_interrupt_enable(level);
  1083. + }
  1084. +
  1085. + return ( EventBits_t ) recved;
  1086. +}
  1087. +/*-----------------------------------------------------------*/
  1088. +
  1089. +EventBits_t xEventGroupClearBits( EventGroupHandle_t xEventGroup,
  1090. + const EventBits_t uxBitsToClear )
  1091. +{
  1092. + rt_event_t event = ( rt_event_t ) xEventGroup;
  1093. + EventBits_t uxReturn;
  1094. + rt_base_t level;
  1095. +
  1096. + configASSERT( xEventGroup );
  1097. +
  1098. + level = rt_hw_interrupt_disable();
  1099. + uxReturn = ( EventBits_t ) event->set;
  1100. + event->set &= ~( ( rt_uint32_t ) uxBitsToClear );
  1101. + rt_hw_interrupt_enable( level );
  1102. +
  1103. + return uxReturn;
  1104. +}
  1105. +/*-----------------------------------------------------------*/
  1106. +
  1107. +BaseType_t xEventGroupClearBitsFromISR( EventGroupHandle_t xEventGroup,
  1108. + const EventBits_t uxBitsToClear )
  1109. +{
  1110. + return xEventGroupClearBits( xEventGroup, uxBitsToClear );
  1111. +}
  1112. +
  1113. +EventBits_t xEventGroupGetBitsFromISR( EventGroupHandle_t xEventGroup )
  1114. +{
  1115. + rt_event_t event = ( rt_event_t ) xEventGroup;
  1116. + EventBits_t uxReturn;
  1117. + rt_base_t level;
  1118. +
  1119. + level = rt_hw_interrupt_disable();
  1120. + uxReturn = ( EventBits_t ) event->set;
  1121. + rt_hw_interrupt_enable( level );
  1122. +
  1123. + return uxReturn;
  1124. +}
  1125. +/*-----------------------------------------------------------*/
  1126. +
  1127. +EventBits_t xEventGroupSetBits( EventGroupHandle_t xEventGroup,
  1128. + const EventBits_t uxBitsToSet )
  1129. +{
  1130. + rt_event_t event = ( rt_event_t ) xEventGroup;
  1131. + rt_base_t level;
  1132. + EventBits_t uxReturn;
  1133. +
  1134. + configASSERT( xEventGroup );
  1135. +
  1136. + rt_event_send( event, ( rt_uint32_t ) uxBitsToSet);
  1137. +
  1138. + level = rt_hw_interrupt_disable();
  1139. + uxReturn = ( EventBits_t ) event->set;
  1140. + rt_hw_interrupt_enable(level);
  1141. +
  1142. + return uxReturn;
  1143. +}
  1144. +/*-----------------------------------------------------------*/
  1145. +
  1146. +void vEventGroupDelete( EventGroupHandle_t xEventGroup )
  1147. +{
  1148. + rt_event_t event = ( rt_event_t ) xEventGroup;
  1149. +
  1150. + configASSERT( xEventGroup );
  1151. +
  1152. +#if ( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) )
  1153. + if ( rt_object_is_systemobject( ( rt_object_t ) event ) )
  1154. +#endif
  1155. + {
  1156. + #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
  1157. + rt_event_detach( event );
  1158. + #endif
  1159. +#if ( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) )
  1160. + }
  1161. + else
  1162. + {
  1163. +#endif
  1164. + #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
  1165. + rt_event_delete( event );
  1166. + #endif
  1167. + }
  1168. +}
  1169. +/*-----------------------------------------------------------*/
  1170. +
  1171. +#if ( ( configUSE_TRACE_FACILITY == 1 ) && ( INCLUDE_xTimerPendFunctionCall == 1 ) && ( configUSE_TIMERS == 1 ) )
  1172. +
  1173. + BaseType_t xEventGroupSetBitsFromISR( EventGroupHandle_t xEventGroup,
  1174. + const EventBits_t uxBitsToSet,
  1175. + BaseType_t * pxHigherPriorityTaskWoken )
  1176. + {
  1177. + xEventGroupSetBits( xEventGroup, uxBitsToSet );
  1178. + if ( pxHigherPriorityTaskWoken != NULL)
  1179. + {
  1180. + pxHigherPriorityTaskWoken = pdFALSE;
  1181. + }
  1182. +
  1183. + return pdPASS;
  1184. + }
  1185. +
  1186. +#endif /* if ( ( configUSE_TRACE_FACILITY == 1 ) && ( INCLUDE_xTimerPendFunctionCall == 1 ) && ( configUSE_TIMERS == 1 ) ) */
  1187. +/*-----------------------------------------------------------*/
  1188. diff --git a/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/freertos_v8_compat.c b/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/freertos_v8_compat.c
  1189. new file mode 100644
  1190. index 0000000000..fe8d689125
  1191. --- /dev/null
  1192. +++ b/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/freertos_v8_compat.c
  1193. @@ -0,0 +1,33 @@
  1194. +// Copyright 2020 Espressif Systems (Shanghai) Co., Ltd.
  1195. +//
  1196. +// Licensed under the Apache License, Version 2.0 (the "License");
  1197. +// you may not use this file except in compliance with the License.
  1198. +// You may obtain a copy of the License at
  1199. +//
  1200. +// http://www.apache.org/licenses/LICENSE-2.0
  1201. +//
  1202. +// Unless required by applicable law or agreed to in writing, software
  1203. +// distributed under the License is distributed on an "AS IS" BASIS,
  1204. +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  1205. +// See the License for the specific language governing permissions and
  1206. +// limitations under the License.
  1207. +
  1208. +#include "FreeRTOS.h"
  1209. +#include "queue.h"
  1210. +#include "semphr.h"
  1211. +
  1212. +/* This API is kept for backward ABI compatibility with prebuilt libraries against FreeRTOS v8/v9 in ESP-IDF */
  1213. +BaseType_t xQueueGenericReceive( QueueHandle_t xQueue, void * const pvBuffer, TickType_t xTicksToWait, const BaseType_t xPeek )
  1214. +{
  1215. + if ( xPeek == pdTRUE )
  1216. + {
  1217. + return xQueuePeek( xQueue, pvBuffer, xTicksToWait );
  1218. + }
  1219. +
  1220. + if ( pvBuffer == NULL )
  1221. + {
  1222. + return xQueueSemaphoreTake( xQueue, xTicksToWait );
  1223. + }
  1224. +
  1225. + return xQueueReceive( xQueue, pvBuffer, xTicksToWait );
  1226. +}
  1227. diff --git a/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/include/esp_additions/freertos/FreeRTOSConfig.h b/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/include/esp_additions/freertos/FreeRTOSConfig.h
  1228. new file mode 100644
  1229. index 0000000000..8a4739a3a5
  1230. --- /dev/null
  1231. +++ b/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/include/esp_additions/freertos/FreeRTOSConfig.h
  1232. @@ -0,0 +1,326 @@
  1233. +/*
  1234. + FreeRTOS V10 - Copyright (C) 2021 Real Time Engineers Ltd.
  1235. + All rights reserved
  1236. +
  1237. + VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
  1238. +
  1239. + This file is part of the FreeRTOS distribution.
  1240. +
  1241. + FreeRTOS is free software; you can redistribute it and/or modify it under
  1242. + the terms of the GNU General Public License (version 2) as published by the
  1243. + Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
  1244. +
  1245. + ***************************************************************************
  1246. + >>! NOTE: The modification to the GPL is included to allow you to !<<
  1247. + >>! distribute a combined work that includes FreeRTOS without being !<<
  1248. + >>! obliged to provide the source code for proprietary components !<<
  1249. + >>! outside of the FreeRTOS kernel. !<<
  1250. + ***************************************************************************
  1251. +
  1252. + FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
  1253. + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  1254. + FOR A PARTICULAR PURPOSE. Full license text is available on the following
  1255. + link: http://www.freertos.org/a00114.html
  1256. +
  1257. + ***************************************************************************
  1258. + * *
  1259. + * FreeRTOS provides completely free yet professionally developed, *
  1260. + * robust, strictly quality controlled, supported, and cross *
  1261. + * platform software that is more than just the market leader, it *
  1262. + * is the industry's de facto standard. *
  1263. + * *
  1264. + * Help yourself get started quickly while simultaneously helping *
  1265. + * to support the FreeRTOS project by purchasing a FreeRTOS *
  1266. + * tutorial book, reference manual, or both: *
  1267. + * http://www.FreeRTOS.org/Documentation *
  1268. + * *
  1269. + ***************************************************************************
  1270. +
  1271. + http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
  1272. + the FAQ page "My application does not run, what could be wrong?". Have you
  1273. + defined configASSERT()?
  1274. +
  1275. + http://www.FreeRTOS.org/support - In return for receiving this top quality
  1276. + embedded software for free we request you assist our global community by
  1277. + participating in the support forum.
  1278. +
  1279. + http://www.FreeRTOS.org/training - Investing in training allows your team to
  1280. + be as productive as possible as early as possible. Now you can receive
  1281. + FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
  1282. + Ltd, and the world's leading authority on the world's leading RTOS.
  1283. +
  1284. + http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
  1285. + including FreeRTOS+Trace - an indispensable productivity tool, a DOS
  1286. + compatible FAT file system, and our tiny thread aware UDP/IP stack.
  1287. +
  1288. + http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
  1289. + Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
  1290. +
  1291. + http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
  1292. + Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
  1293. + licenses offer ticketed support, indemnification and commercial middleware.
  1294. +
  1295. + http://www.SafeRTOS.com - High Integrity Systems also provide a safety
  1296. + engineered and independently SIL3 certified version for use in safety and
  1297. + mission critical applications that require provable dependability.
  1298. +
  1299. + 1 tab == 4 spaces!
  1300. +*/
  1301. +
  1302. +#ifndef FREERTOS_CONFIG_H
  1303. +#define FREERTOS_CONFIG_H
  1304. +
  1305. +#include "sdkconfig.h"
  1306. +
  1307. +/* for likely and unlikely */
  1308. +#include "esp_compiler.h"
  1309. +
  1310. +// The arch-specific FreeRTOSConfig_arch.h in port/<arch>/include.
  1311. +#include "freertos/FreeRTOSConfig_arch.h"
  1312. +
  1313. +#if !(defined(FREERTOS_CONFIG_XTENSA_H) \
  1314. + || defined(FREERTOS_CONFIG_RISCV_H) \
  1315. + || defined(FREERTOS_CONFIG_LINUX_H))
  1316. +#error "Needs architecture-speific FreeRTOSConfig.h!"
  1317. +#endif
  1318. +
  1319. +#ifndef CONFIG_FREERTOS_UNICORE
  1320. +#define portNUM_PROCESSORS 2
  1321. +#else
  1322. +#define portNUM_PROCESSORS 1
  1323. +#endif
  1324. +
  1325. +#define portUSING_MPU_WRAPPERS 0
  1326. +#define configUSE_MUTEX 1
  1327. +
  1328. +#define configNUM_THREAD_LOCAL_STORAGE_POINTERS CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS
  1329. +#define configTHREAD_LOCAL_STORAGE_DELETE_CALLBACKS 1
  1330. +
  1331. +/* configASSERT behaviour */
  1332. +#ifndef __ASSEMBLER__
  1333. +#include <assert.h>
  1334. +
  1335. +// If CONFIG_FREERTOS_ASSERT_DISABLE is set then configASSERT is defined empty later in FreeRTOS.h and the macro
  1336. +// configASSERT_DEFINED remains unset (meaning some warnings are avoided)
  1337. +
  1338. +#if defined(CONFIG_FREERTOS_ASSERT_FAIL_PRINT_CONTINUE)
  1339. +#define configASSERT(a) if (unlikely(!(a))) { \
  1340. + esp_rom_printf("%s:%d (%s)- assert failed!\n", __FILE__, __LINE__, \
  1341. + __FUNCTION__); \
  1342. + }
  1343. +#elif defined(CONFIG_FREERTOS_ASSERT_FAIL_ABORT)
  1344. +#define configASSERT(a) assert(a)
  1345. +#endif
  1346. +
  1347. +#if CONFIG_FREERTOS_ASSERT_ON_UNTESTED_FUNCTION
  1348. +#define UNTESTED_FUNCTION() { esp_rom_printf("Untested FreeRTOS function %s\r\n", __FUNCTION__); configASSERT(false); } while(0)
  1349. +#else
  1350. +#define UNTESTED_FUNCTION()
  1351. +#endif
  1352. +
  1353. +#endif /* def __ASSEMBLER__ */
  1354. +
  1355. +/*-----------------------------------------------------------
  1356. + * Application specific definitions.
  1357. + *
  1358. + * These definitions should be adjusted for your particular hardware and
  1359. + * application requirements.
  1360. + *
  1361. + * Note that the default heap size is deliberately kept small so that
  1362. + * the build is more likely to succeed for configurations with limited
  1363. + * memory.
  1364. + *
  1365. + * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE
  1366. + * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE.
  1367. + *----------------------------------------------------------*/
  1368. +
  1369. +#define configUSE_PREEMPTION 1
  1370. +#define configUSE_IDLE_HOOK 1
  1371. +#define configUSE_TICK_HOOK 1
  1372. +#define configRECORD_STACK_HIGH_ADDRESS 1
  1373. +#define configTICK_RATE_HZ ( CONFIG_FREERTOS_HZ )
  1374. +
  1375. +/* This has impact on speed of search for highest priority */
  1376. +#define configMAX_PRIORITIES ( 32 )
  1377. +
  1378. +/* Various things that impact minimum stack sizes */
  1379. +
  1380. +/* Higher stack checker modes cause overhead on each function call */
  1381. +#if CONFIG_STACK_CHECK_ALL || CONFIG_STACK_CHECK_STRONG
  1382. +#define configSTACK_OVERHEAD_CHECKER 256
  1383. +#else
  1384. +#define configSTACK_OVERHEAD_CHECKER 0
  1385. +#endif
  1386. +
  1387. +/* with optimizations disabled, scheduler uses additional stack */
  1388. +#if CONFIG_COMPILER_OPTIMIZATION_NONE
  1389. +#define configSTACK_OVERHEAD_OPTIMIZATION 320
  1390. +#else
  1391. +#define configSTACK_OVERHEAD_OPTIMIZATION 0
  1392. +#endif
  1393. +
  1394. +/* apptrace mdule increases minimum stack usage */
  1395. +#if CONFIG_APPTRACE_ENABLE
  1396. +#define configSTACK_OVERHEAD_APPTRACE 1280
  1397. +#else
  1398. +#define configSTACK_OVERHEAD_APPTRACE 0
  1399. +#endif
  1400. +
  1401. +/* Stack watchpoint decreases minimum usable stack size by up to 60 bytes.
  1402. + See FreeRTOS FREERTOS_WATCHPOINT_END_OF_STACK option in Kconfig. */
  1403. +#if CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK
  1404. +#define configSTACK_OVERHEAD_WATCHPOINT 60
  1405. +#else
  1406. +#define configSTACK_OVERHEAD_WATCHPOINT 0
  1407. +#endif
  1408. +
  1409. +#define configSTACK_OVERHEAD_TOTAL ( \
  1410. + configSTACK_OVERHEAD_CHECKER + \
  1411. + configSTACK_OVERHEAD_OPTIMIZATION + \
  1412. + configSTACK_OVERHEAD_APPTRACE + \
  1413. + configSTACK_OVERHEAD_WATCHPOINT \
  1414. + )
  1415. +
  1416. +#define configMINIMAL_STACK_SIZE (768 + configSTACK_OVERHEAD_TOTAL)
  1417. +
  1418. +#ifndef configIDLE_TASK_STACK_SIZE
  1419. +#define configIDLE_TASK_STACK_SIZE CONFIG_FREERTOS_IDLE_TASK_STACKSIZE
  1420. +#endif
  1421. +
  1422. +/* Minimal heap size to make sure examples can run on memory limited
  1423. + configs. Adjust this to suit your system. */
  1424. +
  1425. +
  1426. +//We define the heap to span all of the non-statically-allocated shared RAM. ToDo: Make sure there
  1427. +//is some space left for the app and main cpu when running outside of a thread.
  1428. +#define configAPPLICATION_ALLOCATED_HEAP 1
  1429. +#define configTOTAL_HEAP_SIZE (&_heap_end - &_heap_start)//( ( size_t ) (64 * 1024) )
  1430. +
  1431. +#define configMAX_TASK_NAME_LEN ( CONFIG_FREERTOS_MAX_TASK_NAME_LEN )
  1432. +
  1433. +#ifdef CONFIG_FREERTOS_USE_TRACE_FACILITY
  1434. +#define configUSE_TRACE_FACILITY 1 /* Used by uxTaskGetSystemState(), and other trace facility functions */
  1435. +#endif
  1436. +
  1437. +#ifdef CONFIG_FREERTOS_USE_STATS_FORMATTING_FUNCTIONS
  1438. +#define configUSE_STATS_FORMATTING_FUNCTIONS 1 /* Used by vTaskList() */
  1439. +#endif
  1440. +
  1441. +#ifdef CONFIG_FREERTOS_VTASKLIST_INCLUDE_COREID
  1442. +#define configTASKLIST_INCLUDE_COREID 1
  1443. +#endif
  1444. +
  1445. +#ifdef CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS
  1446. +#define configGENERATE_RUN_TIME_STATS 1 /* Used by vTaskGetRunTimeStats() */
  1447. +#endif
  1448. +
  1449. +#define configBENCHMARK 0
  1450. +#define configUSE_16_BIT_TICKS 0
  1451. +#define configIDLE_SHOULD_YIELD 0
  1452. +#define configQUEUE_REGISTRY_SIZE CONFIG_FREERTOS_QUEUE_REGISTRY_SIZE
  1453. +
  1454. +#define configUSE_MUTEXES 1
  1455. +#define configUSE_RECURSIVE_MUTEXES 1
  1456. +#define configUSE_COUNTING_SEMAPHORES 1
  1457. +
  1458. +#if CONFIG_FREERTOS_CHECK_STACKOVERFLOW_NONE
  1459. +#define configCHECK_FOR_STACK_OVERFLOW 0
  1460. +#elif CONFIG_FREERTOS_CHECK_STACKOVERFLOW_PTRVAL
  1461. +#define configCHECK_FOR_STACK_OVERFLOW 1
  1462. +#elif CONFIG_FREERTOS_CHECK_STACKOVERFLOW_CANARY
  1463. +#define configCHECK_FOR_STACK_OVERFLOW 2
  1464. +#endif
  1465. +
  1466. +
  1467. +/* Co-routine definitions. */
  1468. +#define configUSE_CO_ROUTINES 0
  1469. +#define configMAX_CO_ROUTINE_PRIORITIES ( 2 )
  1470. +
  1471. +/* Set the following definitions to 1 to include the API function, or zero
  1472. + to exclude the API function. */
  1473. +
  1474. +#define INCLUDE_vTaskPrioritySet 1
  1475. +#define INCLUDE_uxTaskPriorityGet 1
  1476. +#define INCLUDE_vTaskDelete 1
  1477. +#define INCLUDE_vTaskCleanUpResources 0
  1478. +#define INCLUDE_vTaskSuspend 1
  1479. +#define INCLUDE_vTaskDelayUntil 1
  1480. +#define INCLUDE_vTaskDelay 1
  1481. +#define INCLUDE_uxTaskGetStackHighWaterMark 1
  1482. +#define INCLUDE_pcTaskGetTaskName 1
  1483. +#define INCLUDE_xTaskGetIdleTaskHandle 1
  1484. +#define INCLUDE_pxTaskGetStackStart 1
  1485. +#define INCLUDE_eTaskGetState 1
  1486. +#define INCLUDE_xTaskAbortDelay 1
  1487. +#define INCLUDE_xTaskGetHandle 1
  1488. +#define INCLUDE_xSemaphoreGetMutexHolder 1
  1489. +#define INCLUDE_xTimerPendFunctionCall 1
  1490. +#define INCLUDE_xTimerGetTimerDaemonTaskHandle 0 //Currently there is no need for this API
  1491. +
  1492. +/* The priority at which the tick interrupt runs. This should probably be
  1493. + kept at 1. */
  1494. +#define configKERNEL_INTERRUPT_PRIORITY 1
  1495. +
  1496. +#if !CONFIG_IDF_TARGET_LINUX
  1497. +#define configUSE_NEWLIB_REENTRANT 1
  1498. +#endif
  1499. +
  1500. +#define configSUPPORT_DYNAMIC_ALLOCATION 1
  1501. +#define configSUPPORT_STATIC_ALLOCATION 1
  1502. +
  1503. +#ifndef __ASSEMBLER__
  1504. +#if CONFIG_FREERTOS_ENABLE_STATIC_TASK_CLEAN_UP
  1505. +extern void vPortCleanUpTCB ( void *pxTCB );
  1506. +#define portCLEAN_UP_TCB( pxTCB ) vPortCleanUpTCB( pxTCB )
  1507. +#endif
  1508. +#endif
  1509. +
  1510. +/* Test FreeRTOS timers (with timer task) and more. */
  1511. +/* Some files don't compile if this flag is disabled */
  1512. +#define configUSE_TIMERS 1
  1513. +#define configTIMER_TASK_PRIORITY CONFIG_FREERTOS_TIMER_TASK_PRIORITY
  1514. +#define configTIMER_QUEUE_LENGTH CONFIG_FREERTOS_TIMER_QUEUE_LENGTH
  1515. +#define configTIMER_TASK_STACK_DEPTH CONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH
  1516. +
  1517. +#define configUSE_QUEUE_SETS 1
  1518. +
  1519. +#define configUSE_TICKLESS_IDLE CONFIG_FREERTOS_USE_TICKLESS_IDLE
  1520. +#if configUSE_TICKLESS_IDLE
  1521. +#define configEXPECTED_IDLE_TIME_BEFORE_SLEEP CONFIG_FREERTOS_IDLE_TIME_BEFORE_SLEEP
  1522. +#endif //configUSE_TICKLESS_IDLE
  1523. +
  1524. +
  1525. +#if CONFIG_FREERTOS_ENABLE_TASK_SNAPSHOT
  1526. +#define configENABLE_TASK_SNAPSHOT 1
  1527. +#endif
  1528. +#ifndef configENABLE_TASK_SNAPSHOT
  1529. +#define configENABLE_TASK_SNAPSHOT 0
  1530. +#endif
  1531. +
  1532. +#if CONFIG_SYSVIEW_ENABLE
  1533. +#ifndef __ASSEMBLER__
  1534. +#include "SEGGER_SYSVIEW_FreeRTOS.h"
  1535. +#undef INLINE // to avoid redefinition
  1536. +#endif /* def __ASSEMBLER__ */
  1537. +#endif
  1538. +
  1539. +#if CONFIG_FREERTOS_CHECK_MUTEX_GIVEN_BY_OWNER
  1540. +#define configCHECK_MUTEX_GIVEN_BY_OWNER 1
  1541. +#else
  1542. +#define configCHECK_MUTEX_GIVEN_BY_OWNER 0
  1543. +#endif
  1544. +
  1545. +
  1546. +#define configINCLUDE_FREERTOS_TASK_C_ADDITIONS_H 1
  1547. +
  1548. +#define configTASK_NOTIFICATION_ARRAY_ENTRIES 1
  1549. +
  1550. +// backward compatibility for 4.4
  1551. +#define xTaskRemoveFromUnorderedEventList vTaskRemoveFromUnorderedEventList
  1552. +
  1553. +#define configNUM_CORES portNUM_PROCESSORS
  1554. +
  1555. +/* RT-Thread wrapper */
  1556. +#define INCLUDE_xTaskGetCurrentTaskHandle 1
  1557. +
  1558. +#endif /* FREERTOS_CONFIG_H */
  1559. diff --git a/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/include/esp_additions/freertos/task_snapshot.h b/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/include/esp_additions/freertos/task_snapshot.h
  1560. new file mode 100644
  1561. index 0000000000..1ad04cce69
  1562. --- /dev/null
  1563. +++ b/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/include/esp_additions/freertos/task_snapshot.h
  1564. @@ -0,0 +1,90 @@
  1565. +// Copyright 2015-2021 Espressif Systems (Shanghai) PTE LTD
  1566. +//
  1567. +// Licensed under the Apache License, Version 2.0 (the "License");
  1568. +// you may not use this file except in compliance with the License.
  1569. +// You may obtain a copy of the License at
  1570. +//
  1571. +// http://www.apache.org/licenses/LICENSE-2.0
  1572. +//
  1573. +// Unless required by applicable law or agreed to in writing, software
  1574. +// distributed under the License is distributed on an "AS IS" BASIS,
  1575. +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  1576. +// See the License for the specific language governing permissions and
  1577. +// limitations under the License.
  1578. +
  1579. +#pragma once
  1580. +
  1581. +#include "freertos/FreeRTOS.h"
  1582. +#include "freertos/task.h"
  1583. +
  1584. +#if ( configENABLE_TASK_SNAPSHOT == 1 )
  1585. +
  1586. +#ifdef __cplusplus
  1587. +extern "C" {
  1588. +#endif
  1589. +
  1590. +/**
  1591. + * Check `freertos_tasks_c_additions.h` file for more info
  1592. + * about these functions declaration.
  1593. + */
  1594. +UBaseType_t pxTCBGetSize ( void );
  1595. +ListItem_t* pxTCBGetStateListItem ( void *pxTCB );
  1596. +StackType_t* pxTCBGetStartOfStack ( void *pxTCB );
  1597. +StackType_t* pxTCBGetTopOfStack ( void *pxTCB );
  1598. +StackType_t* pxTCBGetEndOfStack ( void *pxTCB );
  1599. +List_t* pxListGetReadyTask ( UBaseType_t idx );
  1600. +List_t* pxListGetReadyPendingTask ( UBaseType_t idx );
  1601. +List_t* pxGetDelayedTaskList ( void );
  1602. +List_t* pxGetOverflowDelayedTaskList ( void );
  1603. +List_t* pxGetTasksWaitingTermination ( void );
  1604. +List_t* pxGetSuspendedTaskList ( void );
  1605. +
  1606. +/**
  1607. + * Used with the uxTaskGetSnapshotAll() function to save memory snapshot of each task in the system.
  1608. + * We need this struct because TCB_t is defined (hidden) in tasks.c.
  1609. + */
  1610. +typedef struct xTASK_SNAPSHOT
  1611. +{
  1612. + void *pxTCB; /*!< Address of task control block. */
  1613. + StackType_t *pxTopOfStack; /*!< Points to the location of the last item placed on the tasks stack. */
  1614. + StackType_t *pxEndOfStack; /*!< Points to the end of the stack. pxTopOfStack < pxEndOfStack, stack grows hi2lo
  1615. + pxTopOfStack > pxEndOfStack, stack grows lo2hi*/
  1616. +} TaskSnapshot_t;
  1617. +
  1618. +
  1619. +/*
  1620. + * This function fills array with TaskSnapshot_t structures for every task in the system.
  1621. + * Used by panic handling code to get snapshots of all tasks in the system.
  1622. + * Only available when configENABLE_TASK_SNAPSHOT is set to 1.
  1623. + * @param pxTaskSnapshotArray Pointer to array of TaskSnapshot_t structures to store tasks snapshot data.
  1624. + * @param uxArraySize Size of tasks snapshots array.
  1625. + * @param pxTcbSz Pointer to store size of TCB.
  1626. + * @return Number of elements stored in array.
  1627. + */
  1628. +UBaseType_t uxTaskGetSnapshotAll( TaskSnapshot_t * const pxTaskSnapshotArray, const UBaseType_t uxArraySize, UBaseType_t * const pxTcbSz );
  1629. +
  1630. +/*
  1631. + * This function iterates over all tasks in the system.
  1632. + * Used by panic handling code to iterate over tasks in the system.
  1633. + * Only available when configENABLE_TASK_SNAPSHOT is set to 1.
  1634. + * @note This function should not be used while FreeRTOS is running (as it doesn't acquire any locks).
  1635. + * @param pxTask task handle.
  1636. + * @return Handle for the next task. If pxTask is NULL, returns hadnle for the first task.
  1637. + */
  1638. +TaskHandle_t pxTaskGetNext( TaskHandle_t pxTask );
  1639. +
  1640. +/*
  1641. + * This function fills TaskSnapshot_t structure for specified task.
  1642. + * Used by panic handling code to get snapshot of a task.
  1643. + * Only available when configENABLE_TASK_SNAPSHOT is set to 1.
  1644. + * @note This function should not be used while FreeRTOS is running (as it doesn't acquire any locks).
  1645. + * @param pxTask task handle.
  1646. + * @param pxTaskSnapshot address of TaskSnapshot_t structure to fill.
  1647. + */
  1648. +void vTaskGetSnapshot( TaskHandle_t pxTask, TaskSnapshot_t *pxTaskSnapshot );
  1649. +
  1650. +#ifdef __cplusplus
  1651. +}
  1652. +#endif
  1653. +
  1654. +#endif
  1655. diff --git a/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/include/freertos/FreeRTOS.h b/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/include/freertos/FreeRTOS.h
  1656. new file mode 100644
  1657. index 0000000000..b3efa13f20
  1658. --- /dev/null
  1659. +++ b/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/include/freertos/FreeRTOS.h
  1660. @@ -0,0 +1,1198 @@
  1661. +/*
  1662. + * FreeRTOS Kernel V10.4.6
  1663. + * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  1664. + *
  1665. + * SPDX-License-Identifier: MIT
  1666. + *
  1667. + * Permission is hereby granted, free of charge, to any person obtaining a copy of
  1668. + * this software and associated documentation files (the "Software"), to deal in
  1669. + * the Software without restriction, including without limitation the rights to
  1670. + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  1671. + * the Software, and to permit persons to whom the Software is furnished to do so,
  1672. + * subject to the following conditions:
  1673. + *
  1674. + * The above copyright notice and this permission notice shall be included in all
  1675. + * copies or substantial portions of the Software.
  1676. + *
  1677. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  1678. + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  1679. + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  1680. + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  1681. + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  1682. + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  1683. + *
  1684. + * https://www.FreeRTOS.org
  1685. + * https://github.com/FreeRTOS
  1686. + *
  1687. + */
  1688. +
  1689. +#ifndef INC_FREERTOS_H
  1690. +#define INC_FREERTOS_H
  1691. +
  1692. +/*
  1693. + * Include the generic headers required for the FreeRTOS port being used.
  1694. + */
  1695. +#include <stddef.h>
  1696. +
  1697. +/*
  1698. + * If stdint.h cannot be located then:
  1699. + * + If using GCC ensure the -nostdint options is *not* being used.
  1700. + * + Ensure the project's include path includes the directory in which your
  1701. + * compiler stores stdint.h.
  1702. + * + Set any compiler options necessary for it to support C99, as technically
  1703. + * stdint.h is only mandatory with C99 (FreeRTOS does not require C99 in any
  1704. + * other way).
  1705. + * + The FreeRTOS download includes a simple stdint.h definition that can be
  1706. + * used in cases where none is provided by the compiler. The files only
  1707. + * contains the typedefs required to build FreeRTOS. Read the instructions
  1708. + * in FreeRTOS/source/stdint.readme for more information.
  1709. + */
  1710. +#include <stdint.h> /* READ COMMENT ABOVE. */
  1711. +
  1712. +/* *INDENT-OFF* */
  1713. +#ifdef __cplusplus
  1714. + extern "C" {
  1715. +#endif
  1716. +/* *INDENT-ON* */
  1717. +
  1718. +#include <rtthread.h>
  1719. +#include <rthw.h>
  1720. +
  1721. +/* Application specific configuration options. */
  1722. +#include "FreeRTOSConfig.h"
  1723. +
  1724. +/* Basic FreeRTOS definitions. */
  1725. +#include "projdefs.h"
  1726. +
  1727. +/* Definitions specific to the port being used. */
  1728. +#include "portable.h"
  1729. +
  1730. +/* Must be defaulted before configUSE_NEWLIB_REENTRANT is used below. */
  1731. +#ifndef configUSE_NEWLIB_REENTRANT
  1732. + #define configUSE_NEWLIB_REENTRANT 0
  1733. +#endif
  1734. +
  1735. +/* Required if struct _reent is used. */
  1736. +#if ( configUSE_NEWLIB_REENTRANT == 1 )
  1737. + #include <reent.h>
  1738. +#endif
  1739. +
  1740. +/*
  1741. + * Check all the required application specific macros have been defined.
  1742. + * These macros are application specific and (as downloaded) are defined
  1743. + * within FreeRTOSConfig.h.
  1744. + */
  1745. +
  1746. +#ifndef configMINIMAL_STACK_SIZE
  1747. + #error Missing definition: configMINIMAL_STACK_SIZE must be defined in FreeRTOSConfig.h. configMINIMAL_STACK_SIZE defines the size (in words) of the stack allocated to the idle task. Refer to the demo project provided for your port for a suitable value.
  1748. +#endif
  1749. +
  1750. +#ifndef configMAX_PRIORITIES
  1751. + #error Missing definition: configMAX_PRIORITIES must be defined in FreeRTOSConfig.h. See the Configuration section of the FreeRTOS API documentation for details.
  1752. +#endif
  1753. +
  1754. +#if configMAX_PRIORITIES < 1
  1755. + #error configMAX_PRIORITIES must be defined to be greater than or equal to 1.
  1756. +#endif
  1757. +
  1758. +#ifndef configUSE_PREEMPTION
  1759. + #error Missing definition: configUSE_PREEMPTION must be defined in FreeRTOSConfig.h as either 1 or 0. See the Configuration section of the FreeRTOS API documentation for details.
  1760. +#endif
  1761. +
  1762. +#ifndef configUSE_IDLE_HOOK
  1763. + #error Missing definition: configUSE_IDLE_HOOK must be defined in FreeRTOSConfig.h as either 1 or 0. See the Configuration section of the FreeRTOS API documentation for details.
  1764. +#endif
  1765. +
  1766. +#ifndef configUSE_TICK_HOOK
  1767. + #error Missing definition: configUSE_TICK_HOOK must be defined in FreeRTOSConfig.h as either 1 or 0. See the Configuration section of the FreeRTOS API documentation for details.
  1768. +#endif
  1769. +
  1770. +#ifndef configUSE_16_BIT_TICKS
  1771. + #error Missing definition: configUSE_16_BIT_TICKS must be defined in FreeRTOSConfig.h as either 1 or 0. See the Configuration section of the FreeRTOS API documentation for details.
  1772. +#endif
  1773. +
  1774. +#ifndef configUSE_CO_ROUTINES
  1775. + #define configUSE_CO_ROUTINES 0
  1776. +#endif
  1777. +
  1778. +#ifndef INCLUDE_vTaskPrioritySet
  1779. + #define INCLUDE_vTaskPrioritySet 0
  1780. +#endif
  1781. +
  1782. +#ifndef INCLUDE_uxTaskPriorityGet
  1783. + #define INCLUDE_uxTaskPriorityGet 0
  1784. +#endif
  1785. +
  1786. +#ifndef INCLUDE_vTaskDelete
  1787. + #define INCLUDE_vTaskDelete 0
  1788. +#endif
  1789. +
  1790. +#ifndef INCLUDE_vTaskSuspend
  1791. + #define INCLUDE_vTaskSuspend 0
  1792. +#endif
  1793. +
  1794. +#ifdef INCLUDE_xTaskDelayUntil
  1795. + #ifdef INCLUDE_vTaskDelayUntil
  1796. +
  1797. +/* INCLUDE_vTaskDelayUntil was replaced by INCLUDE_xTaskDelayUntil. Backward
  1798. + * compatibility is maintained if only one or the other is defined, but
  1799. + * there is a conflict if both are defined. */
  1800. + #error INCLUDE_vTaskDelayUntil and INCLUDE_xTaskDelayUntil are both defined. INCLUDE_vTaskDelayUntil is no longer required and should be removed
  1801. + #endif
  1802. +#endif
  1803. +
  1804. +#ifndef INCLUDE_xTaskDelayUntil
  1805. + #ifdef INCLUDE_vTaskDelayUntil
  1806. +
  1807. +/* If INCLUDE_vTaskDelayUntil is set but INCLUDE_xTaskDelayUntil is not then
  1808. + * the project's FreeRTOSConfig.h probably pre-dates the introduction of
  1809. + * xTaskDelayUntil and setting INCLUDE_xTaskDelayUntil to whatever
  1810. + * INCLUDE_vTaskDelayUntil is set to will ensure backward compatibility.
  1811. + */
  1812. + #define INCLUDE_xTaskDelayUntil INCLUDE_vTaskDelayUntil
  1813. + #endif
  1814. +#endif
  1815. +
  1816. +#ifndef INCLUDE_xTaskDelayUntil
  1817. + #define INCLUDE_xTaskDelayUntil 0
  1818. +#endif
  1819. +
  1820. +#ifndef INCLUDE_vTaskDelay
  1821. + #define INCLUDE_vTaskDelay 0
  1822. +#endif
  1823. +
  1824. +#ifndef INCLUDE_xTaskGetIdleTaskHandle
  1825. + #define INCLUDE_xTaskGetIdleTaskHandle 0
  1826. +#endif
  1827. +
  1828. +#ifndef INCLUDE_xTaskAbortDelay
  1829. + #define INCLUDE_xTaskAbortDelay 0
  1830. +#endif
  1831. +
  1832. +#ifndef INCLUDE_xQueueGetMutexHolder
  1833. + #define INCLUDE_xQueueGetMutexHolder 0
  1834. +#endif
  1835. +
  1836. +#ifndef INCLUDE_xSemaphoreGetMutexHolder
  1837. + #define INCLUDE_xSemaphoreGetMutexHolder INCLUDE_xQueueGetMutexHolder
  1838. +#endif
  1839. +
  1840. +#ifndef INCLUDE_xTaskGetHandle
  1841. + #define INCLUDE_xTaskGetHandle 0
  1842. +#endif
  1843. +
  1844. +#ifndef INCLUDE_uxTaskGetStackHighWaterMark
  1845. + #define INCLUDE_uxTaskGetStackHighWaterMark 0
  1846. +#endif
  1847. +
  1848. +#ifndef INCLUDE_uxTaskGetStackHighWaterMark2
  1849. + #define INCLUDE_uxTaskGetStackHighWaterMark2 0
  1850. +#endif
  1851. +
  1852. +#ifndef INCLUDE_eTaskGetState
  1853. + #define INCLUDE_eTaskGetState 0
  1854. +#endif
  1855. +
  1856. +#ifndef INCLUDE_xTaskResumeFromISR
  1857. + #define INCLUDE_xTaskResumeFromISR 1
  1858. +#endif
  1859. +
  1860. +#ifndef INCLUDE_xTimerPendFunctionCall
  1861. + #define INCLUDE_xTimerPendFunctionCall 0
  1862. +#endif
  1863. +
  1864. +#ifndef INCLUDE_xTaskGetSchedulerState
  1865. + #define INCLUDE_xTaskGetSchedulerState 0
  1866. +#endif
  1867. +
  1868. +#ifndef INCLUDE_xTaskGetCurrentTaskHandle
  1869. + #define INCLUDE_xTaskGetCurrentTaskHandle 0
  1870. +#endif
  1871. +
  1872. +#if configUSE_CO_ROUTINES != 0
  1873. + #ifndef configMAX_CO_ROUTINE_PRIORITIES
  1874. + #error configMAX_CO_ROUTINE_PRIORITIES must be greater than or equal to 1.
  1875. + #endif
  1876. +#endif
  1877. +
  1878. +#ifndef configUSE_DAEMON_TASK_STARTUP_HOOK
  1879. + #define configUSE_DAEMON_TASK_STARTUP_HOOK 0
  1880. +#endif
  1881. +
  1882. +#ifndef configUSE_APPLICATION_TASK_TAG
  1883. + #define configUSE_APPLICATION_TASK_TAG 0
  1884. +#endif
  1885. +
  1886. +#ifndef configNUM_THREAD_LOCAL_STORAGE_POINTERS
  1887. + #define configNUM_THREAD_LOCAL_STORAGE_POINTERS 0
  1888. +#endif
  1889. +
  1890. +#ifndef configUSE_RECURSIVE_MUTEXES
  1891. + #define configUSE_RECURSIVE_MUTEXES 0
  1892. +#endif
  1893. +
  1894. +#ifndef configUSE_MUTEXES
  1895. + #define configUSE_MUTEXES 0
  1896. +#endif
  1897. +
  1898. +#ifndef configUSE_TIMERS
  1899. + #define configUSE_TIMERS 0
  1900. +#endif
  1901. +
  1902. +#ifndef configUSE_COUNTING_SEMAPHORES
  1903. + #define configUSE_COUNTING_SEMAPHORES 0
  1904. +#endif
  1905. +
  1906. +#ifndef configUSE_ALTERNATIVE_API
  1907. + #define configUSE_ALTERNATIVE_API 0
  1908. +#endif
  1909. +
  1910. +#ifndef portCRITICAL_NESTING_IN_TCB
  1911. + #define portCRITICAL_NESTING_IN_TCB 0
  1912. +#endif
  1913. +
  1914. +#ifndef configMAX_TASK_NAME_LEN
  1915. + #define configMAX_TASK_NAME_LEN 16
  1916. +#endif
  1917. +
  1918. +#ifndef configIDLE_SHOULD_YIELD
  1919. + #define configIDLE_SHOULD_YIELD 1
  1920. +#endif
  1921. +
  1922. +#if configMAX_TASK_NAME_LEN < 1
  1923. + #error configMAX_TASK_NAME_LEN must be set to a minimum of 1 in FreeRTOSConfig.h
  1924. +#endif
  1925. +
  1926. +#ifndef configASSERT
  1927. + #define configASSERT( x )
  1928. + #define configASSERT_DEFINED 0
  1929. +#else
  1930. + #define configASSERT_DEFINED 1
  1931. +#endif
  1932. +
  1933. +/* configPRECONDITION should be defined as configASSERT.
  1934. + * The CBMC proofs need a way to track assumptions and assertions.
  1935. + * A configPRECONDITION statement should express an implicit invariant or
  1936. + * assumption made. A configASSERT statement should express an invariant that must
  1937. + * hold explicit before calling the code. */
  1938. +#ifndef configPRECONDITION
  1939. + #define configPRECONDITION( X ) configASSERT( X )
  1940. + #define configPRECONDITION_DEFINED 0
  1941. +#else
  1942. + #define configPRECONDITION_DEFINED 1
  1943. +#endif
  1944. +
  1945. +#ifndef portMEMORY_BARRIER
  1946. + #define portMEMORY_BARRIER()
  1947. +#endif
  1948. +
  1949. +#ifndef portSOFTWARE_BARRIER
  1950. + #define portSOFTWARE_BARRIER()
  1951. +#endif
  1952. +
  1953. +/* The timers module relies on xTaskGetSchedulerState(). */
  1954. +#if configUSE_TIMERS == 1
  1955. +
  1956. + #ifndef configTIMER_TASK_PRIORITY
  1957. + #error If configUSE_TIMERS is set to 1 then configTIMER_TASK_PRIORITY must also be defined.
  1958. + #endif /* configTIMER_TASK_PRIORITY */
  1959. +
  1960. + #ifndef configTIMER_QUEUE_LENGTH
  1961. + #error If configUSE_TIMERS is set to 1 then configTIMER_QUEUE_LENGTH must also be defined.
  1962. + #endif /* configTIMER_QUEUE_LENGTH */
  1963. +
  1964. + #ifndef configTIMER_TASK_STACK_DEPTH
  1965. + #error If configUSE_TIMERS is set to 1 then configTIMER_TASK_STACK_DEPTH must also be defined.
  1966. + #endif /* configTIMER_TASK_STACK_DEPTH */
  1967. +
  1968. +#endif /* configUSE_TIMERS */
  1969. +
  1970. +#ifndef portSET_INTERRUPT_MASK_FROM_ISR
  1971. + #define portSET_INTERRUPT_MASK_FROM_ISR() 0
  1972. +#endif
  1973. +
  1974. +#ifndef portCLEAR_INTERRUPT_MASK_FROM_ISR
  1975. + #define portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedStatusValue ) ( void ) uxSavedStatusValue
  1976. +#endif
  1977. +
  1978. +#ifndef portCLEAN_UP_TCB
  1979. + #define portCLEAN_UP_TCB( pxTCB ) ( void ) pxTCB
  1980. +#endif
  1981. +
  1982. +#ifndef portPRE_TASK_DELETE_HOOK
  1983. + #define portPRE_TASK_DELETE_HOOK( pvTaskToDelete, pxYieldPending )
  1984. +#endif
  1985. +
  1986. +#ifndef portSETUP_TCB
  1987. + #define portSETUP_TCB( pxTCB ) ( void ) pxTCB
  1988. +#endif
  1989. +
  1990. +#ifndef configQUEUE_REGISTRY_SIZE
  1991. + #define configQUEUE_REGISTRY_SIZE 0U
  1992. +#endif
  1993. +
  1994. +#if ( configQUEUE_REGISTRY_SIZE < 1 )
  1995. + #define vQueueAddToRegistry( xQueue, pcName )
  1996. + #define vQueueUnregisterQueue( xQueue )
  1997. + #define pcQueueGetName( xQueue )
  1998. +#endif
  1999. +
  2000. +#ifndef portPOINTER_SIZE_TYPE
  2001. + #define portPOINTER_SIZE_TYPE uint32_t
  2002. +#endif
  2003. +
  2004. +/* Remove any unused trace macros. */
  2005. +#ifndef traceSTART
  2006. +
  2007. +/* Used to perform any necessary initialisation - for example, open a file
  2008. + * into which trace is to be written. */
  2009. + #define traceSTART()
  2010. +#endif
  2011. +
  2012. +#ifndef traceEND
  2013. +
  2014. +/* Use to close a trace, for example close a file into which trace has been
  2015. + * written. */
  2016. + #define traceEND()
  2017. +#endif
  2018. +
  2019. +#ifndef traceTASK_SWITCHED_IN
  2020. +
  2021. +/* Called after a task has been selected to run. pxCurrentTCB holds a pointer
  2022. + * to the task control block of the selected task. */
  2023. + #define traceTASK_SWITCHED_IN()
  2024. +#endif
  2025. +
  2026. +#ifndef traceINCREASE_TICK_COUNT
  2027. +
  2028. +/* Called before stepping the tick count after waking from tickless idle
  2029. + * sleep. */
  2030. + #define traceINCREASE_TICK_COUNT( x )
  2031. +#endif
  2032. +
  2033. +#ifndef traceLOW_POWER_IDLE_BEGIN
  2034. + /* Called immediately before entering tickless idle. */
  2035. + #define traceLOW_POWER_IDLE_BEGIN()
  2036. +#endif
  2037. +
  2038. +#ifndef traceLOW_POWER_IDLE_END
  2039. + /* Called when returning to the Idle task after a tickless idle. */
  2040. + #define traceLOW_POWER_IDLE_END()
  2041. +#endif
  2042. +
  2043. +#ifndef traceTASK_SWITCHED_OUT
  2044. +
  2045. +/* Called before a task has been selected to run. pxCurrentTCB holds a pointer
  2046. + * to the task control block of the task being switched out. */
  2047. + #define traceTASK_SWITCHED_OUT()
  2048. +#endif
  2049. +
  2050. +#ifndef traceTASK_PRIORITY_INHERIT
  2051. +
  2052. +/* Called when a task attempts to take a mutex that is already held by a
  2053. + * lower priority task. pxTCBOfMutexHolder is a pointer to the TCB of the task
  2054. + * that holds the mutex. uxInheritedPriority is the priority the mutex holder
  2055. + * will inherit (the priority of the task that is attempting to obtain the
  2056. + * muted. */
  2057. + #define traceTASK_PRIORITY_INHERIT( pxTCBOfMutexHolder, uxInheritedPriority )
  2058. +#endif
  2059. +
  2060. +#ifndef traceTASK_PRIORITY_DISINHERIT
  2061. +
  2062. +/* Called when a task releases a mutex, the holding of which had resulted in
  2063. + * the task inheriting the priority of a higher priority task.
  2064. + * pxTCBOfMutexHolder is a pointer to the TCB of the task that is releasing the
  2065. + * mutex. uxOriginalPriority is the task's configured (base) priority. */
  2066. + #define traceTASK_PRIORITY_DISINHERIT( pxTCBOfMutexHolder, uxOriginalPriority )
  2067. +#endif
  2068. +
  2069. +#ifndef traceBLOCKING_ON_QUEUE_RECEIVE
  2070. +
  2071. +/* Task is about to block because it cannot read from a
  2072. + * queue/mutex/semaphore. pxQueue is a pointer to the queue/mutex/semaphore
  2073. + * upon which the read was attempted. pxCurrentTCB points to the TCB of the
  2074. + * task that attempted the read. */
  2075. + #define traceBLOCKING_ON_QUEUE_RECEIVE( pxQueue )
  2076. +#endif
  2077. +
  2078. +#ifndef traceBLOCKING_ON_QUEUE_PEEK
  2079. +
  2080. +/* Task is about to block because it cannot read from a
  2081. + * queue/mutex/semaphore. pxQueue is a pointer to the queue/mutex/semaphore
  2082. + * upon which the read was attempted. pxCurrentTCB points to the TCB of the
  2083. + * task that attempted the read. */
  2084. + #define traceBLOCKING_ON_QUEUE_PEEK( pxQueue )
  2085. +#endif
  2086. +
  2087. +#ifndef traceBLOCKING_ON_QUEUE_SEND
  2088. +
  2089. +/* Task is about to block because it cannot write to a
  2090. + * queue/mutex/semaphore. pxQueue is a pointer to the queue/mutex/semaphore
  2091. + * upon which the write was attempted. pxCurrentTCB points to the TCB of the
  2092. + * task that attempted the write. */
  2093. + #define traceBLOCKING_ON_QUEUE_SEND( pxQueue )
  2094. +#endif
  2095. +
  2096. +#ifndef configCHECK_FOR_STACK_OVERFLOW
  2097. + #define configCHECK_FOR_STACK_OVERFLOW 0
  2098. +#endif
  2099. +
  2100. +#ifndef configRECORD_STACK_HIGH_ADDRESS
  2101. + #define configRECORD_STACK_HIGH_ADDRESS 0
  2102. +#endif
  2103. +
  2104. +#ifndef configINCLUDE_FREERTOS_TASK_C_ADDITIONS_H
  2105. + #define configINCLUDE_FREERTOS_TASK_C_ADDITIONS_H 0
  2106. +#endif
  2107. +
  2108. +/* The following event macros are embedded in the kernel API calls. */
  2109. +
  2110. +#ifndef traceMOVED_TASK_TO_READY_STATE
  2111. + #define traceMOVED_TASK_TO_READY_STATE( pxTCB )
  2112. +#endif
  2113. +
  2114. +#ifndef tracePOST_MOVED_TASK_TO_READY_STATE
  2115. + #define tracePOST_MOVED_TASK_TO_READY_STATE( pxTCB )
  2116. +#endif
  2117. +
  2118. +#ifndef traceQUEUE_CREATE
  2119. + #define traceQUEUE_CREATE( pxNewQueue )
  2120. +#endif
  2121. +
  2122. +#ifndef traceQUEUE_CREATE_FAILED
  2123. + #define traceQUEUE_CREATE_FAILED( ucQueueType )
  2124. +#endif
  2125. +
  2126. +#ifndef traceCREATE_MUTEX
  2127. + #define traceCREATE_MUTEX( pxNewQueue )
  2128. +#endif
  2129. +
  2130. +#ifndef traceCREATE_MUTEX_FAILED
  2131. + #define traceCREATE_MUTEX_FAILED()
  2132. +#endif
  2133. +
  2134. +#ifndef traceGIVE_MUTEX_RECURSIVE
  2135. + #define traceGIVE_MUTEX_RECURSIVE( pxMutex )
  2136. +#endif
  2137. +
  2138. +#ifndef traceGIVE_MUTEX_RECURSIVE_FAILED
  2139. + #define traceGIVE_MUTEX_RECURSIVE_FAILED( pxMutex )
  2140. +#endif
  2141. +
  2142. +#ifndef traceTAKE_MUTEX_RECURSIVE
  2143. + #define traceTAKE_MUTEX_RECURSIVE( pxMutex )
  2144. +#endif
  2145. +
  2146. +#ifndef traceTAKE_MUTEX_RECURSIVE_FAILED
  2147. + #define traceTAKE_MUTEX_RECURSIVE_FAILED( pxMutex )
  2148. +#endif
  2149. +
  2150. +#ifndef traceCREATE_COUNTING_SEMAPHORE
  2151. + #define traceCREATE_COUNTING_SEMAPHORE()
  2152. +#endif
  2153. +
  2154. +#ifndef traceCREATE_COUNTING_SEMAPHORE_FAILED
  2155. + #define traceCREATE_COUNTING_SEMAPHORE_FAILED()
  2156. +#endif
  2157. +
  2158. +#ifndef traceQUEUE_SET_SEND
  2159. + #define traceQUEUE_SET_SEND traceQUEUE_SEND
  2160. +#endif
  2161. +
  2162. +#ifndef traceQUEUE_SEND
  2163. + #define traceQUEUE_SEND( pxQueue )
  2164. +#endif
  2165. +
  2166. +#ifndef traceQUEUE_SEND_FAILED
  2167. + #define traceQUEUE_SEND_FAILED( pxQueue )
  2168. +#endif
  2169. +
  2170. +#ifndef traceQUEUE_RECEIVE
  2171. + #define traceQUEUE_RECEIVE( pxQueue )
  2172. +#endif
  2173. +
  2174. +#ifndef traceQUEUE_PEEK
  2175. + #define traceQUEUE_PEEK( pxQueue )
  2176. +#endif
  2177. +
  2178. +#ifndef traceQUEUE_PEEK_FAILED
  2179. + #define traceQUEUE_PEEK_FAILED( pxQueue )
  2180. +#endif
  2181. +
  2182. +#ifndef traceQUEUE_PEEK_FROM_ISR
  2183. + #define traceQUEUE_PEEK_FROM_ISR( pxQueue )
  2184. +#endif
  2185. +
  2186. +#ifndef traceQUEUE_RECEIVE_FAILED
  2187. + #define traceQUEUE_RECEIVE_FAILED( pxQueue )
  2188. +#endif
  2189. +
  2190. +#ifndef traceQUEUE_SEND_FROM_ISR
  2191. + #define traceQUEUE_SEND_FROM_ISR( pxQueue )
  2192. +#endif
  2193. +
  2194. +#ifndef traceQUEUE_SEND_FROM_ISR_FAILED
  2195. + #define traceQUEUE_SEND_FROM_ISR_FAILED( pxQueue )
  2196. +#endif
  2197. +
  2198. +#ifndef traceQUEUE_RECEIVE_FROM_ISR
  2199. + #define traceQUEUE_RECEIVE_FROM_ISR( pxQueue )
  2200. +#endif
  2201. +
  2202. +#ifndef traceQUEUE_RECEIVE_FROM_ISR_FAILED
  2203. + #define traceQUEUE_RECEIVE_FROM_ISR_FAILED( pxQueue )
  2204. +#endif
  2205. +
  2206. +#ifndef traceQUEUE_PEEK_FROM_ISR_FAILED
  2207. + #define traceQUEUE_PEEK_FROM_ISR_FAILED( pxQueue )
  2208. +#endif
  2209. +
  2210. +#ifndef traceQUEUE_DELETE
  2211. + #define traceQUEUE_DELETE( pxQueue )
  2212. +#endif
  2213. +
  2214. +#ifndef traceTASK_CREATE
  2215. + #define traceTASK_CREATE( pxNewTCB )
  2216. +#endif
  2217. +
  2218. +#ifndef traceTASK_CREATE_FAILED
  2219. + #define traceTASK_CREATE_FAILED()
  2220. +#endif
  2221. +
  2222. +#ifndef traceTASK_DELETE
  2223. + #define traceTASK_DELETE( pxTaskToDelete )
  2224. +#endif
  2225. +
  2226. +#ifndef traceTASK_DELAY_UNTIL
  2227. + #define traceTASK_DELAY_UNTIL( x )
  2228. +#endif
  2229. +
  2230. +#ifndef traceTASK_DELAY
  2231. + #define traceTASK_DELAY()
  2232. +#endif
  2233. +
  2234. +#ifndef traceTASK_PRIORITY_SET
  2235. + #define traceTASK_PRIORITY_SET( pxTask, uxNewPriority )
  2236. +#endif
  2237. +
  2238. +#ifndef traceTASK_SUSPEND
  2239. + #define traceTASK_SUSPEND( pxTaskToSuspend )
  2240. +#endif
  2241. +
  2242. +#ifndef traceTASK_RESUME
  2243. + #define traceTASK_RESUME( pxTaskToResume )
  2244. +#endif
  2245. +
  2246. +#ifndef traceTASK_RESUME_FROM_ISR
  2247. + #define traceTASK_RESUME_FROM_ISR( pxTaskToResume )
  2248. +#endif
  2249. +
  2250. +#ifndef traceTASK_INCREMENT_TICK
  2251. + #define traceTASK_INCREMENT_TICK( xTickCount )
  2252. +#endif
  2253. +
  2254. +#ifndef traceTIMER_CREATE
  2255. + #define traceTIMER_CREATE( pxNewTimer )
  2256. +#endif
  2257. +
  2258. +#ifndef traceTIMER_CREATE_FAILED
  2259. + #define traceTIMER_CREATE_FAILED()
  2260. +#endif
  2261. +
  2262. +#ifndef traceTIMER_COMMAND_SEND
  2263. + #define traceTIMER_COMMAND_SEND( xTimer, xMessageID, xMessageValueValue, xReturn )
  2264. +#endif
  2265. +
  2266. +#ifndef traceTIMER_EXPIRED
  2267. + #define traceTIMER_EXPIRED( pxTimer )
  2268. +#endif
  2269. +
  2270. +#ifndef traceTIMER_COMMAND_RECEIVED
  2271. + #define traceTIMER_COMMAND_RECEIVED( pxTimer, xMessageID, xMessageValue )
  2272. +#endif
  2273. +
  2274. +#ifndef traceMALLOC
  2275. + #define traceMALLOC( pvAddress, uiSize )
  2276. +#endif
  2277. +
  2278. +#ifndef traceFREE
  2279. + #define traceFREE( pvAddress, uiSize )
  2280. +#endif
  2281. +
  2282. +#ifndef traceEVENT_GROUP_CREATE
  2283. + #define traceEVENT_GROUP_CREATE( xEventGroup )
  2284. +#endif
  2285. +
  2286. +#ifndef traceEVENT_GROUP_CREATE_FAILED
  2287. + #define traceEVENT_GROUP_CREATE_FAILED()
  2288. +#endif
  2289. +
  2290. +#ifndef traceEVENT_GROUP_SYNC_BLOCK
  2291. + #define traceEVENT_GROUP_SYNC_BLOCK( xEventGroup, uxBitsToSet, uxBitsToWaitFor )
  2292. +#endif
  2293. +
  2294. +#ifndef traceEVENT_GROUP_SYNC_END
  2295. + #define traceEVENT_GROUP_SYNC_END( xEventGroup, uxBitsToSet, uxBitsToWaitFor, xTimeoutOccurred ) ( void ) xTimeoutOccurred
  2296. +#endif
  2297. +
  2298. +#ifndef traceEVENT_GROUP_WAIT_BITS_BLOCK
  2299. + #define traceEVENT_GROUP_WAIT_BITS_BLOCK( xEventGroup, uxBitsToWaitFor )
  2300. +#endif
  2301. +
  2302. +#ifndef traceEVENT_GROUP_WAIT_BITS_END
  2303. + #define traceEVENT_GROUP_WAIT_BITS_END( xEventGroup, uxBitsToWaitFor, xTimeoutOccurred ) ( void ) xTimeoutOccurred
  2304. +#endif
  2305. +
  2306. +#ifndef traceEVENT_GROUP_CLEAR_BITS
  2307. + #define traceEVENT_GROUP_CLEAR_BITS( xEventGroup, uxBitsToClear )
  2308. +#endif
  2309. +
  2310. +#ifndef traceEVENT_GROUP_CLEAR_BITS_FROM_ISR
  2311. + #define traceEVENT_GROUP_CLEAR_BITS_FROM_ISR( xEventGroup, uxBitsToClear )
  2312. +#endif
  2313. +
  2314. +#ifndef traceEVENT_GROUP_SET_BITS
  2315. + #define traceEVENT_GROUP_SET_BITS( xEventGroup, uxBitsToSet )
  2316. +#endif
  2317. +
  2318. +#ifndef traceEVENT_GROUP_SET_BITS_FROM_ISR
  2319. + #define traceEVENT_GROUP_SET_BITS_FROM_ISR( xEventGroup, uxBitsToSet )
  2320. +#endif
  2321. +
  2322. +#ifndef traceEVENT_GROUP_DELETE
  2323. + #define traceEVENT_GROUP_DELETE( xEventGroup )
  2324. +#endif
  2325. +
  2326. +#ifndef tracePEND_FUNC_CALL
  2327. + #define tracePEND_FUNC_CALL( xFunctionToPend, pvParameter1, ulParameter2, ret )
  2328. +#endif
  2329. +
  2330. +#ifndef tracePEND_FUNC_CALL_FROM_ISR
  2331. + #define tracePEND_FUNC_CALL_FROM_ISR( xFunctionToPend, pvParameter1, ulParameter2, ret )
  2332. +#endif
  2333. +
  2334. +#ifndef traceQUEUE_REGISTRY_ADD
  2335. + #define traceQUEUE_REGISTRY_ADD( xQueue, pcQueueName )
  2336. +#endif
  2337. +
  2338. +#ifndef traceTASK_NOTIFY_TAKE_BLOCK
  2339. + #define traceTASK_NOTIFY_TAKE_BLOCK( uxIndexToWait )
  2340. +#endif
  2341. +
  2342. +#ifndef traceTASK_NOTIFY_TAKE
  2343. + #define traceTASK_NOTIFY_TAKE( uxIndexToWait )
  2344. +#endif
  2345. +
  2346. +#ifndef traceTASK_NOTIFY_WAIT_BLOCK
  2347. + #define traceTASK_NOTIFY_WAIT_BLOCK( uxIndexToWait )
  2348. +#endif
  2349. +
  2350. +#ifndef traceTASK_NOTIFY_WAIT
  2351. + #define traceTASK_NOTIFY_WAIT( uxIndexToWait )
  2352. +#endif
  2353. +
  2354. +#ifndef traceTASK_NOTIFY
  2355. + #define traceTASK_NOTIFY( uxIndexToNotify )
  2356. +#endif
  2357. +
  2358. +#ifndef traceTASK_NOTIFY_FROM_ISR
  2359. + #define traceTASK_NOTIFY_FROM_ISR( uxIndexToNotify )
  2360. +#endif
  2361. +
  2362. +#ifndef traceTASK_NOTIFY_GIVE_FROM_ISR
  2363. + #define traceTASK_NOTIFY_GIVE_FROM_ISR( uxIndexToNotify )
  2364. +#endif
  2365. +
  2366. +#ifndef traceSTREAM_BUFFER_CREATE_FAILED
  2367. + #define traceSTREAM_BUFFER_CREATE_FAILED( xIsMessageBuffer )
  2368. +#endif
  2369. +
  2370. +#ifndef traceSTREAM_BUFFER_CREATE_STATIC_FAILED
  2371. + #define traceSTREAM_BUFFER_CREATE_STATIC_FAILED( xReturn, xIsMessageBuffer )
  2372. +#endif
  2373. +
  2374. +#ifndef traceSTREAM_BUFFER_CREATE
  2375. + #define traceSTREAM_BUFFER_CREATE( pxStreamBuffer, xIsMessageBuffer )
  2376. +#endif
  2377. +
  2378. +#ifndef traceSTREAM_BUFFER_DELETE
  2379. + #define traceSTREAM_BUFFER_DELETE( xStreamBuffer )
  2380. +#endif
  2381. +
  2382. +#ifndef traceSTREAM_BUFFER_RESET
  2383. + #define traceSTREAM_BUFFER_RESET( xStreamBuffer )
  2384. +#endif
  2385. +
  2386. +#ifndef traceBLOCKING_ON_STREAM_BUFFER_SEND
  2387. + #define traceBLOCKING_ON_STREAM_BUFFER_SEND( xStreamBuffer )
  2388. +#endif
  2389. +
  2390. +#ifndef traceSTREAM_BUFFER_SEND
  2391. + #define traceSTREAM_BUFFER_SEND( xStreamBuffer, xBytesSent )
  2392. +#endif
  2393. +
  2394. +#ifndef traceSTREAM_BUFFER_SEND_FAILED
  2395. + #define traceSTREAM_BUFFER_SEND_FAILED( xStreamBuffer )
  2396. +#endif
  2397. +
  2398. +#ifndef traceSTREAM_BUFFER_SEND_FROM_ISR
  2399. + #define traceSTREAM_BUFFER_SEND_FROM_ISR( xStreamBuffer, xBytesSent )
  2400. +#endif
  2401. +
  2402. +#ifndef traceBLOCKING_ON_STREAM_BUFFER_RECEIVE
  2403. + #define traceBLOCKING_ON_STREAM_BUFFER_RECEIVE( xStreamBuffer )
  2404. +#endif
  2405. +
  2406. +#ifndef traceSTREAM_BUFFER_RECEIVE
  2407. + #define traceSTREAM_BUFFER_RECEIVE( xStreamBuffer, xReceivedLength )
  2408. +#endif
  2409. +
  2410. +#ifndef traceSTREAM_BUFFER_RECEIVE_FAILED
  2411. + #define traceSTREAM_BUFFER_RECEIVE_FAILED( xStreamBuffer )
  2412. +#endif
  2413. +
  2414. +#ifndef traceSTREAM_BUFFER_RECEIVE_FROM_ISR
  2415. + #define traceSTREAM_BUFFER_RECEIVE_FROM_ISR( xStreamBuffer, xReceivedLength )
  2416. +#endif
  2417. +
  2418. +#ifdef ESP_PLATFORM
  2419. +#ifndef traceISR_EXIT_TO_SCHEDULER
  2420. + #define traceISR_EXIT_TO_SCHEDULER()
  2421. +#endif
  2422. +
  2423. +#ifndef traceISR_EXIT
  2424. + #define traceISR_EXIT()
  2425. +#endif
  2426. +
  2427. +#ifndef traceISR_ENTER
  2428. + #define traceISR_ENTER(_n_)
  2429. +#endif
  2430. +#endif // ESP_PLATFORM
  2431. +
  2432. +#ifndef configGENERATE_RUN_TIME_STATS
  2433. + #define configGENERATE_RUN_TIME_STATS 0
  2434. +#endif
  2435. +
  2436. +#if ( configGENERATE_RUN_TIME_STATS == 1 )
  2437. +
  2438. + #ifndef portCONFIGURE_TIMER_FOR_RUN_TIME_STATS
  2439. + #error If configGENERATE_RUN_TIME_STATS is defined then portCONFIGURE_TIMER_FOR_RUN_TIME_STATS must also be defined. portCONFIGURE_TIMER_FOR_RUN_TIME_STATS should call a port layer function to setup a peripheral timer/counter that can then be used as the run time counter time base.
  2440. + #endif /* portCONFIGURE_TIMER_FOR_RUN_TIME_STATS */
  2441. +
  2442. + #ifndef portGET_RUN_TIME_COUNTER_VALUE
  2443. + #ifndef portALT_GET_RUN_TIME_COUNTER_VALUE
  2444. + #error If configGENERATE_RUN_TIME_STATS is defined then either portGET_RUN_TIME_COUNTER_VALUE or portALT_GET_RUN_TIME_COUNTER_VALUE must also be defined. See the examples provided and the FreeRTOS web site for more information.
  2445. + #endif /* portALT_GET_RUN_TIME_COUNTER_VALUE */
  2446. + #endif /* portGET_RUN_TIME_COUNTER_VALUE */
  2447. +
  2448. +#endif /* configGENERATE_RUN_TIME_STATS */
  2449. +
  2450. +#ifndef portCONFIGURE_TIMER_FOR_RUN_TIME_STATS
  2451. + #define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS()
  2452. +#endif
  2453. +
  2454. +#ifndef configUSE_MALLOC_FAILED_HOOK
  2455. + #define configUSE_MALLOC_FAILED_HOOK 0
  2456. +#endif
  2457. +
  2458. +#ifndef portPRIVILEGE_BIT
  2459. + #define portPRIVILEGE_BIT ( ( UBaseType_t ) 0x00 )
  2460. +#endif
  2461. +
  2462. +#ifndef portYIELD_WITHIN_API
  2463. + #define portYIELD_WITHIN_API portYIELD
  2464. +#endif
  2465. +
  2466. +#ifndef portSUPPRESS_TICKS_AND_SLEEP
  2467. + #define portSUPPRESS_TICKS_AND_SLEEP( xExpectedIdleTime )
  2468. +#endif
  2469. +
  2470. +#ifndef configEXPECTED_IDLE_TIME_BEFORE_SLEEP
  2471. + #define configEXPECTED_IDLE_TIME_BEFORE_SLEEP 2
  2472. +#endif
  2473. +
  2474. +#if configEXPECTED_IDLE_TIME_BEFORE_SLEEP < 2
  2475. + #error configEXPECTED_IDLE_TIME_BEFORE_SLEEP must not be less than 2
  2476. +#endif
  2477. +
  2478. +#ifndef configUSE_TICKLESS_IDLE
  2479. + #define configUSE_TICKLESS_IDLE 0
  2480. +#endif
  2481. +
  2482. +#ifndef configPRE_SUPPRESS_TICKS_AND_SLEEP_PROCESSING
  2483. + #define configPRE_SUPPRESS_TICKS_AND_SLEEP_PROCESSING( x )
  2484. +#endif
  2485. +
  2486. +#ifndef configPRE_SLEEP_PROCESSING
  2487. + #define configPRE_SLEEP_PROCESSING( x )
  2488. +#endif
  2489. +
  2490. +#ifndef configPOST_SLEEP_PROCESSING
  2491. + #define configPOST_SLEEP_PROCESSING( x )
  2492. +#endif
  2493. +
  2494. +#ifndef configUSE_QUEUE_SETS
  2495. + #define configUSE_QUEUE_SETS 0
  2496. +#endif
  2497. +
  2498. +#ifndef portTASK_USES_FLOATING_POINT
  2499. + #define portTASK_USES_FLOATING_POINT()
  2500. +#endif
  2501. +
  2502. +#ifndef portALLOCATE_SECURE_CONTEXT
  2503. + #define portALLOCATE_SECURE_CONTEXT( ulSecureStackSize )
  2504. +#endif
  2505. +
  2506. +#ifndef portDONT_DISCARD
  2507. + #define portDONT_DISCARD
  2508. +#endif
  2509. +
  2510. +#ifndef configUSE_TIME_SLICING
  2511. + #define configUSE_TIME_SLICING 1
  2512. +#endif
  2513. +
  2514. +#ifndef configINCLUDE_APPLICATION_DEFINED_PRIVILEGED_FUNCTIONS
  2515. + #define configINCLUDE_APPLICATION_DEFINED_PRIVILEGED_FUNCTIONS 0
  2516. +#endif
  2517. +
  2518. +#ifndef configUSE_STATS_FORMATTING_FUNCTIONS
  2519. + #define configUSE_STATS_FORMATTING_FUNCTIONS 0
  2520. +#endif
  2521. +
  2522. +#ifndef portASSERT_IF_INTERRUPT_PRIORITY_INVALID
  2523. + #define portASSERT_IF_INTERRUPT_PRIORITY_INVALID()
  2524. +#endif
  2525. +
  2526. +#ifndef configUSE_TRACE_FACILITY
  2527. + #define configUSE_TRACE_FACILITY 0
  2528. +#endif
  2529. +
  2530. +#ifndef mtCOVERAGE_TEST_MARKER
  2531. + #define mtCOVERAGE_TEST_MARKER()
  2532. +#endif
  2533. +
  2534. +#ifndef mtCOVERAGE_TEST_DELAY
  2535. + #define mtCOVERAGE_TEST_DELAY()
  2536. +#endif
  2537. +
  2538. +#ifndef portASSERT_IF_IN_ISR
  2539. + #define portASSERT_IF_IN_ISR()
  2540. +#endif
  2541. +
  2542. +#ifndef configUSE_PORT_OPTIMISED_TASK_SELECTION
  2543. + #define configUSE_PORT_OPTIMISED_TASK_SELECTION 0
  2544. +#endif
  2545. +
  2546. +#ifndef configAPPLICATION_ALLOCATED_HEAP
  2547. + #define configAPPLICATION_ALLOCATED_HEAP 0
  2548. +#endif
  2549. +
  2550. +#ifndef configUSE_TASK_NOTIFICATIONS
  2551. + #define configUSE_TASK_NOTIFICATIONS 1
  2552. +#endif
  2553. +
  2554. +#ifndef configTASK_NOTIFICATION_ARRAY_ENTRIES
  2555. + #define configTASK_NOTIFICATION_ARRAY_ENTRIES 1
  2556. +#endif
  2557. +
  2558. +#if configTASK_NOTIFICATION_ARRAY_ENTRIES < 1
  2559. + #error configTASK_NOTIFICATION_ARRAY_ENTRIES must be at least 1
  2560. +#endif
  2561. +
  2562. +#ifndef configUSE_POSIX_ERRNO
  2563. + #define configUSE_POSIX_ERRNO 0
  2564. +#endif
  2565. +
  2566. +#ifndef portTICK_TYPE_IS_ATOMIC
  2567. + #define portTICK_TYPE_IS_ATOMIC 0
  2568. +#endif
  2569. +
  2570. +#ifndef configSUPPORT_STATIC_ALLOCATION
  2571. + /* Defaults to 0 for backward compatibility. */
  2572. + #define configSUPPORT_STATIC_ALLOCATION 0
  2573. +#endif
  2574. +
  2575. +#ifndef configSUPPORT_DYNAMIC_ALLOCATION
  2576. + /* Defaults to 1 for backward compatibility. */
  2577. + #define configSUPPORT_DYNAMIC_ALLOCATION 1
  2578. +#endif
  2579. +
  2580. +#ifndef configSTACK_DEPTH_TYPE
  2581. +
  2582. +/* Defaults to uint16_t for backward compatibility, but can be overridden
  2583. + * in FreeRTOSConfig.h if uint16_t is too restrictive. */
  2584. + #define configSTACK_DEPTH_TYPE uint16_t
  2585. +#endif
  2586. +
  2587. +#ifndef configRUN_TIME_COUNTER_TYPE
  2588. +
  2589. +/* Defaults to uint32_t for backward compatibility, but can be overridden in
  2590. + * FreeRTOSConfig.h if uint32_t is too restrictive. */
  2591. +
  2592. + #define configRUN_TIME_COUNTER_TYPE uint32_t
  2593. +#endif
  2594. +
  2595. +#ifndef configMESSAGE_BUFFER_LENGTH_TYPE
  2596. +
  2597. +/* Defaults to size_t for backward compatibility, but can be overridden
  2598. + * in FreeRTOSConfig.h if lengths will always be less than the number of bytes
  2599. + * in a size_t. */
  2600. + #define configMESSAGE_BUFFER_LENGTH_TYPE size_t
  2601. +#endif
  2602. +
  2603. +/* Sanity check the configuration. */
  2604. +#if ( configUSE_TICKLESS_IDLE != 0 )
  2605. + #if ( INCLUDE_vTaskSuspend != 1 )
  2606. + #error INCLUDE_vTaskSuspend must be set to 1 if configUSE_TICKLESS_IDLE is not set to 0
  2607. + #endif /* INCLUDE_vTaskSuspend */
  2608. +#endif /* configUSE_TICKLESS_IDLE */
  2609. +
  2610. +#if ( ( configSUPPORT_STATIC_ALLOCATION == 0 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 0 ) )
  2611. + #error configSUPPORT_STATIC_ALLOCATION and configSUPPORT_DYNAMIC_ALLOCATION cannot both be 0, but can both be 1.
  2612. +#endif
  2613. +
  2614. +#if ( ( configUSE_RECURSIVE_MUTEXES == 1 ) && ( configUSE_MUTEXES != 1 ) )
  2615. + #error configUSE_MUTEXES must be set to 1 to use recursive mutexes
  2616. +#endif
  2617. +
  2618. +#ifndef configINITIAL_TICK_COUNT
  2619. + #define configINITIAL_TICK_COUNT 0
  2620. +#endif
  2621. +
  2622. +#if ( portTICK_TYPE_IS_ATOMIC == 0 )
  2623. +
  2624. +/* Either variables of tick type cannot be read atomically, or
  2625. + * portTICK_TYPE_IS_ATOMIC was not set - map the critical sections used when
  2626. + * the tick count is returned to the standard critical section macros. */
  2627. + #define portTICK_TYPE_ENTER_CRITICAL() portENTER_CRITICAL()
  2628. + #define portTICK_TYPE_EXIT_CRITICAL() portEXIT_CRITICAL()
  2629. + #define portTICK_TYPE_SET_INTERRUPT_MASK_FROM_ISR() portSET_INTERRUPT_MASK_FROM_ISR()
  2630. + #define portTICK_TYPE_CLEAR_INTERRUPT_MASK_FROM_ISR( x ) portCLEAR_INTERRUPT_MASK_FROM_ISR( ( x ) )
  2631. +#else
  2632. +
  2633. +/* The tick type can be read atomically, so critical sections used when the
  2634. + * tick count is returned can be defined away. */
  2635. + #define portTICK_TYPE_ENTER_CRITICAL()
  2636. + #define portTICK_TYPE_EXIT_CRITICAL()
  2637. + #define portTICK_TYPE_SET_INTERRUPT_MASK_FROM_ISR() 0
  2638. + #define portTICK_TYPE_CLEAR_INTERRUPT_MASK_FROM_ISR( x ) ( void ) x
  2639. +#endif /* if ( portTICK_TYPE_IS_ATOMIC == 0 ) */
  2640. +
  2641. +/* Definitions to allow backward compatibility with FreeRTOS versions prior to
  2642. + * V8 if desired. */
  2643. +#ifndef configENABLE_BACKWARD_COMPATIBILITY
  2644. + #define configENABLE_BACKWARD_COMPATIBILITY 1
  2645. +#endif
  2646. +
  2647. +#ifndef configPRINTF
  2648. +
  2649. +/* configPRINTF() was not defined, so define it away to nothing. To use
  2650. + * configPRINTF() then define it as follows (where MyPrintFunction() is
  2651. + * provided by the application writer):
  2652. + *
  2653. + * void MyPrintFunction(const char *pcFormat, ... );
  2654. + #define configPRINTF( X ) MyPrintFunction X
  2655. + *
  2656. + * Then call like a standard printf() function, but placing brackets around
  2657. + * all parameters so they are passed as a single parameter. For example:
  2658. + * configPRINTF( ("Value = %d", MyVariable) ); */
  2659. + #define configPRINTF( X )
  2660. +#endif
  2661. +
  2662. +#ifndef configMAX
  2663. +
  2664. +/* The application writer has not provided their own MAX macro, so define
  2665. + * the following generic implementation. */
  2666. + #define configMAX( a, b ) ( ( ( a ) > ( b ) ) ? ( a ) : ( b ) )
  2667. +#endif
  2668. +
  2669. +#ifndef configMIN
  2670. +
  2671. +/* The application writer has not provided their own MIN macro, so define
  2672. + * the following generic implementation. */
  2673. + #define configMIN( a, b ) ( ( ( a ) < ( b ) ) ? ( a ) : ( b ) )
  2674. +#endif
  2675. +
  2676. +#if configENABLE_BACKWARD_COMPATIBILITY == 1
  2677. + #define eTaskStateGet eTaskGetState
  2678. + #define portTickType TickType_t
  2679. + #define xTaskHandle TaskHandle_t
  2680. + #define xQueueHandle QueueHandle_t
  2681. + #define xSemaphoreHandle SemaphoreHandle_t
  2682. + #define xQueueSetHandle QueueSetHandle_t
  2683. + #define xQueueSetMemberHandle QueueSetMemberHandle_t
  2684. + #define xTimeOutType TimeOut_t
  2685. + #define xMemoryRegion MemoryRegion_t
  2686. + #define xTaskParameters TaskParameters_t
  2687. + #define xTaskStatusType TaskStatus_t
  2688. + #define xTimerHandle TimerHandle_t
  2689. + #define xCoRoutineHandle CoRoutineHandle_t
  2690. + #define pdTASK_HOOK_CODE TaskHookFunction_t
  2691. + #define portTICK_RATE_MS portTICK_PERIOD_MS
  2692. + #define pcTaskGetTaskName pcTaskGetName
  2693. + #define pcTimerGetTimerName pcTimerGetName
  2694. + #define pcQueueGetQueueName pcQueueGetName
  2695. + #define vTaskGetTaskInfo vTaskGetInfo
  2696. + #define xTaskGetIdleRunTimeCounter ulTaskGetIdleRunTimeCounter
  2697. +
  2698. +/* Backward compatibility within the scheduler code only - these definitions
  2699. + * are not really required but are included for completeness. */
  2700. + #define tmrTIMER_CALLBACK TimerCallbackFunction_t
  2701. + #define pdTASK_CODE TaskFunction_t
  2702. + #define xListItem ListItem_t
  2703. + #define xList List_t
  2704. +
  2705. +/* For libraries that break the list data hiding, and access list structure
  2706. + * members directly (which is not supposed to be done). */
  2707. + #define pxContainer pvContainer
  2708. +#endif /* configENABLE_BACKWARD_COMPATIBILITY */
  2709. +
  2710. +#if ( configUSE_ALTERNATIVE_API != 0 )
  2711. + #error The alternative API was deprecated some time ago, and was removed in FreeRTOS V9.0 0
  2712. +#endif
  2713. +
  2714. +/* Set configUSE_TASK_FPU_SUPPORT to 0 to omit floating point support even
  2715. + * if floating point hardware is otherwise supported by the FreeRTOS port in use.
  2716. + * This constant is not supported by all FreeRTOS ports that include floating
  2717. + * point support. */
  2718. +#ifndef configUSE_TASK_FPU_SUPPORT
  2719. + #define configUSE_TASK_FPU_SUPPORT 1
  2720. +#endif
  2721. +
  2722. +/* Set configENABLE_MPU to 1 to enable MPU support and 0 to disable it. This is
  2723. + * currently used in ARMv8M ports. */
  2724. +#ifndef configENABLE_MPU
  2725. + #define configENABLE_MPU 0
  2726. +#endif
  2727. +
  2728. +/* Set configENABLE_FPU to 1 to enable FPU support and 0 to disable it. This is
  2729. + * currently used in ARMv8M ports. */
  2730. +#ifndef configENABLE_FPU
  2731. + #define configENABLE_FPU 1
  2732. +#endif
  2733. +
  2734. +/* Set configENABLE_TRUSTZONE to 1 enable TrustZone support and 0 to disable it.
  2735. + * This is currently used in ARMv8M ports. */
  2736. +#ifndef configENABLE_TRUSTZONE
  2737. + #define configENABLE_TRUSTZONE 1
  2738. +#endif
  2739. +
  2740. +/* Set configRUN_FREERTOS_SECURE_ONLY to 1 to run the FreeRTOS ARMv8M port on
  2741. + * the Secure Side only. */
  2742. +#ifndef configRUN_FREERTOS_SECURE_ONLY
  2743. + #define configRUN_FREERTOS_SECURE_ONLY 0
  2744. +#endif
  2745. +
  2746. +#ifndef configRUN_ADDITIONAL_TESTS
  2747. + #define configRUN_ADDITIONAL_TESTS 0
  2748. +#endif
  2749. +
  2750. +
  2751. +/* Sometimes the FreeRTOSConfig.h settings only allow a task to be created using
  2752. + * dynamically allocated RAM, in which case when any task is deleted it is known
  2753. + * that both the task's stack and TCB need to be freed. Sometimes the
  2754. + * FreeRTOSConfig.h settings only allow a task to be created using statically
  2755. + * allocated RAM, in which case when any task is deleted it is known that neither
  2756. + * the task's stack or TCB should be freed. Sometimes the FreeRTOSConfig.h
  2757. + * settings allow a task to be created using either statically or dynamically
  2758. + * allocated RAM, in which case a member of the TCB is used to record whether the
  2759. + * stack and/or TCB were allocated statically or dynamically, so when a task is
  2760. + * deleted the RAM that was allocated dynamically is freed again and no attempt is
  2761. + * made to free the RAM that was allocated statically.
  2762. + * tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE is only true if it is possible for a
  2763. + * task to be created using either statically or dynamically allocated RAM. Note
  2764. + * that if portUSING_MPU_WRAPPERS is 1 then a protected task can be created with
  2765. + * a statically allocated stack and a dynamically allocated TCB.
  2766. + *
  2767. + * The following table lists various combinations of portUSING_MPU_WRAPPERS,
  2768. + * configSUPPORT_DYNAMIC_ALLOCATION and configSUPPORT_STATIC_ALLOCATION and
  2769. + * when it is possible to have both static and dynamic allocation:
  2770. + * +-----+---------+--------+-----------------------------+-----------------------------------+------------------+-----------+
  2771. + * | MPU | Dynamic | Static | Available Functions | Possible Allocations | Both Dynamic and | Need Free |
  2772. + * | | | | | | Static Possible | |
  2773. + * +-----+---------+--------+-----------------------------+-----------------------------------+------------------+-----------+
  2774. + * | 0 | 0 | 1 | xTaskCreateStatic | TCB - Static, Stack - Static | No | No |
  2775. + * +-----|---------|--------|-----------------------------|-----------------------------------|------------------|-----------|
  2776. + * | 0 | 1 | 0 | xTaskCreate | TCB - Dynamic, Stack - Dynamic | No | Yes |
  2777. + * +-----|---------|--------|-----------------------------|-----------------------------------|------------------|-----------|
  2778. + * | 0 | 1 | 1 | xTaskCreate, | 1. TCB - Dynamic, Stack - Dynamic | Yes | Yes |
  2779. + * | | | | xTaskCreateStatic | 2. TCB - Static, Stack - Static | | |
  2780. + * +-----|---------|--------|-----------------------------|-----------------------------------|------------------|-----------|
  2781. + * | 1 | 0 | 1 | xTaskCreateStatic, | TCB - Static, Stack - Static | No | No |
  2782. + * | | | | xTaskCreateRestrictedStatic | | | |
  2783. + * +-----|---------|--------|-----------------------------|-----------------------------------|------------------|-----------|
  2784. + * | 1 | 1 | 0 | xTaskCreate, | 1. TCB - Dynamic, Stack - Dynamic | Yes | Yes |
  2785. + * | | | | xTaskCreateRestricted | 2. TCB - Dynamic, Stack - Static | | |
  2786. + * +-----|---------|--------|-----------------------------|-----------------------------------|------------------|-----------|
  2787. + * | 1 | 1 | 1 | xTaskCreate, | 1. TCB - Dynamic, Stack - Dynamic | Yes | Yes |
  2788. + * | | | | xTaskCreateStatic, | 2. TCB - Dynamic, Stack - Static | | |
  2789. + * | | | | xTaskCreateRestricted, | 3. TCB - Static, Stack - Static | | |
  2790. + * | | | | xTaskCreateRestrictedStatic | | | |
  2791. + * +-----+---------+--------+-----------------------------+-----------------------------------+------------------+-----------+
  2792. + */
  2793. +#define tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE \
  2794. + ( ( ( portUSING_MPU_WRAPPERS == 0 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) ) || \
  2795. + ( ( portUSING_MPU_WRAPPERS == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) ) )
  2796. +
  2797. +/*
  2798. + * In line with software engineering best practice, especially when supplying a
  2799. + * library that is likely to change in future versions, FreeRTOS implements a
  2800. + * strict data hiding policy. This means the Task structure used internally by
  2801. + * FreeRTOS is not accessible to application code. However, if the application
  2802. + * writer wants to statically allocate the memory required to create a task then
  2803. + * the size of the task object needs to be known. The StaticTask_t structure
  2804. + * below is provided for this purpose. Its sizes and alignment requirements are
  2805. + * guaranteed to match those of the genuine structure, no matter which
  2806. + * architecture is being used, and no matter how the values in FreeRTOSConfig.h
  2807. + * are set. Its contents are somewhat obfuscated in the hope users will
  2808. + * recognise that it would be unwise to make direct use of the structure members.
  2809. + */
  2810. +typedef struct xSTATIC_TCB
  2811. +{
  2812. + struct rt_thread thread;
  2813. + #if ( configUSE_APPLICATION_TASK_TAG == 1 )
  2814. + void * pxTaskTag;
  2815. + #endif
  2816. + #if ( configUSE_TASK_NOTIFICATIONS == 1 )
  2817. + uint32_t ulNotifiedValue[ configTASK_NOTIFICATION_ARRAY_ENTRIES ];
  2818. + uint8_t ucNotifyState[ configTASK_NOTIFICATION_ARRAY_ENTRIES ];
  2819. + #endif
  2820. + #if ( INCLUDE_xTaskAbortDelay == 1 )
  2821. + uint8_t ucDelayAborted;
  2822. + #endif
  2823. +} StaticTask_t;
  2824. +
  2825. +typedef struct
  2826. +{
  2827. + struct rt_ipc_object *rt_ipc;
  2828. + struct rt_messagequeue ipc_obj;
  2829. +} StaticQueue_t;
  2830. +
  2831. +typedef struct
  2832. +{
  2833. + struct rt_ipc_object *rt_ipc;
  2834. + union
  2835. + {
  2836. + struct rt_semaphore_wrapper semaphore;
  2837. + struct rt_mutex mutex;
  2838. + } ipc_obj;
  2839. +} StaticSemaphore_t;
  2840. +
  2841. +typedef struct xSTATIC_EVENT_GROUP
  2842. +{
  2843. + struct rt_event event;
  2844. +} StaticEventGroup_t;
  2845. +
  2846. +typedef struct xSTATIC_TIMER
  2847. +{
  2848. + struct rt_timer timer;
  2849. + void * pvTimerID;
  2850. +} StaticTimer_t;
  2851. +
  2852. +/* *INDENT-OFF* */
  2853. +#ifdef __cplusplus
  2854. + }
  2855. +#endif
  2856. +/* *INDENT-ON* */
  2857. +
  2858. +#endif /* INC_FREERTOS_H */
  2859. diff --git a/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/include/freertos/event_groups.h b/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/include/freertos/event_groups.h
  2860. new file mode 100644
  2861. index 0000000000..591814d37f
  2862. --- /dev/null
  2863. +++ b/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/include/freertos/event_groups.h
  2864. @@ -0,0 +1,621 @@
  2865. +/*
  2866. + * FreeRTOS Kernel V10.4.6
  2867. + * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  2868. + *
  2869. + * SPDX-License-Identifier: MIT
  2870. + *
  2871. + * Permission is hereby granted, free of charge, to any person obtaining a copy of
  2872. + * this software and associated documentation files (the "Software"), to deal in
  2873. + * the Software without restriction, including without limitation the rights to
  2874. + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  2875. + * the Software, and to permit persons to whom the Software is furnished to do so,
  2876. + * subject to the following conditions:
  2877. + *
  2878. + * The above copyright notice and this permission notice shall be included in all
  2879. + * copies or substantial portions of the Software.
  2880. + *
  2881. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  2882. + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  2883. + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  2884. + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  2885. + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  2886. + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  2887. + *
  2888. + * https://www.FreeRTOS.org
  2889. + * https://github.com/FreeRTOS
  2890. + *
  2891. + */
  2892. +
  2893. +#ifndef EVENT_GROUPS_H
  2894. +#define EVENT_GROUPS_H
  2895. +
  2896. +#ifndef INC_FREERTOS_H
  2897. + #error "include FreeRTOS.h" must appear in source files before "include event_groups.h"
  2898. +#endif
  2899. +
  2900. +/* *INDENT-OFF* */
  2901. +#ifdef __cplusplus
  2902. + extern "C" {
  2903. +#endif
  2904. +/* *INDENT-ON* */
  2905. +
  2906. +/**
  2907. + * An event group is a collection of bits to which an application can assign a
  2908. + * meaning. For example, an application may create an event group to convey
  2909. + * the status of various CAN bus related events in which bit 0 might mean "A CAN
  2910. + * message has been received and is ready for processing", bit 1 might mean "The
  2911. + * application has queued a message that is ready for sending onto the CAN
  2912. + * network", and bit 2 might mean "It is time to send a SYNC message onto the
  2913. + * CAN network" etc. A task can then test the bit values to see which events
  2914. + * are active, and optionally enter the Blocked state to wait for a specified
  2915. + * bit or a group of specified bits to be active. To continue the CAN bus
  2916. + * example, a CAN controlling task can enter the Blocked state (and therefore
  2917. + * not consume any processing time) until either bit 0, bit 1 or bit 2 are
  2918. + * active, at which time the bit that was actually active would inform the task
  2919. + * which action it had to take (process a received message, send a message, or
  2920. + * send a SYNC).
  2921. + *
  2922. + * The event groups implementation contains intelligence to avoid race
  2923. + * conditions that would otherwise occur were an application to use a simple
  2924. + * variable for the same purpose. This is particularly important with respect
  2925. + * to when a bit within an event group is to be cleared, and when bits have to
  2926. + * be set and then tested atomically - as is the case where event groups are
  2927. + * used to create a synchronisation point between multiple tasks (a
  2928. + * 'rendezvous').
  2929. + *
  2930. + * \defgroup EventGroup
  2931. + */
  2932. +
  2933. +
  2934. +
  2935. +/**
  2936. + * event_groups.h
  2937. + *
  2938. + * Type by which event groups are referenced. For example, a call to
  2939. + * xEventGroupCreate() returns an EventGroupHandle_t variable that can then
  2940. + * be used as a parameter to other event group functions.
  2941. + *
  2942. + * \defgroup EventGroupHandle_t EventGroupHandle_t
  2943. + * \ingroup EventGroup
  2944. + */
  2945. +struct EventGroupDef_t;
  2946. +typedef struct EventGroupDef_t * EventGroupHandle_t;
  2947. +
  2948. +/*
  2949. + * The type that holds event bits always matches TickType_t - therefore the
  2950. + * number of bits it holds is set by configUSE_16_BIT_TICKS (16 bits if set to 1,
  2951. + * 32 bits if set to 0.
  2952. + *
  2953. + * \defgroup EventBits_t EventBits_t
  2954. + * \ingroup EventGroup
  2955. + */
  2956. +typedef TickType_t EventBits_t;
  2957. +
  2958. +/**
  2959. + * event_groups.h
  2960. + * @code{c}
  2961. + * EventGroupHandle_t xEventGroupCreate( void );
  2962. + * @endcode
  2963. + *
  2964. + * Create a new event group.
  2965. + *
  2966. + * Internally, within the FreeRTOS implementation, event groups use a [small]
  2967. + * block of memory, in which the event group's structure is stored. If an event
  2968. + * groups is created using xEventGroupCreate() then the required memory is
  2969. + * automatically dynamically allocated inside the xEventGroupCreate() function.
  2970. + * (see https://www.FreeRTOS.org/a00111.html). If an event group is created
  2971. + * using xEventGroupCreateStatic() then the application writer must instead
  2972. + * provide the memory that will get used by the event group.
  2973. + * xEventGroupCreateStatic() therefore allows an event group to be created
  2974. + * without using any dynamic memory allocation.
  2975. + *
  2976. + * Although event groups are not related to ticks, for internal implementation
  2977. + * reasons the number of bits available for use in an event group is dependent
  2978. + * on the configUSE_16_BIT_TICKS setting in FreeRTOSConfig.h. If
  2979. + * configUSE_16_BIT_TICKS is 1 then each event group contains 8 usable bits (bit
  2980. + * 0 to bit 7). If configUSE_16_BIT_TICKS is set to 0 then each event group has
  2981. + * 24 usable bits (bit 0 to bit 23). The EventBits_t type is used to store
  2982. + * event bits within an event group.
  2983. + *
  2984. + * @return If the event group was created then a handle to the event group is
  2985. + * returned. If there was insufficient FreeRTOS heap available to create the
  2986. + * event group then NULL is returned. See https://www.FreeRTOS.org/a00111.html
  2987. + *
  2988. + * Example usage:
  2989. + * @code{c}
  2990. + * // Declare a variable to hold the created event group.
  2991. + * EventGroupHandle_t xCreatedEventGroup;
  2992. + *
  2993. + * // Attempt to create the event group.
  2994. + * xCreatedEventGroup = xEventGroupCreate();
  2995. + *
  2996. + * // Was the event group created successfully?
  2997. + * if( xCreatedEventGroup == NULL )
  2998. + * {
  2999. + * // The event group was not created because there was insufficient
  3000. + * // FreeRTOS heap available.
  3001. + * }
  3002. + * else
  3003. + * {
  3004. + * // The event group was created.
  3005. + * }
  3006. + * @endcode
  3007. + * \defgroup xEventGroupCreate xEventGroupCreate
  3008. + * \ingroup EventGroup
  3009. + */
  3010. +#if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
  3011. + EventGroupHandle_t xEventGroupCreate( void );
  3012. +#endif
  3013. +
  3014. +/**
  3015. + * event_groups.h
  3016. + * @code{c}
  3017. + * EventGroupHandle_t xEventGroupCreateStatic( EventGroupHandle_t * pxEventGroupBuffer );
  3018. + * @endcode
  3019. + *
  3020. + * Create a new event group.
  3021. + *
  3022. + * Internally, within the FreeRTOS implementation, event groups use a [small]
  3023. + * block of memory, in which the event group's structure is stored. If an event
  3024. + * groups is created using xEventGroupCreate() then the required memory is
  3025. + * automatically dynamically allocated inside the xEventGroupCreate() function.
  3026. + * (see https://www.FreeRTOS.org/a00111.html). If an event group is created
  3027. + * using xEventGroupCreateStatic() then the application writer must instead
  3028. + * provide the memory that will get used by the event group.
  3029. + * xEventGroupCreateStatic() therefore allows an event group to be created
  3030. + * without using any dynamic memory allocation.
  3031. + *
  3032. + * Although event groups are not related to ticks, for internal implementation
  3033. + * reasons the number of bits available for use in an event group is dependent
  3034. + * on the configUSE_16_BIT_TICKS setting in FreeRTOSConfig.h. If
  3035. + * configUSE_16_BIT_TICKS is 1 then each event group contains 8 usable bits (bit
  3036. + * 0 to bit 7). If configUSE_16_BIT_TICKS is set to 0 then each event group has
  3037. + * 24 usable bits (bit 0 to bit 23). The EventBits_t type is used to store
  3038. + * event bits within an event group.
  3039. + *
  3040. + * @param pxEventGroupBuffer pxEventGroupBuffer must point to a variable of type
  3041. + * StaticEventGroup_t, which will be then be used to hold the event group's data
  3042. + * structures, removing the need for the memory to be allocated dynamically.
  3043. + *
  3044. + * @return If the event group was created then a handle to the event group is
  3045. + * returned. If pxEventGroupBuffer was NULL then NULL is returned.
  3046. + *
  3047. + * Example usage:
  3048. + * @code{c}
  3049. + * // StaticEventGroup_t is a publicly accessible structure that has the same
  3050. + * // size and alignment requirements as the real event group structure. It is
  3051. + * // provided as a mechanism for applications to know the size of the event
  3052. + * // group (which is dependent on the architecture and configuration file
  3053. + * // settings) without breaking the strict data hiding policy by exposing the
  3054. + * // real event group internals. This StaticEventGroup_t variable is passed
  3055. + * // into the xSemaphoreCreateEventGroupStatic() function and is used to store
  3056. + * // the event group's data structures
  3057. + * StaticEventGroup_t xEventGroupBuffer;
  3058. + *
  3059. + * // Create the event group without dynamically allocating any memory.
  3060. + * xEventGroup = xEventGroupCreateStatic( &xEventGroupBuffer );
  3061. + * @endcode
  3062. + */
  3063. +#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
  3064. + EventGroupHandle_t xEventGroupCreateStatic( StaticEventGroup_t * pxEventGroupBuffer );
  3065. +#endif
  3066. +
  3067. +/**
  3068. + * event_groups.h
  3069. + * @code{c}
  3070. + * EventBits_t xEventGroupWaitBits( EventGroupHandle_t xEventGroup,
  3071. + * const EventBits_t uxBitsToWaitFor,
  3072. + * const BaseType_t xClearOnExit,
  3073. + * const BaseType_t xWaitForAllBits,
  3074. + * const TickType_t xTicksToWait );
  3075. + * @endcode
  3076. + *
  3077. + * [Potentially] block to wait for one or more bits to be set within a
  3078. + * previously created event group.
  3079. + *
  3080. + * This function cannot be called from an interrupt.
  3081. + *
  3082. + * @param xEventGroup The event group in which the bits are being tested. The
  3083. + * event group must have previously been created using a call to
  3084. + * xEventGroupCreate().
  3085. + *
  3086. + * @param uxBitsToWaitFor A bitwise value that indicates the bit or bits to test
  3087. + * inside the event group. For example, to wait for bit 0 and/or bit 2 set
  3088. + * uxBitsToWaitFor to 0x05. To wait for bits 0 and/or bit 1 and/or bit 2 set
  3089. + * uxBitsToWaitFor to 0x07. Etc.
  3090. + *
  3091. + * @param xClearOnExit If xClearOnExit is set to pdTRUE then any bits within
  3092. + * uxBitsToWaitFor that are set within the event group will be cleared before
  3093. + * xEventGroupWaitBits() returns if the wait condition was met (if the function
  3094. + * returns for a reason other than a timeout). If xClearOnExit is set to
  3095. + * pdFALSE then the bits set in the event group are not altered when the call to
  3096. + * xEventGroupWaitBits() returns.
  3097. + *
  3098. + * @param xWaitForAllBits If xWaitForAllBits is set to pdTRUE then
  3099. + * xEventGroupWaitBits() will return when either all the bits in uxBitsToWaitFor
  3100. + * are set or the specified block time expires. If xWaitForAllBits is set to
  3101. + * pdFALSE then xEventGroupWaitBits() will return when any one of the bits set
  3102. + * in uxBitsToWaitFor is set or the specified block time expires. The block
  3103. + * time is specified by the xTicksToWait parameter.
  3104. + *
  3105. + * @param xTicksToWait The maximum amount of time (specified in 'ticks') to wait
  3106. + * for one/all (depending on the xWaitForAllBits value) of the bits specified by
  3107. + * uxBitsToWaitFor to become set.
  3108. + *
  3109. + * @return The value of the event group at the time either the bits being waited
  3110. + * for became set, or the block time expired. Test the return value to know
  3111. + * which bits were set. If xEventGroupWaitBits() returned because its timeout
  3112. + * expired then not all the bits being waited for will be set. If
  3113. + * xEventGroupWaitBits() returned because the bits it was waiting for were set
  3114. + * then the returned value is the event group value before any bits were
  3115. + * automatically cleared in the case that xClearOnExit parameter was set to
  3116. + * pdTRUE.
  3117. + *
  3118. + * Example usage:
  3119. + * @code{c}
  3120. + * #define BIT_0 ( 1 << 0 )
  3121. + * #define BIT_4 ( 1 << 4 )
  3122. + *
  3123. + * void aFunction( EventGroupHandle_t xEventGroup )
  3124. + * {
  3125. + * EventBits_t uxBits;
  3126. + * const TickType_t xTicksToWait = 100 / portTICK_PERIOD_MS;
  3127. + *
  3128. + * // Wait a maximum of 100ms for either bit 0 or bit 4 to be set within
  3129. + * // the event group. Clear the bits before exiting.
  3130. + * uxBits = xEventGroupWaitBits(
  3131. + * xEventGroup, // The event group being tested.
  3132. + * BIT_0 | BIT_4, // The bits within the event group to wait for.
  3133. + * pdTRUE, // BIT_0 and BIT_4 should be cleared before returning.
  3134. + * pdFALSE, // Don't wait for both bits, either bit will do.
  3135. + * xTicksToWait ); // Wait a maximum of 100ms for either bit to be set.
  3136. + *
  3137. + * if( ( uxBits & ( BIT_0 | BIT_4 ) ) == ( BIT_0 | BIT_4 ) )
  3138. + * {
  3139. + * // xEventGroupWaitBits() returned because both bits were set.
  3140. + * }
  3141. + * else if( ( uxBits & BIT_0 ) != 0 )
  3142. + * {
  3143. + * // xEventGroupWaitBits() returned because just BIT_0 was set.
  3144. + * }
  3145. + * else if( ( uxBits & BIT_4 ) != 0 )
  3146. + * {
  3147. + * // xEventGroupWaitBits() returned because just BIT_4 was set.
  3148. + * }
  3149. + * else
  3150. + * {
  3151. + * // xEventGroupWaitBits() returned because xTicksToWait ticks passed
  3152. + * // without either BIT_0 or BIT_4 becoming set.
  3153. + * }
  3154. + * }
  3155. + * @endcode
  3156. + * \defgroup xEventGroupWaitBits xEventGroupWaitBits
  3157. + * \ingroup EventGroup
  3158. + */
  3159. +EventBits_t xEventGroupWaitBits( EventGroupHandle_t xEventGroup,
  3160. + const EventBits_t uxBitsToWaitFor,
  3161. + const BaseType_t xClearOnExit,
  3162. + const BaseType_t xWaitForAllBits,
  3163. + TickType_t xTicksToWait );
  3164. +
  3165. +/**
  3166. + * event_groups.h
  3167. + * @code{c}
  3168. + * EventBits_t xEventGroupClearBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToClear );
  3169. + * @endcode
  3170. + *
  3171. + * Clear bits within an event group. This function cannot be called from an
  3172. + * interrupt.
  3173. + *
  3174. + * @param xEventGroup The event group in which the bits are to be cleared.
  3175. + *
  3176. + * @param uxBitsToClear A bitwise value that indicates the bit or bits to clear
  3177. + * in the event group. For example, to clear bit 3 only, set uxBitsToClear to
  3178. + * 0x08. To clear bit 3 and bit 0 set uxBitsToClear to 0x09.
  3179. + *
  3180. + * @return The value of the event group before the specified bits were cleared.
  3181. + *
  3182. + * Example usage:
  3183. + * @code{c}
  3184. + * #define BIT_0 ( 1 << 0 )
  3185. + * #define BIT_4 ( 1 << 4 )
  3186. + *
  3187. + * void aFunction( EventGroupHandle_t xEventGroup )
  3188. + * {
  3189. + * EventBits_t uxBits;
  3190. + *
  3191. + * // Clear bit 0 and bit 4 in xEventGroup.
  3192. + * uxBits = xEventGroupClearBits(
  3193. + * xEventGroup, // The event group being updated.
  3194. + * BIT_0 | BIT_4 );// The bits being cleared.
  3195. + *
  3196. + * if( ( uxBits & ( BIT_0 | BIT_4 ) ) == ( BIT_0 | BIT_4 ) )
  3197. + * {
  3198. + * // Both bit 0 and bit 4 were set before xEventGroupClearBits() was
  3199. + * // called. Both will now be clear (not set).
  3200. + * }
  3201. + * else if( ( uxBits & BIT_0 ) != 0 )
  3202. + * {
  3203. + * // Bit 0 was set before xEventGroupClearBits() was called. It will
  3204. + * // now be clear.
  3205. + * }
  3206. + * else if( ( uxBits & BIT_4 ) != 0 )
  3207. + * {
  3208. + * // Bit 4 was set before xEventGroupClearBits() was called. It will
  3209. + * // now be clear.
  3210. + * }
  3211. + * else
  3212. + * {
  3213. + * // Neither bit 0 nor bit 4 were set in the first place.
  3214. + * }
  3215. + * }
  3216. + * @endcode
  3217. + * \defgroup xEventGroupClearBits xEventGroupClearBits
  3218. + * \ingroup EventGroup
  3219. + */
  3220. +EventBits_t xEventGroupClearBits( EventGroupHandle_t xEventGroup,
  3221. + const EventBits_t uxBitsToClear );
  3222. +
  3223. +/**
  3224. + * event_groups.h
  3225. + * @code{c}
  3226. + * BaseType_t xEventGroupClearBitsFromISR( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet );
  3227. + * @endcode
  3228. + *
  3229. + * A version of xEventGroupClearBits() that can be called from an interrupt.
  3230. + *
  3231. + * Setting bits in an event group is not a deterministic operation because there
  3232. + * are an unknown number of tasks that may be waiting for the bit or bits being
  3233. + * set. FreeRTOS does not allow nondeterministic operations to be performed
  3234. + * while interrupts are disabled, so protects event groups that are accessed
  3235. + * from tasks by suspending the scheduler rather than disabling interrupts. As
  3236. + * a result event groups cannot be accessed directly from an interrupt service
  3237. + * routine. Therefore xEventGroupClearBitsFromISR() sends a message to the
  3238. + * timer task to have the clear operation performed in the context of the timer
  3239. + * task.
  3240. + *
  3241. + * @param xEventGroup The event group in which the bits are to be cleared.
  3242. + *
  3243. + * @param uxBitsToClear A bitwise value that indicates the bit or bits to clear.
  3244. + * For example, to clear bit 3 only, set uxBitsToClear to 0x08. To clear bit 3
  3245. + * and bit 0 set uxBitsToClear to 0x09.
  3246. + *
  3247. + * @return If the request to execute the function was posted successfully then
  3248. + * pdPASS is returned, otherwise pdFALSE is returned. pdFALSE will be returned
  3249. + * if the timer service queue was full.
  3250. + *
  3251. + * Example usage:
  3252. + * @code{c}
  3253. + * #define BIT_0 ( 1 << 0 )
  3254. + * #define BIT_4 ( 1 << 4 )
  3255. + *
  3256. + * // An event group which it is assumed has already been created by a call to
  3257. + * // xEventGroupCreate().
  3258. + * EventGroupHandle_t xEventGroup;
  3259. + *
  3260. + * void anInterruptHandler( void )
  3261. + * {
  3262. + * // Clear bit 0 and bit 4 in xEventGroup.
  3263. + * xResult = xEventGroupClearBitsFromISR(
  3264. + * xEventGroup, // The event group being updated.
  3265. + * BIT_0 | BIT_4 ); // The bits being set.
  3266. + *
  3267. + * if( xResult == pdPASS )
  3268. + * {
  3269. + * // The message was posted successfully.
  3270. + * }
  3271. + * }
  3272. + * @endcode
  3273. + * \defgroup xEventGroupClearBitsFromISR xEventGroupClearBitsFromISR
  3274. + * \ingroup EventGroup
  3275. + */
  3276. +BaseType_t xEventGroupClearBitsFromISR( EventGroupHandle_t xEventGroup,
  3277. + const EventBits_t uxBitsToClear );
  3278. +
  3279. +/**
  3280. + * event_groups.h
  3281. + * @code{c}
  3282. + * EventBits_t xEventGroupSetBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet );
  3283. + * @endcode
  3284. + *
  3285. + * Set bits within an event group.
  3286. + * This function cannot be called from an interrupt. xEventGroupSetBitsFromISR()
  3287. + * is a version that can be called from an interrupt.
  3288. + *
  3289. + * Setting bits in an event group will automatically unblock tasks that are
  3290. + * blocked waiting for the bits.
  3291. + *
  3292. + * @param xEventGroup The event group in which the bits are to be set.
  3293. + *
  3294. + * @param uxBitsToSet A bitwise value that indicates the bit or bits to set.
  3295. + * For example, to set bit 3 only, set uxBitsToSet to 0x08. To set bit 3
  3296. + * and bit 0 set uxBitsToSet to 0x09.
  3297. + *
  3298. + * @return The value of the event group at the time the call to
  3299. + * xEventGroupSetBits() returns. There are two reasons why the returned value
  3300. + * might have the bits specified by the uxBitsToSet parameter cleared. First,
  3301. + * if setting a bit results in a task that was waiting for the bit leaving the
  3302. + * blocked state then it is possible the bit will be cleared automatically
  3303. + * (see the xClearBitOnExit parameter of xEventGroupWaitBits()). Second, any
  3304. + * unblocked (or otherwise Ready state) task that has a priority above that of
  3305. + * the task that called xEventGroupSetBits() will execute and may change the
  3306. + * event group value before the call to xEventGroupSetBits() returns.
  3307. + *
  3308. + * Example usage:
  3309. + * @code{c}
  3310. + * #define BIT_0 ( 1 << 0 )
  3311. + * #define BIT_4 ( 1 << 4 )
  3312. + *
  3313. + * void aFunction( EventGroupHandle_t xEventGroup )
  3314. + * {
  3315. + * EventBits_t uxBits;
  3316. + *
  3317. + * // Set bit 0 and bit 4 in xEventGroup.
  3318. + * uxBits = xEventGroupSetBits(
  3319. + * xEventGroup, // The event group being updated.
  3320. + * BIT_0 | BIT_4 );// The bits being set.
  3321. + *
  3322. + * if( ( uxBits & ( BIT_0 | BIT_4 ) ) == ( BIT_0 | BIT_4 ) )
  3323. + * {
  3324. + * // Both bit 0 and bit 4 remained set when the function returned.
  3325. + * }
  3326. + * else if( ( uxBits & BIT_0 ) != 0 )
  3327. + * {
  3328. + * // Bit 0 remained set when the function returned, but bit 4 was
  3329. + * // cleared. It might be that bit 4 was cleared automatically as a
  3330. + * // task that was waiting for bit 4 was removed from the Blocked
  3331. + * // state.
  3332. + * }
  3333. + * else if( ( uxBits & BIT_4 ) != 0 )
  3334. + * {
  3335. + * // Bit 4 remained set when the function returned, but bit 0 was
  3336. + * // cleared. It might be that bit 0 was cleared automatically as a
  3337. + * // task that was waiting for bit 0 was removed from the Blocked
  3338. + * // state.
  3339. + * }
  3340. + * else
  3341. + * {
  3342. + * // Neither bit 0 nor bit 4 remained set. It might be that a task
  3343. + * // was waiting for both of the bits to be set, and the bits were
  3344. + * // cleared as the task left the Blocked state.
  3345. + * }
  3346. + * }
  3347. + * @endcode
  3348. + * \defgroup xEventGroupSetBits xEventGroupSetBits
  3349. + * \ingroup EventGroup
  3350. + */
  3351. +EventBits_t xEventGroupSetBits( EventGroupHandle_t xEventGroup,
  3352. + const EventBits_t uxBitsToSet );
  3353. +
  3354. +/**
  3355. + * event_groups.h
  3356. + * @code{c}
  3357. + * BaseType_t xEventGroupSetBitsFromISR( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet, BaseType_t *pxHigherPriorityTaskWoken );
  3358. + * @endcode
  3359. + *
  3360. + * A version of xEventGroupSetBits() that can be called from an interrupt.
  3361. + *
  3362. + * Setting bits in an event group is not a deterministic operation because there
  3363. + * are an unknown number of tasks that may be waiting for the bit or bits being
  3364. + * set. FreeRTOS does not allow nondeterministic operations to be performed in
  3365. + * interrupts or from critical sections. Therefore xEventGroupSetBitsFromISR()
  3366. + * sends a message to the timer task to have the set operation performed in the
  3367. + * context of the timer task - where a scheduler lock is used in place of a
  3368. + * critical section.
  3369. + *
  3370. + * @param xEventGroup The event group in which the bits are to be set.
  3371. + *
  3372. + * @param uxBitsToSet A bitwise value that indicates the bit or bits to set.
  3373. + * For example, to set bit 3 only, set uxBitsToSet to 0x08. To set bit 3
  3374. + * and bit 0 set uxBitsToSet to 0x09.
  3375. + *
  3376. + * @param pxHigherPriorityTaskWoken As mentioned above, calling this function
  3377. + * will result in a message being sent to the timer daemon task. If the
  3378. + * priority of the timer daemon task is higher than the priority of the
  3379. + * currently running task (the task the interrupt interrupted) then
  3380. + * *pxHigherPriorityTaskWoken will be set to pdTRUE by
  3381. + * xEventGroupSetBitsFromISR(), indicating that a context switch should be
  3382. + * requested before the interrupt exits. For that reason
  3383. + * *pxHigherPriorityTaskWoken must be initialised to pdFALSE. See the
  3384. + * example code below.
  3385. + *
  3386. + * @return If the request to execute the function was posted successfully then
  3387. + * pdPASS is returned, otherwise pdFALSE is returned. pdFALSE will be returned
  3388. + * if the timer service queue was full.
  3389. + *
  3390. + * Example usage:
  3391. + * @code{c}
  3392. + * #define BIT_0 ( 1 << 0 )
  3393. + * #define BIT_4 ( 1 << 4 )
  3394. + *
  3395. + * // An event group which it is assumed has already been created by a call to
  3396. + * // xEventGroupCreate().
  3397. + * EventGroupHandle_t xEventGroup;
  3398. + *
  3399. + * void anInterruptHandler( void )
  3400. + * {
  3401. + * BaseType_t xHigherPriorityTaskWoken, xResult;
  3402. + *
  3403. + * // xHigherPriorityTaskWoken must be initialised to pdFALSE.
  3404. + * xHigherPriorityTaskWoken = pdFALSE;
  3405. + *
  3406. + * // Set bit 0 and bit 4 in xEventGroup.
  3407. + * xResult = xEventGroupSetBitsFromISR(
  3408. + * xEventGroup, // The event group being updated.
  3409. + * BIT_0 | BIT_4 // The bits being set.
  3410. + * &xHigherPriorityTaskWoken );
  3411. + *
  3412. + * // Was the message posted successfully?
  3413. + * if( xResult == pdPASS )
  3414. + * {
  3415. + * // If xHigherPriorityTaskWoken is now set to pdTRUE then a context
  3416. + * // switch should be requested. The macro used is port specific and
  3417. + * // will be either portYIELD_FROM_ISR() or portEND_SWITCHING_ISR() -
  3418. + * // refer to the documentation page for the port being used.
  3419. + * portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
  3420. + * }
  3421. + * }
  3422. + * @endcode
  3423. + * \defgroup xEventGroupSetBitsFromISR xEventGroupSetBitsFromISR
  3424. + * \ingroup EventGroup
  3425. + */
  3426. +BaseType_t xEventGroupSetBitsFromISR( EventGroupHandle_t xEventGroup,
  3427. + const EventBits_t uxBitsToSet,
  3428. + BaseType_t * pxHigherPriorityTaskWoken );
  3429. +
  3430. +/**
  3431. + * event_groups.h
  3432. + * @code{c}
  3433. + * EventBits_t xEventGroupGetBits( EventGroupHandle_t xEventGroup );
  3434. + * @endcode
  3435. + *
  3436. + * Returns the current value of the bits in an event group. This function
  3437. + * cannot be used from an interrupt.
  3438. + *
  3439. + * @param xEventGroup The event group being queried.
  3440. + *
  3441. + * @return The event group bits at the time xEventGroupGetBits() was called.
  3442. + *
  3443. + * \defgroup xEventGroupGetBits xEventGroupGetBits
  3444. + * \ingroup EventGroup
  3445. + */
  3446. +#define xEventGroupGetBits( xEventGroup ) xEventGroupClearBits( xEventGroup, 0 )
  3447. +
  3448. +/**
  3449. + * event_groups.h
  3450. + * @code{c}
  3451. + * EventBits_t xEventGroupGetBitsFromISR( EventGroupHandle_t xEventGroup );
  3452. + * @endcode
  3453. + *
  3454. + * A version of xEventGroupGetBits() that can be called from an ISR.
  3455. + *
  3456. + * @param xEventGroup The event group being queried.
  3457. + *
  3458. + * @return The event group bits at the time xEventGroupGetBitsFromISR() was called.
  3459. + *
  3460. + * \defgroup xEventGroupGetBitsFromISR xEventGroupGetBitsFromISR
  3461. + * \ingroup EventGroup
  3462. + */
  3463. +EventBits_t xEventGroupGetBitsFromISR( EventGroupHandle_t xEventGroup );
  3464. +
  3465. +/**
  3466. + * event_groups.h
  3467. + * @code{c}
  3468. + * void xEventGroupDelete( EventGroupHandle_t xEventGroup );
  3469. + * @endcode
  3470. + *
  3471. + * Delete an event group that was previously created by a call to
  3472. + * xEventGroupCreate(). Tasks that are blocked on the event group will be
  3473. + * unblocked and obtain 0 as the event group's value.
  3474. + *
  3475. + * @param xEventGroup The event group being deleted.
  3476. + */
  3477. +void vEventGroupDelete( EventGroupHandle_t xEventGroup );
  3478. +
  3479. +/* *INDENT-OFF* */
  3480. +#ifdef __cplusplus
  3481. + }
  3482. +#endif
  3483. +/* *INDENT-ON* */
  3484. +
  3485. +#endif /* EVENT_GROUPS_H */
  3486. diff --git a/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/include/freertos/list.h b/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/include/freertos/list.h
  3487. new file mode 100644
  3488. index 0000000000..dde1f3572e
  3489. --- /dev/null
  3490. +++ b/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/include/freertos/list.h
  3491. @@ -0,0 +1,416 @@
  3492. +/*
  3493. + * FreeRTOS Kernel V10.4.3
  3494. + * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  3495. + *
  3496. + * Permission is hereby granted, free of charge, to any person obtaining a copy of
  3497. + * this software and associated documentation files (the "Software"), to deal in
  3498. + * the Software without restriction, including without limitation the rights to
  3499. + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  3500. + * the Software, and to permit persons to whom the Software is furnished to do so,
  3501. + * subject to the following conditions:
  3502. + *
  3503. + * The above copyright notice and this permission notice shall be included in all
  3504. + * copies or substantial portions of the Software.
  3505. + *
  3506. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  3507. + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  3508. + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  3509. + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  3510. + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  3511. + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  3512. + *
  3513. + * https://www.FreeRTOS.org
  3514. + * https://github.com/FreeRTOS
  3515. + *
  3516. + */
  3517. +
  3518. +/*
  3519. + * This is the list implementation used by the scheduler. While it is tailored
  3520. + * heavily for the schedulers needs, it is also available for use by
  3521. + * application code.
  3522. + *
  3523. + * list_ts can only store pointers to list_item_ts. Each ListItem_t contains a
  3524. + * numeric value (xItemValue). Most of the time the lists are sorted in
  3525. + * descending item value order.
  3526. + *
  3527. + * Lists are created already containing one list item. The value of this
  3528. + * item is the maximum possible that can be stored, it is therefore always at
  3529. + * the end of the list and acts as a marker. The list member pxHead always
  3530. + * points to this marker - even though it is at the tail of the list. This
  3531. + * is because the tail contains a wrap back pointer to the true head of
  3532. + * the list.
  3533. + *
  3534. + * In addition to it's value, each list item contains a pointer to the next
  3535. + * item in the list (pxNext), a pointer to the list it is in (pxContainer)
  3536. + * and a pointer to back to the object that contains it. These later two
  3537. + * pointers are included for efficiency of list manipulation. There is
  3538. + * effectively a two way link between the object containing the list item and
  3539. + * the list item itself.
  3540. + *
  3541. + *
  3542. + * \page ListIntroduction List Implementation
  3543. + * \ingroup FreeRTOSIntro
  3544. + */
  3545. +
  3546. +#ifndef INC_FREERTOS_H
  3547. + #error "FreeRTOS.h must be included before list.h"
  3548. +#endif
  3549. +
  3550. +#ifndef LIST_H
  3551. +#define LIST_H
  3552. +
  3553. +/*
  3554. + * The list structure members are modified from within interrupts, and therefore
  3555. + * by rights should be declared volatile. However, they are only modified in a
  3556. + * functionally atomic way (within critical sections of with the scheduler
  3557. + * suspended) and are either passed by reference into a function or indexed via
  3558. + * a volatile variable. Therefore, in all use cases tested so far, the volatile
  3559. + * qualifier can be omitted in order to provide a moderate performance
  3560. + * improvement without adversely affecting functional behaviour. The assembly
  3561. + * instructions generated by the IAR, ARM and GCC compilers when the respective
  3562. + * compiler's options were set for maximum optimisation has been inspected and
  3563. + * deemed to be as intended. That said, as compiler technology advances, and
  3564. + * especially if aggressive cross module optimisation is used (a use case that
  3565. + * has not been exercised to any great extend) then it is feasible that the
  3566. + * volatile qualifier will be needed for correct optimisation. It is expected
  3567. + * that a compiler removing essential code because, without the volatile
  3568. + * qualifier on the list structure members and with aggressive cross module
  3569. + * optimisation, the compiler deemed the code unnecessary will result in
  3570. + * complete and obvious failure of the scheduler. If this is ever experienced
  3571. + * then the volatile qualifier can be inserted in the relevant places within the
  3572. + * list structures by simply defining configLIST_VOLATILE to volatile in
  3573. + * FreeRTOSConfig.h (as per the example at the bottom of this comment block).
  3574. + * If configLIST_VOLATILE is not defined then the preprocessor directives below
  3575. + * will simply #define configLIST_VOLATILE away completely.
  3576. + *
  3577. + * To use volatile list structure members then add the following line to
  3578. + * FreeRTOSConfig.h (without the quotes):
  3579. + * "#define configLIST_VOLATILE volatile"
  3580. + */
  3581. +#ifndef configLIST_VOLATILE
  3582. + #define configLIST_VOLATILE
  3583. +#endif /* configSUPPORT_CROSS_MODULE_OPTIMISATION */
  3584. +
  3585. +/* *INDENT-OFF* */
  3586. +#ifdef __cplusplus
  3587. + extern "C" {
  3588. +#endif
  3589. +/* *INDENT-ON* */
  3590. +
  3591. +/* Macros that can be used to place known values within the list structures,
  3592. + * then check that the known values do not get corrupted during the execution of
  3593. + * the application. These may catch the list data structures being overwritten in
  3594. + * memory. They will not catch data errors caused by incorrect configuration or
  3595. + * use of FreeRTOS.*/
  3596. +#if ( configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES == 0 )
  3597. + /* Define the macros to do nothing. */
  3598. + #define listFIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE
  3599. + #define listSECOND_LIST_ITEM_INTEGRITY_CHECK_VALUE
  3600. + #define listFIRST_LIST_INTEGRITY_CHECK_VALUE
  3601. + #define listSECOND_LIST_INTEGRITY_CHECK_VALUE
  3602. + #define listSET_FIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE( pxItem )
  3603. + #define listSET_SECOND_LIST_ITEM_INTEGRITY_CHECK_VALUE( pxItem )
  3604. + #define listSET_LIST_INTEGRITY_CHECK_1_VALUE( pxList )
  3605. + #define listSET_LIST_INTEGRITY_CHECK_2_VALUE( pxList )
  3606. + #define listTEST_LIST_ITEM_INTEGRITY( pxItem )
  3607. + #define listTEST_LIST_INTEGRITY( pxList )
  3608. +#else /* if ( configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES == 0 ) */
  3609. + /* Define macros that add new members into the list structures. */
  3610. + #define listFIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE TickType_t xListItemIntegrityValue1;
  3611. + #define listSECOND_LIST_ITEM_INTEGRITY_CHECK_VALUE TickType_t xListItemIntegrityValue2;
  3612. + #define listFIRST_LIST_INTEGRITY_CHECK_VALUE TickType_t xListIntegrityValue1;
  3613. + #define listSECOND_LIST_INTEGRITY_CHECK_VALUE TickType_t xListIntegrityValue2;
  3614. +
  3615. +/* Define macros that set the new structure members to known values. */
  3616. + #define listSET_FIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE( pxItem ) ( pxItem )->xListItemIntegrityValue1 = pdINTEGRITY_CHECK_VALUE
  3617. + #define listSET_SECOND_LIST_ITEM_INTEGRITY_CHECK_VALUE( pxItem ) ( pxItem )->xListItemIntegrityValue2 = pdINTEGRITY_CHECK_VALUE
  3618. + #define listSET_LIST_INTEGRITY_CHECK_1_VALUE( pxList ) ( pxList )->xListIntegrityValue1 = pdINTEGRITY_CHECK_VALUE
  3619. + #define listSET_LIST_INTEGRITY_CHECK_2_VALUE( pxList ) ( pxList )->xListIntegrityValue2 = pdINTEGRITY_CHECK_VALUE
  3620. +
  3621. +/* Define macros that will assert if one of the structure members does not
  3622. + * contain its expected value. */
  3623. + #define listTEST_LIST_ITEM_INTEGRITY( pxItem ) configASSERT( ( ( pxItem )->xListItemIntegrityValue1 == pdINTEGRITY_CHECK_VALUE ) && ( ( pxItem )->xListItemIntegrityValue2 == pdINTEGRITY_CHECK_VALUE ) )
  3624. + #define listTEST_LIST_INTEGRITY( pxList ) configASSERT( ( ( pxList )->xListIntegrityValue1 == pdINTEGRITY_CHECK_VALUE ) && ( ( pxList )->xListIntegrityValue2 == pdINTEGRITY_CHECK_VALUE ) )
  3625. +#endif /* configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES */
  3626. +
  3627. +
  3628. +/*
  3629. + * Definition of the only type of object that a list can contain.
  3630. + */
  3631. +struct xLIST;
  3632. +struct xLIST_ITEM
  3633. +{
  3634. + listFIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE /*< Set to a known value if configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */
  3635. + configLIST_VOLATILE TickType_t xItemValue; /*< The value being listed. In most cases this is used to sort the list in descending order. */
  3636. + struct xLIST_ITEM * configLIST_VOLATILE pxNext; /*< Pointer to the next ListItem_t in the list. */
  3637. + struct xLIST_ITEM * configLIST_VOLATILE pxPrevious; /*< Pointer to the previous ListItem_t in the list. */
  3638. + void * pvOwner; /*< Pointer to the object (normally a TCB) that contains the list item. There is therefore a two way link between the object containing the list item and the list item itself. */
  3639. + struct xLIST * configLIST_VOLATILE pxContainer; /*< Pointer to the list in which this list item is placed (if any). */
  3640. + listSECOND_LIST_ITEM_INTEGRITY_CHECK_VALUE /*< Set to a known value if configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */
  3641. +};
  3642. +typedef struct xLIST_ITEM ListItem_t; /* For some reason lint wants this as two separate definitions. */
  3643. +
  3644. +struct xMINI_LIST_ITEM
  3645. +{
  3646. + listFIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE /*< Set to a known value if configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */
  3647. + configLIST_VOLATILE TickType_t xItemValue;
  3648. + struct xLIST_ITEM * configLIST_VOLATILE pxNext;
  3649. + struct xLIST_ITEM * configLIST_VOLATILE pxPrevious;
  3650. +};
  3651. +typedef struct xMINI_LIST_ITEM MiniListItem_t;
  3652. +
  3653. +/*
  3654. + * Definition of the type of queue used by the scheduler.
  3655. + */
  3656. +typedef struct xLIST
  3657. +{
  3658. + listFIRST_LIST_INTEGRITY_CHECK_VALUE /*< Set to a known value if configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */
  3659. + volatile UBaseType_t uxNumberOfItems;
  3660. + ListItem_t * configLIST_VOLATILE pxIndex; /*< Used to walk through the list. Points to the last item returned by a call to listGET_OWNER_OF_NEXT_ENTRY (). */
  3661. + MiniListItem_t xListEnd; /*< List item that contains the maximum possible item value meaning it is always at the end of the list and is therefore used as a marker. */
  3662. + listSECOND_LIST_INTEGRITY_CHECK_VALUE /*< Set to a known value if configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */
  3663. +} List_t;
  3664. +
  3665. +/*
  3666. + * Access macro to set the owner of a list item. The owner of a list item
  3667. + * is the object (usually a TCB) that contains the list item.
  3668. + *
  3669. + * \page listSET_LIST_ITEM_OWNER listSET_LIST_ITEM_OWNER
  3670. + * \ingroup LinkedList
  3671. + */
  3672. +#define listSET_LIST_ITEM_OWNER( pxListItem, pxOwner ) ( ( pxListItem )->pvOwner = ( void * ) ( pxOwner ) )
  3673. +
  3674. +/*
  3675. + * Access macro to get the owner of a list item. The owner of a list item
  3676. + * is the object (usually a TCB) that contains the list item.
  3677. + *
  3678. + * \page listGET_LIST_ITEM_OWNER listSET_LIST_ITEM_OWNER
  3679. + * \ingroup LinkedList
  3680. + */
  3681. +#define listGET_LIST_ITEM_OWNER( pxListItem ) ( ( pxListItem )->pvOwner )
  3682. +
  3683. +/*
  3684. + * Access macro to set the value of the list item. In most cases the value is
  3685. + * used to sort the list in descending order.
  3686. + *
  3687. + * \page listSET_LIST_ITEM_VALUE listSET_LIST_ITEM_VALUE
  3688. + * \ingroup LinkedList
  3689. + */
  3690. +#define listSET_LIST_ITEM_VALUE( pxListItem, xValue ) ( ( pxListItem )->xItemValue = ( xValue ) )
  3691. +
  3692. +/*
  3693. + * Access macro to retrieve the value of the list item. The value can
  3694. + * represent anything - for example the priority of a task, or the time at
  3695. + * which a task should be unblocked.
  3696. + *
  3697. + * \page listGET_LIST_ITEM_VALUE listGET_LIST_ITEM_VALUE
  3698. + * \ingroup LinkedList
  3699. + */
  3700. +#define listGET_LIST_ITEM_VALUE( pxListItem ) ( ( pxListItem )->xItemValue )
  3701. +
  3702. +/*
  3703. + * Access macro to retrieve the value of the list item at the head of a given
  3704. + * list.
  3705. + *
  3706. + * \page listGET_LIST_ITEM_VALUE listGET_LIST_ITEM_VALUE
  3707. + * \ingroup LinkedList
  3708. + */
  3709. +#define listGET_ITEM_VALUE_OF_HEAD_ENTRY( pxList ) ( ( ( pxList )->xListEnd ).pxNext->xItemValue )
  3710. +
  3711. +/*
  3712. + * Return the list item at the head of the list.
  3713. + *
  3714. + * \page listGET_HEAD_ENTRY listGET_HEAD_ENTRY
  3715. + * \ingroup LinkedList
  3716. + */
  3717. +#define listGET_HEAD_ENTRY( pxList ) ( ( ( pxList )->xListEnd ).pxNext )
  3718. +
  3719. +/*
  3720. + * Return the next list item.
  3721. + *
  3722. + * \page listGET_NEXT listGET_NEXT
  3723. + * \ingroup LinkedList
  3724. + */
  3725. +#define listGET_NEXT( pxListItem ) ( ( pxListItem )->pxNext )
  3726. +
  3727. +/*
  3728. + * Return the list item that marks the end of the list
  3729. + *
  3730. + * \page listGET_END_MARKER listGET_END_MARKER
  3731. + * \ingroup LinkedList
  3732. + */
  3733. +#define listGET_END_MARKER( pxList ) ( ( ListItem_t const * ) ( &( ( pxList )->xListEnd ) ) )
  3734. +
  3735. +/*
  3736. + * Access macro to determine if a list contains any items. The macro will
  3737. + * only have the value true if the list is empty.
  3738. + *
  3739. + * \page listLIST_IS_EMPTY listLIST_IS_EMPTY
  3740. + * \ingroup LinkedList
  3741. + */
  3742. +#define listLIST_IS_EMPTY( pxList ) ( ( ( pxList )->uxNumberOfItems == ( UBaseType_t ) 0 ) ? pdTRUE : pdFALSE )
  3743. +
  3744. +/*
  3745. + * Access macro to return the number of items in the list.
  3746. + */
  3747. +#define listCURRENT_LIST_LENGTH( pxList ) ( ( pxList )->uxNumberOfItems )
  3748. +
  3749. +/*
  3750. + * Access function to obtain the owner of the next entry in a list.
  3751. + *
  3752. + * The list member pxIndex is used to walk through a list. Calling
  3753. + * listGET_OWNER_OF_NEXT_ENTRY increments pxIndex to the next item in the list
  3754. + * and returns that entry's pxOwner parameter. Using multiple calls to this
  3755. + * function it is therefore possible to move through every item contained in
  3756. + * a list.
  3757. + *
  3758. + * The pxOwner parameter of a list item is a pointer to the object that owns
  3759. + * the list item. In the scheduler this is normally a task control block.
  3760. + * The pxOwner parameter effectively creates a two way link between the list
  3761. + * item and its owner.
  3762. + *
  3763. + * @param pxTCB pxTCB is set to the address of the owner of the next list item.
  3764. + * @param pxList The list from which the next item owner is to be returned.
  3765. + *
  3766. + * \page listGET_OWNER_OF_NEXT_ENTRY listGET_OWNER_OF_NEXT_ENTRY
  3767. + * \ingroup LinkedList
  3768. + */
  3769. +#define listGET_OWNER_OF_NEXT_ENTRY( pxTCB, pxList ) \
  3770. + { \
  3771. + List_t * const pxConstList = ( pxList ); \
  3772. + /* Increment the index to the next item and return the item, ensuring */ \
  3773. + /* we don't return the marker used at the end of the list. */ \
  3774. + ( pxConstList )->pxIndex = ( pxConstList )->pxIndex->pxNext; \
  3775. + if( ( void * ) ( pxConstList )->pxIndex == ( void * ) &( ( pxConstList )->xListEnd ) ) \
  3776. + { \
  3777. + ( pxConstList )->pxIndex = ( pxConstList )->pxIndex->pxNext; \
  3778. + } \
  3779. + ( pxTCB ) = ( pxConstList )->pxIndex->pvOwner; \
  3780. + }
  3781. +
  3782. +
  3783. +/*
  3784. + * Access function to obtain the owner of the first entry in a list. Lists
  3785. + * are normally sorted in ascending item value order.
  3786. + *
  3787. + * This function returns the pxOwner member of the first item in the list.
  3788. + * The pxOwner parameter of a list item is a pointer to the object that owns
  3789. + * the list item. In the scheduler this is normally a task control block.
  3790. + * The pxOwner parameter effectively creates a two way link between the list
  3791. + * item and its owner.
  3792. + *
  3793. + * @param pxList The list from which the owner of the head item is to be
  3794. + * returned.
  3795. + *
  3796. + * \page listGET_OWNER_OF_HEAD_ENTRY listGET_OWNER_OF_HEAD_ENTRY
  3797. + * \ingroup LinkedList
  3798. + */
  3799. +#define listGET_OWNER_OF_HEAD_ENTRY( pxList ) ( ( &( ( pxList )->xListEnd ) )->pxNext->pvOwner )
  3800. +
  3801. +/*
  3802. + * Check to see if a list item is within a list. The list item maintains a
  3803. + * "container" pointer that points to the list it is in. All this macro does
  3804. + * is check to see if the container and the list match.
  3805. + *
  3806. + * @param pxList The list we want to know if the list item is within.
  3807. + * @param pxListItem The list item we want to know if is in the list.
  3808. + * @return pdTRUE if the list item is in the list, otherwise pdFALSE.
  3809. + */
  3810. +#define listIS_CONTAINED_WITHIN( pxList, pxListItem ) ( ( ( pxListItem )->pxContainer == ( pxList ) ) ? ( pdTRUE ) : ( pdFALSE ) )
  3811. +
  3812. +/*
  3813. + * Return the list a list item is contained within (referenced from).
  3814. + *
  3815. + * @param pxListItem The list item being queried.
  3816. + * @return A pointer to the List_t object that references the pxListItem
  3817. + */
  3818. +#define listLIST_ITEM_CONTAINER( pxListItem ) ( ( pxListItem )->pxContainer )
  3819. +
  3820. +/*
  3821. + * This provides a crude means of knowing if a list has been initialised, as
  3822. + * pxList->xListEnd.xItemValue is set to portMAX_DELAY by the vListInitialise()
  3823. + * function.
  3824. + */
  3825. +#define listLIST_IS_INITIALISED( pxList ) ( ( pxList )->xListEnd.xItemValue == portMAX_DELAY )
  3826. +
  3827. +/*
  3828. + * Must be called before a list is used! This initialises all the members
  3829. + * of the list structure and inserts the xListEnd item into the list as a
  3830. + * marker to the back of the list.
  3831. + *
  3832. + * @param pxList Pointer to the list being initialised.
  3833. + *
  3834. + * \page vListInitialise vListInitialise
  3835. + * \ingroup LinkedList
  3836. + */
  3837. +void vListInitialise( List_t * const pxList );
  3838. +
  3839. +/*
  3840. + * Must be called before a list item is used. This sets the list container to
  3841. + * null so the item does not think that it is already contained in a list.
  3842. + *
  3843. + * @param pxItem Pointer to the list item being initialised.
  3844. + *
  3845. + * \page vListInitialiseItem vListInitialiseItem
  3846. + * \ingroup LinkedList
  3847. + */
  3848. +void vListInitialiseItem( ListItem_t * const pxItem );
  3849. +
  3850. +/*
  3851. + * Insert a list item into a list. The item will be inserted into the list in
  3852. + * a position determined by its item value (descending item value order).
  3853. + *
  3854. + * @param pxList The list into which the item is to be inserted.
  3855. + *
  3856. + * @param pxNewListItem The item that is to be placed in the list.
  3857. + *
  3858. + * \page vListInsert vListInsert
  3859. + * \ingroup LinkedList
  3860. + */
  3861. +void vListInsert( List_t * const pxList,
  3862. + ListItem_t * const pxNewListItem );
  3863. +
  3864. +/*
  3865. + * Insert a list item into a list. The item will be inserted in a position
  3866. + * such that it will be the last item within the list returned by multiple
  3867. + * calls to listGET_OWNER_OF_NEXT_ENTRY.
  3868. + *
  3869. + * The list member pxIndex is used to walk through a list. Calling
  3870. + * listGET_OWNER_OF_NEXT_ENTRY increments pxIndex to the next item in the list.
  3871. + * Placing an item in a list using vListInsertEnd effectively places the item
  3872. + * in the list position pointed to by pxIndex. This means that every other
  3873. + * item within the list will be returned by listGET_OWNER_OF_NEXT_ENTRY before
  3874. + * the pxIndex parameter again points to the item being inserted.
  3875. + *
  3876. + * @param pxList The list into which the item is to be inserted.
  3877. + *
  3878. + * @param pxNewListItem The list item to be inserted into the list.
  3879. + *
  3880. + * \page vListInsertEnd vListInsertEnd
  3881. + * \ingroup LinkedList
  3882. + */
  3883. +void vListInsertEnd( List_t * const pxList,
  3884. + ListItem_t * const pxNewListItem );
  3885. +
  3886. +/*
  3887. + * Remove an item from a list. The list item has a pointer to the list that
  3888. + * it is in, so only the list item need be passed into the function.
  3889. + *
  3890. + * @param uxListRemove The item to be removed. The item will remove itself from
  3891. + * the list pointed to by it's pxContainer parameter.
  3892. + *
  3893. + * @return The number of items that remain in the list after the list item has
  3894. + * been removed.
  3895. + *
  3896. + * \page uxListRemove uxListRemove
  3897. + * \ingroup LinkedList
  3898. + */
  3899. +UBaseType_t uxListRemove( ListItem_t * const pxItemToRemove );
  3900. +
  3901. +/* *INDENT-OFF* */
  3902. +#ifdef __cplusplus
  3903. + }
  3904. +#endif
  3905. +/* *INDENT-ON* */
  3906. +
  3907. +#endif /* ifndef LIST_H */
  3908. diff --git a/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/include/freertos/portable.h b/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/include/freertos/portable.h
  3909. new file mode 100644
  3910. index 0000000000..f0b56ae166
  3911. --- /dev/null
  3912. +++ b/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/include/freertos/portable.h
  3913. @@ -0,0 +1,141 @@
  3914. +/*
  3915. + * FreeRTOS Kernel V10.4.6
  3916. + * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  3917. + *
  3918. + * SPDX-License-Identifier: MIT
  3919. + *
  3920. + * Permission is hereby granted, free of charge, to any person obtaining a copy of
  3921. + * this software and associated documentation files (the "Software"), to deal in
  3922. + * the Software without restriction, including without limitation the rights to
  3923. + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  3924. + * the Software, and to permit persons to whom the Software is furnished to do so,
  3925. + * subject to the following conditions:
  3926. + *
  3927. + * The above copyright notice and this permission notice shall be included in all
  3928. + * copies or substantial portions of the Software.
  3929. + *
  3930. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  3931. + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  3932. + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  3933. + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  3934. + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  3935. + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  3936. + *
  3937. + * https://www.FreeRTOS.org
  3938. + * https://github.com/FreeRTOS
  3939. + *
  3940. + */
  3941. +
  3942. +/*-----------------------------------------------------------
  3943. +* Portable layer API. Each function must be defined for each port.
  3944. +*----------------------------------------------------------*/
  3945. +
  3946. +#ifndef PORTABLE_H
  3947. +#define PORTABLE_H
  3948. +
  3949. +#include "freertos/portmacro.h"
  3950. +
  3951. +#if portBYTE_ALIGNMENT == 32
  3952. + #define portBYTE_ALIGNMENT_MASK ( 0x001f )
  3953. +#elif portBYTE_ALIGNMENT == 16
  3954. + #define portBYTE_ALIGNMENT_MASK ( 0x000f )
  3955. +#elif portBYTE_ALIGNMENT == 8
  3956. + #define portBYTE_ALIGNMENT_MASK ( 0x0007 )
  3957. +#elif portBYTE_ALIGNMENT == 4
  3958. + #define portBYTE_ALIGNMENT_MASK ( 0x0003 )
  3959. +#elif portBYTE_ALIGNMENT == 2
  3960. + #define portBYTE_ALIGNMENT_MASK ( 0x0001 )
  3961. +#elif portBYTE_ALIGNMENT == 1
  3962. + #define portBYTE_ALIGNMENT_MASK ( 0x0000 )
  3963. +#else /* if portBYTE_ALIGNMENT == 32 */
  3964. + #error "Invalid portBYTE_ALIGNMENT definition"
  3965. +#endif /* if portBYTE_ALIGNMENT == 32 */
  3966. +
  3967. +/* *INDENT-OFF* */
  3968. +#ifdef __cplusplus
  3969. + extern "C" {
  3970. +#endif
  3971. +/* *INDENT-ON* */
  3972. +
  3973. +#ifdef configUSE_FREERTOS_PROVIDED_HEAP
  3974. +
  3975. +/* Used by heap_5.c to define the start address and size of each memory region
  3976. + * that together comprise the total FreeRTOS heap space. */
  3977. +typedef struct HeapRegion
  3978. +{
  3979. + uint8_t * pucStartAddress;
  3980. + size_t xSizeInBytes;
  3981. +} HeapRegion_t;
  3982. +
  3983. +/* Used to pass information about the heap out of vPortGetHeapStats(). */
  3984. +typedef struct xHeapStats
  3985. +{
  3986. + size_t xAvailableHeapSpaceInBytes; /* The total heap size currently available - this is the sum of all the free blocks, not the largest block that can be allocated. */
  3987. + size_t xSizeOfLargestFreeBlockInBytes; /* The maximum size, in bytes, of all the free blocks within the heap at the time vPortGetHeapStats() is called. */
  3988. + size_t xSizeOfSmallestFreeBlockInBytes; /* The minimum size, in bytes, of all the free blocks within the heap at the time vPortGetHeapStats() is called. */
  3989. + size_t xNumberOfFreeBlocks; /* The number of free memory blocks within the heap at the time vPortGetHeapStats() is called. */
  3990. + size_t xMinimumEverFreeBytesRemaining; /* The minimum amount of total free memory (sum of all free blocks) there has been in the heap since the system booted. */
  3991. + size_t xNumberOfSuccessfulAllocations; /* The number of calls to pvPortMalloc() that have returned a valid memory block. */
  3992. + size_t xNumberOfSuccessfulFrees; /* The number of calls to vPortFree() that has successfully freed a block of memory. */
  3993. +} HeapStats_t;
  3994. +
  3995. +/*
  3996. + * Used to define multiple heap regions for use by heap_5.c. This function
  3997. + * must be called before any calls to pvPortMalloc() - not creating a task,
  3998. + * queue, semaphore, mutex, software timer, event group, etc. will result in
  3999. + * pvPortMalloc being called.
  4000. + *
  4001. + * pxHeapRegions passes in an array of HeapRegion_t structures - each of which
  4002. + * defines a region of memory that can be used as the heap. The array is
  4003. + * terminated by a HeapRegions_t structure that has a size of 0. The region
  4004. + * with the lowest start address must appear first in the array.
  4005. + */
  4006. +void vPortDefineHeapRegions( const HeapRegion_t * const pxHeapRegions ) PRIVILEGED_FUNCTION;
  4007. +
  4008. +/*
  4009. + * Returns a HeapStats_t structure filled with information about the current
  4010. + * heap state.
  4011. + */
  4012. +void vPortGetHeapStats( HeapStats_t * pxHeapStats );
  4013. +
  4014. +/*
  4015. + * Map to the memory management routines required for the port.
  4016. + */
  4017. +void * pvPortMalloc( size_t xSize ) PRIVILEGED_FUNCTION;
  4018. +void vPortFree( void * pv ) PRIVILEGED_FUNCTION;
  4019. +void vPortInitialiseBlocks( void ) PRIVILEGED_FUNCTION;
  4020. +size_t xPortGetFreeHeapSize( void ) PRIVILEGED_FUNCTION;
  4021. +size_t xPortGetMinimumEverFreeHeapSize( void ) PRIVILEGED_FUNCTION;
  4022. +
  4023. +#if( configSTACK_ALLOCATION_FROM_SEPARATE_HEAP == 1 )
  4024. + void *pvPortMallocStack( size_t xSize ) PRIVILEGED_FUNCTION;
  4025. + void vPortFreeStack( void *pv ) PRIVILEGED_FUNCTION;
  4026. +#else
  4027. + #define pvPortMallocStack pvPortMalloc
  4028. + #define vPortFreeStack vPortFree
  4029. +#endif
  4030. +#else // configUSE_FREERTOS_PROVIDED_HEAP
  4031. +
  4032. +/*
  4033. + * Map to the memory management routines required for the port.
  4034. + *
  4035. + * Note that libc standard malloc/free are also available for
  4036. + * non-FreeRTOS-specific code, and behave the same as
  4037. + * pvPortMalloc()/vPortFree().
  4038. + */
  4039. +#define pvPortMalloc malloc
  4040. +#define vPortFree free
  4041. +#define xPortGetFreeHeapSize esp_get_free_heap_size
  4042. +#define xPortGetMinimumEverFreeHeapSize esp_get_minimum_free_heap_size
  4043. +
  4044. +#endif
  4045. +
  4046. +void vPortEndScheduler( void );
  4047. +
  4048. +/* *INDENT-OFF* */
  4049. +#ifdef __cplusplus
  4050. + }
  4051. +#endif
  4052. +/* *INDENT-ON* */
  4053. +
  4054. +#endif /* PORTABLE_H */
  4055. diff --git a/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/include/freertos/projdefs.h b/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/include/freertos/projdefs.h
  4056. new file mode 100644
  4057. index 0000000000..8b7c01bee7
  4058. --- /dev/null
  4059. +++ b/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/include/freertos/projdefs.h
  4060. @@ -0,0 +1,64 @@
  4061. +/*
  4062. + * FreeRTOS Kernel V10.4.6
  4063. + * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  4064. + *
  4065. + * SPDX-License-Identifier: MIT
  4066. + *
  4067. + * Permission is hereby granted, free of charge, to any person obtaining a copy of
  4068. + * this software and associated documentation files (the "Software"), to deal in
  4069. + * the Software without restriction, including without limitation the rights to
  4070. + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  4071. + * the Software, and to permit persons to whom the Software is furnished to do so,
  4072. + * subject to the following conditions:
  4073. + *
  4074. + * The above copyright notice and this permission notice shall be included in all
  4075. + * copies or substantial portions of the Software.
  4076. + *
  4077. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  4078. + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  4079. + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  4080. + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  4081. + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  4082. + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  4083. + *
  4084. + * https://www.FreeRTOS.org
  4085. + * https://github.com/FreeRTOS
  4086. + *
  4087. + */
  4088. +
  4089. +#ifndef PROJDEFS_H
  4090. +#define PROJDEFS_H
  4091. +
  4092. +/*
  4093. + * Defines the prototype to which task functions must conform. Defined in this
  4094. + * file to ensure the type is known before portable.h is included.
  4095. + */
  4096. +typedef void (* TaskFunction_t)( void * );
  4097. +
  4098. +/* Converts a time in milliseconds to a time in ticks. This macro can be
  4099. + * overridden by a macro of the same name defined in FreeRTOSConfig.h in case the
  4100. + * definition here is not suitable for your application. */
  4101. +#ifndef pdMS_TO_TICKS
  4102. + #define pdMS_TO_TICKS( xTimeInMs ) ( ( TickType_t ) rt_tick_from_millisecond( (rt_int32_t) xTimeInMs ) )
  4103. +#endif
  4104. +
  4105. +#ifdef ESP_PLATFORM
  4106. +#ifndef pdTICKS_TO_MS
  4107. + #define pdTICKS_TO_MS( xTicks ) ( ( uint32_t ) ( xTicks ) * 1000 / configTICK_RATE_HZ )
  4108. +#endif
  4109. +#endif // ESP_PLATFORM
  4110. +
  4111. +#define pdFALSE ( ( BaseType_t ) 0 )
  4112. +#define pdTRUE ( ( BaseType_t ) 1 )
  4113. +
  4114. +#define pdPASS ( pdTRUE )
  4115. +#define pdFAIL ( pdFALSE )
  4116. +#define errQUEUE_EMPTY ( ( BaseType_t ) 0 )
  4117. +#define errQUEUE_FULL ( ( BaseType_t ) 0 )
  4118. +
  4119. +/* FreeRTOS error definitions. */
  4120. +#define errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY ( -1 )
  4121. +#define errQUEUE_BLOCKED ( -4 )
  4122. +#define errQUEUE_YIELD ( -5 )
  4123. +
  4124. +#endif /* PROJDEFS_H */
  4125. diff --git a/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/include/freertos/queue.h b/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/include/freertos/queue.h
  4126. new file mode 100644
  4127. index 0000000000..57fe10ee8d
  4128. --- /dev/null
  4129. +++ b/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/include/freertos/queue.h
  4130. @@ -0,0 +1,1188 @@
  4131. +/*
  4132. + * FreeRTOS Kernel V10.4.6
  4133. + * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  4134. + *
  4135. + * SPDX-License-Identifier: MIT
  4136. + *
  4137. + * Permission is hereby granted, free of charge, to any person obtaining a copy of
  4138. + * this software and associated documentation files (the "Software"), to deal in
  4139. + * the Software without restriction, including without limitation the rights to
  4140. + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  4141. + * the Software, and to permit persons to whom the Software is furnished to do so,
  4142. + * subject to the following conditions:
  4143. + *
  4144. + * The above copyright notice and this permission notice shall be included in all
  4145. + * copies or substantial portions of the Software.
  4146. + *
  4147. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  4148. + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  4149. + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  4150. + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  4151. + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  4152. + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  4153. + *
  4154. + * https://www.FreeRTOS.org
  4155. + * https://github.com/FreeRTOS
  4156. + *
  4157. + */
  4158. +
  4159. +
  4160. +#ifndef QUEUE_H
  4161. +#define QUEUE_H
  4162. +
  4163. +/* *INDENT-OFF* */
  4164. +#ifdef __cplusplus
  4165. + extern "C" {
  4166. +#endif
  4167. +/* *INDENT-ON* */
  4168. +
  4169. +#include "task.h"
  4170. +
  4171. +/**
  4172. + * Type by which queues are referenced. For example, a call to xQueueCreate()
  4173. + * returns an QueueHandle_t variable that can then be used as a parameter to
  4174. + * xQueueSend(), xQueueReceive(), etc.
  4175. + */
  4176. +struct QueueDefinition; /* Using old naming convention so as not to break kernel aware debuggers. */
  4177. +typedef struct QueueDefinition * QueueHandle_t;
  4178. +
  4179. +/* For internal use only. */
  4180. +#define queueSEND_TO_BACK ( ( BaseType_t ) 0 )
  4181. +#define queueSEND_TO_FRONT ( ( BaseType_t ) 1 )
  4182. +#define queueOVERWRITE ( ( BaseType_t ) 2 )
  4183. +
  4184. +/* For internal use only. These definitions *must* match those in queue.c. */
  4185. +#define queueQUEUE_TYPE_BASE ( ( uint8_t ) 0U )
  4186. +#define queueQUEUE_TYPE_SET ( ( uint8_t ) 0U )
  4187. +#define queueQUEUE_TYPE_MUTEX ( ( uint8_t ) 1U )
  4188. +#define queueQUEUE_TYPE_COUNTING_SEMAPHORE ( ( uint8_t ) 2U )
  4189. +#define queueQUEUE_TYPE_BINARY_SEMAPHORE ( ( uint8_t ) 3U )
  4190. +#define queueQUEUE_TYPE_RECURSIVE_MUTEX ( ( uint8_t ) 4U )
  4191. +
  4192. +/**
  4193. + * queue. h
  4194. + * @code{c}
  4195. + * QueueHandle_t xQueueCreate(
  4196. + * UBaseType_t uxQueueLength,
  4197. + * UBaseType_t uxItemSize
  4198. + * );
  4199. + * @endcode
  4200. + *
  4201. + * Creates a new queue instance, and returns a handle by which the new queue
  4202. + * can be referenced.
  4203. + *
  4204. + * Internally, within the FreeRTOS implementation, queues use two blocks of
  4205. + * memory. The first block is used to hold the queue's data structures. The
  4206. + * second block is used to hold items placed into the queue. If a queue is
  4207. + * created using xQueueCreate() then both blocks of memory are automatically
  4208. + * dynamically allocated inside the xQueueCreate() function. (see
  4209. + * https://www.FreeRTOS.org/a00111.html). If a queue is created using
  4210. + * xQueueCreateStatic() then the application writer must provide the memory that
  4211. + * will get used by the queue. xQueueCreateStatic() therefore allows a queue to
  4212. + * be created without using any dynamic memory allocation.
  4213. + *
  4214. + * https://www.FreeRTOS.org/Embedded-RTOS-Queues.html
  4215. + *
  4216. + * @param uxQueueLength The maximum number of items that the queue can contain.
  4217. + *
  4218. + * @param uxItemSize The number of bytes each item in the queue will require.
  4219. + * Items are queued by copy, not by reference, so this is the number of bytes
  4220. + * that will be copied for each posted item. Each item on the queue must be
  4221. + * the same size.
  4222. + *
  4223. + * @return If the queue is successfully create then a handle to the newly
  4224. + * created queue is returned. If the queue cannot be created then 0 is
  4225. + * returned.
  4226. + *
  4227. + * Example usage:
  4228. + * @code{c}
  4229. + * struct AMessage
  4230. + * {
  4231. + * char ucMessageID;
  4232. + * char ucData[ 20 ];
  4233. + * };
  4234. + *
  4235. + * void vATask( void *pvParameters )
  4236. + * {
  4237. + * QueueHandle_t xQueue1, xQueue2;
  4238. + *
  4239. + * // Create a queue capable of containing 10 uint32_t values.
  4240. + * xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) );
  4241. + * if( xQueue1 == 0 )
  4242. + * {
  4243. + * // Queue was not created and must not be used.
  4244. + * }
  4245. + *
  4246. + * // Create a queue capable of containing 10 pointers to AMessage structures.
  4247. + * // These should be passed by pointer as they contain a lot of data.
  4248. + * xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
  4249. + * if( xQueue2 == 0 )
  4250. + * {
  4251. + * // Queue was not created and must not be used.
  4252. + * }
  4253. + *
  4254. + * // ... Rest of task code.
  4255. + * }
  4256. + * @endcode
  4257. + * \defgroup xQueueCreate xQueueCreate
  4258. + * \ingroup QueueManagement
  4259. + */
  4260. +#if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
  4261. + #define xQueueCreate( uxQueueLength, uxItemSize ) xQueueGenericCreate( ( uxQueueLength ), ( uxItemSize ), ( queueQUEUE_TYPE_BASE ) )
  4262. +#endif
  4263. +
  4264. +/**
  4265. + * queue. h
  4266. + * @code{c}
  4267. + * QueueHandle_t xQueueCreateStatic(
  4268. + * UBaseType_t uxQueueLength,
  4269. + * UBaseType_t uxItemSize,
  4270. + * uint8_t *pucQueueStorage,
  4271. + * StaticQueue_t *pxQueueBuffer
  4272. + * );
  4273. + * @endcode
  4274. + *
  4275. + * Creates a new queue instance, and returns a handle by which the new queue
  4276. + * can be referenced.
  4277. + *
  4278. + * Internally, within the FreeRTOS implementation, queues use two blocks of
  4279. + * memory. The first block is used to hold the queue's data structures. The
  4280. + * second block is used to hold items placed into the queue. If a queue is
  4281. + * created using xQueueCreate() then both blocks of memory are automatically
  4282. + * dynamically allocated inside the xQueueCreate() function. (see
  4283. + * https://www.FreeRTOS.org/a00111.html). If a queue is created using
  4284. + * xQueueCreateStatic() then the application writer must provide the memory that
  4285. + * will get used by the queue. xQueueCreateStatic() therefore allows a queue to
  4286. + * be created without using any dynamic memory allocation.
  4287. + *
  4288. + * https://www.FreeRTOS.org/Embedded-RTOS-Queues.html
  4289. + *
  4290. + * @param uxQueueLength The maximum number of items that the queue can contain.
  4291. + *
  4292. + * @param uxItemSize The number of bytes each item in the queue will require.
  4293. + * Items are queued by copy, not by reference, so this is the number of bytes
  4294. + * that will be copied for each posted item. Each item on the queue must be
  4295. + * the same size.
  4296. + *
  4297. + * @param pucQueueStorage If uxItemSize is not zero then
  4298. + * pucQueueStorage must point to a uint8_t array that is at least large
  4299. + * enough to hold the maximum number of items that can be in the queue at any
  4300. + * one time - which is ( uxQueueLength * uxItemsSize ) bytes. If uxItemSize is
  4301. + * zero then pucQueueStorage can be NULL.
  4302. + *
  4303. + * @param pxQueueBuffer Must point to a variable of type StaticQueue_t, which
  4304. + * will be used to hold the queue's data structure.
  4305. + *
  4306. + * @return If the queue is created then a handle to the created queue is
  4307. + * returned. If pxQueueBuffer is NULL then NULL is returned.
  4308. + *
  4309. + * Example usage:
  4310. + * @code{c}
  4311. + * struct AMessage
  4312. + * {
  4313. + * char ucMessageID;
  4314. + * char ucData[ 20 ];
  4315. + * };
  4316. + *
  4317. + #define QUEUE_LENGTH 10
  4318. + #define ITEM_SIZE sizeof( uint32_t )
  4319. + *
  4320. + * // xQueueBuffer will hold the queue structure.
  4321. + * StaticQueue_t xQueueBuffer;
  4322. + *
  4323. + * // ucQueueStorage will hold the items posted to the queue. Must be at least
  4324. + * // [(queue length) * ( queue item size)] bytes long.
  4325. + * uint8_t ucQueueStorage[ QUEUE_LENGTH * ITEM_SIZE ];
  4326. + *
  4327. + * void vATask( void *pvParameters )
  4328. + * {
  4329. + * QueueHandle_t xQueue1;
  4330. + *
  4331. + * // Create a queue capable of containing 10 uint32_t values.
  4332. + * xQueue1 = xQueueCreate( QUEUE_LENGTH, // The number of items the queue can hold.
  4333. + * ITEM_SIZE // The size of each item in the queue
  4334. + * &( ucQueueStorage[ 0 ] ), // The buffer that will hold the items in the queue.
  4335. + * &xQueueBuffer ); // The buffer that will hold the queue structure.
  4336. + *
  4337. + * // The queue is guaranteed to be created successfully as no dynamic memory
  4338. + * // allocation is used. Therefore xQueue1 is now a handle to a valid queue.
  4339. + *
  4340. + * // ... Rest of task code.
  4341. + * }
  4342. + * @endcode
  4343. + * \defgroup xQueueCreateStatic xQueueCreateStatic
  4344. + * \ingroup QueueManagement
  4345. + */
  4346. +#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
  4347. + #define xQueueCreateStatic( uxQueueLength, uxItemSize, pucQueueStorage, pxQueueBuffer ) xQueueGenericCreateStatic( ( uxQueueLength ), ( uxItemSize ), ( pucQueueStorage ), ( pxQueueBuffer ), ( queueQUEUE_TYPE_BASE ) )
  4348. +#endif /* configSUPPORT_STATIC_ALLOCATION */
  4349. +
  4350. +/**
  4351. + * queue. h
  4352. + * @code{c}
  4353. + * BaseType_t xQueueSendToToFront(
  4354. + * QueueHandle_t xQueue,
  4355. + * const void *pvItemToQueue,
  4356. + * TickType_t xTicksToWait
  4357. + * );
  4358. + * @endcode
  4359. + *
  4360. + * Post an item to the front of a queue. The item is queued by copy, not by
  4361. + * reference. This function must not be called from an interrupt service
  4362. + * routine. See xQueueSendFromISR () for an alternative which may be used
  4363. + * in an ISR.
  4364. + *
  4365. + * @param xQueue The handle to the queue on which the item is to be posted.
  4366. + *
  4367. + * @param pvItemToQueue A pointer to the item that is to be placed on the
  4368. + * queue. The size of the items the queue will hold was defined when the
  4369. + * queue was created, so this many bytes will be copied from pvItemToQueue
  4370. + * into the queue storage area.
  4371. + *
  4372. + * @param xTicksToWait The maximum amount of time the task should block
  4373. + * waiting for space to become available on the queue, should it already
  4374. + * be full. The call will return immediately if this is set to 0 and the
  4375. + * queue is full. The time is defined in tick periods so the constant
  4376. + * portTICK_PERIOD_MS should be used to convert to real time if this is required.
  4377. + *
  4378. + * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
  4379. + *
  4380. + * Example usage:
  4381. + * @code{c}
  4382. + * struct AMessage
  4383. + * {
  4384. + * char ucMessageID;
  4385. + * char ucData[ 20 ];
  4386. + * } xMessage;
  4387. + *
  4388. + * uint32_t ulVar = 10UL;
  4389. + *
  4390. + * void vATask( void *pvParameters )
  4391. + * {
  4392. + * QueueHandle_t xQueue1, xQueue2;
  4393. + * struct AMessage *pxMessage;
  4394. + *
  4395. + * // Create a queue capable of containing 10 uint32_t values.
  4396. + * xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) );
  4397. + *
  4398. + * // Create a queue capable of containing 10 pointers to AMessage structures.
  4399. + * // These should be passed by pointer as they contain a lot of data.
  4400. + * xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
  4401. + *
  4402. + * // ...
  4403. + *
  4404. + * if( xQueue1 != 0 )
  4405. + * {
  4406. + * // Send an uint32_t. Wait for 10 ticks for space to become
  4407. + * // available if necessary.
  4408. + * if( xQueueSendToFront( xQueue1, ( void * ) &ulVar, ( TickType_t ) 10 ) != pdPASS )
  4409. + * {
  4410. + * // Failed to post the message, even after 10 ticks.
  4411. + * }
  4412. + * }
  4413. + *
  4414. + * if( xQueue2 != 0 )
  4415. + * {
  4416. + * // Send a pointer to a struct AMessage object. Don't block if the
  4417. + * // queue is already full.
  4418. + * pxMessage = & xMessage;
  4419. + * xQueueSendToFront( xQueue2, ( void * ) &pxMessage, ( TickType_t ) 0 );
  4420. + * }
  4421. + *
  4422. + * // ... Rest of task code.
  4423. + * }
  4424. + * @endcode
  4425. + * \defgroup xQueueSend xQueueSend
  4426. + * \ingroup QueueManagement
  4427. + */
  4428. +#define xQueueSendToFront( xQueue, pvItemToQueue, xTicksToWait ) \
  4429. + xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_FRONT )
  4430. +
  4431. +/**
  4432. + * queue. h
  4433. + * @code{c}
  4434. + * BaseType_t xQueueSendToBack(
  4435. + * QueueHandle_t xQueue,
  4436. + * const void *pvItemToQueue,
  4437. + * TickType_t xTicksToWait
  4438. + * );
  4439. + * @endcode
  4440. + *
  4441. + * This is a macro that calls xQueueGenericSend().
  4442. + *
  4443. + * Post an item to the back of a queue. The item is queued by copy, not by
  4444. + * reference. This function must not be called from an interrupt service
  4445. + * routine. See xQueueSendFromISR () for an alternative which may be used
  4446. + * in an ISR.
  4447. + *
  4448. + * @param xQueue The handle to the queue on which the item is to be posted.
  4449. + *
  4450. + * @param pvItemToQueue A pointer to the item that is to be placed on the
  4451. + * queue. The size of the items the queue will hold was defined when the
  4452. + * queue was created, so this many bytes will be copied from pvItemToQueue
  4453. + * into the queue storage area.
  4454. + *
  4455. + * @param xTicksToWait The maximum amount of time the task should block
  4456. + * waiting for space to become available on the queue, should it already
  4457. + * be full. The call will return immediately if this is set to 0 and the queue
  4458. + * is full. The time is defined in tick periods so the constant
  4459. + * portTICK_PERIOD_MS should be used to convert to real time if this is required.
  4460. + *
  4461. + * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
  4462. + *
  4463. + * Example usage:
  4464. + * @code{c}
  4465. + * struct AMessage
  4466. + * {
  4467. + * char ucMessageID;
  4468. + * char ucData[ 20 ];
  4469. + * } xMessage;
  4470. + *
  4471. + * uint32_t ulVar = 10UL;
  4472. + *
  4473. + * void vATask( void *pvParameters )
  4474. + * {
  4475. + * QueueHandle_t xQueue1, xQueue2;
  4476. + * struct AMessage *pxMessage;
  4477. + *
  4478. + * // Create a queue capable of containing 10 uint32_t values.
  4479. + * xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) );
  4480. + *
  4481. + * // Create a queue capable of containing 10 pointers to AMessage structures.
  4482. + * // These should be passed by pointer as they contain a lot of data.
  4483. + * xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
  4484. + *
  4485. + * // ...
  4486. + *
  4487. + * if( xQueue1 != 0 )
  4488. + * {
  4489. + * // Send an uint32_t. Wait for 10 ticks for space to become
  4490. + * // available if necessary.
  4491. + * if( xQueueSendToBack( xQueue1, ( void * ) &ulVar, ( TickType_t ) 10 ) != pdPASS )
  4492. + * {
  4493. + * // Failed to post the message, even after 10 ticks.
  4494. + * }
  4495. + * }
  4496. + *
  4497. + * if( xQueue2 != 0 )
  4498. + * {
  4499. + * // Send a pointer to a struct AMessage object. Don't block if the
  4500. + * // queue is already full.
  4501. + * pxMessage = & xMessage;
  4502. + * xQueueSendToBack( xQueue2, ( void * ) &pxMessage, ( TickType_t ) 0 );
  4503. + * }
  4504. + *
  4505. + * // ... Rest of task code.
  4506. + * }
  4507. + * @endcode
  4508. + * \defgroup xQueueSend xQueueSend
  4509. + * \ingroup QueueManagement
  4510. + */
  4511. +#define xQueueSendToBack( xQueue, pvItemToQueue, xTicksToWait ) \
  4512. + xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_BACK )
  4513. +
  4514. +/**
  4515. + * queue. h
  4516. + * @code{c}
  4517. + * BaseType_t xQueueSend(
  4518. + * QueueHandle_t xQueue,
  4519. + * const void * pvItemToQueue,
  4520. + * TickType_t xTicksToWait
  4521. + * );
  4522. + * @endcode
  4523. + *
  4524. + * This is a macro that calls xQueueGenericSend(). It is included for
  4525. + * backward compatibility with versions of FreeRTOS.org that did not
  4526. + * include the xQueueSendToFront() and xQueueSendToBack() macros. It is
  4527. + * equivalent to xQueueSendToBack().
  4528. + *
  4529. + * Post an item on a queue. The item is queued by copy, not by reference.
  4530. + * This function must not be called from an interrupt service routine.
  4531. + * See xQueueSendFromISR () for an alternative which may be used in an ISR.
  4532. + *
  4533. + * @param xQueue The handle to the queue on which the item is to be posted.
  4534. + *
  4535. + * @param pvItemToQueue A pointer to the item that is to be placed on the
  4536. + * queue. The size of the items the queue will hold was defined when the
  4537. + * queue was created, so this many bytes will be copied from pvItemToQueue
  4538. + * into the queue storage area.
  4539. + *
  4540. + * @param xTicksToWait The maximum amount of time the task should block
  4541. + * waiting for space to become available on the queue, should it already
  4542. + * be full. The call will return immediately if this is set to 0 and the
  4543. + * queue is full. The time is defined in tick periods so the constant
  4544. + * portTICK_PERIOD_MS should be used to convert to real time if this is required.
  4545. + *
  4546. + * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
  4547. + *
  4548. + * Example usage:
  4549. + * @code{c}
  4550. + * struct AMessage
  4551. + * {
  4552. + * char ucMessageID;
  4553. + * char ucData[ 20 ];
  4554. + * } xMessage;
  4555. + *
  4556. + * uint32_t ulVar = 10UL;
  4557. + *
  4558. + * void vATask( void *pvParameters )
  4559. + * {
  4560. + * QueueHandle_t xQueue1, xQueue2;
  4561. + * struct AMessage *pxMessage;
  4562. + *
  4563. + * // Create a queue capable of containing 10 uint32_t values.
  4564. + * xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) );
  4565. + *
  4566. + * // Create a queue capable of containing 10 pointers to AMessage structures.
  4567. + * // These should be passed by pointer as they contain a lot of data.
  4568. + * xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
  4569. + *
  4570. + * // ...
  4571. + *
  4572. + * if( xQueue1 != 0 )
  4573. + * {
  4574. + * // Send an uint32_t. Wait for 10 ticks for space to become
  4575. + * // available if necessary.
  4576. + * if( xQueueSend( xQueue1, ( void * ) &ulVar, ( TickType_t ) 10 ) != pdPASS )
  4577. + * {
  4578. + * // Failed to post the message, even after 10 ticks.
  4579. + * }
  4580. + * }
  4581. + *
  4582. + * if( xQueue2 != 0 )
  4583. + * {
  4584. + * // Send a pointer to a struct AMessage object. Don't block if the
  4585. + * // queue is already full.
  4586. + * pxMessage = & xMessage;
  4587. + * xQueueSend( xQueue2, ( void * ) &pxMessage, ( TickType_t ) 0 );
  4588. + * }
  4589. + *
  4590. + * // ... Rest of task code.
  4591. + * }
  4592. + * @endcode
  4593. + * \defgroup xQueueSend xQueueSend
  4594. + * \ingroup QueueManagement
  4595. + */
  4596. +#define xQueueSend( xQueue, pvItemToQueue, xTicksToWait ) \
  4597. + xQueueGenericSend( ( xQueue ), ( pvItemToQueue ), ( xTicksToWait ), queueSEND_TO_BACK )
  4598. +
  4599. +/**
  4600. + * queue. h
  4601. + * @code{c}
  4602. + * BaseType_t xQueueGenericSend(
  4603. + * QueueHandle_t xQueue,
  4604. + * const void * pvItemToQueue,
  4605. + * TickType_t xTicksToWait
  4606. + * BaseType_t xCopyPosition
  4607. + * );
  4608. + * @endcode
  4609. + *
  4610. + * It is preferred that the macros xQueueSend(), xQueueSendToFront() and
  4611. + * xQueueSendToBack() are used in place of calling this function directly.
  4612. + *
  4613. + * Post an item on a queue. The item is queued by copy, not by reference.
  4614. + * This function must not be called from an interrupt service routine.
  4615. + * See xQueueSendFromISR () for an alternative which may be used in an ISR.
  4616. + *
  4617. + * @param xQueue The handle to the queue on which the item is to be posted.
  4618. + *
  4619. + * @param pvItemToQueue A pointer to the item that is to be placed on the
  4620. + * queue. The size of the items the queue will hold was defined when the
  4621. + * queue was created, so this many bytes will be copied from pvItemToQueue
  4622. + * into the queue storage area.
  4623. + *
  4624. + * @param xTicksToWait The maximum amount of time the task should block
  4625. + * waiting for space to become available on the queue, should it already
  4626. + * be full. The call will return immediately if this is set to 0 and the
  4627. + * queue is full. The time is defined in tick periods so the constant
  4628. + * portTICK_PERIOD_MS should be used to convert to real time if this is required.
  4629. + *
  4630. + * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the
  4631. + * item at the back of the queue, or queueSEND_TO_FRONT to place the item
  4632. + * at the front of the queue (for high priority messages).
  4633. + *
  4634. + * @return pdTRUE if the item was successfully posted, otherwise errQUEUE_FULL.
  4635. + *
  4636. + * Example usage:
  4637. + * @code{c}
  4638. + * struct AMessage
  4639. + * {
  4640. + * char ucMessageID;
  4641. + * char ucData[ 20 ];
  4642. + * } xMessage;
  4643. + *
  4644. + * uint32_t ulVar = 10UL;
  4645. + *
  4646. + * void vATask( void *pvParameters )
  4647. + * {
  4648. + * QueueHandle_t xQueue1, xQueue2;
  4649. + * struct AMessage *pxMessage;
  4650. + *
  4651. + * // Create a queue capable of containing 10 uint32_t values.
  4652. + * xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) );
  4653. + *
  4654. + * // Create a queue capable of containing 10 pointers to AMessage structures.
  4655. + * // These should be passed by pointer as they contain a lot of data.
  4656. + * xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
  4657. + *
  4658. + * // ...
  4659. + *
  4660. + * if( xQueue1 != 0 )
  4661. + * {
  4662. + * // Send an uint32_t. Wait for 10 ticks for space to become
  4663. + * // available if necessary.
  4664. + * if( xQueueGenericSend( xQueue1, ( void * ) &ulVar, ( TickType_t ) 10, queueSEND_TO_BACK ) != pdPASS )
  4665. + * {
  4666. + * // Failed to post the message, even after 10 ticks.
  4667. + * }
  4668. + * }
  4669. + *
  4670. + * if( xQueue2 != 0 )
  4671. + * {
  4672. + * // Send a pointer to a struct AMessage object. Don't block if the
  4673. + * // queue is already full.
  4674. + * pxMessage = & xMessage;
  4675. + * xQueueGenericSend( xQueue2, ( void * ) &pxMessage, ( TickType_t ) 0, queueSEND_TO_BACK );
  4676. + * }
  4677. + *
  4678. + * // ... Rest of task code.
  4679. + * }
  4680. + * @endcode
  4681. + * \defgroup xQueueSend xQueueSend
  4682. + * \ingroup QueueManagement
  4683. + */
  4684. +BaseType_t xQueueGenericSend( QueueHandle_t xQueue,
  4685. + const void * const pvItemToQueue,
  4686. + TickType_t xTicksToWait,
  4687. + const BaseType_t xCopyPosition );
  4688. +
  4689. +/**
  4690. + * queue. h
  4691. + * @code{c}
  4692. + * BaseType_t xQueueReceive(
  4693. + * QueueHandle_t xQueue,
  4694. + * void *pvBuffer,
  4695. + * TickType_t xTicksToWait
  4696. + * );
  4697. + * @endcode
  4698. + *
  4699. + * Receive an item from a queue. The item is received by copy so a buffer of
  4700. + * adequate size must be provided. The number of bytes copied into the buffer
  4701. + * was defined when the queue was created.
  4702. + *
  4703. + * Successfully received items are removed from the queue.
  4704. + *
  4705. + * This function must not be used in an interrupt service routine. See
  4706. + * xQueueReceiveFromISR for an alternative that can.
  4707. + *
  4708. + * @param xQueue The handle to the queue from which the item is to be
  4709. + * received.
  4710. + *
  4711. + * @param pvBuffer Pointer to the buffer into which the received item will
  4712. + * be copied.
  4713. + *
  4714. + * @param xTicksToWait The maximum amount of time the task should block
  4715. + * waiting for an item to receive should the queue be empty at the time
  4716. + * of the call. xQueueReceive() will return immediately if xTicksToWait
  4717. + * is zero and the queue is empty. The time is defined in tick periods so the
  4718. + * constant portTICK_PERIOD_MS should be used to convert to real time if this is
  4719. + * required.
  4720. + *
  4721. + * @return pdTRUE if an item was successfully received from the queue,
  4722. + * otherwise pdFALSE.
  4723. + *
  4724. + * Example usage:
  4725. + * @code{c}
  4726. + * struct AMessage
  4727. + * {
  4728. + * char ucMessageID;
  4729. + * char ucData[ 20 ];
  4730. + * } xMessage;
  4731. + *
  4732. + * QueueHandle_t xQueue;
  4733. + *
  4734. + * // Task to create a queue and post a value.
  4735. + * void vATask( void *pvParameters )
  4736. + * {
  4737. + * struct AMessage *pxMessage;
  4738. + *
  4739. + * // Create a queue capable of containing 10 pointers to AMessage structures.
  4740. + * // These should be passed by pointer as they contain a lot of data.
  4741. + * xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );
  4742. + * if( xQueue == 0 )
  4743. + * {
  4744. + * // Failed to create the queue.
  4745. + * }
  4746. + *
  4747. + * // ...
  4748. + *
  4749. + * // Send a pointer to a struct AMessage object. Don't block if the
  4750. + * // queue is already full.
  4751. + * pxMessage = & xMessage;
  4752. + * xQueueSend( xQueue, ( void * ) &pxMessage, ( TickType_t ) 0 );
  4753. + *
  4754. + * // ... Rest of task code.
  4755. + * }
  4756. + *
  4757. + * // Task to receive from the queue.
  4758. + * void vADifferentTask( void *pvParameters )
  4759. + * {
  4760. + * struct AMessage *pxRxedMessage;
  4761. + *
  4762. + * if( xQueue != 0 )
  4763. + * {
  4764. + * // Receive a message on the created queue. Block for 10 ticks if a
  4765. + * // message is not immediately available.
  4766. + * if( xQueueReceive( xQueue, &( pxRxedMessage ), ( TickType_t ) 10 ) )
  4767. + * {
  4768. + * // pcRxedMessage now points to the struct AMessage variable posted
  4769. + * // by vATask.
  4770. + * }
  4771. + * }
  4772. + *
  4773. + * // ... Rest of task code.
  4774. + * }
  4775. + * @endcode
  4776. + * \defgroup xQueueReceive xQueueReceive
  4777. + * \ingroup QueueManagement
  4778. + */
  4779. +BaseType_t xQueueReceive( QueueHandle_t xQueue,
  4780. + void * const pvBuffer,
  4781. + TickType_t xTicksToWait );
  4782. +
  4783. +/**
  4784. + * queue. h
  4785. + * @code{c}
  4786. + * UBaseType_t uxQueueMessagesWaiting( const QueueHandle_t xQueue );
  4787. + * @endcode
  4788. + *
  4789. + * Return the number of messages stored in a queue.
  4790. + *
  4791. + * @param xQueue A handle to the queue being queried.
  4792. + *
  4793. + * @return The number of messages available in the queue.
  4794. + *
  4795. + * \defgroup uxQueueMessagesWaiting uxQueueMessagesWaiting
  4796. + * \ingroup QueueManagement
  4797. + */
  4798. +UBaseType_t uxQueueMessagesWaiting( const QueueHandle_t xQueue );
  4799. +
  4800. +/**
  4801. + * queue. h
  4802. + * @code{c}
  4803. + * UBaseType_t uxQueueSpacesAvailable( const QueueHandle_t xQueue );
  4804. + * @endcode
  4805. + *
  4806. + * Return the number of free spaces available in a queue. This is equal to the
  4807. + * number of items that can be sent to the queue before the queue becomes full
  4808. + * if no items are removed.
  4809. + *
  4810. + * @param xQueue A handle to the queue being queried.
  4811. + *
  4812. + * @return The number of spaces available in the queue.
  4813. + *
  4814. + * \defgroup uxQueueMessagesWaiting uxQueueMessagesWaiting
  4815. + * \ingroup QueueManagement
  4816. + */
  4817. +UBaseType_t uxQueueSpacesAvailable( const QueueHandle_t xQueue );
  4818. +
  4819. +/**
  4820. + * queue. h
  4821. + * @code{c}
  4822. + * void vQueueDelete( QueueHandle_t xQueue );
  4823. + * @endcode
  4824. + *
  4825. + * Delete a queue - freeing all the memory allocated for storing of items
  4826. + * placed on the queue.
  4827. + *
  4828. + * @param xQueue A handle to the queue to be deleted.
  4829. + *
  4830. + * \defgroup vQueueDelete vQueueDelete
  4831. + * \ingroup QueueManagement
  4832. + */
  4833. +void vQueueDelete( QueueHandle_t xQueue );
  4834. +
  4835. +/**
  4836. + * queue. h
  4837. + * @code{c}
  4838. + * BaseType_t xQueueSendToFrontFromISR(
  4839. + * QueueHandle_t xQueue,
  4840. + * const void *pvItemToQueue,
  4841. + * BaseType_t *pxHigherPriorityTaskWoken
  4842. + * );
  4843. + * @endcode
  4844. + *
  4845. + * This is a macro that calls xQueueGenericSendFromISR().
  4846. + *
  4847. + * Post an item to the front of a queue. It is safe to use this macro from
  4848. + * within an interrupt service routine.
  4849. + *
  4850. + * Items are queued by copy not reference so it is preferable to only
  4851. + * queue small items, especially when called from an ISR. In most cases
  4852. + * it would be preferable to store a pointer to the item being queued.
  4853. + *
  4854. + * @param xQueue The handle to the queue on which the item is to be posted.
  4855. + *
  4856. + * @param pvItemToQueue A pointer to the item that is to be placed on the
  4857. + * queue. The size of the items the queue will hold was defined when the
  4858. + * queue was created, so this many bytes will be copied from pvItemToQueue
  4859. + * into the queue storage area.
  4860. + *
  4861. + * @param pxHigherPriorityTaskWoken xQueueSendToFrontFromISR() will set
  4862. + * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
  4863. + * to unblock, and the unblocked task has a priority higher than the currently
  4864. + * running task. If xQueueSendToFromFromISR() sets this value to pdTRUE then
  4865. + * a context switch should be requested before the interrupt is exited.
  4866. + *
  4867. + * @return pdTRUE if the data was successfully sent to the queue, otherwise
  4868. + * errQUEUE_FULL.
  4869. + *
  4870. + * Example usage for buffered IO (where the ISR can obtain more than one value
  4871. + * per call):
  4872. + * @code{c}
  4873. + * void vBufferISR( void )
  4874. + * {
  4875. + * char cIn;
  4876. + * BaseType_t xHigherPrioritTaskWoken;
  4877. + *
  4878. + * // We have not woken a task at the start of the ISR.
  4879. + * xHigherPriorityTaskWoken = pdFALSE;
  4880. + *
  4881. + * // Loop until the buffer is empty.
  4882. + * do
  4883. + * {
  4884. + * // Obtain a byte from the buffer.
  4885. + * cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
  4886. + *
  4887. + * // Post the byte.
  4888. + * xQueueSendToFrontFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
  4889. + *
  4890. + * } while( portINPUT_BYTE( BUFFER_COUNT ) );
  4891. + *
  4892. + * // Now the buffer is empty we can switch context if necessary.
  4893. + * if( xHigherPriorityTaskWoken )
  4894. + * {
  4895. + * taskYIELD ();
  4896. + * }
  4897. + * }
  4898. + * @endcode
  4899. + *
  4900. + * \defgroup xQueueSendFromISR xQueueSendFromISR
  4901. + * \ingroup QueueManagement
  4902. + */
  4903. +#define xQueueSendToFrontFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) \
  4904. + xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_FRONT )
  4905. +
  4906. +
  4907. +/**
  4908. + * queue. h
  4909. + * @code{c}
  4910. + * BaseType_t xQueueSendToBackFromISR(
  4911. + * QueueHandle_t xQueue,
  4912. + * const void *pvItemToQueue,
  4913. + * BaseType_t *pxHigherPriorityTaskWoken
  4914. + * );
  4915. + * @endcode
  4916. + *
  4917. + * This is a macro that calls xQueueGenericSendFromISR().
  4918. + *
  4919. + * Post an item to the back of a queue. It is safe to use this macro from
  4920. + * within an interrupt service routine.
  4921. + *
  4922. + * Items are queued by copy not reference so it is preferable to only
  4923. + * queue small items, especially when called from an ISR. In most cases
  4924. + * it would be preferable to store a pointer to the item being queued.
  4925. + *
  4926. + * @param xQueue The handle to the queue on which the item is to be posted.
  4927. + *
  4928. + * @param pvItemToQueue A pointer to the item that is to be placed on the
  4929. + * queue. The size of the items the queue will hold was defined when the
  4930. + * queue was created, so this many bytes will be copied from pvItemToQueue
  4931. + * into the queue storage area.
  4932. + *
  4933. + * @param pxHigherPriorityTaskWoken xQueueSendToBackFromISR() will set
  4934. + * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
  4935. + * to unblock, and the unblocked task has a priority higher than the currently
  4936. + * running task. If xQueueSendToBackFromISR() sets this value to pdTRUE then
  4937. + * a context switch should be requested before the interrupt is exited.
  4938. + *
  4939. + * @return pdTRUE if the data was successfully sent to the queue, otherwise
  4940. + * errQUEUE_FULL.
  4941. + *
  4942. + * Example usage for buffered IO (where the ISR can obtain more than one value
  4943. + * per call):
  4944. + * @code{c}
  4945. + * void vBufferISR( void )
  4946. + * {
  4947. + * char cIn;
  4948. + * BaseType_t xHigherPriorityTaskWoken;
  4949. + *
  4950. + * // We have not woken a task at the start of the ISR.
  4951. + * xHigherPriorityTaskWoken = pdFALSE;
  4952. + *
  4953. + * // Loop until the buffer is empty.
  4954. + * do
  4955. + * {
  4956. + * // Obtain a byte from the buffer.
  4957. + * cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
  4958. + *
  4959. + * // Post the byte.
  4960. + * xQueueSendToBackFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
  4961. + *
  4962. + * } while( portINPUT_BYTE( BUFFER_COUNT ) );
  4963. + *
  4964. + * // Now the buffer is empty we can switch context if necessary.
  4965. + * if( xHigherPriorityTaskWoken )
  4966. + * {
  4967. + * taskYIELD ();
  4968. + * }
  4969. + * }
  4970. + * @endcode
  4971. + *
  4972. + * \defgroup xQueueSendFromISR xQueueSendFromISR
  4973. + * \ingroup QueueManagement
  4974. + */
  4975. +#define xQueueSendToBackFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) \
  4976. + xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_BACK )
  4977. +
  4978. +/**
  4979. + * queue. h
  4980. + * @code{c}
  4981. + * BaseType_t xQueueSendFromISR(
  4982. + * QueueHandle_t xQueue,
  4983. + * const void *pvItemToQueue,
  4984. + * BaseType_t *pxHigherPriorityTaskWoken
  4985. + * );
  4986. + * @endcode
  4987. + *
  4988. + * This is a macro that calls xQueueGenericSendFromISR(). It is included
  4989. + * for backward compatibility with versions of FreeRTOS.org that did not
  4990. + * include the xQueueSendToBackFromISR() and xQueueSendToFrontFromISR()
  4991. + * macros.
  4992. + *
  4993. + * Post an item to the back of a queue. It is safe to use this function from
  4994. + * within an interrupt service routine.
  4995. + *
  4996. + * Items are queued by copy not reference so it is preferable to only
  4997. + * queue small items, especially when called from an ISR. In most cases
  4998. + * it would be preferable to store a pointer to the item being queued.
  4999. + *
  5000. + * @param xQueue The handle to the queue on which the item is to be posted.
  5001. + *
  5002. + * @param pvItemToQueue A pointer to the item that is to be placed on the
  5003. + * queue. The size of the items the queue will hold was defined when the
  5004. + * queue was created, so this many bytes will be copied from pvItemToQueue
  5005. + * into the queue storage area.
  5006. + *
  5007. + * @param pxHigherPriorityTaskWoken xQueueSendFromISR() will set
  5008. + * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
  5009. + * to unblock, and the unblocked task has a priority higher than the currently
  5010. + * running task. If xQueueSendFromISR() sets this value to pdTRUE then
  5011. + * a context switch should be requested before the interrupt is exited.
  5012. + *
  5013. + * @return pdTRUE if the data was successfully sent to the queue, otherwise
  5014. + * errQUEUE_FULL.
  5015. + *
  5016. + * Example usage for buffered IO (where the ISR can obtain more than one value
  5017. + * per call):
  5018. + * @code{c}
  5019. + * void vBufferISR( void )
  5020. + * {
  5021. + * char cIn;
  5022. + * BaseType_t xHigherPriorityTaskWoken;
  5023. + *
  5024. + * // We have not woken a task at the start of the ISR.
  5025. + * xHigherPriorityTaskWoken = pdFALSE;
  5026. + *
  5027. + * // Loop until the buffer is empty.
  5028. + * do
  5029. + * {
  5030. + * // Obtain a byte from the buffer.
  5031. + * cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
  5032. + *
  5033. + * // Post the byte.
  5034. + * xQueueSendFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWoken );
  5035. + *
  5036. + * } while( portINPUT_BYTE( BUFFER_COUNT ) );
  5037. + *
  5038. + * // Now the buffer is empty we can switch context if necessary.
  5039. + * if( xHigherPriorityTaskWoken )
  5040. + * {
  5041. + * // Actual macro used here is port specific.
  5042. + * portYIELD_FROM_ISR ();
  5043. + * }
  5044. + * }
  5045. + * @endcode
  5046. + *
  5047. + * \defgroup xQueueSendFromISR xQueueSendFromISR
  5048. + * \ingroup QueueManagement
  5049. + */
  5050. +#define xQueueSendFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) \
  5051. + xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), ( pxHigherPriorityTaskWoken ), queueSEND_TO_BACK )
  5052. +
  5053. +/**
  5054. + * queue. h
  5055. + * @code{c}
  5056. + * BaseType_t xQueueGenericSendFromISR(
  5057. + * QueueHandle_t xQueue,
  5058. + * const void *pvItemToQueue,
  5059. + * BaseType_t *pxHigherPriorityTaskWoken,
  5060. + * BaseType_t xCopyPosition
  5061. + * );
  5062. + * @endcode
  5063. + *
  5064. + * It is preferred that the macros xQueueSendFromISR(),
  5065. + * xQueueSendToFrontFromISR() and xQueueSendToBackFromISR() be used in place
  5066. + * of calling this function directly. xQueueGiveFromISR() is an
  5067. + * equivalent for use by semaphores that don't actually copy any data.
  5068. + *
  5069. + * Post an item on a queue. It is safe to use this function from within an
  5070. + * interrupt service routine.
  5071. + *
  5072. + * Items are queued by copy not reference so it is preferable to only
  5073. + * queue small items, especially when called from an ISR. In most cases
  5074. + * it would be preferable to store a pointer to the item being queued.
  5075. + *
  5076. + * @param xQueue The handle to the queue on which the item is to be posted.
  5077. + *
  5078. + * @param pvItemToQueue A pointer to the item that is to be placed on the
  5079. + * queue. The size of the items the queue will hold was defined when the
  5080. + * queue was created, so this many bytes will be copied from pvItemToQueue
  5081. + * into the queue storage area.
  5082. + *
  5083. + * @param pxHigherPriorityTaskWoken xQueueGenericSendFromISR() will set
  5084. + * *pxHigherPriorityTaskWoken to pdTRUE if sending to the queue caused a task
  5085. + * to unblock, and the unblocked task has a priority higher than the currently
  5086. + * running task. If xQueueGenericSendFromISR() sets this value to pdTRUE then
  5087. + * a context switch should be requested before the interrupt is exited.
  5088. + *
  5089. + * @param xCopyPosition Can take the value queueSEND_TO_BACK to place the
  5090. + * item at the back of the queue, or queueSEND_TO_FRONT to place the item
  5091. + * at the front of the queue (for high priority messages).
  5092. + *
  5093. + * @return pdTRUE if the data was successfully sent to the queue, otherwise
  5094. + * errQUEUE_FULL.
  5095. + *
  5096. + * Example usage for buffered IO (where the ISR can obtain more than one value
  5097. + * per call):
  5098. + * @code{c}
  5099. + * void vBufferISR( void )
  5100. + * {
  5101. + * char cIn;
  5102. + * BaseType_t xHigherPriorityTaskWokenByPost;
  5103. + *
  5104. + * // We have not woken a task at the start of the ISR.
  5105. + * xHigherPriorityTaskWokenByPost = pdFALSE;
  5106. + *
  5107. + * // Loop until the buffer is empty.
  5108. + * do
  5109. + * {
  5110. + * // Obtain a byte from the buffer.
  5111. + * cIn = portINPUT_BYTE( RX_REGISTER_ADDRESS );
  5112. + *
  5113. + * // Post each byte.
  5114. + * xQueueGenericSendFromISR( xRxQueue, &cIn, &xHigherPriorityTaskWokenByPost, queueSEND_TO_BACK );
  5115. + *
  5116. + * } while( portINPUT_BYTE( BUFFER_COUNT ) );
  5117. + *
  5118. + * // Now the buffer is empty we can switch context if necessary. Note that the
  5119. + * // name of the yield function required is port specific.
  5120. + * if( xHigherPriorityTaskWokenByPost )
  5121. + * {
  5122. + * portYIELD_FROM_ISR();
  5123. + * }
  5124. + * }
  5125. + * @endcode
  5126. + *
  5127. + * \defgroup xQueueSendFromISR xQueueSendFromISR
  5128. + * \ingroup QueueManagement
  5129. + */
  5130. +BaseType_t xQueueGenericSendFromISR( QueueHandle_t xQueue,
  5131. + const void * const pvItemToQueue,
  5132. + BaseType_t * const pxHigherPriorityTaskWoken,
  5133. + const BaseType_t xCopyPosition );
  5134. +BaseType_t xQueueGiveFromISR( QueueHandle_t xQueue,
  5135. + BaseType_t * const pxHigherPriorityTaskWoken );
  5136. +
  5137. +/**
  5138. + * queue. h
  5139. + * @code{c}
  5140. + * BaseType_t xQueueReceiveFromISR(
  5141. + * QueueHandle_t xQueue,
  5142. + * void *pvBuffer,
  5143. + * BaseType_t *pxTaskWoken
  5144. + * );
  5145. + * @endcode
  5146. + *
  5147. + * Receive an item from a queue. It is safe to use this function from within an
  5148. + * interrupt service routine.
  5149. + *
  5150. + * @param xQueue The handle to the queue from which the item is to be
  5151. + * received.
  5152. + *
  5153. + * @param pvBuffer Pointer to the buffer into which the received item will
  5154. + * be copied.
  5155. + *
  5156. + * @param pxTaskWoken A task may be blocked waiting for space to become
  5157. + * available on the queue. If xQueueReceiveFromISR causes such a task to
  5158. + * unblock *pxTaskWoken will get set to pdTRUE, otherwise *pxTaskWoken will
  5159. + * remain unchanged.
  5160. + *
  5161. + * @return pdTRUE if an item was successfully received from the queue,
  5162. + * otherwise pdFALSE.
  5163. + *
  5164. + * Example usage:
  5165. + * @code{c}
  5166. + *
  5167. + * QueueHandle_t xQueue;
  5168. + *
  5169. + * // Function to create a queue and post some values.
  5170. + * void vAFunction( void *pvParameters )
  5171. + * {
  5172. + * char cValueToPost;
  5173. + * const TickType_t xTicksToWait = ( TickType_t )0xff;
  5174. + *
  5175. + * // Create a queue capable of containing 10 characters.
  5176. + * xQueue = xQueueCreate( 10, sizeof( char ) );
  5177. + * if( xQueue == 0 )
  5178. + * {
  5179. + * // Failed to create the queue.
  5180. + * }
  5181. + *
  5182. + * // ...
  5183. + *
  5184. + * // Post some characters that will be used within an ISR. If the queue
  5185. + * // is full then this task will block for xTicksToWait ticks.
  5186. + * cValueToPost = 'a';
  5187. + * xQueueSend( xQueue, ( void * ) &cValueToPost, xTicksToWait );
  5188. + * cValueToPost = 'b';
  5189. + * xQueueSend( xQueue, ( void * ) &cValueToPost, xTicksToWait );
  5190. + *
  5191. + * // ... keep posting characters ... this task may block when the queue
  5192. + * // becomes full.
  5193. + *
  5194. + * cValueToPost = 'c';
  5195. + * xQueueSend( xQueue, ( void * ) &cValueToPost, xTicksToWait );
  5196. + * }
  5197. + *
  5198. + * // ISR that outputs all the characters received on the queue.
  5199. + * void vISR_Routine( void )
  5200. + * {
  5201. + * BaseType_t xTaskWokenByReceive = pdFALSE;
  5202. + * char cRxedChar;
  5203. + *
  5204. + * while( xQueueReceiveFromISR( xQueue, ( void * ) &cRxedChar, &xTaskWokenByReceive) )
  5205. + * {
  5206. + * // A character was received. Output the character now.
  5207. + * vOutputCharacter( cRxedChar );
  5208. + *
  5209. + * // If removing the character from the queue woke the task that was
  5210. + * // posting onto the queue cTaskWokenByReceive will have been set to
  5211. + * // pdTRUE. No matter how many times this loop iterates only one
  5212. + * // task will be woken.
  5213. + * }
  5214. + *
  5215. + * if( cTaskWokenByPost != ( char ) pdFALSE;
  5216. + * {
  5217. + * taskYIELD ();
  5218. + * }
  5219. + * }
  5220. + * @endcode
  5221. + * \defgroup xQueueReceiveFromISR xQueueReceiveFromISR
  5222. + * \ingroup QueueManagement
  5223. + */
  5224. +BaseType_t xQueueReceiveFromISR( QueueHandle_t xQueue,
  5225. + void * const pvBuffer,
  5226. + BaseType_t * const pxHigherPriorityTaskWoken );
  5227. +
  5228. +/*
  5229. + * Utilities to query queues that are safe to use from an ISR. These utilities
  5230. + * should be used only from witin an ISR, or within a critical section.
  5231. + */
  5232. +BaseType_t xQueueIsQueueEmptyFromISR( const QueueHandle_t xQueue );
  5233. +BaseType_t xQueueIsQueueFullFromISR( const QueueHandle_t xQueue );
  5234. +UBaseType_t uxQueueMessagesWaitingFromISR( const QueueHandle_t xQueue );
  5235. +
  5236. +/*
  5237. + * For internal use only. Use xSemaphoreCreateMutex(),
  5238. + * xSemaphoreCreateCounting() or xSemaphoreGetMutexHolder() instead of calling
  5239. + * these functions directly.
  5240. + */
  5241. +QueueHandle_t xQueueCreateMutex( const uint8_t ucQueueType );
  5242. +QueueHandle_t xQueueCreateMutexStatic( const uint8_t ucQueueType,
  5243. + StaticQueue_t * pxStaticQueue );
  5244. +QueueHandle_t xQueueCreateCountingSemaphore( const UBaseType_t uxMaxCount,
  5245. + const UBaseType_t uxInitialCount );
  5246. +QueueHandle_t xQueueCreateCountingSemaphoreStatic( const UBaseType_t uxMaxCount,
  5247. + const UBaseType_t uxInitialCount,
  5248. + StaticQueue_t * pxStaticQueue );
  5249. +BaseType_t xQueueSemaphoreTake( QueueHandle_t xQueue,
  5250. + TickType_t xTicksToWait );
  5251. +TaskHandle_t xQueueGetMutexHolder( QueueHandle_t xSemaphore );
  5252. +TaskHandle_t xQueueGetMutexHolderFromISR( QueueHandle_t xSemaphore );
  5253. +
  5254. +/*
  5255. + * For internal use only. Use xSemaphoreTakeMutexRecursive() or
  5256. + * xSemaphoreGiveMutexRecursive() instead of calling these functions directly.
  5257. + */
  5258. +BaseType_t xQueueTakeMutexRecursive( QueueHandle_t xMutex,
  5259. + TickType_t xTicksToWait );
  5260. +BaseType_t xQueueGiveMutexRecursive( QueueHandle_t xMutex );
  5261. +
  5262. +/*
  5263. + * Reset a queue back to its original empty state. The return value is now
  5264. + * obsolete and is always set to pdPASS.
  5265. + */
  5266. +#define xQueueReset( xQueue ) xQueueGenericReset( xQueue, pdFALSE )
  5267. +
  5268. +/*
  5269. + * Generic version of the function used to create a queue using dynamic memory
  5270. + * allocation. This is called by other functions and macros that create other
  5271. + * RTOS objects that use the queue structure as their base.
  5272. + */
  5273. +#if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
  5274. + QueueHandle_t xQueueGenericCreate( const UBaseType_t uxQueueLength,
  5275. + const UBaseType_t uxItemSize,
  5276. + const uint8_t ucQueueType );
  5277. +#endif
  5278. +
  5279. +/*
  5280. + * Generic version of the function used to create a queue using dynamic memory
  5281. + * allocation. This is called by other functions and macros that create other
  5282. + * RTOS objects that use the queue structure as their base.
  5283. + */
  5284. +#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
  5285. + QueueHandle_t xQueueGenericCreateStatic( const UBaseType_t uxQueueLength,
  5286. + const UBaseType_t uxItemSize,
  5287. + uint8_t * pucQueueStorage,
  5288. + StaticQueue_t * pxStaticQueue,
  5289. + const uint8_t ucQueueType );
  5290. +#endif
  5291. +
  5292. +/* Not public API functions. */
  5293. +BaseType_t xQueueGenericReset( QueueHandle_t xQueue,
  5294. + BaseType_t xNewQueue );
  5295. +
  5296. +/* Unimplemented */
  5297. +typedef struct QueueDefinition * QueueSetHandle_t;
  5298. +typedef struct QueueDefinition * QueueSetMemberHandle_t;
  5299. +QueueSetHandle_t xQueueCreateSet( const UBaseType_t uxEventQueueLength );
  5300. +BaseType_t xQueueAddToSet( QueueSetMemberHandle_t xQueueOrSemaphore,
  5301. + QueueSetHandle_t xQueueSet );
  5302. +BaseType_t xQueueRemoveFromSet( QueueSetMemberHandle_t xQueueOrSemaphore,
  5303. + QueueSetHandle_t xQueueSet );
  5304. +QueueSetMemberHandle_t xQueueSelectFromSet( QueueSetHandle_t xQueueSet,
  5305. + const TickType_t xTicksToWait );
  5306. +QueueSetMemberHandle_t xQueueSelectFromSetFromISR( QueueSetHandle_t xQueueSet );
  5307. +BaseType_t xQueuePeek( QueueHandle_t xQueue,
  5308. + void * const pvBuffer,
  5309. + TickType_t xTicksToWait );
  5310. +BaseType_t xQueueOverwrite(QueueHandle_t xQueue, const void * pvItemToQueue);
  5311. +BaseType_t xQueueOverwriteFromISR(QueueHandle_t xQueue, const void * pvItemToQueue, BaseType_t *pxHigherPriorityTaskWoken);
  5312. +/* *INDENT-OFF* */
  5313. +#ifdef __cplusplus
  5314. + }
  5315. +#endif
  5316. +/* *INDENT-ON* */
  5317. +
  5318. +#endif /* QUEUE_H */
  5319. diff --git a/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/include/freertos/semphr.h b/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/include/freertos/semphr.h
  5320. new file mode 100644
  5321. index 0000000000..053dd177cf
  5322. --- /dev/null
  5323. +++ b/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/include/freertos/semphr.h
  5324. @@ -0,0 +1,1188 @@
  5325. +/*
  5326. + * FreeRTOS Kernel V10.4.6
  5327. + * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  5328. + *
  5329. + * SPDX-License-Identifier: MIT
  5330. + *
  5331. + * Permission is hereby granted, free of charge, to any person obtaining a copy of
  5332. + * this software and associated documentation files (the "Software"), to deal in
  5333. + * the Software without restriction, including without limitation the rights to
  5334. + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  5335. + * the Software, and to permit persons to whom the Software is furnished to do so,
  5336. + * subject to the following conditions:
  5337. + *
  5338. + * The above copyright notice and this permission notice shall be included in all
  5339. + * copies or substantial portions of the Software.
  5340. + *
  5341. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  5342. + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  5343. + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  5344. + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  5345. + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  5346. + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  5347. + *
  5348. + * https://www.FreeRTOS.org
  5349. + * https://github.com/FreeRTOS
  5350. + *
  5351. + */
  5352. +
  5353. +#ifndef SEMAPHORE_H
  5354. +#define SEMAPHORE_H
  5355. +
  5356. +#ifndef INC_FREERTOS_H
  5357. + #error "include FreeRTOS.h" must appear in source files before "include semphr.h"
  5358. +#endif
  5359. +
  5360. +#include "queue.h"
  5361. +
  5362. +typedef QueueHandle_t SemaphoreHandle_t;
  5363. +
  5364. +#define semBINARY_SEMAPHORE_QUEUE_LENGTH ( ( uint8_t ) 1U )
  5365. +#define semSEMAPHORE_QUEUE_ITEM_LENGTH ( ( uint8_t ) 0U )
  5366. +#define semGIVE_BLOCK_TIME ( ( TickType_t ) 0U )
  5367. +
  5368. +
  5369. +/**
  5370. + * semphr. h
  5371. + * @code{c}
  5372. + * vSemaphoreCreateBinary( SemaphoreHandle_t xSemaphore );
  5373. + * @endcode
  5374. + *
  5375. + * In many usage scenarios it is faster and more memory efficient to use a
  5376. + * direct to task notification in place of a binary semaphore!
  5377. + * https://www.FreeRTOS.org/RTOS-task-notifications.html
  5378. + *
  5379. + * This old vSemaphoreCreateBinary() macro is now deprecated in favour of the
  5380. + * xSemaphoreCreateBinary() function. Note that binary semaphores created using
  5381. + * the vSemaphoreCreateBinary() macro are created in a state such that the
  5382. + * first call to 'take' the semaphore would pass, whereas binary semaphores
  5383. + * created using xSemaphoreCreateBinary() are created in a state such that the
  5384. + * the semaphore must first be 'given' before it can be 'taken'.
  5385. + *
  5386. + * <i>Macro</i> that implements a semaphore by using the existing queue mechanism.
  5387. + * The queue length is 1 as this is a binary semaphore. The data size is 0
  5388. + * as we don't want to actually store any data - we just want to know if the
  5389. + * queue is empty or full.
  5390. + *
  5391. + * This type of semaphore can be used for pure synchronisation between tasks or
  5392. + * between an interrupt and a task. The semaphore need not be given back once
  5393. + * obtained, so one task/interrupt can continuously 'give' the semaphore while
  5394. + * another continuously 'takes' the semaphore. For this reason this type of
  5395. + * semaphore does not use a priority inheritance mechanism. For an alternative
  5396. + * that does use priority inheritance see xSemaphoreCreateMutex().
  5397. + *
  5398. + * @param xSemaphore Handle to the created semaphore. Should be of type SemaphoreHandle_t.
  5399. + *
  5400. + * Example usage:
  5401. + * @code{c}
  5402. + * SemaphoreHandle_t xSemaphore = NULL;
  5403. + *
  5404. + * void vATask( void * pvParameters )
  5405. + * {
  5406. + * // Semaphore cannot be used before a call to vSemaphoreCreateBinary ().
  5407. + * // This is a macro so pass the variable in directly.
  5408. + * vSemaphoreCreateBinary( xSemaphore );
  5409. + *
  5410. + * if( xSemaphore != NULL )
  5411. + * {
  5412. + * // The semaphore was created successfully.
  5413. + * // The semaphore can now be used.
  5414. + * }
  5415. + * }
  5416. + * @endcode
  5417. + * \defgroup vSemaphoreCreateBinary vSemaphoreCreateBinary
  5418. + * \ingroup Semaphores
  5419. + */
  5420. +#if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
  5421. + #define vSemaphoreCreateBinary( xSemaphore ) \
  5422. + { \
  5423. + ( xSemaphore ) = xQueueGenericCreate( ( UBaseType_t ) 1, semSEMAPHORE_QUEUE_ITEM_LENGTH, queueQUEUE_TYPE_BINARY_SEMAPHORE ); \
  5424. + if( ( xSemaphore ) != NULL ) \
  5425. + { \
  5426. + ( void ) xSemaphoreGive( ( xSemaphore ) ); \
  5427. + } \
  5428. + }
  5429. +#endif
  5430. +
  5431. +/**
  5432. + * semphr. h
  5433. + * @code{c}
  5434. + * SemaphoreHandle_t xSemaphoreCreateBinary( void );
  5435. + * @endcode
  5436. + *
  5437. + * Creates a new binary semaphore instance, and returns a handle by which the
  5438. + * new semaphore can be referenced.
  5439. + *
  5440. + * In many usage scenarios it is faster and more memory efficient to use a
  5441. + * direct to task notification in place of a binary semaphore!
  5442. + * https://www.FreeRTOS.org/RTOS-task-notifications.html
  5443. + *
  5444. + * Internally, within the FreeRTOS implementation, binary semaphores use a block
  5445. + * of memory, in which the semaphore structure is stored. If a binary semaphore
  5446. + * is created using xSemaphoreCreateBinary() then the required memory is
  5447. + * automatically dynamically allocated inside the xSemaphoreCreateBinary()
  5448. + * function. (see https://www.FreeRTOS.org/a00111.html). If a binary semaphore
  5449. + * is created using xSemaphoreCreateBinaryStatic() then the application writer
  5450. + * must provide the memory. xSemaphoreCreateBinaryStatic() therefore allows a
  5451. + * binary semaphore to be created without using any dynamic memory allocation.
  5452. + *
  5453. + * The old vSemaphoreCreateBinary() macro is now deprecated in favour of this
  5454. + * xSemaphoreCreateBinary() function. Note that binary semaphores created using
  5455. + * the vSemaphoreCreateBinary() macro are created in a state such that the
  5456. + * first call to 'take' the semaphore would pass, whereas binary semaphores
  5457. + * created using xSemaphoreCreateBinary() are created in a state such that the
  5458. + * the semaphore must first be 'given' before it can be 'taken'.
  5459. + *
  5460. + * This type of semaphore can be used for pure synchronisation between tasks or
  5461. + * between an interrupt and a task. The semaphore need not be given back once
  5462. + * obtained, so one task/interrupt can continuously 'give' the semaphore while
  5463. + * another continuously 'takes' the semaphore. For this reason this type of
  5464. + * semaphore does not use a priority inheritance mechanism. For an alternative
  5465. + * that does use priority inheritance see xSemaphoreCreateMutex().
  5466. + *
  5467. + * @return Handle to the created semaphore, or NULL if the memory required to
  5468. + * hold the semaphore's data structures could not be allocated.
  5469. + *
  5470. + * Example usage:
  5471. + * @code{c}
  5472. + * SemaphoreHandle_t xSemaphore = NULL;
  5473. + *
  5474. + * void vATask( void * pvParameters )
  5475. + * {
  5476. + * // Semaphore cannot be used before a call to xSemaphoreCreateBinary().
  5477. + * // This is a macro so pass the variable in directly.
  5478. + * xSemaphore = xSemaphoreCreateBinary();
  5479. + *
  5480. + * if( xSemaphore != NULL )
  5481. + * {
  5482. + * // The semaphore was created successfully.
  5483. + * // The semaphore can now be used.
  5484. + * }
  5485. + * }
  5486. + * @endcode
  5487. + * \defgroup xSemaphoreCreateBinary xSemaphoreCreateBinary
  5488. + * \ingroup Semaphores
  5489. + */
  5490. +#if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
  5491. + #define xSemaphoreCreateBinary() xQueueGenericCreate( ( UBaseType_t ) 1, semSEMAPHORE_QUEUE_ITEM_LENGTH, queueQUEUE_TYPE_BINARY_SEMAPHORE )
  5492. +#endif
  5493. +
  5494. +/**
  5495. + * semphr. h
  5496. + * @code{c}
  5497. + * SemaphoreHandle_t xSemaphoreCreateBinaryStatic( StaticSemaphore_t *pxSemaphoreBuffer );
  5498. + * @endcode
  5499. + *
  5500. + * Creates a new binary semaphore instance, and returns a handle by which the
  5501. + * new semaphore can be referenced.
  5502. + *
  5503. + * NOTE: In many usage scenarios it is faster and more memory efficient to use a
  5504. + * direct to task notification in place of a binary semaphore!
  5505. + * https://www.FreeRTOS.org/RTOS-task-notifications.html
  5506. + *
  5507. + * Internally, within the FreeRTOS implementation, binary semaphores use a block
  5508. + * of memory, in which the semaphore structure is stored. If a binary semaphore
  5509. + * is created using xSemaphoreCreateBinary() then the required memory is
  5510. + * automatically dynamically allocated inside the xSemaphoreCreateBinary()
  5511. + * function. (see https://www.FreeRTOS.org/a00111.html). If a binary semaphore
  5512. + * is created using xSemaphoreCreateBinaryStatic() then the application writer
  5513. + * must provide the memory. xSemaphoreCreateBinaryStatic() therefore allows a
  5514. + * binary semaphore to be created without using any dynamic memory allocation.
  5515. + *
  5516. + * This type of semaphore can be used for pure synchronisation between tasks or
  5517. + * between an interrupt and a task. The semaphore need not be given back once
  5518. + * obtained, so one task/interrupt can continuously 'give' the semaphore while
  5519. + * another continuously 'takes' the semaphore. For this reason this type of
  5520. + * semaphore does not use a priority inheritance mechanism. For an alternative
  5521. + * that does use priority inheritance see xSemaphoreCreateMutex().
  5522. + *
  5523. + * @param pxSemaphoreBuffer Must point to a variable of type StaticSemaphore_t,
  5524. + * which will then be used to hold the semaphore's data structure, removing the
  5525. + * need for the memory to be allocated dynamically.
  5526. + *
  5527. + * @return If the semaphore is created then a handle to the created semaphore is
  5528. + * returned. If pxSemaphoreBuffer is NULL then NULL is returned.
  5529. + *
  5530. + * Example usage:
  5531. + * @code{c}
  5532. + * SemaphoreHandle_t xSemaphore = NULL;
  5533. + * StaticSemaphore_t xSemaphoreBuffer;
  5534. + *
  5535. + * void vATask( void * pvParameters )
  5536. + * {
  5537. + * // Semaphore cannot be used before a call to xSemaphoreCreateBinary().
  5538. + * // The semaphore's data structures will be placed in the xSemaphoreBuffer
  5539. + * // variable, the address of which is passed into the function. The
  5540. + * // function's parameter is not NULL, so the function will not attempt any
  5541. + * // dynamic memory allocation, and therefore the function will not return
  5542. + * // return NULL.
  5543. + * xSemaphore = xSemaphoreCreateBinary( &xSemaphoreBuffer );
  5544. + *
  5545. + * // Rest of task code goes here.
  5546. + * }
  5547. + * @endcode
  5548. + * \defgroup xSemaphoreCreateBinaryStatic xSemaphoreCreateBinaryStatic
  5549. + * \ingroup Semaphores
  5550. + */
  5551. +#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
  5552. + #define xSemaphoreCreateBinaryStatic( pxStaticSemaphore ) xQueueGenericCreateStatic( ( UBaseType_t ) 1, semSEMAPHORE_QUEUE_ITEM_LENGTH, NULL, ( StaticQueue_t * ) pxStaticSemaphore, queueQUEUE_TYPE_BINARY_SEMAPHORE )
  5553. +#endif /* configSUPPORT_STATIC_ALLOCATION */
  5554. +
  5555. +/**
  5556. + * semphr. h
  5557. + * @code{c}
  5558. + * xSemaphoreTake(
  5559. + * SemaphoreHandle_t xSemaphore,
  5560. + * TickType_t xBlockTime
  5561. + * );
  5562. + * @endcode
  5563. + *
  5564. + * <i>Macro</i> to obtain a semaphore. The semaphore must have previously been
  5565. + * created with a call to xSemaphoreCreateBinary(), xSemaphoreCreateMutex() or
  5566. + * xSemaphoreCreateCounting().
  5567. + *
  5568. + * @param xSemaphore A handle to the semaphore being taken - obtained when
  5569. + * the semaphore was created.
  5570. + *
  5571. + * @param xBlockTime The time in ticks to wait for the semaphore to become
  5572. + * available. The macro portTICK_PERIOD_MS can be used to convert this to a
  5573. + * real time. A block time of zero can be used to poll the semaphore. A block
  5574. + * time of portMAX_DELAY can be used to block indefinitely (provided
  5575. + * INCLUDE_vTaskSuspend is set to 1 in FreeRTOSConfig.h).
  5576. + *
  5577. + * @return pdTRUE if the semaphore was obtained. pdFALSE
  5578. + * if xBlockTime expired without the semaphore becoming available.
  5579. + *
  5580. + * Example usage:
  5581. + * @code{c}
  5582. + * SemaphoreHandle_t xSemaphore = NULL;
  5583. + *
  5584. + * // A task that creates a semaphore.
  5585. + * void vATask( void * pvParameters )
  5586. + * {
  5587. + * // Create the semaphore to guard a shared resource.
  5588. + * xSemaphore = xSemaphoreCreateBinary();
  5589. + * }
  5590. + *
  5591. + * // A task that uses the semaphore.
  5592. + * void vAnotherTask( void * pvParameters )
  5593. + * {
  5594. + * // ... Do other things.
  5595. + *
  5596. + * if( xSemaphore != NULL )
  5597. + * {
  5598. + * // See if we can obtain the semaphore. If the semaphore is not available
  5599. + * // wait 10 ticks to see if it becomes free.
  5600. + * if( xSemaphoreTake( xSemaphore, ( TickType_t ) 10 ) == pdTRUE )
  5601. + * {
  5602. + * // We were able to obtain the semaphore and can now access the
  5603. + * // shared resource.
  5604. + *
  5605. + * // ...
  5606. + *
  5607. + * // We have finished accessing the shared resource. Release the
  5608. + * // semaphore.
  5609. + * xSemaphoreGive( xSemaphore );
  5610. + * }
  5611. + * else
  5612. + * {
  5613. + * // We could not obtain the semaphore and can therefore not access
  5614. + * // the shared resource safely.
  5615. + * }
  5616. + * }
  5617. + * }
  5618. + * @endcode
  5619. + * \defgroup xSemaphoreTake xSemaphoreTake
  5620. + * \ingroup Semaphores
  5621. + */
  5622. +#define xSemaphoreTake( xSemaphore, xBlockTime ) xQueueSemaphoreTake( ( xSemaphore ), ( xBlockTime ) )
  5623. +
  5624. +/**
  5625. + * semphr. h
  5626. + * @code{c}
  5627. + * xSemaphoreTakeRecursive(
  5628. + * SemaphoreHandle_t xMutex,
  5629. + * TickType_t xBlockTime
  5630. + * );
  5631. + * @endcode
  5632. + *
  5633. + * <i>Macro</i> to recursively obtain, or 'take', a mutex type semaphore.
  5634. + * The mutex must have previously been created using a call to
  5635. + * xSemaphoreCreateRecursiveMutex();
  5636. + *
  5637. + * configUSE_RECURSIVE_MUTEXES must be set to 1 in FreeRTOSConfig.h for this
  5638. + * macro to be available.
  5639. + *
  5640. + * This macro must not be used on mutexes created using xSemaphoreCreateMutex().
  5641. + *
  5642. + * A mutex used recursively can be 'taken' repeatedly by the owner. The mutex
  5643. + * doesn't become available again until the owner has called
  5644. + * xSemaphoreGiveRecursive() for each successful 'take' request. For example,
  5645. + * if a task successfully 'takes' the same mutex 5 times then the mutex will
  5646. + * not be available to any other task until it has also 'given' the mutex back
  5647. + * exactly five times.
  5648. + *
  5649. + * @param xMutex A handle to the mutex being obtained. This is the
  5650. + * handle returned by xSemaphoreCreateRecursiveMutex();
  5651. + *
  5652. + * @param xBlockTime The time in ticks to wait for the semaphore to become
  5653. + * available. The macro portTICK_PERIOD_MS can be used to convert this to a
  5654. + * real time. A block time of zero can be used to poll the semaphore. If
  5655. + * the task already owns the semaphore then xSemaphoreTakeRecursive() will
  5656. + * return immediately no matter what the value of xBlockTime.
  5657. + *
  5658. + * @return pdTRUE if the semaphore was obtained. pdFALSE if xBlockTime
  5659. + * expired without the semaphore becoming available.
  5660. + *
  5661. + * Example usage:
  5662. + * @code{c}
  5663. + * SemaphoreHandle_t xMutex = NULL;
  5664. + *
  5665. + * // A task that creates a mutex.
  5666. + * void vATask( void * pvParameters )
  5667. + * {
  5668. + * // Create the mutex to guard a shared resource.
  5669. + * xMutex = xSemaphoreCreateRecursiveMutex();
  5670. + * }
  5671. + *
  5672. + * // A task that uses the mutex.
  5673. + * void vAnotherTask( void * pvParameters )
  5674. + * {
  5675. + * // ... Do other things.
  5676. + *
  5677. + * if( xMutex != NULL )
  5678. + * {
  5679. + * // See if we can obtain the mutex. If the mutex is not available
  5680. + * // wait 10 ticks to see if it becomes free.
  5681. + * if( xSemaphoreTakeRecursive( xSemaphore, ( TickType_t ) 10 ) == pdTRUE )
  5682. + * {
  5683. + * // We were able to obtain the mutex and can now access the
  5684. + * // shared resource.
  5685. + *
  5686. + * // ...
  5687. + * // For some reason due to the nature of the code further calls to
  5688. + * // xSemaphoreTakeRecursive() are made on the same mutex. In real
  5689. + * // code these would not be just sequential calls as this would make
  5690. + * // no sense. Instead the calls are likely to be buried inside
  5691. + * // a more complex call structure.
  5692. + * xSemaphoreTakeRecursive( xMutex, ( TickType_t ) 10 );
  5693. + * xSemaphoreTakeRecursive( xMutex, ( TickType_t ) 10 );
  5694. + *
  5695. + * // The mutex has now been 'taken' three times, so will not be
  5696. + * // available to another task until it has also been given back
  5697. + * // three times. Again it is unlikely that real code would have
  5698. + * // these calls sequentially, but instead buried in a more complex
  5699. + * // call structure. This is just for illustrative purposes.
  5700. + * xSemaphoreGiveRecursive( xMutex );
  5701. + * xSemaphoreGiveRecursive( xMutex );
  5702. + * xSemaphoreGiveRecursive( xMutex );
  5703. + *
  5704. + * // Now the mutex can be taken by other tasks.
  5705. + * }
  5706. + * else
  5707. + * {
  5708. + * // We could not obtain the mutex and can therefore not access
  5709. + * // the shared resource safely.
  5710. + * }
  5711. + * }
  5712. + * }
  5713. + * @endcode
  5714. + * \defgroup xSemaphoreTakeRecursive xSemaphoreTakeRecursive
  5715. + * \ingroup Semaphores
  5716. + */
  5717. +#if ( configUSE_RECURSIVE_MUTEXES == 1 )
  5718. + #define xSemaphoreTakeRecursive( xMutex, xBlockTime ) xQueueTakeMutexRecursive( ( xMutex ), ( xBlockTime ) )
  5719. +#endif
  5720. +
  5721. +/**
  5722. + * semphr. h
  5723. + * @code{c}
  5724. + * xSemaphoreGive( SemaphoreHandle_t xSemaphore );
  5725. + * @endcode
  5726. + *
  5727. + * <i>Macro</i> to release a semaphore. The semaphore must have previously been
  5728. + * created with a call to xSemaphoreCreateBinary(), xSemaphoreCreateMutex() or
  5729. + * xSemaphoreCreateCounting(). and obtained using sSemaphoreTake().
  5730. + *
  5731. + * This macro must not be used from an ISR. See xSemaphoreGiveFromISR () for
  5732. + * an alternative which can be used from an ISR.
  5733. + *
  5734. + * This macro must also not be used on semaphores created using
  5735. + * xSemaphoreCreateRecursiveMutex().
  5736. + *
  5737. + * @param xSemaphore A handle to the semaphore being released. This is the
  5738. + * handle returned when the semaphore was created.
  5739. + *
  5740. + * @return pdTRUE if the semaphore was released. pdFALSE if an error occurred.
  5741. + * Semaphores are implemented using queues. An error can occur if there is
  5742. + * no space on the queue to post a message - indicating that the
  5743. + * semaphore was not first obtained correctly.
  5744. + *
  5745. + * Example usage:
  5746. + * @code{c}
  5747. + * SemaphoreHandle_t xSemaphore = NULL;
  5748. + *
  5749. + * void vATask( void * pvParameters )
  5750. + * {
  5751. + * // Create the semaphore to guard a shared resource.
  5752. + * xSemaphore = vSemaphoreCreateBinary();
  5753. + *
  5754. + * if( xSemaphore != NULL )
  5755. + * {
  5756. + * if( xSemaphoreGive( xSemaphore ) != pdTRUE )
  5757. + * {
  5758. + * // We would expect this call to fail because we cannot give
  5759. + * // a semaphore without first "taking" it!
  5760. + * }
  5761. + *
  5762. + * // Obtain the semaphore - don't block if the semaphore is not
  5763. + * // immediately available.
  5764. + * if( xSemaphoreTake( xSemaphore, ( TickType_t ) 0 ) )
  5765. + * {
  5766. + * // We now have the semaphore and can access the shared resource.
  5767. + *
  5768. + * // ...
  5769. + *
  5770. + * // We have finished accessing the shared resource so can free the
  5771. + * // semaphore.
  5772. + * if( xSemaphoreGive( xSemaphore ) != pdTRUE )
  5773. + * {
  5774. + * // We would not expect this call to fail because we must have
  5775. + * // obtained the semaphore to get here.
  5776. + * }
  5777. + * }
  5778. + * }
  5779. + * }
  5780. + * @endcode
  5781. + * \defgroup xSemaphoreGive xSemaphoreGive
  5782. + * \ingroup Semaphores
  5783. + */
  5784. +#define xSemaphoreGive( xSemaphore ) xQueueGenericSend( ( QueueHandle_t ) ( xSemaphore ), NULL, semGIVE_BLOCK_TIME, queueSEND_TO_BACK )
  5785. +
  5786. +/**
  5787. + * semphr. h
  5788. + * @code{c}
  5789. + * xSemaphoreGiveRecursive( SemaphoreHandle_t xMutex );
  5790. + * @endcode
  5791. + *
  5792. + * <i>Macro</i> to recursively release, or 'give', a mutex type semaphore.
  5793. + * The mutex must have previously been created using a call to
  5794. + * xSemaphoreCreateRecursiveMutex();
  5795. + *
  5796. + * configUSE_RECURSIVE_MUTEXES must be set to 1 in FreeRTOSConfig.h for this
  5797. + * macro to be available.
  5798. + *
  5799. + * This macro must not be used on mutexes created using xSemaphoreCreateMutex().
  5800. + *
  5801. + * A mutex used recursively can be 'taken' repeatedly by the owner. The mutex
  5802. + * doesn't become available again until the owner has called
  5803. + * xSemaphoreGiveRecursive() for each successful 'take' request. For example,
  5804. + * if a task successfully 'takes' the same mutex 5 times then the mutex will
  5805. + * not be available to any other task until it has also 'given' the mutex back
  5806. + * exactly five times.
  5807. + *
  5808. + * @param xMutex A handle to the mutex being released, or 'given'. This is the
  5809. + * handle returned by xSemaphoreCreateMutex();
  5810. + *
  5811. + * @return pdTRUE if the semaphore was given.
  5812. + *
  5813. + * Example usage:
  5814. + * @code{c}
  5815. + * SemaphoreHandle_t xMutex = NULL;
  5816. + *
  5817. + * // A task that creates a mutex.
  5818. + * void vATask( void * pvParameters )
  5819. + * {
  5820. + * // Create the mutex to guard a shared resource.
  5821. + * xMutex = xSemaphoreCreateRecursiveMutex();
  5822. + * }
  5823. + *
  5824. + * // A task that uses the mutex.
  5825. + * void vAnotherTask( void * pvParameters )
  5826. + * {
  5827. + * // ... Do other things.
  5828. + *
  5829. + * if( xMutex != NULL )
  5830. + * {
  5831. + * // See if we can obtain the mutex. If the mutex is not available
  5832. + * // wait 10 ticks to see if it becomes free.
  5833. + * if( xSemaphoreTakeRecursive( xMutex, ( TickType_t ) 10 ) == pdTRUE )
  5834. + * {
  5835. + * // We were able to obtain the mutex and can now access the
  5836. + * // shared resource.
  5837. + *
  5838. + * // ...
  5839. + * // For some reason due to the nature of the code further calls to
  5840. + * // xSemaphoreTakeRecursive() are made on the same mutex. In real
  5841. + * // code these would not be just sequential calls as this would make
  5842. + * // no sense. Instead the calls are likely to be buried inside
  5843. + * // a more complex call structure.
  5844. + * xSemaphoreTakeRecursive( xMutex, ( TickType_t ) 10 );
  5845. + * xSemaphoreTakeRecursive( xMutex, ( TickType_t ) 10 );
  5846. + *
  5847. + * // The mutex has now been 'taken' three times, so will not be
  5848. + * // available to another task until it has also been given back
  5849. + * // three times. Again it is unlikely that real code would have
  5850. + * // these calls sequentially, it would be more likely that the calls
  5851. + * // to xSemaphoreGiveRecursive() would be called as a call stack
  5852. + * // unwound. This is just for demonstrative purposes.
  5853. + * xSemaphoreGiveRecursive( xMutex );
  5854. + * xSemaphoreGiveRecursive( xMutex );
  5855. + * xSemaphoreGiveRecursive( xMutex );
  5856. + *
  5857. + * // Now the mutex can be taken by other tasks.
  5858. + * }
  5859. + * else
  5860. + * {
  5861. + * // We could not obtain the mutex and can therefore not access
  5862. + * // the shared resource safely.
  5863. + * }
  5864. + * }
  5865. + * }
  5866. + * @endcode
  5867. + * \defgroup xSemaphoreGiveRecursive xSemaphoreGiveRecursive
  5868. + * \ingroup Semaphores
  5869. + */
  5870. +#if ( configUSE_RECURSIVE_MUTEXES == 1 )
  5871. + #define xSemaphoreGiveRecursive( xMutex ) xQueueGiveMutexRecursive( ( xMutex ) )
  5872. +#endif
  5873. +
  5874. +/**
  5875. + * semphr. h
  5876. + * @code{c}
  5877. + * xSemaphoreGiveFromISR(
  5878. + * SemaphoreHandle_t xSemaphore,
  5879. + * BaseType_t *pxHigherPriorityTaskWoken
  5880. + * );
  5881. + * @endcode
  5882. + *
  5883. + * <i>Macro</i> to release a semaphore. The semaphore must have previously been
  5884. + * created with a call to xSemaphoreCreateBinary() or xSemaphoreCreateCounting().
  5885. + *
  5886. + * Mutex type semaphores (those created using a call to xSemaphoreCreateMutex())
  5887. + * must not be used with this macro.
  5888. + *
  5889. + * This macro can be used from an ISR.
  5890. + *
  5891. + * @param xSemaphore A handle to the semaphore being released. This is the
  5892. + * handle returned when the semaphore was created.
  5893. + *
  5894. + * @param pxHigherPriorityTaskWoken xSemaphoreGiveFromISR() will set
  5895. + * *pxHigherPriorityTaskWoken to pdTRUE if giving the semaphore caused a task
  5896. + * to unblock, and the unblocked task has a priority higher than the currently
  5897. + * running task. If xSemaphoreGiveFromISR() sets this value to pdTRUE then
  5898. + * a context switch should be requested before the interrupt is exited.
  5899. + *
  5900. + * @return pdTRUE if the semaphore was successfully given, otherwise errQUEUE_FULL.
  5901. + *
  5902. + * Example usage:
  5903. + * @code{c}
  5904. + \#define LONG_TIME 0xffff
  5905. + \#define TICKS_TO_WAIT 10
  5906. + * SemaphoreHandle_t xSemaphore = NULL;
  5907. + *
  5908. + * // Repetitive task.
  5909. + * void vATask( void * pvParameters )
  5910. + * {
  5911. + * for( ;; )
  5912. + * {
  5913. + * // We want this task to run every 10 ticks of a timer. The semaphore
  5914. + * // was created before this task was started.
  5915. + *
  5916. + * // Block waiting for the semaphore to become available.
  5917. + * if( xSemaphoreTake( xSemaphore, LONG_TIME ) == pdTRUE )
  5918. + * {
  5919. + * // It is time to execute.
  5920. + *
  5921. + * // ...
  5922. + *
  5923. + * // We have finished our task. Return to the top of the loop where
  5924. + * // we will block on the semaphore until it is time to execute
  5925. + * // again. Note when using the semaphore for synchronisation with an
  5926. + * // ISR in this manner there is no need to 'give' the semaphore back.
  5927. + * }
  5928. + * }
  5929. + * }
  5930. + *
  5931. + * // Timer ISR
  5932. + * void vTimerISR( void * pvParameters )
  5933. + * {
  5934. + * static uint8_t ucLocalTickCount = 0;
  5935. + * static BaseType_t xHigherPriorityTaskWoken;
  5936. + *
  5937. + * // A timer tick has occurred.
  5938. + *
  5939. + * // ... Do other time functions.
  5940. + *
  5941. + * // Is it time for vATask () to run?
  5942. + * xHigherPriorityTaskWoken = pdFALSE;
  5943. + * ucLocalTickCount++;
  5944. + * if( ucLocalTickCount >= TICKS_TO_WAIT )
  5945. + * {
  5946. + * // Unblock the task by releasing the semaphore.
  5947. + * xSemaphoreGiveFromISR( xSemaphore, &xHigherPriorityTaskWoken );
  5948. + *
  5949. + * // Reset the count so we release the semaphore again in 10 ticks time.
  5950. + * ucLocalTickCount = 0;
  5951. + * }
  5952. + *
  5953. + * if( xHigherPriorityTaskWoken != pdFALSE )
  5954. + * {
  5955. + * // We can force a context switch here. Context switching from an
  5956. + * // ISR uses port specific syntax. Check the demo task for your port
  5957. + * // to find the syntax required.
  5958. + * }
  5959. + * }
  5960. + * @endcode
  5961. + * \defgroup xSemaphoreGiveFromISR xSemaphoreGiveFromISR
  5962. + * \ingroup Semaphores
  5963. + */
  5964. +#define xSemaphoreGiveFromISR( xSemaphore, pxHigherPriorityTaskWoken ) xQueueGiveFromISR( ( QueueHandle_t ) ( xSemaphore ), ( pxHigherPriorityTaskWoken ) )
  5965. +
  5966. +/**
  5967. + * semphr. h
  5968. + * @code{c}
  5969. + * xSemaphoreTakeFromISR(
  5970. + * SemaphoreHandle_t xSemaphore,
  5971. + * BaseType_t *pxHigherPriorityTaskWoken
  5972. + * );
  5973. + * @endcode
  5974. + *
  5975. + * <i>Macro</i> to take a semaphore from an ISR. The semaphore must have
  5976. + * previously been created with a call to xSemaphoreCreateBinary() or
  5977. + * xSemaphoreCreateCounting().
  5978. + *
  5979. + * Mutex type semaphores (those created using a call to xSemaphoreCreateMutex())
  5980. + * must not be used with this macro.
  5981. + *
  5982. + * This macro can be used from an ISR, however taking a semaphore from an ISR
  5983. + * is not a common operation. It is likely to only be useful when taking a
  5984. + * counting semaphore when an interrupt is obtaining an object from a resource
  5985. + * pool (when the semaphore count indicates the number of resources available).
  5986. + *
  5987. + * @param xSemaphore A handle to the semaphore being taken. This is the
  5988. + * handle returned when the semaphore was created.
  5989. + *
  5990. + * @param pxHigherPriorityTaskWoken xSemaphoreTakeFromISR() will set
  5991. + * *pxHigherPriorityTaskWoken to pdTRUE if taking the semaphore caused a task
  5992. + * to unblock, and the unblocked task has a priority higher than the currently
  5993. + * running task. If xSemaphoreTakeFromISR() sets this value to pdTRUE then
  5994. + * a context switch should be requested before the interrupt is exited.
  5995. + *
  5996. + * @return pdTRUE if the semaphore was successfully taken, otherwise
  5997. + * pdFALSE
  5998. + */
  5999. +#define xSemaphoreTakeFromISR( xSemaphore, pxHigherPriorityTaskWoken ) xQueueReceiveFromISR( ( QueueHandle_t ) ( xSemaphore ), NULL, ( pxHigherPriorityTaskWoken ) )
  6000. +
  6001. +/**
  6002. + * semphr. h
  6003. + * @code{c}
  6004. + * SemaphoreHandle_t xSemaphoreCreateMutex( void );
  6005. + * @endcode
  6006. + *
  6007. + * Creates a new mutex type semaphore instance, and returns a handle by which
  6008. + * the new mutex can be referenced.
  6009. + *
  6010. + * Internally, within the FreeRTOS implementation, mutex semaphores use a block
  6011. + * of memory, in which the mutex structure is stored. If a mutex is created
  6012. + * using xSemaphoreCreateMutex() then the required memory is automatically
  6013. + * dynamically allocated inside the xSemaphoreCreateMutex() function. (see
  6014. + * https://www.FreeRTOS.org/a00111.html). If a mutex is created using
  6015. + * xSemaphoreCreateMutexStatic() then the application writer must provided the
  6016. + * memory. xSemaphoreCreateMutexStatic() therefore allows a mutex to be created
  6017. + * without using any dynamic memory allocation.
  6018. + *
  6019. + * Mutexes created using this function can be accessed using the xSemaphoreTake()
  6020. + * and xSemaphoreGive() macros. The xSemaphoreTakeRecursive() and
  6021. + * xSemaphoreGiveRecursive() macros must not be used.
  6022. + *
  6023. + * This type of semaphore uses a priority inheritance mechanism so a task
  6024. + * 'taking' a semaphore MUST ALWAYS 'give' the semaphore back once the
  6025. + * semaphore it is no longer required.
  6026. + *
  6027. + * Mutex type semaphores cannot be used from within interrupt service routines.
  6028. + *
  6029. + * See xSemaphoreCreateBinary() for an alternative implementation that can be
  6030. + * used for pure synchronisation (where one task or interrupt always 'gives' the
  6031. + * semaphore and another always 'takes' the semaphore) and from within interrupt
  6032. + * service routines.
  6033. + *
  6034. + * @return If the mutex was successfully created then a handle to the created
  6035. + * semaphore is returned. If there was not enough heap to allocate the mutex
  6036. + * data structures then NULL is returned.
  6037. + *
  6038. + * Example usage:
  6039. + * @code{c}
  6040. + * SemaphoreHandle_t xSemaphore;
  6041. + *
  6042. + * void vATask( void * pvParameters )
  6043. + * {
  6044. + * // Semaphore cannot be used before a call to xSemaphoreCreateMutex().
  6045. + * // This is a macro so pass the variable in directly.
  6046. + * xSemaphore = xSemaphoreCreateMutex();
  6047. + *
  6048. + * if( xSemaphore != NULL )
  6049. + * {
  6050. + * // The semaphore was created successfully.
  6051. + * // The semaphore can now be used.
  6052. + * }
  6053. + * }
  6054. + * @endcode
  6055. + * \defgroup xSemaphoreCreateMutex xSemaphoreCreateMutex
  6056. + * \ingroup Semaphores
  6057. + */
  6058. +#if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
  6059. + #define xSemaphoreCreateMutex() xQueueCreateMutex( queueQUEUE_TYPE_MUTEX )
  6060. +#endif
  6061. +
  6062. +/**
  6063. + * semphr. h
  6064. + * @code{c}
  6065. + * SemaphoreHandle_t xSemaphoreCreateMutexStatic( StaticSemaphore_t *pxMutexBuffer );
  6066. + * @endcode
  6067. + *
  6068. + * Creates a new mutex type semaphore instance, and returns a handle by which
  6069. + * the new mutex can be referenced.
  6070. + *
  6071. + * Internally, within the FreeRTOS implementation, mutex semaphores use a block
  6072. + * of memory, in which the mutex structure is stored. If a mutex is created
  6073. + * using xSemaphoreCreateMutex() then the required memory is automatically
  6074. + * dynamically allocated inside the xSemaphoreCreateMutex() function. (see
  6075. + * https://www.FreeRTOS.org/a00111.html). If a mutex is created using
  6076. + * xSemaphoreCreateMutexStatic() then the application writer must provided the
  6077. + * memory. xSemaphoreCreateMutexStatic() therefore allows a mutex to be created
  6078. + * without using any dynamic memory allocation.
  6079. + *
  6080. + * Mutexes created using this function can be accessed using the xSemaphoreTake()
  6081. + * and xSemaphoreGive() macros. The xSemaphoreTakeRecursive() and
  6082. + * xSemaphoreGiveRecursive() macros must not be used.
  6083. + *
  6084. + * This type of semaphore uses a priority inheritance mechanism so a task
  6085. + * 'taking' a semaphore MUST ALWAYS 'give' the semaphore back once the
  6086. + * semaphore it is no longer required.
  6087. + *
  6088. + * Mutex type semaphores cannot be used from within interrupt service routines.
  6089. + *
  6090. + * See xSemaphoreCreateBinary() for an alternative implementation that can be
  6091. + * used for pure synchronisation (where one task or interrupt always 'gives' the
  6092. + * semaphore and another always 'takes' the semaphore) and from within interrupt
  6093. + * service routines.
  6094. + *
  6095. + * @param pxMutexBuffer Must point to a variable of type StaticSemaphore_t,
  6096. + * which will be used to hold the mutex's data structure, removing the need for
  6097. + * the memory to be allocated dynamically.
  6098. + *
  6099. + * @return If the mutex was successfully created then a handle to the created
  6100. + * mutex is returned. If pxMutexBuffer was NULL then NULL is returned.
  6101. + *
  6102. + * Example usage:
  6103. + * @code{c}
  6104. + * SemaphoreHandle_t xSemaphore;
  6105. + * StaticSemaphore_t xMutexBuffer;
  6106. + *
  6107. + * void vATask( void * pvParameters )
  6108. + * {
  6109. + * // A mutex cannot be used before it has been created. xMutexBuffer is
  6110. + * // into xSemaphoreCreateMutexStatic() so no dynamic memory allocation is
  6111. + * // attempted.
  6112. + * xSemaphore = xSemaphoreCreateMutexStatic( &xMutexBuffer );
  6113. + *
  6114. + * // As no dynamic memory allocation was performed, xSemaphore cannot be NULL,
  6115. + * // so there is no need to check it.
  6116. + * }
  6117. + * @endcode
  6118. + * \defgroup xSemaphoreCreateMutexStatic xSemaphoreCreateMutexStatic
  6119. + * \ingroup Semaphores
  6120. + */
  6121. +#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
  6122. + #define xSemaphoreCreateMutexStatic( pxMutexBuffer ) xQueueCreateMutexStatic( queueQUEUE_TYPE_MUTEX, ( StaticQueue_t * ) ( pxMutexBuffer ) )
  6123. +#endif /* configSUPPORT_STATIC_ALLOCATION */
  6124. +
  6125. +/**
  6126. + * semphr. h
  6127. + * @code{c}
  6128. + * SemaphoreHandle_t xSemaphoreCreateRecursiveMutex( void );
  6129. + * @endcode
  6130. + *
  6131. + * Creates a new recursive mutex type semaphore instance, and returns a handle
  6132. + * by which the new recursive mutex can be referenced.
  6133. + *
  6134. + * Internally, within the FreeRTOS implementation, recursive mutexs use a block
  6135. + * of memory, in which the mutex structure is stored. If a recursive mutex is
  6136. + * created using xSemaphoreCreateRecursiveMutex() then the required memory is
  6137. + * automatically dynamically allocated inside the
  6138. + * xSemaphoreCreateRecursiveMutex() function. (see
  6139. + * https://www.FreeRTOS.org/a00111.html). If a recursive mutex is created using
  6140. + * xSemaphoreCreateRecursiveMutexStatic() then the application writer must
  6141. + * provide the memory that will get used by the mutex.
  6142. + * xSemaphoreCreateRecursiveMutexStatic() therefore allows a recursive mutex to
  6143. + * be created without using any dynamic memory allocation.
  6144. + *
  6145. + * Mutexes created using this macro can be accessed using the
  6146. + * xSemaphoreTakeRecursive() and xSemaphoreGiveRecursive() macros. The
  6147. + * xSemaphoreTake() and xSemaphoreGive() macros must not be used.
  6148. + *
  6149. + * A mutex used recursively can be 'taken' repeatedly by the owner. The mutex
  6150. + * doesn't become available again until the owner has called
  6151. + * xSemaphoreGiveRecursive() for each successful 'take' request. For example,
  6152. + * if a task successfully 'takes' the same mutex 5 times then the mutex will
  6153. + * not be available to any other task until it has also 'given' the mutex back
  6154. + * exactly five times.
  6155. + *
  6156. + * This type of semaphore uses a priority inheritance mechanism so a task
  6157. + * 'taking' a semaphore MUST ALWAYS 'give' the semaphore back once the
  6158. + * semaphore it is no longer required.
  6159. + *
  6160. + * Mutex type semaphores cannot be used from within interrupt service routines.
  6161. + *
  6162. + * See xSemaphoreCreateBinary() for an alternative implementation that can be
  6163. + * used for pure synchronisation (where one task or interrupt always 'gives' the
  6164. + * semaphore and another always 'takes' the semaphore) and from within interrupt
  6165. + * service routines.
  6166. + *
  6167. + * @return xSemaphore Handle to the created mutex semaphore. Should be of type
  6168. + * SemaphoreHandle_t.
  6169. + *
  6170. + * Example usage:
  6171. + * @code{c}
  6172. + * SemaphoreHandle_t xSemaphore;
  6173. + *
  6174. + * void vATask( void * pvParameters )
  6175. + * {
  6176. + * // Semaphore cannot be used before a call to xSemaphoreCreateMutex().
  6177. + * // This is a macro so pass the variable in directly.
  6178. + * xSemaphore = xSemaphoreCreateRecursiveMutex();
  6179. + *
  6180. + * if( xSemaphore != NULL )
  6181. + * {
  6182. + * // The semaphore was created successfully.
  6183. + * // The semaphore can now be used.
  6184. + * }
  6185. + * }
  6186. + * @endcode
  6187. + * \defgroup xSemaphoreCreateRecursiveMutex xSemaphoreCreateRecursiveMutex
  6188. + * \ingroup Semaphores
  6189. + */
  6190. +#if ( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configUSE_RECURSIVE_MUTEXES == 1 ) )
  6191. + #define xSemaphoreCreateRecursiveMutex() xQueueCreateMutex( queueQUEUE_TYPE_RECURSIVE_MUTEX )
  6192. +#endif
  6193. +
  6194. +/**
  6195. + * semphr. h
  6196. + * @code{c}
  6197. + * SemaphoreHandle_t xSemaphoreCreateRecursiveMutexStatic( StaticSemaphore_t *pxMutexBuffer );
  6198. + * @endcode
  6199. + *
  6200. + * Creates a new recursive mutex type semaphore instance, and returns a handle
  6201. + * by which the new recursive mutex can be referenced.
  6202. + *
  6203. + * Internally, within the FreeRTOS implementation, recursive mutexs use a block
  6204. + * of memory, in which the mutex structure is stored. If a recursive mutex is
  6205. + * created using xSemaphoreCreateRecursiveMutex() then the required memory is
  6206. + * automatically dynamically allocated inside the
  6207. + * xSemaphoreCreateRecursiveMutex() function. (see
  6208. + * https://www.FreeRTOS.org/a00111.html). If a recursive mutex is created using
  6209. + * xSemaphoreCreateRecursiveMutexStatic() then the application writer must
  6210. + * provide the memory that will get used by the mutex.
  6211. + * xSemaphoreCreateRecursiveMutexStatic() therefore allows a recursive mutex to
  6212. + * be created without using any dynamic memory allocation.
  6213. + *
  6214. + * Mutexes created using this macro can be accessed using the
  6215. + * xSemaphoreTakeRecursive() and xSemaphoreGiveRecursive() macros. The
  6216. + * xSemaphoreTake() and xSemaphoreGive() macros must not be used.
  6217. + *
  6218. + * A mutex used recursively can be 'taken' repeatedly by the owner. The mutex
  6219. + * doesn't become available again until the owner has called
  6220. + * xSemaphoreGiveRecursive() for each successful 'take' request. For example,
  6221. + * if a task successfully 'takes' the same mutex 5 times then the mutex will
  6222. + * not be available to any other task until it has also 'given' the mutex back
  6223. + * exactly five times.
  6224. + *
  6225. + * This type of semaphore uses a priority inheritance mechanism so a task
  6226. + * 'taking' a semaphore MUST ALWAYS 'give' the semaphore back once the
  6227. + * semaphore it is no longer required.
  6228. + *
  6229. + * Mutex type semaphores cannot be used from within interrupt service routines.
  6230. + *
  6231. + * See xSemaphoreCreateBinary() for an alternative implementation that can be
  6232. + * used for pure synchronisation (where one task or interrupt always 'gives' the
  6233. + * semaphore and another always 'takes' the semaphore) and from within interrupt
  6234. + * service routines.
  6235. + *
  6236. + * @param pxMutexBuffer Must point to a variable of type StaticSemaphore_t,
  6237. + * which will then be used to hold the recursive mutex's data structure,
  6238. + * removing the need for the memory to be allocated dynamically.
  6239. + *
  6240. + * @return If the recursive mutex was successfully created then a handle to the
  6241. + * created recursive mutex is returned. If pxMutexBuffer was NULL then NULL is
  6242. + * returned.
  6243. + *
  6244. + * Example usage:
  6245. + * @code{c}
  6246. + * SemaphoreHandle_t xSemaphore;
  6247. + * StaticSemaphore_t xMutexBuffer;
  6248. + *
  6249. + * void vATask( void * pvParameters )
  6250. + * {
  6251. + * // A recursive semaphore cannot be used before it is created. Here a
  6252. + * // recursive mutex is created using xSemaphoreCreateRecursiveMutexStatic().
  6253. + * // The address of xMutexBuffer is passed into the function, and will hold
  6254. + * // the mutexes data structures - so no dynamic memory allocation will be
  6255. + * // attempted.
  6256. + * xSemaphore = xSemaphoreCreateRecursiveMutexStatic( &xMutexBuffer );
  6257. + *
  6258. + * // As no dynamic memory allocation was performed, xSemaphore cannot be NULL,
  6259. + * // so there is no need to check it.
  6260. + * }
  6261. + * @endcode
  6262. + * \defgroup xSemaphoreCreateRecursiveMutexStatic xSemaphoreCreateRecursiveMutexStatic
  6263. + * \ingroup Semaphores
  6264. + */
  6265. +#if ( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configUSE_RECURSIVE_MUTEXES == 1 ) )
  6266. + #define xSemaphoreCreateRecursiveMutexStatic( pxStaticSemaphore ) xQueueCreateMutexStatic( queueQUEUE_TYPE_RECURSIVE_MUTEX, ( StaticQueue_t * ) pxStaticSemaphore )
  6267. +#endif /* configSUPPORT_STATIC_ALLOCATION */
  6268. +
  6269. +/**
  6270. + * semphr. h
  6271. + * @code{c}
  6272. + * SemaphoreHandle_t xSemaphoreCreateCounting( UBaseType_t uxMaxCount, UBaseType_t uxInitialCount );
  6273. + * @endcode
  6274. + *
  6275. + * Creates a new counting semaphore instance, and returns a handle by which the
  6276. + * new counting semaphore can be referenced.
  6277. + *
  6278. + * In many usage scenarios it is faster and more memory efficient to use a
  6279. + * direct to task notification in place of a counting semaphore!
  6280. + * https://www.FreeRTOS.org/RTOS-task-notifications.html
  6281. + *
  6282. + * Internally, within the FreeRTOS implementation, counting semaphores use a
  6283. + * block of memory, in which the counting semaphore structure is stored. If a
  6284. + * counting semaphore is created using xSemaphoreCreateCounting() then the
  6285. + * required memory is automatically dynamically allocated inside the
  6286. + * xSemaphoreCreateCounting() function. (see
  6287. + * https://www.FreeRTOS.org/a00111.html). If a counting semaphore is created
  6288. + * using xSemaphoreCreateCountingStatic() then the application writer can
  6289. + * instead optionally provide the memory that will get used by the counting
  6290. + * semaphore. xSemaphoreCreateCountingStatic() therefore allows a counting
  6291. + * semaphore to be created without using any dynamic memory allocation.
  6292. + *
  6293. + * Counting semaphores are typically used for two things:
  6294. + *
  6295. + * 1) Counting events.
  6296. + *
  6297. + * In this usage scenario an event handler will 'give' a semaphore each time
  6298. + * an event occurs (incrementing the semaphore count value), and a handler
  6299. + * task will 'take' a semaphore each time it processes an event
  6300. + * (decrementing the semaphore count value). The count value is therefore
  6301. + * the difference between the number of events that have occurred and the
  6302. + * number that have been processed. In this case it is desirable for the
  6303. + * initial count value to be zero.
  6304. + *
  6305. + * 2) Resource management.
  6306. + *
  6307. + * In this usage scenario the count value indicates the number of resources
  6308. + * available. To obtain control of a resource a task must first obtain a
  6309. + * semaphore - decrementing the semaphore count value. When the count value
  6310. + * reaches zero there are no free resources. When a task finishes with the
  6311. + * resource it 'gives' the semaphore back - incrementing the semaphore count
  6312. + * value. In this case it is desirable for the initial count value to be
  6313. + * equal to the maximum count value, indicating that all resources are free.
  6314. + *
  6315. + * @param uxMaxCount The maximum count value that can be reached. When the
  6316. + * semaphore reaches this value it can no longer be 'given'.
  6317. + *
  6318. + * @param uxInitialCount The count value assigned to the semaphore when it is
  6319. + * created.
  6320. + *
  6321. + * @return Handle to the created semaphore. Null if the semaphore could not be
  6322. + * created.
  6323. + *
  6324. + * Example usage:
  6325. + * @code{c}
  6326. + * SemaphoreHandle_t xSemaphore;
  6327. + *
  6328. + * void vATask( void * pvParameters )
  6329. + * {
  6330. + * SemaphoreHandle_t xSemaphore = NULL;
  6331. + *
  6332. + * // Semaphore cannot be used before a call to xSemaphoreCreateCounting().
  6333. + * // The max value to which the semaphore can count should be 10, and the
  6334. + * // initial value assigned to the count should be 0.
  6335. + * xSemaphore = xSemaphoreCreateCounting( 10, 0 );
  6336. + *
  6337. + * if( xSemaphore != NULL )
  6338. + * {
  6339. + * // The semaphore was created successfully.
  6340. + * // The semaphore can now be used.
  6341. + * }
  6342. + * }
  6343. + * @endcode
  6344. + * \defgroup xSemaphoreCreateCounting xSemaphoreCreateCounting
  6345. + * \ingroup Semaphores
  6346. + */
  6347. +#if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
  6348. + #define xSemaphoreCreateCounting( uxMaxCount, uxInitialCount ) xQueueCreateCountingSemaphore( ( uxMaxCount ), ( uxInitialCount ) )
  6349. +#endif
  6350. +
  6351. +/**
  6352. + * semphr. h
  6353. + * @code{c}
  6354. + * SemaphoreHandle_t xSemaphoreCreateCountingStatic( UBaseType_t uxMaxCount, UBaseType_t uxInitialCount, StaticSemaphore_t *pxSemaphoreBuffer );
  6355. + * @endcode
  6356. + *
  6357. + * Creates a new counting semaphore instance, and returns a handle by which the
  6358. + * new counting semaphore can be referenced.
  6359. + *
  6360. + * In many usage scenarios it is faster and more memory efficient to use a
  6361. + * direct to task notification in place of a counting semaphore!
  6362. + * https://www.FreeRTOS.org/RTOS-task-notifications.html
  6363. + *
  6364. + * Internally, within the FreeRTOS implementation, counting semaphores use a
  6365. + * block of memory, in which the counting semaphore structure is stored. If a
  6366. + * counting semaphore is created using xSemaphoreCreateCounting() then the
  6367. + * required memory is automatically dynamically allocated inside the
  6368. + * xSemaphoreCreateCounting() function. (see
  6369. + * https://www.FreeRTOS.org/a00111.html). If a counting semaphore is created
  6370. + * using xSemaphoreCreateCountingStatic() then the application writer must
  6371. + * provide the memory. xSemaphoreCreateCountingStatic() therefore allows a
  6372. + * counting semaphore to be created without using any dynamic memory allocation.
  6373. + *
  6374. + * Counting semaphores are typically used for two things:
  6375. + *
  6376. + * 1) Counting events.
  6377. + *
  6378. + * In this usage scenario an event handler will 'give' a semaphore each time
  6379. + * an event occurs (incrementing the semaphore count value), and a handler
  6380. + * task will 'take' a semaphore each time it processes an event
  6381. + * (decrementing the semaphore count value). The count value is therefore
  6382. + * the difference between the number of events that have occurred and the
  6383. + * number that have been processed. In this case it is desirable for the
  6384. + * initial count value to be zero.
  6385. + *
  6386. + * 2) Resource management.
  6387. + *
  6388. + * In this usage scenario the count value indicates the number of resources
  6389. + * available. To obtain control of a resource a task must first obtain a
  6390. + * semaphore - decrementing the semaphore count value. When the count value
  6391. + * reaches zero there are no free resources. When a task finishes with the
  6392. + * resource it 'gives' the semaphore back - incrementing the semaphore count
  6393. + * value. In this case it is desirable for the initial count value to be
  6394. + * equal to the maximum count value, indicating that all resources are free.
  6395. + *
  6396. + * @param uxMaxCount The maximum count value that can be reached. When the
  6397. + * semaphore reaches this value it can no longer be 'given'.
  6398. + *
  6399. + * @param uxInitialCount The count value assigned to the semaphore when it is
  6400. + * created.
  6401. + *
  6402. + * @param pxSemaphoreBuffer Must point to a variable of type StaticSemaphore_t,
  6403. + * which will then be used to hold the semaphore's data structure, removing the
  6404. + * need for the memory to be allocated dynamically.
  6405. + *
  6406. + * @return If the counting semaphore was successfully created then a handle to
  6407. + * the created counting semaphore is returned. If pxSemaphoreBuffer was NULL
  6408. + * then NULL is returned.
  6409. + *
  6410. + * Example usage:
  6411. + * @code{c}
  6412. + * SemaphoreHandle_t xSemaphore;
  6413. + * StaticSemaphore_t xSemaphoreBuffer;
  6414. + *
  6415. + * void vATask( void * pvParameters )
  6416. + * {
  6417. + * SemaphoreHandle_t xSemaphore = NULL;
  6418. + *
  6419. + * // Counting semaphore cannot be used before they have been created. Create
  6420. + * // a counting semaphore using xSemaphoreCreateCountingStatic(). The max
  6421. + * // value to which the semaphore can count is 10, and the initial value
  6422. + * // assigned to the count will be 0. The address of xSemaphoreBuffer is
  6423. + * // passed in and will be used to hold the semaphore structure, so no dynamic
  6424. + * // memory allocation will be used.
  6425. + * xSemaphore = xSemaphoreCreateCounting( 10, 0, &xSemaphoreBuffer );
  6426. + *
  6427. + * // No memory allocation was attempted so xSemaphore cannot be NULL, so there
  6428. + * // is no need to check its value.
  6429. + * }
  6430. + * @endcode
  6431. + * \defgroup xSemaphoreCreateCountingStatic xSemaphoreCreateCountingStatic
  6432. + * \ingroup Semaphores
  6433. + */
  6434. +#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
  6435. + #define xSemaphoreCreateCountingStatic( uxMaxCount, uxInitialCount, pxSemaphoreBuffer ) xQueueCreateCountingSemaphoreStatic( ( uxMaxCount ), ( uxInitialCount ), ( StaticQueue_t * ) ( pxSemaphoreBuffer ) )
  6436. +#endif /* configSUPPORT_STATIC_ALLOCATION */
  6437. +
  6438. +/**
  6439. + * semphr. h
  6440. + * @code{c}
  6441. + * void vSemaphoreDelete( SemaphoreHandle_t xSemaphore );
  6442. + * @endcode
  6443. + *
  6444. + * Delete a semaphore. This function must be used with care. For example,
  6445. + * do not delete a mutex type semaphore if the mutex is held by a task.
  6446. + *
  6447. + * @param xSemaphore A handle to the semaphore to be deleted.
  6448. + *
  6449. + * \defgroup vSemaphoreDelete vSemaphoreDelete
  6450. + * \ingroup Semaphores
  6451. + */
  6452. +#define vSemaphoreDelete( xSemaphore ) vQueueDelete( ( QueueHandle_t ) ( xSemaphore ) )
  6453. +
  6454. +/**
  6455. + * semphr.h
  6456. + * @code{c}
  6457. + * TaskHandle_t xSemaphoreGetMutexHolder( SemaphoreHandle_t xMutex );
  6458. + * @endcode
  6459. + *
  6460. + * If xMutex is indeed a mutex type semaphore, return the current mutex holder.
  6461. + * If xMutex is not a mutex type semaphore, or the mutex is available (not held
  6462. + * by a task), return NULL.
  6463. + *
  6464. + * Note: This is a good way of determining if the calling task is the mutex
  6465. + * holder, but not a good way of determining the identity of the mutex holder as
  6466. + * the holder may change between the function exiting and the returned value
  6467. + * being tested.
  6468. + */
  6469. +#define xSemaphoreGetMutexHolder( xSemaphore ) xQueueGetMutexHolder( ( xSemaphore ) )
  6470. +
  6471. +/**
  6472. + * semphr.h
  6473. + * @code{c}
  6474. + * TaskHandle_t xSemaphoreGetMutexHolderFromISR( SemaphoreHandle_t xMutex );
  6475. + * @endcode
  6476. + *
  6477. + * If xMutex is indeed a mutex type semaphore, return the current mutex holder.
  6478. + * If xMutex is not a mutex type semaphore, or the mutex is available (not held
  6479. + * by a task), return NULL.
  6480. + *
  6481. + */
  6482. +#define xSemaphoreGetMutexHolderFromISR( xSemaphore ) xQueueGetMutexHolderFromISR( ( xSemaphore ) )
  6483. +
  6484. +/**
  6485. + * semphr.h
  6486. + * @code{c}
  6487. + * UBaseType_t uxSemaphoreGetCount( SemaphoreHandle_t xSemaphore );
  6488. + * @endcode
  6489. + *
  6490. + * If the semaphore is a counting semaphore then uxSemaphoreGetCount() returns
  6491. + * its current count value. If the semaphore is a binary semaphore then
  6492. + * uxSemaphoreGetCount() returns 1 if the semaphore is available, and 0 if the
  6493. + * semaphore is not available.
  6494. + *
  6495. + */
  6496. +#define uxSemaphoreGetCount( xSemaphore ) uxQueueMessagesWaiting( ( QueueHandle_t ) ( xSemaphore ) )
  6497. +
  6498. +/**
  6499. + * semphr.h
  6500. + * @code{c}
  6501. + * UBaseType_t uxSemaphoreGetCountFromISR( SemaphoreHandle_t xSemaphore );
  6502. + * @endcode
  6503. + *
  6504. + * If the semaphore is a counting semaphore then uxSemaphoreGetCountFromISR() returns
  6505. + * its current count value. If the semaphore is a binary semaphore then
  6506. + * uxSemaphoreGetCountFromISR() returns 1 if the semaphore is available, and 0 if the
  6507. + * semaphore is not available.
  6508. + *
  6509. + */
  6510. +#define uxSemaphoreGetCountFromISR( xSemaphore ) uxQueueMessagesWaitingFromISR( ( QueueHandle_t ) ( xSemaphore ) )
  6511. +
  6512. +#endif /* SEMAPHORE_H */
  6513. diff --git a/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/include/freertos/task.h b/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/include/freertos/task.h
  6514. new file mode 100644
  6515. index 0000000000..20f6a52104
  6516. --- /dev/null
  6517. +++ b/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/include/freertos/task.h
  6518. @@ -0,0 +1,2265 @@
  6519. +/*
  6520. + * FreeRTOS Kernel V10.4.6
  6521. + * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  6522. + *
  6523. + * SPDX-License-Identifier: MIT
  6524. + *
  6525. + * Permission is hereby granted, free of charge, to any person obtaining a copy of
  6526. + * this software and associated documentation files (the "Software"), to deal in
  6527. + * the Software without restriction, including without limitation the rights to
  6528. + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  6529. + * the Software, and to permit persons to whom the Software is furnished to do so,
  6530. + * subject to the following conditions:
  6531. + *
  6532. + * The above copyright notice and this permission notice shall be included in all
  6533. + * copies or substantial portions of the Software.
  6534. + *
  6535. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  6536. + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  6537. + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  6538. + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  6539. + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  6540. + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  6541. + *
  6542. + * https://www.FreeRTOS.org
  6543. + * https://github.com/FreeRTOS
  6544. + *
  6545. + */
  6546. +
  6547. +
  6548. +#ifndef INC_TASK_H
  6549. +#define INC_TASK_H
  6550. +
  6551. +#ifndef INC_FREERTOS_H
  6552. + #error "include FreeRTOS.h must appear in source files before include task.h"
  6553. +#endif
  6554. +
  6555. +/* *INDENT-OFF* */
  6556. +#ifdef __cplusplus
  6557. + extern "C" {
  6558. +#endif
  6559. +/* *INDENT-ON* */
  6560. +
  6561. +/*-----------------------------------------------------------
  6562. +* MACROS AND DEFINITIONS
  6563. +*----------------------------------------------------------*/
  6564. +
  6565. +/*
  6566. + * If tskKERNEL_VERSION_NUMBER ends with + it represents the version in development
  6567. + * after the numbered release.
  6568. + *
  6569. + * The tskKERNEL_VERSION_MAJOR, tskKERNEL_VERSION_MINOR, tskKERNEL_VERSION_BUILD
  6570. + * values will reflect the last released version number.
  6571. + */
  6572. +#define tskKERNEL_VERSION_NUMBER "V10.4.6"
  6573. +#define tskKERNEL_VERSION_MAJOR 10
  6574. +#define tskKERNEL_VERSION_MINOR 4
  6575. +#define tskKERNEL_VERSION_BUILD 6
  6576. +
  6577. +/* The direct to task notification feature used to have only a single notification
  6578. + * per task. Now there is an array of notifications per task that is dimensioned by
  6579. + * configTASK_NOTIFICATION_ARRAY_ENTRIES. For backward compatibility, any use of the
  6580. + * original direct to task notification defaults to using the first index in the
  6581. + * array. */
  6582. +#define tskDEFAULT_INDEX_TO_NOTIFY ( 0 )
  6583. +
  6584. +/* ESP32 */
  6585. +#define tskNO_AFFINITY ( 0x7FFFFFFF )
  6586. +
  6587. +/**
  6588. + * task. h
  6589. + *
  6590. + * Type by which tasks are referenced. For example, a call to xTaskCreate
  6591. + * returns (via a pointer parameter) an TaskHandle_t variable that can then
  6592. + * be used as a parameter to vTaskDelete to delete the task.
  6593. + *
  6594. + * \defgroup TaskHandle_t TaskHandle_t
  6595. + * \ingroup Tasks
  6596. + */
  6597. +struct tskTaskControlBlock; /* The old naming convention is used to prevent breaking kernel aware debuggers. */
  6598. +typedef struct tskTaskControlBlock * TaskHandle_t;
  6599. +
  6600. +/*
  6601. + * Defines the prototype to which the application task hook function must
  6602. + * conform.
  6603. + */
  6604. +typedef BaseType_t (* TaskHookFunction_t)( void * );
  6605. +
  6606. +/* Task states returned by eTaskGetState. */
  6607. +typedef enum
  6608. +{
  6609. + eRunning = 0, /* A task is querying the state of itself, so must be running. */
  6610. + eReady, /* The task being queried is in a ready or pending ready list. */
  6611. + eBlocked, /* The task being queried is in the Blocked state. */
  6612. + eSuspended, /* The task being queried is in the Suspended state, or is in the Blocked state with an infinite time out. */
  6613. + eDeleted, /* The task being queried has been deleted, but its TCB has not yet been freed. */
  6614. + eInvalid /* Used as an 'invalid state' value. */
  6615. +} eTaskState;
  6616. +
  6617. +/* Actions that can be performed when vTaskNotify() is called. */
  6618. +typedef enum
  6619. +{
  6620. + eNoAction = 0, /* Notify the task without updating its notify value. */
  6621. + eSetBits, /* Set bits in the task's notification value. */
  6622. + eIncrement, /* Increment the task's notification value. */
  6623. + eSetValueWithOverwrite, /* Set the task's notification value to a specific value even if the previous value has not yet been read by the task. */
  6624. + eSetValueWithoutOverwrite /* Set the task's notification value if the previous value has been read by the task. */
  6625. +} eNotifyAction;
  6626. +
  6627. +/*
  6628. + * Used internally only.
  6629. + */
  6630. +typedef struct xTIME_OUT
  6631. +{
  6632. + BaseType_t xOverflowCount;
  6633. + TickType_t xTimeOnEntering;
  6634. +} TimeOut_t;
  6635. +
  6636. +/**
  6637. + * Defines the priority used by the idle task. This must not be modified.
  6638. + *
  6639. + * \ingroup TaskUtils
  6640. + */
  6641. +#define tskIDLE_PRIORITY ( ( UBaseType_t ) 0U )
  6642. +
  6643. +/**
  6644. + * task. h
  6645. + *
  6646. + * Macro for forcing a context switch.
  6647. + *
  6648. + * \defgroup taskYIELD taskYIELD
  6649. + * \ingroup SchedulerControl
  6650. + */
  6651. +#define taskYIELD() portYIELD()
  6652. +
  6653. +/**
  6654. + * task. h
  6655. + *
  6656. + * Macro to mark the start of a critical code region. Preemptive context
  6657. + * switches cannot occur when in a critical region.
  6658. + *
  6659. + * NOTE: This may alter the stack (depending on the portable implementation)
  6660. + * so must be used with care!
  6661. + *
  6662. + * \defgroup taskENTER_CRITICAL taskENTER_CRITICAL
  6663. + * \ingroup SchedulerControl
  6664. + */
  6665. +#define taskENTER_CRITICAL() portENTER_CRITICAL()
  6666. +#define taskENTER_CRITICAL_FROM_ISR() portSET_INTERRUPT_MASK_FROM_ISR()
  6667. +
  6668. +/**
  6669. + * task. h
  6670. + *
  6671. + * Macro to mark the end of a critical code region. Preemptive context
  6672. + * switches cannot occur when in a critical region.
  6673. + *
  6674. + * NOTE: This may alter the stack (depending on the portable implementation)
  6675. + * so must be used with care!
  6676. + *
  6677. + * \defgroup taskEXIT_CRITICAL taskEXIT_CRITICAL
  6678. + * \ingroup SchedulerControl
  6679. + */
  6680. +#define taskEXIT_CRITICAL() portEXIT_CRITICAL()
  6681. +#define taskEXIT_CRITICAL_FROM_ISR( x ) portCLEAR_INTERRUPT_MASK_FROM_ISR( x )
  6682. +
  6683. +/**
  6684. + * task. h
  6685. + *
  6686. + * Macro to disable all maskable interrupts.
  6687. + *
  6688. + * \defgroup taskDISABLE_INTERRUPTS taskDISABLE_INTERRUPTS
  6689. + * \ingroup SchedulerControl
  6690. + */
  6691. +#define taskDISABLE_INTERRUPTS() portDISABLE_INTERRUPTS()
  6692. +
  6693. +/**
  6694. + * task. h
  6695. + *
  6696. + * Macro to enable microcontroller interrupts.
  6697. + *
  6698. + * \defgroup taskENABLE_INTERRUPTS taskENABLE_INTERRUPTS
  6699. + * \ingroup SchedulerControl
  6700. + */
  6701. +#define taskENABLE_INTERRUPTS() portENABLE_INTERRUPTS()
  6702. +
  6703. +/* Definitions returned by xTaskGetSchedulerState(). taskSCHEDULER_SUSPENDED is
  6704. + * 0 to generate more optimal code when configASSERT() is defined as the constant
  6705. + * is used in assert() statements. */
  6706. +#define taskSCHEDULER_SUSPENDED ( ( BaseType_t ) 0 )
  6707. +#define taskSCHEDULER_NOT_STARTED ( ( BaseType_t ) 1 )
  6708. +#define taskSCHEDULER_RUNNING ( ( BaseType_t ) 2 )
  6709. +
  6710. +/*-----------------------------------------------------------
  6711. +* TASK CREATION API
  6712. +*----------------------------------------------------------*/
  6713. +
  6714. +/**
  6715. + * task. h
  6716. + * @code{c}
  6717. + * BaseType_t xTaskCreate(
  6718. + * TaskFunction_t pxTaskCode,
  6719. + * const char *pcName,
  6720. + * configSTACK_DEPTH_TYPE usStackDepth,
  6721. + * void *pvParameters,
  6722. + * UBaseType_t uxPriority,
  6723. + * TaskHandle_t *pxCreatedTask
  6724. + * );
  6725. + * @endcode
  6726. + *
  6727. + * Create a new task and add it to the list of tasks that are ready to run.
  6728. + *
  6729. + * Internally, within the FreeRTOS implementation, tasks use two blocks of
  6730. + * memory. The first block is used to hold the task's data structures. The
  6731. + * second block is used by the task as its stack. If a task is created using
  6732. + * xTaskCreate() then both blocks of memory are automatically dynamically
  6733. + * allocated inside the xTaskCreate() function. (see
  6734. + * https://www.FreeRTOS.org/a00111.html). If a task is created using
  6735. + * xTaskCreateStatic() then the application writer must provide the required
  6736. + * memory. xTaskCreateStatic() therefore allows a task to be created without
  6737. + * using any dynamic memory allocation.
  6738. + *
  6739. + * See xTaskCreateStatic() for a version that does not use any dynamic memory
  6740. + * allocation.
  6741. + *
  6742. + * xTaskCreate() can only be used to create a task that has unrestricted
  6743. + * access to the entire microcontroller memory map. Systems that include MPU
  6744. + * support can alternatively create an MPU constrained task using
  6745. + * xTaskCreateRestricted().
  6746. + *
  6747. + * @param pxTaskCode Pointer to the task entry function. Tasks
  6748. + * must be implemented to never return (i.e. continuous loop).
  6749. + *
  6750. + * @param pcName A descriptive name for the task. This is mainly used to
  6751. + * facilitate debugging. Max length defined by configMAX_TASK_NAME_LEN - default
  6752. + * is 16.
  6753. + *
  6754. + * @param usStackDepth The size of the task stack specified as the number of
  6755. + * variables the stack can hold - not the number of bytes. For example, if
  6756. + * the stack is 16 bits wide and usStackDepth is defined as 100, 200 bytes
  6757. + * will be allocated for stack storage.
  6758. + *
  6759. + * @param pvParameters Pointer that will be used as the parameter for the task
  6760. + * being created.
  6761. + *
  6762. + * @param uxPriority The priority at which the task should run. Systems that
  6763. + * include MPU support can optionally create tasks in a privileged (system)
  6764. + * mode by setting bit portPRIVILEGE_BIT of the priority parameter. For
  6765. + * example, to create a privileged task at priority 2 the uxPriority parameter
  6766. + * should be set to ( 2 | portPRIVILEGE_BIT ).
  6767. + *
  6768. + * @param pxCreatedTask Used to pass back a handle by which the created task
  6769. + * can be referenced.
  6770. + *
  6771. + * @return pdPASS if the task was successfully created and added to a ready
  6772. + * list, otherwise an error code defined in the file projdefs.h
  6773. + *
  6774. + * Example usage:
  6775. + * @code{c}
  6776. + * // Task to be created.
  6777. + * void vTaskCode( void * pvParameters )
  6778. + * {
  6779. + * for( ;; )
  6780. + * {
  6781. + * // Task code goes here.
  6782. + * }
  6783. + * }
  6784. + *
  6785. + * // Function that creates a task.
  6786. + * void vOtherFunction( void )
  6787. + * {
  6788. + * static uint8_t ucParameterToPass;
  6789. + * TaskHandle_t xHandle = NULL;
  6790. + *
  6791. + * // Create the task, storing the handle. Note that the passed parameter ucParameterToPass
  6792. + * // must exist for the lifetime of the task, so in this case is declared static. If it was just an
  6793. + * // an automatic stack variable it might no longer exist, or at least have been corrupted, by the time
  6794. + * // the new task attempts to access it.
  6795. + * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, &ucParameterToPass, tskIDLE_PRIORITY, &xHandle );
  6796. + * configASSERT( xHandle );
  6797. + *
  6798. + * // Use the handle to delete the task.
  6799. + * if( xHandle != NULL )
  6800. + * {
  6801. + * vTaskDelete( xHandle );
  6802. + * }
  6803. + * }
  6804. + * @endcode
  6805. + * \defgroup xTaskCreate xTaskCreate
  6806. + * \ingroup Tasks
  6807. + */
  6808. +#if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
  6809. + BaseType_t xTaskCreate( TaskFunction_t pxTaskCode,
  6810. + const char * const pcName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
  6811. + const configSTACK_DEPTH_TYPE usStackDepth,
  6812. + void * const pvParameters,
  6813. + UBaseType_t uxPriority,
  6814. + TaskHandle_t * const pxCreatedTask );
  6815. +#endif
  6816. +/* ESP32 */
  6817. +#if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
  6818. + BaseType_t xTaskCreatePinnedToCore( TaskFunction_t pvTaskCode,
  6819. + const char * const pcName,
  6820. + const uint32_t usStackDepth,
  6821. + void * const pvParameters,
  6822. + UBaseType_t uxPriority,
  6823. + TaskHandle_t * const pvCreatedTask,
  6824. + const BaseType_t xCoreID);
  6825. +
  6826. +#endif
  6827. +
  6828. +/**
  6829. + * task. h
  6830. + * @code{c}
  6831. + * TaskHandle_t xTaskCreateStatic( TaskFunction_t pxTaskCode,
  6832. + * const char *pcName,
  6833. + * uint32_t ulStackDepth,
  6834. + * void *pvParameters,
  6835. + * UBaseType_t uxPriority,
  6836. + * StackType_t *puxStackBuffer,
  6837. + * StaticTask_t *pxTaskBuffer );
  6838. + * @endcode
  6839. + *
  6840. + * Create a new task and add it to the list of tasks that are ready to run.
  6841. + *
  6842. + * Internally, within the FreeRTOS implementation, tasks use two blocks of
  6843. + * memory. The first block is used to hold the task's data structures. The
  6844. + * second block is used by the task as its stack. If a task is created using
  6845. + * xTaskCreate() then both blocks of memory are automatically dynamically
  6846. + * allocated inside the xTaskCreate() function. (see
  6847. + * https://www.FreeRTOS.org/a00111.html). If a task is created using
  6848. + * xTaskCreateStatic() then the application writer must provide the required
  6849. + * memory. xTaskCreateStatic() therefore allows a task to be created without
  6850. + * using any dynamic memory allocation.
  6851. + *
  6852. + * @param pxTaskCode Pointer to the task entry function. Tasks
  6853. + * must be implemented to never return (i.e. continuous loop).
  6854. + *
  6855. + * @param pcName A descriptive name for the task. This is mainly used to
  6856. + * facilitate debugging. The maximum length of the string is defined by
  6857. + * configMAX_TASK_NAME_LEN in FreeRTOSConfig.h.
  6858. + *
  6859. + * @param ulStackDepth The size of the task stack specified as the number of
  6860. + * variables the stack can hold - not the number of bytes. For example, if
  6861. + * the stack is 32-bits wide and ulStackDepth is defined as 100 then 400 bytes
  6862. + * will be allocated for stack storage.
  6863. + *
  6864. + * @param pvParameters Pointer that will be used as the parameter for the task
  6865. + * being created.
  6866. + *
  6867. + * @param uxPriority The priority at which the task will run.
  6868. + *
  6869. + * @param puxStackBuffer Must point to a StackType_t array that has at least
  6870. + * ulStackDepth indexes - the array will then be used as the task's stack,
  6871. + * removing the need for the stack to be allocated dynamically.
  6872. + *
  6873. + * @param pxTaskBuffer Must point to a variable of type StaticTask_t, which will
  6874. + * then be used to hold the task's data structures, removing the need for the
  6875. + * memory to be allocated dynamically.
  6876. + *
  6877. + * @return If neither puxStackBuffer nor pxTaskBuffer are NULL, then the task
  6878. + * will be created and a handle to the created task is returned. If either
  6879. + * puxStackBuffer or pxTaskBuffer are NULL then the task will not be created and
  6880. + * NULL is returned.
  6881. + *
  6882. + * Example usage:
  6883. + * @code{c}
  6884. + *
  6885. + * // Dimensions of the buffer that the task being created will use as its stack.
  6886. + * // NOTE: This is the number of words the stack will hold, not the number of
  6887. + * // bytes. For example, if each stack item is 32-bits, and this is set to 100,
  6888. + * // then 400 bytes (100 * 32-bits) will be allocated.
  6889. + #define STACK_SIZE 200
  6890. + *
  6891. + * // Structure that will hold the TCB of the task being created.
  6892. + * StaticTask_t xTaskBuffer;
  6893. + *
  6894. + * // Buffer that the task being created will use as its stack. Note this is
  6895. + * // an array of StackType_t variables. The size of StackType_t is dependent on
  6896. + * // the RTOS port.
  6897. + * StackType_t xStack[ STACK_SIZE ];
  6898. + *
  6899. + * // Function that implements the task being created.
  6900. + * void vTaskCode( void * pvParameters )
  6901. + * {
  6902. + * // The parameter value is expected to be 1 as 1 is passed in the
  6903. + * // pvParameters value in the call to xTaskCreateStatic().
  6904. + * configASSERT( ( uint32_t ) pvParameters == 1UL );
  6905. + *
  6906. + * for( ;; )
  6907. + * {
  6908. + * // Task code goes here.
  6909. + * }
  6910. + * }
  6911. + *
  6912. + * // Function that creates a task.
  6913. + * void vOtherFunction( void )
  6914. + * {
  6915. + * TaskHandle_t xHandle = NULL;
  6916. + *
  6917. + * // Create the task without using any dynamic memory allocation.
  6918. + * xHandle = xTaskCreateStatic(
  6919. + * vTaskCode, // Function that implements the task.
  6920. + * "NAME", // Text name for the task.
  6921. + * STACK_SIZE, // Stack size in words, not bytes.
  6922. + * ( void * ) 1, // Parameter passed into the task.
  6923. + * tskIDLE_PRIORITY,// Priority at which the task is created.
  6924. + * xStack, // Array to use as the task's stack.
  6925. + * &xTaskBuffer ); // Variable to hold the task's data structure.
  6926. + *
  6927. + * // puxStackBuffer and pxTaskBuffer were not NULL, so the task will have
  6928. + * // been created, and xHandle will be the task's handle. Use the handle
  6929. + * // to suspend the task.
  6930. + * vTaskSuspend( xHandle );
  6931. + * }
  6932. + * @endcode
  6933. + * \defgroup xTaskCreateStatic xTaskCreateStatic
  6934. + * \ingroup Tasks
  6935. + */
  6936. +#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
  6937. + TaskHandle_t xTaskCreateStatic( TaskFunction_t pxTaskCode,
  6938. + const char * const pcName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
  6939. + const uint32_t ulStackDepth,
  6940. + void * const pvParameters,
  6941. + UBaseType_t uxPriority,
  6942. + StackType_t * const puxStackBuffer,
  6943. + StaticTask_t * const pxTaskBuffer );
  6944. +#endif /* configSUPPORT_STATIC_ALLOCATION */
  6945. +
  6946. +/**
  6947. + * task. h
  6948. + * @code{c}
  6949. + * void vTaskDelete( TaskHandle_t xTaskToDelete );
  6950. + * @endcode
  6951. + *
  6952. + * INCLUDE_vTaskDelete must be defined as 1 for this function to be available.
  6953. + * See the configuration section for more information.
  6954. + *
  6955. + * Remove a task from the RTOS real time kernel's management. The task being
  6956. + * deleted will be removed from all ready, blocked, suspended and event lists.
  6957. + *
  6958. + * NOTE: The idle task is responsible for freeing the kernel allocated
  6959. + * memory from tasks that have been deleted. It is therefore important that
  6960. + * the idle task is not starved of microcontroller processing time if your
  6961. + * application makes any calls to vTaskDelete (). Memory allocated by the
  6962. + * task code is not automatically freed, and should be freed before the task
  6963. + * is deleted.
  6964. + *
  6965. + * See the demo application file death.c for sample code that utilises
  6966. + * vTaskDelete ().
  6967. + *
  6968. + * @param xTaskToDelete The handle of the task to be deleted. Passing NULL will
  6969. + * cause the calling task to be deleted.
  6970. + *
  6971. + * Example usage:
  6972. + * @code{c}
  6973. + * void vOtherFunction( void )
  6974. + * {
  6975. + * TaskHandle_t xHandle;
  6976. + *
  6977. + * // Create the task, storing the handle.
  6978. + * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
  6979. + *
  6980. + * // Use the handle to delete the task.
  6981. + * vTaskDelete( xHandle );
  6982. + * }
  6983. + * @endcode
  6984. + * \defgroup vTaskDelete vTaskDelete
  6985. + * \ingroup Tasks
  6986. + */
  6987. +void vTaskDelete( TaskHandle_t xTaskToDelete );
  6988. +
  6989. +/*-----------------------------------------------------------
  6990. +* TASK CONTROL API
  6991. +*----------------------------------------------------------*/
  6992. +
  6993. +/**
  6994. + * task. h
  6995. + * @code{c}
  6996. + * void vTaskDelay( const TickType_t xTicksToDelay );
  6997. + * @endcode
  6998. + *
  6999. + * Delay a task for a given number of ticks. The actual time that the
  7000. + * task remains blocked depends on the tick rate. The constant
  7001. + * portTICK_PERIOD_MS can be used to calculate real time from the tick
  7002. + * rate - with the resolution of one tick period.
  7003. + *
  7004. + * INCLUDE_vTaskDelay must be defined as 1 for this function to be available.
  7005. + * See the configuration section for more information.
  7006. + *
  7007. + *
  7008. + * vTaskDelay() specifies a time at which the task wishes to unblock relative to
  7009. + * the time at which vTaskDelay() is called. For example, specifying a block
  7010. + * period of 100 ticks will cause the task to unblock 100 ticks after
  7011. + * vTaskDelay() is called. vTaskDelay() does not therefore provide a good method
  7012. + * of controlling the frequency of a periodic task as the path taken through the
  7013. + * code, as well as other task and interrupt activity, will affect the frequency
  7014. + * at which vTaskDelay() gets called and therefore the time at which the task
  7015. + * next executes. See xTaskDelayUntil() for an alternative API function designed
  7016. + * to facilitate fixed frequency execution. It does this by specifying an
  7017. + * absolute time (rather than a relative time) at which the calling task should
  7018. + * unblock.
  7019. + *
  7020. + * @param xTicksToDelay The amount of time, in tick periods, that
  7021. + * the calling task should block.
  7022. + *
  7023. + * Example usage:
  7024. + *
  7025. + * void vTaskFunction( void * pvParameters )
  7026. + * {
  7027. + * // Block for 500ms.
  7028. + * const TickType_t xDelay = 500 / portTICK_PERIOD_MS;
  7029. + *
  7030. + * for( ;; )
  7031. + * {
  7032. + * // Simply toggle the LED every 500ms, blocking between each toggle.
  7033. + * vToggleLED();
  7034. + * vTaskDelay( xDelay );
  7035. + * }
  7036. + * }
  7037. + *
  7038. + * \defgroup vTaskDelay vTaskDelay
  7039. + * \ingroup TaskCtrl
  7040. + */
  7041. +void vTaskDelay( const TickType_t xTicksToDelay );
  7042. +
  7043. +/**
  7044. + * task. h
  7045. + * @code{c}
  7046. + * BaseType_t xTaskDelayUntil( TickType_t *pxPreviousWakeTime, const TickType_t xTimeIncrement );
  7047. + * @endcode
  7048. + *
  7049. + * INCLUDE_xTaskDelayUntil must be defined as 1 for this function to be available.
  7050. + * See the configuration section for more information.
  7051. + *
  7052. + * Delay a task until a specified time. This function can be used by periodic
  7053. + * tasks to ensure a constant execution frequency.
  7054. + *
  7055. + * This function differs from vTaskDelay () in one important aspect: vTaskDelay () will
  7056. + * cause a task to block for the specified number of ticks from the time vTaskDelay () is
  7057. + * called. It is therefore difficult to use vTaskDelay () by itself to generate a fixed
  7058. + * execution frequency as the time between a task starting to execute and that task
  7059. + * calling vTaskDelay () may not be fixed [the task may take a different path though the
  7060. + * code between calls, or may get interrupted or preempted a different number of times
  7061. + * each time it executes].
  7062. + *
  7063. + * Whereas vTaskDelay () specifies a wake time relative to the time at which the function
  7064. + * is called, xTaskDelayUntil () specifies the absolute (exact) time at which it wishes to
  7065. + * unblock.
  7066. + *
  7067. + * The macro pdMS_TO_TICKS() can be used to calculate the number of ticks from a
  7068. + * time specified in milliseconds with a resolution of one tick period.
  7069. + *
  7070. + * @param pxPreviousWakeTime Pointer to a variable that holds the time at which the
  7071. + * task was last unblocked. The variable must be initialised with the current time
  7072. + * prior to its first use (see the example below). Following this the variable is
  7073. + * automatically updated within xTaskDelayUntil ().
  7074. + *
  7075. + * @param xTimeIncrement The cycle time period. The task will be unblocked at
  7076. + * time *pxPreviousWakeTime + xTimeIncrement. Calling xTaskDelayUntil with the
  7077. + * same xTimeIncrement parameter value will cause the task to execute with
  7078. + * a fixed interface period.
  7079. + *
  7080. + * @return Value which can be used to check whether the task was actually delayed.
  7081. + * Will be pdTRUE if the task way delayed and pdFALSE otherwise. A task will not
  7082. + * be delayed if the next expected wake time is in the past.
  7083. + *
  7084. + * Example usage:
  7085. + * @code{c}
  7086. + * // Perform an action every 10 ticks.
  7087. + * void vTaskFunction( void * pvParameters )
  7088. + * {
  7089. + * TickType_t xLastWakeTime;
  7090. + * const TickType_t xFrequency = 10;
  7091. + * BaseType_t xWasDelayed;
  7092. + *
  7093. + * // Initialise the xLastWakeTime variable with the current time.
  7094. + * xLastWakeTime = xTaskGetTickCount ();
  7095. + * for( ;; )
  7096. + * {
  7097. + * // Wait for the next cycle.
  7098. + * xWasDelayed = xTaskDelayUntil( &xLastWakeTime, xFrequency );
  7099. + *
  7100. + * // Perform action here. xWasDelayed value can be used to determine
  7101. + * // whether a deadline was missed if the code here took too long.
  7102. + * }
  7103. + * }
  7104. + * @endcode
  7105. + * \defgroup xTaskDelayUntil xTaskDelayUntil
  7106. + * \ingroup TaskCtrl
  7107. + */
  7108. +BaseType_t xTaskDelayUntil( TickType_t * const pxPreviousWakeTime,
  7109. + const TickType_t xTimeIncrement );
  7110. +
  7111. +/*
  7112. + * vTaskDelayUntil() is the older version of xTaskDelayUntil() and does not
  7113. + * return a value.
  7114. + */
  7115. +#define vTaskDelayUntil( pxPreviousWakeTime, xTimeIncrement ) \
  7116. + { \
  7117. + ( void ) xTaskDelayUntil( pxPreviousWakeTime, xTimeIncrement ); \
  7118. + }
  7119. +
  7120. +/**
  7121. + * task. h
  7122. + * @code{c}
  7123. + * BaseType_t xTaskAbortDelay( TaskHandle_t xTask );
  7124. + * @endcode
  7125. + *
  7126. + * INCLUDE_xTaskAbortDelay must be defined as 1 in FreeRTOSConfig.h for this
  7127. + * function to be available.
  7128. + *
  7129. + * A task will enter the Blocked state when it is waiting for an event. The
  7130. + * event it is waiting for can be a temporal event (waiting for a time), such
  7131. + * as when vTaskDelay() is called, or an event on an object, such as when
  7132. + * xQueueReceive() or ulTaskNotifyTake() is called. If the handle of a task
  7133. + * that is in the Blocked state is used in a call to xTaskAbortDelay() then the
  7134. + * task will leave the Blocked state, and return from whichever function call
  7135. + * placed the task into the Blocked state.
  7136. + *
  7137. + * There is no 'FromISR' version of this function as an interrupt would need to
  7138. + * know which object a task was blocked on in order to know which actions to
  7139. + * take. For example, if the task was blocked on a queue the interrupt handler
  7140. + * would then need to know if the queue was locked.
  7141. + *
  7142. + * @param xTask The handle of the task to remove from the Blocked state.
  7143. + *
  7144. + * @return If the task referenced by xTask was not in the Blocked state then
  7145. + * pdFAIL is returned. Otherwise pdPASS is returned.
  7146. + *
  7147. + * \defgroup xTaskAbortDelay xTaskAbortDelay
  7148. + * \ingroup TaskCtrl
  7149. + */
  7150. +BaseType_t xTaskAbortDelay( TaskHandle_t xTask );
  7151. +
  7152. +/**
  7153. + * task. h
  7154. + * @code{c}
  7155. + * UBaseType_t uxTaskPriorityGet( const TaskHandle_t xTask );
  7156. + * @endcode
  7157. + *
  7158. + * INCLUDE_uxTaskPriorityGet must be defined as 1 for this function to be available.
  7159. + * See the configuration section for more information.
  7160. + *
  7161. + * Obtain the priority of any task.
  7162. + *
  7163. + * @param xTask Handle of the task to be queried. Passing a NULL
  7164. + * handle results in the priority of the calling task being returned.
  7165. + *
  7166. + * @return The priority of xTask.
  7167. + *
  7168. + * Example usage:
  7169. + * @code{c}
  7170. + * void vAFunction( void )
  7171. + * {
  7172. + * TaskHandle_t xHandle;
  7173. + *
  7174. + * // Create a task, storing the handle.
  7175. + * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
  7176. + *
  7177. + * // ...
  7178. + *
  7179. + * // Use the handle to obtain the priority of the created task.
  7180. + * // It was created with tskIDLE_PRIORITY, but may have changed
  7181. + * // it itself.
  7182. + * if( uxTaskPriorityGet( xHandle ) != tskIDLE_PRIORITY )
  7183. + * {
  7184. + * // The task has changed it's priority.
  7185. + * }
  7186. + *
  7187. + * // ...
  7188. + *
  7189. + * // Is our priority higher than the created task?
  7190. + * if( uxTaskPriorityGet( xHandle ) < uxTaskPriorityGet( NULL ) )
  7191. + * {
  7192. + * // Our priority (obtained using NULL handle) is higher.
  7193. + * }
  7194. + * }
  7195. + * @endcode
  7196. + * \defgroup uxTaskPriorityGet uxTaskPriorityGet
  7197. + * \ingroup TaskCtrl
  7198. + */
  7199. +UBaseType_t uxTaskPriorityGet( const TaskHandle_t xTask );
  7200. +
  7201. +/**
  7202. + * task. h
  7203. + * @code{c}
  7204. + * UBaseType_t uxTaskPriorityGetFromISR( const TaskHandle_t xTask );
  7205. + * @endcode
  7206. + *
  7207. + * A version of uxTaskPriorityGet() that can be used from an ISR.
  7208. + */
  7209. +UBaseType_t uxTaskPriorityGetFromISR( const TaskHandle_t xTask );
  7210. +
  7211. +/**
  7212. + * task. h
  7213. + * @code{c}
  7214. + * eTaskState eTaskGetState( TaskHandle_t xTask );
  7215. + * @endcode
  7216. + *
  7217. + * INCLUDE_eTaskGetState must be defined as 1 for this function to be available.
  7218. + * See the configuration section for more information.
  7219. + *
  7220. + * Obtain the state of any task. States are encoded by the eTaskState
  7221. + * enumerated type.
  7222. + *
  7223. + * @param xTask Handle of the task to be queried.
  7224. + *
  7225. + * @return The state of xTask at the time the function was called. Note the
  7226. + * state of the task might change between the function being called, and the
  7227. + * functions return value being tested by the calling task.
  7228. + */
  7229. +eTaskState eTaskGetState( TaskHandle_t xTask );
  7230. +
  7231. +/**
  7232. + * task. h
  7233. + * @code{c}
  7234. + * void vTaskPrioritySet( TaskHandle_t xTask, UBaseType_t uxNewPriority );
  7235. + * @endcode
  7236. + *
  7237. + * INCLUDE_vTaskPrioritySet must be defined as 1 for this function to be available.
  7238. + * See the configuration section for more information.
  7239. + *
  7240. + * Set the priority of any task.
  7241. + *
  7242. + * A context switch will occur before the function returns if the priority
  7243. + * being set is higher than the currently executing task.
  7244. + *
  7245. + * @param xTask Handle to the task for which the priority is being set.
  7246. + * Passing a NULL handle results in the priority of the calling task being set.
  7247. + *
  7248. + * @param uxNewPriority The priority to which the task will be set.
  7249. + *
  7250. + * Example usage:
  7251. + * @code{c}
  7252. + * void vAFunction( void )
  7253. + * {
  7254. + * TaskHandle_t xHandle;
  7255. + *
  7256. + * // Create a task, storing the handle.
  7257. + * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
  7258. + *
  7259. + * // ...
  7260. + *
  7261. + * // Use the handle to raise the priority of the created task.
  7262. + * vTaskPrioritySet( xHandle, tskIDLE_PRIORITY + 1 );
  7263. + *
  7264. + * // ...
  7265. + *
  7266. + * // Use a NULL handle to raise our priority to the same value.
  7267. + * vTaskPrioritySet( NULL, tskIDLE_PRIORITY + 1 );
  7268. + * }
  7269. + * @endcode
  7270. + * \defgroup vTaskPrioritySet vTaskPrioritySet
  7271. + * \ingroup TaskCtrl
  7272. + */
  7273. +void vTaskPrioritySet( TaskHandle_t xTask,
  7274. + UBaseType_t uxNewPriority );
  7275. +
  7276. +/**
  7277. + * task. h
  7278. + * @code{c}
  7279. + * void vTaskSuspend( TaskHandle_t xTaskToSuspend );
  7280. + * @endcode
  7281. + *
  7282. + * INCLUDE_vTaskSuspend must be defined as 1 for this function to be available.
  7283. + * See the configuration section for more information.
  7284. + *
  7285. + * Suspend any task. When suspended a task will never get any microcontroller
  7286. + * processing time, no matter what its priority.
  7287. + *
  7288. + * Calls to vTaskSuspend are not accumulative -
  7289. + * i.e. calling vTaskSuspend () twice on the same task still only requires one
  7290. + * call to vTaskResume () to ready the suspended task.
  7291. + *
  7292. + * RT-Thread only supports suspending the current running thread.
  7293. + * This function must be called with NULL as the parameter.
  7294. + *
  7295. + * @param xTaskToSuspend Handle to the task being suspended. Passing a NULL
  7296. + * handle will cause the calling task to be suspended.
  7297. + *
  7298. + * Example usage:
  7299. + * @code{c}
  7300. + * void vAFunction( void )
  7301. + * {
  7302. + * TaskHandle_t xHandle;
  7303. + *
  7304. + * // Create a task, storing the handle.
  7305. + * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
  7306. + *
  7307. + * // ...
  7308. + *
  7309. + * // Use the handle to suspend the created task.
  7310. + * vTaskSuspend( xHandle );
  7311. + *
  7312. + * // ...
  7313. + *
  7314. + * // The created task will not run during this period, unless
  7315. + * // another task calls vTaskResume( xHandle ).
  7316. + *
  7317. + * //...
  7318. + *
  7319. + *
  7320. + * // Suspend ourselves.
  7321. + * vTaskSuspend( NULL );
  7322. + *
  7323. + * // We cannot get here unless another task calls vTaskResume
  7324. + * // with our handle as the parameter.
  7325. + * }
  7326. + * @endcode
  7327. + * \defgroup vTaskSuspend vTaskSuspend
  7328. + * \ingroup TaskCtrl
  7329. + */
  7330. +void vTaskSuspend( TaskHandle_t xTaskToSuspend );
  7331. +
  7332. +/**
  7333. + * task. h
  7334. + * @code{c}
  7335. + * void vTaskResume( TaskHandle_t xTaskToResume );
  7336. + * @endcode
  7337. + *
  7338. + * INCLUDE_vTaskSuspend must be defined as 1 for this function to be available.
  7339. + * See the configuration section for more information.
  7340. + *
  7341. + * Resumes a suspended task.
  7342. + *
  7343. + * A task that has been suspended by one or more calls to vTaskSuspend ()
  7344. + * will be made available for running again by a single call to
  7345. + * vTaskResume ().
  7346. + *
  7347. + * @param xTaskToResume Handle to the task being readied.
  7348. + *
  7349. + * Example usage:
  7350. + * @code{c}
  7351. + * void vAFunction( void )
  7352. + * {
  7353. + * TaskHandle_t xHandle;
  7354. + *
  7355. + * // Create a task, storing the handle.
  7356. + * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
  7357. + *
  7358. + * // ...
  7359. + *
  7360. + * // Use the handle to suspend the created task.
  7361. + * vTaskSuspend( xHandle );
  7362. + *
  7363. + * // ...
  7364. + *
  7365. + * // The created task will not run during this period, unless
  7366. + * // another task calls vTaskResume( xHandle ).
  7367. + *
  7368. + * //...
  7369. + *
  7370. + *
  7371. + * // Resume the suspended task ourselves.
  7372. + * vTaskResume( xHandle );
  7373. + *
  7374. + * // The created task will once again get microcontroller processing
  7375. + * // time in accordance with its priority within the system.
  7376. + * }
  7377. + * @endcode
  7378. + * \defgroup vTaskResume vTaskResume
  7379. + * \ingroup TaskCtrl
  7380. + */
  7381. +void vTaskResume( TaskHandle_t xTaskToResume );
  7382. +
  7383. +/**
  7384. + * task. h
  7385. + * @code{c}
  7386. + * void xTaskResumeFromISR( TaskHandle_t xTaskToResume );
  7387. + * @endcode
  7388. + *
  7389. + * INCLUDE_xTaskResumeFromISR must be defined as 1 for this function to be
  7390. + * available. See the configuration section for more information.
  7391. + *
  7392. + * An implementation of vTaskResume() that can be called from within an ISR.
  7393. + *
  7394. + * A task that has been suspended by one or more calls to vTaskSuspend ()
  7395. + * will be made available for running again by a single call to
  7396. + * xTaskResumeFromISR ().
  7397. + *
  7398. + * xTaskResumeFromISR() should not be used to synchronise a task with an
  7399. + * interrupt if there is a chance that the interrupt could arrive prior to the
  7400. + * task being suspended - as this can lead to interrupts being missed. Use of a
  7401. + * semaphore as a synchronisation mechanism would avoid this eventuality.
  7402. + *
  7403. + * @param xTaskToResume Handle to the task being readied.
  7404. + *
  7405. + * @return pdTRUE if resuming the task should result in a context switch,
  7406. + * otherwise pdFALSE. This is used by the ISR to determine if a context switch
  7407. + * may be required following the ISR.
  7408. + *
  7409. + * \defgroup vTaskResumeFromISR vTaskResumeFromISR
  7410. + * \ingroup TaskCtrl
  7411. + */
  7412. +BaseType_t xTaskResumeFromISR( TaskHandle_t xTaskToResume );
  7413. +
  7414. +/*-----------------------------------------------------------
  7415. +* SCHEDULER CONTROL
  7416. +*----------------------------------------------------------*/
  7417. +
  7418. +/**
  7419. + * task. h
  7420. + * @code{c}
  7421. + * void vTaskStartScheduler( void );
  7422. + * @endcode
  7423. + *
  7424. + * Starts the real time kernel tick processing. After calling the kernel
  7425. + * has control over which tasks are executed and when.
  7426. + *
  7427. + * See the demo application file main.c for an example of creating
  7428. + * tasks and starting the kernel.
  7429. + *
  7430. + * Example usage:
  7431. + * @code{c}
  7432. + * void vAFunction( void )
  7433. + * {
  7434. + * // Create at least one task before starting the kernel.
  7435. + * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
  7436. + *
  7437. + * // Start the real time kernel with preemption.
  7438. + * vTaskStartScheduler ();
  7439. + *
  7440. + * // Will not get here unless a task calls vTaskEndScheduler ()
  7441. + * }
  7442. + * @endcode
  7443. + *
  7444. + * \defgroup vTaskStartScheduler vTaskStartScheduler
  7445. + * \ingroup SchedulerControl
  7446. + */
  7447. +void vTaskStartScheduler( void );
  7448. +
  7449. +/**
  7450. + * task. h
  7451. + * @code{c}
  7452. + * void vTaskEndScheduler( void );
  7453. + * @endcode
  7454. + *
  7455. + * NOTE: At the time of writing only the x86 real mode port, which runs on a PC
  7456. + * in place of DOS, implements this function.
  7457. + *
  7458. + * Stops the real time kernel tick. All created tasks will be automatically
  7459. + * deleted and multitasking (either preemptive or cooperative) will
  7460. + * stop. Execution then resumes from the point where vTaskStartScheduler ()
  7461. + * was called, as if vTaskStartScheduler () had just returned.
  7462. + *
  7463. + * See the demo application file main. c in the demo/PC directory for an
  7464. + * example that uses vTaskEndScheduler ().
  7465. + *
  7466. + * vTaskEndScheduler () requires an exit function to be defined within the
  7467. + * portable layer (see vPortEndScheduler () in port. c for the PC port). This
  7468. + * performs hardware specific operations such as stopping the kernel tick.
  7469. + *
  7470. + * vTaskEndScheduler () will cause all of the resources allocated by the
  7471. + * kernel to be freed - but will not free resources allocated by application
  7472. + * tasks.
  7473. + *
  7474. + * Example usage:
  7475. + * @code{c}
  7476. + * void vTaskCode( void * pvParameters )
  7477. + * {
  7478. + * for( ;; )
  7479. + * {
  7480. + * // Task code goes here.
  7481. + *
  7482. + * // At some point we want to end the real time kernel processing
  7483. + * // so call ...
  7484. + * vTaskEndScheduler ();
  7485. + * }
  7486. + * }
  7487. + *
  7488. + * void vAFunction( void )
  7489. + * {
  7490. + * // Create at least one task before starting the kernel.
  7491. + * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
  7492. + *
  7493. + * // Start the real time kernel with preemption.
  7494. + * vTaskStartScheduler ();
  7495. + *
  7496. + * // Will only get here when the vTaskCode () task has called
  7497. + * // vTaskEndScheduler (). When we get here we are back to single task
  7498. + * // execution.
  7499. + * }
  7500. + * @endcode
  7501. + *
  7502. + * \defgroup vTaskEndScheduler vTaskEndScheduler
  7503. + * \ingroup SchedulerControl
  7504. + */
  7505. +void vTaskEndScheduler( void );
  7506. +
  7507. +/**
  7508. + * task. h
  7509. + * @code{c}
  7510. + * void vTaskSuspendAll( void );
  7511. + * @endcode
  7512. + *
  7513. + * Suspends the scheduler without disabling interrupts. Context switches will
  7514. + * not occur while the scheduler is suspended.
  7515. + *
  7516. + * After calling vTaskSuspendAll () the calling task will continue to execute
  7517. + * without risk of being swapped out until a call to xTaskResumeAll () has been
  7518. + * made.
  7519. + *
  7520. + * API functions that have the potential to cause a context switch (for example,
  7521. + * xTaskDelayUntil(), xQueueSend(), etc.) must not be called while the scheduler
  7522. + * is suspended.
  7523. + *
  7524. + * Example usage:
  7525. + * @code{c}
  7526. + * void vTask1( void * pvParameters )
  7527. + * {
  7528. + * for( ;; )
  7529. + * {
  7530. + * // Task code goes here.
  7531. + *
  7532. + * // ...
  7533. + *
  7534. + * // At some point the task wants to perform a long operation during
  7535. + * // which it does not want to get swapped out. It cannot use
  7536. + * // taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the
  7537. + * // operation may cause interrupts to be missed - including the
  7538. + * // ticks.
  7539. + *
  7540. + * // Prevent the real time kernel swapping out the task.
  7541. + * vTaskSuspendAll ();
  7542. + *
  7543. + * // Perform the operation here. There is no need to use critical
  7544. + * // sections as we have all the microcontroller processing time.
  7545. + * // During this time interrupts will still operate and the kernel
  7546. + * // tick count will be maintained.
  7547. + *
  7548. + * // ...
  7549. + *
  7550. + * // The operation is complete. Restart the kernel.
  7551. + * xTaskResumeAll ();
  7552. + * }
  7553. + * }
  7554. + * @endcode
  7555. + * \defgroup vTaskSuspendAll vTaskSuspendAll
  7556. + * \ingroup SchedulerControl
  7557. + */
  7558. +void vTaskSuspendAll( void );
  7559. +
  7560. +/**
  7561. + * task. h
  7562. + * @code{c}
  7563. + * BaseType_t xTaskResumeAll( void );
  7564. + * @endcode
  7565. + *
  7566. + * Resumes scheduler activity after it was suspended by a call to
  7567. + * vTaskSuspendAll().
  7568. + *
  7569. + * xTaskResumeAll() only resumes the scheduler. It does not unsuspend tasks
  7570. + * that were previously suspended by a call to vTaskSuspend().
  7571. + *
  7572. + * @return If resuming the scheduler caused a context switch then pdTRUE is
  7573. + * returned, otherwise pdFALSE is returned.
  7574. + *
  7575. + * Example usage:
  7576. + * @code{c}
  7577. + * void vTask1( void * pvParameters )
  7578. + * {
  7579. + * for( ;; )
  7580. + * {
  7581. + * // Task code goes here.
  7582. + *
  7583. + * // ...
  7584. + *
  7585. + * // At some point the task wants to perform a long operation during
  7586. + * // which it does not want to get swapped out. It cannot use
  7587. + * // taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the
  7588. + * // operation may cause interrupts to be missed - including the
  7589. + * // ticks.
  7590. + *
  7591. + * // Prevent the real time kernel swapping out the task.
  7592. + * vTaskSuspendAll ();
  7593. + *
  7594. + * // Perform the operation here. There is no need to use critical
  7595. + * // sections as we have all the microcontroller processing time.
  7596. + * // During this time interrupts will still operate and the real
  7597. + * // time kernel tick count will be maintained.
  7598. + *
  7599. + * // ...
  7600. + *
  7601. + * // The operation is complete. Restart the kernel. We want to force
  7602. + * // a context switch - but there is no point if resuming the scheduler
  7603. + * // caused a context switch already.
  7604. + * if( !xTaskResumeAll () )
  7605. + * {
  7606. + * taskYIELD ();
  7607. + * }
  7608. + * }
  7609. + * }
  7610. + * @endcode
  7611. + * \defgroup xTaskResumeAll xTaskResumeAll
  7612. + * \ingroup SchedulerControl
  7613. + */
  7614. +BaseType_t xTaskResumeAll( void );
  7615. +
  7616. +/*-----------------------------------------------------------
  7617. +* TASK UTILITIES
  7618. +*----------------------------------------------------------*/
  7619. +
  7620. +/**
  7621. + * task. h
  7622. + * @code{c}
  7623. + * TickType_t xTaskGetTickCount( void );
  7624. + * @endcode
  7625. + *
  7626. + * @return The count of ticks since vTaskStartScheduler was called.
  7627. + *
  7628. + * \defgroup xTaskGetTickCount xTaskGetTickCount
  7629. + * \ingroup TaskUtils
  7630. + */
  7631. +TickType_t xTaskGetTickCount( void );
  7632. +
  7633. +/**
  7634. + * task. h
  7635. + * @code{c}
  7636. + * TickType_t xTaskGetTickCountFromISR( void );
  7637. + * @endcode
  7638. + *
  7639. + * @return The count of ticks since vTaskStartScheduler was called.
  7640. + *
  7641. + * This is a version of xTaskGetTickCount() that is safe to be called from an
  7642. + * ISR - provided that TickType_t is the natural word size of the
  7643. + * microcontroller being used or interrupt nesting is either not supported or
  7644. + * not being used.
  7645. + *
  7646. + * \defgroup xTaskGetTickCountFromISR xTaskGetTickCountFromISR
  7647. + * \ingroup TaskUtils
  7648. + */
  7649. +TickType_t xTaskGetTickCountFromISR( void );
  7650. +
  7651. +/**
  7652. + * task. h
  7653. + * @code{c}
  7654. + * uint16_t uxTaskGetNumberOfTasks( void );
  7655. + * @endcode
  7656. + *
  7657. + * @return The number of tasks that the real time kernel is currently managing.
  7658. + * This includes all ready, blocked and suspended tasks. A task that
  7659. + * has been deleted but not yet freed by the idle task will also be
  7660. + * included in the count.
  7661. + *
  7662. + * \defgroup uxTaskGetNumberOfTasks uxTaskGetNumberOfTasks
  7663. + * \ingroup TaskUtils
  7664. + */
  7665. +UBaseType_t uxTaskGetNumberOfTasks( void );
  7666. +
  7667. +/**
  7668. + * task. h
  7669. + * @code{c}
  7670. + * char *pcTaskGetName( TaskHandle_t xTaskToQuery );
  7671. + * @endcode
  7672. + *
  7673. + * @return The text (human readable) name of the task referenced by the handle
  7674. + * xTaskToQuery. A task can query its own name by either passing in its own
  7675. + * handle, or by setting xTaskToQuery to NULL.
  7676. + *
  7677. + * \defgroup pcTaskGetName pcTaskGetName
  7678. + * \ingroup TaskUtils
  7679. + */
  7680. +char * pcTaskGetName( TaskHandle_t xTaskToQuery ); /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
  7681. +
  7682. +/**
  7683. + * task. h
  7684. + * @code{c}
  7685. + * TaskHandle_t xTaskGetHandle( const char *pcNameToQuery );
  7686. + * @endcode
  7687. + *
  7688. + * NOTE: This function takes a relatively long time to complete and should be
  7689. + * used sparingly.
  7690. + *
  7691. + * @return The handle of the task that has the human readable name pcNameToQuery.
  7692. + * NULL is returned if no matching name is found. INCLUDE_xTaskGetHandle
  7693. + * must be set to 1 in FreeRTOSConfig.h for pcTaskGetHandle() to be available.
  7694. + *
  7695. + * \defgroup pcTaskGetHandle pcTaskGetHandle
  7696. + * \ingroup TaskUtils
  7697. + */
  7698. +TaskHandle_t xTaskGetHandle( const char * pcNameToQuery ); /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
  7699. +
  7700. +/**
  7701. + * task.h
  7702. + * @code{c}
  7703. + * UBaseType_t uxTaskGetStackHighWaterMark( TaskHandle_t xTask );
  7704. + * @endcode
  7705. + *
  7706. + * INCLUDE_uxTaskGetStackHighWaterMark must be set to 1 in FreeRTOSConfig.h for
  7707. + * this function to be available.
  7708. + *
  7709. + * Returns the high water mark of the stack associated with xTask. That is,
  7710. + * the minimum free stack space there has been (in words, so on a 32 bit machine
  7711. + * a value of 1 means 4 bytes) since the task started. The smaller the returned
  7712. + * number the closer the task has come to overflowing its stack.
  7713. + *
  7714. + * uxTaskGetStackHighWaterMark() and uxTaskGetStackHighWaterMark2() are the
  7715. + * same except for their return type. Using configSTACK_DEPTH_TYPE allows the
  7716. + * user to determine the return type. It gets around the problem of the value
  7717. + * overflowing on 8-bit types without breaking backward compatibility for
  7718. + * applications that expect an 8-bit return type.
  7719. + *
  7720. + * @param xTask Handle of the task associated with the stack to be checked.
  7721. + * Set xTask to NULL to check the stack of the calling task.
  7722. + *
  7723. + * @return The smallest amount of free stack space there has been (in words, so
  7724. + * actual spaces on the stack rather than bytes) since the task referenced by
  7725. + * xTask was created.
  7726. + */
  7727. +UBaseType_t uxTaskGetStackHighWaterMark( TaskHandle_t xTask );
  7728. +
  7729. +/**
  7730. + * task.h
  7731. + * @code{c}
  7732. + * configSTACK_DEPTH_TYPE uxTaskGetStackHighWaterMark2( TaskHandle_t xTask );
  7733. + * @endcode
  7734. + *
  7735. + * INCLUDE_uxTaskGetStackHighWaterMark2 must be set to 1 in FreeRTOSConfig.h for
  7736. + * this function to be available.
  7737. + *
  7738. + * Returns the high water mark of the stack associated with xTask. That is,
  7739. + * the minimum free stack space there has been (in words, so on a 32 bit machine
  7740. + * a value of 1 means 4 bytes) since the task started. The smaller the returned
  7741. + * number the closer the task has come to overflowing its stack.
  7742. + *
  7743. + * uxTaskGetStackHighWaterMark() and uxTaskGetStackHighWaterMark2() are the
  7744. + * same except for their return type. Using configSTACK_DEPTH_TYPE allows the
  7745. + * user to determine the return type. It gets around the problem of the value
  7746. + * overflowing on 8-bit types without breaking backward compatibility for
  7747. + * applications that expect an 8-bit return type.
  7748. + *
  7749. + * @param xTask Handle of the task associated with the stack to be checked.
  7750. + * Set xTask to NULL to check the stack of the calling task.
  7751. + *
  7752. + * @return The smallest amount of free stack space there has been (in words, so
  7753. + * actual spaces on the stack rather than bytes) since the task referenced by
  7754. + * xTask was created.
  7755. + */
  7756. +configSTACK_DEPTH_TYPE uxTaskGetStackHighWaterMark2( TaskHandle_t xTask );
  7757. +
  7758. +/* When using trace macros it is sometimes necessary to include task.h before
  7759. + * FreeRTOS.h. When this is done TaskHookFunction_t will not yet have been defined,
  7760. + * so the following two prototypes will cause a compilation error. This can be
  7761. + * fixed by simply guarding against the inclusion of these two prototypes unless
  7762. + * they are explicitly required by the configUSE_APPLICATION_TASK_TAG configuration
  7763. + * constant. */
  7764. +#ifdef configUSE_APPLICATION_TASK_TAG
  7765. + #if configUSE_APPLICATION_TASK_TAG == 1
  7766. +
  7767. +/**
  7768. + * task.h
  7769. + * @code{c}
  7770. + * void vTaskSetApplicationTaskTag( TaskHandle_t xTask, TaskHookFunction_t pxHookFunction );
  7771. + * @endcode
  7772. + *
  7773. + * Sets pxHookFunction to be the task hook function used by the task xTask.
  7774. + * Passing xTask as NULL has the effect of setting the calling tasks hook
  7775. + * function.
  7776. + */
  7777. + void vTaskSetApplicationTaskTag( TaskHandle_t xTask,
  7778. + TaskHookFunction_t pxHookFunction );
  7779. +
  7780. +/**
  7781. + * task.h
  7782. + * @code{c}
  7783. + * void xTaskGetApplicationTaskTag( TaskHandle_t xTask );
  7784. + * @endcode
  7785. + *
  7786. + * Returns the pxHookFunction value assigned to the task xTask. Do not
  7787. + * call from an interrupt service routine - call
  7788. + * xTaskGetApplicationTaskTagFromISR() instead.
  7789. + */
  7790. + TaskHookFunction_t xTaskGetApplicationTaskTag( TaskHandle_t xTask );
  7791. +
  7792. +/**
  7793. + * task.h
  7794. + * @code{c}
  7795. + * void xTaskGetApplicationTaskTagFromISR( TaskHandle_t xTask );
  7796. + * @endcode
  7797. + *
  7798. + * Returns the pxHookFunction value assigned to the task xTask. Can
  7799. + * be called from an interrupt service routine.
  7800. + */
  7801. + TaskHookFunction_t xTaskGetApplicationTaskTagFromISR( TaskHandle_t xTask );
  7802. + #endif /* configUSE_APPLICATION_TASK_TAG ==1 */
  7803. +#endif /* ifdef configUSE_APPLICATION_TASK_TAG */
  7804. +
  7805. +/**
  7806. + * task.h
  7807. + * @code{c}
  7808. + * BaseType_t xTaskCallApplicationTaskHook( TaskHandle_t xTask, void *pvParameter );
  7809. + * @endcode
  7810. + *
  7811. + * Calls the hook function associated with xTask. Passing xTask as NULL has
  7812. + * the effect of calling the Running tasks (the calling task) hook function.
  7813. + *
  7814. + * pvParameter is passed to the hook function for the task to interpret as it
  7815. + * wants. The return value is the value returned by the task hook function
  7816. + * registered by the user.
  7817. + */
  7818. +BaseType_t xTaskCallApplicationTaskHook( TaskHandle_t xTask,
  7819. + void * pvParameter );
  7820. +
  7821. +/**
  7822. + * xTaskGetIdleTaskHandle() is only available if
  7823. + * INCLUDE_xTaskGetIdleTaskHandle is set to 1 in FreeRTOSConfig.h.
  7824. + *
  7825. + * Simply returns the handle of the idle task. It is not valid to call
  7826. + * xTaskGetIdleTaskHandle() before the scheduler has been started.
  7827. + */
  7828. +TaskHandle_t xTaskGetIdleTaskHandle( void );
  7829. +
  7830. +/**
  7831. + * task. h
  7832. + * @code{c}
  7833. + * BaseType_t xTaskNotifyIndexed( TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify, uint32_t ulValue, eNotifyAction eAction );
  7834. + * BaseType_t xTaskNotify( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction );
  7835. + * @endcode
  7836. + *
  7837. + * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details.
  7838. + *
  7839. + * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for these
  7840. + * functions to be available.
  7841. + *
  7842. + * Sends a direct to task notification to a task, with an optional value and
  7843. + * action.
  7844. + *
  7845. + * Each task has a private array of "notification values" (or 'notifications'),
  7846. + * each of which is a 32-bit unsigned integer (uint32_t). The constant
  7847. + * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the
  7848. + * array, and (for backward compatibility) defaults to 1 if left undefined.
  7849. + * Prior to FreeRTOS V10.4.0 there was only one notification value per task.
  7850. + *
  7851. + * Events can be sent to a task using an intermediary object. Examples of such
  7852. + * objects are queues, semaphores, mutexes and event groups. Task notifications
  7853. + * are a method of sending an event directly to a task without the need for such
  7854. + * an intermediary object.
  7855. + *
  7856. + * A notification sent to a task can optionally perform an action, such as
  7857. + * update, overwrite or increment one of the task's notification values. In
  7858. + * that way task notifications can be used to send data to a task, or be used as
  7859. + * light weight and fast binary or counting semaphores.
  7860. + *
  7861. + * A task can use xTaskNotifyWaitIndexed() or ulTaskNotifyTakeIndexed() to
  7862. + * [optionally] block to wait for a notification to be pending. The task does
  7863. + * not consume any CPU time while it is in the Blocked state.
  7864. + *
  7865. + * A notification sent to a task will remain pending until it is cleared by the
  7866. + * task calling xTaskNotifyWaitIndexed() or ulTaskNotifyTakeIndexed() (or their
  7867. + * un-indexed equivalents). If the task was already in the Blocked state to
  7868. + * wait for a notification when the notification arrives then the task will
  7869. + * automatically be removed from the Blocked state (unblocked) and the
  7870. + * notification cleared.
  7871. + *
  7872. + * **NOTE** Each notification within the array operates independently - a task
  7873. + * can only block on one notification within the array at a time and will not be
  7874. + * unblocked by a notification sent to any other array index.
  7875. + *
  7876. + * Backward compatibility information:
  7877. + * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and
  7878. + * all task notification API functions operated on that value. Replacing the
  7879. + * single notification value with an array of notification values necessitated a
  7880. + * new set of API functions that could address specific notifications within the
  7881. + * array. xTaskNotify() is the original API function, and remains backward
  7882. + * compatible by always operating on the notification value at index 0 in the
  7883. + * array. Calling xTaskNotify() is equivalent to calling xTaskNotifyIndexed()
  7884. + * with the uxIndexToNotify parameter set to 0.
  7885. + *
  7886. + * @param xTaskToNotify The handle of the task being notified. The handle to a
  7887. + * task can be returned from the xTaskCreate() API function used to create the
  7888. + * task, and the handle of the currently running task can be obtained by calling
  7889. + * xTaskGetCurrentTaskHandle().
  7890. + *
  7891. + * @param uxIndexToNotify The index within the target task's array of
  7892. + * notification values to which the notification is to be sent. uxIndexToNotify
  7893. + * must be less than configTASK_NOTIFICATION_ARRAY_ENTRIES. xTaskNotify() does
  7894. + * not have this parameter and always sends notifications to index 0.
  7895. + *
  7896. + * @param ulValue Data that can be sent with the notification. How the data is
  7897. + * used depends on the value of the eAction parameter.
  7898. + *
  7899. + * @param eAction Specifies how the notification updates the task's notification
  7900. + * value, if at all. Valid values for eAction are as follows:
  7901. + *
  7902. + * eSetBits -
  7903. + * The target notification value is bitwise ORed with ulValue.
  7904. + * xTaskNotifyIndexed() always returns pdPASS in this case.
  7905. + *
  7906. + * eIncrement -
  7907. + * The target notification value is incremented. ulValue is not used and
  7908. + * xTaskNotifyIndexed() always returns pdPASS in this case.
  7909. + *
  7910. + * eSetValueWithOverwrite -
  7911. + * The target notification value is set to the value of ulValue, even if the
  7912. + * task being notified had not yet processed the previous notification at the
  7913. + * same array index (the task already had a notification pending at that index).
  7914. + * xTaskNotifyIndexed() always returns pdPASS in this case.
  7915. + *
  7916. + * eSetValueWithoutOverwrite -
  7917. + * If the task being notified did not already have a notification pending at the
  7918. + * same array index then the target notification value is set to ulValue and
  7919. + * xTaskNotifyIndexed() will return pdPASS. If the task being notified already
  7920. + * had a notification pending at the same array index then no action is
  7921. + * performed and pdFAIL is returned.
  7922. + *
  7923. + * eNoAction -
  7924. + * The task receives a notification at the specified array index without the
  7925. + * notification value at that index being updated. ulValue is not used and
  7926. + * xTaskNotifyIndexed() always returns pdPASS in this case.
  7927. + *
  7928. + * pulPreviousNotificationValue -
  7929. + * Can be used to pass out the subject task's notification value before any
  7930. + * bits are modified by the notify function.
  7931. + *
  7932. + * @return Dependent on the value of eAction. See the description of the
  7933. + * eAction parameter.
  7934. + *
  7935. + * \defgroup xTaskNotifyIndexed xTaskNotifyIndexed
  7936. + * \ingroup TaskNotifications
  7937. + */
  7938. +BaseType_t xTaskGenericNotify( TaskHandle_t xTaskToNotify,
  7939. + UBaseType_t uxIndexToNotify,
  7940. + uint32_t ulValue,
  7941. + eNotifyAction eAction,
  7942. + uint32_t * pulPreviousNotificationValue );
  7943. +#define xTaskNotify( xTaskToNotify, ulValue, eAction ) \
  7944. + xTaskGenericNotify( ( xTaskToNotify ), ( tskDEFAULT_INDEX_TO_NOTIFY ), ( ulValue ), ( eAction ), NULL )
  7945. +#define xTaskNotifyIndexed( xTaskToNotify, uxIndexToNotify, ulValue, eAction ) \
  7946. + xTaskGenericNotify( ( xTaskToNotify ), ( uxIndexToNotify ), ( ulValue ), ( eAction ), NULL )
  7947. +
  7948. +/**
  7949. + * task. h
  7950. + * @code{c}
  7951. + * BaseType_t xTaskNotifyAndQueryIndexed( TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotifyValue );
  7952. + * BaseType_t xTaskNotifyAndQuery( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotifyValue );
  7953. + * @endcode
  7954. + *
  7955. + * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details.
  7956. + *
  7957. + * xTaskNotifyAndQueryIndexed() performs the same operation as
  7958. + * xTaskNotifyIndexed() with the addition that it also returns the subject
  7959. + * task's prior notification value (the notification value at the time the
  7960. + * function is called rather than when the function returns) in the additional
  7961. + * pulPreviousNotifyValue parameter.
  7962. + *
  7963. + * xTaskNotifyAndQuery() performs the same operation as xTaskNotify() with the
  7964. + * addition that it also returns the subject task's prior notification value
  7965. + * (the notification value as it was at the time the function is called, rather
  7966. + * than when the function returns) in the additional pulPreviousNotifyValue
  7967. + * parameter.
  7968. + *
  7969. + * \defgroup xTaskNotifyAndQueryIndexed xTaskNotifyAndQueryIndexed
  7970. + * \ingroup TaskNotifications
  7971. + */
  7972. +#define xTaskNotifyAndQuery( xTaskToNotify, ulValue, eAction, pulPreviousNotifyValue ) \
  7973. + xTaskGenericNotify( ( xTaskToNotify ), ( tskDEFAULT_INDEX_TO_NOTIFY ), ( ulValue ), ( eAction ), ( pulPreviousNotifyValue ) )
  7974. +#define xTaskNotifyAndQueryIndexed( xTaskToNotify, uxIndexToNotify, ulValue, eAction, pulPreviousNotifyValue ) \
  7975. + xTaskGenericNotify( ( xTaskToNotify ), ( uxIndexToNotify ), ( ulValue ), ( eAction ), ( pulPreviousNotifyValue ) )
  7976. +
  7977. +/**
  7978. + * task. h
  7979. + * @code{c}
  7980. + * BaseType_t xTaskNotifyIndexedFromISR( TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify, uint32_t ulValue, eNotifyAction eAction, BaseType_t *pxHigherPriorityTaskWoken );
  7981. + * BaseType_t xTaskNotifyFromISR( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, BaseType_t *pxHigherPriorityTaskWoken );
  7982. + * @endcode
  7983. + *
  7984. + * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details.
  7985. + *
  7986. + * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for these
  7987. + * functions to be available.
  7988. + *
  7989. + * A version of xTaskNotifyIndexed() that can be used from an interrupt service
  7990. + * routine (ISR).
  7991. + *
  7992. + * Each task has a private array of "notification values" (or 'notifications'),
  7993. + * each of which is a 32-bit unsigned integer (uint32_t). The constant
  7994. + * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the
  7995. + * array, and (for backward compatibility) defaults to 1 if left undefined.
  7996. + * Prior to FreeRTOS V10.4.0 there was only one notification value per task.
  7997. + *
  7998. + * Events can be sent to a task using an intermediary object. Examples of such
  7999. + * objects are queues, semaphores, mutexes and event groups. Task notifications
  8000. + * are a method of sending an event directly to a task without the need for such
  8001. + * an intermediary object.
  8002. + *
  8003. + * A notification sent to a task can optionally perform an action, such as
  8004. + * update, overwrite or increment one of the task's notification values. In
  8005. + * that way task notifications can be used to send data to a task, or be used as
  8006. + * light weight and fast binary or counting semaphores.
  8007. + *
  8008. + * A task can use xTaskNotifyWaitIndexed() to [optionally] block to wait for a
  8009. + * notification to be pending, or ulTaskNotifyTakeIndexed() to [optionally] block
  8010. + * to wait for a notification value to have a non-zero value. The task does
  8011. + * not consume any CPU time while it is in the Blocked state.
  8012. + *
  8013. + * A notification sent to a task will remain pending until it is cleared by the
  8014. + * task calling xTaskNotifyWaitIndexed() or ulTaskNotifyTakeIndexed() (or their
  8015. + * un-indexed equivalents). If the task was already in the Blocked state to
  8016. + * wait for a notification when the notification arrives then the task will
  8017. + * automatically be removed from the Blocked state (unblocked) and the
  8018. + * notification cleared.
  8019. + *
  8020. + * **NOTE** Each notification within the array operates independently - a task
  8021. + * can only block on one notification within the array at a time and will not be
  8022. + * unblocked by a notification sent to any other array index.
  8023. + *
  8024. + * Backward compatibility information:
  8025. + * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and
  8026. + * all task notification API functions operated on that value. Replacing the
  8027. + * single notification value with an array of notification values necessitated a
  8028. + * new set of API functions that could address specific notifications within the
  8029. + * array. xTaskNotifyFromISR() is the original API function, and remains
  8030. + * backward compatible by always operating on the notification value at index 0
  8031. + * within the array. Calling xTaskNotifyFromISR() is equivalent to calling
  8032. + * xTaskNotifyIndexedFromISR() with the uxIndexToNotify parameter set to 0.
  8033. + *
  8034. + * @param uxIndexToNotify The index within the target task's array of
  8035. + * notification values to which the notification is to be sent. uxIndexToNotify
  8036. + * must be less than configTASK_NOTIFICATION_ARRAY_ENTRIES. xTaskNotifyFromISR()
  8037. + * does not have this parameter and always sends notifications to index 0.
  8038. + *
  8039. + * @param xTaskToNotify The handle of the task being notified. The handle to a
  8040. + * task can be returned from the xTaskCreate() API function used to create the
  8041. + * task, and the handle of the currently running task can be obtained by calling
  8042. + * xTaskGetCurrentTaskHandle().
  8043. + *
  8044. + * @param ulValue Data that can be sent with the notification. How the data is
  8045. + * used depends on the value of the eAction parameter.
  8046. + *
  8047. + * @param eAction Specifies how the notification updates the task's notification
  8048. + * value, if at all. Valid values for eAction are as follows:
  8049. + *
  8050. + * eSetBits -
  8051. + * The task's notification value is bitwise ORed with ulValue. xTaskNotify()
  8052. + * always returns pdPASS in this case.
  8053. + *
  8054. + * eIncrement -
  8055. + * The task's notification value is incremented. ulValue is not used and
  8056. + * xTaskNotify() always returns pdPASS in this case.
  8057. + *
  8058. + * eSetValueWithOverwrite -
  8059. + * The task's notification value is set to the value of ulValue, even if the
  8060. + * task being notified had not yet processed the previous notification (the
  8061. + * task already had a notification pending). xTaskNotify() always returns
  8062. + * pdPASS in this case.
  8063. + *
  8064. + * eSetValueWithoutOverwrite -
  8065. + * If the task being notified did not already have a notification pending then
  8066. + * the task's notification value is set to ulValue and xTaskNotify() will
  8067. + * return pdPASS. If the task being notified already had a notification
  8068. + * pending then no action is performed and pdFAIL is returned.
  8069. + *
  8070. + * eNoAction -
  8071. + * The task receives a notification without its notification value being
  8072. + * updated. ulValue is not used and xTaskNotify() always returns pdPASS in
  8073. + * this case.
  8074. + *
  8075. + * @param pxHigherPriorityTaskWoken xTaskNotifyFromISR() will set
  8076. + * *pxHigherPriorityTaskWoken to pdTRUE if sending the notification caused the
  8077. + * task to which the notification was sent to leave the Blocked state, and the
  8078. + * unblocked task has a priority higher than the currently running task. If
  8079. + * xTaskNotifyFromISR() sets this value to pdTRUE then a context switch should
  8080. + * be requested before the interrupt is exited. How a context switch is
  8081. + * requested from an ISR is dependent on the port - see the documentation page
  8082. + * for the port in use.
  8083. + *
  8084. + * @return Dependent on the value of eAction. See the description of the
  8085. + * eAction parameter.
  8086. + *
  8087. + * \defgroup xTaskNotifyIndexedFromISR xTaskNotifyIndexedFromISR
  8088. + * \ingroup TaskNotifications
  8089. + */
  8090. +BaseType_t xTaskGenericNotifyFromISR( TaskHandle_t xTaskToNotify,
  8091. + UBaseType_t uxIndexToNotify,
  8092. + uint32_t ulValue,
  8093. + eNotifyAction eAction,
  8094. + uint32_t * pulPreviousNotificationValue,
  8095. + BaseType_t * pxHigherPriorityTaskWoken );
  8096. +#define xTaskNotifyFromISR( xTaskToNotify, ulValue, eAction, pxHigherPriorityTaskWoken ) \
  8097. + xTaskGenericNotifyFromISR( ( xTaskToNotify ), ( tskDEFAULT_INDEX_TO_NOTIFY ), ( ulValue ), ( eAction ), NULL, ( pxHigherPriorityTaskWoken ) )
  8098. +#define xTaskNotifyIndexedFromISR( xTaskToNotify, uxIndexToNotify, ulValue, eAction, pxHigherPriorityTaskWoken ) \
  8099. + xTaskGenericNotifyFromISR( ( xTaskToNotify ), ( uxIndexToNotify ), ( ulValue ), ( eAction ), NULL, ( pxHigherPriorityTaskWoken ) )
  8100. +
  8101. +/**
  8102. + * task. h
  8103. + * @code{c}
  8104. + * BaseType_t xTaskNotifyAndQueryIndexedFromISR( TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotificationValue, BaseType_t *pxHigherPriorityTaskWoken );
  8105. + * BaseType_t xTaskNotifyAndQueryFromISR( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotificationValue, BaseType_t *pxHigherPriorityTaskWoken );
  8106. + * @endcode
  8107. + *
  8108. + * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details.
  8109. + *
  8110. + * xTaskNotifyAndQueryIndexedFromISR() performs the same operation as
  8111. + * xTaskNotifyIndexedFromISR() with the addition that it also returns the
  8112. + * subject task's prior notification value (the notification value at the time
  8113. + * the function is called rather than at the time the function returns) in the
  8114. + * additional pulPreviousNotifyValue parameter.
  8115. + *
  8116. + * xTaskNotifyAndQueryFromISR() performs the same operation as
  8117. + * xTaskNotifyFromISR() with the addition that it also returns the subject
  8118. + * task's prior notification value (the notification value at the time the
  8119. + * function is called rather than at the time the function returns) in the
  8120. + * additional pulPreviousNotifyValue parameter.
  8121. + *
  8122. + * \defgroup xTaskNotifyAndQueryIndexedFromISR xTaskNotifyAndQueryIndexedFromISR
  8123. + * \ingroup TaskNotifications
  8124. + */
  8125. +#define xTaskNotifyAndQueryIndexedFromISR( xTaskToNotify, uxIndexToNotify, ulValue, eAction, pulPreviousNotificationValue, pxHigherPriorityTaskWoken ) \
  8126. + xTaskGenericNotifyFromISR( ( xTaskToNotify ), ( uxIndexToNotify ), ( ulValue ), ( eAction ), ( pulPreviousNotificationValue ), ( pxHigherPriorityTaskWoken ) )
  8127. +#define xTaskNotifyAndQueryFromISR( xTaskToNotify, ulValue, eAction, pulPreviousNotificationValue, pxHigherPriorityTaskWoken ) \
  8128. + xTaskGenericNotifyFromISR( ( xTaskToNotify ), ( tskDEFAULT_INDEX_TO_NOTIFY ), ( ulValue ), ( eAction ), ( pulPreviousNotificationValue ), ( pxHigherPriorityTaskWoken ) )
  8129. +
  8130. +/**
  8131. + * task. h
  8132. + * @code{c}
  8133. + * BaseType_t xTaskNotifyWaitIndexed( UBaseType_t uxIndexToWaitOn, uint32_t ulBitsToClearOnEntry, uint32_t ulBitsToClearOnExit, uint32_t *pulNotificationValue, TickType_t xTicksToWait );
  8134. + *
  8135. + * BaseType_t xTaskNotifyWait( uint32_t ulBitsToClearOnEntry, uint32_t ulBitsToClearOnExit, uint32_t *pulNotificationValue, TickType_t xTicksToWait );
  8136. + * @endcode
  8137. + *
  8138. + * Waits for a direct to task notification to be pending at a given index within
  8139. + * an array of direct to task notifications.
  8140. + *
  8141. + * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details.
  8142. + *
  8143. + * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this
  8144. + * function to be available.
  8145. + *
  8146. + * Each task has a private array of "notification values" (or 'notifications'),
  8147. + * each of which is a 32-bit unsigned integer (uint32_t). The constant
  8148. + * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the
  8149. + * array, and (for backward compatibility) defaults to 1 if left undefined.
  8150. + * Prior to FreeRTOS V10.4.0 there was only one notification value per task.
  8151. + *
  8152. + * Events can be sent to a task using an intermediary object. Examples of such
  8153. + * objects are queues, semaphores, mutexes and event groups. Task notifications
  8154. + * are a method of sending an event directly to a task without the need for such
  8155. + * an intermediary object.
  8156. + *
  8157. + * A notification sent to a task can optionally perform an action, such as
  8158. + * update, overwrite or increment one of the task's notification values. In
  8159. + * that way task notifications can be used to send data to a task, or be used as
  8160. + * light weight and fast binary or counting semaphores.
  8161. + *
  8162. + * A notification sent to a task will remain pending until it is cleared by the
  8163. + * task calling xTaskNotifyWaitIndexed() or ulTaskNotifyTakeIndexed() (or their
  8164. + * un-indexed equivalents). If the task was already in the Blocked state to
  8165. + * wait for a notification when the notification arrives then the task will
  8166. + * automatically be removed from the Blocked state (unblocked) and the
  8167. + * notification cleared.
  8168. + *
  8169. + * A task can use xTaskNotifyWaitIndexed() to [optionally] block to wait for a
  8170. + * notification to be pending, or ulTaskNotifyTakeIndexed() to [optionally] block
  8171. + * to wait for a notification value to have a non-zero value. The task does
  8172. + * not consume any CPU time while it is in the Blocked state.
  8173. + *
  8174. + * **NOTE** Each notification within the array operates independently - a task
  8175. + * can only block on one notification within the array at a time and will not be
  8176. + * unblocked by a notification sent to any other array index.
  8177. + *
  8178. + * Backward compatibility information:
  8179. + * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and
  8180. + * all task notification API functions operated on that value. Replacing the
  8181. + * single notification value with an array of notification values necessitated a
  8182. + * new set of API functions that could address specific notifications within the
  8183. + * array. xTaskNotifyWait() is the original API function, and remains backward
  8184. + * compatible by always operating on the notification value at index 0 in the
  8185. + * array. Calling xTaskNotifyWait() is equivalent to calling
  8186. + * xTaskNotifyWaitIndexed() with the uxIndexToWaitOn parameter set to 0.
  8187. + *
  8188. + * @param uxIndexToWaitOn The index within the calling task's array of
  8189. + * notification values on which the calling task will wait for a notification to
  8190. + * be received. uxIndexToWaitOn must be less than
  8191. + * configTASK_NOTIFICATION_ARRAY_ENTRIES. xTaskNotifyWait() does
  8192. + * not have this parameter and always waits for notifications on index 0.
  8193. + *
  8194. + * @param ulBitsToClearOnEntry Bits that are set in ulBitsToClearOnEntry value
  8195. + * will be cleared in the calling task's notification value before the task
  8196. + * checks to see if any notifications are pending, and optionally blocks if no
  8197. + * notifications are pending. Setting ulBitsToClearOnEntry to ULONG_MAX (if
  8198. + * limits.h is included) or 0xffffffffUL (if limits.h is not included) will have
  8199. + * the effect of resetting the task's notification value to 0. Setting
  8200. + * ulBitsToClearOnEntry to 0 will leave the task's notification value unchanged.
  8201. + *
  8202. + * @param ulBitsToClearOnExit If a notification is pending or received before
  8203. + * the calling task exits the xTaskNotifyWait() function then the task's
  8204. + * notification value (see the xTaskNotify() API function) is passed out using
  8205. + * the pulNotificationValue parameter. Then any bits that are set in
  8206. + * ulBitsToClearOnExit will be cleared in the task's notification value (note
  8207. + * *pulNotificationValue is set before any bits are cleared). Setting
  8208. + * ulBitsToClearOnExit to ULONG_MAX (if limits.h is included) or 0xffffffffUL
  8209. + * (if limits.h is not included) will have the effect of resetting the task's
  8210. + * notification value to 0 before the function exits. Setting
  8211. + * ulBitsToClearOnExit to 0 will leave the task's notification value unchanged
  8212. + * when the function exits (in which case the value passed out in
  8213. + * pulNotificationValue will match the task's notification value).
  8214. + *
  8215. + * @param pulNotificationValue Used to pass the task's notification value out
  8216. + * of the function. Note the value passed out will not be effected by the
  8217. + * clearing of any bits caused by ulBitsToClearOnExit being non-zero.
  8218. + *
  8219. + * @param xTicksToWait The maximum amount of time that the task should wait in
  8220. + * the Blocked state for a notification to be received, should a notification
  8221. + * not already be pending when xTaskNotifyWait() was called. The task
  8222. + * will not consume any processing time while it is in the Blocked state. This
  8223. + * is specified in kernel ticks, the macro pdMS_TO_TICKS( value_in_ms ) can be
  8224. + * used to convert a time specified in milliseconds to a time specified in
  8225. + * ticks.
  8226. + *
  8227. + * @return If a notification was received (including notifications that were
  8228. + * already pending when xTaskNotifyWait was called) then pdPASS is
  8229. + * returned. Otherwise pdFAIL is returned.
  8230. + *
  8231. + * \defgroup xTaskNotifyWaitIndexed xTaskNotifyWaitIndexed
  8232. + * \ingroup TaskNotifications
  8233. + */
  8234. +BaseType_t xTaskGenericNotifyWait( UBaseType_t uxIndexToWaitOn,
  8235. + uint32_t ulBitsToClearOnEntry,
  8236. + uint32_t ulBitsToClearOnExit,
  8237. + uint32_t * pulNotificationValue,
  8238. + TickType_t xTicksToWait );
  8239. +#define xTaskNotifyWait( ulBitsToClearOnEntry, ulBitsToClearOnExit, pulNotificationValue, xTicksToWait ) \
  8240. + xTaskGenericNotifyWait( tskDEFAULT_INDEX_TO_NOTIFY, ( ulBitsToClearOnEntry ), ( ulBitsToClearOnExit ), ( pulNotificationValue ), ( xTicksToWait ) )
  8241. +#define xTaskNotifyWaitIndexed( uxIndexToWaitOn, ulBitsToClearOnEntry, ulBitsToClearOnExit, pulNotificationValue, xTicksToWait ) \
  8242. + xTaskGenericNotifyWait( ( uxIndexToWaitOn ), ( ulBitsToClearOnEntry ), ( ulBitsToClearOnExit ), ( pulNotificationValue ), ( xTicksToWait ) )
  8243. +
  8244. +/**
  8245. + * task. h
  8246. + * @code{c}
  8247. + * BaseType_t xTaskNotifyGiveIndexed( TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify );
  8248. + * BaseType_t xTaskNotifyGive( TaskHandle_t xTaskToNotify );
  8249. + * @endcode
  8250. + *
  8251. + * Sends a direct to task notification to a particular index in the target
  8252. + * task's notification array in a manner similar to giving a counting semaphore.
  8253. + *
  8254. + * See https://www.FreeRTOS.org/RTOS-task-notifications.html for more details.
  8255. + *
  8256. + * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for these
  8257. + * macros to be available.
  8258. + *
  8259. + * Each task has a private array of "notification values" (or 'notifications'),
  8260. + * each of which is a 32-bit unsigned integer (uint32_t). The constant
  8261. + * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the
  8262. + * array, and (for backward compatibility) defaults to 1 if left undefined.
  8263. + * Prior to FreeRTOS V10.4.0 there was only one notification value per task.
  8264. + *
  8265. + * Events can be sent to a task using an intermediary object. Examples of such
  8266. + * objects are queues, semaphores, mutexes and event groups. Task notifications
  8267. + * are a method of sending an event directly to a task without the need for such
  8268. + * an intermediary object.
  8269. + *
  8270. + * A notification sent to a task can optionally perform an action, such as
  8271. + * update, overwrite or increment one of the task's notification values. In
  8272. + * that way task notifications can be used to send data to a task, or be used as
  8273. + * light weight and fast binary or counting semaphores.
  8274. + *
  8275. + * xTaskNotifyGiveIndexed() is a helper macro intended for use when task
  8276. + * notifications are used as light weight and faster binary or counting
  8277. + * semaphore equivalents. Actual FreeRTOS semaphores are given using the
  8278. + * xSemaphoreGive() API function, the equivalent action that instead uses a task
  8279. + * notification is xTaskNotifyGiveIndexed().
  8280. + *
  8281. + * When task notifications are being used as a binary or counting semaphore
  8282. + * equivalent then the task being notified should wait for the notification
  8283. + * using the ulTaskNotificationTakeIndexed() API function rather than the
  8284. + * xTaskNotifyWaitIndexed() API function.
  8285. + *
  8286. + * **NOTE** Each notification within the array operates independently - a task
  8287. + * can only block on one notification within the array at a time and will not be
  8288. + * unblocked by a notification sent to any other array index.
  8289. + *
  8290. + * Backward compatibility information:
  8291. + * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and
  8292. + * all task notification API functions operated on that value. Replacing the
  8293. + * single notification value with an array of notification values necessitated a
  8294. + * new set of API functions that could address specific notifications within the
  8295. + * array. xTaskNotifyGive() is the original API function, and remains backward
  8296. + * compatible by always operating on the notification value at index 0 in the
  8297. + * array. Calling xTaskNotifyGive() is equivalent to calling
  8298. + * xTaskNotifyGiveIndexed() with the uxIndexToNotify parameter set to 0.
  8299. + *
  8300. + * @param xTaskToNotify The handle of the task being notified. The handle to a
  8301. + * task can be returned from the xTaskCreate() API function used to create the
  8302. + * task, and the handle of the currently running task can be obtained by calling
  8303. + * xTaskGetCurrentTaskHandle().
  8304. + *
  8305. + * @param uxIndexToNotify The index within the target task's array of
  8306. + * notification values to which the notification is to be sent. uxIndexToNotify
  8307. + * must be less than configTASK_NOTIFICATION_ARRAY_ENTRIES. xTaskNotifyGive()
  8308. + * does not have this parameter and always sends notifications to index 0.
  8309. + *
  8310. + * @return xTaskNotifyGive() is a macro that calls xTaskNotify() with the
  8311. + * eAction parameter set to eIncrement - so pdPASS is always returned.
  8312. + *
  8313. + * \defgroup xTaskNotifyGiveIndexed xTaskNotifyGiveIndexed
  8314. + * \ingroup TaskNotifications
  8315. + */
  8316. +#define xTaskNotifyGive( xTaskToNotify ) \
  8317. + xTaskGenericNotify( ( xTaskToNotify ), ( tskDEFAULT_INDEX_TO_NOTIFY ), ( 0 ), eIncrement, NULL )
  8318. +#define xTaskNotifyGiveIndexed( xTaskToNotify, uxIndexToNotify ) \
  8319. + xTaskGenericNotify( ( xTaskToNotify ), ( uxIndexToNotify ), ( 0 ), eIncrement, NULL )
  8320. +
  8321. +/**
  8322. + * task. h
  8323. + * @code{c}
  8324. + * void vTaskNotifyGiveIndexedFromISR( TaskHandle_t xTaskHandle, UBaseType_t uxIndexToNotify, BaseType_t *pxHigherPriorityTaskWoken );
  8325. + * void vTaskNotifyGiveFromISR( TaskHandle_t xTaskHandle, BaseType_t *pxHigherPriorityTaskWoken );
  8326. + * @endcode
  8327. + *
  8328. + * A version of xTaskNotifyGiveIndexed() that can be called from an interrupt
  8329. + * service routine (ISR).
  8330. + *
  8331. + * See https://www.FreeRTOS.org/RTOS-task-notifications.html for more details.
  8332. + *
  8333. + * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this macro
  8334. + * to be available.
  8335. + *
  8336. + * Each task has a private array of "notification values" (or 'notifications'),
  8337. + * each of which is a 32-bit unsigned integer (uint32_t). The constant
  8338. + * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the
  8339. + * array, and (for backward compatibility) defaults to 1 if left undefined.
  8340. + * Prior to FreeRTOS V10.4.0 there was only one notification value per task.
  8341. + *
  8342. + * Events can be sent to a task using an intermediary object. Examples of such
  8343. + * objects are queues, semaphores, mutexes and event groups. Task notifications
  8344. + * are a method of sending an event directly to a task without the need for such
  8345. + * an intermediary object.
  8346. + *
  8347. + * A notification sent to a task can optionally perform an action, such as
  8348. + * update, overwrite or increment one of the task's notification values. In
  8349. + * that way task notifications can be used to send data to a task, or be used as
  8350. + * light weight and fast binary or counting semaphores.
  8351. + *
  8352. + * vTaskNotifyGiveIndexedFromISR() is intended for use when task notifications
  8353. + * are used as light weight and faster binary or counting semaphore equivalents.
  8354. + * Actual FreeRTOS semaphores are given from an ISR using the
  8355. + * xSemaphoreGiveFromISR() API function, the equivalent action that instead uses
  8356. + * a task notification is vTaskNotifyGiveIndexedFromISR().
  8357. + *
  8358. + * When task notifications are being used as a binary or counting semaphore
  8359. + * equivalent then the task being notified should wait for the notification
  8360. + * using the ulTaskNotificationTakeIndexed() API function rather than the
  8361. + * xTaskNotifyWaitIndexed() API function.
  8362. + *
  8363. + * **NOTE** Each notification within the array operates independently - a task
  8364. + * can only block on one notification within the array at a time and will not be
  8365. + * unblocked by a notification sent to any other array index.
  8366. + *
  8367. + * Backward compatibility information:
  8368. + * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and
  8369. + * all task notification API functions operated on that value. Replacing the
  8370. + * single notification value with an array of notification values necessitated a
  8371. + * new set of API functions that could address specific notifications within the
  8372. + * array. xTaskNotifyFromISR() is the original API function, and remains
  8373. + * backward compatible by always operating on the notification value at index 0
  8374. + * within the array. Calling xTaskNotifyGiveFromISR() is equivalent to calling
  8375. + * xTaskNotifyGiveIndexedFromISR() with the uxIndexToNotify parameter set to 0.
  8376. + *
  8377. + * @param xTaskToNotify The handle of the task being notified. The handle to a
  8378. + * task can be returned from the xTaskCreate() API function used to create the
  8379. + * task, and the handle of the currently running task can be obtained by calling
  8380. + * xTaskGetCurrentTaskHandle().
  8381. + *
  8382. + * @param uxIndexToNotify The index within the target task's array of
  8383. + * notification values to which the notification is to be sent. uxIndexToNotify
  8384. + * must be less than configTASK_NOTIFICATION_ARRAY_ENTRIES.
  8385. + * xTaskNotifyGiveFromISR() does not have this parameter and always sends
  8386. + * notifications to index 0.
  8387. + *
  8388. + * @param pxHigherPriorityTaskWoken vTaskNotifyGiveFromISR() will set
  8389. + * *pxHigherPriorityTaskWoken to pdTRUE if sending the notification caused the
  8390. + * task to which the notification was sent to leave the Blocked state, and the
  8391. + * unblocked task has a priority higher than the currently running task. If
  8392. + * vTaskNotifyGiveFromISR() sets this value to pdTRUE then a context switch
  8393. + * should be requested before the interrupt is exited. How a context switch is
  8394. + * requested from an ISR is dependent on the port - see the documentation page
  8395. + * for the port in use.
  8396. + *
  8397. + * \defgroup vTaskNotifyGiveIndexedFromISR vTaskNotifyGiveIndexedFromISR
  8398. + * \ingroup TaskNotifications
  8399. + */
  8400. +void vTaskGenericNotifyGiveFromISR( TaskHandle_t xTaskToNotify,
  8401. + UBaseType_t uxIndexToNotify,
  8402. + BaseType_t * pxHigherPriorityTaskWoken );
  8403. +#define vTaskNotifyGiveFromISR( xTaskToNotify, pxHigherPriorityTaskWoken ) \
  8404. + vTaskGenericNotifyGiveFromISR( ( xTaskToNotify ), ( tskDEFAULT_INDEX_TO_NOTIFY ), ( pxHigherPriorityTaskWoken ) );
  8405. +#define vTaskNotifyGiveIndexedFromISR( xTaskToNotify, uxIndexToNotify, pxHigherPriorityTaskWoken ) \
  8406. + vTaskGenericNotifyGiveFromISR( ( xTaskToNotify ), ( uxIndexToNotify ), ( pxHigherPriorityTaskWoken ) );
  8407. +
  8408. +/**
  8409. + * task. h
  8410. + * @code{c}
  8411. + * uint32_t ulTaskNotifyTakeIndexed( UBaseType_t uxIndexToWaitOn, BaseType_t xClearCountOnExit, TickType_t xTicksToWait );
  8412. + *
  8413. + * uint32_t ulTaskNotifyTake( BaseType_t xClearCountOnExit, TickType_t xTicksToWait );
  8414. + * @endcode
  8415. + *
  8416. + * Waits for a direct to task notification on a particular index in the calling
  8417. + * task's notification array in a manner similar to taking a counting semaphore.
  8418. + *
  8419. + * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details.
  8420. + *
  8421. + * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this
  8422. + * function to be available.
  8423. + *
  8424. + * Each task has a private array of "notification values" (or 'notifications'),
  8425. + * each of which is a 32-bit unsigned integer (uint32_t). The constant
  8426. + * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the
  8427. + * array, and (for backward compatibility) defaults to 1 if left undefined.
  8428. + * Prior to FreeRTOS V10.4.0 there was only one notification value per task.
  8429. + *
  8430. + * Events can be sent to a task using an intermediary object. Examples of such
  8431. + * objects are queues, semaphores, mutexes and event groups. Task notifications
  8432. + * are a method of sending an event directly to a task without the need for such
  8433. + * an intermediary object.
  8434. + *
  8435. + * A notification sent to a task can optionally perform an action, such as
  8436. + * update, overwrite or increment one of the task's notification values. In
  8437. + * that way task notifications can be used to send data to a task, or be used as
  8438. + * light weight and fast binary or counting semaphores.
  8439. + *
  8440. + * ulTaskNotifyTakeIndexed() is intended for use when a task notification is
  8441. + * used as a faster and lighter weight binary or counting semaphore alternative.
  8442. + * Actual FreeRTOS semaphores are taken using the xSemaphoreTake() API function,
  8443. + * the equivalent action that instead uses a task notification is
  8444. + * ulTaskNotifyTakeIndexed().
  8445. + *
  8446. + * When a task is using its notification value as a binary or counting semaphore
  8447. + * other tasks should send notifications to it using the xTaskNotifyGiveIndexed()
  8448. + * macro, or xTaskNotifyIndex() function with the eAction parameter set to
  8449. + * eIncrement.
  8450. + *
  8451. + * ulTaskNotifyTakeIndexed() can either clear the task's notification value at
  8452. + * the array index specified by the uxIndexToWaitOn parameter to zero on exit,
  8453. + * in which case the notification value acts like a binary semaphore, or
  8454. + * decrement the notification value on exit, in which case the notification
  8455. + * value acts like a counting semaphore.
  8456. + *
  8457. + * A task can use ulTaskNotifyTakeIndexed() to [optionally] block to wait for
  8458. + * a notification. The task does not consume any CPU time while it is in the
  8459. + * Blocked state.
  8460. + *
  8461. + * Where as xTaskNotifyWaitIndexed() will return when a notification is pending,
  8462. + * ulTaskNotifyTakeIndexed() will return when the task's notification value is
  8463. + * not zero.
  8464. + *
  8465. + * **NOTE** Each notification within the array operates independently - a task
  8466. + * can only block on one notification within the array at a time and will not be
  8467. + * unblocked by a notification sent to any other array index.
  8468. + *
  8469. + * Backward compatibility information:
  8470. + * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and
  8471. + * all task notification API functions operated on that value. Replacing the
  8472. + * single notification value with an array of notification values necessitated a
  8473. + * new set of API functions that could address specific notifications within the
  8474. + * array. ulTaskNotifyTake() is the original API function, and remains backward
  8475. + * compatible by always operating on the notification value at index 0 in the
  8476. + * array. Calling ulTaskNotifyTake() is equivalent to calling
  8477. + * ulTaskNotifyTakeIndexed() with the uxIndexToWaitOn parameter set to 0.
  8478. + *
  8479. + * @param uxIndexToWaitOn The index within the calling task's array of
  8480. + * notification values on which the calling task will wait for a notification to
  8481. + * be non-zero. uxIndexToWaitOn must be less than
  8482. + * configTASK_NOTIFICATION_ARRAY_ENTRIES. xTaskNotifyTake() does
  8483. + * not have this parameter and always waits for notifications on index 0.
  8484. + *
  8485. + * @param xClearCountOnExit if xClearCountOnExit is pdFALSE then the task's
  8486. + * notification value is decremented when the function exits. In this way the
  8487. + * notification value acts like a counting semaphore. If xClearCountOnExit is
  8488. + * not pdFALSE then the task's notification value is cleared to zero when the
  8489. + * function exits. In this way the notification value acts like a binary
  8490. + * semaphore.
  8491. + *
  8492. + * @param xTicksToWait The maximum amount of time that the task should wait in
  8493. + * the Blocked state for the task's notification value to be greater than zero,
  8494. + * should the count not already be greater than zero when
  8495. + * ulTaskNotifyTake() was called. The task will not consume any processing
  8496. + * time while it is in the Blocked state. This is specified in kernel ticks,
  8497. + * the macro pdMS_TO_TICKS( value_in_ms ) can be used to convert a time
  8498. + * specified in milliseconds to a time specified in ticks.
  8499. + *
  8500. + * @return The task's notification count before it is either cleared to zero or
  8501. + * decremented (see the xClearCountOnExit parameter).
  8502. + *
  8503. + * \defgroup ulTaskNotifyTakeIndexed ulTaskNotifyTakeIndexed
  8504. + * \ingroup TaskNotifications
  8505. + */
  8506. +uint32_t ulTaskGenericNotifyTake( UBaseType_t uxIndexToWaitOn,
  8507. + BaseType_t xClearCountOnExit,
  8508. + TickType_t xTicksToWait );
  8509. +#define ulTaskNotifyTake( xClearCountOnExit, xTicksToWait ) \
  8510. + ulTaskGenericNotifyTake( ( tskDEFAULT_INDEX_TO_NOTIFY ), ( xClearCountOnExit ), ( xTicksToWait ) )
  8511. +#define ulTaskNotifyTakeIndexed( uxIndexToWaitOn, xClearCountOnExit, xTicksToWait ) \
  8512. + ulTaskGenericNotifyTake( ( uxIndexToWaitOn ), ( xClearCountOnExit ), ( xTicksToWait ) )
  8513. +
  8514. +/**
  8515. + * task. h
  8516. + * @code{c}
  8517. + * BaseType_t xTaskNotifyStateClearIndexed( TaskHandle_t xTask, UBaseType_t uxIndexToCLear );
  8518. + *
  8519. + * BaseType_t xTaskNotifyStateClear( TaskHandle_t xTask );
  8520. + * @endcode
  8521. + *
  8522. + * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details.
  8523. + *
  8524. + * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for these
  8525. + * functions to be available.
  8526. + *
  8527. + * Each task has a private array of "notification values" (or 'notifications'),
  8528. + * each of which is a 32-bit unsigned integer (uint32_t). The constant
  8529. + * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the
  8530. + * array, and (for backward compatibility) defaults to 1 if left undefined.
  8531. + * Prior to FreeRTOS V10.4.0 there was only one notification value per task.
  8532. + *
  8533. + * If a notification is sent to an index within the array of notifications then
  8534. + * the notification at that index is said to be 'pending' until it is read or
  8535. + * explicitly cleared by the receiving task. xTaskNotifyStateClearIndexed()
  8536. + * is the function that clears a pending notification without reading the
  8537. + * notification value. The notification value at the same array index is not
  8538. + * altered. Set xTask to NULL to clear the notification state of the calling
  8539. + * task.
  8540. + *
  8541. + * Backward compatibility information:
  8542. + * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and
  8543. + * all task notification API functions operated on that value. Replacing the
  8544. + * single notification value with an array of notification values necessitated a
  8545. + * new set of API functions that could address specific notifications within the
  8546. + * array. xTaskNotifyStateClear() is the original API function, and remains
  8547. + * backward compatible by always operating on the notification value at index 0
  8548. + * within the array. Calling xTaskNotifyStateClear() is equivalent to calling
  8549. + * xTaskNotifyStateClearIndexed() with the uxIndexToNotify parameter set to 0.
  8550. + *
  8551. + * @param xTask The handle of the RTOS task that will have a notification state
  8552. + * cleared. Set xTask to NULL to clear a notification state in the calling
  8553. + * task. To obtain a task's handle create the task using xTaskCreate() and
  8554. + * make use of the pxCreatedTask parameter, or create the task using
  8555. + * xTaskCreateStatic() and store the returned value, or use the task's name in
  8556. + * a call to xTaskGetHandle().
  8557. + *
  8558. + * @param uxIndexToClear The index within the target task's array of
  8559. + * notification values to act upon. For example, setting uxIndexToClear to 1
  8560. + * will clear the state of the notification at index 1 within the array.
  8561. + * uxIndexToClear must be less than configTASK_NOTIFICATION_ARRAY_ENTRIES.
  8562. + * ulTaskNotifyStateClear() does not have this parameter and always acts on the
  8563. + * notification at index 0.
  8564. + *
  8565. + * @return pdTRUE if the task's notification state was set to
  8566. + * eNotWaitingNotification, otherwise pdFALSE.
  8567. + *
  8568. + * \defgroup xTaskNotifyStateClearIndexed xTaskNotifyStateClearIndexed
  8569. + * \ingroup TaskNotifications
  8570. + */
  8571. +BaseType_t xTaskGenericNotifyStateClear( TaskHandle_t xTask,
  8572. + UBaseType_t uxIndexToClear );
  8573. +#define xTaskNotifyStateClear( xTask ) \
  8574. + xTaskGenericNotifyStateClear( ( xTask ), ( tskDEFAULT_INDEX_TO_NOTIFY ) )
  8575. +#define xTaskNotifyStateClearIndexed( xTask, uxIndexToClear ) \
  8576. + xTaskGenericNotifyStateClear( ( xTask ), ( uxIndexToClear ) )
  8577. +
  8578. +/**
  8579. + * task. h
  8580. + * @code{c}
  8581. + * uint32_t ulTaskNotifyValueClearIndexed( TaskHandle_t xTask, UBaseType_t uxIndexToClear, uint32_t ulBitsToClear );
  8582. + *
  8583. + * uint32_t ulTaskNotifyValueClear( TaskHandle_t xTask, uint32_t ulBitsToClear );
  8584. + * @endcode
  8585. + *
  8586. + * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details.
  8587. + *
  8588. + * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for these
  8589. + * functions to be available.
  8590. + *
  8591. + * Each task has a private array of "notification values" (or 'notifications'),
  8592. + * each of which is a 32-bit unsigned integer (uint32_t). The constant
  8593. + * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the
  8594. + * array, and (for backward compatibility) defaults to 1 if left undefined.
  8595. + * Prior to FreeRTOS V10.4.0 there was only one notification value per task.
  8596. + *
  8597. + * ulTaskNotifyValueClearIndexed() clears the bits specified by the
  8598. + * ulBitsToClear bit mask in the notification value at array index uxIndexToClear
  8599. + * of the task referenced by xTask.
  8600. + *
  8601. + * Backward compatibility information:
  8602. + * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and
  8603. + * all task notification API functions operated on that value. Replacing the
  8604. + * single notification value with an array of notification values necessitated a
  8605. + * new set of API functions that could address specific notifications within the
  8606. + * array. ulTaskNotifyValueClear() is the original API function, and remains
  8607. + * backward compatible by always operating on the notification value at index 0
  8608. + * within the array. Calling ulTaskNotifyValueClear() is equivalent to calling
  8609. + * ulTaskNotifyValueClearIndexed() with the uxIndexToClear parameter set to 0.
  8610. + *
  8611. + * @param xTask The handle of the RTOS task that will have bits in one of its
  8612. + * notification values cleared. Set xTask to NULL to clear bits in a
  8613. + * notification value of the calling task. To obtain a task's handle create the
  8614. + * task using xTaskCreate() and make use of the pxCreatedTask parameter, or
  8615. + * create the task using xTaskCreateStatic() and store the returned value, or
  8616. + * use the task's name in a call to xTaskGetHandle().
  8617. + *
  8618. + * @param uxIndexToClear The index within the target task's array of
  8619. + * notification values in which to clear the bits. uxIndexToClear
  8620. + * must be less than configTASK_NOTIFICATION_ARRAY_ENTRIES.
  8621. + * ulTaskNotifyValueClear() does not have this parameter and always clears bits
  8622. + * in the notification value at index 0.
  8623. + *
  8624. + * @param ulBitsToClear Bit mask of the bits to clear in the notification value of
  8625. + * xTask. Set a bit to 1 to clear the corresponding bits in the task's notification
  8626. + * value. Set ulBitsToClear to 0xffffffff (UINT_MAX on 32-bit architectures) to clear
  8627. + * the notification value to 0. Set ulBitsToClear to 0 to query the task's
  8628. + * notification value without clearing any bits.
  8629. + *
  8630. + *
  8631. + * @return The value of the target task's notification value before the bits
  8632. + * specified by ulBitsToClear were cleared.
  8633. + * \defgroup ulTaskNotifyValueClear ulTaskNotifyValueClear
  8634. + * \ingroup TaskNotifications
  8635. + */
  8636. +uint32_t ulTaskGenericNotifyValueClear( TaskHandle_t xTask,
  8637. + UBaseType_t uxIndexToClear,
  8638. + uint32_t ulBitsToClear );
  8639. +#define ulTaskNotifyValueClear( xTask, ulBitsToClear ) \
  8640. + ulTaskGenericNotifyValueClear( ( xTask ), ( tskDEFAULT_INDEX_TO_NOTIFY ), ( ulBitsToClear ) )
  8641. +#define ulTaskNotifyValueClearIndexed( xTask, uxIndexToClear, ulBitsToClear ) \
  8642. + ulTaskGenericNotifyValueClear( ( xTask ), ( uxIndexToClear ), ( ulBitsToClear ) )
  8643. +
  8644. +/**
  8645. + * task.h
  8646. + * @code{c}
  8647. + * void vTaskSetTimeOutState( TimeOut_t * const pxTimeOut );
  8648. + * @endcode
  8649. + *
  8650. + * Capture the current time for future use with xTaskCheckForTimeOut().
  8651. + *
  8652. + * @param pxTimeOut Pointer to a timeout object into which the current time
  8653. + * is to be captured. The captured time includes the tick count and the number
  8654. + * of times the tick count has overflowed since the system first booted.
  8655. + * \defgroup vTaskSetTimeOutState vTaskSetTimeOutState
  8656. + * \ingroup TaskCtrl
  8657. + */
  8658. +void vTaskSetTimeOutState( TimeOut_t * const pxTimeOut );
  8659. +
  8660. +/**
  8661. + * task.h
  8662. + * @code{c}
  8663. + * BaseType_t xTaskCheckForTimeOut( TimeOut_t * const pxTimeOut, TickType_t * const pxTicksToWait );
  8664. + * @endcode
  8665. + *
  8666. + * Determines if pxTicksToWait ticks has passed since a time was captured
  8667. + * using a call to vTaskSetTimeOutState(). The captured time includes the tick
  8668. + * count and the number of times the tick count has overflowed.
  8669. + *
  8670. + * @param pxTimeOut The time status as captured previously using
  8671. + * vTaskSetTimeOutState. If the timeout has not yet occurred, it is updated
  8672. + * to reflect the current time status.
  8673. + * @param pxTicksToWait The number of ticks to check for timeout i.e. if
  8674. + * pxTicksToWait ticks have passed since pxTimeOut was last updated (either by
  8675. + * vTaskSetTimeOutState() or xTaskCheckForTimeOut()), the timeout has occurred.
  8676. + * If the timeout has not occurred, pxTicksToWait is updated to reflect the
  8677. + * number of remaining ticks.
  8678. + *
  8679. + * @return If timeout has occurred, pdTRUE is returned. Otherwise pdFALSE is
  8680. + * returned and pxTicksToWait is updated to reflect the number of remaining
  8681. + * ticks.
  8682. + *
  8683. + * @see https://www.FreeRTOS.org/xTaskCheckForTimeOut.html
  8684. + *
  8685. + * Example Usage:
  8686. + * @code{c}
  8687. + * // Driver library function used to receive uxWantedBytes from an Rx buffer
  8688. + * // that is filled by a UART interrupt. If there are not enough bytes in the
  8689. + * // Rx buffer then the task enters the Blocked state until it is notified that
  8690. + * // more data has been placed into the buffer. If there is still not enough
  8691. + * // data then the task re-enters the Blocked state, and xTaskCheckForTimeOut()
  8692. + * // is used to re-calculate the Block time to ensure the total amount of time
  8693. + * // spent in the Blocked state does not exceed MAX_TIME_TO_WAIT. This
  8694. + * // continues until either the buffer contains at least uxWantedBytes bytes,
  8695. + * // or the total amount of time spent in the Blocked state reaches
  8696. + * // MAX_TIME_TO_WAIT - at which point the task reads however many bytes are
  8697. + * // available up to a maximum of uxWantedBytes.
  8698. + *
  8699. + * size_t xUART_Receive( uint8_t *pucBuffer, size_t uxWantedBytes )
  8700. + * {
  8701. + * size_t uxReceived = 0;
  8702. + * TickType_t xTicksToWait = MAX_TIME_TO_WAIT;
  8703. + * TimeOut_t xTimeOut;
  8704. + *
  8705. + * // Initialize xTimeOut. This records the time at which this function
  8706. + * // was entered.
  8707. + * vTaskSetTimeOutState( &xTimeOut );
  8708. + *
  8709. + * // Loop until the buffer contains the wanted number of bytes, or a
  8710. + * // timeout occurs.
  8711. + * while( UART_bytes_in_rx_buffer( pxUARTInstance ) < uxWantedBytes )
  8712. + * {
  8713. + * // The buffer didn't contain enough data so this task is going to
  8714. + * // enter the Blocked state. Adjusting xTicksToWait to account for
  8715. + * // any time that has been spent in the Blocked state within this
  8716. + * // function so far to ensure the total amount of time spent in the
  8717. + * // Blocked state does not exceed MAX_TIME_TO_WAIT.
  8718. + * if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) != pdFALSE )
  8719. + * {
  8720. + * //Timed out before the wanted number of bytes were available,
  8721. + * // exit the loop.
  8722. + * break;
  8723. + * }
  8724. + *
  8725. + * // Wait for a maximum of xTicksToWait ticks to be notified that the
  8726. + * // receive interrupt has placed more data into the buffer.
  8727. + * ulTaskNotifyTake( pdTRUE, xTicksToWait );
  8728. + * }
  8729. + *
  8730. + * // Attempt to read uxWantedBytes from the receive buffer into pucBuffer.
  8731. + * // The actual number of bytes read (which might be less than
  8732. + * // uxWantedBytes) is returned.
  8733. + * uxReceived = UART_read_from_receive_buffer( pxUARTInstance,
  8734. + * pucBuffer,
  8735. + * uxWantedBytes );
  8736. + *
  8737. + * return uxReceived;
  8738. + * }
  8739. + * @endcode
  8740. + * \defgroup xTaskCheckForTimeOut xTaskCheckForTimeOut
  8741. + * \ingroup TaskCtrl
  8742. + */
  8743. +BaseType_t xTaskCheckForTimeOut( TimeOut_t * const pxTimeOut,
  8744. + TickType_t * const pxTicksToWait );
  8745. +
  8746. +/*-----------------------------------------------------------
  8747. +* SCHEDULER INTERNALS AVAILABLE FOR PORTING PURPOSES
  8748. +*----------------------------------------------------------*/
  8749. +
  8750. +/*
  8751. + * Return the handle of the calling task.
  8752. + */
  8753. +TaskHandle_t xTaskGetCurrentTaskHandle( void );
  8754. +
  8755. +/*
  8756. + * Returns the scheduler state as taskSCHEDULER_RUNNING,
  8757. + * taskSCHEDULER_NOT_STARTED or taskSCHEDULER_SUSPENDED.
  8758. + */
  8759. +BaseType_t xTaskGetSchedulerState( void );
  8760. +
  8761. +/* ESP32 */
  8762. +BaseType_t xTaskGetAffinity( TaskHandle_t xTask );
  8763. +TaskHandle_t xTaskGetCurrentTaskHandleForCPU( BaseType_t cpuid );
  8764. +TaskHandle_t xTaskGetIdleTaskHandleForCPU( UBaseType_t cpuid );
  8765. +/* Unimplemented */
  8766. +#if ( configNUM_THREAD_LOCAL_STORAGE_POINTERS > 0 )
  8767. +void vTaskSetThreadLocalStoragePointer( TaskHandle_t xTaskToSet,
  8768. + BaseType_t xIndex,
  8769. + void * pvValue );
  8770. +void * pvTaskGetThreadLocalStoragePointer( TaskHandle_t xTaskToQuery,
  8771. + BaseType_t xIndex );
  8772. +#if ( configTHREAD_LOCAL_STORAGE_DELETE_CALLBACKS )
  8773. +typedef void (*TlsDeleteCallbackFunction_t)( int, void * );
  8774. +void vTaskSetThreadLocalStoragePointerAndDelCallback( TaskHandle_t xTaskToSet, BaseType_t xIndex, void *pvValue, TlsDeleteCallbackFunction_t pvDelCallback);
  8775. +#endif
  8776. +#endif
  8777. +
  8778. +/* *INDENT-OFF* */
  8779. +#ifdef __cplusplus
  8780. + }
  8781. +#endif
  8782. +/* *INDENT-ON* */
  8783. +#endif /* INC_TASK_H */
  8784. diff --git a/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/include/freertos/timers.h b/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/include/freertos/timers.h
  8785. new file mode 100644
  8786. index 0000000000..c5d1acf4d4
  8787. --- /dev/null
  8788. +++ b/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/include/freertos/timers.h
  8789. @@ -0,0 +1,1185 @@
  8790. +/*
  8791. + * FreeRTOS Kernel V10.4.6
  8792. + * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  8793. + *
  8794. + * SPDX-License-Identifier: MIT
  8795. + *
  8796. + * Permission is hereby granted, free of charge, to any person obtaining a copy of
  8797. + * this software and associated documentation files (the "Software"), to deal in
  8798. + * the Software without restriction, including without limitation the rights to
  8799. + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  8800. + * the Software, and to permit persons to whom the Software is furnished to do so,
  8801. + * subject to the following conditions:
  8802. + *
  8803. + * The above copyright notice and this permission notice shall be included in all
  8804. + * copies or substantial portions of the Software.
  8805. + *
  8806. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  8807. + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  8808. + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  8809. + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  8810. + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  8811. + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  8812. + *
  8813. + * https://www.FreeRTOS.org
  8814. + * https://github.com/FreeRTOS
  8815. + *
  8816. + */
  8817. +
  8818. +
  8819. +#ifndef TIMERS_H
  8820. +#define TIMERS_H
  8821. +
  8822. +#ifndef INC_FREERTOS_H
  8823. + #error "include FreeRTOS.h must appear in source files before include timers.h"
  8824. +#endif
  8825. +
  8826. +#include "task.h"
  8827. +
  8828. +/* *INDENT-OFF* */
  8829. +#ifdef __cplusplus
  8830. + extern "C" {
  8831. +#endif
  8832. +/* *INDENT-ON* */
  8833. +
  8834. +/*-----------------------------------------------------------
  8835. +* MACROS AND DEFINITIONS
  8836. +*----------------------------------------------------------*/
  8837. +
  8838. +/* IDs for commands that can be sent/received on the timer queue. These are to
  8839. + * be used solely through the macros that make up the public software timer API,
  8840. + * as defined below. The commands that are sent from interrupts must use the
  8841. + * highest numbers as tmrFIRST_FROM_ISR_COMMAND is used to determine if the task
  8842. + * or interrupt version of the queue send function should be used. */
  8843. +#define tmrCOMMAND_EXECUTE_CALLBACK_FROM_ISR ( ( BaseType_t ) -2 )
  8844. +#define tmrCOMMAND_EXECUTE_CALLBACK ( ( BaseType_t ) -1 )
  8845. +#define tmrCOMMAND_START_DONT_TRACE ( ( BaseType_t ) 0 )
  8846. +#define tmrCOMMAND_START ( ( BaseType_t ) 1 )
  8847. +#define tmrCOMMAND_RESET ( ( BaseType_t ) 2 )
  8848. +#define tmrCOMMAND_STOP ( ( BaseType_t ) 3 )
  8849. +#define tmrCOMMAND_CHANGE_PERIOD ( ( BaseType_t ) 4 )
  8850. +#define tmrCOMMAND_DELETE ( ( BaseType_t ) 5 )
  8851. +
  8852. +#define tmrFIRST_FROM_ISR_COMMAND ( ( BaseType_t ) 6 )
  8853. +#define tmrCOMMAND_START_FROM_ISR ( ( BaseType_t ) 6 )
  8854. +#define tmrCOMMAND_RESET_FROM_ISR ( ( BaseType_t ) 7 )
  8855. +#define tmrCOMMAND_STOP_FROM_ISR ( ( BaseType_t ) 8 )
  8856. +#define tmrCOMMAND_CHANGE_PERIOD_FROM_ISR ( ( BaseType_t ) 9 )
  8857. +
  8858. +/**
  8859. + * Type by which software timers are referenced. For example, a call to
  8860. + * xTimerCreate() returns an TimerHandle_t variable that can then be used to
  8861. + * reference the subject timer in calls to other software timer API functions
  8862. + * (for example, xTimerStart(), xTimerReset(), etc.).
  8863. + */
  8864. +struct tmrTimerControl; /* The old naming convention is used to prevent breaking kernel aware debuggers. */
  8865. +typedef struct tmrTimerControl * TimerHandle_t;
  8866. +
  8867. +/*
  8868. + * Defines the prototype to which timer callback functions must conform.
  8869. + */
  8870. +typedef void (* TimerCallbackFunction_t)( TimerHandle_t xTimer );
  8871. +
  8872. +/**
  8873. + * TimerHandle_t xTimerCreate( const char * const pcTimerName,
  8874. + * TickType_t xTimerPeriodInTicks,
  8875. + * UBaseType_t uxAutoReload,
  8876. + * void * pvTimerID,
  8877. + * TimerCallbackFunction_t pxCallbackFunction );
  8878. + *
  8879. + * Creates a new software timer instance, and returns a handle by which the
  8880. + * created software timer can be referenced.
  8881. + *
  8882. + * Internally, within the FreeRTOS implementation, software timers use a block
  8883. + * of memory, in which the timer data structure is stored. If a software timer
  8884. + * is created using xTimerCreate() then the required memory is automatically
  8885. + * dynamically allocated inside the xTimerCreate() function. (see
  8886. + * https://www.FreeRTOS.org/a00111.html). If a software timer is created using
  8887. + * xTimerCreateStatic() then the application writer must provide the memory that
  8888. + * will get used by the software timer. xTimerCreateStatic() therefore allows a
  8889. + * software timer to be created without using any dynamic memory allocation.
  8890. + *
  8891. + * Timers are created in the dormant state. The xTimerStart(), xTimerReset(),
  8892. + * xTimerStartFromISR(), xTimerResetFromISR(), xTimerChangePeriod() and
  8893. + * xTimerChangePeriodFromISR() API functions can all be used to transition a
  8894. + * timer into the active state.
  8895. + *
  8896. + * @param pcTimerName A text name that is assigned to the timer. This is done
  8897. + * purely to assist debugging. The kernel itself only ever references a timer
  8898. + * by its handle, and never by its name.
  8899. + *
  8900. + * @param xTimerPeriodInTicks The timer period. The time is defined in tick
  8901. + * periods so the constant portTICK_PERIOD_MS can be used to convert a time that
  8902. + * has been specified in milliseconds. For example, if the timer must expire
  8903. + * after 100 ticks, then xTimerPeriodInTicks should be set to 100.
  8904. + * Alternatively, if the timer must expire after 500ms, then xPeriod can be set
  8905. + * to ( 500 / portTICK_PERIOD_MS ) provided configTICK_RATE_HZ is less than or
  8906. + * equal to 1000. Time timer period must be greater than 0.
  8907. + *
  8908. + * @param uxAutoReload If uxAutoReload is set to pdTRUE then the timer will
  8909. + * expire repeatedly with a frequency set by the xTimerPeriodInTicks parameter.
  8910. + * If uxAutoReload is set to pdFALSE then the timer will be a one-shot timer and
  8911. + * enter the dormant state after it expires.
  8912. + *
  8913. + * @param pvTimerID An identifier that is assigned to the timer being created.
  8914. + * Typically this would be used in the timer callback function to identify which
  8915. + * timer expired when the same callback function is assigned to more than one
  8916. + * timer.
  8917. + *
  8918. + * @param pxCallbackFunction The function to call when the timer expires.
  8919. + * Callback functions must have the prototype defined by TimerCallbackFunction_t,
  8920. + * which is "void vCallbackFunction( TimerHandle_t xTimer );".
  8921. + *
  8922. + * @return If the timer is successfully created then a handle to the newly
  8923. + * created timer is returned. If the timer cannot be created because there is
  8924. + * insufficient FreeRTOS heap remaining to allocate the timer
  8925. + * structures then NULL is returned.
  8926. + *
  8927. + * Example usage:
  8928. + * @verbatim
  8929. + * #define NUM_TIMERS 5
  8930. + *
  8931. + * // An array to hold handles to the created timers.
  8932. + * TimerHandle_t xTimers[ NUM_TIMERS ];
  8933. + *
  8934. + * // An array to hold a count of the number of times each timer expires.
  8935. + * int32_t lExpireCounters[ NUM_TIMERS ] = { 0 };
  8936. + *
  8937. + * // Define a callback function that will be used by multiple timer instances.
  8938. + * // The callback function does nothing but count the number of times the
  8939. + * // associated timer expires, and stop the timer once the timer has expired
  8940. + * // 10 times.
  8941. + * void vTimerCallback( TimerHandle_t pxTimer )
  8942. + * {
  8943. + * int32_t lArrayIndex;
  8944. + * const int32_t xMaxExpiryCountBeforeStopping = 10;
  8945. + *
  8946. + * // Optionally do something if the pxTimer parameter is NULL.
  8947. + * configASSERT( pxTimer );
  8948. + *
  8949. + * // Which timer expired?
  8950. + * lArrayIndex = ( int32_t ) pvTimerGetTimerID( pxTimer );
  8951. + *
  8952. + * // Increment the number of times that pxTimer has expired.
  8953. + * lExpireCounters[ lArrayIndex ] += 1;
  8954. + *
  8955. + * // If the timer has expired 10 times then stop it from running.
  8956. + * if( lExpireCounters[ lArrayIndex ] == xMaxExpiryCountBeforeStopping )
  8957. + * {
  8958. + * // Do not use a block time if calling a timer API function from a
  8959. + * // timer callback function, as doing so could cause a deadlock!
  8960. + * xTimerStop( pxTimer, 0 );
  8961. + * }
  8962. + * }
  8963. + *
  8964. + * void main( void )
  8965. + * {
  8966. + * int32_t x;
  8967. + *
  8968. + * // Create then start some timers. Starting the timers before the scheduler
  8969. + * // has been started means the timers will start running immediately that
  8970. + * // the scheduler starts.
  8971. + * for( x = 0; x < NUM_TIMERS; x++ )
  8972. + * {
  8973. + * xTimers[ x ] = xTimerCreate( "Timer", // Just a text name, not used by the kernel.
  8974. + * ( 100 * x ), // The timer period in ticks.
  8975. + * pdTRUE, // The timers will auto-reload themselves when they expire.
  8976. + * ( void * ) x, // Assign each timer a unique id equal to its array index.
  8977. + * vTimerCallback // Each timer calls the same callback when it expires.
  8978. + * );
  8979. + *
  8980. + * if( xTimers[ x ] == NULL )
  8981. + * {
  8982. + * // The timer was not created.
  8983. + * }
  8984. + * else
  8985. + * {
  8986. + * // Start the timer. No block time is specified, and even if one was
  8987. + * // it would be ignored because the scheduler has not yet been
  8988. + * // started.
  8989. + * if( xTimerStart( xTimers[ x ], 0 ) != pdPASS )
  8990. + * {
  8991. + * // The timer could not be set into the Active state.
  8992. + * }
  8993. + * }
  8994. + * }
  8995. + *
  8996. + * // ...
  8997. + * // Create tasks here.
  8998. + * // ...
  8999. + *
  9000. + * // Starting the scheduler will start the timers running as they have already
  9001. + * // been set into the active state.
  9002. + * vTaskStartScheduler();
  9003. + *
  9004. + * // Should not reach here.
  9005. + * for( ;; );
  9006. + * }
  9007. + * @endverbatim
  9008. + */
  9009. +#if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
  9010. + TimerHandle_t xTimerCreate( const char * const pcTimerName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
  9011. + const TickType_t xTimerPeriodInTicks,
  9012. + const UBaseType_t uxAutoReload,
  9013. + void * const pvTimerID,
  9014. + TimerCallbackFunction_t pxCallbackFunction );
  9015. +#endif
  9016. +
  9017. +/**
  9018. + * TimerHandle_t xTimerCreateStatic(const char * const pcTimerName,
  9019. + * TickType_t xTimerPeriodInTicks,
  9020. + * UBaseType_t uxAutoReload,
  9021. + * void * pvTimerID,
  9022. + * TimerCallbackFunction_t pxCallbackFunction,
  9023. + * StaticTimer_t *pxTimerBuffer );
  9024. + *
  9025. + * Creates a new software timer instance, and returns a handle by which the
  9026. + * created software timer can be referenced.
  9027. + *
  9028. + * Internally, within the FreeRTOS implementation, software timers use a block
  9029. + * of memory, in which the timer data structure is stored. If a software timer
  9030. + * is created using xTimerCreate() then the required memory is automatically
  9031. + * dynamically allocated inside the xTimerCreate() function. (see
  9032. + * https://www.FreeRTOS.org/a00111.html). If a software timer is created using
  9033. + * xTimerCreateStatic() then the application writer must provide the memory that
  9034. + * will get used by the software timer. xTimerCreateStatic() therefore allows a
  9035. + * software timer to be created without using any dynamic memory allocation.
  9036. + *
  9037. + * Timers are created in the dormant state. The xTimerStart(), xTimerReset(),
  9038. + * xTimerStartFromISR(), xTimerResetFromISR(), xTimerChangePeriod() and
  9039. + * xTimerChangePeriodFromISR() API functions can all be used to transition a
  9040. + * timer into the active state.
  9041. + *
  9042. + * @param pcTimerName A text name that is assigned to the timer. This is done
  9043. + * purely to assist debugging. The kernel itself only ever references a timer
  9044. + * by its handle, and never by its name.
  9045. + *
  9046. + * @param xTimerPeriodInTicks The timer period. The time is defined in tick
  9047. + * periods so the constant portTICK_PERIOD_MS can be used to convert a time that
  9048. + * has been specified in milliseconds. For example, if the timer must expire
  9049. + * after 100 ticks, then xTimerPeriodInTicks should be set to 100.
  9050. + * Alternatively, if the timer must expire after 500ms, then xPeriod can be set
  9051. + * to ( 500 / portTICK_PERIOD_MS ) provided configTICK_RATE_HZ is less than or
  9052. + * equal to 1000. The timer period must be greater than 0.
  9053. + *
  9054. + * @param uxAutoReload If uxAutoReload is set to pdTRUE then the timer will
  9055. + * expire repeatedly with a frequency set by the xTimerPeriodInTicks parameter.
  9056. + * If uxAutoReload is set to pdFALSE then the timer will be a one-shot timer and
  9057. + * enter the dormant state after it expires.
  9058. + *
  9059. + * @param pvTimerID An identifier that is assigned to the timer being created.
  9060. + * Typically this would be used in the timer callback function to identify which
  9061. + * timer expired when the same callback function is assigned to more than one
  9062. + * timer.
  9063. + *
  9064. + * @param pxCallbackFunction The function to call when the timer expires.
  9065. + * Callback functions must have the prototype defined by TimerCallbackFunction_t,
  9066. + * which is "void vCallbackFunction( TimerHandle_t xTimer );".
  9067. + *
  9068. + * @param pxTimerBuffer Must point to a variable of type StaticTimer_t, which
  9069. + * will be then be used to hold the software timer's data structures, removing
  9070. + * the need for the memory to be allocated dynamically.
  9071. + *
  9072. + * @return If the timer is created then a handle to the created timer is
  9073. + * returned. If pxTimerBuffer was NULL then NULL is returned.
  9074. + *
  9075. + * Example usage:
  9076. + * @verbatim
  9077. + *
  9078. + * // The buffer used to hold the software timer's data structure.
  9079. + * static StaticTimer_t xTimerBuffer;
  9080. + *
  9081. + * // A variable that will be incremented by the software timer's callback
  9082. + * // function.
  9083. + * UBaseType_t uxVariableToIncrement = 0;
  9084. + *
  9085. + * // A software timer callback function that increments a variable passed to
  9086. + * // it when the software timer was created. After the 5th increment the
  9087. + * // callback function stops the software timer.
  9088. + * static void prvTimerCallback( TimerHandle_t xExpiredTimer )
  9089. + * {
  9090. + * UBaseType_t *puxVariableToIncrement;
  9091. + * BaseType_t xReturned;
  9092. + *
  9093. + * // Obtain the address of the variable to increment from the timer ID.
  9094. + * puxVariableToIncrement = ( UBaseType_t * ) pvTimerGetTimerID( xExpiredTimer );
  9095. + *
  9096. + * // Increment the variable to show the timer callback has executed.
  9097. + * ( *puxVariableToIncrement )++;
  9098. + *
  9099. + * // If this callback has executed the required number of times, stop the
  9100. + * // timer.
  9101. + * if( *puxVariableToIncrement == 5 )
  9102. + * {
  9103. + * // This is called from a timer callback so must not block.
  9104. + * xTimerStop( xExpiredTimer, staticDONT_BLOCK );
  9105. + * }
  9106. + * }
  9107. + *
  9108. + *
  9109. + * void main( void )
  9110. + * {
  9111. + * // Create the software time. xTimerCreateStatic() has an extra parameter
  9112. + * // than the normal xTimerCreate() API function. The parameter is a pointer
  9113. + * // to the StaticTimer_t structure that will hold the software timer
  9114. + * // structure. If the parameter is passed as NULL then the structure will be
  9115. + * // allocated dynamically, just as if xTimerCreate() had been called.
  9116. + * xTimer = xTimerCreateStatic( "T1", // Text name for the task. Helps debugging only. Not used by FreeRTOS.
  9117. + * xTimerPeriod, // The period of the timer in ticks.
  9118. + * pdTRUE, // This is an auto-reload timer.
  9119. + * ( void * ) &uxVariableToIncrement, // A variable incremented by the software timer's callback function
  9120. + * prvTimerCallback, // The function to execute when the timer expires.
  9121. + * &xTimerBuffer ); // The buffer that will hold the software timer structure.
  9122. + *
  9123. + * // The scheduler has not started yet so a block time is not used.
  9124. + * xReturned = xTimerStart( xTimer, 0 );
  9125. + *
  9126. + * // ...
  9127. + * // Create tasks here.
  9128. + * // ...
  9129. + *
  9130. + * // Starting the scheduler will start the timers running as they have already
  9131. + * // been set into the active state.
  9132. + * vTaskStartScheduler();
  9133. + *
  9134. + * // Should not reach here.
  9135. + * for( ;; );
  9136. + * }
  9137. + * @endverbatim
  9138. + */
  9139. +#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
  9140. + TimerHandle_t xTimerCreateStatic( const char * const pcTimerName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
  9141. + const TickType_t xTimerPeriodInTicks,
  9142. + const UBaseType_t uxAutoReload,
  9143. + void * const pvTimerID,
  9144. + TimerCallbackFunction_t pxCallbackFunction,
  9145. + StaticTimer_t * pxTimerBuffer );
  9146. +#endif /* configSUPPORT_STATIC_ALLOCATION */
  9147. +
  9148. +/**
  9149. + * void *pvTimerGetTimerID( TimerHandle_t xTimer );
  9150. + *
  9151. + * Returns the ID assigned to the timer.
  9152. + *
  9153. + * IDs are assigned to timers using the pvTimerID parameter of the call to
  9154. + * xTimerCreated() that was used to create the timer, and by calling the
  9155. + * vTimerSetTimerID() API function.
  9156. + *
  9157. + * If the same callback function is assigned to multiple timers then the timer
  9158. + * ID can be used as time specific (timer local) storage.
  9159. + *
  9160. + * @param xTimer The timer being queried.
  9161. + *
  9162. + * @return The ID assigned to the timer being queried.
  9163. + *
  9164. + * Example usage:
  9165. + *
  9166. + * See the xTimerCreate() API function example usage scenario.
  9167. + */
  9168. +void * pvTimerGetTimerID( const TimerHandle_t xTimer );
  9169. +
  9170. +/**
  9171. + * void vTimerSetTimerID( TimerHandle_t xTimer, void *pvNewID );
  9172. + *
  9173. + * Sets the ID assigned to the timer.
  9174. + *
  9175. + * IDs are assigned to timers using the pvTimerID parameter of the call to
  9176. + * xTimerCreated() that was used to create the timer.
  9177. + *
  9178. + * If the same callback function is assigned to multiple timers then the timer
  9179. + * ID can be used as time specific (timer local) storage.
  9180. + *
  9181. + * @param xTimer The timer being updated.
  9182. + *
  9183. + * @param pvNewID The ID to assign to the timer.
  9184. + *
  9185. + * Example usage:
  9186. + *
  9187. + * See the xTimerCreate() API function example usage scenario.
  9188. + */
  9189. +void vTimerSetTimerID( TimerHandle_t xTimer,
  9190. + void * pvNewID );
  9191. +
  9192. +/**
  9193. + * BaseType_t xTimerIsTimerActive( TimerHandle_t xTimer );
  9194. + *
  9195. + * Queries a timer to see if it is active or dormant.
  9196. + *
  9197. + * A timer will be dormant if:
  9198. + * 1) It has been created but not started, or
  9199. + * 2) It is an expired one-shot timer that has not been restarted.
  9200. + *
  9201. + * Timers are created in the dormant state. The xTimerStart(), xTimerReset(),
  9202. + * xTimerStartFromISR(), xTimerResetFromISR(), xTimerChangePeriod() and
  9203. + * xTimerChangePeriodFromISR() API functions can all be used to transition a timer into the
  9204. + * active state.
  9205. + *
  9206. + * @param xTimer The timer being queried.
  9207. + *
  9208. + * @return pdFALSE will be returned if the timer is dormant. A value other than
  9209. + * pdFALSE will be returned if the timer is active.
  9210. + *
  9211. + * Example usage:
  9212. + * @verbatim
  9213. + * // This function assumes xTimer has already been created.
  9214. + * void vAFunction( TimerHandle_t xTimer )
  9215. + * {
  9216. + * if( xTimerIsTimerActive( xTimer ) != pdFALSE ) // or more simply and equivalently "if( xTimerIsTimerActive( xTimer ) )"
  9217. + * {
  9218. + * // xTimer is active, do something.
  9219. + * }
  9220. + * else
  9221. + * {
  9222. + * // xTimer is not active, do something else.
  9223. + * }
  9224. + * }
  9225. + * @endverbatim
  9226. + */
  9227. +BaseType_t xTimerIsTimerActive( TimerHandle_t xTimer );
  9228. +
  9229. +/**
  9230. + * TaskHandle_t xTimerGetTimerDaemonTaskHandle( void );
  9231. + *
  9232. + * Simply returns the handle of the timer service/daemon task. It it not valid
  9233. + * to call xTimerGetTimerDaemonTaskHandle() before the scheduler has been started.
  9234. + */
  9235. +TaskHandle_t xTimerGetTimerDaemonTaskHandle( void );
  9236. +
  9237. +/**
  9238. + * BaseType_t xTimerStart( TimerHandle_t xTimer, TickType_t xTicksToWait );
  9239. + *
  9240. + * Timer functionality is provided by a timer service/daemon task. Many of the
  9241. + * public FreeRTOS timer API functions send commands to the timer service task
  9242. + * through a queue called the timer command queue. The timer command queue is
  9243. + * private to the kernel itself and is not directly accessible to application
  9244. + * code. The length of the timer command queue is set by the
  9245. + * configTIMER_QUEUE_LENGTH configuration constant.
  9246. + *
  9247. + * xTimerStart() starts a timer that was previously created using the
  9248. + * xTimerCreate() API function. If the timer had already been started and was
  9249. + * already in the active state, then xTimerStart() has equivalent functionality
  9250. + * to the xTimerReset() API function.
  9251. + *
  9252. + * Starting a timer ensures the timer is in the active state. If the timer
  9253. + * is not stopped, deleted, or reset in the mean time, the callback function
  9254. + * associated with the timer will get called 'n' ticks after xTimerStart() was
  9255. + * called, where 'n' is the timers defined period.
  9256. + *
  9257. + * It is valid to call xTimerStart() before the scheduler has been started, but
  9258. + * when this is done the timer will not actually start until the scheduler is
  9259. + * started, and the timers expiry time will be relative to when the scheduler is
  9260. + * started, not relative to when xTimerStart() was called.
  9261. + *
  9262. + * The configUSE_TIMERS configuration constant must be set to 1 for xTimerStart()
  9263. + * to be available.
  9264. + *
  9265. + * @param xTimer The handle of the timer being started/restarted.
  9266. + *
  9267. + * @param xTicksToWait Specifies the time, in ticks, that the calling task should
  9268. + * be held in the Blocked state to wait for the start command to be successfully
  9269. + * sent to the timer command queue, should the queue already be full when
  9270. + * xTimerStart() was called. xTicksToWait is ignored if xTimerStart() is called
  9271. + * before the scheduler is started.
  9272. + *
  9273. + * @return pdFAIL will be returned if the start command could not be sent to
  9274. + * the timer command queue even after xTicksToWait ticks had passed. pdPASS will
  9275. + * be returned if the command was successfully sent to the timer command queue.
  9276. + * When the command is actually processed will depend on the priority of the
  9277. + * timer service/daemon task relative to other tasks in the system, although the
  9278. + * timers expiry time is relative to when xTimerStart() is actually called. The
  9279. + * timer service/daemon task priority is set by the configTIMER_TASK_PRIORITY
  9280. + * configuration constant.
  9281. + *
  9282. + * Example usage:
  9283. + *
  9284. + * See the xTimerCreate() API function example usage scenario.
  9285. + *
  9286. + */
  9287. +#define xTimerStart( xTimer, xTicksToWait ) \
  9288. + xTimerGenericCommand( ( xTimer ), tmrCOMMAND_START, ( xTaskGetTickCount() ), NULL, ( xTicksToWait ) )
  9289. +
  9290. +/**
  9291. + * BaseType_t xTimerStop( TimerHandle_t xTimer, TickType_t xTicksToWait );
  9292. + *
  9293. + * Timer functionality is provided by a timer service/daemon task. Many of the
  9294. + * public FreeRTOS timer API functions send commands to the timer service task
  9295. + * through a queue called the timer command queue. The timer command queue is
  9296. + * private to the kernel itself and is not directly accessible to application
  9297. + * code. The length of the timer command queue is set by the
  9298. + * configTIMER_QUEUE_LENGTH configuration constant.
  9299. + *
  9300. + * xTimerStop() stops a timer that was previously started using either of the
  9301. + * The xTimerStart(), xTimerReset(), xTimerStartFromISR(), xTimerResetFromISR(),
  9302. + * xTimerChangePeriod() or xTimerChangePeriodFromISR() API functions.
  9303. + *
  9304. + * Stopping a timer ensures the timer is not in the active state.
  9305. + *
  9306. + * The configUSE_TIMERS configuration constant must be set to 1 for xTimerStop()
  9307. + * to be available.
  9308. + *
  9309. + * @param xTimer The handle of the timer being stopped.
  9310. + *
  9311. + * @param xTicksToWait Specifies the time, in ticks, that the calling task should
  9312. + * be held in the Blocked state to wait for the stop command to be successfully
  9313. + * sent to the timer command queue, should the queue already be full when
  9314. + * xTimerStop() was called. xTicksToWait is ignored if xTimerStop() is called
  9315. + * before the scheduler is started.
  9316. + *
  9317. + * @return pdFAIL will be returned if the stop command could not be sent to
  9318. + * the timer command queue even after xTicksToWait ticks had passed. pdPASS will
  9319. + * be returned if the command was successfully sent to the timer command queue.
  9320. + * When the command is actually processed will depend on the priority of the
  9321. + * timer service/daemon task relative to other tasks in the system. The timer
  9322. + * service/daemon task priority is set by the configTIMER_TASK_PRIORITY
  9323. + * configuration constant.
  9324. + *
  9325. + * Example usage:
  9326. + *
  9327. + * See the xTimerCreate() API function example usage scenario.
  9328. + *
  9329. + */
  9330. +#define xTimerStop( xTimer, xTicksToWait ) \
  9331. + xTimerGenericCommand( ( xTimer ), tmrCOMMAND_STOP, 0U, NULL, ( xTicksToWait ) )
  9332. +
  9333. +/**
  9334. + * BaseType_t xTimerChangePeriod( TimerHandle_t xTimer,
  9335. + * TickType_t xNewPeriod,
  9336. + * TickType_t xTicksToWait );
  9337. + *
  9338. + * Timer functionality is provided by a timer service/daemon task. Many of the
  9339. + * public FreeRTOS timer API functions send commands to the timer service task
  9340. + * through a queue called the timer command queue. The timer command queue is
  9341. + * private to the kernel itself and is not directly accessible to application
  9342. + * code. The length of the timer command queue is set by the
  9343. + * configTIMER_QUEUE_LENGTH configuration constant.
  9344. + *
  9345. + * xTimerChangePeriod() changes the period of a timer that was previously
  9346. + * created using the xTimerCreate() API function.
  9347. + *
  9348. + * xTimerChangePeriod() can be called to change the period of an active or
  9349. + * dormant state timer.
  9350. + *
  9351. + * The configUSE_TIMERS configuration constant must be set to 1 for
  9352. + * xTimerChangePeriod() to be available.
  9353. + *
  9354. + * @param xTimer The handle of the timer that is having its period changed.
  9355. + *
  9356. + * @param xNewPeriod The new period for xTimer. Timer periods are specified in
  9357. + * tick periods, so the constant portTICK_PERIOD_MS can be used to convert a time
  9358. + * that has been specified in milliseconds. For example, if the timer must
  9359. + * expire after 100 ticks, then xNewPeriod should be set to 100. Alternatively,
  9360. + * if the timer must expire after 500ms, then xNewPeriod can be set to
  9361. + * ( 500 / portTICK_PERIOD_MS ) provided configTICK_RATE_HZ is less than
  9362. + * or equal to 1000.
  9363. + *
  9364. + * @param xTicksToWait Specifies the time, in ticks, that the calling task should
  9365. + * be held in the Blocked state to wait for the change period command to be
  9366. + * successfully sent to the timer command queue, should the queue already be
  9367. + * full when xTimerChangePeriod() was called. xTicksToWait is ignored if
  9368. + * xTimerChangePeriod() is called before the scheduler is started.
  9369. + *
  9370. + * @return pdFAIL will be returned if the change period command could not be
  9371. + * sent to the timer command queue even after xTicksToWait ticks had passed.
  9372. + * pdPASS will be returned if the command was successfully sent to the timer
  9373. + * command queue. When the command is actually processed will depend on the
  9374. + * priority of the timer service/daemon task relative to other tasks in the
  9375. + * system. The timer service/daemon task priority is set by the
  9376. + * configTIMER_TASK_PRIORITY configuration constant.
  9377. + *
  9378. + * Example usage:
  9379. + * @verbatim
  9380. + * // This function assumes xTimer has already been created. If the timer
  9381. + * // referenced by xTimer is already active when it is called, then the timer
  9382. + * // is deleted. If the timer referenced by xTimer is not active when it is
  9383. + * // called, then the period of the timer is set to 500ms and the timer is
  9384. + * // started.
  9385. + * void vAFunction( TimerHandle_t xTimer )
  9386. + * {
  9387. + * if( xTimerIsTimerActive( xTimer ) != pdFALSE ) // or more simply and equivalently "if( xTimerIsTimerActive( xTimer ) )"
  9388. + * {
  9389. + * // xTimer is already active - delete it.
  9390. + * xTimerDelete( xTimer );
  9391. + * }
  9392. + * else
  9393. + * {
  9394. + * // xTimer is not active, change its period to 500ms. This will also
  9395. + * // cause the timer to start. Block for a maximum of 100 ticks if the
  9396. + * // change period command cannot immediately be sent to the timer
  9397. + * // command queue.
  9398. + * if( xTimerChangePeriod( xTimer, 500 / portTICK_PERIOD_MS, 100 ) == pdPASS )
  9399. + * {
  9400. + * // The command was successfully sent.
  9401. + * }
  9402. + * else
  9403. + * {
  9404. + * // The command could not be sent, even after waiting for 100 ticks
  9405. + * // to pass. Take appropriate action here.
  9406. + * }
  9407. + * }
  9408. + * }
  9409. + * @endverbatim
  9410. + */
  9411. +#define xTimerChangePeriod( xTimer, xNewPeriod, xTicksToWait ) \
  9412. + xTimerGenericCommand( ( xTimer ), tmrCOMMAND_CHANGE_PERIOD, ( xNewPeriod ), NULL, ( xTicksToWait ) )
  9413. +
  9414. +/**
  9415. + * BaseType_t xTimerDelete( TimerHandle_t xTimer, TickType_t xTicksToWait );
  9416. + *
  9417. + * Timer functionality is provided by a timer service/daemon task. Many of the
  9418. + * public FreeRTOS timer API functions send commands to the timer service task
  9419. + * through a queue called the timer command queue. The timer command queue is
  9420. + * private to the kernel itself and is not directly accessible to application
  9421. + * code. The length of the timer command queue is set by the
  9422. + * configTIMER_QUEUE_LENGTH configuration constant.
  9423. + *
  9424. + * xTimerDelete() deletes a timer that was previously created using the
  9425. + * xTimerCreate() API function.
  9426. + *
  9427. + * The configUSE_TIMERS configuration constant must be set to 1 for
  9428. + * xTimerDelete() to be available.
  9429. + *
  9430. + * @param xTimer The handle of the timer being deleted.
  9431. + *
  9432. + * @param xTicksToWait Specifies the time, in ticks, that the calling task should
  9433. + * be held in the Blocked state to wait for the delete command to be
  9434. + * successfully sent to the timer command queue, should the queue already be
  9435. + * full when xTimerDelete() was called. xTicksToWait is ignored if xTimerDelete()
  9436. + * is called before the scheduler is started.
  9437. + *
  9438. + * @return pdFAIL will be returned if the delete command could not be sent to
  9439. + * the timer command queue even after xTicksToWait ticks had passed. pdPASS will
  9440. + * be returned if the command was successfully sent to the timer command queue.
  9441. + * When the command is actually processed will depend on the priority of the
  9442. + * timer service/daemon task relative to other tasks in the system. The timer
  9443. + * service/daemon task priority is set by the configTIMER_TASK_PRIORITY
  9444. + * configuration constant.
  9445. + *
  9446. + * Example usage:
  9447. + *
  9448. + * See the xTimerChangePeriod() API function example usage scenario.
  9449. + */
  9450. +#define xTimerDelete( xTimer, xTicksToWait ) \
  9451. + xTimerGenericCommand( ( xTimer ), tmrCOMMAND_DELETE, 0U, NULL, ( xTicksToWait ) )
  9452. +
  9453. +/**
  9454. + * BaseType_t xTimerReset( TimerHandle_t xTimer, TickType_t xTicksToWait );
  9455. + *
  9456. + * Timer functionality is provided by a timer service/daemon task. Many of the
  9457. + * public FreeRTOS timer API functions send commands to the timer service task
  9458. + * through a queue called the timer command queue. The timer command queue is
  9459. + * private to the kernel itself and is not directly accessible to application
  9460. + * code. The length of the timer command queue is set by the
  9461. + * configTIMER_QUEUE_LENGTH configuration constant.
  9462. + *
  9463. + * xTimerReset() re-starts a timer that was previously created using the
  9464. + * xTimerCreate() API function. If the timer had already been started and was
  9465. + * already in the active state, then xTimerReset() will cause the timer to
  9466. + * re-evaluate its expiry time so that it is relative to when xTimerReset() was
  9467. + * called. If the timer was in the dormant state then xTimerReset() has
  9468. + * equivalent functionality to the xTimerStart() API function.
  9469. + *
  9470. + * Resetting a timer ensures the timer is in the active state. If the timer
  9471. + * is not stopped, deleted, or reset in the mean time, the callback function
  9472. + * associated with the timer will get called 'n' ticks after xTimerReset() was
  9473. + * called, where 'n' is the timers defined period.
  9474. + *
  9475. + * It is valid to call xTimerReset() before the scheduler has been started, but
  9476. + * when this is done the timer will not actually start until the scheduler is
  9477. + * started, and the timers expiry time will be relative to when the scheduler is
  9478. + * started, not relative to when xTimerReset() was called.
  9479. + *
  9480. + * The configUSE_TIMERS configuration constant must be set to 1 for xTimerReset()
  9481. + * to be available.
  9482. + *
  9483. + * @param xTimer The handle of the timer being reset/started/restarted.
  9484. + *
  9485. + * @param xTicksToWait Specifies the time, in ticks, that the calling task should
  9486. + * be held in the Blocked state to wait for the reset command to be successfully
  9487. + * sent to the timer command queue, should the queue already be full when
  9488. + * xTimerReset() was called. xTicksToWait is ignored if xTimerReset() is called
  9489. + * before the scheduler is started.
  9490. + *
  9491. + * @return pdFAIL will be returned if the reset command could not be sent to
  9492. + * the timer command queue even after xTicksToWait ticks had passed. pdPASS will
  9493. + * be returned if the command was successfully sent to the timer command queue.
  9494. + * When the command is actually processed will depend on the priority of the
  9495. + * timer service/daemon task relative to other tasks in the system, although the
  9496. + * timers expiry time is relative to when xTimerStart() is actually called. The
  9497. + * timer service/daemon task priority is set by the configTIMER_TASK_PRIORITY
  9498. + * configuration constant.
  9499. + *
  9500. + * Example usage:
  9501. + * @verbatim
  9502. + * // When a key is pressed, an LCD back-light is switched on. If 5 seconds pass
  9503. + * // without a key being pressed, then the LCD back-light is switched off. In
  9504. + * // this case, the timer is a one-shot timer.
  9505. + *
  9506. + * TimerHandle_t xBacklightTimer = NULL;
  9507. + *
  9508. + * // The callback function assigned to the one-shot timer. In this case the
  9509. + * // parameter is not used.
  9510. + * void vBacklightTimerCallback( TimerHandle_t pxTimer )
  9511. + * {
  9512. + * // The timer expired, therefore 5 seconds must have passed since a key
  9513. + * // was pressed. Switch off the LCD back-light.
  9514. + * vSetBacklightState( BACKLIGHT_OFF );
  9515. + * }
  9516. + *
  9517. + * // The key press event handler.
  9518. + * void vKeyPressEventHandler( char cKey )
  9519. + * {
  9520. + * // Ensure the LCD back-light is on, then reset the timer that is
  9521. + * // responsible for turning the back-light off after 5 seconds of
  9522. + * // key inactivity. Wait 10 ticks for the command to be successfully sent
  9523. + * // if it cannot be sent immediately.
  9524. + * vSetBacklightState( BACKLIGHT_ON );
  9525. + * if( xTimerReset( xBacklightTimer, 100 ) != pdPASS )
  9526. + * {
  9527. + * // The reset command was not executed successfully. Take appropriate
  9528. + * // action here.
  9529. + * }
  9530. + *
  9531. + * // Perform the rest of the key processing here.
  9532. + * }
  9533. + *
  9534. + * void main( void )
  9535. + * {
  9536. + * int32_t x;
  9537. + *
  9538. + * // Create then start the one-shot timer that is responsible for turning
  9539. + * // the back-light off if no keys are pressed within a 5 second period.
  9540. + * xBacklightTimer = xTimerCreate( "BacklightTimer", // Just a text name, not used by the kernel.
  9541. + * ( 5000 / portTICK_PERIOD_MS), // The timer period in ticks.
  9542. + * pdFALSE, // The timer is a one-shot timer.
  9543. + * 0, // The id is not used by the callback so can take any value.
  9544. + * vBacklightTimerCallback // The callback function that switches the LCD back-light off.
  9545. + * );
  9546. + *
  9547. + * if( xBacklightTimer == NULL )
  9548. + * {
  9549. + * // The timer was not created.
  9550. + * }
  9551. + * else
  9552. + * {
  9553. + * // Start the timer. No block time is specified, and even if one was
  9554. + * // it would be ignored because the scheduler has not yet been
  9555. + * // started.
  9556. + * if( xTimerStart( xBacklightTimer, 0 ) != pdPASS )
  9557. + * {
  9558. + * // The timer could not be set into the Active state.
  9559. + * }
  9560. + * }
  9561. + *
  9562. + * // ...
  9563. + * // Create tasks here.
  9564. + * // ...
  9565. + *
  9566. + * // Starting the scheduler will start the timer running as it has already
  9567. + * // been set into the active state.
  9568. + * vTaskStartScheduler();
  9569. + *
  9570. + * // Should not reach here.
  9571. + * for( ;; );
  9572. + * }
  9573. + * @endverbatim
  9574. + */
  9575. +#define xTimerReset( xTimer, xTicksToWait ) \
  9576. + xTimerGenericCommand( ( xTimer ), tmrCOMMAND_RESET, ( xTaskGetTickCount() ), NULL, ( xTicksToWait ) )
  9577. +
  9578. +/**
  9579. + * BaseType_t xTimerStartFromISR( TimerHandle_t xTimer,
  9580. + * BaseType_t *pxHigherPriorityTaskWoken );
  9581. + *
  9582. + * A version of xTimerStart() that can be called from an interrupt service
  9583. + * routine.
  9584. + *
  9585. + * @param xTimer The handle of the timer being started/restarted.
  9586. + *
  9587. + * @param pxHigherPriorityTaskWoken The timer service/daemon task spends most
  9588. + * of its time in the Blocked state, waiting for messages to arrive on the timer
  9589. + * command queue. Calling xTimerStartFromISR() writes a message to the timer
  9590. + * command queue, so has the potential to transition the timer service/daemon
  9591. + * task out of the Blocked state. If calling xTimerStartFromISR() causes the
  9592. + * timer service/daemon task to leave the Blocked state, and the timer service/
  9593. + * daemon task has a priority equal to or greater than the currently executing
  9594. + * task (the task that was interrupted), then *pxHigherPriorityTaskWoken will
  9595. + * get set to pdTRUE internally within the xTimerStartFromISR() function. If
  9596. + * xTimerStartFromISR() sets this value to pdTRUE then a context switch should
  9597. + * be performed before the interrupt exits.
  9598. + *
  9599. + * @return pdFAIL will be returned if the start command could not be sent to
  9600. + * the timer command queue. pdPASS will be returned if the command was
  9601. + * successfully sent to the timer command queue. When the command is actually
  9602. + * processed will depend on the priority of the timer service/daemon task
  9603. + * relative to other tasks in the system, although the timers expiry time is
  9604. + * relative to when xTimerStartFromISR() is actually called. The timer
  9605. + * service/daemon task priority is set by the configTIMER_TASK_PRIORITY
  9606. + * configuration constant.
  9607. + *
  9608. + * Example usage:
  9609. + * @verbatim
  9610. + * // This scenario assumes xBacklightTimer has already been created. When a
  9611. + * // key is pressed, an LCD back-light is switched on. If 5 seconds pass
  9612. + * // without a key being pressed, then the LCD back-light is switched off. In
  9613. + * // this case, the timer is a one-shot timer, and unlike the example given for
  9614. + * // the xTimerReset() function, the key press event handler is an interrupt
  9615. + * // service routine.
  9616. + *
  9617. + * // The callback function assigned to the one-shot timer. In this case the
  9618. + * // parameter is not used.
  9619. + * void vBacklightTimerCallback( TimerHandle_t pxTimer )
  9620. + * {
  9621. + * // The timer expired, therefore 5 seconds must have passed since a key
  9622. + * // was pressed. Switch off the LCD back-light.
  9623. + * vSetBacklightState( BACKLIGHT_OFF );
  9624. + * }
  9625. + *
  9626. + * // The key press interrupt service routine.
  9627. + * void vKeyPressEventInterruptHandler( void )
  9628. + * {
  9629. + * BaseType_t xHigherPriorityTaskWoken = pdFALSE;
  9630. + *
  9631. + * // Ensure the LCD back-light is on, then restart the timer that is
  9632. + * // responsible for turning the back-light off after 5 seconds of
  9633. + * // key inactivity. This is an interrupt service routine so can only
  9634. + * // call FreeRTOS API functions that end in "FromISR".
  9635. + * vSetBacklightState( BACKLIGHT_ON );
  9636. + *
  9637. + * // xTimerStartFromISR() or xTimerResetFromISR() could be called here
  9638. + * // as both cause the timer to re-calculate its expiry time.
  9639. + * // xHigherPriorityTaskWoken was initialised to pdFALSE when it was
  9640. + * // declared (in this function).
  9641. + * if( xTimerStartFromISR( xBacklightTimer, &xHigherPriorityTaskWoken ) != pdPASS )
  9642. + * {
  9643. + * // The start command was not executed successfully. Take appropriate
  9644. + * // action here.
  9645. + * }
  9646. + *
  9647. + * // Perform the rest of the key processing here.
  9648. + *
  9649. + * // If xHigherPriorityTaskWoken equals pdTRUE, then a context switch
  9650. + * // should be performed. The syntax required to perform a context switch
  9651. + * // from inside an ISR varies from port to port, and from compiler to
  9652. + * // compiler. Inspect the demos for the port you are using to find the
  9653. + * // actual syntax required.
  9654. + * if( xHigherPriorityTaskWoken != pdFALSE )
  9655. + * {
  9656. + * // Call the interrupt safe yield function here (actual function
  9657. + * // depends on the FreeRTOS port being used).
  9658. + * }
  9659. + * }
  9660. + * @endverbatim
  9661. + */
  9662. +#define xTimerStartFromISR( xTimer, pxHigherPriorityTaskWoken ) \
  9663. + xTimerGenericCommand( ( xTimer ), tmrCOMMAND_START_FROM_ISR, ( xTaskGetTickCountFromISR() ), ( pxHigherPriorityTaskWoken ), 0U )
  9664. +
  9665. +/**
  9666. + * BaseType_t xTimerStopFromISR( TimerHandle_t xTimer,
  9667. + * BaseType_t *pxHigherPriorityTaskWoken );
  9668. + *
  9669. + * A version of xTimerStop() that can be called from an interrupt service
  9670. + * routine.
  9671. + *
  9672. + * @param xTimer The handle of the timer being stopped.
  9673. + *
  9674. + * @param pxHigherPriorityTaskWoken The timer service/daemon task spends most
  9675. + * of its time in the Blocked state, waiting for messages to arrive on the timer
  9676. + * command queue. Calling xTimerStopFromISR() writes a message to the timer
  9677. + * command queue, so has the potential to transition the timer service/daemon
  9678. + * task out of the Blocked state. If calling xTimerStopFromISR() causes the
  9679. + * timer service/daemon task to leave the Blocked state, and the timer service/
  9680. + * daemon task has a priority equal to or greater than the currently executing
  9681. + * task (the task that was interrupted), then *pxHigherPriorityTaskWoken will
  9682. + * get set to pdTRUE internally within the xTimerStopFromISR() function. If
  9683. + * xTimerStopFromISR() sets this value to pdTRUE then a context switch should
  9684. + * be performed before the interrupt exits.
  9685. + *
  9686. + * @return pdFAIL will be returned if the stop command could not be sent to
  9687. + * the timer command queue. pdPASS will be returned if the command was
  9688. + * successfully sent to the timer command queue. When the command is actually
  9689. + * processed will depend on the priority of the timer service/daemon task
  9690. + * relative to other tasks in the system. The timer service/daemon task
  9691. + * priority is set by the configTIMER_TASK_PRIORITY configuration constant.
  9692. + *
  9693. + * Example usage:
  9694. + * @verbatim
  9695. + * // This scenario assumes xTimer has already been created and started. When
  9696. + * // an interrupt occurs, the timer should be simply stopped.
  9697. + *
  9698. + * // The interrupt service routine that stops the timer.
  9699. + * void vAnExampleInterruptServiceRoutine( void )
  9700. + * {
  9701. + * BaseType_t xHigherPriorityTaskWoken = pdFALSE;
  9702. + *
  9703. + * // The interrupt has occurred - simply stop the timer.
  9704. + * // xHigherPriorityTaskWoken was set to pdFALSE where it was defined
  9705. + * // (within this function). As this is an interrupt service routine, only
  9706. + * // FreeRTOS API functions that end in "FromISR" can be used.
  9707. + * if( xTimerStopFromISR( xTimer, &xHigherPriorityTaskWoken ) != pdPASS )
  9708. + * {
  9709. + * // The stop command was not executed successfully. Take appropriate
  9710. + * // action here.
  9711. + * }
  9712. + *
  9713. + * // If xHigherPriorityTaskWoken equals pdTRUE, then a context switch
  9714. + * // should be performed. The syntax required to perform a context switch
  9715. + * // from inside an ISR varies from port to port, and from compiler to
  9716. + * // compiler. Inspect the demos for the port you are using to find the
  9717. + * // actual syntax required.
  9718. + * if( xHigherPriorityTaskWoken != pdFALSE )
  9719. + * {
  9720. + * // Call the interrupt safe yield function here (actual function
  9721. + * // depends on the FreeRTOS port being used).
  9722. + * }
  9723. + * }
  9724. + * @endverbatim
  9725. + */
  9726. +#define xTimerStopFromISR( xTimer, pxHigherPriorityTaskWoken ) \
  9727. + xTimerGenericCommand( ( xTimer ), tmrCOMMAND_STOP_FROM_ISR, 0, ( pxHigherPriorityTaskWoken ), 0U )
  9728. +
  9729. +/**
  9730. + * BaseType_t xTimerChangePeriodFromISR( TimerHandle_t xTimer,
  9731. + * TickType_t xNewPeriod,
  9732. + * BaseType_t *pxHigherPriorityTaskWoken );
  9733. + *
  9734. + * A version of xTimerChangePeriod() that can be called from an interrupt
  9735. + * service routine.
  9736. + *
  9737. + * @param xTimer The handle of the timer that is having its period changed.
  9738. + *
  9739. + * @param xNewPeriod The new period for xTimer. Timer periods are specified in
  9740. + * tick periods, so the constant portTICK_PERIOD_MS can be used to convert a time
  9741. + * that has been specified in milliseconds. For example, if the timer must
  9742. + * expire after 100 ticks, then xNewPeriod should be set to 100. Alternatively,
  9743. + * if the timer must expire after 500ms, then xNewPeriod can be set to
  9744. + * ( 500 / portTICK_PERIOD_MS ) provided configTICK_RATE_HZ is less than
  9745. + * or equal to 1000.
  9746. + *
  9747. + * @param pxHigherPriorityTaskWoken The timer service/daemon task spends most
  9748. + * of its time in the Blocked state, waiting for messages to arrive on the timer
  9749. + * command queue. Calling xTimerChangePeriodFromISR() writes a message to the
  9750. + * timer command queue, so has the potential to transition the timer service/
  9751. + * daemon task out of the Blocked state. If calling xTimerChangePeriodFromISR()
  9752. + * causes the timer service/daemon task to leave the Blocked state, and the
  9753. + * timer service/daemon task has a priority equal to or greater than the
  9754. + * currently executing task (the task that was interrupted), then
  9755. + * *pxHigherPriorityTaskWoken will get set to pdTRUE internally within the
  9756. + * xTimerChangePeriodFromISR() function. If xTimerChangePeriodFromISR() sets
  9757. + * this value to pdTRUE then a context switch should be performed before the
  9758. + * interrupt exits.
  9759. + *
  9760. + * @return pdFAIL will be returned if the command to change the timers period
  9761. + * could not be sent to the timer command queue. pdPASS will be returned if the
  9762. + * command was successfully sent to the timer command queue. When the command
  9763. + * is actually processed will depend on the priority of the timer service/daemon
  9764. + * task relative to other tasks in the system. The timer service/daemon task
  9765. + * priority is set by the configTIMER_TASK_PRIORITY configuration constant.
  9766. + *
  9767. + * Example usage:
  9768. + * @verbatim
  9769. + * // This scenario assumes xTimer has already been created and started. When
  9770. + * // an interrupt occurs, the period of xTimer should be changed to 500ms.
  9771. + *
  9772. + * // The interrupt service routine that changes the period of xTimer.
  9773. + * void vAnExampleInterruptServiceRoutine( void )
  9774. + * {
  9775. + * BaseType_t xHigherPriorityTaskWoken = pdFALSE;
  9776. + *
  9777. + * // The interrupt has occurred - change the period of xTimer to 500ms.
  9778. + * // xHigherPriorityTaskWoken was set to pdFALSE where it was defined
  9779. + * // (within this function). As this is an interrupt service routine, only
  9780. + * // FreeRTOS API functions that end in "FromISR" can be used.
  9781. + * if( xTimerChangePeriodFromISR( xTimer, &xHigherPriorityTaskWoken ) != pdPASS )
  9782. + * {
  9783. + * // The command to change the timers period was not executed
  9784. + * // successfully. Take appropriate action here.
  9785. + * }
  9786. + *
  9787. + * // If xHigherPriorityTaskWoken equals pdTRUE, then a context switch
  9788. + * // should be performed. The syntax required to perform a context switch
  9789. + * // from inside an ISR varies from port to port, and from compiler to
  9790. + * // compiler. Inspect the demos for the port you are using to find the
  9791. + * // actual syntax required.
  9792. + * if( xHigherPriorityTaskWoken != pdFALSE )
  9793. + * {
  9794. + * // Call the interrupt safe yield function here (actual function
  9795. + * // depends on the FreeRTOS port being used).
  9796. + * }
  9797. + * }
  9798. + * @endverbatim
  9799. + */
  9800. +#define xTimerChangePeriodFromISR( xTimer, xNewPeriod, pxHigherPriorityTaskWoken ) \
  9801. + xTimerGenericCommand( ( xTimer ), tmrCOMMAND_CHANGE_PERIOD_FROM_ISR, ( xNewPeriod ), ( pxHigherPriorityTaskWoken ), 0U )
  9802. +
  9803. +/**
  9804. + * BaseType_t xTimerResetFromISR( TimerHandle_t xTimer,
  9805. + * BaseType_t *pxHigherPriorityTaskWoken );
  9806. + *
  9807. + * A version of xTimerReset() that can be called from an interrupt service
  9808. + * routine.
  9809. + *
  9810. + * @param xTimer The handle of the timer that is to be started, reset, or
  9811. + * restarted.
  9812. + *
  9813. + * @param pxHigherPriorityTaskWoken The timer service/daemon task spends most
  9814. + * of its time in the Blocked state, waiting for messages to arrive on the timer
  9815. + * command queue. Calling xTimerResetFromISR() writes a message to the timer
  9816. + * command queue, so has the potential to transition the timer service/daemon
  9817. + * task out of the Blocked state. If calling xTimerResetFromISR() causes the
  9818. + * timer service/daemon task to leave the Blocked state, and the timer service/
  9819. + * daemon task has a priority equal to or greater than the currently executing
  9820. + * task (the task that was interrupted), then *pxHigherPriorityTaskWoken will
  9821. + * get set to pdTRUE internally within the xTimerResetFromISR() function. If
  9822. + * xTimerResetFromISR() sets this value to pdTRUE then a context switch should
  9823. + * be performed before the interrupt exits.
  9824. + *
  9825. + * @return pdFAIL will be returned if the reset command could not be sent to
  9826. + * the timer command queue. pdPASS will be returned if the command was
  9827. + * successfully sent to the timer command queue. When the command is actually
  9828. + * processed will depend on the priority of the timer service/daemon task
  9829. + * relative to other tasks in the system, although the timers expiry time is
  9830. + * relative to when xTimerResetFromISR() is actually called. The timer service/daemon
  9831. + * task priority is set by the configTIMER_TASK_PRIORITY configuration constant.
  9832. + *
  9833. + * Example usage:
  9834. + * @verbatim
  9835. + * // This scenario assumes xBacklightTimer has already been created. When a
  9836. + * // key is pressed, an LCD back-light is switched on. If 5 seconds pass
  9837. + * // without a key being pressed, then the LCD back-light is switched off. In
  9838. + * // this case, the timer is a one-shot timer, and unlike the example given for
  9839. + * // the xTimerReset() function, the key press event handler is an interrupt
  9840. + * // service routine.
  9841. + *
  9842. + * // The callback function assigned to the one-shot timer. In this case the
  9843. + * // parameter is not used.
  9844. + * void vBacklightTimerCallback( TimerHandle_t pxTimer )
  9845. + * {
  9846. + * // The timer expired, therefore 5 seconds must have passed since a key
  9847. + * // was pressed. Switch off the LCD back-light.
  9848. + * vSetBacklightState( BACKLIGHT_OFF );
  9849. + * }
  9850. + *
  9851. + * // The key press interrupt service routine.
  9852. + * void vKeyPressEventInterruptHandler( void )
  9853. + * {
  9854. + * BaseType_t xHigherPriorityTaskWoken = pdFALSE;
  9855. + *
  9856. + * // Ensure the LCD back-light is on, then reset the timer that is
  9857. + * // responsible for turning the back-light off after 5 seconds of
  9858. + * // key inactivity. This is an interrupt service routine so can only
  9859. + * // call FreeRTOS API functions that end in "FromISR".
  9860. + * vSetBacklightState( BACKLIGHT_ON );
  9861. + *
  9862. + * // xTimerStartFromISR() or xTimerResetFromISR() could be called here
  9863. + * // as both cause the timer to re-calculate its expiry time.
  9864. + * // xHigherPriorityTaskWoken was initialised to pdFALSE when it was
  9865. + * // declared (in this function).
  9866. + * if( xTimerResetFromISR( xBacklightTimer, &xHigherPriorityTaskWoken ) != pdPASS )
  9867. + * {
  9868. + * // The reset command was not executed successfully. Take appropriate
  9869. + * // action here.
  9870. + * }
  9871. + *
  9872. + * // Perform the rest of the key processing here.
  9873. + *
  9874. + * // If xHigherPriorityTaskWoken equals pdTRUE, then a context switch
  9875. + * // should be performed. The syntax required to perform a context switch
  9876. + * // from inside an ISR varies from port to port, and from compiler to
  9877. + * // compiler. Inspect the demos for the port you are using to find the
  9878. + * // actual syntax required.
  9879. + * if( xHigherPriorityTaskWoken != pdFALSE )
  9880. + * {
  9881. + * // Call the interrupt safe yield function here (actual function
  9882. + * // depends on the FreeRTOS port being used).
  9883. + * }
  9884. + * }
  9885. + * @endverbatim
  9886. + */
  9887. +#define xTimerResetFromISR( xTimer, pxHigherPriorityTaskWoken ) \
  9888. + xTimerGenericCommand( ( xTimer ), tmrCOMMAND_RESET_FROM_ISR, ( xTaskGetTickCountFromISR() ), ( pxHigherPriorityTaskWoken ), 0U )
  9889. +
  9890. +/**
  9891. + * const char * const pcTimerGetName( TimerHandle_t xTimer );
  9892. + *
  9893. + * Returns the name that was assigned to a timer when the timer was created.
  9894. + *
  9895. + * @param xTimer The handle of the timer being queried.
  9896. + *
  9897. + * @return The name assigned to the timer specified by the xTimer parameter.
  9898. + */
  9899. +const char * pcTimerGetName( TimerHandle_t xTimer );
  9900. +
  9901. +/**
  9902. + * void vTimerSetReloadMode( TimerHandle_t xTimer, const UBaseType_t uxAutoReload );
  9903. + *
  9904. + * Updates a timer to be either an auto-reload timer, in which case the timer
  9905. + * automatically resets itself each time it expires, or a one-shot timer, in
  9906. + * which case the timer will only expire once unless it is manually restarted.
  9907. + *
  9908. + * @param xTimer The handle of the timer being updated.
  9909. + *
  9910. + * @param uxAutoReload If uxAutoReload is set to pdTRUE then the timer will
  9911. + * expire repeatedly with a frequency set by the timer's period (see the
  9912. + * xTimerPeriodInTicks parameter of the xTimerCreate() API function). If
  9913. + * uxAutoReload is set to pdFALSE then the timer will be a one-shot timer and
  9914. + * enter the dormant state after it expires.
  9915. + */
  9916. +void vTimerSetReloadMode( TimerHandle_t xTimer,
  9917. + const UBaseType_t uxAutoReload );
  9918. +
  9919. +/**
  9920. + * UBaseType_t uxTimerGetReloadMode( TimerHandle_t xTimer );
  9921. + *
  9922. + * Queries a timer to determine if it is an auto-reload timer, in which case the timer
  9923. + * automatically resets itself each time it expires, or a one-shot timer, in
  9924. + * which case the timer will only expire once unless it is manually restarted.
  9925. + *
  9926. + * @param xTimer The handle of the timer being queried.
  9927. + *
  9928. + * @return If the timer is an auto-reload timer then pdTRUE is returned, otherwise
  9929. + * pdFALSE is returned.
  9930. + */
  9931. +UBaseType_t uxTimerGetReloadMode( TimerHandle_t xTimer );
  9932. +
  9933. +/**
  9934. + * TickType_t xTimerGetPeriod( TimerHandle_t xTimer );
  9935. + *
  9936. + * Returns the period of a timer.
  9937. + *
  9938. + * @param xTimer The handle of the timer being queried.
  9939. + *
  9940. + * @return The period of the timer in ticks.
  9941. + */
  9942. +TickType_t xTimerGetPeriod( TimerHandle_t xTimer );
  9943. +
  9944. +/**
  9945. + * TickType_t xTimerGetExpiryTime( TimerHandle_t xTimer );
  9946. + *
  9947. + * Returns the time in ticks at which the timer will expire. If this is less
  9948. + * than the current tick count then the expiry time has overflowed from the
  9949. + * current time.
  9950. + *
  9951. + * @param xTimer The handle of the timer being queried.
  9952. + *
  9953. + * @return If the timer is running then the time in ticks at which the timer
  9954. + * will next expire is returned. If the timer is not running then the return
  9955. + * value is undefined.
  9956. + */
  9957. +TickType_t xTimerGetExpiryTime( TimerHandle_t xTimer );
  9958. +
  9959. +/*
  9960. + * Functions beyond this part are not part of the public API and are intended
  9961. + * for use by the kernel only.
  9962. + */
  9963. +BaseType_t xTimerGenericCommand( TimerHandle_t xTimer,
  9964. + const BaseType_t xCommandID,
  9965. + const TickType_t xOptionalValue,
  9966. + BaseType_t * const pxHigherPriorityTaskWoken,
  9967. + const TickType_t xTicksToWait );
  9968. +
  9969. +/* *INDENT-OFF* */
  9970. +#ifdef __cplusplus
  9971. + }
  9972. +#endif
  9973. +/* *INDENT-ON* */
  9974. +#endif /* TIMERS_H */
  9975. diff --git a/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/list.c b/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/list.c
  9976. new file mode 100644
  9977. index 0000000000..5eec523162
  9978. --- /dev/null
  9979. +++ b/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/list.c
  9980. @@ -0,0 +1,213 @@
  9981. +/*
  9982. + * FreeRTOS Kernel V10.4.3
  9983. + * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  9984. + *
  9985. + * Permission is hereby granted, free of charge, to any person obtaining a copy of
  9986. + * this software and associated documentation files (the "Software"), to deal in
  9987. + * the Software without restriction, including without limitation the rights to
  9988. + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  9989. + * the Software, and to permit persons to whom the Software is furnished to do so,
  9990. + * subject to the following conditions:
  9991. + *
  9992. + * The above copyright notice and this permission notice shall be included in all
  9993. + * copies or substantial portions of the Software.
  9994. + *
  9995. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  9996. + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  9997. + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  9998. + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  9999. + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  10000. + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  10001. + *
  10002. + * https://www.FreeRTOS.org
  10003. + * https://github.com/FreeRTOS
  10004. + *
  10005. + */
  10006. +
  10007. +
  10008. +#include <stdlib.h>
  10009. +
  10010. +/* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining
  10011. + * all the API functions to use the MPU wrappers. That should only be done when
  10012. + * task.h is included from an application file. */
  10013. +#define MPU_WRAPPERS_INCLUDED_FROM_API_FILE
  10014. +
  10015. +#include "FreeRTOS.h"
  10016. +#include "list.h"
  10017. +
  10018. +/* Lint e9021, e961 and e750 are suppressed as a MISRA exception justified
  10019. + * because the MPU ports require MPU_WRAPPERS_INCLUDED_FROM_API_FILE to be
  10020. + * defined for the header files above, but not in this file, in order to
  10021. + * generate the correct privileged Vs unprivileged linkage and placement. */
  10022. +#undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE /*lint !e961 !e750 !e9021. */
  10023. +
  10024. +/*-----------------------------------------------------------
  10025. +* PUBLIC LIST API documented in list.h
  10026. +*----------------------------------------------------------*/
  10027. +
  10028. +void vListInitialise( List_t * const pxList )
  10029. +{
  10030. + /* The list structure contains a list item which is used to mark the
  10031. + * end of the list. To initialise the list the list end is inserted
  10032. + * as the only list entry. */
  10033. + pxList->pxIndex = ( ListItem_t * ) &( pxList->xListEnd ); /*lint !e826 !e740 !e9087 The mini list structure is used as the list end to save RAM. This is checked and valid. */
  10034. +
  10035. + /* The list end value is the highest possible value in the list to
  10036. + * ensure it remains at the end of the list. */
  10037. + pxList->xListEnd.xItemValue = portMAX_DELAY;
  10038. +
  10039. + /* The list end next and previous pointers point to itself so we know
  10040. + * when the list is empty. */
  10041. + pxList->xListEnd.pxNext = ( ListItem_t * ) &( pxList->xListEnd ); /*lint !e826 !e740 !e9087 The mini list structure is used as the list end to save RAM. This is checked and valid. */
  10042. + pxList->xListEnd.pxPrevious = ( ListItem_t * ) &( pxList->xListEnd ); /*lint !e826 !e740 !e9087 The mini list structure is used as the list end to save RAM. This is checked and valid. */
  10043. +
  10044. + pxList->uxNumberOfItems = ( UBaseType_t ) 0U;
  10045. +
  10046. + /* Write known values into the list if
  10047. + * configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */
  10048. + listSET_LIST_INTEGRITY_CHECK_1_VALUE( pxList );
  10049. + listSET_LIST_INTEGRITY_CHECK_2_VALUE( pxList );
  10050. +}
  10051. +/*-----------------------------------------------------------*/
  10052. +
  10053. +void vListInitialiseItem( ListItem_t * const pxItem )
  10054. +{
  10055. + /* Make sure the list item is not recorded as being on a list. */
  10056. + pxItem->pxContainer = NULL;
  10057. +
  10058. + /* Write known values into the list item if
  10059. + * configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */
  10060. + listSET_FIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE( pxItem );
  10061. + listSET_SECOND_LIST_ITEM_INTEGRITY_CHECK_VALUE( pxItem );
  10062. +}
  10063. +/*-----------------------------------------------------------*/
  10064. +
  10065. +void vListInsertEnd( List_t * const pxList,
  10066. + ListItem_t * const pxNewListItem )
  10067. +{
  10068. + ListItem_t * const pxIndex = pxList->pxIndex;
  10069. +
  10070. + /* Only effective when configASSERT() is also defined, these tests may catch
  10071. + * the list data structures being overwritten in memory. They will not catch
  10072. + * data errors caused by incorrect configuration or use of FreeRTOS. */
  10073. + listTEST_LIST_INTEGRITY( pxList );
  10074. + listTEST_LIST_ITEM_INTEGRITY( pxNewListItem );
  10075. +
  10076. + /* Insert a new list item into pxList, but rather than sort the list,
  10077. + * makes the new list item the last item to be removed by a call to
  10078. + * listGET_OWNER_OF_NEXT_ENTRY(). */
  10079. + pxNewListItem->pxNext = pxIndex;
  10080. + pxNewListItem->pxPrevious = pxIndex->pxPrevious;
  10081. +
  10082. + /* Only used during decision coverage testing. */
  10083. + mtCOVERAGE_TEST_DELAY();
  10084. +
  10085. + pxIndex->pxPrevious->pxNext = pxNewListItem;
  10086. + pxIndex->pxPrevious = pxNewListItem;
  10087. +
  10088. + /* Remember which list the item is in. */
  10089. + pxNewListItem->pxContainer = pxList;
  10090. +
  10091. + ( pxList->uxNumberOfItems )++;
  10092. +}
  10093. +/*-----------------------------------------------------------*/
  10094. +
  10095. +void vListInsert( List_t * const pxList,
  10096. + ListItem_t * const pxNewListItem )
  10097. +{
  10098. + ListItem_t * pxIterator;
  10099. + const TickType_t xValueOfInsertion = pxNewListItem->xItemValue;
  10100. +
  10101. + /* Only effective when configASSERT() is also defined, these tests may catch
  10102. + * the list data structures being overwritten in memory. They will not catch
  10103. + * data errors caused by incorrect configuration or use of FreeRTOS. */
  10104. + listTEST_LIST_INTEGRITY( pxList );
  10105. + listTEST_LIST_ITEM_INTEGRITY( pxNewListItem );
  10106. +
  10107. + /* Insert the new list item into the list, sorted in xItemValue order.
  10108. + *
  10109. + * If the list already contains a list item with the same item value then the
  10110. + * new list item should be placed after it. This ensures that TCBs which are
  10111. + * stored in ready lists (all of which have the same xItemValue value) get a
  10112. + * share of the CPU. However, if the xItemValue is the same as the back marker
  10113. + * the iteration loop below will not end. Therefore the value is checked
  10114. + * first, and the algorithm slightly modified if necessary. */
  10115. + if( xValueOfInsertion == portMAX_DELAY )
  10116. + {
  10117. + pxIterator = pxList->xListEnd.pxPrevious;
  10118. + }
  10119. + else
  10120. + {
  10121. + /* *** NOTE ***********************************************************
  10122. + * If you find your application is crashing here then likely causes are
  10123. + * listed below. In addition see https://www.FreeRTOS.org/FAQHelp.html for
  10124. + * more tips, and ensure configASSERT() is defined!
  10125. + * https://www.FreeRTOS.org/a00110.html#configASSERT
  10126. + *
  10127. + * 1) Stack overflow -
  10128. + * see https://www.FreeRTOS.org/Stacks-and-stack-overflow-checking.html
  10129. + * 2) Incorrect interrupt priority assignment, especially on Cortex-M
  10130. + * parts where numerically high priority values denote low actual
  10131. + * interrupt priorities, which can seem counter intuitive. See
  10132. + * https://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html and the definition
  10133. + * of configMAX_SYSCALL_INTERRUPT_PRIORITY on
  10134. + * https://www.FreeRTOS.org/a00110.html
  10135. + * 3) Calling an API function from within a critical section or when
  10136. + * the scheduler is suspended, or calling an API function that does
  10137. + * not end in "FromISR" from an interrupt.
  10138. + * 4) Using a queue or semaphore before it has been initialised or
  10139. + * before the scheduler has been started (are interrupts firing
  10140. + * before vTaskStartScheduler() has been called?).
  10141. + * 5) If the FreeRTOS port supports interrupt nesting then ensure that
  10142. + * the priority of the tick interrupt is at or below
  10143. + * configMAX_SYSCALL_INTERRUPT_PRIORITY.
  10144. + **********************************************************************/
  10145. +
  10146. + for( pxIterator = ( ListItem_t * ) &( pxList->xListEnd ); pxIterator->pxNext->xItemValue <= xValueOfInsertion; pxIterator = pxIterator->pxNext ) /*lint !e826 !e740 !e9087 The mini list structure is used as the list end to save RAM. This is checked and valid. *//*lint !e440 The iterator moves to a different value, not xValueOfInsertion. */
  10147. + {
  10148. + /* There is nothing to do here, just iterating to the wanted
  10149. + * insertion position. */
  10150. + }
  10151. + }
  10152. +
  10153. + pxNewListItem->pxNext = pxIterator->pxNext;
  10154. + pxNewListItem->pxNext->pxPrevious = pxNewListItem;
  10155. + pxNewListItem->pxPrevious = pxIterator;
  10156. + pxIterator->pxNext = pxNewListItem;
  10157. +
  10158. + /* Remember which list the item is in. This allows fast removal of the
  10159. + * item later. */
  10160. + pxNewListItem->pxContainer = pxList;
  10161. +
  10162. + ( pxList->uxNumberOfItems )++;
  10163. +}
  10164. +/*-----------------------------------------------------------*/
  10165. +
  10166. +UBaseType_t uxListRemove( ListItem_t * const pxItemToRemove )
  10167. +{
  10168. +/* The list item knows which list it is in. Obtain the list from the list
  10169. + * item. */
  10170. + List_t * const pxList = pxItemToRemove->pxContainer;
  10171. +
  10172. + pxItemToRemove->pxNext->pxPrevious = pxItemToRemove->pxPrevious;
  10173. + pxItemToRemove->pxPrevious->pxNext = pxItemToRemove->pxNext;
  10174. +
  10175. + /* Only used during decision coverage testing. */
  10176. + mtCOVERAGE_TEST_DELAY();
  10177. +
  10178. + /* Make sure the index is left pointing to a valid item. */
  10179. + if( pxList->pxIndex == pxItemToRemove )
  10180. + {
  10181. + pxList->pxIndex = pxItemToRemove->pxPrevious;
  10182. + }
  10183. + else
  10184. + {
  10185. + mtCOVERAGE_TEST_MARKER();
  10186. + }
  10187. +
  10188. + pxItemToRemove->pxContainer = NULL;
  10189. + ( pxList->uxNumberOfItems )--;
  10190. +
  10191. + return pxList->uxNumberOfItems;
  10192. +}
  10193. +/*-----------------------------------------------------------*/
  10194. diff --git a/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/port/MemMang/heap_1.c b/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/port/MemMang/heap_1.c
  10195. new file mode 100644
  10196. index 0000000000..cebc240892
  10197. --- /dev/null
  10198. +++ b/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/port/MemMang/heap_1.c
  10199. @@ -0,0 +1,145 @@
  10200. +/*
  10201. + * FreeRTOS Kernel V10.4.6
  10202. + * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  10203. + *
  10204. + * SPDX-License-Identifier: MIT
  10205. + *
  10206. + * Permission is hereby granted, free of charge, to any person obtaining a copy of
  10207. + * this software and associated documentation files (the "Software"), to deal in
  10208. + * the Software without restriction, including without limitation the rights to
  10209. + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  10210. + * the Software, and to permit persons to whom the Software is furnished to do so,
  10211. + * subject to the following conditions:
  10212. + *
  10213. + * The above copyright notice and this permission notice shall be included in all
  10214. + * copies or substantial portions of the Software.
  10215. + *
  10216. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  10217. + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  10218. + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  10219. + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  10220. + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  10221. + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  10222. + *
  10223. + * https://www.FreeRTOS.org
  10224. + * https://github.com/FreeRTOS
  10225. + *
  10226. + */
  10227. +
  10228. +
  10229. +/*
  10230. + * The simplest possible implementation of pvPortMalloc(). Note that this
  10231. + * implementation does NOT allow allocated memory to be freed again.
  10232. + *
  10233. + * See heap_2.c, heap_3.c and heap_4.c for alternative implementations, and the
  10234. + * memory management pages of https://www.FreeRTOS.org for more information.
  10235. + */
  10236. +#include <stdlib.h>
  10237. +
  10238. +#include "FreeRTOS.h"
  10239. +#include "task.h"
  10240. +
  10241. +#if ( configSUPPORT_DYNAMIC_ALLOCATION == 0 )
  10242. + #error This file must not be used if configSUPPORT_DYNAMIC_ALLOCATION is 0
  10243. +#endif
  10244. +
  10245. +/* A few bytes might be lost to byte aligning the heap start address. */
  10246. +#define configADJUSTED_HEAP_SIZE ( configTOTAL_HEAP_SIZE - portBYTE_ALIGNMENT )
  10247. +
  10248. +/* Allocate the memory for the heap. */
  10249. +#if ( configAPPLICATION_ALLOCATED_HEAP == 1 )
  10250. +
  10251. +/* The application writer has already defined the array used for the RTOS
  10252. +* heap - probably so it can be placed in a special segment or address. */
  10253. + extern uint8_t ucHeap[ configTOTAL_HEAP_SIZE ];
  10254. +#else
  10255. + static uint8_t ucHeap[ configTOTAL_HEAP_SIZE ];
  10256. +#endif /* configAPPLICATION_ALLOCATED_HEAP */
  10257. +
  10258. +/* Index into the ucHeap array. */
  10259. +static size_t xNextFreeByte = ( size_t ) 0;
  10260. +
  10261. +/*-----------------------------------------------------------*/
  10262. +
  10263. +void * pvPortMalloc( size_t xWantedSize )
  10264. +{
  10265. + void * pvReturn = NULL;
  10266. + static uint8_t * pucAlignedHeap = NULL;
  10267. +
  10268. + /* Ensure that blocks are always aligned. */
  10269. + #if ( portBYTE_ALIGNMENT != 1 )
  10270. + {
  10271. + if( xWantedSize & portBYTE_ALIGNMENT_MASK )
  10272. + {
  10273. + /* Byte alignment required. Check for overflow. */
  10274. + if ( (xWantedSize + ( portBYTE_ALIGNMENT - ( xWantedSize & portBYTE_ALIGNMENT_MASK ) )) > xWantedSize )
  10275. + {
  10276. + xWantedSize += ( portBYTE_ALIGNMENT - ( xWantedSize & portBYTE_ALIGNMENT_MASK ) );
  10277. + }
  10278. + else
  10279. + {
  10280. + xWantedSize = 0;
  10281. + }
  10282. + }
  10283. + }
  10284. + #endif
  10285. +
  10286. + vTaskSuspendAll();
  10287. + {
  10288. + if( pucAlignedHeap == NULL )
  10289. + {
  10290. + /* Ensure the heap starts on a correctly aligned boundary. */
  10291. + pucAlignedHeap = ( uint8_t * ) ( ( ( portPOINTER_SIZE_TYPE ) & ucHeap[ portBYTE_ALIGNMENT - 1 ] ) & ( ~( ( portPOINTER_SIZE_TYPE ) portBYTE_ALIGNMENT_MASK ) ) );
  10292. + }
  10293. +
  10294. + /* Check there is enough room left for the allocation and. */
  10295. + if( ( xWantedSize > 0 ) && /* valid size */
  10296. + ( ( xNextFreeByte + xWantedSize ) < configADJUSTED_HEAP_SIZE ) &&
  10297. + ( ( xNextFreeByte + xWantedSize ) > xNextFreeByte ) ) /* Check for overflow. */
  10298. + {
  10299. + /* Return the next free byte then increment the index past this
  10300. + * block. */
  10301. + pvReturn = pucAlignedHeap + xNextFreeByte;
  10302. + xNextFreeByte += xWantedSize;
  10303. + }
  10304. +
  10305. + }
  10306. + ( void ) xTaskResumeAll();
  10307. +
  10308. + #if ( configUSE_MALLOC_FAILED_HOOK == 1 )
  10309. + {
  10310. + if( pvReturn == NULL )
  10311. + {
  10312. + extern void vApplicationMallocFailedHook( void );
  10313. + vApplicationMallocFailedHook();
  10314. + }
  10315. + }
  10316. + #endif
  10317. +
  10318. + return pvReturn;
  10319. +}
  10320. +/*-----------------------------------------------------------*/
  10321. +
  10322. +void vPortFree( void * pv )
  10323. +{
  10324. + /* Memory cannot be freed using this scheme. See heap_2.c, heap_3.c and
  10325. + * heap_4.c for alternative implementations, and the memory management pages of
  10326. + * https://www.FreeRTOS.org for more information. */
  10327. + ( void ) pv;
  10328. +
  10329. + /* Force an assert as it is invalid to call this function. */
  10330. + configASSERT( pv == NULL );
  10331. +}
  10332. +/*-----------------------------------------------------------*/
  10333. +
  10334. +void vPortInitialiseBlocks( void )
  10335. +{
  10336. + /* Only required when static memory is not cleared. */
  10337. + xNextFreeByte = ( size_t ) 0;
  10338. +}
  10339. +/*-----------------------------------------------------------*/
  10340. +
  10341. +size_t xPortGetFreeHeapSize( void )
  10342. +{
  10343. + return( configADJUSTED_HEAP_SIZE - xNextFreeByte );
  10344. +}
  10345. diff --git a/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/port/MemMang/heap_2.c b/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/port/MemMang/heap_2.c
  10346. new file mode 100644
  10347. index 0000000000..00a68b26b4
  10348. --- /dev/null
  10349. +++ b/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/port/MemMang/heap_2.c
  10350. @@ -0,0 +1,277 @@
  10351. +/*
  10352. + * FreeRTOS Kernel V10.4.6
  10353. + * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  10354. + *
  10355. + * SPDX-License-Identifier: MIT
  10356. + *
  10357. + * Permission is hereby granted, free of charge, to any person obtaining a copy of
  10358. + * this software and associated documentation files (the "Software"), to deal in
  10359. + * the Software without restriction, including without limitation the rights to
  10360. + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  10361. + * the Software, and to permit persons to whom the Software is furnished to do so,
  10362. + * subject to the following conditions:
  10363. + *
  10364. + * The above copyright notice and this permission notice shall be included in all
  10365. + * copies or substantial portions of the Software.
  10366. + *
  10367. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  10368. + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  10369. + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  10370. + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  10371. + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  10372. + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  10373. + *
  10374. + * https://www.FreeRTOS.org
  10375. + * https://github.com/FreeRTOS
  10376. + *
  10377. + */
  10378. +
  10379. +/*
  10380. + * A sample implementation of pvPortMalloc() and vPortFree() that permits
  10381. + * allocated blocks to be freed, but does not combine adjacent free blocks
  10382. + * into a single larger block (and so will fragment memory). See heap_4.c for
  10383. + * an equivalent that does combine adjacent blocks into single larger blocks.
  10384. + *
  10385. + * See heap_1.c, heap_3.c and heap_4.c for alternative implementations, and the
  10386. + * memory management pages of https://www.FreeRTOS.org for more information.
  10387. + */
  10388. +#include <stdlib.h>
  10389. +
  10390. +#include "FreeRTOS.h"
  10391. +#include "task.h"
  10392. +
  10393. +#if ( configSUPPORT_DYNAMIC_ALLOCATION == 0 )
  10394. + #error This file must not be used if configSUPPORT_DYNAMIC_ALLOCATION is 0
  10395. +#endif
  10396. +
  10397. +/* A few bytes might be lost to byte aligning the heap start address. */
  10398. +#define configADJUSTED_HEAP_SIZE ( configTOTAL_HEAP_SIZE - portBYTE_ALIGNMENT )
  10399. +
  10400. +/*
  10401. + * Initialises the heap structures before their first use.
  10402. + */
  10403. +static void prvHeapInit( void );
  10404. +
  10405. +/* Allocate the memory for the heap. */
  10406. +#if ( configAPPLICATION_ALLOCATED_HEAP == 1 )
  10407. +
  10408. +/* The application writer has already defined the array used for the RTOS
  10409. +* heap - probably so it can be placed in a special segment or address. */
  10410. + extern uint8_t ucHeap[ configTOTAL_HEAP_SIZE ];
  10411. +#else
  10412. + static uint8_t ucHeap[ configTOTAL_HEAP_SIZE ];
  10413. +#endif /* configAPPLICATION_ALLOCATED_HEAP */
  10414. +
  10415. +
  10416. +/* Define the linked list structure. This is used to link free blocks in order
  10417. + * of their size. */
  10418. +typedef struct A_BLOCK_LINK
  10419. +{
  10420. + struct A_BLOCK_LINK * pxNextFreeBlock; /*<< The next free block in the list. */
  10421. + size_t xBlockSize; /*<< The size of the free block. */
  10422. +} BlockLink_t;
  10423. +
  10424. +
  10425. +static const uint16_t heapSTRUCT_SIZE = ( ( sizeof( BlockLink_t ) + ( portBYTE_ALIGNMENT - 1 ) ) & ~portBYTE_ALIGNMENT_MASK );
  10426. +#define heapMINIMUM_BLOCK_SIZE ( ( size_t ) ( heapSTRUCT_SIZE * 2 ) )
  10427. +
  10428. +/* Create a couple of list links to mark the start and end of the list. */
  10429. +static BlockLink_t xStart, xEnd;
  10430. +
  10431. +/* Keeps track of the number of free bytes remaining, but says nothing about
  10432. + * fragmentation. */
  10433. +static size_t xFreeBytesRemaining = configADJUSTED_HEAP_SIZE;
  10434. +
  10435. +/* STATIC FUNCTIONS ARE DEFINED AS MACROS TO MINIMIZE THE FUNCTION CALL DEPTH. */
  10436. +
  10437. +/*
  10438. + * Insert a block into the list of free blocks - which is ordered by size of
  10439. + * the block. Small blocks at the start of the list and large blocks at the end
  10440. + * of the list.
  10441. + */
  10442. +#define prvInsertBlockIntoFreeList( pxBlockToInsert ) \
  10443. + { \
  10444. + BlockLink_t * pxIterator; \
  10445. + size_t xBlockSize; \
  10446. + \
  10447. + xBlockSize = pxBlockToInsert->xBlockSize; \
  10448. + \
  10449. + /* Iterate through the list until a block is found that has a larger size */ \
  10450. + /* than the block we are inserting. */ \
  10451. + for( pxIterator = &xStart; pxIterator->pxNextFreeBlock->xBlockSize < xBlockSize; pxIterator = pxIterator->pxNextFreeBlock ) \
  10452. + { \
  10453. + /* There is nothing to do here - just iterate to the correct position. */ \
  10454. + } \
  10455. + \
  10456. + /* Update the list to include the block being inserted in the correct */ \
  10457. + /* position. */ \
  10458. + pxBlockToInsert->pxNextFreeBlock = pxIterator->pxNextFreeBlock; \
  10459. + pxIterator->pxNextFreeBlock = pxBlockToInsert; \
  10460. + }
  10461. +/*-----------------------------------------------------------*/
  10462. +
  10463. +void * pvPortMalloc( size_t xWantedSize )
  10464. +{
  10465. + BlockLink_t * pxBlock, * pxPreviousBlock, * pxNewBlockLink;
  10466. + static BaseType_t xHeapHasBeenInitialised = pdFALSE;
  10467. + void * pvReturn = NULL;
  10468. +
  10469. + vTaskSuspendAll();
  10470. + {
  10471. + /* If this is the first call to malloc then the heap will require
  10472. + * initialisation to setup the list of free blocks. */
  10473. + if( xHeapHasBeenInitialised == pdFALSE )
  10474. + {
  10475. + prvHeapInit();
  10476. + xHeapHasBeenInitialised = pdTRUE;
  10477. + }
  10478. +
  10479. + /* The wanted size must be increased so it can contain a BlockLink_t
  10480. + * structure in addition to the requested amount of bytes. */
  10481. + if( ( xWantedSize > 0 ) &&
  10482. + ( ( xWantedSize + heapSTRUCT_SIZE ) > xWantedSize ) ) /* Overflow check */
  10483. + {
  10484. + xWantedSize += heapSTRUCT_SIZE;
  10485. +
  10486. + /* Byte alignment required. Check for overflow. */
  10487. + if( ( xWantedSize + ( portBYTE_ALIGNMENT - ( xWantedSize & portBYTE_ALIGNMENT_MASK ) ) )
  10488. + > xWantedSize )
  10489. + {
  10490. + xWantedSize += ( portBYTE_ALIGNMENT - ( xWantedSize & portBYTE_ALIGNMENT_MASK ) );
  10491. + configASSERT( ( xWantedSize & portBYTE_ALIGNMENT_MASK ) == 0 );
  10492. + }
  10493. + else
  10494. + {
  10495. + xWantedSize = 0;
  10496. + }
  10497. + }
  10498. + else
  10499. + {
  10500. + xWantedSize = 0;
  10501. + }
  10502. +
  10503. +
  10504. + if( ( xWantedSize > 0 ) && ( xWantedSize <= xFreeBytesRemaining ) )
  10505. + {
  10506. + /* Blocks are stored in byte order - traverse the list from the start
  10507. + * (smallest) block until one of adequate size is found. */
  10508. + pxPreviousBlock = &xStart;
  10509. + pxBlock = xStart.pxNextFreeBlock;
  10510. +
  10511. + while( ( pxBlock->xBlockSize < xWantedSize ) && ( pxBlock->pxNextFreeBlock != NULL ) )
  10512. + {
  10513. + pxPreviousBlock = pxBlock;
  10514. + pxBlock = pxBlock->pxNextFreeBlock;
  10515. + }
  10516. +
  10517. + /* If we found the end marker then a block of adequate size was not found. */
  10518. + if( pxBlock != &xEnd )
  10519. + {
  10520. + /* Return the memory space - jumping over the BlockLink_t structure
  10521. + * at its start. */
  10522. + pvReturn = ( void * ) ( ( ( uint8_t * ) pxPreviousBlock->pxNextFreeBlock ) + heapSTRUCT_SIZE );
  10523. +
  10524. + /* This block is being returned for use so must be taken out of the
  10525. + * list of free blocks. */
  10526. + pxPreviousBlock->pxNextFreeBlock = pxBlock->pxNextFreeBlock;
  10527. +
  10528. + /* If the block is larger than required it can be split into two. */
  10529. + if( ( pxBlock->xBlockSize - xWantedSize ) > heapMINIMUM_BLOCK_SIZE )
  10530. + {
  10531. + /* This block is to be split into two. Create a new block
  10532. + * following the number of bytes requested. The void cast is
  10533. + * used to prevent byte alignment warnings from the compiler. */
  10534. + pxNewBlockLink = ( void * ) ( ( ( uint8_t * ) pxBlock ) + xWantedSize );
  10535. +
  10536. + /* Calculate the sizes of two blocks split from the single
  10537. + * block. */
  10538. + pxNewBlockLink->xBlockSize = pxBlock->xBlockSize - xWantedSize;
  10539. + pxBlock->xBlockSize = xWantedSize;
  10540. +
  10541. + /* Insert the new block into the list of free blocks. */
  10542. + prvInsertBlockIntoFreeList( ( pxNewBlockLink ) );
  10543. + }
  10544. +
  10545. + xFreeBytesRemaining -= pxBlock->xBlockSize;
  10546. + }
  10547. + }
  10548. +
  10549. + }
  10550. + ( void ) xTaskResumeAll();
  10551. +
  10552. + #if ( configUSE_MALLOC_FAILED_HOOK == 1 )
  10553. + {
  10554. + if( pvReturn == NULL )
  10555. + {
  10556. + extern void vApplicationMallocFailedHook( void );
  10557. + vApplicationMallocFailedHook();
  10558. + }
  10559. + }
  10560. + #endif
  10561. +
  10562. + return pvReturn;
  10563. +}
  10564. +/*-----------------------------------------------------------*/
  10565. +
  10566. +void vPortFree( void * pv )
  10567. +{
  10568. + uint8_t * puc = ( uint8_t * ) pv;
  10569. + BlockLink_t * pxLink;
  10570. +
  10571. + if( pv != NULL )
  10572. + {
  10573. + /* The memory being freed will have an BlockLink_t structure immediately
  10574. + * before it. */
  10575. + puc -= heapSTRUCT_SIZE;
  10576. +
  10577. + /* This unexpected casting is to keep some compilers from issuing
  10578. + * byte alignment warnings. */
  10579. + pxLink = ( void * ) puc;
  10580. +
  10581. + vTaskSuspendAll();
  10582. + {
  10583. + /* Add this block to the list of free blocks. */
  10584. + prvInsertBlockIntoFreeList( ( ( BlockLink_t * ) pxLink ) );
  10585. + xFreeBytesRemaining += pxLink->xBlockSize;
  10586. + }
  10587. + ( void ) xTaskResumeAll();
  10588. + }
  10589. +}
  10590. +/*-----------------------------------------------------------*/
  10591. +
  10592. +size_t xPortGetFreeHeapSize( void )
  10593. +{
  10594. + return xFreeBytesRemaining;
  10595. +}
  10596. +/*-----------------------------------------------------------*/
  10597. +
  10598. +void vPortInitialiseBlocks( void )
  10599. +{
  10600. + /* This just exists to keep the linker quiet. */
  10601. +}
  10602. +/*-----------------------------------------------------------*/
  10603. +
  10604. +static void prvHeapInit( void )
  10605. +{
  10606. + BlockLink_t * pxFirstFreeBlock;
  10607. + uint8_t * pucAlignedHeap;
  10608. +
  10609. + /* Ensure the heap starts on a correctly aligned boundary. */
  10610. + pucAlignedHeap = ( uint8_t * ) ( ( ( portPOINTER_SIZE_TYPE ) & ucHeap[ portBYTE_ALIGNMENT - 1 ] ) & ( ~( ( portPOINTER_SIZE_TYPE ) portBYTE_ALIGNMENT_MASK ) ) );
  10611. +
  10612. + /* xStart is used to hold a pointer to the first item in the list of free
  10613. + * blocks. The void cast is used to prevent compiler warnings. */
  10614. + xStart.pxNextFreeBlock = ( void * ) pucAlignedHeap;
  10615. + xStart.xBlockSize = ( size_t ) 0;
  10616. +
  10617. + /* xEnd is used to mark the end of the list of free blocks. */
  10618. + xEnd.xBlockSize = configADJUSTED_HEAP_SIZE;
  10619. + xEnd.pxNextFreeBlock = NULL;
  10620. +
  10621. + /* To start with there is a single free block that is sized to take up the
  10622. + * entire heap space. */
  10623. + pxFirstFreeBlock = ( void * ) pucAlignedHeap;
  10624. + pxFirstFreeBlock->xBlockSize = configADJUSTED_HEAP_SIZE;
  10625. + pxFirstFreeBlock->pxNextFreeBlock = &xEnd;
  10626. +}
  10627. +/*-----------------------------------------------------------*/
  10628. diff --git a/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/port/MemMang/heap_3.c b/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/port/MemMang/heap_3.c
  10629. new file mode 100644
  10630. index 0000000000..7cdd9bb18a
  10631. --- /dev/null
  10632. +++ b/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/port/MemMang/heap_3.c
  10633. @@ -0,0 +1,78 @@
  10634. +/*
  10635. + * FreeRTOS Kernel V10.4.6
  10636. + * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  10637. + *
  10638. + * SPDX-License-Identifier: MIT
  10639. + *
  10640. + * Permission is hereby granted, free of charge, to any person obtaining a copy of
  10641. + * this software and associated documentation files (the "Software"), to deal in
  10642. + * the Software without restriction, including without limitation the rights to
  10643. + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  10644. + * the Software, and to permit persons to whom the Software is furnished to do so,
  10645. + * subject to the following conditions:
  10646. + *
  10647. + * The above copyright notice and this permission notice shall be included in all
  10648. + * copies or substantial portions of the Software.
  10649. + *
  10650. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  10651. + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  10652. + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  10653. + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  10654. + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  10655. + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  10656. + *
  10657. + * https://www.FreeRTOS.org
  10658. + * https://github.com/FreeRTOS
  10659. + *
  10660. + */
  10661. +
  10662. +
  10663. +/*
  10664. + * Implementation of pvPortMalloc() and vPortFree() that relies on the
  10665. + * compilers own malloc() and free() implementations.
  10666. + *
  10667. + * This file can only be used if the linker is configured to to generate
  10668. + * a heap memory area.
  10669. + *
  10670. + * See heap_1.c, heap_2.c and heap_4.c for alternative implementations, and the
  10671. + * memory management pages of https://www.FreeRTOS.org for more information.
  10672. + */
  10673. +
  10674. +#include <stdlib.h>
  10675. +
  10676. +#include "FreeRTOS.h"
  10677. +#include "task.h"
  10678. +
  10679. +#if ( configSUPPORT_DYNAMIC_ALLOCATION == 0 )
  10680. + #error This file must not be used if configSUPPORT_DYNAMIC_ALLOCATION is 0
  10681. +#endif
  10682. +
  10683. +/*-----------------------------------------------------------*/
  10684. +
  10685. +void * pvPortMalloc( size_t xWantedSize )
  10686. +{
  10687. + void * pvReturn;
  10688. +
  10689. + pvReturn = RT_KERNEL_MALLOC( xWantedSize );
  10690. +
  10691. + #if ( configUSE_MALLOC_FAILED_HOOK == 1 )
  10692. + {
  10693. + if( pvReturn == NULL )
  10694. + {
  10695. + extern void vApplicationMallocFailedHook( void );
  10696. + vApplicationMallocFailedHook();
  10697. + }
  10698. + }
  10699. + #endif
  10700. +
  10701. + return pvReturn;
  10702. +}
  10703. +/*-----------------------------------------------------------*/
  10704. +
  10705. +void vPortFree( void * pv )
  10706. +{
  10707. + if( pv )
  10708. + {
  10709. + RT_KERNEL_FREE( pv );
  10710. + }
  10711. +}
  10712. diff --git a/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/port/MemMang/heap_4.c b/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/port/MemMang/heap_4.c
  10713. new file mode 100644
  10714. index 0000000000..53536b7025
  10715. --- /dev/null
  10716. +++ b/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/port/MemMang/heap_4.c
  10717. @@ -0,0 +1,447 @@
  10718. +/*
  10719. + * FreeRTOS Kernel V10.4.6
  10720. + * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  10721. + *
  10722. + * SPDX-License-Identifier: MIT
  10723. + *
  10724. + * Permission is hereby granted, free of charge, to any person obtaining a copy of
  10725. + * this software and associated documentation files (the "Software"), to deal in
  10726. + * the Software without restriction, including without limitation the rights to
  10727. + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  10728. + * the Software, and to permit persons to whom the Software is furnished to do so,
  10729. + * subject to the following conditions:
  10730. + *
  10731. + * The above copyright notice and this permission notice shall be included in all
  10732. + * copies or substantial portions of the Software.
  10733. + *
  10734. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  10735. + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  10736. + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  10737. + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  10738. + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  10739. + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  10740. + *
  10741. + * https://www.FreeRTOS.org
  10742. + * https://github.com/FreeRTOS
  10743. + *
  10744. + */
  10745. +
  10746. +/*
  10747. + * A sample implementation of pvPortMalloc() and vPortFree() that combines
  10748. + * (coalescences) adjacent memory blocks as they are freed, and in so doing
  10749. + * limits memory fragmentation.
  10750. + *
  10751. + * See heap_1.c, heap_2.c and heap_3.c for alternative implementations, and the
  10752. + * memory management pages of https://www.FreeRTOS.org for more information.
  10753. + */
  10754. +#include <stdlib.h>
  10755. +
  10756. +#include "FreeRTOS.h"
  10757. +#include "task.h"
  10758. +
  10759. +#if ( configSUPPORT_DYNAMIC_ALLOCATION == 0 )
  10760. + #error This file must not be used if configSUPPORT_DYNAMIC_ALLOCATION is 0
  10761. +#endif
  10762. +
  10763. +/* Block sizes must not get too small. */
  10764. +#define heapMINIMUM_BLOCK_SIZE ( ( size_t ) ( xHeapStructSize << 1 ) )
  10765. +
  10766. +/* Assumes 8bit bytes! */
  10767. +#define heapBITS_PER_BYTE ( ( size_t ) 8 )
  10768. +
  10769. +/* Allocate the memory for the heap. */
  10770. +#if ( configAPPLICATION_ALLOCATED_HEAP == 1 )
  10771. +
  10772. +/* The application writer has already defined the array used for the RTOS
  10773. +* heap - probably so it can be placed in a special segment or address. */
  10774. + extern uint8_t ucHeap[ configTOTAL_HEAP_SIZE ];
  10775. +#else
  10776. + static uint8_t ucHeap[ configTOTAL_HEAP_SIZE ];
  10777. +#endif /* configAPPLICATION_ALLOCATED_HEAP */
  10778. +
  10779. +/* Define the linked list structure. This is used to link free blocks in order
  10780. + * of their memory address. */
  10781. +typedef struct A_BLOCK_LINK
  10782. +{
  10783. + struct A_BLOCK_LINK * pxNextFreeBlock; /*<< The next free block in the list. */
  10784. + size_t xBlockSize; /*<< The size of the free block. */
  10785. +} BlockLink_t;
  10786. +
  10787. +/*-----------------------------------------------------------*/
  10788. +
  10789. +/*
  10790. + * Inserts a block of memory that is being freed into the correct position in
  10791. + * the list of free memory blocks. The block being freed will be merged with
  10792. + * the block in front it and/or the block behind it if the memory blocks are
  10793. + * adjacent to each other.
  10794. + */
  10795. +static void prvInsertBlockIntoFreeList( BlockLink_t * pxBlockToInsert );
  10796. +
  10797. +/*
  10798. + * Called automatically to setup the required heap structures the first time
  10799. + * pvPortMalloc() is called.
  10800. + */
  10801. +static void prvHeapInit( void );
  10802. +
  10803. +/*-----------------------------------------------------------*/
  10804. +
  10805. +/* The size of the structure placed at the beginning of each allocated memory
  10806. + * block must by correctly byte aligned. */
  10807. +static const size_t xHeapStructSize = ( sizeof( BlockLink_t ) + ( ( size_t ) ( portBYTE_ALIGNMENT - 1 ) ) ) & ~( ( size_t ) portBYTE_ALIGNMENT_MASK );
  10808. +
  10809. +/* Create a couple of list links to mark the start and end of the list. */
  10810. +static BlockLink_t xStart, * pxEnd = NULL;
  10811. +
  10812. +/* Keeps track of the number of calls to allocate and free memory as well as the
  10813. + * number of free bytes remaining, but says nothing about fragmentation. */
  10814. +static size_t xFreeBytesRemaining = 0U;
  10815. +static size_t xMinimumEverFreeBytesRemaining = 0U;
  10816. +static size_t xNumberOfSuccessfulAllocations = 0;
  10817. +static size_t xNumberOfSuccessfulFrees = 0;
  10818. +
  10819. +/* Gets set to the top bit of an size_t type. When this bit in the xBlockSize
  10820. + * member of an BlockLink_t structure is set then the block belongs to the
  10821. + * application. When the bit is free the block is still part of the free heap
  10822. + * space. */
  10823. +static size_t xBlockAllocatedBit = 0;
  10824. +
  10825. +/*-----------------------------------------------------------*/
  10826. +
  10827. +void * pvPortMalloc( size_t xWantedSize )
  10828. +{
  10829. + BlockLink_t * pxBlock, * pxPreviousBlock, * pxNewBlockLink;
  10830. + void * pvReturn = NULL;
  10831. +
  10832. + vTaskSuspendAll();
  10833. + {
  10834. + /* If this is the first call to malloc then the heap will require
  10835. + * initialisation to setup the list of free blocks. */
  10836. + if( pxEnd == NULL )
  10837. + {
  10838. + prvHeapInit();
  10839. + }
  10840. +
  10841. + /* Check the requested block size is not so large that the top bit is
  10842. + * set. The top bit of the block size member of the BlockLink_t structure
  10843. + * is used to determine who owns the block - the application or the
  10844. + * kernel, so it must be free. */
  10845. + if( ( xWantedSize & xBlockAllocatedBit ) == 0 )
  10846. + {
  10847. + /* The wanted size must be increased so it can contain a BlockLink_t
  10848. + * structure in addition to the requested amount of bytes. */
  10849. + if( ( xWantedSize > 0 ) &&
  10850. + ( ( xWantedSize + xHeapStructSize ) > xWantedSize ) ) /* Overflow check */
  10851. + {
  10852. + xWantedSize += xHeapStructSize;
  10853. +
  10854. + /* Ensure that blocks are always aligned. */
  10855. + if( ( xWantedSize & portBYTE_ALIGNMENT_MASK ) != 0x00 )
  10856. + {
  10857. + /* Byte alignment required. Check for overflow. */
  10858. + if( ( xWantedSize + ( portBYTE_ALIGNMENT - ( xWantedSize & portBYTE_ALIGNMENT_MASK ) ) )
  10859. + > xWantedSize )
  10860. + {
  10861. + xWantedSize += ( portBYTE_ALIGNMENT - ( xWantedSize & portBYTE_ALIGNMENT_MASK ) );
  10862. + configASSERT( ( xWantedSize & portBYTE_ALIGNMENT_MASK ) == 0 );
  10863. + }
  10864. + else
  10865. + {
  10866. + xWantedSize = 0;
  10867. + }
  10868. + }
  10869. + }
  10870. + else
  10871. + {
  10872. + xWantedSize = 0;
  10873. + }
  10874. +
  10875. + if( ( xWantedSize > 0 ) && ( xWantedSize <= xFreeBytesRemaining ) )
  10876. + {
  10877. + /* Traverse the list from the start (lowest address) block until
  10878. + * one of adequate size is found. */
  10879. + pxPreviousBlock = &xStart;
  10880. + pxBlock = xStart.pxNextFreeBlock;
  10881. +
  10882. + while( ( pxBlock->xBlockSize < xWantedSize ) && ( pxBlock->pxNextFreeBlock != NULL ) )
  10883. + {
  10884. + pxPreviousBlock = pxBlock;
  10885. + pxBlock = pxBlock->pxNextFreeBlock;
  10886. + }
  10887. +
  10888. + /* If the end marker was reached then a block of adequate size
  10889. + * was not found. */
  10890. + if( pxBlock != pxEnd )
  10891. + {
  10892. + /* Return the memory space pointed to - jumping over the
  10893. + * BlockLink_t structure at its start. */
  10894. + pvReturn = ( void * ) ( ( ( uint8_t * ) pxPreviousBlock->pxNextFreeBlock ) + xHeapStructSize );
  10895. +
  10896. + /* This block is being returned for use so must be taken out
  10897. + * of the list of free blocks. */
  10898. + pxPreviousBlock->pxNextFreeBlock = pxBlock->pxNextFreeBlock;
  10899. +
  10900. + /* If the block is larger than required it can be split into
  10901. + * two. */
  10902. + if( ( pxBlock->xBlockSize - xWantedSize ) > heapMINIMUM_BLOCK_SIZE )
  10903. + {
  10904. + /* This block is to be split into two. Create a new
  10905. + * block following the number of bytes requested. The void
  10906. + * cast is used to prevent byte alignment warnings from the
  10907. + * compiler. */
  10908. + pxNewBlockLink = ( void * ) ( ( ( uint8_t * ) pxBlock ) + xWantedSize );
  10909. + configASSERT( ( ( ( size_t ) pxNewBlockLink ) & portBYTE_ALIGNMENT_MASK ) == 0 );
  10910. +
  10911. + /* Calculate the sizes of two blocks split from the
  10912. + * single block. */
  10913. + pxNewBlockLink->xBlockSize = pxBlock->xBlockSize - xWantedSize;
  10914. + pxBlock->xBlockSize = xWantedSize;
  10915. +
  10916. + /* Insert the new block into the list of free blocks. */
  10917. + prvInsertBlockIntoFreeList( pxNewBlockLink );
  10918. + }
  10919. +
  10920. + xFreeBytesRemaining -= pxBlock->xBlockSize;
  10921. +
  10922. + if( xFreeBytesRemaining < xMinimumEverFreeBytesRemaining )
  10923. + {
  10924. + xMinimumEverFreeBytesRemaining = xFreeBytesRemaining;
  10925. + }
  10926. +
  10927. + /* The block is being returned - it is allocated and owned
  10928. + * by the application and has no "next" block. */
  10929. + pxBlock->xBlockSize |= xBlockAllocatedBit;
  10930. + pxBlock->pxNextFreeBlock = NULL;
  10931. + xNumberOfSuccessfulAllocations++;
  10932. + }
  10933. + }
  10934. + }
  10935. +
  10936. + }
  10937. + ( void ) xTaskResumeAll();
  10938. +
  10939. + #if ( configUSE_MALLOC_FAILED_HOOK == 1 )
  10940. + {
  10941. + if( pvReturn == NULL )
  10942. + {
  10943. + extern void vApplicationMallocFailedHook( void );
  10944. + vApplicationMallocFailedHook();
  10945. + }
  10946. + }
  10947. + #endif /* if ( configUSE_MALLOC_FAILED_HOOK == 1 ) */
  10948. +
  10949. + configASSERT( ( ( ( size_t ) pvReturn ) & ( size_t ) portBYTE_ALIGNMENT_MASK ) == 0 );
  10950. + return pvReturn;
  10951. +}
  10952. +/*-----------------------------------------------------------*/
  10953. +
  10954. +void vPortFree( void * pv )
  10955. +{
  10956. + uint8_t * puc = ( uint8_t * ) pv;
  10957. + BlockLink_t * pxLink;
  10958. +
  10959. + if( pv != NULL )
  10960. + {
  10961. + /* The memory being freed will have an BlockLink_t structure immediately
  10962. + * before it. */
  10963. + puc -= xHeapStructSize;
  10964. +
  10965. + /* This casting is to keep the compiler from issuing warnings. */
  10966. + pxLink = ( void * ) puc;
  10967. +
  10968. + /* Check the block is actually allocated. */
  10969. + configASSERT( ( pxLink->xBlockSize & xBlockAllocatedBit ) != 0 );
  10970. + configASSERT( pxLink->pxNextFreeBlock == NULL );
  10971. +
  10972. + if( ( pxLink->xBlockSize & xBlockAllocatedBit ) != 0 )
  10973. + {
  10974. + if( pxLink->pxNextFreeBlock == NULL )
  10975. + {
  10976. + /* The block is being returned to the heap - it is no longer
  10977. + * allocated. */
  10978. + pxLink->xBlockSize &= ~xBlockAllocatedBit;
  10979. +
  10980. + vTaskSuspendAll();
  10981. + {
  10982. + /* Add this block to the list of free blocks. */
  10983. + xFreeBytesRemaining += pxLink->xBlockSize;
  10984. + prvInsertBlockIntoFreeList( ( ( BlockLink_t * ) pxLink ) );
  10985. + xNumberOfSuccessfulFrees++;
  10986. + }
  10987. + ( void ) xTaskResumeAll();
  10988. + }
  10989. + }
  10990. + }
  10991. +}
  10992. +/*-----------------------------------------------------------*/
  10993. +
  10994. +size_t xPortGetFreeHeapSize( void )
  10995. +{
  10996. + return xFreeBytesRemaining;
  10997. +}
  10998. +/*-----------------------------------------------------------*/
  10999. +
  11000. +size_t xPortGetMinimumEverFreeHeapSize( void )
  11001. +{
  11002. + return xMinimumEverFreeBytesRemaining;
  11003. +}
  11004. +/*-----------------------------------------------------------*/
  11005. +
  11006. +void vPortInitialiseBlocks( void )
  11007. +{
  11008. + /* This just exists to keep the linker quiet. */
  11009. +}
  11010. +/*-----------------------------------------------------------*/
  11011. +
  11012. +static void prvHeapInit( void ) /* PRIVILEGED_FUNCTION */
  11013. +{
  11014. + BlockLink_t * pxFirstFreeBlock;
  11015. + uint8_t * pucAlignedHeap;
  11016. + size_t uxAddress;
  11017. + size_t xTotalHeapSize = configTOTAL_HEAP_SIZE;
  11018. +
  11019. + /* Ensure the heap starts on a correctly aligned boundary. */
  11020. + uxAddress = ( size_t ) ucHeap;
  11021. +
  11022. + if( ( uxAddress & portBYTE_ALIGNMENT_MASK ) != 0 )
  11023. + {
  11024. + uxAddress += ( portBYTE_ALIGNMENT - 1 );
  11025. + uxAddress &= ~( ( size_t ) portBYTE_ALIGNMENT_MASK );
  11026. + xTotalHeapSize -= uxAddress - ( size_t ) ucHeap;
  11027. + }
  11028. +
  11029. + pucAlignedHeap = ( uint8_t * ) uxAddress;
  11030. +
  11031. + /* xStart is used to hold a pointer to the first item in the list of free
  11032. + * blocks. The void cast is used to prevent compiler warnings. */
  11033. + xStart.pxNextFreeBlock = ( void * ) pucAlignedHeap;
  11034. + xStart.xBlockSize = ( size_t ) 0;
  11035. +
  11036. + /* pxEnd is used to mark the end of the list of free blocks and is inserted
  11037. + * at the end of the heap space. */
  11038. + uxAddress = ( ( size_t ) pucAlignedHeap ) + xTotalHeapSize;
  11039. + uxAddress -= xHeapStructSize;
  11040. + uxAddress &= ~( ( size_t ) portBYTE_ALIGNMENT_MASK );
  11041. + pxEnd = ( void * ) uxAddress;
  11042. + pxEnd->xBlockSize = 0;
  11043. + pxEnd->pxNextFreeBlock = NULL;
  11044. +
  11045. + /* To start with there is a single free block that is sized to take up the
  11046. + * entire heap space, minus the space taken by pxEnd. */
  11047. + pxFirstFreeBlock = ( void * ) pucAlignedHeap;
  11048. + pxFirstFreeBlock->xBlockSize = uxAddress - ( size_t ) pxFirstFreeBlock;
  11049. + pxFirstFreeBlock->pxNextFreeBlock = pxEnd;
  11050. +
  11051. + /* Only one block exists - and it covers the entire usable heap space. */
  11052. + xMinimumEverFreeBytesRemaining = pxFirstFreeBlock->xBlockSize;
  11053. + xFreeBytesRemaining = pxFirstFreeBlock->xBlockSize;
  11054. +
  11055. + /* Work out the position of the top bit in a size_t variable. */
  11056. + xBlockAllocatedBit = ( ( size_t ) 1 ) << ( ( sizeof( size_t ) * heapBITS_PER_BYTE ) - 1 );
  11057. +}
  11058. +/*-----------------------------------------------------------*/
  11059. +
  11060. +static void prvInsertBlockIntoFreeList( BlockLink_t * pxBlockToInsert ) /* PRIVILEGED_FUNCTION */
  11061. +{
  11062. + BlockLink_t * pxIterator;
  11063. + uint8_t * puc;
  11064. +
  11065. + /* Iterate through the list until a block is found that has a higher address
  11066. + * than the block being inserted. */
  11067. + for( pxIterator = &xStart; pxIterator->pxNextFreeBlock < pxBlockToInsert; pxIterator = pxIterator->pxNextFreeBlock )
  11068. + {
  11069. + /* Nothing to do here, just iterate to the right position. */
  11070. + }
  11071. +
  11072. + /* Do the block being inserted, and the block it is being inserted after
  11073. + * make a contiguous block of memory? */
  11074. + puc = ( uint8_t * ) pxIterator;
  11075. +
  11076. + if( ( puc + pxIterator->xBlockSize ) == ( uint8_t * ) pxBlockToInsert )
  11077. + {
  11078. + pxIterator->xBlockSize += pxBlockToInsert->xBlockSize;
  11079. + pxBlockToInsert = pxIterator;
  11080. + }
  11081. +
  11082. + /* Do the block being inserted, and the block it is being inserted before
  11083. + * make a contiguous block of memory? */
  11084. + puc = ( uint8_t * ) pxBlockToInsert;
  11085. +
  11086. + if( ( puc + pxBlockToInsert->xBlockSize ) == ( uint8_t * ) pxIterator->pxNextFreeBlock )
  11087. + {
  11088. + if( pxIterator->pxNextFreeBlock != pxEnd )
  11089. + {
  11090. + /* Form one big block from the two blocks. */
  11091. + pxBlockToInsert->xBlockSize += pxIterator->pxNextFreeBlock->xBlockSize;
  11092. + pxBlockToInsert->pxNextFreeBlock = pxIterator->pxNextFreeBlock->pxNextFreeBlock;
  11093. + }
  11094. + else
  11095. + {
  11096. + pxBlockToInsert->pxNextFreeBlock = pxEnd;
  11097. + }
  11098. + }
  11099. + else
  11100. + {
  11101. + pxBlockToInsert->pxNextFreeBlock = pxIterator->pxNextFreeBlock;
  11102. + }
  11103. +
  11104. + /* If the block being inserted plugged a gab, so was merged with the block
  11105. + * before and the block after, then it's pxNextFreeBlock pointer will have
  11106. + * already been set, and should not be set here as that would make it point
  11107. + * to itself. */
  11108. + if( pxIterator != pxBlockToInsert )
  11109. + {
  11110. + pxIterator->pxNextFreeBlock = pxBlockToInsert;
  11111. + }
  11112. +}
  11113. +/*-----------------------------------------------------------*/
  11114. +
  11115. +void vPortGetHeapStats( HeapStats_t * pxHeapStats )
  11116. +{
  11117. + BlockLink_t * pxBlock;
  11118. + size_t xBlocks = 0, xMaxSize = 0, xMinSize = portMAX_DELAY; /* portMAX_DELAY used as a portable way of getting the maximum value. */
  11119. +
  11120. + vTaskSuspendAll();
  11121. + {
  11122. + pxBlock = xStart.pxNextFreeBlock;
  11123. +
  11124. + /* pxBlock will be NULL if the heap has not been initialised. The heap
  11125. + * is initialised automatically when the first allocation is made. */
  11126. + if( pxBlock != NULL )
  11127. + {
  11128. + do
  11129. + {
  11130. + /* Increment the number of blocks and record the largest block seen
  11131. + * so far. */
  11132. + xBlocks++;
  11133. +
  11134. + if( pxBlock->xBlockSize > xMaxSize )
  11135. + {
  11136. + xMaxSize = pxBlock->xBlockSize;
  11137. + }
  11138. +
  11139. + if( pxBlock->xBlockSize < xMinSize )
  11140. + {
  11141. + xMinSize = pxBlock->xBlockSize;
  11142. + }
  11143. +
  11144. + /* Move to the next block in the chain until the last block is
  11145. + * reached. */
  11146. + pxBlock = pxBlock->pxNextFreeBlock;
  11147. + } while( pxBlock != pxEnd );
  11148. + }
  11149. + }
  11150. + ( void ) xTaskResumeAll();
  11151. +
  11152. + pxHeapStats->xSizeOfLargestFreeBlockInBytes = xMaxSize;
  11153. + pxHeapStats->xSizeOfSmallestFreeBlockInBytes = xMinSize;
  11154. + pxHeapStats->xNumberOfFreeBlocks = xBlocks;
  11155. +
  11156. + taskENTER_CRITICAL();
  11157. + {
  11158. + pxHeapStats->xAvailableHeapSpaceInBytes = xFreeBytesRemaining;
  11159. + pxHeapStats->xNumberOfSuccessfulAllocations = xNumberOfSuccessfulAllocations;
  11160. + pxHeapStats->xNumberOfSuccessfulFrees = xNumberOfSuccessfulFrees;
  11161. + pxHeapStats->xMinimumEverFreeBytesRemaining = xMinimumEverFreeBytesRemaining;
  11162. + }
  11163. + taskEXIT_CRITICAL();
  11164. +}
  11165. diff --git a/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/port/MemMang/heap_5.c b/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/port/MemMang/heap_5.c
  11166. new file mode 100644
  11167. index 0000000000..7fadbd4b0f
  11168. --- /dev/null
  11169. +++ b/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/port/MemMang/heap_5.c
  11170. @@ -0,0 +1,506 @@
  11171. +/*
  11172. + * FreeRTOS Kernel V10.4.6
  11173. + * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  11174. + *
  11175. + * SPDX-License-Identifier: MIT
  11176. + *
  11177. + * Permission is hereby granted, free of charge, to any person obtaining a copy of
  11178. + * this software and associated documentation files (the "Software"), to deal in
  11179. + * the Software without restriction, including without limitation the rights to
  11180. + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  11181. + * the Software, and to permit persons to whom the Software is furnished to do so,
  11182. + * subject to the following conditions:
  11183. + *
  11184. + * The above copyright notice and this permission notice shall be included in all
  11185. + * copies or substantial portions of the Software.
  11186. + *
  11187. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  11188. + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  11189. + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  11190. + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  11191. + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  11192. + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  11193. + *
  11194. + * https://www.FreeRTOS.org
  11195. + * https://github.com/FreeRTOS
  11196. + *
  11197. + */
  11198. +
  11199. +/*
  11200. + * A sample implementation of pvPortMalloc() that allows the heap to be defined
  11201. + * across multiple non-contigous blocks and combines (coalescences) adjacent
  11202. + * memory blocks as they are freed.
  11203. + *
  11204. + * See heap_1.c, heap_2.c, heap_3.c and heap_4.c for alternative
  11205. + * implementations, and the memory management pages of https://www.FreeRTOS.org
  11206. + * for more information.
  11207. + *
  11208. + * Usage notes:
  11209. + *
  11210. + * vPortDefineHeapRegions() ***must*** be called before pvPortMalloc().
  11211. + * pvPortMalloc() will be called if any task objects (tasks, queues, event
  11212. + * groups, etc.) are created, therefore vPortDefineHeapRegions() ***must*** be
  11213. + * called before any other objects are defined.
  11214. + *
  11215. + * vPortDefineHeapRegions() takes a single parameter. The parameter is an array
  11216. + * of HeapRegion_t structures. HeapRegion_t is defined in portable.h as
  11217. + *
  11218. + * typedef struct HeapRegion
  11219. + * {
  11220. + * uint8_t *pucStartAddress; << Start address of a block of memory that will be part of the heap.
  11221. + * size_t xSizeInBytes; << Size of the block of memory.
  11222. + * } HeapRegion_t;
  11223. + *
  11224. + * The array is terminated using a NULL zero sized region definition, and the
  11225. + * memory regions defined in the array ***must*** appear in address order from
  11226. + * low address to high address. So the following is a valid example of how
  11227. + * to use the function.
  11228. + *
  11229. + * HeapRegion_t xHeapRegions[] =
  11230. + * {
  11231. + * { ( uint8_t * ) 0x80000000UL, 0x10000 }, << Defines a block of 0x10000 bytes starting at address 0x80000000
  11232. + * { ( uint8_t * ) 0x90000000UL, 0xa0000 }, << Defines a block of 0xa0000 bytes starting at address of 0x90000000
  11233. + * { NULL, 0 } << Terminates the array.
  11234. + * };
  11235. + *
  11236. + * vPortDefineHeapRegions( xHeapRegions ); << Pass the array into vPortDefineHeapRegions().
  11237. + *
  11238. + * Note 0x80000000 is the lower address so appears in the array first.
  11239. + *
  11240. + */
  11241. +#include <stdlib.h>
  11242. +
  11243. +#include "FreeRTOS.h"
  11244. +#include "task.h"
  11245. +
  11246. +#if ( configSUPPORT_DYNAMIC_ALLOCATION == 0 )
  11247. + #error This file must not be used if configSUPPORT_DYNAMIC_ALLOCATION is 0
  11248. +#endif
  11249. +
  11250. +/* Block sizes must not get too small. */
  11251. +#define heapMINIMUM_BLOCK_SIZE ( ( size_t ) ( xHeapStructSize << 1 ) )
  11252. +
  11253. +/* Assumes 8bit bytes! */
  11254. +#define heapBITS_PER_BYTE ( ( size_t ) 8 )
  11255. +
  11256. +/* Define the linked list structure. This is used to link free blocks in order
  11257. + * of their memory address. */
  11258. +typedef struct A_BLOCK_LINK
  11259. +{
  11260. + struct A_BLOCK_LINK * pxNextFreeBlock; /*<< The next free block in the list. */
  11261. + size_t xBlockSize; /*<< The size of the free block. */
  11262. +} BlockLink_t;
  11263. +
  11264. +/*-----------------------------------------------------------*/
  11265. +
  11266. +/*
  11267. + * Inserts a block of memory that is being freed into the correct position in
  11268. + * the list of free memory blocks. The block being freed will be merged with
  11269. + * the block in front it and/or the block behind it if the memory blocks are
  11270. + * adjacent to each other.
  11271. + */
  11272. +static void prvInsertBlockIntoFreeList( BlockLink_t * pxBlockToInsert );
  11273. +
  11274. +/*-----------------------------------------------------------*/
  11275. +
  11276. +/* The size of the structure placed at the beginning of each allocated memory
  11277. + * block must by correctly byte aligned. */
  11278. +static const size_t xHeapStructSize = ( sizeof( BlockLink_t ) + ( ( size_t ) ( portBYTE_ALIGNMENT - 1 ) ) ) & ~( ( size_t ) portBYTE_ALIGNMENT_MASK );
  11279. +
  11280. +/* Create a couple of list links to mark the start and end of the list. */
  11281. +static BlockLink_t xStart, * pxEnd = NULL;
  11282. +
  11283. +/* Keeps track of the number of calls to allocate and free memory as well as the
  11284. + * number of free bytes remaining, but says nothing about fragmentation. */
  11285. +static size_t xFreeBytesRemaining = 0U;
  11286. +static size_t xMinimumEverFreeBytesRemaining = 0U;
  11287. +static size_t xNumberOfSuccessfulAllocations = 0;
  11288. +static size_t xNumberOfSuccessfulFrees = 0;
  11289. +
  11290. +/* Gets set to the top bit of an size_t type. When this bit in the xBlockSize
  11291. + * member of an BlockLink_t structure is set then the block belongs to the
  11292. + * application. When the bit is free the block is still part of the free heap
  11293. + * space. */
  11294. +static size_t xBlockAllocatedBit = 0;
  11295. +
  11296. +/*-----------------------------------------------------------*/
  11297. +
  11298. +void * pvPortMalloc( size_t xWantedSize )
  11299. +{
  11300. + BlockLink_t * pxBlock, * pxPreviousBlock, * pxNewBlockLink;
  11301. + void * pvReturn = NULL;
  11302. +
  11303. + /* The heap must be initialised before the first call to
  11304. + * prvPortMalloc(). */
  11305. + configASSERT( pxEnd );
  11306. +
  11307. + vTaskSuspendAll();
  11308. + {
  11309. + /* Check the requested block size is not so large that the top bit is
  11310. + * set. The top bit of the block size member of the BlockLink_t structure
  11311. + * is used to determine who owns the block - the application or the
  11312. + * kernel, so it must be free. */
  11313. + if( ( xWantedSize & xBlockAllocatedBit ) == 0 )
  11314. + {
  11315. + /* The wanted size is increased so it can contain a BlockLink_t
  11316. + * structure in addition to the requested amount of bytes. */
  11317. + if( ( xWantedSize > 0 ) &&
  11318. + ( ( xWantedSize + xHeapStructSize ) > xWantedSize ) ) /* Overflow check */
  11319. + {
  11320. + xWantedSize += xHeapStructSize;
  11321. +
  11322. + /* Ensure that blocks are always aligned */
  11323. + if( ( xWantedSize & portBYTE_ALIGNMENT_MASK ) != 0x00 )
  11324. + {
  11325. + /* Byte alignment required. Check for overflow */
  11326. + if( ( xWantedSize + ( portBYTE_ALIGNMENT - ( xWantedSize & portBYTE_ALIGNMENT_MASK ) ) ) >
  11327. + xWantedSize )
  11328. + {
  11329. + xWantedSize += ( portBYTE_ALIGNMENT - ( xWantedSize & portBYTE_ALIGNMENT_MASK ) );
  11330. + }
  11331. + else
  11332. + {
  11333. + xWantedSize = 0;
  11334. + }
  11335. + }
  11336. + }
  11337. + else
  11338. + {
  11339. + xWantedSize = 0;
  11340. + }
  11341. +
  11342. + if( ( xWantedSize > 0 ) && ( xWantedSize <= xFreeBytesRemaining ) )
  11343. + {
  11344. + /* Traverse the list from the start (lowest address) block until
  11345. + * one of adequate size is found. */
  11346. + pxPreviousBlock = &xStart;
  11347. + pxBlock = xStart.pxNextFreeBlock;
  11348. +
  11349. + while( ( pxBlock->xBlockSize < xWantedSize ) && ( pxBlock->pxNextFreeBlock != NULL ) )
  11350. + {
  11351. + pxPreviousBlock = pxBlock;
  11352. + pxBlock = pxBlock->pxNextFreeBlock;
  11353. + }
  11354. +
  11355. + /* If the end marker was reached then a block of adequate size
  11356. + * was not found. */
  11357. + if( pxBlock != pxEnd )
  11358. + {
  11359. + /* Return the memory space pointed to - jumping over the
  11360. + * BlockLink_t structure at its start. */
  11361. + pvReturn = ( void * ) ( ( ( uint8_t * ) pxPreviousBlock->pxNextFreeBlock ) + xHeapStructSize );
  11362. +
  11363. + /* This block is being returned for use so must be taken out
  11364. + * of the list of free blocks. */
  11365. + pxPreviousBlock->pxNextFreeBlock = pxBlock->pxNextFreeBlock;
  11366. +
  11367. + /* If the block is larger than required it can be split into
  11368. + * two. */
  11369. + if( ( pxBlock->xBlockSize - xWantedSize ) > heapMINIMUM_BLOCK_SIZE )
  11370. + {
  11371. + /* This block is to be split into two. Create a new
  11372. + * block following the number of bytes requested. The void
  11373. + * cast is used to prevent byte alignment warnings from the
  11374. + * compiler. */
  11375. + pxNewBlockLink = ( void * ) ( ( ( uint8_t * ) pxBlock ) + xWantedSize );
  11376. +
  11377. + /* Calculate the sizes of two blocks split from the
  11378. + * single block. */
  11379. + pxNewBlockLink->xBlockSize = pxBlock->xBlockSize - xWantedSize;
  11380. + pxBlock->xBlockSize = xWantedSize;
  11381. +
  11382. + /* Insert the new block into the list of free blocks. */
  11383. + prvInsertBlockIntoFreeList( ( pxNewBlockLink ) );
  11384. + }
  11385. +
  11386. + xFreeBytesRemaining -= pxBlock->xBlockSize;
  11387. +
  11388. + if( xFreeBytesRemaining < xMinimumEverFreeBytesRemaining )
  11389. + {
  11390. + xMinimumEverFreeBytesRemaining = xFreeBytesRemaining;
  11391. + }
  11392. +
  11393. + /* The block is being returned - it is allocated and owned
  11394. + * by the application and has no "next" block. */
  11395. + pxBlock->xBlockSize |= xBlockAllocatedBit;
  11396. + pxBlock->pxNextFreeBlock = NULL;
  11397. + xNumberOfSuccessfulAllocations++;
  11398. + }
  11399. + }
  11400. + }
  11401. +
  11402. + }
  11403. + ( void ) xTaskResumeAll();
  11404. +
  11405. + #if ( configUSE_MALLOC_FAILED_HOOK == 1 )
  11406. + {
  11407. + if( pvReturn == NULL )
  11408. + {
  11409. + extern void vApplicationMallocFailedHook( void );
  11410. + vApplicationMallocFailedHook();
  11411. + }
  11412. + }
  11413. + #endif /* if ( configUSE_MALLOC_FAILED_HOOK == 1 ) */
  11414. +
  11415. + return pvReturn;
  11416. +}
  11417. +/*-----------------------------------------------------------*/
  11418. +
  11419. +void vPortFree( void * pv )
  11420. +{
  11421. + uint8_t * puc = ( uint8_t * ) pv;
  11422. + BlockLink_t * pxLink;
  11423. +
  11424. + if( pv != NULL )
  11425. + {
  11426. + /* The memory being freed will have an BlockLink_t structure immediately
  11427. + * before it. */
  11428. + puc -= xHeapStructSize;
  11429. +
  11430. + /* This casting is to keep the compiler from issuing warnings. */
  11431. + pxLink = ( void * ) puc;
  11432. +
  11433. + /* Check the block is actually allocated. */
  11434. + configASSERT( ( pxLink->xBlockSize & xBlockAllocatedBit ) != 0 );
  11435. + configASSERT( pxLink->pxNextFreeBlock == NULL );
  11436. +
  11437. + if( ( pxLink->xBlockSize & xBlockAllocatedBit ) != 0 )
  11438. + {
  11439. + if( pxLink->pxNextFreeBlock == NULL )
  11440. + {
  11441. + /* The block is being returned to the heap - it is no longer
  11442. + * allocated. */
  11443. + pxLink->xBlockSize &= ~xBlockAllocatedBit;
  11444. +
  11445. + vTaskSuspendAll();
  11446. + {
  11447. + /* Add this block to the list of free blocks. */
  11448. + xFreeBytesRemaining += pxLink->xBlockSize;
  11449. + prvInsertBlockIntoFreeList( ( ( BlockLink_t * ) pxLink ) );
  11450. + xNumberOfSuccessfulFrees++;
  11451. + }
  11452. + ( void ) xTaskResumeAll();
  11453. + }
  11454. + }
  11455. + }
  11456. +}
  11457. +/*-----------------------------------------------------------*/
  11458. +
  11459. +size_t xPortGetFreeHeapSize( void )
  11460. +{
  11461. + return xFreeBytesRemaining;
  11462. +}
  11463. +/*-----------------------------------------------------------*/
  11464. +
  11465. +size_t xPortGetMinimumEverFreeHeapSize( void )
  11466. +{
  11467. + return xMinimumEverFreeBytesRemaining;
  11468. +}
  11469. +/*-----------------------------------------------------------*/
  11470. +
  11471. +static void prvInsertBlockIntoFreeList( BlockLink_t * pxBlockToInsert )
  11472. +{
  11473. + BlockLink_t * pxIterator;
  11474. + uint8_t * puc;
  11475. +
  11476. + /* Iterate through the list until a block is found that has a higher address
  11477. + * than the block being inserted. */
  11478. + for( pxIterator = &xStart; pxIterator->pxNextFreeBlock < pxBlockToInsert; pxIterator = pxIterator->pxNextFreeBlock )
  11479. + {
  11480. + /* Nothing to do here, just iterate to the right position. */
  11481. + }
  11482. +
  11483. + /* Do the block being inserted, and the block it is being inserted after
  11484. + * make a contiguous block of memory? */
  11485. + puc = ( uint8_t * ) pxIterator;
  11486. +
  11487. + if( ( puc + pxIterator->xBlockSize ) == ( uint8_t * ) pxBlockToInsert )
  11488. + {
  11489. + pxIterator->xBlockSize += pxBlockToInsert->xBlockSize;
  11490. + pxBlockToInsert = pxIterator;
  11491. + }
  11492. +
  11493. + /* Do the block being inserted, and the block it is being inserted before
  11494. + * make a contiguous block of memory? */
  11495. + puc = ( uint8_t * ) pxBlockToInsert;
  11496. +
  11497. + if( ( puc + pxBlockToInsert->xBlockSize ) == ( uint8_t * ) pxIterator->pxNextFreeBlock )
  11498. + {
  11499. + if( pxIterator->pxNextFreeBlock != pxEnd )
  11500. + {
  11501. + /* Form one big block from the two blocks. */
  11502. + pxBlockToInsert->xBlockSize += pxIterator->pxNextFreeBlock->xBlockSize;
  11503. + pxBlockToInsert->pxNextFreeBlock = pxIterator->pxNextFreeBlock->pxNextFreeBlock;
  11504. + }
  11505. + else
  11506. + {
  11507. + pxBlockToInsert->pxNextFreeBlock = pxEnd;
  11508. + }
  11509. + }
  11510. + else
  11511. + {
  11512. + pxBlockToInsert->pxNextFreeBlock = pxIterator->pxNextFreeBlock;
  11513. + }
  11514. +
  11515. + /* If the block being inserted plugged a gab, so was merged with the block
  11516. + * before and the block after, then it's pxNextFreeBlock pointer will have
  11517. + * already been set, and should not be set here as that would make it point
  11518. + * to itself. */
  11519. + if( pxIterator != pxBlockToInsert )
  11520. + {
  11521. + pxIterator->pxNextFreeBlock = pxBlockToInsert;
  11522. + }
  11523. +}
  11524. +/*-----------------------------------------------------------*/
  11525. +
  11526. +void vPortDefineHeapRegions( const HeapRegion_t * const pxHeapRegions )
  11527. +{
  11528. + BlockLink_t * pxFirstFreeBlockInRegion = NULL, * pxPreviousFreeBlock;
  11529. + size_t xAlignedHeap;
  11530. + size_t xTotalRegionSize, xTotalHeapSize = 0;
  11531. + BaseType_t xDefinedRegions = 0;
  11532. + size_t xAddress;
  11533. + const HeapRegion_t * pxHeapRegion;
  11534. +
  11535. + /* Can only call once! */
  11536. + configASSERT( pxEnd == NULL );
  11537. +
  11538. + pxHeapRegion = &( pxHeapRegions[ xDefinedRegions ] );
  11539. +
  11540. + while( pxHeapRegion->xSizeInBytes > 0 )
  11541. + {
  11542. + xTotalRegionSize = pxHeapRegion->xSizeInBytes;
  11543. +
  11544. + /* Ensure the heap region starts on a correctly aligned boundary. */
  11545. + xAddress = ( size_t ) pxHeapRegion->pucStartAddress;
  11546. +
  11547. + if( ( xAddress & portBYTE_ALIGNMENT_MASK ) != 0 )
  11548. + {
  11549. + xAddress += ( portBYTE_ALIGNMENT - 1 );
  11550. + xAddress &= ~portBYTE_ALIGNMENT_MASK;
  11551. +
  11552. + /* Adjust the size for the bytes lost to alignment. */
  11553. + xTotalRegionSize -= xAddress - ( size_t ) pxHeapRegion->pucStartAddress;
  11554. + }
  11555. +
  11556. + xAlignedHeap = xAddress;
  11557. +
  11558. + /* Set xStart if it has not already been set. */
  11559. + if( xDefinedRegions == 0 )
  11560. + {
  11561. + /* xStart is used to hold a pointer to the first item in the list of
  11562. + * free blocks. The void cast is used to prevent compiler warnings. */
  11563. + xStart.pxNextFreeBlock = ( BlockLink_t * ) xAlignedHeap;
  11564. + xStart.xBlockSize = ( size_t ) 0;
  11565. + }
  11566. + else
  11567. + {
  11568. + /* Should only get here if one region has already been added to the
  11569. + * heap. */
  11570. + configASSERT( pxEnd != NULL );
  11571. +
  11572. + /* Check blocks are passed in with increasing start addresses. */
  11573. + configASSERT( xAddress > ( size_t ) pxEnd );
  11574. + }
  11575. +
  11576. + /* Remember the location of the end marker in the previous region, if
  11577. + * any. */
  11578. + pxPreviousFreeBlock = pxEnd;
  11579. +
  11580. + /* pxEnd is used to mark the end of the list of free blocks and is
  11581. + * inserted at the end of the region space. */
  11582. + xAddress = xAlignedHeap + xTotalRegionSize;
  11583. + xAddress -= xHeapStructSize;
  11584. + xAddress &= ~portBYTE_ALIGNMENT_MASK;
  11585. + pxEnd = ( BlockLink_t * ) xAddress;
  11586. + pxEnd->xBlockSize = 0;
  11587. + pxEnd->pxNextFreeBlock = NULL;
  11588. +
  11589. + /* To start with there is a single free block in this region that is
  11590. + * sized to take up the entire heap region minus the space taken by the
  11591. + * free block structure. */
  11592. + pxFirstFreeBlockInRegion = ( BlockLink_t * ) xAlignedHeap;
  11593. + pxFirstFreeBlockInRegion->xBlockSize = xAddress - ( size_t ) pxFirstFreeBlockInRegion;
  11594. + pxFirstFreeBlockInRegion->pxNextFreeBlock = pxEnd;
  11595. +
  11596. + /* If this is not the first region that makes up the entire heap space
  11597. + * then link the previous region to this region. */
  11598. + if( pxPreviousFreeBlock != NULL )
  11599. + {
  11600. + pxPreviousFreeBlock->pxNextFreeBlock = pxFirstFreeBlockInRegion;
  11601. + }
  11602. +
  11603. + xTotalHeapSize += pxFirstFreeBlockInRegion->xBlockSize;
  11604. +
  11605. + /* Move onto the next HeapRegion_t structure. */
  11606. + xDefinedRegions++;
  11607. + pxHeapRegion = &( pxHeapRegions[ xDefinedRegions ] );
  11608. + }
  11609. +
  11610. + xMinimumEverFreeBytesRemaining = xTotalHeapSize;
  11611. + xFreeBytesRemaining = xTotalHeapSize;
  11612. +
  11613. + /* Check something was actually defined before it is accessed. */
  11614. + configASSERT( xTotalHeapSize );
  11615. +
  11616. + /* Work out the position of the top bit in a size_t variable. */
  11617. + xBlockAllocatedBit = ( ( size_t ) 1 ) << ( ( sizeof( size_t ) * heapBITS_PER_BYTE ) - 1 );
  11618. +}
  11619. +/*-----------------------------------------------------------*/
  11620. +
  11621. +void vPortGetHeapStats( HeapStats_t * pxHeapStats )
  11622. +{
  11623. + BlockLink_t * pxBlock;
  11624. + size_t xBlocks = 0, xMaxSize = 0, xMinSize = portMAX_DELAY; /* portMAX_DELAY used as a portable way of getting the maximum value. */
  11625. +
  11626. + vTaskSuspendAll();
  11627. + {
  11628. + pxBlock = xStart.pxNextFreeBlock;
  11629. +
  11630. + /* pxBlock will be NULL if the heap has not been initialised. The heap
  11631. + * is initialised automatically when the first allocation is made. */
  11632. + if( pxBlock != NULL )
  11633. + {
  11634. + do
  11635. + {
  11636. + /* Increment the number of blocks and record the largest block seen
  11637. + * so far. */
  11638. + xBlocks++;
  11639. +
  11640. + if( pxBlock->xBlockSize > xMaxSize )
  11641. + {
  11642. + xMaxSize = pxBlock->xBlockSize;
  11643. + }
  11644. +
  11645. + /* Heap five will have a zero sized block at the end of each
  11646. + * each region - the block is only used to link to the next
  11647. + * heap region so it not a real block. */
  11648. + if( pxBlock->xBlockSize != 0 )
  11649. + {
  11650. + if( pxBlock->xBlockSize < xMinSize )
  11651. + {
  11652. + xMinSize = pxBlock->xBlockSize;
  11653. + }
  11654. + }
  11655. +
  11656. + /* Move to the next block in the chain until the last block is
  11657. + * reached. */
  11658. + pxBlock = pxBlock->pxNextFreeBlock;
  11659. + } while( pxBlock != pxEnd );
  11660. + }
  11661. + }
  11662. + ( void ) xTaskResumeAll();
  11663. +
  11664. + pxHeapStats->xSizeOfLargestFreeBlockInBytes = xMaxSize;
  11665. + pxHeapStats->xSizeOfSmallestFreeBlockInBytes = xMinSize;
  11666. + pxHeapStats->xNumberOfFreeBlocks = xBlocks;
  11667. +
  11668. + taskENTER_CRITICAL();
  11669. + {
  11670. + pxHeapStats->xAvailableHeapSpaceInBytes = xFreeBytesRemaining;
  11671. + pxHeapStats->xNumberOfSuccessfulAllocations = xNumberOfSuccessfulAllocations;
  11672. + pxHeapStats->xNumberOfSuccessfulFrees = xNumberOfSuccessfulFrees;
  11673. + pxHeapStats->xMinimumEverFreeBytesRemaining = xMinimumEverFreeBytesRemaining;
  11674. + }
  11675. + taskEXIT_CRITICAL();
  11676. +}
  11677. diff --git a/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/port/port_common.c b/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/port/port_common.c
  11678. new file mode 100644
  11679. index 0000000000..9d8159f588
  11680. --- /dev/null
  11681. +++ b/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/port/port_common.c
  11682. @@ -0,0 +1,203 @@
  11683. +/*
  11684. + * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
  11685. + *
  11686. + * SPDX-License-Identifier: Apache-2.0
  11687. + */
  11688. +
  11689. +#include <string.h>
  11690. +#include "FreeRTOS.h"
  11691. +#include "task.h"
  11692. +#include "portmacro.h"
  11693. +#include "esp_system.h"
  11694. +#include "esp_heap_caps_init.h"
  11695. +#include "esp_int_wdt.h"
  11696. +#include "esp_task_wdt.h"
  11697. +#include "esp_task.h"
  11698. +#include "esp_private/crosscore_int.h"
  11699. +#include "esp_private/startup_internal.h" /* Required by g_spiram_ok. [refactor-todo] for g_spiram_ok */
  11700. +#include "esp_log.h"
  11701. +#include "soc/soc_memory_types.h"
  11702. +#include "soc/dport_access.h"
  11703. +#include "sdkconfig.h"
  11704. +
  11705. +#if CONFIG_IDF_TARGET_ESP32
  11706. +#include "esp32/spiram.h"
  11707. +#elif CONFIG_IDF_TARGET_ESP32S2
  11708. +#include "esp32s2/spiram.h"
  11709. +#elif CONFIG_IDF_TARGET_ESP32S3
  11710. +#include "esp32s3/spiram.h"
  11711. +#elif CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32H2
  11712. +// SPIRAM is not supported on ESP32-C3
  11713. +#endif
  11714. +
  11715. +#if CONFIG_SPIRAM_MALLOC_RESERVE_INTERNAL
  11716. +static const char* TAG = "cpu_start";
  11717. +#endif
  11718. +
  11719. +/* Architecture-agnostic parts of the FreeRTOS ESP-IDF port layer can go here.
  11720. + *
  11721. + * The actual call flow will be to call esp_startup_start_app() in <ARCH>/port.c,
  11722. + * which will then call esp_startup_start_app_common()
  11723. + */
  11724. +
  11725. +// Duplicate of inaccessible xSchedulerRunning; needed at startup to avoid counting nesting
  11726. +volatile unsigned port_xSchedulerRunning[portNUM_PROCESSORS] = {0};
  11727. +
  11728. +// For now, running FreeRTOS on one core and a bare metal on the other (or other OSes)
  11729. +// is not supported. For now CONFIG_FREERTOS_UNICORE and CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE
  11730. +// should mirror each other's values.
  11731. +//
  11732. +// And since this should be true, we can just check for CONFIG_FREERTOS_UNICORE.
  11733. +#if CONFIG_FREERTOS_UNICORE != CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE
  11734. + #error "FreeRTOS and system configuration mismatch regarding the use of multiple cores."
  11735. +#endif
  11736. +
  11737. +static void main_task(void* args);
  11738. +
  11739. +#ifdef CONFIG_ESP_SYSTEM_GDBSTUB_RUNTIME
  11740. +void esp_gdbstub_init(void);
  11741. +#endif // CONFIG_ESP_SYSTEM_GDBSTUB_RUNTIME
  11742. +
  11743. +extern void app_main(void);
  11744. +
  11745. +void esp_startup_start_app_common(void)
  11746. +{
  11747. +#if CONFIG_ESP_INT_WDT
  11748. + esp_int_wdt_init();
  11749. + //Initialize the interrupt watch dog for CPU0.
  11750. + esp_int_wdt_cpu_init();
  11751. +#endif
  11752. +
  11753. + esp_crosscore_int_init();
  11754. +
  11755. +#ifdef CONFIG_ESP_SYSTEM_GDBSTUB_RUNTIME
  11756. + esp_gdbstub_init();
  11757. +#endif // CONFIG_ESP_SYSTEM_GDBSTUB_RUNTIME
  11758. +
  11759. +#ifdef CONFIG_IDF_RTOS_RTTHREAD
  11760. + app_main();
  11761. +#else
  11762. + portBASE_TYPE res = xTaskCreatePinnedToCore(&main_task, "main",
  11763. + ESP_TASK_MAIN_STACK, NULL,
  11764. + ESP_TASK_MAIN_PRIO, NULL, ESP_TASK_MAIN_CORE);
  11765. + assert(res == pdTRUE);
  11766. + (void)res;
  11767. +#endif
  11768. +
  11769. +}
  11770. +
  11771. +static void main_task(void* args)
  11772. +{
  11773. +#if !CONFIG_FREERTOS_UNICORE
  11774. + // Wait for FreeRTOS initialization to finish on APP CPU, before replacing its startup stack
  11775. + while (port_xSchedulerRunning[1] == 0) {
  11776. + ;
  11777. + }
  11778. +#endif
  11779. +
  11780. + // [refactor-todo] check if there is a way to move the following block to esp_system startup
  11781. + heap_caps_enable_nonos_stack_heaps();
  11782. +
  11783. + // Now we have startup stack RAM available for heap, enable any DMA pool memory
  11784. +#if CONFIG_SPIRAM_MALLOC_RESERVE_INTERNAL
  11785. + if (g_spiram_ok) {
  11786. + esp_err_t r = esp_spiram_reserve_dma_pool(CONFIG_SPIRAM_MALLOC_RESERVE_INTERNAL);
  11787. + if (r != ESP_OK) {
  11788. + ESP_EARLY_LOGE(TAG, "Could not reserve internal/DMA pool (error 0x%x)", r);
  11789. + abort();
  11790. + }
  11791. + }
  11792. +#endif
  11793. +
  11794. + //Initialize task wdt if configured to do so
  11795. +#ifdef CONFIG_ESP_TASK_WDT_PANIC
  11796. + ESP_ERROR_CHECK(esp_task_wdt_init(CONFIG_ESP_TASK_WDT_TIMEOUT_S, true));
  11797. +#elif CONFIG_ESP_TASK_WDT
  11798. + ESP_ERROR_CHECK(esp_task_wdt_init(CONFIG_ESP_TASK_WDT_TIMEOUT_S, false));
  11799. +#endif
  11800. +
  11801. + //Add IDLE 0 to task wdt
  11802. +#ifdef CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0
  11803. + TaskHandle_t idle_0 = xTaskGetIdleTaskHandleForCPU(0);
  11804. + if(idle_0 != NULL){
  11805. + ESP_ERROR_CHECK(esp_task_wdt_add(idle_0));
  11806. + }
  11807. +#endif
  11808. + //Add IDLE 1 to task wdt
  11809. +#ifdef CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU1
  11810. + TaskHandle_t idle_1 = xTaskGetIdleTaskHandleForCPU(1);
  11811. + if(idle_1 != NULL){
  11812. + ESP_ERROR_CHECK(esp_task_wdt_add(idle_1));
  11813. + }
  11814. +#endif
  11815. +
  11816. + app_main();
  11817. + vTaskDelete(NULL);
  11818. +}
  11819. +
  11820. +// -------------------- Heap Related -----------------------
  11821. +
  11822. +bool xPortCheckValidTCBMem(const void *ptr)
  11823. +{
  11824. + return esp_ptr_internal(ptr) && esp_ptr_byte_accessible(ptr);
  11825. +}
  11826. +
  11827. +bool xPortcheckValidStackMem(const void *ptr)
  11828. +{
  11829. +#ifdef CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY
  11830. + return esp_ptr_byte_accessible(ptr);
  11831. +#else
  11832. + return esp_ptr_internal(ptr) && esp_ptr_byte_accessible(ptr);
  11833. +#endif
  11834. +}
  11835. +
  11836. +// ------------- FreeRTOS Static Allocation ----------------
  11837. +
  11838. +/*
  11839. +This function is required by FreeRTOS when configSUPPORT_STATIC_ALLOCATION is
  11840. +enabled and is used by FreeRTOS to obtain memory for its IDLE tasks.
  11841. +
  11842. +Like the pvPortMallocTcbMem() and pvPortMallocStackMem() macros, TCB and stack
  11843. +memory MUST be placed in internal RAM.
  11844. +*/
  11845. +void vApplicationGetIdleTaskMemory(StaticTask_t **ppxIdleTaskTCBBuffer,
  11846. + StackType_t **ppxIdleTaskStackBuffer,
  11847. + uint32_t *pulIdleTaskStackSize )
  11848. +{
  11849. + StaticTask_t *pxTCBBufferTemp;
  11850. + StackType_t *pxStackBufferTemp;
  11851. + //Allocate TCB and stack buffer in internal memory
  11852. + pxTCBBufferTemp = pvPortMallocTcbMem(sizeof(StaticTask_t));
  11853. + pxStackBufferTemp = pvPortMallocStackMem(configIDLE_TASK_STACK_SIZE);
  11854. + assert(pxTCBBufferTemp != NULL);
  11855. + assert(pxStackBufferTemp != NULL);
  11856. + //Write back pointers
  11857. + *ppxIdleTaskTCBBuffer = pxTCBBufferTemp;
  11858. + *ppxIdleTaskStackBuffer = pxStackBufferTemp;
  11859. + *pulIdleTaskStackSize = configIDLE_TASK_STACK_SIZE;
  11860. +}
  11861. +
  11862. +/*
  11863. +This function is required by FreeRTOS when configSUPPORT_STATIC_ALLOCATION is
  11864. +enabled and is used by the FreeRTOS Timer to obtain memory for its daemone task.
  11865. +
  11866. +
  11867. +Like the pvPortMallocTcbMem() and pvPortMallocStackMem() macros, TCB and stack
  11868. +memory MUST be placed in internal RAM.
  11869. +*/
  11870. +void vApplicationGetTimerTaskMemory(StaticTask_t **ppxTimerTaskTCBBuffer,
  11871. + StackType_t **ppxTimerTaskStackBuffer,
  11872. + uint32_t *pulTimerTaskStackSize )
  11873. +{
  11874. + StaticTask_t *pxTCBBufferTemp;
  11875. + StackType_t *pxStackBufferTemp;
  11876. + //Allocate TCB and stack buffer in internal memory
  11877. + pxTCBBufferTemp = pvPortMallocTcbMem(sizeof(StaticTask_t));
  11878. + pxStackBufferTemp = pvPortMallocStackMem(configTIMER_TASK_STACK_DEPTH);
  11879. + assert(pxTCBBufferTemp != NULL);
  11880. + assert(pxStackBufferTemp != NULL);
  11881. + //Write back pointers
  11882. + *ppxTimerTaskTCBBuffer = pxTCBBufferTemp;
  11883. + *ppxTimerTaskStackBuffer = pxStackBufferTemp;
  11884. + *pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;
  11885. +}
  11886. diff --git a/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/port/rt-thread/include/freertos/FreeRTOSConfig_arch.h b/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/port/rt-thread/include/freertos/FreeRTOSConfig_arch.h
  11887. new file mode 100644
  11888. index 0000000000..a7d534343f
  11889. --- /dev/null
  11890. +++ b/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/port/rt-thread/include/freertos/FreeRTOSConfig_arch.h
  11891. @@ -0,0 +1,105 @@
  11892. +/*
  11893. + FreeRTOS V10 - Copyright (C) 2021 Real Time Engineers Ltd.
  11894. + All rights reserved
  11895. +
  11896. + VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
  11897. +
  11898. + This file is part of the FreeRTOS distribution.
  11899. +
  11900. + FreeRTOS is free software; you can redistribute it and/or modify it under
  11901. + the terms of the GNU General Public License (version 2) as published by the
  11902. + Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
  11903. +
  11904. + ***************************************************************************
  11905. + >>! NOTE: The modification to the GPL is included to allow you to !<<
  11906. + >>! distribute a combined work that includes FreeRTOS without being !<<
  11907. + >>! obliged to provide the source code for proprietary components !<<
  11908. + >>! outside of the FreeRTOS kernel. !<<
  11909. + ***************************************************************************
  11910. +
  11911. + FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
  11912. + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  11913. + FOR A PARTICULAR PURPOSE. Full license text is available on the following
  11914. + link: http://www.freertos.org/a00114.html
  11915. +
  11916. + ***************************************************************************
  11917. + * *
  11918. + * FreeRTOS provides completely free yet professionally developed, *
  11919. + * robust, strictly quality controlled, supported, and cross *
  11920. + * platform software that is more than just the market leader, it *
  11921. + * is the industry's de facto standard. *
  11922. + * *
  11923. + * Help yourself get started quickly while simultaneously helping *
  11924. + * to support the FreeRTOS project by purchasing a FreeRTOS *
  11925. + * tutorial book, reference manual, or both: *
  11926. + * http://www.FreeRTOS.org/Documentation *
  11927. + * *
  11928. + ***************************************************************************
  11929. +
  11930. + http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
  11931. + the FAQ page "My application does not run, what could be wrong?". Have you
  11932. + defined configASSERT()?
  11933. +
  11934. + http://www.FreeRTOS.org/support - In return for receiving this top quality
  11935. + embedded software for free we request you assist our global community by
  11936. + participating in the support forum.
  11937. +
  11938. + http://www.FreeRTOS.org/training - Investing in training allows your team to
  11939. + be as productive as possible as early as possible. Now you can receive
  11940. + FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
  11941. + Ltd, and the world's leading authority on the world's leading RTOS.
  11942. +
  11943. + http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
  11944. + including FreeRTOS+Trace - an indispensable productivity tool, a DOS
  11945. + compatible FAT file system, and our tiny thread aware UDP/IP stack.
  11946. +
  11947. + http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
  11948. + Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
  11949. +
  11950. + http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
  11951. + Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
  11952. + licenses offer ticketed support, indemnification and commercial middleware.
  11953. +
  11954. + http://www.SafeRTOS.com - High Integrity Systems also provide a safety
  11955. + engineered and independently SIL3 certified version for use in safety and
  11956. + mission critical applications that require provable dependability.
  11957. +
  11958. + 1 tab == 4 spaces!
  11959. +*/
  11960. +
  11961. +#ifndef FREERTOS_CONFIG_RISCV_H
  11962. +#define FREERTOS_CONFIG_RISCV_H
  11963. +
  11964. +// This file is included in the common FreeRTOSConfig.h.
  11965. +
  11966. +#include "sdkconfig.h"
  11967. +
  11968. +#define configUSE_PORT_OPTIMISED_TASK_SELECTION 0
  11969. +
  11970. +#ifndef __ASSEMBLER__
  11971. +#if CONFIG_IDF_TARGET_ESP32C3
  11972. +#include "esp32c3/rom/ets_sys.h"
  11973. +#elif CONFIG_IDF_TARGET_ESP32H2
  11974. +#include "esp32h2/rom/ets_sys.h"
  11975. +#endif
  11976. +#endif // __ASSEMBLER__
  11977. +
  11978. +/* The maximum interrupt priority from which FreeRTOS.org API functions can
  11979. + be called. Only API functions that end in ...FromISR() can be used within
  11980. + interrupts. */
  11981. +#define configMAX_SYSCALL_INTERRUPT_PRIORITY 0
  11982. +
  11983. +#ifndef configISR_STACK_SIZE
  11984. +#define configISR_STACK_SIZE (CONFIG_FREERTOS_ISR_STACKSIZE)
  11985. +#endif
  11986. +
  11987. +#ifndef __ASSEMBLER__
  11988. +#if CONFIG_APPTRACE_SV_ENABLE
  11989. +extern int xPortSwitchFlag;
  11990. +#define os_task_switch_is_pended(_cpu_) (xPortSwitchFlag)
  11991. +#else
  11992. +#define os_task_switch_is_pended(_cpu_) (false)
  11993. +#endif
  11994. +#endif
  11995. +
  11996. +#endif // FREERTOS_CONFIG_RISCV_H
  11997. diff --git a/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/port/rt-thread/include/freertos/portmacro.h b/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/port/rt-thread/include/freertos/portmacro.h
  11998. new file mode 100644
  11999. index 0000000000..ce683ac301
  12000. --- /dev/null
  12001. +++ b/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/port/rt-thread/include/freertos/portmacro.h
  12002. @@ -0,0 +1,107 @@
  12003. +/*
  12004. + * FreeRTOS Kernel V10.4.6
  12005. + * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  12006. + *
  12007. + * SPDX-License-Identifier: MIT
  12008. + *
  12009. + * Permission is hereby granted, free of charge, to any person obtaining a copy of
  12010. + * this software and associated documentation files (the "Software"), to deal in
  12011. + * the Software without restriction, including without limitation the rights to
  12012. + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  12013. + * the Software, and to permit persons to whom the Software is furnished to do so,
  12014. + * subject to the following conditions:
  12015. + *
  12016. + * The above copyright notice and this permission notice shall be included in all
  12017. + * copies or substantial portions of the Software.
  12018. + *
  12019. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12020. + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  12021. + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  12022. + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  12023. + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  12024. + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  12025. + *
  12026. + * https://www.FreeRTOS.org
  12027. + * https://github.com/FreeRTOS
  12028. + *
  12029. + */
  12030. +
  12031. +
  12032. +#ifndef PORTMACRO_H
  12033. + #define PORTMACRO_H
  12034. +
  12035. + #ifdef __cplusplus
  12036. + extern "C" {
  12037. + #endif
  12038. +
  12039. +/*-----------------------------------------------------------
  12040. + * Port specific definitions.
  12041. + *
  12042. + * The settings in this file configure FreeRTOS correctly for the
  12043. + * given hardware and compiler.
  12044. + *
  12045. + * These settings should not be altered.
  12046. + *-----------------------------------------------------------
  12047. + */
  12048. +
  12049. +/* Type definitions. */
  12050. + #define portCHAR char
  12051. + #define portFLOAT float
  12052. + #define portDOUBLE double
  12053. + #define portLONG long
  12054. + #define portSHORT short
  12055. + #define portSTACK_TYPE rt_ubase_t
  12056. + #define portBASE_TYPE rt_base_t
  12057. +
  12058. + typedef portSTACK_TYPE StackType_t;
  12059. + typedef rt_base_t BaseType_t;
  12060. + typedef rt_ubase_t UBaseType_t;
  12061. + typedef rt_tick_t TickType_t;
  12062. + #define portMAX_DELAY ( TickType_t ) RT_TICK_MAX
  12063. +
  12064. + struct rt_semaphore_wrapper
  12065. + {
  12066. + struct rt_semaphore sem;
  12067. + rt_uint16_t max_value;
  12068. + };
  12069. +
  12070. +/*-----------------------------------------------------------*/
  12071. +
  12072. +/* Architecture specifics. */
  12073. + #define portBYTE_ALIGNMENT RT_ALIGN_SIZE
  12074. + #define portPOINTER_SIZE_TYPE rt_size_t
  12075. +/*-----------------------------------------------------------*/
  12076. +
  12077. +/* Scheduler utilities. */
  12078. + #define portYIELD() rt_thread_yield()
  12079. + #define portYIELD_FROM_ISR( x ) rt_thread_yield()
  12080. +
  12081. +/*-----------------------------------------------------------*/
  12082. +
  12083. +/* Critical section management. */
  12084. + extern void vPortEnterCritical( void );
  12085. + extern void vPortExitCritical( void );
  12086. + #define portSET_INTERRUPT_MASK_FROM_ISR() rt_hw_interrupt_disable()
  12087. + #define portCLEAR_INTERRUPT_MASK_FROM_ISR( x ) rt_hw_interrupt_enable( x )
  12088. + #define portDISABLE_INTERRUPTS() vPortEnterCritical()
  12089. + #define portENABLE_INTERRUPTS() vPortExitCritical()
  12090. + //#define portENTER_CRITICAL() vPortEnterCritical()
  12091. + //#define portEXIT_CRITICAL() vPortExitCritical()
  12092. +
  12093. +/*-----------------------------------------------------------*/
  12094. +
  12095. +/* Use this macro to calculate the buffer size when allocating a queue statically
  12096. + * To ensure the buffer can fit the desired number of messages
  12097. + */
  12098. + #define QUEUE_BUFFER_SIZE( uxQueueLength, uxItemSize ) ( ( RT_ALIGN( uxItemSize, RT_ALIGN_SIZE ) + sizeof( void * ) ) * uxQueueLength )
  12099. +
  12100. + BaseType_t rt_err_to_freertos(rt_err_t rt_err);
  12101. +
  12102. +/* For ESP32 */
  12103. + #include "portmacro_esp32c3.h"
  12104. +
  12105. + #ifdef __cplusplus
  12106. + }
  12107. + #endif
  12108. +
  12109. +#endif /* PORTMACRO_H */
  12110. diff --git a/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/port/rt-thread/include/freertos/portmacro_deprecated.h b/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/port/rt-thread/include/freertos/portmacro_deprecated.h
  12111. new file mode 100644
  12112. index 0000000000..597d99c333
  12113. --- /dev/null
  12114. +++ b/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/port/rt-thread/include/freertos/portmacro_deprecated.h
  12115. @@ -0,0 +1,94 @@
  12116. +/*
  12117. + * SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
  12118. + *
  12119. + * SPDX-License-Identifier: Apache-2.0
  12120. + */
  12121. +
  12122. +/* ---------------------------------------------------- Deprecate ------------------------------------------------------
  12123. + * - Macros or functions that should be deprecated in v5.0, then removed in the next major release
  12124. + * - Kept as not to cause a breaking change
  12125. + * - Include this header at the end of portmacro.h
  12126. + * ------------------------------------------------------------------------------------------------------------------ */
  12127. +
  12128. +/**
  12129. + * @brief Disable interrupts in a nested manner
  12130. + *
  12131. + * Does the exact same thing as portSET_INTERRUPT_MASK_FROM_ISR()
  12132. + *
  12133. + * @deprecated This function is deprecated. Call portSET_INTERRUPT_MASK_FROM_ISR() instead
  12134. + */
  12135. +static inline __attribute__((deprecated)) UBaseType_t portENTER_CRITICAL_NESTED(void) {
  12136. + return portSET_INTERRUPT_MASK_FROM_ISR();
  12137. +}
  12138. +
  12139. +/**
  12140. + * @brief Reenables interrupts in a nested manner
  12141. + *
  12142. + * Does the exact same thing as portCLEAR_INTERRUPT_MASK_FROM_ISR()
  12143. + *
  12144. + * @deprecated This function is deprecated. Call portCLEAR_INTERRUPT_MASK_FROM_ISR() instead
  12145. + */
  12146. +static inline void __attribute__((deprecated)) portEXIT_CRITICAL_NESTED(UBaseType_t prev_level)
  12147. +{
  12148. + portCLEAR_INTERRUPT_MASK_FROM_ISR(prev_level);
  12149. +}
  12150. +
  12151. +/* ---------------------- Spinlocks --------------------- */
  12152. +
  12153. +/**
  12154. + * @brief Deprecated placed holder function to initialize a spinlock
  12155. + *
  12156. + * Currently does nothing.
  12157. + *
  12158. + * @deprecated This function is deprecated. If on multi-core, use spinlock_initialize() instead
  12159. + * @param[in] mux Spinlock
  12160. + */
  12161. +static inline void __attribute__((deprecated)) __attribute__((always_inline)) vPortCPUInitializeMutex(portMUX_TYPE *mux)
  12162. +{
  12163. + (void)mux;
  12164. +}
  12165. +
  12166. +/**
  12167. + * @brief Deprecated placed holder function to acquire a spinlock
  12168. + *
  12169. + * Currently does nothing.
  12170. + *
  12171. + * @deprecated This function is deprecated. If on multi-core, use spinlock_acquire() instead
  12172. + * @param[in] mux Spinlock
  12173. + */
  12174. +static inline void __attribute__((deprecated)) __attribute__((always_inline)) vPortCPUAcquireMutex(portMUX_TYPE *mux)
  12175. +{
  12176. + (void)mux;
  12177. +}
  12178. +
  12179. +/**
  12180. + * @brief Deprecated placed holder function to acquire a spinlock but with a specified timeout
  12181. + *
  12182. + * Currently just returns true
  12183. + *
  12184. + * @deprecated This function is deprecated. If on multi-core, use spinlock_acquire() instead
  12185. + * @note Does not have deprecated attribute due to usage in app_trace_util.c
  12186. + * @param[in] mux Spinlock
  12187. + * @param[in] timeout Timeout in number of CPU cycles
  12188. + * @return true Always returns true
  12189. + */
  12190. +static inline bool __attribute__((always_inline)) vPortCPUAcquireMutexTimeout(portMUX_TYPE *mux, int timeout_cycles)
  12191. +{
  12192. + (void)mux;
  12193. + (void)timeout_cycles;
  12194. + return true;
  12195. +}
  12196. +
  12197. +/**
  12198. + * @brief Deprecated placed holder function to release a spinlock
  12199. + *
  12200. + * Currently does nothing.
  12201. + *
  12202. + * @deprecated This function is deprecated. If on multi-core, use spinlock_release() instead
  12203. + * @note Does not have deprecated attribute due to usage in app_trace_util.c
  12204. + * @param[in] mux Spinlock
  12205. + */
  12206. +static inline void __attribute__((always_inline)) vPortCPUReleaseMutex(portMUX_TYPE *mux)
  12207. +{
  12208. + (void)mux;
  12209. +}
  12210. diff --git a/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/port/rt-thread/include/freertos/portmacro_esp32c3.h b/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/port/rt-thread/include/freertos/portmacro_esp32c3.h
  12211. new file mode 100644
  12212. index 0000000000..88459bb6a2
  12213. --- /dev/null
  12214. +++ b/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/port/rt-thread/include/freertos/portmacro_esp32c3.h
  12215. @@ -0,0 +1,424 @@
  12216. +/*
  12217. + * FreeRTOS Kernel V10.4.3
  12218. + * Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  12219. + *
  12220. + * Permission is hereby granted, free of charge, to any person obtaining a copy of
  12221. + * this software and associated documentation files (the "Software"), to deal in
  12222. + * the Software without restriction, including without limitation the rights to
  12223. + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  12224. + * the Software, and to permit persons to whom the Software is furnished to do so,
  12225. + * subject to the following conditions:
  12226. + *
  12227. + * The above copyright notice and this permission notice shall be included in all
  12228. + * copies or substantial portions of the Software.
  12229. + *
  12230. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12231. + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  12232. + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  12233. + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  12234. + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  12235. + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  12236. + *
  12237. + * http://www.FreeRTOS.org
  12238. + * http://aws.amazon.com/freertos
  12239. + *
  12240. + * 1 tab == 4 spaces!
  12241. + */
  12242. +
  12243. +#ifndef PORTMACRO_ESP32C3_H
  12244. +#define PORTMACRO_ESP32C3_H
  12245. +
  12246. +#ifndef __ASSEMBLER__
  12247. +
  12248. +#include "sdkconfig.h"
  12249. +#include <stdint.h>
  12250. +#include <stdlib.h>
  12251. +#include <stdbool.h>
  12252. +#include <stdio.h>
  12253. +#include "soc/spinlock.h"
  12254. +#include "soc/interrupt_core0_reg.h"
  12255. +#include "soc/cpu.h"
  12256. +#include "esp_attr.h"
  12257. +#include "esp_rom_sys.h"
  12258. +#include "esp_timer.h" /* required for FreeRTOS run time stats */
  12259. +#include "esp_heap_caps.h"
  12260. +#include "esp_system.h" /* required by esp_get_...() functions in portable.h. [refactor-todo] Update portable.h */
  12261. +#include "esp_newlib.h"
  12262. +//#include "portbenchmark.h"
  12263. +
  12264. +/* [refactor-todo] These includes are not directly used in this file. They are kept into to prevent a breaking change. Remove these. */
  12265. +#include <limits.h>
  12266. +#ifdef CONFIG_LEGACY_INCLUDE_COMMON_HEADERS
  12267. +#include "soc/soc_memory_layout.h"
  12268. +#endif
  12269. +
  12270. +#ifdef __cplusplus
  12271. +extern "C" {
  12272. +#endif
  12273. +
  12274. +
  12275. +
  12276. +/* --------------------------------------------------- Port Types ------------------------------------------------------
  12277. + * - Port specific types.
  12278. + * - The settings in this file configure FreeRTOS correctly for the given hardware and compiler.
  12279. + * - These settings should not be altered.
  12280. + * - The port types must come first as they are used further down in this file
  12281. + * ------------------------------------------------------------------------------------------------------------------ */
  12282. +
  12283. +/* Task function macros as described on the FreeRTOS.org WEB site. */
  12284. +#define portTASK_FUNCTION_PROTO(vFunction, pvParameters) void vFunction(void *pvParameters)
  12285. +#define portTASK_FUNCTION(vFunction, pvParameters) void vFunction(void *pvParameters)
  12286. +
  12287. +// interrupt module will mask interrupt with priority less than threshold
  12288. +#define RVHAL_EXCM_LEVEL 4
  12289. +
  12290. +
  12291. +/* ----------------------------------------------- Port Configurations -------------------------------------------------
  12292. + * - Configurations values supplied by each port
  12293. + * - Required by FreeRTOS
  12294. + * ------------------------------------------------------------------------------------------------------------------ */
  12295. +
  12296. +#define portCRITICAL_NESTING_IN_TCB 0
  12297. +#define portSTACK_GROWTH (-1)
  12298. +#define portTICK_PERIOD_MS ((TickType_t) (1000 / configTICK_RATE_HZ))
  12299. +#define portNOP() __asm volatile (" nop ")
  12300. +
  12301. +
  12302. +
  12303. +/* ---------------------------------------------- Forward Declarations -------------------------------------------------
  12304. + * - Forward declarations of all the port functions and macros need to implement the FreeRTOS porting interface
  12305. + * - These must come before definition/declaration of the FreeRTOS porting interface
  12306. + * ------------------------------------------------------------------------------------------------------------------ */
  12307. +
  12308. +// --------------------- Interrupts ------------------------
  12309. +
  12310. +/**
  12311. + * @brief Checks if the current core is in an ISR context
  12312. + *
  12313. + * - ISR context consist of Low/Mid priority ISR, or time tick ISR
  12314. + * - High priority ISRs aren't detected here, but they normally cannot call C code, so that should not be an issue anyway.
  12315. + *
  12316. + * @note [refactor-todo] Check if this should be inlined
  12317. + * @return
  12318. + * - pdTRUE if in ISR
  12319. + * - pdFALSE otherwise
  12320. + */
  12321. +BaseType_t xPortInIsrContext(void);
  12322. +
  12323. +/**
  12324. + * @brief Check if in ISR context from High priority ISRs
  12325. + *
  12326. + * - Called from High priority ISR
  12327. + * - Checks if the previous context (before high priority interrupt) was in ISR context (meaning low/med priority)
  12328. + *
  12329. + * @note [refactor-todo] Check if this should be inlined
  12330. + * @return
  12331. + * - pdTRUE if in previous in ISR context
  12332. + * - pdFALSE otherwise
  12333. + */
  12334. +BaseType_t xPortInterruptedFromISRContext(void);
  12335. +
  12336. +/* ---------------------- Spinlocks ------------------------
  12337. + - Spinlocks added to match API with SMP FreeRTOS. Single core RISC-V does not need spin locks
  12338. + - Because single core does not have a primitive spinlock data type, we have to implement one here
  12339. + * @note [refactor-todo] Refactor critical section API so that this is no longer required
  12340. + * ------------------------------------------------------ */
  12341. +
  12342. +/**
  12343. + * @brief Spinlock object
  12344. + * Owner:
  12345. + * - Set to 0 if uninitialized
  12346. + * - Set to portMUX_FREE_VAL when free
  12347. + * - Set to CORE_ID_REGVAL_PRO or CORE_ID_REGVAL_AP when locked
  12348. + * - Any other value indicates corruption
  12349. + * Count:
  12350. + * - 0 if unlocked
  12351. + * - Recursive count if locked
  12352. + *
  12353. + * @note Not a true spinlock as single core RISC-V does not have atomic compare and set instruction
  12354. + * @note Keep portMUX_INITIALIZER_UNLOCKED in sync with this struct
  12355. + */
  12356. +typedef struct {
  12357. + uint32_t owner;
  12358. + uint32_t count;
  12359. +} portMUX_TYPE;
  12360. +/**< Spinlock initializer */
  12361. +#define portMUX_INITIALIZER_UNLOCKED { \
  12362. + .owner = portMUX_FREE_VAL, \
  12363. + .count = 0, \
  12364. + }
  12365. +#define portMUX_FREE_VAL SPINLOCK_FREE /**< Spinlock is free. [refactor-todo] check if this is still required */
  12366. +#define portMUX_NO_TIMEOUT SPINLOCK_WAIT_FOREVER /**< When passed for 'timeout_cycles', spin forever if necessary. [refactor-todo] check if this is still required */
  12367. +#define portMUX_TRY_LOCK SPINLOCK_NO_WAIT /**< Try to acquire the spinlock a single time only. [refactor-todo] check if this is still required */
  12368. +#define portMUX_INITIALIZE(mux) ({ \
  12369. + (mux)->owner = portMUX_FREE_VAL; \
  12370. + (mux)->count = 0; \
  12371. +})
  12372. +
  12373. +/**
  12374. + * @brief Wrapper for atomic compare-and-set instruction
  12375. + *
  12376. + * @note Isn't a real atomic CAS.
  12377. + * @note [refactor-todo] check if we still need this
  12378. + * @note [refactor-todo] Check if this function should be renamed (due to void return type)
  12379. + *
  12380. + * @param[inout] addr Pointer to target address
  12381. + * @param[in] compare Compare value
  12382. + * @param[inout] set Pointer to set value
  12383. + */
  12384. +static inline void __attribute__((always_inline)) uxPortCompareSet(volatile uint32_t *addr, uint32_t compare, uint32_t *set);
  12385. +
  12386. +/**
  12387. + * @brief Wrapper for atomic compare-and-set instruction in external RAM
  12388. + *
  12389. + * @note Isn't a real atomic CAS.
  12390. + * @note [refactor-todo] check if we still need this
  12391. + * @note [refactor-todo] Check if this function should be renamed (due to void return type)
  12392. + *
  12393. + * @param[inout] addr Pointer to target address
  12394. + * @param[in] compare Compare value
  12395. + * @param[inout] set Pointer to set value
  12396. + */
  12397. +static inline void uxPortCompareSetExtram(volatile uint32_t *addr, uint32_t compare, uint32_t *set);
  12398. +
  12399. +// ---------------------- Yielding -------------------------
  12400. +
  12401. +/**
  12402. + * @brief Perform a context switch from a task
  12403. + *
  12404. + * @note [refactor-todo] The rest of ESP-IDF should call taskYield() instead
  12405. + */
  12406. +#define vPortYield() portYIELD()
  12407. +
  12408. +/**
  12409. + * @brief Perform a context switch from an ISR
  12410. + */
  12411. +#define vPortYieldFromISR() portYIELD_FROM_ISR(0)
  12412. +
  12413. +/**
  12414. + * @brief Checks if the current core can yield
  12415. + *
  12416. + * - A core cannot yield if its in an ISR or in a critical section
  12417. + *
  12418. + * @note [refactor-todo] See if this can be separated from port macro
  12419. + * @note [refactor-todo] Check if this function should be renamed (due to bool return type)
  12420. + * @return true Core can yield
  12421. + * @return false Core cannot yield
  12422. + */
  12423. +static inline bool IRAM_ATTR xPortCanYield(void);
  12424. +
  12425. +// ------------------- Hook Functions ----------------------
  12426. +
  12427. +extern void esp_vApplicationIdleHook(void);
  12428. +extern void esp_vApplicationTickHook(void);
  12429. +
  12430. +/**
  12431. + * @brief Hook function called on entry to tickless idle
  12432. + *
  12433. + * - Implemented in pm_impl.c
  12434. + *
  12435. + * @param xExpectedIdleTime Expected idle time
  12436. + */
  12437. +void vApplicationSleep(TickType_t xExpectedIdleTime);
  12438. +
  12439. +// ----------------------- System --------------------------
  12440. +
  12441. +/**
  12442. + * @brief Get the tick rate per second
  12443. + *
  12444. + * @note [refactor-todo] make this inline
  12445. + * @note [refactor-todo] Check if this function should be renamed (due to uint return type)
  12446. + * @return uint32_t Tick rate in Hz
  12447. + */
  12448. +uint32_t xPortGetTickRateHz(void);
  12449. +
  12450. +/**
  12451. + * @brief Set a watchpoint to watch the last 32 bytes of the stack
  12452. + *
  12453. + * Callback to set a watchpoint on the end of the stack. Called every context switch to change the stack watchpoint
  12454. + * around.
  12455. + *
  12456. + * @param pxStackStart Pointer to the start of the stack
  12457. + */
  12458. +void vPortSetStackWatchpoint(void *pxStackStart);
  12459. +
  12460. +/**
  12461. + * @brief Get the current core's ID
  12462. + *
  12463. + * @note Added to be compatible with SMP API
  12464. + * @note [refactor-todo] IDF should call a FreeRTOS like macro instead of port function directly
  12465. + * @return BaseType_t Core ID
  12466. + */
  12467. +static inline BaseType_t IRAM_ATTR xPortGetCoreID(void)
  12468. +{
  12469. + return (uint32_t) cpu_hal_get_core_id();
  12470. +}
  12471. +
  12472. +
  12473. +
  12474. +/* ------------------------------------------- FreeRTOS Porting Interface ----------------------------------------------
  12475. + * - Contains all the mappings of the macros required by FreeRTOS
  12476. + * - Most come after forward declare as porting macros map to declared functions
  12477. + * - Maps to forward declared functions
  12478. + * ------------------------------------------------------------------------------------------------------------------ */
  12479. +
  12480. +// ----------------------- Memory --------------------------
  12481. +
  12482. +/**
  12483. + * @brief Task memory allocation macros
  12484. + *
  12485. + * @note Because the ROM routines don't necessarily handle a stack in external RAM correctly, we force the stack
  12486. + * memory to always be internal.
  12487. + * @note [refactor-todo] Update portable.h to match v10.4.3 to use new malloc prototypes
  12488. + */
  12489. +#define portTcbMemoryCaps (MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT)
  12490. +#define portStackMemoryCaps (MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT)
  12491. +#define pvPortMallocTcbMem(size) pvPortMalloc(size)
  12492. +#define pvPortMallocStackMem(size) pvPortMalloc(size)
  12493. +
  12494. +// ------------------ Critical Sections --------------------
  12495. +#define portENTER_CRITICAL(mux) {(void)mux; vPortEnterCritical();}
  12496. +#define portEXIT_CRITICAL(mux) {(void)mux; vPortExitCritical();}
  12497. +#define portTRY_ENTER_CRITICAL(mux, timeout) ({ \
  12498. + (void)mux; (void)timeout; \
  12499. + vPortEnterCritical(); \
  12500. + BaseType_t ret = pdPASS; \
  12501. + ret; \
  12502. +})
  12503. +//In single-core RISC-V, we can use the same critical section API
  12504. +#define portENTER_CRITICAL_ISR(mux) portENTER_CRITICAL(mux)
  12505. +#define portEXIT_CRITICAL_ISR(mux) portEXIT_CRITICAL(mux)
  12506. +#define portTRY_ENTER_CRITICAL_ISR(mux, timeout) portTRY_ENTER_CRITICAL(mux, timeout)
  12507. +
  12508. +/* [refactor-todo] on RISC-V, both ISR and non-ISR cases result in the same call. We can redefine this macro */
  12509. +#define portENTER_CRITICAL_SAFE(mux) ({ \
  12510. + if (xPortInIsrContext()) { \
  12511. + portENTER_CRITICAL_ISR(mux); \
  12512. + } else { \
  12513. + portENTER_CRITICAL(mux); \
  12514. + } \
  12515. +})
  12516. +#define portEXIT_CRITICAL_SAFE(mux) ({ \
  12517. + if (xPortInIsrContext()) { \
  12518. + portEXIT_CRITICAL_ISR(mux); \
  12519. + } else { \
  12520. + portEXIT_CRITICAL(mux); \
  12521. + } \
  12522. +})
  12523. +#define portTRY_ENTER_CRITICAL_SAFE(mux, timeout) portENTER_CRITICAL_SAFE(mux, timeout)
  12524. +
  12525. +// ---------------------- Yielding -------------------------
  12526. +
  12527. +#define portEND_SWITCHING_ISR(xSwitchRequired) if(xSwitchRequired) vPortYield()
  12528. +/* Yielding within an API call (when interrupts are off), means the yield should be delayed
  12529. + until interrupts are re-enabled.
  12530. + To do this, we use the "cross-core" interrupt as a trigger to yield on this core when interrupts are re-enabled.This
  12531. + is the same interrupt & code path which is used to trigger a yield between CPUs, although in this case the yield is
  12532. + happening on the same CPU.
  12533. +*/
  12534. +#define portYIELD_WITHIN_API() portYIELD()
  12535. +
  12536. +// ------------------- Hook Functions ----------------------
  12537. +
  12538. +#ifndef CONFIG_FREERTOS_LEGACY_HOOKS
  12539. +#define vApplicationIdleHook esp_vApplicationIdleHook
  12540. +#define vApplicationTickHook esp_vApplicationTickHook
  12541. +#endif /* !CONFIG_FREERTOS_LEGACY_HOOKS */
  12542. +#define portSUPPRESS_TICKS_AND_SLEEP(idleTime) vApplicationSleep(idleTime)
  12543. +
  12544. +// ------------------- Run Time Stats ----------------------
  12545. +
  12546. +#define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS()
  12547. +#define portGET_RUN_TIME_COUNTER_VALUE() 0
  12548. +#ifdef CONFIG_FREERTOS_RUN_TIME_STATS_USING_ESP_TIMER
  12549. +/* Coarse resolution time (us) */
  12550. +#define portALT_GET_RUN_TIME_COUNTER_VALUE(x) do {x = (uint32_t)esp_timer_get_time();} while(0)
  12551. +#endif
  12552. +
  12553. +
  12554. +
  12555. +/* --------------------------------------------- Inline Implementations ------------------------------------------------
  12556. + * - Implementation of inline functions of the forward declares
  12557. + * - Should come after forward declare and FreeRTOS Porting interface, as implementation may use both.
  12558. + * - For implementation of non-inlined functions, see port.c, port_common.c, or other assembly files
  12559. + * ------------------------------------------------------------------------------------------------------------------ */
  12560. +
  12561. +// --------------------- Interrupts ------------------------
  12562. +
  12563. +
  12564. +
  12565. +// ---------------------- Spinlocks ------------------------
  12566. +
  12567. +static inline void __attribute__((always_inline)) uxPortCompareSet(volatile uint32_t *addr, uint32_t compare, uint32_t *set)
  12568. +{
  12569. + compare_and_set_native(addr, compare, set);
  12570. +}
  12571. +
  12572. +static inline void uxPortCompareSetExtram(volatile uint32_t *addr, uint32_t compare, uint32_t *set)
  12573. +{
  12574. +#if defined(CONFIG_SPIRAM)
  12575. + compare_and_set_extram(addr, compare, set);
  12576. +#endif
  12577. +}
  12578. +
  12579. +// ---------------------- Yielding -------------------------
  12580. +
  12581. +static inline bool IRAM_ATTR xPortCanYield(void)
  12582. +{
  12583. + uint32_t threshold = REG_READ(INTERRUPT_CORE0_CPU_INT_THRESH_REG);
  12584. + /* when enter critical code, FreeRTOS will mask threshold to RVHAL_EXCM_LEVEL
  12585. + * and exit critical code, will recover threshold value (1). so threshold <= 1
  12586. + * means not in critical code
  12587. + */
  12588. + return (threshold <= 1);
  12589. +}
  12590. +
  12591. +
  12592. +
  12593. +/* ------------------------------------------------------ Misc ---------------------------------------------------------
  12594. + * - Miscellaneous porting macros
  12595. + * - These are not port of the FreeRTOS porting interface, but are used by other FreeRTOS dependent components
  12596. + * ------------------------------------------------------------------------------------------------------------------ */
  12597. +
  12598. +// -------------------- Heap Related -----------------------
  12599. +
  12600. +/**
  12601. + * @brief Checks if a given piece of memory can be used to store a task's TCB
  12602. + *
  12603. + * - Defined in port_common.c
  12604. + *
  12605. + * @param ptr Pointer to memory
  12606. + * @return true Memory can be used to store a TCB
  12607. + * @return false Otherwise
  12608. + */
  12609. +bool xPortCheckValidTCBMem(const void *ptr);
  12610. +
  12611. +/**
  12612. + * @brief Checks if a given piece of memory can be used to store a task's stack
  12613. + *
  12614. + * - Defined in port_common.c
  12615. + *
  12616. + * @param ptr Pointer to memory
  12617. + * @return true Memory can be used to store a task stack
  12618. + * @return false Otherwise
  12619. + */
  12620. +bool xPortcheckValidStackMem(const void *ptr);
  12621. +
  12622. +#define portVALID_TCB_MEM(ptr) xPortCheckValidTCBMem(ptr)
  12623. +#define portVALID_STACK_MEM(ptr) xPortcheckValidStackMem(ptr)
  12624. +
  12625. +
  12626. +
  12627. +/* ---------------------------------------------------- Deprecate ------------------------------------------------------
  12628. + * - Pull in header containing deprecated macros here
  12629. + * ------------------------------------------------------------------------------------------------------------------ */
  12630. +
  12631. +#include "portmacro_deprecated.h"
  12632. +
  12633. +#ifdef __cplusplus
  12634. +}
  12635. +#endif
  12636. +
  12637. +#endif //__ASSEMBLER__
  12638. +
  12639. +#endif /* PORTMACRO_H */
  12640. diff --git a/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/port/rt-thread/port.c b/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/port/rt-thread/port.c
  12641. new file mode 100644
  12642. index 0000000000..9d8195f832
  12643. --- /dev/null
  12644. +++ b/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/port/rt-thread/port.c
  12645. @@ -0,0 +1,44 @@
  12646. +#include <FreeRTOS.h>
  12647. +
  12648. +static rt_base_t level = 0;
  12649. +static rt_base_t critical_nesting = 0;
  12650. +
  12651. +void vPortEnterCritical( void )
  12652. +{
  12653. + if ( critical_nesting == 0 )
  12654. + {
  12655. + level = rt_hw_interrupt_disable();
  12656. + }
  12657. + critical_nesting += 1;
  12658. +}
  12659. +
  12660. +void vPortExitCritical( void )
  12661. +{
  12662. + critical_nesting -= 1;
  12663. + if ( critical_nesting == 0 )
  12664. + {
  12665. + rt_hw_interrupt_enable( level );
  12666. + }
  12667. +}
  12668. +
  12669. +void vPortEndScheduler( void )
  12670. +{
  12671. + /* Not implemented in ports where there is nothing to return to. */
  12672. +}
  12673. +
  12674. +BaseType_t rt_err_to_freertos(rt_err_t rt_err)
  12675. +{
  12676. + switch(-rt_err)
  12677. + {
  12678. + case RT_EOK:
  12679. + return pdPASS;
  12680. + case RT_ENOMEM:
  12681. + return errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY;
  12682. + case RT_EFULL:
  12683. + return errQUEUE_FULL;
  12684. + case RT_EEMPTY:
  12685. + return errQUEUE_EMPTY;
  12686. + default:
  12687. + return pdFAIL;
  12688. + }
  12689. +}
  12690. diff --git a/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/port/rt-thread/port_esp32c3.c b/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/port/rt-thread/port_esp32c3.c
  12691. new file mode 100644
  12692. index 0000000000..64fbe9b15b
  12693. --- /dev/null
  12694. +++ b/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/port/rt-thread/port_esp32c3.c
  12695. @@ -0,0 +1,197 @@
  12696. +/*
  12697. + FreeRTOS V8.2.3 - Copyright (C) 2015 Real Time Engineers Ltd.
  12698. + All rights reserved
  12699. +
  12700. + VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
  12701. +
  12702. + This file is part of the FreeRTOS distribution and was contributed
  12703. + to the project by Technolution B.V. (www.technolution.nl,
  12704. + freertos-riscv@technolution.eu) under the terms of the FreeRTOS
  12705. + contributors license.
  12706. +
  12707. + FreeRTOS is free software; you can redistribute it and/or modify it under
  12708. + the terms of the GNU General Public License (version 2) as published by the
  12709. + Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.
  12710. +
  12711. + ***************************************************************************
  12712. + >>! NOTE: The modification to the GPL is included to allow you to !<<
  12713. + >>! distribute a combined work that includes FreeRTOS without being !<<
  12714. + >>! obliged to provide the source code for proprietary components !<<
  12715. + >>! outside of the FreeRTOS kernel. !<<
  12716. + ***************************************************************************
  12717. +
  12718. + FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
  12719. + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  12720. + FOR A PARTICULAR PURPOSE. Full license text is available on the following
  12721. + link: http://www.freertos.org/a00114.html
  12722. +
  12723. + ***************************************************************************
  12724. + * *
  12725. + * FreeRTOS provides completely free yet professionally developed, *
  12726. + * robust, strictly quality controlled, supported, and cross *
  12727. + * platform software that is more than just the market leader, it *
  12728. + * is the industry's de facto standard. *
  12729. + * *
  12730. + * Help yourself get started quickly while simultaneously helping *
  12731. + * to support the FreeRTOS project by purchasing a FreeRTOS *
  12732. + * tutorial book, reference manual, or both: *
  12733. + * http://www.FreeRTOS.org/Documentation *
  12734. + * *
  12735. + ***************************************************************************
  12736. +
  12737. + http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
  12738. + the FAQ page "My application does not run, what could be wrong?". Have you
  12739. + defined configASSERT()?
  12740. +
  12741. + http://www.FreeRTOS.org/support - In return for receiving this top quality
  12742. + embedded software for free we request you assist our global community by
  12743. + participating in the support forum.
  12744. +
  12745. + http://www.FreeRTOS.org/training - Investing in training allows your team to
  12746. + be as productive as possible as early as possible. Now you can receive
  12747. + FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
  12748. + Ltd, and the world's leading authority on the world's leading RTOS.
  12749. +
  12750. + http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
  12751. + including FreeRTOS+Trace - an indispensable productivity tool, a DOS
  12752. + compatible FAT file system, and our tiny thread aware UDP/IP stack.
  12753. +
  12754. + http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
  12755. + Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
  12756. +
  12757. + http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
  12758. + Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
  12759. + licenses offer ticketed support, indemnification and commercial middleware.
  12760. +
  12761. + http://www.SafeRTOS.com - High Integrity Systems also provide a safety
  12762. + engineered and independently SIL3 certified version for use in safety and
  12763. + mission critical applications that require provable dependability.
  12764. +
  12765. + 1 tab == 4 spaces!
  12766. +*/
  12767. +
  12768. +/*-----------------------------------------------------------------------
  12769. + * Implementation of functions defined in portable.h for the RISC-V port.
  12770. + *----------------------------------------------------------------------*/
  12771. +
  12772. +#include "sdkconfig.h"
  12773. +#include <string.h>
  12774. +#include "soc/soc_caps.h"
  12775. +#include "soc/periph_defs.h"
  12776. +#include "soc/system_reg.h"
  12777. +#include "hal/systimer_hal.h"
  12778. +#include "hal/systimer_ll.h"
  12779. +#include "riscv/rvruntime-frames.h"
  12780. +#include "riscv/riscv_interrupts.h"
  12781. +#include "riscv/interrupt.h"
  12782. +#include "esp_private/crosscore_int.h"
  12783. +#include "esp_private/pm_trace.h"
  12784. +#include "esp_attr.h"
  12785. +#include "esp_system.h"
  12786. +#include "esp_intr_alloc.h"
  12787. +#include "esp_debug_helpers.h"
  12788. +#include "esp_log.h"
  12789. +#include "FreeRTOS.h" /* This pulls in portmacro.h */
  12790. +#include "task.h"
  12791. +#include "portmacro.h"
  12792. +//#include "port_systick.h"
  12793. +
  12794. +
  12795. +
  12796. +/* ---------------------------------------------------- Variables ------------------------------------------------------
  12797. + *
  12798. + * ------------------------------------------------------------------------------------------------------------------ */
  12799. +
  12800. +static const char *TAG = "cpu_start"; // [refactor-todo]: might be appropriate to change in the future, but
  12801. +
  12802. +/**
  12803. + * @brief A variable is used to keep track of the critical section nesting.
  12804. + * @note This variable has to be stored as part of the task context and must be initialized to a non zero value
  12805. + * to ensure interrupts don't inadvertently become unmasked before the scheduler starts.
  12806. + * As it is stored as part of the task context it will automatically be set to 0 when the first task is started.
  12807. + */
  12808. +static UBaseType_t uxCriticalNesting = 0;
  12809. +static UBaseType_t uxSavedInterruptState = 0;
  12810. +BaseType_t uxSchedulerRunning = 0;
  12811. +UBaseType_t uxInterruptNesting = 0;
  12812. +BaseType_t xPortSwitchFlag = 0;
  12813. +__attribute__((aligned(16))) static StackType_t xIsrStack[configISR_STACK_SIZE];
  12814. +StackType_t *xIsrStackTop = &xIsrStack[0] + (configISR_STACK_SIZE & (~((portPOINTER_SIZE_TYPE)portBYTE_ALIGNMENT_MASK)));
  12815. +
  12816. +
  12817. +
  12818. +/* ---------------------------------------------- Port Implementations -------------------------------------------------
  12819. + *
  12820. + * ------------------------------------------------------------------------------------------------------------------ */
  12821. +
  12822. +// --------------------- Interrupts ------------------------
  12823. +
  12824. +BaseType_t xPortInIsrContext(void)
  12825. +{
  12826. + return (BaseType_t)rt_interrupt_get_nest();
  12827. +}
  12828. +
  12829. +BaseType_t IRAM_ATTR xPortInterruptedFromISRContext(void)
  12830. +{
  12831. + /* For single core, this can be the same as xPortInIsrContext() because reading it is atomic */
  12832. + return (BaseType_t)rt_interrupt_get_nest();
  12833. +}
  12834. +
  12835. +// ---------------------- Spinlocks ------------------------
  12836. +
  12837. +
  12838. +// ---------------------- Yielding -------------------------
  12839. +
  12840. +
  12841. +// ------------------- Hook Functions ----------------------
  12842. +
  12843. +void __attribute__((weak)) vApplicationStackOverflowHook(TaskHandle_t xTask, char *pcTaskName)
  12844. +{
  12845. +#define ERR_STR1 "***ERROR*** A stack overflow in task "
  12846. +#define ERR_STR2 " has been detected."
  12847. + const char *str[] = {ERR_STR1, pcTaskName, ERR_STR2};
  12848. +
  12849. + char buf[sizeof(ERR_STR1) + CONFIG_FREERTOS_MAX_TASK_NAME_LEN + sizeof(ERR_STR2) + 1 /* null char */] = {0};
  12850. +
  12851. + char *dest = buf;
  12852. + for (int i = 0; i < sizeof(str) / sizeof(str[0]); i++) {
  12853. + dest = strcat(dest, str[i]);
  12854. + }
  12855. + esp_system_abort(buf);
  12856. +}
  12857. +
  12858. +// ----------------------- System --------------------------
  12859. +
  12860. +uint32_t xPortGetTickRateHz(void)
  12861. +{
  12862. + return (uint32_t)configTICK_RATE_HZ;
  12863. +}
  12864. +
  12865. +#define STACK_WATCH_AREA_SIZE 32
  12866. +#define STACK_WATCH_POINT_NUMBER (SOC_CPU_WATCHPOINTS_NUM - 1)
  12867. +
  12868. +void vPortSetStackWatchpoint(void *pxStackStart)
  12869. +{
  12870. + uint32_t addr = (uint32_t)pxStackStart;
  12871. + addr = (addr + (STACK_WATCH_AREA_SIZE - 1)) & (~(STACK_WATCH_AREA_SIZE - 1));
  12872. + esp_cpu_set_watchpoint(STACK_WATCH_POINT_NUMBER, (char *)addr, STACK_WATCH_AREA_SIZE, ESP_WATCHPOINT_STORE);
  12873. +}
  12874. +
  12875. +
  12876. +
  12877. +/* ---------------------------------------------- Misc Implementations -------------------------------------------------
  12878. + *
  12879. + * ------------------------------------------------------------------------------------------------------------------ */
  12880. +
  12881. +// --------------------- App Start-up ----------------------
  12882. +
  12883. +/* [refactor-todo]: See if we can include this through a header */
  12884. +extern void esp_startup_start_app_common(void);
  12885. +
  12886. +void esp_startup_start_app(void)
  12887. +{
  12888. + esp_startup_start_app_common();
  12889. +
  12890. + ESP_LOGI(TAG, "Starting scheduler.");
  12891. + vTaskStartScheduler();
  12892. +}
  12893. diff --git a/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/queue.c b/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/queue.c
  12894. new file mode 100644
  12895. index 0000000000..8965e193d0
  12896. --- /dev/null
  12897. +++ b/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/queue.c
  12898. @@ -0,0 +1,787 @@
  12899. +/*
  12900. + * FreeRTOS Kernel V10.4.6
  12901. + * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  12902. + *
  12903. + * SPDX-License-Identifier: MIT
  12904. + *
  12905. + * Permission is hereby granted, free of charge, to any person obtaining a copy of
  12906. + * this software and associated documentation files (the "Software"), to deal in
  12907. + * the Software without restriction, including without limitation the rights to
  12908. + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  12909. + * the Software, and to permit persons to whom the Software is furnished to do so,
  12910. + * subject to the following conditions:
  12911. + *
  12912. + * The above copyright notice and this permission notice shall be included in all
  12913. + * copies or substantial portions of the Software.
  12914. + *
  12915. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12916. + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  12917. + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  12918. + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  12919. + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  12920. + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  12921. + *
  12922. + * https://www.FreeRTOS.org
  12923. + * https://github.com/FreeRTOS
  12924. + *
  12925. + */
  12926. +
  12927. +#include <stdlib.h>
  12928. +#include <string.h>
  12929. +
  12930. +#include "FreeRTOS.h"
  12931. +#include "queue.h"
  12932. +
  12933. +/* Semaphores do not actually store or copy data, so have an item size of
  12934. + * zero. */
  12935. +#define queueSEMAPHORE_QUEUE_ITEM_LENGTH ( ( UBaseType_t ) 0 )
  12936. +#define queueMUTEX_GIVE_BLOCK_TIME ( ( TickType_t ) 0U )
  12937. +
  12938. +typedef struct QueueDefinition
  12939. +{
  12940. + struct rt_ipc_object *rt_ipc;
  12941. +} xQUEUE;
  12942. +typedef xQUEUE Queue_t;
  12943. +
  12944. +static volatile rt_uint8_t mutex_index = 0;
  12945. +static volatile rt_uint8_t sem_index = 0;
  12946. +static volatile rt_uint8_t queue_index = 0;
  12947. +
  12948. +/*-----------------------------------------------------------*/
  12949. +
  12950. +BaseType_t xQueueGenericReset( QueueHandle_t xQueue,
  12951. + BaseType_t xNewQueue )
  12952. +{
  12953. + Queue_t * const pxQueue = xQueue;
  12954. + struct rt_ipc_object *pipc;
  12955. + rt_uint8_t type;
  12956. +
  12957. + configASSERT( pxQueue );
  12958. +
  12959. + pipc = pxQueue->rt_ipc;
  12960. + RT_ASSERT( pipc != RT_NULL );
  12961. + type = rt_object_get_type( &pipc->parent );
  12962. +
  12963. + if ( type == RT_Object_Class_Semaphore )
  12964. + {
  12965. + rt_sem_control( ( rt_sem_t ) pipc, RT_IPC_CMD_RESET, ( void * ) 0);
  12966. + }
  12967. + else if ( type == RT_Object_Class_MessageQueue )
  12968. + {
  12969. + rt_mq_control( ( rt_mq_t ) pipc, RT_IPC_CMD_RESET, RT_NULL );
  12970. + }
  12971. +
  12972. + return pdPASS;
  12973. +}
  12974. +/*-----------------------------------------------------------*/
  12975. +
  12976. +#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
  12977. +
  12978. + QueueHandle_t xQueueGenericCreateStatic( const UBaseType_t uxQueueLength,
  12979. + const UBaseType_t uxItemSize,
  12980. + uint8_t * pucQueueStorage,
  12981. + StaticQueue_t * pxStaticQueue,
  12982. + const uint8_t ucQueueType )
  12983. + {
  12984. + Queue_t * pxNewQueue = NULL;
  12985. + char name[RT_NAME_MAX] = {0};
  12986. +
  12987. + /* The StaticQueue_t structure and the queue storage area must be
  12988. + * supplied. */
  12989. + configASSERT( pxStaticQueue );
  12990. +
  12991. + if( ( uxQueueLength > ( UBaseType_t ) 0 ) &&
  12992. + ( pxStaticQueue != NULL ) &&
  12993. +
  12994. + /* A queue storage area should be provided if the item size is not 0, and
  12995. + * should not be provided if the item size is 0. */
  12996. + ( !( ( pucQueueStorage != NULL ) && ( uxItemSize == 0 ) ) ) &&
  12997. + ( !( ( pucQueueStorage == NULL ) && ( uxItemSize != 0 ) ) ) )
  12998. + {
  12999. + if ( ucQueueType == queueQUEUE_TYPE_RECURSIVE_MUTEX || ucQueueType == queueQUEUE_TYPE_MUTEX )
  13000. + {
  13001. + rt_snprintf( name, RT_NAME_MAX, "mutex%02d", mutex_index++ );
  13002. + rt_mutex_init( ( rt_mutex_t ) &( ( StaticSemaphore_t * ) pxStaticQueue )->ipc_obj.mutex, name, RT_IPC_FLAG_PRIO );
  13003. + }
  13004. + else if ( ucQueueType == queueQUEUE_TYPE_BINARY_SEMAPHORE || ucQueueType == queueQUEUE_TYPE_COUNTING_SEMAPHORE )
  13005. + {
  13006. + rt_snprintf( name, RT_NAME_MAX, "sem%02d", sem_index++ );
  13007. + rt_sem_init( ( rt_sem_t ) &( ( StaticSemaphore_t * ) pxStaticQueue )->ipc_obj.semaphore, name, 0, RT_IPC_FLAG_PRIO );
  13008. + ( ( StaticSemaphore_t * ) pxStaticQueue )->ipc_obj.semaphore.max_value = uxQueueLength;
  13009. + }
  13010. + else if ( ucQueueType == queueQUEUE_TYPE_BASE )
  13011. + {
  13012. + rt_snprintf( name, RT_NAME_MAX, "queue%02d", queue_index++ );
  13013. + rt_mq_init( &( pxStaticQueue->ipc_obj ), name, pucQueueStorage, uxItemSize, QUEUE_BUFFER_SIZE( uxQueueLength, uxItemSize ), RT_IPC_FLAG_PRIO );
  13014. + }
  13015. + else
  13016. + {
  13017. + return pxNewQueue;
  13018. + }
  13019. + pxStaticQueue->rt_ipc = ( struct rt_ipc_object * ) &pxStaticQueue->ipc_obj;
  13020. + pxNewQueue = ( QueueHandle_t ) pxStaticQueue;
  13021. + }
  13022. +
  13023. + return pxNewQueue;
  13024. + }
  13025. +
  13026. +#endif /* configSUPPORT_STATIC_ALLOCATION */
  13027. +/*-----------------------------------------------------------*/
  13028. +
  13029. +#if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
  13030. +
  13031. + QueueHandle_t xQueueGenericCreate( const UBaseType_t uxQueueLength,
  13032. + const UBaseType_t uxItemSize,
  13033. + const uint8_t ucQueueType )
  13034. + {
  13035. + Queue_t * pxNewQueue = NULL;
  13036. + char name[RT_NAME_MAX] = {0};
  13037. + struct rt_ipc_object * pipc = RT_NULL;
  13038. +
  13039. + if( ( uxQueueLength > ( UBaseType_t ) 0 ) &&
  13040. + /* Check for multiplication overflow. */
  13041. + ( ( SIZE_MAX / uxQueueLength ) >= uxItemSize ) &&
  13042. + /* Check for addition overflow. */
  13043. + ( ( SIZE_MAX - sizeof( Queue_t ) ) >= ( uxQueueLength * uxItemSize ) ) )
  13044. + {
  13045. + pxNewQueue = ( Queue_t * ) RT_KERNEL_MALLOC( sizeof( Queue_t ) );
  13046. + if ( pxNewQueue == NULL )
  13047. + {
  13048. + return ( QueueHandle_t ) pxNewQueue;
  13049. + }
  13050. + if ( ucQueueType == queueQUEUE_TYPE_RECURSIVE_MUTEX || ucQueueType == queueQUEUE_TYPE_MUTEX )
  13051. + {
  13052. + rt_snprintf( name, RT_NAME_MAX, "mutex%02d", mutex_index++ );
  13053. + pipc = ( struct rt_ipc_object * ) rt_mutex_create( name, RT_IPC_FLAG_PRIO );
  13054. + }
  13055. + else if ( ucQueueType == queueQUEUE_TYPE_BINARY_SEMAPHORE || ucQueueType == queueQUEUE_TYPE_COUNTING_SEMAPHORE )
  13056. + {
  13057. + rt_snprintf( name, RT_NAME_MAX, "sem%02d", sem_index++ );
  13058. + pipc = ( struct rt_ipc_object * ) RT_KERNEL_MALLOC( sizeof( struct rt_semaphore_wrapper ) );
  13059. + if ( pipc != RT_NULL )
  13060. + {
  13061. + rt_sem_init( ( rt_sem_t ) pipc, name, 0, RT_IPC_FLAG_PRIO );
  13062. + ( ( struct rt_semaphore_wrapper * ) pipc )->max_value = uxQueueLength;
  13063. + /* Mark as dynamic so we can distinguish in vQueueDelete */
  13064. + pipc->parent.type &= ~RT_Object_Class_Static;
  13065. + }
  13066. + }
  13067. + else if ( ucQueueType == queueQUEUE_TYPE_BASE )
  13068. + {
  13069. + rt_snprintf( name, RT_NAME_MAX, "queue%02d", queue_index++ );
  13070. + pipc = ( struct rt_ipc_object * ) rt_mq_create( name, uxItemSize, uxQueueLength, RT_IPC_FLAG_PRIO);
  13071. + }
  13072. +
  13073. + if ( pipc == RT_NULL )
  13074. + {
  13075. + RT_KERNEL_FREE( pxNewQueue );
  13076. + return NULL;
  13077. + }
  13078. + pxNewQueue->rt_ipc = pipc;
  13079. + }
  13080. +
  13081. + return ( QueueHandle_t ) pxNewQueue;
  13082. + }
  13083. +
  13084. +#endif /* configSUPPORT_STATIC_ALLOCATION */
  13085. +/*-----------------------------------------------------------*/
  13086. +
  13087. +#if ( ( configUSE_MUTEXES == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) )
  13088. +
  13089. + QueueHandle_t xQueueCreateMutex( const uint8_t ucQueueType )
  13090. + {
  13091. + QueueHandle_t xNewQueue;
  13092. + const UBaseType_t uxMutexLength = ( UBaseType_t ) 1, uxMutexSize = ( UBaseType_t ) 0;
  13093. +
  13094. + xNewQueue = xQueueGenericCreate( uxMutexLength, uxMutexSize, ucQueueType );
  13095. + return xNewQueue;
  13096. + }
  13097. +
  13098. +#endif /* configUSE_MUTEXES */
  13099. +/*-----------------------------------------------------------*/
  13100. +
  13101. +#if ( ( configUSE_MUTEXES == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) )
  13102. +
  13103. + QueueHandle_t xQueueCreateMutexStatic( const uint8_t ucQueueType,
  13104. + StaticQueue_t * pxStaticQueue )
  13105. + {
  13106. + QueueHandle_t xNewQueue;
  13107. + const UBaseType_t uxMutexLength = ( UBaseType_t ) 1, uxMutexSize = ( UBaseType_t ) 0;
  13108. +
  13109. + xNewQueue = xQueueGenericCreateStatic( uxMutexLength, uxMutexSize, NULL, pxStaticQueue, ucQueueType );
  13110. +
  13111. + return xNewQueue;
  13112. + }
  13113. +
  13114. +#endif /* configUSE_MUTEXES */
  13115. +/*-----------------------------------------------------------*/
  13116. +
  13117. +#if ( ( configUSE_MUTEXES == 1 ) && ( INCLUDE_xSemaphoreGetMutexHolder == 1 ) )
  13118. +
  13119. + TaskHandle_t xQueueGetMutexHolder( QueueHandle_t xSemaphore )
  13120. + {
  13121. + TaskHandle_t pxReturn;
  13122. + struct rt_ipc_object *pipc;
  13123. + rt_uint8_t type;
  13124. + rt_base_t level;
  13125. +
  13126. + configASSERT( xSemaphore );
  13127. +
  13128. + pipc = xSemaphore->rt_ipc;
  13129. + RT_ASSERT( pipc != RT_NULL );
  13130. + type = rt_object_get_type( &pipc->parent );
  13131. +
  13132. + if ( type == RT_Object_Class_Mutex )
  13133. + {
  13134. + level = rt_hw_interrupt_disable();
  13135. + pxReturn = ( TaskHandle_t ) ( ( rt_mutex_t ) pipc )->owner;
  13136. + rt_hw_interrupt_enable( level );
  13137. + }
  13138. + else
  13139. + {
  13140. + pxReturn = NULL;
  13141. + }
  13142. +
  13143. + return pxReturn;
  13144. + }
  13145. +
  13146. +#endif /* if ( ( configUSE_MUTEXES == 1 ) && ( INCLUDE_xSemaphoreGetMutexHolder == 1 ) ) */
  13147. +/*-----------------------------------------------------------*/
  13148. +
  13149. +#if ( ( configUSE_MUTEXES == 1 ) && ( INCLUDE_xSemaphoreGetMutexHolder == 1 ) )
  13150. +
  13151. + TaskHandle_t xQueueGetMutexHolderFromISR( QueueHandle_t xSemaphore )
  13152. + {
  13153. + return xQueueGetMutexHolder( xSemaphore );
  13154. + }
  13155. +
  13156. +#endif /* if ( ( configUSE_MUTEXES == 1 ) && ( INCLUDE_xSemaphoreGetMutexHolder == 1 ) ) */
  13157. +/*-----------------------------------------------------------*/
  13158. +
  13159. +#if ( configUSE_RECURSIVE_MUTEXES == 1 )
  13160. +
  13161. + BaseType_t xQueueGiveMutexRecursive( QueueHandle_t xMutex )
  13162. + {
  13163. + Queue_t * const pxMutex = ( Queue_t * ) xMutex;
  13164. + configASSERT( pxMutex );
  13165. + return xQueueGenericSend( pxMutex, NULL, queueMUTEX_GIVE_BLOCK_TIME, queueSEND_TO_BACK );
  13166. + }
  13167. +
  13168. +#endif /* configUSE_RECURSIVE_MUTEXES */
  13169. +/*-----------------------------------------------------------*/
  13170. +
  13171. +#if ( configUSE_RECURSIVE_MUTEXES == 1 )
  13172. +
  13173. + BaseType_t xQueueTakeMutexRecursive( QueueHandle_t xMutex,
  13174. + TickType_t xTicksToWait )
  13175. + {
  13176. + Queue_t * const pxMutex = ( Queue_t * ) xMutex;
  13177. + configASSERT( pxMutex );
  13178. + return xQueueSemaphoreTake( pxMutex, xTicksToWait );
  13179. + }
  13180. +
  13181. +#endif /* configUSE_RECURSIVE_MUTEXES */
  13182. +/*-----------------------------------------------------------*/
  13183. +
  13184. +#if ( ( configUSE_COUNTING_SEMAPHORES == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) )
  13185. +
  13186. + QueueHandle_t xQueueCreateCountingSemaphoreStatic( const UBaseType_t uxMaxCount,
  13187. + const UBaseType_t uxInitialCount,
  13188. + StaticQueue_t * pxStaticQueue )
  13189. + {
  13190. + QueueHandle_t xHandle = NULL;
  13191. +
  13192. + if( ( uxMaxCount != 0 ) &&
  13193. + ( uxInitialCount <= uxMaxCount ) )
  13194. + {
  13195. + xHandle = xQueueGenericCreateStatic( uxMaxCount, queueSEMAPHORE_QUEUE_ITEM_LENGTH, NULL, pxStaticQueue, queueQUEUE_TYPE_COUNTING_SEMAPHORE );
  13196. +
  13197. + if( xHandle != NULL )
  13198. + {
  13199. + ( ( rt_sem_t ) ( ( Queue_t * ) xHandle )->rt_ipc )->value = uxInitialCount;
  13200. + }
  13201. + }
  13202. + else
  13203. + {
  13204. + configASSERT( xHandle );
  13205. + }
  13206. +
  13207. + return xHandle;
  13208. + }
  13209. +
  13210. +#endif /* ( ( configUSE_COUNTING_SEMAPHORES == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) ) */
  13211. +/*-----------------------------------------------------------*/
  13212. +
  13213. +#if ( ( configUSE_COUNTING_SEMAPHORES == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) )
  13214. +
  13215. + QueueHandle_t xQueueCreateCountingSemaphore( const UBaseType_t uxMaxCount,
  13216. + const UBaseType_t uxInitialCount )
  13217. + {
  13218. + QueueHandle_t xHandle = NULL;
  13219. +
  13220. + if( ( uxMaxCount != 0 ) &&
  13221. + ( uxInitialCount <= uxMaxCount ) )
  13222. + {
  13223. + xHandle = xQueueGenericCreate( uxMaxCount, queueSEMAPHORE_QUEUE_ITEM_LENGTH, queueQUEUE_TYPE_COUNTING_SEMAPHORE );
  13224. +
  13225. + if( xHandle != NULL )
  13226. + {
  13227. + ( ( rt_sem_t ) ( ( Queue_t * ) xHandle )->rt_ipc )->value = uxInitialCount;
  13228. + }
  13229. + }
  13230. + else
  13231. + {
  13232. + configASSERT( xHandle );
  13233. + }
  13234. +
  13235. + return xHandle;
  13236. + }
  13237. +
  13238. +#endif /* ( ( configUSE_COUNTING_SEMAPHORES == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) ) */
  13239. +/*-----------------------------------------------------------*/
  13240. +
  13241. +BaseType_t xQueueGenericSend( QueueHandle_t xQueue,
  13242. + const void * const pvItemToQueue,
  13243. + TickType_t xTicksToWait,
  13244. + const BaseType_t xCopyPosition )
  13245. +{
  13246. + Queue_t * const pxQueue = xQueue;
  13247. + struct rt_ipc_object *pipc;
  13248. + rt_uint8_t type;
  13249. + rt_base_t level;
  13250. + rt_err_t err = -RT_ERROR;
  13251. +
  13252. + configASSERT( pxQueue );
  13253. + #if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )
  13254. + {
  13255. + configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) );
  13256. + }
  13257. + #endif
  13258. +
  13259. + pipc = pxQueue->rt_ipc;
  13260. + RT_ASSERT( pipc != RT_NULL );
  13261. + type = rt_object_get_type( &pipc->parent );
  13262. + if ( type == RT_Object_Class_Mutex )
  13263. + {
  13264. + err = rt_mutex_release( ( rt_mutex_t ) pipc );
  13265. + }
  13266. + else if ( type == RT_Object_Class_Semaphore )
  13267. + {
  13268. + level = rt_hw_interrupt_disable();
  13269. + if ( ( ( rt_sem_t ) pipc )->value < ( ( struct rt_semaphore_wrapper * ) pipc )->max_value )
  13270. + {
  13271. + err = rt_sem_release( ( rt_sem_t ) pipc );
  13272. + }
  13273. + rt_hw_interrupt_enable( level );
  13274. + }
  13275. + else if ( type == RT_Object_Class_MessageQueue )
  13276. + {
  13277. + if ( xCopyPosition == queueSEND_TO_BACK )
  13278. + {
  13279. + err = rt_mq_send_wait( ( rt_mq_t ) pipc, pvItemToQueue, ( ( rt_mq_t ) pipc )->msg_size, ( rt_int32_t ) xTicksToWait );
  13280. + }
  13281. + else if ( xCopyPosition == queueSEND_TO_FRONT )
  13282. + {
  13283. + // TODO: need to implement the timeout for LIFO
  13284. + err = rt_mq_urgent( ( rt_mq_t ) pipc, pvItemToQueue, ( ( rt_mq_t ) pipc )->msg_size );
  13285. + }
  13286. + }
  13287. +
  13288. + return rt_err_to_freertos( err );
  13289. +}
  13290. +/*-----------------------------------------------------------*/
  13291. +
  13292. +BaseType_t xQueueGenericSendFromISR( QueueHandle_t xQueue,
  13293. + const void * const pvItemToQueue,
  13294. + BaseType_t * const pxHigherPriorityTaskWoken,
  13295. + const BaseType_t xCopyPosition )
  13296. +{
  13297. + Queue_t * const pxQueue = xQueue;
  13298. + struct rt_ipc_object *pipc;
  13299. + rt_uint8_t type;
  13300. + rt_err_t err = -RT_ERROR;
  13301. +
  13302. + configASSERT( pxQueue );
  13303. +
  13304. + pipc = pxQueue->rt_ipc;
  13305. + RT_ASSERT( pipc != RT_NULL );
  13306. + type = rt_object_get_type( &pipc->parent );
  13307. + if ( type == RT_Object_Class_MessageQueue )
  13308. + {
  13309. + if ( xCopyPosition == queueSEND_TO_BACK )
  13310. + {
  13311. + err = rt_mq_send( ( rt_mq_t ) pipc, pvItemToQueue, ( ( rt_mq_t ) pipc )->msg_size);
  13312. + }
  13313. + else if ( xCopyPosition == queueSEND_TO_FRONT )
  13314. + {
  13315. + err = rt_mq_urgent( ( rt_mq_t ) pipc, pvItemToQueue, ( ( rt_mq_t ) pipc )->msg_size );
  13316. + }
  13317. + }
  13318. +
  13319. + return rt_err_to_freertos( err );
  13320. +}
  13321. +/*-----------------------------------------------------------*/
  13322. +
  13323. +BaseType_t xQueueGiveFromISR( QueueHandle_t xQueue,
  13324. + BaseType_t * const pxHigherPriorityTaskWoken )
  13325. +{
  13326. + Queue_t * const pxQueue = xQueue;
  13327. + struct rt_ipc_object *pipc;
  13328. + rt_uint8_t type;
  13329. + rt_base_t level;
  13330. + rt_err_t err = -RT_ERROR;
  13331. +
  13332. + configASSERT( pxQueue );
  13333. +
  13334. + pipc = pxQueue->rt_ipc;
  13335. + RT_ASSERT( pipc != RT_NULL );
  13336. + type = rt_object_get_type( &pipc->parent );
  13337. + RT_ASSERT( type != RT_Object_Class_Mutex );
  13338. + if ( type == RT_Object_Class_Semaphore )
  13339. + {
  13340. + level = rt_hw_interrupt_disable();
  13341. + if ( ( ( rt_sem_t ) pipc )->value < ( ( struct rt_semaphore_wrapper * ) pipc )->max_value )
  13342. + {
  13343. + err = rt_sem_release( ( rt_sem_t ) pipc );
  13344. + }
  13345. + rt_hw_interrupt_enable( level );
  13346. + }
  13347. + if ( pxHigherPriorityTaskWoken != NULL )
  13348. + {
  13349. + *pxHigherPriorityTaskWoken = pdFALSE;
  13350. + }
  13351. +
  13352. + return rt_err_to_freertos( err );
  13353. +}
  13354. +/*-----------------------------------------------------------*/
  13355. +
  13356. +BaseType_t xQueueReceive( QueueHandle_t xQueue,
  13357. + void * const pvBuffer,
  13358. + TickType_t xTicksToWait )
  13359. +{
  13360. + Queue_t * const pxQueue = xQueue;
  13361. + struct rt_ipc_object *pipc;
  13362. + rt_uint8_t type;
  13363. + rt_err_t err = -RT_ERROR;
  13364. +
  13365. + /* Check the queue pointer is not NULL. */
  13366. + configASSERT( ( pxQueue ) );
  13367. +
  13368. + /* Cannot block if the scheduler is suspended. */
  13369. + #if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )
  13370. + {
  13371. + configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) );
  13372. + }
  13373. + #endif
  13374. +
  13375. + pipc = pxQueue->rt_ipc;
  13376. + RT_ASSERT( pipc != RT_NULL );
  13377. + type = rt_object_get_type( &pipc->parent );
  13378. + if ( type == RT_Object_Class_MessageQueue )
  13379. + {
  13380. + err = rt_mq_recv( ( rt_mq_t ) pipc, pvBuffer, ( ( rt_mq_t ) pipc )->msg_size, ( rt_int32_t ) xTicksToWait );
  13381. + }
  13382. +
  13383. + return rt_err_to_freertos( err );
  13384. +}
  13385. +/*-----------------------------------------------------------*/
  13386. +
  13387. +BaseType_t xQueueSemaphoreTake( QueueHandle_t xQueue,
  13388. + TickType_t xTicksToWait )
  13389. +{
  13390. + Queue_t * const pxQueue = xQueue;
  13391. + struct rt_ipc_object *pipc;
  13392. + rt_uint8_t type;
  13393. + rt_err_t err = -RT_ERROR;
  13394. +
  13395. + /* Check the queue pointer is not NULL. */
  13396. + configASSERT( ( pxQueue ) );
  13397. +
  13398. + /* Cannot block if the scheduler is suspended. */
  13399. + #if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )
  13400. + {
  13401. + configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) );
  13402. + }
  13403. + #endif
  13404. +
  13405. + pipc = pxQueue->rt_ipc;
  13406. + RT_ASSERT( pipc != RT_NULL );
  13407. + type = rt_object_get_type( &pipc->parent );
  13408. + if ( type == RT_Object_Class_Mutex )
  13409. + {
  13410. + err = rt_mutex_take( ( rt_mutex_t ) pipc, ( rt_int32_t ) xTicksToWait );
  13411. + }
  13412. + else if ( type == RT_Object_Class_Semaphore )
  13413. + {
  13414. + err = rt_sem_take( ( rt_sem_t ) pipc, ( rt_int32_t ) xTicksToWait );
  13415. + }
  13416. +
  13417. + return rt_err_to_freertos( err );
  13418. +}
  13419. +/*-----------------------------------------------------------*/
  13420. +
  13421. +BaseType_t xQueueReceiveFromISR( QueueHandle_t xQueue,
  13422. + void * const pvBuffer,
  13423. + BaseType_t * const pxHigherPriorityTaskWoken )
  13424. +{
  13425. + Queue_t * const pxQueue = xQueue;
  13426. + struct rt_ipc_object *pipc;
  13427. + rt_uint8_t type;
  13428. + rt_err_t err = -RT_ERROR;
  13429. +
  13430. + configASSERT( pxQueue );
  13431. +
  13432. + pipc = pxQueue->rt_ipc;
  13433. + RT_ASSERT( pipc != RT_NULL );
  13434. + type = rt_object_get_type( &pipc->parent );
  13435. + RT_ASSERT( type != RT_Object_Class_Mutex );
  13436. + if ( type == RT_Object_Class_Semaphore )
  13437. + {
  13438. + err = rt_sem_take( ( rt_sem_t ) pipc, RT_WAITING_NO );
  13439. + }
  13440. + else if ( type == RT_Object_Class_MessageQueue )
  13441. + {
  13442. + err = rt_mq_recv( ( rt_mq_t ) pipc, pvBuffer, ( ( rt_mq_t ) pipc )->msg_size, RT_WAITING_NO );
  13443. + }
  13444. + if ( pxHigherPriorityTaskWoken != NULL )
  13445. + {
  13446. + *pxHigherPriorityTaskWoken = pdFALSE;
  13447. + }
  13448. +
  13449. + return rt_err_to_freertos( err );
  13450. +}
  13451. +/*-----------------------------------------------------------*/
  13452. +
  13453. +UBaseType_t uxQueueMessagesWaiting( const QueueHandle_t xQueue )
  13454. +{
  13455. + UBaseType_t uxReturn = 0;
  13456. + struct rt_ipc_object *pipc;
  13457. + rt_uint8_t type;
  13458. + rt_base_t level;
  13459. +
  13460. + configASSERT( xQueue );
  13461. +
  13462. + pipc = xQueue->rt_ipc;
  13463. + RT_ASSERT( pipc != RT_NULL );
  13464. + type = rt_object_get_type( &pipc->parent );
  13465. +
  13466. + level = rt_hw_interrupt_disable();
  13467. +
  13468. + if ( type == RT_Object_Class_Mutex )
  13469. + {
  13470. + uxReturn = ( ( rt_mutex_t ) pipc )->value;
  13471. + }
  13472. + else if ( type == RT_Object_Class_Semaphore )
  13473. + {
  13474. + uxReturn = ( ( rt_sem_t ) pipc )->value;
  13475. + }
  13476. + else if ( type == RT_Object_Class_MessageQueue )
  13477. + {
  13478. + uxReturn = ( ( rt_mq_t ) pipc )->entry;
  13479. + }
  13480. +
  13481. + rt_hw_interrupt_enable( level );
  13482. +
  13483. + return uxReturn;
  13484. +}
  13485. +/*-----------------------------------------------------------*/
  13486. +
  13487. +UBaseType_t uxQueueSpacesAvailable( const QueueHandle_t xQueue )
  13488. +{
  13489. + UBaseType_t uxReturn = 0;
  13490. + struct rt_ipc_object *pipc;
  13491. + rt_uint8_t type;
  13492. + rt_base_t level;
  13493. +
  13494. + configASSERT( xQueue );
  13495. +
  13496. + pipc = xQueue->rt_ipc;
  13497. + RT_ASSERT( pipc != RT_NULL );
  13498. + type = rt_object_get_type( &pipc->parent );
  13499. +
  13500. + level = rt_hw_interrupt_disable();
  13501. +
  13502. + if ( type == RT_Object_Class_Mutex )
  13503. + {
  13504. + uxReturn = 1 - ( ( rt_mutex_t ) pipc )->value;
  13505. + }
  13506. + else if ( type == RT_Object_Class_Semaphore )
  13507. + {
  13508. + uxReturn = ( ( struct rt_semaphore_wrapper * ) pipc )->max_value - ( ( rt_sem_t ) pipc )->value;
  13509. + }
  13510. + else if ( type == RT_Object_Class_MessageQueue )
  13511. + {
  13512. + uxReturn = ( ( rt_mq_t ) pipc )->max_msgs - ( ( rt_mq_t ) pipc )->entry;
  13513. + }
  13514. +
  13515. + rt_hw_interrupt_enable( level );
  13516. +
  13517. + return uxReturn;
  13518. +}
  13519. +/*-----------------------------------------------------------*/
  13520. +
  13521. +UBaseType_t uxQueueMessagesWaitingFromISR( const QueueHandle_t xQueue )
  13522. +{
  13523. + return uxQueueMessagesWaiting( xQueue );
  13524. +}
  13525. +/*-----------------------------------------------------------*/
  13526. +
  13527. +void vQueueDelete( QueueHandle_t xQueue )
  13528. +{
  13529. + Queue_t * const pxQueue = xQueue;
  13530. + struct rt_ipc_object *pipc;
  13531. + rt_uint8_t type;
  13532. +
  13533. + configASSERT( pxQueue );
  13534. +
  13535. + pipc = pxQueue->rt_ipc;
  13536. + RT_ASSERT( pipc != RT_NULL );
  13537. + type = rt_object_get_type( &pipc->parent );
  13538. +#if ( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) )
  13539. + if ( rt_object_is_systemobject( ( rt_object_t ) pipc ) )
  13540. +#endif
  13541. + {
  13542. + #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
  13543. + if ( type == RT_Object_Class_Mutex )
  13544. + {
  13545. + rt_mutex_detach( ( rt_mutex_t ) pipc );
  13546. + }
  13547. + else if ( type == RT_Object_Class_Semaphore )
  13548. + {
  13549. + rt_sem_detach( ( rt_sem_t ) pipc );
  13550. + }
  13551. + else if ( type == RT_Object_Class_MessageQueue )
  13552. + {
  13553. + rt_mq_detach( ( rt_mq_t ) pipc );
  13554. + }
  13555. + #endif
  13556. +#if ( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) )
  13557. + }
  13558. + else
  13559. + {
  13560. +#endif
  13561. + #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
  13562. + if ( type == RT_Object_Class_Mutex )
  13563. + {
  13564. + rt_mutex_delete( ( rt_mutex_t ) pipc );
  13565. + }
  13566. + else if ( type == RT_Object_Class_Semaphore )
  13567. + {
  13568. + /* Allocated with rt_sem_init in xQueueGenericCreate */
  13569. + pipc->parent.type |= RT_Object_Class_Static;
  13570. + rt_sem_detach( ( rt_sem_t ) pipc );
  13571. + RT_KERNEL_FREE( pipc );
  13572. + }
  13573. + else if ( type == RT_Object_Class_MessageQueue )
  13574. + {
  13575. + rt_mq_delete( ( rt_mq_t ) pipc );
  13576. + }
  13577. + else
  13578. + {
  13579. + return;
  13580. + }
  13581. + RT_KERNEL_FREE( pxQueue );
  13582. + #endif
  13583. + }
  13584. +}
  13585. +/*-----------------------------------------------------------*/
  13586. +
  13587. +BaseType_t xQueueIsQueueEmptyFromISR( const QueueHandle_t xQueue )
  13588. +{
  13589. + BaseType_t xReturn;
  13590. +
  13591. + configASSERT( xQueue );
  13592. +
  13593. + if( uxQueueMessagesWaiting( xQueue ) == ( UBaseType_t ) 0 )
  13594. + {
  13595. + xReturn = pdTRUE;
  13596. + }
  13597. + else
  13598. + {
  13599. + xReturn = pdFALSE;
  13600. + }
  13601. +
  13602. + return xReturn;
  13603. +}
  13604. +/*-----------------------------------------------------------*/
  13605. +
  13606. +BaseType_t xQueueIsQueueFullFromISR( const QueueHandle_t xQueue )
  13607. +{
  13608. + BaseType_t xReturn;
  13609. +
  13610. + configASSERT( xQueue );
  13611. +
  13612. + if ( uxQueueSpacesAvailable( xQueue ) == ( UBaseType_t ) 0 )
  13613. + {
  13614. + xReturn = pdTRUE;
  13615. + }
  13616. + else
  13617. + {
  13618. + xReturn = pdFALSE;
  13619. + }
  13620. +
  13621. + return xReturn;
  13622. +}
  13623. +/*-----------------------------------------------------------*/
  13624. +
  13625. +/* Unimplemented */
  13626. +#include "esp_log.h"
  13627. +QueueSetHandle_t xQueueCreateSet( const UBaseType_t uxEventQueueLength )
  13628. +{
  13629. + ESP_LOGE("freertos", "xQueueCreateSet unimplemented");
  13630. + RT_ASSERT(0);
  13631. + return NULL;
  13632. +}
  13633. +BaseType_t xQueueAddToSet( QueueSetMemberHandle_t xQueueOrSemaphore,
  13634. + QueueSetHandle_t xQueueSet )
  13635. +{
  13636. + ESP_LOGE("freertos", "xQueueAddToSet unimplemented");
  13637. + RT_ASSERT(0);
  13638. + return pdFAIL;
  13639. +}
  13640. +
  13641. +BaseType_t xQueueRemoveFromSet( QueueSetMemberHandle_t xQueueOrSemaphore,
  13642. + QueueSetHandle_t xQueueSet )
  13643. +{
  13644. + ESP_LOGE("freertos", "xQueueRemoveFromSet unimplemented");
  13645. + RT_ASSERT(0);
  13646. + return pdFAIL;
  13647. +}
  13648. +
  13649. +QueueSetMemberHandle_t xQueueSelectFromSet( QueueSetHandle_t xQueueSet,
  13650. + const TickType_t xTicksToWait )
  13651. +{
  13652. + ESP_LOGE("freertos", "xQueueSelectFromSet unimplemented");
  13653. + RT_ASSERT(0);
  13654. + return NULL;
  13655. +}
  13656. +
  13657. +QueueSetMemberHandle_t xQueueSelectFromSetFromISR( QueueSetHandle_t xQueueSet )
  13658. +{
  13659. + ESP_LOGE("freertos", "xQueueSelectFromSetFromISR unimplemented");
  13660. + RT_ASSERT(0);
  13661. + return NULL;
  13662. +}
  13663. +
  13664. +BaseType_t xQueuePeek( QueueHandle_t xQueue,
  13665. + void * const pvBuffer,
  13666. + TickType_t xTicksToWait )
  13667. +{
  13668. + ESP_LOGE("freertos", "xQueuePeek unimplemented");
  13669. + RT_ASSERT(0);
  13670. + return pdFAIL;
  13671. +}
  13672. +
  13673. +BaseType_t xQueueOverwrite(QueueHandle_t xQueue, const void * pvItemToQueue)
  13674. +{
  13675. + ESP_LOGE("freertos", "xQueueOverwrite unimplemented");
  13676. + RT_ASSERT(0);
  13677. + return pdFAIL;
  13678. +}
  13679. +
  13680. +BaseType_t xQueueOverwriteFromISR(QueueHandle_t xQueue, const void * pvItemToQueue, BaseType_t *pxHigherPriorityTaskWoken)
  13681. +{
  13682. + ESP_LOGE("freertos", "xQueueOverwriteFromISR unimplemented");
  13683. + RT_ASSERT(0);
  13684. + return pdFAIL;
  13685. +}
  13686. diff --git a/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/tasks.c b/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/tasks.c
  13687. new file mode 100644
  13688. index 0000000000..d3e8c27a09
  13689. --- /dev/null
  13690. +++ b/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/tasks.c
  13691. @@ -0,0 +1,1254 @@
  13692. +/*
  13693. + * FreeRTOS Kernel V10.4.6
  13694. + * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  13695. + *
  13696. + * SPDX-License-Identifier: MIT
  13697. + *
  13698. + * Permission is hereby granted, free of charge, to any person obtaining a copy of
  13699. + * this software and associated documentation files (the "Software"), to deal in
  13700. + * the Software without restriction, including without limitation the rights to
  13701. + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  13702. + * the Software, and to permit persons to whom the Software is furnished to do so,
  13703. + * subject to the following conditions:
  13704. + *
  13705. + * The above copyright notice and this permission notice shall be included in all
  13706. + * copies or substantial portions of the Software.
  13707. + *
  13708. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13709. + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  13710. + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  13711. + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  13712. + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  13713. + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  13714. + *
  13715. + * https://www.FreeRTOS.org
  13716. + * https://github.com/FreeRTOS
  13717. + *
  13718. + */
  13719. +
  13720. +/* Standard includes. */
  13721. +#include <stdlib.h>
  13722. +#include <string.h>
  13723. +
  13724. +/* FreeRTOS includes. */
  13725. +#include "FreeRTOS.h"
  13726. +#include "task.h"
  13727. +
  13728. +//TODO: check configMAX_PRIORITIES == RT_THREAD_PRIORITY_MAX
  13729. +#define FREERTOS_PRIORITY_TO_RTTHREAD(priority) ( configMAX_PRIORITIES - 1 - ( priority ) )
  13730. +#define RTTHREAD_PRIORITY_TO_FREERTOS(priority) ( RT_THREAD_PRIORITY_MAX - 1 - ( priority ) )
  13731. +
  13732. +/* Values that can be assigned to the ucNotifyState member of the TCB. */
  13733. +#define taskNOT_WAITING_NOTIFICATION ( ( uint8_t ) 0 ) /* Must be zero as it is the initialised value. */
  13734. +#define taskWAITING_NOTIFICATION ( ( uint8_t ) 1 )
  13735. +#define taskNOTIFICATION_RECEIVED ( ( uint8_t ) 2 )
  13736. +
  13737. +/*
  13738. + * Several functions take a TaskHandle_t parameter that can optionally be NULL,
  13739. + * where NULL is used to indicate that the handle of the currently executing
  13740. + * task should be used in place of the parameter. This macro simply checks to
  13741. + * see if the parameter is NULL and returns a pointer to the appropriate TCB.
  13742. + */
  13743. +#define prvGetTCBFromHandle( pxHandle ) ( ( ( pxHandle ) == NULL ) ? ( xTaskGetCurrentTaskHandle() ) : ( pxHandle ) )
  13744. +
  13745. +/*
  13746. + * Task control block. A task control block (TCB) is allocated for each task,
  13747. + * and stores task state information, including a pointer to the task's context
  13748. + * (the task's run time environment, including register values)
  13749. + */
  13750. +typedef struct tskTaskControlBlock
  13751. +{
  13752. + struct rt_thread thread;
  13753. + #if ( configUSE_APPLICATION_TASK_TAG == 1 )
  13754. + TaskHookFunction_t pxTaskTag;
  13755. + #endif
  13756. + #if ( configUSE_TASK_NOTIFICATIONS == 1 )
  13757. + volatile uint32_t ulNotifiedValue[ configTASK_NOTIFICATION_ARRAY_ENTRIES ];
  13758. + volatile uint8_t ucNotifyState[ configTASK_NOTIFICATION_ARRAY_ENTRIES ];
  13759. + #endif
  13760. + #if ( INCLUDE_xTaskAbortDelay == 1 )
  13761. + uint8_t ucDelayAborted;
  13762. + #endif
  13763. +} tskTCB;
  13764. +typedef tskTCB TCB_t;
  13765. +
  13766. +/* Other file private variables. --------------------------------*/
  13767. +static volatile BaseType_t xSchedulerRunning = pdFALSE;
  13768. +
  13769. +/*-----------------------------------------------------------*/
  13770. +
  13771. +/*
  13772. + * Called after a Task_t structure has been allocated either statically or
  13773. + * dynamically to fill in the structure's members.
  13774. + */
  13775. +static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
  13776. + const char * const pcName,
  13777. + const uint32_t ulStackDepth,
  13778. + void * const pvParameters,
  13779. + UBaseType_t uxPriority,
  13780. + TaskHandle_t * const pxCreatedTask,
  13781. + TCB_t * pxNewTCB,
  13782. + StackType_t * const puxStackBuffer );
  13783. +
  13784. +#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
  13785. +
  13786. + TaskHandle_t xTaskCreateStatic( TaskFunction_t pxTaskCode,
  13787. + const char * const pcName,
  13788. + const uint32_t ulStackDepth,
  13789. + void * const pvParameters,
  13790. + UBaseType_t uxPriority,
  13791. + StackType_t * const puxStackBuffer,
  13792. + StaticTask_t * const pxTaskBuffer )
  13793. + {
  13794. + TCB_t * pxNewTCB;
  13795. + TaskHandle_t xReturn = NULL;
  13796. +
  13797. + configASSERT( puxStackBuffer != NULL );
  13798. + configASSERT( pxTaskBuffer != NULL );
  13799. +
  13800. + #if ( configASSERT_DEFINED == 1 )
  13801. + {
  13802. + /* Sanity check that the size of the structure used to declare a
  13803. + * variable of type StaticTask_t equals the size of the real task
  13804. + * structure. */
  13805. + volatile size_t xSize = sizeof( StaticTask_t );
  13806. + configASSERT( xSize == sizeof( TCB_t ) );
  13807. + ( void ) xSize; /* Prevent lint warning when configASSERT() is not used. */
  13808. + }
  13809. + #endif /* configASSERT_DEFINED */
  13810. +
  13811. + if( ( pxTaskBuffer != NULL ) && ( puxStackBuffer != NULL ) )
  13812. + {
  13813. + pxNewTCB = ( TCB_t * ) pxTaskBuffer;
  13814. + prvInitialiseNewTask( pxTaskCode, pcName, ulStackDepth, pvParameters, uxPriority, &xReturn, pxNewTCB, puxStackBuffer );
  13815. + rt_thread_startup( ( rt_thread_t ) pxNewTCB );
  13816. + }
  13817. +
  13818. + return xReturn;
  13819. + }
  13820. +
  13821. +#endif /* SUPPORT_STATIC_ALLOCATION */
  13822. +
  13823. +#if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
  13824. +
  13825. + BaseType_t xTaskCreate( TaskFunction_t pxTaskCode,
  13826. + const char * const pcName,
  13827. + const configSTACK_DEPTH_TYPE usStackDepth,
  13828. + void * const pvParameters,
  13829. + UBaseType_t uxPriority,
  13830. + TaskHandle_t * const pxCreatedTask )
  13831. + {
  13832. + TCB_t * pxNewTCB;
  13833. + BaseType_t xReturn = errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY;
  13834. + void * stack_start = RT_NULL;
  13835. +
  13836. + pxNewTCB = ( TCB_t * ) RT_KERNEL_MALLOC( sizeof( TCB_t ) );
  13837. + if ( pxNewTCB != NULL )
  13838. + {
  13839. + stack_start = RT_KERNEL_MALLOC( usStackDepth * sizeof( StackType_t ) );
  13840. + if ( stack_start != RT_NULL )
  13841. + {
  13842. + prvInitialiseNewTask( pxTaskCode, pcName, ( uint32_t ) usStackDepth, pvParameters, uxPriority, pxCreatedTask, pxNewTCB, ( StackType_t * ) stack_start );
  13843. + xReturn = pdPASS;
  13844. + /* Mark as dynamic */
  13845. + ( ( struct rt_thread * ) pxNewTCB )->type &= ~RT_Object_Class_Static;
  13846. + rt_thread_startup( ( rt_thread_t ) pxNewTCB );
  13847. + }
  13848. + else
  13849. + {
  13850. + RT_KERNEL_FREE( pxNewTCB );
  13851. + }
  13852. + }
  13853. +
  13854. + return xReturn;
  13855. + }
  13856. +
  13857. +#endif /* configSUPPORT_DYNAMIC_ALLOCATION */
  13858. +/*-----------------------------------------------------------*/
  13859. +
  13860. +/* ESP32 */
  13861. +#if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
  13862. +
  13863. + BaseType_t xTaskCreatePinnedToCore( TaskFunction_t pvTaskCode,
  13864. + const char * const pcName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
  13865. + const uint32_t usStackDepth,
  13866. + void * const pvParameters,
  13867. + UBaseType_t uxPriority,
  13868. + TaskHandle_t * const pvCreatedTask,
  13869. + const BaseType_t xCoreID)
  13870. + {
  13871. + ( void ) xCoreID;
  13872. + return xTaskCreate( pvTaskCode, pcName, usStackDepth, pvParameters, uxPriority, pvCreatedTask );
  13873. + }
  13874. +
  13875. +#endif /* configSUPPORT_DYNAMIC_ALLOCATION */
  13876. +/*-----------------------------------------------------------*/
  13877. +
  13878. +static void prvInitialiseNewTask( TaskFunction_t pxTaskCode,
  13879. + const char * const pcName,
  13880. + const uint32_t ulStackDepth,
  13881. + void * const pvParameters,
  13882. + UBaseType_t uxPriority,
  13883. + TaskHandle_t * const pxCreatedTask,
  13884. + TCB_t * pxNewTCB,
  13885. + StackType_t * const puxStackBuffer )
  13886. +{
  13887. + /* This is used as an array index so must ensure it's not too large. */
  13888. + configASSERT( uxPriority < configMAX_PRIORITIES );
  13889. +
  13890. + if( uxPriority >= ( UBaseType_t ) configMAX_PRIORITIES )
  13891. + {
  13892. + uxPriority = ( UBaseType_t ) configMAX_PRIORITIES - ( UBaseType_t ) 1U;
  13893. + }
  13894. +
  13895. + rt_thread_init( ( struct rt_thread * ) pxNewTCB, pcName, pxTaskCode, pvParameters,
  13896. + puxStackBuffer, ulStackDepth * sizeof( StackType_t ), FREERTOS_PRIORITY_TO_RTTHREAD( uxPriority ), 1 );
  13897. +
  13898. +#if ( configUSE_APPLICATION_TASK_TAG == 1 )
  13899. + pxNewTCB->pxTaskTag = NULL;
  13900. +#endif
  13901. +
  13902. +#if ( configUSE_TASK_NOTIFICATIONS == 1 )
  13903. + rt_memset( ( void * ) &( pxNewTCB->ulNotifiedValue[ 0 ] ), 0x00, sizeof( pxNewTCB->ulNotifiedValue ) );
  13904. + rt_memset( ( void * ) &( pxNewTCB->ucNotifyState[ 0 ] ), 0x00, sizeof( pxNewTCB->ucNotifyState ) );
  13905. +#endif
  13906. +
  13907. +#if ( INCLUDE_xTaskAbortDelay == 1 )
  13908. + pxNewTCB->ucDelayAborted = pdFALSE;
  13909. +#endif
  13910. +
  13911. + if ( pxCreatedTask != NULL )
  13912. + {
  13913. + *pxCreatedTask = ( TaskHandle_t ) pxNewTCB;
  13914. + }
  13915. +}
  13916. +/*-----------------------------------------------------------*/
  13917. +
  13918. +#if ( INCLUDE_vTaskDelete == 1 )
  13919. +
  13920. + void vTaskDelete( TaskHandle_t xTaskToDelete )
  13921. + {
  13922. + rt_thread_t thread = ( rt_thread_t ) prvGetTCBFromHandle( xTaskToDelete );
  13923. + if ( thread == RT_NULL )
  13924. + {
  13925. + thread = rt_thread_self();
  13926. + }
  13927. + #if ( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) )
  13928. + if ( rt_object_is_systemobject( ( rt_object_t ) thread ) )
  13929. + #endif
  13930. + {
  13931. + #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
  13932. + rt_thread_detach( thread );
  13933. + #endif
  13934. + #if ( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) )
  13935. + }
  13936. + else
  13937. + {
  13938. + #endif
  13939. + #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
  13940. + rt_thread_delete( thread );
  13941. + #endif
  13942. + }
  13943. +
  13944. + if ( thread == rt_thread_self() )
  13945. + {
  13946. + rt_schedule();
  13947. + }
  13948. + }
  13949. +
  13950. +#endif /* INCLUDE_vTaskDelete */
  13951. +/*-----------------------------------------------------------*/
  13952. +
  13953. +#if ( INCLUDE_xTaskDelayUntil == 1 )
  13954. +
  13955. + BaseType_t xTaskDelayUntil( TickType_t * const pxPreviousWakeTime,
  13956. + const TickType_t xTimeIncrement )
  13957. + {
  13958. + BaseType_t xShouldDelay = pdFALSE;
  13959. + rt_base_t level;
  13960. + rt_tick_t cur_tick;
  13961. +
  13962. + RT_ASSERT( pxPreviousWakeTime != RT_NULL );
  13963. + RT_ASSERT( xTimeIncrement > 0U );
  13964. +
  13965. + level = rt_hw_interrupt_disable();
  13966. + cur_tick = rt_tick_get();
  13967. + if (cur_tick - *pxPreviousWakeTime < xTimeIncrement)
  13968. + {
  13969. + rt_thread_delay_until( pxPreviousWakeTime, xTimeIncrement );
  13970. + xShouldDelay = pdTRUE;
  13971. + }
  13972. + rt_hw_interrupt_enable( level );
  13973. +
  13974. + return xShouldDelay;
  13975. + }
  13976. +
  13977. +#endif /* INCLUDE_xTaskDelayUntil */
  13978. +/*-----------------------------------------------------------*/
  13979. +
  13980. +#if ( INCLUDE_vTaskDelay == 1 )
  13981. +
  13982. + void vTaskDelay( const TickType_t xTicksToDelay )
  13983. + {
  13984. + rt_thread_delay( xTicksToDelay );
  13985. + }
  13986. +
  13987. +#endif /* INCLUDE_vTaskDelay */
  13988. +/*-----------------------------------------------------------*/
  13989. +
  13990. +#if ( ( INCLUDE_eTaskGetState == 1 ) || ( configUSE_TRACE_FACILITY == 1 ) || ( INCLUDE_xTaskAbortDelay == 1 ) )
  13991. +
  13992. + eTaskState eTaskGetState( TaskHandle_t xTask )
  13993. + {
  13994. + eTaskState eReturn;
  13995. + rt_thread_t thread = ( rt_thread_t ) xTask;
  13996. + rt_base_t level;
  13997. +
  13998. + configASSERT( xTask );
  13999. +
  14000. + level = rt_hw_interrupt_disable();
  14001. +
  14002. + switch ( thread->stat & RT_THREAD_STAT_MASK )
  14003. + {
  14004. + case RT_THREAD_READY:
  14005. + {
  14006. + eReturn = eReady;
  14007. + break;
  14008. + }
  14009. + case RT_THREAD_SUSPEND:
  14010. + {
  14011. + /* If thread timer is activated it is blocked with a timeout */
  14012. + if ( thread->thread_timer.parent.flag & RT_TIMER_FLAG_ACTIVATED )
  14013. + {
  14014. + eReturn = eBlocked;
  14015. + }
  14016. + /* Otherwise it is suspended or blocked with an infinite timeout */
  14017. + else
  14018. + {
  14019. + eReturn = eSuspended;
  14020. + }
  14021. + break;
  14022. + }
  14023. + case RT_THREAD_RUNNING:
  14024. + {
  14025. + eReturn = eRunning;
  14026. + break;
  14027. + }
  14028. + case RT_THREAD_CLOSE:
  14029. + {
  14030. + eReturn = eDeleted;
  14031. + break;
  14032. + }
  14033. + default:
  14034. + eReturn = eInvalid;
  14035. + }
  14036. +
  14037. + rt_hw_interrupt_enable( level );
  14038. +
  14039. + return eReturn;
  14040. + }
  14041. +
  14042. +#endif /* INCLUDE_eTaskGetState */
  14043. +/*-----------------------------------------------------------*/
  14044. +
  14045. +#if ( INCLUDE_uxTaskPriorityGet == 1 )
  14046. +
  14047. + UBaseType_t uxTaskPriorityGet( const TaskHandle_t xTask )
  14048. + {
  14049. + UBaseType_t uxReturn;
  14050. + rt_thread_t thread = ( rt_thread_t ) prvGetTCBFromHandle( xTask );
  14051. + rt_base_t level;
  14052. +
  14053. + level = rt_hw_interrupt_disable();
  14054. + uxReturn = thread->current_priority;
  14055. + rt_hw_interrupt_enable( level );
  14056. +
  14057. + return RTTHREAD_PRIORITY_TO_FREERTOS( uxReturn );
  14058. + }
  14059. +
  14060. +#endif /* INCLUDE_uxTaskPriorityGet */
  14061. +/*-----------------------------------------------------------*/
  14062. +
  14063. +#if ( INCLUDE_uxTaskPriorityGet == 1 )
  14064. +
  14065. + UBaseType_t uxTaskPriorityGetFromISR( const TaskHandle_t xTask )
  14066. + {
  14067. + return uxTaskPriorityGet( xTask );
  14068. + }
  14069. +
  14070. +#endif /* INCLUDE_uxTaskPriorityGet */
  14071. +/*-----------------------------------------------------------*/
  14072. +
  14073. +#if ( INCLUDE_vTaskPrioritySet == 1 )
  14074. +
  14075. + void vTaskPrioritySet( TaskHandle_t xTask,
  14076. + UBaseType_t uxNewPriority )
  14077. + {
  14078. + extern rt_thread_t rt_current_thread;
  14079. + rt_thread_t thread;
  14080. + rt_uint8_t current_priority;
  14081. + rt_bool_t need_schedule = RT_FALSE;
  14082. + rt_base_t level;
  14083. +
  14084. + configASSERT( uxNewPriority < configMAX_PRIORITIES );
  14085. +
  14086. + /* Ensure the new priority is valid. */
  14087. + if( uxNewPriority >= ( UBaseType_t ) configMAX_PRIORITIES )
  14088. + {
  14089. + uxNewPriority = ( UBaseType_t ) configMAX_PRIORITIES - ( UBaseType_t ) 1U;
  14090. + }
  14091. + uxNewPriority = FREERTOS_PRIORITY_TO_RTTHREAD( uxNewPriority );
  14092. +
  14093. + level = rt_hw_interrupt_disable();
  14094. +
  14095. + thread = ( rt_thread_t ) prvGetTCBFromHandle( xTask );
  14096. + current_priority = thread->current_priority;
  14097. + if ( current_priority != uxNewPriority )
  14098. + {
  14099. + rt_thread_control( thread, RT_THREAD_CTRL_CHANGE_PRIORITY, &uxNewPriority);
  14100. + if ( uxNewPriority < current_priority )
  14101. + {
  14102. + /* The priority of a task other than the currently running task is being raised.
  14103. + * Need to schedule if the priority is raised above that of the running task */
  14104. + if ( thread != rt_current_thread && uxNewPriority <= rt_current_thread->current_priority )
  14105. + {
  14106. + need_schedule = RT_TRUE;
  14107. + }
  14108. + }
  14109. + /* Setting the priority of the running task down means
  14110. + * there may now be another task of higher priority that
  14111. + * is ready to execute. */
  14112. + else if ( thread == rt_current_thread )
  14113. + {
  14114. + need_schedule = RT_TRUE;
  14115. + }
  14116. + }
  14117. +
  14118. + rt_hw_interrupt_enable( level );
  14119. +
  14120. + if ( need_schedule == RT_TRUE )
  14121. + {
  14122. + rt_schedule();
  14123. + }
  14124. + }
  14125. +
  14126. +#endif /* INCLUDE_vTaskPrioritySet */
  14127. +/*-----------------------------------------------------------*/
  14128. +
  14129. +#if ( INCLUDE_vTaskSuspend == 1 )
  14130. +
  14131. + void vTaskSuspend( TaskHandle_t xTaskToSuspend )
  14132. + {
  14133. + rt_thread_t thread = ( rt_thread_t ) prvGetTCBFromHandle( xTaskToSuspend );
  14134. + if ( rt_thread_suspend( thread ) == RT_EOK )
  14135. + {
  14136. + rt_schedule();
  14137. + }
  14138. + }
  14139. +
  14140. +#endif /* INCLUDE_vTaskSuspend */
  14141. +/*-----------------------------------------------------------*/
  14142. +
  14143. +#if ( INCLUDE_vTaskSuspend == 1 )
  14144. +
  14145. + void vTaskResume( TaskHandle_t xTaskToResume )
  14146. + {
  14147. + rt_thread_t thread = ( rt_thread_t ) xTaskToResume;
  14148. + rt_bool_t need_schedule = RT_FALSE;
  14149. + rt_base_t level;
  14150. +
  14151. + /* It does not make sense to resume the calling task. */
  14152. + configASSERT( xTaskToResume );
  14153. +
  14154. + if ( thread != NULL && thread != rt_thread_self() )
  14155. + {
  14156. + level = rt_hw_interrupt_disable();
  14157. + /* A task with higher priority than the current running task is ready */
  14158. + if ( rt_thread_resume( thread ) == RT_EOK && thread->current_priority <= rt_thread_self()->current_priority )
  14159. + {
  14160. + need_schedule = RT_TRUE;
  14161. + }
  14162. + rt_hw_interrupt_enable( level );
  14163. + }
  14164. + if (need_schedule == RT_TRUE)
  14165. + {
  14166. + rt_schedule();
  14167. + }
  14168. + }
  14169. +
  14170. +#endif /* INCLUDE_vTaskSuspend */
  14171. +
  14172. +/*-----------------------------------------------------------*/
  14173. +
  14174. +#if ( ( INCLUDE_xTaskResumeFromISR == 1 ) && ( INCLUDE_vTaskSuspend == 1 ) )
  14175. +
  14176. + BaseType_t xTaskResumeFromISR( TaskHandle_t xTaskToResume )
  14177. + {
  14178. + vTaskResume( xTaskToResume );
  14179. + return pdFALSE;
  14180. + }
  14181. +
  14182. +#endif /* ( ( INCLUDE_xTaskResumeFromISR == 1 ) && ( INCLUDE_vTaskSuspend == 1 ) ) */
  14183. +/*-----------------------------------------------------------*/
  14184. +
  14185. +void vTaskStartScheduler( void )
  14186. +{
  14187. + xSchedulerRunning = pdTRUE;
  14188. +}
  14189. +/*-----------------------------------------------------------*/
  14190. +
  14191. +void vTaskEndScheduler( void )
  14192. +{
  14193. + xSchedulerRunning = pdFALSE;
  14194. + vPortEndScheduler();
  14195. +}
  14196. +/*----------------------------------------------------------*/
  14197. +
  14198. +#if ( configUSE_NEWLIB_REENTRANT == 1 )
  14199. +struct _reent* __getreent(void) {
  14200. + return _GLOBAL_REENT;
  14201. +}
  14202. +#endif
  14203. +
  14204. +void vTaskSuspendAll( void )
  14205. +{
  14206. + rt_enter_critical();
  14207. +}
  14208. +/*----------------------------------------------------------*/
  14209. +
  14210. +BaseType_t xTaskResumeAll( void )
  14211. +{
  14212. + rt_exit_critical();
  14213. + return pdFALSE;
  14214. +}
  14215. +/*-----------------------------------------------------------*/
  14216. +
  14217. +TickType_t xTaskGetTickCount( void )
  14218. +{
  14219. + return rt_tick_get();
  14220. +}
  14221. +/*-----------------------------------------------------------*/
  14222. +
  14223. +TickType_t xTaskGetTickCountFromISR( void )
  14224. +{
  14225. + return rt_tick_get();
  14226. +}
  14227. +/*-----------------------------------------------------------*/
  14228. +
  14229. +UBaseType_t uxTaskGetNumberOfTasks( void )
  14230. +{
  14231. + UBaseType_t uxReturn = 0;
  14232. + rt_base_t level;
  14233. + struct rt_object_information *information;
  14234. + struct rt_list_node *node = RT_NULL;
  14235. +
  14236. + information = rt_object_get_information( RT_Object_Class_Thread );
  14237. + RT_ASSERT( information != RT_NULL );
  14238. +
  14239. + level = rt_hw_interrupt_disable();
  14240. +
  14241. + rt_list_for_each( node, &( information->object_list ) )
  14242. + {
  14243. + uxReturn += 1;
  14244. + }
  14245. +
  14246. + rt_hw_interrupt_enable( level );
  14247. +
  14248. + return uxReturn;
  14249. +}
  14250. +/*-----------------------------------------------------------*/
  14251. +
  14252. +char * pcTaskGetName( TaskHandle_t xTaskToQuery )
  14253. +{
  14254. + rt_thread_t thread = ( rt_thread_t ) prvGetTCBFromHandle( xTaskToQuery );
  14255. + return &( thread->name[ 0 ] );
  14256. +}
  14257. +/*-----------------------------------------------------------*/
  14258. +
  14259. +#if ( INCLUDE_xTaskGetHandle == 1 )
  14260. +
  14261. + TaskHandle_t xTaskGetHandle( const char * pcNameToQuery )
  14262. + {
  14263. + return ( TaskHandle_t ) rt_thread_find( ( char * ) pcNameToQuery );
  14264. + }
  14265. +
  14266. +#endif /* INCLUDE_xTaskGetHandle */
  14267. +/*-----------------------------------------------------------*/
  14268. +
  14269. +#if ( INCLUDE_xTaskGetIdleTaskHandle == 1 )
  14270. +
  14271. + TaskHandle_t xTaskGetIdleTaskHandle( void )
  14272. + {
  14273. + return ( TaskHandle_t ) rt_thread_find( "tidle0" );
  14274. + }
  14275. +
  14276. +#endif /* INCLUDE_xTaskGetIdleTaskHandle */
  14277. +/*----------------------------------------------------------*/
  14278. +
  14279. +#if ( INCLUDE_xTaskAbortDelay == 1 )
  14280. +
  14281. + BaseType_t xTaskAbortDelay( TaskHandle_t xTask )
  14282. + {
  14283. + TCB_t * pxTCB = xTask;
  14284. + BaseType_t xReturn;
  14285. + rt_thread_t thread = ( rt_thread_t ) xTask;
  14286. + rt_bool_t need_schedule = RT_FALSE;
  14287. + rt_base_t level;
  14288. +
  14289. + configASSERT( pxTCB );
  14290. +
  14291. + level = rt_hw_interrupt_disable();
  14292. +
  14293. + if ( eTaskGetState( xTask ) == eBlocked )
  14294. + {
  14295. + rt_thread_resume( thread );
  14296. + thread->error = -RT_ETIMEOUT;
  14297. + pxTCB->ucDelayAborted = pdTRUE;
  14298. + if ( thread->current_priority < rt_thread_self()->current_priority ){
  14299. + need_schedule = RT_TRUE;
  14300. + }
  14301. + xReturn = pdPASS;
  14302. + }
  14303. + else
  14304. + {
  14305. + xReturn = pdFAIL;
  14306. + }
  14307. +
  14308. + rt_hw_interrupt_enable( level );
  14309. +
  14310. + if ( need_schedule == RT_TRUE )
  14311. + {
  14312. + rt_schedule();
  14313. + }
  14314. +
  14315. + return xReturn;
  14316. + }
  14317. +
  14318. +#endif /* INCLUDE_xTaskAbortDelay */
  14319. +/*----------------------------------------------------------*/
  14320. +
  14321. +#if ( configUSE_APPLICATION_TASK_TAG == 1 )
  14322. +
  14323. + void vTaskSetApplicationTaskTag( TaskHandle_t xTask,
  14324. + TaskHookFunction_t pxHookFunction )
  14325. + {
  14326. + TCB_t * xTCB = prvGetTCBFromHandle( xTask );
  14327. + rt_base_t level;
  14328. +
  14329. + level = rt_hw_interrupt_disable();
  14330. + xTCB->pxTaskTag = pxHookFunction;
  14331. + rt_hw_interrupt_enable( level );
  14332. + }
  14333. +
  14334. +#endif /* configUSE_APPLICATION_TASK_TAG */
  14335. +/*-----------------------------------------------------------*/
  14336. +
  14337. +#if ( configUSE_APPLICATION_TASK_TAG == 1 )
  14338. +
  14339. + TaskHookFunction_t xTaskGetApplicationTaskTag( TaskHandle_t xTask )
  14340. + {
  14341. + TaskHookFunction_t xReturn;
  14342. + TCB_t * xTCB = prvGetTCBFromHandle( xTask );
  14343. + rt_base_t level;
  14344. +
  14345. + level = rt_hw_interrupt_disable();
  14346. + xReturn = xTCB->pxTaskTag;
  14347. + rt_hw_interrupt_enable( level );
  14348. +
  14349. + return xReturn;
  14350. + }
  14351. +
  14352. +#endif /* configUSE_APPLICATION_TASK_TAG */
  14353. +/*-----------------------------------------------------------*/
  14354. +
  14355. +#if ( configUSE_APPLICATION_TASK_TAG == 1 )
  14356. +
  14357. + TaskHookFunction_t xTaskGetApplicationTaskTagFromISR( TaskHandle_t xTask )
  14358. + {
  14359. + return xTaskGetApplicationTaskTag( xTask );
  14360. + }
  14361. +
  14362. +#endif /* configUSE_APPLICATION_TASK_TAG */
  14363. +/*-----------------------------------------------------------*/
  14364. +
  14365. +#if ( configUSE_APPLICATION_TASK_TAG == 1 )
  14366. +
  14367. + BaseType_t xTaskCallApplicationTaskHook( TaskHandle_t xTask,
  14368. + void * pvParameter )
  14369. + {
  14370. + BaseType_t xReturn;
  14371. + TCB_t * xTCB = prvGetTCBFromHandle( xTask );
  14372. +
  14373. + if( xTCB->pxTaskTag != NULL )
  14374. + {
  14375. + xReturn = xTCB->pxTaskTag( pvParameter );
  14376. + }
  14377. + else
  14378. + {
  14379. + xReturn = pdFAIL;
  14380. + }
  14381. +
  14382. + return xReturn;
  14383. + }
  14384. +
  14385. +#endif /* configUSE_APPLICATION_TASK_TAG */
  14386. +/*-----------------------------------------------------------*/
  14387. +
  14388. +void vTaskSetTimeOutState( TimeOut_t * const pxTimeOut )
  14389. +{
  14390. + rt_base_t level;
  14391. +
  14392. + configASSERT( pxTimeOut );
  14393. + level = rt_hw_interrupt_disable();
  14394. + pxTimeOut->xOverflowCount = 0;
  14395. + pxTimeOut->xTimeOnEntering = ( TickType_t ) rt_tick_get();
  14396. + rt_hw_interrupt_enable( level );
  14397. +}
  14398. +/*-----------------------------------------------------------*/
  14399. +
  14400. +void vTaskInternalSetTimeOutState( TimeOut_t * const pxTimeOut )
  14401. +{
  14402. + /* For internal use only as it does not use a critical section. */
  14403. + pxTimeOut->xOverflowCount = 0;
  14404. + pxTimeOut->xTimeOnEntering = ( TickType_t ) rt_tick_get();;
  14405. +}
  14406. +/*-----------------------------------------------------------*/
  14407. +
  14408. +BaseType_t xTaskCheckForTimeOut( TimeOut_t * const pxTimeOut,
  14409. + TickType_t * const pxTicksToWait )
  14410. +{
  14411. + TCB_t * pxCurrentTCB = ( TCB_t * ) rt_thread_self();
  14412. + BaseType_t xReturn;
  14413. + rt_base_t level;
  14414. +
  14415. + configASSERT( pxTimeOut );
  14416. + configASSERT( pxTicksToWait );
  14417. +
  14418. + level = rt_hw_interrupt_disable();
  14419. + /* Minor optimisation. The tick count cannot change in this block. */
  14420. + const TickType_t xConstTickCount = ( TickType_t ) rt_tick_get();
  14421. + const TickType_t xElapsedTime = xConstTickCount - pxTimeOut->xTimeOnEntering;
  14422. +
  14423. +#if ( INCLUDE_xTaskAbortDelay == 1 )
  14424. + if( pxCurrentTCB->ucDelayAborted != ( uint8_t ) pdFALSE )
  14425. + {
  14426. + /* The delay was aborted, which is not the same as a time out,
  14427. + * but has the same result. */
  14428. + pxCurrentTCB->ucDelayAborted = pdFALSE;
  14429. + xReturn = pdTRUE;
  14430. + }
  14431. + else
  14432. +#endif
  14433. +
  14434. +#if ( INCLUDE_vTaskSuspend == 1 )
  14435. + if( *pxTicksToWait == portMAX_DELAY )
  14436. + {
  14437. + /* If INCLUDE_vTaskSuspend is set to 1 and the block time
  14438. + * specified is the maximum block time then the task should block
  14439. + * indefinitely, and therefore never time out. */
  14440. + xReturn = pdFALSE;
  14441. + }
  14442. + else
  14443. +#endif
  14444. +
  14445. + if( xElapsedTime < *pxTicksToWait )
  14446. + {
  14447. + /* Not a genuine timeout. Adjust parameters for time remaining. */
  14448. + *pxTicksToWait -= xElapsedTime;
  14449. + vTaskInternalSetTimeOutState( pxTimeOut );
  14450. + xReturn = pdFALSE;
  14451. + }
  14452. + else
  14453. + {
  14454. + *pxTicksToWait = ( TickType_t ) 0;
  14455. + xReturn = pdTRUE;
  14456. + }
  14457. + rt_hw_interrupt_enable( level );
  14458. +
  14459. + return xReturn;
  14460. +}
  14461. +/*-----------------------------------------------------------*/
  14462. +
  14463. +#if ( ( INCLUDE_xTaskGetCurrentTaskHandle == 1 ) )
  14464. +
  14465. + TaskHandle_t xTaskGetCurrentTaskHandle( void )
  14466. + {
  14467. + TaskHandle_t xReturn;
  14468. +
  14469. + /* A critical section is not required as this is not called from
  14470. + * an interrupt and the current TCB will always be the same for any
  14471. + * individual execution thread. */
  14472. + xReturn = ( TaskHandle_t ) rt_thread_self();
  14473. +
  14474. + return xReturn;
  14475. + }
  14476. +
  14477. +#endif /* ( ( INCLUDE_xTaskGetCurrentTaskHandle == 1 ) || ( configUSE_MUTEXES == 1 ) ) */
  14478. +/*-----------------------------------------------------------*/
  14479. +
  14480. +#if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )
  14481. +
  14482. + BaseType_t xTaskGetSchedulerState( void )
  14483. + {
  14484. + BaseType_t xReturn;
  14485. +
  14486. + if( xSchedulerRunning == pdFALSE )
  14487. + {
  14488. + xReturn = taskSCHEDULER_NOT_STARTED;
  14489. + }
  14490. + else
  14491. + {
  14492. + if( rt_critical_level() == 0 )
  14493. + {
  14494. + xReturn = taskSCHEDULER_RUNNING;
  14495. + }
  14496. + else
  14497. + {
  14498. + xReturn = taskSCHEDULER_SUSPENDED;
  14499. + }
  14500. + }
  14501. +
  14502. + return xReturn;
  14503. + }
  14504. +
  14505. +#endif /* ( ( INCLUDE_xTaskGetSchedulerState == 1 ) ) */
  14506. +/*-----------------------------------------------------------*/
  14507. +
  14508. +#if ( configUSE_TASK_NOTIFICATIONS == 1 )
  14509. +
  14510. + uint32_t ulTaskGenericNotifyTake( UBaseType_t uxIndexToWait,
  14511. + BaseType_t xClearCountOnExit,
  14512. + TickType_t xTicksToWait )
  14513. + {
  14514. + uint32_t ulReturn;
  14515. + TCB_t * pxCurrentTCB = ( TCB_t * ) rt_thread_self();
  14516. + rt_thread_t thread = ( rt_thread_t ) pxCurrentTCB;
  14517. + rt_base_t level;
  14518. +
  14519. + configASSERT( uxIndexToWait < configTASK_NOTIFICATION_ARRAY_ENTRIES );
  14520. +
  14521. + level = rt_hw_interrupt_disable();
  14522. + /* Only block if the notification count is not already non-zero. */
  14523. + if( pxCurrentTCB->ulNotifiedValue[ uxIndexToWait ] == 0UL )
  14524. + {
  14525. + /* Mark this task as waiting for a notification. */
  14526. + pxCurrentTCB->ucNotifyState[ uxIndexToWait ] = taskWAITING_NOTIFICATION;
  14527. +
  14528. + if( xTicksToWait > ( TickType_t ) 0 )
  14529. + {
  14530. + rt_thread_suspend( thread );
  14531. + if ( ( rt_int32_t ) xTicksToWait > 0 )
  14532. + {
  14533. + rt_timer_control(&(thread->thread_timer),
  14534. + RT_TIMER_CTRL_SET_TIME,
  14535. + &xTicksToWait);
  14536. + rt_timer_start(&(thread->thread_timer));
  14537. + }
  14538. + rt_hw_interrupt_enable(level);
  14539. + rt_schedule();
  14540. + /* Clear thread error. */
  14541. + thread->error = RT_EOK;
  14542. + }
  14543. + }
  14544. + rt_hw_interrupt_enable( level );
  14545. +
  14546. + level = rt_hw_interrupt_disable();
  14547. + ulReturn = pxCurrentTCB->ulNotifiedValue[ uxIndexToWait ];
  14548. +
  14549. + if( ulReturn != 0UL )
  14550. + {
  14551. + if( xClearCountOnExit != pdFALSE )
  14552. + {
  14553. + pxCurrentTCB->ulNotifiedValue[ uxIndexToWait ] = 0UL;
  14554. + }
  14555. + else
  14556. + {
  14557. + pxCurrentTCB->ulNotifiedValue[ uxIndexToWait ] = ulReturn - ( uint32_t ) 1;
  14558. + }
  14559. + }
  14560. +
  14561. + pxCurrentTCB->ucNotifyState[ uxIndexToWait ] = taskNOT_WAITING_NOTIFICATION;
  14562. + rt_hw_interrupt_enable( level );
  14563. +
  14564. + return ulReturn;
  14565. + }
  14566. +
  14567. +#endif /* configUSE_TASK_NOTIFICATIONS */
  14568. +/*-----------------------------------------------------------*/
  14569. +
  14570. +#if ( configUSE_TASK_NOTIFICATIONS == 1 )
  14571. +
  14572. + BaseType_t xTaskGenericNotifyWait( UBaseType_t uxIndexToWait,
  14573. + uint32_t ulBitsToClearOnEntry,
  14574. + uint32_t ulBitsToClearOnExit,
  14575. + uint32_t * pulNotificationValue,
  14576. + TickType_t xTicksToWait )
  14577. + {
  14578. + BaseType_t xReturn;
  14579. + TCB_t * pxCurrentTCB = ( TCB_t * ) rt_thread_self();
  14580. + rt_thread_t thread = ( rt_thread_t ) pxCurrentTCB;
  14581. + rt_base_t level;
  14582. +
  14583. + configASSERT( uxIndexToWait < configTASK_NOTIFICATION_ARRAY_ENTRIES );
  14584. +
  14585. + level = rt_hw_interrupt_disable();
  14586. + /* Only block if a notification is not already pending. */
  14587. + if( pxCurrentTCB->ucNotifyState[ uxIndexToWait ] != taskNOTIFICATION_RECEIVED )
  14588. + {
  14589. + /* Clear bits in the task's notification value as bits may get
  14590. + * set by the notifying task or interrupt. This can be used to
  14591. + * clear the value to zero. */
  14592. + pxCurrentTCB->ulNotifiedValue[ uxIndexToWait ] &= ~ulBitsToClearOnEntry;
  14593. +
  14594. + /* Mark this task as waiting for a notification. */
  14595. + pxCurrentTCB->ucNotifyState[ uxIndexToWait ] = taskWAITING_NOTIFICATION;
  14596. +
  14597. + if( xTicksToWait > ( TickType_t ) 0 )
  14598. + {
  14599. + rt_thread_suspend( thread );
  14600. + if ( ( rt_int32_t ) xTicksToWait > 0 )
  14601. + {
  14602. + rt_timer_control(&(thread->thread_timer),
  14603. + RT_TIMER_CTRL_SET_TIME,
  14604. + &xTicksToWait);
  14605. + rt_timer_start(&(thread->thread_timer));
  14606. + }
  14607. + rt_hw_interrupt_enable(level);
  14608. + rt_schedule();
  14609. + /* Clear thread error. It is not used to determine the function return value. */
  14610. + thread->error = RT_EOK;
  14611. + }
  14612. + else
  14613. + {
  14614. + rt_hw_interrupt_enable( level );
  14615. + }
  14616. + }
  14617. + else
  14618. + {
  14619. + rt_hw_interrupt_enable( level );
  14620. + }
  14621. +
  14622. + level = rt_hw_interrupt_disable();
  14623. +
  14624. + if( pulNotificationValue != NULL )
  14625. + {
  14626. + /* Output the current notification value, which may or may not
  14627. + * have changed. */
  14628. + *pulNotificationValue = pxCurrentTCB->ulNotifiedValue[ uxIndexToWait ];
  14629. + }
  14630. +
  14631. + /* If ucNotifyValue is set then either the task never entered the
  14632. + * blocked state (because a notification was already pending) or the
  14633. + * task unblocked because of a notification. Otherwise the task
  14634. + * unblocked because of a timeout. */
  14635. + if( pxCurrentTCB->ucNotifyState[ uxIndexToWait ] != taskNOTIFICATION_RECEIVED )
  14636. + {
  14637. + /* A notification was not received. */
  14638. + xReturn = pdFALSE;
  14639. + }
  14640. + else
  14641. + {
  14642. + /* A notification was already pending or a notification was
  14643. + * received while the task was waiting. */
  14644. + pxCurrentTCB->ulNotifiedValue[ uxIndexToWait ] &= ~ulBitsToClearOnExit;
  14645. + xReturn = pdTRUE;
  14646. + }
  14647. +
  14648. + pxCurrentTCB->ucNotifyState[ uxIndexToWait ] = taskNOT_WAITING_NOTIFICATION;
  14649. + rt_hw_interrupt_enable( level );
  14650. +
  14651. + return xReturn;
  14652. + }
  14653. +
  14654. +#endif /* configUSE_TASK_NOTIFICATIONS */
  14655. +/*-----------------------------------------------------------*/
  14656. +
  14657. +#if ( configUSE_TASK_NOTIFICATIONS == 1 )
  14658. +
  14659. + BaseType_t xTaskGenericNotify( TaskHandle_t xTaskToNotify,
  14660. + UBaseType_t uxIndexToNotify,
  14661. + uint32_t ulValue,
  14662. + eNotifyAction eAction,
  14663. + uint32_t * pulPreviousNotificationValue )
  14664. + {
  14665. + TCB_t * pxTCB;
  14666. + BaseType_t xReturn = pdPASS;
  14667. + uint8_t ucOriginalNotifyState;
  14668. + rt_base_t level;
  14669. +
  14670. + configASSERT( uxIndexToNotify < configTASK_NOTIFICATION_ARRAY_ENTRIES );
  14671. + configASSERT( xTaskToNotify );
  14672. + pxTCB = xTaskToNotify;
  14673. +
  14674. + level = rt_hw_interrupt_disable();
  14675. +
  14676. + if( pulPreviousNotificationValue != NULL )
  14677. + {
  14678. + *pulPreviousNotificationValue = pxTCB->ulNotifiedValue[ uxIndexToNotify ];
  14679. + }
  14680. +
  14681. + ucOriginalNotifyState = pxTCB->ucNotifyState[ uxIndexToNotify ];
  14682. +
  14683. + pxTCB->ucNotifyState[ uxIndexToNotify ] = taskNOTIFICATION_RECEIVED;
  14684. +
  14685. + switch( eAction )
  14686. + {
  14687. + case eSetBits:
  14688. + pxTCB->ulNotifiedValue[ uxIndexToNotify ] |= ulValue;
  14689. + break;
  14690. +
  14691. + case eIncrement:
  14692. + ( pxTCB->ulNotifiedValue[ uxIndexToNotify ] )++;
  14693. + break;
  14694. +
  14695. + case eSetValueWithOverwrite:
  14696. + pxTCB->ulNotifiedValue[ uxIndexToNotify ] = ulValue;
  14697. + break;
  14698. +
  14699. + case eSetValueWithoutOverwrite:
  14700. +
  14701. + if( ucOriginalNotifyState != taskNOTIFICATION_RECEIVED )
  14702. + {
  14703. + pxTCB->ulNotifiedValue[ uxIndexToNotify ] = ulValue;
  14704. + }
  14705. + else
  14706. + {
  14707. + /* The value could not be written to the task. */
  14708. + xReturn = pdFAIL;
  14709. + }
  14710. +
  14711. + break;
  14712. +
  14713. + case eNoAction:
  14714. +
  14715. + /* The task is being notified without its notify value being
  14716. + * updated. */
  14717. + break;
  14718. +
  14719. + default:
  14720. +
  14721. + /* Should not get here if all enums are handled.
  14722. + * Artificially force an assert by testing a value the
  14723. + * compiler can't assume is const. */
  14724. + configASSERT( xTaskToNotify == NULL );
  14725. +
  14726. + break;
  14727. + }
  14728. +
  14729. +
  14730. + /* If the task is in the blocked state specifically to wait for a
  14731. + * notification then unblock it now. */
  14732. + if( ucOriginalNotifyState == taskWAITING_NOTIFICATION )
  14733. + {
  14734. + rt_thread_resume( ( rt_thread_t ) pxTCB );
  14735. +
  14736. + if( ( ( rt_thread_t ) pxTCB )->current_priority < rt_thread_self()->current_priority )
  14737. + {
  14738. + /* The notified task has a priority above the currently
  14739. + * executing task so a schedule is required. */
  14740. + rt_schedule();
  14741. + }
  14742. + }
  14743. + rt_hw_interrupt_enable( level );
  14744. +
  14745. + return xReturn;
  14746. + }
  14747. +
  14748. +#endif /* configUSE_TASK_NOTIFICATIONS */
  14749. +/*-----------------------------------------------------------*/
  14750. +
  14751. +#if ( configUSE_TASK_NOTIFICATIONS == 1 )
  14752. +
  14753. + BaseType_t xTaskGenericNotifyFromISR( TaskHandle_t xTaskToNotify,
  14754. + UBaseType_t uxIndexToNotify,
  14755. + uint32_t ulValue,
  14756. + eNotifyAction eAction,
  14757. + uint32_t * pulPreviousNotificationValue,
  14758. + BaseType_t * pxHigherPriorityTaskWoken )
  14759. + {
  14760. + BaseType_t xReturn;
  14761. +
  14762. + xReturn = xTaskGenericNotify( xTaskToNotify, uxIndexToNotify, ulValue, eAction, pulPreviousNotificationValue );
  14763. + if ( pxHigherPriorityTaskWoken != NULL )
  14764. + {
  14765. + *pxHigherPriorityTaskWoken = pdFALSE;
  14766. + }
  14767. +
  14768. + return xReturn;
  14769. + }
  14770. +
  14771. +#endif /* configUSE_TASK_NOTIFICATIONS */
  14772. +/*-----------------------------------------------------------*/
  14773. +
  14774. +#if ( configUSE_TASK_NOTIFICATIONS == 1 )
  14775. +
  14776. + void vTaskGenericNotifyGiveFromISR( TaskHandle_t xTaskToNotify,
  14777. + UBaseType_t uxIndexToNotify,
  14778. + BaseType_t * pxHigherPriorityTaskWoken )
  14779. + {
  14780. + xTaskNotifyGiveIndexed( xTaskToNotify, uxIndexToNotify );
  14781. + if ( pxHigherPriorityTaskWoken != NULL )
  14782. + {
  14783. + *pxHigherPriorityTaskWoken = pdFALSE;
  14784. + }
  14785. + }
  14786. +
  14787. +#endif /* configUSE_TASK_NOTIFICATIONS */
  14788. +/*-----------------------------------------------------------*/
  14789. +
  14790. +#if ( configUSE_TASK_NOTIFICATIONS == 1 )
  14791. +
  14792. + BaseType_t xTaskGenericNotifyStateClear( TaskHandle_t xTask,
  14793. + UBaseType_t uxIndexToClear )
  14794. + {
  14795. + TCB_t * pxTCB;
  14796. + BaseType_t xReturn;
  14797. + rt_base_t level;
  14798. +
  14799. + configASSERT( uxIndexToClear < configTASK_NOTIFICATION_ARRAY_ENTRIES );
  14800. +
  14801. + /* If null is passed in here then it is the calling task that is having
  14802. + * its notification state cleared. */
  14803. + pxTCB = prvGetTCBFromHandle( xTask );
  14804. +
  14805. + level = rt_hw_interrupt_disable();
  14806. +
  14807. + if( pxTCB->ucNotifyState[ uxIndexToClear ] == taskNOTIFICATION_RECEIVED )
  14808. + {
  14809. + pxTCB->ucNotifyState[ uxIndexToClear ] = taskNOT_WAITING_NOTIFICATION;
  14810. + xReturn = pdPASS;
  14811. + }
  14812. + else
  14813. + {
  14814. + xReturn = pdFAIL;
  14815. + }
  14816. +
  14817. + rt_hw_interrupt_enable( level );
  14818. +
  14819. + return xReturn;
  14820. + }
  14821. +
  14822. +#endif /* configUSE_TASK_NOTIFICATIONS */
  14823. +/*-----------------------------------------------------------*/
  14824. +
  14825. +#if ( configUSE_TASK_NOTIFICATIONS == 1 )
  14826. +
  14827. + uint32_t ulTaskGenericNotifyValueClear( TaskHandle_t xTask,
  14828. + UBaseType_t uxIndexToClear,
  14829. + uint32_t ulBitsToClear )
  14830. + {
  14831. + TCB_t * pxTCB;
  14832. + uint32_t ulReturn;
  14833. + rt_base_t level;
  14834. +
  14835. + /* If null is passed in here then it is the calling task that is having
  14836. + * its notification state cleared. */
  14837. + pxTCB = prvGetTCBFromHandle( xTask );
  14838. +
  14839. + level = rt_hw_interrupt_disable();
  14840. +
  14841. + /* Return the notification as it was before the bits were cleared,
  14842. + * then clear the bit mask. */
  14843. + ulReturn = pxTCB->ulNotifiedValue[ uxIndexToClear ];
  14844. + pxTCB->ulNotifiedValue[ uxIndexToClear ] &= ~ulBitsToClear;
  14845. +
  14846. + rt_hw_interrupt_enable( level );
  14847. +
  14848. + return ulReturn;
  14849. + }
  14850. +
  14851. +#endif /* configUSE_TASK_NOTIFICATIONS */
  14852. +/*-----------------------------------------------------------*/
  14853. +
  14854. +#if ( INCLUDE_uxTaskGetStackHighWaterMark2 == 1 )
  14855. +
  14856. +/* uxTaskGetStackHighWaterMark() and uxTaskGetStackHighWaterMark2() are the
  14857. + * same except for their return type. Using configSTACK_DEPTH_TYPE allows the
  14858. + * user to determine the return type. It gets around the problem of the value
  14859. + * overflowing on 8-bit types without breaking backward compatibility for
  14860. + * applications that expect an 8-bit return type. */
  14861. + configSTACK_DEPTH_TYPE uxTaskGetStackHighWaterMark2( TaskHandle_t xTask )
  14862. + {
  14863. + uint32_t ulCount = 0U;
  14864. + rt_thread_t thread = ( rt_thread_t ) prvGetTCBFromHandle( xTask );
  14865. + rt_uint8_t * stack_addr = thread->stack_addr;
  14866. +
  14867. + #ifdef ARCH_CPU_STACK_GROWS_UPWARD
  14868. + stack_addr = stack_addr + thread->stack_size - 1;
  14869. + while ( *stack_addr == '#' )
  14870. + {
  14871. + ulCount += 1;
  14872. + stack_addr -= 1;
  14873. + }
  14874. + #else
  14875. + while ( *stack_addr == '#' )
  14876. + {
  14877. + ulCount += 1;
  14878. + stack_addr += 1;
  14879. + }
  14880. + #endif
  14881. +
  14882. + ulCount /= ( uint32_t ) sizeof( StackType_t );
  14883. +
  14884. + return ( configSTACK_DEPTH_TYPE ) ulCount;
  14885. + }
  14886. +
  14887. +#endif /* INCLUDE_uxTaskGetStackHighWaterMark2 */
  14888. +/*-----------------------------------------------------------*/
  14889. +
  14890. +#if ( INCLUDE_uxTaskGetStackHighWaterMark == 1 )
  14891. +
  14892. + UBaseType_t uxTaskGetStackHighWaterMark( TaskHandle_t xTask )
  14893. + {
  14894. + return ( UBaseType_t ) uxTaskGetStackHighWaterMark2( xTask );
  14895. + }
  14896. +
  14897. +#endif /* INCLUDE_uxTaskGetStackHighWaterMark */
  14898. +/*-----------------------------------------------------------*/
  14899. +
  14900. +
  14901. +/* ESP32 */
  14902. +BaseType_t xTaskGetAffinity( TaskHandle_t xTask )
  14903. +{
  14904. + ( void ) xTask;
  14905. + return 0;
  14906. +}
  14907. +
  14908. +TaskHandle_t xTaskGetCurrentTaskHandleForCPU( BaseType_t cpuid )
  14909. +{
  14910. + ( void ) cpuid;
  14911. + return xTaskGetCurrentTaskHandle();
  14912. +}
  14913. +
  14914. +TaskHandle_t xTaskGetIdleTaskHandleForCPU( UBaseType_t cpuid )
  14915. +{
  14916. + ( void ) cpuid;
  14917. + return xTaskGetIdleTaskHandle();
  14918. +}
  14919. +
  14920. +/* Unimplemented */
  14921. +#include "esp_log.h"
  14922. +#if ( configNUM_THREAD_LOCAL_STORAGE_POINTERS > 0 )
  14923. +void vTaskSetThreadLocalStoragePointer( TaskHandle_t xTaskToSet,
  14924. + BaseType_t xIndex,
  14925. + void * pvValue )
  14926. +{
  14927. + ESP_LOGE("freertos", "vTaskSetThreadLocalStoragePointer unimplemented");
  14928. + RT_ASSERT(0);
  14929. +}
  14930. +void * pvTaskGetThreadLocalStoragePointer( TaskHandle_t xTaskToQuery,
  14931. + BaseType_t xIndex )
  14932. +{
  14933. + ESP_LOGE("freertos", "pvTaskGetThreadLocalStoragePointer unimplemented");
  14934. + RT_ASSERT(0);
  14935. + return NULL;
  14936. +}
  14937. +#if ( configTHREAD_LOCAL_STORAGE_DELETE_CALLBACKS )
  14938. +typedef void (*TlsDeleteCallbackFunction_t)( int, void * );
  14939. +void vTaskSetThreadLocalStoragePointerAndDelCallback( TaskHandle_t xTaskToSet, BaseType_t xIndex, void *pvValue, TlsDeleteCallbackFunction_t pvDelCallback)
  14940. +{
  14941. + ESP_LOGE("freertos", "vTaskSetThreadLocalStoragePointerAndDelCallback unimplemented");
  14942. + RT_ASSERT(0);
  14943. +}
  14944. +#endif
  14945. +#endif
  14946. diff --git a/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/timers.c b/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/timers.c
  14947. new file mode 100644
  14948. index 0000000000..b5b5693d53
  14949. --- /dev/null
  14950. +++ b/components/freertos/RT-Thread-wrapper-of-FreeRTOS/FreeRTOS/timers.c
  14951. @@ -0,0 +1,328 @@
  14952. +/*
  14953. + * FreeRTOS Kernel V10.4.6
  14954. + * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  14955. + *
  14956. + * SPDX-License-Identifier: MIT
  14957. + *
  14958. + * Permission is hereby granted, free of charge, to any person obtaining a copy of
  14959. + * this software and associated documentation files (the "Software"), to deal in
  14960. + * the Software without restriction, including without limitation the rights to
  14961. + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  14962. + * the Software, and to permit persons to whom the Software is furnished to do so,
  14963. + * subject to the following conditions:
  14964. + *
  14965. + * The above copyright notice and this permission notice shall be included in all
  14966. + * copies or substantial portions of the Software.
  14967. + *
  14968. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14969. + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  14970. + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  14971. + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  14972. + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  14973. + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  14974. + *
  14975. + * https://www.FreeRTOS.org
  14976. + * https://github.com/FreeRTOS
  14977. + *
  14978. + */
  14979. +
  14980. +/* Standard includes. */
  14981. +#include <stdlib.h>
  14982. +
  14983. +#include "FreeRTOS.h"
  14984. +#include "task.h"
  14985. +#include "queue.h"
  14986. +#include "timers.h"
  14987. +
  14988. +/* This entire source file will be skipped if the application is not configured
  14989. + * to include software timer functionality. This #if is closed at the very bottom
  14990. + * of this file. If you want to include software timer functionality then ensure
  14991. + * configUSE_TIMERS is set to 1 in FreeRTOSConfig.h. */
  14992. +#if ( configUSE_TIMERS == 1 )
  14993. +
  14994. + typedef void (* rt_timer_callback_t)(void *);
  14995. +
  14996. +/* The definition of the timers themselves. */
  14997. + typedef struct tmrTimerControl
  14998. + {
  14999. + struct rt_timer timer;
  15000. + void * pvTimerID; /*<< An ID to identify the timer. This allows the timer to be identified when the same callback is used for multiple timers. */
  15001. + } xTIMER;
  15002. +
  15003. + typedef xTIMER Timer_t;
  15004. +
  15005. +/*-----------------------------------------------------------*/
  15006. +
  15007. + #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
  15008. +
  15009. + TimerHandle_t xTimerCreate( const char * const pcTimerName,
  15010. + const TickType_t xTimerPeriodInTicks,
  15011. + const UBaseType_t uxAutoReload,
  15012. + void * const pvTimerID,
  15013. + TimerCallbackFunction_t pxCallbackFunction )
  15014. + {
  15015. + Timer_t * pxNewTimer;
  15016. + rt_uint8_t flag = RT_TIMER_FLAG_SOFT_TIMER;
  15017. +
  15018. + pxNewTimer = ( Timer_t * ) RT_KERNEL_MALLOC( sizeof( Timer_t ) );
  15019. +
  15020. + if( pxNewTimer != RT_NULL )
  15021. + {
  15022. + if ( uxAutoReload != pdFALSE )
  15023. + {
  15024. + flag |= RT_TIMER_FLAG_PERIODIC;
  15025. + }
  15026. + else
  15027. + {
  15028. + flag |= RT_TIMER_FLAG_ONE_SHOT;
  15029. + }
  15030. + rt_timer_init( ( rt_timer_t ) pxNewTimer, pcTimerName, ( rt_timer_callback_t ) pxCallbackFunction, pxNewTimer, xTimerPeriodInTicks, flag );
  15031. + pxNewTimer->pvTimerID = pvTimerID;
  15032. + /* Mark as dynamic so we can distinguish when deleting */
  15033. + ( ( rt_timer_t ) pxNewTimer )->parent.type &= ~RT_Object_Class_Static;
  15034. + }
  15035. +
  15036. + return pxNewTimer;
  15037. + }
  15038. +
  15039. + #endif /* configSUPPORT_DYNAMIC_ALLOCATION */
  15040. +/*-----------------------------------------------------------*/
  15041. +
  15042. + #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
  15043. +
  15044. + TimerHandle_t xTimerCreateStatic( const char * const pcTimerName,
  15045. + const TickType_t xTimerPeriodInTicks,
  15046. + const UBaseType_t uxAutoReload,
  15047. + void * const pvTimerID,
  15048. + TimerCallbackFunction_t pxCallbackFunction,
  15049. + StaticTimer_t * pxTimerBuffer )
  15050. + {
  15051. + Timer_t * pxNewTimer;
  15052. + rt_uint8_t flag = RT_TIMER_FLAG_SOFT_TIMER;
  15053. +
  15054. + #if ( configASSERT_DEFINED == 1 )
  15055. + {
  15056. + /* Sanity check that the size of the structure used to declare a
  15057. + * variable of type StaticTimer_t equals the size of the real timer
  15058. + * structure. */
  15059. + volatile size_t xSize = sizeof( StaticTimer_t );
  15060. + configASSERT( xSize == sizeof( Timer_t ) );
  15061. + ( void ) xSize; /* Keeps lint quiet when configASSERT() is not defined. */
  15062. + }
  15063. + #endif /* configASSERT_DEFINED */
  15064. +
  15065. + /* A pointer to a StaticTimer_t structure MUST be provided, use it. */
  15066. + configASSERT( pxTimerBuffer );
  15067. + pxNewTimer = ( Timer_t * ) pxTimerBuffer;
  15068. +
  15069. + if( pxNewTimer != NULL )
  15070. + {
  15071. + if ( uxAutoReload != pdFALSE )
  15072. + {
  15073. + flag |= RT_TIMER_FLAG_PERIODIC;
  15074. + }
  15075. + else
  15076. + {
  15077. + flag |= RT_TIMER_FLAG_ONE_SHOT;
  15078. + }
  15079. + rt_timer_init( ( rt_timer_t ) pxNewTimer, pcTimerName, ( rt_timer_callback_t ) pxCallbackFunction, pxNewTimer, xTimerPeriodInTicks, flag );
  15080. + pxNewTimer->pvTimerID = pvTimerID;
  15081. + }
  15082. +
  15083. + return pxNewTimer;
  15084. + }
  15085. +
  15086. + #endif /* configSUPPORT_STATIC_ALLOCATION */
  15087. +/*-----------------------------------------------------------*/
  15088. +
  15089. + BaseType_t xTimerGenericCommand( TimerHandle_t xTimer,
  15090. + const BaseType_t xCommandID,
  15091. + const TickType_t xOptionalValue,
  15092. + BaseType_t * const pxHigherPriorityTaskWoken,
  15093. + const TickType_t xTicksToWait )
  15094. + {
  15095. + rt_err_t err = -RT_ERROR;
  15096. +
  15097. + configASSERT( xTimer );
  15098. +
  15099. + if ( ( xCommandID == tmrCOMMAND_START ) || ( xCommandID == tmrCOMMAND_START_FROM_ISR )
  15100. + || ( xCommandID == tmrCOMMAND_RESET ) || ( xCommandID == tmrCOMMAND_RESET_FROM_ISR ) )
  15101. + {
  15102. + err = rt_timer_start( ( rt_timer_t ) xTimer );
  15103. + }
  15104. + else if ( ( xCommandID == tmrCOMMAND_STOP ) || ( xCommandID == tmrCOMMAND_STOP_FROM_ISR ) )
  15105. + {
  15106. + err = rt_timer_stop( ( rt_timer_t ) xTimer );
  15107. + }
  15108. + else if ( ( xCommandID == tmrCOMMAND_CHANGE_PERIOD ) || ( xCommandID == tmrCOMMAND_CHANGE_PERIOD_FROM_ISR ) )
  15109. + {
  15110. + if ( rt_timer_stop( ( rt_timer_t ) xTimer ) == RT_EOK )
  15111. + {
  15112. + if ( rt_timer_control( ( rt_timer_t ) xTimer, RT_TIMER_CTRL_SET_TIME, ( void * ) &xOptionalValue ) == RT_EOK )
  15113. + {
  15114. + err = rt_timer_start( ( rt_timer_t ) xTimer );
  15115. + }
  15116. + }
  15117. + }
  15118. + else if ( xCommandID == tmrCOMMAND_DELETE )
  15119. + {
  15120. + #if ( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) )
  15121. + if ( rt_object_is_systemobject( ( rt_object_t ) xTimer ) )
  15122. + #endif
  15123. + {
  15124. + #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
  15125. + err = rt_timer_detach( ( rt_timer_t ) xTimer );
  15126. + #endif
  15127. + #if ( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) )
  15128. + }
  15129. + else
  15130. + {
  15131. + #endif
  15132. + #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
  15133. + ( ( rt_timer_t ) xTimer )->parent.type |= RT_Object_Class_Static;
  15134. + err = rt_timer_detach( ( rt_timer_t ) xTimer );
  15135. + RT_KERNEL_FREE( xTimer );
  15136. + #endif
  15137. + }
  15138. + }
  15139. +
  15140. + if ( ( xCommandID >= tmrFIRST_FROM_ISR_COMMAND ) && ( xCommandID <= tmrCOMMAND_CHANGE_PERIOD_FROM_ISR ) && ( pxHigherPriorityTaskWoken != NULL ) )
  15141. + {
  15142. + *pxHigherPriorityTaskWoken = pdFALSE;
  15143. + }
  15144. +
  15145. + return rt_err_to_freertos( err );
  15146. + }
  15147. +/*-----------------------------------------------------------*/
  15148. +
  15149. + TaskHandle_t xTimerGetTimerDaemonTaskHandle( void )
  15150. + {
  15151. + return ( TaskHandle_t ) rt_thread_find( "timer" );
  15152. + }
  15153. +/*-----------------------------------------------------------*/
  15154. +
  15155. + TickType_t xTimerGetPeriod( TimerHandle_t xTimer )
  15156. + {
  15157. + Timer_t * pxTimer = xTimer;
  15158. + rt_tick_t arg;
  15159. +
  15160. + configASSERT( xTimer );
  15161. + rt_timer_control( ( rt_timer_t ) pxTimer, RT_TIMER_CTRL_GET_TIME, &arg );
  15162. +
  15163. + return ( TickType_t ) arg;
  15164. + }
  15165. +/*-----------------------------------------------------------*/
  15166. +
  15167. + void vTimerSetReloadMode( TimerHandle_t xTimer,
  15168. + const UBaseType_t uxAutoReload )
  15169. + {
  15170. + Timer_t * pxTimer = xTimer;
  15171. +
  15172. + configASSERT( xTimer );
  15173. + if ( uxAutoReload != pdFALSE )
  15174. + {
  15175. + rt_timer_control( ( rt_timer_t ) pxTimer, RT_TIMER_CTRL_SET_PERIODIC, RT_NULL );
  15176. + }
  15177. + else
  15178. + {
  15179. + rt_timer_control( ( rt_timer_t ) pxTimer, RT_TIMER_CTRL_SET_ONESHOT, RT_NULL );
  15180. + }
  15181. + }
  15182. +/*-----------------------------------------------------------*/
  15183. +
  15184. + UBaseType_t uxTimerGetReloadMode( TimerHandle_t xTimer )
  15185. + {
  15186. + Timer_t * pxTimer = xTimer;
  15187. + UBaseType_t uxReturn;
  15188. + rt_base_t level;
  15189. +
  15190. + configASSERT( xTimer );
  15191. + level = rt_hw_interrupt_disable();
  15192. + if ( ( ( rt_timer_t ) pxTimer )->parent.flag & RT_TIMER_FLAG_PERIODIC )
  15193. + {
  15194. + uxReturn = ( UBaseType_t ) pdTRUE;
  15195. + }
  15196. + else
  15197. + {
  15198. + uxReturn = ( UBaseType_t ) pdFALSE;
  15199. + }
  15200. + rt_hw_interrupt_enable( level );
  15201. +
  15202. + return uxReturn;
  15203. + }
  15204. +/*-----------------------------------------------------------*/
  15205. +
  15206. + TickType_t xTimerGetExpiryTime( TimerHandle_t xTimer )
  15207. + {
  15208. + Timer_t * pxTimer = xTimer;
  15209. + TickType_t xReturn;
  15210. +
  15211. + configASSERT( xTimer );
  15212. + rt_timer_control( ( rt_timer_t ) pxTimer, RT_TIMER_CTRL_GET_REMAIN_TIME, &xReturn );
  15213. +
  15214. + return xReturn;
  15215. + }
  15216. +/*-----------------------------------------------------------*/
  15217. +
  15218. + const char * pcTimerGetName( TimerHandle_t xTimer )
  15219. + {
  15220. + Timer_t * pxTimer = xTimer;
  15221. +
  15222. + configASSERT( xTimer );
  15223. + return ( ( rt_timer_t ) pxTimer )->parent.name;
  15224. + }
  15225. +/*-----------------------------------------------------------*/
  15226. +
  15227. + BaseType_t xTimerIsTimerActive( TimerHandle_t xTimer )
  15228. + {
  15229. + BaseType_t xReturn;
  15230. + Timer_t * pxTimer = xTimer;
  15231. + rt_uint32_t arg;
  15232. +
  15233. + configASSERT( xTimer );
  15234. +
  15235. + rt_timer_control( ( rt_timer_t ) pxTimer, RT_TIMER_CTRL_GET_STATE, &arg );
  15236. + if ( arg == RT_TIMER_FLAG_ACTIVATED )
  15237. + {
  15238. + xReturn = pdTRUE;
  15239. + }
  15240. + else
  15241. + {
  15242. + xReturn = pdFALSE;
  15243. + }
  15244. +
  15245. + return xReturn;
  15246. + }
  15247. +/*-----------------------------------------------------------*/
  15248. +
  15249. + void * pvTimerGetTimerID( const TimerHandle_t xTimer )
  15250. + {
  15251. + Timer_t * const pxTimer = xTimer;
  15252. + void * pvReturn;
  15253. + rt_base_t level;
  15254. +
  15255. + configASSERT( xTimer );
  15256. +
  15257. + level = rt_hw_interrupt_disable();
  15258. + pvReturn = pxTimer->pvTimerID;
  15259. + rt_hw_interrupt_enable( level );
  15260. +
  15261. + return pvReturn;
  15262. + }
  15263. +/*-----------------------------------------------------------*/
  15264. +
  15265. + void vTimerSetTimerID( TimerHandle_t xTimer,
  15266. + void * pvNewID )
  15267. + {
  15268. + Timer_t * const pxTimer = xTimer;
  15269. + rt_base_t level;
  15270. +
  15271. + configASSERT( xTimer );
  15272. +
  15273. + level = rt_hw_interrupt_disable();
  15274. + pxTimer->pvTimerID = pvNewID;
  15275. + rt_hw_interrupt_enable( level );
  15276. + }
  15277. +/*-----------------------------------------------------------*/
  15278. +
  15279. +#endif /* configUSE_TIMERS == 1 */
  15280. diff --git a/components/freertos/RT-Thread-wrapper-of-FreeRTOS/readme.md b/components/freertos/RT-Thread-wrapper-of-FreeRTOS/readme.md
  15281. new file mode 100644
  15282. index 0000000000..6a0fafb4c7
  15283. --- /dev/null
  15284. +++ b/components/freertos/RT-Thread-wrapper-of-FreeRTOS/readme.md
  15285. @@ -0,0 +1,3 @@
  15286. +# RT-Thread操作系统的FreeRTOS兼容层
  15287. +## FreeRTOS Application Compatibility Layer (ACL) for RT-Thread
  15288. +## 让基于FreeRTOS开发的应用层无感地迁移到RT-Thread操作系统
  15289. --
  15290. 2.32.0 (Apple Git-132)
  15291. From 9981521890074b517074bf85a4e0a1f71cef851e Mon Sep 17 00:00:00 2001
  15292. From: tangzz98 <tangz98@outlook.com>
  15293. Date: Wed, 3 Aug 2022 16:17:06 +0800
  15294. Subject: [PATCH 4/4] Update linker script for finsh
  15295. ---
  15296. components/esp_system/ld/esp32c3/sections.ld.in | 10 ++++++++++
  15297. 1 file changed, 10 insertions(+)
  15298. diff --git a/components/esp_system/ld/esp32c3/sections.ld.in b/components/esp_system/ld/esp32c3/sections.ld.in
  15299. index 8215237fff..561ae92318 100644
  15300. --- a/components/esp_system/ld/esp32c3/sections.ld.in
  15301. +++ b/components/esp_system/ld/esp32c3/sections.ld.in
  15302. @@ -248,6 +248,16 @@ SECTIONS
  15303. *(.fini.literal)
  15304. *(.fini)
  15305. *(.gnu.version)
  15306. +
  15307. + /* section information for finsh shell */
  15308. + . = ALIGN(4);
  15309. + __fsymtab_start = .;
  15310. + KEEP(*(FSymTab))
  15311. + __fsymtab_end = .;
  15312. + . = ALIGN(4);
  15313. + __vsymtab_start = .;
  15314. + KEEP(*(VSymTab))
  15315. + __vsymtab_end = .;
  15316. /** CPU will try to prefetch up to 16 bytes of
  15317. * of instructions. This means that any configuration (e.g. MMU, PMS) must allow
  15318. --
  15319. 2.32.0 (Apple Git-132)