rainbowbs manual · rainbowbs(rbs) is an open-source base library developed for embedded systems...

300
RainbowBS Manual v0.1.0 Written by QWQ([email protected]) Acknowledgement and About

Upload: others

Post on 21-Mar-2020

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

RainbowBSManualv0.1.0WrittenbyQWQ([email protected])

AcknowledgementandAbout

Page 2: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

AcknowledgmentsThanksgoto:

DimitrivanHeesch,authorofDoxygen.AdamDunkels,authorofprotothreadslibraryandContikiOSkernel.NiuYuQingforlogoandsuggestions.Myfamilyforsupportingandencourage.Haroopad,awell-donemarkdowntool.Enyaforgreatvoicetolistentowhilecoding.

Page 3: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

AboutWhatisthismanualfor

ThismanualisusedasareferencetoRainbowBS(RBS)whichisanopen-sourcebaselibrarydevelopedforembeddedsystemsespeciallywithlimitresources.

Page 4: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

HowtogetsourcepackageRBShasbeencommittedtoGitHub.Soyoucangetthenewestsourcepackagefromhttps://github.com/jacobqwq/RainbowBS/

Page 5: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

FutureworkThisv0.1.0isthefirstdistributedRBSversion.

AlthoughRBScanbeusedindependently,itwillalsobecomeabasicpartofRainbowSysaccordingtotheplan.

ThegoalofRainbowSysistobuildanopen-sourceflexibleandconfigurablesystemsoftwarewrittenbyClanguageforembeddedsystems,especiallylikelowcostmicro-controllerswhichhavelimitresources.RainbowSyswillconsistofCMSIS-compatibleRTOS,filesystem,GUI,comunicationstack,etc....

SoRBSisthefirstdistributedcomponentofRainbowSysandwilloffercommonsupportfortheothercomponentsofRainbowSys.

ThenextdistributedcomponentofRainbowSyswillbetheGUIcomponentnamedRainbowGX(RGX),whichisnowbeingimprovedcontinuouslytogetherwithRBS.AndyouwillseeRGXsoon.:)

RGXDeskLevelDemonstration

Page 6: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

AuthorDesignedbyQWQcomingfromQingdao,ShandongProv,China.

Email:[email protected]

Generatedby 1.8.9.1

Page 7: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

TableofContents

WhatisRainbowBSRainbowBSFeaturesRequirementsLicenceConventions

RainbowBSManualv0.1.0WrittenbyQWQ([email protected])

Chapter1Introduction

Page 8: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

WhatisRainbowBSRainbowBS(RBS)isanopen-sourcebaselibrarydevelopedforembeddedsystemsespeciallywithlimitresources.

RBSiswrittenbyClanguageincompliancewiththeISO/IEC9899:1999standardanditisset-uptobehighlyportable.Thereforeitisindependentofhardwarearchitectureandcanbeincorporatedintolowcostmicro-controllerslike8051,AVR,PIC,ARMandetc...,justwithsmallportingcode.

ThisdocumentshowsyouhowtoconfigureanduseRBS.

FollowingdiagramshowstheRBSpositionintheentiresoftwarearchitecture:

RBSinApplication

FollowingdiagramshowstheRBSarchitecture:

RBSArchitecture

Page 9: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

RainbowBSFeaturesHardwareFeatures

Any8/16/32bitsCPUcanuseit.OnetimerandverylittleflashandRAMneeded.

SoftwareFeaturesPortable:RBSiswrittenbyClanguage,soitisportableonanyCcompilercompatiblewiththeC99standard.Configurable:RBShasbasecomponentsandoptionaladvancedcomponentslistedbelow.

BasicType

BasicMacros

System/CPUInfo.

MemoryOperation

Conversionrelated

base base base base base

Debug DynamicMemoryManagement

ProtothreadProcessModel

OSsupport

optional optional optional optional

OSIndependence:RBScanrunwithorwithoutOSsupport.Itoffersthread-safetyfeatureforOS.PCTools:RAutoConfigforgeneratingconfigurablefilebyUI.

Page 10: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

Requirements1. OnlyCPU,timer,RAMandflasharenecessaryinthetargetsystem.2. TheCcompilercompatiblewiththeISO/IEC9899:1999

standard(C99).

Page 11: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

LicenceRainbowBSisanopen-sourcebaselibraryforembeddedsystems.Thisisafreesoftwareandopenedforeducation,researchandcommercialdevelopmentsunderlicensepolicyoffollowingterms.

Copyright©2015-2016QWQ([email protected]).Allrightsreserved.

Redistributionanduseinsourceandbinaryforms,withorwithoutmodification,arepermittedprovidedthatthefollowingconditionsaremet:

Redistributionsofsourcecodemustretaintheabovecopyrightnotice,thislistofconditionsandthefollowingdisclaimer.Redistributionsinbinaryformmustreproducetheabovecopyrightnotice,thislistofconditionsandthefollowingdisclaimerinthedocumentationand/orothermaterialsprovidedwiththedistribution.Thenameoftheauthormaynotbeusedtoendorseorpromoteproductsderivedfromthissoftwarewithoutspecificpriorwrittenpermission.

THISSOFTWAREISPROVIDEDBYTHECOPYRIGHTHOLDERSANDCONTRIBUTORS"ASIS"ANDANYEXPRESSORIMPLIEDWARRANTIES,INCLUDING,BUTNOTLIMITEDTO,THEIMPLIEDWARRANTIESOFMERCHANTABILITYANDFITNESSFORAPARTICULARPURPOSEAREDISCLAIMED.INNOEVENTSHALLCOPYRIGHTHOLDERSANDCONTRIBUTORSBELIABLEFORANYDIRECT,INDIRECT,INCIDENTAL,SPECIAL,EXEMPLARY,ORCONSEQUENTIALDAMAGES(INCLUDING,BUTNOTLIMITEDTO,PROCUREMENTOFSUBSTITUTEGOODSORSERVICES;LOSSOFUSE,DATA,ORPROFITS;ORBUSINESSINTERRUPTION)HOWEVERCAUSEDANDONANYTHEORYOFLIABILITY,WHETHERINCONTRACT,STRICTLIABILITY,ORTORT(INCLUDINGNEGLIGENCEOROTHERWISE)ARISINGINANYWAYOUTOFTHEUSEOFTHISSOFTWARE,EVENIF

Page 12: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

ADVISEDOFTHEPOSSIBILITYOFSUCHDAMAGE.

Page 13: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

ConventionsFollowingconventionsareusedinthisdocument

textusedfornormaltextitemusedforitememphasizeboldfontusedtoemphasizeprintf()usedforcodequotes

Generatedby 1.8.9.1

Page 14: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

TableofContents

Howtoportbasiccomponents

RainbowBSManualv0.1.0WrittenbyQWQ([email protected])

Chapter2BasicComponents

Basiccomponentsconsistoftype,macros,system/CPUinformation,memoryoperationanddigitconversion.

Typedefinationreferstobasictypes

Macrosreferstobasicmacros

Systemrelatedreferstosystemreleted

CPUrelatedreferstoCPUinformation

Memoryoperationrelatedreferstomemoryoperation

Digitconversionreferstoconversionreleted

Page 15: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

HowtoportbasiccomponentsSystem/CPUinformationneedsomemacrosdefinedinfileRainbowBSConf.h.

RBS_CFG_SYS_INFOindicatesastringwhichRBS_GetSysInfo()returns.

RBS_CFG_TICK_RATEindicatesthetimertickpersecond.

RBS_CFG_CPU_WORD_SIZEindicatessizewhichRBS_GetCPUBits()returns.

RBS_CFG_CPU_BYTE_ORDER_Lisdefinedto0or1whichRBS_IsCPULittleEndian()uses.

RBS_CFG_CPU_STACK_DOWNisdefinedto0or1whichRBS_IsStackGrowDown()uses.

Generatedby 1.8.9.1

Page 16: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

TableofContents

ApplicationModelIntroductionApplicationModelSupportedbyRBSProtothreadProcessLocalvariablesSchedulingImplementation

RainbowBSManualv0.1.0WrittenbyQWQ([email protected])

Chapter3ApplicationModel

Page 17: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

ApplicationModelIntroductionFromtheviewofapplicationdevelopersforanembeddedsystem,therearemainlytwowaystoconstructprogramforanapplication.

Event-Drivenapplicationmodel

Thismodelisverysuitableforsimpleapplications.Twomethodsareused,pollingorinterruptdriven.

Forpollingmethod,theprocessorcanwaitfordatareadytoprocessit,andwaitagain.Thepollingmethodworkswellforverysimpleapplications,butithasseveraldisadvantages.Forexample,whentheapplicationgetsmorecomplex,thepollingloopdesignmightgetverydifficulttomaintain.Also,itisdifficulttodefineprioritiesbetweendifferentservicesusingpollingandyoumightendupwithpoorresponsiveness,whereaperipheralrequestingservicemightneedtowaitalongtimewhiletheprocessorishandlinglessimportanttasks.Andlotsofenergyiswastedduringthepollingwhenserviceisnotrequired.

Page 18: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

pollingmethod

Forinterruptdrivenmethod,almostallmicro-controllershavesomesortofsleepmodesupporttoreducepower,inwhichtheperipheralcanwakeuptheprocessorwhenitrequiresaservice.Interruptsfromdifferentperipheralscanbeassignedwithdifferentinterruptprioritylevelssothatthisallowsmuchbetterresponsiveness..

Page 19: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

interruptdrivenmethod

Insomecases,theprocessingofdatafromperipheralservicescanbepartitionedintotwoparts:thefirstpartneedstobedonequickly,andthesecondpartcanbecarriedoutalittlebitlater.Insuchsituationswecanuseamixtureofinterrupt-drivenandpollingmethodstoconstructtheprogram.Whenaperipheralrequiresservice,ittriggersaninterruptrequestasinaninterrupt-drivenapplication.Oncethefirstpartoftheinterruptserviceiscarriedout,itupdatessomesoftwarevariablessothatthesecondpartoftheservicecanbeexecutedinthepolling-basedapplicationcode.

Page 20: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

mixedpollingandinterruptdrivenmethod

Usingthisarrangement,wecanreducethedurationofhigh-priorityinterrupthandlerssothatlowerpriorityinterruptservicescangetservedquicker.Atthesametime,theprocessorcanstillentersleepmodetosavepowerwhennoservicingisneeded.

Multi-Threadedapplicationmodel

Whentheapplicationsgetmorecomplex,apollingandinterrupt-drivenprogramstructuremightnotbeabletohandletheprocessingrequirements.Forexample,sometasksthatcantakealongtimetoexecutemightneedtobeprocessedconcurrently.Thiscanbedonebydividingtheprocessor’stimeintoanumberoftimeslotsandallocatingthetimeslotstothesetasks.Whileitistechnicallypossibletocreatesuchanarrangementbymanuallypartitioningthe

Page 21: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

tasksandbuildingasimpleschedulertohandlethis,itisoftenimpracticaltodothisinrealprojectsasitistimeconsumingandcanmaketheprogrammuchhardertomaintainanddebug.

Intheseapplications,aReal-TimeOperatingSystem(RTOS)canbeusedtohandlethetaskscheduling(Figure2.11).AnRTOSallowsmultipleprocessestobeexecutedconcurrently,bydividingtheprocessor’stimeintotimeslotsandallocatingthetimeslotstotheprocessesthatrequireservices.AtimerisneedtohandlethetimekeepingfortheRTOS,andattheendofeachtimeslot,thetimergeneratesatimerinterrupt,whichtriggersthetaskscheduleranddecidesifcontextswitchingshouldbecarriedout.Ifyes,thecurrentexecutingprocessissuspendedandtheprocessorexecutesanotherprocess.

multi-thresdedmethod

Page 22: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

ApplicationModelSupportedbyRBSTherearethreeoptionalapplicationmodeltowriteyourapplicationcodebasedonRBS.

NormalModel

Thisisanevent-drivensystemmodelsothatanendlessloopisneededinmain().

OSModel

Thisisamulti-threadedsystemmodelsothatanOSkernelisneeded.

PrptothreadProcessModel

Thisisanevent-drivensystemwithmulti-threadedlikedblockingproperty.

Protothreadsareaextremelylightweight,stacklesstypeofthreadsthatprovidesablockingcontextontopofanevent-drivensystem,withouttheoverheadofper-threadstacks.Thepurposeofprotothreadsistoimplementsequentialflowofcontrolwithoutcomplexstatemachinesorfullmulti-threading.ProtothreadsprovidesconditionalblockinginsideCfunctions.

Theadvantageofprotothreadsoverapurelyevent-drivenapproachisthatprotothreadsprovidesasequentialcodestructurethatallowsforblockingfunctions.Inpurelyevent-drivensystems,blockingmustbeimplementedbymanuallybreakingthefunctionintotwopieces-oneforthepieceofcodebeforetheblockingcallandoneforthecodeaftertheblockingcall.Thismakesithardtousecontrolstructuressuchasif()conditionalsandwhile()loops.

Theadvantageofprotothreadsoverordinarythreadsisthataprotothreaddonotrequireaseparatestack.Inmemoryconstrained

Page 23: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

systems,theoverheadofallocatingmultiplestackscanconsumelargeamountsoftheavailablememory.Incontrast,eachprotothreadonlyrequiresbetweentwoandtwelvebytesofstate,dependingonthearchitecture.

Page 24: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

ProtothreadProcessTheprotothreadslibrarywaswrittenbyAdamDunkelsadam@[email protected].

Protothreadsareaextremelylightweight,stacklessthreadsthatprovidesablockingcontextontopofanevent-drivensystem,withouttheoverheadofper-threadstacks.Thepurposeofprotothreadsistoimplementsequentialflowofcontrolwithoutusingcomplexstatemachinesorfullmulti-threading.ProtothreadsprovidesconditionalblockinginsideaCfunction.

Inmemoryconstrainedsystems,suchasdeeplyembeddedsystems,traditionalmulti-threadingmayhaveatoolargememoryoverhead.Intraditionalmulti-threading,eachthreadrequiresitsownstack,thattypicallyisover-provisioned.Thestacksmayuselargepartsoftheavailablememory.

Themainadvantageofprotothreadsoverordinarythreadsisthatprotothreadsareverylightweight:aprotothreaddoesnotrequireitsownstack.Rather,allprotothreadsrunonthesamestackandcontextswitchingisdonebystackrewinding.Thisisadvantageousinmemoryconstrainedsystems,whereastackforathreadmightusealargepartoftheavailablememory.Aprotothreadonlyrequiresonlytwobytesofmemoryperprotothread.Moreover,protothreadsareimplementedinpureCanddonotrequireanymachine-specificassemblercode.

AprotothreadrunswithinasingleCfunctionandcannotspanoverotherfunctions.AprotothreadmaycallnormalCfunctions,butcannotblockinsideacalledfunction.Blockinginsidenestedfunctioncallsisinsteadmadebyspawningaseparateprotothreadforeachpotentiallyblockingfunction.Theadvantageofthisapproachisthatblockingisexplicit:theprogrammerknowsexactlywhichfunctionsthatblockthatwhichfunctionstheneverblocks.

Protothreadsaresimilartoasymmetricco-routines.Themaindifferenceisthatco-routinesusesaseparatestackforeachco-routine,whereasprotothreadsarestackless.ThemostsimilarmechanismtoprotothreadsarePythongenerators.Thesearealsostacklessconstructs,buthavea

Page 25: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

differentpurpose.ProtothreadsprovidesblockingcontextsinsideaCfunction,whereasPythongeneratorsprovidemultipleexitpointsfromageneratorfunction.

Detailreferancestoprotothreadprocessprotothreadprocess

Page 26: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

LocalvariablesNote

Becauseprotothreadsdonotsavethestackcontextacrossablockingcall,localvariablesarenotpreservedwhentheprotothreadblocks.Thismeansthatlocalvariablesshouldbeusedwithutmostcare-ifindoubt,donotuselocalvariablesinsideaprotothread!

Page 27: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

SchedulingAprotothreadisdrivenbyrepeatedcallstothefunctioninwhichtheprotothreadisrunning.Eachtimethefunctioniscalled,theprotothreadwillrununtilitblocksorexits.Thustheschedulingofprotothreadsisdonebytheapplicationthatusesprotothreads.

Page 28: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

ImplementationProtothreadsareimplementedusinglocalcontinuations.Alocalcontinuationrepresentsthecurrentstateofexecutionataparticularplaceintheprogram,butdoesnotprovideanycallhistoryorlocalvariables.Alocalcontinuationcanbesetinaspecificfunctiontocapturethestateofthefunction.Afteralocalcontinuationhasbeensetcanberesumedinordertorestorethestateofthefunctionatthepointwherethelocalcontinuationwasset.

Localcontinuationscanbeimplementedinavarietyofways:

byusingmachinespecificassemblercode.byusingstandardCconstructs.byusingcompilerextensions.

Thefirstwayworksbysavingandrestoringtheprocessorstate,exceptforstackpointers,andrequiresbetween16and32bytesofmemoryperprotothread.Theexactamountofmemoryrequireddependsonthearchitecture.

ThestandardCimplementationrequiresonlytwobytesofstateperprotothreadandutilizestheCswitch()statementinanon-obviouswaythatissimilartoDuff'sdevice.Thisimplementationdoes,however,imposeaslightrestrictiontothecodethatusesprotothreadsinthatthecodecannotuseswitch()statementsitself.

CertaincompilershasCextensionsthatcanbeusedtoimplementprotothreads.GCCsupportslabelpointersthatcanbeusedforthispurpose.Withthisimplementation,protothreadsrequire4bytesofRAMperprotothread.

Generatedby 1.8.9.1

Page 29: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

TableofContents

DMMFeaturesMemoryBlockMemoryPoolUsageConfiguration

