Subversion Repositories NaviCtrl

Rev

Rev 1 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1 Rev 196
1
/******************** (C) COPYRIGHT 2006 STMicroelectronics ********************
1
/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
2
* File Name          : 91x_ssp.c
2
* File Name          : 91x_ssp.c
3
* Author             : MCD Application Team
3
* Author             : MCD Application Team
-
 
4
* Version            : V2.1
4
* Date First Issued  : 05/18/2006 : Version 1.0
5
* Date               : 12/22/2008
5
* Description        : This file provides all the SSP software functions.
6
* Description        : This file provides all the SSP firmware functions.
6
********************************************************************************
-
 
7
* History:
-
 
8
* 05/22/2007 : Version 1.2
-
 
9
* 05/24/2006 : Version 1.1
-
 
10
* 05/18/2006 : Version 1.0
-
 
11
********************************************************************************
7
********************************************************************************
12
* THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
8
* THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
13
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
9
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
14
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
10
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
15
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
11
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
16
* CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
12
* CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
17
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
13
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
18
*******************************************************************************/
14
*******************************************************************************/
19
 
15
 
20
/* Includes ------------------------------------------------------------------*/
16
/* Includes ------------------------------------------------------------------*/
21
#include "91x_ssp.h"
17
#include "91x_ssp.h"
22
#include "91x_scu.h"
18
#include "91x_scu.h"
23
 
19
 
24
/* Private typedef -----------------------------------------------------------*/
20
/* Private typedef -----------------------------------------------------------*/
25
/* Private define ------------------------------------------------------------*/
21
/* Private define ------------------------------------------------------------*/
26
/* Private macro -------------------------------------------------------------*/
22
/* Private macro -------------------------------------------------------------*/
27
/* Private variables ---------------------------------------------------------*/
23
/* Private variables ---------------------------------------------------------*/
28
 
24
 
29
/* SSP peripheral Enable */
25
/* SSP peripheral Enable */
30
#define SSP_Enable   0x0002
26
#define SSP_Enable   0x0002
31
#define SSP_Disable  0xFFFD
27
#define SSP_Disable  0xFFFD
32
 
28
 
33
/* SSP Loop Back Mode Enable */
29
/* SSP Loop Back Mode Enable */
34
#define SSP_LoopBackMode_Enable   0x0001
30
#define SSP_LoopBackMode_Enable   0x0001
35
#define SSP_LoopBackMode_Disable  0xFFFE
31
#define SSP_LoopBackMode_Disable  0xFFFE
36
 
32
 
37
/* SSP Flag Mask */
33
/* SSP Flag Mask */
38
#define SSP_Flag_Mask  0x001F
34
#define SSP_Flag_Mask  0x001F
39
 
35
 
40
/* SSP DMA transmit/ receive enable/disable Masks */
36
/* SSP DMA transmit/ receive enable/disable Masks */
41
#define SSP_DMA_TransmitEnable   0x0002
37
#define SSP_DMA_TransmitEnable   0x0002
42
#define SSP_DMA_TransmitDisable  0xFFFD
38
#define SSP_DMA_TransmitDisable  0xFFFD
43
#define SSP_DMA_ReceiveEnable    0x0001
39
#define SSP_DMA_ReceiveEnable    0x0001
44
#define SSP_DMA_ReceiveDisable   0xFFFE
40
#define SSP_DMA_ReceiveDisable   0xFFFE
45
 
41
 
46
/* SSP Masks */
42
/* SSP Masks */
47
#define SSP_FrameFormat_Mask     0xFFCF
43
#define SSP_FrameFormat_Mask     0xFFCF
48
#define SSP_DataSize_Mask        0xFFF0
44
#define SSP_DataSize_Mask        0xFFF0
49
#define SSP_ClockRate_Mask       0x00FF
45
#define SSP_ClockRate_Mask       0x00FF
50
#define SSP_ClockPrescaler_Mask  0xFF00
46
#define SSP_ClockPrescaler_Mask  0xFF00
51
 
47
 
52
/* Private function prototypes -----------------------------------------------*/
48
/* Private function prototypes -----------------------------------------------*/
53
/* Private functions ---------------------------------------------------------*/
49
/* Private functions ---------------------------------------------------------*/
54
 
50
 
