lib_AT91SAM7X128.h 170 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558
  1. //* ----------------------------------------------------------------------------
  2. //* ATMEL Microcontroller Software Support - ROUSSET -
  3. //* ----------------------------------------------------------------------------
  4. //* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
  5. //* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  6. //* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
  7. //* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
  8. //* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  9. //* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  10. //* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  11. //* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  12. //* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  13. //* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  14. //* ----------------------------------------------------------------------------
  15. //* File Name : lib_AT91SAM7X128.h
  16. //* Object : AT91SAM7X128 inlined functions
  17. //* Generated : AT91 SW Application Group 05/20/2005 (16:22:23)
  18. //*
  19. //* CVS Reference : /lib_dbgu.h/1.1/Fri Jan 31 12:18:40 2003//
  20. //* CVS Reference : /lib_pmc_SAM7X.h/1.1/Tue Feb 1 08:32:10 2005//
  21. //* CVS Reference : /lib_VREG_6085B.h/1.1/Tue Feb 1 16:20:47 2005//
  22. //* CVS Reference : /lib_rstc_6098A.h/1.1/Wed Oct 6 10:39:20 2004//
  23. //* CVS Reference : /lib_ssc.h/1.4/Fri Jan 31 12:19:20 2003//
  24. //* CVS Reference : /lib_wdtc_6080A.h/1.1/Wed Oct 6 10:38:30 2004//
  25. //* CVS Reference : /lib_usart.h/1.5/Thu Nov 21 16:01:54 2002//
  26. //* CVS Reference : /lib_spi2.h/1.1/Mon Aug 25 14:23:52 2003//
  27. //* CVS Reference : /lib_pitc_6079A.h/1.2/Tue Nov 9 14:43:56 2004//
  28. //* CVS Reference : /lib_aic_6075b.h/1.1/Fri May 20 14:01:19 2005//
  29. //* CVS Reference : /lib_aes_6149a.h/1.1/Mon Jan 17 07:43:09 2005//
  30. //* CVS Reference : /lib_twi.h/1.3/Mon Jul 19 14:27:58 2004//
  31. //* CVS Reference : /lib_adc.h/1.6/Fri Oct 17 09:12:38 2003//
  32. //* CVS Reference : /lib_rttc_6081A.h/1.1/Wed Oct 6 10:39:38 2004//
  33. //* CVS Reference : /lib_udp.h/1.4/Wed Feb 16 08:39:34 2005//
  34. //* CVS Reference : /lib_des3_6150a.h/1.1/Mon Jan 17 09:19:19 2005//
  35. //* CVS Reference : /lib_tc_1753b.h/1.1/Fri Jan 31 12:20:02 2003//
  36. //* CVS Reference : /lib_MC_SAM7X.h/1.1/Thu Mar 25 15:19:14 2004//
  37. //* CVS Reference : /lib_pio.h/1.3/Fri Jan 31 12:18:56 2003//
  38. //* CVS Reference : /lib_can_AT91.h/1.4/Fri Oct 17 09:12:50 2003//
  39. //* CVS Reference : /lib_PWM_SAM.h/1.3/Thu Jan 22 10:10:50 2004//
  40. //* CVS Reference : /lib_pdc.h/1.2/Tue Jul 2 13:29:40 2002//
  41. //* ----------------------------------------------------------------------------
  42. #ifndef lib_AT91SAM7X128_H
  43. #define lib_AT91SAM7X128_H
  44. /* *****************************************************************************
  45. SOFTWARE API FOR AIC
  46. ***************************************************************************** */
  47. #define AT91C_AIC_BRANCH_OPCODE ((void (*) ()) 0xE51FFF20) // ldr, pc, [pc, #-&F20]
  48. //*----------------------------------------------------------------------------
  49. //* \fn AT91F_AIC_ConfigureIt
  50. //* \brief Interrupt Handler Initialization
  51. //*----------------------------------------------------------------------------
  52. __inline unsigned int AT91F_AIC_ConfigureIt (
  53. AT91PS_AIC pAic, // \arg pointer to the AIC registers
  54. unsigned int irq_id, // \arg interrupt number to initialize
  55. unsigned int priority, // \arg priority to give to the interrupt
  56. unsigned int src_type, // \arg activation and sense of activation
  57. void (*newHandler) (void) ) // \arg address of the interrupt handler
  58. {
  59. unsigned int oldHandler;
  60. unsigned int mask ;
  61. oldHandler = pAic->AIC_SVR[irq_id];
  62. mask = 0x1 << irq_id ;
  63. //* Disable the interrupt on the interrupt controller
  64. pAic->AIC_IDCR = mask ;
  65. //* Save the interrupt handler routine pointer and the interrupt priority
  66. pAic->AIC_SVR[irq_id] = (unsigned int) newHandler ;
  67. //* Store the Source Mode Register
  68. pAic->AIC_SMR[irq_id] = src_type | priority ;
  69. //* Clear the interrupt on the interrupt controller
  70. pAic->AIC_ICCR = mask ;
  71. return oldHandler;
  72. }
  73. //*----------------------------------------------------------------------------
  74. //* \fn AT91F_AIC_EnableIt
  75. //* \brief Enable corresponding IT number
  76. //*----------------------------------------------------------------------------
  77. __inline void AT91F_AIC_EnableIt (
  78. AT91PS_AIC pAic, // \arg pointer to the AIC registers
  79. unsigned int irq_id ) // \arg interrupt number to initialize
  80. {
  81. //* Enable the interrupt on the interrupt controller
  82. pAic->AIC_IECR = 0x1 << irq_id ;
  83. }
  84. //*----------------------------------------------------------------------------
  85. //* \fn AT91F_AIC_DisableIt
  86. //* \brief Disable corresponding IT number
  87. //*----------------------------------------------------------------------------
  88. __inline void AT91F_AIC_DisableIt (
  89. AT91PS_AIC pAic, // \arg pointer to the AIC registers
  90. unsigned int irq_id ) // \arg interrupt number to initialize
  91. {
  92. unsigned int mask = 0x1 << irq_id;
  93. //* Disable the interrupt on the interrupt controller
  94. pAic->AIC_IDCR = mask ;
  95. //* Clear the interrupt on the Interrupt Controller ( if one is pending )
  96. pAic->AIC_ICCR = mask ;
  97. }
  98. //*----------------------------------------------------------------------------
  99. //* \fn AT91F_AIC_ClearIt
  100. //* \brief Clear corresponding IT number
  101. //*----------------------------------------------------------------------------
  102. __inline void AT91F_AIC_ClearIt (
  103. AT91PS_AIC pAic, // \arg pointer to the AIC registers
  104. unsigned int irq_id) // \arg interrupt number to initialize
  105. {
  106. //* Clear the interrupt on the Interrupt Controller ( if one is pending )
  107. pAic->AIC_ICCR = (0x1 << irq_id);
  108. }
  109. //*----------------------------------------------------------------------------
  110. //* \fn AT91F_AIC_AcknowledgeIt
  111. //* \brief Acknowledge corresponding IT number
  112. //*----------------------------------------------------------------------------
  113. __inline void AT91F_AIC_AcknowledgeIt (
  114. AT91PS_AIC pAic) // \arg pointer to the AIC registers
  115. {
  116. pAic->AIC_EOICR = pAic->AIC_EOICR;
  117. }
  118. //*----------------------------------------------------------------------------
  119. //* \fn AT91F_AIC_SetExceptionVector
  120. //* \brief Configure vector handler
  121. //*----------------------------------------------------------------------------
  122. __inline unsigned int AT91F_AIC_SetExceptionVector (
  123. unsigned int *pVector, // \arg pointer to the AIC registers
  124. void (*Handler) () ) // \arg Interrupt Handler
  125. {
  126. unsigned int oldVector = *pVector;
  127. if ((unsigned int) Handler == (unsigned int) AT91C_AIC_BRANCH_OPCODE)
  128. *pVector = (unsigned int) AT91C_AIC_BRANCH_OPCODE;
  129. else
  130. *pVector = (((((unsigned int) Handler) - ((unsigned int) pVector) - 0x8) >> 2) & 0x00FFFFFF) | 0xEA000000;
  131. return oldVector;
  132. }
  133. //*----------------------------------------------------------------------------
  134. //* \fn AT91F_AIC_Trig
  135. //* \brief Trig an IT
  136. //*----------------------------------------------------------------------------
  137. __inline void AT91F_AIC_Trig (
  138. AT91PS_AIC pAic, // \arg pointer to the AIC registers
  139. unsigned int irq_id) // \arg interrupt number
  140. {
  141. pAic->AIC_ISCR = (0x1 << irq_id) ;
  142. }
  143. //*----------------------------------------------------------------------------
  144. //* \fn AT91F_AIC_IsActive
  145. //* \brief Test if an IT is active
  146. //*----------------------------------------------------------------------------
  147. __inline unsigned int AT91F_AIC_IsActive (
  148. AT91PS_AIC pAic, // \arg pointer to the AIC registers
  149. unsigned int irq_id) // \arg Interrupt Number
  150. {
  151. return (pAic->AIC_ISR & (0x1 << irq_id));
  152. }
  153. //*----------------------------------------------------------------------------
  154. //* \fn AT91F_AIC_IsPending
  155. //* \brief Test if an IT is pending
  156. //*----------------------------------------------------------------------------
  157. __inline unsigned int AT91F_AIC_IsPending (
  158. AT91PS_AIC pAic, // \arg pointer to the AIC registers
  159. unsigned int irq_id) // \arg Interrupt Number
  160. {
  161. return (pAic->AIC_IPR & (0x1 << irq_id));
  162. }
  163. //*----------------------------------------------------------------------------
  164. //* \fn AT91F_AIC_Open
  165. //* \brief Set exception vectors and AIC registers to default values
  166. //*----------------------------------------------------------------------------
  167. __inline void AT91F_AIC_Open(
  168. AT91PS_AIC pAic, // \arg pointer to the AIC registers
  169. void (*IrqHandler) (), // \arg Default IRQ vector exception
  170. void (*FiqHandler) (), // \arg Default FIQ vector exception
  171. void (*DefaultHandler) (), // \arg Default Handler set in ISR
  172. void (*SpuriousHandler) (), // \arg Default Spurious Handler
  173. unsigned int protectMode) // \arg Debug Control Register
  174. {
  175. int i;
  176. // Disable all interrupts and set IVR to the default handler
  177. for (i = 0; i < 32; ++i) {
  178. AT91F_AIC_DisableIt(pAic, i);
  179. AT91F_AIC_ConfigureIt(pAic, i, AT91C_AIC_PRIOR_LOWEST, AT91C_AIC_SRCTYPE_HIGH_LEVEL, DefaultHandler);
  180. }
  181. // Set the IRQ exception vector
  182. AT91F_AIC_SetExceptionVector((unsigned int *) 0x18, IrqHandler);
  183. // Set the Fast Interrupt exception vector
  184. AT91F_AIC_SetExceptionVector((unsigned int *) 0x1C, FiqHandler);
  185. pAic->AIC_SPU = (unsigned int) SpuriousHandler;
  186. pAic->AIC_DCR = protectMode;
  187. }
  188. /* *****************************************************************************
  189. SOFTWARE API FOR PDC
  190. ***************************************************************************** */
  191. //*----------------------------------------------------------------------------
  192. //* \fn AT91F_PDC_SetNextRx
  193. //* \brief Set the next receive transfer descriptor
  194. //*----------------------------------------------------------------------------
  195. __inline void AT91F_PDC_SetNextRx (
  196. AT91PS_PDC pPDC, // \arg pointer to a PDC controller
  197. char *address, // \arg address to the next bloc to be received
  198. unsigned int bytes) // \arg number of bytes to be received
  199. {
  200. pPDC->PDC_RNPR = (unsigned int) address;
  201. pPDC->PDC_RNCR = bytes;
  202. }
  203. //*----------------------------------------------------------------------------
  204. //* \fn AT91F_PDC_SetNextTx
  205. //* \brief Set the next transmit transfer descriptor
  206. //*----------------------------------------------------------------------------
  207. __inline void AT91F_PDC_SetNextTx (
  208. AT91PS_PDC pPDC, // \arg pointer to a PDC controller
  209. char *address, // \arg address to the next bloc to be transmitted
  210. unsigned int bytes) // \arg number of bytes to be transmitted
  211. {
  212. pPDC->PDC_TNPR = (unsigned int) address;
  213. pPDC->PDC_TNCR = bytes;
  214. }
  215. //*----------------------------------------------------------------------------
  216. //* \fn AT91F_PDC_SetRx
  217. //* \brief Set the receive transfer descriptor
  218. //*----------------------------------------------------------------------------
  219. __inline void AT91F_PDC_SetRx (
  220. AT91PS_PDC pPDC, // \arg pointer to a PDC controller
  221. char *address, // \arg address to the next bloc to be received
  222. unsigned int bytes) // \arg number of bytes to be received
  223. {
  224. pPDC->PDC_RPR = (unsigned int) address;
  225. pPDC->PDC_RCR = bytes;
  226. }
  227. //*----------------------------------------------------------------------------
  228. //* \fn AT91F_PDC_SetTx
  229. //* \brief Set the transmit transfer descriptor
  230. //*----------------------------------------------------------------------------
  231. __inline void AT91F_PDC_SetTx (
  232. AT91PS_PDC pPDC, // \arg pointer to a PDC controller
  233. char *address, // \arg address to the next bloc to be transmitted
  234. unsigned int bytes) // \arg number of bytes to be transmitted
  235. {
  236. pPDC->PDC_TPR = (unsigned int) address;
  237. pPDC->PDC_TCR = bytes;
  238. }
  239. //*----------------------------------------------------------------------------
  240. //* \fn AT91F_PDC_EnableTx
  241. //* \brief Enable transmit
  242. //*----------------------------------------------------------------------------
  243. __inline void AT91F_PDC_EnableTx (
  244. AT91PS_PDC pPDC ) // \arg pointer to a PDC controller
  245. {
  246. pPDC->PDC_PTCR = AT91C_PDC_TXTEN;
  247. }
  248. //*----------------------------------------------------------------------------
  249. //* \fn AT91F_PDC_EnableRx
  250. //* \brief Enable receive
  251. //*----------------------------------------------------------------------------
  252. __inline void AT91F_PDC_EnableRx (
  253. AT91PS_PDC pPDC ) // \arg pointer to a PDC controller
  254. {
  255. pPDC->PDC_PTCR = AT91C_PDC_RXTEN;
  256. }
  257. //*----------------------------------------------------------------------------
  258. //* \fn AT91F_PDC_DisableTx
  259. //* \brief Disable transmit
  260. //*----------------------------------------------------------------------------
  261. __inline void AT91F_PDC_DisableTx (
  262. AT91PS_PDC pPDC ) // \arg pointer to a PDC controller
  263. {
  264. pPDC->PDC_PTCR = AT91C_PDC_TXTDIS;
  265. }
  266. //*----------------------------------------------------------------------------
  267. //* \fn AT91F_PDC_DisableRx
  268. //* \brief Disable receive
  269. //*----------------------------------------------------------------------------
  270. __inline void AT91F_PDC_DisableRx (
  271. AT91PS_PDC pPDC ) // \arg pointer to a PDC controller
  272. {
  273. pPDC->PDC_PTCR = AT91C_PDC_RXTDIS;
  274. }
  275. //*----------------------------------------------------------------------------
  276. //* \fn AT91F_PDC_IsTxEmpty
  277. //* \brief Test if the current transfer descriptor has been sent
  278. //*----------------------------------------------------------------------------
  279. __inline int AT91F_PDC_IsTxEmpty ( // \return return 1 if transfer is complete
  280. AT91PS_PDC pPDC ) // \arg pointer to a PDC controller
  281. {
  282. return !(pPDC->PDC_TCR);
  283. }
  284. //*----------------------------------------------------------------------------
  285. //* \fn AT91F_PDC_IsNextTxEmpty
  286. //* \brief Test if the next transfer descriptor has been moved to the current td
  287. //*----------------------------------------------------------------------------
  288. __inline int AT91F_PDC_IsNextTxEmpty ( // \return return 1 if transfer is complete
  289. AT91PS_PDC pPDC ) // \arg pointer to a PDC controller
  290. {
  291. return !(pPDC->PDC_TNCR);
  292. }
  293. //*----------------------------------------------------------------------------
  294. //* \fn AT91F_PDC_IsRxEmpty
  295. //* \brief Test if the current transfer descriptor has been filled
  296. //*----------------------------------------------------------------------------
  297. __inline int AT91F_PDC_IsRxEmpty ( // \return return 1 if transfer is complete
  298. AT91PS_PDC pPDC ) // \arg pointer to a PDC controller
  299. {
  300. return !(pPDC->PDC_RCR);
  301. }
  302. //*----------------------------------------------------------------------------
  303. //* \fn AT91F_PDC_IsNextRxEmpty
  304. //* \brief Test if the next transfer descriptor has been moved to the current td
  305. //*----------------------------------------------------------------------------
  306. __inline int AT91F_PDC_IsNextRxEmpty ( // \return return 1 if transfer is complete
  307. AT91PS_PDC pPDC ) // \arg pointer to a PDC controller
  308. {
  309. return !(pPDC->PDC_RNCR);
  310. }
  311. //*----------------------------------------------------------------------------
  312. //* \fn AT91F_PDC_Open
  313. //* \brief Open PDC: disable TX and RX reset transfer descriptors, re-enable RX and TX
  314. //*----------------------------------------------------------------------------
  315. __inline void AT91F_PDC_Open (
  316. AT91PS_PDC pPDC) // \arg pointer to a PDC controller
  317. {
  318. //* Disable the RX and TX PDC transfer requests
  319. AT91F_PDC_DisableRx(pPDC);
  320. AT91F_PDC_DisableTx(pPDC);
  321. //* Reset all Counter register Next buffer first
  322. AT91F_PDC_SetNextTx(pPDC, (char *) 0, 0);
  323. AT91F_PDC_SetNextRx(pPDC, (char *) 0, 0);
  324. AT91F_PDC_SetTx(pPDC, (char *) 0, 0);
  325. AT91F_PDC_SetRx(pPDC, (char *) 0, 0);
  326. //* Enable the RX and TX PDC transfer requests
  327. AT91F_PDC_EnableRx(pPDC);
  328. AT91F_PDC_EnableTx(pPDC);
  329. }
  330. //*----------------------------------------------------------------------------
  331. //* \fn AT91F_PDC_Close
  332. //* \brief Close PDC: disable TX and RX reset transfer descriptors
  333. //*----------------------------------------------------------------------------
  334. __inline void AT91F_PDC_Close (
  335. AT91PS_PDC pPDC) // \arg pointer to a PDC controller
  336. {
  337. //* Disable the RX and TX PDC transfer requests
  338. AT91F_PDC_DisableRx(pPDC);
  339. AT91F_PDC_DisableTx(pPDC);
  340. //* Reset all Counter register Next buffer first
  341. AT91F_PDC_SetNextTx(pPDC, (char *) 0, 0);
  342. AT91F_PDC_SetNextRx(pPDC, (char *) 0, 0);
  343. AT91F_PDC_SetTx(pPDC, (char *) 0, 0);
  344. AT91F_PDC_SetRx(pPDC, (char *) 0, 0);
  345. }
  346. //*----------------------------------------------------------------------------
  347. //* \fn AT91F_PDC_SendFrame
  348. //* \brief Close PDC: disable TX and RX reset transfer descriptors
  349. //*----------------------------------------------------------------------------
  350. __inline unsigned int AT91F_PDC_SendFrame(
  351. AT91PS_PDC pPDC,
  352. char *pBuffer,
  353. unsigned int szBuffer,
  354. char *pNextBuffer,
  355. unsigned int szNextBuffer )
  356. {
  357. if (AT91F_PDC_IsTxEmpty(pPDC)) {
  358. //* Buffer and next buffer can be initialized
  359. AT91F_PDC_SetTx(pPDC, pBuffer, szBuffer);
  360. AT91F_PDC_SetNextTx(pPDC, pNextBuffer, szNextBuffer);
  361. return 2;
  362. }
  363. else if (AT91F_PDC_IsNextTxEmpty(pPDC)) {
  364. //* Only one buffer can be initialized
  365. AT91F_PDC_SetNextTx(pPDC, pBuffer, szBuffer);
  366. return 1;
  367. }
  368. else {
  369. //* All buffer are in use...
  370. return 0;
  371. }
  372. }
  373. //*----------------------------------------------------------------------------
  374. //* \fn AT91F_PDC_ReceiveFrame
  375. //* \brief Close PDC: disable TX and RX reset transfer descriptors
  376. //*----------------------------------------------------------------------------
  377. __inline unsigned int AT91F_PDC_ReceiveFrame (
  378. AT91PS_PDC pPDC,
  379. char *pBuffer,
  380. unsigned int szBuffer,
  381. char *pNextBuffer,
  382. unsigned int szNextBuffer )
  383. {
  384. if (AT91F_PDC_IsRxEmpty(pPDC)) {
  385. //* Buffer and next buffer can be initialized
  386. AT91F_PDC_SetRx(pPDC, pBuffer, szBuffer);
  387. AT91F_PDC_SetNextRx(pPDC, pNextBuffer, szNextBuffer);
  388. return 2;
  389. }
  390. else if (AT91F_PDC_IsNextRxEmpty(pPDC)) {
  391. //* Only one buffer can be initialized
  392. AT91F_PDC_SetNextRx(pPDC, pBuffer, szBuffer);
  393. return 1;
  394. }
  395. else {
  396. //* All buffer are in use...
  397. return 0;
  398. }
  399. }
  400. /* *****************************************************************************
  401. SOFTWARE API FOR DBGU
  402. ***************************************************************************** */
  403. //*----------------------------------------------------------------------------
  404. //* \fn AT91F_DBGU_InterruptEnable
  405. //* \brief Enable DBGU Interrupt
  406. //*----------------------------------------------------------------------------
  407. __inline void AT91F_DBGU_InterruptEnable(
  408. AT91PS_DBGU pDbgu, // \arg pointer to a DBGU controller
  409. unsigned int flag) // \arg dbgu interrupt to be enabled
  410. {
  411. pDbgu->DBGU_IER = flag;
  412. }
  413. //*----------------------------------------------------------------------------
  414. //* \fn AT91F_DBGU_InterruptDisable
  415. //* \brief Disable DBGU Interrupt
  416. //*----------------------------------------------------------------------------
  417. __inline void AT91F_DBGU_InterruptDisable(
  418. AT91PS_DBGU pDbgu, // \arg pointer to a DBGU controller
  419. unsigned int flag) // \arg dbgu interrupt to be disabled
  420. {
  421. pDbgu->DBGU_IDR = flag;
  422. }
  423. //*----------------------------------------------------------------------------
  424. //* \fn AT91F_DBGU_GetInterruptMaskStatus
  425. //* \brief Return DBGU Interrupt Mask Status
  426. //*----------------------------------------------------------------------------
  427. __inline unsigned int AT91F_DBGU_GetInterruptMaskStatus( // \return DBGU Interrupt Mask Status
  428. AT91PS_DBGU pDbgu) // \arg pointer to a DBGU controller
  429. {
  430. return pDbgu->DBGU_IMR;
  431. }
  432. //*----------------------------------------------------------------------------
  433. //* \fn AT91F_DBGU_IsInterruptMasked
  434. //* \brief Test if DBGU Interrupt is Masked
  435. //*----------------------------------------------------------------------------
  436. __inline int AT91F_DBGU_IsInterruptMasked(
  437. AT91PS_DBGU pDbgu, // \arg pointer to a DBGU controller
  438. unsigned int flag) // \arg flag to be tested
  439. {
  440. return (AT91F_DBGU_GetInterruptMaskStatus(pDbgu) & flag);
  441. }
  442. /* *****************************************************************************
  443. SOFTWARE API FOR PIO
  444. ***************************************************************************** */
  445. //*----------------------------------------------------------------------------
  446. //* \fn AT91F_PIO_CfgPeriph
  447. //* \brief Enable pins to be drived by peripheral
  448. //*----------------------------------------------------------------------------
  449. __inline void AT91F_PIO_CfgPeriph(
  450. AT91PS_PIO pPio, // \arg pointer to a PIO controller
  451. unsigned int periphAEnable, // \arg PERIPH A to enable
  452. unsigned int periphBEnable) // \arg PERIPH B to enable
  453. {
  454. pPio->PIO_ASR = periphAEnable;
  455. pPio->PIO_BSR = periphBEnable;
  456. pPio->PIO_PDR = (periphAEnable | periphBEnable); // Set in Periph mode
  457. }
  458. //*----------------------------------------------------------------------------
  459. //* \fn AT91F_PIO_CfgOutput
  460. //* \brief Enable PIO in output mode
  461. //*----------------------------------------------------------------------------
  462. __inline void AT91F_PIO_CfgOutput(
  463. AT91PS_PIO pPio, // \arg pointer to a PIO controller
  464. unsigned int pioEnable) // \arg PIO to be enabled
  465. {
  466. pPio->PIO_PER = pioEnable; // Set in PIO mode
  467. pPio->PIO_OER = pioEnable; // Configure in Output
  468. }
  469. //*----------------------------------------------------------------------------
  470. //* \fn AT91F_PIO_CfgInput
  471. //* \brief Enable PIO in input mode
  472. //*----------------------------------------------------------------------------
  473. __inline void AT91F_PIO_CfgInput(
  474. AT91PS_PIO pPio, // \arg pointer to a PIO controller
  475. unsigned int inputEnable) // \arg PIO to be enabled
  476. {
  477. // Disable output
  478. pPio->PIO_ODR = inputEnable;
  479. pPio->PIO_PER = inputEnable;
  480. }
  481. //*----------------------------------------------------------------------------
  482. //* \fn AT91F_PIO_CfgOpendrain
  483. //* \brief Configure PIO in open drain
  484. //*----------------------------------------------------------------------------
  485. __inline void AT91F_PIO_CfgOpendrain(
  486. AT91PS_PIO pPio, // \arg pointer to a PIO controller
  487. unsigned int multiDrvEnable) // \arg pio to be configured in open drain
  488. {
  489. // Configure the multi-drive option
  490. pPio->PIO_MDDR = ~multiDrvEnable;
  491. pPio->PIO_MDER = multiDrvEnable;
  492. }
  493. //*----------------------------------------------------------------------------
  494. //* \fn AT91F_PIO_CfgPullup
  495. //* \brief Enable pullup on PIO
  496. //*----------------------------------------------------------------------------
  497. __inline void AT91F_PIO_CfgPullup(
  498. AT91PS_PIO pPio, // \arg pointer to a PIO controller
  499. unsigned int pullupEnable) // \arg enable pullup on PIO
  500. {
  501. // Connect or not Pullup
  502. pPio->PIO_PPUDR = ~pullupEnable;
  503. pPio->PIO_PPUER = pullupEnable;
  504. }
  505. //*----------------------------------------------------------------------------
  506. //* \fn AT91F_PIO_CfgDirectDrive
  507. //* \brief Enable direct drive on PIO
  508. //*----------------------------------------------------------------------------
  509. __inline void AT91F_PIO_CfgDirectDrive(
  510. AT91PS_PIO pPio, // \arg pointer to a PIO controller
  511. unsigned int directDrive) // \arg PIO to be configured with direct drive
  512. {
  513. // Configure the Direct Drive
  514. pPio->PIO_OWDR = ~directDrive;
  515. pPio->PIO_OWER = directDrive;
  516. }
  517. //*----------------------------------------------------------------------------
  518. //* \fn AT91F_PIO_CfgInputFilter
  519. //* \brief Enable input filter on input PIO
  520. //*----------------------------------------------------------------------------
  521. __inline void AT91F_PIO_CfgInputFilter(
  522. AT91PS_PIO pPio, // \arg pointer to a PIO controller
  523. unsigned int inputFilter) // \arg PIO to be configured with input filter
  524. {
  525. // Configure the Direct Drive
  526. pPio->PIO_IFDR = ~inputFilter;
  527. pPio->PIO_IFER = inputFilter;
  528. }
  529. //*----------------------------------------------------------------------------
  530. //* \fn AT91F_PIO_GetInput
  531. //* \brief Return PIO input value
  532. //*----------------------------------------------------------------------------
  533. __inline unsigned int AT91F_PIO_GetInput( // \return PIO input
  534. AT91PS_PIO pPio) // \arg pointer to a PIO controller
  535. {
  536. return pPio->PIO_PDSR;
  537. }
  538. //*----------------------------------------------------------------------------
  539. //* \fn AT91F_PIO_IsInputSet
  540. //* \brief Test if PIO is input flag is active
  541. //*----------------------------------------------------------------------------
  542. __inline int AT91F_PIO_IsInputSet(
  543. AT91PS_PIO pPio, // \arg pointer to a PIO controller
  544. unsigned int flag) // \arg flag to be tested
  545. {
  546. return (AT91F_PIO_GetInput(pPio) & flag);
  547. }
  548. //*----------------------------------------------------------------------------
  549. //* \fn AT91F_PIO_SetOutput
  550. //* \brief Set to 1 output PIO
  551. //*----------------------------------------------------------------------------
  552. __inline void AT91F_PIO_SetOutput(
  553. AT91PS_PIO pPio, // \arg pointer to a PIO controller
  554. unsigned int flag) // \arg output to be set
  555. {
  556. pPio->PIO_SODR = flag;
  557. }
  558. //*----------------------------------------------------------------------------
  559. //* \fn AT91F_PIO_ClearOutput
  560. //* \brief Set to 0 output PIO
  561. //*----------------------------------------------------------------------------
  562. __inline void AT91F_PIO_ClearOutput(
  563. AT91PS_PIO pPio, // \arg pointer to a PIO controller
  564. unsigned int flag) // \arg output to be cleared
  565. {
  566. pPio->PIO_CODR = flag;
  567. }
  568. //*----------------------------------------------------------------------------
  569. //* \fn AT91F_PIO_ForceOutput
  570. //* \brief Force output when Direct drive option is enabled
  571. //*----------------------------------------------------------------------------
  572. __inline void AT91F_PIO_ForceOutput(
  573. AT91PS_PIO pPio, // \arg pointer to a PIO controller
  574. unsigned int flag) // \arg output to be forced
  575. {
  576. pPio->PIO_ODSR = flag;
  577. }
  578. //*----------------------------------------------------------------------------
  579. //* \fn AT91F_PIO_Enable
  580. //* \brief Enable PIO
  581. //*----------------------------------------------------------------------------
  582. __inline void AT91F_PIO_Enable(
  583. AT91PS_PIO pPio, // \arg pointer to a PIO controller
  584. unsigned int flag) // \arg pio to be enabled
  585. {
  586. pPio->PIO_PER = flag;
  587. }
  588. //*----------------------------------------------------------------------------
  589. //* \fn AT91F_PIO_Disable
  590. //* \brief Disable PIO
  591. //*----------------------------------------------------------------------------
  592. __inline void AT91F_PIO_Disable(
  593. AT91PS_PIO pPio, // \arg pointer to a PIO controller
  594. unsigned int flag) // \arg pio to be disabled
  595. {
  596. pPio->PIO_PDR = flag;
  597. }
  598. //*----------------------------------------------------------------------------
  599. //* \fn AT91F_PIO_GetStatus
  600. //* \brief Return PIO Status
  601. //*----------------------------------------------------------------------------
  602. __inline unsigned int AT91F_PIO_GetStatus( // \return PIO Status
  603. AT91PS_PIO pPio) // \arg pointer to a PIO controller
  604. {
  605. return pPio->PIO_PSR;
  606. }
  607. //*----------------------------------------------------------------------------
  608. //* \fn AT91F_PIO_IsSet
  609. //* \brief Test if PIO is Set
  610. //*----------------------------------------------------------------------------
  611. __inline int AT91F_PIO_IsSet(
  612. AT91PS_PIO pPio, // \arg pointer to a PIO controller
  613. unsigned int flag) // \arg flag to be tested
  614. {
  615. return (AT91F_PIO_GetStatus(pPio) & flag);
  616. }
  617. //*----------------------------------------------------------------------------
  618. //* \fn AT91F_PIO_OutputEnable
  619. //* \brief Output Enable PIO
  620. //*----------------------------------------------------------------------------
  621. __inline void AT91F_PIO_OutputEnable(
  622. AT91PS_PIO pPio, // \arg pointer to a PIO controller
  623. unsigned int flag) // \arg pio output to be enabled
  624. {
  625. pPio->PIO_OER = flag;
  626. }
  627. //*----------------------------------------------------------------------------
  628. //* \fn AT91F_PIO_OutputDisable
  629. //* \brief Output Enable PIO
  630. //*----------------------------------------------------------------------------
  631. __inline void AT91F_PIO_OutputDisable(
  632. AT91PS_PIO pPio, // \arg pointer to a PIO controller
  633. unsigned int flag) // \arg pio output to be disabled
  634. {
  635. pPio->PIO_ODR = flag;
  636. }
  637. //*----------------------------------------------------------------------------
  638. //* \fn AT91F_PIO_GetOutputStatus
  639. //* \brief Return PIO Output Status
  640. //*----------------------------------------------------------------------------
  641. __inline unsigned int AT91F_PIO_GetOutputStatus( // \return PIO Output Status
  642. AT91PS_PIO pPio) // \arg pointer to a PIO controller
  643. {
  644. return pPio->PIO_OSR;
  645. }
  646. //*----------------------------------------------------------------------------
  647. //* \fn AT91F_PIO_IsOuputSet
  648. //* \brief Test if PIO Output is Set
  649. //*----------------------------------------------------------------------------
  650. __inline int AT91F_PIO_IsOutputSet(
  651. AT91PS_PIO pPio, // \arg pointer to a PIO controller
  652. unsigned int flag) // \arg flag to be tested
  653. {
  654. return (AT91F_PIO_GetOutputStatus(pPio) & flag);
  655. }
  656. //*----------------------------------------------------------------------------
  657. //* \fn AT91F_PIO_InputFilterEnable
  658. //* \brief Input Filter Enable PIO
  659. //*----------------------------------------------------------------------------
  660. __inline void AT91F_PIO_InputFilterEnable(
  661. AT91PS_PIO pPio, // \arg pointer to a PIO controller
  662. unsigned int flag) // \arg pio input filter to be enabled
  663. {
  664. pPio->PIO_IFER = flag;
  665. }
  666. //*----------------------------------------------------------------------------
  667. //* \fn AT91F_PIO_InputFilterDisable
  668. //* \brief Input Filter Disable PIO
  669. //*----------------------------------------------------------------------------
  670. __inline void AT91F_PIO_InputFilterDisable(
  671. AT91PS_PIO pPio, // \arg pointer to a PIO controller
  672. unsigned int flag) // \arg pio input filter to be disabled
  673. {
  674. pPio->PIO_IFDR = flag;
  675. }
  676. //*----------------------------------------------------------------------------
  677. //* \fn AT91F_PIO_GetInputFilterStatus
  678. //* \brief Return PIO Input Filter Status
  679. //*----------------------------------------------------------------------------
  680. __inline unsigned int AT91F_PIO_GetInputFilterStatus( // \return PIO Input Filter Status
  681. AT91PS_PIO pPio) // \arg pointer to a PIO controller
  682. {
  683. return pPio->PIO_IFSR;
  684. }
  685. //*----------------------------------------------------------------------------
  686. //* \fn AT91F_PIO_IsInputFilterSet
  687. //* \brief Test if PIO Input filter is Set
  688. //*----------------------------------------------------------------------------
  689. __inline int AT91F_PIO_IsInputFilterSet(
  690. AT91PS_PIO pPio, // \arg pointer to a PIO controller
  691. unsigned int flag) // \arg flag to be tested
  692. {
  693. return (AT91F_PIO_GetInputFilterStatus(pPio) & flag);
  694. }
  695. //*----------------------------------------------------------------------------
  696. //* \fn AT91F_PIO_GetOutputDataStatus
  697. //* \brief Return PIO Output Data Status
  698. //*----------------------------------------------------------------------------
  699. __inline unsigned int AT91F_PIO_GetOutputDataStatus( // \return PIO Output Data Status
  700. AT91PS_PIO pPio) // \arg pointer to a PIO controller
  701. {
  702. return pPio->PIO_ODSR;
  703. }
  704. //*----------------------------------------------------------------------------
  705. //* \fn AT91F_PIO_InterruptEnable
  706. //* \brief Enable PIO Interrupt
  707. //*----------------------------------------------------------------------------
  708. __inline void AT91F_PIO_InterruptEnable(
  709. AT91PS_PIO pPio, // \arg pointer to a PIO controller
  710. unsigned int flag) // \arg pio interrupt to be enabled
  711. {
  712. pPio->PIO_IER = flag;
  713. }
  714. //*----------------------------------------------------------------------------
  715. //* \fn AT91F_PIO_InterruptDisable
  716. //* \brief Disable PIO Interrupt
  717. //*----------------------------------------------------------------------------
  718. __inline void AT91F_PIO_InterruptDisable(
  719. AT91PS_PIO pPio, // \arg pointer to a PIO controller
  720. unsigned int flag) // \arg pio interrupt to be disabled
  721. {
  722. pPio->PIO_IDR = flag;
  723. }
  724. //*----------------------------------------------------------------------------
  725. //* \fn AT91F_PIO_GetInterruptMaskStatus
  726. //* \brief Return PIO Interrupt Mask Status
  727. //*----------------------------------------------------------------------------
  728. __inline unsigned int AT91F_PIO_GetInterruptMaskStatus( // \return PIO Interrupt Mask Status
  729. AT91PS_PIO pPio) // \arg pointer to a PIO controller
  730. {
  731. return pPio->PIO_IMR;
  732. }
  733. //*----------------------------------------------------------------------------
  734. //* \fn AT91F_PIO_GetInterruptStatus
  735. //* \brief Return PIO Interrupt Status
  736. //*----------------------------------------------------------------------------
  737. __inline unsigned int AT91F_PIO_GetInterruptStatus( // \return PIO Interrupt Status
  738. AT91PS_PIO pPio) // \arg pointer to a PIO controller
  739. {
  740. return pPio->PIO_ISR;
  741. }
  742. //*----------------------------------------------------------------------------
  743. //* \fn AT91F_PIO_IsInterruptMasked
  744. //* \brief Test if PIO Interrupt is Masked
  745. //*----------------------------------------------------------------------------
  746. __inline int AT91F_PIO_IsInterruptMasked(
  747. AT91PS_PIO pPio, // \arg pointer to a PIO controller
  748. unsigned int flag) // \arg flag to be tested
  749. {
  750. return (AT91F_PIO_GetInterruptMaskStatus(pPio) & flag);
  751. }
  752. //*----------------------------------------------------------------------------
  753. //* \fn AT91F_PIO_IsInterruptSet
  754. //* \brief Test if PIO Interrupt is Set
  755. //*----------------------------------------------------------------------------
  756. __inline int AT91F_PIO_IsInterruptSet(
  757. AT91PS_PIO pPio, // \arg pointer to a PIO controller
  758. unsigned int flag) // \arg flag to be tested
  759. {
  760. return (AT91F_PIO_GetInterruptStatus(pPio) & flag);
  761. }
  762. //*----------------------------------------------------------------------------
  763. //* \fn AT91F_PIO_MultiDriverEnable
  764. //* \brief Multi Driver Enable PIO
  765. //*----------------------------------------------------------------------------
  766. __inline void AT91F_PIO_MultiDriverEnable(
  767. AT91PS_PIO pPio, // \arg pointer to a PIO controller
  768. unsigned int flag) // \arg pio to be enabled
  769. {
  770. pPio->PIO_MDER = flag;
  771. }
  772. //*----------------------------------------------------------------------------
  773. //* \fn AT91F_PIO_MultiDriverDisable
  774. //* \brief Multi Driver Disable PIO
  775. //*----------------------------------------------------------------------------
  776. __inline void AT91F_PIO_MultiDriverDisable(
  777. AT91PS_PIO pPio, // \arg pointer to a PIO controller
  778. unsigned int flag) // \arg pio to be disabled
  779. {
  780. pPio->PIO_MDDR = flag;
  781. }
  782. //*----------------------------------------------------------------------------
  783. //* \fn AT91F_PIO_GetMultiDriverStatus
  784. //* \brief Return PIO Multi Driver Status
  785. //*----------------------------------------------------------------------------
  786. __inline unsigned int AT91F_PIO_GetMultiDriverStatus( // \return PIO Multi Driver Status
  787. AT91PS_PIO pPio) // \arg pointer to a PIO controller
  788. {
  789. return pPio->PIO_MDSR;
  790. }
  791. //*----------------------------------------------------------------------------
  792. //* \fn AT91F_PIO_IsMultiDriverSet
  793. //* \brief Test if PIO MultiDriver is Set
  794. //*----------------------------------------------------------------------------
  795. __inline int AT91F_PIO_IsMultiDriverSet(
  796. AT91PS_PIO pPio, // \arg pointer to a PIO controller
  797. unsigned int flag) // \arg flag to be tested
  798. {
  799. return (AT91F_PIO_GetMultiDriverStatus(pPio) & flag);
  800. }
  801. //*----------------------------------------------------------------------------
  802. //* \fn AT91F_PIO_A_RegisterSelection
  803. //* \brief PIO A Register Selection
  804. //*----------------------------------------------------------------------------
  805. __inline void AT91F_PIO_A_RegisterSelection(
  806. AT91PS_PIO pPio, // \arg pointer to a PIO controller
  807. unsigned int flag) // \arg pio A register selection
  808. {
  809. pPio->PIO_ASR = flag;
  810. }
  811. //*----------------------------------------------------------------------------
  812. //* \fn AT91F_PIO_B_RegisterSelection
  813. //* \brief PIO B Register Selection
  814. //*----------------------------------------------------------------------------
  815. __inline void AT91F_PIO_B_RegisterSelection(
  816. AT91PS_PIO pPio, // \arg pointer to a PIO controller
  817. unsigned int flag) // \arg pio B register selection
  818. {
  819. pPio->PIO_BSR = flag;
  820. }
  821. //*----------------------------------------------------------------------------
  822. //* \fn AT91F_PIO_Get_AB_RegisterStatus
  823. //* \brief Return PIO Interrupt Status
  824. //*----------------------------------------------------------------------------
  825. __inline unsigned int AT91F_PIO_Get_AB_RegisterStatus( // \return PIO AB Register Status
  826. AT91PS_PIO pPio) // \arg pointer to a PIO controller
  827. {
  828. return pPio->PIO_ABSR;
  829. }
  830. //*----------------------------------------------------------------------------
  831. //* \fn AT91F_PIO_IsAB_RegisterSet
  832. //* \brief Test if PIO AB Register is Set
  833. //*----------------------------------------------------------------------------
  834. __inline int AT91F_PIO_IsAB_RegisterSet(
  835. AT91PS_PIO pPio, // \arg pointer to a PIO controller
  836. unsigned int flag) // \arg flag to be tested
  837. {
  838. return (AT91F_PIO_Get_AB_RegisterStatus(pPio) & flag);
  839. }
  840. //*----------------------------------------------------------------------------
  841. //* \fn AT91F_PIO_OutputWriteEnable
  842. //* \brief Output Write Enable PIO
  843. //*----------------------------------------------------------------------------
  844. __inline void AT91F_PIO_OutputWriteEnable(
  845. AT91PS_PIO pPio, // \arg pointer to a PIO controller
  846. unsigned int flag) // \arg pio output write to be enabled
  847. {
  848. pPio->PIO_OWER = flag;
  849. }
  850. //*----------------------------------------------------------------------------
  851. //* \fn AT91F_PIO_OutputWriteDisable
  852. //* \brief Output Write Disable PIO
  853. //*----------------------------------------------------------------------------
  854. __inline void AT91F_PIO_OutputWriteDisable(
  855. AT91PS_PIO pPio, // \arg pointer to a PIO controller
  856. unsigned int flag) // \arg pio output write to be disabled
  857. {
  858. pPio->PIO_OWDR = flag;
  859. }
  860. //*----------------------------------------------------------------------------
  861. //* \fn AT91F_PIO_GetOutputWriteStatus
  862. //* \brief Return PIO Output Write Status
  863. //*----------------------------------------------------------------------------
  864. __inline unsigned int AT91F_PIO_GetOutputWriteStatus( // \return PIO Output Write Status
  865. AT91PS_PIO pPio) // \arg pointer to a PIO controller
  866. {
  867. return pPio->PIO_OWSR;
  868. }
  869. //*----------------------------------------------------------------------------
  870. //* \fn AT91F_PIO_IsOutputWriteSet
  871. //* \brief Test if PIO OutputWrite is Set
  872. //*----------------------------------------------------------------------------
  873. __inline int AT91F_PIO_IsOutputWriteSet(
  874. AT91PS_PIO pPio, // \arg pointer to a PIO controller
  875. unsigned int flag) // \arg flag to be tested
  876. {
  877. return (AT91F_PIO_GetOutputWriteStatus(pPio) & flag);
  878. }
  879. //*----------------------------------------------------------------------------
  880. //* \fn AT91F_PIO_GetCfgPullup
  881. //* \brief Return PIO Configuration Pullup
  882. //*----------------------------------------------------------------------------
  883. __inline unsigned int AT91F_PIO_GetCfgPullup( // \return PIO Configuration Pullup
  884. AT91PS_PIO pPio) // \arg pointer to a PIO controller
  885. {
  886. return pPio->PIO_PPUSR;
  887. }
  888. //*----------------------------------------------------------------------------
  889. //* \fn AT91F_PIO_IsOutputDataStatusSet
  890. //* \brief Test if PIO Output Data Status is Set
  891. //*----------------------------------------------------------------------------
  892. __inline int AT91F_PIO_IsOutputDataStatusSet(
  893. AT91PS_PIO pPio, // \arg pointer to a PIO controller
  894. unsigned int flag) // \arg flag to be tested
  895. {
  896. return (AT91F_PIO_GetOutputDataStatus(pPio) & flag);
  897. }
  898. //*----------------------------------------------------------------------------
  899. //* \fn AT91F_PIO_IsCfgPullupStatusSet
  900. //* \brief Test if PIO Configuration Pullup Status is Set
  901. //*----------------------------------------------------------------------------
  902. __inline int AT91F_PIO_IsCfgPullupStatusSet(
  903. AT91PS_PIO pPio, // \arg pointer to a PIO controller
  904. unsigned int flag) // \arg flag to be tested
  905. {
  906. return (~AT91F_PIO_GetCfgPullup(pPio) & flag);
  907. }
  908. /* *****************************************************************************
  909. SOFTWARE API FOR PMC
  910. ***************************************************************************** */
  911. //*----------------------------------------------------------------------------
  912. //* \fn AT91F_PMC_CfgSysClkEnableReg
  913. //* \brief Configure the System Clock Enable Register of the PMC controller
  914. //*----------------------------------------------------------------------------
  915. __inline void AT91F_PMC_CfgSysClkEnableReg (
  916. AT91PS_PMC pPMC, // \arg pointer to PMC controller
  917. unsigned int mode)
  918. {
  919. //* Write to the SCER register
  920. pPMC->PMC_SCER = mode;
  921. }
  922. //*----------------------------------------------------------------------------
  923. //* \fn AT91F_PMC_CfgSysClkDisableReg
  924. //* \brief Configure the System Clock Disable Register of the PMC controller
  925. //*----------------------------------------------------------------------------
  926. __inline void AT91F_PMC_CfgSysClkDisableReg (
  927. AT91PS_PMC pPMC, // \arg pointer to PMC controller
  928. unsigned int mode)
  929. {
  930. //* Write to the SCDR register
  931. pPMC->PMC_SCDR = mode;
  932. }
  933. //*----------------------------------------------------------------------------
  934. //* \fn AT91F_PMC_GetSysClkStatusReg
  935. //* \brief Return the System Clock Status Register of the PMC controller
  936. //*----------------------------------------------------------------------------
  937. __inline unsigned int AT91F_PMC_GetSysClkStatusReg (
  938. AT91PS_PMC pPMC // pointer to a CAN controller
  939. )
  940. {
  941. return pPMC->PMC_SCSR;
  942. }
  943. //*----------------------------------------------------------------------------
  944. //* \fn AT91F_PMC_EnablePeriphClock
  945. //* \brief Enable peripheral clock
  946. //*----------------------------------------------------------------------------
  947. __inline void AT91F_PMC_EnablePeriphClock (
  948. AT91PS_PMC pPMC, // \arg pointer to PMC controller
  949. unsigned int periphIds) // \arg IDs of peripherals to enable
  950. {
  951. pPMC->PMC_PCER = periphIds;
  952. }
  953. //*----------------------------------------------------------------------------
  954. //* \fn AT91F_PMC_DisablePeriphClock
  955. //* \brief Disable peripheral clock
  956. //*----------------------------------------------------------------------------
  957. __inline void AT91F_PMC_DisablePeriphClock (
  958. AT91PS_PMC pPMC, // \arg pointer to PMC controller
  959. unsigned int periphIds) // \arg IDs of peripherals to enable
  960. {
  961. pPMC->PMC_PCDR = periphIds;
  962. }
  963. //*----------------------------------------------------------------------------
  964. //* \fn AT91F_PMC_GetPeriphClock
  965. //* \brief Get peripheral clock status
  966. //*----------------------------------------------------------------------------
  967. __inline unsigned int AT91F_PMC_GetPeriphClock (
  968. AT91PS_PMC pPMC) // \arg pointer to PMC controller
  969. {
  970. return pPMC->PMC_PCSR;
  971. }
  972. //*----------------------------------------------------------------------------
  973. //* \fn AT91F_CKGR_CfgMainOscillatorReg
  974. //* \brief Cfg the main oscillator
  975. //*----------------------------------------------------------------------------
  976. __inline void AT91F_CKGR_CfgMainOscillatorReg (
  977. AT91PS_CKGR pCKGR, // \arg pointer to CKGR controller
  978. unsigned int mode)
  979. {
  980. pCKGR->CKGR_MOR = mode;
  981. }
  982. //*----------------------------------------------------------------------------
  983. //* \fn AT91F_CKGR_GetMainOscillatorReg
  984. //* \brief Cfg the main oscillator
  985. //*----------------------------------------------------------------------------
  986. __inline unsigned int AT91F_CKGR_GetMainOscillatorReg (
  987. AT91PS_CKGR pCKGR) // \arg pointer to CKGR controller
  988. {
  989. return pCKGR->CKGR_MOR;
  990. }
  991. //*----------------------------------------------------------------------------
  992. //* \fn AT91F_CKGR_EnableMainOscillator
  993. //* \brief Enable the main oscillator
  994. //*----------------------------------------------------------------------------
  995. __inline void AT91F_CKGR_EnableMainOscillator(
  996. AT91PS_CKGR pCKGR) // \arg pointer to CKGR controller
  997. {
  998. pCKGR->CKGR_MOR |= AT91C_CKGR_MOSCEN;
  999. }
  1000. //*----------------------------------------------------------------------------
  1001. //* \fn AT91F_CKGR_DisableMainOscillator
  1002. //* \brief Disable the main oscillator
  1003. //*----------------------------------------------------------------------------
  1004. __inline void AT91F_CKGR_DisableMainOscillator (
  1005. AT91PS_CKGR pCKGR) // \arg pointer to CKGR controller
  1006. {
  1007. pCKGR->CKGR_MOR &= ~AT91C_CKGR_MOSCEN;
  1008. }
  1009. //*----------------------------------------------------------------------------
  1010. //* \fn AT91F_CKGR_CfgMainOscStartUpTime
  1011. //* \brief Cfg MOR Register according to the main osc startup time
  1012. //*----------------------------------------------------------------------------
  1013. __inline void AT91F_CKGR_CfgMainOscStartUpTime (
  1014. AT91PS_CKGR pCKGR, // \arg pointer to CKGR controller
  1015. unsigned int startup_time, // \arg main osc startup time in microsecond (us)
  1016. unsigned int slowClock) // \arg slowClock in Hz
  1017. {
  1018. pCKGR->CKGR_MOR &= ~AT91C_CKGR_OSCOUNT;
  1019. pCKGR->CKGR_MOR |= ((slowClock * startup_time)/(8*1000000)) << 8;
  1020. }
  1021. //*----------------------------------------------------------------------------
  1022. //* \fn AT91F_CKGR_GetMainClockFreqReg
  1023. //* \brief Cfg the main oscillator
  1024. //*----------------------------------------------------------------------------
  1025. __inline unsigned int AT91F_CKGR_GetMainClockFreqReg (
  1026. AT91PS_CKGR pCKGR) // \arg pointer to CKGR controller
  1027. {
  1028. return pCKGR->CKGR_MCFR;
  1029. }
  1030. //*----------------------------------------------------------------------------
  1031. //* \fn AT91F_CKGR_GetMainClock
  1032. //* \brief Return Main clock in Hz
  1033. //*----------------------------------------------------------------------------
  1034. __inline unsigned int AT91F_CKGR_GetMainClock (
  1035. AT91PS_CKGR pCKGR, // \arg pointer to CKGR controller
  1036. unsigned int slowClock) // \arg slowClock in Hz
  1037. {
  1038. return ((pCKGR->CKGR_MCFR & AT91C_CKGR_MAINF) * slowClock) >> 4;
  1039. }
  1040. //*----------------------------------------------------------------------------
  1041. //* \fn AT91F_PMC_CfgMCKReg
  1042. //* \brief Cfg Master Clock Register
  1043. //*----------------------------------------------------------------------------
  1044. __inline void AT91F_PMC_CfgMCKReg (
  1045. AT91PS_PMC pPMC, // \arg pointer to PMC controller
  1046. unsigned int mode)
  1047. {
  1048. pPMC->PMC_MCKR = mode;
  1049. }
  1050. //*----------------------------------------------------------------------------
  1051. //* \fn AT91F_PMC_GetMCKReg
  1052. //* \brief Return Master Clock Register
  1053. //*----------------------------------------------------------------------------
  1054. __inline unsigned int AT91F_PMC_GetMCKReg(
  1055. AT91PS_PMC pPMC) // \arg pointer to PMC controller
  1056. {
  1057. return pPMC->PMC_MCKR;
  1058. }
  1059. //*------------------------------------------------------------------------------
  1060. //* \fn AT91F_PMC_GetMasterClock
  1061. //* \brief Return master clock in Hz which correponds to processor clock for ARM7
  1062. //*------------------------------------------------------------------------------
  1063. __inline unsigned int AT91F_PMC_GetMasterClock (
  1064. AT91PS_PMC pPMC, // \arg pointer to PMC controller
  1065. AT91PS_CKGR pCKGR, // \arg pointer to CKGR controller
  1066. unsigned int slowClock) // \arg slowClock in Hz
  1067. {
  1068. unsigned int reg = pPMC->PMC_MCKR;
  1069. unsigned int prescaler = (1 << ((reg & AT91C_PMC_PRES) >> 2));
  1070. unsigned int pllDivider, pllMultiplier;
  1071. switch (reg & AT91C_PMC_CSS) {
  1072. case AT91C_PMC_CSS_SLOW_CLK: // Slow clock selected
  1073. return slowClock / prescaler;
  1074. case AT91C_PMC_CSS_MAIN_CLK: // Main clock is selected
  1075. return AT91F_CKGR_GetMainClock(pCKGR, slowClock) / prescaler;
  1076. case AT91C_PMC_CSS_PLL_CLK: // PLLB clock is selected
  1077. reg = pCKGR->CKGR_PLLR;
  1078. pllDivider = (reg & AT91C_CKGR_DIV);
  1079. pllMultiplier = ((reg & AT91C_CKGR_MUL) >> 16) + 1;
  1080. return AT91F_CKGR_GetMainClock(pCKGR, slowClock) / pllDivider * pllMultiplier / prescaler;
  1081. }
  1082. return 0;
  1083. }
  1084. //*----------------------------------------------------------------------------
  1085. //* \fn AT91F_PMC_EnablePCK
  1086. //* \brief Enable peripheral clock
  1087. //*----------------------------------------------------------------------------
  1088. __inline void AT91F_PMC_EnablePCK (
  1089. AT91PS_PMC pPMC, // \arg pointer to PMC controller
  1090. unsigned int pck, // \arg Peripheral clock identifier 0 .. 7
  1091. unsigned int mode)
  1092. {
  1093. pPMC->PMC_PCKR[pck] = mode;
  1094. pPMC->PMC_SCER = (1 << pck) << 8;
  1095. }
  1096. //*----------------------------------------------------------------------------
  1097. //* \fn AT91F_PMC_DisablePCK
  1098. //* \brief Enable peripheral clock
  1099. //*----------------------------------------------------------------------------
  1100. __inline void AT91F_PMC_DisablePCK (
  1101. AT91PS_PMC pPMC, // \arg pointer to PMC controller
  1102. unsigned int pck) // \arg Peripheral clock identifier 0 .. 7
  1103. {
  1104. pPMC->PMC_SCDR = (1 << pck) << 8;
  1105. }
  1106. //*----------------------------------------------------------------------------
  1107. //* \fn AT91F_PMC_EnableIt
  1108. //* \brief Enable PMC interrupt
  1109. //*----------------------------------------------------------------------------
  1110. __inline void AT91F_PMC_EnableIt (
  1111. AT91PS_PMC pPMC, // pointer to a PMC controller
  1112. unsigned int flag) // IT to be enabled
  1113. {
  1114. //* Write to the IER register
  1115. pPMC->PMC_IER = flag;
  1116. }
  1117. //*----------------------------------------------------------------------------
  1118. //* \fn AT91F_PMC_DisableIt
  1119. //* \brief Disable PMC interrupt
  1120. //*----------------------------------------------------------------------------
  1121. __inline void AT91F_PMC_DisableIt (
  1122. AT91PS_PMC pPMC, // pointer to a PMC controller
  1123. unsigned int flag) // IT to be disabled
  1124. {
  1125. //* Write to the IDR register
  1126. pPMC->PMC_IDR = flag;
  1127. }
  1128. //*----------------------------------------------------------------------------
  1129. //* \fn AT91F_PMC_GetStatus
  1130. //* \brief Return PMC Interrupt Status
  1131. //*----------------------------------------------------------------------------
  1132. __inline unsigned int AT91F_PMC_GetStatus( // \return PMC Interrupt Status
  1133. AT91PS_PMC pPMC) // pointer to a PMC controller
  1134. {
  1135. return pPMC->PMC_SR;
  1136. }
  1137. //*----------------------------------------------------------------------------
  1138. //* \fn AT91F_PMC_GetInterruptMaskStatus
  1139. //* \brief Return PMC Interrupt Mask Status
  1140. //*----------------------------------------------------------------------------
  1141. __inline unsigned int AT91F_PMC_GetInterruptMaskStatus( // \return PMC Interrupt Mask Status
  1142. AT91PS_PMC pPMC) // pointer to a PMC controller
  1143. {
  1144. return pPMC->PMC_IMR;
  1145. }
  1146. //*----------------------------------------------------------------------------
  1147. //* \fn AT91F_PMC_IsInterruptMasked
  1148. //* \brief Test if PMC Interrupt is Masked
  1149. //*----------------------------------------------------------------------------
  1150. __inline unsigned int AT91F_PMC_IsInterruptMasked(
  1151. AT91PS_PMC pPMC, // \arg pointer to a PMC controller
  1152. unsigned int flag) // \arg flag to be tested
  1153. {
  1154. return (AT91F_PMC_GetInterruptMaskStatus(pPMC) & flag);
  1155. }
  1156. //*----------------------------------------------------------------------------
  1157. //* \fn AT91F_PMC_IsStatusSet
  1158. //* \brief Test if PMC Status is Set
  1159. //*----------------------------------------------------------------------------
  1160. __inline unsigned int AT91F_PMC_IsStatusSet(
  1161. AT91PS_PMC pPMC, // \arg pointer to a PMC controller
  1162. unsigned int flag) // \arg flag to be tested
  1163. {
  1164. return (AT91F_PMC_GetStatus(pPMC) & flag);
  1165. }/* *****************************************************************************
  1166. SOFTWARE API FOR RSTC
  1167. ***************************************************************************** */
  1168. //*----------------------------------------------------------------------------
  1169. //* \fn AT91F_RSTSoftReset
  1170. //* \brief Start Software Reset
  1171. //*----------------------------------------------------------------------------
  1172. __inline void AT91F_RSTSoftReset(
  1173. AT91PS_RSTC pRSTC,
  1174. unsigned int reset)
  1175. {
  1176. pRSTC->RSTC_RCR = (0xA5000000 | reset);
  1177. }
  1178. //*----------------------------------------------------------------------------
  1179. //* \fn AT91F_RSTSetMode
  1180. //* \brief Set Reset Mode
  1181. //*----------------------------------------------------------------------------
  1182. __inline void AT91F_RSTSetMode(
  1183. AT91PS_RSTC pRSTC,
  1184. unsigned int mode)
  1185. {
  1186. pRSTC->RSTC_RMR = (0xA5000000 | mode);
  1187. }
  1188. //*----------------------------------------------------------------------------
  1189. //* \fn AT91F_RSTGetMode
  1190. //* \brief Get Reset Mode
  1191. //*----------------------------------------------------------------------------
  1192. __inline unsigned int AT91F_RSTGetMode(
  1193. AT91PS_RSTC pRSTC)
  1194. {
  1195. return (pRSTC->RSTC_RMR);
  1196. }
  1197. //*----------------------------------------------------------------------------
  1198. //* \fn AT91F_RSTGetStatus
  1199. //* \brief Get Reset Status
  1200. //*----------------------------------------------------------------------------
  1201. __inline unsigned int AT91F_RSTGetStatus(
  1202. AT91PS_RSTC pRSTC)
  1203. {
  1204. return (pRSTC->RSTC_RSR);
  1205. }
  1206. //*----------------------------------------------------------------------------
  1207. //* \fn AT91F_RSTIsSoftRstActive
  1208. //* \brief Return !=0 if software reset is still not completed
  1209. //*----------------------------------------------------------------------------
  1210. __inline unsigned int AT91F_RSTIsSoftRstActive(
  1211. AT91PS_RSTC pRSTC)
  1212. {
  1213. return ((pRSTC->RSTC_RSR) & AT91C_RSTC_SRCMP);
  1214. }
  1215. /* *****************************************************************************
  1216. SOFTWARE API FOR RTTC
  1217. ***************************************************************************** */
  1218. //*--------------------------------------------------------------------------------------
  1219. //* \fn AT91F_SetRTT_TimeBase()
  1220. //* \brief Set the RTT prescaler according to the TimeBase in ms
  1221. //*--------------------------------------------------------------------------------------
  1222. __inline unsigned int AT91F_RTTSetTimeBase(
  1223. AT91PS_RTTC pRTTC,
  1224. unsigned int ms)
  1225. {
  1226. if (ms > 2000)
  1227. return 1; // AT91C_TIME_OUT_OF_RANGE
  1228. pRTTC->RTTC_RTMR &= ~0xFFFF;
  1229. pRTTC->RTTC_RTMR |= (((ms << 15) /1000) & 0xFFFF);
  1230. return 0;
  1231. }
  1232. //*--------------------------------------------------------------------------------------
  1233. //* \fn AT91F_RTTSetPrescaler()
  1234. //* \brief Set the new prescaler value
  1235. //*--------------------------------------------------------------------------------------
  1236. __inline unsigned int AT91F_RTTSetPrescaler(
  1237. AT91PS_RTTC pRTTC,
  1238. unsigned int rtpres)
  1239. {
  1240. pRTTC->RTTC_RTMR &= ~0xFFFF;
  1241. pRTTC->RTTC_RTMR |= (rtpres & 0xFFFF);
  1242. return (pRTTC->RTTC_RTMR);
  1243. }
  1244. //*--------------------------------------------------------------------------------------
  1245. //* \fn AT91F_RTTRestart()
  1246. //* \brief Restart the RTT prescaler
  1247. //*--------------------------------------------------------------------------------------
  1248. __inline void AT91F_RTTRestart(
  1249. AT91PS_RTTC pRTTC)
  1250. {
  1251. pRTTC->RTTC_RTMR |= AT91C_RTTC_RTTRST;
  1252. }
  1253. //*--------------------------------------------------------------------------------------
  1254. //* \fn AT91F_RTT_SetAlarmINT()
  1255. //* \brief Enable RTT Alarm Interrupt
  1256. //*--------------------------------------------------------------------------------------
  1257. __inline void AT91F_RTTSetAlarmINT(
  1258. AT91PS_RTTC pRTTC)
  1259. {
  1260. pRTTC->RTTC_RTMR |= AT91C_RTTC_ALMIEN;
  1261. }
  1262. //*--------------------------------------------------------------------------------------
  1263. //* \fn AT91F_RTT_ClearAlarmINT()
  1264. //* \brief Disable RTT Alarm Interrupt
  1265. //*--------------------------------------------------------------------------------------
  1266. __inline void AT91F_RTTClearAlarmINT(
  1267. AT91PS_RTTC pRTTC)
  1268. {
  1269. pRTTC->RTTC_RTMR &= ~AT91C_RTTC_ALMIEN;
  1270. }
  1271. //*--------------------------------------------------------------------------------------
  1272. //* \fn AT91F_RTT_SetRttIncINT()
  1273. //* \brief Enable RTT INC Interrupt
  1274. //*--------------------------------------------------------------------------------------
  1275. __inline void AT91F_RTTSetRttIncINT(
  1276. AT91PS_RTTC pRTTC)
  1277. {
  1278. pRTTC->RTTC_RTMR |= AT91C_RTTC_RTTINCIEN;
  1279. }
  1280. //*--------------------------------------------------------------------------------------
  1281. //* \fn AT91F_RTT_ClearRttIncINT()
  1282. //* \brief Disable RTT INC Interrupt
  1283. //*--------------------------------------------------------------------------------------
  1284. __inline void AT91F_RTTClearRttIncINT(
  1285. AT91PS_RTTC pRTTC)
  1286. {
  1287. pRTTC->RTTC_RTMR &= ~AT91C_RTTC_RTTINCIEN;
  1288. }
  1289. //*--------------------------------------------------------------------------------------
  1290. //* \fn AT91F_RTT_SetAlarmValue()
  1291. //* \brief Set RTT Alarm Value
  1292. //*--------------------------------------------------------------------------------------
  1293. __inline void AT91F_RTTSetAlarmValue(
  1294. AT91PS_RTTC pRTTC, unsigned int alarm)
  1295. {
  1296. pRTTC->RTTC_RTAR = alarm;
  1297. }
  1298. //*--------------------------------------------------------------------------------------
  1299. //* \fn AT91F_RTT_GetAlarmValue()
  1300. //* \brief Get RTT Alarm Value
  1301. //*--------------------------------------------------------------------------------------
  1302. __inline unsigned int AT91F_RTTGetAlarmValue(
  1303. AT91PS_RTTC pRTTC)
  1304. {
  1305. return(pRTTC->RTTC_RTAR);
  1306. }
  1307. //*--------------------------------------------------------------------------------------
  1308. //* \fn AT91F_RTTGetStatus()
  1309. //* \brief Read the RTT status
  1310. //*--------------------------------------------------------------------------------------
  1311. __inline unsigned int AT91F_RTTGetStatus(
  1312. AT91PS_RTTC pRTTC)
  1313. {
  1314. return(pRTTC->RTTC_RTSR);
  1315. }
  1316. //*--------------------------------------------------------------------------------------
  1317. //* \fn AT91F_RTT_ReadValue()
  1318. //* \brief Read the RTT value
  1319. //*--------------------------------------------------------------------------------------
  1320. __inline unsigned int AT91F_RTTReadValue(
  1321. AT91PS_RTTC pRTTC)
  1322. {
  1323. register volatile unsigned int val1,val2;
  1324. do
  1325. {
  1326. val1 = pRTTC->RTTC_RTVR;
  1327. val2 = pRTTC->RTTC_RTVR;
  1328. }
  1329. while(val1 != val2);
  1330. return(val1);
  1331. }
  1332. /* *****************************************************************************
  1333. SOFTWARE API FOR PITC
  1334. ***************************************************************************** */
  1335. //*----------------------------------------------------------------------------
  1336. //* \fn AT91F_PITInit
  1337. //* \brief System timer init : period in µsecond, system clock freq in MHz
  1338. //*----------------------------------------------------------------------------
  1339. __inline void AT91F_PITInit(
  1340. AT91PS_PITC pPITC,
  1341. unsigned int period,
  1342. unsigned int pit_frequency)
  1343. {
  1344. pPITC->PITC_PIMR = period? (period * pit_frequency + 8) >> 4 : 0; // +8 to avoid %10 and /10
  1345. pPITC->PITC_PIMR |= AT91C_PITC_PITEN;
  1346. }
  1347. //*----------------------------------------------------------------------------
  1348. //* \fn AT91F_PITSetPIV
  1349. //* \brief Set the PIT Periodic Interval Value
  1350. //*----------------------------------------------------------------------------
  1351. __inline void AT91F_PITSetPIV(
  1352. AT91PS_PITC pPITC,
  1353. unsigned int piv)
  1354. {
  1355. pPITC->PITC_PIMR = piv | (pPITC->PITC_PIMR & (AT91C_PITC_PITEN | AT91C_PITC_PITIEN));
  1356. }
  1357. //*----------------------------------------------------------------------------
  1358. //* \fn AT91F_PITEnableInt
  1359. //* \brief Enable PIT periodic interrupt
  1360. //*----------------------------------------------------------------------------
  1361. __inline void AT91F_PITEnableInt(
  1362. AT91PS_PITC pPITC)
  1363. {
  1364. pPITC->PITC_PIMR |= AT91C_PITC_PITIEN;
  1365. }
  1366. //*----------------------------------------------------------------------------
  1367. //* \fn AT91F_PITDisableInt
  1368. //* \brief Disable PIT periodic interrupt
  1369. //*----------------------------------------------------------------------------
  1370. __inline void AT91F_PITDisableInt(
  1371. AT91PS_PITC pPITC)
  1372. {
  1373. pPITC->PITC_PIMR &= ~AT91C_PITC_PITIEN;
  1374. }
  1375. //*----------------------------------------------------------------------------
  1376. //* \fn AT91F_PITGetMode
  1377. //* \brief Read PIT mode register
  1378. //*----------------------------------------------------------------------------
  1379. __inline unsigned int AT91F_PITGetMode(
  1380. AT91PS_PITC pPITC)
  1381. {
  1382. return(pPITC->PITC_PIMR);
  1383. }
  1384. //*----------------------------------------------------------------------------
  1385. //* \fn AT91F_PITGetStatus
  1386. //* \brief Read PIT status register
  1387. //*----------------------------------------------------------------------------
  1388. __inline unsigned int AT91F_PITGetStatus(
  1389. AT91PS_PITC pPITC)
  1390. {
  1391. return(pPITC->PITC_PISR);
  1392. }
  1393. //*----------------------------------------------------------------------------
  1394. //* \fn AT91F_PITGetPIIR
  1395. //* \brief Read PIT CPIV and PICNT without ressetting the counters
  1396. //*----------------------------------------------------------------------------
  1397. __inline unsigned int AT91F_PITGetPIIR(
  1398. AT91PS_PITC pPITC)
  1399. {
  1400. return(pPITC->PITC_PIIR);
  1401. }
  1402. //*----------------------------------------------------------------------------
  1403. //* \fn AT91F_PITGetPIVR
  1404. //* \brief Read System timer CPIV and PICNT without ressetting the counters
  1405. //*----------------------------------------------------------------------------
  1406. __inline unsigned int AT91F_PITGetPIVR(
  1407. AT91PS_PITC pPITC)
  1408. {
  1409. return(pPITC->PITC_PIVR);
  1410. }
  1411. /* *****************************************************************************
  1412. SOFTWARE API FOR WDTC
  1413. ***************************************************************************** */
  1414. //*----------------------------------------------------------------------------
  1415. //* \fn AT91F_WDTSetMode
  1416. //* \brief Set Watchdog Mode Register
  1417. //*----------------------------------------------------------------------------
  1418. __inline void AT91F_WDTSetMode(
  1419. AT91PS_WDTC pWDTC,
  1420. unsigned int Mode)
  1421. {
  1422. pWDTC->WDTC_WDMR = Mode;
  1423. }
  1424. //*----------------------------------------------------------------------------
  1425. //* \fn AT91F_WDTRestart
  1426. //* \brief Restart Watchdog
  1427. //*----------------------------------------------------------------------------
  1428. __inline void AT91F_WDTRestart(
  1429. AT91PS_WDTC pWDTC)
  1430. {
  1431. pWDTC->WDTC_WDCR = 0xA5000001;
  1432. }
  1433. //*----------------------------------------------------------------------------
  1434. //* \fn AT91F_WDTSGettatus
  1435. //* \brief Get Watchdog Status
  1436. //*----------------------------------------------------------------------------
  1437. __inline unsigned int AT91F_WDTSGettatus(
  1438. AT91PS_WDTC pWDTC)
  1439. {
  1440. return(pWDTC->WDTC_WDSR & 0x3);
  1441. }
  1442. //*----------------------------------------------------------------------------
  1443. //* \fn AT91F_WDTGetPeriod
  1444. //* \brief Translate ms into Watchdog Compatible value
  1445. //*----------------------------------------------------------------------------
  1446. __inline unsigned int AT91F_WDTGetPeriod(unsigned int ms)
  1447. {
  1448. if ((ms < 4) || (ms > 16000))
  1449. return 0;
  1450. return((ms << 8) / 1000);
  1451. }
  1452. /* *****************************************************************************
  1453. SOFTWARE API FOR VREG
  1454. ***************************************************************************** */
  1455. //*----------------------------------------------------------------------------
  1456. //* \fn AT91F_VREG_Enable_LowPowerMode
  1457. //* \brief Enable VREG Low Power Mode
  1458. //*----------------------------------------------------------------------------
  1459. __inline void AT91F_VREG_Enable_LowPowerMode(
  1460. AT91PS_VREG pVREG)
  1461. {
  1462. pVREG->VREG_MR |= AT91C_VREG_PSTDBY;
  1463. }
  1464. //*----------------------------------------------------------------------------
  1465. //* \fn AT91F_VREG_Disable_LowPowerMode
  1466. //* \brief Disable VREG Low Power Mode
  1467. //*----------------------------------------------------------------------------
  1468. __inline void AT91F_VREG_Disable_LowPowerMode(
  1469. AT91PS_VREG pVREG)
  1470. {
  1471. pVREG->VREG_MR &= ~AT91C_VREG_PSTDBY;
  1472. }/* *****************************************************************************
  1473. SOFTWARE API FOR MC
  1474. ***************************************************************************** */
  1475. #define AT91C_MC_CORRECT_KEY ((unsigned int) 0x5A << 24) // (MC) Correct Protect Key
  1476. //*----------------------------------------------------------------------------
  1477. //* \fn AT91F_MC_Remap
  1478. //* \brief Make Remap
  1479. //*----------------------------------------------------------------------------
  1480. __inline void AT91F_MC_Remap (void) //
  1481. {
  1482. AT91PS_MC pMC = (AT91PS_MC) AT91C_BASE_MC;
  1483. pMC->MC_RCR = AT91C_MC_RCB;
  1484. }
  1485. //*----------------------------------------------------------------------------
  1486. //* \fn AT91F_MC_EFC_CfgModeReg
  1487. //* \brief Configure the EFC Mode Register of the MC controller
  1488. //*----------------------------------------------------------------------------
  1489. __inline void AT91F_MC_EFC_CfgModeReg (
  1490. AT91PS_MC pMC, // pointer to a MC controller
  1491. unsigned int mode) // mode register
  1492. {
  1493. // Write to the FMR register
  1494. pMC->MC_FMR = mode;
  1495. }
  1496. //*----------------------------------------------------------------------------
  1497. //* \fn AT91F_MC_EFC_GetModeReg
  1498. //* \brief Return MC EFC Mode Regsiter
  1499. //*----------------------------------------------------------------------------
  1500. __inline unsigned int AT91F_MC_EFC_GetModeReg(
  1501. AT91PS_MC pMC) // pointer to a MC controller
  1502. {
  1503. return pMC->MC_FMR;
  1504. }
  1505. //*----------------------------------------------------------------------------
  1506. //* \fn AT91F_MC_EFC_ComputeFMCN
  1507. //* \brief Return MC EFC Mode Regsiter
  1508. //*----------------------------------------------------------------------------
  1509. __inline unsigned int AT91F_MC_EFC_ComputeFMCN(
  1510. int master_clock) // master clock in Hz
  1511. {
  1512. return (master_clock/1000000 +2);
  1513. }
  1514. //*----------------------------------------------------------------------------
  1515. //* \fn AT91F_MC_EFC_PerformCmd
  1516. //* \brief Perform EFC Command
  1517. //*----------------------------------------------------------------------------
  1518. __inline void AT91F_MC_EFC_PerformCmd (
  1519. AT91PS_MC pMC, // pointer to a MC controller
  1520. unsigned int transfer_cmd)
  1521. {
  1522. pMC->MC_FCR = transfer_cmd;
  1523. }
  1524. //*----------------------------------------------------------------------------
  1525. //* \fn AT91F_MC_EFC_GetStatus
  1526. //* \brief Return MC EFC Status
  1527. //*----------------------------------------------------------------------------
  1528. __inline unsigned int AT91F_MC_EFC_GetStatus(
  1529. AT91PS_MC pMC) // pointer to a MC controller
  1530. {
  1531. return pMC->MC_FSR;
  1532. }
  1533. //*----------------------------------------------------------------------------
  1534. //* \fn AT91F_MC_EFC_IsInterruptMasked
  1535. //* \brief Test if EFC MC Interrupt is Masked
  1536. //*----------------------------------------------------------------------------
  1537. __inline unsigned int AT91F_MC_EFC_IsInterruptMasked(
  1538. AT91PS_MC pMC, // \arg pointer to a MC controller
  1539. unsigned int flag) // \arg flag to be tested
  1540. {
  1541. return (AT91F_MC_EFC_GetModeReg(pMC) & flag);
  1542. }
  1543. //*----------------------------------------------------------------------------
  1544. //* \fn AT91F_MC_EFC_IsInterruptSet
  1545. //* \brief Test if EFC MC Interrupt is Set
  1546. //*----------------------------------------------------------------------------
  1547. __inline unsigned int AT91F_MC_EFC_IsInterruptSet(
  1548. AT91PS_MC pMC, // \arg pointer to a MC controller
  1549. unsigned int flag) // \arg flag to be tested
  1550. {
  1551. return (AT91F_MC_EFC_GetStatus(pMC) & flag);
  1552. }
  1553. /* *****************************************************************************
  1554. SOFTWARE API FOR SPI
  1555. ***************************************************************************** */
  1556. //*----------------------------------------------------------------------------
  1557. //* \fn AT91F_SPI_Open
  1558. //* \brief Open a SPI Port
  1559. //*----------------------------------------------------------------------------
  1560. __inline unsigned int AT91F_SPI_Open (
  1561. const unsigned int null) // \arg
  1562. {
  1563. /* NOT DEFINED AT THIS MOMENT */
  1564. return ( 0 );
  1565. }
  1566. //*----------------------------------------------------------------------------
  1567. //* \fn AT91F_SPI_CfgCs
  1568. //* \brief Configure SPI chip select register
  1569. //*----------------------------------------------------------------------------
  1570. __inline void AT91F_SPI_CfgCs (
  1571. AT91PS_SPI pSPI, // pointer to a SPI controller
  1572. int cs, // SPI cs number (0 to 3)
  1573. int val) // chip select register
  1574. {
  1575. //* Write to the CSR register
  1576. *(pSPI->SPI_CSR + cs) = val;
  1577. }
  1578. //*----------------------------------------------------------------------------
  1579. //* \fn AT91F_SPI_EnableIt
  1580. //* \brief Enable SPI interrupt
  1581. //*----------------------------------------------------------------------------
  1582. __inline void AT91F_SPI_EnableIt (
  1583. AT91PS_SPI pSPI, // pointer to a SPI controller
  1584. unsigned int flag) // IT to be enabled
  1585. {
  1586. //* Write to the IER register
  1587. pSPI->SPI_IER = flag;
  1588. }
  1589. //*----------------------------------------------------------------------------
  1590. //* \fn AT91F_SPI_DisableIt
  1591. //* \brief Disable SPI interrupt
  1592. //*----------------------------------------------------------------------------
  1593. __inline void AT91F_SPI_DisableIt (
  1594. AT91PS_SPI pSPI, // pointer to a SPI controller
  1595. unsigned int flag) // IT to be disabled
  1596. {
  1597. //* Write to the IDR register
  1598. pSPI->SPI_IDR = flag;
  1599. }
  1600. //*----------------------------------------------------------------------------
  1601. //* \fn AT91F_SPI_Reset
  1602. //* \brief Reset the SPI controller
  1603. //*----------------------------------------------------------------------------
  1604. __inline void AT91F_SPI_Reset (
  1605. AT91PS_SPI pSPI // pointer to a SPI controller
  1606. )
  1607. {
  1608. //* Write to the CR register
  1609. pSPI->SPI_CR = AT91C_SPI_SWRST;
  1610. }
  1611. //*----------------------------------------------------------------------------
  1612. //* \fn AT91F_SPI_Enable
  1613. //* \brief Enable the SPI controller
  1614. //*----------------------------------------------------------------------------
  1615. __inline void AT91F_SPI_Enable (
  1616. AT91PS_SPI pSPI // pointer to a SPI controller
  1617. )
  1618. {
  1619. //* Write to the CR register
  1620. pSPI->SPI_CR = AT91C_SPI_SPIEN;
  1621. }
  1622. //*----------------------------------------------------------------------------
  1623. //* \fn AT91F_SPI_Disable
  1624. //* \brief Disable the SPI controller
  1625. //*----------------------------------------------------------------------------
  1626. __inline void AT91F_SPI_Disable (
  1627. AT91PS_SPI pSPI // pointer to a SPI controller
  1628. )
  1629. {
  1630. //* Write to the CR register
  1631. pSPI->SPI_CR = AT91C_SPI_SPIDIS;
  1632. }
  1633. //*----------------------------------------------------------------------------
  1634. //* \fn AT91F_SPI_CfgMode
  1635. //* \brief Enable the SPI controller
  1636. //*----------------------------------------------------------------------------
  1637. __inline void AT91F_SPI_CfgMode (
  1638. AT91PS_SPI pSPI, // pointer to a SPI controller
  1639. int mode) // mode register
  1640. {
  1641. //* Write to the MR register
  1642. pSPI->SPI_MR = mode;
  1643. }
  1644. //*----------------------------------------------------------------------------
  1645. //* \fn AT91F_SPI_CfgPCS
  1646. //* \brief Switch to the correct PCS of SPI Mode Register : Fixed Peripheral Selected
  1647. //*----------------------------------------------------------------------------
  1648. __inline void AT91F_SPI_CfgPCS (
  1649. AT91PS_SPI pSPI, // pointer to a SPI controller
  1650. char PCS_Device) // PCS of the Device
  1651. {
  1652. //* Write to the MR register
  1653. pSPI->SPI_MR &= 0xFFF0FFFF;
  1654. pSPI->SPI_MR |= ( (PCS_Device<<16) & AT91C_SPI_PCS );
  1655. }
  1656. //*----------------------------------------------------------------------------
  1657. //* \fn AT91F_SPI_ReceiveFrame
  1658. //* \brief Return 2 if PDC has been initialized with Buffer and Next Buffer, 1 if PDC has been initializaed with Next Buffer, 0 if PDC is busy
  1659. //*----------------------------------------------------------------------------
  1660. __inline unsigned int AT91F_SPI_ReceiveFrame (
  1661. AT91PS_SPI pSPI,
  1662. char *pBuffer,
  1663. unsigned int szBuffer,
  1664. char *pNextBuffer,
  1665. unsigned int szNextBuffer )
  1666. {
  1667. return AT91F_PDC_ReceiveFrame(
  1668. (AT91PS_PDC) &(pSPI->SPI_RPR),
  1669. pBuffer,
  1670. szBuffer,
  1671. pNextBuffer,
  1672. szNextBuffer);
  1673. }
  1674. //*----------------------------------------------------------------------------
  1675. //* \fn AT91F_SPI_SendFrame
  1676. //* \brief Return 2 if PDC has been initialized with Buffer and Next Buffer, 1 if PDC has been initializaed with Next Buffer, 0 if PDC is bSPIy
  1677. //*----------------------------------------------------------------------------
  1678. __inline unsigned int AT91F_SPI_SendFrame(
  1679. AT91PS_SPI pSPI,
  1680. char *pBuffer,
  1681. unsigned int szBuffer,
  1682. char *pNextBuffer,
  1683. unsigned int szNextBuffer )
  1684. {
  1685. return AT91F_PDC_SendFrame(
  1686. (AT91PS_PDC) &(pSPI->SPI_RPR),
  1687. pBuffer,
  1688. szBuffer,
  1689. pNextBuffer,
  1690. szNextBuffer);
  1691. }
  1692. //*----------------------------------------------------------------------------
  1693. //* \fn AT91F_SPI_Close
  1694. //* \brief Close SPI: disable IT disable transfert, close PDC
  1695. //*----------------------------------------------------------------------------
  1696. __inline void AT91F_SPI_Close (
  1697. AT91PS_SPI pSPI) // \arg pointer to a SPI controller
  1698. {
  1699. //* Reset all the Chip Select register
  1700. pSPI->SPI_CSR[0] = 0 ;
  1701. pSPI->SPI_CSR[1] = 0 ;
  1702. pSPI->SPI_CSR[2] = 0 ;
  1703. pSPI->SPI_CSR[3] = 0 ;
  1704. //* Reset the SPI mode
  1705. pSPI->SPI_MR = 0 ;
  1706. //* Disable all interrupts
  1707. pSPI->SPI_IDR = 0xFFFFFFFF ;
  1708. //* Abort the Peripheral Data Transfers
  1709. AT91F_PDC_Close((AT91PS_PDC) &(pSPI->SPI_RPR));
  1710. //* Disable receiver and transmitter and stop any activity immediately
  1711. pSPI->SPI_CR = AT91C_SPI_SPIDIS;
  1712. }
  1713. //*----------------------------------------------------------------------------
  1714. //* \fn AT91F_SPI_PutChar
  1715. //* \brief Send a character,does not check if ready to send
  1716. //*----------------------------------------------------------------------------
  1717. __inline void AT91F_SPI_PutChar (
  1718. AT91PS_SPI pSPI,
  1719. unsigned int character,
  1720. unsigned int cs_number )
  1721. {
  1722. unsigned int value_for_cs;
  1723. value_for_cs = (~(1 << cs_number)) & 0xF; //Place a zero among a 4 ONEs number
  1724. pSPI->SPI_TDR = (character & 0xFFFF) | (value_for_cs << 16);
  1725. }
  1726. //*----------------------------------------------------------------------------
  1727. //* \fn AT91F_SPI_GetChar
  1728. //* \brief Receive a character,does not check if a character is available
  1729. //*----------------------------------------------------------------------------
  1730. __inline int AT91F_SPI_GetChar (
  1731. const AT91PS_SPI pSPI)
  1732. {
  1733. return((pSPI->SPI_RDR) & 0xFFFF);
  1734. }
  1735. //*----------------------------------------------------------------------------
  1736. //* \fn AT91F_SPI_GetInterruptMaskStatus
  1737. //* \brief Return SPI Interrupt Mask Status
  1738. //*----------------------------------------------------------------------------
  1739. __inline unsigned int AT91F_SPI_GetInterruptMaskStatus( // \return SPI Interrupt Mask Status
  1740. AT91PS_SPI pSpi) // \arg pointer to a SPI controller
  1741. {
  1742. return pSpi->SPI_IMR;
  1743. }
  1744. //*----------------------------------------------------------------------------
  1745. //* \fn AT91F_SPI_IsInterruptMasked
  1746. //* \brief Test if SPI Interrupt is Masked
  1747. //*----------------------------------------------------------------------------
  1748. __inline int AT91F_SPI_IsInterruptMasked(
  1749. AT91PS_SPI pSpi, // \arg pointer to a SPI controller
  1750. unsigned int flag) // \arg flag to be tested
  1751. {
  1752. return (AT91F_SPI_GetInterruptMaskStatus(pSpi) & flag);
  1753. }
  1754. /* *****************************************************************************
  1755. SOFTWARE API FOR USART
  1756. ***************************************************************************** */
  1757. //*----------------------------------------------------------------------------
  1758. //* \fn AT91F_US_Baudrate
  1759. //* \brief Calculate the baudrate
  1760. //* Standard Asynchronous Mode : 8 bits , 1 stop , no parity
  1761. #define AT91C_US_ASYNC_MODE ( AT91C_US_USMODE_NORMAL + \
  1762. AT91C_US_NBSTOP_1_BIT + \
  1763. AT91C_US_PAR_NONE + \
  1764. AT91C_US_CHRL_8_BITS + \
  1765. AT91C_US_CLKS_CLOCK )
  1766. //* Standard External Asynchronous Mode : 8 bits , 1 stop , no parity
  1767. #define AT91C_US_ASYNC_SCK_MODE ( AT91C_US_USMODE_NORMAL + \
  1768. AT91C_US_NBSTOP_1_BIT + \
  1769. AT91C_US_PAR_NONE + \
  1770. AT91C_US_CHRL_8_BITS + \
  1771. AT91C_US_CLKS_EXT )
  1772. //* Standard Synchronous Mode : 8 bits , 1 stop , no parity
  1773. #define AT91C_US_SYNC_MODE ( AT91C_US_SYNC + \
  1774. AT91C_US_USMODE_NORMAL + \
  1775. AT91C_US_NBSTOP_1_BIT + \
  1776. AT91C_US_PAR_NONE + \
  1777. AT91C_US_CHRL_8_BITS + \
  1778. AT91C_US_CLKS_CLOCK )
  1779. //* SCK used Label
  1780. #define AT91C_US_SCK_USED (AT91C_US_CKLO | AT91C_US_CLKS_EXT)
  1781. //* Standard ISO T=0 Mode : 8 bits , 1 stop , parity
  1782. #define AT91C_US_ISO_READER_MODE ( AT91C_US_USMODE_ISO7816_0 + \
  1783. AT91C_US_CLKS_CLOCK +\
  1784. AT91C_US_NBSTOP_1_BIT + \
  1785. AT91C_US_PAR_EVEN + \
  1786. AT91C_US_CHRL_8_BITS + \
  1787. AT91C_US_CKLO +\
  1788. AT91C_US_OVER)
  1789. //* Standard IRDA mode
  1790. #define AT91C_US_ASYNC_IRDA_MODE ( AT91C_US_USMODE_IRDA + \
  1791. AT91C_US_NBSTOP_1_BIT + \
  1792. AT91C_US_PAR_NONE + \
  1793. AT91C_US_CHRL_8_BITS + \
  1794. AT91C_US_CLKS_CLOCK )
  1795. //*----------------------------------------------------------------------------
  1796. //* \fn AT91F_US_Baudrate
  1797. //* \brief Caluculate baud_value according to the main clock and the baud rate
  1798. //*----------------------------------------------------------------------------
  1799. __inline unsigned int AT91F_US_Baudrate (
  1800. const unsigned int main_clock, // \arg peripheral clock
  1801. const unsigned int baud_rate) // \arg UART baudrate
  1802. {
  1803. unsigned int baud_value = ((main_clock*10)/(baud_rate * 16));
  1804. if ((baud_value % 10) >= 5)
  1805. baud_value = (baud_value / 10) + 1;
  1806. else
  1807. baud_value /= 10;
  1808. return baud_value;
  1809. }
  1810. //*----------------------------------------------------------------------------
  1811. //* \fn AT91F_US_SetBaudrate
  1812. //* \brief Set the baudrate according to the CPU clock
  1813. //*----------------------------------------------------------------------------
  1814. __inline void AT91F_US_SetBaudrate (
  1815. AT91PS_USART pUSART, // \arg pointer to a USART controller
  1816. unsigned int mainClock, // \arg peripheral clock
  1817. unsigned int speed) // \arg UART baudrate
  1818. {
  1819. //* Define the baud rate divisor register
  1820. pUSART->US_BRGR = AT91F_US_Baudrate(mainClock, speed);
  1821. }
  1822. //*----------------------------------------------------------------------------
  1823. //* \fn AT91F_US_SetTimeguard
  1824. //* \brief Set USART timeguard
  1825. //*----------------------------------------------------------------------------
  1826. __inline void AT91F_US_SetTimeguard (
  1827. AT91PS_USART pUSART, // \arg pointer to a USART controller
  1828. unsigned int timeguard) // \arg timeguard value
  1829. {
  1830. //* Write the Timeguard Register
  1831. pUSART->US_TTGR = timeguard ;
  1832. }
  1833. //*----------------------------------------------------------------------------
  1834. //* \fn AT91F_US_EnableIt
  1835. //* \brief Enable USART IT
  1836. //*----------------------------------------------------------------------------
  1837. __inline void AT91F_US_EnableIt (
  1838. AT91PS_USART pUSART, // \arg pointer to a USART controller
  1839. unsigned int flag) // \arg IT to be enabled
  1840. {
  1841. //* Write to the IER register
  1842. pUSART->US_IER = flag;
  1843. }
  1844. //*----------------------------------------------------------------------------
  1845. //* \fn AT91F_US_DisableIt
  1846. //* \brief Disable USART IT
  1847. //*----------------------------------------------------------------------------
  1848. __inline void AT91F_US_DisableIt (
  1849. AT91PS_USART pUSART, // \arg pointer to a USART controller
  1850. unsigned int flag) // \arg IT to be disabled
  1851. {
  1852. //* Write to the IER register
  1853. pUSART->US_IDR = flag;
  1854. }
  1855. //*----------------------------------------------------------------------------
  1856. //* \fn AT91F_US_Configure
  1857. //* \brief Configure USART
  1858. //*----------------------------------------------------------------------------
  1859. __inline void AT91F_US_Configure (
  1860. AT91PS_USART pUSART, // \arg pointer to a USART controller
  1861. unsigned int mainClock, // \arg peripheral clock
  1862. unsigned int mode , // \arg mode Register to be programmed
  1863. unsigned int baudRate , // \arg baudrate to be programmed
  1864. unsigned int timeguard ) // \arg timeguard to be programmed
  1865. {
  1866. //* Disable interrupts
  1867. pUSART->US_IDR = (unsigned int) -1;
  1868. //* Reset receiver and transmitter
  1869. pUSART->US_CR = AT91C_US_RSTRX | AT91C_US_RSTTX | AT91C_US_RXDIS | AT91C_US_TXDIS ;
  1870. //* Define the baud rate divisor register
  1871. AT91F_US_SetBaudrate(pUSART, mainClock, baudRate);
  1872. //* Write the Timeguard Register
  1873. AT91F_US_SetTimeguard(pUSART, timeguard);
  1874. //* Clear Transmit and Receive Counters
  1875. AT91F_PDC_Open((AT91PS_PDC) &(pUSART->US_RPR));
  1876. //* Define the USART mode
  1877. pUSART->US_MR = mode ;
  1878. }
  1879. //*----------------------------------------------------------------------------
  1880. //* \fn AT91F_US_EnableRx
  1881. //* \brief Enable receiving characters
  1882. //*----------------------------------------------------------------------------
  1883. __inline void AT91F_US_EnableRx (
  1884. AT91PS_USART pUSART) // \arg pointer to a USART controller
  1885. {
  1886. //* Enable receiver
  1887. pUSART->US_CR = AT91C_US_RXEN;
  1888. }
  1889. //*----------------------------------------------------------------------------
  1890. //* \fn AT91F_US_EnableTx
  1891. //* \brief Enable sending characters
  1892. //*----------------------------------------------------------------------------
  1893. __inline void AT91F_US_EnableTx (
  1894. AT91PS_USART pUSART) // \arg pointer to a USART controller
  1895. {
  1896. //* Enable transmitter
  1897. pUSART->US_CR = AT91C_US_TXEN;
  1898. }
  1899. //*----------------------------------------------------------------------------
  1900. //* \fn AT91F_US_ResetRx
  1901. //* \brief Reset Receiver and re-enable it
  1902. //*----------------------------------------------------------------------------
  1903. __inline void AT91F_US_ResetRx (
  1904. AT91PS_USART pUSART) // \arg pointer to a USART controller
  1905. {
  1906. //* Reset receiver
  1907. pUSART->US_CR = AT91C_US_RSTRX;
  1908. //* Re-Enable receiver
  1909. pUSART->US_CR = AT91C_US_RXEN;
  1910. }
  1911. //*----------------------------------------------------------------------------
  1912. //* \fn AT91F_US_ResetTx
  1913. //* \brief Reset Transmitter and re-enable it
  1914. //*----------------------------------------------------------------------------
  1915. __inline void AT91F_US_ResetTx (
  1916. AT91PS_USART pUSART) // \arg pointer to a USART controller
  1917. {
  1918. //* Reset transmitter
  1919. pUSART->US_CR = AT91C_US_RSTTX;
  1920. //* Enable transmitter
  1921. pUSART->US_CR = AT91C_US_TXEN;
  1922. }
  1923. //*----------------------------------------------------------------------------
  1924. //* \fn AT91F_US_DisableRx
  1925. //* \brief Disable Receiver
  1926. //*----------------------------------------------------------------------------
  1927. __inline void AT91F_US_DisableRx (
  1928. AT91PS_USART pUSART) // \arg pointer to a USART controller
  1929. {
  1930. //* Disable receiver
  1931. pUSART->US_CR = AT91C_US_RXDIS;
  1932. }
  1933. //*----------------------------------------------------------------------------
  1934. //* \fn AT91F_US_DisableTx
  1935. //* \brief Disable Transmitter
  1936. //*----------------------------------------------------------------------------
  1937. __inline void AT91F_US_DisableTx (
  1938. AT91PS_USART pUSART) // \arg pointer to a USART controller
  1939. {
  1940. //* Disable transmitter
  1941. pUSART->US_CR = AT91C_US_TXDIS;
  1942. }
  1943. //*----------------------------------------------------------------------------
  1944. //* \fn AT91F_US_Close
  1945. //* \brief Close USART: disable IT disable receiver and transmitter, close PDC
  1946. //*----------------------------------------------------------------------------
  1947. __inline void AT91F_US_Close (
  1948. AT91PS_USART pUSART) // \arg pointer to a USART controller
  1949. {
  1950. //* Reset the baud rate divisor register
  1951. pUSART->US_BRGR = 0 ;
  1952. //* Reset the USART mode
  1953. pUSART->US_MR = 0 ;
  1954. //* Reset the Timeguard Register
  1955. pUSART->US_TTGR = 0;
  1956. //* Disable all interrupts
  1957. pUSART->US_IDR = 0xFFFFFFFF ;
  1958. //* Abort the Peripheral Data Transfers
  1959. AT91F_PDC_Close((AT91PS_PDC) &(pUSART->US_RPR));
  1960. //* Disable receiver and transmitter and stop any activity immediately
  1961. pUSART->US_CR = AT91C_US_TXDIS | AT91C_US_RXDIS | AT91C_US_RSTTX | AT91C_US_RSTRX ;
  1962. }
  1963. //*----------------------------------------------------------------------------
  1964. //* \fn AT91F_US_TxReady
  1965. //* \brief Return 1 if a character can be written in US_THR
  1966. //*----------------------------------------------------------------------------
  1967. __inline unsigned int AT91F_US_TxReady (
  1968. AT91PS_USART pUSART ) // \arg pointer to a USART controller
  1969. {
  1970. return (pUSART->US_CSR & AT91C_US_TXRDY);
  1971. }
  1972. //*----------------------------------------------------------------------------
  1973. //* \fn AT91F_US_RxReady
  1974. //* \brief Return 1 if a character can be read in US_RHR
  1975. //*----------------------------------------------------------------------------
  1976. __inline unsigned int AT91F_US_RxReady (
  1977. AT91PS_USART pUSART ) // \arg pointer to a USART controller
  1978. {
  1979. return (pUSART->US_CSR & AT91C_US_RXRDY);
  1980. }
  1981. //*----------------------------------------------------------------------------
  1982. //* \fn AT91F_US_Error
  1983. //* \brief Return the error flag
  1984. //*----------------------------------------------------------------------------
  1985. __inline unsigned int AT91F_US_Error (
  1986. AT91PS_USART pUSART ) // \arg pointer to a USART controller
  1987. {
  1988. return (pUSART->US_CSR &
  1989. (AT91C_US_OVRE | // Overrun error
  1990. AT91C_US_FRAME | // Framing error
  1991. AT91C_US_PARE)); // Parity error
  1992. }
  1993. //*----------------------------------------------------------------------------
  1994. //* \fn AT91F_US_PutChar
  1995. //* \brief Send a character,does not check if ready to send
  1996. //*----------------------------------------------------------------------------
  1997. __inline void AT91F_US_PutChar (
  1998. AT91PS_USART pUSART,
  1999. int character )
  2000. {
  2001. pUSART->US_THR = (character & 0x1FF);
  2002. }
  2003. //*----------------------------------------------------------------------------
  2004. //* \fn AT91F_US_GetChar
  2005. //* \brief Receive a character,does not check if a character is available
  2006. //*----------------------------------------------------------------------------
  2007. __inline int AT91F_US_GetChar (
  2008. const AT91PS_USART pUSART)
  2009. {
  2010. return((pUSART->US_RHR) & 0x1FF);
  2011. }
  2012. //*----------------------------------------------------------------------------
  2013. //* \fn AT91F_US_SendFrame
  2014. //* \brief Return 2 if PDC has been initialized with Buffer and Next Buffer, 1 if PDC has been initializaed with Next Buffer, 0 if PDC is busy
  2015. //*----------------------------------------------------------------------------
  2016. __inline unsigned int AT91F_US_SendFrame(
  2017. AT91PS_USART pUSART,
  2018. char *pBuffer,
  2019. unsigned int szBuffer,
  2020. char *pNextBuffer,
  2021. unsigned int szNextBuffer )
  2022. {
  2023. return AT91F_PDC_SendFrame(
  2024. (AT91PS_PDC) &(pUSART->US_RPR),
  2025. pBuffer,
  2026. szBuffer,
  2027. pNextBuffer,
  2028. szNextBuffer);
  2029. }
  2030. //*----------------------------------------------------------------------------
  2031. //* \fn AT91F_US_ReceiveFrame
  2032. //* \brief Return 2 if PDC has been initialized with Buffer and Next Buffer, 1 if PDC has been initializaed with Next Buffer, 0 if PDC is busy
  2033. //*----------------------------------------------------------------------------
  2034. __inline unsigned int AT91F_US_ReceiveFrame (
  2035. AT91PS_USART pUSART,
  2036. char *pBuffer,
  2037. unsigned int szBuffer,
  2038. char *pNextBuffer,
  2039. unsigned int szNextBuffer )
  2040. {
  2041. return AT91F_PDC_ReceiveFrame(
  2042. (AT91PS_PDC) &(pUSART->US_RPR),
  2043. pBuffer,
  2044. szBuffer,
  2045. pNextBuffer,
  2046. szNextBuffer);
  2047. }
  2048. //*----------------------------------------------------------------------------
  2049. //* \fn AT91F_US_SetIrdaFilter
  2050. //* \brief Set the value of IrDa filter tregister
  2051. //*----------------------------------------------------------------------------
  2052. __inline void AT91F_US_SetIrdaFilter (
  2053. AT91PS_USART pUSART,
  2054. unsigned char value
  2055. )
  2056. {
  2057. pUSART->US_IF = value;
  2058. }
  2059. /* *****************************************************************************
  2060. SOFTWARE API FOR SSC
  2061. ***************************************************************************** */
  2062. //* Define the standard I2S mode configuration
  2063. //* Configuration to set in the SSC Transmit Clock Mode Register
  2064. //* Parameters : nb_bit_by_slot : 8, 16 or 32 bits
  2065. //* nb_slot_by_frame : number of channels
  2066. #define AT91C_I2S_ASY_MASTER_TX_SETTING(nb_bit_by_slot, nb_slot_by_frame)( +\
  2067. AT91C_SSC_CKS_DIV +\
  2068. AT91C_SSC_CKO_CONTINOUS +\
  2069. AT91C_SSC_CKG_NONE +\
  2070. AT91C_SSC_START_FALL_RF +\
  2071. AT91C_SSC_STTOUT +\
  2072. ((1<<16) & AT91C_SSC_STTDLY) +\
  2073. ((((nb_bit_by_slot*nb_slot_by_frame)/2)-1) <<24))
  2074. //* Configuration to set in the SSC Transmit Frame Mode Register
  2075. //* Parameters : nb_bit_by_slot : 8, 16 or 32 bits
  2076. //* nb_slot_by_frame : number of channels
  2077. #define AT91C_I2S_ASY_TX_FRAME_SETTING(nb_bit_by_slot, nb_slot_by_frame)( +\
  2078. (nb_bit_by_slot-1) +\
  2079. AT91C_SSC_MSBF +\
  2080. (((nb_slot_by_frame-1)<<8) & AT91C_SSC_DATNB) +\
  2081. (((nb_bit_by_slot-1)<<16) & AT91C_SSC_FSLEN) +\
  2082. AT91C_SSC_FSOS_NEGATIVE)
  2083. //*----------------------------------------------------------------------------
  2084. //* \fn AT91F_SSC_SetBaudrate
  2085. //* \brief Set the baudrate according to the CPU clock
  2086. //*----------------------------------------------------------------------------
  2087. __inline void AT91F_SSC_SetBaudrate (
  2088. AT91PS_SSC pSSC, // \arg pointer to a SSC controller
  2089. unsigned int mainClock, // \arg peripheral clock
  2090. unsigned int speed) // \arg SSC baudrate
  2091. {
  2092. unsigned int baud_value;
  2093. //* Define the baud rate divisor register
  2094. if (speed == 0)
  2095. baud_value = 0;
  2096. else
  2097. {
  2098. baud_value = (unsigned int) (mainClock * 10)/(2*speed);
  2099. if ((baud_value % 10) >= 5)
  2100. baud_value = (baud_value / 10) + 1;
  2101. else
  2102. baud_value /= 10;
  2103. }
  2104. pSSC->SSC_CMR = baud_value;
  2105. }
  2106. //*----------------------------------------------------------------------------
  2107. //* \fn AT91F_SSC_Configure
  2108. //* \brief Configure SSC
  2109. //*----------------------------------------------------------------------------
  2110. __inline void AT91F_SSC_Configure (
  2111. AT91PS_SSC pSSC, // \arg pointer to a SSC controller
  2112. unsigned int syst_clock, // \arg System Clock Frequency
  2113. unsigned int baud_rate, // \arg Expected Baud Rate Frequency
  2114. unsigned int clock_rx, // \arg Receiver Clock Parameters
  2115. unsigned int mode_rx, // \arg mode Register to be programmed
  2116. unsigned int clock_tx, // \arg Transmitter Clock Parameters
  2117. unsigned int mode_tx) // \arg mode Register to be programmed
  2118. {
  2119. //* Disable interrupts
  2120. pSSC->SSC_IDR = (unsigned int) -1;
  2121. //* Reset receiver and transmitter
  2122. pSSC->SSC_CR = AT91C_SSC_SWRST | AT91C_SSC_RXDIS | AT91C_SSC_TXDIS ;
  2123. //* Define the Clock Mode Register
  2124. AT91F_SSC_SetBaudrate(pSSC, syst_clock, baud_rate);
  2125. //* Write the Receive Clock Mode Register
  2126. pSSC->SSC_RCMR = clock_rx;
  2127. //* Write the Transmit Clock Mode Register
  2128. pSSC->SSC_TCMR = clock_tx;
  2129. //* Write the Receive Frame Mode Register
  2130. pSSC->SSC_RFMR = mode_rx;
  2131. //* Write the Transmit Frame Mode Register
  2132. pSSC->SSC_TFMR = mode_tx;
  2133. //* Clear Transmit and Receive Counters
  2134. AT91F_PDC_Open((AT91PS_PDC) &(pSSC->SSC_RPR));
  2135. }
  2136. //*----------------------------------------------------------------------------
  2137. //* \fn AT91F_SSC_EnableRx
  2138. //* \brief Enable receiving datas
  2139. //*----------------------------------------------------------------------------
  2140. __inline void AT91F_SSC_EnableRx (
  2141. AT91PS_SSC pSSC) // \arg pointer to a SSC controller
  2142. {
  2143. //* Enable receiver
  2144. pSSC->SSC_CR = AT91C_SSC_RXEN;
  2145. }
  2146. //*----------------------------------------------------------------------------
  2147. //* \fn AT91F_SSC_DisableRx
  2148. //* \brief Disable receiving datas
  2149. //*----------------------------------------------------------------------------
  2150. __inline void AT91F_SSC_DisableRx (
  2151. AT91PS_SSC pSSC) // \arg pointer to a SSC controller
  2152. {
  2153. //* Disable receiver
  2154. pSSC->SSC_CR = AT91C_SSC_RXDIS;
  2155. }
  2156. //*----------------------------------------------------------------------------
  2157. //* \fn AT91F_SSC_EnableTx
  2158. //* \brief Enable sending datas
  2159. //*----------------------------------------------------------------------------
  2160. __inline void AT91F_SSC_EnableTx (
  2161. AT91PS_SSC pSSC) // \arg pointer to a SSC controller
  2162. {
  2163. //* Enable transmitter
  2164. pSSC->SSC_CR = AT91C_SSC_TXEN;
  2165. }
  2166. //*----------------------------------------------------------------------------
  2167. //* \fn AT91F_SSC_DisableTx
  2168. //* \brief Disable sending datas
  2169. //*----------------------------------------------------------------------------
  2170. __inline void AT91F_SSC_DisableTx (
  2171. AT91PS_SSC pSSC) // \arg pointer to a SSC controller
  2172. {
  2173. //* Disable transmitter
  2174. pSSC->SSC_CR = AT91C_SSC_TXDIS;
  2175. }
  2176. //*----------------------------------------------------------------------------
  2177. //* \fn AT91F_SSC_EnableIt
  2178. //* \brief Enable SSC IT
  2179. //*----------------------------------------------------------------------------
  2180. __inline void AT91F_SSC_EnableIt (
  2181. AT91PS_SSC pSSC, // \arg pointer to a SSC controller
  2182. unsigned int flag) // \arg IT to be enabled
  2183. {
  2184. //* Write to the IER register
  2185. pSSC->SSC_IER = flag;
  2186. }
  2187. //*----------------------------------------------------------------------------
  2188. //* \fn AT91F_SSC_DisableIt
  2189. //* \brief Disable SSC IT
  2190. //*----------------------------------------------------------------------------
  2191. __inline void AT91F_SSC_DisableIt (
  2192. AT91PS_SSC pSSC, // \arg pointer to a SSC controller
  2193. unsigned int flag) // \arg IT to be disabled
  2194. {
  2195. //* Write to the IDR register
  2196. pSSC->SSC_IDR = flag;
  2197. }
  2198. //*----------------------------------------------------------------------------
  2199. //* \fn AT91F_SSC_ReceiveFrame
  2200. //* \brief Return 2 if PDC has been initialized with Buffer and Next Buffer, 1 if PDC has been initialized with Next Buffer, 0 if PDC is busy
  2201. //*----------------------------------------------------------------------------
  2202. __inline unsigned int AT91F_SSC_ReceiveFrame (
  2203. AT91PS_SSC pSSC,
  2204. char *pBuffer,
  2205. unsigned int szBuffer,
  2206. char *pNextBuffer,
  2207. unsigned int szNextBuffer )
  2208. {
  2209. return AT91F_PDC_ReceiveFrame(
  2210. (AT91PS_PDC) &(pSSC->SSC_RPR),
  2211. pBuffer,
  2212. szBuffer,
  2213. pNextBuffer,
  2214. szNextBuffer);
  2215. }
  2216. //*----------------------------------------------------------------------------
  2217. //* \fn AT91F_SSC_SendFrame
  2218. //* \brief Return 2 if PDC has been initialized with Buffer and Next Buffer, 1 if PDC has been initialized with Next Buffer, 0 if PDC is busy
  2219. //*----------------------------------------------------------------------------
  2220. __inline unsigned int AT91F_SSC_SendFrame(
  2221. AT91PS_SSC pSSC,
  2222. char *pBuffer,
  2223. unsigned int szBuffer,
  2224. char *pNextBuffer,
  2225. unsigned int szNextBuffer )
  2226. {
  2227. return AT91F_PDC_SendFrame(
  2228. (AT91PS_PDC) &(pSSC->SSC_RPR),
  2229. pBuffer,
  2230. szBuffer,
  2231. pNextBuffer,
  2232. szNextBuffer);
  2233. }
  2234. //*----------------------------------------------------------------------------
  2235. //* \fn AT91F_SSC_GetInterruptMaskStatus
  2236. //* \brief Return SSC Interrupt Mask Status
  2237. //*----------------------------------------------------------------------------
  2238. __inline unsigned int AT91F_SSC_GetInterruptMaskStatus( // \return SSC Interrupt Mask Status
  2239. AT91PS_SSC pSsc) // \arg pointer to a SSC controller
  2240. {
  2241. return pSsc->SSC_IMR;
  2242. }
  2243. //*----------------------------------------------------------------------------
  2244. //* \fn AT91F_SSC_IsInterruptMasked
  2245. //* \brief Test if SSC Interrupt is Masked
  2246. //*----------------------------------------------------------------------------
  2247. __inline int AT91F_SSC_IsInterruptMasked(
  2248. AT91PS_SSC pSsc, // \arg pointer to a SSC controller
  2249. unsigned int flag) // \arg flag to be tested
  2250. {
  2251. return (AT91F_SSC_GetInterruptMaskStatus(pSsc) & flag);
  2252. }
  2253. /* *****************************************************************************
  2254. SOFTWARE API FOR TWI
  2255. ***************************************************************************** */
  2256. //*----------------------------------------------------------------------------
  2257. //* \fn AT91F_TWI_EnableIt
  2258. //* \brief Enable TWI IT
  2259. //*----------------------------------------------------------------------------
  2260. __inline void AT91F_TWI_EnableIt (
  2261. AT91PS_TWI pTWI, // \arg pointer to a TWI controller
  2262. unsigned int flag) // \arg IT to be enabled
  2263. {
  2264. //* Write to the IER register
  2265. pTWI->TWI_IER = flag;
  2266. }
  2267. //*----------------------------------------------------------------------------
  2268. //* \fn AT91F_TWI_DisableIt
  2269. //* \brief Disable TWI IT
  2270. //*----------------------------------------------------------------------------
  2271. __inline void AT91F_TWI_DisableIt (
  2272. AT91PS_TWI pTWI, // \arg pointer to a TWI controller
  2273. unsigned int flag) // \arg IT to be disabled
  2274. {
  2275. //* Write to the IDR register
  2276. pTWI->TWI_IDR = flag;
  2277. }
  2278. //*----------------------------------------------------------------------------
  2279. //* \fn AT91F_TWI_Configure
  2280. //* \brief Configure TWI in master mode
  2281. //*----------------------------------------------------------------------------
  2282. __inline void AT91F_TWI_Configure ( AT91PS_TWI pTWI ) // \arg pointer to a TWI controller
  2283. {
  2284. //* Disable interrupts
  2285. pTWI->TWI_IDR = (unsigned int) -1;
  2286. //* Reset peripheral
  2287. pTWI->TWI_CR = AT91C_TWI_SWRST;
  2288. //* Set Master mode
  2289. pTWI->TWI_CR = AT91C_TWI_MSEN;
  2290. }
  2291. //*----------------------------------------------------------------------------
  2292. //* \fn AT91F_TWI_GetInterruptMaskStatus
  2293. //* \brief Return TWI Interrupt Mask Status
  2294. //*----------------------------------------------------------------------------
  2295. __inline unsigned int AT91F_TWI_GetInterruptMaskStatus( // \return TWI Interrupt Mask Status
  2296. AT91PS_TWI pTwi) // \arg pointer to a TWI controller
  2297. {
  2298. return pTwi->TWI_IMR;
  2299. }
  2300. //*----------------------------------------------------------------------------
  2301. //* \fn AT91F_TWI_IsInterruptMasked
  2302. //* \brief Test if TWI Interrupt is Masked
  2303. //*----------------------------------------------------------------------------
  2304. __inline int AT91F_TWI_IsInterruptMasked(
  2305. AT91PS_TWI pTwi, // \arg pointer to a TWI controller
  2306. unsigned int flag) // \arg flag to be tested
  2307. {
  2308. return (AT91F_TWI_GetInterruptMaskStatus(pTwi) & flag);
  2309. }
  2310. /* *****************************************************************************
  2311. SOFTWARE API FOR PWMC
  2312. ***************************************************************************** */
  2313. //*----------------------------------------------------------------------------
  2314. //* \fn AT91F_PWM_GetStatus
  2315. //* \brief Return PWM Interrupt Status
  2316. //*----------------------------------------------------------------------------
  2317. __inline unsigned int AT91F_PWMC_GetStatus( // \return PWM Interrupt Status
  2318. AT91PS_PWMC pPWM) // pointer to a PWM controller
  2319. {
  2320. return pPWM->PWMC_SR;
  2321. }
  2322. //*----------------------------------------------------------------------------
  2323. //* \fn AT91F_PWM_InterruptEnable
  2324. //* \brief Enable PWM Interrupt
  2325. //*----------------------------------------------------------------------------
  2326. __inline void AT91F_PWMC_InterruptEnable(
  2327. AT91PS_PWMC pPwm, // \arg pointer to a PWM controller
  2328. unsigned int flag) // \arg PWM interrupt to be enabled
  2329. {
  2330. pPwm->PWMC_IER = flag;
  2331. }
  2332. //*----------------------------------------------------------------------------
  2333. //* \fn AT91F_PWM_InterruptDisable
  2334. //* \brief Disable PWM Interrupt
  2335. //*----------------------------------------------------------------------------
  2336. __inline void AT91F_PWMC_InterruptDisable(
  2337. AT91PS_PWMC pPwm, // \arg pointer to a PWM controller
  2338. unsigned int flag) // \arg PWM interrupt to be disabled
  2339. {
  2340. pPwm->PWMC_IDR = flag;
  2341. }
  2342. //*----------------------------------------------------------------------------
  2343. //* \fn AT91F_PWM_GetInterruptMaskStatus
  2344. //* \brief Return PWM Interrupt Mask Status
  2345. //*----------------------------------------------------------------------------
  2346. __inline unsigned int AT91F_PWMC_GetInterruptMaskStatus( // \return PWM Interrupt Mask Status
  2347. AT91PS_PWMC pPwm) // \arg pointer to a PWM controller
  2348. {
  2349. return pPwm->PWMC_IMR;
  2350. }
  2351. //*----------------------------------------------------------------------------
  2352. //* \fn AT91F_PWM_IsInterruptMasked
  2353. //* \brief Test if PWM Interrupt is Masked
  2354. //*----------------------------------------------------------------------------
  2355. __inline unsigned int AT91F_PWMC_IsInterruptMasked(
  2356. AT91PS_PWMC pPWM, // \arg pointer to a PWM controller
  2357. unsigned int flag) // \arg flag to be tested
  2358. {
  2359. return (AT91F_PWMC_GetInterruptMaskStatus(pPWM) & flag);
  2360. }
  2361. //*----------------------------------------------------------------------------
  2362. //* \fn AT91F_PWM_IsStatusSet
  2363. //* \brief Test if PWM Interrupt is Set
  2364. //*----------------------------------------------------------------------------
  2365. __inline unsigned int AT91F_PWMC_IsStatusSet(
  2366. AT91PS_PWMC pPWM, // \arg pointer to a PWM controller
  2367. unsigned int flag) // \arg flag to be tested
  2368. {
  2369. return (AT91F_PWMC_GetStatus(pPWM) & flag);
  2370. }
  2371. //*----------------------------------------------------------------------------
  2372. //* \fn AT91F_PWM_CfgChannel
  2373. //* \brief Test if PWM Interrupt is Set
  2374. //*----------------------------------------------------------------------------
  2375. __inline void AT91F_PWMC_CfgChannel(
  2376. AT91PS_PWMC pPWM, // \arg pointer to a PWM controller
  2377. unsigned int channelId, // \arg PWM channel ID
  2378. unsigned int mode, // \arg PWM mode
  2379. unsigned int period, // \arg PWM period
  2380. unsigned int duty) // \arg PWM duty cycle
  2381. {
  2382. pPWM->PWMC_CH[channelId].PWMC_CMR = mode;
  2383. pPWM->PWMC_CH[channelId].PWMC_CDTYR = duty;
  2384. pPWM->PWMC_CH[channelId].PWMC_CPRDR = period;
  2385. }
  2386. //*----------------------------------------------------------------------------
  2387. //* \fn AT91F_PWM_StartChannel
  2388. //* \brief Enable channel
  2389. //*----------------------------------------------------------------------------
  2390. __inline void AT91F_PWMC_StartChannel(
  2391. AT91PS_PWMC pPWM, // \arg pointer to a PWM controller
  2392. unsigned int flag) // \arg Channels IDs to be enabled
  2393. {
  2394. pPWM->PWMC_ENA = flag;
  2395. }
  2396. //*----------------------------------------------------------------------------
  2397. //* \fn AT91F_PWM_StopChannel
  2398. //* \brief Disable channel
  2399. //*----------------------------------------------------------------------------
  2400. __inline void AT91F_PWMC_StopChannel(
  2401. AT91PS_PWMC pPWM, // \arg pointer to a PWM controller
  2402. unsigned int flag) // \arg Channels IDs to be enabled
  2403. {
  2404. pPWM->PWMC_DIS = flag;
  2405. }
  2406. //*----------------------------------------------------------------------------
  2407. //* \fn AT91F_PWM_UpdateChannel
  2408. //* \brief Update Period or Duty Cycle
  2409. //*----------------------------------------------------------------------------
  2410. __inline void AT91F_PWMC_UpdateChannel(
  2411. AT91PS_PWMC pPWM, // \arg pointer to a PWM controller
  2412. unsigned int channelId, // \arg PWM channel ID
  2413. unsigned int update) // \arg Channels IDs to be enabled
  2414. {
  2415. pPWM->PWMC_CH[channelId].PWMC_CUPDR = update;
  2416. }
  2417. /* *****************************************************************************
  2418. SOFTWARE API FOR UDP
  2419. ***************************************************************************** */
  2420. //*----------------------------------------------------------------------------
  2421. //* \fn AT91F_UDP_EnableIt
  2422. //* \brief Enable UDP IT
  2423. //*----------------------------------------------------------------------------
  2424. __inline void AT91F_UDP_EnableIt (
  2425. AT91PS_UDP pUDP, // \arg pointer to a UDP controller
  2426. unsigned int flag) // \arg IT to be enabled
  2427. {
  2428. //* Write to the IER register
  2429. pUDP->UDP_IER = flag;
  2430. }
  2431. //*----------------------------------------------------------------------------
  2432. //* \fn AT91F_UDP_DisableIt
  2433. //* \brief Disable UDP IT
  2434. //*----------------------------------------------------------------------------
  2435. __inline void AT91F_UDP_DisableIt (
  2436. AT91PS_UDP pUDP, // \arg pointer to a UDP controller
  2437. unsigned int flag) // \arg IT to be disabled
  2438. {
  2439. //* Write to the IDR register
  2440. pUDP->UDP_IDR = flag;
  2441. }
  2442. //*----------------------------------------------------------------------------
  2443. //* \fn AT91F_UDP_SetAddress
  2444. //* \brief Set UDP functional address
  2445. //*----------------------------------------------------------------------------
  2446. __inline void AT91F_UDP_SetAddress (
  2447. AT91PS_UDP pUDP, // \arg pointer to a UDP controller
  2448. unsigned char address) // \arg new UDP address
  2449. {
  2450. pUDP->UDP_FADDR = (AT91C_UDP_FEN | address);
  2451. }
  2452. //*----------------------------------------------------------------------------
  2453. //* \fn AT91F_UDP_EnableEp
  2454. //* \brief Enable Endpoint
  2455. //*----------------------------------------------------------------------------
  2456. __inline void AT91F_UDP_EnableEp (
  2457. AT91PS_UDP pUDP, // \arg pointer to a UDP controller
  2458. unsigned char endpoint) // \arg endpoint number
  2459. {
  2460. pUDP->UDP_CSR[endpoint] |= AT91C_UDP_EPEDS;
  2461. }
  2462. //*----------------------------------------------------------------------------
  2463. //* \fn AT91F_UDP_DisableEp
  2464. //* \brief Enable Endpoint
  2465. //*----------------------------------------------------------------------------
  2466. __inline void AT91F_UDP_DisableEp (
  2467. AT91PS_UDP pUDP, // \arg pointer to a UDP controller
  2468. unsigned char endpoint) // \arg endpoint number
  2469. {
  2470. pUDP->UDP_CSR[endpoint] &= ~AT91C_UDP_EPEDS;
  2471. }
  2472. //*----------------------------------------------------------------------------
  2473. //* \fn AT91F_UDP_SetState
  2474. //* \brief Set UDP Device state
  2475. //*----------------------------------------------------------------------------
  2476. __inline void AT91F_UDP_SetState (
  2477. AT91PS_UDP pUDP, // \arg pointer to a UDP controller
  2478. unsigned int flag) // \arg new UDP address
  2479. {
  2480. pUDP->UDP_GLBSTATE &= ~(AT91C_UDP_FADDEN | AT91C_UDP_CONFG);
  2481. pUDP->UDP_GLBSTATE |= flag;
  2482. }
  2483. //*----------------------------------------------------------------------------
  2484. //* \fn AT91F_UDP_GetState
  2485. //* \brief return UDP Device state
  2486. //*----------------------------------------------------------------------------
  2487. __inline unsigned int AT91F_UDP_GetState ( // \return the UDP device state
  2488. AT91PS_UDP pUDP) // \arg pointer to a UDP controller
  2489. {
  2490. return (pUDP->UDP_GLBSTATE & (AT91C_UDP_FADDEN | AT91C_UDP_CONFG));
  2491. }
  2492. //*----------------------------------------------------------------------------
  2493. //* \fn AT91F_UDP_ResetEp
  2494. //* \brief Reset UDP endpoint
  2495. //*----------------------------------------------------------------------------
  2496. __inline void AT91F_UDP_ResetEp ( // \return the UDP device state
  2497. AT91PS_UDP pUDP, // \arg pointer to a UDP controller
  2498. unsigned int flag) // \arg Endpoints to be reset
  2499. {
  2500. pUDP->UDP_RSTEP = flag;
  2501. pUDP->UDP_RSTEP = 0;
  2502. }
  2503. //*----------------------------------------------------------------------------
  2504. //* \fn AT91F_UDP_EpStall
  2505. //* \brief Endpoint will STALL requests
  2506. //*----------------------------------------------------------------------------
  2507. __inline void AT91F_UDP_EpStall(
  2508. AT91PS_UDP pUDP, // \arg pointer to a UDP controller
  2509. unsigned char endpoint) // \arg endpoint number
  2510. {
  2511. pUDP->UDP_CSR[endpoint] |= AT91C_UDP_FORCESTALL;
  2512. }
  2513. //*----------------------------------------------------------------------------
  2514. //* \fn AT91F_UDP_EpWrite
  2515. //* \brief Write value in the DPR
  2516. //*----------------------------------------------------------------------------
  2517. __inline void AT91F_UDP_EpWrite(
  2518. AT91PS_UDP pUDP, // \arg pointer to a UDP controller
  2519. unsigned char endpoint, // \arg endpoint number
  2520. unsigned char value) // \arg value to be written in the DPR
  2521. {
  2522. pUDP->UDP_FDR[endpoint] = value;
  2523. }
  2524. //*----------------------------------------------------------------------------
  2525. //* \fn AT91F_UDP_EpRead
  2526. //* \brief Return value from the DPR
  2527. //*----------------------------------------------------------------------------
  2528. __inline unsigned int AT91F_UDP_EpRead(
  2529. AT91PS_UDP pUDP, // \arg pointer to a UDP controller
  2530. unsigned char endpoint) // \arg endpoint number
  2531. {
  2532. return pUDP->UDP_FDR[endpoint];
  2533. }
  2534. //*----------------------------------------------------------------------------
  2535. //* \fn AT91F_UDP_EpEndOfWr
  2536. //* \brief Notify the UDP that values in DPR are ready to be sent
  2537. //*----------------------------------------------------------------------------
  2538. __inline void AT91F_UDP_EpEndOfWr(
  2539. AT91PS_UDP pUDP, // \arg pointer to a UDP controller
  2540. unsigned char endpoint) // \arg endpoint number
  2541. {
  2542. pUDP->UDP_CSR[endpoint] |= AT91C_UDP_TXPKTRDY;
  2543. }
  2544. //*----------------------------------------------------------------------------
  2545. //* \fn AT91F_UDP_EpClear
  2546. //* \brief Clear flag in the endpoint CSR register
  2547. //*----------------------------------------------------------------------------
  2548. __inline void AT91F_UDP_EpClear(
  2549. AT91PS_UDP pUDP, // \arg pointer to a UDP controller
  2550. unsigned char endpoint, // \arg endpoint number
  2551. unsigned int flag) // \arg flag to be cleared
  2552. {
  2553. pUDP->UDP_CSR[endpoint] &= ~(flag);
  2554. }
  2555. //*----------------------------------------------------------------------------
  2556. //* \fn AT91F_UDP_EpSet
  2557. //* \brief Set flag in the endpoint CSR register
  2558. //*----------------------------------------------------------------------------
  2559. __inline void AT91F_UDP_EpSet(
  2560. AT91PS_UDP pUDP, // \arg pointer to a UDP controller
  2561. unsigned char endpoint, // \arg endpoint number
  2562. unsigned int flag) // \arg flag to be cleared
  2563. {
  2564. pUDP->UDP_CSR[endpoint] |= flag;
  2565. }
  2566. //*----------------------------------------------------------------------------
  2567. //* \fn AT91F_UDP_EpStatus
  2568. //* \brief Return the endpoint CSR register
  2569. //*----------------------------------------------------------------------------
  2570. __inline unsigned int AT91F_UDP_EpStatus(
  2571. AT91PS_UDP pUDP, // \arg pointer to a UDP controller
  2572. unsigned char endpoint) // \arg endpoint number
  2573. {
  2574. return pUDP->UDP_CSR[endpoint];
  2575. }
  2576. //*----------------------------------------------------------------------------
  2577. //* \fn AT91F_UDP_GetInterruptMaskStatus
  2578. //* \brief Return UDP Interrupt Mask Status
  2579. //*----------------------------------------------------------------------------
  2580. __inline unsigned int AT91F_UDP_GetInterruptMaskStatus( // \return UDP Interrupt Mask Status
  2581. AT91PS_UDP pUdp) // \arg pointer to a UDP controller
  2582. {
  2583. return pUdp->UDP_IMR;
  2584. }
  2585. //*----------------------------------------------------------------------------
  2586. //* \fn AT91F_UDP_IsInterruptMasked
  2587. //* \brief Test if UDP Interrupt is Masked
  2588. //*----------------------------------------------------------------------------
  2589. __inline int AT91F_UDP_IsInterruptMasked(
  2590. AT91PS_UDP pUdp, // \arg pointer to a UDP controller
  2591. unsigned int flag) // \arg flag to be tested
  2592. {
  2593. return (AT91F_UDP_GetInterruptMaskStatus(pUdp) & flag);
  2594. }
  2595. /* *****************************************************************************
  2596. SOFTWARE API FOR TC
  2597. ***************************************************************************** */
  2598. //*----------------------------------------------------------------------------
  2599. //* \fn AT91F_TC_InterruptEnable
  2600. //* \brief Enable TC Interrupt
  2601. //*----------------------------------------------------------------------------
  2602. __inline void AT91F_TC_InterruptEnable(
  2603. AT91PS_TC pTc, // \arg pointer to a TC controller
  2604. unsigned int flag) // \arg TC interrupt to be enabled
  2605. {
  2606. pTc->TC_IER = flag;
  2607. }
  2608. //*----------------------------------------------------------------------------
  2609. //* \fn AT91F_TC_InterruptDisable
  2610. //* \brief Disable TC Interrupt
  2611. //*----------------------------------------------------------------------------
  2612. __inline void AT91F_TC_InterruptDisable(
  2613. AT91PS_TC pTc, // \arg pointer to a TC controller
  2614. unsigned int flag) // \arg TC interrupt to be disabled
  2615. {
  2616. pTc->TC_IDR = flag;
  2617. }
  2618. //*----------------------------------------------------------------------------
  2619. //* \fn AT91F_TC_GetInterruptMaskStatus
  2620. //* \brief Return TC Interrupt Mask Status
  2621. //*----------------------------------------------------------------------------
  2622. __inline unsigned int AT91F_TC_GetInterruptMaskStatus( // \return TC Interrupt Mask Status
  2623. AT91PS_TC pTc) // \arg pointer to a TC controller
  2624. {
  2625. return pTc->TC_IMR;
  2626. }
  2627. //*----------------------------------------------------------------------------
  2628. //* \fn AT91F_TC_IsInterruptMasked
  2629. //* \brief Test if TC Interrupt is Masked
  2630. //*----------------------------------------------------------------------------
  2631. __inline int AT91F_TC_IsInterruptMasked(
  2632. AT91PS_TC pTc, // \arg pointer to a TC controller
  2633. unsigned int flag) // \arg flag to be tested
  2634. {
  2635. return (AT91F_TC_GetInterruptMaskStatus(pTc) & flag);
  2636. }
  2637. /* *****************************************************************************
  2638. SOFTWARE API FOR CAN
  2639. ***************************************************************************** */
  2640. #define STANDARD_FORMAT 0
  2641. #define EXTENDED_FORMAT 1
  2642. //*----------------------------------------------------------------------------
  2643. //* \fn AT91F_InitMailboxRegisters()
  2644. //* \brief Configure the corresponding mailbox
  2645. //*----------------------------------------------------------------------------
  2646. __inline void AT91F_InitMailboxRegisters(AT91PS_CAN_MB CAN_Mailbox,
  2647. int mode_reg,
  2648. int acceptance_mask_reg,
  2649. int id_reg,
  2650. int data_low_reg,
  2651. int data_high_reg,
  2652. int control_reg)
  2653. {
  2654. CAN_Mailbox->CAN_MB_MCR = 0x0;
  2655. CAN_Mailbox->CAN_MB_MMR = mode_reg;
  2656. CAN_Mailbox->CAN_MB_MAM = acceptance_mask_reg;
  2657. CAN_Mailbox->CAN_MB_MID = id_reg;
  2658. CAN_Mailbox->CAN_MB_MDL = data_low_reg;
  2659. CAN_Mailbox->CAN_MB_MDH = data_high_reg;
  2660. CAN_Mailbox->CAN_MB_MCR = control_reg;
  2661. }
  2662. //*----------------------------------------------------------------------------
  2663. //* \fn AT91F_EnableCAN()
  2664. //* \brief
  2665. //*----------------------------------------------------------------------------
  2666. __inline void AT91F_EnableCAN(
  2667. AT91PS_CAN pCAN) // pointer to a CAN controller
  2668. {
  2669. pCAN->CAN_MR |= AT91C_CAN_CANEN;
  2670. // Wait for WAKEUP flag raising <=> 11-recessive-bit were scanned by the transceiver
  2671. while( (pCAN->CAN_SR & AT91C_CAN_WAKEUP) != AT91C_CAN_WAKEUP );
  2672. }
  2673. //*----------------------------------------------------------------------------
  2674. //* \fn AT91F_DisableCAN()
  2675. //* \brief
  2676. //*----------------------------------------------------------------------------
  2677. __inline void AT91F_DisableCAN(
  2678. AT91PS_CAN pCAN) // pointer to a CAN controller
  2679. {
  2680. pCAN->CAN_MR &= ~AT91C_CAN_CANEN;
  2681. }
  2682. //*----------------------------------------------------------------------------
  2683. //* \fn AT91F_CAN_EnableIt
  2684. //* \brief Enable CAN interrupt
  2685. //*----------------------------------------------------------------------------
  2686. __inline void AT91F_CAN_EnableIt (
  2687. AT91PS_CAN pCAN, // pointer to a CAN controller
  2688. unsigned int flag) // IT to be enabled
  2689. {
  2690. //* Write to the IER register
  2691. pCAN->CAN_IER = flag;
  2692. }
  2693. //*----------------------------------------------------------------------------
  2694. //* \fn AT91F_CAN_DisableIt
  2695. //* \brief Disable CAN interrupt
  2696. //*----------------------------------------------------------------------------
  2697. __inline void AT91F_CAN_DisableIt (
  2698. AT91PS_CAN pCAN, // pointer to a CAN controller
  2699. unsigned int flag) // IT to be disabled
  2700. {
  2701. //* Write to the IDR register
  2702. pCAN->CAN_IDR = flag;
  2703. }
  2704. //*----------------------------------------------------------------------------
  2705. //* \fn AT91F_CAN_GetStatus
  2706. //* \brief Return CAN Interrupt Status
  2707. //*----------------------------------------------------------------------------
  2708. __inline unsigned int AT91F_CAN_GetStatus( // \return CAN Interrupt Status
  2709. AT91PS_CAN pCAN) // pointer to a CAN controller
  2710. {
  2711. return pCAN->CAN_SR;
  2712. }
  2713. //*----------------------------------------------------------------------------
  2714. //* \fn AT91F_CAN_GetInterruptMaskStatus
  2715. //* \brief Return CAN Interrupt Mask Status
  2716. //*----------------------------------------------------------------------------
  2717. __inline unsigned int AT91F_CAN_GetInterruptMaskStatus( // \return CAN Interrupt Mask Status
  2718. AT91PS_CAN pCAN) // pointer to a CAN controller
  2719. {
  2720. return pCAN->CAN_IMR;
  2721. }
  2722. //*----------------------------------------------------------------------------
  2723. //* \fn AT91F_CAN_IsInterruptMasked
  2724. //* \brief Test if CAN Interrupt is Masked
  2725. //*----------------------------------------------------------------------------
  2726. __inline unsigned int AT91F_CAN_IsInterruptMasked(
  2727. AT91PS_CAN pCAN, // \arg pointer to a CAN controller
  2728. unsigned int flag) // \arg flag to be tested
  2729. {
  2730. return (AT91F_CAN_GetInterruptMaskStatus(pCAN) & flag);
  2731. }
  2732. //*----------------------------------------------------------------------------
  2733. //* \fn AT91F_CAN_IsStatusSet
  2734. //* \brief Test if CAN Interrupt is Set
  2735. //*----------------------------------------------------------------------------
  2736. __inline unsigned int AT91F_CAN_IsStatusSet(
  2737. AT91PS_CAN pCAN, // \arg pointer to a CAN controller
  2738. unsigned int flag) // \arg flag to be tested
  2739. {
  2740. return (AT91F_CAN_GetStatus(pCAN) & flag);
  2741. }
  2742. //*----------------------------------------------------------------------------
  2743. //* \fn AT91F_CAN_CfgModeReg
  2744. //* \brief Configure the Mode Register of the CAN controller
  2745. //*----------------------------------------------------------------------------
  2746. __inline void AT91F_CAN_CfgModeReg (
  2747. AT91PS_CAN pCAN, // pointer to a CAN controller
  2748. unsigned int mode) // mode register
  2749. {
  2750. //* Write to the MR register
  2751. pCAN->CAN_MR = mode;
  2752. }
  2753. //*----------------------------------------------------------------------------
  2754. //* \fn AT91F_CAN_GetModeReg
  2755. //* \brief Return the Mode Register of the CAN controller value
  2756. //*----------------------------------------------------------------------------
  2757. __inline unsigned int AT91F_CAN_GetModeReg (
  2758. AT91PS_CAN pCAN // pointer to a CAN controller
  2759. )
  2760. {
  2761. return pCAN->CAN_MR;
  2762. }
  2763. //*----------------------------------------------------------------------------
  2764. //* \fn AT91F_CAN_CfgBaudrateReg
  2765. //* \brief Configure the Baudrate of the CAN controller for the network
  2766. //*----------------------------------------------------------------------------
  2767. __inline void AT91F_CAN_CfgBaudrateReg (
  2768. AT91PS_CAN pCAN, // pointer to a CAN controller
  2769. unsigned int baudrate_cfg)
  2770. {
  2771. //* Write to the BR register
  2772. pCAN->CAN_BR = baudrate_cfg;
  2773. }
  2774. //*----------------------------------------------------------------------------
  2775. //* \fn AT91F_CAN_GetBaudrate
  2776. //* \brief Return the Baudrate of the CAN controller for the network value
  2777. //*----------------------------------------------------------------------------
  2778. __inline unsigned int AT91F_CAN_GetBaudrate (
  2779. AT91PS_CAN pCAN // pointer to a CAN controller
  2780. )
  2781. {
  2782. return pCAN->CAN_BR;
  2783. }
  2784. //*----------------------------------------------------------------------------
  2785. //* \fn AT91F_CAN_GetInternalCounter
  2786. //* \brief Return CAN Timer Regsiter Value
  2787. //*----------------------------------------------------------------------------
  2788. __inline unsigned int AT91F_CAN_GetInternalCounter (
  2789. AT91PS_CAN pCAN // pointer to a CAN controller
  2790. )
  2791. {
  2792. return pCAN->CAN_TIM;
  2793. }
  2794. //*----------------------------------------------------------------------------
  2795. //* \fn AT91F_CAN_GetTimestamp
  2796. //* \brief Return CAN Timestamp Register Value
  2797. //*----------------------------------------------------------------------------
  2798. __inline unsigned int AT91F_CAN_GetTimestamp (
  2799. AT91PS_CAN pCAN // pointer to a CAN controller
  2800. )
  2801. {
  2802. return pCAN->CAN_TIMESTP;
  2803. }
  2804. //*----------------------------------------------------------------------------
  2805. //* \fn AT91F_CAN_GetErrorCounter
  2806. //* \brief Return CAN Error Counter Register Value
  2807. //*----------------------------------------------------------------------------
  2808. __inline unsigned int AT91F_CAN_GetErrorCounter (
  2809. AT91PS_CAN pCAN // pointer to a CAN controller
  2810. )
  2811. {
  2812. return pCAN->CAN_ECR;
  2813. }
  2814. //*----------------------------------------------------------------------------
  2815. //* \fn AT91F_CAN_InitTransferRequest
  2816. //* \brief Request for a transfer on the corresponding mailboxes
  2817. //*----------------------------------------------------------------------------
  2818. __inline void AT91F_CAN_InitTransferRequest (
  2819. AT91PS_CAN pCAN, // pointer to a CAN controller
  2820. unsigned int transfer_cmd)
  2821. {
  2822. pCAN->CAN_TCR = transfer_cmd;
  2823. }
  2824. //*----------------------------------------------------------------------------
  2825. //* \fn AT91F_CAN_InitAbortRequest
  2826. //* \brief Abort the corresponding mailboxes
  2827. //*----------------------------------------------------------------------------
  2828. __inline void AT91F_CAN_InitAbortRequest (
  2829. AT91PS_CAN pCAN, // pointer to a CAN controller
  2830. unsigned int abort_cmd)
  2831. {
  2832. pCAN->CAN_ACR = abort_cmd;
  2833. }
  2834. //*----------------------------------------------------------------------------
  2835. //* \fn AT91F_CAN_CfgMessageModeReg
  2836. //* \brief Program the Message Mode Register
  2837. //*----------------------------------------------------------------------------
  2838. __inline void AT91F_CAN_CfgMessageModeReg (
  2839. AT91PS_CAN_MB CAN_Mailbox, // pointer to a CAN Mailbox
  2840. unsigned int mode)
  2841. {
  2842. CAN_Mailbox->CAN_MB_MMR = mode;
  2843. }
  2844. //*----------------------------------------------------------------------------
  2845. //* \fn AT91F_CAN_GetMessageModeReg
  2846. //* \brief Return the Message Mode Register
  2847. //*----------------------------------------------------------------------------
  2848. __inline unsigned int AT91F_CAN_GetMessageModeReg (
  2849. AT91PS_CAN_MB CAN_Mailbox) // pointer to a CAN Mailbox
  2850. {
  2851. return CAN_Mailbox->CAN_MB_MMR;
  2852. }
  2853. //*----------------------------------------------------------------------------
  2854. //* \fn AT91F_CAN_CfgMessageIDReg
  2855. //* \brief Program the Message ID Register
  2856. //* \brief Version == 0 for Standard messsage, Version == 1 for Extended
  2857. //*----------------------------------------------------------------------------
  2858. __inline void AT91F_CAN_CfgMessageIDReg (
  2859. AT91PS_CAN_MB CAN_Mailbox, // pointer to a CAN Mailbox
  2860. unsigned int id,
  2861. unsigned char version)
  2862. {
  2863. if(version==0) // IDvA Standard Format
  2864. CAN_Mailbox->CAN_MB_MID = id<<18;
  2865. else // IDvB Extended Format
  2866. CAN_Mailbox->CAN_MB_MID = id | (1<<29); // set MIDE bit
  2867. }
  2868. //*----------------------------------------------------------------------------
  2869. //* \fn AT91F_CAN_GetMessageIDReg
  2870. //* \brief Return the Message ID Register
  2871. //*----------------------------------------------------------------------------
  2872. __inline unsigned int AT91F_CAN_GetMessageIDReg (
  2873. AT91PS_CAN_MB CAN_Mailbox) // pointer to a CAN Mailbox
  2874. {
  2875. return CAN_Mailbox->CAN_MB_MID;
  2876. }
  2877. //*----------------------------------------------------------------------------
  2878. //* \fn AT91F_CAN_CfgMessageAcceptanceMaskReg
  2879. //* \brief Program the Message Acceptance Mask Register
  2880. //*----------------------------------------------------------------------------
  2881. __inline void AT91F_CAN_CfgMessageAcceptanceMaskReg (
  2882. AT91PS_CAN_MB CAN_Mailbox, // pointer to a CAN Mailbox
  2883. unsigned int mask)
  2884. {
  2885. CAN_Mailbox->CAN_MB_MAM = mask;
  2886. }
  2887. //*----------------------------------------------------------------------------
  2888. //* \fn AT91F_CAN_GetMessageAcceptanceMaskReg
  2889. //* \brief Return the Message Acceptance Mask Register
  2890. //*----------------------------------------------------------------------------
  2891. __inline unsigned int AT91F_CAN_GetMessageAcceptanceMaskReg (
  2892. AT91PS_CAN_MB CAN_Mailbox) // pointer to a CAN Mailbox
  2893. {
  2894. return CAN_Mailbox->CAN_MB_MAM;
  2895. }
  2896. //*----------------------------------------------------------------------------
  2897. //* \fn AT91F_CAN_GetFamilyID
  2898. //* \brief Return the Message ID Register
  2899. //*----------------------------------------------------------------------------
  2900. __inline unsigned int AT91F_CAN_GetFamilyID (
  2901. AT91PS_CAN_MB CAN_Mailbox) // pointer to a CAN Mailbox
  2902. {
  2903. return CAN_Mailbox->CAN_MB_MFID;
  2904. }
  2905. //*----------------------------------------------------------------------------
  2906. //* \fn AT91F_CAN_CfgMessageCtrl
  2907. //* \brief Request and config for a transfer on the corresponding mailbox
  2908. //*----------------------------------------------------------------------------
  2909. __inline void AT91F_CAN_CfgMessageCtrlReg (
  2910. AT91PS_CAN_MB CAN_Mailbox, // pointer to a CAN Mailbox
  2911. unsigned int message_ctrl_cmd)
  2912. {
  2913. CAN_Mailbox->CAN_MB_MCR = message_ctrl_cmd;
  2914. }
  2915. //*----------------------------------------------------------------------------
  2916. //* \fn AT91F_CAN_GetMessageStatus
  2917. //* \brief Return CAN Mailbox Status
  2918. //*----------------------------------------------------------------------------
  2919. __inline unsigned int AT91F_CAN_GetMessageStatus (
  2920. AT91PS_CAN_MB CAN_Mailbox) // pointer to a CAN Mailbox
  2921. {
  2922. return CAN_Mailbox->CAN_MB_MSR;
  2923. }
  2924. //*----------------------------------------------------------------------------
  2925. //* \fn AT91F_CAN_CfgMessageDataLow
  2926. //* \brief Program data low value
  2927. //*----------------------------------------------------------------------------
  2928. __inline void AT91F_CAN_CfgMessageDataLow (
  2929. AT91PS_CAN_MB CAN_Mailbox, // pointer to a CAN Mailbox
  2930. unsigned int data)
  2931. {
  2932. CAN_Mailbox->CAN_MB_MDL = data;
  2933. }
  2934. //*----------------------------------------------------------------------------
  2935. //* \fn AT91F_CAN_GetMessageDataLow
  2936. //* \brief Return data low value
  2937. //*----------------------------------------------------------------------------
  2938. __inline unsigned int AT91F_CAN_GetMessageDataLow (
  2939. AT91PS_CAN_MB CAN_Mailbox) // pointer to a CAN Mailbox
  2940. {
  2941. return CAN_Mailbox->CAN_MB_MDL;
  2942. }
  2943. //*----------------------------------------------------------------------------
  2944. //* \fn AT91F_CAN_CfgMessageDataHigh
  2945. //* \brief Program data high value
  2946. //*----------------------------------------------------------------------------
  2947. __inline void AT91F_CAN_CfgMessageDataHigh (
  2948. AT91PS_CAN_MB CAN_Mailbox, // pointer to a CAN Mailbox
  2949. unsigned int data)
  2950. {
  2951. CAN_Mailbox->CAN_MB_MDH = data;
  2952. }
  2953. //*----------------------------------------------------------------------------
  2954. //* \fn AT91F_CAN_GetMessageDataHigh
  2955. //* \brief Return data high value
  2956. //*----------------------------------------------------------------------------
  2957. __inline unsigned int AT91F_CAN_GetMessageDataHigh (
  2958. AT91PS_CAN_MB CAN_Mailbox) // pointer to a CAN Mailbox
  2959. {
  2960. return CAN_Mailbox->CAN_MB_MDH;
  2961. }
  2962. //*----------------------------------------------------------------------------
  2963. //* \fn AT91F_CAN_Open
  2964. //* \brief Open a CAN Port
  2965. //*----------------------------------------------------------------------------
  2966. __inline unsigned int AT91F_CAN_Open (
  2967. const unsigned int null) // \arg
  2968. {
  2969. /* NOT DEFINED AT THIS MOMENT */
  2970. return ( 0 );
  2971. }
  2972. /* *****************************************************************************
  2973. SOFTWARE API FOR ADC
  2974. ***************************************************************************** */
  2975. //*----------------------------------------------------------------------------
  2976. //* \fn AT91F_ADC_EnableIt
  2977. //* \brief Enable ADC interrupt
  2978. //*----------------------------------------------------------------------------
  2979. __inline void AT91F_ADC_EnableIt (
  2980. AT91PS_ADC pADC, // pointer to a ADC controller
  2981. unsigned int flag) // IT to be enabled
  2982. {
  2983. //* Write to the IER register
  2984. pADC->ADC_IER = flag;
  2985. }
  2986. //*----------------------------------------------------------------------------
  2987. //* \fn AT91F_ADC_DisableIt
  2988. //* \brief Disable ADC interrupt
  2989. //*----------------------------------------------------------------------------
  2990. __inline void AT91F_ADC_DisableIt (
  2991. AT91PS_ADC pADC, // pointer to a ADC controller
  2992. unsigned int flag) // IT to be disabled
  2993. {
  2994. //* Write to the IDR register
  2995. pADC->ADC_IDR = flag;
  2996. }
  2997. //*----------------------------------------------------------------------------
  2998. //* \fn AT91F_ADC_GetStatus
  2999. //* \brief Return ADC Interrupt Status
  3000. //*----------------------------------------------------------------------------
  3001. __inline unsigned int AT91F_ADC_GetStatus( // \return ADC Interrupt Status
  3002. AT91PS_ADC pADC) // pointer to a ADC controller
  3003. {
  3004. return pADC->ADC_SR;
  3005. }
  3006. //*----------------------------------------------------------------------------
  3007. //* \fn AT91F_ADC_GetInterruptMaskStatus
  3008. //* \brief Return ADC Interrupt Mask Status
  3009. //*----------------------------------------------------------------------------
  3010. __inline unsigned int AT91F_ADC_GetInterruptMaskStatus( // \return ADC Interrupt Mask Status
  3011. AT91PS_ADC pADC) // pointer to a ADC controller
  3012. {
  3013. return pADC->ADC_IMR;
  3014. }
  3015. //*----------------------------------------------------------------------------
  3016. //* \fn AT91F_ADC_IsInterruptMasked
  3017. //* \brief Test if ADC Interrupt is Masked
  3018. //*----------------------------------------------------------------------------
  3019. __inline unsigned int AT91F_ADC_IsInterruptMasked(
  3020. AT91PS_ADC pADC, // \arg pointer to a ADC controller
  3021. unsigned int flag) // \arg flag to be tested
  3022. {
  3023. return (AT91F_ADC_GetInterruptMaskStatus(pADC) & flag);
  3024. }
  3025. //*----------------------------------------------------------------------------
  3026. //* \fn AT91F_ADC_IsStatusSet
  3027. //* \brief Test if ADC Status is Set
  3028. //*----------------------------------------------------------------------------
  3029. __inline unsigned int AT91F_ADC_IsStatusSet(
  3030. AT91PS_ADC pADC, // \arg pointer to a ADC controller
  3031. unsigned int flag) // \arg flag to be tested
  3032. {
  3033. return (AT91F_ADC_GetStatus(pADC) & flag);
  3034. }
  3035. //*----------------------------------------------------------------------------
  3036. //* \fn AT91F_ADC_CfgModeReg
  3037. //* \brief Configure the Mode Register of the ADC controller
  3038. //*----------------------------------------------------------------------------
  3039. __inline void AT91F_ADC_CfgModeReg (
  3040. AT91PS_ADC pADC, // pointer to a ADC controller
  3041. unsigned int mode) // mode register
  3042. {
  3043. //* Write to the MR register
  3044. pADC->ADC_MR = mode;
  3045. }
  3046. //*----------------------------------------------------------------------------
  3047. //* \fn AT91F_ADC_GetModeReg
  3048. //* \brief Return the Mode Register of the ADC controller value
  3049. //*----------------------------------------------------------------------------
  3050. __inline unsigned int AT91F_ADC_GetModeReg (
  3051. AT91PS_ADC pADC // pointer to a ADC controller
  3052. )
  3053. {
  3054. return pADC->ADC_MR;
  3055. }
  3056. //*----------------------------------------------------------------------------
  3057. //* \fn AT91F_ADC_CfgTimings
  3058. //* \brief Configure the different necessary timings of the ADC controller
  3059. //*----------------------------------------------------------------------------
  3060. __inline void AT91F_ADC_CfgTimings (
  3061. AT91PS_ADC pADC, // pointer to a ADC controller
  3062. unsigned int mck_clock, // in MHz
  3063. unsigned int adc_clock, // in MHz
  3064. unsigned int startup_time, // in us
  3065. unsigned int sample_and_hold_time) // in ns
  3066. {
  3067. unsigned int prescal,startup,shtim;
  3068. prescal = mck_clock/(2*adc_clock) - 1;
  3069. startup = adc_clock*startup_time/8 - 1;
  3070. shtim = adc_clock*sample_and_hold_time/1000 - 1;
  3071. //* Write to the MR register
  3072. pADC->ADC_MR = ( (prescal<<8) & AT91C_ADC_PRESCAL) | ( (startup<<16) & AT91C_ADC_STARTUP) | ( (shtim<<24) & AT91C_ADC_SHTIM);
  3073. }
  3074. //*----------------------------------------------------------------------------
  3075. //* \fn AT91F_ADC_EnableChannel
  3076. //* \brief Return ADC Timer Register Value
  3077. //*----------------------------------------------------------------------------
  3078. __inline void AT91F_ADC_EnableChannel (
  3079. AT91PS_ADC pADC, // pointer to a ADC controller
  3080. unsigned int channel) // mode register
  3081. {
  3082. //* Write to the CHER register
  3083. pADC->ADC_CHER = channel;
  3084. }
  3085. //*----------------------------------------------------------------------------
  3086. //* \fn AT91F_ADC_DisableChannel
  3087. //* \brief Return ADC Timer Register Value
  3088. //*----------------------------------------------------------------------------
  3089. __inline void AT91F_ADC_DisableChannel (
  3090. AT91PS_ADC pADC, // pointer to a ADC controller
  3091. unsigned int channel) // mode register
  3092. {
  3093. //* Write to the CHDR register
  3094. pADC->ADC_CHDR = channel;
  3095. }
  3096. //*----------------------------------------------------------------------------
  3097. //* \fn AT91F_ADC_GetChannelStatus
  3098. //* \brief Return ADC Timer Register Value
  3099. //*----------------------------------------------------------------------------
  3100. __inline unsigned int AT91F_ADC_GetChannelStatus (
  3101. AT91PS_ADC pADC // pointer to a ADC controller
  3102. )
  3103. {
  3104. return pADC->ADC_CHSR;
  3105. }
  3106. //*----------------------------------------------------------------------------
  3107. //* \fn AT91F_ADC_StartConversion
  3108. //* \brief Software request for a analog to digital conversion
  3109. //*----------------------------------------------------------------------------
  3110. __inline void AT91F_ADC_StartConversion (
  3111. AT91PS_ADC pADC // pointer to a ADC controller
  3112. )
  3113. {
  3114. pADC->ADC_CR = AT91C_ADC_START;
  3115. }
  3116. //*----------------------------------------------------------------------------
  3117. //* \fn AT91F_ADC_SoftReset
  3118. //* \brief Software reset
  3119. //*----------------------------------------------------------------------------
  3120. __inline void AT91F_ADC_SoftReset (
  3121. AT91PS_ADC pADC // pointer to a ADC controller
  3122. )
  3123. {
  3124. pADC->ADC_CR = AT91C_ADC_SWRST;
  3125. }
  3126. //*----------------------------------------------------------------------------
  3127. //* \fn AT91F_ADC_GetLastConvertedData
  3128. //* \brief Return the Last Converted Data
  3129. //*----------------------------------------------------------------------------
  3130. __inline unsigned int AT91F_ADC_GetLastConvertedData (
  3131. AT91PS_ADC pADC // pointer to a ADC controller
  3132. )
  3133. {
  3134. return pADC->ADC_LCDR;
  3135. }
  3136. //*----------------------------------------------------------------------------
  3137. //* \fn AT91F_ADC_GetConvertedDataCH0
  3138. //* \brief Return the Channel 0 Converted Data
  3139. //*----------------------------------------------------------------------------
  3140. __inline unsigned int AT91F_ADC_GetConvertedDataCH0 (
  3141. AT91PS_ADC pADC // pointer to a ADC controller
  3142. )
  3143. {
  3144. return pADC->ADC_CDR0;
  3145. }
  3146. //*----------------------------------------------------------------------------
  3147. //* \fn AT91F_ADC_GetConvertedDataCH1
  3148. //* \brief Return the Channel 1 Converted Data
  3149. //*----------------------------------------------------------------------------
  3150. __inline unsigned int AT91F_ADC_GetConvertedDataCH1 (
  3151. AT91PS_ADC pADC // pointer to a ADC controller
  3152. )
  3153. {
  3154. return pADC->ADC_CDR1;
  3155. }
  3156. //*----------------------------------------------------------------------------
  3157. //* \fn AT91F_ADC_GetConvertedDataCH2
  3158. //* \brief Return the Channel 2 Converted Data
  3159. //*----------------------------------------------------------------------------
  3160. __inline unsigned int AT91F_ADC_GetConvertedDataCH2 (
  3161. AT91PS_ADC pADC // pointer to a ADC controller
  3162. )
  3163. {
  3164. return pADC->ADC_CDR2;
  3165. }
  3166. //*----------------------------------------------------------------------------
  3167. //* \fn AT91F_ADC_GetConvertedDataCH3
  3168. //* \brief Return the Channel 3 Converted Data
  3169. //*----------------------------------------------------------------------------
  3170. __inline unsigned int AT91F_ADC_GetConvertedDataCH3 (
  3171. AT91PS_ADC pADC // pointer to a ADC controller
  3172. )
  3173. {
  3174. return pADC->ADC_CDR3;
  3175. }
  3176. //*----------------------------------------------------------------------------
  3177. //* \fn AT91F_ADC_GetConvertedDataCH4
  3178. //* \brief Return the Channel 4 Converted Data
  3179. //*----------------------------------------------------------------------------
  3180. __inline unsigned int AT91F_ADC_GetConvertedDataCH4 (
  3181. AT91PS_ADC pADC // pointer to a ADC controller
  3182. )
  3183. {
  3184. return pADC->ADC_CDR4;
  3185. }
  3186. //*----------------------------------------------------------------------------
  3187. //* \fn AT91F_ADC_GetConvertedDataCH5
  3188. //* \brief Return the Channel 5 Converted Data
  3189. //*----------------------------------------------------------------------------
  3190. __inline unsigned int AT91F_ADC_GetConvertedDataCH5 (
  3191. AT91PS_ADC pADC // pointer to a ADC controller
  3192. )
  3193. {
  3194. return pADC->ADC_CDR5;
  3195. }
  3196. //*----------------------------------------------------------------------------
  3197. //* \fn AT91F_ADC_GetConvertedDataCH6
  3198. //* \brief Return the Channel 6 Converted Data
  3199. //*----------------------------------------------------------------------------
  3200. __inline unsigned int AT91F_ADC_GetConvertedDataCH6 (
  3201. AT91PS_ADC pADC // pointer to a ADC controller
  3202. )
  3203. {
  3204. return pADC->ADC_CDR6;
  3205. }
  3206. //*----------------------------------------------------------------------------
  3207. //* \fn AT91F_ADC_GetConvertedDataCH7
  3208. //* \brief Return the Channel 7 Converted Data
  3209. //*----------------------------------------------------------------------------
  3210. __inline unsigned int AT91F_ADC_GetConvertedDataCH7 (
  3211. AT91PS_ADC pADC // pointer to a ADC controller
  3212. )
  3213. {
  3214. return pADC->ADC_CDR7;
  3215. }
  3216. /* *****************************************************************************
  3217. SOFTWARE API FOR AES
  3218. ***************************************************************************** */
  3219. //*----------------------------------------------------------------------------
  3220. //* \fn AT91F_AES_EnableIt
  3221. //* \brief Enable AES interrupt
  3222. //*----------------------------------------------------------------------------
  3223. __inline void AT91F_AES_EnableIt (
  3224. AT91PS_AES pAES, // pointer to a AES controller
  3225. unsigned int flag) // IT to be enabled
  3226. {
  3227. //* Write to the IER register
  3228. pAES->AES_IER = flag;
  3229. }
  3230. //*----------------------------------------------------------------------------
  3231. //* \fn AT91F_AES_DisableIt
  3232. //* \brief Disable AES interrupt
  3233. //*----------------------------------------------------------------------------
  3234. __inline void AT91F_AES_DisableIt (
  3235. AT91PS_AES pAES, // pointer to a AES controller
  3236. unsigned int flag) // IT to be disabled
  3237. {
  3238. //* Write to the IDR register
  3239. pAES->AES_IDR = flag;
  3240. }
  3241. //*----------------------------------------------------------------------------
  3242. //* \fn AT91F_AES_GetStatus
  3243. //* \brief Return AES Interrupt Status
  3244. //*----------------------------------------------------------------------------
  3245. __inline unsigned int AT91F_AES_GetStatus( // \return AES Interrupt Status
  3246. AT91PS_AES pAES) // pointer to a AES controller
  3247. {
  3248. return pAES->AES_ISR;
  3249. }
  3250. //*----------------------------------------------------------------------------
  3251. //* \fn AT91F_AES_GetInterruptMaskStatus
  3252. //* \brief Return AES Interrupt Mask Status
  3253. //*----------------------------------------------------------------------------
  3254. __inline unsigned int AT91F_AES_GetInterruptMaskStatus( // \return AES Interrupt Mask Status
  3255. AT91PS_AES pAES) // pointer to a AES controller
  3256. {
  3257. return pAES->AES_IMR;
  3258. }
  3259. //*----------------------------------------------------------------------------
  3260. //* \fn AT91F_AES_IsInterruptMasked
  3261. //* \brief Test if AES Interrupt is Masked
  3262. //*----------------------------------------------------------------------------
  3263. __inline unsigned int AT91F_AES_IsInterruptMasked(
  3264. AT91PS_AES pAES, // \arg pointer to a AES controller
  3265. unsigned int flag) // \arg flag to be tested
  3266. {
  3267. return (AT91F_AES_GetInterruptMaskStatus(pAES) & flag);
  3268. }
  3269. //*----------------------------------------------------------------------------
  3270. //* \fn AT91F_AES_IsStatusSet
  3271. //* \brief Test if AES Status is Set
  3272. //*----------------------------------------------------------------------------
  3273. __inline unsigned int AT91F_AES_IsStatusSet(
  3274. AT91PS_AES pAES, // \arg pointer to a AES controller
  3275. unsigned int flag) // \arg flag to be tested
  3276. {
  3277. return (AT91F_AES_GetStatus(pAES) & flag);
  3278. }
  3279. //*----------------------------------------------------------------------------
  3280. //* \fn AT91F_AES_CfgModeReg
  3281. //* \brief Configure the Mode Register of the AES controller
  3282. //*----------------------------------------------------------------------------
  3283. __inline void AT91F_AES_CfgModeReg (
  3284. AT91PS_AES pAES, // pointer to a AES controller
  3285. unsigned int mode) // mode register
  3286. {
  3287. //* Write to the MR register
  3288. pAES->AES_MR = mode;
  3289. }
  3290. //*----------------------------------------------------------------------------
  3291. //* \fn AT91F_AES_GetModeReg
  3292. //* \brief Return the Mode Register of the AES controller value
  3293. //*----------------------------------------------------------------------------
  3294. __inline unsigned int AT91F_AES_GetModeReg (
  3295. AT91PS_AES pAES // pointer to a AES controller
  3296. )
  3297. {
  3298. return pAES->AES_MR;
  3299. }
  3300. //*----------------------------------------------------------------------------
  3301. //* \fn AT91F_AES_StartProcessing
  3302. //* \brief Start Encryption or Decryption
  3303. //*----------------------------------------------------------------------------
  3304. __inline void AT91F_AES_StartProcessing (
  3305. AT91PS_AES pAES // pointer to a AES controller
  3306. )
  3307. {
  3308. pAES->AES_CR = AT91C_AES_START;
  3309. }
  3310. //*----------------------------------------------------------------------------
  3311. //* \fn AT91F_AES_SoftReset
  3312. //* \brief Reset AES
  3313. //*----------------------------------------------------------------------------
  3314. __inline void AT91F_AES_SoftReset (
  3315. AT91PS_AES pAES // pointer to a AES controller
  3316. )
  3317. {
  3318. pAES->AES_CR = AT91C_AES_SWRST;
  3319. }
  3320. //*----------------------------------------------------------------------------
  3321. //* \fn AT91F_AES_LoadNewSeed
  3322. //* \brief Load New Seed in the random number generator
  3323. //*----------------------------------------------------------------------------
  3324. __inline void AT91F_AES_LoadNewSeed (
  3325. AT91PS_AES pAES // pointer to a AES controller
  3326. )
  3327. {
  3328. pAES->AES_CR = AT91C_AES_LOADSEED;
  3329. }
  3330. //*----------------------------------------------------------------------------
  3331. //* \fn AT91F_AES_SetCryptoKey
  3332. //* \brief Set Cryptographic Key x
  3333. //*----------------------------------------------------------------------------
  3334. __inline void AT91F_AES_SetCryptoKey (
  3335. AT91PS_AES pAES, // pointer to a AES controller
  3336. unsigned char index,
  3337. unsigned int keyword
  3338. )
  3339. {
  3340. pAES->AES_KEYWxR[index] = keyword;
  3341. }
  3342. //*----------------------------------------------------------------------------
  3343. //* \fn AT91F_AES_InputData
  3344. //* \brief Set Input Data x
  3345. //*----------------------------------------------------------------------------
  3346. __inline void AT91F_AES_InputData (
  3347. AT91PS_AES pAES, // pointer to a AES controller
  3348. unsigned char index,
  3349. unsigned int indata
  3350. )
  3351. {
  3352. pAES->AES_IDATAxR[index] = indata;
  3353. }
  3354. //*----------------------------------------------------------------------------
  3355. //* \fn AT91F_AES_GetOutputData
  3356. //* \brief Get Output Data x
  3357. //*----------------------------------------------------------------------------
  3358. __inline unsigned int AT91F_AES_GetOutputData (
  3359. AT91PS_AES pAES, // pointer to a AES controller
  3360. unsigned char index
  3361. )
  3362. {
  3363. return pAES->AES_ODATAxR[index];
  3364. }
  3365. //*----------------------------------------------------------------------------
  3366. //* \fn AT91F_AES_SetInitializationVector
  3367. //* \brief Set Initialization Vector (or Counter) x
  3368. //*----------------------------------------------------------------------------
  3369. __inline void AT91F_AES_SetInitializationVector (
  3370. AT91PS_AES pAES, // pointer to a AES controller
  3371. unsigned char index,
  3372. unsigned int initvector
  3373. )
  3374. {
  3375. pAES->AES_IVxR[index] = initvector;
  3376. }
  3377. /* *****************************************************************************
  3378. SOFTWARE API FOR TDES
  3379. ***************************************************************************** */
  3380. //*----------------------------------------------------------------------------
  3381. //* \fn AT91F_TDES_EnableIt
  3382. //* \brief Enable TDES interrupt
  3383. //*----------------------------------------------------------------------------
  3384. __inline void AT91F_TDES_EnableIt (
  3385. AT91PS_TDES pTDES, // pointer to a TDES controller
  3386. unsigned int flag) // IT to be enabled
  3387. {
  3388. //* Write to the IER register
  3389. pTDES->TDES_IER = flag;
  3390. }
  3391. //*----------------------------------------------------------------------------
  3392. //* \fn AT91F_TDES_DisableIt
  3393. //* \brief Disable TDES interrupt
  3394. //*----------------------------------------------------------------------------
  3395. __inline void AT91F_TDES_DisableIt (
  3396. AT91PS_TDES pTDES, // pointer to a TDES controller
  3397. unsigned int flag) // IT to be disabled
  3398. {
  3399. //* Write to the IDR register
  3400. pTDES->TDES_IDR = flag;
  3401. }
  3402. //*----------------------------------------------------------------------------
  3403. //* \fn AT91F_TDES_GetStatus
  3404. //* \brief Return TDES Interrupt Status
  3405. //*----------------------------------------------------------------------------
  3406. __inline unsigned int AT91F_TDES_GetStatus( // \return TDES Interrupt Status
  3407. AT91PS_TDES pTDES) // pointer to a TDES controller
  3408. {
  3409. return pTDES->TDES_ISR;
  3410. }
  3411. //*----------------------------------------------------------------------------
  3412. //* \fn AT91F_TDES_GetInterruptMaskStatus
  3413. //* \brief Return TDES Interrupt Mask Status
  3414. //*----------------------------------------------------------------------------
  3415. __inline unsigned int AT91F_TDES_GetInterruptMaskStatus( // \return TDES Interrupt Mask Status
  3416. AT91PS_TDES pTDES) // pointer to a TDES controller
  3417. {
  3418. return pTDES->TDES_IMR;
  3419. }
  3420. //*----------------------------------------------------------------------------
  3421. //* \fn AT91F_TDES_IsInterruptMasked
  3422. //* \brief Test if TDES Interrupt is Masked
  3423. //*----------------------------------------------------------------------------
  3424. __inline unsigned int AT91F_TDES_IsInterruptMasked(
  3425. AT91PS_TDES pTDES, // \arg pointer to a TDES controller
  3426. unsigned int flag) // \arg flag to be tested
  3427. {
  3428. return (AT91F_TDES_GetInterruptMaskStatus(pTDES) & flag);
  3429. }
  3430. //*----------------------------------------------------------------------------
  3431. //* \fn AT91F_TDES_IsStatusSet
  3432. //* \brief Test if TDES Status is Set
  3433. //*----------------------------------------------------------------------------
  3434. __inline unsigned int AT91F_TDES_IsStatusSet(
  3435. AT91PS_TDES pTDES, // \arg pointer to a TDES controller
  3436. unsigned int flag) // \arg flag to be tested
  3437. {
  3438. return (AT91F_TDES_GetStatus(pTDES) & flag);
  3439. }
  3440. //*----------------------------------------------------------------------------
  3441. //* \fn AT91F_TDES_CfgModeReg
  3442. //* \brief Configure the Mode Register of the TDES controller
  3443. //*----------------------------------------------------------------------------
  3444. __inline void AT91F_TDES_CfgModeReg (
  3445. AT91PS_TDES pTDES, // pointer to a TDES controller
  3446. unsigned int mode) // mode register
  3447. {
  3448. //* Write to the MR register
  3449. pTDES->TDES_MR = mode;
  3450. }
  3451. //*----------------------------------------------------------------------------
  3452. //* \fn AT91F_TDES_GetModeReg
  3453. //* \brief Return the Mode Register of the TDES controller value
  3454. //*----------------------------------------------------------------------------
  3455. __inline unsigned int AT91F_TDES_GetModeReg (
  3456. AT91PS_TDES pTDES // pointer to a TDES controller
  3457. )
  3458. {
  3459. return pTDES->TDES_MR;
  3460. }
  3461. //*----------------------------------------------------------------------------
  3462. //* \fn AT91F_TDES_StartProcessing
  3463. //* \brief Start Encryption or Decryption
  3464. //*----------------------------------------------------------------------------
  3465. __inline void AT91F_TDES_StartProcessing (
  3466. AT91PS_TDES pTDES // pointer to a TDES controller
  3467. )
  3468. {
  3469. pTDES->TDES_CR = AT91C_TDES_START;
  3470. }
  3471. //*----------------------------------------------------------------------------
  3472. //* \fn AT91F_TDES_SoftReset
  3473. //* \brief Reset TDES
  3474. //*----------------------------------------------------------------------------
  3475. __inline void AT91F_TDES_SoftReset (
  3476. AT91PS_TDES pTDES // pointer to a TDES controller
  3477. )
  3478. {
  3479. pTDES->TDES_CR = AT91C_TDES_SWRST;
  3480. }
  3481. //*----------------------------------------------------------------------------
  3482. //* \fn AT91F_TDES_SetCryptoKey1
  3483. //* \brief Set Cryptographic Key 1 Word x
  3484. //*----------------------------------------------------------------------------
  3485. __inline void AT91F_TDES_SetCryptoKey1 (
  3486. AT91PS_TDES pTDES, // pointer to a TDES controller
  3487. unsigned char index,
  3488. unsigned int keyword
  3489. )
  3490. {
  3491. pTDES->TDES_KEY1WxR[index] = keyword;
  3492. }
  3493. //*----------------------------------------------------------------------------
  3494. //* \fn AT91F_TDES_SetCryptoKey2
  3495. //* \brief Set Cryptographic Key 2 Word x
  3496. //*----------------------------------------------------------------------------
  3497. __inline void AT91F_TDES_SetCryptoKey2 (
  3498. AT91PS_TDES pTDES, // pointer to a TDES controller
  3499. unsigned char index,
  3500. unsigned int keyword
  3501. )
  3502. {
  3503. pTDES->TDES_KEY2WxR[index] = keyword;
  3504. }
  3505. //*----------------------------------------------------------------------------
  3506. //* \fn AT91F_TDES_SetCryptoKey3
  3507. //* \brief Set Cryptographic Key 3 Word x
  3508. //*----------------------------------------------------------------------------
  3509. __inline void AT91F_TDES_SetCryptoKey3 (
  3510. AT91PS_TDES pTDES, // pointer to a TDES controller
  3511. unsigned char index,
  3512. unsigned int keyword
  3513. )
  3514. {
  3515. pTDES->TDES_KEY3WxR[index] = keyword;
  3516. }
  3517. //*----------------------------------------------------------------------------
  3518. //* \fn AT91F_TDES_InputData
  3519. //* \brief Set Input Data x
  3520. //*----------------------------------------------------------------------------
  3521. __inline void AT91F_TDES_InputData (
  3522. AT91PS_TDES pTDES, // pointer to a TDES controller
  3523. unsigned char index,
  3524. unsigned int indata
  3525. )
  3526. {
  3527. pTDES->TDES_IDATAxR[index] = indata;
  3528. }
  3529. //*----------------------------------------------------------------------------
  3530. //* \fn AT91F_TDES_GetOutputData
  3531. //* \brief Get Output Data x
  3532. //*----------------------------------------------------------------------------
  3533. __inline unsigned int AT91F_TDES_GetOutputData (
  3534. AT91PS_TDES pTDES, // pointer to a TDES controller
  3535. unsigned char index
  3536. )
  3537. {
  3538. return pTDES->TDES_ODATAxR[index];
  3539. }
  3540. //*----------------------------------------------------------------------------
  3541. //* \fn AT91F_TDES_SetInitializationVector
  3542. //* \brief Set Initialization Vector x
  3543. //*----------------------------------------------------------------------------
  3544. __inline void AT91F_TDES_SetInitializationVector (
  3545. AT91PS_TDES pTDES, // pointer to a TDES controller
  3546. unsigned char index,
  3547. unsigned int initvector
  3548. )
  3549. {
  3550. pTDES->TDES_IVxR[index] = initvector;
  3551. }
  3552. //*----------------------------------------------------------------------------
  3553. //* \fn AT91F_DBGU_CfgPMC
  3554. //* \brief Enable Peripheral clock in PMC for DBGU
  3555. //*----------------------------------------------------------------------------
  3556. __inline void AT91F_DBGU_CfgPMC (void)
  3557. {
  3558. AT91F_PMC_EnablePeriphClock(
  3559. AT91C_BASE_PMC, // PIO controller base address
  3560. ((unsigned int) 1 << AT91C_ID_SYS));
  3561. }
  3562. //*----------------------------------------------------------------------------
  3563. //* \fn AT91F_DBGU_CfgPIO
  3564. //* \brief Configure PIO controllers to drive DBGU signals
  3565. //*----------------------------------------------------------------------------
  3566. __inline void AT91F_DBGU_CfgPIO (void)
  3567. {
  3568. // Configure PIO controllers to periph mode
  3569. AT91F_PIO_CfgPeriph(
  3570. AT91C_BASE_PIOA, // PIO controller base address
  3571. ((unsigned int) AT91C_PA27_DRXD ) |
  3572. ((unsigned int) AT91C_PA28_DTXD ), // Peripheral A
  3573. 0); // Peripheral B
  3574. }
  3575. //*----------------------------------------------------------------------------
  3576. //* \fn AT91F_PMC_CfgPMC
  3577. //* \brief Enable Peripheral clock in PMC for PMC
  3578. //*----------------------------------------------------------------------------
  3579. __inline void AT91F_PMC_CfgPMC (void)
  3580. {
  3581. AT91F_PMC_EnablePeriphClock(
  3582. AT91C_BASE_PMC, // PIO controller base address
  3583. ((unsigned int) 1 << AT91C_ID_SYS));
  3584. }
  3585. //*----------------------------------------------------------------------------
  3586. //* \fn AT91F_PMC_CfgPIO
  3587. //* \brief Configure PIO controllers to drive PMC signals
  3588. //*----------------------------------------------------------------------------
  3589. __inline void AT91F_PMC_CfgPIO (void)
  3590. {
  3591. // Configure PIO controllers to periph mode
  3592. AT91F_PIO_CfgPeriph(
  3593. AT91C_BASE_PIOB, // PIO controller base address
  3594. ((unsigned int) AT91C_PB30_PCK2 ) |
  3595. ((unsigned int) AT91C_PB29_PCK1 ), // Peripheral A
  3596. ((unsigned int) AT91C_PB20_PCK0 ) |
  3597. ((unsigned int) AT91C_PB0_PCK0 ) |
  3598. ((unsigned int) AT91C_PB22_PCK2 ) |
  3599. ((unsigned int) AT91C_PB21_PCK1 )); // Peripheral B
  3600. // Configure PIO controllers to periph mode
  3601. AT91F_PIO_CfgPeriph(
  3602. AT91C_BASE_PIOA, // PIO controller base address
  3603. 0, // Peripheral A
  3604. ((unsigned int) AT91C_PA30_PCK2 ) |
  3605. ((unsigned int) AT91C_PA13_PCK1 ) |
  3606. ((unsigned int) AT91C_PA27_PCK3 )); // Peripheral B
  3607. }
  3608. //*----------------------------------------------------------------------------
  3609. //* \fn AT91F_VREG_CfgPMC
  3610. //* \brief Enable Peripheral clock in PMC for VREG
  3611. //*----------------------------------------------------------------------------
  3612. __inline void AT91F_VREG_CfgPMC (void)
  3613. {
  3614. AT91F_PMC_EnablePeriphClock(
  3615. AT91C_BASE_PMC, // PIO controller base address
  3616. ((unsigned int) 1 << AT91C_ID_SYS));
  3617. }
  3618. //*----------------------------------------------------------------------------
  3619. //* \fn AT91F_RSTC_CfgPMC
  3620. //* \brief Enable Peripheral clock in PMC for RSTC
  3621. //*----------------------------------------------------------------------------
  3622. __inline void AT91F_RSTC_CfgPMC (void)
  3623. {
  3624. AT91F_PMC_EnablePeriphClock(
  3625. AT91C_BASE_PMC, // PIO controller base address
  3626. ((unsigned int) 1 << AT91C_ID_SYS));
  3627. }
  3628. //*----------------------------------------------------------------------------
  3629. //* \fn AT91F_SSC_CfgPMC
  3630. //* \brief Enable Peripheral clock in PMC for SSC
  3631. //*----------------------------------------------------------------------------
  3632. __inline void AT91F_SSC_CfgPMC (void)
  3633. {
  3634. AT91F_PMC_EnablePeriphClock(
  3635. AT91C_BASE_PMC, // PIO controller base address
  3636. ((unsigned int) 1 << AT91C_ID_SSC));
  3637. }
  3638. //*----------------------------------------------------------------------------
  3639. //* \fn AT91F_SSC_CfgPIO
  3640. //* \brief Configure PIO controllers to drive SSC signals
  3641. //*----------------------------------------------------------------------------
  3642. __inline void AT91F_SSC_CfgPIO (void)
  3643. {
  3644. // Configure PIO controllers to periph mode
  3645. AT91F_PIO_CfgPeriph(
  3646. AT91C_BASE_PIOA, // PIO controller base address
  3647. ((unsigned int) AT91C_PA25_RK ) |
  3648. ((unsigned int) AT91C_PA22_TK ) |
  3649. ((unsigned int) AT91C_PA21_TF ) |
  3650. ((unsigned int) AT91C_PA24_RD ) |
  3651. ((unsigned int) AT91C_PA26_RF ) |
  3652. ((unsigned int) AT91C_PA23_TD ), // Peripheral A
  3653. 0); // Peripheral B
  3654. }
  3655. //*----------------------------------------------------------------------------
  3656. //* \fn AT91F_WDTC_CfgPMC
  3657. //* \brief Enable Peripheral clock in PMC for WDTC
  3658. //*----------------------------------------------------------------------------
  3659. __inline void AT91F_WDTC_CfgPMC (void)
  3660. {
  3661. AT91F_PMC_EnablePeriphClock(
  3662. AT91C_BASE_PMC, // PIO controller base address
  3663. ((unsigned int) 1 << AT91C_ID_SYS));
  3664. }
  3665. //*----------------------------------------------------------------------------
  3666. //* \fn AT91F_US1_CfgPMC
  3667. //* \brief Enable Peripheral clock in PMC for US1
  3668. //*----------------------------------------------------------------------------
  3669. __inline void AT91F_US1_CfgPMC (void)
  3670. {
  3671. AT91F_PMC_EnablePeriphClock(
  3672. AT91C_BASE_PMC, // PIO controller base address
  3673. ((unsigned int) 1 << AT91C_ID_US1));
  3674. }
  3675. //*----------------------------------------------------------------------------
  3676. //* \fn AT91F_US1_CfgPIO
  3677. //* \brief Configure PIO controllers to drive US1 signals
  3678. //*----------------------------------------------------------------------------
  3679. __inline void AT91F_US1_CfgPIO (void)
  3680. {
  3681. // Configure PIO controllers to periph mode
  3682. AT91F_PIO_CfgPeriph(
  3683. AT91C_BASE_PIOB, // PIO controller base address
  3684. 0, // Peripheral A
  3685. ((unsigned int) AT91C_PB26_RI1 ) |
  3686. ((unsigned int) AT91C_PB24_DSR1 ) |
  3687. ((unsigned int) AT91C_PB23_DCD1 ) |
  3688. ((unsigned int) AT91C_PB25_DTR1 )); // Peripheral B
  3689. // Configure PIO controllers to periph mode
  3690. AT91F_PIO_CfgPeriph(
  3691. AT91C_BASE_PIOA, // PIO controller base address
  3692. ((unsigned int) AT91C_PA7_SCK1 ) |
  3693. ((unsigned int) AT91C_PA8_RTS1 ) |
  3694. ((unsigned int) AT91C_PA6_TXD1 ) |
  3695. ((unsigned int) AT91C_PA5_RXD1 ) |
  3696. ((unsigned int) AT91C_PA9_CTS1 ), // Peripheral A
  3697. 0); // Peripheral B
  3698. }
  3699. //*----------------------------------------------------------------------------
  3700. //* \fn AT91F_US0_CfgPMC
  3701. //* \brief Enable Peripheral clock in PMC for US0
  3702. //*----------------------------------------------------------------------------
  3703. __inline void AT91F_US0_CfgPMC (void)
  3704. {
  3705. AT91F_PMC_EnablePeriphClock(
  3706. AT91C_BASE_PMC, // PIO controller base address
  3707. ((unsigned int) 1 << AT91C_ID_US0));
  3708. }
  3709. //*----------------------------------------------------------------------------
  3710. //* \fn AT91F_US0_CfgPIO
  3711. //* \brief Configure PIO controllers to drive US0 signals
  3712. //*----------------------------------------------------------------------------
  3713. __inline void AT91F_US0_CfgPIO (void)
  3714. {
  3715. // Configure PIO controllers to periph mode
  3716. AT91F_PIO_CfgPeriph(
  3717. AT91C_BASE_PIOA, // PIO controller base address
  3718. ((unsigned int) AT91C_PA0_RXD0 ) |
  3719. ((unsigned int) AT91C_PA4_CTS0 ) |
  3720. ((unsigned int) AT91C_PA3_RTS0 ) |
  3721. ((unsigned int) AT91C_PA2_SCK0 ) |
  3722. ((unsigned int) AT91C_PA1_TXD0 ), // Peripheral A
  3723. 0); // Peripheral B
  3724. }
  3725. //*----------------------------------------------------------------------------
  3726. //* \fn AT91F_SPI1_CfgPMC
  3727. //* \brief Enable Peripheral clock in PMC for SPI1
  3728. //*----------------------------------------------------------------------------
  3729. __inline void AT91F_SPI1_CfgPMC (void)
  3730. {
  3731. AT91F_PMC_EnablePeriphClock(
  3732. AT91C_BASE_PMC, // PIO controller base address
  3733. ((unsigned int) 1 << AT91C_ID_SPI1));
  3734. }
  3735. //*----------------------------------------------------------------------------
  3736. //* \fn AT91F_SPI1_CfgPIO
  3737. //* \brief Configure PIO controllers to drive SPI1 signals
  3738. //*----------------------------------------------------------------------------
  3739. __inline void AT91F_SPI1_CfgPIO (void)
  3740. {
  3741. // Configure PIO controllers to periph mode
  3742. AT91F_PIO_CfgPeriph(
  3743. AT91C_BASE_PIOB, // PIO controller base address
  3744. 0, // Peripheral A
  3745. ((unsigned int) AT91C_PB16_NPCS13 ) |
  3746. ((unsigned int) AT91C_PB10_NPCS11 ) |
  3747. ((unsigned int) AT91C_PB11_NPCS12 )); // Peripheral B
  3748. // Configure PIO controllers to periph mode
  3749. AT91F_PIO_CfgPeriph(
  3750. AT91C_BASE_PIOA, // PIO controller base address
  3751. 0, // Peripheral A
  3752. ((unsigned int) AT91C_PA4_NPCS13 ) |
  3753. ((unsigned int) AT91C_PA29_NPCS13 ) |
  3754. ((unsigned int) AT91C_PA21_NPCS10 ) |
  3755. ((unsigned int) AT91C_PA22_SPCK1 ) |
  3756. ((unsigned int) AT91C_PA25_NPCS11 ) |
  3757. ((unsigned int) AT91C_PA2_NPCS11 ) |
  3758. ((unsigned int) AT91C_PA24_MISO1 ) |
  3759. ((unsigned int) AT91C_PA3_NPCS12 ) |
  3760. ((unsigned int) AT91C_PA26_NPCS12 ) |
  3761. ((unsigned int) AT91C_PA23_MOSI1 )); // Peripheral B
  3762. }
  3763. //*----------------------------------------------------------------------------
  3764. //* \fn AT91F_SPI0_CfgPMC
  3765. //* \brief Enable Peripheral clock in PMC for SPI0
  3766. //*----------------------------------------------------------------------------
  3767. __inline void AT91F_SPI0_CfgPMC (void)
  3768. {
  3769. AT91F_PMC_EnablePeriphClock(
  3770. AT91C_BASE_PMC, // PIO controller base address
  3771. ((unsigned int) 1 << AT91C_ID_SPI0));
  3772. }
  3773. //*----------------------------------------------------------------------------
  3774. //* \fn AT91F_SPI0_CfgPIO
  3775. //* \brief Configure PIO controllers to drive SPI0 signals
  3776. //*----------------------------------------------------------------------------
  3777. __inline void AT91F_SPI0_CfgPIO (void)
  3778. {
  3779. // Configure PIO controllers to periph mode
  3780. AT91F_PIO_CfgPeriph(
  3781. AT91C_BASE_PIOB, // PIO controller base address
  3782. 0, // Peripheral A
  3783. ((unsigned int) AT91C_PB13_NPCS01 ) |
  3784. ((unsigned int) AT91C_PB17_NPCS03 ) |
  3785. ((unsigned int) AT91C_PB14_NPCS02 )); // Peripheral B
  3786. // Configure PIO controllers to periph mode
  3787. AT91F_PIO_CfgPeriph(
  3788. AT91C_BASE_PIOA, // PIO controller base address
  3789. ((unsigned int) AT91C_PA16_MISO0 ) |
  3790. ((unsigned int) AT91C_PA13_NPCS01 ) |
  3791. ((unsigned int) AT91C_PA15_NPCS03 ) |
  3792. ((unsigned int) AT91C_PA17_MOSI0 ) |
  3793. ((unsigned int) AT91C_PA18_SPCK0 ) |
  3794. ((unsigned int) AT91C_PA14_NPCS02 ) |
  3795. ((unsigned int) AT91C_PA12_NPCS00 ), // Peripheral A
  3796. ((unsigned int) AT91C_PA7_NPCS01 ) |
  3797. ((unsigned int) AT91C_PA9_NPCS03 ) |
  3798. ((unsigned int) AT91C_PA8_NPCS02 )); // Peripheral B
  3799. }
  3800. //*----------------------------------------------------------------------------
  3801. //* \fn AT91F_PITC_CfgPMC
  3802. //* \brief Enable Peripheral clock in PMC for PITC
  3803. //*----------------------------------------------------------------------------
  3804. __inline void AT91F_PITC_CfgPMC (void)
  3805. {
  3806. AT91F_PMC_EnablePeriphClock(
  3807. AT91C_BASE_PMC, // PIO controller base address
  3808. ((unsigned int) 1 << AT91C_ID_SYS));
  3809. }
  3810. //*----------------------------------------------------------------------------
  3811. //* \fn AT91F_AIC_CfgPMC
  3812. //* \brief Enable Peripheral clock in PMC for AIC
  3813. //*----------------------------------------------------------------------------
  3814. __inline void AT91F_AIC_CfgPMC (void)
  3815. {
  3816. AT91F_PMC_EnablePeriphClock(
  3817. AT91C_BASE_PMC, // PIO controller base address
  3818. ((unsigned int) 1 << AT91C_ID_FIQ) |
  3819. ((unsigned int) 1 << AT91C_ID_IRQ0) |
  3820. ((unsigned int) 1 << AT91C_ID_IRQ1));
  3821. }
  3822. //*----------------------------------------------------------------------------
  3823. //* \fn AT91F_AIC_CfgPIO
  3824. //* \brief Configure PIO controllers to drive AIC signals
  3825. //*----------------------------------------------------------------------------
  3826. __inline void AT91F_AIC_CfgPIO (void)
  3827. {
  3828. // Configure PIO controllers to periph mode
  3829. AT91F_PIO_CfgPeriph(
  3830. AT91C_BASE_PIOA, // PIO controller base address
  3831. ((unsigned int) AT91C_PA30_IRQ0 ) |
  3832. ((unsigned int) AT91C_PA29_FIQ ), // Peripheral A
  3833. ((unsigned int) AT91C_PA14_IRQ1 )); // Peripheral B
  3834. }
  3835. //*----------------------------------------------------------------------------
  3836. //* \fn AT91F_AES_CfgPMC
  3837. //* \brief Enable Peripheral clock in PMC for AES
  3838. //*----------------------------------------------------------------------------
  3839. __inline void AT91F_AES_CfgPMC (void)
  3840. {
  3841. AT91F_PMC_EnablePeriphClock(
  3842. AT91C_BASE_PMC, // PIO controller base address
  3843. ((unsigned int) 1 << AT91C_ID_AES));
  3844. }
  3845. //*----------------------------------------------------------------------------
  3846. //* \fn AT91F_TWI_CfgPMC
  3847. //* \brief Enable Peripheral clock in PMC for TWI
  3848. //*----------------------------------------------------------------------------
  3849. __inline void AT91F_TWI_CfgPMC (void)
  3850. {
  3851. AT91F_PMC_EnablePeriphClock(
  3852. AT91C_BASE_PMC, // PIO controller base address
  3853. ((unsigned int) 1 << AT91C_ID_TWI));
  3854. }
  3855. //*----------------------------------------------------------------------------
  3856. //* \fn AT91F_TWI_CfgPIO
  3857. //* \brief Configure PIO controllers to drive TWI signals
  3858. //*----------------------------------------------------------------------------
  3859. __inline void AT91F_TWI_CfgPIO (void)
  3860. {
  3861. // Configure PIO controllers to periph mode
  3862. AT91F_PIO_CfgPeriph(
  3863. AT91C_BASE_PIOA, // PIO controller base address
  3864. ((unsigned int) AT91C_PA11_TWCK ) |
  3865. ((unsigned int) AT91C_PA10_TWD ), // Peripheral A
  3866. 0); // Peripheral B
  3867. }
  3868. //*----------------------------------------------------------------------------
  3869. //* \fn AT91F_ADC_CfgPMC
  3870. //* \brief Enable Peripheral clock in PMC for ADC
  3871. //*----------------------------------------------------------------------------
  3872. __inline void AT91F_ADC_CfgPMC (void)
  3873. {
  3874. AT91F_PMC_EnablePeriphClock(
  3875. AT91C_BASE_PMC, // PIO controller base address
  3876. ((unsigned int) 1 << AT91C_ID_ADC));
  3877. }
  3878. //*----------------------------------------------------------------------------
  3879. //* \fn AT91F_ADC_CfgPIO
  3880. //* \brief Configure PIO controllers to drive ADC signals
  3881. //*----------------------------------------------------------------------------
  3882. __inline void AT91F_ADC_CfgPIO (void)
  3883. {
  3884. // Configure PIO controllers to periph mode
  3885. AT91F_PIO_CfgPeriph(
  3886. AT91C_BASE_PIOB, // PIO controller base address
  3887. 0, // Peripheral A
  3888. ((unsigned int) AT91C_PB18_ADTRG )); // Peripheral B
  3889. }
  3890. //*----------------------------------------------------------------------------
  3891. //* \fn AT91F_PWMC_CH3_CfgPIO
  3892. //* \brief Configure PIO controllers to drive PWMC_CH3 signals
  3893. //*----------------------------------------------------------------------------
  3894. __inline void AT91F_PWMC_CH3_CfgPIO (void)
  3895. {
  3896. // Configure PIO controllers to periph mode
  3897. AT91F_PIO_CfgPeriph(
  3898. AT91C_BASE_PIOB, // PIO controller base address
  3899. ((unsigned int) AT91C_PB22_PWM3 ), // Peripheral A
  3900. ((unsigned int) AT91C_PB30_PWM3 )); // Peripheral B
  3901. }
  3902. //*----------------------------------------------------------------------------
  3903. //* \fn AT91F_PWMC_CH2_CfgPIO
  3904. //* \brief Configure PIO controllers to drive PWMC_CH2 signals
  3905. //*----------------------------------------------------------------------------
  3906. __inline void AT91F_PWMC_CH2_CfgPIO (void)
  3907. {
  3908. // Configure PIO controllers to periph mode
  3909. AT91F_PIO_CfgPeriph(
  3910. AT91C_BASE_PIOB, // PIO controller base address
  3911. ((unsigned int) AT91C_PB21_PWM2 ), // Peripheral A
  3912. ((unsigned int) AT91C_PB29_PWM2 )); // Peripheral B
  3913. }
  3914. //*----------------------------------------------------------------------------
  3915. //* \fn AT91F_PWMC_CH1_CfgPIO
  3916. //* \brief Configure PIO controllers to drive PWMC_CH1 signals
  3917. //*----------------------------------------------------------------------------
  3918. __inline void AT91F_PWMC_CH1_CfgPIO (void)
  3919. {
  3920. // Configure PIO controllers to periph mode
  3921. AT91F_PIO_CfgPeriph(
  3922. AT91C_BASE_PIOB, // PIO controller base address
  3923. ((unsigned int) AT91C_PB20_PWM1 ), // Peripheral A
  3924. ((unsigned int) AT91C_PB28_PWM1 )); // Peripheral B
  3925. }
  3926. //*----------------------------------------------------------------------------
  3927. //* \fn AT91F_PWMC_CH0_CfgPIO
  3928. //* \brief Configure PIO controllers to drive PWMC_CH0 signals
  3929. //*----------------------------------------------------------------------------
  3930. __inline void AT91F_PWMC_CH0_CfgPIO (void)
  3931. {
  3932. // Configure PIO controllers to periph mode
  3933. AT91F_PIO_CfgPeriph(
  3934. AT91C_BASE_PIOB, // PIO controller base address
  3935. ((unsigned int) AT91C_PB19_PWM0 ), // Peripheral A
  3936. ((unsigned int) AT91C_PB27_PWM0 )); // Peripheral B
  3937. }
  3938. //*----------------------------------------------------------------------------
  3939. //* \fn AT91F_RTTC_CfgPMC
  3940. //* \brief Enable Peripheral clock in PMC for RTTC
  3941. //*----------------------------------------------------------------------------
  3942. __inline void AT91F_RTTC_CfgPMC (void)
  3943. {
  3944. AT91F_PMC_EnablePeriphClock(
  3945. AT91C_BASE_PMC, // PIO controller base address
  3946. ((unsigned int) 1 << AT91C_ID_SYS));
  3947. }
  3948. //*----------------------------------------------------------------------------
  3949. //* \fn AT91F_UDP_CfgPMC
  3950. //* \brief Enable Peripheral clock in PMC for UDP
  3951. //*----------------------------------------------------------------------------
  3952. __inline void AT91F_UDP_CfgPMC (void)
  3953. {
  3954. AT91F_PMC_EnablePeriphClock(
  3955. AT91C_BASE_PMC, // PIO controller base address
  3956. ((unsigned int) 1 << AT91C_ID_UDP));
  3957. }
  3958. //*----------------------------------------------------------------------------
  3959. //* \fn AT91F_TDES_CfgPMC
  3960. //* \brief Enable Peripheral clock in PMC for TDES
  3961. //*----------------------------------------------------------------------------
  3962. __inline void AT91F_TDES_CfgPMC (void)
  3963. {
  3964. AT91F_PMC_EnablePeriphClock(
  3965. AT91C_BASE_PMC, // PIO controller base address
  3966. ((unsigned int) 1 << AT91C_ID_TDES));
  3967. }
  3968. //*----------------------------------------------------------------------------
  3969. //* \fn AT91F_EMAC_CfgPMC
  3970. //* \brief Enable Peripheral clock in PMC for EMAC
  3971. //*----------------------------------------------------------------------------
  3972. __inline void AT91F_EMAC_CfgPMC (void)
  3973. {
  3974. AT91F_PMC_EnablePeriphClock(
  3975. AT91C_BASE_PMC, // PIO controller base address
  3976. ((unsigned int) 1 << AT91C_ID_EMAC));
  3977. }
  3978. //*----------------------------------------------------------------------------
  3979. //* \fn AT91F_EMAC_CfgPIO
  3980. //* \brief Configure PIO controllers to drive EMAC signals
  3981. //*----------------------------------------------------------------------------
  3982. __inline void AT91F_EMAC_CfgPIO (void)
  3983. {
  3984. // Configure PIO controllers to periph mode
  3985. AT91F_PIO_CfgPeriph(
  3986. AT91C_BASE_PIOB, // PIO controller base address
  3987. ((unsigned int) AT91C_PB2_ETX0 ) |
  3988. ((unsigned int) AT91C_PB12_ETXER ) |
  3989. ((unsigned int) AT91C_PB16_ECOL ) |
  3990. ((unsigned int) AT91C_PB11_ETX3 ) |
  3991. ((unsigned int) AT91C_PB6_ERX1 ) |
  3992. ((unsigned int) AT91C_PB15_ERXDV ) |
  3993. ((unsigned int) AT91C_PB13_ERX2 ) |
  3994. ((unsigned int) AT91C_PB3_ETX1 ) |
  3995. ((unsigned int) AT91C_PB8_EMDC ) |
  3996. ((unsigned int) AT91C_PB5_ERX0 ) |
  3997. //((unsigned int) AT91C_PB18_EF100 ) |
  3998. ((unsigned int) AT91C_PB14_ERX3 ) |
  3999. ((unsigned int) AT91C_PB4_ECRS_ECRSDV) |
  4000. ((unsigned int) AT91C_PB1_ETXEN ) |
  4001. ((unsigned int) AT91C_PB10_ETX2 ) |
  4002. ((unsigned int) AT91C_PB0_ETXCK_EREFCK) |
  4003. ((unsigned int) AT91C_PB9_EMDIO ) |
  4004. ((unsigned int) AT91C_PB7_ERXER ) |
  4005. ((unsigned int) AT91C_PB17_ERXCK ), // Peripheral A
  4006. 0); // Peripheral B
  4007. }
  4008. //*----------------------------------------------------------------------------
  4009. //* \fn AT91F_TC0_CfgPMC
  4010. //* \brief Enable Peripheral clock in PMC for TC0
  4011. //*----------------------------------------------------------------------------
  4012. __inline void AT91F_TC0_CfgPMC (void)
  4013. {
  4014. AT91F_PMC_EnablePeriphClock(
  4015. AT91C_BASE_PMC, // PIO controller base address
  4016. ((unsigned int) 1 << AT91C_ID_TC0));
  4017. }
  4018. //*----------------------------------------------------------------------------
  4019. //* \fn AT91F_TC0_CfgPIO
  4020. //* \brief Configure PIO controllers to drive TC0 signals
  4021. //*----------------------------------------------------------------------------
  4022. __inline void AT91F_TC0_CfgPIO (void)
  4023. {
  4024. // Configure PIO controllers to periph mode
  4025. AT91F_PIO_CfgPeriph(
  4026. AT91C_BASE_PIOB, // PIO controller base address
  4027. ((unsigned int) AT91C_PB23_TIOA0 ) |
  4028. ((unsigned int) AT91C_PB24_TIOB0 ), // Peripheral A
  4029. ((unsigned int) AT91C_PB12_TCLK0 )); // Peripheral B
  4030. }
  4031. //*----------------------------------------------------------------------------
  4032. //* \fn AT91F_TC1_CfgPMC
  4033. //* \brief Enable Peripheral clock in PMC for TC1
  4034. //*----------------------------------------------------------------------------
  4035. __inline void AT91F_TC1_CfgPMC (void)
  4036. {
  4037. AT91F_PMC_EnablePeriphClock(
  4038. AT91C_BASE_PMC, // PIO controller base address
  4039. ((unsigned int) 1 << AT91C_ID_TC1));
  4040. }
  4041. //*----------------------------------------------------------------------------
  4042. //* \fn AT91F_TC1_CfgPIO
  4043. //* \brief Configure PIO controllers to drive TC1 signals
  4044. //*----------------------------------------------------------------------------
  4045. __inline void AT91F_TC1_CfgPIO (void)
  4046. {
  4047. // Configure PIO controllers to periph mode
  4048. AT91F_PIO_CfgPeriph(
  4049. AT91C_BASE_PIOB, // PIO controller base address
  4050. ((unsigned int) AT91C_PB25_TIOA1 ) |
  4051. ((unsigned int) AT91C_PB26_TIOB1 ), // Peripheral A
  4052. ((unsigned int) AT91C_PB19_TCLK1 )); // Peripheral B
  4053. }
  4054. //*----------------------------------------------------------------------------
  4055. //* \fn AT91F_TC2_CfgPMC
  4056. //* \brief Enable Peripheral clock in PMC for TC2
  4057. //*----------------------------------------------------------------------------
  4058. __inline void AT91F_TC2_CfgPMC (void)
  4059. {
  4060. AT91F_PMC_EnablePeriphClock(
  4061. AT91C_BASE_PMC, // PIO controller base address
  4062. ((unsigned int) 1 << AT91C_ID_TC2));
  4063. }
  4064. //*----------------------------------------------------------------------------
  4065. //* \fn AT91F_TC2_CfgPIO
  4066. //* \brief Configure PIO controllers to drive TC2 signals
  4067. //*----------------------------------------------------------------------------
  4068. __inline void AT91F_TC2_CfgPIO (void)
  4069. {
  4070. // Configure PIO controllers to periph mode
  4071. AT91F_PIO_CfgPeriph(
  4072. AT91C_BASE_PIOB, // PIO controller base address
  4073. ((unsigned int) AT91C_PB28_TIOB2 ) |
  4074. ((unsigned int) AT91C_PB27_TIOA2 ), // Peripheral A
  4075. 0); // Peripheral B
  4076. // Configure PIO controllers to periph mode
  4077. AT91F_PIO_CfgPeriph(
  4078. AT91C_BASE_PIOA, // PIO controller base address
  4079. 0, // Peripheral A
  4080. ((unsigned int) AT91C_PA15_TCLK2 )); // Peripheral B
  4081. }
  4082. //*----------------------------------------------------------------------------
  4083. //* \fn AT91F_MC_CfgPMC
  4084. //* \brief Enable Peripheral clock in PMC for MC
  4085. //*----------------------------------------------------------------------------
  4086. __inline void AT91F_MC_CfgPMC (void)
  4087. {
  4088. AT91F_PMC_EnablePeriphClock(
  4089. AT91C_BASE_PMC, // PIO controller base address
  4090. ((unsigned int) 1 << AT91C_ID_SYS));
  4091. }
  4092. //*----------------------------------------------------------------------------
  4093. //* \fn AT91F_PIOA_CfgPMC
  4094. //* \brief Enable Peripheral clock in PMC for PIOA
  4095. //*----------------------------------------------------------------------------
  4096. __inline void AT91F_PIOA_CfgPMC (void)
  4097. {
  4098. AT91F_PMC_EnablePeriphClock(
  4099. AT91C_BASE_PMC, // PIO controller base address
  4100. ((unsigned int) 1 << AT91C_ID_PIOA));
  4101. }
  4102. //*----------------------------------------------------------------------------
  4103. //* \fn AT91F_PIOB_CfgPMC
  4104. //* \brief Enable Peripheral clock in PMC for PIOB
  4105. //*----------------------------------------------------------------------------
  4106. __inline void AT91F_PIOB_CfgPMC (void)
  4107. {
  4108. AT91F_PMC_EnablePeriphClock(
  4109. AT91C_BASE_PMC, // PIO controller base address
  4110. ((unsigned int) 1 << AT91C_ID_PIOB));
  4111. }
  4112. //*----------------------------------------------------------------------------
  4113. //* \fn AT91F_CAN_CfgPMC
  4114. //* \brief Enable Peripheral clock in PMC for CAN
  4115. //*----------------------------------------------------------------------------
  4116. __inline void AT91F_CAN_CfgPMC (void)
  4117. {
  4118. AT91F_PMC_EnablePeriphClock(
  4119. AT91C_BASE_PMC, // PIO controller base address
  4120. ((unsigned int) 1 << AT91C_ID_CAN));
  4121. }
  4122. //*----------------------------------------------------------------------------
  4123. //* \fn AT91F_CAN_CfgPIO
  4124. //* \brief Configure PIO controllers to drive CAN signals
  4125. //*----------------------------------------------------------------------------
  4126. __inline void AT91F_CAN_CfgPIO (void)
  4127. {
  4128. // Configure PIO controllers to periph mode
  4129. AT91F_PIO_CfgPeriph(
  4130. AT91C_BASE_PIOA, // PIO controller base address
  4131. ((unsigned int) AT91C_PA20_CANTX ) |
  4132. ((unsigned int) AT91C_PA19_CANRX ), // Peripheral A
  4133. 0); // Peripheral B
  4134. }
  4135. //*----------------------------------------------------------------------------
  4136. //* \fn AT91F_PWMC_CfgPMC
  4137. //* \brief Enable Peripheral clock in PMC for PWMC
  4138. //*----------------------------------------------------------------------------
  4139. __inline void AT91F_PWMC_CfgPMC (void)
  4140. {
  4141. AT91F_PMC_EnablePeriphClock(
  4142. AT91C_BASE_PMC, // PIO controller base address
  4143. ((unsigned int) 1 << AT91C_ID_PWMC));
  4144. }
  4145. #endif // lib_AT91SAM7X128_H