OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [ARM7_STR75x_IAR/] [STLibrary/] [src/] [75x_uart.c] - Blame information for rev 867

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 577 jeremybenn
/******************** (C) COPYRIGHT 2006 STMicroelectronics ********************
2
* File Name          : 75x_uart.c
3
* Author             : MCD Application Team
4
* Date First Issued  : 03/10/2006
5
* Description        : This file provides all the UART software functions.
6
********************************************************************************
7
* History:
8
* 07/17/2006 : V1.0
9
* 03/10/2006 : V0.1
10
********************************************************************************
11
* THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
12
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
13
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
14
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
15
* CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
16
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
17
*******************************************************************************/
18
 
19
/* Includes ------------------------------------------------------------------*/
20
#include "75x_uart.h"
21
#include "75x_mrcc.h"
22
 
23
/* Private typedef -----------------------------------------------------------*/
24
/* Private define ------------------------------------------------------------*/
25
/* UART LIN Mask */
26
#define UART_LIN_Disable_Mask           0xFEFF /* LIN Disable Mask */
27
#define UART_LIN_Enable_Mask            0x0100 /* LIN Enable Mask */
28
 
29
/* UART Mask */
30
#define UART_Enable_Mask                0x0001 /* UART Enable Mask */
31
#define UART_Disable_Mask               0xFFFE /* UART Disable Mask */
32
 
33
/* UART LoopBack */
34
#define UART_LoopBack_Disable_Mask      0xFF7F/* LoopBack Disable Mask */
35
#define UART_LoopBack_Enable_Mask       0x0080/* LoopBack Enable Mask */
36
 
37
#define UART_WordLength_Mask            0xFF9F  /* UART Word Length Mask */
38
#define UART_Parity_Mask                0xFF79  /* UART Parity Mask */
39
#define UART_HardwareFlowControl_Mask   0x3FFF  /* UART Hardware Flow Control Mask */
40
#define UART_TxRxFIFOLevel_Mask         0xFFC0  /* UART Tx Rx FIFO Level Mask */
41
#define UART_LINBreakLength_Mask        0xE1FF  /* UART LIN Break Length Mask */
42
#define UART_BreakChar_Mask             0x0001  /* UART Break Character send Mask */
43
#define UART_FLAG_Mask                  0x1F    /* UART Flag Mask */
44
#define UART_Mode_Mask                  0xFCFF  /* UART Mode Mask */
45
#define UART_RTSSET_Mask                0xF7FF  /* RTS signal is high */
46
#define UART_RTSRESET_Mask              0x0800  /* RTS signal is low */
47
 
48
/* Private macro -------------------------------------------------------------*/
49
/* Private variables ---------------------------------------------------------*/
50
/* Private function prototypes -----------------------------------------------*/
51
/* Private functions ---------------------------------------------------------*/
52
 
53
/*******************************************************************************
54
* Function Name  : UART_DeInit
55
* Description    : Deinitializes the UARTx peripheral registers to their default
56
*                  reset values.
57
* Input          : UARTx: where x can be 0,1 or 2 to select the UART peripheral.
58
* Output         : None
59
* Return         : None
60
*******************************************************************************/
61
void UART_DeInit(UART_TypeDef* UARTx)
62
{
63
  /* Reset the UARTx registers values */
64
  if(UARTx == UART0)
65
  {
66
    MRCC_PeripheralSWResetConfig(MRCC_Peripheral_UART0,ENABLE);
67
    MRCC_PeripheralSWResetConfig(MRCC_Peripheral_UART0,DISABLE);
68
  }
69
  else if(UARTx == UART1)
70
  {
71
    MRCC_PeripheralSWResetConfig(MRCC_Peripheral_UART1,ENABLE);
72
    MRCC_PeripheralSWResetConfig(MRCC_Peripheral_UART1,DISABLE);
73
  }
74
  else if(UARTx == UART2)
75
  {
76
    MRCC_PeripheralSWResetConfig(MRCC_Peripheral_UART2,ENABLE);
77
    MRCC_PeripheralSWResetConfig(MRCC_Peripheral_UART2,DISABLE);
78
  }
79
}
80
 