RainbowBSManualv0.1.0WrittenbyQWQ([email protected])

Chapter4DynamicMemoryManagment

Dynamicmemorymanagementisanoptionalcomponentformemoryusage.Itoffersbothmemoryblockandmemorypoolmechanism.

Page 30: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

DMMFeaturesmemoryblockoffersfixedsizememorymanagement.memorypooloffersvariablesizememorymanagement.bothmechanismssupportregister,byte-alignment,usagecheckandthread-safety.

Page 31: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

MemoryBlockregistermemoryblock

DependingontheRBS_CFG_APP_MODELconfigurationwhetherornotusingOS,oneoftworegisterinterfacesshouldbeusedbeforeusingmemoryblock.

IfRBS_CFG_APP_MODELisconfiguratedtoRBS_APP_OS,thread-safetyversionshouldbeused.

hDMMRBS_DMM_RegisterBlock(char*pName,void*pDM,USIZESize,USIZEBlockSize,HMUTEXhMutex)

IfRBS_CFG_APP_MODELisconfiguratedtoothers.

hDMMRBS_DMM_RegisterBlock(char*pName,void*pDM,USIZESize,USIZEBlockSize)

allocateandfreeblock

hBLOCKRBS_DMM_AllocZeroBlock(hDMMhDmm)

hBLOCKRBS_DMM_AllocBlock(hDMMhDmm)

BOOLRBS_DMM_FreeBlock(hBLOCKhBlock)

blockusage

void*RBS_DMM_UseHBlock(hBLOCKhBlock)

BOOLRBS_DMM_UnuseHBlock(hBLOCKhBlock)

Page 32: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

MemoryPoolregistermemorypool

DependingontheRBS_CFG_APP_MODELconfigurationwhetherornotusingOS,oneoftworegisterinterfacesshouldbeusedbeforusingmemorypool.

IfRBS_CFG_APP_MODELisconfiguratedtoRBS_APP_OS,thread-safetyversionshouldbeused.

hDMMRBS_DMM_RegisterPool(char*pName,void*pDM,USIZESize,BOOLbAntiFrag,U16HCount,HMUTEXhMutex)

IfRBS_CFG_APP_MODELisconfiguratedtoothers.

hDMMRBS_DMM_RegisterPool(char*pName,void*pDM,USIZESize,BOOLbAntiFrag,U16HCount)

allocateandfreepool

hMEMRBS_DMM_AllocZeroMem(hDMMhDmm,USIZEsize)

hMEMRBS_DMM_AllocMem(hDMMhDmm,USIZEsize)

hMEMRBS_DMM_ReallocMem(hMEMhMem,USIZEsize)

BOOLRBS_DMM_FreeMem(hMEMhMem)

poolusage

void*RBS_DMM_UseHMem(hMEMhMem)

BOOLRBS_DMM_UnuseHMem(hMEMhMem)

USIZERBS_DMM_GetHMemSize(hMEMhMem)

Page 33: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

UsageInanembeddedsystem,therearesomememorytypeswithdifferentsizesuchasinternalSRAMintegratedinmicro-controller,externalSDRAM,SRAM,etc...andthosememorycanbebyte-addressedinthesameaddressspace.Someofthemareusedforstacks,whilesomeusedforglobaldataandsomeusedfordynamicmemoryallocation.Sothespecificusageofthosememoryaredecidedbytheapplication.

UnliketraditionalmemorymanagementlikemallocinClibrary,DMMcanmanagemorethanonecontinuousbyte-addressedmemoryfordynamicmemoryallocationandcanbesensitivetomemoryusage.

Asanexample,amicro-controllerhas8K-bytessizeinternalRAMinandexternal2M-bytesSDRAM.Youwanttouse2K-bytesinternalRAMand1M-bytesexternalSDRAMspacefordynamicmemoryallocation.Firstofall,youjustdefinetwobytearray,oneforthe2KinternalRAMandtheotherforthe1M-bytesexternalSDRAM,andtheusetheregisterinterfacetodefinethetwomemoryspace.Afterregister,youcanallocatememoryfromthembytheDMMhandlereturnedfromregister.

Allocatedmemorywillreturnamemoryhandleandthenyoucanusethememoryhandletouse,notuseorfreetheallocatedmemory.

UsingRBS_DMM_UseHBlock()orRBS_DMM_UseHMem()torefertotheallocatedmemoryspace.

UsingRBS_DMM_UnuseHBlock()orBS_DMM_UnuseHMem()tonotifytheDMMtoendthelastmemoryreferance.

UsingRBS_DMM_FreeBlock()orRBS_DMM_FreeMem()tonotifytheDMMtoreleasethememory.

RBS_DMM_UseHBloc()andBRS_DMM_UnuseHBlock()areusedinpair,whileRBS_DMM_UseHMem()andRBS_DMM_UnuseHMem()areinpair.Thereasonisthateachmemoryhandlehasareferancecounterininternal,andthecounterisincreasedby1perusageanddecreaseby1pernousage.Soifthecounterisnotinitialvalue,itwillnotbereleased

Page 34: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

successfullybyRBS_DMM_FreeBlock()orRBS_DMM_FreeMem().Thisiscalledusagecheck.DevelopersshouldkeepinmindthataftereachreferencetotheallocatedmemorybyRBS_DMM_UseHBlock()orRBS_DMM_UseHMem(),anRBS_DMM_UnuseHBlock()orRBS_DMM_UnuseHMem()shouldbecalledandifhewantstorefertothememoryagain,thenRBS_DMM_UseHBlock()orBS_DMM_UseHMem()shouldbecalledagain.Withusagecheck,developerswillfindmemoryusageconflictsandbugsearlier.Forexample,therearetworunningtasksAandBthatbothusinganallocatedmemory.IftaskAisusingthememorywithoutcallingRBS_DMM_UnuseHBlock()orRBS_DMM_UnuseHMem()andtaskBcallRBS_DMM_FreeBlock()orRBS_DMM_FreeMem(),thenanerrorinformationwillbeprintedbydebugcomponent,tellingthatitcannotreleasememoryhandlebecauseitisusing.

RememberthatusagecheckisonlyeffectiveifRBSdebugcomponentisenabled,otherwiseusagecheckisdisabled.FollowingistheexamplecodeforDMMusage.

1 /*definearray*/

2 U8aInternalRAM[2048]

__attribute__((at(0x20000000)));//2K-bytes

internalRAMstartingfrom0x20000000

3 U8aExternalRAM[1024*1024]

__attribute__((at(0x08011000)));//1M-bytes

externalSDRAMstartingfrom0x08011000

4 /*register*/

