lib_at91sam7s.h 141 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763
  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_AT91SAM7S64.h
  16. // Object : AT91SAM7S64 inlined functions
  17. // Generated : AT91 SW Application Group 08/30/2005 (15:52:59)
  18. //
  19. // ----------------------------------------------------------------------------
  20. #ifndef AT91SAM7SLIB_H
  21. #define AT91SAM7SLIB_H
  22. //{{{ AIC - Advanced interrupt controller
  23. /* *****************************************************************************
  24. SOFTWARE API FOR AIC
  25. ***************************************************************************** */
  26. #define AT91C_AIC_BRANCH_OPCODE ((void (*) ()) 0xE51FFF20) // ldr, pc, [pc, #-&F20]
  27. //----------------------------------------------------------------------------
  28. // \fn AT91F_AIC_ConfigureIt
  29. // \brief Interrupt Handler Initialization
  30. //----------------------------------------------------------------------------
  31. __inline unsigned int AT91F_AIC_ConfigureIt (
  32. AT91PS_AIC pAic, // \arg pointer to the AIC registers
  33. unsigned int irq_id, // \arg interrupt number to initialize
  34. unsigned int priority, // \arg priority to give to the interrupt
  35. unsigned int src_type, // \arg activation and sense of activation
  36. void (*newHandler) () ) // \arg address of the interrupt handler
  37. {
  38. unsigned int oldHandler;
  39. unsigned int mask ;
  40. oldHandler = pAic->AIC_SVR[irq_id];
  41. mask = 0x1 << irq_id ;
  42. // Disable the interrupt on the interrupt controller
  43. pAic->AIC_IDCR = mask ;
  44. // Save the interrupt handler routine pointer and the interrupt priority
  45. pAic->AIC_SVR[irq_id] = (unsigned int) newHandler ;
  46. // Store the Source Mode Register
  47. pAic->AIC_SMR[irq_id] = src_type | priority ;
  48. // Clear the interrupt on the interrupt controller
  49. pAic->AIC_ICCR = mask ;
  50. return oldHandler;
  51. }
  52. //----------------------------------------------------------------------------
  53. // \fn AT91F_AIC_EnableIt
  54. // \brief Enable corresponding IT number
  55. //----------------------------------------------------------------------------
  56. __inline void AT91F_AIC_EnableIt (
  57. AT91PS_AIC pAic, // \arg pointer to the AIC registers
  58. unsigned int irq_id ) // \arg interrupt number to initialize
  59. {
  60. // Enable the interrupt on the interrupt controller
  61. pAic->AIC_IECR = 0x1 << irq_id ;
  62. }
  63. //----------------------------------------------------------------------------
  64. // \fn AT91F_AIC_DisableIt
  65. // \brief Disable corresponding IT number
  66. //----------------------------------------------------------------------------
  67. __inline void AT91F_AIC_DisableIt (
  68. AT91PS_AIC pAic, // \arg pointer to the AIC registers
  69. unsigned int irq_id ) // \arg interrupt number to initialize
  70. {
  71. unsigned int mask = 0x1 << irq_id;
  72. // Disable the interrupt on the interrupt controller
  73. pAic->AIC_IDCR = mask ;
  74. // Clear the interrupt on the Interrupt Controller ( if one is pending )
  75. pAic->AIC_ICCR = mask ;
  76. }
  77. //----------------------------------------------------------------------------
  78. // \fn AT91F_AIC_ClearIt
  79. // \brief Clear corresponding IT number
  80. //----------------------------------------------------------------------------
  81. __inline void AT91F_AIC_ClearIt (
  82. AT91PS_AIC pAic, // \arg pointer to the AIC registers
  83. unsigned int irq_id) // \arg interrupt number to initialize
  84. {
  85. // Clear the interrupt on the Interrupt Controller ( if one is pending )
  86. pAic->AIC_ICCR = (0x1 << irq_id);
  87. }
  88. //----------------------------------------------------------------------------
  89. // \fn AT91F_AIC_AcknowledgeIt
  90. // \brief Acknowledge corresponding IT number
  91. //----------------------------------------------------------------------------
  92. __inline void AT91F_AIC_AcknowledgeIt (
  93. AT91PS_AIC pAic) // \arg pointer to the AIC registers
  94. {
  95. pAic->AIC_EOICR = pAic->AIC_EOICR;
  96. }
  97. //----------------------------------------------------------------------------
  98. // \fn AT91F_AIC_SetExceptionVector
  99. // \brief Configure vector handler
  100. //----------------------------------------------------------------------------
  101. __inline unsigned int AT91F_AIC_SetExceptionVector (
  102. unsigned int *pVector, // \arg pointer to the AIC registers
  103. void (*Handler) () ) // \arg Interrupt Handler
  104. {
  105. unsigned int oldVector = *pVector;
  106. if ((unsigned int) Handler == (unsigned int) AT91C_AIC_BRANCH_OPCODE)
  107. *pVector = (unsigned int) AT91C_AIC_BRANCH_OPCODE;
  108. else
  109. *pVector = (((((unsigned int) Handler) - ((unsigned int) pVector) - 0x8) >> 2) & 0x00FFFFFF) | 0xEA000000;
  110. return oldVector;
  111. }
  112. //----------------------------------------------------------------------------
  113. // \fn AT91F_AIC_Trig
  114. // \brief Trig an IT
  115. //----------------------------------------------------------------------------
  116. __inline void AT91F_AIC_Trig (
  117. AT91PS_AIC pAic, // \arg pointer to the AIC registers
  118. unsigned int irq_id) // \arg interrupt number
  119. {
  120. pAic->AIC_ISCR = (0x1 << irq_id) ;
  121. }
  122. //----------------------------------------------------------------------------
  123. // \fn AT91F_AIC_IsActive
  124. // \brief Test if an IT is active
  125. //----------------------------------------------------------------------------
  126. __inline unsigned int AT91F_AIC_IsActive (
  127. AT91PS_AIC pAic, // \arg pointer to the AIC registers
  128. unsigned int irq_id) // \arg Interrupt Number
  129. {
  130. return (pAic->AIC_ISR & (0x1 << irq_id));
  131. }
  132. //----------------------------------------------------------------------------
  133. // \fn AT91F_AIC_IsPending
  134. // \brief Test if an IT is pending
  135. //----------------------------------------------------------------------------
  136. __inline unsigned int AT91F_AIC_IsPending (
  137. AT91PS_AIC pAic, // \arg pointer to the AIC registers
  138. unsigned int irq_id) // \arg Interrupt Number
  139. {
  140. return (pAic->AIC_IPR & (0x1 << irq_id));
  141. }
  142. //----------------------------------------------------------------------------
  143. // \fn AT91F_AIC_Open
  144. // \brief Set exception vectors and AIC registers to default values
  145. //----------------------------------------------------------------------------
  146. __inline void AT91F_AIC_Open(
  147. AT91PS_AIC pAic, // \arg pointer to the AIC registers
  148. void (*IrqHandler) (), // \arg Default IRQ vector exception
  149. void (*FiqHandler) (), // \arg Default FIQ vector exception
  150. void (*DefaultHandler) (), // \arg Default Handler set in ISR
  151. void (*SpuriousHandler) (), // \arg Default Spurious Handler
  152. unsigned int protectMode) // \arg Debug Control Register
  153. {
  154. int i;
  155. // Disable all interrupts and set IVR to the default handler
  156. for (i = 0; i < 32; ++i) {
  157. AT91F_AIC_DisableIt(pAic, i);
  158. AT91F_AIC_ConfigureIt(pAic, i, AT91C_AIC_PRIOR_LOWEST, AT91C_AIC_SRCTYPE_HIGH_LEVEL, DefaultHandler);
  159. }
  160. // Set the IRQ exception vector
  161. AT91F_AIC_SetExceptionVector((unsigned int *) 0x18, IrqHandler);
  162. // Set the Fast Interrupt exception vector
  163. AT91F_AIC_SetExceptionVector((unsigned int *) 0x1C, FiqHandler);
  164. pAic->AIC_SPU = (unsigned int) SpuriousHandler;
  165. pAic->AIC_DCR = protectMode;
  166. }//}}}
  167. //{{{ PDC - Peripheral DMA controller
  168. /* *****************************************************************************
  169. SOFTWARE API FOR PDC
  170. ***************************************************************************** */
  171. //----------------------------------------------------------------------------
  172. // \fn AT91F_PDC_SetNextRx
  173. // \brief Set the next receive transfer descriptor
  174. //----------------------------------------------------------------------------
  175. __inline void AT91F_PDC_SetNextRx (
  176. AT91PS_PDC pPDC, // \arg pointer to a PDC controller
  177. char *address, // \arg address to the next bloc to be received
  178. unsigned int bytes) // \arg number of bytes to be received
  179. {
  180. pPDC->PDC_RNPR = (unsigned int) address;
  181. pPDC->PDC_RNCR = bytes;
  182. }
  183. //----------------------------------------------------------------------------
  184. // \fn AT91F_PDC_SetNextTx
  185. // \brief Set the next transmit transfer descriptor
  186. //----------------------------------------------------------------------------
  187. __inline void AT91F_PDC_SetNextTx (
  188. AT91PS_PDC pPDC, // \arg pointer to a PDC controller
  189. char *address, // \arg address to the next bloc to be transmitted
  190. unsigned int bytes) // \arg number of bytes to be transmitted
  191. {
  192. pPDC->PDC_TNPR = (unsigned int) address;
  193. pPDC->PDC_TNCR = bytes;
  194. }
  195. //----------------------------------------------------------------------------
  196. // \fn AT91F_PDC_SetRx
  197. // \brief Set the receive transfer descriptor
  198. //----------------------------------------------------------------------------
  199. __inline void AT91F_PDC_SetRx (
  200. AT91PS_PDC pPDC, // \arg pointer to a PDC controller
  201. char *address, // \arg address to the next bloc to be received
  202. unsigned int bytes) // \arg number of bytes to be received
  203. {
  204. pPDC->PDC_RPR = (unsigned int) address;
  205. pPDC->PDC_RCR = bytes;
  206. }
  207. //----------------------------------------------------------------------------
  208. // \fn AT91F_PDC_SetTx
  209. // \brief Set the transmit transfer descriptor
  210. //----------------------------------------------------------------------------
  211. __inline void AT91F_PDC_SetTx (
  212. AT91PS_PDC pPDC, // \arg pointer to a PDC controller
  213. char *address, // \arg address to the next bloc to be transmitted
  214. unsigned int bytes) // \arg number of bytes to be transmitted
  215. {
  216. pPDC->PDC_TPR = (unsigned int) address;
  217. pPDC->PDC_TCR = bytes;
  218. }
  219. //----------------------------------------------------------------------------
  220. // \fn AT91F_PDC_EnableTx
  221. // \brief Enable transmit
  222. //----------------------------------------------------------------------------
  223. __inline void AT91F_PDC_EnableTx (
  224. AT91PS_PDC pPDC ) // \arg pointer to a PDC controller
  225. {
  226. pPDC->PDC_PTCR = AT91C_PDC_TXTEN;
  227. }
  228. //----------------------------------------------------------------------------
  229. // \fn AT91F_PDC_EnableRx
  230. // \brief Enable receive
  231. //----------------------------------------------------------------------------
  232. __inline void AT91F_PDC_EnableRx (
  233. AT91PS_PDC pPDC ) // \arg pointer to a PDC controller
  234. {
  235. pPDC->PDC_PTCR = AT91C_PDC_RXTEN;
  236. }
  237. //----------------------------------------------------------------------------
  238. // \fn AT91F_PDC_DisableTx
  239. // \brief Disable transmit
  240. //----------------------------------------------------------------------------
  241. __inline void AT91F_PDC_DisableTx (
  242. AT91PS_PDC pPDC ) // \arg pointer to a PDC controller
  243. {
  244. pPDC->PDC_PTCR = AT91C_PDC_TXTDIS;
  245. }
  246. //----------------------------------------------------------------------------
  247. // \fn AT91F_PDC_DisableRx
  248. // \brief Disable receive
  249. //----------------------------------------------------------------------------
  250. __inline void AT91F_PDC_DisableRx (
  251. AT91PS_PDC pPDC ) // \arg pointer to a PDC controller
  252. {
  253. pPDC->PDC_PTCR = AT91C_PDC_RXTDIS;
  254. }
  255. //----------------------------------------------------------------------------
  256. // \fn AT91F_PDC_IsTxEmpty
  257. // \brief Test if the current transfer descriptor has been sent
  258. //----------------------------------------------------------------------------
  259. __inline int AT91F_PDC_IsTxEmpty ( // \return return 1 if transfer is complete
  260. AT91PS_PDC pPDC ) // \arg pointer to a PDC controller
  261. {
  262. return !(pPDC->PDC_TCR);
  263. }
  264. //----------------------------------------------------------------------------
  265. // \fn AT91F_PDC_IsNextTxEmpty
  266. // \brief Test if the next transfer descriptor has been moved to the current td
  267. //----------------------------------------------------------------------------
  268. __inline int AT91F_PDC_IsNextTxEmpty ( // \return return 1 if transfer is complete
  269. AT91PS_PDC pPDC ) // \arg pointer to a PDC controller
  270. {
  271. return !(pPDC->PDC_TNCR);
  272. }
  273. //----------------------------------------------------------------------------
  274. // \fn AT91F_PDC_IsRxEmpty
  275. // \brief Test if the current transfer descriptor has been filled
  276. //----------------------------------------------------------------------------
  277. __inline int AT91F_PDC_IsRxEmpty ( // \return return 1 if transfer is complete
  278. AT91PS_PDC pPDC ) // \arg pointer to a PDC controller
  279. {
  280. return !(pPDC->PDC_RCR);
  281. }
  282. //----------------------------------------------------------------------------
  283. // \fn AT91F_PDC_IsNextRxEmpty
  284. // \brief Test if the next transfer descriptor has been moved to the current td
  285. //----------------------------------------------------------------------------
  286. __inline int AT91F_PDC_IsNextRxEmpty ( // \return return 1 if transfer is complete
  287. AT91PS_PDC pPDC ) // \arg pointer to a PDC controller
  288. {
  289. return !(pPDC->PDC_RNCR);
  290. }
  291. //----------------------------------------------------------------------------
  292. // \fn AT91F_PDC_Open
  293. // \brief Open PDC: disable TX and RX reset transfer descriptors, re-enable RX and TX
  294. //----------------------------------------------------------------------------
  295. __inline void AT91F_PDC_Open (
  296. AT91PS_PDC pPDC) // \arg pointer to a PDC controller
  297. {
  298. // Disable the RX and TX PDC transfer requests
  299. AT91F_PDC_DisableRx(pPDC);
  300. AT91F_PDC_DisableTx(pPDC);
  301. // Reset all Counter register Next buffer first
  302. AT91F_PDC_SetNextTx(pPDC, (char *) 0, 0);
  303. AT91F_PDC_SetNextRx(pPDC, (char *) 0, 0);
  304. AT91F_PDC_SetTx(pPDC, (char *) 0, 0);
  305. AT91F_PDC_SetRx(pPDC, (char *) 0, 0);
  306. // Enable the RX and TX PDC transfer requests
  307. AT91F_PDC_EnableRx(pPDC);
  308. AT91F_PDC_EnableTx(pPDC);
  309. }
  310. //----------------------------------------------------------------------------
  311. // \fn AT91F_PDC_Close
  312. // \brief Close PDC: disable TX and RX reset transfer descriptors
  313. //----------------------------------------------------------------------------
  314. __inline void AT91F_PDC_Close (
  315. AT91PS_PDC pPDC) // \arg pointer to a PDC controller
  316. {
  317. // Disable the RX and TX PDC transfer requests
  318. AT91F_PDC_DisableRx(pPDC);
  319. AT91F_PDC_DisableTx(pPDC);
  320. // Reset all Counter register Next buffer first
  321. AT91F_PDC_SetNextTx(pPDC, (char *) 0, 0);
  322. AT91F_PDC_SetNextRx(pPDC, (char *) 0, 0);
  323. AT91F_PDC_SetTx(pPDC, (char *) 0, 0);
  324. AT91F_PDC_SetRx(pPDC, (char *) 0, 0);
  325. }
  326. //----------------------------------------------------------------------------
  327. // \fn AT91F_PDC_SendFrame
  328. // \brief Close PDC: disable TX and RX reset transfer descriptors
  329. //----------------------------------------------------------------------------
  330. __inline unsigned int AT91F_PDC_SendFrame(
  331. AT91PS_PDC pPDC,
  332. char *pBuffer,
  333. unsigned int szBuffer,
  334. char *pNextBuffer,
  335. unsigned int szNextBuffer )
  336. {
  337. if (AT91F_PDC_IsTxEmpty(pPDC)) {
  338. // Buffer and next buffer can be initialized
  339. AT91F_PDC_SetTx(pPDC, pBuffer, szBuffer);
  340. AT91F_PDC_SetNextTx(pPDC, pNextBuffer, szNextBuffer);
  341. return 2;
  342. }
  343. else if (AT91F_PDC_IsNextTxEmpty(pPDC)) {
  344. // Only one buffer can be initialized
  345. AT91F_PDC_SetNextTx(pPDC, pBuffer, szBuffer);
  346. return 1;
  347. }
  348. else {
  349. // All buffer are in use...
  350. return 0;
  351. }
  352. }
  353. //----------------------------------------------------------------------------
  354. // \fn AT91F_PDC_ReceiveFrame
  355. // \brief Close PDC: disable TX and RX reset transfer descriptors
  356. //----------------------------------------------------------------------------
  357. __inline unsigned int AT91F_PDC_ReceiveFrame (
  358. AT91PS_PDC pPDC,
  359. char *pBuffer,
  360. unsigned int szBuffer,
  361. char *pNextBuffer,
  362. unsigned int szNextBuffer )
  363. {
  364. if (AT91F_PDC_IsRxEmpty(pPDC)) {
  365. // Buffer and next buffer can be initialized
  366. AT91F_PDC_SetRx(pPDC, pBuffer, szBuffer);
  367. AT91F_PDC_SetNextRx(pPDC, pNextBuffer, szNextBuffer);
  368. return 2;
  369. }
  370. else if (AT91F_PDC_IsNextRxEmpty(pPDC)) {
  371. // Only one buffer can be initialized
  372. AT91F_PDC_SetNextRx(pPDC, pBuffer, szBuffer);
  373. return 1;
  374. }
  375. else {
  376. // All buffer are in use...
  377. return 0;
  378. }
  379. }//}}}
  380. //{{{ DBGU - Debug unit
  381. /* *****************************************************************************
  382. SOFTWARE API FOR DBGU
  383. ***************************************************************************** */
  384. //----------------------------------------------------------------------------
  385. // \fn AT91F_DBGU_InterruptEnable
  386. // \brief Enable DBGU Interrupt
  387. //----------------------------------------------------------------------------
  388. __inline void AT91F_DBGU_InterruptEnable(
  389. AT91PS_DBGU pDbgu, // \arg pointer to a DBGU controller
  390. unsigned int flag) // \arg dbgu interrupt to be enabled
  391. {
  392. pDbgu->DBGU_IER = flag;
  393. }
  394. //----------------------------------------------------------------------------
  395. // \fn AT91F_DBGU_InterruptDisable
  396. // \brief Disable DBGU Interrupt
  397. //----------------------------------------------------------------------------
  398. __inline void AT91F_DBGU_InterruptDisable(
  399. AT91PS_DBGU pDbgu, // \arg pointer to a DBGU controller
  400. unsigned int flag) // \arg dbgu interrupt to be disabled
  401. {
  402. pDbgu->DBGU_IDR = flag;
  403. }
  404. //----------------------------------------------------------------------------
  405. // \fn AT91F_DBGU_GetInterruptMaskStatus
  406. // \brief Return DBGU Interrupt Mask Status
  407. //----------------------------------------------------------------------------
  408. __inline unsigned int AT91F_DBGU_GetInterruptMaskStatus( // \return DBGU Interrupt Mask Status
  409. AT91PS_DBGU pDbgu) // \arg pointer to a DBGU controller
  410. {
  411. return pDbgu->DBGU_IMR;
  412. }
  413. //----------------------------------------------------------------------------
  414. // \fn AT91F_DBGU_IsInterruptMasked
  415. // \brief Test if DBGU Interrupt is Masked
  416. //----------------------------------------------------------------------------
  417. __inline int AT91F_DBGU_IsInterruptMasked(
  418. AT91PS_DBGU pDbgu, // \arg pointer to a DBGU controller
  419. unsigned int flag) // \arg flag to be tested
  420. {
  421. return (AT91F_DBGU_GetInterruptMaskStatus(pDbgu) & flag);
  422. }
  423. //}}}
  424. //{{{ PIO - Parallel I/O controller
  425. /* *****************************************************************************
  426. SOFTWARE API FOR PIO
  427. ***************************************************************************** */
  428. //----------------------------------------------------------------------------
  429. // \fn AT91F_PIO_CfgPeriph
  430. // \brief Enable pins to be drived by peripheral
  431. //----------------------------------------------------------------------------
  432. __inline void AT91F_PIO_CfgPeriph(
  433. AT91PS_PIO pPio, // \arg pointer to a PIO controller
  434. unsigned int periphAEnable, // \arg PERIPH A to enable
  435. unsigned int periphBEnable) // \arg PERIPH B to enable
  436. {
  437. pPio->PIO_ASR = periphAEnable;
  438. pPio->PIO_BSR = periphBEnable;
  439. pPio->PIO_PDR = (periphAEnable | periphBEnable); // Set in Periph mode
  440. }
  441. //----------------------------------------------------------------------------
  442. // \fn AT91F_PIO_CfgOutput
  443. // \brief Enable PIO in output mode
  444. //----------------------------------------------------------------------------
  445. __inline void AT91F_PIO_CfgOutput(
  446. AT91PS_PIO pPio, // \arg pointer to a PIO controller
  447. unsigned int pioEnable) // \arg PIO to be enabled
  448. {
  449. pPio->PIO_PER = pioEnable; // Set in PIO mode
  450. pPio->PIO_OER = pioEnable; // Configure in Output
  451. }
  452. //----------------------------------------------------------------------------
  453. // \fn AT91F_PIO_CfgInput
  454. // \brief Enable PIO in input mode
  455. //----------------------------------------------------------------------------
  456. __inline void AT91F_PIO_CfgInput(
  457. AT91PS_PIO pPio, // \arg pointer to a PIO controller
  458. unsigned int inputEnable) // \arg PIO to be enabled
  459. {
  460. // Disable output
  461. pPio->PIO_ODR = inputEnable;
  462. pPio->PIO_PER = inputEnable;
  463. }
  464. //----------------------------------------------------------------------------
  465. // \fn AT91F_PIO_CfgOpendrain
  466. // \brief Configure PIO in open drain
  467. //----------------------------------------------------------------------------
  468. __inline void AT91F_PIO_CfgOpendrain(
  469. AT91PS_PIO pPio, // \arg pointer to a PIO controller
  470. unsigned int multiDrvEnable) // \arg pio to be configured in open drain
  471. {
  472. // Configure the multi-drive option
  473. pPio->PIO_MDDR = ~multiDrvEnable;
  474. pPio->PIO_MDER = multiDrvEnable;
  475. }
  476. //----------------------------------------------------------------------------
  477. // \fn AT91F_PIO_CfgPullup
  478. // \brief Enable pullup on PIO
  479. //----------------------------------------------------------------------------
  480. __inline void AT91F_PIO_CfgPullup(
  481. AT91PS_PIO pPio, // \arg pointer to a PIO controller
  482. unsigned int pullupEnable) // \arg enable pullup on PIO
  483. {
  484. // Connect or not Pullup
  485. pPio->PIO_PPUDR = ~pullupEnable;
  486. pPio->PIO_PPUER = pullupEnable;
  487. }
  488. //----------------------------------------------------------------------------
  489. // \fn AT91F_PIO_CfgDirectDrive
  490. // \brief Enable direct drive on PIO
  491. //----------------------------------------------------------------------------
  492. __inline void AT91F_PIO_CfgDirectDrive(
  493. AT91PS_PIO pPio, // \arg pointer to a PIO controller
  494. unsigned int directDrive) // \arg PIO to be configured with direct drive
  495. {
  496. // Configure the Direct Drive
  497. pPio->PIO_OWDR = ~directDrive;
  498. pPio->PIO_OWER = directDrive;
  499. }
  500. //----------------------------------------------------------------------------
  501. // \fn AT91F_PIO_CfgInputFilter
  502. // \brief Enable input filter on input PIO
  503. //----------------------------------------------------------------------------
  504. __inline void AT91F_PIO_CfgInputFilter(
  505. AT91PS_PIO pPio, // \arg pointer to a PIO controller
  506. unsigned int inputFilter) // \arg PIO to be configured with input filter
  507. {
  508. // Configure the Direct Drive
  509. pPio->PIO_IFDR = ~inputFilter;
  510. pPio->PIO_IFER = inputFilter;
  511. }
  512. //----------------------------------------------------------------------------
  513. // \fn AT91F_PIO_GetInput
  514. // \brief Return PIO input value
  515. //----------------------------------------------------------------------------
  516. __inline unsigned int AT91F_PIO_GetInput( // \return PIO input
  517. AT91PS_PIO pPio) // \arg pointer to a PIO controller
  518. {
  519. return pPio->PIO_PDSR;
  520. }
  521. //----------------------------------------------------------------------------
  522. // \fn AT91F_PIO_IsInputSet
  523. // \brief Test if PIO is input flag is active
  524. //----------------------------------------------------------------------------
  525. __inline int AT91F_PIO_IsInputSet(
  526. AT91PS_PIO pPio, // \arg pointer to a PIO controller
  527. unsigned int flag) // \arg flag to be tested
  528. {
  529. return (AT91F_PIO_GetInput(pPio) & flag);
  530. }
  531. //----------------------------------------------------------------------------
  532. // \fn AT91F_PIO_SetOutput
  533. // \brief Set to 1 output PIO
  534. //----------------------------------------------------------------------------
  535. __inline void AT91F_PIO_SetOutput(
  536. AT91PS_PIO pPio, // \arg pointer to a PIO controller
  537. unsigned int flag) // \arg output to be set
  538. {
  539. pPio->PIO_SODR = flag;
  540. }
  541. //----------------------------------------------------------------------------
  542. // \fn AT91F_PIO_ClearOutput
  543. // \brief Set to 0 output PIO
  544. //----------------------------------------------------------------------------
  545. __inline void AT91F_PIO_ClearOutput(
  546. AT91PS_PIO pPio, // \arg pointer to a PIO controller
  547. unsigned int flag) // \arg output to be cleared
  548. {
  549. pPio->PIO_CODR = flag;
  550. }
  551. //----------------------------------------------------------------------------
  552. // \fn AT91F_PIO_ForceOutput
  553. // \brief Force output when Direct drive option is enabled
  554. //----------------------------------------------------------------------------
  555. __inline void AT91F_PIO_ForceOutput(
  556. AT91PS_PIO pPio, // \arg pointer to a PIO controller
  557. unsigned int flag) // \arg output to be forced
  558. {
  559. pPio->PIO_ODSR = flag;
  560. }
  561. //----------------------------------------------------------------------------
  562. // \fn AT91F_PIO_Enable
  563. // \brief Enable PIO
  564. //----------------------------------------------------------------------------
  565. __inline void AT91F_PIO_Enable(
  566. AT91PS_PIO pPio, // \arg pointer to a PIO controller
  567. unsigned int flag) // \arg pio to be enabled
  568. {
  569. pPio->PIO_PER = flag;
  570. }
  571. //----------------------------------------------------------------------------
  572. // \fn AT91F_PIO_Disable
  573. // \brief Disable PIO
  574. //----------------------------------------------------------------------------
  575. __inline void AT91F_PIO_Disable(
  576. AT91PS_PIO pPio, // \arg pointer to a PIO controller
  577. unsigned int flag) // \arg pio to be disabled
  578. {
  579. pPio->PIO_PDR = flag;
  580. }
  581. //----------------------------------------------------------------------------
  582. // \fn AT91F_PIO_GetStatus
  583. // \brief Return PIO Status
  584. //----------------------------------------------------------------------------
  585. __inline unsigned int AT91F_PIO_GetStatus( // \return PIO Status
  586. AT91PS_PIO pPio) // \arg pointer to a PIO controller
  587. {
  588. return pPio->PIO_PSR;
  589. }
  590. //----------------------------------------------------------------------------
  591. // \fn AT91F_PIO_IsSet
  592. // \brief Test if PIO is Set
  593. //----------------------------------------------------------------------------
  594. __inline int AT91F_PIO_IsSet(
  595. AT91PS_PIO pPio, // \arg pointer to a PIO controller
  596. unsigned int flag) // \arg flag to be tested
  597. {
  598. return (AT91F_PIO_GetStatus(pPio) & flag);
  599. }
  600. //----------------------------------------------------------------------------
  601. // \fn AT91F_PIO_OutputEnable
  602. // \brief Output Enable PIO
  603. //----------------------------------------------------------------------------
  604. __inline void AT91F_PIO_OutputEnable(
  605. AT91PS_PIO pPio, // \arg pointer to a PIO controller
  606. unsigned int flag) // \arg pio output to be enabled
  607. {
  608. pPio->PIO_OER = flag;
  609. }
  610. //----------------------------------------------------------------------------
  611. // \fn AT91F_PIO_OutputDisable
  612. // \brief Output Enable PIO
  613. //----------------------------------------------------------------------------
  614. __inline void AT91F_PIO_OutputDisable(
  615. AT91PS_PIO pPio, // \arg pointer to a PIO controller
  616. unsigned int flag) // \arg pio output to be disabled
  617. {
  618. pPio->PIO_ODR = flag;
  619. }
  620. //----------------------------------------------------------------------------
  621. // \fn AT91F_PIO_GetOutputStatus
  622. // \brief Return PIO Output Status
  623. //----------------------------------------------------------------------------
  624. __inline unsigned int AT91F_PIO_GetOutputStatus( // \return PIO Output Status
  625. AT91PS_PIO pPio) // \arg pointer to a PIO controller
  626. {
  627. return pPio->PIO_OSR;
  628. }
  629. //----------------------------------------------------------------------------
  630. // \fn AT91F_PIO_IsOuputSet
  631. // \brief Test if PIO Output is Set
  632. //----------------------------------------------------------------------------
  633. __inline int AT91F_PIO_IsOutputSet(
  634. AT91PS_PIO pPio, // \arg pointer to a PIO controller
  635. unsigned int flag) // \arg flag to be tested
  636. {
  637. return (AT91F_PIO_GetOutputStatus(pPio) & flag);
  638. }
  639. //----------------------------------------------------------------------------
  640. // \fn AT91F_PIO_InputFilterEnable
  641. // \brief Input Filter Enable PIO
  642. //----------------------------------------------------------------------------
  643. __inline void AT91F_PIO_InputFilterEnable(
  644. AT91PS_PIO pPio, // \arg pointer to a PIO controller
  645. unsigned int flag) // \arg pio input filter to be enabled
  646. {
  647. pPio->PIO_IFER = flag;
  648. }
  649. //----------------------------------------------------------------------------
  650. // \fn AT91F_PIO_InputFilterDisable
  651. // \brief Input Filter Disable PIO
  652. //----------------------------------------------------------------------------
  653. __inline void AT91F_PIO_InputFilterDisable(
  654. AT91PS_PIO pPio, // \arg pointer to a PIO controller
  655. unsigned int flag) // \arg pio input filter to be disabled
  656. {
  657. pPio->PIO_IFDR = flag;
  658. }
  659. //----------------------------------------------------------------------------
  660. // \fn AT91F_PIO_GetInputFilterStatus
  661. // \brief Return PIO Input Filter Status
  662. //----------------------------------------------------------------------------
  663. __inline unsigned int AT91F_PIO_GetInputFilterStatus( // \return PIO Input Filter Status
  664. AT91PS_PIO pPio) // \arg pointer to a PIO controller
  665. {
  666. return pPio->PIO_IFSR;
  667. }
  668. //----------------------------------------------------------------------------
  669. // \fn AT91F_PIO_IsInputFilterSet
  670. // \brief Test if PIO Input filter is Set
  671. //----------------------------------------------------------------------------
  672. __inline int AT91F_PIO_IsInputFilterSet(
  673. AT91PS_PIO pPio, // \arg pointer to a PIO controller
  674. unsigned int flag) // \arg flag to be tested
  675. {
  676. return (AT91F_PIO_GetInputFilterStatus(pPio) & flag);
  677. }
  678. //----------------------------------------------------------------------------
  679. // \fn AT91F_PIO_GetOutputDataStatus
  680. // \brief Return PIO Output Data Status
  681. //----------------------------------------------------------------------------
  682. __inline unsigned int AT91F_PIO_GetOutputDataStatus( // \return PIO Output Data Status
  683. AT91PS_PIO pPio) // \arg pointer to a PIO controller
  684. {
  685. return pPio->PIO_ODSR;
  686. }
  687. //----------------------------------------------------------------------------
  688. // \fn AT91F_PIO_InterruptEnable
  689. // \brief Enable PIO Interrupt
  690. //----------------------------------------------------------------------------
  691. __inline void AT91F_PIO_InterruptEnable(
  692. AT91PS_PIO pPio, // \arg pointer to a PIO controller
  693. unsigned int flag) // \arg pio interrupt to be enabled
  694. {
  695. pPio->PIO_IER = flag;
  696. }
  697. //----------------------------------------------------------------------------
  698. // \fn AT91F_PIO_InterruptDisable
  699. // \brief Disable PIO Interrupt
  700. //----------------------------------------------------------------------------
  701. __inline void AT91F_PIO_InterruptDisable(
  702. AT91PS_PIO pPio, // \arg pointer to a PIO controller
  703. unsigned int flag) // \arg pio interrupt to be disabled
  704. {
  705. pPio->PIO_IDR = flag;
  706. }
  707. //----------------------------------------------------------------------------
  708. // \fn AT91F_PIO_GetInterruptMaskStatus
  709. // \brief Return PIO Interrupt Mask Status
  710. //----------------------------------------------------------------------------
  711. __inline unsigned int AT91F_PIO_GetInterruptMaskStatus( // \return PIO Interrupt Mask Status
  712. AT91PS_PIO pPio) // \arg pointer to a PIO controller
  713. {
  714. return pPio->PIO_IMR;
  715. }
  716. //----------------------------------------------------------------------------
  717. // \fn AT91F_PIO_GetInterruptStatus
  718. // \brief Return PIO Interrupt Status
  719. //----------------------------------------------------------------------------
  720. __inline unsigned int AT91F_PIO_GetInterruptStatus( // \return PIO Interrupt Status
  721. AT91PS_PIO pPio) // \arg pointer to a PIO controller
  722. {
  723. return pPio->PIO_ISR;
  724. }
  725. //----------------------------------------------------------------------------
  726. // \fn AT91F_PIO_IsInterruptMasked
  727. // \brief Test if PIO Interrupt is Masked
  728. //----------------------------------------------------------------------------
  729. __inline int AT91F_PIO_IsInterruptMasked(
  730. AT91PS_PIO pPio, // \arg pointer to a PIO controller
  731. unsigned int flag) // \arg flag to be tested
  732. {
  733. return (AT91F_PIO_GetInterruptMaskStatus(pPio) & flag);
  734. }
  735. //----------------------------------------------------------------------------
  736. // \fn AT91F_PIO_IsInterruptSet
  737. // \brief Test if PIO Interrupt is Set
  738. //----------------------------------------------------------------------------
  739. __inline int AT91F_PIO_IsInterruptSet(
  740. AT91PS_PIO pPio, // \arg pointer to a PIO controller
  741. unsigned int flag) // \arg flag to be tested
  742. {
  743. return (AT91F_PIO_GetInterruptStatus(pPio) & flag);
  744. }
  745. //----------------------------------------------------------------------------
  746. // \fn AT91F_PIO_MultiDriverEnable
  747. // \brief Multi Driver Enable PIO
  748. //----------------------------------------------------------------------------
  749. __inline void AT91F_PIO_MultiDriverEnable(
  750. AT91PS_PIO pPio, // \arg pointer to a PIO controller
  751. unsigned int flag) // \arg pio to be enabled
  752. {
  753. pPio->PIO_MDER = flag;
  754. }
  755. //----------------------------------------------------------------------------
  756. // \fn AT91F_PIO_MultiDriverDisable
  757. // \brief Multi Driver Disable PIO
  758. //----------------------------------------------------------------------------
  759. __inline void AT91F_PIO_MultiDriverDisable(
  760. AT91PS_PIO pPio, // \arg pointer to a PIO controller
  761. unsigned int flag) // \arg pio to be disabled
  762. {
  763. pPio->PIO_MDDR = flag;
  764. }
  765. //----------------------------------------------------------------------------
  766. // \fn AT91F_PIO_GetMultiDriverStatus
  767. // \brief Return PIO Multi Driver Status
  768. //----------------------------------------------------------------------------
  769. __inline unsigned int AT91F_PIO_GetMultiDriverStatus( // \return PIO Multi Driver Status
  770. AT91PS_PIO pPio) // \arg pointer to a PIO controller
  771. {
  772. return pPio->PIO_MDSR;
  773. }
  774. //----------------------------------------------------------------------------
  775. // \fn AT91F_PIO_IsMultiDriverSet
  776. // \brief Test if PIO MultiDriver is Set
  777. //----------------------------------------------------------------------------
  778. __inline int AT91F_PIO_IsMultiDriverSet(
  779. AT91PS_PIO pPio, // \arg pointer to a PIO controller
  780. unsigned int flag) // \arg flag to be tested
  781. {
  782. return (AT91F_PIO_GetMultiDriverStatus(pPio) & flag);
  783. }
  784. //----------------------------------------------------------------------------
  785. // \fn AT91F_PIO_A_RegisterSelection
  786. // \brief PIO A Register Selection
  787. //----------------------------------------------------------------------------
  788. __inline void AT91F_PIO_A_RegisterSelection(
  789. AT91PS_PIO pPio, // \arg pointer to a PIO controller
  790. unsigned int flag) // \arg pio A register selection
  791. {
  792. pPio->PIO_ASR = flag;
  793. }
  794. //----------------------------------------------------------------------------
  795. // \fn AT91F_PIO_B_RegisterSelection
  796. // \brief PIO B Register Selection
  797. //----------------------------------------------------------------------------
  798. __inline void AT91F_PIO_B_RegisterSelection(
  799. AT91PS_PIO pPio, // \arg pointer to a PIO controller
  800. unsigned int flag) // \arg pio B register selection
  801. {
  802. pPio->PIO_BSR = flag;
  803. }
  804. //----------------------------------------------------------------------------
  805. // \fn AT91F_PIO_Get_AB_RegisterStatus
  806. // \brief Return PIO Interrupt Status
  807. //----------------------------------------------------------------------------
  808. __inline unsigned int AT91F_PIO_Get_AB_RegisterStatus( // \return PIO AB Register Status
  809. AT91PS_PIO pPio) // \arg pointer to a PIO controller
  810. {
  811. return pPio->PIO_ABSR;
  812. }
  813. //----------------------------------------------------------------------------
  814. // \fn AT91F_PIO_IsAB_RegisterSet
  815. // \brief Test if PIO AB Register is Set
  816. //----------------------------------------------------------------------------
  817. __inline int AT91F_PIO_IsAB_RegisterSet(
  818. AT91PS_PIO pPio, // \arg pointer to a PIO controller
  819. unsigned int flag) // \arg flag to be tested
  820. {
  821. return (AT91F_PIO_Get_AB_RegisterStatus(pPio) & flag);
  822. }
  823. //----------------------------------------------------------------------------
  824. // \fn AT91F_PIO_OutputWriteEnable
  825. // \brief Output Write Enable PIO
  826. //----------------------------------------------------------------------------
  827. __inline void AT91F_PIO_OutputWriteEnable(
  828. AT91PS_PIO pPio, // \arg pointer to a PIO controller
  829. unsigned int flag) // \arg pio output write to be enabled
  830. {
  831. pPio->PIO_OWER = flag;
  832. }
  833. //----------------------------------------------------------------------------
  834. // \fn AT91F_PIO_OutputWriteDisable
  835. // \brief Output Write Disable PIO
  836. //----------------------------------------------------------------------------
  837. __inline void AT91F_PIO_OutputWriteDisable(
  838. AT91PS_PIO pPio, // \arg pointer to a PIO controller
  839. unsigned int flag) // \arg pio output write to be disabled
  840. {
  841. pPio->PIO_OWDR = flag;
  842. }
  843. //----------------------------------------------------------------------------
  844. // \fn AT91F_PIO_GetOutputWriteStatus
  845. // \brief Return PIO Output Write Status
  846. //----------------------------------------------------------------------------
  847. __inline unsigned int AT91F_PIO_GetOutputWriteStatus( // \return PIO Output Write Status
  848. AT91PS_PIO pPio) // \arg pointer to a PIO controller
  849. {
  850. return pPio->PIO_OWSR;
  851. }
  852. //----------------------------------------------------------------------------
  853. // \fn AT91F_PIO_IsOutputWriteSet
  854. // \brief Test if PIO OutputWrite is Set
  855. //----------------------------------------------------------------------------
  856. __inline int AT91F_PIO_IsOutputWriteSet(
  857. AT91PS_PIO pPio, // \arg pointer to a PIO controller
  858. unsigned int flag) // \arg flag to be tested
  859. {
  860. return (AT91F_PIO_GetOutputWriteStatus(pPio) & flag);
  861. }
  862. //----------------------------------------------------------------------------
  863. // \fn AT91F_PIO_GetCfgPullup
  864. // \brief Return PIO Configuration Pullup
  865. //----------------------------------------------------------------------------
  866. __inline unsigned int AT91F_PIO_GetCfgPullup( // \return PIO Configuration Pullup
  867. AT91PS_PIO pPio) // \arg pointer to a PIO controller
  868. {
  869. return pPio->PIO_PPUSR;
  870. }
  871. //----------------------------------------------------------------------------
  872. // \fn AT91F_PIO_IsOutputDataStatusSet
  873. // \brief Test if PIO Output Data Status is Set
  874. //----------------------------------------------------------------------------
  875. __inline int AT91F_PIO_IsOutputDataStatusSet(
  876. AT91PS_PIO pPio, // \arg pointer to a PIO controller
  877. unsigned int flag) // \arg flag to be tested
  878. {
  879. return (AT91F_PIO_GetOutputDataStatus(pPio) & flag);
  880. }
  881. //----------------------------------------------------------------------------
  882. // \fn AT91F_PIO_IsCfgPullupStatusSet
  883. // \brief Test if PIO Configuration Pullup Status is Set
  884. //----------------------------------------------------------------------------
  885. __inline int AT91F_PIO_IsCfgPullupStatusSet(
  886. AT91PS_PIO pPio, // \arg pointer to a PIO controller
  887. unsigned int flag) // \arg flag to be tested
  888. {
  889. return (~AT91F_PIO_GetCfgPullup(pPio) & flag);
  890. }
  891. //}}}
  892. //{{{ PMC - Power management controller
  893. /* *****************************************************************************
  894. SOFTWARE API FOR PMC
  895. ***************************************************************************** */
  896. //----------------------------------------------------------------------------
  897. // \fn AT91F_PMC_CfgSysClkEnableReg
  898. // \brief Configure the System Clock Enable Register of the PMC controller
  899. //----------------------------------------------------------------------------
  900. __inline void AT91F_PMC_CfgSysClkEnableReg (
  901. AT91PS_PMC pPMC, // \arg pointer to PMC controller
  902. unsigned int mode)
  903. {
  904. // Write to the SCER register
  905. pPMC->PMC_SCER = mode;
  906. }
  907. //----------------------------------------------------------------------------
  908. // \fn AT91F_PMC_CfgSysClkDisableReg
  909. // \brief Configure the System Clock Disable Register of the PMC controller
  910. //----------------------------------------------------------------------------
  911. __inline void AT91F_PMC_CfgSysClkDisableReg (
  912. AT91PS_PMC pPMC, // \arg pointer to PMC controller
  913. unsigned int mode)
  914. {
  915. // Write to the SCDR register
  916. pPMC->PMC_SCDR = mode;
  917. }
  918. //----------------------------------------------------------------------------
  919. // \fn AT91F_PMC_GetSysClkStatusReg
  920. // \brief Return the System Clock Status Register of the PMC controller
  921. //----------------------------------------------------------------------------
  922. __inline unsigned int AT91F_PMC_GetSysClkStatusReg (
  923. AT91PS_PMC pPMC // pointer to a CAN controller
  924. )
  925. {
  926. return pPMC->PMC_SCSR;
  927. }
  928. //----------------------------------------------------------------------------
  929. // \fn AT91F_PMC_EnablePeriphClock
  930. // \brief Enable peripheral clock
  931. //----------------------------------------------------------------------------
  932. __inline void AT91F_PMC_EnablePeriphClock (
  933. AT91PS_PMC pPMC, // \arg pointer to PMC controller
  934. unsigned int periphIds) // \arg IDs of peripherals to enable
  935. {
  936. pPMC->PMC_PCER = periphIds;
  937. }
  938. //----------------------------------------------------------------------------
  939. // \fn AT91F_PMC_DisablePeriphClock
  940. // \brief Disable peripheral clock
  941. //----------------------------------------------------------------------------
  942. __inline void AT91F_PMC_DisablePeriphClock (
  943. AT91PS_PMC pPMC, // \arg pointer to PMC controller
  944. unsigned int periphIds) // \arg IDs of peripherals to enable
  945. {
  946. pPMC->PMC_PCDR = periphIds;
  947. }
  948. //----------------------------------------------------------------------------
  949. // \fn AT91F_PMC_GetPeriphClock
  950. // \brief Get peripheral clock status
  951. //----------------------------------------------------------------------------
  952. __inline unsigned int AT91F_PMC_GetPeriphClock (
  953. AT91PS_PMC pPMC) // \arg pointer to PMC controller
  954. {
  955. return pPMC->PMC_PCSR;
  956. }
  957. //----------------------------------------------------------------------------
  958. // \fn AT91F_CKGR_CfgMainOscillatorReg
  959. // \brief Cfg the main oscillator
  960. //----------------------------------------------------------------------------
  961. __inline void AT91F_CKGR_CfgMainOscillatorReg (
  962. AT91PS_CKGR pCKGR, // \arg pointer to CKGR controller
  963. unsigned int mode)
  964. {
  965. pCKGR->CKGR_MOR = mode;
  966. }
  967. //----------------------------------------------------------------------------
  968. // \fn AT91F_CKGR_GetMainOscillatorReg
  969. // \brief Cfg the main oscillator
  970. //----------------------------------------------------------------------------
  971. __inline unsigned int AT91F_CKGR_GetMainOscillatorReg (
  972. AT91PS_CKGR pCKGR) // \arg pointer to CKGR controller
  973. {
  974. return pCKGR->CKGR_MOR;
  975. }
  976. //----------------------------------------------------------------------------
  977. // \fn AT91F_CKGR_EnableMainOscillator
  978. // \brief Enable the main oscillator
  979. //----------------------------------------------------------------------------
  980. __inline void AT91F_CKGR_EnableMainOscillator(
  981. AT91PS_CKGR pCKGR) // \arg pointer to CKGR controller
  982. {
  983. pCKGR->CKGR_MOR |= AT91C_CKGR_MOSCEN;
  984. }
  985. //----------------------------------------------------------------------------
  986. // \fn AT91F_CKGR_DisableMainOscillator
  987. // \brief Disable the main oscillator
  988. //----------------------------------------------------------------------------
  989. __inline void AT91F_CKGR_DisableMainOscillator (
  990. AT91PS_CKGR pCKGR) // \arg pointer to CKGR controller
  991. {
  992. pCKGR->CKGR_MOR &= ~AT91C_CKGR_MOSCEN;
  993. }
  994. //----------------------------------------------------------------------------
  995. // \fn AT91F_CKGR_CfgMainOscStartUpTime
  996. // \brief Cfg MOR Register according to the main osc startup time
  997. //----------------------------------------------------------------------------
  998. __inline void AT91F_CKGR_CfgMainOscStartUpTime (
  999. AT91PS_CKGR pCKGR, // \arg pointer to CKGR controller
  1000. unsigned int startup_time, // \arg main osc startup time in microsecond (us)
  1001. unsigned int slowClock) // \arg slowClock in Hz
  1002. {
  1003. pCKGR->CKGR_MOR &= ~AT91C_CKGR_OSCOUNT;
  1004. pCKGR->CKGR_MOR |= ((slowClock * startup_time)/(8*1000000)) << 8;
  1005. }
  1006. //----------------------------------------------------------------------------
  1007. // \fn AT91F_CKGR_GetMainClockFreqReg
  1008. // \brief Cfg the main oscillator
  1009. //----------------------------------------------------------------------------
  1010. __inline unsigned int AT91F_CKGR_GetMainClockFreqReg (
  1011. AT91PS_CKGR pCKGR) // \arg pointer to CKGR controller
  1012. {
  1013. return pCKGR->CKGR_MCFR;
  1014. }
  1015. //----------------------------------------------------------------------------
  1016. // \fn AT91F_CKGR_GetMainClock
  1017. // \brief Return Main clock in Hz
  1018. //----------------------------------------------------------------------------
  1019. __inline unsigned int AT91F_CKGR_GetMainClock (
  1020. AT91PS_CKGR pCKGR, // \arg pointer to CKGR controller
  1021. unsigned int slowClock) // \arg slowClock in Hz
  1022. {
  1023. return ((pCKGR->CKGR_MCFR & AT91C_CKGR_MAINF) * slowClock) >> 4;
  1024. }
  1025. //----------------------------------------------------------------------------
  1026. // \fn AT91F_PMC_CfgMCKReg
  1027. // \brief Cfg Master Clock Register
  1028. //----------------------------------------------------------------------------
  1029. __inline void AT91F_PMC_CfgMCKReg (
  1030. AT91PS_PMC pPMC, // \arg pointer to PMC controller
  1031. unsigned int mode)
  1032. {
  1033. pPMC->PMC_MCKR = mode;
  1034. }
  1035. //----------------------------------------------------------------------------
  1036. // \fn AT91F_PMC_GetMCKReg
  1037. // \brief Return Master Clock Register
  1038. //----------------------------------------------------------------------------
  1039. __inline unsigned int AT91F_PMC_GetMCKReg(
  1040. AT91PS_PMC pPMC) // \arg pointer to PMC controller
  1041. {
  1042. return pPMC->PMC_MCKR;
  1043. }
  1044. //------------------------------------------------------------------------------
  1045. // \fn AT91F_PMC_GetMasterClock
  1046. // \brief Return master clock in Hz which correponds to processor clock for ARM7
  1047. //------------------------------------------------------------------------------
  1048. __inline unsigned int AT91F_PMC_GetMasterClock (
  1049. AT91PS_PMC pPMC, // \arg pointer to PMC controller
  1050. AT91PS_CKGR pCKGR, // \arg pointer to CKGR controller
  1051. unsigned int slowClock) // \arg slowClock in Hz
  1052. {
  1053. unsigned int reg = pPMC->PMC_MCKR;
  1054. unsigned int prescaler = (1 << ((reg & AT91C_PMC_PRES) >> 2));
  1055. unsigned int pllDivider, pllMultiplier;
  1056. switch (reg & AT91C_PMC_CSS) {
  1057. case AT91C_PMC_CSS_SLOW_CLK: // Slow clock selected
  1058. return slowClock / prescaler;
  1059. case AT91C_PMC_CSS_MAIN_CLK: // Main clock is selected
  1060. return AT91F_CKGR_GetMainClock(pCKGR, slowClock) / prescaler;
  1061. case AT91C_PMC_CSS_PLL_CLK: // PLLB clock is selected
  1062. reg = pCKGR->CKGR_PLLR;
  1063. pllDivider = (reg & AT91C_CKGR_DIV);
  1064. pllMultiplier = ((reg & AT91C_CKGR_MUL) >> 16) + 1;
  1065. return AT91F_CKGR_GetMainClock(pCKGR, slowClock) / pllDivider * pllMultiplier / prescaler;
  1066. }
  1067. return 0;
  1068. }
  1069. //----------------------------------------------------------------------------
  1070. // \fn AT91F_PMC_EnablePCK
  1071. // \brief Enable peripheral clock
  1072. //----------------------------------------------------------------------------
  1073. __inline void AT91F_PMC_EnablePCK (
  1074. AT91PS_PMC pPMC, // \arg pointer to PMC controller
  1075. unsigned int pck, // \arg Peripheral clock identifier 0 .. 7
  1076. unsigned int mode)
  1077. {
  1078. pPMC->PMC_PCKR[pck] = mode;
  1079. pPMC->PMC_SCER = (1 << pck) << 8;
  1080. }
  1081. //----------------------------------------------------------------------------
  1082. // \fn AT91F_PMC_DisablePCK
  1083. // \brief Enable peripheral clock
  1084. //----------------------------------------------------------------------------
  1085. __inline void AT91F_PMC_DisablePCK (
  1086. AT91PS_PMC pPMC, // \arg pointer to PMC controller
  1087. unsigned int pck) // \arg Peripheral clock identifier 0 .. 7
  1088. {
  1089. pPMC->PMC_SCDR = (1 << pck) << 8;
  1090. }
  1091. //----------------------------------------------------------------------------
  1092. // \fn AT91F_PMC_EnableIt
  1093. // \brief Enable PMC interrupt
  1094. //----------------------------------------------------------------------------
  1095. __inline void AT91F_PMC_EnableIt (
  1096. AT91PS_PMC pPMC, // pointer to a PMC controller
  1097. unsigned int flag) // IT to be enabled
  1098. {
  1099. // Write to the IER register
  1100. pPMC->PMC_IER = flag;
  1101. }
  1102. //----------------------------------------------------------------------------
  1103. // \fn AT91F_PMC_DisableIt
  1104. // \brief Disable PMC interrupt
  1105. //----------------------------------------------------------------------------
  1106. __inline void AT91F_PMC_DisableIt (
  1107. AT91PS_PMC pPMC, // pointer to a PMC controller
  1108. unsigned int flag) // IT to be disabled
  1109. {
  1110. // Write to the IDR register
  1111. pPMC->PMC_IDR = flag;
  1112. }
  1113. //----------------------------------------------------------------------------
  1114. // \fn AT91F_PMC_GetStatus
  1115. // \brief Return PMC Interrupt Status
  1116. //----------------------------------------------------------------------------
  1117. __inline unsigned int AT91F_PMC_GetStatus( // \return PMC Interrupt Status
  1118. AT91PS_PMC pPMC) // pointer to a PMC controller
  1119. {
  1120. return pPMC->PMC_SR;
  1121. }
  1122. //----------------------------------------------------------------------------
  1123. // \fn AT91F_PMC_GetInterruptMaskStatus
  1124. // \brief Return PMC Interrupt Mask Status
  1125. //----------------------------------------------------------------------------
  1126. __inline unsigned int AT91F_PMC_GetInterruptMaskStatus( // \return PMC Interrupt Mask Status
  1127. AT91PS_PMC pPMC) // pointer to a PMC controller
  1128. {
  1129. return pPMC->PMC_IMR;
  1130. }
  1131. //----------------------------------------------------------------------------
  1132. // \fn AT91F_PMC_IsInterruptMasked
  1133. // \brief Test if PMC Interrupt is Masked
  1134. //----------------------------------------------------------------------------
  1135. __inline unsigned int AT91F_PMC_IsInterruptMasked(
  1136. AT91PS_PMC pPMC, // \arg pointer to a PMC controller
  1137. unsigned int flag) // \arg flag to be tested
  1138. {
  1139. return (AT91F_PMC_GetInterruptMaskStatus(pPMC) & flag);
  1140. }
  1141. //----------------------------------------------------------------------------
  1142. // \fn AT91F_PMC_IsStatusSet
  1143. // \brief Test if PMC Status is Set
  1144. //----------------------------------------------------------------------------
  1145. __inline unsigned int AT91F_PMC_IsStatusSet(
  1146. AT91PS_PMC pPMC, // \arg pointer to a PMC controller
  1147. unsigned int flag) // \arg flag to be tested
  1148. {
  1149. return (AT91F_PMC_GetStatus(pPMC) & flag);
  1150. }
  1151. // ----------------------------------------------------------------------------
  1152. // \fn AT91F_CKGR_CfgPLLReg
  1153. // \brief Cfg the PLL Register
  1154. // ----------------------------------------------------------------------------
  1155. __inline void AT91F_CKGR_CfgPLLReg (
  1156. AT91PS_CKGR pCKGR, // \arg pointer to CKGR controller
  1157. unsigned int mode)
  1158. {
  1159. pCKGR->CKGR_PLLR = mode;
  1160. }
  1161. // ----------------------------------------------------------------------------
  1162. // \fn AT91F_CKGR_GetPLLReg
  1163. // \brief Get the PLL Register
  1164. // ----------------------------------------------------------------------------
  1165. __inline unsigned int AT91F_CKGR_GetPLLReg (
  1166. AT91PS_CKGR pCKGR) // \arg pointer to CKGR controller
  1167. {
  1168. return pCKGR->CKGR_PLLR;
  1169. }
  1170. //}}}
  1171. //{{{ RST - Reset controller
  1172. /* *****************************************************************************
  1173. SOFTWARE API FOR RSTC
  1174. ***************************************************************************** */
  1175. //----------------------------------------------------------------------------
  1176. // \fn AT91F_RSTSoftReset
  1177. // \brief Start Software Reset
  1178. //----------------------------------------------------------------------------
  1179. __inline void AT91F_RSTSoftReset(
  1180. AT91PS_RSTC pRSTC,
  1181. unsigned int reset)
  1182. {
  1183. pRSTC->RSTC_RCR = (0xA5000000 | reset);
  1184. }
  1185. //----------------------------------------------------------------------------
  1186. // \fn AT91F_RSTSetMode
  1187. // \brief Set Reset Mode
  1188. //----------------------------------------------------------------------------
  1189. __inline void AT91F_RSTSetMode(
  1190. AT91PS_RSTC pRSTC,
  1191. unsigned int mode)
  1192. {
  1193. pRSTC->RSTC_RMR = (0xA5000000 | mode);
  1194. }
  1195. //----------------------------------------------------------------------------
  1196. // \fn AT91F_RSTGetMode
  1197. // \brief Get Reset Mode
  1198. //----------------------------------------------------------------------------
  1199. __inline unsigned int AT91F_RSTGetMode(
  1200. AT91PS_RSTC pRSTC)
  1201. {
  1202. return (pRSTC->RSTC_RMR);
  1203. }
  1204. //----------------------------------------------------------------------------
  1205. // \fn AT91F_RSTGetStatus
  1206. // \brief Get Reset Status
  1207. //----------------------------------------------------------------------------
  1208. __inline unsigned int AT91F_RSTGetStatus(
  1209. AT91PS_RSTC pRSTC)
  1210. {
  1211. return (pRSTC->RSTC_RSR);
  1212. }
  1213. //----------------------------------------------------------------------------
  1214. // \fn AT91F_RSTIsSoftRstActive
  1215. // \brief Return !=0 if software reset is still not completed
  1216. //----------------------------------------------------------------------------
  1217. __inline unsigned int AT91F_RSTIsSoftRstActive(
  1218. AT91PS_RSTC pRSTC)
  1219. {
  1220. return ((pRSTC->RSTC_RSR) & AT91C_RSTC_SRCMP);
  1221. }//}}}
  1222. //{{{ RTT - Real time timer
  1223. /* *****************************************************************************
  1224. SOFTWARE API FOR RTTC
  1225. ***************************************************************************** */
  1226. //--------------------------------------------------------------------------------------
  1227. // \fn AT91F_SetRTT_TimeBase()
  1228. // \brief Set the RTT prescaler according to the TimeBase in ms
  1229. //--------------------------------------------------------------------------------------
  1230. __inline unsigned int AT91F_RTTSetTimeBase(
  1231. AT91PS_RTTC pRTTC,
  1232. unsigned int ms)
  1233. {
  1234. if (ms > 2000)
  1235. return 1; // AT91C_TIME_OUT_OF_RANGE
  1236. pRTTC->RTTC_RTMR &= ~0xFFFF;
  1237. pRTTC->RTTC_RTMR |= (((ms << 15) /1000) & 0xFFFF);
  1238. return 0;
  1239. }
  1240. //--------------------------------------------------------------------------------------
  1241. // \fn AT91F_RTTSetPrescaler()
  1242. // \brief Set the new prescaler value
  1243. //--------------------------------------------------------------------------------------
  1244. __inline unsigned int AT91F_RTTSetPrescaler(
  1245. AT91PS_RTTC pRTTC,
  1246. unsigned int rtpres)
  1247. {
  1248. pRTTC->RTTC_RTMR &= ~0xFFFF;
  1249. pRTTC->RTTC_RTMR |= (rtpres & 0xFFFF);
  1250. return (pRTTC->RTTC_RTMR);
  1251. }
  1252. //--------------------------------------------------------------------------------------
  1253. // \fn AT91F_RTTRestart()
  1254. // \brief Restart the RTT prescaler
  1255. //--------------------------------------------------------------------------------------
  1256. __inline void AT91F_RTTRestart(
  1257. AT91PS_RTTC pRTTC)
  1258. {
  1259. pRTTC->RTTC_RTMR |= AT91C_RTTC_RTTRST;
  1260. }
  1261. //--------------------------------------------------------------------------------------
  1262. // \fn AT91F_RTT_SetAlarmINT()
  1263. // \brief Enable RTT Alarm Interrupt
  1264. //--------------------------------------------------------------------------------------
  1265. __inline void AT91F_RTTSetAlarmINT(
  1266. AT91PS_RTTC pRTTC)
  1267. {
  1268. pRTTC->RTTC_RTMR |= AT91C_RTTC_ALMIEN;
  1269. }
  1270. //--------------------------------------------------------------------------------------
  1271. // \fn AT91F_RTT_ClearAlarmINT()
  1272. // \brief Disable RTT Alarm Interrupt
  1273. //--------------------------------------------------------------------------------------
  1274. __inline void AT91F_RTTClearAlarmINT(
  1275. AT91PS_RTTC pRTTC)
  1276. {
  1277. pRTTC->RTTC_RTMR &= ~AT91C_RTTC_ALMIEN;
  1278. }
  1279. //--------------------------------------------------------------------------------------
  1280. // \fn AT91F_RTT_SetRttIncINT()
  1281. // \brief Enable RTT INC Interrupt
  1282. //--------------------------------------------------------------------------------------
  1283. __inline void AT91F_RTTSetRttIncINT(
  1284. AT91PS_RTTC pRTTC)
  1285. {
  1286. pRTTC->RTTC_RTMR |= AT91C_RTTC_RTTINCIEN;
  1287. }
  1288. //--------------------------------------------------------------------------------------
  1289. // \fn AT91F_RTT_ClearRttIncINT()
  1290. // \brief Disable RTT INC Interrupt
  1291. //--------------------------------------------------------------------------------------
  1292. __inline void AT91F_RTTClearRttIncINT(
  1293. AT91PS_RTTC pRTTC)
  1294. {
  1295. pRTTC->RTTC_RTMR &= ~AT91C_RTTC_RTTINCIEN;
  1296. }
  1297. //--------------------------------------------------------------------------------------
  1298. // \fn AT91F_RTT_SetAlarmValue()
  1299. // \brief Set RTT Alarm Value
  1300. //--------------------------------------------------------------------------------------
  1301. __inline void AT91F_RTTSetAlarmValue(
  1302. AT91PS_RTTC pRTTC, unsigned int alarm)
  1303. {
  1304. pRTTC->RTTC_RTAR = alarm;
  1305. }
  1306. //--------------------------------------------------------------------------------------
  1307. // \fn AT91F_RTT_GetAlarmValue()
  1308. // \brief Get RTT Alarm Value
  1309. //--------------------------------------------------------------------------------------
  1310. __inline unsigned int AT91F_RTTGetAlarmValue(
  1311. AT91PS_RTTC pRTTC)
  1312. {
  1313. return(pRTTC->RTTC_RTAR);
  1314. }
  1315. //--------------------------------------------------------------------------------------
  1316. // \fn AT91F_RTTGetStatus()
  1317. // \brief Read the RTT status
  1318. //--------------------------------------------------------------------------------------
  1319. __inline unsigned int AT91F_RTTGetStatus(
  1320. AT91PS_RTTC pRTTC)
  1321. {
  1322. return(pRTTC->RTTC_RTSR);
  1323. }
  1324. //--------------------------------------------------------------------------------------
  1325. // \fn AT91F_RTT_ReadValue()
  1326. // \brief Read the RTT value
  1327. //--------------------------------------------------------------------------------------
  1328. __inline unsigned int AT91F_RTTReadValue(
  1329. AT91PS_RTTC pRTTC)
  1330. {
  1331. register volatile unsigned int val1,val2;
  1332. do
  1333. {
  1334. val1 = pRTTC->RTTC_RTVR;
  1335. val2 = pRTTC->RTTC_RTVR;
  1336. }
  1337. while(val1 != val2);
  1338. return(val1);
  1339. }//}}}
  1340. //{{{ PIT - Periodic interval timer
  1341. /* *****************************************************************************
  1342. SOFTWARE API FOR PITC
  1343. ***************************************************************************** */
  1344. //----------------------------------------------------------------------------
  1345. // \fn AT91F_PITInit
  1346. // \brief System timer init : period in µsecond, system clock freq in MHz
  1347. //----------------------------------------------------------------------------
  1348. __inline void AT91F_PITInit(
  1349. AT91PS_PITC pPITC,
  1350. unsigned int period,
  1351. unsigned int pit_frequency)
  1352. {
  1353. pPITC->PITC_PIMR = period? (period * pit_frequency + 8) >> 4 : 0; // +8 to avoid %10 and /10
  1354. pPITC->PITC_PIMR |= AT91C_PITC_PITEN;
  1355. }
  1356. //----------------------------------------------------------------------------
  1357. // \fn AT91F_PITSetPIV
  1358. // \brief Set the PIT Periodic Interval Value
  1359. //----------------------------------------------------------------------------
  1360. __inline void AT91F_PITSetPIV(
  1361. AT91PS_PITC pPITC,
  1362. unsigned int piv)
  1363. {
  1364. pPITC->PITC_PIMR = piv | (pPITC->PITC_PIMR & (AT91C_PITC_PITEN | AT91C_PITC_PITIEN));
  1365. }
  1366. //----------------------------------------------------------------------------
  1367. // \fn AT91F_PITEnableInt
  1368. // \brief Enable PIT periodic interrupt
  1369. //----------------------------------------------------------------------------
  1370. __inline void AT91F_PITEnableInt(
  1371. AT91PS_PITC pPITC)
  1372. {
  1373. pPITC->PITC_PIMR |= AT91C_PITC_PITIEN;
  1374. }
  1375. //----------------------------------------------------------------------------
  1376. // \fn AT91F_PITDisableInt
  1377. // \brief Disable PIT periodic interrupt
  1378. //----------------------------------------------------------------------------
  1379. __inline void AT91F_PITDisableInt(
  1380. AT91PS_PITC pPITC)
  1381. {
  1382. pPITC->PITC_PIMR &= ~AT91C_PITC_PITIEN;
  1383. }
  1384. //----------------------------------------------------------------------------
  1385. // \fn AT91F_PITGetMode
  1386. // \brief Read PIT mode register
  1387. //----------------------------------------------------------------------------
  1388. __inline unsigned int AT91F_PITGetMode(
  1389. AT91PS_PITC pPITC)
  1390. {
  1391. return(pPITC->PITC_PIMR);
  1392. }
  1393. //----------------------------------------------------------------------------
  1394. // \fn AT91F_PITGetStatus
  1395. // \brief Read PIT status register
  1396. //----------------------------------------------------------------------------
  1397. __inline unsigned int AT91F_PITGetStatus(
  1398. AT91PS_PITC pPITC)
  1399. {
  1400. return(pPITC->PITC_PISR);
  1401. }
  1402. //----------------------------------------------------------------------------
  1403. // \fn AT91F_PITGetPIIR
  1404. // \brief Read PIT CPIV and PICNT without ressetting the counters
  1405. //----------------------------------------------------------------------------
  1406. __inline unsigned int AT91F_PITGetPIIR(
  1407. AT91PS_PITC pPITC)
  1408. {
  1409. return(pPITC->PITC_PIIR);
  1410. }
  1411. //----------------------------------------------------------------------------
  1412. // \fn AT91F_PITGetPIVR
  1413. // \brief Read System timer CPIV and PICNT without ressetting the counters
  1414. //----------------------------------------------------------------------------
  1415. __inline unsigned int AT91F_PITGetPIVR(
  1416. AT91PS_PITC pPITC)
  1417. {
  1418. return(pPITC->PITC_PIVR);
  1419. }//}}}
  1420. //{{{ WDT - Watchdog timer
  1421. /* *****************************************************************************
  1422. SOFTWARE API FOR WDTC
  1423. ***************************************************************************** */
  1424. //----------------------------------------------------------------------------
  1425. // \fn AT91F_WDTSetMode
  1426. // \brief Set Watchdog Mode Register
  1427. //----------------------------------------------------------------------------
  1428. __inline void AT91F_WDTSetMode(
  1429. AT91PS_WDTC pWDTC,
  1430. unsigned int Mode)
  1431. {
  1432. pWDTC->WDTC_WDMR = Mode;
  1433. }
  1434. //----------------------------------------------------------------------------
  1435. // \fn AT91F_WDTRestart
  1436. // \brief Restart Watchdog
  1437. //----------------------------------------------------------------------------
  1438. __inline void AT91F_WDTRestart(
  1439. AT91PS_WDTC pWDTC)
  1440. {
  1441. pWDTC->WDTC_WDCR = 0xA5000001;
  1442. }
  1443. //----------------------------------------------------------------------------
  1444. // \fn AT91F_WDTSGettatus
  1445. // \brief Get Watchdog Status
  1446. //----------------------------------------------------------------------------
  1447. __inline unsigned int AT91F_WDTSGettatus(
  1448. AT91PS_WDTC pWDTC)
  1449. {
  1450. return(pWDTC->WDTC_WDSR & 0x3);
  1451. }
  1452. //----------------------------------------------------------------------------
  1453. // \fn AT91F_WDTGetPeriod
  1454. // \brief Translate ms into Watchdog Compatible value
  1455. //----------------------------------------------------------------------------
  1456. __inline unsigned int AT91F_WDTGetPeriod(unsigned int ms)
  1457. {
  1458. if ((ms < 4) || (ms > 16000))
  1459. return 0;
  1460. return((ms << 8) / 1000);
  1461. }//}}}
  1462. //{{{ VREG - Voltage regulator
  1463. /* *****************************************************************************
  1464. SOFTWARE API FOR VREG
  1465. ***************************************************************************** */
  1466. //----------------------------------------------------------------------------
  1467. // \fn AT91F_VREG_Enable_LowPowerMode
  1468. // \brief Enable VREG Low Power Mode
  1469. //----------------------------------------------------------------------------
  1470. __inline void AT91F_VREG_Enable_LowPowerMode(
  1471. AT91PS_VREG pVREG)
  1472. {
  1473. pVREG->VREG_MR |= AT91C_VREG_PSTDBY;
  1474. }
  1475. //----------------------------------------------------------------------------
  1476. // \fn AT91F_VREG_Disable_LowPowerMode
  1477. // \brief Disable VREG Low Power Mode
  1478. //----------------------------------------------------------------------------
  1479. __inline void AT91F_VREG_Disable_LowPowerMode(
  1480. AT91PS_VREG pVREG)
  1481. {
  1482. pVREG->VREG_MR &= ~AT91C_VREG_PSTDBY;
  1483. }
  1484. //}}}
  1485. //{{{ MC - Memory controller
  1486. /* *****************************************************************************
  1487. SOFTWARE API FOR MC
  1488. ***************************************************************************** */
  1489. #define AT91C_MC_CORRECT_KEY ((unsigned int) 0x5A << 24) // (MC) Correct Protect Key
  1490. //----------------------------------------------------------------------------
  1491. // \fn AT91F_MC_Remap
  1492. // \brief Make Remap
  1493. //----------------------------------------------------------------------------
  1494. __inline void AT91F_MC_Remap (void) //
  1495. {
  1496. AT91PS_MC pMC = (AT91PS_MC) AT91C_BASE_MC;
  1497. pMC->MC_RCR = AT91C_MC_RCB;
  1498. }
  1499. //----------------------------------------------------------------------------
  1500. // \fn AT91F_MC_EFC_CfgModeReg
  1501. // \brief Configure the EFC Mode Register of the MC controller
  1502. //----------------------------------------------------------------------------
  1503. __inline void AT91F_MC_EFC_CfgModeReg (
  1504. AT91PS_MC pMC, // pointer to a MC controller
  1505. unsigned int mode) // mode register
  1506. {
  1507. // Write to the FMR register
  1508. pMC->MC_FMR = mode;
  1509. }
  1510. //----------------------------------------------------------------------------
  1511. // \fn AT91F_MC_EFC_GetModeReg
  1512. // \brief Return MC EFC Mode Regsiter
  1513. //----------------------------------------------------------------------------
  1514. __inline unsigned int AT91F_MC_EFC_GetModeReg(
  1515. AT91PS_MC pMC) // pointer to a MC controller
  1516. {
  1517. return pMC->MC_FMR;
  1518. }
  1519. //----------------------------------------------------------------------------
  1520. // \fn AT91F_MC_EFC_ComputeFMCN
  1521. // \brief Return MC EFC Mode Regsiter
  1522. //----------------------------------------------------------------------------
  1523. __inline unsigned int AT91F_MC_EFC_ComputeFMCN(
  1524. int master_clock) // master clock in Hz
  1525. {
  1526. return (master_clock/1000000 +2);
  1527. }
  1528. //----------------------------------------------------------------------------
  1529. // \fn AT91F_MC_EFC_PerformCmd
  1530. // \brief Perform EFC Command
  1531. //----------------------------------------------------------------------------
  1532. __inline void AT91F_MC_EFC_PerformCmd (
  1533. AT91PS_MC pMC, // pointer to a MC controller
  1534. unsigned int transfer_cmd)
  1535. {
  1536. pMC->MC_FCR = transfer_cmd;
  1537. }
  1538. //----------------------------------------------------------------------------
  1539. // \fn AT91F_MC_EFC_GetStatus
  1540. // \brief Return MC EFC Status
  1541. //----------------------------------------------------------------------------
  1542. __inline unsigned int AT91F_MC_EFC_GetStatus(
  1543. AT91PS_MC pMC) // pointer to a MC controller
  1544. {
  1545. return pMC->MC_FSR;
  1546. }
  1547. //----------------------------------------------------------------------------
  1548. // \fn AT91F_MC_EFC_IsInterruptMasked
  1549. // \brief Test if EFC MC Interrupt is Masked
  1550. //----------------------------------------------------------------------------
  1551. __inline unsigned int AT91F_MC_EFC_IsInterruptMasked(
  1552. AT91PS_MC pMC, // \arg pointer to a MC controller
  1553. unsigned int flag) // \arg flag to be tested
  1554. {
  1555. return (AT91F_MC_EFC_GetModeReg(pMC) & flag);
  1556. }
  1557. //----------------------------------------------------------------------------
  1558. // \fn AT91F_MC_EFC_IsInterruptSet
  1559. // \brief Test if EFC MC Interrupt is Set
  1560. //----------------------------------------------------------------------------
  1561. __inline unsigned int AT91F_MC_EFC_IsInterruptSet(
  1562. AT91PS_MC pMC, // \arg pointer to a MC controller
  1563. unsigned int flag) // \arg flag to be tested
  1564. {
  1565. return (AT91F_MC_EFC_GetStatus(pMC) & flag);
  1566. }
  1567. //}}}
  1568. //{{{ SPI - Serial peripheral interface
  1569. /* *****************************************************************************
  1570. SOFTWARE API FOR SPI
  1571. ***************************************************************************** */
  1572. //----------------------------------------------------------------------------
  1573. // \fn AT91F_SPI_CfgCs
  1574. // \brief Configure SPI chip select register
  1575. //----------------------------------------------------------------------------
  1576. __inline void AT91F_SPI_CfgCs (
  1577. AT91PS_SPI pSPI, // pointer to a SPI controller
  1578. int cs, // SPI cs number (0 to 3)
  1579. int val) // chip select register
  1580. {
  1581. // Write to the CSR register
  1582. *(pSPI->SPI_CSR + cs) = val;
  1583. }
  1584. //----------------------------------------------------------------------------
  1585. // \fn AT91F_SPI_EnableIt
  1586. // \brief Enable SPI interrupt
  1587. //----------------------------------------------------------------------------
  1588. __inline void AT91F_SPI_EnableIt (
  1589. AT91PS_SPI pSPI, // pointer to a SPI controller
  1590. unsigned int flag) // IT to be enabled
  1591. {
  1592. // Write to the IER register
  1593. pSPI->SPI_IER = flag;
  1594. }
  1595. //----------------------------------------------------------------------------
  1596. // \fn AT91F_SPI_DisableIt
  1597. // \brief Disable SPI interrupt
  1598. //----------------------------------------------------------------------------
  1599. __inline void AT91F_SPI_DisableIt (
  1600. AT91PS_SPI pSPI, // pointer to a SPI controller
  1601. unsigned int flag) // IT to be disabled
  1602. {
  1603. // Write to the IDR register
  1604. pSPI->SPI_IDR = flag;
  1605. }
  1606. //----------------------------------------------------------------------------
  1607. // \fn AT91F_SPI_Reset
  1608. // \brief Reset the SPI controller
  1609. //----------------------------------------------------------------------------
  1610. __inline void AT91F_SPI_Reset (
  1611. AT91PS_SPI pSPI // pointer to a SPI controller
  1612. )
  1613. {
  1614. // Write to the CR register
  1615. pSPI->SPI_CR = AT91C_SPI_SWRST;
  1616. }
  1617. //----------------------------------------------------------------------------
  1618. // \fn AT91F_SPI_Enable
  1619. // \brief Enable the SPI controller
  1620. //----------------------------------------------------------------------------
  1621. __inline void AT91F_SPI_Enable (
  1622. AT91PS_SPI pSPI // pointer to a SPI controller
  1623. )
  1624. {
  1625. // Write to the CR register
  1626. pSPI->SPI_CR = AT91C_SPI_SPIEN;
  1627. }
  1628. //----------------------------------------------------------------------------
  1629. // \fn AT91F_SPI_Disable
  1630. // \brief Disable the SPI controller
  1631. //----------------------------------------------------------------------------
  1632. __inline void AT91F_SPI_Disable (
  1633. AT91PS_SPI pSPI // pointer to a SPI controller
  1634. )
  1635. {
  1636. // Write to the CR register
  1637. pSPI->SPI_CR = AT91C_SPI_SPIDIS;
  1638. }
  1639. //----------------------------------------------------------------------------
  1640. // \fn AT91F_SPI_CfgMode
  1641. // \brief Enable the SPI controller
  1642. //----------------------------------------------------------------------------
  1643. __inline void AT91F_SPI_CfgMode (
  1644. AT91PS_SPI pSPI, // pointer to a SPI controller
  1645. int mode) // mode register
  1646. {
  1647. // Write to the MR register
  1648. pSPI->SPI_MR = mode;
  1649. }
  1650. //----------------------------------------------------------------------------
  1651. // \fn AT91F_SPI_CfgPCS
  1652. // \brief Switch to the correct PCS of SPI Mode Register : Fixed Peripheral Selected
  1653. //----------------------------------------------------------------------------
  1654. __inline void AT91F_SPI_CfgPCS (
  1655. AT91PS_SPI pSPI, // pointer to a SPI controller
  1656. char PCS_Device) // PCS of the Device
  1657. {
  1658. // Write to the MR register
  1659. pSPI->SPI_MR &= 0xFFF0FFFF;
  1660. pSPI->SPI_MR |= ( (PCS_Device<<16) & AT91C_SPI_PCS );
  1661. }
  1662. //----------------------------------------------------------------------------
  1663. // \fn AT91F_SPI_ReceiveFrame
  1664. // \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
  1665. //----------------------------------------------------------------------------
  1666. __inline unsigned int AT91F_SPI_ReceiveFrame (
  1667. AT91PS_SPI pSPI,
  1668. char *pBuffer,
  1669. unsigned int szBuffer,
  1670. char *pNextBuffer,
  1671. unsigned int szNextBuffer )
  1672. {
  1673. return AT91F_PDC_ReceiveFrame(
  1674. (AT91PS_PDC) &(pSPI->SPI_RPR),
  1675. pBuffer,
  1676. szBuffer,
  1677. pNextBuffer,
  1678. szNextBuffer);
  1679. }
  1680. //----------------------------------------------------------------------------
  1681. // \fn AT91F_SPI_SendFrame
  1682. // \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
  1683. //----------------------------------------------------------------------------
  1684. __inline unsigned int AT91F_SPI_SendFrame(
  1685. AT91PS_SPI pSPI,
  1686. char *pBuffer,
  1687. unsigned int szBuffer,
  1688. char *pNextBuffer,
  1689. unsigned int szNextBuffer )
  1690. {
  1691. return AT91F_PDC_SendFrame(
  1692. (AT91PS_PDC) &(pSPI->SPI_RPR),
  1693. pBuffer,
  1694. szBuffer,
  1695. pNextBuffer,
  1696. szNextBuffer);
  1697. }
  1698. //----------------------------------------------------------------------------
  1699. // \fn AT91F_SPI_Close
  1700. // \brief Close SPI: disable IT disable transfert, close PDC
  1701. //----------------------------------------------------------------------------
  1702. __inline void AT91F_SPI_Close (
  1703. AT91PS_SPI pSPI) // \arg pointer to a SPI controller
  1704. {
  1705. // Reset all the Chip Select register
  1706. pSPI->SPI_CSR[0] = 0 ;
  1707. pSPI->SPI_CSR[1] = 0 ;
  1708. pSPI->SPI_CSR[2] = 0 ;
  1709. pSPI->SPI_CSR[3] = 0 ;
  1710. // Reset the SPI mode
  1711. pSPI->SPI_MR = 0 ;
  1712. // Disable all interrupts
  1713. pSPI->SPI_IDR = 0xFFFFFFFF ;
  1714. // Abort the Peripheral Data Transfers
  1715. AT91F_PDC_Close((AT91PS_PDC) &(pSPI->SPI_RPR));
  1716. // Disable receiver and transmitter and stop any activity immediately
  1717. pSPI->SPI_CR = AT91C_SPI_SPIDIS;
  1718. }
  1719. //----------------------------------------------------------------------------
  1720. // \fn AT91F_SPI_PutChar
  1721. // \brief Send a character,does not check if ready to send
  1722. //----------------------------------------------------------------------------
  1723. __inline void AT91F_SPI_PutChar (
  1724. AT91PS_SPI pSPI,
  1725. unsigned int character,
  1726. unsigned int cs_number )
  1727. {
  1728. unsigned int value_for_cs;
  1729. value_for_cs = (~(1 << cs_number)) & 0xF; //Place a zero among a 4 ONEs number
  1730. pSPI->SPI_TDR = (character & 0xFFFF) | (value_for_cs << 16);
  1731. }
  1732. //----------------------------------------------------------------------------
  1733. // \fn AT91F_SPI_GetChar
  1734. // \brief Receive a character,does not check if a character is available
  1735. //----------------------------------------------------------------------------
  1736. __inline int AT91F_SPI_GetChar (
  1737. const AT91PS_SPI pSPI)
  1738. {
  1739. return((pSPI->SPI_RDR) & 0xFFFF);
  1740. }
  1741. //----------------------------------------------------------------------------
  1742. // \fn AT91F_SPI_GetInterruptMaskStatus
  1743. // \brief Return SPI Interrupt Mask Status
  1744. //----------------------------------------------------------------------------
  1745. __inline unsigned int AT91F_SPI_GetInterruptMaskStatus( // \return SPI Interrupt Mask Status
  1746. AT91PS_SPI pSpi) // \arg pointer to a SPI controller
  1747. {
  1748. return pSpi->SPI_IMR;
  1749. }
  1750. //----------------------------------------------------------------------------
  1751. // \fn AT91F_SPI_IsInterruptMasked
  1752. // \brief Test if SPI Interrupt is Masked
  1753. //----------------------------------------------------------------------------
  1754. __inline int AT91F_SPI_IsInterruptMasked(
  1755. AT91PS_SPI pSpi, // \arg pointer to a SPI controller
  1756. unsigned int flag) // \arg flag to be tested
  1757. {
  1758. return (AT91F_SPI_GetInterruptMaskStatus(pSpi) & flag);
  1759. }
  1760. //}}}
  1761. //{{{ ADC - Analog to digital converter
  1762. /* *****************************************************************************
  1763. SOFTWARE API FOR ADC
  1764. ***************************************************************************** */
  1765. //----------------------------------------------------------------------------
  1766. // \fn AT91F_ADC_EnableIt
  1767. // \brief Enable ADC interrupt
  1768. //----------------------------------------------------------------------------
  1769. __inline void AT91F_ADC_EnableIt (
  1770. AT91PS_ADC pADC, // pointer to a ADC controller
  1771. unsigned int flag) // IT to be enabled
  1772. {
  1773. // Write to the IER register
  1774. pADC->ADC_IER = flag;
  1775. }
  1776. //----------------------------------------------------------------------------
  1777. // \fn AT91F_ADC_DisableIt
  1778. // \brief Disable ADC interrupt
  1779. //----------------------------------------------------------------------------
  1780. __inline void AT91F_ADC_DisableIt (
  1781. AT91PS_ADC pADC, // pointer to a ADC controller
  1782. unsigned int flag) // IT to be disabled
  1783. {
  1784. // Write to the IDR register
  1785. pADC->ADC_IDR = flag;
  1786. }
  1787. //----------------------------------------------------------------------------
  1788. // \fn AT91F_ADC_GetStatus
  1789. // \brief Return ADC Interrupt Status
  1790. //----------------------------------------------------------------------------
  1791. __inline unsigned int AT91F_ADC_GetStatus( // \return ADC Interrupt Status
  1792. AT91PS_ADC pADC) // pointer to a ADC controller
  1793. {
  1794. return pADC->ADC_SR;
  1795. }
  1796. //----------------------------------------------------------------------------
  1797. // \fn AT91F_ADC_GetInterruptMaskStatus
  1798. // \brief Return ADC Interrupt Mask Status
  1799. //----------------------------------------------------------------------------
  1800. __inline unsigned int AT91F_ADC_GetInterruptMaskStatus( // \return ADC Interrupt Mask Status
  1801. AT91PS_ADC pADC) // pointer to a ADC controller
  1802. {
  1803. return pADC->ADC_IMR;
  1804. }
  1805. //----------------------------------------------------------------------------
  1806. // \fn AT91F_ADC_IsInterruptMasked
  1807. // \brief Test if ADC Interrupt is Masked
  1808. //----------------------------------------------------------------------------
  1809. __inline unsigned int AT91F_ADC_IsInterruptMasked(
  1810. AT91PS_ADC pADC, // \arg pointer to a ADC controller
  1811. unsigned int flag) // \arg flag to be tested
  1812. {
  1813. return (AT91F_ADC_GetInterruptMaskStatus(pADC) & flag);
  1814. }
  1815. //----------------------------------------------------------------------------
  1816. // \fn AT91F_ADC_IsStatusSet
  1817. // \brief Test if ADC Status is Set
  1818. //----------------------------------------------------------------------------
  1819. __inline unsigned int AT91F_ADC_IsStatusSet(
  1820. AT91PS_ADC pADC, // \arg pointer to a ADC controller
  1821. unsigned int flag) // \arg flag to be tested
  1822. {
  1823. return (AT91F_ADC_GetStatus(pADC) & flag);
  1824. }
  1825. //----------------------------------------------------------------------------
  1826. // \fn AT91F_ADC_CfgModeReg
  1827. // \brief Configure the Mode Register of the ADC controller
  1828. //----------------------------------------------------------------------------
  1829. __inline void AT91F_ADC_CfgModeReg (
  1830. AT91PS_ADC pADC, // pointer to a ADC controller
  1831. unsigned int mode) // mode register
  1832. {
  1833. // Write to the MR register
  1834. pADC->ADC_MR = mode;
  1835. }
  1836. //----------------------------------------------------------------------------
  1837. // \fn AT91F_ADC_GetModeReg
  1838. // \brief Return the Mode Register of the ADC controller value
  1839. //----------------------------------------------------------------------------
  1840. __inline unsigned int AT91F_ADC_GetModeReg (
  1841. AT91PS_ADC pADC // pointer to a ADC controller
  1842. )
  1843. {
  1844. return pADC->ADC_MR;
  1845. }
  1846. //----------------------------------------------------------------------------
  1847. // \fn AT91F_ADC_CfgTimings
  1848. // \brief Configure the different necessary timings of the ADC controller
  1849. //----------------------------------------------------------------------------
  1850. __inline void AT91F_ADC_CfgTimings (
  1851. AT91PS_ADC pADC, // pointer to a ADC controller
  1852. unsigned int mck_clock, // in MHz
  1853. unsigned int adc_clock, // in MHz
  1854. unsigned int startup_time, // in us
  1855. unsigned int sample_and_hold_time) // in ns
  1856. {
  1857. unsigned int prescal,startup,shtim;
  1858. prescal = mck_clock/(2*adc_clock) - 1;
  1859. startup = adc_clock*startup_time/8 - 1;
  1860. shtim = adc_clock*sample_and_hold_time/1000 - 1;
  1861. // Write to the MR register
  1862. pADC->ADC_MR = ( (prescal<<8) & AT91C_ADC_PRESCAL) | ( (startup<<16) & AT91C_ADC_STARTUP) | ( (shtim<<24) & AT91C_ADC_SHTIM);
  1863. }
  1864. //----------------------------------------------------------------------------
  1865. // \fn AT91F_ADC_EnableChannel
  1866. // \brief Return ADC Timer Register Value
  1867. //----------------------------------------------------------------------------
  1868. __inline void AT91F_ADC_EnableChannel (
  1869. AT91PS_ADC pADC, // pointer to a ADC controller
  1870. unsigned int channel) // mode register
  1871. {
  1872. // Write to the CHER register
  1873. pADC->ADC_CHER = channel;
  1874. }
  1875. //----------------------------------------------------------------------------
  1876. // \fn AT91F_ADC_DisableChannel
  1877. // \brief Return ADC Timer Register Value
  1878. //----------------------------------------------------------------------------
  1879. __inline void AT91F_ADC_DisableChannel (
  1880. AT91PS_ADC pADC, // pointer to a ADC controller
  1881. unsigned int channel) // mode register
  1882. {
  1883. // Write to the CHDR register
  1884. pADC->ADC_CHDR = channel;
  1885. }
  1886. //----------------------------------------------------------------------------
  1887. // \fn AT91F_ADC_GetChannelStatus
  1888. // \brief Return ADC Timer Register Value
  1889. //----------------------------------------------------------------------------
  1890. __inline unsigned int AT91F_ADC_GetChannelStatus (
  1891. AT91PS_ADC pADC // pointer to a ADC controller
  1892. )
  1893. {
  1894. return pADC->ADC_CHSR;
  1895. }
  1896. //----------------------------------------------------------------------------
  1897. // \fn AT91F_ADC_StartConversion
  1898. // \brief Software request for a analog to digital conversion
  1899. //----------------------------------------------------------------------------
  1900. __inline void AT91F_ADC_StartConversion (
  1901. AT91PS_ADC pADC // pointer to a ADC controller
  1902. )
  1903. {
  1904. pADC->ADC_CR = AT91C_ADC_START;
  1905. }
  1906. //----------------------------------------------------------------------------
  1907. // \fn AT91F_ADC_SoftReset
  1908. // \brief Software reset
  1909. //----------------------------------------------------------------------------
  1910. __inline void AT91F_ADC_SoftReset (
  1911. AT91PS_ADC pADC // pointer to a ADC controller
  1912. )
  1913. {
  1914. pADC->ADC_CR = AT91C_ADC_SWRST;
  1915. }
  1916. //----------------------------------------------------------------------------
  1917. // \fn AT91F_ADC_GetLastConvertedData
  1918. // \brief Return the Last Converted Data
  1919. //----------------------------------------------------------------------------
  1920. __inline unsigned int AT91F_ADC_GetLastConvertedData (
  1921. AT91PS_ADC pADC // pointer to a ADC controller
  1922. )
  1923. {
  1924. return pADC->ADC_LCDR;
  1925. }
  1926. //----------------------------------------------------------------------------
  1927. // \fn AT91F_ADC_GetConvertedDataCH0
  1928. // \brief Return the Channel 0 Converted Data
  1929. //----------------------------------------------------------------------------
  1930. __inline unsigned int AT91F_ADC_GetConvertedDataCH0 (
  1931. AT91PS_ADC pADC // pointer to a ADC controller
  1932. )
  1933. {
  1934. return pADC->ADC_CDR0;
  1935. }
  1936. //----------------------------------------------------------------------------
  1937. // \fn AT91F_ADC_GetConvertedDataCH1
  1938. // \brief Return the Channel 1 Converted Data
  1939. //----------------------------------------------------------------------------
  1940. __inline unsigned int AT91F_ADC_GetConvertedDataCH1 (
  1941. AT91PS_ADC pADC // pointer to a ADC controller
  1942. )
  1943. {
  1944. return pADC->ADC_CDR1;
  1945. }
  1946. //----------------------------------------------------------------------------
  1947. // \fn AT91F_ADC_GetConvertedDataCH2
  1948. // \brief Return the Channel 2 Converted Data
  1949. //----------------------------------------------------------------------------
  1950. __inline unsigned int AT91F_ADC_GetConvertedDataCH2 (
  1951. AT91PS_ADC pADC // pointer to a ADC controller
  1952. )
  1953. {
  1954. return pADC->ADC_CDR2;
  1955. }
  1956. //----------------------------------------------------------------------------
  1957. // \fn AT91F_ADC_GetConvertedDataCH3
  1958. // \brief Return the Channel 3 Converted Data
  1959. //----------------------------------------------------------------------------
  1960. __inline unsigned int AT91F_ADC_GetConvertedDataCH3 (
  1961. AT91PS_ADC pADC // pointer to a ADC controller
  1962. )
  1963. {
  1964. return pADC->ADC_CDR3;
  1965. }
  1966. //----------------------------------------------------------------------------
  1967. // \fn AT91F_ADC_GetConvertedDataCH4
  1968. // \brief Return the Channel 4 Converted Data
  1969. //----------------------------------------------------------------------------
  1970. __inline unsigned int AT91F_ADC_GetConvertedDataCH4 (
  1971. AT91PS_ADC pADC // pointer to a ADC controller
  1972. )
  1973. {
  1974. return pADC->ADC_CDR4;
  1975. }
  1976. //----------------------------------------------------------------------------
  1977. // \fn AT91F_ADC_GetConvertedDataCH5
  1978. // \brief Return the Channel 5 Converted Data
  1979. //----------------------------------------------------------------------------
  1980. __inline unsigned int AT91F_ADC_GetConvertedDataCH5 (
  1981. AT91PS_ADC pADC // pointer to a ADC controller
  1982. )
  1983. {
  1984. return pADC->ADC_CDR5;
  1985. }
  1986. //----------------------------------------------------------------------------
  1987. // \fn AT91F_ADC_GetConvertedDataCH6
  1988. // \brief Return the Channel 6 Converted Data
  1989. //----------------------------------------------------------------------------
  1990. __inline unsigned int AT91F_ADC_GetConvertedDataCH6 (
  1991. AT91PS_ADC pADC // pointer to a ADC controller
  1992. )
  1993. {
  1994. return pADC->ADC_CDR6;
  1995. }
  1996. //----------------------------------------------------------------------------
  1997. // \fn AT91F_ADC_GetConvertedDataCH7
  1998. // \brief Return the Channel 7 Converted Data
  1999. //----------------------------------------------------------------------------
  2000. __inline unsigned int AT91F_ADC_GetConvertedDataCH7 (
  2001. AT91PS_ADC pADC // pointer to a ADC controller
  2002. )
  2003. {
  2004. return pADC->ADC_CDR7;
  2005. }
  2006. //}}}
  2007. //{{{ SSC - Synchronous serial controller
  2008. /* *****************************************************************************
  2009. SOFTWARE API FOR SSC
  2010. ***************************************************************************** */
  2011. // Define the standard I2S mode configuration
  2012. // Configuration to set in the SSC Transmit Clock Mode Register
  2013. // Parameters : nb_bit_by_slot : 8, 16 or 32 bits
  2014. // nb_slot_by_frame : number of channels
  2015. #define AT91C_I2S_ASY_MASTER_TX_SETTING(nb_bit_by_slot, nb_slot_by_frame)( +\
  2016. AT91C_SSC_CKS_DIV +\
  2017. AT91C_SSC_CKO_CONTINOUS +\
  2018. AT91C_SSC_CKG_NONE +\
  2019. AT91C_SSC_START_FALL_RF +\
  2020. AT91C_SSC_STTOUT +\
  2021. ((1<<16) & AT91C_SSC_STTDLY) +\
  2022. ((((nb_bit_by_slot*nb_slot_by_frame)/2)-1) <<24))
  2023. // Configuration to set in the SSC Transmit Frame Mode Register
  2024. // Parameters : nb_bit_by_slot : 8, 16 or 32 bits
  2025. // nb_slot_by_frame : number of channels
  2026. #define AT91C_I2S_ASY_TX_FRAME_SETTING(nb_bit_by_slot, nb_slot_by_frame)( +\
  2027. (nb_bit_by_slot-1) +\
  2028. AT91C_SSC_MSBF +\
  2029. (((nb_slot_by_frame-1)<<8) & AT91C_SSC_DATNB) +\
  2030. (((nb_bit_by_slot-1)<<16) & AT91C_SSC_FSLEN) +\
  2031. AT91C_SSC_FSOS_NEGATIVE)
  2032. //----------------------------------------------------------------------------
  2033. // \fn AT91F_SSC_SetBaudrate
  2034. // \brief Set the baudrate according to the CPU clock
  2035. //----------------------------------------------------------------------------
  2036. __inline void AT91F_SSC_SetBaudrate (
  2037. AT91PS_SSC pSSC, // \arg pointer to a SSC controller
  2038. unsigned int mainClock, // \arg peripheral clock
  2039. unsigned int speed) // \arg SSC baudrate
  2040. {
  2041. unsigned int baud_value;
  2042. // Define the baud rate divisor register
  2043. if (speed == 0)
  2044. baud_value = 0;
  2045. else
  2046. {
  2047. baud_value = (unsigned int) (mainClock * 10)/(2*speed);
  2048. if ((baud_value % 10) >= 5)
  2049. baud_value = (baud_value / 10) + 1;
  2050. else
  2051. baud_value /= 10;
  2052. }
  2053. pSSC->SSC_CMR = baud_value;
  2054. }
  2055. //----------------------------------------------------------------------------
  2056. // \fn AT91F_SSC_Configure
  2057. // \brief Configure SSC
  2058. //----------------------------------------------------------------------------
  2059. __inline void AT91F_SSC_Configure (
  2060. AT91PS_SSC pSSC, // \arg pointer to a SSC controller
  2061. unsigned int syst_clock, // \arg System Clock Frequency
  2062. unsigned int baud_rate, // \arg Expected Baud Rate Frequency
  2063. unsigned int clock_rx, // \arg Receiver Clock Parameters
  2064. unsigned int mode_rx, // \arg mode Register to be programmed
  2065. unsigned int clock_tx, // \arg Transmitter Clock Parameters
  2066. unsigned int mode_tx) // \arg mode Register to be programmed
  2067. {
  2068. // Disable interrupts
  2069. pSSC->SSC_IDR = (unsigned int) -1;
  2070. // Reset receiver and transmitter
  2071. pSSC->SSC_CR = AT91C_SSC_SWRST | AT91C_SSC_RXDIS | AT91C_SSC_TXDIS ;
  2072. // Define the Clock Mode Register
  2073. AT91F_SSC_SetBaudrate(pSSC, syst_clock, baud_rate);
  2074. // Write the Receive Clock Mode Register
  2075. pSSC->SSC_RCMR = clock_rx;
  2076. // Write the Transmit Clock Mode Register
  2077. pSSC->SSC_TCMR = clock_tx;
  2078. // Write the Receive Frame Mode Register
  2079. pSSC->SSC_RFMR = mode_rx;
  2080. // Write the Transmit Frame Mode Register
  2081. pSSC->SSC_TFMR = mode_tx;
  2082. // Clear Transmit and Receive Counters
  2083. AT91F_PDC_Open((AT91PS_PDC) &(pSSC->SSC_RPR));
  2084. }
  2085. //----------------------------------------------------------------------------
  2086. // \fn AT91F_SSC_EnableRx
  2087. // \brief Enable receiving datas
  2088. //----------------------------------------------------------------------------
  2089. __inline void AT91F_SSC_EnableRx (
  2090. AT91PS_SSC pSSC) // \arg pointer to a SSC controller
  2091. {
  2092. // Enable receiver
  2093. pSSC->SSC_CR = AT91C_SSC_RXEN;
  2094. }
  2095. //----------------------------------------------------------------------------
  2096. // \fn AT91F_SSC_DisableRx
  2097. // \brief Disable receiving datas
  2098. //----------------------------------------------------------------------------
  2099. __inline void AT91F_SSC_DisableRx (
  2100. AT91PS_SSC pSSC) // \arg pointer to a SSC controller
  2101. {
  2102. // Disable receiver
  2103. pSSC->SSC_CR = AT91C_SSC_RXDIS;
  2104. }
  2105. //----------------------------------------------------------------------------
  2106. // \fn AT91F_SSC_EnableTx
  2107. // \brief Enable sending datas
  2108. //----------------------------------------------------------------------------
  2109. __inline void AT91F_SSC_EnableTx (
  2110. AT91PS_SSC pSSC) // \arg pointer to a SSC controller
  2111. {
  2112. // Enable transmitter
  2113. pSSC->SSC_CR = AT91C_SSC_TXEN;
  2114. }
  2115. //----------------------------------------------------------------------------
  2116. // \fn AT91F_SSC_DisableTx
  2117. // \brief Disable sending datas
  2118. //----------------------------------------------------------------------------
  2119. __inline void AT91F_SSC_DisableTx (
  2120. AT91PS_SSC pSSC) // \arg pointer to a SSC controller
  2121. {
  2122. // Disable transmitter
  2123. pSSC->SSC_CR = AT91C_SSC_TXDIS;
  2124. }
  2125. //----------------------------------------------------------------------------
  2126. // \fn AT91F_SSC_EnableIt
  2127. // \brief Enable SSC IT
  2128. //----------------------------------------------------------------------------
  2129. __inline void AT91F_SSC_EnableIt (
  2130. AT91PS_SSC pSSC, // \arg pointer to a SSC controller
  2131. unsigned int flag) // \arg IT to be enabled
  2132. {
  2133. // Write to the IER register
  2134. pSSC->SSC_IER = flag;
  2135. }
  2136. //----------------------------------------------------------------------------
  2137. // \fn AT91F_SSC_DisableIt
  2138. // \brief Disable SSC IT
  2139. //----------------------------------------------------------------------------
  2140. __inline void AT91F_SSC_DisableIt (
  2141. AT91PS_SSC pSSC, // \arg pointer to a SSC controller
  2142. unsigned int flag) // \arg IT to be disabled
  2143. {
  2144. // Write to the IDR register
  2145. pSSC->SSC_IDR = flag;
  2146. }
  2147. //----------------------------------------------------------------------------
  2148. // \fn AT91F_SSC_ReceiveFrame
  2149. // \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
  2150. //----------------------------------------------------------------------------
  2151. __inline unsigned int AT91F_SSC_ReceiveFrame (
  2152. AT91PS_SSC pSSC,
  2153. char *pBuffer,
  2154. unsigned int szBuffer,
  2155. char *pNextBuffer,
  2156. unsigned int szNextBuffer )
  2157. {
  2158. return AT91F_PDC_ReceiveFrame(
  2159. (AT91PS_PDC) &(pSSC->SSC_RPR),
  2160. pBuffer,
  2161. szBuffer,
  2162. pNextBuffer,
  2163. szNextBuffer);
  2164. }
  2165. //----------------------------------------------------------------------------
  2166. // \fn AT91F_SSC_SendFrame
  2167. // \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
  2168. //----------------------------------------------------------------------------
  2169. __inline unsigned int AT91F_SSC_SendFrame(
  2170. AT91PS_SSC pSSC,
  2171. char *pBuffer,
  2172. unsigned int szBuffer,
  2173. char *pNextBuffer,
  2174. unsigned int szNextBuffer )
  2175. {
  2176. return AT91F_PDC_SendFrame(
  2177. (AT91PS_PDC) &(pSSC->SSC_RPR),
  2178. pBuffer,
  2179. szBuffer,
  2180. pNextBuffer,
  2181. szNextBuffer);
  2182. }
  2183. //----------------------------------------------------------------------------
  2184. // \fn AT91F_SSC_GetInterruptMaskStatus
  2185. // \brief Return SSC Interrupt Mask Status
  2186. //----------------------------------------------------------------------------
  2187. __inline unsigned int AT91F_SSC_GetInterruptMaskStatus( // \return SSC Interrupt Mask Status
  2188. AT91PS_SSC pSsc) // \arg pointer to a SSC controller
  2189. {
  2190. return pSsc->SSC_IMR;
  2191. }
  2192. //----------------------------------------------------------------------------
  2193. // \fn AT91F_SSC_IsInterruptMasked
  2194. // \brief Test if SSC Interrupt is Masked
  2195. //----------------------------------------------------------------------------
  2196. __inline int AT91F_SSC_IsInterruptMasked(
  2197. AT91PS_SSC pSsc, // \arg pointer to a SSC controller
  2198. unsigned int flag) // \arg flag to be tested
  2199. {
  2200. return (AT91F_SSC_GetInterruptMaskStatus(pSsc) & flag);
  2201. }
  2202. //}}}
  2203. //{{{ USART - Universal synchronous asynchronous serial receiver transmitter
  2204. /* *****************************************************************************
  2205. SOFTWARE API FOR USART
  2206. ***************************************************************************** */
  2207. //----------------------------------------------------------------------------
  2208. // \fn AT91F_US_Baudrate
  2209. // \brief Calculate the baudrate
  2210. // Standard Asynchronous Mode : 8 bits , 1 stop , no parity
  2211. #define AT91C_US_ASYNC_MODE ( AT91C_US_USMODE_NORMAL + \
  2212. AT91C_US_NBSTOP_1_BIT + \
  2213. AT91C_US_PAR_NONE + \
  2214. AT91C_US_CHRL_8_BITS + \
  2215. AT91C_US_CLKS_CLOCK )
  2216. // Standard External Asynchronous Mode : 8 bits , 1 stop , no parity
  2217. #define AT91C_US_ASYNC_SCK_MODE ( AT91C_US_USMODE_NORMAL + \
  2218. AT91C_US_NBSTOP_1_BIT + \
  2219. AT91C_US_PAR_NONE + \
  2220. AT91C_US_CHRL_8_BITS + \
  2221. AT91C_US_CLKS_EXT )
  2222. // Standard Synchronous Mode : 8 bits , 1 stop , no parity
  2223. #define AT91C_US_SYNC_MODE ( AT91C_US_SYNC + \
  2224. AT91C_US_USMODE_NORMAL + \
  2225. AT91C_US_NBSTOP_1_BIT + \
  2226. AT91C_US_PAR_NONE + \
  2227. AT91C_US_CHRL_8_BITS + \
  2228. AT91C_US_CLKS_CLOCK )
  2229. // SCK used Label
  2230. #define AT91C_US_SCK_USED (AT91C_US_CKLO | AT91C_US_CLKS_EXT)
  2231. // Standard ISO T=0 Mode : 8 bits , 1 stop , parity
  2232. #define AT91C_US_ISO_READER_MODE ( AT91C_US_USMODE_ISO7816_0 + \
  2233. AT91C_US_CLKS_CLOCK +\
  2234. AT91C_US_NBSTOP_1_BIT + \
  2235. AT91C_US_PAR_EVEN + \
  2236. AT91C_US_CHRL_8_BITS + \
  2237. AT91C_US_CKLO +\
  2238. AT91C_US_OVER)
  2239. // Standard IRDA mode
  2240. #define AT91C_US_ASYNC_IRDA_MODE ( AT91C_US_USMODE_IRDA + \
  2241. AT91C_US_NBSTOP_1_BIT + \
  2242. AT91C_US_PAR_NONE + \
  2243. AT91C_US_CHRL_8_BITS + \
  2244. AT91C_US_CLKS_CLOCK )
  2245. //----------------------------------------------------------------------------
  2246. // \fn AT91F_US_Baudrate
  2247. // \brief Caluculate baud_value according to the main clock and the baud rate
  2248. //----------------------------------------------------------------------------
  2249. __inline unsigned int AT91F_US_Baudrate (
  2250. const unsigned int main_clock, // \arg peripheral clock
  2251. const unsigned int baud_rate) // \arg UART baudrate
  2252. {
  2253. unsigned int baud_value = ((main_clock*10)/(baud_rate * 16));
  2254. if ((baud_value % 10) >= 5)
  2255. baud_value = (baud_value / 10) + 1;
  2256. else
  2257. baud_value /= 10;
  2258. return baud_value;
  2259. }
  2260. //----------------------------------------------------------------------------
  2261. // \fn AT91F_US_SetBaudrate
  2262. // \brief Set the baudrate according to the CPU clock
  2263. //----------------------------------------------------------------------------
  2264. __inline void AT91F_US_SetBaudrate (
  2265. AT91PS_USART pUSART, // \arg pointer to a USART controller
  2266. unsigned int mainClock, // \arg peripheral clock
  2267. unsigned int speed) // \arg UART baudrate
  2268. {
  2269. // Define the baud rate divisor register
  2270. pUSART->US_BRGR = AT91F_US_Baudrate(mainClock, speed);
  2271. }
  2272. //----------------------------------------------------------------------------
  2273. // \fn AT91F_US_SetTimeguard
  2274. // \brief Set USART timeguard
  2275. //----------------------------------------------------------------------------
  2276. __inline void AT91F_US_SetTimeguard (
  2277. AT91PS_USART pUSART, // \arg pointer to a USART controller
  2278. unsigned int timeguard) // \arg timeguard value
  2279. {
  2280. // Write the Timeguard Register
  2281. pUSART->US_TTGR = timeguard ;
  2282. }
  2283. //----------------------------------------------------------------------------
  2284. // \fn AT91F_US_EnableIt
  2285. // \brief Enable USART IT
  2286. //----------------------------------------------------------------------------
  2287. __inline void AT91F_US_EnableIt (
  2288. AT91PS_USART pUSART, // \arg pointer to a USART controller
  2289. unsigned int flag) // \arg IT to be enabled
  2290. {
  2291. // Write to the IER register
  2292. pUSART->US_IER = flag;
  2293. }
  2294. //----------------------------------------------------------------------------
  2295. // \fn AT91F_US_DisableIt
  2296. // \brief Disable USART IT
  2297. //----------------------------------------------------------------------------
  2298. __inline void AT91F_US_DisableIt (
  2299. AT91PS_USART pUSART, // \arg pointer to a USART controller
  2300. unsigned int flag) // \arg IT to be disabled
  2301. {
  2302. // Write to the IER register
  2303. pUSART->US_IDR = flag;
  2304. }
  2305. //----------------------------------------------------------------------------
  2306. // \fn AT91F_US_Configure
  2307. // \brief Configure USART
  2308. //----------------------------------------------------------------------------
  2309. __inline void AT91F_US_Configure (
  2310. AT91PS_USART pUSART, // \arg pointer to a USART controller
  2311. unsigned int mainClock, // \arg peripheral clock
  2312. unsigned int mode , // \arg mode Register to be programmed
  2313. unsigned int baudRate , // \arg baudrate to be programmed
  2314. unsigned int timeguard ) // \arg timeguard to be programmed
  2315. {
  2316. // Disable interrupts
  2317. pUSART->US_IDR = (unsigned int) -1;
  2318. // Reset receiver and transmitter
  2319. pUSART->US_CR = AT91C_US_RSTRX | AT91C_US_RSTTX | AT91C_US_RXDIS | AT91C_US_TXDIS ;
  2320. // Define the baud rate divisor register
  2321. AT91F_US_SetBaudrate(pUSART, mainClock, baudRate);
  2322. // Write the Timeguard Register
  2323. AT91F_US_SetTimeguard(pUSART, timeguard);
  2324. // Clear Transmit and Receive Counters
  2325. AT91F_PDC_Open((AT91PS_PDC) &(pUSART->US_RPR));
  2326. // Define the USART mode
  2327. pUSART->US_MR = mode ;
  2328. }
  2329. //----------------------------------------------------------------------------
  2330. // \fn AT91F_US_EnableRx
  2331. // \brief Enable receiving characters
  2332. //----------------------------------------------------------------------------
  2333. __inline void AT91F_US_EnableRx (
  2334. AT91PS_USART pUSART) // \arg pointer to a USART controller
  2335. {
  2336. // Enable receiver
  2337. pUSART->US_CR = AT91C_US_RXEN;
  2338. }
  2339. //----------------------------------------------------------------------------
  2340. // \fn AT91F_US_EnableTx
  2341. // \brief Enable sending characters
  2342. //----------------------------------------------------------------------------
  2343. __inline void AT91F_US_EnableTx (
  2344. AT91PS_USART pUSART) // \arg pointer to a USART controller
  2345. {
  2346. // Enable transmitter
  2347. pUSART->US_CR = AT91C_US_TXEN;
  2348. }
  2349. //----------------------------------------------------------------------------
  2350. // \fn AT91F_US_ResetRx
  2351. // \brief Reset Receiver and re-enable it
  2352. //----------------------------------------------------------------------------
  2353. __inline void AT91F_US_ResetRx (
  2354. AT91PS_USART pUSART) // \arg pointer to a USART controller
  2355. {
  2356. // Reset receiver
  2357. pUSART->US_CR = AT91C_US_RSTRX;
  2358. // Re-Enable receiver
  2359. pUSART->US_CR = AT91C_US_RXEN;
  2360. }
  2361. //----------------------------------------------------------------------------
  2362. // \fn AT91F_US_ResetTx
  2363. // \brief Reset Transmitter and re-enable it
  2364. //----------------------------------------------------------------------------
  2365. __inline void AT91F_US_ResetTx (
  2366. AT91PS_USART pUSART) // \arg pointer to a USART controller
  2367. {
  2368. // Reset transmitter
  2369. pUSART->US_CR = AT91C_US_RSTTX;
  2370. // Enable transmitter
  2371. pUSART->US_CR = AT91C_US_TXEN;
  2372. }
  2373. //----------------------------------------------------------------------------
  2374. // \fn AT91F_US_DisableRx
  2375. // \brief Disable Receiver
  2376. //----------------------------------------------------------------------------
  2377. __inline void AT91F_US_DisableRx (
  2378. AT91PS_USART pUSART) // \arg pointer to a USART controller
  2379. {
  2380. // Disable receiver
  2381. pUSART->US_CR = AT91C_US_RXDIS;
  2382. }
  2383. //----------------------------------------------------------------------------
  2384. // \fn AT91F_US_DisableTx
  2385. // \brief Disable Transmitter
  2386. //----------------------------------------------------------------------------
  2387. __inline void AT91F_US_DisableTx (
  2388. AT91PS_USART pUSART) // \arg pointer to a USART controller
  2389. {
  2390. // Disable transmitter
  2391. pUSART->US_CR = AT91C_US_TXDIS;
  2392. }
  2393. //----------------------------------------------------------------------------
  2394. // \fn AT91F_US_Close
  2395. // \brief Close USART: disable IT disable receiver and transmitter, close PDC
  2396. //----------------------------------------------------------------------------
  2397. __inline void AT91F_US_Close (
  2398. AT91PS_USART pUSART) // \arg pointer to a USART controller
  2399. {
  2400. // Reset the baud rate divisor register
  2401. pUSART->US_BRGR = 0 ;
  2402. // Reset the USART mode
  2403. pUSART->US_MR = 0 ;
  2404. // Reset the Timeguard Register
  2405. pUSART->US_TTGR = 0;
  2406. // Disable all interrupts
  2407. pUSART->US_IDR = 0xFFFFFFFF ;
  2408. // Abort the Peripheral Data Transfers
  2409. AT91F_PDC_Close((AT91PS_PDC) &(pUSART->US_RPR));
  2410. // Disable receiver and transmitter and stop any activity immediately
  2411. pUSART->US_CR = AT91C_US_TXDIS | AT91C_US_RXDIS | AT91C_US_RSTTX | AT91C_US_RSTRX ;
  2412. }
  2413. //----------------------------------------------------------------------------
  2414. // \fn AT91F_US_TxReady
  2415. // \brief Return 1 if a character can be written in US_THR
  2416. //----------------------------------------------------------------------------
  2417. __inline unsigned int AT91F_US_TxReady (
  2418. AT91PS_USART pUSART ) // \arg pointer to a USART controller
  2419. {
  2420. return (pUSART->US_CSR & AT91C_US_TXRDY);
  2421. }
  2422. //----------------------------------------------------------------------------
  2423. // \fn AT91F_US_RxReady
  2424. // \brief Return 1 if a character can be read in US_RHR
  2425. //----------------------------------------------------------------------------
  2426. __inline unsigned int AT91F_US_RxReady (
  2427. AT91PS_USART pUSART ) // \arg pointer to a USART controller
  2428. {
  2429. return (pUSART->US_CSR & AT91C_US_RXRDY);
  2430. }
  2431. //----------------------------------------------------------------------------
  2432. // \fn AT91F_US_Error
  2433. // \brief Return the error flag
  2434. //----------------------------------------------------------------------------
  2435. __inline unsigned int AT91F_US_Error (
  2436. AT91PS_USART pUSART ) // \arg pointer to a USART controller
  2437. {
  2438. return (pUSART->US_CSR &
  2439. (AT91C_US_OVRE | // Overrun error
  2440. AT91C_US_FRAME | // Framing error
  2441. AT91C_US_PARE)); // Parity error
  2442. }
  2443. //----------------------------------------------------------------------------
  2444. // \fn AT91F_US_PutChar
  2445. // \brief Send a character,does not check if ready to send
  2446. //----------------------------------------------------------------------------
  2447. __inline void AT91F_US_PutChar (
  2448. AT91PS_USART pUSART,
  2449. int character )
  2450. {
  2451. pUSART->US_THR = (character & 0x1FF);
  2452. }
  2453. //----------------------------------------------------------------------------
  2454. // \fn AT91F_US_GetChar
  2455. // \brief Receive a character,does not check if a character is available
  2456. //----------------------------------------------------------------------------
  2457. __inline int AT91F_US_GetChar (
  2458. const AT91PS_USART pUSART)
  2459. {
  2460. return((pUSART->US_RHR) & 0x1FF);
  2461. }
  2462. //----------------------------------------------------------------------------
  2463. // \fn AT91F_US_SendFrame
  2464. // \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
  2465. //----------------------------------------------------------------------------
  2466. __inline unsigned int AT91F_US_SendFrame(
  2467. AT91PS_USART pUSART,
  2468. char *pBuffer,
  2469. unsigned int szBuffer,
  2470. char *pNextBuffer,
  2471. unsigned int szNextBuffer )
  2472. {
  2473. return AT91F_PDC_SendFrame(
  2474. (AT91PS_PDC) &(pUSART->US_RPR),
  2475. pBuffer,
  2476. szBuffer,
  2477. pNextBuffer,
  2478. szNextBuffer);
  2479. }
  2480. //----------------------------------------------------------------------------
  2481. // \fn AT91F_US_ReceiveFrame
  2482. // \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
  2483. //----------------------------------------------------------------------------
  2484. __inline unsigned int AT91F_US_ReceiveFrame (
  2485. AT91PS_USART pUSART,
  2486. char *pBuffer,
  2487. unsigned int szBuffer,
  2488. char *pNextBuffer,
  2489. unsigned int szNextBuffer )
  2490. {
  2491. return AT91F_PDC_ReceiveFrame(
  2492. (AT91PS_PDC) &(pUSART->US_RPR),
  2493. pBuffer,
  2494. szBuffer,
  2495. pNextBuffer,
  2496. szNextBuffer);
  2497. }
  2498. //----------------------------------------------------------------------------
  2499. // \fn AT91F_US_SetIrdaFilter
  2500. // \brief Set the value of IrDa filter tregister
  2501. //----------------------------------------------------------------------------
  2502. __inline void AT91F_US_SetIrdaFilter (
  2503. AT91PS_USART pUSART,
  2504. unsigned char value
  2505. )
  2506. {
  2507. pUSART->US_IF = value;
  2508. }
  2509. //}}}
  2510. //{{{ TWI - Two wire interface
  2511. /* *****************************************************************************
  2512. SOFTWARE API FOR TWI
  2513. ***************************************************************************** */
  2514. //----------------------------------------------------------------------------
  2515. // \fn AT91F_TWI_EnableIt
  2516. // \brief Enable TWI IT
  2517. //----------------------------------------------------------------------------
  2518. __inline void AT91F_TWI_EnableIt (
  2519. AT91PS_TWI pTWI, // \arg pointer to a TWI controller
  2520. unsigned int flag) // \arg IT to be enabled
  2521. {
  2522. // Write to the IER register
  2523. pTWI->TWI_IER = flag;
  2524. }
  2525. //----------------------------------------------------------------------------
  2526. // \fn AT91F_TWI_DisableIt
  2527. // \brief Disable TWI IT
  2528. //----------------------------------------------------------------------------
  2529. __inline void AT91F_TWI_DisableIt (
  2530. AT91PS_TWI pTWI, // \arg pointer to a TWI controller
  2531. unsigned int flag) // \arg IT to be disabled
  2532. {
  2533. // Write to the IDR register
  2534. pTWI->TWI_IDR = flag;
  2535. }
  2536. //----------------------------------------------------------------------------
  2537. // \fn AT91F_TWI_Configure
  2538. // \brief Configure TWI in master mode
  2539. //----------------------------------------------------------------------------
  2540. __inline void AT91F_TWI_Configure ( AT91PS_TWI pTWI ) // \arg pointer to a TWI controller
  2541. {
  2542. // Disable interrupts
  2543. pTWI->TWI_IDR = (unsigned int) -1;
  2544. // Reset peripheral
  2545. pTWI->TWI_CR = AT91C_TWI_SWRST;
  2546. // Set Master mode
  2547. pTWI->TWI_CR = AT91C_TWI_MSEN;
  2548. }
  2549. //----------------------------------------------------------------------------
  2550. // \fn AT91F_TWI_GetInterruptMaskStatus
  2551. // \brief Return TWI Interrupt Mask Status
  2552. //----------------------------------------------------------------------------
  2553. __inline unsigned int AT91F_TWI_GetInterruptMaskStatus( // \return TWI Interrupt Mask Status
  2554. AT91PS_TWI pTwi) // \arg pointer to a TWI controller
  2555. {
  2556. return pTwi->TWI_IMR;
  2557. }
  2558. //----------------------------------------------------------------------------
  2559. // \fn AT91F_TWI_IsInterruptMasked
  2560. // \brief Test if TWI Interrupt is Masked
  2561. //----------------------------------------------------------------------------
  2562. __inline int AT91F_TWI_IsInterruptMasked(
  2563. AT91PS_TWI pTwi, // \arg pointer to a TWI controller
  2564. unsigned int flag) // \arg flag to be tested
  2565. {
  2566. return (AT91F_TWI_GetInterruptMaskStatus(pTwi) & flag);
  2567. }
  2568. //}}}
  2569. //{{{ TC - Timer controller
  2570. /* *****************************************************************************
  2571. SOFTWARE API FOR TC
  2572. ***************************************************************************** */
  2573. //----------------------------------------------------------------------------
  2574. // \fn AT91F_TC_InterruptEnable
  2575. // \brief Enable TC Interrupt
  2576. //----------------------------------------------------------------------------
  2577. __inline void AT91F_TC_InterruptEnable(
  2578. AT91PS_TC pTc, // \arg pointer to a TC controller
  2579. unsigned int flag) // \arg TC interrupt to be enabled
  2580. {
  2581. pTc->TC_IER = flag;
  2582. }
  2583. //----------------------------------------------------------------------------
  2584. // \fn AT91F_TC_InterruptDisable
  2585. // \brief Disable TC Interrupt
  2586. //----------------------------------------------------------------------------
  2587. __inline void AT91F_TC_InterruptDisable(
  2588. AT91PS_TC pTc, // \arg pointer to a TC controller
  2589. unsigned int flag) // \arg TC interrupt to be disabled
  2590. {
  2591. pTc->TC_IDR = flag;
  2592. }
  2593. //----------------------------------------------------------------------------
  2594. // \fn AT91F_TC_GetInterruptMaskStatus
  2595. // \brief Return TC Interrupt Mask Status
  2596. //----------------------------------------------------------------------------
  2597. __inline unsigned int AT91F_TC_GetInterruptMaskStatus( // \return TC Interrupt Mask Status
  2598. AT91PS_TC pTc) // \arg pointer to a TC controller
  2599. {
  2600. return pTc->TC_IMR;
  2601. }
  2602. //----------------------------------------------------------------------------
  2603. // \fn AT91F_TC_IsInterruptMasked
  2604. // \brief Test if TC Interrupt is Masked
  2605. //----------------------------------------------------------------------------
  2606. __inline int AT91F_TC_IsInterruptMasked(
  2607. AT91PS_TC pTc, // \arg pointer to a TC controller
  2608. unsigned int flag) // \arg flag to be tested
  2609. {
  2610. return (AT91F_TC_GetInterruptMaskStatus(pTc) & flag);
  2611. }
  2612. //}}}
  2613. //{{{ PWM - Pulse witdh modulator
  2614. /* *****************************************************************************
  2615. SOFTWARE API FOR PWMC
  2616. ***************************************************************************** */
  2617. //----------------------------------------------------------------------------
  2618. // \fn AT91F_PWM_GetStatus
  2619. // \brief Return PWM Interrupt Status
  2620. //----------------------------------------------------------------------------
  2621. __inline unsigned int AT91F_PWMC_GetStatus( // \return PWM Interrupt Status
  2622. AT91PS_PWMC pPWM) // pointer to a PWM controller
  2623. {
  2624. return pPWM->PWMC_SR;
  2625. }
  2626. //----------------------------------------------------------------------------
  2627. // \fn AT91F_PWM_InterruptEnable
  2628. // \brief Enable PWM Interrupt
  2629. //----------------------------------------------------------------------------
  2630. __inline void AT91F_PWMC_InterruptEnable(
  2631. AT91PS_PWMC pPwm, // \arg pointer to a PWM controller
  2632. unsigned int flag) // \arg PWM interrupt to be enabled
  2633. {
  2634. pPwm->PWMC_IER = flag;
  2635. }
  2636. //----------------------------------------------------------------------------
  2637. // \fn AT91F_PWM_InterruptDisable
  2638. // \brief Disable PWM Interrupt
  2639. //----------------------------------------------------------------------------
  2640. __inline void AT91F_PWMC_InterruptDisable(
  2641. AT91PS_PWMC pPwm, // \arg pointer to a PWM controller
  2642. unsigned int flag) // \arg PWM interrupt to be disabled
  2643. {
  2644. pPwm->PWMC_IDR = flag;
  2645. }
  2646. //----------------------------------------------------------------------------
  2647. // \fn AT91F_PWM_GetInterruptMaskStatus
  2648. // \brief Return PWM Interrupt Mask Status
  2649. //----------------------------------------------------------------------------
  2650. __inline unsigned int AT91F_PWMC_GetInterruptMaskStatus( // \return PWM Interrupt Mask Status
  2651. AT91PS_PWMC pPwm) // \arg pointer to a PWM controller
  2652. {
  2653. return pPwm->PWMC_IMR;
  2654. }
  2655. //----------------------------------------------------------------------------
  2656. // \fn AT91F_PWM_IsInterruptMasked
  2657. // \brief Test if PWM Interrupt is Masked
  2658. //----------------------------------------------------------------------------
  2659. __inline unsigned int AT91F_PWMC_IsInterruptMasked(
  2660. AT91PS_PWMC pPWM, // \arg pointer to a PWM controller
  2661. unsigned int flag) // \arg flag to be tested
  2662. {
  2663. return (AT91F_PWMC_GetInterruptMaskStatus(pPWM) & flag);
  2664. }
  2665. //----------------------------------------------------------------------------
  2666. // \fn AT91F_PWM_IsStatusSet
  2667. // \brief Test if PWM Interrupt is Set
  2668. //----------------------------------------------------------------------------
  2669. __inline unsigned int AT91F_PWMC_IsStatusSet(
  2670. AT91PS_PWMC pPWM, // \arg pointer to a PWM controller
  2671. unsigned int flag) // \arg flag to be tested
  2672. {
  2673. return (AT91F_PWMC_GetStatus(pPWM) & flag);
  2674. }
  2675. //----------------------------------------------------------------------------
  2676. // \fn AT91F_PWM_CfgChannel
  2677. // \brief Test if PWM Interrupt is Set
  2678. //----------------------------------------------------------------------------
  2679. __inline void AT91F_PWMC_CfgChannel(
  2680. AT91PS_PWMC pPWM, // \arg pointer to a PWM controller
  2681. unsigned int channelId, // \arg PWM channel ID
  2682. unsigned int mode, // \arg PWM mode
  2683. unsigned int period, // \arg PWM period
  2684. unsigned int duty) // \arg PWM duty cycle
  2685. {
  2686. pPWM->PWMC_CH[channelId].PWMC_CMR = mode;
  2687. pPWM->PWMC_CH[channelId].PWMC_CDTYR = duty;
  2688. pPWM->PWMC_CH[channelId].PWMC_CPRDR = period;
  2689. }
  2690. //----------------------------------------------------------------------------
  2691. // \fn AT91F_PWM_StartChannel
  2692. // \brief Enable channel
  2693. //----------------------------------------------------------------------------
  2694. __inline void AT91F_PWMC_StartChannel(
  2695. AT91PS_PWMC pPWM, // \arg pointer to a PWM controller
  2696. unsigned int flag) // \arg Channels IDs to be enabled
  2697. {
  2698. pPWM->PWMC_ENA = flag;
  2699. }
  2700. //----------------------------------------------------------------------------
  2701. // \fn AT91F_PWM_StopChannel
  2702. // \brief Disable channel
  2703. //----------------------------------------------------------------------------
  2704. __inline void AT91F_PWMC_StopChannel(
  2705. AT91PS_PWMC pPWM, // \arg pointer to a PWM controller
  2706. unsigned int flag) // \arg Channels IDs to be enabled
  2707. {
  2708. pPWM->PWMC_DIS = flag;
  2709. }
  2710. //----------------------------------------------------------------------------
  2711. // \fn AT91F_PWM_UpdateChannel
  2712. // \brief Update Period or Duty Cycle
  2713. //----------------------------------------------------------------------------
  2714. __inline void AT91F_PWMC_UpdateChannel(
  2715. AT91PS_PWMC pPWM, // \arg pointer to a PWM controller
  2716. unsigned int channelId, // \arg PWM channel ID
  2717. unsigned int update) // \arg Channels IDs to be enabled
  2718. {
  2719. pPWM->PWMC_CH[channelId].PWMC_CUPDR = update;
  2720. }
  2721. //}}}
  2722. //{{{ UDP - USB controller
  2723. /* *****************************************************************************
  2724. SOFTWARE API FOR UDP
  2725. ***************************************************************************** */
  2726. //----------------------------------------------------------------------------
  2727. // \fn AT91F_UDP_EnableIt
  2728. // \brief Enable UDP IT
  2729. //----------------------------------------------------------------------------
  2730. __inline void AT91F_UDP_EnableIt (
  2731. AT91PS_UDP pUDP, // \arg pointer to a UDP controller
  2732. unsigned int flag) // \arg IT to be enabled
  2733. {
  2734. // Write to the IER register
  2735. pUDP->UDP_IER = flag;
  2736. }
  2737. //----------------------------------------------------------------------------
  2738. // \fn AT91F_UDP_DisableIt
  2739. // \brief Disable UDP IT
  2740. //----------------------------------------------------------------------------
  2741. __inline void AT91F_UDP_DisableIt (
  2742. AT91PS_UDP pUDP, // \arg pointer to a UDP controller
  2743. unsigned int flag) // \arg IT to be disabled
  2744. {
  2745. // Write to the IDR register
  2746. pUDP->UDP_IDR = flag;
  2747. }
  2748. //----------------------------------------------------------------------------
  2749. // \fn AT91F_UDP_SetAddress
  2750. // \brief Set UDP functional address
  2751. //----------------------------------------------------------------------------
  2752. __inline void AT91F_UDP_SetAddress (
  2753. AT91PS_UDP pUDP, // \arg pointer to a UDP controller
  2754. unsigned char address) // \arg new UDP address
  2755. {
  2756. pUDP->UDP_FADDR = (AT91C_UDP_FEN | address);
  2757. }
  2758. //----------------------------------------------------------------------------
  2759. // \fn AT91F_UDP_EnableEp
  2760. // \brief Enable Endpoint
  2761. //----------------------------------------------------------------------------
  2762. __inline void AT91F_UDP_EnableEp (
  2763. AT91PS_UDP pUDP, // \arg pointer to a UDP controller
  2764. unsigned char endpoint) // \arg endpoint number
  2765. {
  2766. pUDP->UDP_CSR[endpoint] |= AT91C_UDP_EPEDS;
  2767. }
  2768. //----------------------------------------------------------------------------
  2769. // \fn AT91F_UDP_DisableEp
  2770. // \brief Enable Endpoint
  2771. //----------------------------------------------------------------------------
  2772. __inline void AT91F_UDP_DisableEp (
  2773. AT91PS_UDP pUDP, // \arg pointer to a UDP controller
  2774. unsigned char endpoint) // \arg endpoint number
  2775. {
  2776. pUDP->UDP_CSR[endpoint] &= ~AT91C_UDP_EPEDS;
  2777. }
  2778. //----------------------------------------------------------------------------
  2779. // \fn AT91F_UDP_SetState
  2780. // \brief Set UDP Device state
  2781. //----------------------------------------------------------------------------
  2782. __inline void AT91F_UDP_SetState (
  2783. AT91PS_UDP pUDP, // \arg pointer to a UDP controller
  2784. unsigned int flag) // \arg new UDP address
  2785. {
  2786. pUDP->UDP_GLBSTATE &= ~(AT91C_UDP_FADDEN | AT91C_UDP_CONFG);
  2787. pUDP->UDP_GLBSTATE |= flag;
  2788. }
  2789. //----------------------------------------------------------------------------
  2790. // \fn AT91F_UDP_GetState
  2791. // \brief return UDP Device state
  2792. //----------------------------------------------------------------------------
  2793. __inline unsigned int AT91F_UDP_GetState ( // \return the UDP device state
  2794. AT91PS_UDP pUDP) // \arg pointer to a UDP controller
  2795. {
  2796. return (pUDP->UDP_GLBSTATE & (AT91C_UDP_FADDEN | AT91C_UDP_CONFG));
  2797. }
  2798. //----------------------------------------------------------------------------
  2799. // \fn AT91F_UDP_ResetEp
  2800. // \brief Reset UDP endpoint
  2801. //----------------------------------------------------------------------------
  2802. __inline void AT91F_UDP_ResetEp ( // \return the UDP device state
  2803. AT91PS_UDP pUDP, // \arg pointer to a UDP controller
  2804. unsigned int flag) // \arg Endpoints to be reset
  2805. {
  2806. pUDP->UDP_RSTEP = flag;
  2807. pUDP->UDP_RSTEP = 0;
  2808. }
  2809. //----------------------------------------------------------------------------
  2810. // \fn AT91F_UDP_EpStall
  2811. // \brief Endpoint will STALL requests
  2812. //----------------------------------------------------------------------------
  2813. __inline void AT91F_UDP_EpStall(
  2814. AT91PS_UDP pUDP, // \arg pointer to a UDP controller
  2815. unsigned char endpoint) // \arg endpoint number
  2816. {
  2817. pUDP->UDP_CSR[endpoint] |= AT91C_UDP_FORCESTALL;
  2818. }
  2819. //----------------------------------------------------------------------------
  2820. // \fn AT91F_UDP_EpWrite
  2821. // \brief Write value in the DPR
  2822. //----------------------------------------------------------------------------
  2823. __inline void AT91F_UDP_EpWrite(
  2824. AT91PS_UDP pUDP, // \arg pointer to a UDP controller
  2825. unsigned char endpoint, // \arg endpoint number
  2826. unsigned char value) // \arg value to be written in the DPR
  2827. {
  2828. pUDP->UDP_FDR[endpoint] = value;
  2829. }
  2830. //----------------------------------------------------------------------------
  2831. // \fn AT91F_UDP_EpRead
  2832. // \brief Return value from the DPR
  2833. //----------------------------------------------------------------------------
  2834. __inline unsigned int AT91F_UDP_EpRead(
  2835. AT91PS_UDP pUDP, // \arg pointer to a UDP controller
  2836. unsigned char endpoint) // \arg endpoint number
  2837. {
  2838. return pUDP->UDP_FDR[endpoint];
  2839. }
  2840. //----------------------------------------------------------------------------
  2841. // \fn AT91F_UDP_EpEndOfWr
  2842. // \brief Notify the UDP that values in DPR are ready to be sent
  2843. //----------------------------------------------------------------------------
  2844. __inline void AT91F_UDP_EpEndOfWr(
  2845. AT91PS_UDP pUDP, // \arg pointer to a UDP controller
  2846. unsigned char endpoint) // \arg endpoint number
  2847. {
  2848. pUDP->UDP_CSR[endpoint] |= AT91C_UDP_TXPKTRDY;
  2849. }
  2850. //----------------------------------------------------------------------------
  2851. // \fn AT91F_UDP_EpClear
  2852. // \brief Clear flag in the endpoint CSR register
  2853. //----------------------------------------------------------------------------
  2854. __inline void AT91F_UDP_EpClear(
  2855. AT91PS_UDP pUDP, // \arg pointer to a UDP controller
  2856. unsigned char endpoint, // \arg endpoint number
  2857. unsigned int flag) // \arg flag to be cleared
  2858. {
  2859. pUDP->UDP_CSR[endpoint] &= ~(flag);
  2860. }
  2861. //----------------------------------------------------------------------------
  2862. // \fn AT91F_UDP_EpSet
  2863. // \brief Set flag in the endpoint CSR register
  2864. //----------------------------------------------------------------------------
  2865. __inline void AT91F_UDP_EpSet(
  2866. AT91PS_UDP pUDP, // \arg pointer to a UDP controller
  2867. unsigned char endpoint, // \arg endpoint number
  2868. unsigned int flag) // \arg flag to be cleared
  2869. {
  2870. pUDP->UDP_CSR[endpoint] |= flag;
  2871. }
  2872. //----------------------------------------------------------------------------
  2873. // \fn AT91F_UDP_EpStatus
  2874. // \brief Return the endpoint CSR register
  2875. //----------------------------------------------------------------------------
  2876. __inline unsigned int AT91F_UDP_EpStatus(
  2877. AT91PS_UDP pUDP, // \arg pointer to a UDP controller
  2878. unsigned char endpoint) // \arg endpoint number
  2879. {
  2880. return pUDP->UDP_CSR[endpoint];
  2881. }
  2882. //----------------------------------------------------------------------------
  2883. // \fn AT91F_UDP_GetInterruptMaskStatus
  2884. // \brief Return UDP Interrupt Mask Status
  2885. //----------------------------------------------------------------------------
  2886. __inline unsigned int AT91F_UDP_GetInterruptMaskStatus(
  2887. AT91PS_UDP pUdp) // \arg pointer to a UDP controller
  2888. {
  2889. return pUdp->UDP_IMR;
  2890. }
  2891. //----------------------------------------------------------------------------
  2892. // \fn AT91F_UDP_IsInterruptMasked
  2893. // \brief Test if UDP Interrupt is Masked
  2894. //----------------------------------------------------------------------------
  2895. __inline int AT91F_UDP_IsInterruptMasked(
  2896. AT91PS_UDP pUdp, // \arg pointer to a UDP controller
  2897. unsigned int flag) // \arg flag to be tested
  2898. {
  2899. return (AT91F_UDP_GetInterruptMaskStatus(pUdp) & flag);
  2900. }
  2901. // ----------------------------------------------------------------------------
  2902. // \fn AT91F_UDP_InterruptStatusRegister
  2903. // \brief Return the Interrupt Status Register
  2904. // ----------------------------------------------------------------------------
  2905. __inline unsigned int AT91F_UDP_InterruptStatusRegister(
  2906. AT91PS_UDP pUDP ) // \arg pointer to a UDP controller
  2907. {
  2908. return pUDP->UDP_ISR;
  2909. }
  2910. // ----------------------------------------------------------------------------
  2911. // \fn AT91F_UDP_InterruptClearRegister
  2912. // \brief Clear Interrupt Register
  2913. // ----------------------------------------------------------------------------
  2914. __inline void AT91F_UDP_InterruptClearRegister (
  2915. AT91PS_UDP pUDP, // \arg pointer to UDP controller
  2916. unsigned int flag) // \arg IT to be cleat
  2917. {
  2918. pUDP->UDP_ICR = flag;
  2919. }
  2920. // ----------------------------------------------------------------------------
  2921. // \fn AT91F_UDP_EnableTransceiver
  2922. // \brief Enable transceiver
  2923. // ----------------------------------------------------------------------------
  2924. __inline void AT91F_UDP_EnableTransceiver(
  2925. AT91PS_UDP pUDP ) // \arg pointer to a UDP controller
  2926. {
  2927. pUDP->UDP_TXVC &= ~AT91C_UDP_TXVDIS;
  2928. }
  2929. // ----------------------------------------------------------------------------
  2930. // \fn AT91F_UDP_DisableTransceiver
  2931. // \brief Disable transceiver
  2932. // ----------------------------------------------------------------------------
  2933. __inline void AT91F_UDP_DisableTransceiver(
  2934. AT91PS_UDP pUDP ) // \arg pointer to a UDP controller
  2935. {
  2936. pUDP->UDP_TXVC = AT91C_UDP_TXVDIS;
  2937. }
  2938. //}}}
  2939. //{{{ Peripheral Clock enable and pin enable
  2940. //----------------------------------------------------------------------------
  2941. // \fn AT91F_DBGU_CfgPMC
  2942. // \brief Enable Peripheral clock in PMC for DBGU
  2943. //----------------------------------------------------------------------------
  2944. __inline void AT91F_DBGU_CfgPMC (void)
  2945. {
  2946. AT91F_PMC_EnablePeriphClock(
  2947. AT91C_BASE_PMC, // PIO controller base address
  2948. ((unsigned int) 1 << AT91C_ID_SYS));
  2949. }
  2950. //----------------------------------------------------------------------------
  2951. // \fn AT91F_DBGU_CfgPIO
  2952. // \brief Configure PIO controllers to drive DBGU signals
  2953. //----------------------------------------------------------------------------
  2954. __inline void AT91F_DBGU_CfgPIO (void)
  2955. {
  2956. // Configure PIO controllers to periph mode
  2957. AT91F_PIO_CfgPeriph(
  2958. AT91C_BASE_PIOA, // PIO controller base address
  2959. ((unsigned int) AT91C_PA9_DRXD ) |
  2960. ((unsigned int) AT91C_PA10_DTXD ), // Peripheral A
  2961. 0); // Peripheral B
  2962. }
  2963. //----------------------------------------------------------------------------
  2964. // \fn AT91F_PMC_CfgPMC
  2965. // \brief Enable Peripheral clock in PMC for PMC
  2966. //----------------------------------------------------------------------------
  2967. __inline void AT91F_PMC_CfgPMC (void)
  2968. {
  2969. AT91F_PMC_EnablePeriphClock(
  2970. AT91C_BASE_PMC, // PIO controller base address
  2971. ((unsigned int) 1 << AT91C_ID_SYS));
  2972. }
  2973. //----------------------------------------------------------------------------
  2974. // \fn AT91F_PMC_CfgPIO
  2975. // \brief Configure PIO controllers to drive PMC signals
  2976. //----------------------------------------------------------------------------
  2977. __inline void AT91F_PMC_CfgPIO (void)
  2978. {
  2979. // Configure PIO controllers to periph mode
  2980. AT91F_PIO_CfgPeriph(
  2981. AT91C_BASE_PIOA, // PIO controller base address
  2982. 0, // Peripheral A
  2983. ((unsigned int) AT91C_PA6_PCK0 ) |
  2984. ((unsigned int) AT91C_PA18_PCK2 ) |
  2985. ((unsigned int) AT91C_PA31_PCK2 ) |
  2986. ((unsigned int) AT91C_PA21_PCK1 ) |
  2987. ((unsigned int) AT91C_PA17_PCK1 )); // Peripheral B
  2988. }
  2989. //----------------------------------------------------------------------------
  2990. // \fn AT91F_VREG_CfgPMC
  2991. // \brief Enable Peripheral clock in PMC for VREG
  2992. //----------------------------------------------------------------------------
  2993. __inline void AT91F_VREG_CfgPMC (void)
  2994. {
  2995. AT91F_PMC_EnablePeriphClock(
  2996. AT91C_BASE_PMC, // PIO controller base address
  2997. ((unsigned int) 1 << AT91C_ID_SYS));
  2998. }
  2999. //----------------------------------------------------------------------------
  3000. // \fn AT91F_RSTC_CfgPMC
  3001. // \brief Enable Peripheral clock in PMC for RSTC
  3002. //----------------------------------------------------------------------------
  3003. __inline void AT91F_RSTC_CfgPMC (void)
  3004. {
  3005. AT91F_PMC_EnablePeriphClock(
  3006. AT91C_BASE_PMC, // PIO controller base address
  3007. ((unsigned int) 1 << AT91C_ID_SYS));
  3008. }
  3009. //----------------------------------------------------------------------------
  3010. // \fn AT91F_SSC_CfgPMC
  3011. // \brief Enable Peripheral clock in PMC for SSC
  3012. //----------------------------------------------------------------------------
  3013. __inline void AT91F_SSC_CfgPMC (void)
  3014. {
  3015. AT91F_PMC_EnablePeriphClock(
  3016. AT91C_BASE_PMC, // PIO controller base address
  3017. ((unsigned int) 1 << AT91C_ID_SSC));
  3018. }
  3019. //----------------------------------------------------------------------------
  3020. // \fn AT91F_SSC_CfgPIO
  3021. // \brief Configure PIO controllers to drive SSC signals
  3022. //----------------------------------------------------------------------------
  3023. __inline void AT91F_SSC_CfgPIO (void)
  3024. {
  3025. // Configure PIO controllers to periph mode
  3026. AT91F_PIO_CfgPeriph(
  3027. AT91C_BASE_PIOA, // PIO controller base address
  3028. ((unsigned int) AT91C_PA19_RK ) |
  3029. ((unsigned int) AT91C_PA16_TK ) |
  3030. ((unsigned int) AT91C_PA15_TF ) |
  3031. ((unsigned int) AT91C_PA18_RD ) |
  3032. ((unsigned int) AT91C_PA20_RF ) |
  3033. ((unsigned int) AT91C_PA17_TD ), // Peripheral A
  3034. 0); // Peripheral B
  3035. }
  3036. //----------------------------------------------------------------------------
  3037. // \fn AT91F_WDTC_CfgPMC
  3038. // \brief Enable Peripheral clock in PMC for WDTC
  3039. //----------------------------------------------------------------------------
  3040. __inline void AT91F_WDTC_CfgPMC (void)
  3041. {
  3042. AT91F_PMC_EnablePeriphClock(
  3043. AT91C_BASE_PMC, // PIO controller base address
  3044. ((unsigned int) 1 << AT91C_ID_SYS));
  3045. }
  3046. //----------------------------------------------------------------------------
  3047. // \fn AT91F_US1_CfgPMC
  3048. // \brief Enable Peripheral clock in PMC for US1
  3049. //----------------------------------------------------------------------------
  3050. __inline void AT91F_US1_CfgPMC (void)
  3051. {
  3052. AT91F_PMC_EnablePeriphClock(
  3053. AT91C_BASE_PMC, // PIO controller base address
  3054. ((unsigned int) 1 << AT91C_ID_US1));
  3055. }
  3056. //----------------------------------------------------------------------------
  3057. // \fn AT91F_US1_CfgPIO
  3058. // \brief Configure PIO controllers to drive US1 signals
  3059. //----------------------------------------------------------------------------
  3060. __inline void AT91F_US1_CfgPIO (void)
  3061. {
  3062. // Configure PIO controllers to periph mode
  3063. AT91F_PIO_CfgPeriph(
  3064. AT91C_BASE_PIOA, // PIO controller base address
  3065. ((unsigned int) AT91C_PA29_RI1 ) |
  3066. ((unsigned int) AT91C_PA26_DCD1 ) |
  3067. ((unsigned int) AT91C_PA28_DSR1 ) |
  3068. ((unsigned int) AT91C_PA27_DTR1 ) |
  3069. ((unsigned int) AT91C_PA23_SCK1 ) |
  3070. ((unsigned int) AT91C_PA24_RTS1 ) |
  3071. ((unsigned int) AT91C_PA22_TXD1 ) |
  3072. ((unsigned int) AT91C_PA21_RXD1 ) |
  3073. ((unsigned int) AT91C_PA25_CTS1 ), // Peripheral A
  3074. 0); // Peripheral B
  3075. }
  3076. //----------------------------------------------------------------------------
  3077. // \fn AT91F_US0_CfgPMC
  3078. // \brief Enable Peripheral clock in PMC for US0
  3079. //----------------------------------------------------------------------------
  3080. __inline void AT91F_US0_CfgPMC (void)
  3081. {
  3082. AT91F_PMC_EnablePeriphClock(
  3083. AT91C_BASE_PMC, // PIO controller base address
  3084. ((unsigned int) 1 << AT91C_ID_US0));
  3085. }
  3086. //----------------------------------------------------------------------------
  3087. // \fn AT91F_US0_CfgPIO
  3088. // \brief Configure PIO controllers to drive US0 signals
  3089. //----------------------------------------------------------------------------
  3090. __inline void AT91F_US0_CfgPIO (void)
  3091. {
  3092. // Configure PIO controllers to periph mode
  3093. AT91F_PIO_CfgPeriph(
  3094. AT91C_BASE_PIOA, // PIO controller base address
  3095. ((unsigned int) AT91C_PA5_RXD0 ) |
  3096. ((unsigned int) AT91C_PA8_CTS0 ) |
  3097. ((unsigned int) AT91C_PA7_RTS0 ) |
  3098. ((unsigned int) AT91C_PA6_TXD0 ), // Peripheral A
  3099. ((unsigned int) AT91C_PA2_SCK0 )); // Peripheral B
  3100. }
  3101. //----------------------------------------------------------------------------
  3102. // \fn AT91F_SPI_CfgPMC
  3103. // \brief Enable Peripheral clock in PMC for SPI
  3104. //----------------------------------------------------------------------------
  3105. __inline void AT91F_SPI_CfgPMC (void)
  3106. {
  3107. AT91F_PMC_EnablePeriphClock(
  3108. AT91C_BASE_PMC, // PIO controller base address
  3109. ((unsigned int) 1 << AT91C_ID_SPI));
  3110. }
  3111. //----------------------------------------------------------------------------
  3112. // \fn AT91F_SPI_CfgPIO
  3113. // \brief Configure PIO controllers to drive SPI signals
  3114. //----------------------------------------------------------------------------
  3115. __inline void AT91F_SPI_CfgPIO (void)
  3116. {
  3117. // Configure PIO controllers to periph mode
  3118. AT91F_PIO_CfgPeriph(
  3119. AT91C_BASE_PIOA, // PIO controller base address
  3120. ((unsigned int) AT91C_PA13_MOSI ) |
  3121. ((unsigned int) AT91C_PA31_NPCS1 ) |
  3122. ((unsigned int) AT91C_PA14_SPCK ) |
  3123. ((unsigned int) AT91C_PA11_NPCS0 ) |
  3124. ((unsigned int) AT91C_PA12_MISO ), // Peripheral A
  3125. ((unsigned int) AT91C_PA9_NPCS1 ) |
  3126. ((unsigned int) AT91C_PA22_NPCS3 ) |
  3127. ((unsigned int) AT91C_PA3_NPCS3 ) |
  3128. ((unsigned int) AT91C_PA5_NPCS3 ) |
  3129. ((unsigned int) AT91C_PA10_NPCS2 ) |
  3130. ((unsigned int) AT91C_PA30_NPCS2 )); // Peripheral B
  3131. }
  3132. //----------------------------------------------------------------------------
  3133. // \fn AT91F_PITC_CfgPMC
  3134. // \brief Enable Peripheral clock in PMC for PITC
  3135. //----------------------------------------------------------------------------
  3136. __inline void AT91F_PITC_CfgPMC (void)
  3137. {
  3138. AT91F_PMC_EnablePeriphClock(
  3139. AT91C_BASE_PMC, // PIO controller base address
  3140. ((unsigned int) 1 << AT91C_ID_SYS));
  3141. }
  3142. //----------------------------------------------------------------------------
  3143. // \fn AT91F_AIC_CfgPMC
  3144. // \brief Enable Peripheral clock in PMC for AIC
  3145. //----------------------------------------------------------------------------
  3146. __inline void AT91F_AIC_CfgPMC (void)
  3147. {
  3148. AT91F_PMC_EnablePeriphClock(
  3149. AT91C_BASE_PMC, // PIO controller base address
  3150. ((unsigned int) 1 << AT91C_ID_FIQ) |
  3151. ((unsigned int) 1 << AT91C_ID_IRQ0) |
  3152. ((unsigned int) 1 << AT91C_ID_IRQ1));
  3153. }
  3154. //----------------------------------------------------------------------------
  3155. // \fn AT91F_AIC_CfgPIO
  3156. // \brief Configure PIO controllers to drive AIC signals
  3157. //----------------------------------------------------------------------------
  3158. __inline void AT91F_AIC_CfgPIO (void)
  3159. {
  3160. // Configure PIO controllers to periph mode
  3161. AT91F_PIO_CfgPeriph(
  3162. AT91C_BASE_PIOA, // PIO controller base address
  3163. ((unsigned int) AT91C_PA30_IRQ1 ), // Peripheral A
  3164. ((unsigned int) AT91C_PA20_IRQ0 ) |
  3165. ((unsigned int) AT91C_PA19_FIQ )); // Peripheral B
  3166. }
  3167. //----------------------------------------------------------------------------
  3168. // \fn AT91F_TWI_CfgPMC
  3169. // \brief Enable Peripheral clock in PMC for TWI
  3170. //----------------------------------------------------------------------------
  3171. __inline void AT91F_TWI_CfgPMC (void)
  3172. {
  3173. AT91F_PMC_EnablePeriphClock(
  3174. AT91C_BASE_PMC, // PIO controller base address
  3175. ((unsigned int) 1 << AT91C_ID_TWI));
  3176. }
  3177. //----------------------------------------------------------------------------
  3178. // \fn AT91F_TWI_CfgPIO
  3179. // \brief Configure PIO controllers to drive TWI signals
  3180. //----------------------------------------------------------------------------
  3181. __inline void AT91F_TWI_CfgPIO (void)
  3182. {
  3183. // Configure PIO controllers to periph mode
  3184. AT91F_PIO_CfgPeriph(
  3185. AT91C_BASE_PIOA, // PIO controller base address
  3186. ((unsigned int) AT91C_PA4_TWCK ) |
  3187. ((unsigned int) AT91C_PA3_TWD ), // Peripheral A
  3188. 0); // Peripheral B
  3189. }
  3190. //----------------------------------------------------------------------------
  3191. // \fn AT91F_PWMC_CH3_CfgPIO
  3192. // \brief Configure PIO controllers to drive PWMC_CH3 signals
  3193. //----------------------------------------------------------------------------
  3194. __inline void AT91F_PWMC_CH3_CfgPIO (void)
  3195. {
  3196. // Configure PIO controllers to periph mode
  3197. AT91F_PIO_CfgPeriph(
  3198. AT91C_BASE_PIOA, // PIO controller base address
  3199. 0, // Peripheral A
  3200. ((unsigned int) AT91C_PA7_PWM3 ) |
  3201. ((unsigned int) AT91C_PA14_PWM3 )); // Peripheral B
  3202. }
  3203. //----------------------------------------------------------------------------
  3204. // \fn AT91F_PWMC_CH2_CfgPIO
  3205. // \brief Configure PIO controllers to drive PWMC_CH2 signals
  3206. //----------------------------------------------------------------------------
  3207. __inline void AT91F_PWMC_CH2_CfgPIO (void)
  3208. {
  3209. // Configure PIO controllers to periph mode
  3210. AT91F_PIO_CfgPeriph(
  3211. AT91C_BASE_PIOA, // PIO controller base address
  3212. ((unsigned int) AT91C_PA2_PWM2 ), // Peripheral A
  3213. ((unsigned int) AT91C_PA13_PWM2 ) |
  3214. ((unsigned int) AT91C_PA25_PWM2 )); // Peripheral B
  3215. }
  3216. //----------------------------------------------------------------------------
  3217. // \fn AT91F_PWMC_CH1_CfgPIO
  3218. // \brief Configure PIO controllers to drive PWMC_CH1 signals
  3219. //----------------------------------------------------------------------------
  3220. __inline void AT91F_PWMC_CH1_CfgPIO (void)
  3221. {
  3222. // Configure PIO controllers to periph mode
  3223. AT91F_PIO_CfgPeriph(
  3224. AT91C_BASE_PIOA, // PIO controller base address
  3225. ((unsigned int) AT91C_PA1_PWM1 ), // Peripheral A
  3226. ((unsigned int) AT91C_PA24_PWM1 ) |
  3227. ((unsigned int) AT91C_PA12_PWM1 )); // Peripheral B
  3228. }
  3229. //----------------------------------------------------------------------------
  3230. // \fn AT91F_PWMC_CH0_CfgPIO
  3231. // \brief Configure PIO controllers to drive PWMC_CH0 signals
  3232. //----------------------------------------------------------------------------
  3233. __inline void AT91F_PWMC_CH0_CfgPIO (void)
  3234. {
  3235. // Configure PIO controllers to periph mode
  3236. AT91F_PIO_CfgPeriph(
  3237. AT91C_BASE_PIOA, // PIO controller base address
  3238. ((unsigned int) AT91C_PA0_PWM0 ), // Peripheral A
  3239. ((unsigned int) AT91C_PA23_PWM0 ) |
  3240. ((unsigned int) AT91C_PA11_PWM0 )); // Peripheral B
  3241. }
  3242. //----------------------------------------------------------------------------
  3243. // \fn AT91F_ADC_CfgPMC
  3244. // \brief Enable Peripheral clock in PMC for ADC
  3245. //----------------------------------------------------------------------------
  3246. __inline void AT91F_ADC_CfgPMC (void)
  3247. {
  3248. AT91F_PMC_EnablePeriphClock(
  3249. AT91C_BASE_PMC, // PIO controller base address
  3250. ((unsigned int) 1 << AT91C_ID_ADC));
  3251. }
  3252. //----------------------------------------------------------------------------
  3253. // \fn AT91F_ADC_CfgPIO
  3254. // \brief Configure PIO controllers to drive ADC signals
  3255. //----------------------------------------------------------------------------
  3256. __inline void AT91F_ADC_CfgPIO (void)
  3257. {
  3258. // Configure PIO controllers to periph mode
  3259. AT91F_PIO_CfgPeriph(
  3260. AT91C_BASE_PIOA, // PIO controller base address
  3261. 0, // Peripheral A
  3262. ((unsigned int) AT91C_PA8_ADTRG )); // Peripheral B
  3263. }
  3264. //----------------------------------------------------------------------------
  3265. // \fn AT91F_RTTC_CfgPMC
  3266. // \brief Enable Peripheral clock in PMC for RTTC
  3267. //----------------------------------------------------------------------------
  3268. __inline void AT91F_RTTC_CfgPMC (void)
  3269. {
  3270. AT91F_PMC_EnablePeriphClock(
  3271. AT91C_BASE_PMC, // PIO controller base address
  3272. ((unsigned int) 1 << AT91C_ID_SYS));
  3273. }
  3274. //----------------------------------------------------------------------------
  3275. // \fn AT91F_UDP_CfgPMC
  3276. // \brief Enable Peripheral clock in PMC for UDP
  3277. //----------------------------------------------------------------------------
  3278. __inline void AT91F_UDP_CfgPMC (void)
  3279. {
  3280. AT91F_PMC_EnablePeriphClock(
  3281. AT91C_BASE_PMC, // PIO controller base address
  3282. ((unsigned int) 1 << AT91C_ID_UDP));
  3283. }
  3284. //----------------------------------------------------------------------------
  3285. // \fn AT91F_TC0_CfgPMC
  3286. // \brief Enable Peripheral clock in PMC for TC0
  3287. //----------------------------------------------------------------------------
  3288. __inline void AT91F_TC0_CfgPMC (void)
  3289. {
  3290. AT91F_PMC_EnablePeriphClock(
  3291. AT91C_BASE_PMC, // PIO controller base address
  3292. ((unsigned int) 1 << AT91C_ID_TC0));
  3293. }
  3294. //----------------------------------------------------------------------------
  3295. // \fn AT91F_TC0_CfgPIO
  3296. // \brief Configure PIO controllers to drive TC0 signals
  3297. //----------------------------------------------------------------------------
  3298. __inline void AT91F_TC0_CfgPIO (void)
  3299. {
  3300. // Configure PIO controllers to periph mode
  3301. AT91F_PIO_CfgPeriph(
  3302. AT91C_BASE_PIOA, // PIO controller base address
  3303. 0, // Peripheral A
  3304. ((unsigned int) AT91C_PA0_TIOA0 ) |
  3305. ((unsigned int) AT91C_PA4_TCLK0 ) |
  3306. ((unsigned int) AT91C_PA1_TIOB0 )); // Peripheral B
  3307. }
  3308. //----------------------------------------------------------------------------
  3309. // \fn AT91F_TC1_CfgPMC
  3310. // \brief Enable Peripheral clock in PMC for TC1
  3311. //----------------------------------------------------------------------------
  3312. __inline void AT91F_TC1_CfgPMC (void)
  3313. {
  3314. AT91F_PMC_EnablePeriphClock(
  3315. AT91C_BASE_PMC, // PIO controller base address
  3316. ((unsigned int) 1 << AT91C_ID_TC1));
  3317. }
  3318. //----------------------------------------------------------------------------
  3319. // \fn AT91F_TC1_CfgPIO
  3320. // \brief Configure PIO controllers to drive TC1 signals
  3321. //----------------------------------------------------------------------------
  3322. __inline void AT91F_TC1_CfgPIO (void)
  3323. {
  3324. // Configure PIO controllers to periph mode
  3325. AT91F_PIO_CfgPeriph(
  3326. AT91C_BASE_PIOA, // PIO controller base address
  3327. 0, // Peripheral A
  3328. ((unsigned int) AT91C_PA15_TIOA1 ) |
  3329. ((unsigned int) AT91C_PA28_TCLK1 ) |
  3330. ((unsigned int) AT91C_PA16_TIOB1 )); // Peripheral B
  3331. }
  3332. //----------------------------------------------------------------------------
  3333. // \fn AT91F_TC2_CfgPMC
  3334. // \brief Enable Peripheral clock in PMC for TC2
  3335. //----------------------------------------------------------------------------
  3336. __inline void AT91F_TC2_CfgPMC (void)
  3337. {
  3338. AT91F_PMC_EnablePeriphClock(
  3339. AT91C_BASE_PMC, // PIO controller base address
  3340. ((unsigned int) 1 << AT91C_ID_TC2));
  3341. }
  3342. //----------------------------------------------------------------------------
  3343. // \fn AT91F_TC2_CfgPIO
  3344. // \brief Configure PIO controllers to drive TC2 signals
  3345. //----------------------------------------------------------------------------
  3346. __inline void AT91F_TC2_CfgPIO (void)
  3347. {
  3348. // Configure PIO controllers to periph mode
  3349. AT91F_PIO_CfgPeriph(
  3350. AT91C_BASE_PIOA, // PIO controller base address
  3351. 0, // Peripheral A
  3352. ((unsigned int) AT91C_PA27_TIOB2 ) |
  3353. ((unsigned int) AT91C_PA26_TIOA2 ) |
  3354. ((unsigned int) AT91C_PA29_TCLK2 )); // Peripheral B
  3355. }
  3356. //----------------------------------------------------------------------------
  3357. // \fn AT91F_MC_CfgPMC
  3358. // \brief Enable Peripheral clock in PMC for MC
  3359. //----------------------------------------------------------------------------
  3360. __inline void AT91F_MC_CfgPMC (void)
  3361. {
  3362. AT91F_PMC_EnablePeriphClock(
  3363. AT91C_BASE_PMC, // PIO controller base address
  3364. ((unsigned int) 1 << AT91C_ID_SYS));
  3365. }
  3366. //----------------------------------------------------------------------------
  3367. // \fn AT91F_PIOA_CfgPMC
  3368. // \brief Enable Peripheral clock in PMC for PIOA
  3369. //----------------------------------------------------------------------------
  3370. __inline void AT91F_PIOA_CfgPMC (void)
  3371. {
  3372. AT91F_PMC_EnablePeriphClock(
  3373. AT91C_BASE_PMC, // PIO controller base address
  3374. ((unsigned int) 1 << AT91C_ID_PIOA));
  3375. }
  3376. //----------------------------------------------------------------------------
  3377. // \fn AT91F_PWMC_CfgPMC
  3378. // \brief Enable Peripheral clock in PMC for PWMC
  3379. //----------------------------------------------------------------------------
  3380. __inline void AT91F_PWMC_CfgPMC (void)
  3381. {
  3382. AT91F_PMC_EnablePeriphClock(
  3383. AT91C_BASE_PMC, // PIO controller base address
  3384. ((unsigned int) 1 << AT91C_ID_PWMC));
  3385. }
  3386. //}}}
  3387. #endif