81
/*******************************************************************************
82
* Function Name  : UART_Init
83
* Description    : Initializes the UARTx peripheral according to the specified
84
*                  parameters in the UART_InitStruct .
85
* Input          : - UARTx: where x can be 0,1or 2 to select the UART peripheral.
86
*                  - UART_InitStruct: pointer to a UART_InitTypeDef structure
87
*                    that contains the configuration information for the
88
*                    specified UART peripheral.
89
* Output         : None
90
* Return         : None
91
*******************************************************************************/
92
void UART_Init(UART_TypeDef* UARTx, UART_InitTypeDef* UART_InitStruct)
93
{
94
 
95
  u32 APBClock = 0;
96
  u32 IntegerDivider = 0;
97
  u32 FractionalDivider = 0;
98
  MRCC_ClocksTypeDef  MRCC_ClocksStatus;
99
 
100
  /* Clear the WLEN bits */
101
  UARTx->LCR &= UART_WordLength_Mask;
102
  /* Set the WLEN bits according to UART_WordLength value */
103
  UARTx->LCR |= UART_InitStruct->UART_WordLength;
104
 
105
  /* Choose Stop Bits */
106
  if(UART_InitStruct->UART_StopBits == UART_StopBits_1)
107
  {
108
    /* One Stop Bit */
109
    UARTx->LCR &= UART_StopBits_1;
110
  }
111
  else
112
  {
113
    /* Two Stop Bits */
114
    UARTx->LCR |= UART_StopBits_2;
115
  }
116
 
117
  /* Clear SPS, EPS and PEN bits */
118
  UARTx->LCR &= UART_Parity_Mask;
119
  /* Set PS, EPS and PEN bits according to UART_Parity value */
120
  UARTx->LCR |= UART_InitStruct->UART_Parity;
121
 
122
  /* Configure the BaudRate --------------------------------------------------*/
123
  /* Get the APB frequency */
124
  MRCC_GetClocksStatus(&MRCC_ClocksStatus);
125
  APBClock = MRCC_ClocksStatus.PCLK_Frequency;
126
 
127
  /* Determine the integer part */
128
  IntegerDivider = ((100) * (APBClock) / (16 * (UART_InitStruct->UART_BaudRate)));
129
  UARTx->IBRD = IntegerDivider / 100;
130
 
131
  /* Determine the fractional part */
132
  FractionalDivider = IntegerDivider - (100 * (UARTx->IBRD));
133
  UARTx->FBRD = ((((FractionalDivider * 64) + 50) / 100));
134
 
135
  /* Choose the Hardware Flow Control */
136
  /* Clear RTSEn and CTSEn bits */
137
  UARTx->CR &=  UART_HardwareFlowControl_Mask;
138
  /* Set RTSEn and CTSEn bits according to UART_HardwareFlowControl value */
139
  UARTx->CR |= UART_InitStruct->UART_HardwareFlowControl;
140
 
141
  /* Configure the UART mode */
142
  /* Clear TXE and RXE bits */
143
  UARTx->CR &= UART_Mode_Mask;
144
  /* Set TXE and RXE bits according to UART_Mode value */
145
  UARTx->CR |= UART_InitStruct->UART_Mode;
146
 
147
  /* Enable or disable the FIFOs */
148
  /* Set the FIFOs Levels */
149
  if(UART_InitStruct->UART_FIFO == UART_FIFO_Enable)
150
  {
151
    /* Enable the FIFOs */
152
    UARTx->LCR |= UART_FIFO_Enable;
153
 
154
    /* Clear TXIFLSEL and RXIFLSEL bits */
155
    UARTx->IFLS &=  UART_TxRxFIFOLevel_Mask;
156
 
157
    /* Set RXIFLSEL bits according to UART_RxFIFOLevel value */
158
    UARTx->IFLS |= (UART_InitStruct->UART_RxFIFOLevel << 3);
159
 
160
    /* Set TXIFLSEL bits according to UART_TxFIFOLevel value */
161
    UARTx->IFLS |= UART_InitStruct->UART_TxFIFOLevel;
162
  }
163
  else
164
  {
165
    /* Disable the FIFOs */
166
    UARTx->LCR &= UART_FIFO_Disable;
167
  }
168
}
169
 