5 hDMMhBlockDMM=RBS_DMM_RegisterBlock("Block

DMM",aInternalRAM,sizeof(aInternalRAM),60);//re

gisteramemoryblockwith60bytesperblock.

6 hDMMhPoolDMM=RBS_DMM_RegisterPool("Pool

DMM",aExternalRAM,sizeof(aExternalRAM),FALSE,20

0);//registeramemorypoolwith200handle

available.

7 /*allocate*/

8 hBLOCKhBlock=

RBS_DMM_AllocBlock(hBlockDMM);//allocatea

blockfromhBlockDMM

Page 35: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

9 hMEMhMem=

RBS_DMM_AllocMem(hPoolDMM,200);//allocate200

bytesfromhPoolDMM

10 /*reference*/

11 void*pBlock=

RBS_DMM_UseHBlock(hBlock);//usinghBlock

12 void*pMem=RBS_DMM_UseHMem(hMem);//using

hMem

13 ...//usingmemory

14 RBS_DMM_UnuseHBlock(hBlock);//notusehBlock

15 RBS_DMM_UnuseHMem(hMem);//unusinghMem

16 /*free*/

17 RBS_DMM_FreeBlock(hBlock);//releasehBlock

18 RBS_DMM_FreeMem(hMem);//releasehMem

Page 36: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

ConfigurationRBS_CFG_DMM_ALIGNisdefinedfordefinebyte-alignment.3means8bytes,2means4bytes,1means2bytes,0means1bytes.

Allocatedmemorystartedaddressandsizearebothalignment.SoifRBS_CFG_DMM_ALIGNis2andyouallocated25bytes,thenyouget28bytesactually.

Generatedby 1.8.9.1

Page 37: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

TableofContents

DebugFeaturesDebugUsageHowtoconfiguredebugcomponentHowtoportdebugcomponent

RainbowBSManualv0.1.0WrittenbyQWQ([email protected])

Chapter5Debug

DebugisimportantforsoftwaredevelopmentandRBScontainsausefuldebugcomponent.Detailreferencestodebug

Page 38: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

DebugFeaturesfouroptionaldebuglevels:none,error,warning,logoutputre-targetingthread-safetysupport

Page 39: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

DebugUsageFourtypesdebugmacrosareavailable.

debugstatement

RBS_DEBUG_STA(sta)

RBS_DEBUG_IF(exp,sta)

RBS_DEBUG_ELSIF(sta1,exp,sta2)

RBS_DEBUG_ENDIF(sta)

debugerroroutput

RBS_DEBUG_ERROR(exp,s)

RBS_DEBUG_ERROR_FORMAT(exp,format,...)

debugwarningoutput

RBS_DEBUG_WARN(exp,s)

RBS_DEBUG_WARN_FORMAT(exp,format,...)

debuglogoutput

RBS_DEBUG_LOG(s)

RBS_DEBUG_LOG_FORMAT(format,...)

Page 40: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

HowtoconfiguredebugcomponentTherearetwomacroconfigurationfordebugcomponent.

RBS_CFG_DEBUG_LEVEListheconfigurationfordebuglevel.YoucandefineRBS_CFG_DEBUG_LEVELfromoneofthefouroptionaldebuglevelsmacros.

RBS_DEBUG_LEVEL_NOCHECKdisablealldebugstatementandoutputRBS_DEBUG_LEVEL_ERRORSonlyenabledebugstatementanddebugerroroutputRBS_DEBUG_LEVEL_WARNINGSdebugwarningoutputplusBS_DEBUG_LEVEL_ERRORS

RBS_DEBUG_LEVEL_ALLdebuglogoutputplusBS_DEBUG_LEVEL_WARNINGS

RBS_CFG_DEBUG_BUFSIZEcofigurethedebugbuffersizeinbytes.Defaultsizeis300bytes.Oneoutputstringlengthshouldnotexceeddebugbuffersize.

Page 41: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

HowtoportdebugcomponentDependingtodebuglevelyouconfigureRBS_CFG_DEBUG_LEVEL,differentportingfunctionsareneeded.Andyoucanre-targetingoutputbytheseportingfunctions.

RBS_DEBUG_LEVEL_ERRORSneeds:

voidPort_Printf_Error(constchar*s)fordebugerroroutput

RBS_DEBUG_LEVEL_WARNINGSneeds:

voidPort_Printf_Error(constchar*s)fordebugerroroutputvoidPort_Printf_Warn(constchar*s)fordebugwarningoutput

BS_DEBUG_LEVEL_ALLneeds:

voidPort_Printf_Error(constchar*s)fordebugerroroutputvoidPort_Printf_Warn(constchar*s)fordebugwarningoutputvoidPort_Printf_Log(constchar*s)fordebuglogoutput

IfapplicationmodelRBS_CFG_APP_MODELisconfiguredtoRBS_APP_OS,thenOSlocksuchasmutexorsemaphoreshouldusedforthread-safedebug.

Debugerroroutput(RBS_DEBUG_LEVEL_ERRORS),debugwarningoutput(RBS_DEBUG_LEVEL_WARNINGS)anddebuglog(RBS_DEBUG_LEVEL_ALL)outputusethesamelock.Andthreefollowingportingfunctionsshouldbepresent.

BOOLPort_Init(void)forcreatingdebuglockBOOLPort_GetMutex(HMUTEXhMutex)forlockdebugoutputBOOLPort_FreeMutex(HMUTEXhMutex)forunlockdebugoutput

Generatedby 1.8.9.1

Page 42: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

TableofContents

ConfigurationclassSystemandCPUApplicationmodelDMMDebug

UsingRAutoConfig

RainbowBSManualv0.1.0WrittenbyQWQ([email protected])

Chapter6Configration

RBSconfigurationisdefinedbyfileRainbowBSConf.h.YoucanwriteormodifythisfileorusePCtoolRAutoConfig.exetogeneratethisfile.

Page 43: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

ConfigurationclassSystemandCPU

RBS_CFG_SYS_INFO

defineastringfordescribingtheapplication.

RBS_CFG_TICK_RATE

timertickpersecond.Thevalidvalueshouldbeinrangof1to1000and1000shouldbedividedwithnoremainderbyit.

RBS_CFG_CPU_WORD_SIZE

definitionofCPUwordsize8bits/16bits/32bits.

RBS_CFG_CPU_BYTE_ORDER_L

CPUbyteorder.1meanslittle-endiaand0meansbig-endia.

RBS_CFG_CPU_STACK_DOWN

stackgrowthdirection.1meansgrowingtolowaddressand0meansgrowingtohighaddress.

Page 44: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

ApplicationmodelRBS_CFG_APP_MODEL

oneofthreeapplicationmodelsshouldbechosen.

RBS_APP_NONEtraditionalevent-drivenmodel.RBS_APP_PTPprotothreadevent-drivenmodel.RBS_APP_OSmultitaskmodel.OSkernelneeded.

HMUTEX

typeofmutexdefinedbyOSused.ThishaseffectonlywhenRBS_CFG_APP_MODELisconfiguredtoRBS_APP_OS.

Headfilename

headfileofferedbyOSused.ThishaseffectonlywhenRBS_CFG_APP_MODELisconfiguredtoRBS_APP_OS.

RBS_CFG_PTP_NO_PROCESS_NAME

processname.1meansdisabled,0meansenabled.ThishaseffectonlywhenRBS_CFG_APP_MODELisconfiguredtoRBS_APP_PTP.

RBS_CFG_PTP_PROCESS_STATS

usedtostatisticsforeventsused.1meansenabled,0meansdisabled.ThishaseffectonlywhenRBS_CFG_APP_MODELisconfiguredtoRBS_APP_PTP.

RBS_CFG_PTP_NUMEVENTS

eventcount.ThishaseffectonlywhenRBS_CFG_APP_MODELisconfiguredtoRBS_APP_PTP.

Page 45: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

DMMRBS_CFG_DMM_ALIGN

definethealignmentbytesformemoryaddressandsize.3means8bytes,2means4bytes,1means2bytes,0means1byte.

Page 46: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

DebugRBS_CFG_DEBUG_LEVEL

debugoutputlevel.oneoffourshouldbechosen.

RBS_DEBUG_LEVEL_NOCHECKdisabledebugoutput.norunningtimechecksareperformed.RBS_DEBUG_LEVEL_ERRORSerrorsarerecorded.RBS_DEBUG_LEVEL_WARNINGSerrorsandwarningsarerecorded.RBS_DEBUG_LEVEL_LOGerrors,warningsandlogsarerecorded.

RBS_CFG_DEBUG_BUFSIZE

outputbufferlength.ThishaseffectonlywhenRBS_CFG_DEBUG_LEVELisnotconfiguredtoRBS_DEBUG_LEVEL_NOCHECK.

Page 47: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

UsingRAutoConfigRAutoConfigisin"RainbowBS\RBSTools".

RainbowAutoConfig

Generatedby 1.8.9.1

Page 48: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

TableofContents

PortedonPCPortedonCortex-M

RainbowBSManualv0.1.0WrittenbyQWQ([email protected])

Chapter7PortingandExample

Currently,RBShasbeenportedonPCandARMCortex-MMCU.Alsoitcanbeportedonanyotherarchitecturebyreferencetothat.

Recommendprojectfilearchitectureasfollowing:

FileArchitecture

Page 49: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

PortedonPCRefertotheexamplein"RainbowBS/RBSDemoProjects/X86_VS2008/RBSDemo_VS2008.sln".TherearethreeconfigurationtargetscorrespondingtothethreeRBSapplicationmodelsrespectively.

Page 50: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

PortedonCortex-MRefertotheexamplein"RainbowBS/RBSDemoProjects/STM32F4_MDK/RBSDemo_STM32F4.uvprojx".TherearethreeconfigurationtargetscorrespondingtothethreeRBSapplicationmodelsrespectively.ThestandardoutputisdefinedtouseSWOintheexample.YoucanuseKeil-MDKDebugViewerorJLinkSWOViewer(ifJLinkisusedasadaptor)toview.

OutputinDebugViewer

Page 51: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

OutputinJLinkSWOViewer

Generatedby 1.8.9.1

Page 52: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

RainbowBSManualv0.1.0WrittenbyQWQ([email protected])

Modules

Hereisalistofallmodules:[detaillevel 1 2 ]

RBSconfigration basictypes basicmacros systemreleted CPUinformation memoryoperation conversionreleted dynamicmemorymanagement protothreadprocess Eventtimers debug▼Pt Localcontinuations Protothreadsemaphores

Generatedby 1.8.9.1

Page 53: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

Macros

RainbowBSManualv0.1.0WrittenbyQWQ([email protected])

RBSconfigration

Page 54: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

Macros#define RBS_CFG_SYS_INFO"RainbowSys"#define RBS_CFG_TICK_RATE100#define RBS_CFG_CPU_WORD_SIZE32/*CPUwordsize*/#define RBS_CFG_CPU_BYTE_ORDER_L1/*CPUbyteorder*/

#define RBS_CFG_CPU_STACK_DOWN1/*stackgrowthdirection*/

#define RBS_APP_NONE0#define RBS_APP_PTP1#define RBS_APP_OS2#define RBS_CFG_APP_MODELRBS_APP_PTP#define RBS_CFG_PTP_NO_PROCESS_NAME0#define RBS_CFG_PTP_PROCESS_STATS0#define RBS_CFG_PTP_NUMEVENTS32#define RBS_CFG_DMM_ALIGN2

#define RBS_DEBUG_LEVEL_NOCHECK0/*Norunningtimechecksareperformed*/#define RBS_DEBUG_LEVEL_ERRORS1/*Errorsarerecorded*/

#define RBS_DEBUG_LEVEL_WARNINGS2/*ErrorsandWarningsarerecorded*/

Page 55: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

#define RBS_DEBUG_LEVEL_LOG3/*Errors,Warningsandlogsarerecorded*/

#define RBS_CFG_DEBUG_BUFSIZE300#define RBS_CFG_DEBUG_LEVELRBS_DEBUG_LEVEL_LOG

Page 56: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

DetailedDescription

Generatedby 1.8.9.1

Page 57: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

Typedefs

RainbowBSManualv0.1.0WrittenbyQWQ([email protected])

basictypes

Page 58: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

Typedefstypedefuint8_t BOOL

typedefint8_t I8

typedefuint8_t U8

typedefint16_t I16

typedefuint16_t U16typedefint32_t I32

typedefuint32_t U32typedefint64_t I64

typedefuint64_t U64

typedefsize_t USIZEtypedefptrdiff_t IPTRDIFF

typedefU64 TICK

Page 59: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

DetailedDescription

basictypesdefination.

Generatedby 1.8.9.1

Page 60: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

Macros

RainbowBSManualv0.1.0WrittenbyQWQ([email protected])

basicmacros

Page 61: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

Macros#define FALSE0u#define TRUE1u#define USE_PARA(para)(para=(para))#define MIN(v0,v1)(((v0)>(v1))?(v1):(v0))#define MAX(v0,v1)(((v0)>(v1))?(v0):(v1))#define ABS(v)(((v)>=0)?(v):(-(v)))#define SWAP(a,b)(a=(a)+(b),b=(a)-(b),a=(a)-(b))#define COUNT_OF(a)(sizeof(a)/sizeof(a[0]))#define _STR(a)#a#define STR(a)_STR(a)#define _CONS(a,b)a##b#define CONS(a,b)_CONS(a,b)

#define ALIGN_F(pointer,power2)(((IPTRDIFF)(pointer)+((IPTRDIFF)((power2)-1)))&(~((IPTRDIFF)((power2)-1))))

#define ALIGN_B(pointer,power2)((IPTRDIFF)(pointer)&(~((IPTRDIFF)((power2)-1))))

Page 62: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

DetailedDescription

basicmacrosdefination.

Generatedby 1.8.9.1

Page 63: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

DataStructures|Functions

RainbowBSManualv0.1.0WrittenbyQWQ([email protected])

systemreleted

Page 64: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

DataStructuresstruct tTime Timestructure.More...

Page 65: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

FunctionsBOOL RBS_Init(void) InitializeRainbowBS.More...

Page 66: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

systeminformationconstchar* RBS_GetVersionString(void) GetRainbowBSversionstring.More...constchar* RBS_GetSysInfo(void) Getsystemdescriptionstring.More...

Page 67: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

timereleatedTICK RBS_GetTickCount(void)

Getsystemtick.More...

U64 RBS_GetRunTime(void) Getsystemrunningtime(ms).More...

void RBS_GetLocalTime(tTime*ptTime) Getsystemlocaltime.More...

void RBS_Delay(U32milliseconds) Delaysomemilliseconds.More...#define RBS_TICK_MS(1000u/RBS_CFG_TICK_RATE)

Page 68: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

DetailedDescription

Implementationofsystemreleted.

Page 69: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

FunctionDocumentation

voidRBS_Delay ( U32 milliseconds )

Parameters[in]millisecondsmillisecondcount.

Hereisthecallgraphforthisfunction:

voidRBS_GetLocalTime ( tTime* ptTime )

Parameters[out] ptTime localtimepointer.

SeealsoRBS_GetRunTime()

Hereisthecallgraphforthisfunction:

U64RBS_GetRunTime ( void )

Returnssystemrunningtimeinmillisecond.

SeealsoRBS_GetLocalTime()

Hereisthecallgraphforthisfunction:

Page 70: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

constchar*RBS_GetSysInfo ( void )

Returnssystemdescriptionstring.

SeealsoRBS_GetVersionString()

TICKRBS_GetTickCount ( void )

Returnssystemtick.

Hereisthecallgraphforthisfunction:

Hereisthecallergraphforthisfunction:

constchar*RBS_GetVersionString ( void )

Returnsversionstring.

SeealsoRBS_GetSysInfo()

BOOLRBS_Init ( void )

ReturnvaluesTRUE successfully.

Page 71: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

FALSE failed.

Hereisthecallgraphforthisfunction:

Generatedby 1.8.9.1

Page 72: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

DataFields

RainbowBSManualv0.1.0WrittenbyQWQ([email protected])

tTimeStructReferencesystemreleted

Timestructure.

#include<RainbowBS.h>

CollaborationdiagramfortTime:

Page 73: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

DataFieldsU16 yearU8 month

U8 day

U8 day_of_week

U8 hour

U8 minute

U8 second

U16 milliseconds

Page 74: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

FieldDocumentation

U8day

dayofmonth[1,31]

U8day_of_week

dayofweek[0,6]

U8hour

hour[0,23]

U16milliseconds

milliseconds[0,999]

U8minute

minute[0,59]

U8month

month[1,12]

U8second

Page 75: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

second[0,59]

U16year

year[1601,30827]

Thedocumentationforthisstructwasgeneratedfromthefollowingfile:

RainbowBS.h

Generatedby 1.8.9.1

Page 76: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

Functions

RainbowBSManualv0.1.0WrittenbyQWQ([email protected])

CPUinformation

Page 77: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

FunctionsU8 RBS_GetCPUBits(void)

CPUword-width.More...BOOL RBS_IsCPULittleEndian(void) CheckifCPUislittle-endian.More...BOOL RBS_IsStackGrowDown(void) Checkifstackgrowsdown.More...

Page 78: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

DetailedDescription

InformationaboutCPU.

Page 79: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

FunctionDocumentation

U8RBS_GetCPUBits ( void )

ReturnsCPUword-width(8/16/32/64).

BOOLRBS_IsCPULittleEndian ( void )

ReturnvaluesTRUE little-endian.FALSE big-endian.

BOOLRBS_IsStackGrowDown ( void )

ReturnvaluesTRUE growthdown.FALSE growthup.

Generatedby 1.8.9.1

Page 80: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

Functions

RainbowBSManualv0.1.0WrittenbyQWQ([email protected])

memoryoperation

Page 81: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

Functionsvoid RBS_MemSet8(U8*pDes,U8fill,USIZEnum) Setmemorybybyteunit.More...void RBS_MemSet16(U16*pDes,U16fill,USIZEnum) Setmemorybytwo-bytesunit.More...void RBS_MemSet32(U32*pDes,U32fill,USIZEnum) Setmemorybyfour-bytesunit.More...void RBS_MemCpy8(U8*pDes,constU8*pSrc,USIZEnum) Copymemorybybyteunit.More...U16 RBS_Read16L(constU8**ppData) Reada16-bitsentityinlittle-endian.More...U32 RBS_Read32L(constU8**ppData) Reada32-bitsentityinlittle-endian.More...void RBS_Write16L(U8**ppData,U16data) Writea16-bitsentityinlittle-endian.More...void RBS_Write32L(U8**ppData,U32data) Writea32-bitsentityinlittle-endian.More...U16 RBS_Read16B(constU8**ppData) Reada16-bitsentityinbig-endian.More...U32 RBS_Read32B(constU8**ppData) Reada32-bitsentityinbig-endian.More...void RBS_Write16B(U8**ppData,U16data) Writea16-bitsentityinbig-endian.More...

Page 82: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

void RBS_Write32B(U8**ppData,U32data) Writea32-bitsentityinbig-endian.More...

Page 83: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

DetailedDescription

Memorysetandcopyoperation.

Page 84: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

FunctionDocumentation

voidRBS_MemCpy8 ( U8* pDes,constU8* pSrc,USIZE num)

Parameters[out] pDes destinationpointer.[in] pSrc sourcepointer.[in] num totalunits.

Hereisthecallergraphforthisfunction:

voidRBS_MemSet16 ( U16* pDes,U16 fill,USIZE num)

Parameters[out] pDes destinationpointer(two-bytesalignment).[in] fill two-bytesfilled.[in] num totalunits.

voidRBS_MemSet32 ( U32* pDes,U32 fill,USIZE num)

Page 85: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

Parameters[out] pDes destinationpointer(four-bytesalignment).[in] fill four-bytesfilled.[in] num totalunits.

voidRBS_MemSet8 ( U8* pDes,U8 fill,USIZE num)

Parameters[out] pDes destinationpointer.[in] fill bytefilled.[in] num totalunits.

Hereisthecallergraphforthisfunction:

U16RBS_Read16B ( constU8** ppData )

Parameters[in,out] ppData datapointer,added2bytesaftercalling.

Returnsdataentity

U16RBS_Read16L ( constU8** ppData )

Parameters[in,out] ppData datapointer,added2bytesaftercalling.

Page 86: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

Returnsdataentity

U32RBS_Read32B ( constU8** ppData )

Parameters[in,out] ppData datapointer,added4bytesaftercalling.

Returnsdataentity

U32RBS_Read32L ( constU8** ppData )

Parameters[in,out] ppData datapointer,added4bytesaftercalling.

Returnsdataentity

voidRBS_Write16B ( U8** ppData,U16 data)

Parameters[in,out] ppData datapointer,added2bytesaftercalling.[in] data datatobewtitten.

voidRBS_Write16L ( U8** ppData,U16 data)

Parameters[in,out] ppData datapointer,added2bytesaftercalling.

Page 87: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

[in] data datatobewtitten.

voidRBS_Write32B ( U8** ppData,U32 data)

Parameters[in,out] ppData datapointer,added4bytesaftercalling.[in] data datatobewtitten.

voidRBS_Write32L ( U8** ppData,U32 data)

Parameters[in,out] ppData datapointer,added4bytesaftercalling.[in] data datatobewtitten.

Generatedby 1.8.9.1

Page 88: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

RainbowBSManualv0.1.0WrittenbyQWQ([email protected])

conversionreleted

Page 89: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

convertdigittostringenum ePOW{SHEX,SBINARY,SDECIMAL} Specifichex,binaryordecimal.More...

U8 RBS_Number2String(U32value,ePOWePow,U8length,char*pText)

ConvertunsigneddigittoASCIIstring.More...

Page 90: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

trigonometricreletedint RBS_sin(intangle)

Calculatesine.More...

int RBS_cos(intangle) Calculatecosine.More...

int RBS_tan(intangle) Calculatetangent.More...

int RBS_ctan(intangle) Calculatecotangent.More...#define ANG_45DEG1024#define ANG_90DEG(2*ANG_45DEG)#define ANG_135DEG(3*ANG_45DEG)#define ANG_180DEG(4*ANG_45DEG)#define ANG_225DEG(5*ANG_45DEG)#define ANG_270DEG(6*ANG_45DEG)#define ANG_315DEG(7*ANG_45DEG)#define ANG_360DEG(8*ANG_45DEG)

Page 91: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

DetailedDescription

EnumerationTypeDocumentation

enumePOW

Enumerator

SHEX hexSBINARY binarySDECIMAL decimal

Page 92: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

FunctionDocumentation

intRBS_cos ( int angle )

Thisfunctioncalculatescosinewithoutusingfloat-pointnumbers.Ituseaconstanttabletolookupfortheappropriatevalue.

Parameters[in] angle angle=degrees*ANG_45DEG/45,degrees=angle*45/ANG_45DEG.

Returnscos(degrees)*1024.

intRBS_ctan ( int angle )

Thisfunctioncalculatescotangentwithoutusingfloat-pointnumbers.Ituseaconstanttabletolookupfortheappropriatevalue.

Parameters[in] angle angle=degrees*ANG_45DEG/45,degrees=angle*45/ANG_45DEG.

Returnscotan(degrees)*1024.

U8RBS_Number2String ( U32 value,ePOW ePow,U8 length,char* pText)

Parameters[in] value unsigneddigit.

Page 93: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

[in] ePow choosehex,binaryordecimal.[in] lengthMax.bitsfromlowestbit.IfLenis0,choosing

Min.charactersautomatically.[out] pText outputstringbuffer.

Returnscharacternumber.

SeealsoePOW

intRBS_sin ( int angle )

Thisfunctioncalculatessinewithoutusingfloat-pointnumbers.Ituseaconstanttabletolookupfortheapproximatevalue.

Parameters[in] angle angle=degrees*ANG_45DEG/45,degrees=angle*45/ANG_45DEG.

Returnssin(degrees)*1024.

Example:

1 //calculatesineof30degrees,thereturnvalueis

511which

2 //isapproximatelyequaltosin30*1024whichis512.

3 intvalue=RBS_sin(30*ANG_45DEG/45);

intRBS_tan ( int angle )

Thisfunctioncalculatestangentwithoutusingfloat-pointnumbers.Ituseaconstanttabletolookupfortheappropriatevalue.

Parameters[in] angle angle=degrees*ANG_45DEG/45,degrees=angle*45/ANG_45DEG.

Page 94: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

Returnstan(degrees)*1024.

Generatedby 1.8.9.1

Page 95: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

Macros|Typedefs|Functions

RainbowBSManualv0.1.0WrittenbyQWQ([email protected])

dynamicmemorymanagement

Page 96: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

Macros#define HDMM_NULLNULL#define HBLOCK_NULLNULL#define HMEM_NULLNULL

Page 97: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

Typedefstypedefvoid* hDMMtypedefvoid* hBLOCKtypedefvoid* hMEM

Page 98: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

Functions

hDMM RBS_DMM_RegisterBlock(char*pName,void*pDM,USIZEsize,USIZEblock_size,HMUTEXhMutex)

Registerthememoryareaasadynamicblockmemoryarea.More...

hBLOCK RBS_DMM_AllocZeroBlock(hDMMhDmm) Allocateafreeblockwithzeroinitializationfromthedynamic

blockmemoryarea.More...hBLOCK RBS_DMM_AllocBlock(hDMMhDmm) Allocateafreeblockfromthedynamicblockmemoryarea.

More...

BOOL RBS_DMM_FreeBlock(hBLOCKhBlock) Freetheallocatedblock.More...

void* RBS_DMM_UseHBlock(hBLOCKhBlock) Gettheallocatedblockpointer.More...

BOOL RBS_DMM_UnuseHBlock(hBLOCKhBlock) Unusetheallocatedblockarea.More...

hDMM RBS_DMM_RegisterPool(char*pName,void*pDM,USIZEsize,BOOLbAntiFrag,U16handle_count,HMUTEXhMutex)

Registerthememoryareaasadynamicpoolmemoryarea.More...

hMEM RBS_DMM_AllocZeroMem(hDMMhDmm,USIZEsize)

Allocateafreememorywithzeroinitializationfromthedynamicmemoryarea.More...

hMEM RBS_DMM_AllocMem(hDMMhDmm,USIZEsize)

Allocateafreememoryfromthedynamicmemoryarea.More...

Page 99: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

hMEM RBS_DMM_ReallocMem(hMEMhMem,USIZEsize)

Reallocateafreememoryfromthesamedynamicmemoryarea.More...

BOOL RBS_DMM_FreeMem(hMEMhMem)

Freetheallocatedmemory.More...

void* RBS_DMM_UseHMem(hMEMhMem) Gettheallocatedmemorypointer.More...

BOOL RBS_DMM_UnuseHMem(hMEMhMem) Unusetheallocatedmemoryarea.More...

USIZE RBS_DMM_GetHMemSize(hMEMhMem) Gettheallocatedmemorysize.More...

Page 100: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

DetailedDescription

Dynamicmemorymanagementforbothmemorypollandblock.

Page 101: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

FunctionDocumentation

hBLOCKRBS_DMM_AllocBlock ( hDMM hDmm )

Parameters[in] hDmm handleofdynamicblockmemoryarea.

ReturnvaluesHBLOCK_NULL failed.others handleofdynamicmemoryarea.

Hereisthecallgraphforthisfunction:

Hereisthecallergraphforthisfunction:

hMEMRBS_DMM_AllocMem ( hDMM hDmm,USIZE size)

Parameters[in] hDmm handleofdynamicmemoryarea.[in] size memoryareabytes.

ReturnvaluesHMEM_NULL failed.others handleofdynamicmemoryarea.

Page 102: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

Hereisthecallgraphforthisfunction:

Hereisthecallergraphforthisfunction:

hBLOCKRBS_DMM_AllocZeroBlock ( hDMM hDmm )

Parameters[in] hDmm handleofdynamicblockmemoryarea.

ReturnvaluesHBLOCK_NULL failed.others handleofdynamicmemoryarea.

Hereisthecallgraphforthisfunction:

hMEMRBS_DMM_AllocZeroMem ( hDMM hDmm,USIZE size)

Parameters[in] hDmm handleofdynamicmemoryarea.[in] size memoryareabytes.

Page 103: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

ReturnvaluesHMEM_NULL failed.others handleofdynamicmemoryarea.

Hereisthecallgraphforthisfunction:

BOOLRBS_DMM_FreeBlock ( hBLOCK hBlock )

Parameters[in] hBlock handleofaallocatedblock.

ReturnvaluesTRUE successful.FALSE failed.

Hereisthecallgraphforthisfunction:

BOOLRBS_DMM_FreeMem ( hMEM hMem )

Parameters[in] hMem handleofaallocatedmemory.

Returnvalues

Page 104: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

TRUE successful.FALSE failed.

Hereisthecallgraphforthisfunction:

USIZERBS_DMM_GetHMemSize ( hMEM hMem )

Parameters[in] hMem handleoftheallocatedmemory.

Returnsmemoryareasize.

Hereisthecallgraphforthisfunction:

hMEMRBS_DMM_ReallocMem ( hMEM hMem,USIZE size)

Parameters[in] hMem handleofanallocatedmemory.[in] size memoryareabytes.

ReturnvaluesHMEM_NULL failed.others handleofdynamicmemoryarea.

Hereisthecallgraphforthisfunction:

Page 105: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

hDMMRBS_DMM_RegisterBlock ( char* pName,void* pDM,USIZE size,USIZE block_size,HMUTEX hMutex)

Parameters[in] pName blockmemoryname.[in] pDM pointertotheblockmemoryarea.[in] size blockmemoryareasize(bytes).[in] block_size eachblocksize.[in] hMutex memoryblockmutexforthread-safe.IfNULL,no

thread-safesupport.

ReturnvaluesHDMM_NULL failed.other handleofdynamicblockmemoryarea.

Hereisthecallgraphforthisfunction:

Hereisthecallergraphforthisfunction:

Page 106: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

hDMMRBS_DMM_RegisterPool ( char* pName,void* pDM,USIZE size,BOOL bAntiFrag,U16 handle_count,HMUTEX hMutex)

Parameters[in] pName memorypoolname.[in] pDM pointertothememoryarea.[in] size memoryareasize(bytes).[in] bAntiFrag enabledefragmentation.[in] handle_count countofmemoryhandles.[in] hMutex memorypoolmutexforthread-safety.If

NULL,nothread-safesupport.

ReturnvaluesNot HDMM_NULLsuccessful.HDMM_NULL failed.

Hereisthecallgraphforthisfunction:

Hereisthecallergraphforthisfunction:

BOOLRBS_DMM_UnuseHBlock ( hBLOCK hBlock )

Parameters[in] hBlock handleofaallocatedblock.

Page 107: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

Returnsblockareapointer.

SeealsoRBS_DMM_UseHBlock()

NoteusedinpairwithRBS_DMM_UseHBlock()

Hereisthecallgraphforthisfunction:

Hereisthecallergraphforthisfunction:

BOOLRBS_DMM_UnuseHMem ( hMEM hMem )

Parameters[in] hMem handleofaallocatedmemory.

Returnsmemoryareapointer.

SeealsoRBS_DMM_UseHMem()

NoteusedinpairwithRBS_DMM_UseHMem()

Hereisthecallgraphforthisfunction:

Hereisthecallergraphforthisfunction:

Page 108: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

void*RBS_DMM_UseHBlock ( hBLOCK hBlock )

Parameters[in] hBlock handleofaallocatedblock.

Returnsblockareapointer.

SeealsoRBS_DMM_UnuseHBlock()

NoteusedinpairwithRBS_DMM_UnuseHBlock()

Hereisthecallgraphforthisfunction:

Hereisthecallergraphforthisfunction:

void*RBS_DMM_UseHMem ( hMEM hMem )

Parameters[in] hMem handleofaallocatedmemory.

Returnsmemoryareapointer.

SeealsoRBS_DMM_UnuseHMem()

Page 109: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

NoteusedinpairwithRBS_DMM_UnuseHMem()

Hereisthecallgraphforthisfunction:

Hereisthecallergraphforthisfunction:

Generatedby 1.8.9.1

Page 110: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

DataStructures|Macros|Typedefs

RainbowBSManualv0.1.0WrittenbyQWQ([email protected])

protothreadprocess

Page 111: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

DataStructuresstruct process_struct Processstructure(oneprocessconsistsoneprotothread).

More...

Page 112: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

Macros#define PROCESS_NONENULL#define PROCESS_BROADCASTNULL

Page 113: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

TypedefstypedefU8 process_event_t

typedefvoid* process_data_t

typedefstructprocess_struct tPROCESS Processstructure(oneprocessconsists

oneprotothread).More...

Page 114: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

predefinedeventtype#define PROCESS_EVENT_NONE0x80#define PROCESS_EVENT_INIT0x81#define PROCESS_EVENT_POLL0x82#define PROCESS_EVENT_EXIT0x83#define PROCESS_EVENT_SERVICE_REMOVED0x84#define PROCESS_EVENT_CONTINUE0x85#define PROCESS_EVENT_MSG0x86#define PROCESS_EVENT_EXITED0x87#define PROCESS_EVENT_TIMER0x88#define PROCESS_EVENT_COM0x89#define PROCESS_EVENT_MAX0x8a

Page 115: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

processdeclarationanddefinition#define PROCESS_THREAD(name,ev,data) Definethebodyofaprocess.More...#define PROCESS_NAME(name)externtPROCESSname Declarethenameofaprocess.More...#define PROCESS(name,strname) Defineaprocess.More...

Page 116: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

semaphoredeclarationanddefinition#define SEM_NAME(name)externstructpt_semsem_##name Declarethenameofasemaphore.More...#define SEM(name,count) Defineasemaphore.More...

Page 117: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

processprotothreadfunctions#define PROCESS_BEGIN() Definethebeginningofaprocess.More...#define PROCESS_END() Definetheendofaprocess.More...#define PROCESS_WAIT_EVENT() Waitforaneventtobepostedtotheprocess.More...#define PROCESS_WAIT_EVENT_UNTIL(c) Waitforaneventtobepostedtotheprocess,withanextra

condition.More...#define PROCESS_YIELD() Yieldthecurrentlyrunningprocess.#define PROCESS_YIELD_UNTIL(c) Yieldthecurrentlyrunningprocessuntilaconditionoccurs.

More...#define PROCESS_WAIT_UNTIL(c) Waitforaconditiontooccur.More...#define PROCESS_WAIT_WHILE(c) Waitforaconditionnotoccur.More...#define PROCESS_EXIT() Exitthecurrentlyrunningprocess.#define PROCESS_PT_SPAWN(pt,thread) Spawnaprotothreadfromtheprocess.More...#define PROCESS_PAUSE()

Page 118: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

Yieldtheprocessforashortwhile.More...#define PROCESS_WAIT_SEM(name)#define PROCESS_SIGNAL_SEM(name)

Page 119: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

pollandexithandlers

#define PROCESS_POLLHANDLER(handler)if(ev==PROCESS_EVENT_POLL){handler;} Specifyanactionwhenaprocessispolled.More...

#define PROCESS_EXITHANDLER(handler)if(ev==PROCESS_EVENT_EXIT){handler;} Specifyanactionwhenaprocessexits.More...

Page 120: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

processfunctionscalledfromapplicationprogramstPROCESS* process_current

BOOL process_start(tPROCESS*ptProcess,process_data_targ) Startaprocess.More...

BOOL process_post(tPROCESS*ptProcess,process_event_tev,void*data)

Postanasynchronouseventtooneorallprocesses.More...

void process_send(tPROCESS*ptProcess,process_event_tev,void*data) Sendasynchronouseventtoaprocess.More...

void process_exit(tPROCESS*ptProcess) Causeaprocesstoexit.More...process_event_t process_alloc_event(void) Allocateaglobaleventnumber.More...

#define PROCESS_CURRENT()process_current Getapointertothecurrentlyrunningprocess.More...

#definePROCESS_CONTEXT_BEGIN(ptProcess){tPROCESS*tmp_current=PROCESS_CURRENT();process_current=ptProcess

Switchcontexttoanotherprocess.More...

#define PROCESS_CONTEXT_END(ptProcess)process_current=tmp_current;} Endacontextswitch.More...

Page 121: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

processfunctionscalledfromdevicedrivers.BOOL process_poll(tPROCESS*ptProcess) Requestaprocesstobepolled.More...

Page 122: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

functionscalledbythesystemandboot-upcodeU16 process_run(void)

Runthesystemonce-callpollhandlersandprocessoneevent.More...

BOOL process_is_running(tPROCESS*ptProcess) Checkifaprocessisrunning.More...

U16 process_nevents(void) Numberofeventswaitingtobeprocessed.More...

Page 123: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

DetailedDescription

Aprocessinconsistsofasingleprotothread.

Page 124: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

MacroDefinitionDocumentation

#definePROCESS ( name, strname)

Thismacrodefinesaprocess.Theprocesshastwonames:thevariableoftheprocessstructure,whichisusedbytheCprogram,andahumanreadablestringname,whichisusedwhendebugging.AconfigurationoptionallowsremovalofthereadablenametosaveRAM.

Parameters[in] name Thevariablenameoftheprocessstructure.[in] strname Thestringrepresentationoftheprocess'name.

Notedefinitionmustbeglobal.

#definePROCESS_BEGIN ( )

Thismacrodefinesthebeginningofaprocess,andmustalwaysappearinaPROCESS_THREAD()definition.ThePROCESS_END()macromustcomeattheendoftheprocess.

#definePROCESS_CONTEXT_BEGIN ( ptProcess )

{tPROCESS*tmp_current=PROCESS_CURRENT();process_current=ptProcess

Thisfunctionswitchcontexttothespecifiedprocessandexecutesthecodeasifrunbythatprocess.Typicaluseofthisfunctionistoswitchcontextinservices,calledbyotherprocesses.EachPROCESS_CONTEXT_BEGIN()mustbefollowedbythe

Page 125: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

PROCESS_CONTEXT_END()macrotoendthecontextswitch.

Parameters[in] ptProcess Theprocesstouseascontext

SeealsoPROCESS_CONTEXT_END()PROCESS_CURRENT()

Example:

1 PROCESS_CONTEXT_BEGIN(&test_process);

2 etimer_set(&timer,CLOCK_SECOND);

3 PROCESS_CONTEXT_END(&test_process);

#definePROCESS_CONTEXT_END ( ptProcess )

process_current=tmp_current;}

Thisfunctionendsacontextswitchandchangesbacktothepreviousprocess.

Parameters[in] ptProcess Theprocessusedinthecontextswitch

SeealsoPROCESS_CONTEXT_START()

#definePROCESS_CURRENT ( ) process_current

Thismacrogetapointertothecurrentlyrunningprocess.Typically,thismacroisusedtopostaneventtothecurrentprocesswithprocess_post().

#definePROCESS_END ( )

Thismacrodefinestheendofaprocess.Itmustappearina

Page 126: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

PROCESS_THREAD()definitionandmustalwaysbeincluded.TheprocessexitswhenthePROCESS_END()macroisreached.

#definePROCESS_EXITHANDLER ( handler )

if(ev==PROCESS_EVENT_EXIT){handler;}

NoteThisdeclarationmustcomeimmediatelybeforethePROCESS_BEGIN()macro.

Parametershandler Theactiontobeperformed.

#definePROCESS_NAME ( name ) externtPROCESSname

ThismacroistypicallyusedinheaderfilestodeclarethenameofaprocessthatisimplementedintheCfile.

#definePROCESS_PAUSE ( )

Thismacroyieldsthecurrentlyrunningprocessforashortwhile,thuslettingotherprocessesrunbeforetheprocesscontinues.

#definePROCESS_POLLHANDLER ( handler )

if(ev==PROCESS_EVENT_POLL){handler;}

NoteThisdeclarationmustcomeimmediatelybeforethePROCESS_BEGIN()macro.

Parametershandler Theactiontobeperformed.

Page 127: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

#definePROCESS_PT_SPAWN ( pt, thread)

Parameterspt[inout] Theprotothreadstate(structpt)forthenew

protothreadthread[in] Thecalltotheprotothreadfunction.

SeealsoPT_SPAWN()

#definePROCESS_SIGNAL_SEM ( name )

Signalasemaphore

Thismacrocarriesoutthe"signal"operationonthesemaphore.

Parameters[in] name semaphorename

NoteIt'stheapplication'sresponsibilitytonotifythewaitingprocessifsemaphoreisavilable.

SeealsoPROCESS_WAIT_SEM()

#definePROCESS_THREAD ( name, ev, data)

Thismacroisusedtodefinethebody(protothread)ofaprocess.The

Page 128: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

processiscalledwheneveraneventoccursinthesystem,AprocessalwaysstartwiththePROCESS_BEGIN()macroandendwiththePROCESS_END()macro.

#definePROCESS_WAIT_EVENT ( )

Thismacroblocksthecurrentlyrunningprocessuntiltheprocessreceivesanevent.

#definePROCESS_WAIT_EVENT_UNTIL ( c )

ThismacroissimilartoPROCESS_WAIT_EVENT()inthatitblocksthecurrentlyrunningprocessuntiltheprocessreceivesanevent.ButPROCESS_WAIT_EVENT_UNTIL()takesanextraconditionwhichmustbetruefortheprocesstocontinue.

Parameters[in] c Theconditionthatmustbetruefortheprocessto

continue.

SeealsoPT_WAIT_UNTIL()

#definePROCESS_WAIT_SEM ( name )

Waitforasemaphore

Thismacrocarriesoutthe"wait"operationonthesemaphore.

Parameters[in] name semaphorename

NoteIt'stheapplication'sresponsibilitytonotifythewaitingprocessifsemaphoreisavilable.

Page 129: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

SeealsoPROCESS_SIGNAL_SEM()

#definePROCESS_WAIT_UNTIL ( c )

Thismacrodoesnotguaranteethattheprocessyields,andshouldthereforebeusedwithcare.Inmostcases,PROCESS_WAIT_EVENT(),PROCESS_WAIT_EVENT_UNTIL(),PROCESS_YIELD()orPROCESS_YIELD_UNTIL()shouldbeusedinstead.

Parameters[in] c Theconditionthatmustbetruefortheprocessto

continue

#definePROCESS_WAIT_WHILE ( c )

Thismacrodoesnotguaranteethattheprocessyields,andshouldthereforebeusedwithcare.Inmostcases,PROCESS_WAIT_EVENT(),PROCESS_WAIT_EVENT_UNTIL(),PROCESS_YIELD()orPROCESS_YIELD_UNTIL()shouldbeusedinstead.

Parameters[in] c Theconditionthatmustbefalsefortheprocessto

continue.

#definePROCESS_YIELD_UNTIL ( c )

ThismacroisdifferentfromPROCESS_WAIT_UNTIL()inthatPROCESS_YIELD_UNTIL()isguaranteedtoalwaysyieldatleastonce.ThisensuresthattheprocessdoesnotendupinaninfiniteloopandmonopolizingtheCPU.

Parameters

Page 130: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

[in] c Theconditiontowaitfor.

#defineSEM ( name, count)

Parametersname Thevariablenameofthesemaphorestructure.count Thecountvalueofthesemaphore.

Notedefinitionmustbeglobal.

#defineSEM_NAME ( name ) externstructpt_semsem_##name

ThismacroistypicallyusedinheaderfilestodeclarethenameofasemaphorethatisimplementedintheCfile.

Page 131: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

TypedefDocumentation

typedefstructprocess_structtPROCESS

Noteapplicationcodeshouldnotchangeanymemberoftheprocessstructurefortheyaremaintainedbysysteminside.

Page 132: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

FunctionDocumentation

process_event_tprocess_alloc_event ( void )

eventnumbersabove128areglobalandmaybepostedfromoneprocesstoanother.Thisfunctionallocatesonesucheventnumber.

NoteTherecurrentlyisnowaytodeallocateanallocatedeventnumber.

ReturnsTheallocatedeventnumber

voidprocess_exit ( tPROCESS* ptProcess )

Thisfunctioncausesaprocesstoexit.Theprocesscaneitherbethecurrentlyexecutingprocess,oranotherprocessthatiscurrentlyrunning.

Parameters[in,out] ptProcess Theprocessthatistobeexited

SeealsoPROCESS_CURRENT()

BOOLprocess_is_running ( tPROCESS* ptProcess )

Thisfunctionchecksifaspecificprocessisrunning.Aprocesscanbeonrunningstateaftercallingprocess_start()normally.

Parameters[in] ptProcess Theprocesspointer.

Page 133: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

ReturnvaluesTRUE iftheprocessisrunning.FALSE iftheprocessisnotrunning.

Hereisthecallergraphforthisfunction:

U16process_nevents ( void )

ReturnsNumberofeventsthatarecurrentlywaitingtobeprocessed.

BOOLprocess_poll ( tPROCESS* ptProcess )

Thisfunctiontypicallyiscalledfromaninterrupthandlertocauseaprocesstobepolled.

Parameters[in,out] ptProcess Apointertotheprocess'processstructure.

ReturnvaluesTRUE pollsuccessfully.FALSE iftheprocessisnotrunning.

Hereisthecallgraphforthisfunction:

Hereisthecallergraphforthisfunction:

BOOLprocess_post ( tPROCESS* ptProcess,process_event_t ev,void* data

Page 134: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

)

Thisfunctionpostsanasynchronouseventtooneorallprocesses.Thehandingoftheeventisdeferreduntilthetargetprocessisscheduledbythekernel.Aneventcanbebroadcasttoallprocesses,inwhichcaseallprocessesinthesystemwillbescheduledtohandletheevent.

Parameters[in,out] ptProcess Theprocesstowhichtheeventshouldbe

posted,orPROCESS_BROADCASTiftheeventshouldbepostedtoallprocesses.

[in] ev Theeventtobeposted.[in,out] data Theauxiliarydatatobesentwiththeevent

ReturnvaluesTRUE Theeventcouldbeposted.FALSE Theeventqueuewasfullandtheeventcouldnotbe

posted.

Seealsoprocess_send()

U16process_run ( void )

Thisfunctionshouldbecalledrepeatedlyfromthemain()programtoactuallyrunthesystem.Itcallsthenecessarypollhandlers,andprocessesoneevent.ThefunctionreturnsthenumberofeventsthatarewaitingintheeventqueuesothatthecallermaychoosetoputtheCPUtosleepwhentherearenopendingevents.

Exampleabouthowtouseprotothreadprocessmodelforevent-drivensystem:

1 intmain(void){

2 RBS_Init();//RBSinitialization

3 process_start();//startprocess

Page 135: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

4 ...

5 while(1){

6 do{

7 ...//dosomeoptionalusercode

8 }while(process_run()>0);

9 sleep();//gotosleep

10 }

11 }

ReturnsThenumberofeventsthatarecurrentlywaitingtobeprocessed.

voidprocess_send ( tPROCESS* ptProcess,process_event_t ev,void* data)

Thisfunctionsendsasynchronouseventtooneprocesses.Onoppositeofprocess_post(),thehandingoftheeventiscompletedimmediatelyaftercalling.

Parameters[in,out] ptProcess Apointertotheprocess'processstructure.[in] ev Theeventtobeposted.[in,out] data Apointertoadditionaldatathatisposted

togetherwiththeevent.

Seealsoprocess_post()

Hereisthecallergraphforthisfunction:

BOOLprocess_start ( tPROCESS* ptProcess,process_data_t arg

Page 136: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

)

Parameters[in,out] ptProcess Apointertoaprocessstructure.[in] arg Anargumentpointerthatcanbepassedto

thenewprocess

ReturnvaluesTRUE successful.FALSE Trytostartaprocessthatisalreadyrunning.

Hereisthecallgraphforthisfunction:

Hereisthecallergraphforthisfunction:

Generatedby 1.8.9.1

Page 137: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

PublicMemberFunctions|DataFields

RainbowBSManualv0.1.0WrittenbyQWQ([email protected])

process_structStructReferenceprotothreadprocess

Processstructure(oneprocessconsistsoneprotothread).More...

#include<RainbowBS.h>

Collaborationdiagramforprocess_struct:

Page 138: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

PublicMemberFunctions PT_THREAD((*thread)(structpt*,process_event_t,process_data_t))

Page 139: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

DataFieldsstructprocess_struct* next

constchar* name

structpt pt

U8 state

BOOL needspoll

Page 140: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

DetailedDescription

Noteapplicationcodeshouldnotchangeanymemberoftheprocessstructurefortheyaremaintainedbysysteminside.

Page 141: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

FieldDocumentation

constchar*name

processnamestring

BOOLneedspoll

indicateifaprocesshashighprivilegetobecalled,

Seealsoprocess_poll()

structprocess_struct*next

pointertothenextprocess,allprocessesareinaprocesslist

U8state

indicateprocessstate

Thedocumentationforthisstructwasgeneratedfromthefollowingfile:

RainbowBS.h

Generatedby 1.8.9.1

Page 142: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

DataStructures|Typedefs

RainbowBSManualv0.1.0WrittenbyQWQ([email protected])

Eventtimers

Page 143: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

DataStructuresstruct etime_struct Eventtimerstructure.More...

Page 144: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

Typedefstypedefstructetime_struct tETIME Eventtimerstructure.More...

Page 145: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

etimerfunctionscalledfromapplicationprogramsvoid etimer_set(tETIME*ptEtime,TICKinterval)

Setaneventtimer.More...

void etimer_reset(tETIME*ptEtime) Resetaneventtimerwiththesameintervalaswaspreviously

set.More...

void etimer_restart(tETIME*ptEtime) Restartaneventtimerfromthecurrentpointintime.More...

void etimer_adjust(tETIME*ptEtime,inttimediff) Adjusttheexpirationtimeforaneventtimer.More...TICK etimer_expiration_time(tETIME*ptEtime) Gettheexpirationtimefortheeventtimer.More...TICK etimer_start_time(tETIME*ptEtime) Getthestarttimefortheeventtimer.More...BOOL etimer_expired(tETIME*ptEtime) Checkifaneventtimerhasexpired.More...

void etimer_stop(tETIME*ptEtime) Stopapendingeventtimer.More...

Page 146: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

etimerfunctionscalledfromtimerinterrupts,bythesystem

void etimer_request_poll(void) Maketheeventtimerawarethattheclockhaschanged.More...BOOL etimer_pending(void) Checkifthereareanynon-expiredeventtimers.More...

Page 147: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

DetailedDescription

Eventtimersprovidesawaytogeneratetimedevents.Aneventtimerwillpostaneventtotheprocessthatsetthetimerwhentheeventtimerexpires.

Aneventtimerisdeclaredasastructetimerandallaccesstotheeventtimerismadebyapointertothedeclaredeventtimer.

Page 148: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

TypedefDocumentation

typedefstructetime_structtETIME

Thisstructureisusedfordeclaringatimer.Thetimermustbesetwithetimer_set()beforeitcanbeused.

Page 149: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

FunctionDocumentation

voidetimer_adjust ( tETIME* ptEtime,int timediff)

Thisfunctionisusedtoadjustthetimetheeventtimerwillexpire.Itcanbeusedtosynchronizeperiodictimerswithouttheneedtorestartthetimerorchangethetimerinterval.

Parameters[in,out] ptEtime Apointertotheeventtimer.[in] timediff Thetimedifferencetoadjusttheexpiration

timewith.

NoteThisfunctionshouldonlybeusedforsmalladjustments.Forlargeadjustmentsuseetimer_set()instead.Aperiodictimerwilldriftunlesstheetimer_reset()functionisused.

Seealsoetimer_set()etimer_reset()

TICKetimer_expiration_time ( tETIME* ptEtime )

Thisfunctionreturnstheexpirationtimeforaneventtimer.

Parameters[in,out] ptEtime Apointertotheeventtimer.

Returns

Page 150: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

Theexpirationtimefortheeventtimer.

BOOLetimer_expired ( tETIME* ptEtime )

Thisfunctiontestsifaneventtimerhasexpiredandreturnstrueorfalsedependingonitsstatus.

Parameters[in] ptEtime Apointertotheeventtimer.

ReturnvaluesTRUE ifthetimerhasexpired.FALSE ifthetimerhasnotexpired.

BOOLetimer_pending ( void )

Thisfunctionchecksifthereareanyactiveeventtimersthathavenotexpired.

ReturnvaluesTRUE ifthereareactiveeventtimers.FALSE iftherearenoactivetimers.

voidetimer_request_poll ( void )

Thisfunctionisusedtoinformtheeventtimermodulethatthesystemclockhasbeenupdated.Typically,thisfunctionwouldbecalledfromthetimerinterrupthandlerwhentheclockhasticked.

Hereisthecallgraphforthisfunction:

voidetimer_reset ( tETIME* ptEtime )

Page 151: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

Thisfunctionresetstheeventtimerwiththesameintervalthatwasgiventotheeventtimerwiththeetimer_set()function.Thestartpointoftheintervalistheexacttimethattheeventtimerlastexpired.Therefore,thisfunctionwillcausethetimertobestableovertime,unliketheetimer_restart()function.

Parameters[in,out] ptEtime Apointertotheeventtimer.

Seealsoetimer_restart()

voidetimer_restart ( tETIME* ptEtime )

Thisfunctionrestartstheeventtimerwiththesameintervalthatwasgiventotheetimer_set()function.Theeventtimerwillstartatthecurrenttime.

Parameters[in,out] ptEtime Apointertotheeventtimer.

NoteAperiodictimerwilldriftifthisfunctionisusedtoresetit.Forperiodictimers,usetheetimer_reset()functioninstead.

Seealsoetimer_reset()

Hereisthecallgraphforthisfunction:

voidetimer_set ( tETIME* ptEtime,TICK interval)

Thisfunctionisusedtosetaneventtimerforatimesometimeinthe

Page 152: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

future.Whentheeventtimerexpires,theeventPROCESS_EVENT_TIMERwillbepostedtotheprocessthatcalledtheetimer_set()function.

Parameters[in,out] ptEtime Apointertotheeventtimer[in] interval Theintervalbeforethetimerexpires.

Hereisthecallgraphforthisfunction:

TICKetimer_start_time ( tETIME* ptEtime )

Thisfunctionreturnsthestarttime(whenthetimerwaslastset)foraneventtimer.

Parameters[in,out] ptEtime Apointertotheeventtimer

ReturnsThestarttimefortheeventtimer.

voidetimer_stop ( tETIME* ptEtime )

Thisfunctionstopsaneventtimerthathaspreviouslybeensetwithetimer_set()oretimer_reset().Afterthisfunctionhasbeencalled,theeventtimerwillnotemitanyeventwhenitexpires.

Parameters[in,out] ptEtime Apointertothependingeventtimer.

Generatedby 1.8.9.1

Page 153: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

DataFields

RainbowBSManualv0.1.0WrittenbyQWQ([email protected])

etime_structStructReferenceEventtimers

Eventtimerstructure.More...

#include<RainbowBS.h>

Collaborationdiagramforetime_struct:

Page 154: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

DataFieldsTICK start

TICK interval

structetime_struct* next

tPROCESS* p

Page 155: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

DetailedDescription

Thisstructureisusedfordeclaringatimer.Thetimermustbesetwithetimer_set()beforeitcanbeused.

Thedocumentationforthisstructwasgeneratedfromthefollowingfile:

RainbowBS.h

Generatedby 1.8.9.1

Page 156: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

RainbowBSManualv0.1.0WrittenbyQWQ([email protected])

debug

Page 157: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

statementmacros

statementmacrosfordebug

#define RBS_DEBUG_STA(sta)sta Cstatementstaiscompiledifenabledebug.More...#define RBS_DEBUG_IF(exp,sta)if(exp){sta Cstatementifiscompiledifenabledebug.More...

#define RBS_DEBUG_ELSIF(sta1,exp,sta2)sta1;}elseif(exp){sta2 Cstatementelseifiscompiledifenabledebug.More...#define RBS_DEBUG_ENDIF(sta)sta;} Cstatement}forifiscompiledifenabledebug.More...

Page 158: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

errormacrofunction

errormacrosfordebugoutput

#define RBS_DEBUG_ERROR(exp,s,sta) Outputerrorinformation.More...#define RBS_DEBUG_ERROR_FORMAT(exp,format,sta,...) Outputformaterrorinformationconditionally.More...

Page 159: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

warningmacrofunction

warningmacrosfordebugoutput

#define RBS_DEBUG_WARN(exp,s) Outputwarninginformationconditionally.More...#define RBS_DEBUG_WARN_FORMAT(exp,format,...) Outputformatwarninginformationconditionally.More...

Page 160: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

logmacrofunction

logmacrosfordebugoutput

#define RBS_DEBUG_LOG(s) Outputformatloginformation.More...#define RBS_DEBUG_LOG_FORMAT(format,...) Outputformatloginformation.More...

Page 161: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

DetailedDescription

usedforsystemorapplicationdebug.

Page 162: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

MacroDefinitionDocumentation

#defineRBS_DEBUG_ELSIF ( sta1, exp, sta2) sta1;}elseif(exp){sta2

Thismacroequalstosta1;}elseif(exp){sta2

Parameterssta1Cstatement.exp Cexpression.sta2Cstatement.

NotethisshouldusedwithRBS_DEBUG_IF()andRBS_DEBUG_ENDIF().

SeealsoRBS_DEBUG_IF()RBS_DEBUG_ENDIF()

#defineRBS_DEBUG_ENDIF ( sta ) sta;}

Thismacroequalstosta1;}