55
/*******************************************************************************
51
/*******************************************************************************
56
* Function Name  : SSP_DeInit
52
* Function Name  : SSP_DeInit
57
* Description    : Deinitializes the SSPx peripheral registers to their default
53
* Description    : Deinitializes the SSPx peripheral registers to their default
58
*                  reset values.
54
*                  reset values.
59
* Input          : SSPx: where x can be 0 or 1 to select the SSP peripheral.
55
* Input          : SSPx: where x can be 0 or 1 to select the SSP peripheral.
60
* Output         : None
56
* Output         : None
61
* Return         : None
57
* Return         : None
62
*******************************************************************************/
58
*******************************************************************************/
63
void SSP_DeInit(SSP_TypeDef* SSPx)
59
void SSP_DeInit(SSP_TypeDef* SSPx)
64
{
60
{
65
  if(SSPx == SSP0)
61
  if(SSPx == SSP0)
66
  {
62
  {
67
    /* Reset the SSP0 registers values*/
63
    /* Reset the SSP0 registers values*/
68
    SCU_APBPeriphReset(__SSP0,ENABLE);
64
    SCU_APBPeriphReset(__SSP0,ENABLE);
69
    SCU_APBPeriphReset(__SSP0,DISABLE);
65
    SCU_APBPeriphReset(__SSP0,DISABLE);
70
  }
66
  }
71
  else if (SSPx == SSP1)
67
  else if (SSPx == SSP1)
72
  {
68
  {
73
    /* Reset the SSP1 registers values*/
69
    /* Reset the SSP1 registers values*/
74
    SCU_APBPeriphReset(__SSP1,ENABLE);
70
    SCU_APBPeriphReset(__SSP1,ENABLE);
75
    SCU_APBPeriphReset(__SSP1,DISABLE);
71
    SCU_APBPeriphReset(__SSP1,DISABLE);
76
  }
72
  }
77
}
73
}
78
 
74
 