170
/*******************************************************************************
171
* Function Name  : UART_StructInit
172
* Description    : Fills each UART_InitStruct member with its default value.
173
* Input          : UART_InitStruct: pointer to a UART_InitTypeDef structure which
174
*                  will be initialized.
175
* Output         : None
176
* Return         : None
177
*******************************************************************************/
178
void UART_StructInit(UART_InitTypeDef* UART_InitStruct)
179
{
180
  /* UART_InitStruct members default value */
181
  UART_InitStruct->UART_WordLength = UART_WordLength_8D;
182
  UART_InitStruct->UART_StopBits = UART_StopBits_1;
183
  UART_InitStruct->UART_Parity = UART_Parity_Odd ;
184
  UART_InitStruct->UART_BaudRate = 9600;
185
  UART_InitStruct->UART_HardwareFlowControl = UART_HardwareFlowControl_None;
186
  UART_InitStruct->UART_Mode = UART_Mode_Tx_Rx;
187
  UART_InitStruct->UART_FIFO = UART_FIFO_Enable;
188
  UART_InitStruct->UART_TxFIFOLevel = UART_FIFOLevel_1_2;
189
  UART_InitStruct->UART_RxFIFOLevel = UART_FIFOLevel_1_2;
190
}
191
 
192
/*******************************************************************************
193
* Function Name  : UART_Cmd
194
* Description    : Enables or disables the specified UART peripheral.
195
* Input          : - UARTx: where x can be 0,1 or 2 to select the UART peripheral
196
*                  - NewState: new state of the UARTx peripheral.
197
*                    This parameter can be: ENABLE or DISABLE.
198
* Output         : None
199
* Return         : None
200
*******************************************************************************/
201
void UART_Cmd(UART_TypeDef* UARTx, FunctionalState NewState)
202
{
203
  if (NewState == ENABLE)
204
  {
205
    /* Enable the selected UART by setting the UARTEN bit in the CR register */
206
    UARTx->CR |= UART_Enable_Mask;
207
  }
208
  else
209
  {
210
    /* Disable the selected UART by clearing the UARTEN bit in the CR register */
211
    UARTx->CR &= UART_Disable_Mask;
212
  }
213
}
214
 
215
/*******************************************************************************
216
* Function Name  : UART_ITConfig
217
* Description    : Enables or disables the specified UART interrupts.
218
* Input          : - UARTx: where x can be 0,1 or 2 to select the UART peripheral
219
*                  - UART_IT: specifies the UART interrupts sources to be
220
*                    enabled or disabled. This parameter can be any combination
221
*                    of the following values:
222
*                       - UART_IT_OverrunError: Overrun Error interrupt
223
*                       - UART_IT_BreakError: Break Error interrupt
224
*                       - UART_IT_ParityError: Parity Error interrupt
225
*                       - UART_IT_FrameError: Frame Error interrupt
226
*                       - UART_IT_ReceiveTimeOut: Receive Time Out interrupt
227
*                       - UART_IT_Transmit: Transmit interrupt
228
*                       - UART_IT_Receive: Receive interrupt
229
*                       - UART_IT_CTS: CTS interrupt
230
*                  - NewState: new state of the UARTx peripheral.
231
*                  This parameter can be: ENABLE or DISABLE.
232
* Output         : None
233
* Return         : None
234
*******************************************************************************/
235
void UART_ITConfig(UART_TypeDef* UARTx, u16 UART_IT, FunctionalState NewState)
236
{
237
  if(NewState == ENABLE)
238
  {
239
    /* Enables the selected interrupts */
240
    UARTx->IMSC |= UART_IT;
241
  }
242
  else
243
  {
244
    /* Disables the selected interrupts */
245
    UARTx->IMSC &= ~UART_IT;
246
  }
247
}
248
 
