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_AT91SAM7X256.h */
16 /** Object : AT91SAM7X256 inlined functions */
17 /** Generated : AT91 SW Application Group 05/20/2005 (16:22:29) */
19 /** CVS Reference : /lib_dbgu.h/1.1/Fri Jan 31 12:18:40 2003// */
20 /** CVS Reference : /lib_pmc_SAM7X.h/1.1/Tue Feb 1 08:32:10 2005// */
21 /** CVS Reference : /lib_VREG_6085B.h/1.1/Tue Feb 1 16:20:47 2005// */
22 /** CVS Reference : /lib_rstc_6098A.h/1.1/Wed Oct 6 10:39:20 2004// */
23 /** CVS Reference : /lib_ssc.h/1.4/Fri Jan 31 12:19:20 2003// */
24 /** CVS Reference : /lib_wdtc_6080A.h/1.1/Wed Oct 6 10:38:30 2004// */
25 /** CVS Reference : /lib_usart.h/1.5/Thu Nov 21 16:01:54 2002// */
26 /** CVS Reference : /lib_spi2.h/1.1/Mon Aug 25 14:23:52 2003// */
27 /** CVS Reference : /lib_pitc_6079A.h/1.2/Tue Nov 9 14:43:56 2004// */
28 /** CVS Reference : /lib_aic_6075b.h/1.1/Fri May 20 14:01:19 2005// */
29 /** CVS Reference : /lib_aes_6149a.h/1.1/Mon Jan 17 07:43:09 2005// */
30 /** CVS Reference : /lib_twi.h/1.3/Mon Jul 19 14:27:58 2004// */
31 /** CVS Reference : /lib_adc.h/1.6/Fri Oct 17 09:12:38 2003// */
32 /** CVS Reference : /lib_rttc_6081A.h/1.1/Wed Oct 6 10:39:38 2004// */
33 /** CVS Reference : /lib_udp.h/1.4/Wed Feb 16 08:39:34 2005// */
34 /** CVS Reference : /lib_des3_6150a.h/1.1/Mon Jan 17 09:19:19 2005// */
35 /** CVS Reference : /lib_tc_1753b.h/1.1/Fri Jan 31 12:20:02 2003// */
36 /** CVS Reference : /lib_MC_SAM7X.h/1.1/Thu Mar 25 15:19:14 2004// */
37 /** CVS Reference : /lib_pio.h/1.3/Fri Jan 31 12:18:56 2003// */
38 /** CVS Reference : /lib_can_AT91.h/1.4/Fri Oct 17 09:12:50 2003// */
39 /** CVS Reference : /lib_PWM_SAM.h/1.3/Thu Jan 22 10:10:50 2004// */
40 /** CVS Reference : /lib_pdc.h/1.2/Tue Jul 2 13:29:40 2002// */
41 /** ---------------------------------------------------------------------------- */
43 #ifndef lib_AT91SAM7X256_H
44 #define lib_AT91SAM7X256_H
46 /* *****************************************************************************
47 * SOFTWARE API FOR AIC
48 ***************************************************************************** */
49 #define AT91C_AIC_BRANCH_OPCODE ( ( void ( * )() ) 0xE51FFF20 ) /* ldr, pc, [pc, #-&F20] */
51 /**---------------------------------------------------------------------------- */
52 /** \fn AT91F_AIC_ConfigureIt */
53 /** \brief Interrupt Handler Initialization */
54 /**---------------------------------------------------------------------------- */
55 __inline unsigned int AT91F_AIC_ConfigureIt( AT91PS_AIC pAic, /* \arg pointer to the AIC registers */
56 unsigned int irq_id, /* \arg interrupt number to initialize */
57 unsigned int priority, /* \arg priority to give to the interrupt */
58 unsigned int src_type, /* \arg activation and sense of activation */
59 void ( * newHandler )( void ) ) /* \arg address of the interrupt handler */
61 unsigned int oldHandler;
64 oldHandler = pAic->AIC_SVR[ irq_id ];
67 /** Disable the interrupt on the interrupt controller */
68 pAic->AIC_IDCR = mask;
69 /** Save the interrupt handler routine pointer and the interrupt priority */
70 pAic->AIC_SVR[ irq_id ] = ( unsigned int ) newHandler;
71 /** Store the Source Mode Register */
72 pAic->AIC_SMR[ irq_id ] = src_type | priority;
73 /** Clear the interrupt on the interrupt controller */
74 pAic->AIC_ICCR = mask;
79 /**---------------------------------------------------------------------------- */
80 /** \fn AT91F_AIC_EnableIt */
81 /** \brief Enable corresponding IT number */
82 /**---------------------------------------------------------------------------- */
83 __inline void AT91F_AIC_EnableIt( AT91PS_AIC pAic, /* \arg pointer to the AIC registers */
84 unsigned int irq_id ) /* \arg interrupt number to initialize */
86 /** Enable the interrupt on the interrupt controller */
87 pAic->AIC_IECR = 0x1 << irq_id;
90 /**---------------------------------------------------------------------------- */
91 /** \fn AT91F_AIC_DisableIt */
92 /** \brief Disable corresponding IT number */
93 /**---------------------------------------------------------------------------- */
94 __inline void AT91F_AIC_DisableIt( AT91PS_AIC pAic, /* \arg pointer to the AIC registers */
95 unsigned int irq_id ) /* \arg interrupt number to initialize */
97 unsigned int mask = 0x1 << irq_id;
99 /** Disable the interrupt on the interrupt controller */
100 pAic->AIC_IDCR = mask;
101 /** Clear the interrupt on the Interrupt Controller ( if one is pending ) */
102 pAic->AIC_ICCR = mask;
105 /**---------------------------------------------------------------------------- */
106 /** \fn AT91F_AIC_ClearIt */
107 /** \brief Clear corresponding IT number */
108 /**---------------------------------------------------------------------------- */
109 __inline void AT91F_AIC_ClearIt( AT91PS_AIC pAic, /* \arg pointer to the AIC registers */
110 unsigned int irq_id ) /* \arg interrupt number to initialize */
112 /** Clear the interrupt on the Interrupt Controller ( if one is pending ) */
113 pAic->AIC_ICCR = ( 0x1 << irq_id );
116 /**---------------------------------------------------------------------------- */
117 /** \fn AT91F_AIC_AcknowledgeIt */
118 /** \brief Acknowledge corresponding IT number */
119 /**---------------------------------------------------------------------------- */
120 __inline void AT91F_AIC_AcknowledgeIt( AT91PS_AIC pAic ) /* \arg pointer to the AIC registers */
122 pAic->AIC_EOICR = pAic->AIC_EOICR;
125 /**---------------------------------------------------------------------------- */
126 /** \fn AT91F_AIC_SetExceptionVector */
127 /** \brief Configure vector handler */
128 /**---------------------------------------------------------------------------- */
129 __inline unsigned int AT91F_AIC_SetExceptionVector( unsigned int * pVector, /* \arg pointer to the AIC registers */
130 void ( * Handler )() ) /* \arg Interrupt Handler */
132 unsigned int oldVector = *pVector;
134 if( ( unsigned int ) Handler == ( unsigned int ) AT91C_AIC_BRANCH_OPCODE )
136 *pVector = ( unsigned int ) AT91C_AIC_BRANCH_OPCODE;
140 *pVector = ( ( ( ( ( unsigned int ) Handler ) - ( ( unsigned int ) pVector ) - 0x8 ) >> 2 ) & 0x00FFFFFF ) | 0xEA000000;
146 /**---------------------------------------------------------------------------- */
147 /** \fn AT91F_AIC_Trig */
148 /** \brief Trig an IT */
149 /**---------------------------------------------------------------------------- */
150 __inline void AT91F_AIC_Trig( AT91PS_AIC pAic, /* \arg pointer to the AIC registers */
151 unsigned int irq_id ) /* \arg interrupt number */
153 pAic->AIC_ISCR = ( 0x1 << irq_id );
156 /**---------------------------------------------------------------------------- */
157 /** \fn AT91F_AIC_IsActive */
158 /** \brief Test if an IT is active */
159 /**---------------------------------------------------------------------------- */
160 __inline unsigned int AT91F_AIC_IsActive( AT91PS_AIC pAic, /* \arg pointer to the AIC registers */
161 unsigned int irq_id ) /* \arg Interrupt Number */
163 return( pAic->AIC_ISR & ( 0x1 << irq_id ) );
166 /**---------------------------------------------------------------------------- */
167 /** \fn AT91F_AIC_IsPending */
168 /** \brief Test if an IT is pending */
169 /**---------------------------------------------------------------------------- */
170 __inline unsigned int AT91F_AIC_IsPending( AT91PS_AIC pAic, /* \arg pointer to the AIC registers */
171 unsigned int irq_id ) /* \arg Interrupt Number */
173 return( pAic->AIC_IPR & ( 0x1 << irq_id ) );
176 /**---------------------------------------------------------------------------- */
177 /** \fn AT91F_AIC_Open */
178 /** \brief Set exception vectors and AIC registers to default values */
179 /**---------------------------------------------------------------------------- */
180 __inline void AT91F_AIC_Open( AT91PS_AIC pAic, /* \arg pointer to the AIC registers */
181 void ( * IrqHandler )(), /* \arg Default IRQ vector exception */
182 void ( * FiqHandler )(), /* \arg Default FIQ vector exception */
183 void ( * DefaultHandler )(), /* \arg Default Handler set in ISR */
184 void ( * SpuriousHandler )(), /* \arg Default Spurious Handler */
185 unsigned int protectMode ) /* \arg Debug Control Register */
189 /* Disable all interrupts and set IVR to the default handler */
190 for( i = 0; i < 32; ++i )
192 AT91F_AIC_DisableIt( pAic, i );
193 AT91F_AIC_ConfigureIt( pAic, i, AT91C_AIC_PRIOR_LOWEST, AT91C_AIC_SRCTYPE_HIGH_LEVEL, DefaultHandler );
196 /* Set the IRQ exception vector */
197 AT91F_AIC_SetExceptionVector( ( unsigned int * ) 0x18, IrqHandler );
198 /* Set the Fast Interrupt exception vector */
199 AT91F_AIC_SetExceptionVector( ( unsigned int * ) 0x1C, FiqHandler );
201 pAic->AIC_SPU = ( unsigned int ) SpuriousHandler;
202 pAic->AIC_DCR = protectMode;
205 /* *****************************************************************************
206 * SOFTWARE API FOR PDC
207 ***************************************************************************** */
208 /**---------------------------------------------------------------------------- */
209 /** \fn AT91F_PDC_SetNextRx */
210 /** \brief Set the next receive transfer descriptor */
211 /**---------------------------------------------------------------------------- */
212 __inline void AT91F_PDC_SetNextRx( AT91PS_PDC pPDC, /* \arg pointer to a PDC controller */
213 char * address, /* \arg address to the next block to be received */
214 unsigned int bytes ) /* \arg number of bytes to be received */
216 pPDC->PDC_RNPR = ( unsigned int ) address;
217 pPDC->PDC_RNCR = bytes;
220 /**---------------------------------------------------------------------------- */
221 /** \fn AT91F_PDC_SetNextTx */
222 /** \brief Set the next transmit transfer descriptor */
223 /**---------------------------------------------------------------------------- */
224 __inline void AT91F_PDC_SetNextTx( AT91PS_PDC pPDC, /* \arg pointer to a PDC controller */
225 char * address, /* \arg address to the next block to be transmitted */
226 unsigned int bytes ) /* \arg number of bytes to be transmitted */
228 pPDC->PDC_TNPR = ( unsigned int ) address;
229 pPDC->PDC_TNCR = bytes;
232 /**---------------------------------------------------------------------------- */
233 /** \fn AT91F_PDC_SetRx */
234 /** \brief Set the receive transfer descriptor */
235 /**---------------------------------------------------------------------------- */
236 __inline void AT91F_PDC_SetRx( AT91PS_PDC pPDC, /* \arg pointer to a PDC controller */
237 char * address, /* \arg address to the next block to be received */
238 unsigned int bytes ) /* \arg number of bytes to be received */
240 pPDC->PDC_RPR = ( unsigned int ) address;
241 pPDC->PDC_RCR = bytes;
244 /**---------------------------------------------------------------------------- */
245 /** \fn AT91F_PDC_SetTx */
246 /** \brief Set the transmit transfer descriptor */
247 /**---------------------------------------------------------------------------- */
248 __inline void AT91F_PDC_SetTx( AT91PS_PDC pPDC, /* \arg pointer to a PDC controller */
249 char * address, /* \arg address to the next block to be transmitted */
250 unsigned int bytes ) /* \arg number of bytes to be transmitted */
252 pPDC->PDC_TPR = ( unsigned int ) address;
253 pPDC->PDC_TCR = bytes;
256 /**---------------------------------------------------------------------------- */
257 /** \fn AT91F_PDC_EnableTx */
258 /** \brief Enable transmit */
259 /**---------------------------------------------------------------------------- */
260 __inline void AT91F_PDC_EnableTx( AT91PS_PDC pPDC ) /* \arg pointer to a PDC controller */
262 pPDC->PDC_PTCR = AT91C_PDC_TXTEN;
265 /**---------------------------------------------------------------------------- */
266 /** \fn AT91F_PDC_EnableRx */
267 /** \brief Enable receive */
268 /**---------------------------------------------------------------------------- */
269 __inline void AT91F_PDC_EnableRx( AT91PS_PDC pPDC ) /* \arg pointer to a PDC controller */
271 pPDC->PDC_PTCR = AT91C_PDC_RXTEN;
274 /**---------------------------------------------------------------------------- */
275 /** \fn AT91F_PDC_DisableTx */
276 /** \brief Disable transmit */
277 /**---------------------------------------------------------------------------- */
278 __inline void AT91F_PDC_DisableTx( AT91PS_PDC pPDC ) /* \arg pointer to a PDC controller */
280 pPDC->PDC_PTCR = AT91C_PDC_TXTDIS;
283 /**---------------------------------------------------------------------------- */
284 /** \fn AT91F_PDC_DisableRx */
285 /** \brief Disable receive */
286 /**---------------------------------------------------------------------------- */
287 __inline void AT91F_PDC_DisableRx( AT91PS_PDC pPDC ) /* \arg pointer to a PDC controller */
289 pPDC->PDC_PTCR = AT91C_PDC_RXTDIS;
292 /**---------------------------------------------------------------------------- */
293 /** \fn AT91F_PDC_IsTxEmpty */
294 /** \brief Test if the current transfer descriptor has been sent */
295 /**---------------------------------------------------------------------------- */
296 __inline int AT91F_PDC_IsTxEmpty( /* \return return 1 if transfer is complete */
297 AT91PS_PDC pPDC ) /* \arg pointer to a PDC controller */
299 return !( pPDC->PDC_TCR );
302 /**---------------------------------------------------------------------------- */
303 /** \fn AT91F_PDC_IsNextTxEmpty */
304 /** \brief Test if the next transfer descriptor has been moved to the current td */
305 /**---------------------------------------------------------------------------- */
306 __inline int AT91F_PDC_IsNextTxEmpty( /* \return return 1 if transfer is complete */
307 AT91PS_PDC pPDC ) /* \arg pointer to a PDC controller */
309 return !( pPDC->PDC_TNCR );
312 /**---------------------------------------------------------------------------- */
313 /** \fn AT91F_PDC_IsRxEmpty */
314 /** \brief Test if the current transfer descriptor has been filled */
315 /**---------------------------------------------------------------------------- */
316 __inline int AT91F_PDC_IsRxEmpty( /* \return return 1 if transfer is complete */
317 AT91PS_PDC pPDC ) /* \arg pointer to a PDC controller */
319 return !( pPDC->PDC_RCR );
322 /**---------------------------------------------------------------------------- */
323 /** \fn AT91F_PDC_IsNextRxEmpty */
324 /** \brief Test if the next transfer descriptor has been moved to the current td */
325 /**---------------------------------------------------------------------------- */
326 __inline int AT91F_PDC_IsNextRxEmpty( /* \return return 1 if transfer is complete */
327 AT91PS_PDC pPDC ) /* \arg pointer to a PDC controller */
329 return !( pPDC->PDC_RNCR );
332 /**---------------------------------------------------------------------------- */
333 /** \fn AT91F_PDC_Open */
334 /** \brief Open PDC: disable TX and RX reset transfer descriptors, re-enable RX and TX */
335 /**---------------------------------------------------------------------------- */
336 __inline void AT91F_PDC_Open( AT91PS_PDC pPDC ) /* \arg pointer to a PDC controller */
338 /** Disable the RX and TX PDC transfer requests */
339 AT91F_PDC_DisableRx( pPDC );
340 AT91F_PDC_DisableTx( pPDC );
342 /** Reset all Counter register Next buffer first */
343 AT91F_PDC_SetNextTx( pPDC, ( char * ) 0, 0 );
344 AT91F_PDC_SetNextRx( pPDC, ( char * ) 0, 0 );
345 AT91F_PDC_SetTx( pPDC, ( char * ) 0, 0 );
346 AT91F_PDC_SetRx( pPDC, ( char * ) 0, 0 );
348 /** Enable the RX and TX PDC transfer requests */
349 AT91F_PDC_EnableRx( pPDC );
350 AT91F_PDC_EnableTx( pPDC );
353 /**---------------------------------------------------------------------------- */
354 /** \fn AT91F_PDC_Close */
355 /** \brief Close PDC: disable TX and RX reset transfer descriptors */
356 /**---------------------------------------------------------------------------- */
357 __inline void AT91F_PDC_Close( AT91PS_PDC pPDC ) /* \arg pointer to a PDC controller */
359 /** Disable the RX and TX PDC transfer requests */
360 AT91F_PDC_DisableRx( pPDC );
361 AT91F_PDC_DisableTx( pPDC );
363 /** Reset all Counter register Next buffer first */
364 AT91F_PDC_SetNextTx( pPDC, ( char * ) 0, 0 );
365 AT91F_PDC_SetNextRx( pPDC, ( char * ) 0, 0 );
366 AT91F_PDC_SetTx( pPDC, ( char * ) 0, 0 );
367 AT91F_PDC_SetRx( pPDC, ( char * ) 0, 0 );
370 /**---------------------------------------------------------------------------- */
371 /** \fn AT91F_PDC_SendFrame */
372 /** \brief Close PDC: disable TX and RX reset transfer descriptors */
373 /**---------------------------------------------------------------------------- */
374 __inline unsigned int AT91F_PDC_SendFrame( AT91PS_PDC pPDC,
376 unsigned int szBuffer,
378 unsigned int szNextBuffer )
380 if( AT91F_PDC_IsTxEmpty( pPDC ) )
382 /** Buffer and next buffer can be initialized */
383 AT91F_PDC_SetTx( pPDC, pBuffer, szBuffer );
384 AT91F_PDC_SetNextTx( pPDC, pNextBuffer, szNextBuffer );
387 else if( AT91F_PDC_IsNextTxEmpty( pPDC ) )
389 /** Only one buffer can be initialized */
390 AT91F_PDC_SetNextTx( pPDC, pBuffer, szBuffer );
395 /** All buffer are in use... */
400 /**---------------------------------------------------------------------------- */
401 /** \fn AT91F_PDC_ReceiveFrame */
402 /** \brief Close PDC: disable TX and RX reset transfer descriptors */
403 /**---------------------------------------------------------------------------- */
404 __inline unsigned int AT91F_PDC_ReceiveFrame( AT91PS_PDC pPDC,
406 unsigned int szBuffer,
408 unsigned int szNextBuffer )
410 if( AT91F_PDC_IsRxEmpty( pPDC ) )
412 /** Buffer and next buffer can be initialized */
413 AT91F_PDC_SetRx( pPDC, pBuffer, szBuffer );
414 AT91F_PDC_SetNextRx( pPDC, pNextBuffer, szNextBuffer );
417 else if( AT91F_PDC_IsNextRxEmpty( pPDC ) )
419 /** Only one buffer can be initialized */
420 AT91F_PDC_SetNextRx( pPDC, pBuffer, szBuffer );
425 /** All buffer are in use... */
430 /* *****************************************************************************
431 * SOFTWARE API FOR DBGU
432 ***************************************************************************** */
433 /**---------------------------------------------------------------------------- */
434 /** \fn AT91F_DBGU_InterruptEnable */
435 /** \brief Enable DBGU Interrupt */
436 /**---------------------------------------------------------------------------- */
437 __inline void AT91F_DBGU_InterruptEnable( AT91PS_DBGU pDbgu, /* \arg pointer to a DBGU controller */
438 unsigned int flag ) /* \arg dbgu interrupt to be enabled */
440 pDbgu->DBGU_IER = flag;
443 /**---------------------------------------------------------------------------- */
444 /** \fn AT91F_DBGU_InterruptDisable */
445 /** \brief Disable DBGU Interrupt */
446 /**---------------------------------------------------------------------------- */
447 __inline void AT91F_DBGU_InterruptDisable( AT91PS_DBGU pDbgu, /* \arg pointer to a DBGU controller */
448 unsigned int flag ) /* \arg dbgu interrupt to be disabled */
450 pDbgu->DBGU_IDR = flag;
453 /**---------------------------------------------------------------------------- */
454 /** \fn AT91F_DBGU_GetInterruptMaskStatus */
455 /** \brief Return DBGU Interrupt Mask Status */
456 /**---------------------------------------------------------------------------- */
457 __inline unsigned int AT91F_DBGU_GetInterruptMaskStatus( /* \return DBGU Interrupt Mask Status */
458 AT91PS_DBGU pDbgu ) /* \arg pointer to a DBGU controller */
460 return pDbgu->DBGU_IMR;
463 /**---------------------------------------------------------------------------- */
464 /** \fn AT91F_DBGU_IsInterruptMasked */
465 /** \brief Test if DBGU Interrupt is Masked */
466 /**---------------------------------------------------------------------------- */
467 __inline int AT91F_DBGU_IsInterruptMasked( AT91PS_DBGU pDbgu, /* \arg pointer to a DBGU controller */
468 unsigned int flag ) /* \arg flag to be tested */
470 return( AT91F_DBGU_GetInterruptMaskStatus( pDbgu ) & flag );
473 /* *****************************************************************************
474 * SOFTWARE API FOR PIO
475 ***************************************************************************** */
476 /**---------------------------------------------------------------------------- */
477 /** \fn AT91F_PIO_CfgPeriph */
478 /** \brief Enable pins to be derived by peripheral */
479 /**---------------------------------------------------------------------------- */
480 __inline void AT91F_PIO_CfgPeriph( AT91PS_PIO pPio, /* \arg pointer to a PIO controller */
481 unsigned int periphAEnable, /* \arg PERIPH A to enable */
482 unsigned int periphBEnable ) /* \arg PERIPH B to enable */
485 pPio->PIO_ASR = periphAEnable;
486 pPio->PIO_BSR = periphBEnable;
487 pPio->PIO_PDR = ( periphAEnable | periphBEnable ); /* Set in Periph mode */
490 /**---------------------------------------------------------------------------- */
491 /** \fn AT91F_PIO_CfgOutput */
492 /** \brief Enable PIO in output mode */
493 /**---------------------------------------------------------------------------- */
494 __inline void AT91F_PIO_CfgOutput( AT91PS_PIO pPio, /* \arg pointer to a PIO controller */
495 unsigned int pioEnable ) /* \arg PIO to be enabled */
497 pPio->PIO_PER = pioEnable; /* Set in PIO mode */
498 pPio->PIO_OER = pioEnable; /* Configure in Output */
501 /**---------------------------------------------------------------------------- */
502 /** \fn AT91F_PIO_CfgInput */
503 /** \brief Enable PIO in input mode */
504 /**---------------------------------------------------------------------------- */
505 __inline void AT91F_PIO_CfgInput( AT91PS_PIO pPio, /* \arg pointer to a PIO controller */
506 unsigned int inputEnable ) /* \arg PIO to be enabled */
509 pPio->PIO_ODR = inputEnable;
510 pPio->PIO_PER = inputEnable;
513 /**---------------------------------------------------------------------------- */
514 /** \fn AT91F_PIO_CfgOpendrain */
515 /** \brief Configure PIO in open drain */
516 /**---------------------------------------------------------------------------- */
517 __inline void AT91F_PIO_CfgOpendrain( AT91PS_PIO pPio, /* \arg pointer to a PIO controller */
518 unsigned int multiDrvEnable ) /* \arg pio to be configured in open drain */
520 /* Configure the multi-drive option */
521 pPio->PIO_MDDR = ~multiDrvEnable;
522 pPio->PIO_MDER = multiDrvEnable;
525 /**---------------------------------------------------------------------------- */
526 /** \fn AT91F_PIO_CfgPullup */
527 /** \brief Enable pullup on PIO */
528 /**---------------------------------------------------------------------------- */
529 __inline void AT91F_PIO_CfgPullup( AT91PS_PIO pPio, /* \arg pointer to a PIO controller */
530 unsigned int pullupEnable ) /* \arg enable pullup on PIO */
532 /* Connect or not Pullup */
533 pPio->PIO_PPUDR = ~pullupEnable;
534 pPio->PIO_PPUER = pullupEnable;
537 /**---------------------------------------------------------------------------- */
538 /** \fn AT91F_PIO_CfgDirectDrive */
539 /** \brief Enable direct drive on PIO */
540 /**---------------------------------------------------------------------------- */
541 __inline void AT91F_PIO_CfgDirectDrive( AT91PS_PIO pPio, /* \arg pointer to a PIO controller */
542 unsigned int directDrive ) /* \arg PIO to be configured with direct drive */
545 /* Configure the Direct Drive */
546 pPio->PIO_OWDR = ~directDrive;
547 pPio->PIO_OWER = directDrive;
550 /**---------------------------------------------------------------------------- */
551 /** \fn AT91F_PIO_CfgInputFilter */
552 /** \brief Enable input filter on input PIO */
553 /**---------------------------------------------------------------------------- */
554 __inline void AT91F_PIO_CfgInputFilter( AT91PS_PIO pPio, /* \arg pointer to a PIO controller */
555 unsigned int inputFilter ) /* \arg PIO to be configured with input filter */
558 /* Configure the Direct Drive */
559 pPio->PIO_IFDR = ~inputFilter;
560 pPio->PIO_IFER = inputFilter;
563 /**---------------------------------------------------------------------------- */
564 /** \fn AT91F_PIO_GetInput */
565 /** \brief Return PIO input value */
566 /**---------------------------------------------------------------------------- */
567 __inline unsigned int AT91F_PIO_GetInput( /* \return PIO input */
568 AT91PS_PIO pPio ) /* \arg pointer to a PIO controller */
570 return pPio->PIO_PDSR;
573 /**---------------------------------------------------------------------------- */
574 /** \fn AT91F_PIO_IsInputSet */
575 /** \brief Test if PIO is input flag is active */
576 /**---------------------------------------------------------------------------- */
577 __inline int AT91F_PIO_IsInputSet( AT91PS_PIO pPio, /* \arg pointer to a PIO controller */
578 unsigned int flag ) /* \arg flag to be tested */
580 return( AT91F_PIO_GetInput( pPio ) & flag );
584 /**---------------------------------------------------------------------------- */
585 /** \fn AT91F_PIO_SetOutput */
586 /** \brief Set to 1 output PIO */
587 /**---------------------------------------------------------------------------- */
588 __inline void AT91F_PIO_SetOutput( AT91PS_PIO pPio, /* \arg pointer to a PIO controller */
589 unsigned int flag ) /* \arg output to be set */
591 pPio->PIO_SODR = flag;
594 /**---------------------------------------------------------------------------- */
595 /** \fn AT91F_PIO_ClearOutput */
596 /** \brief Set to 0 output PIO */
597 /**---------------------------------------------------------------------------- */
598 __inline void AT91F_PIO_ClearOutput( AT91PS_PIO pPio, /* \arg pointer to a PIO controller */
599 unsigned int flag ) /* \arg output to be cleared */
601 pPio->PIO_CODR = flag;
604 /**---------------------------------------------------------------------------- */
605 /** \fn AT91F_PIO_ForceOutput */
606 /** \brief Force output when Direct drive option is enabled */
607 /**---------------------------------------------------------------------------- */
608 __inline void AT91F_PIO_ForceOutput( AT91PS_PIO pPio, /* \arg pointer to a PIO controller */
609 unsigned int flag ) /* \arg output to be forced */
611 pPio->PIO_ODSR = flag;
614 /**---------------------------------------------------------------------------- */
615 /** \fn AT91F_PIO_Enable */
616 /** \brief Enable PIO */
617 /**---------------------------------------------------------------------------- */
618 __inline void AT91F_PIO_Enable( AT91PS_PIO pPio, /* \arg pointer to a PIO controller */
619 unsigned int flag ) /* \arg pio to be enabled */
621 pPio->PIO_PER = flag;
624 /**---------------------------------------------------------------------------- */
625 /** \fn AT91F_PIO_Disable */
626 /** \brief Disable PIO */
627 /**---------------------------------------------------------------------------- */
628 __inline void AT91F_PIO_Disable( AT91PS_PIO pPio, /* \arg pointer to a PIO controller */
629 unsigned int flag ) /* \arg pio to be disabled */
631 pPio->PIO_PDR = flag;
634 /**---------------------------------------------------------------------------- */
635 /** \fn AT91F_PIO_GetStatus */
636 /** \brief Return PIO Status */
637 /**---------------------------------------------------------------------------- */
638 __inline unsigned int AT91F_PIO_GetStatus( /* \return PIO Status */
639 AT91PS_PIO pPio ) /* \arg pointer to a PIO controller */
641 return pPio->PIO_PSR;
644 /**---------------------------------------------------------------------------- */
645 /** \fn AT91F_PIO_IsSet */
646 /** \brief Test if PIO is Set */
647 /**---------------------------------------------------------------------------- */
648 __inline int AT91F_PIO_IsSet( AT91PS_PIO pPio, /* \arg pointer to a PIO controller */
649 unsigned int flag ) /* \arg flag to be tested */
651 return( AT91F_PIO_GetStatus( pPio ) & flag );
654 /**---------------------------------------------------------------------------- */
655 /** \fn AT91F_PIO_OutputEnable */
656 /** \brief Output Enable PIO */
657 /**---------------------------------------------------------------------------- */
658 __inline void AT91F_PIO_OutputEnable( AT91PS_PIO pPio, /* \arg pointer to a PIO controller */
659 unsigned int flag ) /* \arg pio output to be enabled */
661 pPio->PIO_OER = flag;
664 /**---------------------------------------------------------------------------- */
665 /** \fn AT91F_PIO_OutputDisable */
666 /** \brief Output Enable PIO */
667 /**---------------------------------------------------------------------------- */
668 __inline void AT91F_PIO_OutputDisable( AT91PS_PIO pPio, /* \arg pointer to a PIO controller */
669 unsigned int flag ) /* \arg pio output to be disabled */
671 pPio->PIO_ODR = flag;
674 /**---------------------------------------------------------------------------- */
675 /** \fn AT91F_PIO_GetOutputStatus */
676 /** \brief Return PIO Output Status */
677 /**---------------------------------------------------------------------------- */
678 __inline unsigned int AT91F_PIO_GetOutputStatus( /* \return PIO Output Status */
679 AT91PS_PIO pPio ) /* \arg pointer to a PIO controller */
681 return pPio->PIO_OSR;
684 /**---------------------------------------------------------------------------- */
685 /** \fn AT91F_PIO_IsOuputSet */
686 /** \brief Test if PIO Output is Set */
687 /**---------------------------------------------------------------------------- */
688 __inline int AT91F_PIO_IsOutputSet( AT91PS_PIO pPio, /* \arg pointer to a PIO controller */
689 unsigned int flag ) /* \arg flag to be tested */
691 return( AT91F_PIO_GetOutputStatus( pPio ) & flag );
694 /**---------------------------------------------------------------------------- */
695 /** \fn AT91F_PIO_InputFilterEnable */
696 /** \brief Input Filter Enable PIO */
697 /**---------------------------------------------------------------------------- */
698 __inline void AT91F_PIO_InputFilterEnable( AT91PS_PIO pPio, /* \arg pointer to a PIO controller */
699 unsigned int flag ) /* \arg pio input filter to be enabled */
701 pPio->PIO_IFER = flag;
704 /**---------------------------------------------------------------------------- */
705 /** \fn AT91F_PIO_InputFilterDisable */
706 /** \brief Input Filter Disable PIO */
707 /**---------------------------------------------------------------------------- */
708 __inline void AT91F_PIO_InputFilterDisable( AT91PS_PIO pPio, /* \arg pointer to a PIO controller */
709 unsigned int flag ) /* \arg pio input filter to be disabled */
711 pPio->PIO_IFDR = flag;
714 /**---------------------------------------------------------------------------- */
715 /** \fn AT91F_PIO_GetInputFilterStatus */
716 /** \brief Return PIO Input Filter Status */
717 /**---------------------------------------------------------------------------- */
718 __inline unsigned int AT91F_PIO_GetInputFilterStatus( /* \return PIO Input Filter Status */
719 AT91PS_PIO pPio ) /* \arg pointer to a PIO controller */
721 return pPio->PIO_IFSR;
724 /**---------------------------------------------------------------------------- */
725 /** \fn AT91F_PIO_IsInputFilterSet */
726 /** \brief Test if PIO Input filter is Set */
727 /**---------------------------------------------------------------------------- */
728 __inline int AT91F_PIO_IsInputFilterSet( AT91PS_PIO pPio, /* \arg pointer to a PIO controller */
729 unsigned int flag ) /* \arg flag to be tested */
731 return( AT91F_PIO_GetInputFilterStatus( pPio ) & flag );
734 /**---------------------------------------------------------------------------- */
735 /** \fn AT91F_PIO_GetOutputDataStatus */
736 /** \brief Return PIO Output Data Status */
737 /**---------------------------------------------------------------------------- */
738 __inline unsigned int AT91F_PIO_GetOutputDataStatus( /* \return PIO Output Data Status */
739 AT91PS_PIO pPio ) /* \arg pointer to a PIO controller */
741 return pPio->PIO_ODSR;
744 /**---------------------------------------------------------------------------- */
745 /** \fn AT91F_PIO_InterruptEnable */
746 /** \brief Enable PIO Interrupt */
747 /**---------------------------------------------------------------------------- */
748 __inline void AT91F_PIO_InterruptEnable( AT91PS_PIO pPio, /* \arg pointer to a PIO controller */
749 unsigned int flag ) /* \arg pio interrupt to be enabled */
751 pPio->PIO_IER = flag;
754 /**---------------------------------------------------------------------------- */
755 /** \fn AT91F_PIO_InterruptDisable */
756 /** \brief Disable PIO Interrupt */
757 /**---------------------------------------------------------------------------- */
758 __inline void AT91F_PIO_InterruptDisable( AT91PS_PIO pPio, /* \arg pointer to a PIO controller */
759 unsigned int flag ) /* \arg pio interrupt to be disabled */
761 pPio->PIO_IDR = flag;
764 /**---------------------------------------------------------------------------- */
765 /** \fn AT91F_PIO_GetInterruptMaskStatus */
766 /** \brief Return PIO Interrupt Mask Status */
767 /**---------------------------------------------------------------------------- */
768 __inline unsigned int AT91F_PIO_GetInterruptMaskStatus( /* \return PIO Interrupt Mask Status */
769 AT91PS_PIO pPio ) /* \arg pointer to a PIO controller */
771 return pPio->PIO_IMR;
774 /**---------------------------------------------------------------------------- */
775 /** \fn AT91F_PIO_GetInterruptStatus */
776 /** \brief Return PIO Interrupt Status */
777 /**---------------------------------------------------------------------------- */
778 __inline unsigned int AT91F_PIO_GetInterruptStatus( /* \return PIO Interrupt Status */
779 AT91PS_PIO pPio ) /* \arg pointer to a PIO controller */
781 return pPio->PIO_ISR;
784 /**---------------------------------------------------------------------------- */
785 /** \fn AT91F_PIO_IsInterruptMasked */
786 /** \brief Test if PIO Interrupt is Masked */
787 /**---------------------------------------------------------------------------- */
788 __inline int AT91F_PIO_IsInterruptMasked( AT91PS_PIO pPio, /* \arg pointer to a PIO controller */
789 unsigned int flag ) /* \arg flag to be tested */
791 return( AT91F_PIO_GetInterruptMaskStatus( pPio ) & flag );
794 /**---------------------------------------------------------------------------- */
795 /** \fn AT91F_PIO_IsInterruptSet */
796 /** \brief Test if PIO Interrupt is Set */
797 /**---------------------------------------------------------------------------- */
798 __inline int AT91F_PIO_IsInterruptSet( AT91PS_PIO pPio, /* \arg pointer to a PIO controller */
799 unsigned int flag ) /* \arg flag to be tested */
801 return( AT91F_PIO_GetInterruptStatus( pPio ) & flag );
804 /**---------------------------------------------------------------------------- */
805 /** \fn AT91F_PIO_MultiDriverEnable */
806 /** \brief Multi Driver Enable PIO */
807 /**---------------------------------------------------------------------------- */
808 __inline void AT91F_PIO_MultiDriverEnable( AT91PS_PIO pPio, /* \arg pointer to a PIO controller */
809 unsigned int flag ) /* \arg pio to be enabled */
811 pPio->PIO_MDER = flag;
814 /**---------------------------------------------------------------------------- */
815 /** \fn AT91F_PIO_MultiDriverDisable */
816 /** \brief Multi Driver Disable PIO */
817 /**---------------------------------------------------------------------------- */
818 __inline void AT91F_PIO_MultiDriverDisable( AT91PS_PIO pPio, /* \arg pointer to a PIO controller */
819 unsigned int flag ) /* \arg pio to be disabled */
821 pPio->PIO_MDDR = flag;
824 /**---------------------------------------------------------------------------- */
825 /** \fn AT91F_PIO_GetMultiDriverStatus */
826 /** \brief Return PIO Multi Driver Status */
827 /**---------------------------------------------------------------------------- */
828 __inline unsigned int AT91F_PIO_GetMultiDriverStatus( /* \return PIO Multi Driver Status */
829 AT91PS_PIO pPio ) /* \arg pointer to a PIO controller */
831 return pPio->PIO_MDSR;
834 /**---------------------------------------------------------------------------- */
835 /** \fn AT91F_PIO_IsMultiDriverSet */
836 /** \brief Test if PIO MultiDriver is Set */
837 /**---------------------------------------------------------------------------- */
838 __inline int AT91F_PIO_IsMultiDriverSet( AT91PS_PIO pPio, /* \arg pointer to a PIO controller */
839 unsigned int flag ) /* \arg flag to be tested */
841 return( AT91F_PIO_GetMultiDriverStatus( pPio ) & flag );
844 /**---------------------------------------------------------------------------- */
845 /** \fn AT91F_PIO_A_RegisterSelection */
846 /** \brief PIO A Register Selection */
847 /**---------------------------------------------------------------------------- */
848 __inline void AT91F_PIO_A_RegisterSelection( AT91PS_PIO pPio, /* \arg pointer to a PIO controller */
849 unsigned int flag ) /* \arg pio A register selection */
851 pPio->PIO_ASR = flag;
854 /**---------------------------------------------------------------------------- */
855 /** \fn AT91F_PIO_B_RegisterSelection */
856 /** \brief PIO B Register Selection */
857 /**---------------------------------------------------------------------------- */
858 __inline void AT91F_PIO_B_RegisterSelection( AT91PS_PIO pPio, /* \arg pointer to a PIO controller */
859 unsigned int flag ) /* \arg pio B register selection */
861 pPio->PIO_BSR = flag;
864 /**---------------------------------------------------------------------------- */
865 /** \fn AT91F_PIO_Get_AB_RegisterStatus */
866 /** \brief Return PIO Interrupt Status */
867 /**---------------------------------------------------------------------------- */
868 __inline unsigned int AT91F_PIO_Get_AB_RegisterStatus( /* \return PIO AB Register Status */
869 AT91PS_PIO pPio ) /* \arg pointer to a PIO controller */
871 return pPio->PIO_ABSR;
874 /**---------------------------------------------------------------------------- */
875 /** \fn AT91F_PIO_IsAB_RegisterSet */
876 /** \brief Test if PIO AB Register is Set */
877 /**---------------------------------------------------------------------------- */
878 __inline int AT91F_PIO_IsAB_RegisterSet( AT91PS_PIO pPio, /* \arg pointer to a PIO controller */
879 unsigned int flag ) /* \arg flag to be tested */
881 return( AT91F_PIO_Get_AB_RegisterStatus( pPio ) & flag );
884 /**---------------------------------------------------------------------------- */
885 /** \fn AT91F_PIO_OutputWriteEnable */
886 /** \brief Output Write Enable PIO */
887 /**---------------------------------------------------------------------------- */
888 __inline void AT91F_PIO_OutputWriteEnable( AT91PS_PIO pPio, /* \arg pointer to a PIO controller */
889 unsigned int flag ) /* \arg pio output write to be enabled */
891 pPio->PIO_OWER = flag;
894 /**---------------------------------------------------------------------------- */
895 /** \fn AT91F_PIO_OutputWriteDisable */
896 /** \brief Output Write Disable PIO */
897 /**---------------------------------------------------------------------------- */
898 __inline void AT91F_PIO_OutputWriteDisable( AT91PS_PIO pPio, /* \arg pointer to a PIO controller */
899 unsigned int flag ) /* \arg pio output write to be disabled */
901 pPio->PIO_OWDR = flag;
904 /**---------------------------------------------------------------------------- */
905 /** \fn AT91F_PIO_GetOutputWriteStatus */
906 /** \brief Return PIO Output Write Status */
907 /**---------------------------------------------------------------------------- */
908 __inline unsigned int AT91F_PIO_GetOutputWriteStatus( /* \return PIO Output Write Status */
909 AT91PS_PIO pPio ) /* \arg pointer to a PIO controller */
911 return pPio->PIO_OWSR;
914 /**---------------------------------------------------------------------------- */
915 /** \fn AT91F_PIO_IsOutputWriteSet */
916 /** \brief Test if PIO OutputWrite is Set */
917 /**---------------------------------------------------------------------------- */
918 __inline int AT91F_PIO_IsOutputWriteSet( AT91PS_PIO pPio, /* \arg pointer to a PIO controller */
919 unsigned int flag ) /* \arg flag to be tested */
921 return( AT91F_PIO_GetOutputWriteStatus( pPio ) & flag );
924 /**---------------------------------------------------------------------------- */
925 /** \fn AT91F_PIO_GetCfgPullup */
926 /** \brief Return PIO Configuration Pullup */
927 /**---------------------------------------------------------------------------- */
928 __inline unsigned int AT91F_PIO_GetCfgPullup( /* \return PIO Configuration Pullup */
929 AT91PS_PIO pPio ) /* \arg pointer to a PIO controller */
931 return pPio->PIO_PPUSR;
934 /**---------------------------------------------------------------------------- */
935 /** \fn AT91F_PIO_IsOutputDataStatusSet */
936 /** \brief Test if PIO Output Data Status is Set */
937 /**---------------------------------------------------------------------------- */
938 __inline int AT91F_PIO_IsOutputDataStatusSet( AT91PS_PIO pPio, /* \arg pointer to a PIO controller */
939 unsigned int flag ) /* \arg flag to be tested */
941 return( AT91F_PIO_GetOutputDataStatus( pPio ) & flag );
944 /**---------------------------------------------------------------------------- */
945 /** \fn AT91F_PIO_IsCfgPullupStatusSet */
946 /** \brief Test if PIO Configuration Pullup Status is Set */
947 /**---------------------------------------------------------------------------- */
948 __inline int AT91F_PIO_IsCfgPullupStatusSet( AT91PS_PIO pPio, /* \arg pointer to a PIO controller */
949 unsigned int flag ) /* \arg flag to be tested */
951 return( ~AT91F_PIO_GetCfgPullup( pPio ) & flag );
954 /* *****************************************************************************
955 * SOFTWARE API FOR PMC
956 ***************************************************************************** */
957 /**---------------------------------------------------------------------------- */
958 /** \fn AT91F_PMC_CfgSysClkEnableReg */
959 /** \brief Configure the System Clock Enable Register of the PMC controller */
960 /**---------------------------------------------------------------------------- */
961 __inline void AT91F_PMC_CfgSysClkEnableReg( AT91PS_PMC pPMC, /* \arg pointer to PMC controller */
964 /** Write to the SCER register */
965 pPMC->PMC_SCER = mode;
968 /**---------------------------------------------------------------------------- */
969 /** \fn AT91F_PMC_CfgSysClkDisableReg */
970 /** \brief Configure the System Clock Disable Register of the PMC controller */
971 /**---------------------------------------------------------------------------- */
972 __inline void AT91F_PMC_CfgSysClkDisableReg( AT91PS_PMC pPMC, /* \arg pointer to PMC controller */
975 /** Write to the SCDR register */
976 pPMC->PMC_SCDR = mode;
979 /**---------------------------------------------------------------------------- */
980 /** \fn AT91F_PMC_GetSysClkStatusReg */
981 /** \brief Return the System Clock Status Register of the PMC controller */
982 /**---------------------------------------------------------------------------- */
983 __inline unsigned int AT91F_PMC_GetSysClkStatusReg( AT91PS_PMC pPMC /* pointer to a CAN controller */
986 return pPMC->PMC_SCSR;
989 /**---------------------------------------------------------------------------- */
990 /** \fn AT91F_PMC_EnablePeriphClock */
991 /** \brief Enable peripheral clock */
992 /**---------------------------------------------------------------------------- */
993 __inline void AT91F_PMC_EnablePeriphClock( AT91PS_PMC pPMC, /* \arg pointer to PMC controller */
994 unsigned int periphIds ) /* \arg IDs of peripherals to enable */
996 pPMC->PMC_PCER = periphIds;
999 /**---------------------------------------------------------------------------- */
1000 /** \fn AT91F_PMC_DisablePeriphClock */
1001 /** \brief Disable peripheral clock */
1002 /**---------------------------------------------------------------------------- */
1003 __inline void AT91F_PMC_DisablePeriphClock( AT91PS_PMC pPMC, /* \arg pointer to PMC controller */
1004 unsigned int periphIds ) /* \arg IDs of peripherals to enable */
1006 pPMC->PMC_PCDR = periphIds;
1009 /**---------------------------------------------------------------------------- */
1010 /** \fn AT91F_PMC_GetPeriphClock */
1011 /** \brief Get peripheral clock status */
1012 /**---------------------------------------------------------------------------- */
1013 __inline unsigned int AT91F_PMC_GetPeriphClock( AT91PS_PMC pPMC ) /* \arg pointer to PMC controller */
1015 return pPMC->PMC_PCSR;
1018 /**---------------------------------------------------------------------------- */
1019 /** \fn AT91F_CKGR_CfgMainOscillatorReg */
1020 /** \brief Cfg the main oscillator */
1021 /**---------------------------------------------------------------------------- */
1022 __inline void AT91F_CKGR_CfgMainOscillatorReg( AT91PS_CKGR pCKGR, /* \arg pointer to CKGR controller */
1025 pCKGR->CKGR_MOR = mode;
1028 /**---------------------------------------------------------------------------- */
1029 /** \fn AT91F_CKGR_GetMainOscillatorReg */
1030 /** \brief Cfg the main oscillator */
1031 /**---------------------------------------------------------------------------- */
1032 __inline unsigned int AT91F_CKGR_GetMainOscillatorReg( AT91PS_CKGR pCKGR ) /* \arg pointer to CKGR controller */
1034 return pCKGR->CKGR_MOR;
1037 /**---------------------------------------------------------------------------- */
1038 /** \fn AT91F_CKGR_EnableMainOscillator */
1039 /** \brief Enable the main oscillator */
1040 /**---------------------------------------------------------------------------- */
1041 __inline void AT91F_CKGR_EnableMainOscillator( AT91PS_CKGR pCKGR ) /* \arg pointer to CKGR controller */
1043 pCKGR->CKGR_MOR |= AT91C_CKGR_MOSCEN;
1046 /**---------------------------------------------------------------------------- */
1047 /** \fn AT91F_CKGR_DisableMainOscillator */
1048 /** \brief Disable the main oscillator */
1049 /**---------------------------------------------------------------------------- */
1050 __inline void AT91F_CKGR_DisableMainOscillator( AT91PS_CKGR pCKGR ) /* \arg pointer to CKGR controller */
1052 pCKGR->CKGR_MOR &= ~AT91C_CKGR_MOSCEN;
1055 /**---------------------------------------------------------------------------- */
1056 /** \fn AT91F_CKGR_CfgMainOscStartUpTime */
1057 /** \brief Cfg MORE Register according to the main osc startup time */
1058 /**---------------------------------------------------------------------------- */
1059 __inline void AT91F_CKGR_CfgMainOscStartUpTime( AT91PS_CKGR pCKGR, /* \arg pointer to CKGR controller */
1060 unsigned int startup_time, /* \arg main osc startup time in microsecond (us) */
1061 unsigned int slowClock ) /* \arg slowClock in Hz */
1063 pCKGR->CKGR_MOR &= ~AT91C_CKGR_OSCOUNT;
1064 pCKGR->CKGR_MOR |= ( ( slowClock * startup_time ) / ( 8 * 1000000 ) ) << 8;
1067 /**---------------------------------------------------------------------------- */
1068 /** \fn AT91F_CKGR_GetMainClockFreqReg */
1069 /** \brief Cfg the main oscillator */
1070 /**---------------------------------------------------------------------------- */
1071 __inline unsigned int AT91F_CKGR_GetMainClockFreqReg( AT91PS_CKGR pCKGR ) /* \arg pointer to CKGR controller */
1073 return pCKGR->CKGR_MCFR;
1076 /**---------------------------------------------------------------------------- */
1077 /** \fn AT91F_CKGR_GetMainClock */
1078 /** \brief Return Main clock in Hz */
1079 /**---------------------------------------------------------------------------- */
1080 __inline unsigned int AT91F_CKGR_GetMainClock( AT91PS_CKGR pCKGR, /* \arg pointer to CKGR controller */
1081 unsigned int slowClock ) /* \arg slowClock in Hz */
1083 return ( ( pCKGR->CKGR_MCFR & AT91C_CKGR_MAINF ) * slowClock ) >> 4;
1086 /**---------------------------------------------------------------------------- */
1087 /** \fn AT91F_PMC_CfgMCKReg */
1088 /** \brief Cfg Master Clock Register */
1089 /**---------------------------------------------------------------------------- */
1090 __inline void AT91F_PMC_CfgMCKReg( AT91PS_PMC pPMC, /* \arg pointer to PMC controller */
1093 pPMC->PMC_MCKR = mode;
1096 /**---------------------------------------------------------------------------- */
1097 /** \fn AT91F_PMC_GetMCKReg */
1098 /** \brief Return Master Clock Register */
1099 /**---------------------------------------------------------------------------- */
1100 __inline unsigned int AT91F_PMC_GetMCKReg( AT91PS_PMC pPMC ) /* \arg pointer to PMC controller */
1102 return pPMC->PMC_MCKR;
1105 /**------------------------------------------------------------------------------ */
1106 /** \fn AT91F_PMC_GetMasterClock */
1107 /** \brief Return master clock in Hz which corresponds to processor clock for ARM7 */
1108 /**------------------------------------------------------------------------------ */
1109 __inline unsigned int AT91F_PMC_GetMasterClock( AT91PS_PMC pPMC, /* \arg pointer to PMC controller */
1110 AT91PS_CKGR pCKGR, /* \arg pointer to CKGR controller */
1111 unsigned int slowClock ) /* \arg slowClock in Hz */
1113 unsigned int reg = pPMC->PMC_MCKR;
1114 unsigned int prescaler = ( 1 << ( ( reg & AT91C_PMC_PRES ) >> 2 ) );
1115 unsigned int pllDivider, pllMultiplier;
1117 switch( reg & AT91C_PMC_CSS )
1119 case AT91C_PMC_CSS_SLOW_CLK: /* Slow clock selected */
1120 return slowClock / prescaler;
1122 case AT91C_PMC_CSS_MAIN_CLK: /* Main clock is selected */
1123 return AT91F_CKGR_GetMainClock( pCKGR, slowClock ) / prescaler;
1125 case AT91C_PMC_CSS_PLL_CLK: /* PLLB clock is selected */
1126 reg = pCKGR->CKGR_PLLR;
1127 pllDivider = ( reg & AT91C_CKGR_DIV );
1128 pllMultiplier = ( ( reg & AT91C_CKGR_MUL ) >> 16 ) + 1;
1129 return AT91F_CKGR_GetMainClock( pCKGR, slowClock ) / pllDivider * pllMultiplier / prescaler;
1135 /**---------------------------------------------------------------------------- */
1136 /** \fn AT91F_PMC_EnablePCK */
1137 /** \brief Enable peripheral clock */
1138 /**---------------------------------------------------------------------------- */
1139 __inline void AT91F_PMC_EnablePCK( AT91PS_PMC pPMC, /* \arg pointer to PMC controller */
1140 unsigned int pck, /* \arg Peripheral clock identifier 0 .. 7 */
1143 pPMC->PMC_PCKR[ pck ] = mode;
1144 pPMC->PMC_SCER = ( 1 << pck ) << 8;
1147 /**---------------------------------------------------------------------------- */
1148 /** \fn AT91F_PMC_DisablePCK */
1149 /** \brief Enable peripheral clock */
1150 /**---------------------------------------------------------------------------- */
1151 __inline void AT91F_PMC_DisablePCK( AT91PS_PMC pPMC, /* \arg pointer to PMC controller */
1152 unsigned int pck ) /* \arg Peripheral clock identifier 0 .. 7 */
1154 pPMC->PMC_SCDR = ( 1 << pck ) << 8;
1157 /**---------------------------------------------------------------------------- */
1158 /** \fn AT91F_PMC_EnableIt */
1159 /** \brief Enable PMC interrupt */
1160 /**---------------------------------------------------------------------------- */
1161 __inline void AT91F_PMC_EnableIt( AT91PS_PMC pPMC, /* pointer to a PMC controller */
1162 unsigned int flag ) /* IT to be enabled */
1164 /** Write to the IER register */
1165 pPMC->PMC_IER = flag;
1168 /**---------------------------------------------------------------------------- */
1169 /** \fn AT91F_PMC_DisableIt */
1170 /** \brief Disable PMC interrupt */
1171 /**---------------------------------------------------------------------------- */
1172 __inline void AT91F_PMC_DisableIt( AT91PS_PMC pPMC, /* pointer to a PMC controller */
1173 unsigned int flag ) /* IT to be disabled */
1175 /** Write to the IDR register */
1176 pPMC->PMC_IDR = flag;
1179 /**---------------------------------------------------------------------------- */
1180 /** \fn AT91F_PMC_GetStatus */
1181 /** \brief Return PMC Interrupt Status */
1182 /**---------------------------------------------------------------------------- */
1183 __inline unsigned int AT91F_PMC_GetStatus( /* \return PMC Interrupt Status */
1184 AT91PS_PMC pPMC ) /* pointer to a PMC controller */
1186 return pPMC->PMC_SR;
1189 /**---------------------------------------------------------------------------- */
1190 /** \fn AT91F_PMC_GetInterruptMaskStatus */
1191 /** \brief Return PMC Interrupt Mask Status */
1192 /**---------------------------------------------------------------------------- */
1193 __inline unsigned int AT91F_PMC_GetInterruptMaskStatus( /* \return PMC Interrupt Mask Status */
1194 AT91PS_PMC pPMC ) /* pointer to a PMC controller */
1196 return pPMC->PMC_IMR;
1199 /**---------------------------------------------------------------------------- */
1200 /** \fn AT91F_PMC_IsInterruptMasked */
1201 /** \brief Test if PMC Interrupt is Masked */
1202 /**---------------------------------------------------------------------------- */
1203 __inline unsigned int AT91F_PMC_IsInterruptMasked( AT91PS_PMC pPMC, /* \arg pointer to a PMC controller */
1204 unsigned int flag ) /* \arg flag to be tested */
1206 return( AT91F_PMC_GetInterruptMaskStatus( pPMC ) & flag );
1209 /**---------------------------------------------------------------------------- */
1210 /** \fn AT91F_PMC_IsStatusSet */
1211 /** \brief Test if PMC Status is Set */
1212 /**---------------------------------------------------------------------------- */
1213 __inline unsigned int AT91F_PMC_IsStatusSet( AT91PS_PMC pPMC, /* \arg pointer to a PMC controller */
1214 unsigned int flag ) /* \arg flag to be tested */
1216 return( AT91F_PMC_GetStatus( pPMC ) & flag );
1217 } /* *****************************************************************************
1218 * SOFTWARE API FOR RSTC
1219 ***************************************************************************** */
1220 /**---------------------------------------------------------------------------- */
1221 /** \fn AT91F_RSTSoftReset */
1222 /** \brief Start Software Reset */
1223 /**---------------------------------------------------------------------------- */
1224 __inline void AT91F_RSTSoftReset( AT91PS_RSTC pRSTC,
1225 unsigned int reset )
1227 pRSTC->RSTC_RCR = ( 0xA5000000 | reset );
1230 /**---------------------------------------------------------------------------- */
1231 /** \fn AT91F_RSTSetMode */
1232 /** \brief Set Reset Mode */
1233 /**---------------------------------------------------------------------------- */
1234 __inline void AT91F_RSTSetMode( AT91PS_RSTC pRSTC,
1237 pRSTC->RSTC_RMR = ( 0xA5000000 | mode );
1240 /**---------------------------------------------------------------------------- */
1241 /** \fn AT91F_RSTGetMode */
1242 /** \brief Get Reset Mode */
1243 /**---------------------------------------------------------------------------- */
1244 __inline unsigned int AT91F_RSTGetMode( AT91PS_RSTC pRSTC )
1246 return( pRSTC->RSTC_RMR );
1249 /**---------------------------------------------------------------------------- */
1250 /** \fn AT91F_RSTGetStatus */
1251 /** \brief Get Reset Status */
1252 /**---------------------------------------------------------------------------- */
1253 __inline unsigned int AT91F_RSTGetStatus( AT91PS_RSTC pRSTC )
1255 return( pRSTC->RSTC_RSR );
1258 /**---------------------------------------------------------------------------- */
1259 /** \fn AT91F_RSTIsSoftRstActive */
1260 /** \brief Return !=0 if software reset is still not completed */
1261 /**---------------------------------------------------------------------------- */
1262 __inline unsigned int AT91F_RSTIsSoftRstActive( AT91PS_RSTC pRSTC )
1264 return( ( pRSTC->RSTC_RSR ) & AT91C_RSTC_SRCMP );
1267 /* *****************************************************************************
1268 * SOFTWARE API FOR RTTC
1269 ***************************************************************************** */
1270 /**-------------------------------------------------------------------------------------- */
1271 /** \fn AT91F_SetRTT_TimeBase() */
1272 /** \brief Set the RTT prescaler according to the TimeBase in ms */
1273 /**-------------------------------------------------------------------------------------- */
1274 __inline unsigned int AT91F_RTTSetTimeBase( AT91PS_RTTC pRTTC,
1279 return 1; /* AT91C_TIME_OUT_OF_RANGE */
1282 pRTTC->RTTC_RTMR &= ~0xFFFF;
1283 pRTTC->RTTC_RTMR |= ( ( ( ms << 15 ) / 1000 ) & 0xFFFF );
1287 /**-------------------------------------------------------------------------------------- */
1288 /** \fn AT91F_RTTSetPrescaler() */
1289 /** \brief Set the new prescaler value */
1290 /**-------------------------------------------------------------------------------------- */
1291 __inline unsigned int AT91F_RTTSetPrescaler( AT91PS_RTTC pRTTC,
1292 unsigned int rtpres )
1294 pRTTC->RTTC_RTMR &= ~0xFFFF;
1295 pRTTC->RTTC_RTMR |= ( rtpres & 0xFFFF );
1296 return( pRTTC->RTTC_RTMR );
1299 /**-------------------------------------------------------------------------------------- */
1300 /** \fn AT91F_RTTRestart() */
1301 /** \brief Restart the RTT prescaler */
1302 /**-------------------------------------------------------------------------------------- */
1303 __inline void AT91F_RTTRestart( AT91PS_RTTC pRTTC )
1305 pRTTC->RTTC_RTMR |= AT91C_RTTC_RTTRST;
1309 /**-------------------------------------------------------------------------------------- */
1310 /** \fn AT91F_RTT_SetAlarmINT() */
1311 /** \brief Enable RTT Alarm Interrupt */
1312 /**-------------------------------------------------------------------------------------- */
1313 __inline void AT91F_RTTSetAlarmINT( AT91PS_RTTC pRTTC )
1315 pRTTC->RTTC_RTMR |= AT91C_RTTC_ALMIEN;
1318 /**-------------------------------------------------------------------------------------- */
1319 /** \fn AT91F_RTT_ClearAlarmINT() */
1320 /** \brief Disable RTT Alarm Interrupt */
1321 /**-------------------------------------------------------------------------------------- */
1322 __inline void AT91F_RTTClearAlarmINT( AT91PS_RTTC pRTTC )
1324 pRTTC->RTTC_RTMR &= ~AT91C_RTTC_ALMIEN;
1327 /**-------------------------------------------------------------------------------------- */
1328 /** \fn AT91F_RTT_SetRttIncINT() */
1329 /** \brief Enable RTT INC Interrupt */
1330 /**-------------------------------------------------------------------------------------- */
1331 __inline void AT91F_RTTSetRttIncINT( AT91PS_RTTC pRTTC )
1333 pRTTC->RTTC_RTMR |= AT91C_RTTC_RTTINCIEN;
1336 /**-------------------------------------------------------------------------------------- */
1337 /** \fn AT91F_RTT_ClearRttIncINT() */
1338 /** \brief Disable RTT INC Interrupt */
1339 /**-------------------------------------------------------------------------------------- */
1340 __inline void AT91F_RTTClearRttIncINT( AT91PS_RTTC pRTTC )
1342 pRTTC->RTTC_RTMR &= ~AT91C_RTTC_RTTINCIEN;
1345 /**-------------------------------------------------------------------------------------- */
1346 /** \fn AT91F_RTT_SetAlarmValue() */
1347 /** \brief Set RTT Alarm Value */
1348 /**-------------------------------------------------------------------------------------- */
1349 __inline void AT91F_RTTSetAlarmValue( AT91PS_RTTC pRTTC,
1350 unsigned int alarm )
1352 pRTTC->RTTC_RTAR = alarm;
1355 /**-------------------------------------------------------------------------------------- */
1356 /** \fn AT91F_RTT_GetAlarmValue() */
1357 /** \brief Get RTT Alarm Value */
1358 /**-------------------------------------------------------------------------------------- */
1359 __inline unsigned int AT91F_RTTGetAlarmValue( AT91PS_RTTC pRTTC )
1361 return( pRTTC->RTTC_RTAR );
1364 /**-------------------------------------------------------------------------------------- */
1365 /** \fn AT91F_RTTGetStatus() */
1366 /** \brief Read the RTT status */
1367 /**-------------------------------------------------------------------------------------- */
1368 __inline unsigned int AT91F_RTTGetStatus( AT91PS_RTTC pRTTC )
1370 return( pRTTC->RTTC_RTSR );
1373 /**-------------------------------------------------------------------------------------- */
1374 /** \fn AT91F_RTT_ReadValue() */
1375 /** \brief Read the RTT value */
1376 /**-------------------------------------------------------------------------------------- */
1377 __inline unsigned int AT91F_RTTReadValue( AT91PS_RTTC pRTTC )
1379 register volatile unsigned int val1, val2;
1383 val1 = pRTTC->RTTC_RTVR;
1384 val2 = pRTTC->RTTC_RTVR;
1386 while( val1 != val2 );
1391 /* *****************************************************************************
1392 * SOFTWARE API FOR PITC
1393 ***************************************************************************** */
1394 /**---------------------------------------------------------------------------- */
1395 /** \fn AT91F_PITInit */
1396 /** \brief System timer init : period in */