79
/*******************************************************************************
75
/*******************************************************************************
80
* Function Name  : SSP_Init
76
* Function Name  : SSP_Init
81
* Description    : Initializes the SSPx  peripheral accordingto the specified
77
* Description    : Initializes the SSPx  peripheral according to the specified
82
*                  parameters in the SSP_InitTypeDef structure.
78
*                  parameters in the SSP_InitTypeDef structure.
83
* Input          : - SSPx: where x can be 0 or 1 to select the SSP peripheral.
79
* Input          : - SSPx: where x can be 0 or 1 to select the SSP peripheral.
84
*                  - SSP_InitStruct: pointer to a SSP_InitTypeDef structure that
80
*                  - SSP_InitStruct: pointer to a SSP_InitTypeDef structure that
85
*                    contains the configuration information for the specified SSP
81
*                    contains the configuration information for the specified SSP
86
*                    peripheral.
82
*                    peripheral.
87
* Output         : None
83
* Output         : None
88
* Return         : None
84
* Return         : None
89
*******************************************************************************/
85
*******************************************************************************/
90
void SSP_Init(SSP_TypeDef* SSPx, SSP_InitTypeDef* SSP_InitStruct)
86
void SSP_Init(SSP_TypeDef* SSPx, SSP_InitTypeDef* SSP_InitStruct)
91
{
87
{
92
  if(SSP_InitStruct->SSP_FrameFormat == SSP_FrameFormat_Motorola)
88
  if(SSP_InitStruct->SSP_FrameFormat == SSP_FrameFormat_Motorola)
93
  {
89
  {
94
    /* Set the Motorola frame format */
90
    /* Set the Motorola frame format */
95
    SSPx->CR0 &= SSP_FrameFormat_Motorola;
91
    SSPx->CR0 &= SSP_FrameFormat_Motorola;
96
    /* Configure the Clock polarity */
92
    /* Configure the Clock polarity */
97
    if(SSP_InitStruct->SSP_CPOL == SSP_CPOL_High)
93
    if(SSP_InitStruct->SSP_CPOL == SSP_CPOL_High)
98
    {
94
    {
99
      /* SCK is held high when no data is being transfered */
95
      /* SCK is held high when no data is being transfered */
100
      SSPx->CR0 |= SSP_CPOL_High;
96
      SSPx->CR0 |= SSP_CPOL_High;
101
    }
97
    }
102
    else
98
    else
103
    {
99
    {
104
      /* SCK is held low when no data is being transfered */
100
      /* SCK is held low when no data is being transfered */
105
      SSPx->CR0 &= SSP_CPOL_Low;
101
      SSPx->CR0 &= SSP_CPOL_Low;
106
    }
102
    }
107
    /* Configure the Clock Phase */
103
    /* Configure the Clock Phase */
108
    if(SSP_InitStruct->SSP_CPHA == SSP_CPHA_2Edge)
104
    if(SSP_InitStruct->SSP_CPHA == SSP_CPHA_2Edge)
109
    {
105
    {
110
      /* Data captured on second clock edge */
106
      /* Data captured on second clock edge */
111
      SSPx->CR0 |= SSP_CPHA_2Edge;
107
      SSPx->CR0 |= SSP_CPHA_2Edge;
112
    }
108
    }
113
    else
109
    else
114
    {
110
    {
115
      /* Data captured on first clock edge */
111
      /* Data captured on first clock edge */
116
      SSPx->CR0 &= SSP_CPHA_1Edge;
112
      SSPx->CR0 &= SSP_CPHA_1Edge;
117
    }
113
    }
118
  }
114
  }
119
   /* Configure the Frame format */
115
   /* Configure the Frame format */
120
  else
116
  else
121
  {
117
  {
122
    /* Clear the FRF[1:0] bits */
118
    /* Clear the FRF[1:0] bits */
123
    SSPx->CR0 &= SSP_FrameFormat_Mask;
119
    SSPx->CR0 &= SSP_FrameFormat_Mask;
124
    /* Set the TI frame format */
120
    /* Set the TI frame format */
125
    SSPx->CR0 |= SSP_InitStruct->SSP_FrameFormat;
121
    SSPx->CR0 |= SSP_InitStruct->SSP_FrameFormat;
126
  }
122
  }
127
  /* Configure the Mode */
123
  /* Configure the Mode */
128
  if(SSP_InitStruct->SSP_Mode == SSP_Mode_Slave)
124
  if(SSP_InitStruct->SSP_Mode == SSP_Mode_Slave)
129
  {
125
  {
130
    /* Set the slave mode */
126
    /* Set the slave mode */
131
    SSPx->CR1 |= SSP_Mode_Slave;
127
    SSPx->CR1 |= SSP_Mode_Slave;
132
    /* Configure the Slave output */
128
    /* Configure the Slave output */
133
    if(SSP_InitStruct->SSP_SlaveOutput == SSP_SlaveOutput_Disable)
129
    if(SSP_InitStruct->SSP_SlaveOutput == SSP_SlaveOutput_Disable)
134
    {
130
    {
135
      /* Slave output disabled */
131
      /* Slave output disabled */
136
      SSPx->CR1 |= SSP_SlaveOutput_Disable;
132
      SSPx->CR1 |= SSP_SlaveOutput_Disable;
137
    }
133
    }
138
    else
134
    else
139
    {
135
    {
140
      /* Slave output enabled */
136
      /* Slave output enabled */
141
      SSPx->CR1 &= SSP_SlaveOutput_Enable;
137
      SSPx->CR1 &= SSP_SlaveOutput_Enable;
142
    }
138
    }
143
  }
139
  }
144
  else
140
  else
145
  {
141
  {
146
    /* Set the master mode */
142
    /* Set the master mode */
147
    SSPx->CR1 &= SSP_Mode_Master;
143
    SSPx->CR1 &= SSP_Mode_Master;
148
    /* Clear clock rate SCR[7:0] bits */
144
    /* Clear clock rate SCR[7:0] bits */
149
    SSPx->CR0 &= SSP_ClockRate_Mask;
145
    SSPx->CR0 &= SSP_ClockRate_Mask;
150
    /* Set the serial clock rate */
146
    /* Set the serial clock rate */
151
    SSPx->CR0 |= (SSP_InitStruct->SSP_ClockRate<<8);
147
    SSPx->CR0 |= (SSP_InitStruct->SSP_ClockRate<<8);
152
    /* Clear clock prescaler CPSDVSR[7:0] bits */
148
    /* Clear clock prescaler CPSDVSR[7:0] bits */
153
    SSPx->PR &= SSP_ClockPrescaler_Mask;
149
    SSPx->PR &= SSP_ClockPrescaler_Mask;
154
    /* Set the serial clock prescaler */
150
    /* Set the serial clock prescaler */
155
    SSPx->PR |= SSP_InitStruct->SSP_ClockPrescaler;
151
    SSPx->PR |= SSP_InitStruct->SSP_ClockPrescaler;
156
  }
152
  }
157
 
153
 
158
  /* Clear data size DSS[3:0] bits */
154
  /* Clear data size DSS[3:0] bits */
159
  SSPx->CR0 &= SSP_DataSize_Mask;
155
  SSPx->CR0 &= SSP_DataSize_Mask;
160
  /* Set the data size */
156
  /* Set the data size */
161
  SSPx->CR0 |= SSP_InitStruct->SSP_DataSize;
157
  SSPx->CR0 |= SSP_InitStruct->SSP_DataSize;
162
}
158
}
163
/*******************************************************************************
159
/*******************************************************************************
164
* Function Name  : SSP_StructInit
160
* Function Name  : SSP_StructInit
165
* Description    : Fills in a SSP_InitTypeDef structure with the reset value of
161
* Description    : Fills in a SSP_InitTypeDef structure with the reset value of
166
*                  each parameter.
162
*                  each parameter.
167
* Input          : SSP_InitStruct : pointer to a SSP_InitTypeDef structure
163
* Input          : SSP_InitStruct : pointer to a SSP_InitTypeDef structure
168
                   which will be initialized.
164
                   which will be initialized.
169
* Output         : None
165
* Output         : None
170
* Return         : None
166
* Return         : None
171
*******************************************************************************/
167
*******************************************************************************/
172
void SSP_StructInit(SSP_InitTypeDef* SSP_InitStruct)
168
void SSP_StructInit(SSP_InitTypeDef* SSP_InitStruct)
173
{
169
{
174
  /* Initialize the SSP_FrameFormat member */
170
  /* Initialize the SSP_FrameFormat member */
175
  SSP_InitStruct->SSP_FrameFormat = SSP_FrameFormat_Motorola;
171
  SSP_InitStruct->SSP_FrameFormat = SSP_FrameFormat_Motorola;
176
 
172
 
177
  /* Initialize the SSP_Mode member */
173
  /* Initialize the SSP_Mode member */
178
  SSP_InitStruct->SSP_Mode = SSP_Mode_Master;
174
  SSP_InitStruct->SSP_Mode = SSP_Mode_Master;
179
 
175
 
180
  /* Initialize the SSP_CPOL member */
176
  /* Initialize the SSP_CPOL member */
181
  SSP_InitStruct->SSP_CPOL = SSP_CPOL_Low;
177
  SSP_InitStruct->SSP_CPOL = SSP_CPOL_Low;
182
 
178
 
183
  /* Initialize the SSP_CPHA member */
179
  /* Initialize the SSP_CPHA member */
184
  SSP_InitStruct->SSP_CPHA = SSP_CPHA_1Edge;
180
  SSP_InitStruct->SSP_CPHA = SSP_CPHA_1Edge;
185
 
181
 
186
  /* Initialize the SSP_DataSize member */
182
  /* Initialize the SSP_DataSize member */
187
  SSP_InitStruct->SSP_DataSize = SSP_DataSize_8b;
183
  SSP_InitStruct->SSP_DataSize = SSP_DataSize_8b;
188
 
184
 
189
  /* Initialize the SSP_SlaveOutput member */
185
  /* Initialize the SSP_SlaveOutput member */
190
  SSP_InitStruct->SSP_SlaveOutput = SSP_SlaveOutput_Enable;
186
  SSP_InitStruct->SSP_SlaveOutput = SSP_SlaveOutput_Enable;
191
 
187
 
192
  /* Initialize the SSP_ClockRate member */
188
  /* Initialize the SSP_ClockRate member */
193
  SSP_InitStruct->SSP_ClockRate = 0;
189
  SSP_InitStruct->SSP_ClockRate = 0;
194
 
190
 
195
  /* Initialize the SSP_ClockPrescaler member */
191
  /* Initialize the SSP_ClockPrescaler member */
196
  SSP_InitStruct->SSP_ClockPrescaler = 0;
192
  SSP_InitStruct->SSP_ClockPrescaler = 0;
197
}
193
}
198
 