249
/*******************************************************************************
250
* Function Name  : UART_DMAConfig
251
* Description    : Configures the UART0 DMA interface.
252
* Input          : - UART0_DMAtransfer : specifies the configuration of DMA request.
253
*                    This parameter can be:
254
*                         - UART0_DMATransfer_Single: Single DMA transfer
255
*                         - UART0_DMATransfer_Burst: Burst DMA transfer
256
*                  - UART0_DMAOnError: specifies the DMA on error request.
257
*                    This parameter can be:
258
*                         - UART0_DMAOnError_Enable: DMA receive request enabled
259
*                           when the UART error interrupt is asserted.
260
*                         - UART0_DMAOnError_Disable: DMA receive request disabled
261
*                           when the UART error interrupt is asserted.
262
* Output         : None
263
* Return         : None
264
*******************************************************************************/
265
void UART_DMAConfig(u16 UART0_DMATransfer, u16 UART0_DMAOnError)
266
{
267
  if(UART0_DMATransfer == UART0_DMATransfer_Single)
268
  {
269
    /* Configure the DMA request from the UART0 as single transfer */
270
    UART0->DMACR &= UART0_DMATransfer_Single;
271
  }
272
  else
273
  {
274
    UART0->DMACR |= UART0_DMATransfer_Burst;
275
  }
276
 
277
  if(UART0_DMAOnError == UART0_DMAOnError_Enable)
278
  {
279
    UART0->DMACR &= UART0_DMAOnError_Enable;
280
  }
281
  else
282
  {
283
    UART0->DMACR |= UART0_DMAOnError_Disable;
284
  }
285
}
286
 
287
/*******************************************************************************
288
* Function Name  : UART_DMACmd
289
* Description    : Enables or disables the UART0’s DMA interface.
290
* Input          : - UART0_DMAReq: specifies the DMA request.
291
*                    This parameter can be:
292
*                     - UART0_DMAReq_Tx: Transmit DMA request
293
*                     - UART0_DMAReq_Rx: Receive DMA request
294
*                  - NewState: new state of the UART0’s DMA request.
295
*                    This parameter can be: ENABLE or DISABLE.
296
* Output         : None
297
* Return         : None
298
*******************************************************************************/
299
void UART_DMACmd(u16 UART0_DMAReq, FunctionalState NewState)
300
{
301
  if(UART0_DMAReq == UART0_DMAReq_Tx)
302
  {
303
    if(NewState == ENABLE)
304
    {
305
      UART0->DMACR |=  UART0_DMAReq_Tx;
306
    }
307
    else
308
    {
309
      UART0->DMACR &= ~UART0_DMAReq_Tx;
310
    }
311
  }
312
  else
313
  {
314
    if(NewState == ENABLE)
315
    {
316
      UART0->DMACR |=  UART0_DMAReq_Rx;
317
    }
318
    else
319
    {
320
      UART0->DMACR &= ~UART0_DMAReq_Rx;
321
    }
322
  }
323
}
324
 
325
/*******************************************************************************
326
* Function Name  : UART_LoopBackConfig
327
* Description    : Enables or disables LoopBack mode in UARTx.
328
* Input          : - UARTx: where x can be 0,1 or 2 to select the UART peripheral
329
*                  - NewState: new state of the UARTx’s LoopBack mode.
330
*                    This parameter can be: ENABLE or DISABLE.
331
* Output         : None
332
* Return         : None
333
*******************************************************************************/
334
void UART_LoopBackConfig(UART_TypeDef* UARTx, FunctionalState NewState)
335
{
336
  if (NewState == ENABLE)
337
  {
338
    /* Enable the LoopBack mode of the specified UART */
339
    UARTx->CR |= UART_LoopBack_Enable_Mask;
340
  }
341
  else
342
  {
343
    /* Disable the LoopBack mode of the specified UART */
344
    UARTx->CR &= UART_LoopBack_Disable_Mask;
345
  }
346
}
347
 