ParametersstaCstatement.

NotethisshouldusedwithRBS_DEBUG_IF()andRBS_DEBUG_ELSIF().

SeealsoRBS_DEBUG_IF()

Page 163: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

RBS_DEBUG_ELSIF()

#defineRBS_DEBUG_ERROR ( exp, s, sta)

Parameters[in] exp Clanguagelogicalexpression.[in] s informationstring.[in] sta Cstatement.

NotelengthofinformationstringshouldnotexceedRBS_CFG_DEBUG_BUFSIZE

#defineRBS_DEBUG_ERROR_FORMAT ( exp, format, sta, ...)

Parameters[in] exp Clanguagelogicalexpression.[in] format formatinformationstring.[in] sta Cstatement.[in] ... parameters.

NotelengthofinformationstringshouldnotexceedRBS_CFG_DEBUG_BUFSIZE

#defineRBS_DEBUG_IF ( exp,

Page 164: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

sta) if(exp){sta

Thismacroequalstoif(exp){sta

Parametersexp Cexpression.sta Cstatement.

NotethisshouldusedwithRBS_DEBUG_ELSIF()andRBS_DEBUG_ENDIF().

SeealsoRBS_DEBUG_ELSIF()RBS_DEBUG_ENDIF()

#defineRBS_DEBUG_LOG ( s )

Parameters[in] s informationstring.

NotelengthofinformationstringshouldnotexceedRBS_CFG_DEBUG_BUFSIZE

#defineRBS_DEBUG_LOG_FORMAT ( format, ...)

Parameters[in] format formatinformationstring.[in] ... parameters.

Notelengthofinformationstringshouldnotexceed

Page 165: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

RBS_CFG_DEBUG_BUFSIZE

#defineRBS_DEBUG_STA ( sta ) sta

ParametersstaCstatement

#defineRBS_DEBUG_WARN ( exp, s)

Parameters[in] exp Clanguagelogicalexpression.[in] s informationstring.

NotelengthofinformationstringshouldnotexceedRBS_CFG_DEBUG_BUFSIZE

#defineRBS_DEBUG_WARN_FORMAT ( exp, format, ...)

Parameters[in] exp Clanguagelogicalexpression.[in] format formatinformationstring.[in] ... parameters.

NotelengthofinformationstringshouldnotexceedRBS_CFG_DEBUG_BUFSIZE

Page 166: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

Generatedby 1.8.9.1

Page 167: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

Modules|Files|DataStructures|Macros

RainbowBSManualv0.1.0WrittenbyQWQ([email protected])

Pt

CollaborationdiagramforPt:

Page 168: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

Modules Localcontinuations Protothreadsemaphores

Page 169: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

Filesfile pt.h

Page 170: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

DataStructuresstruct pt

Page 171: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

Macros#define PT_WAITING0#define PT_YIELDED1#define PT_EXITED2#define PT_ENDED3

Page 172: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

Initialization#define PT_INIT(pt)

Page 173: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

Declarationanddefinition#define PT_THREAD(name_args)#define PT_BEGIN(pt)#define PT_END(pt)

Page 174: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

Blockedwait#define PT_WAIT_UNTIL(pt,condition)#define PT_WAIT_WHILE(pt,cond)

Page 175: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

Hierarchicalprotothreads#define PT_WAIT_THREAD(pt,thread)#define PT_SPAWN(pt,child,thread)

Page 176: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

Exitingandrestarting#define PT_RESTART(pt)#define PT_EXIT(pt)

Page 177: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

Callingaprotothread#define PT_SCHEDULE(f)

Page 178: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

Yieldingfromaprotothread#define PT_YIELD(pt)#define PT_YIELD_UNTIL(pt,cond) Yieldfromtheprotothreaduntilaconditionoccurs.More...

Page 179: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

DetailedDescription

MacroDefinitionDocumentation

#definePT_BEGIN ( pt )

DeclarethestartofaprotothreadinsidetheCfunctionimplementingtheprotothread.

Thismacroisusedtodeclarethestartingpointofaprotothread.Itshouldbeplacedatthestartofthefunctioninwhichtheprotothreadruns.AllCstatementsabovethePT_BEGIN()invokationwillbeexecutedeachtimetheprotothreadisscheduled.

Parameterspt Apointertotheprotothreadcontrolstructure.

#definePT_END ( pt )

Declaretheendofaprotothread.

Thismacroisusedfordeclaringthataprotothreadends.ItmustalwaysbeusedtogetherwithamatchingPT_BEGIN()macro.

Parameterspt Apointertotheprotothreadcontrolstructure.

#definePT_EXIT ( pt )

Exittheprotothread.

Page 180: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

Thismacrocausestheprotothreadtoexit.Iftheprotothreadwasspawnedbyanotherprotothread,theparentprotothreadwillbecomeunblockedandcancontinuetorun.

Parameterspt Apointertotheprotothreadcontrolstructure.

#definePT_INIT ( pt )

Initializeaprotothread.

Initializesaprotothread.Initializationmustbedonepriortostartingtoexecutetheprotothread.

Parameterspt Apointertotheprotothreadcontrolstructure.

SeealsoPT_SPAWN()

#definePT_RESTART ( pt )

Restarttheprotothread.

ThismacrowillblockandcausetherunningprotothreadtorestartitsexecutionattheplaceofthePT_BEGIN()call.

Parameterspt Apointertotheprotothreadcontrolstructure.

#definePT_SCHEDULE ( f )

Scheduleaprotothread.

Thisfunctionshedulesaprotothread.Thereturnvalueofthefunctionisnon-zeroiftheprotothreadisrunningorzeroiftheprotothreadhas

Page 181: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

exited.

Parametersf ThecalltotheCfunctionimplementingtheprotothreadtobescheduled

#definePT_SPAWN ( pt, child, thread)

Spawnachildprotothreadandwaituntilitexits.

Thismacrospawnsachildprotothreadandwaitsuntilitexits.Themacrocanonlybeusedwithinaprotothread.

Parameterspt Apointertotheprotothreadcontrolstructure.child Apointertothechildprotothread'scontrolstructure.thread Thechildprotothreadwitharguments

#definePT_THREAD ( name_args )

Declarationofaprotothread.

Thismacroisusedtodeclareaprotothread.Allprotothreadsmustbedeclaredwiththismacro.

Parametersname_args ThenameandargumentsoftheCfunction

implementingtheprotothread.

#definePT_WAIT_THREAD ( pt, thread)

Page 182: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

Blockandwaituntilachildprotothreadcompletes.

Thismacroschedulesachildprotothread.Thecurrentprotothreadwillblockuntilthechildprotothreadcompletes.

NoteThechildprotothreadmustbemanuallyinitializedwiththePT_INIT()functionbeforethisfunctionisused.

Parameterspt Apointertotheprotothreadcontrolstructure.thread Thechildprotothreadwitharguments

SeealsoPT_SPAWN()

#definePT_WAIT_UNTIL ( pt, condition)

Blockandwaituntilconditionistrue.

Thismacroblockstheprotothreaduntilthespecifiedconditionistrue.

Parameterspt Apointertotheprotothreadcontrolstructure.condition Thecondition.

#definePT_WAIT_WHILE ( pt, cond)

Blockandwaitwhileconditionistrue.

Thisfunctionblocksandwaitswhileconditionistrue.See

Page 183: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

PT_WAIT_UNTIL().

Parameterspt Apointertotheprotothreadcontrolstructure.cond Thecondition.

#definePT_YIELD ( pt )

Yieldfromthecurrentprotothread.

Thisfunctionwillyieldtheprotothread,therebyallowingotherprocessingtotakeplaceinthesystem.

Parameterspt Apointertotheprotothreadcontrolstructure.

#definePT_YIELD_UNTIL ( pt, cond)

Parameterspt Apointertotheprotothreadcontrolstructure.cond Thecondition.

Thisfunctionwillyieldtheprotothread,untilthe

specifiedconditionevaluatestotrue.

Generatedby 1.8.9.1

Page 184: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

Files|Macros|Typedefs

RainbowBSManualv0.1.0WrittenbyQWQ([email protected])

LocalcontinuationsPt

CollaborationdiagramforLocalcontinuations:

Page 185: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

Filesfile lc-addrlabels.hfile lc-switch.hfile lc.h

Page 186: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

Macros#define LC_INIT(s)s=NULL#define LC_RESUME(s)#define LC_CONCAT2(s1,s2)s1##s2#define LC_CONCAT(s1,s2)LC_CONCAT2(s1,s2)#define LC_SET(s)#define LC_END(s)#define LC_INIT(s)s=0;#define LC_RESUME(s)switch(s){case0:#define LC_SET(s)s=__LINE__;case__LINE__:#define LC_END(s)}#define __LC_H__

Page 187: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

Typedefstypedefvoid* lc_t

typedefunsignedshort lc_t

Page 188: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

DetailedDescription

Localcontinuationsformthebasisforimplementingprotothreads.Alocalcontinuationcanbesetinaspecificfunctiontocapturethestateofthefunction.Afteralocalcontinuationhasbeensetcanberesumedinordertorestorethestateofthefunctionatthepointwherethelocalcontinuationwasset.

Page 189: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

MacroDefinitionDocumentation

#defineLC_RESUME ( s )

Value:do{\

if(s!=NULL){\

goto*s;\

}\

}while(0)

#defineLC_SET ( s )

Value:do{\

LC_CONCAT(LC_LABEL,__LINE__):\

(s)=&&LC_CONCAT(LC_LABEL,__LINE__);\

}while(0)

Generatedby 1.8.9.1

Page 190: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

RainbowBS RBSSource Base Protothreads

Macros|Typedefs

RainbowBSManualv0.1.0WrittenbyQWQ([email protected])

lc-addrlabels.hFileReferencePt»Localcontinuations

Page 191: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

Macros#define LC_INIT(s)s=NULL#define LC_RESUME(s)#define LC_CONCAT2(s1,s2)s1##s2#define LC_CONCAT(s1,s2)LC_CONCAT2(s1,s2)#define LC_SET(s)#define LC_END(s)

Page 192: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

Typedefstypedefvoid* lc_t

Page 193: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

DetailedDescription

Implementationoflocalcontinuationsbasedonthe"Labelsasvalues"featureofgcc

[email protected]

ThisimplementationoflocalcontinuationsisbasedonaspecialfeatureoftheGCCCcompilercalled"labelsasvalues".ThisfeatureallowsassigningpointerswiththeaddressofthecodecorrespondingtoaparticularClabel.

Formoreinformation,seetheGCCdocumentation:http://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html

Generatedby 1.8.9.1

Page 194: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

RainbowBS RBSSource Base Protothreads

Macros|Typedefs

RainbowBSManualv0.1.0WrittenbyQWQ([email protected])

lc-switch.hFileReferencePt»Localcontinuations

Thisgraphshowswhichfilesdirectlyorindirectlyincludethisfile:

Page 195: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

Macros#define LC_INIT(s)s=0;#define LC_RESUME(s)switch(s){case0:#define LC_SET(s)s=__LINE__;case__LINE__:#define LC_END(s)}

Page 196: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

Typedefstypedefunsignedshort lc_t

Page 197: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

DetailedDescription

Implementationoflocalcontinuationsbasedonswitch()statment

[email protected]

ThisimplementationoflocalcontinuationsusestheCswitch()statementtoresumeexecutionofafunctionsomewhereinsidethefunction'sbody.Theimplementationisbasedonthefactthatswitch()statementsareabletojumpdirectlyintothebodiesofcontrolstructuressuchasif()orwhile()statmenets.

ThisimplementationborrowsheavilyfromSimonTatham'scoroutinesimplementationinC:http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html

Generatedby 1.8.9.1

Page 198: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

RainbowBS RBSSource Base Protothreads

Macros

RainbowBSManualv0.1.0WrittenbyQWQ([email protected])

lc.hFileReferencePt»Localcontinuations

#include"lc-switch.h"

Includedependencygraphforlc.h:

Thisgraphshowswhichfilesdirectlyorindirectlyincludethisfile:

Page 199: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

DetailedDescription

Localcontinuations

[email protected]

Generatedby 1.8.9.1

Page 200: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

Files|DataStructures|Macros

RainbowBSManualv0.1.0WrittenbyQWQ([email protected])

ProtothreadsemaphoresPt

CollaborationdiagramforProtothreadsemaphores:

Page 201: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

Filesfile pt-sem.h

Page 202: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

DataStructuresstruct pt_sem

Page 203: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

Macros#define PT_SEM_INIT(s,c)#define PT_SEM_WAIT(pt,s)#define PT_SEM_SIGNAL(pt,s)

Page 204: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

DetailedDescription

Thismoduleimplementscountingsemaphoresontopofprotothreads.Semaphoresareasynchronizationprimitivethatprovidetwooperations:"wait"and"signal".The"wait"operationchecksthesemaphorecounterandblocksthethreadifthecounteriszero.The"signal"operationincreasesthesemaphorecounterbutdoesnotblock.Ifanotherthreadhasblockedwaitingforthesemaphorethatissignalled,theblockedthreadwillbecomerunnableagain.

Semaphorescanbeusedtoimplementother,morestructured,synchronizationprimitivessuchasmonitorsandmessagequeues/boundedbuffers(seebelow).

Thefollowingexampleshowshowtheproducer-consumerproblem,alsoknownastheboundedbufferproblem,canbesolvedusingprotothreadsandsemaphores.Notesontheprogramfollowaftertheexample.

#include"pt-sem.h"

#defineNUM_ITEMS32

#defineBUFSIZE8

staticstructpt_semmutex,full,empty;

PT_THREAD(producer(structpt*pt))

{

staticintproduced;

PT_BEGIN(pt);

for(produced=0;produced<NUM_ITEMS;++produced)

{

PT_SEM_WAIT(pt,&full);

PT_SEM_WAIT(pt,&mutex);

add_to_buffer(produce_item());

PT_SEM_SIGNAL(pt,&mutex);

Page 205: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

PT_SEM_SIGNAL(pt,&empty);

}

PT_END(pt);

}

PT_THREAD(consumer(structpt*pt))

{

staticintconsumed;

PT_BEGIN(pt);

for(consumed=0;consumed<NUM_ITEMS;++consumed)

{

PT_SEM_WAIT(pt,&empty);

PT_SEM_WAIT(pt,&mutex);

consume_item(get_from_buffer());

PT_SEM_SIGNAL(pt,&mutex);

PT_SEM_SIGNAL(pt,&full);

}

PT_END(pt);

}

PT_THREAD(driver_thread(structpt*pt))

{

staticstructptpt_producer,pt_consumer;

PT_BEGIN(pt);

PT_SEM_INIT(&empty,0);

PT_SEM_INIT(&full,BUFSIZE);

PT_SEM_INIT(&mutex,1);

PT_INIT(&pt_producer);

PT_INIT(&pt_consumer);

PT_WAIT_THREAD(pt,producer(&pt_producer)&

consumer(&pt_consumer));

Page 206: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

PT_END(pt);

}

Theprogramusesthreeprotothreads:oneprotothreadthatimplementstheconsumer,onethreadthatimplementstheproducer,andoneprotothreadthatdrivesthetwootherprotothreads.Theprogramusesthreesemaphores:"full","empty"and"mutex".The"mutex"semaphoreisusedtoprovidemutualexclusionforthebuffer,the"empty"semaphoreisusedtoblocktheconsumeristhebufferisempty,andthe"full"semaphoreisusedtoblocktheproduceristhebufferisfull.

The"driver_thread"holdstwoprotothreadstatevariables,"pt_producer"and"pt_consumer".Itisimportanttonotethatboththesevariablesaredeclaredasstatic.Ifthestatickeywordisnotused,bothvariablesarestoredonthestack.Sinceprotothreadsdonotstorethestack,thesevariablesmaybeoverwrittenduringaprotothreadwaitoperation.Similarly,boththe"consumer"and"producer"protothreadsdeclaretheirlocalvariablesasstatic,toavoidthembeingstoredonthestack.

Page 207: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

MacroDefinitionDocumentation

#definePT_SEM_INIT ( s, c)

Initializeasemaphore

Thismacroinitializesasemaphorewithavalueforthecounter.Internally,thesemaphoresusean"unsignedint"torepresentthecounter,andthereforethe"count"argumentshouldbewithinrangeofanunsignedint.

Parameterss (structpt_sem*)Apointertothept_semstructrepresentingthesemaphore

c (unsignedint)Theinitialcountofthesemaphore.

#definePT_SEM_SIGNAL ( pt, s)

Signalasemaphore

Thismacrocarriesoutthe"signal"operationonthesemaphore.Thesignaloperationincrementsthecounterinsidethesemaphore,whicheventuallywillcausewaitingprotothreadstocontinueexecuting.

Parameterspt (structpt*)Apointertotheprotothread(structpt)inwhichtheoperationisexecuted.

s (structpt_sem*)Apointertothept_semstructrepresentingthesemaphore

Page 208: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

#definePT_SEM_WAIT ( pt, s)

Waitforasemaphore

Thismacrocarriesoutthe"wait"operationonthesemaphore.Thewaitoperationcausestheprotothreadtoblockwhilethecounteriszero.Whenthecounterreachesavaluelargerthanzero,theprotothreadwillcontinue.

Parameterspt (structpt*)Apointertotheprotothread(structpt)inwhichtheoperationisexecuted.

s (structpt_sem*)Apointertothept_semstructrepresentingthesemaphore

Generatedby 1.8.9.1

Page 209: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

RainbowBS RBSSource Base Protothreads

DataStructures|Macros

RainbowBSManualv0.1.0WrittenbyQWQ([email protected])

pt-sem.hFileReferencePt»Protothreadsemaphores

#include"pt.h"

Includedependencygraphforpt-sem.h:

Thisgraphshowswhichfilesdirectlyorindirectlyincludethisfile:

Page 210: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

DataStructuresstruct pt_sem

Page 211: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

Macros#define PT_SEM_INIT(s,c)#define PT_SEM_WAIT(pt,s)#define PT_SEM_SIGNAL(pt,s)

Page 212: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

DetailedDescription

Coutingsemaphoresimplementedonprotothreads

[email protected]

Generatedby 1.8.9.1

Page 213: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

DataFields

RainbowBSManualv0.1.0WrittenbyQWQ([email protected])

pt_semStructReferencePt»Protothreadsemaphores

Collaborationdiagramforpt_sem:

Page 214: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

DataFieldsunsignedint count

Thedocumentationforthisstructwasgeneratedfromthefollowingfile:

pt-sem.h

Generatedby 1.8.9.1

Page 215: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

RainbowBS RBSSource Base Protothreads

DataStructures|Macros

RainbowBSManualv0.1.0WrittenbyQWQ([email protected])

pt.hFileReferencePt

#include"lc.h"

Includedependencygraphforpt.h:

Thisgraphshowswhichfilesdirectlyorindirectlyincludethisfile:

Page 216: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

DataStructuresstruct pt

Page 217: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

Macros#define PT_WAITING0#define PT_YIELDED1#define PT_EXITED2#define PT_ENDED3

Initialization#define PT_INIT(pt)

Declarationanddefinition#define PT_THREAD(name_args)#define PT_BEGIN(pt)#define PT_END(pt)

Blockedwait#define PT_WAIT_UNTIL(pt,condition)#define PT_WAIT_WHILE(pt,cond)

Hierarchicalprotothreads#define PT_WAIT_THREAD(pt,thread)#define PT_SPAWN(pt,child,thread)

Exitingandrestarting#define PT_RESTART(pt)

Page 218: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

#define PT_EXIT(pt)

Callingaprotothread#define PT_SCHEDULE(f)

Yieldingfromaprotothread#define PT_YIELD(pt)#define PT_YIELD_UNTIL(pt,cond) Yieldfromtheprotothreaduntilaconditionoccurs.More...

Page 219: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

DetailedDescription

Protothreadsimplementation.

[email protected]

Generatedby 1.8.9.1

Page 220: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

DataFields

RainbowBSManualv0.1.0WrittenbyQWQ([email protected])

ptStructReferencePt

Collaborationdiagramforpt:

Page 221: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

DataFieldslc_t lc

Thedocumentationforthisstructwasgeneratedfromthefollowingfile:

pt.h

Generatedby 1.8.9.1

Page 222: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

RainbowBSManualv0.1.0WrittenbyQWQ([email protected])

DataStructures

Herearethedatastructureswithbriefdescriptions:

C etime_struct Eventtimerstructure C event_struct C MEM_struct C process_struct Processstructure(oneprocessconsistsone

protothread) C pt C pt_sem C tBLOCK C tDMMHEAD C tTime Timestructure

Generatedby 1.8.9.1

Page 223: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

DataFields

RainbowBSManualv0.1.0WrittenbyQWQ([email protected])

event_structStructReference

Collaborationdiagramforevent_struct:

Page 224: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

DataFieldsprocess_event_t evprocess_data_t data

tPROCESS* p

Thedocumentationforthisstructwasgeneratedfromthefollowingfile:

process.c

Generatedby 1.8.9.1

Page 225: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

DataFields

RainbowBSManualv0.1.0WrittenbyQWQ([email protected])

MEM_structStructReference

CollaborationdiagramforMEM_struct:

Page 226: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

DataFieldshDMM hDmm

U8* pData

USIZE size

structMEM_struct* pNextstructMEM_struct* pPrev

U8 lock_count

Page 227: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

FieldDocumentation

hDMMhDmm

DMMhandle

U8lock_count

0:notallocated,1:allocated,[2,255]:beingusedlock_count-1times.

U8*pData

pointerofmemoryarea

structMEM_struct*pNext

nexthandleinlinkedlist

structMEM_struct*pPrev

prevhandleinlinkedlist

USIZEsize

usablesizeofallocatedblock

Thedocumentationforthisstructwasgeneratedfromthefollowingfile:

Page 228: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

DMM.c

Generatedby 1.8.9.1

Page 229: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

DataFields

RainbowBSManualv0.1.0WrittenbyQWQ([email protected])

tBLOCKStructReference

CollaborationdiagramfortBLOCK:

Page 230: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

DataFieldshDMM hDmm

U8* pData

U8 lock_count

Page 231: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

FieldDocumentation

hDMMhDmm

DMMhandle

U8lock_count

0:notallocated,1:allocated,[2,255]:beingusedlock_count-1times

U8*pData

pointerofdataarea

Thedocumentationforthisstructwasgeneratedfromthefollowingfile:

DMM.c

Generatedby 1.8.9.1

Page 232: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

DataFields

RainbowBSManualv0.1.0WrittenbyQWQ([email protected])

tDMMHEADStructReference

CollaborationdiagramfortDMMHEAD:

Page 233: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

DataFieldseDMTYPE eType

char* pName

void* pObjectArrayStart

void* pObjectArrayLast

void* pFreeObject

USIZE free_object_count

USIZE free_bytes

U8* pDataStart

U8* pDataEnd

USIZE block_sizeHMUTEX hMutex

Page 234: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

FieldDocumentation

USIZEblock_size

blocksizeifeTypeisDM_BLOCK

eDMTYPEeType

DMMtype

USIZEfree_bytes

countoffreebytesifeTypeisDM_POOLorDM_POOL_AUTO

USIZEfree_object_count

countoffreearray(tBLOCKortMEM)objects

HMUTEXhMutex

lock

U8*pDataEnd

pointerofdataend

U8*pDataStart

Page 235: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

pointerofdatahead

void*pFreeObject

pointerforacceleratingallocation

char*pName

DMMname

void*pObjectArrayLast

pointerofthelastarray(tBLOCKortMEM)object

void*pObjectArrayStart

pointerofthefirstarray(tBLOCKortMEM)object

Thedocumentationforthisstructwasgeneratedfromthefollowingfile:

DMM.c

Generatedby 1.8.9.1

Page 236: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

RainbowBSManualv0.1.0WrittenbyQWQ([email protected])

DataStructureIndex

E|M|P|T

M event_struct pt tDMMHEAD

p pt_sem tTimeMEM_struct te process_struct

tBLOCKetime_struct

E|M|P|T

Generatedby 1.8.9.1

Page 237: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

RainbowBSManualv0.1.0WrittenbyQWQ([email protected])

Hereisalistofalldocumentedstructandunionfieldswithlinkstothestruct/uniondocumentationforeachfield:

-b-

block_size:tDMMHEAD

-d-

day:tTimeday_of_week:tTime

-e-

eType:tDMMHEAD

-f-

free_bytes:tDMMHEADfree_object_count:tDMMHEAD

-h-

hDmm:MEM_struct,tBLOCKhMutex:tDMMHEADhour:tTime

-l-

lock_count:MEM_struct,tBLOCK

-m-

milliseconds:tTime

Page 238: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

minute:tTimemonth:tTime

-n-

name:process_structneedspoll:process_structnext:process_struct

-p-

pData:MEM_struct,tBLOCKpDataEnd:tDMMHEADpDataStart:tDMMHEADpFreeObject:tDMMHEADpName:tDMMHEADpNext:MEM_structpObjectArrayLast:tDMMHEADpObjectArrayStart:tDMMHEADpPrev:MEM_struct

-s-

second:tTimesize:MEM_structstate:process_struct

-y-

year:tTime

Generatedby 1.8.9.1

Page 239: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

RainbowBSManualv0.1.0WrittenbyQWQ([email protected])

-b-

block_size:tDMMHEAD

-d-

day:tTimeday_of_week:tTime

-e-

eType:tDMMHEAD

-f-

free_bytes:tDMMHEADfree_object_count:tDMMHEAD

-h-

hDmm:MEM_struct,tBLOCKhMutex:tDMMHEADhour:tTime

-l-

lock_count:MEM_struct,tBLOCK

-m-

milliseconds:tTimeminute:tTime

Page 240: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

month:tTime

-n-

name:process_structneedspoll:process_structnext:process_struct

-p-

pData:MEM_struct,tBLOCKpDataEnd:tDMMHEADpDataStart:tDMMHEADpFreeObject:tDMMHEADpName:tDMMHEADpNext:MEM_structpObjectArrayLast:tDMMHEADpObjectArrayStart:tDMMHEADpPrev:MEM_struct

-s-

second:tTimesize:MEM_structstate:process_struct

-y-

year:tTime

Generatedby 1.8.9.1

Page 241: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

RainbowBSManualv0.1.0WrittenbyQWQ([email protected])

FileList

Hereisalistofalldocumentedfileswithbriefdescriptions:

lc-addrlabels.h lc-switch.h lc.h Port.h pt-sem.h pt.h RainbowBS.h RainbowBSConf.h

Generatedby 1.8.9.1

Page 242: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

RainbowBS RBSSource Port

Functions

RainbowBSManualv0.1.0WrittenbyQWQ([email protected])

Port.hFileReference#include"RainbowBS.h"

IncludedependencygraphforPort.h:

Page 243: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

FunctionsBOOL Port_Init(void) Initializehardware.More...TICK Port_GetTickCount(void) Getsystemtick.More...

void Port_GetLocalTime(tTime*pTime) Getsystemlocaltime.More...

void Port_Delay(U32millisec) Delaysomemillisecond.More...

void Port_Printf_Error(constchar*s) Outputerrorinformation.More...

void Port_Printf_Warn(constchar*s) Outputwarninginformation.More...

void Port_Printf_Log(constchar*s) Outputloginformation.More...BOOL Port_GetMutex(HMUTEXhMutex) Waitforamutex.More...BOOL Port_FreeMutex(HMUTEXhMutex) Releaseamutex.More...

Page 244: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

DetailedDescription

Implementationofporting.

[email protected]

Page 245: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

FunctionDocumentation

voidPort_Delay ( U32 millisec )

Parameters[in]millisecmillisecondcount.

Hereisthecallergraphforthisfunction:

BOOLPort_FreeMutex ( HMUTEX hMutex )

Parameters[in] hMutex handleofmutex.

Hereisthecallergraphforthisfunction:

Page 246: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

voidPort_GetLocalTime ( tTime* pTime )

Parameters[out] pTime timestructure.

Hereisthecallergraphforthisfunction:

BOOLPort_GetMutex ( HMUTEX hMutex )

Parameters[in] hMutex handleofmutex.

Page 247: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

Hereisthecallergraphforthisfunction:

TICKPort_GetTickCount ( void )

Returnssystemtick.

Hereisthecallergraphforthisfunction:

BOOLPort_Init ( void )

Page 248: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

ReturnvaluesTRUE successful.FALSE failed.

Hereisthecallergraphforthisfunction:

voidPort_Printf_Error ( constchar* s )

Parameters[in] s string.

voidPort_Printf_Log ( constchar* s )

Parameters[in] s string.

voidPort_Printf_Warn ( constchar* s )

Parameters[in] s string.

Generatedby 1.8.9.1

Page 249: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

RainbowBS RBSSource

DataStructures|Macros|Typedefs|Functions

RainbowBSManualv0.1.0WrittenbyQWQ([email protected])

RainbowBS.hFileReference

#include<stddef.h>#include<windows.h>#include"RainbowBSConf.h"

#include"pt.h"

#include"pt-sem.h"

#include<stdio.h>

#include<string.h>

IncludedependencygraphforRainbowBS.h:

Thisgraphshowswhichfilesdirectlyorindirectlyincludethisfile:

Page 250: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

DataStructuresstruct tTime Timestructure.More...struct process_struct Processstructure(oneprocessconsistsoneprotothread).

More...struct etime_struct Eventtimerstructure.More...

Page 251: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

Macros#define RBS_VERSION"0.1.0"#define RBS_VERNUM0x0100#define RBS_VER_MAJOR0#define RBS_VER_MINOR1#define RBS_VER_REVISION0#define RBS_VER_SUBREVISION0#define FALSE0u#define TRUE1u#define USE_PARA(para)(para=(para))#define MIN(v0,v1)(((v0)>(v1))?(v1):(v0))#define MAX(v0,v1)(((v0)>(v1))?(v0):(v1))#define ABS(v)(((v)>=0)?(v):(-(v)))#define SWAP(a,b)(a=(a)+(b),b=(a)-(b),a=(a)-(b))#define COUNT_OF(a)(sizeof(a)/sizeof(a[0]))#define _STR(a)#a#define STR(a)_STR(a)#define _CONS(a,b)a##b

Page 252: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

#define CONS(a,b)_CONS(a,b)

#define ALIGN_F(pointer,power2)(((IPTRDIFF)(pointer)+((IPTRDIFF)((power2)-1)))&(~((IPTRDIFF)((power2)-1))))

#define ALIGN_B(pointer,power2)((IPTRDIFF)(pointer)&(~((IPTRDIFF)((power2)-1))))#define HDMM_NULLNULL#define HBLOCK_NULLNULL#define HMEM_NULLNULL#define PROCESS_NONENULL#define PROCESS_BROADCASTNULL

#define PROCESS_NAME_STRING(process)((NULL==(process))?"NoName":(process)->name)

predefinedeventtype#define PROCESS_EVENT_NONE0x80#define PROCESS_EVENT_INIT0x81#define PROCESS_EVENT_POLL0x82#define PROCESS_EVENT_EXIT0x83#define PROCESS_EVENT_SERVICE_REMOVED0x84#define PROCESS_EVENT_CONTINUE0x85#define PROCESS_EVENT_MSG0x86#define PROCESS_EVENT_EXITED0x87

Page 253: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

#define PROCESS_EVENT_TIMER0x88#define PROCESS_EVENT_COM0x89#define PROCESS_EVENT_MAX0x8a

processdeclarationanddefinition#define PROCESS_THREAD(name,ev,data) Definethebodyofaprocess.More...#define PROCESS_NAME(name)externtPROCESSname Declarethenameofaprocess.More...#define PROCESS(name,strname) Defineaprocess.More...

semaphoredeclarationanddefinition#define SEM_NAME(name)externstructpt_semsem_##name Declarethenameofasemaphore.More...#define SEM(name,count) Defineasemaphore.More...

processprotothreadfunctions#define PROCESS_BEGIN() Definethebeginningofaprocess.More...#define PROCESS_END() Definetheendofaprocess.More...#define PROCESS_WAIT_EVENT() Waitforaneventtobepostedtotheprocess.More...

Page 254: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

#define PROCESS_WAIT_EVENT_UNTIL(c) Waitforaneventtobepostedtotheprocess,withanextra

condition.More...#define PROCESS_YIELD() Yieldthecurrentlyrunningprocess.#define PROCESS_YIELD_UNTIL(c) Yieldthecurrentlyrunningprocessuntilaconditionoccurs.

More...#define PROCESS_WAIT_UNTIL(c) Waitforaconditiontooccur.More...#define PROCESS_WAIT_WHILE(c) Waitforaconditionnotoccur.More...#define PROCESS_EXIT() Exitthecurrentlyrunningprocess.#define PROCESS_PT_SPAWN(pt,thread) Spawnaprotothreadfromtheprocess.More...#define PROCESS_PAUSE() Yieldtheprocessforashortwhile.More...#define PROCESS_WAIT_SEM(name)#define PROCESS_SIGNAL_SEM(name)

pollandexithandlers

#define PROCESS_POLLHANDLER(handler)if(ev==PROCESS_EVENT_POLL){handler;} Specifyanactionwhenaprocessispolled.More...

#define PROCESS_EXITHANDLER(handler)if(ev==

Page 255: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

PROCESS_EVENT_EXIT){handler;} Specifyanactionwhenaprocessexits.More...

statementmacros

statementmacrosfordebug

#define RBS_DEBUG_STA(sta)sta Cstatementstaiscompiledifenabledebug.More...#define RBS_DEBUG_IF(exp,sta)if(exp){sta Cstatementifiscompiledifenabledebug.More...

#define RBS_DEBUG_ELSIF(sta1,exp,sta2)sta1;}elseif(exp){sta2 Cstatementelseifiscompiledifenabledebug.More...#define RBS_DEBUG_ENDIF(sta)sta;} Cstatement}forifiscompiledifenabledebug.More...

errormacrofunction

errormacrosfordebugoutput

#define RBS_DEBUG_ERROR(exp,s,sta) Outputerrorinformation.More...#define RBS_DEBUG_ERROR_FORMAT(exp,format,sta,...) Outputformaterrorinformationconditionally.More...

warningmacrofunction

warningmacrosfordebugoutput

#define RBS_DEBUG_WARN(exp,s)

Page 256: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

Outputwarninginformationconditionally.More...#define RBS_DEBUG_WARN_FORMAT(exp,format,...) Outputformatwarninginformationconditionally.More...

logmacrofunction

logmacrosfordebugoutput

#define RBS_DEBUG_LOG(s) Outputformatloginformation.More...#define RBS_DEBUG_LOG_FORMAT(format,...) Outputformatloginformation.More...

Page 257: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

Typedefstypedefuint8_t BOOL

typedefint8_t I8

typedefuint8_t U8

typedefint16_t I16

typedefuint16_t U16

typedefint32_t I32

typedefuint32_t U32

typedefint64_t I64

typedefuint64_t U64

typedefsize_t USIZE

typedefptrdiff_t IPTRDIFF

typedefU64 TICK

typedefvoid* hDMM

typedefvoid* hBLOCK

typedefvoid* hMEM

typedefU8 process_event_t

typedefvoid* process_data_t

Page 258: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

typedefstructprocess_struct tPROCESS Processstructure(oneprocessconsists

oneprotothread).More...

typedefstructetime_struct tETIME Eventtimerstructure.More...

Page 259: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

FunctionsBOOL RBS_Init(void)

InitializeRainbowBS.More...

U8 RBS_GetCPUBits(void) CPUword-width.More...

BOOL RBS_IsCPULittleEndian(void) CheckifCPUislittle-endian.More...

BOOL RBS_IsStackGrowDown(void) Checkifstackgrowsdown.More...

void RBS_MemSet8(U8*pDes,U8fill,USIZEnum) Setmemorybybyteunit.More...

void RBS_MemSet16(U16*pDes,U16fill,USIZEnum) Setmemorybytwo-bytesunit.More...

void RBS_MemSet32(U32*pDes,U32fill,USIZEnum) Setmemorybyfour-bytesunit.More...

void RBS_MemCpy8(U8*pDes,constU8*pSrc,USIZEnum) Copymemorybybyteunit.More...

U16 RBS_Read16L(constU8**ppData) Reada16-bitsentityinlittle-endian.More...

U32 RBS_Read32L(constU8**ppData) Reada32-bitsentityinlittle-endian.More...

void RBS_Write16L(U8**ppData,U16data) Writea16-bitsentityinlittle-endian.More...

Page 260: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

void RBS_Write32L(U8**ppData,U32data) Writea32-bitsentityinlittle-endian.More...

U16 RBS_Read16B(constU8**ppData) Reada16-bitsentityinbig-endian.More...

U32 RBS_Read32B(constU8**ppData) Reada32-bitsentityinbig-endian.More...

void RBS_Write16B(U8**ppData,U16data) Writea16-bitsentityinbig-endian.More...

void RBS_Write32B(U8**ppData,U32data) Writea32-bitsentityinbig-endian.More...

hDMM RBS_DMM_RegisterBlock(char*pName,void*pDM,USIZEsize,USIZEblock_size,HMUTEXhMutex)

Registerthememoryareaasadynamicblockmemoryarea.More...

hBLOCK RBS_DMM_AllocZeroBlock(hDMMhDmm)

Allocateafreeblockwithzeroinitializationfromthedynamicblockmemoryarea.More...

hBLOCK RBS_DMM_AllocBlock(hDMMhDmm)

Allocateafreeblockfromthedynamicblockmemoryarea.More...

BOOL RBS_DMM_FreeBlock(hBLOCKhBlock)

Freetheallocatedblock.More...

void* RBS_DMM_UseHBlock(hBLOCKhBlock) Gettheallocatedblockpointer.More...

BOOL RBS_DMM_UnuseHBlock(hBLOCKhBlock) Unusetheallocatedblockarea.More...

Page 261: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

hDMMRBS_DMM_RegisterPool(char*pName,void*pDM,USIZEsize,BOOLbAntiFrag,U16handle_count,HMUTEXhMutex)

Registerthememoryareaasadynamicpoolmemoryarea.More...

hMEM RBS_DMM_AllocZeroMem(hDMMhDmm,USIZEsize)

Allocateafreememorywithzeroinitializationfromthedynamicmemoryarea.More...

hMEM RBS_DMM_AllocMem(hDMMhDmm,USIZEsize)

Allocateafreememoryfromthedynamicmemoryarea.More...

hMEM RBS_DMM_ReallocMem(hMEMhMem,USIZEsize)

Reallocateafreememoryfromthesamedynamicmemoryarea.More...

BOOL RBS_DMM_FreeMem(hMEMhMem)

Freetheallocatedmemory.More...

void* RBS_DMM_UseHMem(hMEMhMem) Gettheallocatedmemorypointer.More...

BOOL RBS_DMM_UnuseHMem(hMEMhMem) Unusetheallocatedmemoryarea.More...

USIZE RBS_DMM_GetHMemSize(hMEMhMem) Gettheallocatedmemorysize.More...

systeminformationconstchar* RBS_GetVersionString(void) GetRainbowBSversionstring.More...constchar* RBS_GetSysInfo(void)

Page 262: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

Getsystemdescriptionstring.More...

processfunctionscalledfromdevicedrivers.BOOL process_poll(tPROCESS*ptProcess)

Requestaprocesstobepolled.More...

functionscalledbythesystemandboot-upcodeU16 process_run(void)

Runthesystemonce-callpollhandlersandprocessoneevent.More...

BOOL process_is_running(tPROCESS*ptProcess)

Checkifaprocessisrunning.More...

U16 process_nevents(void) Numberofeventswaitingtobeprocessed.More...

etimerfunctionscalledfromapplicationprogramsvoid etimer_set(tETIME*ptEtime,TICKinterval)

Setaneventtimer.More...

void etimer_reset(tETIME*ptEtime) Resetaneventtimerwiththesameintervalaswas

previouslyset.More...

void etimer_restart(tETIME*ptEtime) Restartaneventtimerfromthecurrentpointintime.

More...

void etimer_adjust(tETIME*ptEtime,inttimediff) Adjusttheexpirationtimeforaneventtimer.More...

TICK etimer_expiration_time(tETIME*ptEtime) Gettheexpirationtimefortheeventtimer.More...

Page 263: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

TICK etimer_start_time(tETIME*ptEtime) Getthestarttimefortheeventtimer.More...

BOOL etimer_expired(tETIME*ptEtime)

Checkifaneventtimerhasexpired.More...

void etimer_stop(tETIME*ptEtime) Stopapendingeventtimer.More...

etimerfunctionscalledfromtimerinterrupts,bythesystemvoid etimer_request_poll(void)

Maketheeventtimerawarethattheclockhaschanged.More...

BOOL etimer_pending(void)

Checkifthereareanynon-expiredeventtimers.More...

Page 264: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

timereleated#define RBS_TICK_MS(1000u/RBS_CFG_TICK_RATE)

TICK RBS_GetTickCount(void) Getsystemtick.More...

U64 RBS_GetRunTime(void) Getsystemrunningtime(ms).More...

void RBS_GetLocalTime(tTime*ptTime) Getsystemlocaltime.More...

void RBS_Delay(U32milliseconds) Delaysomemilliseconds.More...

Page 265: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

convertdigittostringenum ePOW{SHEX,SBINARY,SDECIMAL} Specifichex,binaryordecimal.More...

U8 RBS_Number2String(U32value,ePOWePow,U8length,char*pText)

ConvertunsigneddigittoASCIIstring.More...

Page 266: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

trigonometricreleted#define ANG_45DEG1024#define ANG_90DEG(2*ANG_45DEG)#define ANG_135DEG(3*ANG_45DEG)#define ANG_180DEG(4*ANG_45DEG)#define ANG_225DEG(5*ANG_45DEG)#define ANG_270DEG(6*ANG_45DEG)#define ANG_315DEG(7*ANG_45DEG)#define ANG_360DEG(8*ANG_45DEG)

int RBS_sin(intangle) Calculatesine.More...

int RBS_cos(intangle) Calculatecosine.More...

int RBS_tan(intangle) Calculatetangent.More...

int RBS_ctan(intangle) Calculatecotangent.More...

Page 267: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

processfunctionscalledfromapplicationprograms#define PROCESS_CURRENT()process_current

Getapointertothecurrentlyrunningprocess.More...

#definePROCESS_CONTEXT_BEGIN(ptProcess){tPROCESS*tmp_current=PROCESS_CURRENT();process_current=ptProcess

Switchcontexttoanotherprocess.More...

#define PROCESS_CONTEXT_END(ptProcess)process_current=tmp_current;} Endacontextswitch.More...

tPROCESS* process_current

BOOL process_start(tPROCESS*ptProcess,process_data_targ) Startaprocess.More...

BOOL process_post(tPROCESS*ptProcess,process_event_tev,void*data)

Postanasynchronouseventtooneorallprocesses.More...

void process_send(tPROCESS*ptProcess,process_event_tev,void*data) Sendasynchronouseventtoaprocess.More...

void process_exit(tPROCESS*ptProcess) Causeaprocesstoexit.More...process_event_t process_alloc_event(void) Allocateaglobaleventnumber.More...

Page 268: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

DetailedDescription

RainbowBSInterface.

[email protected]

Generatedby 1.8.9.1

Page 269: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

RainbowBS RBSSource Config

Macros

RainbowBSManualv0.1.0WrittenbyQWQ([email protected])

RainbowBSConf.hFileReference

Thisgraphshowswhichfilesdirectlyorindirectlyincludethisfile:

Page 270: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

Macros#define RBS_CFG_SYS_INFO"RainbowSys"#define RBS_CFG_TICK_RATE100#define RBS_CFG_CPU_WORD_SIZE32/*CPUwordsize*/#define RBS_CFG_CPU_BYTE_ORDER_L1/*CPUbyteorder*/

#define RBS_CFG_CPU_STACK_DOWN1/*stackgrowthdirection*/

#define RBS_APP_NONE0#define RBS_APP_PTP1#define RBS_APP_OS2#define RBS_CFG_APP_MODELRBS_APP_PTP#define RBS_CFG_PTP_NO_PROCESS_NAME0#define RBS_CFG_PTP_PROCESS_STATS0#define RBS_CFG_PTP_NUMEVENTS32#define RBS_CFG_DMM_ALIGN2

#define RBS_DEBUG_LEVEL_NOCHECK0/*Norunningtimechecksareperformed*/#define RBS_DEBUG_LEVEL_ERRORS1/*Errorsarerecorded*/

#define RBS_DEBUG_LEVEL_WARNINGS2/*ErrorsandWarningsarerecorded*/

Page 271: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

#define RBS_DEBUG_LEVEL_LOG3/*Errors,Warningsandlogsarerecorded*/

#define RBS_CFG_DEBUG_BUFSIZE300#define RBS_CFG_DEBUG_LEVELRBS_DEBUG_LEVEL_LOG

Page 272: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

DetailedDescription

RainbowBSConfiguration.

[email protected]

Generatedby 1.8.9.1

Page 273: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

RainbowBSManualv0.1.0WrittenbyQWQ([email protected])

Hereisalistofalldocumentedfunctions,variables,defines,enums,andtypedefswithlinkstothedocumentation:

-e-

ePOW:RainbowBS.hetimer_adjust():RainbowBS.hetimer_expiration_time():RainbowBS.hetimer_expired():RainbowBS.hetimer_pending():RainbowBS.hetimer_request_poll():RainbowBS.hetimer_reset():RainbowBS.hetimer_restart():RainbowBS.hetimer_set():RainbowBS.hetimer_start_time():RainbowBS.hetimer_stop():RainbowBS.h

-p-

Port_Delay():Port.hPort_FreeMutex():Port.hPort_GetLocalTime():Port.hPort_GetMutex():Port.hPort_GetTickCount():Port.hPort_Init():Port.hPort_Printf_Error():Port.hPort_Printf_Log():Port.hPort_Printf_Warn():Port.hPROCESS:RainbowBS.hprocess_alloc_event():RainbowBS.hPROCESS_BEGIN:RainbowBS.hPROCESS_CONTEXT_BEGIN:RainbowBS.hPROCESS_CONTEXT_END:RainbowBS.hPROCESS_CURRENT:RainbowBS.hPROCESS_END:RainbowBS.hprocess_exit():RainbowBS.h

Page 274: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

PROCESS_EXIT:RainbowBS.hPROCESS_EXITHANDLER:RainbowBS.hprocess_is_running():RainbowBS.hPROCESS_NAME:RainbowBS.hprocess_nevents():RainbowBS.hPROCESS_PAUSE:RainbowBS.hprocess_poll():RainbowBS.hPROCESS_POLLHANDLER:RainbowBS.hprocess_post():RainbowBS.hPROCESS_PT_SPAWN:RainbowBS.hprocess_run():RainbowBS.hprocess_send():RainbowBS.hPROCESS_SIGNAL_SEM:RainbowBS.hprocess_start():RainbowBS.hPROCESS_THREAD:RainbowBS.hPROCESS_WAIT_EVENT:RainbowBS.hPROCESS_WAIT_EVENT_UNTIL:RainbowBS.hPROCESS_WAIT_SEM:RainbowBS.hPROCESS_WAIT_UNTIL:RainbowBS.hPROCESS_WAIT_WHILE:RainbowBS.hPROCESS_YIELD:RainbowBS.hPROCESS_YIELD_UNTIL:RainbowBS.hPT_BEGIN:pt.hPT_END:pt.hPT_EXIT:pt.hPT_INIT:pt.hPT_RESTART:pt.hPT_SCHEDULE:pt.hPT_SEM_INIT:pt-sem.hPT_SEM_SIGNAL:pt-sem.hPT_SEM_WAIT:pt-sem.hPT_SPAWN:pt.hPT_THREAD:pt.hPT_WAIT_THREAD:pt.hPT_WAIT_UNTIL:pt.hPT_WAIT_WHILE:pt.hPT_YIELD:pt.hPT_YIELD_UNTIL:pt.h

-r-

Page 275: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

RBS_cos():RainbowBS.hRBS_ctan():RainbowBS.hRBS_DEBUG_ELSIF:RainbowBS.hRBS_DEBUG_ENDIF:RainbowBS.hRBS_DEBUG_ERROR:RainbowBS.hRBS_DEBUG_ERROR_FORMAT:RainbowBS.hRBS_DEBUG_IF:RainbowBS.hRBS_DEBUG_LOG:RainbowBS.hRBS_DEBUG_LOG_FORMAT:RainbowBS.hRBS_DEBUG_STA:RainbowBS.hRBS_DEBUG_WARN:RainbowBS.hRBS_DEBUG_WARN_FORMAT:RainbowBS.hRBS_Delay():RainbowBS.hRBS_DMM_AllocBlock():RainbowBS.hRBS_DMM_AllocMem():RainbowBS.hRBS_DMM_AllocZeroBlock():RainbowBS.hRBS_DMM_AllocZeroMem():RainbowBS.hRBS_DMM_FreeBlock():RainbowBS.hRBS_DMM_FreeMem():RainbowBS.hRBS_DMM_GetHMemSize():RainbowBS.hRBS_DMM_ReallocMem():RainbowBS.hRBS_DMM_RegisterBlock():RainbowBS.hRBS_DMM_RegisterPool():RainbowBS.hRBS_DMM_UnuseHBlock():RainbowBS.hRBS_DMM_UnuseHMem():RainbowBS.hRBS_DMM_UseHBlock():RainbowBS.hRBS_DMM_UseHMem():RainbowBS.hRBS_GetCPUBits():RainbowBS.hRBS_GetLocalTime():RainbowBS.hRBS_GetRunTime():RainbowBS.hRBS_GetSysInfo():RainbowBS.hRBS_GetTickCount():RainbowBS.hRBS_GetVersionString():RainbowBS.hRBS_Init():RainbowBS.hRBS_IsCPULittleEndian():RainbowBS.hRBS_IsStackGrowDown():RainbowBS.hRBS_MemCpy8():RainbowBS.hRBS_MemSet16():RainbowBS.hRBS_MemSet32():RainbowBS.hRBS_MemSet8():RainbowBS.h

Page 276: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

RBS_Number2String():RainbowBS.hRBS_Read16B():RainbowBS.hRBS_Read16L():RainbowBS.hRBS_Read32B():RainbowBS.hRBS_Read32L():RainbowBS.hRBS_sin():RainbowBS.hRBS_tan():RainbowBS.hRBS_Write16B():RainbowBS.hRBS_Write16L():RainbowBS.hRBS_Write32B():RainbowBS.hRBS_Write32L():RainbowBS.h

-s-

SBINARY:RainbowBS.hSDECIMAL:RainbowBS.hSEM:RainbowBS.hSEM_NAME:RainbowBS.hSHEX:RainbowBS.h

-t-

tETIME:RainbowBS.htPROCESS:RainbowBS.h

Generatedby 1.8.9.1

Page 277: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

RainbowBSManualv0.1.0WrittenbyQWQ([email protected])

-e-

etimer_adjust():RainbowBS.hetimer_expiration_time():RainbowBS.hetimer_expired():RainbowBS.hetimer_pending():RainbowBS.hetimer_request_poll():RainbowBS.hetimer_reset():RainbowBS.hetimer_restart():RainbowBS.hetimer_set():RainbowBS.hetimer_start_time():RainbowBS.hetimer_stop():RainbowBS.h

-p-

Port_Delay():Port.hPort_FreeMutex():Port.hPort_GetLocalTime():Port.hPort_GetMutex():Port.hPort_GetTickCount():Port.hPort_Init():Port.hPort_Printf_Error():Port.hPort_Printf_Log():Port.hPort_Printf_Warn():Port.hprocess_alloc_event():RainbowBS.hprocess_exit():RainbowBS.hprocess_is_running():RainbowBS.hprocess_nevents():RainbowBS.hprocess_poll():RainbowBS.hprocess_post():RainbowBS.hprocess_run():RainbowBS.hprocess_send():RainbowBS.hprocess_start():RainbowBS.h

Page 278: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

-r-

RBS_cos():RainbowBS.hRBS_ctan():RainbowBS.hRBS_Delay():RainbowBS.hRBS_DMM_AllocBlock():RainbowBS.hRBS_DMM_AllocMem():RainbowBS.hRBS_DMM_AllocZeroBlock():RainbowBS.hRBS_DMM_AllocZeroMem():RainbowBS.hRBS_DMM_FreeBlock():RainbowBS.hRBS_DMM_FreeMem():RainbowBS.hRBS_DMM_GetHMemSize():RainbowBS.hRBS_DMM_ReallocMem():RainbowBS.hRBS_DMM_RegisterBlock():RainbowBS.hRBS_DMM_RegisterPool():RainbowBS.hRBS_DMM_UnuseHBlock():RainbowBS.hRBS_DMM_UnuseHMem():RainbowBS.hRBS_DMM_UseHBlock():RainbowBS.hRBS_DMM_UseHMem():RainbowBS.hRBS_GetCPUBits():RainbowBS.hRBS_GetLocalTime():RainbowBS.hRBS_GetRunTime():RainbowBS.hRBS_GetSysInfo():RainbowBS.hRBS_GetTickCount():RainbowBS.hRBS_GetVersionString():RainbowBS.hRBS_Init():RainbowBS.hRBS_IsCPULittleEndian():RainbowBS.hRBS_IsStackGrowDown():RainbowBS.hRBS_MemCpy8():RainbowBS.hRBS_MemSet16():RainbowBS.hRBS_MemSet32():RainbowBS.hRBS_MemSet8():RainbowBS.hRBS_Number2String():RainbowBS.hRBS_Read16B():RainbowBS.hRBS_Read16L():RainbowBS.hRBS_Read32B():RainbowBS.hRBS_Read32L():RainbowBS.hRBS_sin():RainbowBS.hRBS_tan():RainbowBS.hRBS_Write16B():RainbowBS.h

Page 279: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

RBS_Write16L():RainbowBS.hRBS_Write32B():RainbowBS.hRBS_Write32L():RainbowBS.h

Generatedby 1.8.9.1

Page 280: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

RainbowBSManualv0.1.0WrittenbyQWQ([email protected])

tETIME:RainbowBS.htPROCESS:RainbowBS.h

Generatedby 1.8.9.1

Page 281: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

RainbowBSManualv0.1.0WrittenbyQWQ([email protected])

ePOW:RainbowBS.h

Generatedby 1.8.9.1

Page 282: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

RainbowBSManualv0.1.0WrittenbyQWQ([email protected])

SBINARY:RainbowBS.hSDECIMAL:RainbowBS.hSHEX:RainbowBS.h

Generatedby 1.8.9.1

Page 283: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

RainbowBSManualv0.1.0WrittenbyQWQ([email protected])

-p-

PROCESS:RainbowBS.hPROCESS_BEGIN:RainbowBS.hPROCESS_CONTEXT_BEGIN:RainbowBS.hPROCESS_CONTEXT_END:RainbowBS.hPROCESS_CURRENT:RainbowBS.hPROCESS_END:RainbowBS.hPROCESS_EXIT:RainbowBS.hPROCESS_EXITHANDLER:RainbowBS.hPROCESS_NAME:RainbowBS.hPROCESS_PAUSE:RainbowBS.hPROCESS_POLLHANDLER:RainbowBS.hPROCESS_PT_SPAWN:RainbowBS.hPROCESS_SIGNAL_SEM:RainbowBS.hPROCESS_THREAD:RainbowBS.hPROCESS_WAIT_EVENT:RainbowBS.hPROCESS_WAIT_EVENT_UNTIL:RainbowBS.hPROCESS_WAIT_SEM:RainbowBS.hPROCESS_WAIT_UNTIL:RainbowBS.hPROCESS_WAIT_WHILE:RainbowBS.hPROCESS_YIELD:RainbowBS.hPROCESS_YIELD_UNTIL:RainbowBS.hPT_BEGIN:pt.hPT_END:pt.hPT_EXIT:pt.hPT_INIT:pt.hPT_RESTART:pt.hPT_SCHEDULE:pt.hPT_SEM_INIT:pt-sem.hPT_SEM_SIGNAL:pt-sem.hPT_SEM_WAIT:pt-sem.hPT_SPAWN:pt.hPT_THREAD:pt.h

Page 284: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

PT_WAIT_THREAD:pt.hPT_WAIT_UNTIL:pt.hPT_WAIT_WHILE:pt.hPT_YIELD:pt.hPT_YIELD_UNTIL:pt.h

-r-

RBS_DEBUG_ELSIF:RainbowBS.hRBS_DEBUG_ENDIF:RainbowBS.hRBS_DEBUG_ERROR:RainbowBS.hRBS_DEBUG_ERROR_FORMAT:RainbowBS.hRBS_DEBUG_IF:RainbowBS.hRBS_DEBUG_LOG:RainbowBS.hRBS_DEBUG_LOG_FORMAT:RainbowBS.hRBS_DEBUG_STA:RainbowBS.hRBS_DEBUG_WARN:RainbowBS.hRBS_DEBUG_WARN_FORMAT:RainbowBS.h

-s-

SEM:RainbowBS.hSEM_NAME:RainbowBS.h

Generatedby 1.8.9.1

Page 285: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

RainbowBS

RainbowBSManualv0.1.0WrittenbyQWQ([email protected])

RainbowBSDirectoryReference

DirectorydependencygraphforRainbowBS:

Page 286: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

Directoriesdirectory RBSSource

Generatedby 1.8.9.1

Page 287: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

RainbowBS RBSSource

RainbowBSManualv0.1.0WrittenbyQWQ([email protected])

RBSSourceDirectoryReference

DirectorydependencygraphforRBSSource:

Page 288: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

Directoriesdirectory Basedirectory Configdirectory Port

Page 289: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

Filesfile RainbowBS.h

Generatedby 1.8.9.1

Page 290: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

RainbowBS RBSSource Base

RainbowBSManualv0.1.0WrittenbyQWQ([email protected])

BaseDirectoryReference

DirectorydependencygraphforBase:

Page 291: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

Directoriesdirectory Processdirectory Protothreads

Page 292: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

Filesfile Convert.cfile Debug.cfile DMM.cfile MemOP.cfile System.c

Generatedby 1.8.9.1

Page 293: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

RainbowBS RBSSource Base Protothreads

RainbowBSManualv0.1.0WrittenbyQWQ([email protected])

ProtothreadsDirectoryReference

DirectorydependencygraphforProtothreads:

Page 294: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

Filesfile lc-addrlabels.hfile lc-switch.hfile lc.hfile pt-sem.hfile pt.h

Generatedby 1.8.9.1

Page 295: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

RainbowBS RBSSource Port

RainbowBSManualv0.1.0WrittenbyQWQ([email protected])

PortDirectoryReference

DirectorydependencygraphforPort:

Page 296: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

Filesfile Port.cfile Port.h

Generatedby 1.8.9.1

Page 297: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

RainbowBS RBSSource Config

RainbowBSManualv0.1.0WrittenbyQWQ([email protected])

ConfigDirectoryReference

DirectorydependencygraphforConfig:

Page 298: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

Filesfile RainbowBSConf.h

Generatedby 1.8.9.1

Page 299: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

RainbowBS RBSSource Base Process

RainbowBSManualv0.1.0WrittenbyQWQ([email protected])

ProcessDirectoryReference

DirectorydependencygraphforProcess:

Page 300: RainbowBS Manual · RainbowBS(RBS) is an open-source base library developed for embedded systems especially with limit resources. RBS is written by C language in compliance with the

Filesfile etimer.cfile process.c

Generatedby 1.8.9.1