1 /* ----------------------------------------------------------------------------
\r
2 * SAM Software Package License
\r
3 * ----------------------------------------------------------------------------
\r
4 * Copyright (c) 2012, Atmel Corporation
\r
6 * All rights reserved.
\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
11 * - Redistributions of source code must retain the above copyright notice,
\r
12 * this list of conditions and the disclaimer below.
\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
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
30 /** \addtogroup ssc_module Working with SSC
\r
31 * The SSC driver provides the interface to configure and use the SSC
\r
36 * -# Enable the SSC interface pins.
\r
37 * -# Configure the SSC to operate at a specific frequency by calling
\r
38 * SSC_Configure(). This function enables the peripheral clock of the SSC,
\r
40 * -# Configure the transmitter and/or the receiver using the
\r
41 * SSC_ConfigureTransmitter() and SSC_ConfigureEmitter() functions.
\r
42 * -# Enable the PIOs or the transmitter and/or the received.
\r
43 * -# Enable the transmitter and/or the receiver using SSC_EnableTransmitter()
\r
44 * and SSC_EnableReceiver()
\r
45 * -# Send data through the transmitter using SSC_Write()
\r
46 * -# Receive data from the receiver using SSC_Read()
\r
47 * -# Disable the transmitter and/or the receiver using SSC_DisableTransmitter()
\r
48 * and SSC_DisableReceiver()
\r
50 * For more accurate information, please look at the SSC section of the
\r
64 * Implementation of Synchronous Serial (SSC) controller.
\r
68 /*----------------------------------------------------------------------------
\r
70 *----------------------------------------------------------------------------*/
\r
74 /*----------------------------------------------------------------------------
\r
75 * Exported functions
\r
76 *----------------------------------------------------------------------------*/
\r
79 * \brief Configures a SSC peripheral.If the divided clock is not used, the master
\r
80 * clock frequency can be set to 0.
\r
81 * \note The emitter and transmitter are disabled by this function.
\r
82 * \param ssc Pointer to an SSC instance.
\r
83 * \param bitRate bit rate.
\r
84 * \param masterClock master clock.
\r
86 void SSC_Configure(Ssc *ssc, uint32_t bitRate, uint32_t masterClock)
\r
89 // uint32_t maxClock;
\r
91 // maxClock = PMC_SetPeriMaxClock(id, masterClock);
\r
93 /* Reset, disable receiver & transmitter */
\r
94 ssc->SSC_CR = SSC_CR_RXDIS | SSC_CR_TXDIS | SSC_CR_SWRST;
\r
96 /* Configure clock frequency */
\r
99 ssc->SSC_CMR = masterClock / (2 * bitRate);
\r
105 /* Enable SSC peripheral clock */
\r
106 PMC_EnablePeripheral(id);
\r
110 * \brief Configures the transmitter of a SSC peripheral.
\r
111 * \param ssc Pointer to an SSC instance.
\r
112 * \param tcmr Transmit Clock Mode Register value.
\r
113 * \param tfmr Transmit Frame Mode Register value.
\r
115 void SSC_ConfigureTransmitter(Ssc *ssc,uint32_t tcmr, uint32_t tfmr)
\r
117 ssc->SSC_TCMR = tcmr;
\r
118 ssc->SSC_TFMR = tfmr;
\r
122 * \brief Configures the receiver of a SSC peripheral.
\r
123 * \param ssc Pointer to an SSC instance.
\r
124 * \param rcmr Receive Clock Mode Register value.
\r
125 * \param rfmr Receive Frame Mode Register value.
\r
127 void SSC_ConfigureReceiver(Ssc *ssc, uint32_t rcmr, uint32_t rfmr)
\r
129 ssc->SSC_RCMR = rcmr;
\r
130 ssc->SSC_RFMR = rfmr;
\r
134 * \brief Enables the transmitter of a SSC peripheral.
\r
135 * \param ssc Pointer to an SSC instance.
\r
137 void SSC_EnableTransmitter(Ssc *ssc)
\r
139 ssc->SSC_CR = SSC_CR_TXEN;
\r
143 * \brief Disables the transmitter of a SSC peripheral.
\r
144 * \param ssc Pointer to an SSC instance.
\r
146 void SSC_DisableTransmitter(Ssc *ssc)
\r
148 ssc->SSC_CR = SSC_CR_TXDIS;
\r
152 * \brief Enables the receiver of a SSC peripheral.
\r
153 * \param ssc Pointer to an SSC instance.
\r
155 void SSC_EnableReceiver(Ssc *ssc)
\r
157 ssc->SSC_CR = SSC_CR_RXEN;
\r
161 * \brief Disables the receiver of a SSC peripheral.
\r
162 * \param ssc Pointer to an SSC instance.
\r
164 void SSC_DisableReceiver(Ssc *ssc)
\r
166 ssc->SSC_CR = SSC_CR_RXDIS;
\r
170 * \brief Enables one or more interrupt sources of a SSC peripheral.
\r
171 * \param ssc Pointer to an SSC instance.
\r
172 * \param sources Bitwise OR of selected interrupt sources.
\r
174 void SSC_EnableInterrupts(Ssc *ssc, uint32_t sources)
\r
176 ssc->SSC_IER = sources;
\r
180 * \brief Disables one or more interrupt sources of a SSC peripheral.
\r
181 * \param ssc Pointer to an SSC instance.
\r
182 * \param sources Bitwise OR of selected interrupt sources.
\r
184 void SSC_DisableInterrupts(Ssc *ssc, uint32_t sources)
\r
186 ssc->SSC_IDR = sources;
\r
190 * \brief Sends one data frame through a SSC peripheral. If another frame is currently
\r
191 * being sent, this function waits for the previous transfer to complete.
\r
192 * \param ssc Pointer to an SSC instance.
\r
193 * \param frame Data frame to send.
\r
195 void SSC_Write(Ssc *ssc, uint32_t frame)
\r
197 while ((ssc->SSC_SR & SSC_SR_TXRDY) == 0);
\r
198 ssc->SSC_THR = frame;
\r
202 * \brief Waits until one frame is received on a SSC peripheral, and returns it.
\r
203 * \param ssc Pointer to an SSC instance.
\r
205 uint32_t SSC_Read(Ssc *ssc)
\r
207 while ((ssc->SSC_SR & SSC_SR_RXRDY) == 0);
\r
208 return ssc->SSC_RHR;
\r
212 * \brief Return 1 if one frame is received, 0 otherwise.
\r
213 * \param ssc Pointer to an SSC instance.
\r
215 uint8_t SSC_IsRxReady(Ssc *ssc)
\r
217 return ((ssc->SSC_SR & SSC_SR_RXRDY) > 0);
\r