348
/*******************************************************************************
349
* Function Name  : UART_LINConfig
350
* Description    : Sets the LIN break length.
351
* Input          : - UARTx: where x can be 0,1 or 2 to select the UART peripheral.
352
*                  - UART_LINBreakLength: Break length value.
353
*                    This parameter can be:
354
*                         - UART_LINBreakLength_10: 10 low bits
355
*                         - UART_LINBreakLength_11: 11 low bits
356
*                         - UART_LINBreakLength_12: 12 low bits
357
*                         - UART_LINBreakLength_13: 13 low bits
358
*                         - UART_LINBreakLength_14: 14 low bits
359
*                         - UART_LINBreakLength_15: 15 low bits
360
*                         - UART_LINBreakLength_16: 16 low bits
361
*                         - UART_LINBreakLength_17: 17 low bits
362
*                         - UART_LINBreakLength_18: 18 low bits
363
*                         - UART_LINBreakLength_19: 19 low bits
364
*                         - UART_LINBreakLength_20: 20 low bits
365
* Output         : None
366
* Return         : None
367
*******************************************************************************/
368
void UART_LINConfig(UART_TypeDef* UARTx, u16 UART_LINBreakLength)
369
{
370
  /* Clear LBKLEN bits */
371
  UARTx->LCR &= UART_LINBreakLength_Mask;
372
 
373
  /* Set LBKLEN bits according to UART_LINBreakLength value */
374
  UARTx->LCR |= UART_LINBreakLength;
375
}
376
 
377
/*******************************************************************************
378
* Function Name  : UART_LINCmd
379
* Description    : Enables or disables LIN master mode in UARTx.
380
* Input          : - UARTx: where x can be 0,1 or 2 to select the UART peripheral
381
*                  - NewState: new state of the UARTx’s LIN interface.
382
*                    This parameter can be: ENABLE or DISABLE.
383
* Output         : None
384
* Return         : None
385
*******************************************************************************/
386
void UART_LINCmd(UART_TypeDef* UARTx, FunctionalState NewState)
387
{
388
  if(NewState == ENABLE)
389
  {
390
    /* Enable the LIN mode of the specified UART */
391
    UARTx->LCR |= UART_LIN_Enable_Mask;
392
  }
393
  else
394
  {
395
    /* Disable the LIN mode of the specified UART */
396
    UARTx->LCR &= UART_LIN_Disable_Mask;
397
  }
398
}
399
 
400
/*******************************************************************************
401
* Function Name  : UART_SendData
402
* Description    : Transmits a signle Byte of data through the UARTx peripheral.
403
* Input          : - UARTx: where x can be 0,1 or 2 to select the UART peripheral.
404
*                  - Data: the byte to transmit
405
* Output         : None
406
* Return         : None
407
*******************************************************************************/
408
void UART_SendData(UART_TypeDef* UARTx, u8 Data)
409
{
410
  /* Transmit one byte */
411
  UARTx->DR = Data;
412
}
413
 
414
/*******************************************************************************
415
* Function Name  : UART_ReceiveData
416
* Description    : Returns the most recent received Byte by the UARTx peripheral.
417
* Input          : UARTx: where x can be 0,1 or 2 to select the UART peripheral.
418
* Output         : None
419
* Return         : The received data
420
*******************************************************************************/
421
u8 UART_ReceiveData(UART_TypeDef* UARTx)
422
{
423
  /* Receive one byte */
424
  return ((u8)UARTx->DR);
425
}
426
 