194
 
199
/*******************************************************************************
195
/*******************************************************************************
200
* Function Name  : SSP_Cmd
196
* Function Name  : SSP_Cmd
201
* Description    : Enables or disables the specified SSP peripheral.
197
* Description    : Enables or disables the specified SSP peripheral.
202
* Input          : - SSPx: where x can be 0 or 1 to select the SSP peripheral.
198
* Input          : - SSPx: where x can be 0 or 1 to select the SSP peripheral.
203
*                  - NewState: new state of the  SSPx peripheral. This parameter
199
*                  - NewState: new state of the  SSPx peripheral. This parameter
204
*                    can be: ENABLE or DISABLE.
200
*                    can be: ENABLE or DISABLE.
205
* Output         : None
201
* Output         : None
206
* Return         : None
202
* Return         : None
207
*******************************************************************************/
203
*******************************************************************************/
208
void SSP_Cmd(SSP_TypeDef* SSPx, FunctionalState NewState)
204
void SSP_Cmd(SSP_TypeDef* SSPx, FunctionalState NewState)
209
{
205
{
210
  if(NewState == ENABLE)
206
  if(NewState == ENABLE)
211
  {
207
  {
212
    /* Enable the SSP peripheral */
208
    /* Enable the SSP peripheral */
213
    SSPx->CR1 |= SSP_Enable;
209
    SSPx->CR1 |= SSP_Enable;
214
  }
210
  }
215
  else
211
  else
216
  {
212
  {
217
    /* Disable the SSP peripheral */
213
    /* Disable the SSP peripheral */
218
    SSPx->CR1 &= SSP_Disable;
214
    SSPx->CR1 &= SSP_Disable;
219
  }
215
  }
220
}
216
}
221
 
217
 
