Subversion Repositories NaviCtrl

Rev

Rev 196 | Details | Compare with Previous | Last modification | View Log | RSS feed

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