]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_AT91SAM3U256_IAR/AT91Lib/peripherals/ssc/ssc.h
Add FreeRTOS-Plus directory.
[freertos] / FreeRTOS / Demo / CORTEX_AT91SAM3U256_IAR / AT91Lib / peripherals / ssc / ssc.h
1 /* ----------------------------------------------------------------------------\r
2  *         ATMEL Microcontroller Software Support \r
3  * ----------------------------------------------------------------------------\r
4  * Copyright (c) 2008, Atmel Corporation\r
5  *\r
6  * All rights reserved.\r
7  *\r
8  * Redistribution and use in source and binary forms, with or without\r
9  * modification, are permitted provided that the following conditions are met:\r
10  *\r
11  * - Redistributions of source code must retain the above copyright notice,\r
12  * this list of conditions and the disclaimer below.\r
13  *\r
14  * Atmel's name may not be used to endorse or promote products derived from\r
15  * this software without specific prior written permission.\r
16  *\r
17  * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR\r
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\r
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE\r
20  * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,\r
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,\r
23  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\r
24  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
25  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\r
26  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
27  * ----------------------------------------------------------------------------\r
28  */\r
29 \r
30 //------------------------------------------------------------------------------\r
31 /// \dir\r
32 /// !Purpose\r
33 ///\r
34 /// Set of functions and definition for using a SSC peripheral.\r
35 ///\r
36 /// !Usage\r
37 ///\r
38 /// -# Enable the SSC interface pins (see pio & board.h).\r
39 /// -# Configure the SSC to operate at a specific frequency by calling\r
40 ///    SSC_Configure(). This function enables the peripheral clock of the SSC,\r
41 ///    but not its PIOs.\r
42 /// -# Configure the transmitter and/or the receiver using the\r
43 ///    SSC_ConfigureTransmitter() and SSC_ConfigureEmitter() functions.\r
44 /// -# Enable the PIOs or the transmitter and/or the received.\r
45 /// -# Enable the transmitter and/or the receiver using SSC_EnableTransmitter()\r
46 ///    and SSC_EnableReceiver()\r
47 /// -# Send data through the transmitter using SSC_Write() and SSC_WriteBuffer()\r
48 /// -# Receive data from the receiver using SSC_Read() and SSC_ReadBuffer()\r
49 /// -# Disable the transmitter and/or the receiver using SSC_DisableTransmitter()\r
50 ///    and SSC_DisableReceiver()\r
51 //------------------------------------------------------------------------------\r
52 \r
53 #ifndef SSC_H\r
54 #define SSC_H\r
55 \r
56 //------------------------------------------------------------------------------\r
57 //         Headers\r
58 //------------------------------------------------------------------------------\r
59 \r
60 #include <board.h>\r
61 \r
62 //------------------------------------------------------------------------------\r
63 //         Definitions\r
64 //------------------------------------------------------------------------------\r
65 \r
66 //------------------------------------------------------------------------------\r
67 /// \page "SSC configuration macros"\r
68 /// This page lists several macros which are used when configuring a SSC\r
69 /// peripheral.\r
70 /// \r
71 /// !Macros\r
72 /// - SSC_STTDLY\r
73 /// - SSC_PERIOD\r
74 /// - SSC_DATLEN\r
75 /// - SSC_DATNB\r
76 /// - SSC_FSLEN\r
77 \r
78 /// Calculates the value of the STTDLY field given the number of clock cycles\r
79 /// before the first bit of a new frame is transmitted.\r
80 #define SSC_STTDLY(bits)        (bits << 16)\r
81 \r
82 /// Calculates the value of the PERIOD field of the Transmit Clock Mode Register\r
83 /// of an SSC interface, given the desired clock divider.\r
84 #define SSC_PERIOD(divider)     (((divider / 2) - 1) << 24)\r
85 \r
86 /// Calculates the value of the DATLEN field of the Transmit Frame Mode Register\r
87 /// of an SSC interface, given the number of bits in one sample.\r
88 #define SSC_DATLEN(bits)        (bits - 1)\r
89 \r
90 /// Calculates the value of the DATNB field of the Transmit Frame Mode Register\r
91 /// of an SSC interface, given the number of samples in one frame.\r
92 #define SSC_DATNB(samples)      ((samples -1) << 8)\r
93 \r
94 /// Calculates the value of the FSLEN field of the Transmit Frame Mode Register\r
95 /// of an SSC interface, given the number of transmit clock periods that the \r
96 /// frame sync signal should take.\r
97 #define SSC_FSLEN(periods)      ((periods - 1) << 16)\r
98 //------------------------------------------------------------------------------\r
99 \r
100 //------------------------------------------------------------------------------\r
101 //         Exported functions\r
102 //------------------------------------------------------------------------------\r
103 extern void SSC_Configure(AT91S_SSC *ssc,\r
104                                  unsigned int id,\r
105                                  unsigned int bitRate,\r
106                                  unsigned int masterClock);\r
107 extern void SSC_ConfigureTransmitter(AT91S_SSC *ssc,\r
108                                             unsigned int tcmr,\r
109                                             unsigned int tfmr);\r
110 extern void SSC_ConfigureReceiver(AT91S_SSC *ssc,\r
111                                          unsigned int rcmr,\r
112                                          unsigned int rfmr);\r
113 \r
114 extern void SSC_EnableTransmitter(AT91S_SSC *ssc);\r
115 extern void SSC_DisableTransmitter(AT91S_SSC *ssc);\r
116 extern void SSC_EnableReceiver(AT91S_SSC *ssc);\r
117 extern void SSC_DisableReceiver(AT91S_SSC *ssc);\r
118 \r
119 extern void SSC_EnableInterrupts(AT91S_SSC *ssc, unsigned int sources);\r
120 extern void SSC_DisableInterrupts(AT91S_SSC *ssc, unsigned int sources);\r
121 \r
122 extern void SSC_Write(AT91S_SSC *ssc, unsigned int frame);\r
123 extern unsigned char SSC_WriteBuffer(AT91S_SSC *ssc,\r
124                                             void *buffer,\r
125                                             unsigned int length);\r
126 extern unsigned int SSC_Read(AT91S_SSC *ssc);\r
127 extern unsigned char SSC_ReadBuffer(AT91S_SSC *ssc,\r
128                                            void *buffer,\r
129                                            unsigned int length);\r
130 \r
131 #endif //#ifndef SSC_H\r
132 \r