222
/*******************************************************************************
218
/*******************************************************************************
223
* Function Name  : SSP_ITConfig
219
* Function Name  : SSP_ITConfig
224
* Description    : Enables or disables the specified SSP interrupts.
220
* Description    : Enables or disables the specified SSP interrupts.
225
* Input          : - SSPx: where x can be 0 or 1 to select the SSP peripheral.
221
* Input          : - SSPx: where x can be 0 or 1 to select the SSP peripheral.
226
*                  - SSP_IT: specifies the SSP interrupts sources to be enabled
222
*                  - SSP_IT: specifies the SSP interrupts sources to be enabled
227
*                    or disabled. This parameter can be any combination of the
223
*                    or disabled. This parameter can be any combination of the
228
*                    following values:
224
*                    following values:
229
*                         - SSP_IT_TxFifo: Transmit FIFO half empty or less interrupt
225
*                         - SSP_IT_TxFifo: Transmit FIFO half empty or less interrupt
230
*                         - SSP_IT_RxFifo: Receive FIFO half full or less interrupt
226
*                         - SSP_IT_RxFifo: Receive FIFO half full or less interrupt
231
*                         - SSP_IT_RxTimeOut: Receive timeout interrupt
227
*                         - SSP_IT_RxTimeOut: Receive timeout interrupt
232
*                         - SSP_IT_RxOverrun: Receive overrun interrupt
228
*                         - SSP_IT_RxOverrun: Receive overrun interrupt
233
*                  - NewState: new state of the specified SSP interrupts.
229
*                  - NewState: new state of the specified SSP interrupts.
234
*                    This parameter can be: ENABLE or DISABLE.
230
*                    This parameter can be: ENABLE or DISABLE.
235
* Output         : None
231
* Output         : None
236
* Return         : None
232
* Return         : None
237
*******************************************************************************/
233
*******************************************************************************/
238
void SSP_ITConfig(SSP_TypeDef* SSPx, u16 SSP_IT, FunctionalState NewState)
234
void SSP_ITConfig(SSP_TypeDef* SSPx, u16 SSP_IT, FunctionalState NewState)
239
{
235
{
240
  if(NewState == ENABLE)
236
  if(NewState == ENABLE)
241
  {
237
  {
242
    /* Enable the selected SSP interrupts */
238
    /* Enable the selected SSP interrupts */
243
    SSPx->IMSCR |= SSP_IT;
239
    SSPx->IMSCR |= SSP_IT;
244
  }
240
  }
245
  else
241
  else
246
  {
242
  {
247
    /* Disable the selected SSP interrupts */
243
    /* Disable the selected SSP interrupts */
248
    SSPx->IMSCR &= ~SSP_IT;
244
    SSPx->IMSCR &= ~SSP_IT;
249
  }
245
  }
250
}
246
}
251
 
247
 
252
/*******************************************************************************
248
/*******************************************************************************
253
* Function Name  : SSP_DMACmd
249
* Function Name  : SSP_DMACmd
254
* Description    : Configures the SSP0 DMA interface.
250
* Description    : Configures the SSP0 DMA interface.
255
* Input          :  - SSPx: where x can be 0 or 1 to select the SSP peripheral.
251
* Input          :  - SSPx: where x can be 0 or 1 to select the SSP peripheral.
256
*                   - SSP_DMATransfert : specifies the DMA transfert to be
252
*                   - SSP_DMATransfert : specifies the DMA transfert to be
257
*                    enabled or disabled. This parameter can be one of the
253
*                    enabled or disabled. This parameter can be one of the
258
*                    following values:
254
*                    following values:
259
*                         - SSP_DMA_Transmit: transmit Fifo DMA transfert
255
*                         - SSP_DMA_Transmit: transmit Fifo DMA transfert
260
*                         - SSP_DMA_Receive : receive Fifo DMA transfert
256
*                         - SSP_DMA_Receive : receive Fifo DMA transfert
261
*                  - NewState: new state of the DMA transfert.
257
*                  - NewState: new state of the DMA transfert.
262
*                    This parameter can be: ENABLE or DISABLE.
258
*                    This parameter can be: ENABLE or DISABLE.
263
* Output         : None
259
* Output         : None
264
* Return         : None
260
* Return         : None
265
*******************************************************************************/
261
*******************************************************************************/
266
void SSP_DMACmd(SSP_TypeDef* SSPx, u16 SSP_DMATransfert, FunctionalState NewState)
262
void SSP_DMACmd(SSP_TypeDef* SSPx, u16 SSP_DMATransfert, FunctionalState NewState)
267
{
263
{
268
  if(NewState == ENABLE)
264
  if(NewState == ENABLE)
269
  {
265
  {
270
    if(SSP_DMATransfert == SSP_DMA_Transmit)
266
    if(SSP_DMATransfert == SSP_DMA_Transmit)
271
    {
267
    {
272
      /* Enable DMA for the transmit FIFO */
268
      /* Enable DMA for the transmit FIFO */
273
      SSPx->DMACR |= SSP_DMA_TransmitEnable;
269
      SSPx->DMACR |= SSP_DMA_TransmitEnable;
274
    }
270
    }
275
    else
271
    else
276
    {
272
    {
277
      /* Enable DMA for the receive FIFO */
273
      /* Enable DMA for the receive FIFO */
278
      SSPx->DMACR |= SSP_DMA_ReceiveEnable;
274
      SSPx->DMACR |= SSP_DMA_ReceiveEnable;
279
    }
275
    }
280
  }
276
  }
281
  else
277
  else
282
  {
278
  {
283
    if(SSP_DMATransfert == SSP_DMA_Transmit)
279
    if(SSP_DMATransfert == SSP_DMA_Transmit)
284
    {
280
    {
285
      /* Disable DMA for the transmit FIFO */
281
      /* Disable DMA for the transmit FIFO */
286
      SSPx->DMACR &= SSP_DMA_TransmitDisable;
282
      SSPx->DMACR &= SSP_DMA_TransmitDisable;
287
    }
283
    }
288
    else
284
    else
289
    {
285
    {
290
      /* Disable DMA for the receive FIFO */
286
      /* Disable DMA for the receive FIFO */
291
      SSPx->DMACR &= SSP_DMA_ReceiveDisable;
287
      SSPx->DMACR &= SSP_DMA_ReceiveDisable;
292
    }
288
    }
293
  }
289
  }
294
}
290
}
295
 
291
 