427
/*******************************************************************************
428
* Function Name  : UART_SendBreak
429
* Description    : Transmits break characters.
430
* Input          : UARTx: where x can be 0,1 or 2 to select the UART peripheral.
431
* Output         : None
432
* Return         : None
433
*******************************************************************************/
434
void UART_SendBreak(UART_TypeDef* UARTx)
435
{
436
  /* Send break characters */
437
  UARTx->BKR |= UART_BreakChar_Mask;
438
}
439
 
440
/*******************************************************************************
441
* Function Name  : UART_RTSConfig
442
* Description    : Sets or Resets the RTS signal
443
* Input          : - UARTx: where x can be 0,1 or 2 to select the UART peripheral.
444
*                  - RTSState: new state of the RTS signal.
445
*                    This parameter can be: RTSSET or RTSRESET
446
* Output         : None
447
* Return         : None
448
*******************************************************************************/
449
void UART_RTSConfig(UART_TypeDef* UARTx, UART_RTSTypeDef RTSState)
450
{
451
  if(RTSState == RTSRESET)
452
  {
453
    UARTx->CR |= UART_RTSRESET_Mask;
454
  }
455
  else if(RTSState == RTSSET)
456
  {
457
    UARTx->CR &= UART_RTSSET_Mask;
458
  }
459
}
460
 
461
/*******************************************************************************
462
* Function Name  : UART_GetFlagStatus
463
* Description    : Checks whether the specified UART flag is set or not.
464
* Input          : - UARTx: where x can be 0,1 or 2 to select the UART peripheral
465
*                  - UART_FLAG: specifies the flag to check.
466
*                    This parameter can be one of the following values:
467
*                     - UART_FLAG_OverrunError: Overrun error flag
468
*                     - UART_FLAG_Break: break error flag
469
*                     - UART_FLAG_ParityError: parity error flag
470
*                     - UART_FLAG_FrameError: frame error flag
471
*                     - UART_FLAG_TxFIFOEmpty: Transmit FIFO Empty flag
472
*                     - UART_FLAG_RxFIFOFull: Receive FIFO Full flag
473
*                     - UART_FLAG_TxFIFOFull: Transmit FIFO Full flag
474
*                     - UART_FLAG_RxFIFOEmpty: Receive FIFO Empty flag
475
*                     - UART_FLAG_Busy: Busy flag
476
*                     - UART_FLAG_CTS: CTS flag
477
*                     - UART_RawIT_OverrunError: Overrun Error interrupt flag
478
*                     - UART_RawIT_BreakError: Break Error interrupt flag
479
*                     - UART_RawIT_ParityError: Parity Error interrupt flag
480
*                     - UART_RawIT_FrameError: Frame Error interrupt flag
481
*                     - UART_RawIT_ReceiveTimeOut: ReceiveTimeOut interrupt flag
482
*                     - UART_RawIT_Transmit: Transmit interrupt flag
483
*                     - UART_RawIT_Receive: Receive interrupt flag
484
*                     - UART_RawIT_CTS: CTS interrupt flag
485
* Output         : None
486
* Return         : The new state of UART_FLAG (SET or RESET).
487
*******************************************************************************/
488
FlagStatus UART_GetFlagStatus(UART_TypeDef* UARTx, u16 UART_FLAG)
489
{
490
  u32 UARTReg = 0, FlagPos = 0;
491
  u32 StatusReg = 0;
492
 
493
  /* Get the UART register index */
494
  UARTReg = UART_FLAG >> 5;
495
 
496
  /* Get the flag position */
497
  FlagPos = UART_FLAG & UART_FLAG_Mask;
498
 
499
  if(UARTReg == 1) /* The flag to check is in RSR register */
500
  {
501
    StatusReg = UARTx->RSR;
502
  }
503
  else if (UARTReg == 2) /* The flag to check is in FR register */
504
  {
505
    StatusReg = UARTx->FR;
506
  }
507
  else if(UARTReg == 3) /* The flag to check is in RIS register */
508
  {
509
    StatusReg = UARTx->RIS;
510
  }
511
 
512
  if((StatusReg & (1 << FlagPos))!= RESET)
513
  {
514
    return SET;
515
  }
516
  else
517
  {
518
    return RESET;
519
  }
520
}
521
 
