1 /**---------------------------------------------------------------------------- */
2 /** ATMEL Microcontroller Software Support - ROUSSET - */
3 /**---------------------------------------------------------------------------- */
4 /** The software is delivered "AS IS" without warranty or condition of any */
5 /** kind, either express, implied or statutory. This includes without */
6 /** limitation any warranty or condition with respect to merchantability or */
7 /** fitness for any particular purpose, or against the infringements of */
8 /** intellectual property rights of others. */
9 /**---------------------------------------------------------------------------- */
10 /** File Name : lib_AT91SAM7S64.h */
11 /** Object : AT91SAM7S64 inlined functions */
12 /** Generated : AT91 SW Application Group 07/16/2004 (07:43:09) */
14 /** CVS Reference : /lib_MC_SAM.h/1.3/Thu Mar 25 15:19:14 2004// */
15 /** CVS Reference : /lib_pdc_1363d.h/1.2/Wed Feb 19 09:25:22 2003// */
16 /** CVS Reference : /lib_dbgu.h/1.1/Fri Jan 31 12:18:40 2003// */
17 /** CVS Reference : /lib_ssc.h/1.4/Fri Jan 31 12:19:20 2003// */
18 /** CVS Reference : /lib_spi2.h/1.1/Mon Aug 25 13:23:52 2003// */
19 /** CVS Reference : /lib_PWM_SAM.h/1.3/Thu Jan 22 10:10:50 2004// */
20 /** CVS Reference : /lib_tc_1753b.h/1.1/Fri Jan 31 12:20:02 2003// */
21 /** CVS Reference : /lib_pmc_SAM.h/1.6/Tue Apr 27 13:53:52 2004// */
22 /** CVS Reference : /lib_adc.h/1.6/Fri Oct 17 08:12:38 2003// */
23 /** CVS Reference : /lib_pio.h/1.3/Fri Jan 31 12:18:56 2003// */
24 /** CVS Reference : /lib_twi.h/1.2/Fri Jan 31 12:19:38 2003// */
25 /** CVS Reference : /lib_usart.h/1.5/Thu Nov 21 16:01:54 2002// */
26 /** CVS Reference : /lib_udp.h/1.3/Fri Jan 31 12:19:48 2003// */
27 /** CVS Reference : /lib_aic.h/1.3/Fri Jul 12 07:46:12 2002// */
28 /**---------------------------------------------------------------------------- */
30 #ifndef lib_AT91SAM7S64_H
31 #define lib_AT91SAM7S64_H
33 /* *****************************************************************************
35 ***************************************************************************** */
37 #define AT91C_MC_CORRECT_KEY ( ( unsigned int ) 0x5A << 24 ) /* (MC) Correct Protect Key */
39 /**---------------------------------------------------------------------------- */
40 /** \fn AT91F_MC_Remap */
41 /** \brief Make Remap */
42 /**---------------------------------------------------------------------------- */
43 __inline void AT91F_MC_Remap( void ) /* */
45 AT91PS_MC pMC = ( AT91PS_MC ) AT91C_BASE_MC;
47 pMC->MC_RCR = AT91C_MC_RCB;
50 /**---------------------------------------------------------------------------- */
51 /** \fn AT91F_MC_EFC_CfgModeReg */
52 /** \brief Configure the EFC Mode Register of the MC controller */
53 /**---------------------------------------------------------------------------- */
54 __inline void AT91F_MC_EFC_CfgModeReg( AT91PS_MC pMC, /* pointer to a MC controller */
55 unsigned int mode ) /* mode register */
57 /* Write to the FMR register */
61 /**---------------------------------------------------------------------------- */
62 /** \fn AT91F_MC_EFC_GetModeReg */
63 /** \brief Return MC EFC Mode Register */
64 /**---------------------------------------------------------------------------- */
65 __inline unsigned int AT91F_MC_EFC_GetModeReg( AT91PS_MC pMC ) /* pointer to a MC controller */
70 /**---------------------------------------------------------------------------- */
71 /** \fn AT91F_MC_EFC_ComputeFMCN */
72 /** \brief Return MC EFC Mode Register */
73 /**---------------------------------------------------------------------------- */
74 __inline unsigned int AT91F_MC_EFC_ComputeFMCN( int master_clock ) /* master clock in Hz */
76 return( master_clock / 1000000 + 2 );
79 /**---------------------------------------------------------------------------- */
80 /** \fn AT91F_MC_EFC_PerformCmd */
81 /** \brief Perform EFC Command */
82 /**---------------------------------------------------------------------------- */
83 __inline void AT91F_MC_EFC_PerformCmd( AT91PS_MC pMC, /* pointer to a MC controller */
84 unsigned int transfer_cmd )
86 pMC->MC_FCR = transfer_cmd;
89 /**---------------------------------------------------------------------------- */
90 /** \fn AT91F_MC_EFC_GetStatus */
91 /** \brief Return MC EFC Status */
92 /**---------------------------------------------------------------------------- */
93 __inline unsigned int AT91F_MC_EFC_GetStatus( AT91PS_MC pMC ) /* pointer to a MC controller */
98 /**---------------------------------------------------------------------------- */
99 /** \fn AT91F_MC_EFC_IsInterruptMasked */
100 /** \brief Test if EFC MC Interrupt is Masked */
101 /**---------------------------------------------------------------------------- */
102 __inline unsigned int AT91F_MC_EFC_IsInterruptMasked( AT91PS_MC pMC, /* \arg pointer to a MC controller */
103 unsigned int flag ) /* \arg flag to be tested */
105 return( AT91F_MC_EFC_GetModeReg( pMC ) & flag );
108 /**---------------------------------------------------------------------------- */
109 /** \fn AT91F_MC_EFC_IsInterruptSet */
110 /** \brief Test if EFC MC Interrupt is Set */
111 /**---------------------------------------------------------------------------- */
112 __inline unsigned int AT91F_MC_EFC_IsInterruptSet( AT91PS_MC pMC, /* \arg pointer to a MC controller */
113 unsigned int flag ) /* \arg flag to be tested */
115 return( AT91F_MC_EFC_GetStatus( pMC ) & flag );
118 /* *****************************************************************************
119 * SOFTWARE API FOR PDC
120 ***************************************************************************** */
121 /**---------------------------------------------------------------------------- */
122 /** \fn AT91F_PDC_SetNextRx */
123 /** \brief Set the next receive transfer descriptor */
124 /**---------------------------------------------------------------------------- */
125 __inline void AT91F_PDC_SetNextRx( AT91PS_PDC pPDC, /* \arg pointer to a PDC controller */
126 char * address, /* \arg address to the next block to be received */
127 unsigned int bytes ) /* \arg number of bytes to be received */
129 pPDC->PDC_RNPR = ( unsigned int ) address;
130 pPDC->PDC_RNCR = bytes;
133 /**---------------------------------------------------------------------------- */
134 /** \fn AT91F_PDC_SetNextTx */
135 /** \brief Set the next transmit transfer descriptor */
136 /**---------------------------------------------------------------------------- */
137 __inline void AT91F_PDC_SetNextTx( AT91PS_PDC pPDC, /* \arg pointer to a PDC controller */
138 char * address, /* \arg address to the next block to be transmitted */
139 unsigned int bytes ) /* \arg number of bytes to be transmitted */
141 pPDC->PDC_TNPR = ( unsigned int ) address;
142 pPDC->PDC_TNCR = bytes;
145 /**---------------------------------------------------------------------------- */
146 /** \fn AT91F_PDC_SetRx */
147 /** \brief Set the receive transfer descriptor */
148 /**---------------------------------------------------------------------------- */
149 __inline void AT91F_PDC_SetRx( AT91PS_PDC pPDC, /* \arg pointer to a PDC controller */
150 char * address, /* \arg address to the next block to be received */
151 unsigned int bytes ) /* \arg number of bytes to be received */
153 pPDC->PDC_RPR = ( unsigned int ) address;
154 pPDC->PDC_RCR = bytes;
157 /**---------------------------------------------------------------------------- */
158 /** \fn AT91F_PDC_SetTx */
159 /** \brief Set the transmit transfer descriptor */
160 /**---------------------------------------------------------------------------- */
161 __inline void AT91F_PDC_SetTx( AT91PS_PDC pPDC, /* \arg pointer to a PDC controller */
162 char * address, /* \arg address to the next block to be transmitted */
163 unsigned int bytes ) /* \arg number of bytes to be transmitted */
165 pPDC->PDC_TPR = ( unsigned int ) address;
166 pPDC->PDC_TCR = bytes;
169 /**---------------------------------------------------------------------------- */
170 /** \fn AT91F_PDC_EnableTx */
171 /** \brief Enable transmit */
172 /**---------------------------------------------------------------------------- */
173 __inline void AT91F_PDC_EnableTx( AT91PS_PDC pPDC ) /* \arg pointer to a PDC controller */
175 pPDC->PDC_PTCR = AT91C_PDC_TXTEN;
178 /**---------------------------------------------------------------------------- */
179 /** \fn AT91F_PDC_EnableRx */
180 /** \brief Enable receive */
181 /**---------------------------------------------------------------------------- */
182 __inline void AT91F_PDC_EnableRx( AT91PS_PDC pPDC ) /* \arg pointer to a PDC controller */
184 pPDC->PDC_PTCR = AT91C_PDC_RXTEN;
187 /**---------------------------------------------------------------------------- */
188 /** \fn AT91F_PDC_DisableTx */
189 /** \brief Disable transmit */
190 /**---------------------------------------------------------------------------- */
191 __inline void AT91F_PDC_DisableTx( AT91PS_PDC pPDC ) /* \arg pointer to a PDC controller */
193 pPDC->PDC_PTCR = AT91C_PDC_TXTDIS;
196 /**---------------------------------------------------------------------------- */
197 /** \fn AT91F_PDC_DisableRx */
198 /** \brief Disable receive */
199 /**---------------------------------------------------------------------------- */
200 __inline void AT91F_PDC_DisableRx( AT91PS_PDC pPDC ) /* \arg pointer to a PDC controller */
202 pPDC->PDC_PTCR = AT91C_PDC_RXTDIS;
205 /**---------------------------------------------------------------------------- */
206 /** \fn AT91F_PDC_IsTxEmpty */
207 /** \brief Test if the current transfer descriptor has been sent */
208 /**---------------------------------------------------------------------------- */
209 __inline int AT91F_PDC_IsTxEmpty( /* \return return 1 if transfer is complete */
210 AT91PS_PDC pPDC ) /* \arg pointer to a PDC controller */
212 return !( pPDC->PDC_TCR );
215 /**---------------------------------------------------------------------------- */
216 /** \fn AT91F_PDC_IsNextTxEmpty */
217 /** \brief Test if the next transfer descriptor has been moved to the current td */
218 /**---------------------------------------------------------------------------- */
219 __inline int AT91F_PDC_IsNextTxEmpty( /* \return return 1 if transfer is complete */
220 AT91PS_PDC pPDC ) /* \arg pointer to a PDC controller */
222 return !( pPDC->PDC_TNCR );
225 /**---------------------------------------------------------------------------- */
226 /** \fn AT91F_PDC_IsRxEmpty */
227 /** \brief Test if the current transfer descriptor has been filled */
228 /**---------------------------------------------------------------------------- */
229 __inline int AT91F_PDC_IsRxEmpty( /* \return return 1 if transfer is complete */
230 AT91PS_PDC pPDC ) /* \arg pointer to a PDC controller */
232 return !( pPDC->PDC_RCR );
235 /**---------------------------------------------------------------------------- */
236 /** \fn AT91F_PDC_IsNextRxEmpty */
237 /** \brief Test if the next transfer descriptor has been moved to the current td */
238 /**---------------------------------------------------------------------------- */
239 __inline int AT91F_PDC_IsNextRxEmpty( /* \return return 1 if transfer is complete */
240 AT91PS_PDC pPDC ) /* \arg pointer to a PDC controller */
242 return !( pPDC->PDC_RNCR );
245 /**---------------------------------------------------------------------------- */
246 /** \fn AT91F_PDC_Open */
247 /** \brief Open PDC: disable TX and RX reset transfer descriptors, re-enable RX and TX */
248 /**---------------------------------------------------------------------------- */
249 __inline void AT91F_PDC_Open( AT91PS_PDC pPDC ) /* \arg pointer to a PDC controller */
251 /** Disable the RX and TX PDC transfer requests */
252 AT91F_PDC_DisableRx( pPDC );
253 AT91F_PDC_DisableTx( pPDC );
255 /** Reset all Counter register Next buffer first */
256 AT91F_PDC_SetNextTx( pPDC, ( char * ) 0, 0 );
257 AT91F_PDC_SetNextRx( pPDC, ( char * ) 0, 0 );
258 AT91F_PDC_SetTx( pPDC, ( char * ) 0, 0 );
259 AT91F_PDC_SetRx( pPDC, ( char * ) 0, 0 );
261 /** Enable the RX and TX PDC transfer requests */
262 AT91F_PDC_EnableRx( pPDC );
263 AT91F_PDC_EnableTx( pPDC );
266 /**---------------------------------------------------------------------------- */
267 /** \fn AT91F_PDC_Close */
268 /** \brief Close PDC: disable TX and RX reset transfer descriptors */
269 /**---------------------------------------------------------------------------- */
270 __inline void AT91F_PDC_Close( AT91PS_PDC pPDC ) /* \arg pointer to a PDC controller */
272 /** Disable the RX and TX PDC transfer requests */
273 AT91F_PDC_DisableRx( pPDC );
274 AT91F_PDC_DisableTx( pPDC );
276 /** Reset all Counter register Next buffer first */
277 AT91F_PDC_SetNextTx( pPDC, ( char * ) 0, 0 );
278 AT91F_PDC_SetNextRx( pPDC, ( char * ) 0, 0 );
279 AT91F_PDC_SetTx( pPDC, ( char * ) 0, 0 );
280 AT91F_PDC_SetRx( pPDC, ( char * ) 0, 0 );
283 /**---------------------------------------------------------------------------- */
284 /** \fn AT91F_PDC_SendFrame */
285 /** \brief Close PDC: disable TX and RX reset transfer descriptors */
286 /**---------------------------------------------------------------------------- */
287 __inline unsigned int AT91F_PDC_SendFrame( AT91PS_PDC pPDC,
289 unsigned int szBuffer,
291 unsigned int szNextBuffer )
293 if( AT91F_PDC_IsTxEmpty( pPDC ) )
295 /** Buffer and next buffer can be initialized */
296 AT91F_PDC_SetTx( pPDC, pBuffer, szBuffer );
297 AT91F_PDC_SetNextTx( pPDC, pNextBuffer, szNextBuffer );
300 else if( AT91F_PDC_IsNextTxEmpty( pPDC ) )
302 /** Only one buffer can be initialized */
303 AT91F_PDC_SetNextTx( pPDC, pBuffer, szBuffer );
308 /** All buffer are in use... */
313 /**---------------------------------------------------------------------------- */
314 /** \fn AT91F_PDC_ReceiveFrame */
315 /** \brief Close PDC: disable TX and RX reset transfer descriptors */
316 /**---------------------------------------------------------------------------- */
317 __inline unsigned int AT91F_PDC_ReceiveFrame( AT91PS_PDC pPDC,
319 unsigned int szBuffer,
321 unsigned int szNextBuffer )
323 if( AT91F_PDC_IsRxEmpty( pPDC ) )
325 /** Buffer and next buffer can be initialized */
326 AT91F_PDC_SetRx( pPDC, pBuffer, szBuffer );
327 AT91F_PDC_SetNextRx( pPDC, pNextBuffer, szNextBuffer );
330 else if( AT91F_PDC_IsNextRxEmpty( pPDC ) )
332 /** Only one buffer can be initialized */
333 AT91F_PDC_SetNextRx( pPDC, pBuffer, szBuffer );
338 /** All buffer are in use... */
343 /* *****************************************************************************
344 * SOFTWARE API FOR DBGU
345 ***************************************************************************** */
346 /**---------------------------------------------------------------------------- */
347 /** \fn AT91F_DBGU_InterruptEnable */
348 /** \brief Enable DBGU Interrupt */
349 /**---------------------------------------------------------------------------- */
350 __inline void AT91F_DBGU_InterruptEnable( AT91PS_DBGU pDbgu, /* \arg pointer to a DBGU controller */
351 unsigned int flag ) /* \arg dbgu interrupt to be enabled */
353 pDbgu->DBGU_IER = flag;
356 /**---------------------------------------------------------------------------- */
357 /** \fn AT91F_DBGU_InterruptDisable */
358 /** \brief Disable DBGU Interrupt */
359 /**---------------------------------------------------------------------------- */
360 __inline void AT91F_DBGU_InterruptDisable( AT91PS_DBGU pDbgu, /* \arg pointer to a DBGU controller */
361 unsigned int flag ) /* \arg dbgu interrupt to be disabled */
363 pDbgu->DBGU_IDR = flag;
366 /**---------------------------------------------------------------------------- */
367 /** \fn AT91F_DBGU_GetInterruptMaskStatus */
368 /** \brief Return DBGU Interrupt Mask Status */
369 /**---------------------------------------------------------------------------- */
370 __inline unsigned int AT91F_DBGU_GetInterruptMaskStatus( /* \return DBGU Interrupt Mask Status */
371 AT91PS_DBGU pDbgu ) /* \arg pointer to a DBGU controller */
373 return pDbgu->DBGU_IMR;
376 /**---------------------------------------------------------------------------- */
377 /** \fn AT91F_DBGU_IsInterruptMasked */
378 /** \brief Test if DBGU Interrupt is Masked */
379 /**---------------------------------------------------------------------------- */
380 __inline int AT91F_DBGU_IsInterruptMasked( AT91PS_DBGU pDbgu, /* \arg pointer to a DBGU controller */
381 unsigned int flag ) /* \arg flag to be tested */
383 return( AT91F_DBGU_GetInterruptMaskStatus( pDbgu ) & flag );
386 /* *****************************************************************************
387 * SOFTWARE API FOR SSC
388 ***************************************************************************** */
389 /** Define the standard I2S mode configuration */
391 /** Configuration to set in the SSC Transmit Clock Mode Register */
392 /** Parameters : nb_bit_by_slot : 8, 16 or 32 bits */
393 /** nb_slot_by_frame : number of channels */
394 #define AT91C_I2S_ASY_MASTER_TX_SETTING( nb_bit_by_slot, nb_slot_by_frame ) \
396 AT91C_SSC_CKS_DIV + \
397 AT91C_SSC_CKO_CONTINUOUS + \
398 AT91C_SSC_CKG_NONE + \
399 AT91C_SSC_START_FALL_RF + \
401 ( ( 1 << 16 ) & AT91C_SSC_STTDLY ) + \
402 ( ( ( ( nb_bit_by_slot * nb_slot_by_frame ) / 2 ) - 1 ) << 24 ) )
405 /** Configuration to set in the SSC Transmit Frame Mode Register */
406 /** Parameters : nb_bit_by_slot : 8, 16 or 32 bits */
407 /** nb_slot_by_frame : number of channels */
408 #define AT91C_I2S_ASY_TX_FRAME_SETTING( nb_bit_by_slot, nb_slot_by_frame ) \
410 ( nb_bit_by_slot - 1 ) + \
412 ( ( ( nb_slot_by_frame - 1 ) << 8 ) & AT91C_SSC_DATNB ) + \
413 ( ( ( nb_bit_by_slot - 1 ) << 16 ) & AT91C_SSC_FSLEN ) + \
414 AT91C_SSC_FSOS_NEGATIVE )
417 /**---------------------------------------------------------------------------- */
418 /** \fn AT91F_SSC_SetBaudrate */
419 /** \brief Set the baudrate according to the CPU clock */
420 /**---------------------------------------------------------------------------- */
421 __inline void AT91F_SSC_SetBaudrate( AT91PS_SSC pSSC, /* \arg pointer to a SSC controller */
422 unsigned int mainClock, /* \arg peripheral clock */
423 unsigned int speed ) /* \arg SSC baudrate */
425 unsigned int baud_value;
427 /** Define the baud rate divisor register */
434 baud_value = ( unsigned int ) ( mainClock * 10 ) / ( 2 * speed );
436 if( ( baud_value % 10 ) >= 5 )
438 baud_value = ( baud_value / 10 ) + 1;
446 pSSC->SSC_CMR = baud_value;
449 /**---------------------------------------------------------------------------- */
450 /** \fn AT91F_SSC_Configure */
451 /** \brief Configure SSC */
452 /**---------------------------------------------------------------------------- */
453 __inline void AT91F_SSC_Configure( AT91PS_SSC pSSC, /* \arg pointer to a SSC controller */
454 unsigned int syst_clock, /* \arg System Clock Frequency */
455 unsigned int baud_rate, /* \arg Expected Baud Rate Frequency */
456 unsigned int clock_rx, /* \arg Receiver Clock Parameters */
457 unsigned int mode_rx, /* \arg mode Register to be programmed */
458 unsigned int clock_tx, /* \arg Transmitter Clock Parameters */
459 unsigned int mode_tx ) /* \arg mode Register to be programmed */
461 /** Disable interrupts */
462 pSSC->SSC_IDR = ( unsigned int ) -1;
464 /** Reset receiver and transmitter */
465 pSSC->SSC_CR = AT91C_SSC_SWRST | AT91C_SSC_RXDIS | AT91C_SSC_TXDIS;
467 /** Define the Clock Mode Register */
468 AT91F_SSC_SetBaudrate( pSSC, syst_clock, baud_rate );
470 /** Write the Receive Clock Mode Register */
471 pSSC->SSC_RCMR = clock_rx;
473 /** Write the Transmit Clock Mode Register */
474 pSSC->SSC_TCMR = clock_tx;
476 /** Write the Receive Frame Mode Register */
477 pSSC->SSC_RFMR = mode_rx;
479 /** Write the Transmit Frame Mode Register */
480 pSSC->SSC_TFMR = mode_tx;
482 /** Clear Transmit and Receive Counters */
483 AT91F_PDC_Open( ( AT91PS_PDC ) &( pSSC->SSC_RPR ) );
486 /**---------------------------------------------------------------------------- */
487 /** \fn AT91F_SSC_EnableRx */
488 /** \brief Enable receiving data */
489 /**---------------------------------------------------------------------------- */
490 __inline void AT91F_SSC_EnableRx( AT91PS_SSC pSSC ) /* \arg pointer to a SSC controller */
492 /** Enable receiver */
493 pSSC->SSC_CR = AT91C_SSC_RXEN;
496 /**---------------------------------------------------------------------------- */
497 /** \fn AT91F_SSC_DisableRx */
498 /** \brief Disable receiving data */
499 /**---------------------------------------------------------------------------- */
500 __inline void AT91F_SSC_DisableRx( AT91PS_SSC pSSC ) /* \arg pointer to a SSC controller */
502 /** Disable receiver */
503 pSSC->SSC_CR = AT91C_SSC_RXDIS;
506 /**---------------------------------------------------------------------------- */
507 /** \fn AT91F_SSC_EnableTx */
508 /** \brief Enable sending data */
509 /**---------------------------------------------------------------------------- */
510 __inline void AT91F_SSC_EnableTx( AT91PS_SSC pSSC ) /* \arg pointer to a SSC controller */
512 /** Enable transmitter */
513 pSSC->SSC_CR = AT91C_SSC_TXEN;
516 /**---------------------------------------------------------------------------- */
517 /** \fn AT91F_SSC_DisableTx */
518 /** \brief Disable sending data */
519 /**---------------------------------------------------------------------------- */
520 __inline void AT91F_SSC_DisableTx( AT91PS_SSC pSSC ) /* \arg pointer to a SSC controller */
522 /** Disable transmitter */
523 pSSC->SSC_CR = AT91C_SSC_TXDIS;
526 /**---------------------------------------------------------------------------- */
527 /** \fn AT91F_SSC_EnableIt */
528 /** \brief Enable SSC IT */
529 /**---------------------------------------------------------------------------- */
530 __inline void AT91F_SSC_EnableIt( AT91PS_SSC pSSC, /* \arg pointer to a SSC controller */
531 unsigned int flag ) /* \arg IT to be enabled */
533 /** Write to the IER register */
534 pSSC->SSC_IER = flag;
537 /**---------------------------------------------------------------------------- */
538 /** \fn AT91F_SSC_DisableIt */
539 /** \brief Disable SSC IT */
540 /**---------------------------------------------------------------------------- */
541 __inline void AT91F_SSC_DisableIt( AT91PS_SSC pSSC, /* \arg pointer to a SSC controller */
542 unsigned int flag ) /* \arg IT to be disabled */
544 /** Write to the IDR register */
545 pSSC->SSC_IDR = flag;
548 /**---------------------------------------------------------------------------- */
549 /** \fn AT91F_SSC_ReceiveFrame */
550 /** \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 */
551 /**---------------------------------------------------------------------------- */
552 __inline unsigned int AT91F_SSC_ReceiveFrame( AT91PS_SSC pSSC,
554 unsigned int szBuffer,
556 unsigned int szNextBuffer )
558 return AT91F_PDC_ReceiveFrame(
559 ( AT91PS_PDC ) &( pSSC->SSC_RPR ),
566 /**---------------------------------------------------------------------------- */
567 /** \fn AT91F_SSC_SendFrame */
568 /** \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 */
569 /**---------------------------------------------------------------------------- */
570 __inline unsigned int AT91F_SSC_SendFrame( AT91PS_SSC pSSC,
572 unsigned int szBuffer,
574 unsigned int szNextBuffer )
576 return AT91F_PDC_SendFrame(
577 ( AT91PS_PDC ) &( pSSC->SSC_RPR ),
584 /**---------------------------------------------------------------------------- */
585 /** \fn AT91F_SSC_GetInterruptMaskStatus */
586 /** \brief Return SSC Interrupt Mask Status */
587 /**---------------------------------------------------------------------------- */
588 __inline unsigned int AT91F_SSC_GetInterruptMaskStatus( /* \return SSC Interrupt Mask Status */
589 AT91PS_SSC pSsc ) /* \arg pointer to a SSC controller */
591 return pSsc->SSC_IMR;
594 /**---------------------------------------------------------------------------- */
595 /** \fn AT91F_SSC_IsInterruptMasked */
596 /** \brief Test if SSC Interrupt is Masked */
597 /**---------------------------------------------------------------------------- */
598 __inline int AT91F_SSC_IsInterruptMasked( AT91PS_SSC pSsc, /* \arg pointer to a SSC controller */
599 unsigned int flag ) /* \arg flag to be tested */
601 return( AT91F_SSC_GetInterruptMaskStatus( pSsc ) & flag );
604 /* *****************************************************************************
605 * SOFTWARE API FOR SPI
606 ***************************************************************************** */
607 /**---------------------------------------------------------------------------- */
608 /** \fn AT91F_SPI_Open */
609 /** \brief Open a SPI Port */
610 /**---------------------------------------------------------------------------- */
611 __inline unsigned int AT91F_SPI_Open( const unsigned int null ) /* \arg */
613 /* NOT DEFINED AT THIS MOMENT */
617 /**---------------------------------------------------------------------------- */
618 /** \fn AT91F_SPI_CfgCs */
619 /** \brief Configure SPI chip select register */
620 /**---------------------------------------------------------------------------- */
621 __inline void AT91F_SPI_CfgCs( AT91PS_SPI pSPI, /* pointer to a SPI controller */
622 int cs, /* SPI cs number (0 to 3) */
623 int val ) /* chip select register */
625 /** Write to the CSR register */
626 *( pSPI->SPI_CSR + cs ) = val;
629 /**---------------------------------------------------------------------------- */
630 /** \fn AT91F_SPI_EnableIt */
631 /** \brief Enable SPI interrupt */
632 /**---------------------------------------------------------------------------- */
633 __inline void AT91F_SPI_EnableIt( AT91PS_SPI pSPI, /* pointer to a SPI controller */
634 unsigned int flag ) /* IT to be enabled */
636 /** Write to the IER register */
637 pSPI->SPI_IER = flag;
640 /**---------------------------------------------------------------------------- */
641 /** \fn AT91F_SPI_DisableIt */
642 /** \brief Disable SPI interrupt */
643 /**---------------------------------------------------------------------------- */
644 __inline void AT91F_SPI_DisableIt( AT91PS_SPI pSPI, /* pointer to a SPI controller */
645 unsigned int flag ) /* IT to be disabled */
647 /** Write to the IDR register */
648 pSPI->SPI_IDR = flag;
651 /**---------------------------------------------------------------------------- */
652 /** \fn AT91F_SPI_Reset */
653 /** \brief Reset the SPI controller */
654 /**---------------------------------------------------------------------------- */
655 __inline void AT91F_SPI_Reset( AT91PS_SPI pSPI /* pointer to a SPI controller */
658 /** Write to the CR register */
659 pSPI->SPI_CR = AT91C_SPI_SWRST;
662 /**---------------------------------------------------------------------------- */
663 /** \fn AT91F_SPI_Enable */
664 /** \brief Enable the SPI controller */
665 /**---------------------------------------------------------------------------- */
666 __inline void AT91F_SPI_Enable( AT91PS_SPI pSPI /* pointer to a SPI controller */
669 /** Write to the CR register */
670 pSPI->SPI_CR = AT91C_SPI_SPIEN;
673 /**---------------------------------------------------------------------------- */
674 /** \fn AT91F_SPI_Disable */
675 /** \brief Disable the SPI controller */
676 /**---------------------------------------------------------------------------- */
677 __inline void AT91F_SPI_Disable( AT91PS_SPI pSPI /* pointer to a SPI controller */
680 /** Write to the CR register */
681 pSPI->SPI_CR = AT91C_SPI_SPIDIS;
684 /**---------------------------------------------------------------------------- */
685 /** \fn AT91F_SPI_CfgMode */
686 /** \brief Enable the SPI controller */
687 /**---------------------------------------------------------------------------- */
688 __inline void AT91F_SPI_CfgMode( AT91PS_SPI pSPI, /* pointer to a SPI controller */
689 int mode ) /* mode register */
691 /** Write to the MR register */
695 /**---------------------------------------------------------------------------- */
696 /** \fn AT91F_SPI_CfgPCS */
697 /** \brief Switch to the correct PCS of SPI Mode Register : Fixed Peripheral Selected */
698 /**---------------------------------------------------------------------------- */
699 __inline void AT91F_SPI_CfgPCS( AT91PS_SPI pSPI, /* pointer to a SPI controller */
700 char PCS_Device ) /* PCS of the Device */
702 /** Write to the MR register */
703 pSPI->SPI_MR &= 0xFFF0FFFF;
704 pSPI->SPI_MR |= ( ( PCS_Device << 16 ) & AT91C_SPI_PCS );
707 /**---------------------------------------------------------------------------- */
708 /** \fn AT91F_SPI_ReceiveFrame */
709 /** \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 */
710 /**---------------------------------------------------------------------------- */
711 __inline unsigned int AT91F_SPI_ReceiveFrame( AT91PS_SPI pSPI,
713 unsigned int szBuffer,
715 unsigned int szNextBuffer )
717 return AT91F_PDC_ReceiveFrame(
718 ( AT91PS_PDC ) &( pSPI->SPI_RPR ),
725 /**---------------------------------------------------------------------------- */
726 /** \fn AT91F_SPI_SendFrame */
727 /** \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 bSPIy */
728 /**---------------------------------------------------------------------------- */
729 __inline unsigned int AT91F_SPI_SendFrame( AT91PS_SPI pSPI,
731 unsigned int szBuffer,
733 unsigned int szNextBuffer )
735 return AT91F_PDC_SendFrame(
736 ( AT91PS_PDC ) &( pSPI->SPI_RPR ),
743 /**---------------------------------------------------------------------------- */
744 /** \fn AT91F_SPI_Close */
745 /** \brief Close SPI: disable IT disable transfer, close PDC */
746 /**---------------------------------------------------------------------------- */
747 __inline void AT91F_SPI_Close( AT91PS_SPI pSPI ) /* \arg pointer to a SPI controller */
749 /** Reset all the Chip Select register */
750 pSPI->SPI_CSR[ 0 ] = 0;
751 pSPI->SPI_CSR[ 1 ] = 0;
752 pSPI->SPI_CSR[ 2 ] = 0;
753 pSPI->SPI_CSR[ 3 ] = 0;
755 /** Reset the SPI mode */
758 /** Disable all interrupts */
759 pSPI->SPI_IDR = 0xFFFFFFFF;
761 /** Abort the Peripheral Data Transfers */
762 AT91F_PDC_Close( ( AT91PS_PDC ) &( pSPI->SPI_RPR ) );
764 /** Disable receiver and transmitter and stop any activity immediately */
765 pSPI->SPI_CR = AT91C_SPI_SPIDIS;
768 /**---------------------------------------------------------------------------- */
769 /** \fn AT91F_SPI_PutChar */
770 /** \brief Send a character,does not check if ready to send */
771 /**---------------------------------------------------------------------------- */
772 __inline void AT91F_SPI_PutChar( AT91PS_SPI pSPI,
773 unsigned int character,
774 unsigned int cs_number )
776 unsigned int value_for_cs;
778 value_for_cs = ( ~( 1 << cs_number ) ) & 0xF; /*Place a zero among a 4 ONEs number */
779 pSPI->SPI_TDR = ( character & 0xFFFF ) | ( value_for_cs << 16 );
782 /**---------------------------------------------------------------------------- */
783 /** \fn AT91F_SPI_GetChar */
784 /** \brief Receive a character,does not check if a character is available */
785 /**---------------------------------------------------------------------------- */
786 __inline int AT91F_SPI_GetChar( const AT91PS_SPI pSPI )
788 return( ( pSPI->SPI_RDR ) & 0xFFFF );
791 /**---------------------------------------------------------------------------- */
792 /** \fn AT91F_SPI_GetInterruptMaskStatus */
793 /** \brief Return SPI Interrupt Mask Status */
794 /**---------------------------------------------------------------------------- */
795 __inline unsigned int AT91F_SPI_GetInterruptMaskStatus( /* \return SPI Interrupt Mask Status */
796 AT91PS_SPI pSpi ) /* \arg pointer to a SPI controller */
798 return pSpi->SPI_IMR;
801 /**---------------------------------------------------------------------------- */
802 /** \fn AT91F_SPI_IsInterruptMasked */
803 /** \brief Test if SPI Interrupt is Masked */
804 /**---------------------------------------------------------------------------- */
805 __inline int AT91F_SPI_IsInterruptMasked( AT91PS_SPI pSpi, /* \arg pointer to a SPI controller */
806 unsigned int flag ) /* \arg flag to be tested */
808 return( AT91F_SPI_GetInterruptMaskStatus( pSpi ) & flag );
811 /* *****************************************************************************
812 * SOFTWARE API FOR PWMC
813 ***************************************************************************** */
814 /**---------------------------------------------------------------------------- */
815 /** \fn AT91F_PWM_GetStatus */
816 /** \brief Return PWM Interrupt Status */
817 /**---------------------------------------------------------------------------- */
818 __inline unsigned int AT91F_PWMC_GetStatus( /* \return PWM Interrupt Status */
819 AT91PS_PWMC pPWM ) /* pointer to a PWM controller */
821 return pPWM->PWMC_SR;
824 /**---------------------------------------------------------------------------- */
825 /** \fn AT91F_PWM_InterruptEnable */
826 /** \brief Enable PWM Interrupt */
827 /**---------------------------------------------------------------------------- */
828 __inline void AT91F_PWMC_InterruptEnable( AT91PS_PWMC pPwm, /* \arg pointer to a PWM controller */
829 unsigned int flag ) /* \arg PWM interrupt to be enabled */
831 pPwm->PWMC_IER = flag;
834 /**---------------------------------------------------------------------------- */
835 /** \fn AT91F_PWM_InterruptDisable */
836 /** \brief Disable PWM Interrupt */
837 /**---------------------------------------------------------------------------- */
838 __inline void AT91F_PWMC_InterruptDisable( AT91PS_PWMC pPwm, /* \arg pointer to a PWM controller */
839 unsigned int flag ) /* \arg PWM interrupt to be disabled */
841 pPwm->PWMC_IDR = flag;
844 /**---------------------------------------------------------------------------- */
845 /** \fn AT91F_PWM_GetInterruptMaskStatus */
846 /** \brief Return PWM Interrupt Mask Status */
847 /**---------------------------------------------------------------------------- */
848 __inline unsigned int AT91F_PWMC_GetInterruptMaskStatus( /* \return PWM Interrupt Mask Status */
849 AT91PS_PWMC pPwm ) /* \arg pointer to a PWM controller */
851 return pPwm->PWMC_IMR;
854 /**---------------------------------------------------------------------------- */
855 /** \fn AT91F_PWM_IsInterruptMasked */
856 /** \brief Test if PWM Interrupt is Masked */
857 /**---------------------------------------------------------------------------- */
858 __inline unsigned int AT91F_PWMC_IsInterruptMasked( AT91PS_PWMC pPWM, /* \arg pointer to a PWM controller */
859 unsigned int flag ) /* \arg flag to be tested */
861 return( AT91F_PWMC_GetInterruptMaskStatus( pPWM ) & flag );
864 /**---------------------------------------------------------------------------- */
865 /** \fn AT91F_PWM_IsStatusSet */
866 /** \brief Test if PWM Interrupt is Set */
867 /**---------------------------------------------------------------------------- */
868 __inline unsigned int AT91F_PWMC_IsStatusSet( AT91PS_PWMC pPWM, /* \arg pointer to a PWM controller */
869 unsigned int flag ) /* \arg flag to be tested */
871 return( AT91F_PWMC_GetStatus( pPWM ) & flag );
874 /**---------------------------------------------------------------------------- */
875 /** \fn AT91F_PWM_CfgChannel */
876 /** \brief Test if PWM Interrupt is Set */
877 /**---------------------------------------------------------------------------- */
878 __inline void AT91F_PWMC_CfgChannel( AT91PS_PWMC pPWM, /* \arg pointer to a PWM controller */
879 unsigned int channelId, /* \arg PWM channel ID */
880 unsigned int mode, /* \arg PWM mode */
881 unsigned int period, /* \arg PWM period */
882 unsigned int duty ) /* \arg PWM duty cycle */
884 pPWM->PWMC_CH[ channelId ].PWMC_CMR = mode;
885 pPWM->PWMC_CH[ channelId ].PWMC_CDTYR = duty;
886 pPWM->PWMC_CH[ channelId ].PWMC_CPRDR = period;
889 /**---------------------------------------------------------------------------- */
890 /** \fn AT91F_PWM_StartChannel */
891 /** \brief Enable channel */
892 /**---------------------------------------------------------------------------- */
893 __inline void AT91F_PWMC_StartChannel( AT91PS_PWMC pPWM, /* \arg pointer to a PWM controller */
894 unsigned int flag ) /* \arg Channels IDs to be enabled */
896 pPWM->PWMC_ENA = flag;
899 /**---------------------------------------------------------------------------- */
900 /** \fn AT91F_PWM_StopChannel */
901 /** \brief Disable channel */
902 /**---------------------------------------------------------------------------- */
903 __inline void AT91F_PWMC_StopChannel( AT91PS_PWMC pPWM, /* \arg pointer to a PWM controller */
904 unsigned int flag ) /* \arg Channels IDs to be enabled */
906 pPWM->PWMC_DIS = flag;
909 /**---------------------------------------------------------------------------- */
910 /** \fn AT91F_PWM_UpdateChannel */
911 /** \brief Update Period or Duty Cycle */
912 /**---------------------------------------------------------------------------- */
913 __inline void AT91F_PWMC_UpdateChannel( AT91PS_PWMC pPWM, /* \arg pointer to a PWM controller */
914 unsigned int channelId, /* \arg PWM channel ID */
915 unsigned int update ) /* \arg Channels IDs to be enabled */
917 pPWM->PWMC_CH[ channelId ].PWMC_CUPDR = update;
920 /* *****************************************************************************
921 * SOFTWARE API FOR TC
922 ***************************************************************************** */
923 /**---------------------------------------------------------------------------- */
924 /** \fn AT91F_TC_InterruptEnable */
925 /** \brief Enable TC Interrupt */
926 /**---------------------------------------------------------------------------- */
927 __inline void AT91F_TC_InterruptEnable( AT91PS_TC pTc, /* \arg pointer to a TC controller */
928 unsigned int flag ) /* \arg TC interrupt to be enabled */
933 /**---------------------------------------------------------------------------- */
934 /** \fn AT91F_TC_InterruptDisable */
935 /** \brief Disable TC Interrupt */
936 /**---------------------------------------------------------------------------- */
937 __inline void AT91F_TC_InterruptDisable( AT91PS_TC pTc, /* \arg pointer to a TC controller */
938 unsigned int flag ) /* \arg TC interrupt to be disabled */
943 /**---------------------------------------------------------------------------- */
944 /** \fn AT91F_TC_GetInterruptMaskStatus */
945 /** \brief Return TC Interrupt Mask Status */
946 /**---------------------------------------------------------------------------- */
947 __inline unsigned int AT91F_TC_GetInterruptMaskStatus( /* \return TC Interrupt Mask Status */
948 AT91PS_TC pTc ) /* \arg pointer to a TC controller */
953 /**---------------------------------------------------------------------------- */
954 /** \fn AT91F_TC_IsInterruptMasked */
955 /** \brief Test if TC Interrupt is Masked */
956 /**---------------------------------------------------------------------------- */
957 __inline int AT91F_TC_IsInterruptMasked( AT91PS_TC pTc, /* \arg pointer to a TC controller */
958 unsigned int flag ) /* \arg flag to be tested */
960 return( AT91F_TC_GetInterruptMaskStatus( pTc ) & flag );
963 /* *****************************************************************************
964 * SOFTWARE API FOR PMC
965 ***************************************************************************** */
966 /**---------------------------------------------------------------------------- */
967 /** \fn AT91F_PMC_CfgSysClkEnableReg */
968 /** \brief Configure the System Clock Enable Register of the PMC controller */
969 /**---------------------------------------------------------------------------- */
970 __inline void AT91F_PMC_CfgSysClkEnableReg( AT91PS_PMC pPMC, /* \arg pointer to PMC controller */
973 /** Write to the SCER register */
974 pPMC->PMC_SCER = mode;
977 /**---------------------------------------------------------------------------- */
978 /** \fn AT91F_PMC_CfgSysClkDisableReg */
979 /** \brief Configure the System Clock Disable Register of the PMC controller */
980 /**---------------------------------------------------------------------------- */
981 __inline void AT91F_PMC_CfgSysClkDisableReg( AT91PS_PMC pPMC, /* \arg pointer to PMC controller */
984 /** Write to the SCDR register */
985 pPMC->PMC_SCDR = mode;
988 /**---------------------------------------------------------------------------- */
989 /** \fn AT91F_PMC_GetSysClkStatusReg */
990 /** \brief Return the System Clock Status Register of the PMC controller */
991 /**---------------------------------------------------------------------------- */
992 __inline unsigned int AT91F_PMC_GetSysClkStatusReg( AT91PS_PMC pPMC /* pointer to a CAN controller */
995 return pPMC->PMC_SCSR;
998 /**---------------------------------------------------------------------------- */
999 /** \fn AT91F_PMC_EnablePeriphClock */
1000 /** \brief Enable peripheral clock */
1001 /**---------------------------------------------------------------------------- */
1002 __inline void AT91F_PMC_EnablePeriphClock( AT91PS_PMC pPMC, /* \arg pointer to PMC controller */
1003 unsigned int periphIds ) /* \arg IDs of peripherals to enable */
1005 pPMC->PMC_PCER = periphIds;
1008 /**---------------------------------------------------------------------------- */
1009 /** \fn AT91F_PMC_DisablePeriphClock */
1010 /** \brief Disable peripheral clock */
1011 /**---------------------------------------------------------------------------- */
1012 __inline void AT91F_PMC_DisablePeriphClock( AT91PS_PMC pPMC, /* \arg pointer to PMC controller */
1013 unsigned int periphIds ) /* \arg IDs of peripherals to enable */
1015 pPMC->PMC_PCDR = periphIds;
1018 /**---------------------------------------------------------------------------- */
1019 /** \fn AT91F_PMC_GetPeriphClock */
1020 /** \brief Get peripheral clock status */
1021 /**---------------------------------------------------------------------------- */
1022 __inline unsigned int AT91F_PMC_GetPeriphClock( AT91PS_PMC pPMC ) /* \arg pointer to PMC controller */
1024 return pPMC->PMC_PCSR;
1027 /**---------------------------------------------------------------------------- */
1028 /** \fn AT91F_CKGR_CfgMainOscillatorReg */
1029 /** \brief Cfg the main oscillator */
1030 /**---------------------------------------------------------------------------- */
1031 __inline void AT91F_CKGR_CfgMainOscillatorReg( AT91PS_CKGR pCKGR, /* \arg pointer to CKGR controller */
1034 pCKGR->CKGR_MOR = mode;
1037 /**---------------------------------------------------------------------------- */
1038 /** \fn AT91F_CKGR_GetMainOscillatorReg */
1039 /** \brief Cfg the main oscillator */
1040 /**---------------------------------------------------------------------------- */
1041 __inline unsigned int AT91F_CKGR_GetMainOscillatorReg( AT91PS_CKGR pCKGR ) /* \arg pointer to CKGR controller */
1043 return pCKGR->CKGR_MOR;
1046 /**---------------------------------------------------------------------------- */
1047 /** \fn AT91F_CKGR_EnableMainOscillator */
1048 /** \brief Enable the main oscillator */
1049 /**---------------------------------------------------------------------------- */
1050 __inline void AT91F_CKGR_EnableMainOscillator( AT91PS_CKGR pCKGR ) /* \arg pointer to CKGR controller */
1052 pCKGR->CKGR_MOR |= AT91C_CKGR_MOSCEN;
1055 /**---------------------------------------------------------------------------- */
1056 /** \fn AT91F_CKGR_DisableMainOscillator */
1057 /** \brief Disable the main oscillator */
1058 /**---------------------------------------------------------------------------- */
1059 __inline void AT91F_CKGR_DisableMainOscillator( AT91PS_CKGR pCKGR ) /* \arg pointer to CKGR controller */
1061 pCKGR->CKGR_MOR &= ~AT91C_CKGR_MOSCEN;
1064 /**---------------------------------------------------------------------------- */
1065 /** \fn AT91F_CKGR_CfgMainOscStartUpTime */
1066 /** \brief Cfg MORE Register according to the main osc startup time */
1067 /**---------------------------------------------------------------------------- */
1068 __inline void AT91F_CKGR_CfgMainOscStartUpTime( AT91PS_CKGR pCKGR, /* \arg pointer to CKGR controller */
1069 unsigned int startup_time, /* \arg main osc startup time in microsecond (us) */
1070 unsigned int slowClock ) /* \arg slowClock in Hz */
1072 pCKGR->CKGR_MOR &= ~AT91C_CKGR_OSCOUNT;
1073 pCKGR->CKGR_MOR |= ( ( slowClock * startup_time ) / ( 8 * 1000000 ) ) << 8;
1076 /**---------------------------------------------------------------------------- */
1077 /** \fn AT91F_CKGR_GetMainClockFreqReg */
1078 /** \brief Cfg the main oscillator */
1079 /**---------------------------------------------------------------------------- */
1080 __inline unsigned int AT91F_CKGR_GetMainClockFreqReg( AT91PS_CKGR pCKGR ) /* \arg pointer to CKGR controller */
1082 return pCKGR->CKGR_MCFR;
1085 /**---------------------------------------------------------------------------- */
1086 /** \fn AT91F_CKGR_GetMainClock */
1087 /** \brief Return Main clock in Hz */
1088 /**---------------------------------------------------------------------------- */
1089 __inline unsigned int AT91F_CKGR_GetMainClock( AT91PS_CKGR pCKGR, /* \arg pointer to CKGR controller */
1090 unsigned int slowClock ) /* \arg slowClock in Hz */
1092 return ( ( pCKGR->CKGR_MCFR & AT91C_CKGR_MAINF ) * slowClock ) >> 4;
1095 /**---------------------------------------------------------------------------- */
1096 /** \fn AT91F_PMC_CfgMCKReg */
1097 /** \brief Cfg Master Clock Register */
1098 /**---------------------------------------------------------------------------- */
1099 __inline void AT91F_PMC_CfgMCKReg( AT91PS_PMC pPMC, /* \arg pointer to PMC controller */
1102 pPMC->PMC_MCKR = mode;
1105 /**---------------------------------------------------------------------------- */
1106 /** \fn AT91F_PMC_GetMCKReg */
1107 /** \brief Return Master Clock Register */
1108 /**---------------------------------------------------------------------------- */
1109 __inline unsigned int AT91F_PMC_GetMCKReg( AT91PS_PMC pPMC ) /* \arg pointer to PMC controller */
1111 return pPMC->PMC_MCKR;
1114 /**------------------------------------------------------------------------------ */
1115 /** \fn AT91F_PMC_GetMasterClock */
1116 /** \brief Return master clock in Hz which corresponds to processor clock for ARM7 */
1117 /**------------------------------------------------------------------------------ */
1118 __inline unsigned int AT91F_PMC_GetMasterClock( AT91PS_PMC pPMC, /* \arg pointer to PMC controller */
1119 AT91PS_CKGR pCKGR, /* \arg pointer to CKGR controller */
1120 unsigned int slowClock ) /* \arg slowClock in Hz */
1122 unsigned int reg = pPMC->PMC_MCKR;
1123 unsigned int prescaler = ( 1 << ( ( reg & AT91C_PMC_PRES ) >> 2 ) );
1124 unsigned int pllDivider, pllMultiplier;
1126 switch( reg & AT91C_PMC_CSS )
1128 case AT91C_PMC_CSS_SLOW_CLK: /* Slow clock selected */
1129 return slowClock / prescaler;
1131 case AT91C_PMC_CSS_MAIN_CLK: /* Main clock is selected */
1132 return AT91F_CKGR_GetMainClock( pCKGR, slowClock ) / prescaler;
1134 case AT91C_PMC_CSS_PLL_CLK: /* PLLB clock is selected */
1135 reg = pCKGR->CKGR_PLLR;
1136 pllDivider = ( reg & AT91C_CKGR_DIV );
1137 pllMultiplier = ( ( reg & AT91C_CKGR_MUL ) >> 16 ) + 1;
1138 return AT91F_CKGR_GetMainClock( pCKGR, slowClock ) / pllDivider * pllMultiplier / prescaler;
1144 /**---------------------------------------------------------------------------- */
1145 /** \fn AT91F_PMC_EnablePCK */
1146 /** \brief Enable peripheral clock */
1147 /**---------------------------------------------------------------------------- */
1148 __inline void AT91F_PMC_EnablePCK( AT91PS_PMC pPMC, /* \arg pointer to PMC controller */
1149 unsigned int pck, /* \arg Peripheral clock identifier 0 .. 7 */
1152 pPMC->PMC_PCKR[ pck ] = mode;
1153 pPMC->PMC_SCER = ( 1 << pck ) << 8;
1156 /**---------------------------------------------------------------------------- */
1157 /** \fn AT91F_PMC_DisablePCK */
1158 /** \brief Enable peripheral clock */
1159 /**---------------------------------------------------------------------------- */
1160 __inline void AT91F_PMC_DisablePCK( AT91PS_PMC pPMC, /* \arg pointer to PMC controller */
1161 unsigned int pck ) /* \arg Peripheral clock identifier 0 .. 7 */
1163 pPMC->PMC_SCDR = ( 1 << pck ) << 8;
1166 /**---------------------------------------------------------------------------- */
1167 /** \fn AT91F_PMC_EnableIt */
1168 /** \brief Enable PMC interrupt */
1169 /**---------------------------------------------------------------------------- */
1170 __inline void AT91F_PMC_EnableIt( AT91PS_PMC pPMC, /* pointer to a PMC controller */
1171 unsigned int flag ) /* IT to be enabled */
1173 /** Write to the IER register */
1174 pPMC->PMC_IER = flag;
1177 /**---------------------------------------------------------------------------- */
1178 /** \fn AT91F_PMC_DisableIt */
1179 /** \brief Disable PMC interrupt */
1180 /**---------------------------------------------------------------------------- */
1181 __inline void AT91F_PMC_DisableIt( AT91PS_PMC pPMC, /* pointer to a PMC controller */
1182 unsigned int flag ) /* IT to be disabled */
1184 /** Write to the IDR register */
1185 pPMC->PMC_IDR = flag;
1188 /**---------------------------------------------------------------------------- */
1189 /** \fn AT91F_PMC_GetStatus */
1190 /** \brief Return PMC Interrupt Status */
1191 /**---------------------------------------------------------------------------- */
1192 __inline unsigned int AT91F_PMC_GetStatus( /* \return PMC Interrupt Status */
1193 AT91PS_PMC pPMC ) /* pointer to a PMC controller */
1195 return pPMC->PMC_SR;
1198 /**---------------------------------------------------------------------------- */
1199 /** \fn AT91F_PMC_GetInterruptMaskStatus */
1200 /** \brief Return PMC Interrupt Mask Status */
1201 /**---------------------------------------------------------------------------- */
1202 __inline unsigned int AT91F_PMC_GetInterruptMaskStatus( /* \return PMC Interrupt Mask Status */
1203 AT91PS_PMC pPMC ) /* pointer to a PMC controller */
1205 return pPMC->PMC_IMR;
1208 /**---------------------------------------------------------------------------- */
1209 /** \fn AT91F_PMC_IsInterruptMasked */
1210 /** \brief Test if PMC Interrupt is Masked */
1211 /**---------------------------------------------------------------------------- */
1212 __inline unsigned int AT91F_PMC_IsInterruptMasked( AT91PS_PMC pPMC, /* \arg pointer to a PMC controller */
1213 unsigned int flag ) /* \arg flag to be tested */
1215 return( AT91F_PMC_GetInterruptMaskStatus( pPMC ) & flag );
1218 /**---------------------------------------------------------------------------- */
1219 /** \fn AT91F_PMC_IsStatusSet */
1220 /** \brief Test if PMC Status is Set */
1221 /**---------------------------------------------------------------------------- */
1222 __inline unsigned int AT91F_PMC_IsStatusSet( AT91PS_PMC pPMC, /* \arg pointer to a PMC controller */
1223 unsigned int flag ) /* \arg flag to be tested */
1225 return( AT91F_PMC_GetStatus( pPMC ) & flag );
1226 } /* *****************************************************************************
1227 * SOFTWARE API FOR ADC
1228 ***************************************************************************** */
1229 /**---------------------------------------------------------------------------- */
1230 /** \fn AT91F_ADC_EnableIt */
1231 /** \brief Enable ADC interrupt */
1232 /**---------------------------------------------------------------------------- */
1233 __inline void AT91F_ADC_EnableIt( AT91PS_ADC pADC, /* pointer to a ADC controller */
1234 unsigned int flag ) /* IT to be enabled */
1236 /** Write to the IER register */
1237 pADC->ADC_IER = flag;
1240 /**---------------------------------------------------------------------------- */
1241 /** \fn AT91F_ADC_DisableIt */
1242 /** \brief Disable ADC interrupt */
1243 /**---------------------------------------------------------------------------- */
1244 __inline void AT91F_ADC_DisableIt( AT91PS_ADC pADC, /* pointer to a ADC controller */
1245 unsigned int flag ) /* IT to be disabled */
1247 /** Write to the IDR register */
1248 pADC->ADC_IDR = flag;
1251 /**---------------------------------------------------------------------------- */
1252 /** \fn AT91F_ADC_GetStatus */
1253 /** \brief Return ADC Interrupt Status */
1254 /**---------------------------------------------------------------------------- */
1255 __inline unsigned int AT91F_ADC_GetStatus( /* \return ADC Interrupt Status */
1256 AT91PS_ADC pADC ) /* pointer to a ADC controller */
1258 return pADC->ADC_SR;
1261 /**---------------------------------------------------------------------------- */
1262 /** \fn AT91F_ADC_GetInterruptMaskStatus */
1263 /** \brief Return ADC Interrupt Mask Status */
1264 /**---------------------------------------------------------------------------- */
1265 __inline unsigned int AT91F_ADC_GetInterruptMaskStatus( /* \return ADC Interrupt Mask Status */
1266 AT91PS_ADC pADC ) /* pointer to a ADC controller */
1268 return pADC->ADC_IMR;
1271 /**---------------------------------------------------------------------------- */
1272 /** \fn AT91F_ADC_IsInterruptMasked */
1273 /** \brief Test if ADC Interrupt is Masked */
1274 /**---------------------------------------------------------------------------- */
1275 __inline unsigned int AT91F_ADC_IsInterruptMasked( AT91PS_ADC pADC, /* \arg pointer to a ADC controller */
1276 unsigned int flag ) /* \arg flag to be tested */
1278 return( AT91F_ADC_GetInterruptMaskStatus( pADC ) & flag );
1281 /**---------------------------------------------------------------------------- */
1282 /** \fn AT91F_ADC_IsStatusSet */
1283 /** \brief Test if ADC Status is Set */
1284 /**---------------------------------------------------------------------------- */
1285 __inline unsigned int AT91F_ADC_IsStatusSet( AT91PS_ADC pADC, /* \arg pointer to a ADC controller */
1286 unsigned int flag ) /* \arg flag to be tested */
1288 return( AT91F_ADC_GetStatus( pADC ) & flag );
1291 /**---------------------------------------------------------------------------- */
1292 /** \fn AT91F_ADC_CfgModeReg */
1293 /** \brief Configure the Mode Register of the ADC controller */
1294 /**---------------------------------------------------------------------------- */
1295 __inline void AT91F_ADC_CfgModeReg( AT91PS_ADC pADC, /* pointer to a ADC controller */
1296 unsigned int mode ) /* mode register */
1298 /** Write to the MR register */
1299 pADC->ADC_MR = mode;
1302 /**---------------------------------------------------------------------------- */
1303 /** \fn AT91F_ADC_GetModeReg */
1304 /** \brief Return the Mode Register of the ADC controller value */
1305 /**---------------------------------------------------------------------------- */
1306 __inline unsigned int AT91F_ADC_GetModeReg( AT91PS_ADC pADC /* pointer to a ADC controller */
1309 return pADC->ADC_MR;
1312 /**---------------------------------------------------------------------------- */
1313 /** \fn AT91F_ADC_CfgTimings */
1314 /** \brief Configure the different necessary timings of the ADC controller */
1315 /**---------------------------------------------------------------------------- */
1316 __inline void AT91F_ADC_CfgTimings( AT91PS_ADC pADC, /* pointer to a ADC controller */
1317 unsigned int mck_clock, /* in MHz */
1318 unsigned int adc_clock, /* in MHz */
1319 unsigned int startup_time, /* in us */
1320 unsigned int sample_and_hold_time ) /* in ns */
1322 unsigned int prescal, startup, shtim;
1324 prescal = mck_clock / ( 2 * adc_clock ) - 1;
1325 startup = adc_clock * startup_time / 8 - 1;
1326 shtim = adc_clock * sample_and_hold_time / 1000 - 1;
1328 /** Write to the MR register */
1329 pADC->ADC_MR = ( ( prescal << 8 ) & AT91C_ADC_PRESCAL ) | ( ( startup << 16 ) & AT91C_ADC_STARTUP ) | ( ( shtim << 24 ) & AT91C_ADC_SHTIM );
1332 /**---------------------------------------------------------------------------- */
1333 /** \fn AT91F_ADC_EnableChannel */
1334 /** \brief Return ADC Timer Register Value */
1335 /**---------------------------------------------------------------------------- */
1336 __inline void AT91F_ADC_EnableChannel( AT91PS_ADC pADC, /* pointer to a ADC controller */
1337 unsigned int channel ) /* mode register */
1339 /** Write to the CHER register */
1340 pADC->ADC_CHER = channel;
1343 /**---------------------------------------------------------------------------- */
1344 /** \fn AT91F_ADC_DisableChannel */
1345 /** \brief Return ADC Timer Register Value */
1346 /**---------------------------------------------------------------------------- */
1347 __inline void AT91F_ADC_DisableChannel( AT91PS_ADC pADC, /* pointer to a ADC controller */
1348 unsigned int channel ) /* mode register */
1350 /** Write to the CHDR register */
1351 pADC->ADC_CHDR = channel;
1354 /**---------------------------------------------------------------------------- */
1355 /** \fn AT91F_ADC_GetChannelStatus */
1356 /** \brief Return ADC Timer Register Value */
1357 /**---------------------------------------------------------------------------- */
1358 __inline unsigned int AT91F_ADC_GetChannelStatus( AT91PS_ADC pADC /* pointer to a ADC controller */
1361 return pADC->ADC_CHSR;
1364 /**---------------------------------------------------------------------------- */
1365 /** \fn AT91F_ADC_StartConversion */
1366 /** \brief Software request for a analog to digital conversion */
1367 /**---------------------------------------------------------------------------- */
1368 __inline void AT91F_ADC_StartConversion( AT91PS_ADC pADC /* pointer to a ADC controller */
1371 pADC->ADC_CR = AT91C_ADC_START;
1374 /**---------------------------------------------------------------------------- */
1375 /** \fn AT91F_ADC_SoftReset */
1376 /** \brief Software reset */
1377 /**---------------------------------------------------------------------------- */
1378 __inline void AT91F_ADC_SoftReset( AT91PS_ADC pADC /* pointer to a ADC controller */
1381 pADC->ADC_CR = AT91C_ADC_SWRST;
1384 /**---------------------------------------------------------------------------- */
1385 /** \fn AT91F_ADC_GetLastConvertedData */
1386 /** \brief Return the Last Converted Data */
1387 /**---------------------------------------------------------------------------- */
1388 __inline unsigned int AT91F_ADC_GetLastConvertedData( AT91PS_ADC pADC /* pointer to a ADC controller */
1391 return pADC->ADC_LCDR;
1394 /**---------------------------------------------------------------------------- */
1395 /** \fn AT91F_ADC_GetConvertedDataCH0 */
1396 /** \brief Return the Channel 0 Converted Data */
1397 /**---------------------------------------------------------------------------- */
1398 __inline unsigned int AT91F_ADC_GetConvertedDataCH0( AT91PS_ADC pADC /* pointer to a ADC controller */
1401 return pADC->ADC_CDR0;
1404 /**---------------------------------------------------------------------------- */
1405 /** \fn AT91F_ADC_GetConvertedDataCH1 */
1406 /** \brief Return the Channel 1 Converted Data */
1407 /**---------------------------------------------------------------------------- */
1408 __inline unsigned int AT91F_ADC_GetConvertedDataCH1( AT91PS_ADC pADC /* pointer to a ADC controller */
1411 return pADC->ADC_CDR1;
1414 /**---------------------------------------------------------------------------- */
1415 /** \fn AT91F_ADC_GetConvertedDataCH2 */
1416 /** \brief Return the Channel 2 Converted Data */
1417 /**---------------------------------------------------------------------------- */
1418 __inline unsigned int AT91F_ADC_GetConvertedDataCH2( AT91PS_ADC pADC /* pointer to a ADC controller */
1421 return pADC->ADC_CDR2;
1424 /**---------------------------------------------------------------------------- */
1425 /** \fn AT91F_ADC_GetConvertedDataCH3 */
1426 /** \brief Return the Channel 3 Converted Data */
1427 /**---------------------------------------------------------------------------- */
1428 __inline unsigned int AT91F_ADC_GetConvertedDataCH3( AT91PS_ADC pADC /* pointer to a ADC controller */
1431 return pADC->ADC_CDR3;
1434 /**---------------------------------------------------------------------------- */
1435 /** \fn AT91F_ADC_GetConvertedDataCH4 */
1436 /** \brief Return the Channel 4 Converted Data */
1437 /**---------------------------------------------------------------------------- */
1438 __inline unsigned int AT91F_ADC_GetConvertedDataCH4( AT91PS_ADC pADC /* pointer to a ADC controller */
1441 return pADC->ADC_CDR4;
1444 /**---------------------------------------------------------------------------- */
1445 /** \fn AT91F_ADC_GetConvertedDataCH5 */
1446 /** \brief Return the Channel 5 Converted Data */
1447 /**---------------------------------------------------------------------------- */
1448 __inline unsigned int AT91F_ADC_GetConvertedDataCH5( AT91PS_ADC pADC /* pointer to a ADC controller */
1451 return pADC->ADC_CDR5;
1454 /**---------------------------------------------------------------------------- */
1455 /** \fn AT91F_ADC_GetConvertedDataCH6 */
1456 /** \brief Return the Channel 6 Converted Data */
1457 /**---------------------------------------------------------------------------- */
1458 __inline unsigned int AT91F_ADC_GetConvertedDataCH6( AT91PS_ADC pADC /* pointer to a ADC controller */
1461 return pADC->ADC_CDR6;
1464 /**---------------------------------------------------------------------------- */
1465 /** \fn AT91F_ADC_GetConvertedDataCH7 */
1466 /** \brief Return the Channel 7 Converted Data */
1467 /**---------------------------------------------------------------------------- */
1468 __inline unsigned int AT91F_ADC_GetConvertedDataCH7( AT91PS_ADC pADC /* pointer to a ADC controller */
1471 return pADC->ADC_CDR7;
1474 /* *****************************************************************************
1475 * SOFTWARE API FOR PIO
1476 ***************************************************************************** */
1477 /**---------------------------------------------------------------------------- */
1478 /** \fn AT91F_PIO_CfgPeriph */
1479 /** \brief Enable pins to be derived by peripheral */
1480 /**---------------------------------------------------------------------------- */
1481 __inline void AT91F_PIO_CfgPeriph( AT91PS_PIO pPio, /* \arg pointer to a PIO controller */
1482 unsigned int periphAEnable, /* \arg PERIPH A to enable */
1483 unsigned int periphBEnable ) /* \arg PERIPH B to enable */
1486 pPio->PIO_ASR = periphAEnable;
1487 pPio->PIO_BSR = periphBEnable;
1488 pPio->PIO_PDR = ( periphAEnable | periphBEnable ); /* Set in Periph mode */
1491 /**---------------------------------------------------------------------------- */
1492 /** \fn AT91F_PIO_CfgOutput */
1493 /** \brief Enable PIO in output mode */
1494 /**---------------------------------------------------------------------------- */
1495 __inline void AT91F_PIO_CfgOutput( AT91PS_PIO pPio, /* \arg pointer to a PIO controller */
1496 unsigned int pioEnable ) /* \arg PIO to be enabled */
1498 pPio->PIO_PER = pioEnable; /* Set in PIO mode */
1499 pPio->PIO_OER = pioEnable; /* Configure in Output */
1502 /**---------------------------------------------------------------------------- */
1503 /** \fn AT91F_PIO_CfgInput */
1504 /** \brief Enable PIO in input mode */
1505 /**---------------------------------------------------------------------------- */
1506 __inline void AT91F_PIO_CfgInput( AT91PS_PIO pPio, /* \arg pointer to a PIO controller */
1507 unsigned int inputEnable ) /* \arg PIO to be enabled */
1509 /* Disable output */
1510 pPio->PIO_ODR = inputEnable;
1511 pPio->PIO_PER = inputEnable;
1514 /**---------------------------------------------------------------------------- */
1515 /** \fn AT91F_PIO_CfgOpendrain */
1516 /** \brief Configure PIO in open drain */
1517 /**---------------------------------------------------------------------------- */
1518 __inline void AT91F_PIO_CfgOpendrain( AT91PS_PIO pPio, /* \arg pointer to a PIO controller */
1519 unsigned int multiDrvEnable ) /* \arg pio to be configured in open drain */
1521 /* Configure the multi-drive option */
1522 pPio->PIO_MDDR = ~multiDrvEnable;
1523 pPio->PIO_MDER = multiDrvEnable;
1526 /**---------------------------------------------------------------------------- */
1527 /** \fn AT91F_PIO_CfgPullup */
1528 /** \brief Enable pullup on PIO */
1529 /**---------------------------------------------------------------------------- */
1530 __inline void AT91F_PIO_CfgPullup( AT91PS_PIO pPio, /* \arg pointer to a PIO controller */
1531 unsigned int pullupEnable ) /* \arg enable pullup on PIO */
1533 /* Connect or not Pullup */
1534 pPio->PIO_PPUDR = ~pullupEnable;
1535 pPio->PIO_PPUER = pullupEnable;
1538 /**---------------------------------------------------------------------------- */
1539 /** \fn AT91F_PIO_CfgDirectDrive */
1540 /** \brief Enable direct drive on PIO */
1541 /**---------------------------------------------------------------------------- */
1542 __inline void AT91F_PIO_CfgDirectDrive( AT91PS_PIO pPio, /* \arg pointer to a PIO controller */
1543 unsigned int directDrive ) /* \arg PIO to be configured with direct drive */
1546 /* Configure the Direct Drive */
1547 pPio->PIO_OWDR = ~directDrive;
1548 pPio->PIO_OWER = directDrive;
1551 /**---------------------------------------------------------------------------- */
1552 /** \fn AT91F_PIO_CfgInputFilter */
1553 /** \brief Enable input filter on input PIO */
1554 /**---------------------------------------------------------------------------- */
1555 __inline void AT91F_PIO_CfgInputFilter( AT91PS_PIO pPio, /* \arg pointer to a PIO controller */
1556 unsigned int inputFilter ) /* \arg PIO to be configured with input filter */
1559 /* Configure the Direct Drive */
1560 pPio->PIO_IFDR = ~inputFilter;
1561 pPio->PIO_IFER = inputFilter;
1564 /**---------------------------------------------------------------------------- */
1565 /** \fn AT91F_PIO_GetInput */
1566 /** \brief Return PIO input value */
1567 /**---------------------------------------------------------------------------- */
1568 __inline unsigned int AT91F_PIO_GetInput( /* \return PIO input */
1569 AT91PS_PIO pPio ) /* \arg pointer to a PIO controller */
1571 return pPio->PIO_PDSR;
1574 /**---------------------------------------------------------------------------- */
1575 /** \fn AT91F_PIO_IsInputSet */
1576 /** \brief Test if PIO is input flag is active */
1577 /**---------------------------------------------------------------------------- */
1578 __inline int AT91F_PIO_IsInputSet( AT91PS_PIO pPio, /* \arg pointer to a PIO controller */
1579 unsigned int flag ) /* \arg flag to be tested */
1581 return( AT91F_PIO_GetInput( pPio ) & flag );
1585 /**---------------------------------------------------------------------------- */
1586 /** \fn AT91F_PIO_SetOutput */
1587 /** \brief Set to 1 output PIO */
1588 /**---------------------------------------------------------------------------- */
1589 __inline void AT91F_PIO_SetOutput( AT91PS_PIO pPio, /* \arg pointer to a PIO controller */
1590 unsigned int flag ) /* \arg output to be set */
1592 pPio->PIO_SODR = flag;
1595 /**---------------------------------------------------------------------------- */
1596 /** \fn AT91F_PIO_ClearOutput */
1597 /** \brief Set to 0 output PIO */
1598 /**---------------------------------------------------------------------------- */
1599 __inline void AT91F_PIO_ClearOutput( AT91PS_PIO pPio, /* \arg pointer to a PIO controller */
1600 unsigned int flag ) /* \arg output to be cleared */
1602 pPio->PIO_CODR = flag;
1605 /**---------------------------------------------------------------------------- */
1606 /** \fn AT91F_PIO_ForceOutput */
1607 /** \brief Force output when Direct drive option is enabled */
1608 /**---------------------------------------------------------------------------- */
1609 __inline void AT91F_PIO_ForceOutput( AT91PS_PIO pPio, /* \arg pointer to a PIO controller */
1610 unsigned int flag ) /* \arg output to be forced */
1612 pPio->PIO_ODSR = flag;
1615 /**---------------------------------------------------------------------------- */
1616 /** \fn AT91F_PIO_Enable */
1617 /** \brief Enable PIO */
1618 /**---------------------------------------------------------------------------- */
1619 __inline void AT91F_PIO_Enable( AT91PS_PIO pPio, /* \arg pointer to a PIO controller */
1620 unsigned int flag ) /* \arg pio to be enabled */
1622 pPio->PIO_PER = flag;
1625 /**---------------------------------------------------------------------------- */
1626 /** \fn AT91F_PIO_Disable */
1627 /** \brief Disable PIO */
1628 /**---------------------------------------------------------------------------- */
1629 __inline void AT91F_PIO_Disable( AT91PS_PIO pPio, /* \arg pointer to a PIO controller */
1630 unsigned int flag ) /* \arg pio to be disabled */
1632 pPio->PIO_PDR = flag;
1635 /**---------------------------------------------------------------------------- */
1636 /** \fn AT91F_PIO_GetStatus */
1637 /** \brief Return PIO Status */
1638 /**---------------------------------------------------------------------------- */
1639 __inline unsigned int AT91F_PIO_GetStatus( /* \return PIO Status */
1640 AT91PS_PIO pPio ) /* \arg pointer to a PIO controller */
1642 return pPio->PIO_PSR;
1645 /**---------------------------------------------------------------------------- */
1646 /** \fn AT91F_PIO_IsSet */
1647 /** \brief Test if PIO is Set */
1648 /**---------------------------------------------------------------------------- */
1649 __inline int AT91F_PIO_IsSet( AT91PS_PIO pPio, /* \arg pointer to a PIO controller */
1650 unsigned int flag ) /* \arg flag to be tested */
1652 return( AT91F_PIO_GetStatus( pPio ) & flag );
1655 /**---------------------------------------------------------------------------- */
1656 /** \fn AT91F_PIO_OutputEnable */
1657 /** \brief Output Enable PIO */
1658 /**---------------------------------------------------------------------------- */
1659 __inline void AT91F_PIO_OutputEnable( AT91PS_PIO pPio, /* \arg pointer to a PIO controller */
1660 unsigned int flag ) /* \arg pio output to be enabled */
1662 pPio->PIO_OER = flag;
1665 /**---------------------------------------------------------------------------- */
1666 /** \fn AT91F_PIO_OutputDisable */
1667 /** \brief Output Enable PIO */
1668 /**---------------------------------------------------------------------------- */
1669 __inline void AT91F_PIO_OutputDisable( AT91PS_PIO pPio, /* \arg pointer to a PIO controller */
1670 unsigned int flag ) /* \arg pio output to be disabled */
1672 pPio->PIO_ODR = flag;
1675 /**---------------------------------------------------------------------------- */
1676 /** \fn AT91F_PIO_GetOutputStatus */
1677 /** \brief Return PIO Output Status */
1678 /**---------------------------------------------------------------------------- */
1679 __inline unsigned int AT91F_PIO_GetOutputStatus( /* \return PIO Output Status */
1680 AT91PS_PIO pPio ) /* \arg pointer to a PIO controller */
1682 return pPio->PIO_OSR;
1685 /**---------------------------------------------------------------------------- */
1686 /** \fn AT91F_PIO_IsOuputSet */
1687 /** \brief Test if PIO Output is Set */
1688 /**---------------------------------------------------------------------------- */
1689 __inline int AT91F_PIO_IsOutputSet( AT91PS_PIO pPio, /* \arg pointer to a PIO controller */
1690 unsigned int flag ) /* \arg flag to be tested */
1692 return( AT91F_PIO_GetOutputStatus( pPio ) & flag );
1695 /**---------------------------------------------------------------------------- */
1696 /** \fn AT91F_PIO_InputFilterEnable */
1697 /** \brief Input Filter Enable PIO */
1698 /**---------------------------------------------------------------------------- */
1699 __inline void AT91F_PIO_InputFilterEnable( AT91PS_PIO pPio, /* \arg pointer to a PIO controller */
1700 unsigned int flag ) /* \arg pio input filter to be enabled */
1702 pPio->PIO_IFER = flag;
1705 /**---------------------------------------------------------------------------- */
1706 /** \fn AT91F_PIO_InputFilterDisable */
1707 /** \brief Input Filter Disable PIO */
1708 /**---------------------------------------------------------------------------- */
1709 __inline void AT91F_PIO_InputFilterDisable( AT91PS_PIO pPio, /* \arg pointer to a PIO controller */
1710 unsigned int flag ) /* \arg pio input filter to be disabled */
1712 pPio->PIO_IFDR = flag;
1715 /**---------------------------------------------------------------------------- */
1716 /** \fn AT91F_PIO_GetInputFilterStatus */
1717 /** \brief Return PIO Input Filter Status */
1718 /**---------------------------------------------------------------------------- */
1719 __inline unsigned int AT91F_PIO_GetInputFilterStatus( /* \return PIO Input Filter Status */
1720 AT91PS_PIO pPio ) /* \arg pointer to a PIO controller */
1722 return pPio->PIO_IFSR;
1725 /**---------------------------------------------------------------------------- */
1726 /** \fn AT91F_PIO_IsInputFilterSet */
1727 /** \brief Test if PIO Input filter is Set */
1728 /**---------------------------------------------------------------------------- */
1729 __inline int AT91F_PIO_IsInputFilterSet( AT91PS_PIO pPio, /* \arg pointer to a PIO controller */
1730 unsigned int flag ) /* \arg flag to be tested */
1732 return( AT91F_PIO_GetInputFilterStatus( pPio ) & flag );
1735 /**---------------------------------------------------------------------------- */
1736 /** \fn AT91F_PIO_GetOutputDataStatus */
1737 /** \brief Return PIO Output Data Status */
1738 /**---------------------------------------------------------------------------- */
1739 __inline unsigned int AT91F_PIO_GetOutputDataStatus( /* \return PIO Output Data Status */
1740 AT91PS_PIO pPio ) /* \arg pointer to a PIO controller */
1742 return pPio->PIO_ODSR;
1745 /**---------------------------------------------------------------------------- */
1746 /** \fn AT91F_PIO_InterruptEnable */
1747 /** \brief Enable PIO Interrupt */
1748 /**---------------------------------------------------------------------------- */
1749 __inline void AT91F_PIO_InterruptEnable( AT91PS_PIO pPio, /* \arg pointer to a PIO controller */
1750 unsigned int flag ) /* \arg pio interrupt to be enabled */
1752 pPio->PIO_IER = flag;
1755 /**---------------------------------------------------------------------------- */
1756 /** \fn AT91F_PIO_InterruptDisable */
1757 /** \brief Disable PIO Interrupt */
1758 /**---------------------------------------------------------------------------- */
1759 __inline void AT91F_PIO_InterruptDisable( AT91PS_PIO pPio, /* \arg pointer to a PIO controller */
1760 unsigned int flag ) /* \arg pio interrupt to be disabled */
1762 pPio->PIO_IDR = flag;
1765 /**---------------------------------------------------------------------------- */
1766 /** \fn AT91F_PIO_GetInterruptMaskStatus */
1767 /** \brief Return PIO Interrupt Mask Status */
1768 /**---------------------------------------------------------------------------- */
1769 __inline unsigned int AT91F_PIO_GetInterruptMaskStatus( /* \return PIO Interrupt Mask Status */
1770 AT91PS_PIO pPio ) /* \arg pointer to a PIO controller */
1772 return pPio->PIO_IMR;
1775 /**---------------------------------------------------------------------------- */
1776 /** \fn AT91F_PIO_GetInterruptStatus */
1777 /** \brief Return PIO Interrupt Status */
1778 /**---------------------------------------------------------------------------- */
1779 __inline unsigned int AT91F_PIO_GetInterruptStatus( /* \return PIO Interrupt Status */
1780 AT91PS_PIO pPio ) /* \arg pointer to a PIO controller */
1782 return pPio->PIO_ISR;
1785 /**---------------------------------------------------------------------------- */
1786 /** \fn AT91F_PIO_IsInterruptMasked */
1787 /** \brief Test if PIO Interrupt is Masked */
1788 /**---------------------------------------------------------------------------- */
1789 __inline int AT91F_PIO_IsInterruptMasked( AT91PS_PIO pPio, /* \arg pointer to a PIO controller */
1790 unsigned int flag ) /* \arg flag to be tested */
1792 return( AT91F_PIO_GetInterruptMaskStatus( pPio ) & flag );
1795 /**---------------------------------------------------------------------------- */
1796 /** \fn AT91F_PIO_IsInterruptSet */
1797 /** \brief Test if PIO Interrupt is Set */
1798 /**---------------------------------------------------------------------------- */
1799 __inline int AT91F_PIO_IsInterruptSet( AT91PS_PIO pPio, /* \arg pointer to a PIO controller */
1800 unsigned int flag ) /* \arg flag to be tested */
1802 return( AT91F_PIO_GetInterruptStatus( pPio ) & flag );
1805 /**---------------------------------------------------------------------------- */
1806 /** \fn AT91F_PIO_MultiDriverEnable */
1807 /** \brief Multi Driver Enable PIO */
1808 /**---------------------------------------------------------------------------- */
1809 __inline void AT91F_PIO_MultiDriverEnable( AT91PS_PIO pPio, /* \arg pointer to a PIO controller */
1810 unsigned int flag ) /* \arg pio to be enabled */
1812 pPio->PIO_MDER = flag;
1815 /**---------------------------------------------------------------------------- */
1816 /** \fn AT91F_PIO_MultiDriverDisable */
1817 /** \brief Multi Driver Disable PIO */
1818 /**---------------------------------------------------------------------------- */
1819 __inline void AT91F_PIO_MultiDriverDisable( AT91PS_PIO pPio, /* \arg pointer to a PIO controller */
1820 unsigned int flag ) /* \arg pio to be disabled */
1822 pPio->PIO_MDDR = flag;
1825 /**---------------------------------------------------------------------------- */
1826 /** \fn AT91F_PIO_GetMultiDriverStatus */
1827 /** \brief Return PIO Multi Driver Status */
1828 /**---------------------------------------------------------------------------- */
1829 __inline unsigned int AT91F_PIO_GetMultiDriverStatus( /* \return PIO Multi Driver Status */
1830 AT91PS_PIO pPio ) /* \arg pointer to a PIO controller */
1832 return pPio->PIO_MDSR;
1835 /**---------------------------------------------------------------------------- */
1836 /** \fn AT91F_PIO_IsMultiDriverSet */
1837 /** \brief Test if PIO MultiDriver is Set */
1838 /**---------------------------------------------------------------------------- */
1839 __inline int AT91F_PIO_IsMultiDriverSet( AT91PS_PIO pPio, /* \arg pointer to a PIO controller */
1840 unsigned int flag ) /* \arg flag to be tested */
1842 return( AT91F_PIO_GetMultiDriverStatus( pPio ) & flag );
1845 /**---------------------------------------------------------------------------- */
1846 /** \fn AT91F_PIO_A_RegisterSelection */
1847 /** \brief PIO A Register Selection */
1848 /**---------------------------------------------------------------------------- */
1849 __inline void AT91F_PIO_A_RegisterSelection( AT91PS_PIO pPio, /* \arg pointer to a PIO controller */
1850 unsigned int flag ) /* \arg pio A register selection */
1852 pPio->PIO_ASR = flag;
1855 /**---------------------------------------------------------------------------- */
1856 /** \fn AT91F_PIO_B_RegisterSelection */
1857 /** \brief PIO B Register Selection */
1858 /**---------------------------------------------------------------------------- */
1859 __inline void AT91F_PIO_B_RegisterSelection( AT91PS_PIO pPio, /* \arg pointer to a PIO controller */
1860 unsigned int flag ) /* \arg pio B register selection */
1862 pPio->PIO_BSR = flag;
1865 /**---------------------------------------------------------------------------- */
1866 /** \fn AT91F_PIO_Get_AB_RegisterStatus */
1867 /** \brief Return PIO Interrupt Status */
1868 /**---------------------------------------------------------------------------- */
1869 __inline unsigned int AT91F_PIO_Get_AB_RegisterStatus( /* \return PIO AB Register Status */
1870 AT91PS_PIO pPio ) /* \arg pointer to a PIO controller */
1872 return pPio->PIO_ABSR;
1875 /**---------------------------------------------------------------------------- */
1876 /** \fn AT91F_PIO_IsAB_RegisterSet */
1877 /** \brief Test if PIO AB Register is Set */
1878 /**---------------------------------------------------------------------------- */
1879 __inline int AT91F_PIO_IsAB_RegisterSet( AT91PS_PIO pPio, /* \arg pointer to a PIO controller */
1880 unsigned int flag ) /* \arg flag to be tested */
1882 return( AT91F_PIO_Get_AB_RegisterStatus( pPio ) & flag );
1885 /**---------------------------------------------------------------------------- */
1886 /** \fn AT91F_PIO_OutputWriteEnable */
1887 /** \brief Output Write Enable PIO */
1888 /**---------------------------------------------------------------------------- */
1889 __inline void AT91F_PIO_OutputWriteEnable( AT91PS_PIO pPio, /* \arg pointer to a PIO controller */
1890 unsigned int flag ) /* \arg pio output write to be enabled */
1892 pPio->PIO_OWER = flag;
1895 /**---------------------------------------------------------------------------- */
1896 /** \fn AT91F_PIO_OutputWriteDisable */
1897 /** \brief Output Write Disable PIO */
1898 /**---------------------------------------------------------------------------- */
1899 __inline void AT91F_PIO_OutputWriteDisable( AT91PS_PIO pPio, /* \arg pointer to a PIO controller */
1900 unsigned int flag ) /* \arg pio output write to be disabled */
1902 pPio->PIO_OWDR = flag;
1905 /**---------------------------------------------------------------------------- */
1906 /** \fn AT91F_PIO_GetOutputWriteStatus */
1907 /** \brief Return PIO Output Write Status */
1908 /**---------------------------------------------------------------------------- */
1909 __inline unsigned int AT91F_PIO_GetOutputWriteStatus( /* \return PIO Output Write Status */
1910 AT91PS_PIO pPio ) /* \arg pointer to a PIO controller */
1912 return pPio->PIO_OWSR;
1915 /**---------------------------------------------------------------------------- */
1916 /** \fn AT91F_PIO_IsOutputWriteSet */
1917 /** \brief Test if PIO OutputWrite is Set */
1918 /**---------------------------------------------------------------------------- */
1919 __inline int AT91F_PIO_IsOutputWriteSet( AT91PS_PIO pPio, /* \arg pointer to a PIO controller */
1920 unsigned int flag ) /* \arg flag to be tested */
1922 return( AT91F_PIO_GetOutputWriteStatus( pPio ) & flag );
1925 /**---------------------------------------------------------------------------- */
1926 /** \fn AT91F_PIO_GetCfgPullup */
1927 /** \brief Return PIO Configuration Pullup */
1928 /**---------------------------------------------------------------------------- */
1929 __inline unsigned int AT91F_PIO_GetCfgPullup( /* \return PIO Configuration Pullup */
1930 AT91PS_PIO pPio ) /* \arg pointer to a PIO controller */
1932 return pPio->PIO_PPUSR;
1935 /**---------------------------------------------------------------------------- */
1936 /** \fn AT91F_PIO_IsOutputDataStatusSet */
1937 /** \brief Test if PIO Output Data Status is Set */
1938 /**---------------------------------------------------------------------------- */
1939 __inline int AT91F_PIO_IsOutputDataStatusSet( AT91PS_PIO pPio, /* \arg pointer to a PIO controller */
1940 unsigned int flag ) /* \arg flag to be tested */
1942 return( AT91F_PIO_GetOutputDataStatus( pPio ) & flag );
1945 /**---------------------------------------------------------------------------- */
1946 /** \fn AT91F_PIO_IsCfgPullupStatusSet */
1947 /** \brief Test if PIO Configuration Pullup Status is Set */
1948 /**---------------------------------------------------------------------------- */
1949 __inline int AT91F_PIO_IsCfgPullupStatusSet( AT91PS_PIO pPio, /* \arg pointer to a PIO controller */
1950 unsigned int flag ) /* \arg flag to be tested */
1952 return( ~AT91F_PIO_GetCfgPullup( pPio ) & flag );
1955 /* *****************************************************************************
1956 * SOFTWARE API FOR TWI
1957 ***************************************************************************** */
1958 /**---------------------------------------------------------------------------- */
1959 /** \fn AT91F_TWI_EnableIt */
1960 /** \brief Enable TWI IT */
1961 /**---------------------------------------------------------------------------- */
1962 __inline void AT91F_TWI_EnableIt( AT91PS_TWI pTWI, /* \arg pointer to a TWI controller */
1963 unsigned int flag ) /* \arg IT to be enabled */
1965 /** Write to the IER register */
1966 pTWI->TWI_IER = flag;
1969 /**---------------------------------------------------------------------------- */
1970 /** \fn AT91F_TWI_DisableIt */
1971 /** \brief Disable TWI IT */
1972 /**---------------------------------------------------------------------------- */
1973 __inline void AT91F_TWI_DisableIt( AT91PS_TWI pTWI, /* \arg pointer to a TWI controller */
1974 unsigned int flag ) /* \arg IT to be disabled */
1976 /** Write to the IDR register */
1977 pTWI->TWI_IDR = flag;
1980 /**---------------------------------------------------------------------------- */
1981 /** \fn AT91F_TWI_Configure */
1982 /** \brief Configure TWI in master mode */
1983 /**---------------------------------------------------------------------------- */
1984 __inline void AT91F_TWI_Configure( AT91PS_TWI pTWI ) /* \arg pointer to a TWI controller */
1986 /** Disable interrupts */
1987 pTWI->TWI_IDR = ( unsigned int ) -1;
1989 /** Reset peripheral */
1990 pTWI->TWI_CR = AT91C_TWI_SWRST;
1992 /** Set Master mode */
1993 pTWI->TWI_CR = AT91C_TWI_MSEN | AT91C_TWI_SVDIS;
1996 /**---------------------------------------------------------------------------- */
1997 /** \fn AT91F_TWI_GetInterruptMaskStatus */
1998 /** \brief Return TWI Interrupt Mask Status */
1999 /**---------------------------------------------------------------------------- */
2000 __inline unsigned int AT91F_TWI_GetInterruptMaskStatus( /* \return TWI Interrupt Mask Status */
2001 AT91PS_TWI pTwi ) /* \arg pointer to a TWI controller */
2003 return pTwi->TWI_IMR;
2006 /**---------------------------------------------------------------------------- */
2007 /** \fn AT91F_TWI_IsInterruptMasked */
2008 /** \brief Test if TWI Interrupt is Masked */
2009 /**---------------------------------------------------------------------------- */
2010 __inline int AT91F_TWI_IsInterruptMasked( AT91PS_TWI pTwi, /* \arg pointer to a TWI controller */
2011 unsigned int flag ) /* \arg flag to be tested */
2013 return( AT91F_TWI_GetInterruptMaskStatus( pTwi ) & flag );
2016 /* *****************************************************************************
2017 * SOFTWARE API FOR USART
2018 ***************************************************************************** */
2019 /**---------------------------------------------------------------------------- */
2020 /** \fn AT91F_US_Baudrate */
2021 /** \brief Calculate the baudrate */
2022 /** Standard Asynchronous Mode : 8 bits , 1 stop , no parity */
2023 #define AT91C_US_ASYNC_MODE \
2024 ( AT91C_US_USMODE_NORMAL + \
2025 AT91C_US_NBSTOP_1_BIT + \
2026 AT91C_US_PAR_NONE + \
2027 AT91C_US_CHRL_8_BITS + \
2028 AT91C_US_CLKS_CLOCK )
2030 /** Standard External Asynchronous Mode : 8 bits , 1 stop , no parity */
2031 #define AT91C_US_ASYNC_SCK_MODE \
2032 ( AT91C_US_USMODE_NORMAL + \
2033 AT91C_US_NBSTOP_1_BIT + \
2034 AT91C_US_PAR_NONE + \
2035 AT91C_US_CHRL_8_BITS + \
2038 /** Standard Synchronous Mode : 8 bits , 1 stop , no parity */
2039 #define AT91C_US_SYNC_MODE \
2041 AT91C_US_USMODE_NORMAL + \
2042 AT91C_US_NBSTOP_1_BIT + \
2043 AT91C_US_PAR_NONE + \
2044 AT91C_US_CHRL_8_BITS + \
2045 AT91C_US_CLKS_CLOCK )
2047 /** SCK used Label */
2048 #define AT91C_US_SCK_USED ( AT91C_US_CKLO | AT91C_US_CLKS_EXT )
2050 /** Standard ISO T=0 Mode : 8 bits , 1 stop , parity */
2051 #define AT91C_US_ISO_READER_MODE \
2052 ( AT91C_US_USMODE_ISO7816_0 + \
2053 AT91C_US_CLKS_CLOCK + \
2054 AT91C_US_NBSTOP_1_BIT + \
2055 AT91C_US_PAR_EVEN + \
2056 AT91C_US_CHRL_8_BITS + \
2060 /** Standard IRDA mode */
2061 #define AT91C_US_ASYNC_IRDA_MODE \
2062 ( AT91C_US_USMODE_IRDA + \
2063 AT91C_US_NBSTOP_1_BIT + \
2064 AT91C_US_PAR_NONE + \
2065 AT91C_US_CHRL_8_BITS + \
2066 AT91C_US_CLKS_CLOCK )
2068 /**---------------------------------------------------------------------------- */
2069 /** \fn AT91F_US_Baudrate */
2070 /** \brief Calculate baud_value according to the main clock and the baud rate */
2071 /**---------------------------------------------------------------------------- */
2072 __inline unsigned int AT91F_US_Baudrate( const unsigned int main_clock, /* \arg peripheral clock */
2073 const unsigned int baud_rate ) /* \arg UART baudrate */
2075 unsigned int baud_value = ( ( main_clock * 10 ) / ( baud_rate * 16 ) );
2077 if( ( baud_value % 10 ) >= 5 )
2079 baud_value = ( baud_value / 10 ) + 1;
2089 /**---------------------------------------------------------------------------- */
2090 /** \fn AT91F_US_SetBaudrate */
2091 /** \brief Set the baudrate according to the CPU clock */
2092 /**---------------------------------------------------------------------------- */
2093 __inline void AT91F_US_SetBaudrate( AT91PS_USART pUSART, /* \arg pointer to a USART controller */
2094 unsigned int mainClock, /* \arg peripheral clock */
2095 unsigned int speed ) /* \arg UART baudrate */
2097 /** Define the baud rate divisor register */
2098 pUSART->US_BRGR = AT91F_US_Baudrate( mainClock, speed );
2101 /**---------------------------------------------------------------------------- */
2102 /** \fn AT91F_US_SetTimeguard */
2103 /** \brief Set USART timeguard */
2104 /**---------------------------------------------------------------------------- */
2105 __inline void AT91F_US_SetTimeguard( AT91PS_USART pUSART, /* \arg pointer to a USART controller */
2106 unsigned int timeguard ) /* \arg timeguard value */
2108 /** Write the Timeguard Register */
2109 pUSART->US_TTGR = timeguard;
2112 /**---------------------------------------------------------------------------- */
2113 /** \fn AT91F_US_EnableIt */
2114 /** \brief Enable USART IT */
2115 /**---------------------------------------------------------------------------- */
2116 __inline void AT91F_US_EnableIt( AT91PS_USART pUSART, /* \arg pointer to a USART controller */
2117 unsigned int flag ) /* \arg IT to be enabled */
2119 /** Write to the IER register */
2120 pUSART->US_IER = flag;
2123 /**---------------------------------------------------------------------------- */
2124 /** \fn AT91F_US_DisableIt */
2125 /** \brief Disable USART IT */
2126 /**---------------------------------------------------------------------------- */
2127 __inline void AT91F_US_DisableIt( AT91PS_USART pUSART, /* \arg pointer to a USART controller */
2128 unsigned int flag ) /* \arg IT to be disabled */
2130 /** Write to the IER register */
2131 pUSART->US_IDR = flag;
2134 /**---------------------------------------------------------------------------- */
2135 /** \fn AT91F_US_Configure */
2136 /** \brief Configure USART */
2137 /**---------------------------------------------------------------------------- */
2138 __inline void AT91F_US_Configure( AT91PS_USART pUSART, /* \arg pointer to a USART controller */
2139 unsigned int mainClock, /* \arg peripheral clock */
2140 unsigned int mode, /* \arg mode Register to be programmed */
2141 unsigned int baudRate, /* \arg baudrate to be programmed */
2142 unsigned int timeguard ) /* \arg timeguard to be programmed */
2144 /** Disable interrupts */
2145 pUSART->US_IDR = ( unsigned int ) -1;
2147 /** Reset receiver and transmitter */
2148 pUSART->US_CR = AT91C_US_RSTRX | AT91C_US_RSTTX | AT91C_US_RXDIS | AT91C_US_TXDIS;
2150 /** Define the baud rate divisor register */
2151 AT91F_US_SetBaudrate( pUSART, mainClock, baudRate );
2153 /** Write the Timeguard Register */
2154 AT91F_US_SetTimeguard( pUSART, timeguard );
2156 /** Clear Transmit and Receive Counters */
2157 AT91F_PDC_Open( ( AT91PS_PDC ) &( pUSART->US_RPR ) );
2159 /** Define the USART mode */
2160 pUSART->US_MR = mode;
2163 /**---------------------------------------------------------------------------- */
2164 /** \fn AT91F_US_EnableRx */
2165 /** \brief Enable receiving characters */
2166 /**---------------------------------------------------------------------------- */
2167 __inline void AT91F_US_EnableRx( AT91PS_USART pUSART ) /* \arg pointer to a USART controller */
2169 /** Enable receiver */
2170 pUSART->US_CR = AT91C_US_RXEN;
2173 /**---------------------------------------------------------------------------- */
2174 /** \fn AT91F_US_EnableTx */
2175 /** \brief Enable sending characters */
2176 /**---------------------------------------------------------------------------- */
2177 __inline void AT91F_US_EnableTx( AT91PS_USART pUSART ) /* \arg pointer to a USART controller */
2179 /** Enable transmitter */
2180 pUSART->US_CR = AT91C_US_TXEN;
2183 /**---------------------------------------------------------------------------- */
2184 /** \fn AT91F_US_ResetRx */
2185 /** \brief Reset Receiver and re-enable it */
2186 /**---------------------------------------------------------------------------- */
2187 __inline void AT91F_US_ResetRx( AT91PS_USART pUSART ) /* \arg pointer to a USART controller */
2189 /** Reset receiver */
2190 pUSART->US_CR = AT91C_US_RSTRX;
2191 /** Re-Enable receiver */
2192 pUSART->US_CR = AT91C_US_RXEN;
2195 /**---------------------------------------------------------------------------- */
2196 /** \fn AT91F_US_ResetTx */
2197 /** \brief Reset Transmitter and re-enable it */
2198 /**---------------------------------------------------------------------------- */
2199 __inline void AT91F_US_ResetTx( AT91PS_USART pUSART ) /* \arg pointer to a USART controller */
2201 /** Reset transmitter */
2202 pUSART->US_CR = AT91C_US_RSTTX;
2203 /** Enable transmitter */
2204 pUSART->US_CR = AT91C_US_TXEN;
2207 /**---------------------------------------------------------------------------- */
2208 /** \fn AT91F_US_DisableRx */
2209 /** \brief Disable Receiver */
2210 /**---------------------------------------------------------------------------- */
2211 __inline void AT91F_US_DisableRx( AT91PS_USART pUSART ) /* \arg pointer to a USART controller */
2213 /** Disable receiver */
2214 pUSART->US_CR = AT91C_US_RXDIS;
2217 /**---------------------------------------------------------------------------- */
2218 /** \fn AT91F_US_DisableTx */
2219 /** \brief Disable Transmitter */
2220 /**---------------------------------------------------------------------------- */
2221 __inline void AT91F_US_DisableTx( AT91PS_USART pUSART ) /* \arg pointer to a USART controller */
2223 /** Disable transmitter */
2224 pUSART->US_CR = AT91C_US_TXDIS;
2227 /**---------------------------------------------------------------------------- */
2228 /** \fn AT91F_US_Close */
2229 /** \brief Close USART: disable IT disable receiver and transmitter, close PDC */
2230 /**---------------------------------------------------------------------------- */
2231 __inline void AT91F_US_Close( AT91PS_USART pUSART ) /* \arg pointer to a USART controller */
2233 /** Reset the baud rate divisor register */
2234 pUSART->US_BRGR = 0;
2236 /** Reset the USART mode */
2239 /** Reset the Timeguard Register */
2240 pUSART->US_TTGR = 0;
2242 /** Disable all interrupts */
2243 pUSART->US_IDR = 0xFFFFFFFF;
2245 /** Abort the Peripheral Data Transfers */
2246 AT91F_PDC_Close( ( AT91PS_PDC ) &( pUSART->US_RPR ) );
2248 /** Disable receiver and transmitter and stop any activity immediately */
2249 pUSART->US_CR = AT91C_US_TXDIS | AT91C_US_RXDIS | AT91C_US_RSTTX | AT91C_US_RSTRX;
2252 /**---------------------------------------------------------------------------- */
2253 /** \fn AT91F_US_TxReady */
2254 /** \brief Return 1 if a character can be written in US_THR */
2255 /**---------------------------------------------------------------------------- */
2256 __inline unsigned int AT91F_US_TxReady( AT91PS_USART pUSART ) /* \arg pointer to a USART controller */
2258 return( pUSART->US_CSR & AT91C_US_TXRDY );
2261 /**---------------------------------------------------------------------------- */
2262 /** \fn AT91F_US_RxReady */
2263 /** \brief Return 1 if a character can be read in US_RHR */
2264 /**---------------------------------------------------------------------------- */
2265 __inline unsigned int AT91F_US_RxReady( AT91PS_USART pUSART ) /* \arg pointer to a USART controller */
2267 return( pUSART->US_CSR & AT91C_US_RXRDY );
2270 /**---------------------------------------------------------------------------- */
2271 /** \fn AT91F_US_Error */
2272 /** \brief Return the error flag */
2273 /**---------------------------------------------------------------------------- */
2274 __inline unsigned int AT91F_US_Error( AT91PS_USART pUSART ) /* \arg pointer to a USART controller */
2276 return( pUSART->US_CSR &
2277 ( AT91C_US_OVRE | /* Overrun error */
2278 AT91C_US_FRAME | /* Framing error */
2279 AT91C_US_PARE ) ); /* Parity error */
2282 /**---------------------------------------------------------------------------- */
2283 /** \fn AT91F_US_PutChar */
2284 /** \brief Send a character,does not check if ready to send */
2285 /**---------------------------------------------------------------------------- */
2286 __inline void AT91F_US_PutChar( AT91PS_USART pUSART,
2289 pUSART->US_THR = ( character & 0x1FF );
2292 /**---------------------------------------------------------------------------- */
2293 /** \fn AT91F_US_GetChar */
2294 /** \brief Receive a character,does not check if a character is available */
2295 /**---------------------------------------------------------------------------- */
2296 __inline int AT91F_US_GetChar( const AT91PS_USART pUSART )
2298 return( ( pUSART->US_RHR ) & 0x1FF );
2301 /**---------------------------------------------------------------------------- */
2302 /** \fn AT91F_US_SendFrame */
2303 /** \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 */
2304 /**---------------------------------------------------------------------------- */
2305 __inline unsigned int AT91F_US_SendFrame( AT91PS_USART pUSART,
2307 unsigned int szBuffer,
2309 unsigned int szNextBuffer )
2311 return AT91F_PDC_SendFrame(
2312 ( AT91PS_PDC ) &( pUSART->US_RPR ),
2319 /**---------------------------------------------------------------------------- */
2320 /** \fn AT91F_US_ReceiveFrame */
2321 /** \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 */
2322 /**---------------------------------------------------------------------------- */
2323 __inline unsigned int AT91F_US_ReceiveFrame( AT91PS_USART pUSART,
2325 unsigned int szBuffer,
2327 unsigned int szNextBuffer )
2329 return AT91F_PDC_ReceiveFrame(
2330 ( AT91PS_PDC ) &( pUSART->US_RPR ),
2337 /**---------------------------------------------------------------------------- */
2338 /** \fn AT91F_US_SetIrdaFilter */
2339 /** \brief Set the value of IrDa filter register */
2340 /**---------------------------------------------------------------------------- */
2341 __inline void AT91F_US_SetIrdaFilter( AT91PS_USART pUSART,
2342 unsigned char value )
2344 pUSART->US_IF = value;
2347 /* *****************************************************************************
2348 * SOFTWARE API FOR UDP
2349 ***************************************************************************** */
2350 /**---------------------------------------------------------------------------- */
2351 /** \fn AT91F_UDP_EnableIt */
2352 /** \brief Enable UDP IT */
2353 /**---------------------------------------------------------------------------- */
2354 __inline void AT91F_UDP_EnableIt( AT91PS_UDP pUDP, /* \arg pointer to a UDP controller */
2355 unsigned int flag ) /* \arg IT to be enabled */
2357 /** Write to the IER register */
2358 pUDP->UDP_IER = flag;
2361 /**---------------------------------------------------------------------------- */
2362 /** \fn AT91F_UDP_DisableIt */
2363 /** \brief Disable UDP IT */
2364 /**---------------------------------------------------------------------------- */
2365 __inline void AT91F_UDP_DisableIt( AT91PS_UDP pUDP, /* \arg pointer to a UDP controller */
2366 unsigned int flag ) /* \arg IT to be disabled */
2368 /** Write to the IDR register */
2369 pUDP->UDP_IDR = flag;
2372 /**---------------------------------------------------------------------------- */
2373 /** \fn AT91F_UDP_SetAddress */
2374 /** \brief Set UDP functional address */
2375 /**---------------------------------------------------------------------------- */
2376 __inline void AT91F_UDP_SetAddress( AT91PS_UDP pUDP, /* \arg pointer to a UDP controller */
2377 unsigned char address ) /* \arg new UDP address */
2379 pUDP->UDP_FADDR = ( AT91C_UDP_FEN | address );
2382 /**---------------------------------------------------------------------------- */
2383 /** \fn AT91F_UDP_EnableEp */
2384 /** \brief Enable Endpoint */
2385 /**---------------------------------------------------------------------------- */
2386 __inline void AT91F_UDP_EnableEp( AT91PS_UDP pUDP, /* \arg pointer to a UDP controller */
2387 unsigned int flag ) /* \arg endpoints to be enabled */
2389 pUDP->UDP_GLBSTATE |= flag;
2392 /**---------------------------------------------------------------------------- */
2393 /** \fn AT91F_UDP_DisableEp */
2394 /** \brief Enable Endpoint */
2395 /**---------------------------------------------------------------------------- */
2396 __inline void AT91F_UDP_DisableEp( AT91PS_UDP pUDP, /* \arg pointer to a UDP controller */
2397 unsigned int flag ) /* \arg endpoints to be enabled */
2399 pUDP->UDP_GLBSTATE &= ~( flag );
2402 /**---------------------------------------------------------------------------- */
2403 /** \fn AT91F_UDP_SetState */
2404 /** \brief Set UDP Device state */
2405 /**---------------------------------------------------------------------------- */
2406 __inline void AT91F_UDP_SetState( AT91PS_UDP pUDP, /* \arg pointer to a UDP controller */
2407 unsigned int flag ) /* \arg new UDP address */
2409 pUDP->UDP_GLBSTATE &= ~( AT91C_UDP_FADDEN | AT91C_UDP_CONFG );
2410 pUDP->UDP_GLBSTATE |= flag;
2413 /**---------------------------------------------------------------------------- */
2414 /** \fn AT91F_UDP_GetState */
2415 /** \brief return UDP Device state */
2416 /**---------------------------------------------------------------------------- */
2417 __inline unsigned int AT91F_UDP_GetState( /* \return the UDP device state */
2418 AT91PS_UDP pUDP ) /* \arg pointer to a UDP controller */
2420 return( pUDP->UDP_GLBSTATE & ( AT91C_UDP_FADDEN | AT91C_UDP_CONFG ) );
2423 /**---------------------------------------------------------------------------- */
2424 /** \fn AT91F_UDP_ResetEp */
2425 /** \brief Reset UDP endpoint */
2426 /**---------------------------------------------------------------------------- */
2427 __inline void AT91F_UDP_ResetEp( /* \return the UDP device state */
2428 AT91PS_UDP pUDP, /* \arg pointer to a UDP controller */
2429 unsigned int flag ) /* \arg Endpoints to be reset */
2431 pUDP->UDP_RSTEP = flag;
2434 /**---------------------------------------------------------------------------- */
2435 /** \fn AT91F_UDP_EpStall */
2436 /** \brief Endpoint will STALL requests */
2437 /**---------------------------------------------------------------------------- */
2438 __inline void AT91F_UDP_EpStall( AT91PS_UDP pUDP, /* \arg pointer to a UDP controller */
2439 unsigned char endpoint ) /* \arg endpoint number */
2441 pUDP->UDP_CSR[ endpoint ] |= AT91C_UDP_FORCESTALL;
2444 /**---------------------------------------------------------------------------- */
2445 /** \fn AT91F_UDP_EpWrite */
2446 /** \brief Write value in the DPR */
2447 /**---------------------------------------------------------------------------- */
2448 __inline void AT91F_UDP_EpWrite( AT91PS_UDP pUDP, /* \arg pointer to a UDP controller */
2449 unsigned char endpoint, /* \arg endpoint number */
2450 unsigned char value ) /* \arg value to be written in the DPR */
2452 pUDP->UDP_FDR[ endpoint ] = value;
2455 /**---------------------------------------------------------------------------- */
2456 /** \fn AT91F_UDP_EpRead */
2457 /** \brief Return value from the DPR */
2458 /**---------------------------------------------------------------------------- */
2459 __inline unsigned int AT91F_UDP_EpRead( AT91PS_UDP pUDP, /* \arg pointer to a UDP controller */
2460 unsigned char endpoint ) /* \arg endpoint number */
2462 return pUDP->UDP_FDR[ endpoint ];
2465 /**---------------------------------------------------------------------------- */
2466 /** \fn AT91F_UDP_EpEndOfWr */
2467 /** \brief Notify the UDP that values in DPR are ready to be sent */
2468 /**---------------------------------------------------------------------------- */
2469 __inline void AT91F_UDP_EpEndOfWr( AT91PS_UDP pUDP, /* \arg pointer to a UDP controller */
2470 unsigned char endpoint ) /* \arg endpoint number */
2472 pUDP->UDP_CSR[ endpoint ] |= AT91C_UDP_TXPKTRDY;
2475 /**---------------------------------------------------------------------------- */
2476 /** \fn AT91F_UDP_EpClear */
2477 /** \brief Clear flag in the endpoint CSR register */
2478 /**---------------------------------------------------------------------------- */
2479 __inline void AT91F_UDP_EpClear( AT91PS_UDP pUDP, /* \arg pointer to a UDP controller */
2480 unsigned char endpoint, /* \arg endpoint number */
2481 unsigned int flag ) /* \arg flag to be cleared */
2483 pUDP->UDP_CSR[ endpoint ] &= ~( flag );
2486 /**---------------------------------------------------------------------------- */
2487 /** \fn AT91F_UDP_EpSet */
2488 /** \brief Set flag in the endpoint CSR register */
2489 /**---------------------------------------------------------------------------- */
2490 __inline void AT91F_UDP_EpSet( AT91PS_UDP pUDP, /* \arg pointer to a UDP controller */
2491 unsigned char endpoint, /* \arg endpoint number */
2492 unsigned int flag ) /* \arg flag to be cleared */
2494 pUDP->UDP_CSR[ endpoint ] |= flag;
2497 /**---------------------------------------------------------------------------- */
2498 /** \fn AT91F_UDP_EpStatus */
2499 /** \brief Return the endpoint CSR register */
2500 /**---------------------------------------------------------------------------- */
2501 __inline unsigned int AT91F_UDP_EpStatus( AT91PS_UDP pUDP, /* \arg pointer to a UDP controller */
2502 unsigned char endpoint ) /* \arg endpoint number */
2504 return pUDP->UDP_CSR[ endpoint ];
2507 /**---------------------------------------------------------------------------- */
2508 /** \fn AT91F_UDP_GetInterruptMaskStatus */
2509 /** \brief Return UDP Interrupt Mask Status */
2510 /**---------------------------------------------------------------------------- */
2511 __inline unsigned int AT91F_UDP_GetInterruptMaskStatus( /* \return UDP Interrupt Mask Status */
2512 AT91PS_UDP pUdp ) /* \arg pointer to a UDP controller */
2514 return pUdp->UDP_IMR;
2517 /**---------------------------------------------------------------------------- */
2518 /** \fn AT91F_UDP_IsInterruptMasked */
2519 /** \brief Test if UDP Interrupt is Masked */
2520 /**---------------------------------------------------------------------------- */
2521 __inline int AT91F_UDP_IsInterruptMasked( AT91PS_UDP pUdp, /* \arg pointer to a UDP controller */
2522 unsigned int flag ) /* \arg flag to be tested */
2524 return( AT91F_UDP_GetInterruptMaskStatus( pUdp ) & flag );
2527 /* *****************************************************************************
2528 * SOFTWARE API FOR AIC
2529 ***************************************************************************** */
2530 #define AT91C_AIC_BRANCH_OPCODE ( ( void ( * )() ) 0xE51FFF20 ) /* ldr, pc, [pc, #-&F20] */
2532 /**---------------------------------------------------------------------------- */
2533 /** \fn AT91F_AIC_ConfigureIt */
2534 /** \brief Interrupt Handler Initialization */
2535 /**---------------------------------------------------------------------------- */
2536 __inline unsigned int AT91F_AIC_ConfigureIt( AT91PS_AIC pAic, /* \arg pointer to the AIC registers */
2537 unsigned int irq_id, /* \arg interrupt number to initialize */
2538 unsigned int priority, /* \arg priority to give to the interrupt */
2539 unsigned int src_type, /* \arg activation and sense of activation */
2540 void ( * newHandler )( void ) ) /* \arg address of the interrupt handler */
2542 unsigned int oldHandler;
2545 oldHandler = pAic->AIC_SVR[ irq_id ];
2547 mask = 0x1 << irq_id;
2548 /** Disable the interrupt on the interrupt controller */
2549 pAic->AIC_IDCR = mask;
2550 /** Save the interrupt handler routine pointer and the interrupt priority */
2551 pAic->AIC_SVR[ irq_id ] = ( unsigned int ) newHandler;
2552 /** Store the Source Mode Register */
2553 pAic->AIC_SMR[ irq_id ] = src_type | priority;
2554 /** Clear the interrupt on the interrupt controller */
2555 pAic->AIC_ICCR = mask;
2560 /**---------------------------------------------------------------------------- */
2561 /** \fn AT91F_AIC_EnableIt */
2562 /** \brief Enable corresponding IT number */
2563 /**---------------------------------------------------------------------------- */
2564 __inline void AT91F_AIC_EnableIt( AT91PS_AIC pAic, /* \arg pointer to the AIC registers */
2565 unsigned int irq_id ) /* \arg interrupt number to initialize */
2567 /** Enable the interrupt on the interrupt controller */
2568 pAic->AIC_IECR = 0x1 << irq_id;
2571 /**---------------------------------------------------------------------------- */
2572 /** \fn AT91F_AIC_DisableIt */
2573 /** \brief Disable corresponding IT number */
2574 /**---------------------------------------------------------------------------- */
2575 __inline void AT91F_AIC_DisableIt( AT91PS_AIC pAic, /* \arg pointer to the AIC registers */
2576 unsigned int irq_id ) /* \arg interrupt number to initialize */
2578 unsigned int mask = 0x1 << irq_id;
2580 /** Disable the interrupt on the interrupt controller */
2581 pAic->AIC_IDCR = mask;
2582 /** Clear the interrupt on the Interrupt Controller ( if one is pending ) */
2583 pAic->AIC_ICCR = mask;
2586 /**---------------------------------------------------------------------------- */
2587 /** \fn AT91F_AIC_ClearIt */
2588 /** \brief Clear corresponding IT number */
2589 /**---------------------------------------------------------------------------- */
2590 __inline void AT91F_AIC_ClearIt( AT91PS_AIC pAic, /* \arg pointer to the AIC registers */
2591 unsigned int irq_id ) /* \arg interrupt number to initialize */
2593 /** Clear the interrupt on the Interrupt Controller ( if one is pending ) */
2594 pAic->AIC_ICCR = ( 0x1 << irq_id );
2597 /**---------------------------------------------------------------------------- */
2598 /** \fn AT91F_AIC_AcknowledgeIt */
2599 /** \brief Acknowledge corresponding IT number */
2600 /**---------------------------------------------------------------------------- */
2601 __inline void AT91F_AIC_AcknowledgeIt( AT91PS_AIC pAic ) /* \arg pointer to the AIC registers */
2603 pAic->AIC_EOICR = pAic->AIC_EOICR;
2606 /**---------------------------------------------------------------------------- */
2607 /** \fn AT91F_AIC_SetExceptionVector */
2608 /** \brief Configure vector handler */
2609 /**---------------------------------------------------------------------------- */
2610 __inline unsigned int AT91F_AIC_SetExceptionVector( unsigned int * pVector, /* \arg pointer to the AIC registers */
2611 void ( * Handler )() ) /* \arg Interrupt Handler */
2613 unsigned int oldVector = *pVector;
2615 if( ( unsigned int ) Handler == ( unsigned int ) AT91C_AIC_BRANCH_OPCODE )
2617 *pVector = ( unsigned int ) AT91C_AIC_BRANCH_OPCODE;
2621 *pVector = ( ( ( ( ( unsigned int ) Handler ) - ( ( unsigned int ) pVector ) - 0x8 ) >> 2 ) & 0x00FFFFFF ) | 0xEA000000;
2627 /**---------------------------------------------------------------------------- */
2628 /** \fn AT91F_AIC_Trig */
2629 /** \brief Trig an IT */
2630 /**---------------------------------------------------------------------------- */
2631 __inline void AT91F_AIC_Trig( AT91PS_AIC pAic, /* \arg pointer to the AIC registers */
2632 unsigned int irq_id ) /* \arg interrupt number */
2634 pAic->AIC_ISCR = ( 0x1 << irq_id );
2637 /**---------------------------------------------------------------------------- */
2638 /** \fn AT91F_AIC_IsActive */
2639 /** \brief Test if an IT is active */
2640 /**---------------------------------------------------------------------------- */
2641 __inline unsigned int AT91F_AIC_IsActive( AT91PS_AIC pAic, /* \arg pointer to the AIC registers */
2642 unsigned int irq_id ) /* \arg Interrupt Number */
2644 return( pAic->AIC_ISR & ( 0x1 << irq_id ) );
2647 /**---------------------------------------------------------------------------- */
2648 /** \fn AT91F_AIC_IsPending */
2649 /** \brief Test if an IT is pending */
2650 /**---------------------------------------------------------------------------- */
2651 __inline unsigned int AT91F_AIC_IsPending( AT91PS_AIC pAic, /* \arg pointer to the AIC registers */
2652 unsigned int irq_id ) /* \arg Interrupt Number */
2654 return( pAic->AIC_IPR & ( 0x1 << irq_id ) );
2657 /**---------------------------------------------------------------------------- */
2658 /** \fn AT91F_AIC_Open */
2659 /** \brief Set exception vectors and AIC registers to default values */
2660 /**---------------------------------------------------------------------------- */
2661 __inline void AT91F_AIC_Open( AT91PS_AIC pAic, /* \arg pointer to the AIC registers */
2662 void ( * IrqHandler )(), /* \arg Default IRQ vector exception */
2663 void ( * FiqHandler )(), /* \arg Default FIQ vector exception */
2664 void ( * DefaultHandler )(), /* \arg Default Handler set in ISR */
2665 void ( * SpuriousHandler )(), /* \arg Default Spurious Handler */
2666 unsigned int protectMode ) /* \arg Debug Control Register */
2670 /* Disable all interrupts and set IVR to the default handler */
2671 for( i = 0; i < 32; ++i )
2673 AT91F_AIC_DisableIt( pAic, i );
2674 AT91F_AIC_ConfigureIt( pAic, i, AT91C_AIC_PRIOR_LOWEST, AT91C_AIC_SRCTYPE_INT_LEVEL_SENSITIVE, DefaultHandler );
2677 /* Set the IRQ exception vector */
2678 AT91F_AIC_SetExceptionVector( ( unsigned int * ) 0x18, IrqHandler );
2679 /* Set the Fast Interrupt exception vector */
2680 AT91F_AIC_SetExceptionVector( ( unsigned int * ) 0x1C, FiqHandler );
2682 pAic->AIC_SPU = ( unsigned int ) SpuriousHandler;
2683 pAic->AIC_DCR = protectMode;
2685 /**---------------------------------------------------------------------------- */
2686 /** \fn AT91F_MC_CfgPMC */
2687 /** \brief Enable Peripheral clock in PMC for MC */
2688 /**---------------------------------------------------------------------------- */
2689 __inline void AT91F_MC_CfgPMC( void )
2691 AT91F_PMC_EnablePeriphClock(
2692 AT91C_BASE_PMC, /* PIO controller base address */
2693 ( ( unsigned int ) 1 << AT91C_ID_SYS ) );
2696 /**---------------------------------------------------------------------------- */
2697 /** \fn AT91F_DBGU_CfgPMC */
2698 /** \brief Enable Peripheral clock in PMC for DBGU */
2699 /**---------------------------------------------------------------------------- */
2700 __inline void AT91F_DBGU_CfgPMC( void )
2702 AT91F_PMC_EnablePeriphClock(
2703 AT91C_BASE_PMC, /* PIO controller base address */
2704 ( ( unsigned int ) 1 << AT91C_ID_SYS ) );
2707 /**---------------------------------------------------------------------------- */
2708 /** \fn AT91F_DBGU_CfgPIO */
2709 /** \brief Configure PIO controllers to drive DBGU signals */
2710 /**---------------------------------------------------------------------------- */
2711 __inline void AT91F_DBGU_CfgPIO( void )
2713 /* Configure PIO controllers to periph mode */
2714 AT91F_PIO_CfgPeriph(
2715 AT91C_BASE_PIOA, /* PIO controller base address */
2716 ( ( unsigned int ) AT91C_PA10_DTXD ) |
2717 ( ( unsigned int ) AT91C_PA9_DRXD ), /* Peripheral A */
2718 0 ); /* Peripheral B */
2721 /**---------------------------------------------------------------------------- */
2722 /** \fn AT91F_PWMC_CH3_CfgPIO */
2723 /** \brief Configure PIO controllers to drive PWMC_CH3 signals */
2724 /**---------------------------------------------------------------------------- */
2725 __inline void AT91F_PWMC_CH3_CfgPIO( void )
2727 /* Configure PIO controllers to periph mode */
2728 AT91F_PIO_CfgPeriph(
2729 AT91C_BASE_PIOA, /* PIO controller base address */
2730 0, /* Peripheral A */
2731 ( ( unsigned int ) AT91C_PA14_PWM3 ) |
2732 ( ( unsigned int ) AT91C_PA7_PWM3 ) ); /* Peripheral B */
2735 /**---------------------------------------------------------------------------- */
2736 /** \fn AT91F_PWMC_CH2_CfgPIO */
2737 /** \brief Configure PIO controllers to drive PWMC_CH2 signals */
2738 /**---------------------------------------------------------------------------- */
2739 __inline void AT91F_PWMC_CH2_CfgPIO( void )
2741 /* Configure PIO controllers to periph mode */
2742 AT91F_PIO_CfgPeriph(
2743 AT91C_BASE_PIOA, /* PIO controller base address */
2744 ( ( unsigned int ) AT91C_PA2_PWM2 ), /* Peripheral A */
2745 ( ( unsigned int ) AT91C_PA25_PWM2 ) |
2746 ( ( unsigned int ) AT91C_PA13_PWM2 ) ); /* Peripheral B */
2749 /**---------------------------------------------------------------------------- */
2750 /** \fn AT91F_PWMC_CH1_CfgPIO */
2751 /** \brief Configure PIO controllers to drive PWMC_CH1 signals */
2752 /**---------------------------------------------------------------------------- */
2753 __inline void AT91F_PWMC_CH1_CfgPIO( void )
2755 /* Configure PIO controllers to periph mode */
2756 AT91F_PIO_CfgPeriph(
2757 AT91C_BASE_PIOA, /* PIO controller base address */
2758 ( ( unsigned int ) AT91C_PA1_PWM1 ), /* Peripheral A */
2759 ( ( unsigned int ) AT91C_PA24_PWM1 ) |
2760 ( ( unsigned int ) AT91C_PA12_PWM1 ) ); /* Peripheral B */
2763 /**---------------------------------------------------------------------------- */
2764 /** \fn AT91F_PWMC_CH0_CfgPIO */
2765 /** \brief Configure PIO controllers to drive PWMC_CH0 signals */
2766 /**---------------------------------------------------------------------------- */
2767 __inline void AT91F_PWMC_CH0_CfgPIO( void )
2769 /* Configure PIO controllers to periph mode */
2770 AT91F_PIO_CfgPeriph(
2771 AT91C_BASE_PIOA, /* PIO controller base address */
2772 ( ( unsigned int ) AT91C_PA0_PWM0 ), /* Peripheral A */
2773 ( ( unsigned int ) AT91C_PA23_PWM0 ) |
2774 ( ( unsigned int ) AT91C_PA11_PWM0 ) ); /* Peripheral B */
2777 /**---------------------------------------------------------------------------- */
2778 /** \fn AT91F_SSC_CfgPMC */
2779 /** \brief Enable Peripheral clock in PMC for SSC */
2780 /**---------------------------------------------------------------------------- */
2781 __inline void AT91F_SSC_CfgPMC( void )
2783 AT91F_PMC_EnablePeriphClock(
2784 AT91C_BASE_PMC, /* PIO controller base address */
2785 ( ( unsigned int ) 1 << AT91C_ID_SSC ) );
2788 /**---------------------------------------------------------------------------- */
2789 /** \fn AT91F_SSC_CfgPIO */
2790 /** \brief Configure PIO controllers to drive SSC signals */
2791 /**---------------------------------------------------------------------------- */
2792 __inline void AT91F_SSC_CfgPIO( void )
2794 /* Configure PIO controllers to periph mode */
2795 AT91F_PIO_CfgPeriph(
2796 AT91C_BASE_PIOA, /* PIO controller base address */
2797 ( ( unsigned int ) AT91C_PA17_TD ) |
2798 ( ( unsigned int ) AT91C_PA15_TF ) |
2799 ( ( unsigned int ) AT91C_PA19_RK ) |
2800 ( ( unsigned int ) AT91C_PA18_RD ) |
2801 ( ( unsigned int ) AT91C_PA20_RF ) |
2802 ( ( unsigned int ) AT91C_PA16_TK ), /* Peripheral A */
2803 0 ); /* Peripheral B */
2806 /**---------------------------------------------------------------------------- */
2807 /** \fn AT91F_SPI_CfgPMC */
2808 /** \brief Enable Peripheral clock in PMC for SPI */
2809 /**---------------------------------------------------------------------------- */
2810 __inline void AT91F_SPI_CfgPMC( void )
2812 AT91F_PMC_EnablePeriphClock(
2813 AT91C_BASE_PMC, /* PIO controller base address */
2814 ( ( unsigned int ) 1 << AT91C_ID_SPI ) );
2817 /**---------------------------------------------------------------------------- */
2818 /** \fn AT91F_SPI_CfgPIO */
2819 /** \brief Configure PIO controllers to drive SPI signals */
2820 /**---------------------------------------------------------------------------- */
2821 __inline void AT91F_SPI_CfgPIO( void )
2823 /* Configure PIO controllers to periph mode */
2824 AT91F_PIO_CfgPeriph(
2825 AT91C_BASE_PIOA, /* PIO controller base address */
2826 ( ( unsigned int ) AT91C_PA11_NPCS0 ) |
2827 ( ( unsigned int ) AT91C_PA13_MOSI ) |
2828 ( ( unsigned int ) AT91C_PA31_NPCS1 ) |
2829 ( ( unsigned int ) AT91C_PA12_MISO ) |
2830 ( ( unsigned int ) AT91C_PA14_SPCK ), /* Peripheral A */
2831 ( ( unsigned int ) AT91C_PA9_NPCS1 ) |
2832 ( ( unsigned int ) AT91C_PA30_NPCS2 ) |
2833 ( ( unsigned int ) AT91C_PA10_NPCS2 ) |
2834 ( ( unsigned int ) AT91C_PA22_NPCS3 ) |
2835 ( ( unsigned int ) AT91C_PA3_NPCS3 ) |
2836 ( ( unsigned int ) AT91C_PA5_NPCS3 ) ); /* Peripheral B */
2839 /**---------------------------------------------------------------------------- */
2840 /** \fn AT91F_PWMC_CfgPMC */
2841 /** \brief Enable Peripheral clock in PMC for PWMC */
2842 /**---------------------------------------------------------------------------- */
2843 __inline void AT91F_PWMC_CfgPMC( void )
2845 AT91F_PMC_EnablePeriphClock(
2846 AT91C_BASE_PMC, /* PIO controller base address */
2847 ( ( unsigned int ) 1 << AT91C_ID_PWMC ) );
2850 /**---------------------------------------------------------------------------- */
2851 /** \fn AT91F_TC2_CfgPMC */
2852 /** \brief Enable Peripheral clock in PMC for TC2 */
2853 /**---------------------------------------------------------------------------- */
2854 __inline void AT91F_TC2_CfgPMC( void )
2856 AT91F_PMC_EnablePeriphClock(
2857 AT91C_BASE_PMC, /* PIO controller base address */
2858 ( ( unsigned int ) 1 << AT91C_ID_TC2 ) );
2861 /**---------------------------------------------------------------------------- */
2862 /** \fn AT91F_TC2_CfgPIO */
2863 /** \brief Configure PIO controllers to drive TC2 signals */
2864 /**---------------------------------------------------------------------------- */
2865 __inline void AT91F_TC2_CfgPIO( void )
2867 /* Configure PIO controllers to periph mode */
2868 AT91F_PIO_CfgPeriph(
2869 AT91C_BASE_PIOA, /* PIO controller base address */
2870 0, /* Peripheral A */
2871 ( ( unsigned int ) AT91C_PA26_TIOA2 ) |
2872 ( ( unsigned int ) AT91C_PA27_TIOB2 ) |
2873 ( ( unsigned int ) AT91C_PA29_TCLK2 ) ); /* Peripheral B */
2876 /**---------------------------------------------------------------------------- */
2877 /** \fn AT91F_TC1_CfgPMC */
2878 /** \brief Enable Peripheral clock in PMC for TC1 */
2879 /**---------------------------------------------------------------------------- */
2880 __inline void AT91F_TC1_CfgPMC( void )
2882 AT91F_PMC_EnablePeriphClock(
2883 AT91C_BASE_PMC, /* PIO controller base address */
2884 ( ( unsigned int ) 1 << AT91C_ID_TC1 ) );
2887 /**---------------------------------------------------------------------------- */
2888 /** \fn AT91F_TC1_CfgPIO */
2889 /** \brief Configure PIO controllers to drive TC1 signals */
2890 /**---------------------------------------------------------------------------- */
2891 __inline void AT91F_TC1_CfgPIO( void )
2893 /* Configure PIO controllers to periph mode */
2894 AT91F_PIO_CfgPeriph(
2895 AT91C_BASE_PIOA, /* PIO controller base address */
2896 0, /* Peripheral A */
2897 ( ( unsigned int ) AT91C_PA15_TIOA1 ) |
2898 ( ( unsigned int ) AT91C_PA16_TIOB1 ) |
2899 ( ( unsigned int ) AT91C_PA28_TCLK1 ) ); /* Peripheral B */
2902 /**---------------------------------------------------------------------------- */
2903 /** \fn AT91F_TC0_CfgPMC */
2904 /** \brief Enable Peripheral clock in PMC for TC0 */
2905 /**---------------------------------------------------------------------------- */
2906 __inline void AT91F_TC0_CfgPMC( void )
2908 AT91F_PMC_EnablePeriphClock(
2909 AT91C_BASE_PMC, /* PIO controller base address */
2910 ( ( unsigned int ) 1 << AT91C_ID_TC0 ) );
2913 /**---------------------------------------------------------------------------- */
2914 /** \fn AT91F_TC0_CfgPIO */
2915 /** \brief Configure PIO controllers to drive TC0 signals */
2916 /**---------------------------------------------------------------------------- */
2917 __inline void AT91F_TC0_CfgPIO( void )
2919 /* Configure PIO controllers to periph mode */
2920 AT91F_PIO_CfgPeriph(
2921 AT91C_BASE_PIOA, /* PIO controller base address */
2922 0, /* Peripheral A */
2923 ( ( unsigned int ) AT91C_PA0_TIOA0 ) |
2924 ( ( unsigned int ) AT91C_PA1_TIOB0 ) |
2925 ( ( unsigned int ) AT91C_PA4_TCLK0 ) ); /* Peripheral B */
2928 /**---------------------------------------------------------------------------- */
2929 /** \fn AT91F_PMC_CfgPMC */
2930 /** \brief Enable Peripheral clock in PMC for PMC */
2931 /**---------------------------------------------------------------------------- */
2932 __inline void AT91F_PMC_CfgPMC( void )
2934 AT91F_PMC_EnablePeriphClock(
2935 AT91C_BASE_PMC, /* PIO controller base address */
2936 ( ( unsigned int ) 1 << AT91C_ID_SYS ) );
2939 /**---------------------------------------------------------------------------- */
2940 /** \fn AT91F_PMC_CfgPIO */
2941 /** \brief Configure PIO controllers to drive PMC signals */
2942 /**---------------------------------------------------------------------------- */
2943 __inline void AT91F_PMC_CfgPIO( void )
2945 /* Configure PIO controllers to periph mode */
2946 AT91F_PIO_CfgPeriph(
2947 AT91C_BASE_PIOA, /* PIO controller base address */
2948 0, /* Peripheral A */
2949 ( ( unsigned int ) AT91C_PA17_PCK1 ) |
2950 ( ( unsigned int ) AT91C_PA21_PCK1 ) |
2951 ( ( unsigned int ) AT91C_PA31_PCK2 ) |
2952 ( ( unsigned int ) AT91C_PA18_PCK2 ) |
2953 ( ( unsigned int ) AT91C_PA6_PCK0 ) ); /* Peripheral B */
2956 /**---------------------------------------------------------------------------- */
2957 /** \fn AT91F_ADC_CfgPMC */
2958 /** \brief Enable Peripheral clock in PMC for ADC */
2959 /**---------------------------------------------------------------------------- */
2960 __inline void AT91F_ADC_CfgPMC( void )
2962 AT91F_PMC_EnablePeriphClock(
2963 AT91C_BASE_PMC, /* PIO controller base address */
2964 ( ( unsigned int ) 1 << AT91C_ID_ADC ) );
2967 /**---------------------------------------------------------------------------- */
2968 /** \fn AT91F_ADC_CfgPIO */
2969 /** \brief Configure PIO controllers to drive ADC signals */
2970 /**---------------------------------------------------------------------------- */
2971 __inline void AT91F_ADC_CfgPIO( void )
2973 /* Configure PIO controllers to periph mode */
2974 AT91F_PIO_CfgPeriph(
2975 AT91C_BASE_PIOA, /* PIO controller base address */
2976 0, /* Peripheral A */
2977 ( ( unsigned int ) AT91C_PA8_ADTRG ) ); /* Peripheral B */
2980 /**---------------------------------------------------------------------------- */
2981 /** \fn AT91F_PIOA_CfgPMC */
2982 /** \brief Enable Peripheral clock in PMC for PIOA */
2983 /**---------------------------------------------------------------------------- */
2984 __inline void AT91F_PIOA_CfgPMC( void )
2986 AT91F_PMC_EnablePeriphClock(
2987 AT91C_BASE_PMC, /* PIO controller base address */
2988 ( ( unsigned int ) 1 << AT91C_ID_PIOA ) );
2991 /**---------------------------------------------------------------------------- */
2992 /** \fn AT91F_TWI_CfgPMC */
2993 /** \brief Enable Peripheral clock in PMC for TWI */
2994 /**---------------------------------------------------------------------------- */
2995 __inline void AT91F_TWI_CfgPMC( void )
2997 AT91F_PMC_EnablePeriphClock(
2998 AT91C_BASE_PMC, /* PIO controller base address */
2999 ( ( unsigned int ) 1 << AT91C_ID_TWI ) );
3002 /**---------------------------------------------------------------------------- */
3003 /** \fn AT91F_TWI_CfgPIO */
3004 /** \brief Configure PIO controllers to drive TWI signals */
3005 /**---------------------------------------------------------------------------- */
3006 __inline void AT91F_TWI_CfgPIO( void )
3008 /* Configure PIO controllers to periph mode */
3009 AT91F_PIO_CfgPeriph(
3010 AT91C_BASE_PIOA, /* PIO controller base address */
3011 ( ( unsigned int ) AT91C_PA3_TWD ) |
3012 ( ( unsigned int ) AT91C_PA4_TWCK ), /* Peripheral A */
3013 0 ); /* Peripheral B */
3016 /**---------------------------------------------------------------------------- */
3017 /** \fn AT91F_US1_CfgPMC */
3018 /** \brief Enable Peripheral clock in PMC for US1 */
3019 /**---------------------------------------------------------------------------- */
3020 __inline void AT91F_US1_CfgPMC( void )
3022 AT91F_PMC_EnablePeriphClock(
3023 AT91C_BASE_PMC, /* PIO controller base address */
3024 ( ( unsigned int ) 1 << AT91C_ID_US1 ) );
3027 /**---------------------------------------------------------------------------- */
3028 /** \fn AT91F_US1_CfgPIO */
3029 /** \brief Configure PIO controllers to drive US1 signals */
3030 /**---------------------------------------------------------------------------- */
3031 __inline void AT91F_US1_CfgPIO( void )
3033 /* Configure PIO controllers to periph mode */
3034 AT91F_PIO_CfgPeriph(
3035 AT91C_BASE_PIOA, /* PIO controller base address */
3036 ( ( unsigned int ) AT91C_PA21_RXD1 ) |
3037 ( ( unsigned int ) AT91C_PA27_DTR1 ) |
3038 ( ( unsigned int ) AT91C_PA26_DCD1 ) |
3039 ( ( unsigned int ) AT91C_PA22_TXD1 ) |
3040 ( ( unsigned int ) AT91C_PA24_RTS1 ) |
3041 ( ( unsigned int ) AT91C_PA23_SCK1 ) |
3042 ( ( unsigned int ) AT91C_PA28_DSR1 ) |
3043 ( ( unsigned int ) AT91C_PA29_RI1 ) |
3044 ( ( unsigned int ) AT91C_PA25_CTS1 ), /* Peripheral A */
3045 0 ); /* Peripheral B */
3048 /**---------------------------------------------------------------------------- */
3049 /** \fn AT91F_US0_CfgPMC */
3050 /** \brief Enable Peripheral clock in PMC for US0 */
3051 /**---------------------------------------------------------------------------- */
3052 __inline void AT91F_US0_CfgPMC( void )
3054 AT91F_PMC_EnablePeriphClock(
3055 AT91C_BASE_PMC, /* PIO controller base address */
3056 ( ( unsigned int ) 1 << AT91C_ID_US0 ) );
3059 /**---------------------------------------------------------------------------- */
3060 /** \fn AT91F_US0_CfgPIO */
3061 /** \brief Configure PIO controllers to drive US0 signals */
3062 /**---------------------------------------------------------------------------- */
3063 __inline void AT91F_US0_CfgPIO( void )
3065 /* Configure PIO controllers to periph mode */
3066 AT91F_PIO_CfgPeriph(
3067 AT91C_BASE_PIOA, /* PIO controller base address */
3068 ( ( unsigned int ) AT91C_PA5_RXD0 ) |
3069 ( ( unsigned int ) AT91C_PA6_TXD0 ) |
3070 ( ( unsigned int ) AT91C_PA7_RTS0 ) |
3071 ( ( unsigned int ) AT91C_PA8_CTS0 ), /* Peripheral A */
3072 ( ( unsigned int ) AT91C_PA2_SCK0 ) ); /* Peripheral B */
3075 /**---------------------------------------------------------------------------- */
3076 /** \fn AT91F_UDP_CfgPMC */
3077 /** \brief Enable Peripheral clock in PMC for UDP */
3078 /**---------------------------------------------------------------------------- */
3079 __inline void AT91F_UDP_CfgPMC( void )
3081 AT91F_PMC_EnablePeriphClock(
3082 AT91C_BASE_PMC, /* PIO controller base address */
3083 ( ( unsigned int ) 1 << AT91C_ID_UDP ) );
3086 /**---------------------------------------------------------------------------- */
3087 /** \fn AT91F_AIC_CfgPMC */
3088 /** \brief Enable Peripheral clock in PMC for AIC */
3089 /**---------------------------------------------------------------------------- */
3090 __inline void AT91F_AIC_CfgPMC( void )
3092 AT91F_PMC_EnablePeriphClock(
3093 AT91C_BASE_PMC, /* PIO controller base address */
3094 ( ( unsigned int ) 1 << AT91C_ID_IRQ0 ) |
3095 ( ( unsigned int ) 1 << AT91C_ID_FIQ ) |
3096 ( ( unsigned int ) 1 << AT91C_ID_IRQ1 ) );
3099 /**---------------------------------------------------------------------------- */
3100 /** \fn AT91F_AIC_CfgPIO */
3101 /** \brief Configure PIO controllers to drive AIC signals */
3102 /**---------------------------------------------------------------------------- */
3103 __inline void AT91F_AIC_CfgPIO( void )
3105 /* Configure PIO controllers to periph mode */
3106 AT91F_PIO_CfgPeriph(
3107 AT91C_BASE_PIOA, /* PIO controller base address */
3108 ( ( unsigned int ) AT91C_PA30_IRQ1 ), /* Peripheral A */
3109 ( ( unsigned int ) AT91C_PA20_IRQ0 ) |
3110 ( ( unsigned int ) AT91C_PA19_FIQ ) ); /* Peripheral B */
3113 #endif // lib_AT91SAM7S64_H