296
/*******************************************************************************
292
/*******************************************************************************
297
* Function Name  : SSP_SendData.
293
* Function Name  : SSP_SendData.
298
* Description    : Transmits a Data through the SSP peripheral.
294
* Description    : Transmits a Data through the SSP peripheral.
299
* Input          : - SSPx: where x can be 0 or 1 to select the SSP peripheral.
295
* Input          : - SSPx: where x can be 0 or 1 to select the SSP peripheral.
300
*                  - Data : Data to be transmitted.
296
*                  - Data : Data to be transmitted.
301
* Output         : None
297
* Output         : None
302
* Return         : None
298
* Return         : None
303
*******************************************************************************/
299
*******************************************************************************/
304
void SSP_SendData(SSP_TypeDef* SSPx, u16 Data)
300
void SSP_SendData(SSP_TypeDef* SSPx, u16 Data)
305
{
301
{
306
  /* Write in the DR register the data to be sent */
302
  /* Write in the DR register the data to be sent */
307
  SSPx->DR = Data;
303
  SSPx->DR = Data;
308
}
304
}
309
 
305
 
310
/*******************************************************************************
306
/*******************************************************************************
311
* Function Name  : SSP_ReceiveData.
307
* Function Name  : SSP_ReceiveData.
312
* Description    : Returns the most recent received data by the SSP peripheral.
308
* Description    : Returns the most recent received data by the SSP peripheral.
313
* Input          : SSPx: where x can be 0 or 1 to select the SSP peripheral.
309
* Input          : SSPx: where x can be 0 or 1 to select the SSP peripheral.
314
* Output         : None
310
* Output         : None
315
* Return         : The value of the received data.
311
* Return         : The value of the received data.
316
*******************************************************************************/
312
*******************************************************************************/
317
u16 SSP_ReceiveData(SSP_TypeDef* SSPx)
313
u16 SSP_ReceiveData(SSP_TypeDef* SSPx)
318
{
314
{
319
  /* Return the data in the DR register */     
315
  /* Return the data in the DR register */     
320
  return SSPx->DR;
316
  return SSPx->DR;
321
}
317
}
322
 
318
 
323
/*******************************************************************************
319
/*******************************************************************************
324
* Function Name  : SSP_LoopBackConfig
320
* Function Name  : SSP_LoopBackConfig
325
* Description    : Enable or disable the Loop back mode for the selected SSPx peripheral.
321
* Description    : Enable or disable the Loop back mode for the selected SSPx peripheral.
326
* Input          : - SSPx: where x can be 0 or 1 to select the SSP peripheral.
322
* Input          : - SSPx: where x can be 0 or 1 to select the SSP peripheral.
327
*                  - NewState: new state of the Loop Back mode.
323
*                  - NewState: new state of the Loop Back mode.
328
*                    This parameter can be: ENABLE or DISABLE.
324
*                    This parameter can be: ENABLE or DISABLE.
329
* Output         : None
325
* Output         : None
330
* Return         : None.
326
* Return         : None.
331
*******************************************************************************/
327
*******************************************************************************/
332
void SSP_LoopBackConfig(SSP_TypeDef* SSPx, FunctionalState NewState)
328
void SSP_LoopBackConfig(SSP_TypeDef* SSPx, FunctionalState NewState)
333
{
329
{
334
  if(NewState == ENABLE)
330
  if(NewState == ENABLE)
335
  {
331
  {
336
    /* Enable loop back mode */
332
    /* Enable loop back mode */
337
    SSPx->CR1 |= SSP_LoopBackMode_Enable;
333
    SSPx->CR1 |= SSP_LoopBackMode_Enable;
338
  }
334
  }
339
  else
335
  else
340
  {
336
  {
341
    /* Disable loop back mode */
337
    /* Disable loop back mode */
342
    SSPx->CR1 &= SSP_LoopBackMode_Disable;
338
    SSPx->CR1 &= SSP_LoopBackMode_Disable;
343
  }
339
  }
344
}
340
}
345
 
341
 
346
 
342
 
347
 
343
 
