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
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 (
55 AT91PS_MC pMC, // pointer to a MC controller
56 unsigned int mode) // mode register
58 // Write to the FMR register
62 //*----------------------------------------------------------------------------
63 //* \fn AT91F_MC_EFC_GetModeReg
64 //* \brief Return MC EFC Mode Regsiter
65 //*----------------------------------------------------------------------------
66 __inline unsigned int AT91F_MC_EFC_GetModeReg(
67 AT91PS_MC pMC) // pointer to a MC controller
72 //*----------------------------------------------------------------------------
73 //* \fn AT91F_MC_EFC_ComputeFMCN
74 //* \brief Return MC EFC Mode Regsiter
75 //*----------------------------------------------------------------------------
76 __inline unsigned int AT91F_MC_EFC_ComputeFMCN(
77 int master_clock) // master clock in Hz
79 return (master_clock/1000000 +2);
82 //*----------------------------------------------------------------------------
83 //* \fn AT91F_MC_EFC_PerformCmd
84 //* \brief Perform EFC Command
85 //*----------------------------------------------------------------------------
86 __inline void AT91F_MC_EFC_PerformCmd (
87 AT91PS_MC pMC, // pointer to a MC controller
88 unsigned int transfer_cmd)
90 pMC->MC_FCR = transfer_cmd;
93 //*----------------------------------------------------------------------------
94 //* \fn AT91F_MC_EFC_GetStatus
95 //* \brief Return MC EFC Status
96 //*----------------------------------------------------------------------------
97 __inline unsigned int AT91F_MC_EFC_GetStatus(
98 AT91PS_MC pMC) // pointer to a MC controller
103 //*----------------------------------------------------------------------------
104 //* \fn AT91F_MC_EFC_IsInterruptMasked
105 //* \brief Test if EFC MC Interrupt is Masked
106 //*----------------------------------------------------------------------------
107 __inline unsigned int AT91F_MC_EFC_IsInterruptMasked(
108 AT91PS_MC pMC, // \arg pointer to a MC controller
109 unsigned int flag) // \arg flag to be tested
111 return (AT91F_MC_EFC_GetModeReg(pMC) & flag);
114 //*----------------------------------------------------------------------------
115 //* \fn AT91F_MC_EFC_IsInterruptSet
116 //* \brief Test if EFC MC Interrupt is Set
117 //*----------------------------------------------------------------------------
118 __inline unsigned int AT91F_MC_EFC_IsInterruptSet(
119 AT91PS_MC pMC, // \arg pointer to a MC controller
120 unsigned int flag) // \arg flag to be tested
122 return (AT91F_MC_EFC_GetStatus(pMC) & flag);
125 /* *****************************************************************************
127 ***************************************************************************** */
128 //*----------------------------------------------------------------------------
129 //* \fn AT91F_PDC_SetNextRx
130 //* \brief Set the next receive transfer descriptor
131 //*----------------------------------------------------------------------------
132 __inline void AT91F_PDC_SetNextRx (
133 AT91PS_PDC pPDC, // \arg pointer to a PDC controller
134 char *address, // \arg address to the next bloc to be received
135 unsigned int bytes) // \arg number of bytes to be received
137 pPDC->PDC_RNPR = (unsigned int) address;
138 pPDC->PDC_RNCR = bytes;
141 //*----------------------------------------------------------------------------
142 //* \fn AT91F_PDC_SetNextTx
143 //* \brief Set the next transmit transfer descriptor
144 //*----------------------------------------------------------------------------
145 __inline void AT91F_PDC_SetNextTx (
146 AT91PS_PDC pPDC, // \arg pointer to a PDC controller
147 char *address, // \arg address to the next bloc to be transmitted
148 unsigned int bytes) // \arg number of bytes to be transmitted
150 pPDC->PDC_TNPR = (unsigned int) address;
151 pPDC->PDC_TNCR = bytes;
154 //*----------------------------------------------------------------------------
155 //* \fn AT91F_PDC_SetRx
156 //* \brief Set the receive transfer descriptor
157 //*----------------------------------------------------------------------------
158 __inline void AT91F_PDC_SetRx (
159 AT91PS_PDC pPDC, // \arg pointer to a PDC controller
160 char *address, // \arg address to the next bloc to be received
161 unsigned int bytes) // \arg number of bytes to be received
163 pPDC->PDC_RPR = (unsigned int) address;
164 pPDC->PDC_RCR = bytes;
167 //*----------------------------------------------------------------------------
168 //* \fn AT91F_PDC_SetTx
169 //* \brief Set the transmit transfer descriptor
170 //*----------------------------------------------------------------------------
171 __inline void AT91F_PDC_SetTx (
172 AT91PS_PDC pPDC, // \arg pointer to a PDC controller
173 char *address, // \arg address to the next bloc to be transmitted
174 unsigned int bytes) // \arg number of bytes to be transmitted
176 pPDC->PDC_TPR = (unsigned int) address;
177 pPDC->PDC_TCR = bytes;
180 //*----------------------------------------------------------------------------
181 //* \fn AT91F_PDC_EnableTx
182 //* \brief Enable transmit
183 //*----------------------------------------------------------------------------
184 __inline void AT91F_PDC_EnableTx (
185 AT91PS_PDC pPDC ) // \arg pointer to a PDC controller
187 pPDC->PDC_PTCR = AT91C_PDC_TXTEN;
190 //*----------------------------------------------------------------------------
191 //* \fn AT91F_PDC_EnableRx
192 //* \brief Enable receive
193 //*----------------------------------------------------------------------------
194 __inline void AT91F_PDC_EnableRx (
195 AT91PS_PDC pPDC ) // \arg pointer to a PDC controller
197 pPDC->PDC_PTCR = AT91C_PDC_RXTEN;
200 //*----------------------------------------------------------------------------
201 //* \fn AT91F_PDC_DisableTx
202 //* \brief Disable transmit
203 //*----------------------------------------------------------------------------
204 __inline void AT91F_PDC_DisableTx (
205 AT91PS_PDC pPDC ) // \arg pointer to a PDC controller
207 pPDC->PDC_PTCR = AT91C_PDC_TXTDIS;
210 //*----------------------------------------------------------------------------
211 //* \fn AT91F_PDC_DisableRx
212 //* \brief Disable receive
213 //*----------------------------------------------------------------------------
214 __inline void AT91F_PDC_DisableRx (
215 AT91PS_PDC pPDC ) // \arg pointer to a PDC controller
217 pPDC->PDC_PTCR = AT91C_PDC_RXTDIS;
220 //*----------------------------------------------------------------------------
221 //* \fn AT91F_PDC_IsTxEmpty
222 //* \brief Test if the current transfer descriptor has been sent
223 //*----------------------------------------------------------------------------
224 __inline int AT91F_PDC_IsTxEmpty ( // \return return 1 if transfer is complete
225 AT91PS_PDC pPDC ) // \arg pointer to a PDC controller
227 return !(pPDC->PDC_TCR);
230 //*----------------------------------------------------------------------------
231 //* \fn AT91F_PDC_IsNextTxEmpty
232 //* \brief Test if the next transfer descriptor has been moved to the current td
233 //*----------------------------------------------------------------------------
234 __inline int AT91F_PDC_IsNextTxEmpty ( // \return return 1 if transfer is complete
235 AT91PS_PDC pPDC ) // \arg pointer to a PDC controller
237 return !(pPDC->PDC_TNCR);
240 //*----------------------------------------------------------------------------
241 //* \fn AT91F_PDC_IsRxEmpty
242 //* \brief Test if the current transfer descriptor has been filled
243 //*----------------------------------------------------------------------------
244 __inline int AT91F_PDC_IsRxEmpty ( // \return return 1 if transfer is complete
245 AT91PS_PDC pPDC ) // \arg pointer to a PDC controller
247 return !(pPDC->PDC_RCR);
250 //*----------------------------------------------------------------------------
251 //* \fn AT91F_PDC_IsNextRxEmpty
252 //* \brief Test if the next transfer descriptor has been moved to the current td
253 //*----------------------------------------------------------------------------
254 __inline int AT91F_PDC_IsNextRxEmpty ( // \return return 1 if transfer is complete
255 AT91PS_PDC pPDC ) // \arg pointer to a PDC controller
257 return !(pPDC->PDC_RNCR);
260 //*----------------------------------------------------------------------------
261 //* \fn AT91F_PDC_Open
262 //* \brief Open PDC: disable TX and RX reset transfer descriptors, re-enable RX and TX
263 //*----------------------------------------------------------------------------
264 __inline void AT91F_PDC_Open (
265 AT91PS_PDC pPDC) // \arg pointer to a PDC controller
267 //* Disable the RX and TX PDC transfer requests
268 AT91F_PDC_DisableRx(pPDC);
269 AT91F_PDC_DisableTx(pPDC);
271 //* Reset all Counter register Next buffer first
272 AT91F_PDC_SetNextTx(pPDC, (char *) 0, 0);
273 AT91F_PDC_SetNextRx(pPDC, (char *) 0, 0);
274 AT91F_PDC_SetTx(pPDC, (char *) 0, 0);
275 AT91F_PDC_SetRx(pPDC, (char *) 0, 0);
277 //* Enable the RX and TX PDC transfer requests
278 AT91F_PDC_EnableRx(pPDC);
279 AT91F_PDC_EnableTx(pPDC);
282 //*----------------------------------------------------------------------------
283 //* \fn AT91F_PDC_Close
284 //* \brief Close PDC: disable TX and RX reset transfer descriptors
285 //*----------------------------------------------------------------------------
286 __inline void AT91F_PDC_Close (
287 AT91PS_PDC pPDC) // \arg pointer to a PDC controller
289 //* Disable the RX and TX PDC transfer requests
290 AT91F_PDC_DisableRx(pPDC);
291 AT91F_PDC_DisableTx(pPDC);
293 //* Reset all Counter register Next buffer first
294 AT91F_PDC_SetNextTx(pPDC, (char *) 0, 0);
295 AT91F_PDC_SetNextRx(pPDC, (char *) 0, 0);
296 AT91F_PDC_SetTx(pPDC, (char *) 0, 0);
297 AT91F_PDC_SetRx(pPDC, (char *) 0, 0);
301 //*----------------------------------------------------------------------------
302 //* \fn AT91F_PDC_SendFrame
303 //* \brief Close PDC: disable TX and RX reset transfer descriptors
304 //*----------------------------------------------------------------------------
305 __inline unsigned int AT91F_PDC_SendFrame(
308 unsigned int szBuffer,
310 unsigned int szNextBuffer )
312 if (AT91F_PDC_IsTxEmpty(pPDC)) {
313 //* Buffer and next buffer can be initialized
314 AT91F_PDC_SetTx(pPDC, pBuffer, szBuffer);
315 AT91F_PDC_SetNextTx(pPDC, pNextBuffer, szNextBuffer);
318 else if (AT91F_PDC_IsNextTxEmpty(pPDC)) {
319 //* Only one buffer can be initialized
320 AT91F_PDC_SetNextTx(pPDC, pBuffer, szBuffer);
324 //* All buffer are in use...
329 //*----------------------------------------------------------------------------
330 //* \fn AT91F_PDC_ReceiveFrame
331 //* \brief Close PDC: disable TX and RX reset transfer descriptors
332 //*----------------------------------------------------------------------------
333 __inline unsigned int AT91F_PDC_ReceiveFrame (
336 unsigned int szBuffer,
338 unsigned int szNextBuffer )
340 if (AT91F_PDC_IsRxEmpty(pPDC)) {
341 //* Buffer and next buffer can be initialized
342 AT91F_PDC_SetRx(pPDC, pBuffer, szBuffer);
343 AT91F_PDC_SetNextRx(pPDC, pNextBuffer, szNextBuffer);
346 else if (AT91F_PDC_IsNextRxEmpty(pPDC)) {
347 //* Only one buffer can be initialized
348 AT91F_PDC_SetNextRx(pPDC, pBuffer, szBuffer);
352 //* All buffer are in use...
356 /* *****************************************************************************
357 SOFTWARE API FOR DBGU
358 ***************************************************************************** */
359 //*----------------------------------------------------------------------------
360 //* \fn AT91F_DBGU_InterruptEnable
361 //* \brief Enable DBGU Interrupt
362 //*----------------------------------------------------------------------------
363 __inline void AT91F_DBGU_InterruptEnable(
364 AT91PS_DBGU pDbgu, // \arg pointer to a DBGU controller
365 unsigned int flag) // \arg dbgu interrupt to be enabled
367 pDbgu->DBGU_IER = flag;
370 //*----------------------------------------------------------------------------
371 //* \fn AT91F_DBGU_InterruptDisable
372 //* \brief Disable DBGU Interrupt
373 //*----------------------------------------------------------------------------
374 __inline void AT91F_DBGU_InterruptDisable(
375 AT91PS_DBGU pDbgu, // \arg pointer to a DBGU controller
376 unsigned int flag) // \arg dbgu interrupt to be disabled
378 pDbgu->DBGU_IDR = flag;
381 //*----------------------------------------------------------------------------
382 //* \fn AT91F_DBGU_GetInterruptMaskStatus
383 //* \brief Return DBGU Interrupt Mask Status
384 //*----------------------------------------------------------------------------
385 __inline unsigned int AT91F_DBGU_GetInterruptMaskStatus( // \return DBGU Interrupt Mask Status
386 AT91PS_DBGU pDbgu) // \arg pointer to a DBGU controller
388 return pDbgu->DBGU_IMR;
391 //*----------------------------------------------------------------------------
392 //* \fn AT91F_DBGU_IsInterruptMasked
393 //* \brief Test if DBGU Interrupt is Masked
394 //*----------------------------------------------------------------------------
395 __inline int AT91F_DBGU_IsInterruptMasked(
396 AT91PS_DBGU pDbgu, // \arg pointer to a DBGU controller
397 unsigned int flag) // \arg flag to be tested
399 return (AT91F_DBGU_GetInterruptMaskStatus(pDbgu) & flag);
402 /* *****************************************************************************
404 ***************************************************************************** */
405 //* Define the standard I2S mode configuration
407 //* Configuration to set in the SSC Transmit Clock Mode Register
408 //* Parameters : nb_bit_by_slot : 8, 16 or 32 bits
409 //* nb_slot_by_frame : number of channels
410 #define AT91C_I2S_ASY_MASTER_TX_SETTING(nb_bit_by_slot, nb_slot_by_frame)( +\
412 AT91C_SSC_CKO_CONTINOUS +\
413 AT91C_SSC_CKG_NONE +\
414 AT91C_SSC_START_FALL_RF +\
416 ((1<<16) & AT91C_SSC_STTDLY) +\
417 ((((nb_bit_by_slot*nb_slot_by_frame)/2)-1) <<24))
420 //* Configuration to set in the SSC Transmit Frame Mode Register
421 //* Parameters : nb_bit_by_slot : 8, 16 or 32 bits
422 //* nb_slot_by_frame : number of channels
423 #define AT91C_I2S_ASY_TX_FRAME_SETTING(nb_bit_by_slot, nb_slot_by_frame)( +\
424 (nb_bit_by_slot-1) +\
426 (((nb_slot_by_frame-1)<<8) & AT91C_SSC_DATNB) +\
427 (((nb_bit_by_slot-1)<<16) & AT91C_SSC_FSLEN) +\
428 AT91C_SSC_FSOS_NEGATIVE)
431 //*----------------------------------------------------------------------------
432 //* \fn AT91F_SSC_SetBaudrate
433 //* \brief Set the baudrate according to the CPU clock
434 //*----------------------------------------------------------------------------
435 __inline void AT91F_SSC_SetBaudrate (
436 AT91PS_SSC pSSC, // \arg pointer to a SSC controller
437 unsigned int mainClock, // \arg peripheral clock
438 unsigned int speed) // \arg SSC baudrate
440 unsigned int baud_value;
441 //* Define the baud rate divisor register
446 baud_value = (unsigned int) (mainClock * 10)/(2*speed);
447 if ((baud_value % 10) >= 5)
448 baud_value = (baud_value / 10) + 1;
453 pSSC->SSC_CMR = baud_value;
456 //*----------------------------------------------------------------------------
457 //* \fn AT91F_SSC_Configure
458 //* \brief Configure SSC
459 //*----------------------------------------------------------------------------
460 __inline void AT91F_SSC_Configure (
461 AT91PS_SSC pSSC, // \arg pointer to a SSC controller
462 unsigned int syst_clock, // \arg System Clock Frequency
463 unsigned int baud_rate, // \arg Expected Baud Rate Frequency
464 unsigned int clock_rx, // \arg Receiver Clock Parameters
465 unsigned int mode_rx, // \arg mode Register to be programmed
466 unsigned int clock_tx, // \arg Transmitter Clock Parameters
467 unsigned int mode_tx) // \arg mode Register to be programmed
469 //* Disable interrupts
470 pSSC->SSC_IDR = (unsigned int) -1;
472 //* Reset receiver and transmitter
473 pSSC->SSC_CR = AT91C_SSC_SWRST | AT91C_SSC_RXDIS | AT91C_SSC_TXDIS ;
475 //* Define the Clock Mode Register
476 AT91F_SSC_SetBaudrate(pSSC, syst_clock, baud_rate);
478 //* Write the Receive Clock Mode Register
479 pSSC->SSC_RCMR = clock_rx;
481 //* Write the Transmit Clock Mode Register
482 pSSC->SSC_TCMR = clock_tx;
484 //* Write the Receive Frame Mode Register
485 pSSC->SSC_RFMR = mode_rx;
487 //* Write the Transmit Frame Mode Register
488 pSSC->SSC_TFMR = mode_tx;
490 //* Clear Transmit and Receive Counters
491 AT91F_PDC_Open((AT91PS_PDC) &(pSSC->SSC_RPR));
496 //*----------------------------------------------------------------------------
497 //* \fn AT91F_SSC_EnableRx
498 //* \brief Enable receiving datas
499 //*----------------------------------------------------------------------------
500 __inline void AT91F_SSC_EnableRx (
501 AT91PS_SSC pSSC) // \arg pointer to a SSC controller
504 pSSC->SSC_CR = AT91C_SSC_RXEN;
507 //*----------------------------------------------------------------------------
508 //* \fn AT91F_SSC_DisableRx
509 //* \brief Disable receiving datas
510 //*----------------------------------------------------------------------------
511 __inline void AT91F_SSC_DisableRx (
512 AT91PS_SSC pSSC) // \arg pointer to a SSC controller
515 pSSC->SSC_CR = AT91C_SSC_RXDIS;
518 //*----------------------------------------------------------------------------
519 //* \fn AT91F_SSC_EnableTx
520 //* \brief Enable sending datas
521 //*----------------------------------------------------------------------------
522 __inline void AT91F_SSC_EnableTx (
523 AT91PS_SSC pSSC) // \arg pointer to a SSC controller
525 //* Enable transmitter
526 pSSC->SSC_CR = AT91C_SSC_TXEN;
529 //*----------------------------------------------------------------------------
530 //* \fn AT91F_SSC_DisableTx
531 //* \brief Disable sending datas
532 //*----------------------------------------------------------------------------
533 __inline void AT91F_SSC_DisableTx (
534 AT91PS_SSC pSSC) // \arg pointer to a SSC controller
536 //* Disable transmitter
537 pSSC->SSC_CR = AT91C_SSC_TXDIS;
540 //*----------------------------------------------------------------------------
541 //* \fn AT91F_SSC_EnableIt
542 //* \brief Enable SSC IT
543 //*----------------------------------------------------------------------------
544 __inline void AT91F_SSC_EnableIt (
545 AT91PS_SSC pSSC, // \arg pointer to a SSC controller
546 unsigned int flag) // \arg IT to be enabled
548 //* Write to the IER register
549 pSSC->SSC_IER = flag;
552 //*----------------------------------------------------------------------------
553 //* \fn AT91F_SSC_DisableIt
554 //* \brief Disable SSC IT
555 //*----------------------------------------------------------------------------
556 __inline void AT91F_SSC_DisableIt (
557 AT91PS_SSC pSSC, // \arg pointer to a SSC controller
558 unsigned int flag) // \arg IT to be disabled
560 //* Write to the IDR register
561 pSSC->SSC_IDR = flag;
564 //*----------------------------------------------------------------------------
565 //* \fn AT91F_SSC_ReceiveFrame
566 //* \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
567 //*----------------------------------------------------------------------------
568 __inline unsigned int AT91F_SSC_ReceiveFrame (
571 unsigned int szBuffer,
573 unsigned int szNextBuffer )
575 return AT91F_PDC_ReceiveFrame(
576 (AT91PS_PDC) &(pSSC->SSC_RPR),
583 //*----------------------------------------------------------------------------
584 //* \fn AT91F_SSC_SendFrame
585 //* \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
586 //*----------------------------------------------------------------------------
587 __inline unsigned int AT91F_SSC_SendFrame(
590 unsigned int szBuffer,
592 unsigned int szNextBuffer )
594 return AT91F_PDC_SendFrame(
595 (AT91PS_PDC) &(pSSC->SSC_RPR),
602 //*----------------------------------------------------------------------------
603 //* \fn AT91F_SSC_GetInterruptMaskStatus
604 //* \brief Return SSC Interrupt Mask Status
605 //*----------------------------------------------------------------------------
606 __inline unsigned int AT91F_SSC_GetInterruptMaskStatus( // \return SSC Interrupt Mask Status
607 AT91PS_SSC pSsc) // \arg pointer to a SSC controller
609 return pSsc->SSC_IMR;
612 //*----------------------------------------------------------------------------
613 //* \fn AT91F_SSC_IsInterruptMasked
614 //* \brief Test if SSC Interrupt is Masked
615 //*----------------------------------------------------------------------------
616 __inline int AT91F_SSC_IsInterruptMasked(
617 AT91PS_SSC pSsc, // \arg pointer to a SSC controller
618 unsigned int flag) // \arg flag to be tested
620 return (AT91F_SSC_GetInterruptMaskStatus(pSsc) & flag);
623 /* *****************************************************************************
625 ***************************************************************************** */
626 //*----------------------------------------------------------------------------
627 //* \fn AT91F_SPI_Open
628 //* \brief Open a SPI Port
629 //*----------------------------------------------------------------------------
630 __inline unsigned int AT91F_SPI_Open (
631 const unsigned int null) // \arg
633 /* NOT DEFINED AT THIS MOMENT */
637 //*----------------------------------------------------------------------------
638 //* \fn AT91F_SPI_CfgCs
639 //* \brief Configure SPI chip select register
640 //*----------------------------------------------------------------------------
641 __inline void AT91F_SPI_CfgCs (
642 AT91PS_SPI pSPI, // pointer to a SPI controller
643 int cs, // SPI cs number (0 to 3)
644 int val) // chip select register
646 //* Write to the CSR register
647 *(pSPI->SPI_CSR + cs) = val;
650 //*----------------------------------------------------------------------------
651 //* \fn AT91F_SPI_EnableIt
652 //* \brief Enable SPI interrupt
653 //*----------------------------------------------------------------------------
654 __inline void AT91F_SPI_EnableIt (
655 AT91PS_SPI pSPI, // pointer to a SPI controller
656 unsigned int flag) // IT to be enabled
658 //* Write to the IER register
659 pSPI->SPI_IER = flag;
662 //*----------------------------------------------------------------------------
663 //* \fn AT91F_SPI_DisableIt
664 //* \brief Disable SPI interrupt
665 //*----------------------------------------------------------------------------
666 __inline void AT91F_SPI_DisableIt (
667 AT91PS_SPI pSPI, // pointer to a SPI controller
668 unsigned int flag) // IT to be disabled
670 //* Write to the IDR register
671 pSPI->SPI_IDR = flag;
674 //*----------------------------------------------------------------------------
675 //* \fn AT91F_SPI_Reset
676 //* \brief Reset the SPI controller
677 //*----------------------------------------------------------------------------
678 __inline void AT91F_SPI_Reset (
679 AT91PS_SPI pSPI // pointer to a SPI controller
682 //* Write to the CR register
683 pSPI->SPI_CR = AT91C_SPI_SWRST;
686 //*----------------------------------------------------------------------------
687 //* \fn AT91F_SPI_Enable
688 //* \brief Enable the SPI controller
689 //*----------------------------------------------------------------------------
690 __inline void AT91F_SPI_Enable (
691 AT91PS_SPI pSPI // pointer to a SPI controller
694 //* Write to the CR register
695 pSPI->SPI_CR = AT91C_SPI_SPIEN;
698 //*----------------------------------------------------------------------------
699 //* \fn AT91F_SPI_Disable
700 //* \brief Disable the SPI controller
701 //*----------------------------------------------------------------------------
702 __inline void AT91F_SPI_Disable (
703 AT91PS_SPI pSPI // pointer to a SPI controller
706 //* Write to the CR register
707 pSPI->SPI_CR = AT91C_SPI_SPIDIS;
710 //*----------------------------------------------------------------------------
711 //* \fn AT91F_SPI_CfgMode
712 //* \brief Enable the SPI controller
713 //*----------------------------------------------------------------------------
714 __inline void AT91F_SPI_CfgMode (
715 AT91PS_SPI pSPI, // pointer to a SPI controller
716 int mode) // mode register
718 //* Write to the MR register
722 //*----------------------------------------------------------------------------
723 //* \fn AT91F_SPI_CfgPCS
724 //* \brief Switch to the correct PCS of SPI Mode Register : Fixed Peripheral Selected
725 //*----------------------------------------------------------------------------
726 __inline void AT91F_SPI_CfgPCS (
727 AT91PS_SPI pSPI, // pointer to a SPI controller
728 char PCS_Device) // PCS of the Device
730 //* Write to the MR register
731 pSPI->SPI_MR &= 0xFFF0FFFF;
732 pSPI->SPI_MR |= ( (PCS_Device<<16) & AT91C_SPI_PCS );
735 //*----------------------------------------------------------------------------
736 //* \fn AT91F_SPI_ReceiveFrame
737 //* \brief Return 2 if PDC has been initialized with Buffer and Next Buffer, 1 if PDC has been initializaed with Next Buffer, 0 if PDC is busy
738 //*----------------------------------------------------------------------------
739 __inline unsigned int AT91F_SPI_ReceiveFrame (
742 unsigned int szBuffer,
744 unsigned int szNextBuffer )
746 return AT91F_PDC_ReceiveFrame(
747 (AT91PS_PDC) &(pSPI->SPI_RPR),
754 //*----------------------------------------------------------------------------
755 //* \fn AT91F_SPI_SendFrame
756 //* \brief Return 2 if PDC has been initialized with Buffer and Next Buffer, 1 if PDC has been initializaed with Next Buffer, 0 if PDC is bSPIy
757 //*----------------------------------------------------------------------------
758 __inline unsigned int AT91F_SPI_SendFrame(
761 unsigned int szBuffer,
763 unsigned int szNextBuffer )
765 return AT91F_PDC_SendFrame(
766 (AT91PS_PDC) &(pSPI->SPI_RPR),
773 //*----------------------------------------------------------------------------
774 //* \fn AT91F_SPI_Close
775 //* \brief Close SPI: disable IT disable transfert, close PDC
776 //*----------------------------------------------------------------------------
777 __inline void AT91F_SPI_Close (
778 AT91PS_SPI pSPI) // \arg pointer to a SPI controller
780 //* Reset all the Chip Select register
781 pSPI->SPI_CSR[0] = 0 ;
782 pSPI->SPI_CSR[1] = 0 ;
783 pSPI->SPI_CSR[2] = 0 ;
784 pSPI->SPI_CSR[3] = 0 ;
786 //* Reset the SPI mode
789 //* Disable all interrupts
790 pSPI->SPI_IDR = 0xFFFFFFFF ;
792 //* Abort the Peripheral Data Transfers
793 AT91F_PDC_Close((AT91PS_PDC) &(pSPI->SPI_RPR));
795 //* Disable receiver and transmitter and stop any activity immediately
796 pSPI->SPI_CR = AT91C_SPI_SPIDIS;
799 //*----------------------------------------------------------------------------
800 //* \fn AT91F_SPI_PutChar
801 //* \brief Send a character,does not check if ready to send
802 //*----------------------------------------------------------------------------
803 __inline void AT91F_SPI_PutChar (
805 unsigned int character,
806 unsigned int cs_number )
808 unsigned int value_for_cs;
809 value_for_cs = (~(1 << cs_number)) & 0xF; //Place a zero among a 4 ONEs number
810 pSPI->SPI_TDR = (character & 0xFFFF) | (value_for_cs << 16);
813 //*----------------------------------------------------------------------------
814 //* \fn AT91F_SPI_GetChar
815 //* \brief Receive a character,does not check if a character is available
816 //*----------------------------------------------------------------------------
817 __inline int AT91F_SPI_GetChar (
818 const AT91PS_SPI pSPI)
820 return((pSPI->SPI_RDR) & 0xFFFF);
823 //*----------------------------------------------------------------------------
824 //* \fn AT91F_SPI_GetInterruptMaskStatus
825 //* \brief Return SPI Interrupt Mask Status
826 //*----------------------------------------------------------------------------
827 __inline unsigned int AT91F_SPI_GetInterruptMaskStatus( // \return SPI Interrupt Mask Status
828 AT91PS_SPI pSpi) // \arg pointer to a SPI controller
830 return pSpi->SPI_IMR;
833 //*----------------------------------------------------------------------------
834 //* \fn AT91F_SPI_IsInterruptMasked
835 //* \brief Test if SPI Interrupt is Masked
836 //*----------------------------------------------------------------------------
837 __inline int AT91F_SPI_IsInterruptMasked(
838 AT91PS_SPI pSpi, // \arg pointer to a SPI controller
839 unsigned int flag) // \arg flag to be tested
841 return (AT91F_SPI_GetInterruptMaskStatus(pSpi) & flag);
844 /* *****************************************************************************
845 SOFTWARE API FOR PWMC
846 ***************************************************************************** */
847 //*----------------------------------------------------------------------------
848 //* \fn AT91F_PWM_GetStatus
849 //* \brief Return PWM Interrupt Status
850 //*----------------------------------------------------------------------------
851 __inline unsigned int AT91F_PWMC_GetStatus( // \return PWM Interrupt Status
852 AT91PS_PWMC pPWM) // pointer to a PWM controller
854 return pPWM->PWMC_SR;
857 //*----------------------------------------------------------------------------
858 //* \fn AT91F_PWM_InterruptEnable
859 //* \brief Enable PWM Interrupt
860 //*----------------------------------------------------------------------------
861 __inline void AT91F_PWMC_InterruptEnable(
862 AT91PS_PWMC pPwm, // \arg pointer to a PWM controller
863 unsigned int flag) // \arg PWM interrupt to be enabled
865 pPwm->PWMC_IER = flag;
868 //*----------------------------------------------------------------------------
869 //* \fn AT91F_PWM_InterruptDisable
870 //* \brief Disable PWM Interrupt
871 //*----------------------------------------------------------------------------
872 __inline void AT91F_PWMC_InterruptDisable(
873 AT91PS_PWMC pPwm, // \arg pointer to a PWM controller
874 unsigned int flag) // \arg PWM interrupt to be disabled
876 pPwm->PWMC_IDR = flag;
879 //*----------------------------------------------------------------------------
880 //* \fn AT91F_PWM_GetInterruptMaskStatus
881 //* \brief Return PWM Interrupt Mask Status
882 //*----------------------------------------------------------------------------
883 __inline unsigned int AT91F_PWMC_GetInterruptMaskStatus( // \return PWM Interrupt Mask Status
884 AT91PS_PWMC pPwm) // \arg pointer to a PWM controller
886 return pPwm->PWMC_IMR;
889 //*----------------------------------------------------------------------------
890 //* \fn AT91F_PWM_IsInterruptMasked
891 //* \brief Test if PWM Interrupt is Masked
892 //*----------------------------------------------------------------------------
893 __inline unsigned int AT91F_PWMC_IsInterruptMasked(
894 AT91PS_PWMC pPWM, // \arg pointer to a PWM controller
895 unsigned int flag) // \arg flag to be tested
897 return (AT91F_PWMC_GetInterruptMaskStatus(pPWM) & flag);
900 //*----------------------------------------------------------------------------
901 //* \fn AT91F_PWM_IsStatusSet
902 //* \brief Test if PWM Interrupt is Set
903 //*----------------------------------------------------------------------------
904 __inline unsigned int AT91F_PWMC_IsStatusSet(
905 AT91PS_PWMC pPWM, // \arg pointer to a PWM controller
906 unsigned int flag) // \arg flag to be tested
908 return (AT91F_PWMC_GetStatus(pPWM) & flag);
911 //*----------------------------------------------------------------------------
912 //* \fn AT91F_PWM_CfgChannel
913 //* \brief Test if PWM Interrupt is Set
914 //*----------------------------------------------------------------------------
915 __inline void AT91F_PWMC_CfgChannel(
916 AT91PS_PWMC pPWM, // \arg pointer to a PWM controller
917 unsigned int channelId, // \arg PWM channel ID
918 unsigned int mode, // \arg PWM mode
919 unsigned int period, // \arg PWM period
920 unsigned int duty) // \arg PWM duty cycle
922 pPWM->PWMC_CH[channelId].PWMC_CMR = mode;
923 pPWM->PWMC_CH[channelId].PWMC_CDTYR = duty;
924 pPWM->PWMC_CH[channelId].PWMC_CPRDR = period;
927 //*----------------------------------------------------------------------------
928 //* \fn AT91F_PWM_StartChannel
929 //* \brief Enable channel
930 //*----------------------------------------------------------------------------
931 __inline void AT91F_PWMC_StartChannel(
932 AT91PS_PWMC pPWM, // \arg pointer to a PWM controller
933 unsigned int flag) // \arg Channels IDs to be enabled
935 pPWM->PWMC_ENA = flag;
938 //*----------------------------------------------------------------------------
939 //* \fn AT91F_PWM_StopChannel
940 //* \brief Disable channel
941 //*----------------------------------------------------------------------------
942 __inline void AT91F_PWMC_StopChannel(
943 AT91PS_PWMC pPWM, // \arg pointer to a PWM controller
944 unsigned int flag) // \arg Channels IDs to be enabled
946 pPWM->PWMC_DIS = flag;
949 //*----------------------------------------------------------------------------
950 //* \fn AT91F_PWM_UpdateChannel
951 //* \brief Update Period or Duty Cycle
952 //*----------------------------------------------------------------------------
953 __inline void AT91F_PWMC_UpdateChannel(
954 AT91PS_PWMC pPWM, // \arg pointer to a PWM controller
955 unsigned int channelId, // \arg PWM channel ID
956 unsigned int update) // \arg Channels IDs to be enabled
958 pPWM->PWMC_CH[channelId].PWMC_CUPDR = update;
961 /* *****************************************************************************
963 ***************************************************************************** */
964 //*----------------------------------------------------------------------------
965 //* \fn AT91F_TC_InterruptEnable
966 //* \brief Enable TC Interrupt
967 //*----------------------------------------------------------------------------
968 __inline void AT91F_TC_InterruptEnable(
969 AT91PS_TC pTc, // \arg pointer to a TC controller
970 unsigned int flag) // \arg TC interrupt to be enabled
975 //*----------------------------------------------------------------------------
976 //* \fn AT91F_TC_InterruptDisable
977 //* \brief Disable TC Interrupt
978 //*----------------------------------------------------------------------------
979 __inline void AT91F_TC_InterruptDisable(
980 AT91PS_TC pTc, // \arg pointer to a TC controller
981 unsigned int flag) // \arg TC interrupt to be disabled
986 //*----------------------------------------------------------------------------
987 //* \fn AT91F_TC_GetInterruptMaskStatus
988 //* \brief Return TC Interrupt Mask Status
989 //*----------------------------------------------------------------------------
990 __inline unsigned int AT91F_TC_GetInterruptMaskStatus( // \return TC Interrupt Mask Status
991 AT91PS_TC pTc) // \arg pointer to a TC controller
996 //*----------------------------------------------------------------------------
997 //* \fn AT91F_TC_IsInterruptMasked
998 //* \brief Test if TC Interrupt is Masked
999 //*----------------------------------------------------------------------------
1000 __inline int AT91F_TC_IsInterruptMasked(
1001 AT91PS_TC pTc, // \arg pointer to a TC controller
1002 unsigned int flag) // \arg flag to be tested
1004 return (AT91F_TC_GetInterruptMaskStatus(pTc) & flag);
1007 /* *****************************************************************************
1008 SOFTWARE API FOR PMC
1009 ***************************************************************************** */
1010 //*----------------------------------------------------------------------------
1011 //* \fn AT91F_PMC_CfgSysClkEnableReg
1012 //* \brief Configure the System Clock Enable Register of the PMC controller
1013 //*----------------------------------------------------------------------------
1014 __inline void AT91F_PMC_CfgSysClkEnableReg (
1015 AT91PS_PMC pPMC, // \arg pointer to PMC controller
1018 //* Write to the SCER register
1019 pPMC->PMC_SCER = mode;
1022 //*----------------------------------------------------------------------------
1023 //* \fn AT91F_PMC_CfgSysClkDisableReg
1024 //* \brief Configure the System Clock Disable Register of the PMC controller
1025 //*----------------------------------------------------------------------------
1026 __inline void AT91F_PMC_CfgSysClkDisableReg (
1027 AT91PS_PMC pPMC, // \arg pointer to PMC controller
1030 //* Write to the SCDR register
1031 pPMC->PMC_SCDR = mode;
1034 //*----------------------------------------------------------------------------
1035 //* \fn AT91F_PMC_GetSysClkStatusReg
1036 //* \brief Return the System Clock Status Register of the PMC controller
1037 //*----------------------------------------------------------------------------
1038 __inline unsigned int AT91F_PMC_GetSysClkStatusReg (
1039 AT91PS_PMC pPMC // pointer to a CAN controller
1042 return pPMC->PMC_SCSR;
1045 //*----------------------------------------------------------------------------
1046 //* \fn AT91F_PMC_EnablePeriphClock
1047 //* \brief Enable peripheral clock
1048 //*----------------------------------------------------------------------------
1049 __inline void AT91F_PMC_EnablePeriphClock (
1050 AT91PS_PMC pPMC, // \arg pointer to PMC controller
1051 unsigned int periphIds) // \arg IDs of peripherals to enable
1053 pPMC->PMC_PCER = periphIds;
1056 //*----------------------------------------------------------------------------
1057 //* \fn AT91F_PMC_DisablePeriphClock
1058 //* \brief Disable peripheral clock
1059 //*----------------------------------------------------------------------------
1060 __inline void AT91F_PMC_DisablePeriphClock (
1061 AT91PS_PMC pPMC, // \arg pointer to PMC controller
1062 unsigned int periphIds) // \arg IDs of peripherals to enable
1064 pPMC->PMC_PCDR = periphIds;
1067 //*----------------------------------------------------------------------------
1068 //* \fn AT91F_PMC_GetPeriphClock
1069 //* \brief Get peripheral clock status
1070 //*----------------------------------------------------------------------------
1071 __inline unsigned int AT91F_PMC_GetPeriphClock (
1072 AT91PS_PMC pPMC) // \arg pointer to PMC controller
1074 return pPMC->PMC_PCSR;
1077 //*----------------------------------------------------------------------------
1078 //* \fn AT91F_CKGR_CfgMainOscillatorReg
1079 //* \brief Cfg the main oscillator
1080 //*----------------------------------------------------------------------------
1081 __inline void AT91F_CKGR_CfgMainOscillatorReg (
1082 AT91PS_CKGR pCKGR, // \arg pointer to CKGR controller
1085 pCKGR->CKGR_MOR = mode;
1088 //*----------------------------------------------------------------------------
1089 //* \fn AT91F_CKGR_GetMainOscillatorReg
1090 //* \brief Cfg the main oscillator
1091 //*----------------------------------------------------------------------------
1092 __inline unsigned int AT91F_CKGR_GetMainOscillatorReg (
1093 AT91PS_CKGR pCKGR) // \arg pointer to CKGR controller
1095 return pCKGR->CKGR_MOR;
1098 //*----------------------------------------------------------------------------
1099 //* \fn AT91F_CKGR_EnableMainOscillator
1100 //* \brief Enable the main oscillator
1101 //*----------------------------------------------------------------------------
1102 __inline void AT91F_CKGR_EnableMainOscillator(
1103 AT91PS_CKGR pCKGR) // \arg pointer to CKGR controller
1105 pCKGR->CKGR_MOR |= AT91C_CKGR_MOSCEN;
1108 //*----------------------------------------------------------------------------
1109 //* \fn AT91F_CKGR_DisableMainOscillator
1110 //* \brief Disable the main oscillator
1111 //*----------------------------------------------------------------------------
1112 __inline void AT91F_CKGR_DisableMainOscillator (
1113 AT91PS_CKGR pCKGR) // \arg pointer to CKGR controller
1115 pCKGR->CKGR_MOR &= ~AT91C_CKGR_MOSCEN;
1118 //*----------------------------------------------------------------------------
1119 //* \fn AT91F_CKGR_CfgMainOscStartUpTime
1120 //* \brief Cfg MOR Register according to the main osc startup time
1121 //*----------------------------------------------------------------------------
1122 __inline void AT91F_CKGR_CfgMainOscStartUpTime (
1123 AT91PS_CKGR pCKGR, // \arg pointer to CKGR controller
1124 unsigned int startup_time, // \arg main osc startup time in microsecond (us)
1125 unsigned int slowClock) // \arg slowClock in Hz
1127 pCKGR->CKGR_MOR &= ~AT91C_CKGR_OSCOUNT;
1128 pCKGR->CKGR_MOR |= ((slowClock * startup_time)/(8*1000000)) << 8;
1131 //*----------------------------------------------------------------------------
1132 //* \fn AT91F_CKGR_GetMainClockFreqReg
1133 //* \brief Cfg the main oscillator
1134 //*----------------------------------------------------------------------------
1135 __inline unsigned int AT91F_CKGR_GetMainClockFreqReg (
1136 AT91PS_CKGR pCKGR) // \arg pointer to CKGR controller
1138 return pCKGR->CKGR_MCFR;
1141 //*----------------------------------------------------------------------------
1142 //* \fn AT91F_CKGR_GetMainClock
1143 //* \brief Return Main clock in Hz
1144 //*----------------------------------------------------------------------------
1145 __inline unsigned int AT91F_CKGR_GetMainClock (
1146 AT91PS_CKGR pCKGR, // \arg pointer to CKGR controller
1147 unsigned int slowClock) // \arg slowClock in Hz
1149 return ((pCKGR->CKGR_MCFR & AT91C_CKGR_MAINF) * slowClock) >> 4;
1152 //*----------------------------------------------------------------------------
1153 //* \fn AT91F_PMC_CfgMCKReg
1154 //* \brief Cfg Master Clock Register
1155 //*----------------------------------------------------------------------------
1156 __inline void AT91F_PMC_CfgMCKReg (
1157 AT91PS_PMC pPMC, // \arg pointer to PMC controller
1160 pPMC->PMC_MCKR = mode;
1163 //*----------------------------------------------------------------------------
1164 //* \fn AT91F_PMC_GetMCKReg
1165 //* \brief Return Master Clock Register
1166 //*----------------------------------------------------------------------------
1167 __inline unsigned int AT91F_PMC_GetMCKReg(
1168 AT91PS_PMC pPMC) // \arg pointer to PMC controller
1170 return pPMC->PMC_MCKR;
1173 //*------------------------------------------------------------------------------
1174 //* \fn AT91F_PMC_GetMasterClock
1175 //* \brief Return master clock in Hz which correponds to processor clock for ARM7
1176 //*------------------------------------------------------------------------------
1177 __inline unsigned int AT91F_PMC_GetMasterClock (
1178 AT91PS_PMC pPMC, // \arg pointer to PMC controller
1179 AT91PS_CKGR pCKGR, // \arg pointer to CKGR controller
1180 unsigned int slowClock) // \arg slowClock in Hz
1182 unsigned int reg = pPMC->PMC_MCKR;
1183 unsigned int prescaler = (1 << ((reg & AT91C_PMC_PRES) >> 2));
1184 unsigned int pllDivider, pllMultiplier;
1186 switch (reg & AT91C_PMC_CSS) {
1187 case AT91C_PMC_CSS_SLOW_CLK: // Slow clock selected
1188 return slowClock / prescaler;
1189 case AT91C_PMC_CSS_MAIN_CLK: // Main clock is selected
1190 return AT91F_CKGR_GetMainClock(pCKGR, slowClock) / prescaler;
1191 case AT91C_PMC_CSS_PLL_CLK: // PLLB clock is selected
1192 reg = pCKGR->CKGR_PLLR;
1193 pllDivider = (reg & AT91C_CKGR_DIV);
1194 pllMultiplier = ((reg & AT91C_CKGR_MUL) >> 16) + 1;
1195 return AT91F_CKGR_GetMainClock(pCKGR, slowClock) / pllDivider * pllMultiplier / prescaler;
1200 //*----------------------------------------------------------------------------
1201 //* \fn AT91F_PMC_EnablePCK
1202 //* \brief Enable peripheral clock
1203 //*----------------------------------------------------------------------------
1204 __inline void AT91F_PMC_EnablePCK (
1205 AT91PS_PMC pPMC, // \arg pointer to PMC controller
1206 unsigned int pck, // \arg Peripheral clock identifier 0 .. 7
1209 pPMC->PMC_PCKR[pck] = mode;
1210 pPMC->PMC_SCER = (1 << pck) << 8;
1213 //*----------------------------------------------------------------------------
1214 //* \fn AT91F_PMC_DisablePCK
1215 //* \brief Enable peripheral clock
1216 //*----------------------------------------------------------------------------
1217 __inline void AT91F_PMC_DisablePCK (
1218 AT91PS_PMC pPMC, // \arg pointer to PMC controller
1219 unsigned int pck) // \arg Peripheral clock identifier 0 .. 7
1221 pPMC->PMC_SCDR = (1 << pck) << 8;
1224 //*----------------------------------------------------------------------------
1225 //* \fn AT91F_PMC_EnableIt
1226 //* \brief Enable PMC interrupt
1227 //*----------------------------------------------------------------------------
1228 __inline void AT91F_PMC_EnableIt (
1229 AT91PS_PMC pPMC, // pointer to a PMC controller
1230 unsigned int flag) // IT to be enabled
1232 //* Write to the IER register
1233 pPMC->PMC_IER = flag;
1236 //*----------------------------------------------------------------------------
1237 //* \fn AT91F_PMC_DisableIt
1238 //* \brief Disable PMC interrupt
1239 //*----------------------------------------------------------------------------
1240 __inline void AT91F_PMC_DisableIt (
1241 AT91PS_PMC pPMC, // pointer to a PMC controller
1242 unsigned int flag) // IT to be disabled
1244 //* Write to the IDR register
1245 pPMC->PMC_IDR = flag;
1248 //*----------------------------------------------------------------------------
1249 //* \fn AT91F_PMC_GetStatus
1250 //* \brief Return PMC Interrupt Status
1251 //*----------------------------------------------------------------------------
1252 __inline unsigned int AT91F_PMC_GetStatus( // \return PMC Interrupt Status
1253 AT91PS_PMC pPMC) // pointer to a PMC controller
1255 return pPMC->PMC_SR;
1258 //*----------------------------------------------------------------------------
1259 //* \fn AT91F_PMC_GetInterruptMaskStatus
1260 //* \brief Return PMC Interrupt Mask Status
1261 //*----------------------------------------------------------------------------
1262 __inline unsigned int AT91F_PMC_GetInterruptMaskStatus( // \return PMC Interrupt Mask Status
1263 AT91PS_PMC pPMC) // pointer to a PMC controller
1265 return pPMC->PMC_IMR;
1268 //*----------------------------------------------------------------------------
1269 //* \fn AT91F_PMC_IsInterruptMasked
1270 //* \brief Test if PMC Interrupt is Masked
1271 //*----------------------------------------------------------------------------
1272 __inline unsigned int AT91F_PMC_IsInterruptMasked(
1273 AT91PS_PMC pPMC, // \arg pointer to a PMC controller
1274 unsigned int flag) // \arg flag to be tested
1276 return (AT91F_PMC_GetInterruptMaskStatus(pPMC) & flag);
1279 //*----------------------------------------------------------------------------
1280 //* \fn AT91F_PMC_IsStatusSet
1281 //* \brief Test if PMC Status is Set
1282 //*----------------------------------------------------------------------------
1283 __inline unsigned int AT91F_PMC_IsStatusSet(
1284 AT91PS_PMC pPMC, // \arg pointer to a PMC controller
1285 unsigned int flag) // \arg flag to be tested
1287 return (AT91F_PMC_GetStatus(pPMC) & flag);
1288 }/* *****************************************************************************
1289 SOFTWARE API FOR ADC
1290 ***************************************************************************** */
1291 //*----------------------------------------------------------------------------
1292 //* \fn AT91F_ADC_EnableIt
1293 //* \brief Enable ADC interrupt
1294 //*----------------------------------------------------------------------------
1295 __inline void AT91F_ADC_EnableIt (
1296 AT91PS_ADC pADC, // pointer to a ADC controller
1297 unsigned int flag) // IT to be enabled
1299 //* Write to the IER register
1300 pADC->ADC_IER = flag;
1303 //*----------------------------------------------------------------------------
1304 //* \fn AT91F_ADC_DisableIt
1305 //* \brief Disable ADC interrupt
1306 //*----------------------------------------------------------------------------
1307 __inline void AT91F_ADC_DisableIt (
1308 AT91PS_ADC pADC, // pointer to a ADC controller
1309 unsigned int flag) // IT to be disabled
1311 //* Write to the IDR register
1312 pADC->ADC_IDR = flag;
1315 //*----------------------------------------------------------------------------
1316 //* \fn AT91F_ADC_GetStatus
1317 //* \brief Return ADC Interrupt Status
1318 //*----------------------------------------------------------------------------
1319 __inline unsigned int AT91F_ADC_GetStatus( // \return ADC Interrupt Status
1320 AT91PS_ADC pADC) // pointer to a ADC controller
1322 return pADC->ADC_SR;
1325 //*----------------------------------------------------------------------------
1326 //* \fn AT91F_ADC_GetInterruptMaskStatus
1327 //* \brief Return ADC Interrupt Mask Status
1328 //*----------------------------------------------------------------------------
1329 __inline unsigned int AT91F_ADC_GetInterruptMaskStatus( // \return ADC Interrupt Mask Status
1330 AT91PS_ADC pADC) // pointer to a ADC controller
1332 return pADC->ADC_IMR;
1335 //*----------------------------------------------------------------------------
1336 //* \fn AT91F_ADC_IsInterruptMasked
1337 //* \brief Test if ADC Interrupt is Masked
1338 //*----------------------------------------------------------------------------
1339 __inline unsigned int AT91F_ADC_IsInterruptMasked(
1340 AT91PS_ADC pADC, // \arg pointer to a ADC controller
1341 unsigned int flag) // \arg flag to be tested
1343 return (AT91F_ADC_GetInterruptMaskStatus(pADC) & flag);
1346 //*----------------------------------------------------------------------------
1347 //* \fn AT91F_ADC_IsStatusSet
1348 //* \brief Test if ADC Status is Set
1349 //*----------------------------------------------------------------------------
1350 __inline unsigned int AT91F_ADC_IsStatusSet(
1351 AT91PS_ADC pADC, // \arg pointer to a ADC controller
1352 unsigned int flag) // \arg flag to be tested
1354 return (AT91F_ADC_GetStatus(pADC) & flag);
1357 //*----------------------------------------------------------------------------
1358 //* \fn AT91F_ADC_CfgModeReg
1359 //* \brief Configure the Mode Register of the ADC controller
1360 //*----------------------------------------------------------------------------
1361 __inline void AT91F_ADC_CfgModeReg (
1362 AT91PS_ADC pADC, // pointer to a ADC controller
1363 unsigned int mode) // mode register
1365 //* Write to the MR register
1366 pADC->ADC_MR = mode;
1369 //*----------------------------------------------------------------------------
1370 //* \fn AT91F_ADC_GetModeReg
1371 //* \brief Return the Mode Register of the ADC controller value
1372 //*----------------------------------------------------------------------------
1373 __inline unsigned int AT91F_ADC_GetModeReg (
1374 AT91PS_ADC pADC // pointer to a ADC controller
1377 return pADC->ADC_MR;
1380 //*----------------------------------------------------------------------------
1381 //* \fn AT91F_ADC_CfgTimings
1382 //* \brief Configure the different necessary timings of the ADC controller
1383 //*----------------------------------------------------------------------------
1384 __inline void AT91F_ADC_CfgTimings (
1385 AT91PS_ADC pADC, // pointer to a ADC controller
1386 unsigned int mck_clock, // in MHz
1387 unsigned int adc_clock, // in MHz
1388 unsigned int startup_time, // in us
1389 unsigned int sample_and_hold_time) // in ns
1391 unsigned int prescal,startup,shtim;
1393 prescal = mck_clock/(2*adc_clock) - 1;
1394 startup = adc_clock*startup_time/8 - 1;
1395 shtim = adc_clock*sample_and_hold_time/1000 - 1;
1397 //* Write to the MR register
1398 pADC->ADC_MR = ( (prescal<<8) & AT91C_ADC_PRESCAL) | ( (startup<<16) & AT91C_ADC_STARTUP) | ( (shtim<<24) & AT91C_ADC_SHTIM);
1401 //*----------------------------------------------------------------------------
1402 //* \fn AT91F_ADC_EnableChannel
1403 //* \brief Return ADC Timer Register Value
1404 //*----------------------------------------------------------------------------
1405 __inline void AT91F_ADC_EnableChannel (
1406 AT91PS_ADC pADC, // pointer to a ADC controller
1407 unsigned int channel) // mode register
1409 //* Write to the CHER register
1410 pADC->ADC_CHER = channel;
1413 //*----------------------------------------------------------------------------
1414 //* \fn AT91F_ADC_DisableChannel
1415 //* \brief Return ADC Timer Register Value
1416 //*----------------------------------------------------------------------------
1417 __inline void AT91F_ADC_DisableChannel (
1418 AT91PS_ADC pADC, // pointer to a ADC controller
1419 unsigned int channel) // mode register
1421 //* Write to the CHDR register
1422 pADC->ADC_CHDR = channel;
1425 //*----------------------------------------------------------------------------
1426 //* \fn AT91F_ADC_GetChannelStatus
1427 //* \brief Return ADC Timer Register Value
1428 //*----------------------------------------------------------------------------
1429 __inline unsigned int AT91F_ADC_GetChannelStatus (
1430 AT91PS_ADC pADC // pointer to a ADC controller
1433 return pADC->ADC_CHSR;
1436 //*----------------------------------------------------------------------------
1437 //* \fn AT91F_ADC_StartConversion
1438 //* \brief Software request for a analog to digital conversion
1439 //*----------------------------------------------------------------------------
1440 __inline void AT91F_ADC_StartConversion (
1441 AT91PS_ADC pADC // pointer to a ADC controller
1444 pADC->ADC_CR = AT91C_ADC_START;
1447 //*----------------------------------------------------------------------------
1448 //* \fn AT91F_ADC_SoftReset
1449 //* \brief Software reset
1450 //*----------------------------------------------------------------------------
1451 __inline void AT91F_ADC_SoftReset (
1452 AT91PS_ADC pADC // pointer to a ADC controller
1455 pADC->ADC_CR = AT91C_ADC_SWRST;
1458 //*----------------------------------------------------------------------------
1459 //* \fn AT91F_ADC_GetLastConvertedData
1460 //* \brief Return the Last Converted Data
1461 //*----------------------------------------------------------------------------
1462 __inline unsigned int AT91F_ADC_GetLastConvertedData (
1463 AT91PS_ADC pADC // pointer to a ADC controller
1466 return pADC->ADC_LCDR;
1469 //*----------------------------------------------------------------------------
1470 //* \fn AT91F_ADC_GetConvertedDataCH0
1471 //* \brief Return the Channel 0 Converted Data
1472 //*----------------------------------------------------------------------------
1473 __inline unsigned int AT91F_ADC_GetConvertedDataCH0 (
1474 AT91PS_ADC pADC // pointer to a ADC controller
1477 return pADC->ADC_CDR0;
1480 //*----------------------------------------------------------------------------
1481 //* \fn AT91F_ADC_GetConvertedDataCH1
1482 //* \brief Return the Channel 1 Converted Data
1483 //*----------------------------------------------------------------------------
1484 __inline unsigned int AT91F_ADC_GetConvertedDataCH1 (
1485 AT91PS_ADC pADC // pointer to a ADC controller
1488 return pADC->ADC_CDR1;
1491 //*----------------------------------------------------------------------------
1492 //* \fn AT91F_ADC_GetConvertedDataCH2
1493 //* \brief Return the Channel 2 Converted Data
1494 //*----------------------------------------------------------------------------
1495 __inline unsigned int AT91F_ADC_GetConvertedDataCH2 (
1496 AT91PS_ADC pADC // pointer to a ADC controller
1499 return pADC->ADC_CDR2;
1502 //*----------------------------------------------------------------------------
1503 //* \fn AT91F_ADC_GetConvertedDataCH3
1504 //* \brief Return the Channel 3 Converted Data
1505 //*----------------------------------------------------------------------------
1506 __inline unsigned int AT91F_ADC_GetConvertedDataCH3 (
1507 AT91PS_ADC pADC // pointer to a ADC controller
1510 return pADC->ADC_CDR3;
1513 //*----------------------------------------------------------------------------
1514 //* \fn AT91F_ADC_GetConvertedDataCH4
1515 //* \brief Return the Channel 4 Converted Data
1516 //*----------------------------------------------------------------------------
1517 __inline unsigned int AT91F_ADC_GetConvertedDataCH4 (
1518 AT91PS_ADC pADC // pointer to a ADC controller
1521 return pADC->ADC_CDR4;
1524 //*----------------------------------------------------------------------------
1525 //* \fn AT91F_ADC_GetConvertedDataCH5
1526 //* \brief Return the Channel 5 Converted Data
1527 //*----------------------------------------------------------------------------
1528 __inline unsigned int AT91F_ADC_GetConvertedDataCH5 (
1529 AT91PS_ADC pADC // pointer to a ADC controller
1532 return pADC->ADC_CDR5;
1535 //*----------------------------------------------------------------------------
1536 //* \fn AT91F_ADC_GetConvertedDataCH6
1537 //* \brief Return the Channel 6 Converted Data
1538 //*----------------------------------------------------------------------------
1539 __inline unsigned int AT91F_ADC_GetConvertedDataCH6 (
1540 AT91PS_ADC pADC // pointer to a ADC controller
1543 return pADC->ADC_CDR6;
1546 //*----------------------------------------------------------------------------
1547 //* \fn AT91F_ADC_GetConvertedDataCH7
1548 //* \brief Return the Channel 7 Converted Data
1549 //*----------------------------------------------------------------------------
1550 __inline unsigned int AT91F_ADC_GetConvertedDataCH7 (
1551 AT91PS_ADC pADC // pointer to a ADC controller
1554 return pADC->ADC_CDR7;
1557 /* *****************************************************************************
1558 SOFTWARE API FOR PIO
1559 ***************************************************************************** */
1560 //*----------------------------------------------------------------------------
1561 //* \fn AT91F_PIO_CfgPeriph
1562 //* \brief Enable pins to be drived by peripheral
1563 //*----------------------------------------------------------------------------
1564 __inline void AT91F_PIO_CfgPeriph(
1565 AT91PS_PIO pPio, // \arg pointer to a PIO controller
1566 unsigned int periphAEnable, // \arg PERIPH A to enable
1567 unsigned int periphBEnable) // \arg PERIPH B to enable
1570 pPio->PIO_ASR = periphAEnable;
1571 pPio->PIO_BSR = periphBEnable;
1572 pPio->PIO_PDR = (periphAEnable | periphBEnable); // Set in Periph mode
1575 //*----------------------------------------------------------------------------
1576 //* \fn AT91F_PIO_CfgOutput
1577 //* \brief Enable PIO in output mode
1578 //*----------------------------------------------------------------------------
1579 __inline void AT91F_PIO_CfgOutput(
1580 AT91PS_PIO pPio, // \arg pointer to a PIO controller
1581 unsigned int pioEnable) // \arg PIO to be enabled
1583 pPio->PIO_PER = pioEnable; // Set in PIO mode
1584 pPio->PIO_OER = pioEnable; // Configure in Output
1587 //*----------------------------------------------------------------------------
1588 //* \fn AT91F_PIO_CfgInput
1589 //* \brief Enable PIO in input mode
1590 //*----------------------------------------------------------------------------
1591 __inline void AT91F_PIO_CfgInput(
1592 AT91PS_PIO pPio, // \arg pointer to a PIO controller
1593 unsigned int inputEnable) // \arg PIO to be enabled
1596 pPio->PIO_ODR = inputEnable;
1597 pPio->PIO_PER = inputEnable;
1600 //*----------------------------------------------------------------------------
1601 //* \fn AT91F_PIO_CfgOpendrain
1602 //* \brief Configure PIO in open drain
1603 //*----------------------------------------------------------------------------
1604 __inline void AT91F_PIO_CfgOpendrain(
1605 AT91PS_PIO pPio, // \arg pointer to a PIO controller
1606 unsigned int multiDrvEnable) // \arg pio to be configured in open drain
1608 // Configure the multi-drive option
1609 pPio->PIO_MDDR = ~multiDrvEnable;
1610 pPio->PIO_MDER = multiDrvEnable;
1613 //*----------------------------------------------------------------------------
1614 //* \fn AT91F_PIO_CfgPullup
1615 //* \brief Enable pullup on PIO
1616 //*----------------------------------------------------------------------------
1617 __inline void AT91F_PIO_CfgPullup(
1618 AT91PS_PIO pPio, // \arg pointer to a PIO controller
1619 unsigned int pullupEnable) // \arg enable pullup on PIO
1621 // Connect or not Pullup
1622 pPio->PIO_PPUDR = ~pullupEnable;
1623 pPio->PIO_PPUER = pullupEnable;
1626 //*----------------------------------------------------------------------------
1627 //* \fn AT91F_PIO_CfgDirectDrive
1628 //* \brief Enable direct drive on PIO
1629 //*----------------------------------------------------------------------------
1630 __inline void AT91F_PIO_CfgDirectDrive(
1631 AT91PS_PIO pPio, // \arg pointer to a PIO controller
1632 unsigned int directDrive) // \arg PIO to be configured with direct drive
1635 // Configure the Direct Drive
1636 pPio->PIO_OWDR = ~directDrive;
1637 pPio->PIO_OWER = directDrive;
1640 //*----------------------------------------------------------------------------
1641 //* \fn AT91F_PIO_CfgInputFilter
1642 //* \brief Enable input filter on input PIO
1643 //*----------------------------------------------------------------------------
1644 __inline void AT91F_PIO_CfgInputFilter(
1645 AT91PS_PIO pPio, // \arg pointer to a PIO controller
1646 unsigned int inputFilter) // \arg PIO to be configured with input filter
1649 // Configure the Direct Drive
1650 pPio->PIO_IFDR = ~inputFilter;
1651 pPio->PIO_IFER = inputFilter;
1654 //*----------------------------------------------------------------------------
1655 //* \fn AT91F_PIO_GetInput
1656 //* \brief Return PIO input value
1657 //*----------------------------------------------------------------------------
1658 __inline unsigned int AT91F_PIO_GetInput( // \return PIO input
1659 AT91PS_PIO pPio) // \arg pointer to a PIO controller
1661 return pPio->PIO_PDSR;
1664 //*----------------------------------------------------------------------------
1665 //* \fn AT91F_PIO_IsInputSet
1666 //* \brief Test if PIO is input flag is active
1667 //*----------------------------------------------------------------------------
1668 __inline int AT91F_PIO_IsInputSet(
1669 AT91PS_PIO pPio, // \arg pointer to a PIO controller
1670 unsigned int flag) // \arg flag to be tested
1672 return (AT91F_PIO_GetInput(pPio) & flag);
1676 //*----------------------------------------------------------------------------
1677 //* \fn AT91F_PIO_SetOutput
1678 //* \brief Set to 1 output PIO
1679 //*----------------------------------------------------------------------------
1680 __inline void AT91F_PIO_SetOutput(
1681 AT91PS_PIO pPio, // \arg pointer to a PIO controller
1682 unsigned int flag) // \arg output to be set
1684 pPio->PIO_SODR = flag;
1687 //*----------------------------------------------------------------------------
1688 //* \fn AT91F_PIO_ClearOutput
1689 //* \brief Set to 0 output PIO
1690 //*----------------------------------------------------------------------------
1691 __inline void AT91F_PIO_ClearOutput(
1692 AT91PS_PIO pPio, // \arg pointer to a PIO controller
1693 unsigned int flag) // \arg output to be cleared
1695 pPio->PIO_CODR = flag;
1698 //*----------------------------------------------------------------------------
1699 //* \fn AT91F_PIO_ForceOutput
1700 //* \brief Force output when Direct drive option is enabled
1701 //*----------------------------------------------------------------------------
1702 __inline void AT91F_PIO_ForceOutput(
1703 AT91PS_PIO pPio, // \arg pointer to a PIO controller
1704 unsigned int flag) // \arg output to be forced
1706 pPio->PIO_ODSR = flag;
1709 //*----------------------------------------------------------------------------
1710 //* \fn AT91F_PIO_Enable
1711 //* \brief Enable PIO
1712 //*----------------------------------------------------------------------------
1713 __inline void AT91F_PIO_Enable(
1714 AT91PS_PIO pPio, // \arg pointer to a PIO controller
1715 unsigned int flag) // \arg pio to be enabled
1717 pPio->PIO_PER = flag;
1720 //*----------------------------------------------------------------------------
1721 //* \fn AT91F_PIO_Disable
1722 //* \brief Disable PIO
1723 //*----------------------------------------------------------------------------
1724 __inline void AT91F_PIO_Disable(
1725 AT91PS_PIO pPio, // \arg pointer to a PIO controller
1726 unsigned int flag) // \arg pio to be disabled
1728 pPio->PIO_PDR = flag;
1731 //*----------------------------------------------------------------------------
1732 //* \fn AT91F_PIO_GetStatus
1733 //* \brief Return PIO Status
1734 //*----------------------------------------------------------------------------
1735 __inline unsigned int AT91F_PIO_GetStatus( // \return PIO Status
1736 AT91PS_PIO pPio) // \arg pointer to a PIO controller
1738 return pPio->PIO_PSR;
1741 //*----------------------------------------------------------------------------
1742 //* \fn AT91F_PIO_IsSet
1743 //* \brief Test if PIO is Set
1744 //*----------------------------------------------------------------------------
1745 __inline int AT91F_PIO_IsSet(
1746 AT91PS_PIO pPio, // \arg pointer to a PIO controller
1747 unsigned int flag) // \arg flag to be tested
1749 return (AT91F_PIO_GetStatus(pPio) & flag);
1752 //*----------------------------------------------------------------------------
1753 //* \fn AT91F_PIO_OutputEnable
1754 //* \brief Output Enable PIO
1755 //*----------------------------------------------------------------------------
1756 __inline void AT91F_PIO_OutputEnable(
1757 AT91PS_PIO pPio, // \arg pointer to a PIO controller
1758 unsigned int flag) // \arg pio output to be enabled
1760 pPio->PIO_OER = flag;
1763 //*----------------------------------------------------------------------------
1764 //* \fn AT91F_PIO_OutputDisable
1765 //* \brief Output Enable PIO
1766 //*----------------------------------------------------------------------------
1767 __inline void AT91F_PIO_OutputDisable(
1768 AT91PS_PIO pPio, // \arg pointer to a PIO controller
1769 unsigned int flag) // \arg pio output to be disabled
1771 pPio->PIO_ODR = flag;
1774 //*----------------------------------------------------------------------------
1775 //* \fn AT91F_PIO_GetOutputStatus
1776 //* \brief Return PIO Output Status
1777 //*----------------------------------------------------------------------------
1778 __inline unsigned int AT91F_PIO_GetOutputStatus( // \return PIO Output Status
1779 AT91PS_PIO pPio) // \arg pointer to a PIO controller
1781 return pPio->PIO_OSR;
1784 //*----------------------------------------------------------------------------
1785 //* \fn AT91F_PIO_IsOuputSet
1786 //* \brief Test if PIO Output is Set
1787 //*----------------------------------------------------------------------------
1788 __inline int AT91F_PIO_IsOutputSet(
1789 AT91PS_PIO pPio, // \arg pointer to a PIO controller
1790 unsigned int flag) // \arg flag to be tested
1792 return (AT91F_PIO_GetOutputStatus(pPio) & flag);
1795 //*----------------------------------------------------------------------------
1796 //* \fn AT91F_PIO_InputFilterEnable
1797 //* \brief Input Filter Enable PIO
1798 //*----------------------------------------------------------------------------
1799 __inline void AT91F_PIO_InputFilterEnable(
1800 AT91PS_PIO pPio, // \arg pointer to a PIO controller
1801 unsigned int flag) // \arg pio input filter to be enabled
1803 pPio->PIO_IFER = flag;
1806 //*----------------------------------------------------------------------------
1807 //* \fn AT91F_PIO_InputFilterDisable
1808 //* \brief Input Filter Disable PIO
1809 //*----------------------------------------------------------------------------
1810 __inline void AT91F_PIO_InputFilterDisable(
1811 AT91PS_PIO pPio, // \arg pointer to a PIO controller
1812 unsigned int flag) // \arg pio input filter to be disabled
1814 pPio->PIO_IFDR = flag;
1817 //*----------------------------------------------------------------------------
1818 //* \fn AT91F_PIO_GetInputFilterStatus
1819 //* \brief Return PIO Input Filter Status
1820 //*----------------------------------------------------------------------------
1821 __inline unsigned int AT91F_PIO_GetInputFilterStatus( // \return PIO Input Filter Status
1822 AT91PS_PIO pPio) // \arg pointer to a PIO controller
1824 return pPio->PIO_IFSR;
1827 //*----------------------------------------------------------------------------
1828 //* \fn AT91F_PIO_IsInputFilterSet
1829 //* \brief Test if PIO Input filter is Set
1830 //*----------------------------------------------------------------------------
1831 __inline int AT91F_PIO_IsInputFilterSet(
1832 AT91PS_PIO pPio, // \arg pointer to a PIO controller
1833 unsigned int flag) // \arg flag to be tested
1835 return (AT91F_PIO_GetInputFilterStatus(pPio) & flag);
1838 //*----------------------------------------------------------------------------
1839 //* \fn AT91F_PIO_GetOutputDataStatus
1840 //* \brief Return PIO Output Data Status
1841 //*----------------------------------------------------------------------------
1842 __inline unsigned int AT91F_PIO_GetOutputDataStatus( // \return PIO Output Data Status
1843 AT91PS_PIO pPio) // \arg pointer to a PIO controller
1845 return pPio->PIO_ODSR;
1848 //*----------------------------------------------------------------------------
1849 //* \fn AT91F_PIO_InterruptEnable
1850 //* \brief Enable PIO Interrupt
1851 //*----------------------------------------------------------------------------
1852 __inline void AT91F_PIO_InterruptEnable(
1853 AT91PS_PIO pPio, // \arg pointer to a PIO controller
1854 unsigned int flag) // \arg pio interrupt to be enabled
1856 pPio->PIO_IER = flag;
1859 //*----------------------------------------------------------------------------
1860 //* \fn AT91F_PIO_InterruptDisable
1861 //* \brief Disable PIO Interrupt
1862 //*----------------------------------------------------------------------------
1863 __inline void AT91F_PIO_InterruptDisable(
1864 AT91PS_PIO pPio, // \arg pointer to a PIO controller
1865 unsigned int flag) // \arg pio interrupt to be disabled
1867 pPio->PIO_IDR = flag;
1870 //*----------------------------------------------------------------------------
1871 //* \fn AT91F_PIO_GetInterruptMaskStatus
1872 //* \brief Return PIO Interrupt Mask Status
1873 //*----------------------------------------------------------------------------
1874 __inline unsigned int AT91F_PIO_GetInterruptMaskStatus( // \return PIO Interrupt Mask Status
1875 AT91PS_PIO pPio) // \arg pointer to a PIO controller
1877 return pPio->PIO_IMR;
1880 //*----------------------------------------------------------------------------
1881 //* \fn AT91F_PIO_GetInterruptStatus
1882 //* \brief Return PIO Interrupt Status
1883 //*----------------------------------------------------------------------------
1884 __inline unsigned int AT91F_PIO_GetInterruptStatus( // \return PIO Interrupt Status
1885 AT91PS_PIO pPio) // \arg pointer to a PIO controller
1887 return pPio->PIO_ISR;
1890 //*----------------------------------------------------------------------------
1891 //* \fn AT91F_PIO_IsInterruptMasked
1892 //* \brief Test if PIO Interrupt is Masked
1893 //*----------------------------------------------------------------------------
1894 __inline int AT91F_PIO_IsInterruptMasked(
1895 AT91PS_PIO pPio, // \arg pointer to a PIO controller
1896 unsigned int flag) // \arg flag to be tested
1898 return (AT91F_PIO_GetInterruptMaskStatus(pPio) & flag);
1901 //*----------------------------------------------------------------------------
1902 //* \fn AT91F_PIO_IsInterruptSet
1903 //* \brief Test if PIO Interrupt is Set
1904 //*----------------------------------------------------------------------------
1905 __inline int AT91F_PIO_IsInterruptSet(
1906 AT91PS_PIO pPio, // \arg pointer to a PIO controller
1907 unsigned int flag) // \arg flag to be tested
1909 return (AT91F_PIO_GetInterruptStatus(pPio) & flag);
1912 //*----------------------------------------------------------------------------
1913 //* \fn AT91F_PIO_MultiDriverEnable
1914 //* \brief Multi Driver Enable PIO
1915 //*----------------------------------------------------------------------------
1916 __inline void AT91F_PIO_MultiDriverEnable(
1917 AT91PS_PIO pPio, // \arg pointer to a PIO controller
1918 unsigned int flag) // \arg pio to be enabled
1920 pPio->PIO_MDER = flag;
1923 //*----------------------------------------------------------------------------
1924 //* \fn AT91F_PIO_MultiDriverDisable
1925 //* \brief Multi Driver Disable PIO
1926 //*----------------------------------------------------------------------------
1927 __inline void AT91F_PIO_MultiDriverDisable(
1928 AT91PS_PIO pPio, // \arg pointer to a PIO controller
1929 unsigned int flag) // \arg pio to be disabled
1931 pPio->PIO_MDDR = flag;
1934 //*----------------------------------------------------------------------------
1935 //* \fn AT91F_PIO_GetMultiDriverStatus
1936 //* \brief Return PIO Multi Driver Status
1937 //*----------------------------------------------------------------------------
1938 __inline unsigned int AT91F_PIO_GetMultiDriverStatus( // \return PIO Multi Driver Status
1939 AT91PS_PIO pPio) // \arg pointer to a PIO controller
1941 return pPio->PIO_MDSR;
1944 //*----------------------------------------------------------------------------
1945 //* \fn AT91F_PIO_IsMultiDriverSet
1946 //* \brief Test if PIO MultiDriver is Set
1947 //*----------------------------------------------------------------------------
1948 __inline int AT91F_PIO_IsMultiDriverSet(
1949 AT91PS_PIO pPio, // \arg pointer to a PIO controller
1950 unsigned int flag) // \arg flag to be tested
1952 return (AT91F_PIO_GetMultiDriverStatus(pPio) & flag);
1955 //*----------------------------------------------------------------------------
1956 //* \fn AT91F_PIO_A_RegisterSelection
1957 //* \brief PIO A Register Selection
1958 //*----------------------------------------------------------------------------
1959 __inline void AT91F_PIO_A_RegisterSelection(
1960 AT91PS_PIO pPio, // \arg pointer to a PIO controller
1961 unsigned int flag) // \arg pio A register selection
1963 pPio->PIO_ASR = flag;
1966 //*----------------------------------------------------------------------------
1967 //* \fn AT91F_PIO_B_RegisterSelection
1968 //* \brief PIO B Register Selection
1969 //*----------------------------------------------------------------------------
1970 __inline void AT91F_PIO_B_RegisterSelection(
1971 AT91PS_PIO pPio, // \arg pointer to a PIO controller
1972 unsigned int flag) // \arg pio B register selection
1974 pPio->PIO_BSR = flag;
1977 //*----------------------------------------------------------------------------
1978 //* \fn AT91F_PIO_Get_AB_RegisterStatus
1979 //* \brief Return PIO Interrupt Status
1980 //*----------------------------------------------------------------------------
1981 __inline unsigned int AT91F_PIO_Get_AB_RegisterStatus( // \return PIO AB Register Status
1982 AT91PS_PIO pPio) // \arg pointer to a PIO controller
1984 return pPio->PIO_ABSR;
1987 //*----------------------------------------------------------------------------
1988 //* \fn AT91F_PIO_IsAB_RegisterSet
1989 //* \brief Test if PIO AB Register is Set
1990 //*----------------------------------------------------------------------------
1991 __inline int AT91F_PIO_IsAB_RegisterSet(
1992 AT91PS_PIO pPio, // \arg pointer to a PIO controller
1993 unsigned int flag) // \arg flag to be tested
1995 return (AT91F_PIO_Get_AB_RegisterStatus(pPio) & flag);
1998 //*----------------------------------------------------------------------------
1999 //* \fn AT91F_PIO_OutputWriteEnable
2000 //* \brief Output Write Enable PIO
2001 //*----------------------------------------------------------------------------
2002 __inline void AT91F_PIO_OutputWriteEnable(
2003 AT91PS_PIO pPio, // \arg pointer to a PIO controller
2004 unsigned int flag) // \arg pio output write to be enabled
2006 pPio->PIO_OWER = flag;
2009 //*----------------------------------------------------------------------------
2010 //* \fn AT91F_PIO_OutputWriteDisable
2011 //* \brief Output Write Disable PIO
2012 //*----------------------------------------------------------------------------
2013 __inline void AT91F_PIO_OutputWriteDisable(
2014 AT91PS_PIO pPio, // \arg pointer to a PIO controller
2015 unsigned int flag) // \arg pio output write to be disabled
2017 pPio->PIO_OWDR = flag;
2020 //*----------------------------------------------------------------------------
2021 //* \fn AT91F_PIO_GetOutputWriteStatus
2022 //* \brief Return PIO Output Write Status
2023 //*----------------------------------------------------------------------------
2024 __inline unsigned int AT91F_PIO_GetOutputWriteStatus( // \return PIO Output Write Status
2025 AT91PS_PIO pPio) // \arg pointer to a PIO controller
2027 return pPio->PIO_OWSR;
2030 //*----------------------------------------------------------------------------
2031 //* \fn AT91F_PIO_IsOutputWriteSet
2032 //* \brief Test if PIO OutputWrite is Set
2033 //*----------------------------------------------------------------------------
2034 __inline int AT91F_PIO_IsOutputWriteSet(
2035 AT91PS_PIO pPio, // \arg pointer to a PIO controller
2036 unsigned int flag) // \arg flag to be tested
2038 return (AT91F_PIO_GetOutputWriteStatus(pPio) & flag);
2041 //*----------------------------------------------------------------------------
2042 //* \fn AT91F_PIO_GetCfgPullup
2043 //* \brief Return PIO Configuration Pullup
2044 //*----------------------------------------------------------------------------
2045 __inline unsigned int AT91F_PIO_GetCfgPullup( // \return PIO Configuration Pullup
2046 AT91PS_PIO pPio) // \arg pointer to a PIO controller
2048 return pPio->PIO_PPUSR;
2051 //*----------------------------------------------------------------------------
2052 //* \fn AT91F_PIO_IsOutputDataStatusSet
2053 //* \brief Test if PIO Output Data Status is Set
2054 //*----------------------------------------------------------------------------
2055 __inline int AT91F_PIO_IsOutputDataStatusSet(
2056 AT91PS_PIO pPio, // \arg pointer to a PIO controller
2057 unsigned int flag) // \arg flag to be tested
2059 return (AT91F_PIO_GetOutputDataStatus(pPio) & flag);
2062 //*----------------------------------------------------------------------------
2063 //* \fn AT91F_PIO_IsCfgPullupStatusSet
2064 //* \brief Test if PIO Configuration Pullup Status is Set
2065 //*----------------------------------------------------------------------------
2066 __inline int AT91F_PIO_IsCfgPullupStatusSet(
2067 AT91PS_PIO pPio, // \arg pointer to a PIO controller
2068 unsigned int flag) // \arg flag to be tested
2070 return (~AT91F_PIO_GetCfgPullup(pPio) & flag);
2073 /* *****************************************************************************
2074 SOFTWARE API FOR TWI
2075 ***************************************************************************** */
2076 //*----------------------------------------------------------------------------
2077 //* \fn AT91F_TWI_EnableIt
2078 //* \brief Enable TWI IT
2079 //*----------------------------------------------------------------------------
2080 __inline void AT91F_TWI_EnableIt (
2081 AT91PS_TWI pTWI, // \arg pointer to a TWI controller
2082 unsigned int flag) // \arg IT to be enabled
2084 //* Write to the IER register
2085 pTWI->TWI_IER = flag;
2088 //*----------------------------------------------------------------------------
2089 //* \fn AT91F_TWI_DisableIt
2090 //* \brief Disable TWI IT
2091 //*----------------------------------------------------------------------------
2092 __inline void AT91F_TWI_DisableIt (
2093 AT91PS_TWI pTWI, // \arg pointer to a TWI controller
2094 unsigned int flag) // \arg IT to be disabled
2096 //* Write to the IDR register
2097 pTWI->TWI_IDR = flag;
2100 //*----------------------------------------------------------------------------
2101 //* \fn AT91F_TWI_Configure
2102 //* \brief Configure TWI in master mode
2103 //*----------------------------------------------------------------------------
2104 __inline void AT91F_TWI_Configure ( AT91PS_TWI pTWI ) // \arg pointer to a TWI controller
2106 //* Disable interrupts
2107 pTWI->TWI_IDR = (unsigned int) -1;
2109 //* Reset peripheral
2110 pTWI->TWI_CR = AT91C_TWI_SWRST;
2113 pTWI->TWI_CR = AT91C_TWI_MSEN | AT91C_TWI_SVDIS;
2117 //*----------------------------------------------------------------------------
2118 //* \fn AT91F_TWI_GetInterruptMaskStatus
2119 //* \brief Return TWI Interrupt Mask Status
2120 //*----------------------------------------------------------------------------
2121 __inline unsigned int AT91F_TWI_GetInterruptMaskStatus( // \return TWI Interrupt Mask Status
2122 AT91PS_TWI pTwi) // \arg pointer to a TWI controller
2124 return pTwi->TWI_IMR;
2127 //*----------------------------------------------------------------------------
2128 //* \fn AT91F_TWI_IsInterruptMasked
2129 //* \brief Test if TWI Interrupt is Masked
2130 //*----------------------------------------------------------------------------
2131 __inline int AT91F_TWI_IsInterruptMasked(
2132 AT91PS_TWI pTwi, // \arg pointer to a TWI controller
2133 unsigned int flag) // \arg flag to be tested
2135 return (AT91F_TWI_GetInterruptMaskStatus(pTwi) & flag);
2138 /* *****************************************************************************
2139 SOFTWARE API FOR USART
2140 ***************************************************************************** */
2141 //*----------------------------------------------------------------------------
2142 //* \fn AT91F_US_Baudrate
2143 //* \brief Calculate the baudrate
2144 //* Standard Asynchronous Mode : 8 bits , 1 stop , no parity
2145 #define AT91C_US_ASYNC_MODE ( AT91C_US_USMODE_NORMAL + \
2146 AT91C_US_NBSTOP_1_BIT + \
2147 AT91C_US_PAR_NONE + \
2148 AT91C_US_CHRL_8_BITS + \
2149 AT91C_US_CLKS_CLOCK )
2151 //* Standard External Asynchronous Mode : 8 bits , 1 stop , no parity
2152 #define AT91C_US_ASYNC_SCK_MODE ( AT91C_US_USMODE_NORMAL + \
2153 AT91C_US_NBSTOP_1_BIT + \
2154 AT91C_US_PAR_NONE + \
2155 AT91C_US_CHRL_8_BITS + \
2158 //* Standard Synchronous Mode : 8 bits , 1 stop , no parity
2159 #define AT91C_US_SYNC_MODE ( AT91C_US_SYNC + \
2160 AT91C_US_USMODE_NORMAL + \
2161 AT91C_US_NBSTOP_1_BIT + \
2162 AT91C_US_PAR_NONE + \
2163 AT91C_US_CHRL_8_BITS + \
2164 AT91C_US_CLKS_CLOCK )
2167 #define AT91C_US_SCK_USED (AT91C_US_CKLO | AT91C_US_CLKS_EXT)
2169 //* Standard ISO T=0 Mode : 8 bits , 1 stop , parity
2170 #define AT91C_US_ISO_READER_MODE ( AT91C_US_USMODE_ISO7816_0 + \
2171 AT91C_US_CLKS_CLOCK +\
2172 AT91C_US_NBSTOP_1_BIT + \
2173 AT91C_US_PAR_EVEN + \
2174 AT91C_US_CHRL_8_BITS + \
2178 //* Standard IRDA mode
2179 #define AT91C_US_ASYNC_IRDA_MODE ( AT91C_US_USMODE_IRDA + \
2180 AT91C_US_NBSTOP_1_BIT + \
2181 AT91C_US_PAR_NONE + \
2182 AT91C_US_CHRL_8_BITS + \
2183 AT91C_US_CLKS_CLOCK )
2185 //*----------------------------------------------------------------------------
2186 //* \fn AT91F_US_Baudrate
2187 //* \brief Caluculate baud_value according to the main clock and the baud rate
2188 //*----------------------------------------------------------------------------
2189 __inline unsigned int AT91F_US_Baudrate (
2190 const unsigned int main_clock, // \arg peripheral clock
2191 const unsigned int baud_rate) // \arg UART baudrate
2193 unsigned int baud_value = ((main_clock*10)/(baud_rate * 16));
2194 if ((baud_value % 10) >= 5)
2195 baud_value = (baud_value / 10) + 1;
2201 //*----------------------------------------------------------------------------
2202 //* \fn AT91F_US_SetBaudrate
2203 //* \brief Set the baudrate according to the CPU clock
2204 //*----------------------------------------------------------------------------
2205 __inline void AT91F_US_SetBaudrate (
2206 AT91PS_USART pUSART, // \arg pointer to a USART controller
2207 unsigned int mainClock, // \arg peripheral clock
2208 unsigned int speed) // \arg UART baudrate
2210 //* Define the baud rate divisor register
2211 pUSART->US_BRGR = AT91F_US_Baudrate(mainClock, speed);
2214 //*----------------------------------------------------------------------------
2215 //* \fn AT91F_US_SetTimeguard
2216 //* \brief Set USART timeguard
2217 //*----------------------------------------------------------------------------
2218 __inline void AT91F_US_SetTimeguard (
2219 AT91PS_USART pUSART, // \arg pointer to a USART controller
2220 unsigned int timeguard) // \arg timeguard value
2222 //* Write the Timeguard Register
2223 pUSART->US_TTGR = timeguard ;
2226 //*----------------------------------------------------------------------------
2227 //* \fn AT91F_US_EnableIt
2228 //* \brief Enable USART IT
2229 //*----------------------------------------------------------------------------
2230 __inline void AT91F_US_EnableIt (
2231 AT91PS_USART pUSART, // \arg pointer to a USART controller
2232 unsigned int flag) // \arg IT to be enabled
2234 //* Write to the IER register
2235 pUSART->US_IER = flag;
2238 //*----------------------------------------------------------------------------
2239 //* \fn AT91F_US_DisableIt
2240 //* \brief Disable USART IT
2241 //*----------------------------------------------------------------------------
2242 __inline void AT91F_US_DisableIt (
2243 AT91PS_USART pUSART, // \arg pointer to a USART controller
2244 unsigned int flag) // \arg IT to be disabled
2246 //* Write to the IER register
2247 pUSART->US_IDR = flag;
2250 //*----------------------------------------------------------------------------
2251 //* \fn AT91F_US_Configure
2252 //* \brief Configure USART
2253 //*----------------------------------------------------------------------------
2254 __inline void AT91F_US_Configure (
2255 AT91PS_USART pUSART, // \arg pointer to a USART controller
2256 unsigned int mainClock, // \arg peripheral clock
2257 unsigned int mode , // \arg mode Register to be programmed
2258 unsigned int baudRate , // \arg baudrate to be programmed
2259 unsigned int timeguard ) // \arg timeguard to be programmed
2261 //* Disable interrupts
2262 pUSART->US_IDR = (unsigned int) -1;
2264 //* Reset receiver and transmitter
2265 pUSART->US_CR = AT91C_US_RSTRX | AT91C_US_RSTTX | AT91C_US_RXDIS | AT91C_US_TXDIS ;
2267 //* Define the baud rate divisor register
2268 AT91F_US_SetBaudrate(pUSART, mainClock, baudRate);
2270 //* Write the Timeguard Register
2271 AT91F_US_SetTimeguard(pUSART, timeguard);
2273 //* Clear Transmit and Receive Counters
2274 AT91F_PDC_Open((AT91PS_PDC) &(pUSART->US_RPR));
2276 //* Define the USART mode
2277 pUSART->US_MR = mode ;
2281 //*----------------------------------------------------------------------------
2282 //* \fn AT91F_US_EnableRx
2283 //* \brief Enable receiving characters
2284 //*----------------------------------------------------------------------------
2285 __inline void AT91F_US_EnableRx (
2286 AT91PS_USART pUSART) // \arg pointer to a USART controller
2289 pUSART->US_CR = AT91C_US_RXEN;
2292 //*----------------------------------------------------------------------------
2293 //* \fn AT91F_US_EnableTx
2294 //* \brief Enable sending characters
2295 //*----------------------------------------------------------------------------
2296 __inline void AT91F_US_EnableTx (
2297 AT91PS_USART pUSART) // \arg pointer to a USART controller
2299 //* Enable transmitter
2300 pUSART->US_CR = AT91C_US_TXEN;
2303 //*----------------------------------------------------------------------------
2304 //* \fn AT91F_US_ResetRx
2305 //* \brief Reset Receiver and re-enable it
2306 //*----------------------------------------------------------------------------
2307 __inline void AT91F_US_ResetRx (
2308 AT91PS_USART pUSART) // \arg pointer to a USART controller
2311 pUSART->US_CR = AT91C_US_RSTRX;
2312 //* Re-Enable receiver
2313 pUSART->US_CR = AT91C_US_RXEN;
2316 //*----------------------------------------------------------------------------
2317 //* \fn AT91F_US_ResetTx
2318 //* \brief Reset Transmitter and re-enable it
2319 //*----------------------------------------------------------------------------
2320 __inline void AT91F_US_ResetTx (
2321 AT91PS_USART pUSART) // \arg pointer to a USART controller
2323 //* Reset transmitter
2324 pUSART->US_CR = AT91C_US_RSTTX;
2325 //* Enable transmitter
2326 pUSART->US_CR = AT91C_US_TXEN;
2329 //*----------------------------------------------------------------------------
2330 //* \fn AT91F_US_DisableRx
2331 //* \brief Disable Receiver
2332 //*----------------------------------------------------------------------------
2333 __inline void AT91F_US_DisableRx (
2334 AT91PS_USART pUSART) // \arg pointer to a USART controller
2336 //* Disable receiver
2337 pUSART->US_CR = AT91C_US_RXDIS;
2340 //*----------------------------------------------------------------------------
2341 //* \fn AT91F_US_DisableTx
2342 //* \brief Disable Transmitter
2343 //*----------------------------------------------------------------------------
2344 __inline void AT91F_US_DisableTx (
2345 AT91PS_USART pUSART) // \arg pointer to a USART controller
2347 //* Disable transmitter
2348 pUSART->US_CR = AT91C_US_TXDIS;
2351 //*----------------------------------------------------------------------------
2352 //* \fn AT91F_US_Close
2353 //* \brief Close USART: disable IT disable receiver and transmitter, close PDC
2354 //*----------------------------------------------------------------------------
2355 __inline void AT91F_US_Close (
2356 AT91PS_USART pUSART) // \arg pointer to a USART controller
2358 //* Reset the baud rate divisor register
2359 pUSART->US_BRGR = 0 ;
2361 //* Reset the USART mode
2364 //* Reset the Timeguard Register
2365 pUSART->US_TTGR = 0;
2367 //* Disable all interrupts
2368 pUSART->US_IDR = 0xFFFFFFFF ;
2370 //* Abort the Peripheral Data Transfers
2371 AT91F_PDC_Close((AT91PS_PDC) &(pUSART->US_RPR));
2373 //* Disable receiver and transmitter and stop any activity immediately
2374 pUSART->US_CR = AT91C_US_TXDIS | AT91C_US_RXDIS | AT91C_US_RSTTX | AT91C_US_RSTRX ;
2377 //*----------------------------------------------------------------------------
2378 //* \fn AT91F_US_TxReady
2379 //* \brief Return 1 if a character can be written in US_THR
2380 //*----------------------------------------------------------------------------
2381 __inline unsigned int AT91F_US_TxReady (
2382 AT91PS_USART pUSART ) // \arg pointer to a USART controller
2384 return (pUSART->US_CSR & AT91C_US_TXRDY);
2387 //*----------------------------------------------------------------------------
2388 //* \fn AT91F_US_RxReady
2389 //* \brief Return 1 if a character can be read in US_RHR
2390 //*----------------------------------------------------------------------------
2391 __inline unsigned int AT91F_US_RxReady (
2392 AT91PS_USART pUSART ) // \arg pointer to a USART controller
2394 return (pUSART->US_CSR & AT91C_US_RXRDY);
2397 //*----------------------------------------------------------------------------
2398 //* \fn AT91F_US_Error
2399 //* \brief Return the error flag
2400 //*----------------------------------------------------------------------------
2401 __inline unsigned int AT91F_US_Error (
2402 AT91PS_USART pUSART ) // \arg pointer to a USART controller
2404 return (pUSART->US_CSR &
2405 (AT91C_US_OVRE | // Overrun error
2406 AT91C_US_FRAME | // Framing error
2407 AT91C_US_PARE)); // Parity error
2410 //*----------------------------------------------------------------------------
2411 //* \fn AT91F_US_PutChar
2412 //* \brief Send a character,does not check if ready to send
2413 //*----------------------------------------------------------------------------
2414 __inline void AT91F_US_PutChar (
2415 AT91PS_USART pUSART,
2418 pUSART->US_THR = (character & 0x1FF);
2421 //*----------------------------------------------------------------------------
2422 //* \fn AT91F_US_GetChar
2423 //* \brief Receive a character,does not check if a character is available
2424 //*----------------------------------------------------------------------------
2425 __inline int AT91F_US_GetChar (
2426 const AT91PS_USART pUSART)
2428 return((pUSART->US_RHR) & 0x1FF);
2431 //*----------------------------------------------------------------------------
2432 //* \fn AT91F_US_SendFrame
2433 //* \brief Return 2 if PDC has been initialized with Buffer and Next Buffer, 1 if PDC has been initializaed with Next Buffer, 0 if PDC is busy
2434 //*----------------------------------------------------------------------------
2435 __inline unsigned int AT91F_US_SendFrame(
2436 AT91PS_USART pUSART,
2438 unsigned int szBuffer,
2440 unsigned int szNextBuffer )
2442 return AT91F_PDC_SendFrame(
2443 (AT91PS_PDC) &(pUSART->US_RPR),
2450 //*----------------------------------------------------------------------------
2451 //* \fn AT91F_US_ReceiveFrame
2452 //* \brief Return 2 if PDC has been initialized with Buffer and Next Buffer, 1 if PDC has been initializaed with Next Buffer, 0 if PDC is busy
2453 //*----------------------------------------------------------------------------
2454 __inline unsigned int AT91F_US_ReceiveFrame (
2455 AT91PS_USART pUSART,
2457 unsigned int szBuffer,
2459 unsigned int szNextBuffer )
2461 return AT91F_PDC_ReceiveFrame(
2462 (AT91PS_PDC) &(pUSART->US_RPR),
2469 //*----------------------------------------------------------------------------
2470 //* \fn AT91F_US_SetIrdaFilter
2471 //* \brief Set the value of IrDa filter tregister
2472 //*----------------------------------------------------------------------------
2473 __inline void AT91F_US_SetIrdaFilter (
2474 AT91PS_USART pUSART,
2478 pUSART->US_IF = value;
2481 /* *****************************************************************************
2482 SOFTWARE API FOR UDP
2483 ***************************************************************************** */
2484 //*----------------------------------------------------------------------------
2485 //* \fn AT91F_UDP_EnableIt
2486 //* \brief Enable UDP IT
2487 //*----------------------------------------------------------------------------
2488 __inline void AT91F_UDP_EnableIt (
2489 AT91PS_UDP pUDP, // \arg pointer to a UDP controller
2490 unsigned int flag) // \arg IT to be enabled
2492 //* Write to the IER register
2493 pUDP->UDP_IER = flag;
2496 //*----------------------------------------------------------------------------
2497 //* \fn AT91F_UDP_DisableIt
2498 //* \brief Disable UDP IT
2499 //*----------------------------------------------------------------------------
2500 __inline void AT91F_UDP_DisableIt (
2501 AT91PS_UDP pUDP, // \arg pointer to a UDP controller
2502 unsigned int flag) // \arg IT to be disabled
2504 //* Write to the IDR register
2505 pUDP->UDP_IDR = flag;
2508 //*----------------------------------------------------------------------------
2509 //* \fn AT91F_UDP_SetAddress
2510 //* \brief Set UDP functional address
2511 //*----------------------------------------------------------------------------
2512 __inline void AT91F_UDP_SetAddress (
2513 AT91PS_UDP pUDP, // \arg pointer to a UDP controller
2514 unsigned char address) // \arg new UDP address
2516 pUDP->UDP_FADDR = (AT91C_UDP_FEN | address);
2519 //*----------------------------------------------------------------------------
2520 //* \fn AT91F_UDP_EnableEp
2521 //* \brief Enable Endpoint
2522 //*----------------------------------------------------------------------------
2523 __inline void AT91F_UDP_EnableEp (
2524 AT91PS_UDP pUDP, // \arg pointer to a UDP controller
2525 unsigned int flag) // \arg endpoints to be enabled
2527 pUDP->UDP_GLBSTATE |= flag;
2530 //*----------------------------------------------------------------------------
2531 //* \fn AT91F_UDP_DisableEp
2532 //* \brief Enable Endpoint
2533 //*----------------------------------------------------------------------------
2534 __inline void AT91F_UDP_DisableEp (
2535 AT91PS_UDP pUDP, // \arg pointer to a UDP controller
2536 unsigned int flag) // \arg endpoints to be enabled
2538 pUDP->UDP_GLBSTATE &= ~(flag);
2541 //*----------------------------------------------------------------------------
2542 //* \fn AT91F_UDP_SetState
2543 //* \brief Set UDP Device state
2544 //*----------------------------------------------------------------------------
2545 __inline void AT91F_UDP_SetState (
2546 AT91PS_UDP pUDP, // \arg pointer to a UDP controller
2547 unsigned int flag) // \arg new UDP address
2549 pUDP->UDP_GLBSTATE &= ~(AT91C_UDP_FADDEN | AT91C_UDP_CONFG);
2550 pUDP->UDP_GLBSTATE |= flag;
2553 //*----------------------------------------------------------------------------
2554 //* \fn AT91F_UDP_GetState
2555 //* \brief return UDP Device state
2556 //*----------------------------------------------------------------------------
2557 __inline unsigned int AT91F_UDP_GetState ( // \return the UDP device state
2558 AT91PS_UDP pUDP) // \arg pointer to a UDP controller
2560 return (pUDP->UDP_GLBSTATE & (AT91C_UDP_FADDEN | AT91C_UDP_CONFG));
2563 //*----------------------------------------------------------------------------
2564 //* \fn AT91F_UDP_ResetEp
2565 //* \brief Reset UDP endpoint
2566 //*----------------------------------------------------------------------------
2567 __inline void AT91F_UDP_ResetEp ( // \return the UDP device state
2568 AT91PS_UDP pUDP, // \arg pointer to a UDP controller
2569 unsigned int flag) // \arg Endpoints to be reset
2571 pUDP->UDP_RSTEP = flag;
2574 //*----------------------------------------------------------------------------
2575 //* \fn AT91F_UDP_EpStall
2576 //* \brief Endpoint will STALL requests
2577 //*----------------------------------------------------------------------------
2578 __inline void AT91F_UDP_EpStall(
2579 AT91PS_UDP pUDP, // \arg pointer to a UDP controller
2580 unsigned char endpoint) // \arg endpoint number
2582 pUDP->UDP_CSR[endpoint] |= AT91C_UDP_FORCESTALL;
2585 //*----------------------------------------------------------------------------
2586 //* \fn AT91F_UDP_EpWrite
2587 //* \brief Write value in the DPR
2588 //*----------------------------------------------------------------------------
2589 __inline void AT91F_UDP_EpWrite(
2590 AT91PS_UDP pUDP, // \arg pointer to a UDP controller
2591 unsigned char endpoint, // \arg endpoint number
2592 unsigned char value) // \arg value to be written in the DPR
2594 pUDP->UDP_FDR[endpoint] = value;
2597 //*----------------------------------------------------------------------------
2598 //* \fn AT91F_UDP_EpRead
2599 //* \brief Return value from the DPR
2600 //*----------------------------------------------------------------------------
2601 __inline unsigned int AT91F_UDP_EpRead(
2602 AT91PS_UDP pUDP, // \arg pointer to a UDP controller
2603 unsigned char endpoint) // \arg endpoint number
2605 return pUDP->UDP_FDR[endpoint];
2608 //*----------------------------------------------------------------------------
2609 //* \fn AT91F_UDP_EpEndOfWr
2610 //* \brief Notify the UDP that values in DPR are ready to be sent
2611 //*----------------------------------------------------------------------------
2612 __inline void AT91F_UDP_EpEndOfWr(
2613 AT91PS_UDP pUDP, // \arg pointer to a UDP controller
2614 unsigned char endpoint) // \arg endpoint number
2616 pUDP->UDP_CSR[endpoint] |= AT91C_UDP_TXPKTRDY;
2619 //*----------------------------------------------------------------------------
2620 //* \fn AT91F_UDP_EpClear
2621 //* \brief Clear flag in the endpoint CSR register
2622 //*----------------------------------------------------------------------------
2623 __inline void AT91F_UDP_EpClear(
2624 AT91PS_UDP pUDP, // \arg pointer to a UDP controller
2625 unsigned char endpoint, // \arg endpoint number
2626 unsigned int flag) // \arg flag to be cleared
2628 pUDP->UDP_CSR[endpoint] &= ~(flag);
2631 //*----------------------------------------------------------------------------
2632 //* \fn AT91F_UDP_EpSet
2633 //* \brief Set flag in the endpoint CSR register
2634 //*----------------------------------------------------------------------------
2635 __inline void AT91F_UDP_EpSet(
2636 AT91PS_UDP pUDP, // \arg pointer to a UDP controller
2637 unsigned char endpoint, // \arg endpoint number
2638 unsigned int flag) // \arg flag to be cleared
2640 pUDP->UDP_CSR[endpoint] |= flag;
2643 //*----------------------------------------------------------------------------
2644 //* \fn AT91F_UDP_EpStatus
2645 //* \brief Return the endpoint CSR register
2646 //*----------------------------------------------------------------------------
2647 __inline unsigned int AT91F_UDP_EpStatus(
2648 AT91PS_UDP pUDP, // \arg pointer to a UDP controller
2649 unsigned char endpoint) // \arg endpoint number
2651 return pUDP->UDP_CSR[endpoint];
2654 //*----------------------------------------------------------------------------
2655 //* \fn AT91F_UDP_GetInterruptMaskStatus
2656 //* \brief Return UDP Interrupt Mask Status
2657 //*----------------------------------------------------------------------------
2658 __inline unsigned int AT91F_UDP_GetInterruptMaskStatus( // \return UDP Interrupt Mask Status
2659 AT91PS_UDP pUdp) // \arg pointer to a UDP controller
2661 return pUdp->UDP_IMR;
2664 //*----------------------------------------------------------------------------
2665 //* \fn AT91F_UDP_IsInterruptMasked
2666 //* \brief Test if UDP Interrupt is Masked
2667 //*----------------------------------------------------------------------------
2668 __inline int AT91F_UDP_IsInterruptMasked(
2669 AT91PS_UDP pUdp, // \arg pointer to a UDP controller
2670 unsigned int flag) // \arg flag to be tested
2672 return (AT91F_UDP_GetInterruptMaskStatus(pUdp) & flag);
2675 /* *****************************************************************************
2676 SOFTWARE API FOR AIC
2677 ***************************************************************************** */
2678 #define AT91C_AIC_BRANCH_OPCODE ((void (*) ()) 0xE51FFF20) // ldr, pc, [pc, #-&F20]
2680 //*----------------------------------------------------------------------------
2681 //* \fn AT91F_AIC_ConfigureIt
2682 //* \brief Interrupt Handler Initialization
2683 //*----------------------------------------------------------------------------
2684 __inline unsigned int AT91F_AIC_ConfigureIt (
2685 AT91PS_AIC pAic, // \arg pointer to the AIC registers
2686 unsigned int irq_id, // \arg interrupt number to initialize
2687 unsigned int priority, // \arg priority to give to the interrupt
2688 unsigned int src_type, // \arg activation and sense of activation
2689 void (*newHandler) (void) ) // \arg address of the interrupt handler
2691 unsigned int oldHandler;
2694 oldHandler = pAic->AIC_SVR[irq_id];
2696 mask = 0x1 << irq_id ;
2697 //* Disable the interrupt on the interrupt controller
2698 pAic->AIC_IDCR = mask ;
2699 //* Save the interrupt handler routine pointer and the interrupt priority
2700 pAic->AIC_SVR[irq_id] = (unsigned int) newHandler ;
2701 //* Store the Source Mode Register
2702 pAic->AIC_SMR[irq_id] = src_type | priority ;
2703 //* Clear the interrupt on the interrupt controller
2704 pAic->AIC_ICCR = mask ;
2709 //*----------------------------------------------------------------------------
2710 //* \fn AT91F_AIC_EnableIt
2711 //* \brief Enable corresponding IT number
2712 //*----------------------------------------------------------------------------
2713 __inline void AT91F_AIC_EnableIt (
2714 AT91PS_AIC pAic, // \arg pointer to the AIC registers
2715 unsigned int irq_id ) // \arg interrupt number to initialize
2717 //* Enable the interrupt on the interrupt controller
2718 pAic->AIC_IECR = 0x1 << irq_id ;
2721 //*----------------------------------------------------------------------------
2722 //* \fn AT91F_AIC_DisableIt
2723 //* \brief Disable corresponding IT number
2724 //*----------------------------------------------------------------------------
2725 __inline void AT91F_AIC_DisableIt (
2726 AT91PS_AIC pAic, // \arg pointer to the AIC registers
2727 unsigned int irq_id ) // \arg interrupt number to initialize
2729 unsigned int mask = 0x1 << irq_id;
2730 //* Disable the interrupt on the interrupt controller
2731 pAic->AIC_IDCR = mask ;
2732 //* Clear the interrupt on the Interrupt Controller ( if one is pending )
2733 pAic->AIC_ICCR = mask ;
2736 //*----------------------------------------------------------------------------
2737 //* \fn AT91F_AIC_ClearIt
2738 //* \brief Clear corresponding IT number
2739 //*----------------------------------------------------------------------------
2740 __inline void AT91F_AIC_ClearIt (
2741 AT91PS_AIC pAic, // \arg pointer to the AIC registers
2742 unsigned int irq_id) // \arg interrupt number to initialize
2744 //* Clear the interrupt on the Interrupt Controller ( if one is pending )
2745 pAic->AIC_ICCR = (0x1 << irq_id);
2748 //*----------------------------------------------------------------------------
2749 //* \fn AT91F_AIC_AcknowledgeIt
2750 //* \brief Acknowledge corresponding IT number
2751 //*----------------------------------------------------------------------------
2752 __inline void AT91F_AIC_AcknowledgeIt (
2753 AT91PS_AIC pAic) // \arg pointer to the AIC registers
2755 pAic->AIC_EOICR = pAic->AIC_EOICR;
2758 //*----------------------------------------------------------------------------
2759 //* \fn AT91F_AIC_SetExceptionVector
2760 //* \brief Configure vector handler
2761 //*----------------------------------------------------------------------------
2762 __inline unsigned int AT91F_AIC_SetExceptionVector (
2763 unsigned int *pVector, // \arg pointer to the AIC registers
2764 void (*Handler) () ) // \arg Interrupt Handler
2766 unsigned int oldVector = *pVector;
2768 if ((unsigned int) Handler == (unsigned int) AT91C_AIC_BRANCH_OPCODE)
2769 *pVector = (unsigned int) AT91C_AIC_BRANCH_OPCODE;
2771 *pVector = (((((unsigned int) Handler) - ((unsigned int) pVector) - 0x8) >> 2) & 0x00FFFFFF) | 0xEA000000;
2776 //*----------------------------------------------------------------------------
2777 //* \fn AT91F_AIC_Trig
2778 //* \brief Trig an IT
2779 //*----------------------------------------------------------------------------
2780 __inline void AT91F_AIC_Trig (
2781 AT91PS_AIC pAic, // \arg pointer to the AIC registers
2782 unsigned int irq_id) // \arg interrupt number
2784 pAic->AIC_ISCR = (0x1 << irq_id) ;
2787 //*----------------------------------------------------------------------------
2788 //* \fn AT91F_AIC_IsActive
2789 //* \brief Test if an IT is active
2790 //*----------------------------------------------------------------------------
2791 __inline unsigned int AT91F_AIC_IsActive (
2792 AT91PS_AIC pAic, // \arg pointer to the AIC registers
2793 unsigned int irq_id) // \arg Interrupt Number
2795 return (pAic->AIC_ISR & (0x1 << irq_id));
2798 //*----------------------------------------------------------------------------
2799 //* \fn AT91F_AIC_IsPending
2800 //* \brief Test if an IT is pending
2801 //*----------------------------------------------------------------------------
2802 __inline unsigned int AT91F_AIC_IsPending (
2803 AT91PS_AIC pAic, // \arg pointer to the AIC registers
2804 unsigned int irq_id) // \arg Interrupt Number
2806 return (pAic->AIC_IPR & (0x1 << irq_id));
2809 //*----------------------------------------------------------------------------
2810 //* \fn AT91F_AIC_Open
2811 //* \brief Set exception vectors and AIC registers to default values
2812 //*----------------------------------------------------------------------------
2813 __inline void AT91F_AIC_Open(
2814 AT91PS_AIC pAic, // \arg pointer to the AIC registers
2815 void (*IrqHandler) (), // \arg Default IRQ vector exception
2816 void (*FiqHandler) (), // \arg Default FIQ vector exception
2817 void (*DefaultHandler) (), // \arg Default Handler set in ISR
2818 void (*SpuriousHandler) (), // \arg Default Spurious Handler
2819 unsigned int protectMode) // \arg Debug Control Register
2823 // Disable all interrupts and set IVR to the default handler
2824 for (i = 0; i < 32; ++i) {
2825 AT91F_AIC_DisableIt(pAic, i);
2826 AT91F_AIC_ConfigureIt(pAic, i, AT91C_AIC_PRIOR_LOWEST, AT91C_AIC_SRCTYPE_INT_LEVEL_SENSITIVE, DefaultHandler);
2829 // Set the IRQ exception vector
2830 AT91F_AIC_SetExceptionVector((unsigned int *) 0x18, IrqHandler);
2831 // Set the Fast Interrupt exception vector
2832 AT91F_AIC_SetExceptionVector((unsigned int *) 0x1C, FiqHandler);
2834 pAic->AIC_SPU = (unsigned int) SpuriousHandler;
2835 pAic->AIC_DCR = protectMode;
2837 //*----------------------------------------------------------------------------
2838 //* \fn AT91F_MC_CfgPMC
2839 //* \brief Enable Peripheral clock in PMC for MC
2840 //*----------------------------------------------------------------------------
2841 __inline void AT91F_MC_CfgPMC (void)
2843 AT91F_PMC_EnablePeriphClock(
2844 AT91C_BASE_PMC, // PIO controller base address
2845 ((unsigned int) 1 << AT91C_ID_SYS));
2848 //*----------------------------------------------------------------------------
2849 //* \fn AT91F_DBGU_CfgPMC
2850 //* \brief Enable Peripheral clock in PMC for DBGU
2851 //*----------------------------------------------------------------------------
2852 __inline void AT91F_DBGU_CfgPMC (void)
2854 AT91F_PMC_EnablePeriphClock(
2855 AT91C_BASE_PMC, // PIO controller base address
2856 ((unsigned int) 1 << AT91C_ID_SYS));
2859 //*----------------------------------------------------------------------------
2860 //* \fn AT91F_DBGU_CfgPIO
2861 //* \brief Configure PIO controllers to drive DBGU signals
2862 //*----------------------------------------------------------------------------
2863 __inline void AT91F_DBGU_CfgPIO (void)
2865 // Configure PIO controllers to periph mode
2866 AT91F_PIO_CfgPeriph(
2867 AT91C_BASE_PIOA, // PIO controller base address
2868 ((unsigned int) AT91C_PA10_DTXD ) |
2869 ((unsigned int) AT91C_PA9_DRXD ), // Peripheral A
2873 //*----------------------------------------------------------------------------
2874 //* \fn AT91F_PWMC_CH3_CfgPIO
2875 //* \brief Configure PIO controllers to drive PWMC_CH3 signals
2876 //*----------------------------------------------------------------------------
2877 __inline void AT91F_PWMC_CH3_CfgPIO (void)
2879 // Configure PIO controllers to periph mode
2880 AT91F_PIO_CfgPeriph(
2881 AT91C_BASE_PIOA, // PIO controller base address
2883 ((unsigned int) AT91C_PA14_PWM3 ) |
2884 ((unsigned int) AT91C_PA7_PWM3 )); // Peripheral B
2887 //*----------------------------------------------------------------------------
2888 //* \fn AT91F_PWMC_CH2_CfgPIO
2889 //* \brief Configure PIO controllers to drive PWMC_CH2 signals
2890 //*----------------------------------------------------------------------------
2891 __inline void AT91F_PWMC_CH2_CfgPIO (void)
2893 // Configure PIO controllers to periph mode
2894 AT91F_PIO_CfgPeriph(
2895 AT91C_BASE_PIOA, // PIO controller base address
2896 ((unsigned int) AT91C_PA2_PWM2 ), // Peripheral A
2897 ((unsigned int) AT91C_PA25_PWM2 ) |
2898 ((unsigned int) AT91C_PA13_PWM2 )); // Peripheral B
2901 //*----------------------------------------------------------------------------
2902 //* \fn AT91F_PWMC_CH1_CfgPIO
2903 //* \brief Configure PIO controllers to drive PWMC_CH1 signals
2904 //*----------------------------------------------------------------------------
2905 __inline void AT91F_PWMC_CH1_CfgPIO (void)
2907 // Configure PIO controllers to periph mode
2908 AT91F_PIO_CfgPeriph(
2909 AT91C_BASE_PIOA, // PIO controller base address
2910 ((unsigned int) AT91C_PA1_PWM1 ), // Peripheral A
2911 ((unsigned int) AT91C_PA24_PWM1 ) |
2912 ((unsigned int) AT91C_PA12_PWM1 )); // Peripheral B
2915 //*----------------------------------------------------------------------------
2916 //* \fn AT91F_PWMC_CH0_CfgPIO
2917 //* \brief Configure PIO controllers to drive PWMC_CH0 signals
2918 //*----------------------------------------------------------------------------
2919 __inline void AT91F_PWMC_CH0_CfgPIO (void)
2921 // Configure PIO controllers to periph mode
2922 AT91F_PIO_CfgPeriph(
2923 AT91C_BASE_PIOA, // PIO controller base address
2924 ((unsigned int) AT91C_PA0_PWM0 ), // Peripheral A
2925 ((unsigned int) AT91C_PA23_PWM0 ) |
2926 ((unsigned int) AT91C_PA11_PWM0 )); // Peripheral B
2929 //*----------------------------------------------------------------------------
2930 //* \fn AT91F_SSC_CfgPMC
2931 //* \brief Enable Peripheral clock in PMC for SSC
2932 //*----------------------------------------------------------------------------
2933 __inline void AT91F_SSC_CfgPMC (void)
2935 AT91F_PMC_EnablePeriphClock(
2936 AT91C_BASE_PMC, // PIO controller base address
2937 ((unsigned int) 1 << AT91C_ID_SSC));
2940 //*----------------------------------------------------------------------------
2941 //* \fn AT91F_SSC_CfgPIO
2942 //* \brief Configure PIO controllers to drive SSC signals
2943 //*----------------------------------------------------------------------------
2944 __inline void AT91F_SSC_CfgPIO (void)
2946 // Configure PIO controllers to periph mode
2947 AT91F_PIO_CfgPeriph(
2948 AT91C_BASE_PIOA, // PIO controller base address
2949 ((unsigned int) AT91C_PA17_TD ) |
2950 ((unsigned int) AT91C_PA15_TF ) |
2951 ((unsigned int) AT91C_PA19_RK ) |
2952 ((unsigned int) AT91C_PA18_RD ) |
2953 ((unsigned int) AT91C_PA20_RF ) |
2954 ((unsigned int) AT91C_PA16_TK ), // Peripheral A
2958 //*----------------------------------------------------------------------------
2959 //* \fn AT91F_SPI_CfgPMC
2960 //* \brief Enable Peripheral clock in PMC for SPI
2961 //*----------------------------------------------------------------------------
2962 __inline void AT91F_SPI_CfgPMC (void)
2964 AT91F_PMC_EnablePeriphClock(
2965 AT91C_BASE_PMC, // PIO controller base address
2966 ((unsigned int) 1 << AT91C_ID_SPI));
2969 //*----------------------------------------------------------------------------
2970 //* \fn AT91F_SPI_CfgPIO
2971 //* \brief Configure PIO controllers to drive SPI signals
2972 //*----------------------------------------------------------------------------
2973 __inline void AT91F_SPI_CfgPIO (void)
2975 // Configure PIO controllers to periph mode
2976 AT91F_PIO_CfgPeriph(
2977 AT91C_BASE_PIOA, // PIO controller base address
2978 ((unsigned int) AT91C_PA11_NPCS0 ) |
2979 ((unsigned int) AT91C_PA13_MOSI ) |
2980 ((unsigned int) AT91C_PA31_NPCS1 ) |
2981 ((unsigned int) AT91C_PA12_MISO ) |
2982 ((unsigned int) AT91C_PA14_SPCK ), // Peripheral A
2983 ((unsigned int) AT91C_PA9_NPCS1 ) |
2984 ((unsigned int) AT91C_PA30_NPCS2 ) |
2985 ((unsigned int) AT91C_PA10_NPCS2 ) |
2986 ((unsigned int) AT91C_PA22_NPCS3 ) |
2987 ((unsigned int) AT91C_PA3_NPCS3 ) |
2988 ((unsigned int) AT91C_PA5_NPCS3 )); // Peripheral B
2991 //*----------------------------------------------------------------------------
2992 //* \fn AT91F_PWMC_CfgPMC
2993 //* \brief Enable Peripheral clock in PMC for PWMC
2994 //*----------------------------------------------------------------------------
2995 __inline void AT91F_PWMC_CfgPMC (void)
2997 AT91F_PMC_EnablePeriphClock(
2998 AT91C_BASE_PMC, // PIO controller base address
2999 ((unsigned int) 1 << AT91C_ID_PWMC));
3002 //*----------------------------------------------------------------------------
3003 //* \fn AT91F_TC2_CfgPMC
3004 //* \brief Enable Peripheral clock in PMC for TC2
3005 //*----------------------------------------------------------------------------
3006 __inline void AT91F_TC2_CfgPMC (void)
3008 AT91F_PMC_EnablePeriphClock(
3009 AT91C_BASE_PMC, // PIO controller base address
3010 ((unsigned int) 1 << AT91C_ID_TC2));
3013 //*----------------------------------------------------------------------------
3014 //* \fn AT91F_TC2_CfgPIO
3015 //* \brief Configure PIO controllers to drive TC2 signals
3016 //*----------------------------------------------------------------------------
3017 __inline void AT91F_TC2_CfgPIO (void)
3019 // Configure PIO controllers to periph mode
3020 AT91F_PIO_CfgPeriph(
3021 AT91C_BASE_PIOA, // PIO controller base address
3023 ((unsigned int) AT91C_PA26_TIOA2 ) |
3024 ((unsigned int) AT91C_PA27_TIOB2 ) |
3025 ((unsigned int) AT91C_PA29_TCLK2 )); // Peripheral B
3028 //*----------------------------------------------------------------------------
3029 //* \fn AT91F_TC1_CfgPMC
3030 //* \brief Enable Peripheral clock in PMC for TC1
3031 //*----------------------------------------------------------------------------
3032 __inline void AT91F_TC1_CfgPMC (void)
3034 AT91F_PMC_EnablePeriphClock(
3035 AT91C_BASE_PMC, // PIO controller base address
3036 ((unsigned int) 1 << AT91C_ID_TC1));
3039 //*----------------------------------------------------------------------------
3040 //* \fn AT91F_TC1_CfgPIO
3041 //* \brief Configure PIO controllers to drive TC1 signals
3042 //*----------------------------------------------------------------------------
3043 __inline void AT91F_TC1_CfgPIO (void)
3045 // Configure PIO controllers to periph mode
3046 AT91F_PIO_CfgPeriph(
3047 AT91C_BASE_PIOA, // PIO controller base address
3049 ((unsigned int) AT91C_PA15_TIOA1 ) |
3050 ((unsigned int) AT91C_PA16_TIOB1 ) |
3051 ((unsigned int) AT91C_PA28_TCLK1 )); // Peripheral B
3054 //*----------------------------------------------------------------------------
3055 //* \fn AT91F_TC0_CfgPMC
3056 //* \brief Enable Peripheral clock in PMC for TC0
3057 //*----------------------------------------------------------------------------
3058 __inline void AT91F_TC0_CfgPMC (void)
3060 AT91F_PMC_EnablePeriphClock(
3061 AT91C_BASE_PMC, // PIO controller base address
3062 ((unsigned int) 1 << AT91C_ID_TC0));
3065 //*----------------------------------------------------------------------------
3066 //* \fn AT91F_TC0_CfgPIO
3067 //* \brief Configure PIO controllers to drive TC0 signals
3068 //*----------------------------------------------------------------------------
3069 __inline void AT91F_TC0_CfgPIO (void)
3071 // Configure PIO controllers to periph mode
3072 AT91F_PIO_CfgPeriph(
3073 AT91C_BASE_PIOA, // PIO controller base address
3075 ((unsigned int) AT91C_PA0_TIOA0 ) |
3076 ((unsigned int) AT91C_PA1_TIOB0 ) |
3077 ((unsigned int) AT91C_PA4_TCLK0 )); // Peripheral B
3080 //*----------------------------------------------------------------------------
3081 //* \fn AT91F_PMC_CfgPMC
3082 //* \brief Enable Peripheral clock in PMC for PMC
3083 //*----------------------------------------------------------------------------
3084 __inline void AT91F_PMC_CfgPMC (void)
3086 AT91F_PMC_EnablePeriphClock(
3087 AT91C_BASE_PMC, // PIO controller base address
3088 ((unsigned int) 1 << AT91C_ID_SYS));
3091 //*----------------------------------------------------------------------------
3092 //* \fn AT91F_PMC_CfgPIO
3093 //* \brief Configure PIO controllers to drive PMC signals
3094 //*----------------------------------------------------------------------------
3095 __inline void AT91F_PMC_CfgPIO (void)
3097 // Configure PIO controllers to periph mode
3098 AT91F_PIO_CfgPeriph(
3099 AT91C_BASE_PIOA, // PIO controller base address
3101 ((unsigned int) AT91C_PA17_PCK1 ) |
3102 ((unsigned int) AT91C_PA21_PCK1 ) |
3103 ((unsigned int) AT91C_PA31_PCK2 ) |
3104 ((unsigned int) AT91C_PA18_PCK2 ) |
3105 ((unsigned int) AT91C_PA6_PCK0 )); // Peripheral B
3108 //*----------------------------------------------------------------------------
3109 //* \fn AT91F_ADC_CfgPMC
3110 //* \brief Enable Peripheral clock in PMC for ADC
3111 //*----------------------------------------------------------------------------
3112 __inline void AT91F_ADC_CfgPMC (void)
3114 AT91F_PMC_EnablePeriphClock(
3115 AT91C_BASE_PMC, // PIO controller base address
3116 ((unsigned int) 1 << AT91C_ID_ADC));
3119 //*----------------------------------------------------------------------------
3120 //* \fn AT91F_ADC_CfgPIO
3121 //* \brief Configure PIO controllers to drive ADC signals
3122 //*----------------------------------------------------------------------------
3123 __inline void AT91F_ADC_CfgPIO (void)
3125 // Configure PIO controllers to periph mode
3126 AT91F_PIO_CfgPeriph(
3127 AT91C_BASE_PIOA, // PIO controller base address
3129 ((unsigned int) AT91C_PA8_ADTRG )); // Peripheral B
3132 //*----------------------------------------------------------------------------
3133 //* \fn AT91F_PIOA_CfgPMC
3134 //* \brief Enable Peripheral clock in PMC for PIOA
3135 //*----------------------------------------------------------------------------
3136 __inline void AT91F_PIOA_CfgPMC (void)
3138 AT91F_PMC_EnablePeriphClock(
3139 AT91C_BASE_PMC, // PIO controller base address
3140 ((unsigned int) 1 << AT91C_ID_PIOA));
3143 //*----------------------------------------------------------------------------
3144 //* \fn AT91F_TWI_CfgPMC
3145 //* \brief Enable Peripheral clock in PMC for TWI
3146 //*----------------------------------------------------------------------------
3147 __inline void AT91F_TWI_CfgPMC (void)
3149 AT91F_PMC_EnablePeriphClock(
3150 AT91C_BASE_PMC, // PIO controller base address
3151 ((unsigned int) 1 << AT91C_ID_TWI));
3154 //*----------------------------------------------------------------------------
3155 //* \fn AT91F_TWI_CfgPIO
3156 //* \brief Configure PIO controllers to drive TWI signals
3157 //*----------------------------------------------------------------------------
3158 __inline void AT91F_TWI_CfgPIO (void)
3160 // Configure PIO controllers to periph mode
3161 AT91F_PIO_CfgPeriph(
3162 AT91C_BASE_PIOA, // PIO controller base address
3163 ((unsigned int) AT91C_PA3_TWD ) |
3164 ((unsigned int) AT91C_PA4_TWCK ), // Peripheral A
3168 //*----------------------------------------------------------------------------
3169 //* \fn AT91F_US1_CfgPMC
3170 //* \brief Enable Peripheral clock in PMC for US1
3171 //*----------------------------------------------------------------------------
3172 __inline void AT91F_US1_CfgPMC (void)
3174 AT91F_PMC_EnablePeriphClock(
3175 AT91C_BASE_PMC, // PIO controller base address
3176 ((unsigned int) 1 << AT91C_ID_US1));
3179 //*----------------------------------------------------------------------------
3180 //* \fn AT91F_US1_CfgPIO
3181 //* \brief Configure PIO controllers to drive US1 signals
3182 //*----------------------------------------------------------------------------
3183 __inline void AT91F_US1_CfgPIO (void)
3185 // Configure PIO controllers to periph mode
3186 AT91F_PIO_CfgPeriph(
3187 AT91C_BASE_PIOA, // PIO controller base address
3188 ((unsigned int) AT91C_PA21_RXD1 ) |
3189 ((unsigned int) AT91C_PA27_DTR1 ) |
3190 ((unsigned int) AT91C_PA26_DCD1 ) |
3191 ((unsigned int) AT91C_PA22_TXD1 ) |
3192 ((unsigned int) AT91C_PA24_RTS1 ) |
3193 ((unsigned int) AT91C_PA23_SCK1 ) |
3194 ((unsigned int) AT91C_PA28_DSR1 ) |
3195 ((unsigned int) AT91C_PA29_RI1 ) |
3196 ((unsigned int) AT91C_PA25_CTS1 ), // Peripheral A
3200 //*----------------------------------------------------------------------------
3201 //* \fn AT91F_US0_CfgPMC
3202 //* \brief Enable Peripheral clock in PMC for US0
3203 //*----------------------------------------------------------------------------
3204 __inline void AT91F_US0_CfgPMC (void)
3206 AT91F_PMC_EnablePeriphClock(
3207 AT91C_BASE_PMC, // PIO controller base address
3208 ((unsigned int) 1 << AT91C_ID_US0));
3211 //*----------------------------------------------------------------------------
3212 //* \fn AT91F_US0_CfgPIO
3213 //* \brief Configure PIO controllers to drive US0 signals
3214 //*----------------------------------------------------------------------------
3215 __inline void AT91F_US0_CfgPIO (void)
3217 // Configure PIO controllers to periph mode
3218 AT91F_PIO_CfgPeriph(
3219 AT91C_BASE_PIOA, // PIO controller base address
3220 ((unsigned int) AT91C_PA5_RXD0 ) |
3221 ((unsigned int) AT91C_PA6_TXD0 ) |
3222 ((unsigned int) AT91C_PA7_RTS0 ) |
3223 ((unsigned int) AT91C_PA8_CTS0 ), // Peripheral A
3224 ((unsigned int) AT91C_PA2_SCK0 )); // Peripheral B
3227 //*----------------------------------------------------------------------------
3228 //* \fn AT91F_UDP_CfgPMC
3229 //* \brief Enable Peripheral clock in PMC for UDP
3230 //*----------------------------------------------------------------------------
3231 __inline void AT91F_UDP_CfgPMC (void)
3233 AT91F_PMC_EnablePeriphClock(
3234 AT91C_BASE_PMC, // PIO controller base address
3235 ((unsigned int) 1 << AT91C_ID_UDP));
3238 //*----------------------------------------------------------------------------
3239 //* \fn AT91F_AIC_CfgPMC
3240 //* \brief Enable Peripheral clock in PMC for AIC
3241 //*----------------------------------------------------------------------------
3242 __inline void AT91F_AIC_CfgPMC (void)
3244 AT91F_PMC_EnablePeriphClock(
3245 AT91C_BASE_PMC, // PIO controller base address
3246 ((unsigned int) 1 << AT91C_ID_IRQ0) |
3247 ((unsigned int) 1 << AT91C_ID_FIQ) |
3248 ((unsigned int) 1 << AT91C_ID_IRQ1));
3251 //*----------------------------------------------------------------------------
3252 //* \fn AT91F_AIC_CfgPIO
3253 //* \brief Configure PIO controllers to drive AIC signals
3254 //*----------------------------------------------------------------------------
3255 __inline void AT91F_AIC_CfgPIO (void)
3257 // Configure PIO controllers to periph mode
3258 AT91F_PIO_CfgPeriph(
3259 AT91C_BASE_PIOA, // PIO controller base address
3260 ((unsigned int) AT91C_PA30_IRQ1 ), // Peripheral A
3261 ((unsigned int) AT91C_PA20_IRQ0 ) |
3262 ((unsigned int) AT91C_PA19_FIQ )); // Peripheral B
3265 #endif // lib_AT91SAM7S64_H