522
/*******************************************************************************
523
* Function Name  : UART_ClearFlag
524
* Description    : Clears the UARTx’s pending flags.
525
* Input          : - UARTx: where x can be 0,1or 2 to select the UART peripheral.
526
*                  - UART_FLAG: specifies the flag to clear.
527
*                    This parameter can be one of the following values:
528
*                       - UART_FLAG_OverrunError: Overrun error flag
529
*                       - UART_FLAG_Break: break error flag
530
*                       - UART_FLAG_ParityError: parity error flag
531
*                       - UART_FLAG_FrameError: frame error flag
532
* Output         : None
533
* Return         : None
534
*******************************************************************************/
535
void UART_ClearFlag(UART_TypeDef* UARTx, u16 UART_FLAG)
536
{
537
  u8 FlagPos = 0;
538
 
539
  /* Get the flag position */
540
  FlagPos = UART_FLAG & UART_FLAG_Mask;
541
 
542
  /* Clear the sepecified flag */
543
  UARTx->RSR &= ~(1 << FlagPos);
544
}
545
 
546
/*******************************************************************************
547
* Function Name  : UART_GetITStatus
548
* Description    : Checks whether the specified UART interrupt has occurred or not.
549
* Input          : - UARTx: where x can be 0,1or 2 to select the UART peripheral.
550
*                  - UART_IT: specifies the interrupt source to check.
551
*                    This parameter can be one of the following values:
552
*                       - UART_IT_OverrunError: Overrun Error interrupt
553
*                       - UART_IT_BreakError: Break Error interrupt
554
*                       - UART_IT_ParityError: Parity Error interrupt
555
*                       - UART_IT_FrameError: Frame Error interrupt
556
*                       - UART_IT_ReceiveTimeOut: Receive Time Out interrupt
557
*                       - UART_IT_Transmit: Transmit interrupt
558
*                       - UART_IT_Receive: Receive interrupt
559
*                       - UART_IT_CTS: CTS interrupt
560
* Output         : None
561
* Return         : The new state of UART_IT (SET or RESET).
562
*******************************************************************************/
563
ITStatus UART_GetITStatus(UART_TypeDef* UARTx, u16 UART_IT)
564
{
565
  if((UARTx->MIS & UART_IT) != RESET)
566
  {
567
    return SET;
568
  }
569
  else
570
  {
571
    return RESET;
572
  }
573
}
574
 
575
/*******************************************************************************
576
* Function Name  : UART_ClearITPendingBit
577
* Description    : Clears the UARTx’s interrupt pending bits.
578
* Input          : - UARTx: where x can be 0,1or 2 to select the UART peripheral.
579
*                  - UART_IT: specifies the interrupt pending bit to clear.
580
*                    More than one interrupt can be cleared using the “|” operator.
581
*                    This parameter can be:
582
*                       - UART_IT_OverrunError: Overrun Error interrupt
583
*                       - UART_IT_BreakError: Break Error interrupt
584
*                       - UART_IT_ParityError: Parity Error interrupt
585
*                       - UART_IT_FrameError: Frame Error interrupt
586
*                       - UART_IT_ReceiveTimeOut: Receive Time Out interrupt
587
*                       - UART_IT_Transmit: Transmit interrupt
588
*                       - UART_IT_Receive: Receive interrupt
589
*                       - UART_IT_CTS: CTS interrupt
590
* Output         : None
591
* Return         : None
592
*******************************************************************************/
593
void UART_ClearITPendingBit(UART_TypeDef* UARTx, u16 UART_IT)
594
{
595
  /* Clear the specified interrupt */
596
  UARTx->ICR = UART_IT;
597
}
598
 
599
/******************* (C) COPYRIGHT 2006 STMicroelectronics *****END OF FILE****/

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.