348
/*******************************************************************************
344
/*******************************************************************************
349
* Function Name  : SSP_GetFlagStatus
345
* Function Name  : SSP_GetFlagStatus
350
* Description    : Checks whether the specified SSP flag is set or not.
346
* Description    : Checks whether the specified SSP flag is set or not.
351
* Input          : - SSPx: where x can be 0 or 1 to select the SSP peripheral.
347
* Input          : - SSPx: where x can be 0 or 1 to select the SSP peripheral.
352
*                  - SSP_FLAG: flag to check. This parameter can be one of the
348
*                  - SSP_FLAG: flag to check. This parameter can be one of the
353
*                    following values:
349
*                    following values:
354
*                         - SSP_FLAG_Busy: busy flag
350
*                         - SSP_FLAG_Busy: busy flag
355
*                         - SSP_FLAG_RxFifoFull: Receive FIFO full flag
351
*                         - SSP_FLAG_RxFifoFull: Receive FIFO full flag
356
*                         - SSP_FLAG_RxFifoNotEmpty: Receive FIFO not empty flag
352
*                         - SSP_FLAG_RxFifoNotEmpty: Receive FIFO not empty flag
357
*                         - SSP_FLAG_TxFifoNotFull: Transmit FIFO not full flag
353
*                         - SSP_FLAG_TxFifoNotFull: Transmit FIFO not full flag
358
*                         - SSP_FLAG_TxFifoEmpty: Transmit FIFO empty flag
354
*                         - SSP_FLAG_TxFifoEmpty: Transmit FIFO empty flag
359
*                         - SSP_FLAG_TxFifo: Transmit FIFO half empty or less flag
355
*                         - SSP_FLAG_TxFifo: Transmit FIFO half empty or less flag
360
*                         - SSP_FLAG_RxFifo: Receive FIFO half full or less flag
356
*                         - SSP_FLAG_RxFifo: Receive FIFO half full or less flag
361
*                         - SSP_FLAG_RxTimeOut: Receive timeout flag
357
*                         - SSP_FLAG_RxTimeOut: Receive timeout flag
362
*                         - SSP_FLAG_RxOverrun: Receive overrun flag
358
*                         - SSP_FLAG_RxOverrun: Receive overrun flag
363
* Output         : None
359
* Output         : None
364
* Return         : The new state of SSP_Flag (SET or RESET).
360
* Return         : The new state of SSP_Flag (SET or RESET).
365
*******************************************************************************/
361
*******************************************************************************/
366
FlagStatus SSP_GetFlagStatus(SSP_TypeDef* SSPx, u16 SSP_FLAG)
362
FlagStatus SSP_GetFlagStatus(SSP_TypeDef* SSPx, u16 SSP_FLAG)
367
{
363
{
368
    u32 SSPReg = 0, FlagPos = 0;
364
    u32 SSPReg = 0, FlagPos = 0;
369
    u32 StatusReg = 0;
365
    u32 StatusReg = 0;
370
 
366
 
371
  /* Get the SSP register index */
367
  /* Get the SSP register index */
372
  SSPReg = SSP_FLAG >> 5;
368
  SSPReg = SSP_FLAG >> 5;
373
 
369
 
374
  /* Get the flag position */
370
  /* Get the flag position */
375
  FlagPos = SSP_FLAG & SSP_Flag_Mask;
371
  FlagPos = SSP_FLAG & SSP_Flag_Mask;
376
 
372
 
377
  /* Find the register of the flag to check */
373
  /* Find the register of the flag to check */
378
  if(SSPReg == 1)
374
  if(SSPReg == 1)
379
  {
375
  {
380
    /* The flag to check is in SR register */
376
    /* The flag to check is in SR register */
381
    StatusReg = SSPx->SR;      
377
    StatusReg = SSPx->SR;      
382
  }
378
  }
383
  else if (SSPReg == 2)
379
  else if (SSPReg == 2)
384
  {
380
  {
385
    /* The flag to check is in RISR register */
381
    /* The flag to check is in RISR register */
386
    StatusReg = SSPx->RISR;
382
    StatusReg = SSPx->RISR;
387
  }
383
  }
388
 
384
 
389
  /* Check the status of the specified SSP flag */
385
  /* Check the status of the specified SSP flag */
390
  if((StatusReg & (1 << FlagPos)) != RESET)
386
  if((StatusReg & (1 << FlagPos)) != RESET)
391
  {
387
  {
392
    /* Return SET if the SSP flag is set */
388
    /* Return SET if the SSP flag is set */
393
    return SET;
389
    return SET;
394
  }
390
  }
395
  else
391
  else
396
  {
392
  {
397
    /* Return RESET if the SSP flag is reset */
393
    /* Return RESET if the SSP flag is reset */
398
    return RESET;
394
    return RESET;
399
  }
395
  }
400
}
396
}
401
 
397
 
402
/*******************************************************************************
398
/*******************************************************************************
403
* Function Name  : SSP_ClearFlag
399
* Function Name  : SSP_ClearFlag
404
* Description    : Clears the SSPx flags.
400
* Description    : Clears the SSPx flags.
405
* Input          : - SSPx: where x can be 0 or 1 to select the SSP peripheral.
401
* Input          : - SSPx: where x can be 0 or 1 to select the SSP peripheral.
406
*                  - SSP_FLAG: flags to clear. This parameter one of the
402
*                  - SSP_FLAG: flags to clear. This parameter one of the
407
*                    following values:
403
*                    following values:
408
*                         - SSP_FLAG_RxTimeOut: Receive timeout flag
404
*                         - SSP_FLAG_RxTimeOut: Receive timeout flag
409
*                         - SSP_FLAG_RxOverrun: Receive overrun flag
405
*                         - SSP_FLAG_RxOverrun: Receive overrun flag
410
* Output         : None
406
* Output         : None
411
* Return         : None
407
* Return         : None
412
*******************************************************************************/
408
*******************************************************************************/
413
void SSP_ClearFlag(SSP_TypeDef* SSPx, u16 SSP_FLAG)
409
void SSP_ClearFlag(SSP_TypeDef* SSPx, u16 SSP_FLAG)
414
{
410
{
415
    u8 FlagPos = 0;
411
    u8 FlagPos = 0;
416
 
412
 
417
  /* Get the flag position */
413
  /* Get the flag position */
418
  FlagPos = SSP_FLAG & SSP_Flag_Mask;
414
  FlagPos = SSP_FLAG & SSP_Flag_Mask;
419
 
415
 
420
  /* Clear the selected SSP flag */
416
  /* Clear the selected SSP flag */
421
  SSPx->ICR = (1 << FlagPos);
417
  SSPx->ICR = (1 << FlagPos);
422
}
418
}
423
 
