]> git.sur5r.net Git - freertos/blob - Demo/Common/drivers/Atmel/at91lib/peripherals/ssc/ssc.h
Atmel provided hardware specifics.
[freertos] / Demo / Common / drivers / Atmel / 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\r
35 /// peripheral.\r
36 ///\r
37 /// !Usage\r
38 ///\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 using\r
45 ///    CHIP_EnableSSCTransmitter() and CHIP_EnableSSCReceiver().\r
46 /// -# Enable the transmitter and/or the receiver using SSC_EnableTransmitter()\r
47 ///    and SSC_EnableReceiver()\r
48 /// -# Send data through the transmitter using SSC_Write() and SSC_WriteBuffer()\r
49 /// -# Receive data from the receiver using SSC_Read() and SSC_ReadBuffer()\r
50 /// -# Disable the transmitter and/or the receiver using SSC_DisableTransmitter()\r
51 ///    and SSC_DisableReceiver()\r
52 //------------------------------------------------------------------------------\r
53 \r
54 #ifndef SSC_H\r
55 #define SSC_H\r
56 \r
57 //------------------------------------------------------------------------------\r
58 //         Headers\r
59 //------------------------------------------------------------------------------\r
60 \r
61 #include <board.h>\r
62 \r
63 //------------------------------------------------------------------------------\r
64 //         Definitions\r
65 //------------------------------------------------------------------------------\r
66 \r
67 //------------------------------------------------------------------------------\r
68 /// \page "SSC configuration macros"\r
69 /// This page lists several macros which are used when configuring a SSC\r
70 /// peripheral.\r
71 /// \r
72 /// !Macros\r
73 /// - SSC_STTDLY\r
74 /// - SSC_PERIOD\r
75 /// - SSC_DATLEN\r
76 /// - SSC_DATNB\r
77 /// - SSC_FSLEN\r
78 \r
79 /// Calculates the value of the STTDLY field given the number of clock cycles\r
80 /// before the first bit of a new frame is transmitted.\r
81 #define SSC_STTDLY(bits)        (bits << 16)\r
82 \r
83 /// Calculates the value of the PERIOD field of the Transmit Clock Mode Register\r
84 /// of an SSC interface, given the desired clock divider.\r
85 #define SSC_PERIOD(divider)     (((divider / 2) - 1) << 24)\r
86 \r
87 /// Calculates the value of the DATLEN field of the Transmit Frame Mode Register\r
88 /// of an SSC interface, given the number of bits in one sample.\r
89 #define SSC_DATLEN(bits)        (bits - 1)\r
90 \r
91 /// Calculates the value of the DATNB field of the Transmit Frame Mode Register\r
92 /// of an SSC interface, given the number of samples in one frame.\r
93 #define SSC_DATNB(samples)      ((samples -1) << 8)\r
94 \r
95 /// Calculates the value of the FSLEN field of the Transmit Frame Mode Register\r
96 /// of an SSC interface, given the number of transmit clock periods that the \r
97 /// frame sync signal should take.\r
98 #define SSC_FSLEN(periods)      ((periods - 1) << 16)\r
99 //------------------------------------------------------------------------------\r
100 \r
101 //------------------------------------------------------------------------------\r
102 //         Exported functions\r
103 //------------------------------------------------------------------------------\r
104 extern void SSC_Configure(AT91S_SSC *ssc,\r
105                                  unsigned int id,\r
106                                  unsigned int bitRate,\r
107                                  unsigned int masterClock);\r
108 extern void SSC_ConfigureTransmitter(AT91S_SSC *ssc,\r
109                                             unsigned int tcmr,\r
110                                             unsigned int tfmr);\r
111 extern void SSC_ConfigureReceiver(AT91S_SSC *ssc,\r
112                                          unsigned int rcmr,\r
113                                          unsigned int rfmr);\r
114 \r
115 extern void SSC_EnableTransmitter(AT91S_SSC *ssc);\r
116 extern void SSC_DisableTransmitter(AT91S_SSC *ssc);\r
117 extern void SSC_EnableReceiver(AT91S_SSC *ssc);\r
118 extern void SSC_DisableReceiver(AT91S_SSC *ssc);\r
119 \r
120 extern void SSC_EnableInterrupts(AT91S_SSC *ssc, unsigned int sources);\r
121 extern void SSC_DisableInterrupts(AT91S_SSC *ssc, unsigned int sources);\r
122 \r
123 extern void SSC_Write(AT91S_SSC *ssc, unsigned int frame);\r
124 extern unsigned char SSC_WriteBuffer(AT91S_SSC *ssc,\r
125                                             void *buffer,\r
126                                             unsigned int length);\r
127 extern unsigned int SSC_Read(AT91S_SSC *ssc);\r
128 extern unsigned char SSC_ReadBuffer(AT91S_SSC *ssc,\r
129                                            void *buffer,\r
130                                            unsigned int length);\r
131 \r
132 #endif //#ifndef SSC_H\r
133 \r