419
 
424
/*******************************************************************************
420
/*******************************************************************************
425
* Function Name  : SSP_GetITStatus
421
* Function Name  : SSP_GetITStatus
426
* Description    : Checks whether the specified SSP interrupt flag is set or not.
422
* Description    : Checks whether the specified SSP interrupt flag is set or not.
427
* Input          : - SSPx: where x can be 0 or 1 to select the SSP peripheral.
423
* Input          : - SSPx: where x can be 0 or 1 to select the SSP peripheral.
428
*                  - SSP_IT: interrupt flag to check. This parameter can be one
424
*                  - SSP_IT: interrupt flag to check. This parameter can be one
429
*                    of the following values:
425
*                    of the following values:
430
*                         - SSP_IT_TxFifo: Transmit FIFO half empty or less interrupt
426
*                         - SSP_IT_TxFifo: Transmit FIFO half empty or less interrupt
431
*                         - SSP_IT_RxFifo: Receive FIFO half full or less interrupt
427
*                         - SSP_IT_RxFifo: Receive FIFO half full or less interrupt
432
*                         - SSP_IT_RxTimeOut: Receive timeout interrupt
428
*                         - SSP_IT_RxTimeOut: Receive timeout interrupt
433
*                         - SSP_IT_RxOverrun: Receive overrun interrupt
429
*                         - SSP_IT_RxOverrun: Receive overrun interrupt
434
* Output         : None
430
* Output         : None
435
* Return         : The new state of SSP_IT flag (SET or RESET).
431
* Return         : The new state of SSP_IT flag (SET or RESET).
436
*******************************************************************************/
432
*******************************************************************************/
437
ITStatus SSP_GetITStatus(SSP_TypeDef* SSPx, u16 SSP_IT)
433
ITStatus SSP_GetITStatus(SSP_TypeDef* SSPx, u16 SSP_IT)
438
{
434
{
439
  /* Check the status of the specified interrupt flag */
435
  /* Check the status of the specified interrupt flag */
440
  if((SSPx->MISR & SSP_IT) != RESET)
436
  if((SSPx->MISR & SSP_IT) != RESET)
441
  {
437
  {
442
    /* Return SET if the SSP interrupt flag is set */
438
    /* Return SET if the SSP interrupt flag is set */
443
    return SET;
439
    return SET;
444
  }
440
  }
445
  else
441
  else
446
  {
442
  {
447
    /* Return RESET if SSP interrupt flag is reset */
443
    /* Return RESET if SSP interrupt flag is reset */
448
    return RESET;
444
    return RESET;
449
  }
445
  }
450
}
446
}
451
 
447
 
452
/*******************************************************************************
448
/*******************************************************************************
453
* Function Name  : SSP_ClearITPendingBit
449
* Function Name  : SSP_ClearITPendingBit
454
* Description    : Clears the pending interrupt flags.
450
* Description    : Clears the pending interrupt flags.
455
* Input          : - SSPx: where x can be 0 or 1 to select the SSP peripheral.
451
* Input          : - SSPx: where x can be 0 or 1 to select the SSP peripheral.
456
*                  - SSP_IT: interrupts pending bits to clear. This parameter
452
*                  - SSP_IT: interrupts pending bits to clear. This parameter
457
*                    can be any combination of the following values:
453
*                    can be any combination of the following values:
458
*                         - SSP_IT_RxTimeOut: Receive timeout interrupt
454
*                         - SSP_IT_RxTimeOut: Receive timeout interrupt
459
*                         - SSP_IT_RxOverrun: Receive overrun interrupt
455
*                         - SSP_IT_RxOverrun: Receive overrun interrupt
460
* Output         : None
456
* Output         : None
461
* Return         : None
457
* Return         : None
462
*******************************************************************************/
458
*******************************************************************************/
463
void SSP_ClearITPendingBit(SSP_TypeDef* SSPx, u16 SSP_IT)
459
void SSP_ClearITPendingBit(SSP_TypeDef* SSPx, u16 SSP_IT)
464
{
460
{
465
  /* Clear the selected SSP interrupts pending bits */
461
  /* Clear the selected SSP interrupts pending bits */
466
  SSPx->ICR = SSP_IT;
462
  SSPx->ICR = SSP_IT;
467
}
463
}
468
 
464
 
469
/******************* (C) COPYRIGHT 2006 STMicroelectronics *****END OF FILE****/
465
/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
470
 
466
 
471
 
467