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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [ARM9_STR91X_IAR/] [Library/] [source/] [91x_tim.c] - Blame information for rev 583

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          : 91x_tim.c
3
* Author             : MCD Application Team
4
* Date First Issued  : 05/18/2006 : Version 1.0
5
* Description        : This file provides all the TIM software 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
********************************************************************************
12
* THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS WITH
13
* CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. AS
14
* A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT
15
* OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT
16
* OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION
17
* CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
18
*******************************************************************************/
19
 
20
/* Includes ------------------------------------------------------------------*/
21
#include "91x_tim.h"
22
 
23
/* Include of other module interface headers ---------------------------------*/
24
/* Local includes ------------------------------------------------------------*/
25
/* Private typedef -----------------------------------------------------------*/
26
/* Private define ------------------------------------------------------------*/
27
 
28
/* TIM Bits Masks */
29
 
30
#define TIM_PWM_MASK          0x0010
31
#define TIM_OPM_MASK          0x0020
32
#define TIM_OC1_ENABLE_MASK   0x0040
33
#define TIM_OC1_DISABLE_MASK  0xFFBF
34
#define TIM_OC2_ENABLE_MASK   0x0080
35
#define TIM_OC2_DISABLE_MASK  0xFF7F
36
 
37
#define TIM_OLVL1_SET_MASK    0x0100
38
#define TIM_OLVL1_RESET_MASK  0xFEFF
39
 
40
#define TIM_OLVL2_SET_MASK    0x0200
41
#define TIM_OLVL2_RESET_MASK  0xFDFF
42
 
43
#define TIM_ENABLE_MASK       0x8000
44
#define TIM_DISABLE_MASK      0x7FFF
45
 
46
#define TIM_DMA_CLEAR_MASK    0xCFFF
47
 
48
/* Private macro -------------------------------------------------------------*/
49
/* Private variables ---------------------------------------------------------*/
50
/* Private function prototypes -----------------------------------------------*/
51
/* Interface functions -------------------------------------------------------*/
52
/* Private functions ---------------------------------------------------------*/
53
/*******************************************************************************
54
* Function Name  : TIM_DeInit
55
* Description    : Initializes TIM peripheral control and registers to their
56
*                : default reset values.
57
* Input          : TIMx: where x can be from 0 to 3 to select the TIM
58
*                  peripheral.
59
* Output         : None
60
* Return         : None
61
*******************************************************************************/
62
void TIM_DeInit(TIM_TypeDef *TIMx)
63
{
64
  if((TIMx == TIM0)||(TIMx == TIM1))
65
  {
66
    SCU_APBPeriphReset(__TIM01, DISABLE);    /* TIM0 & TIM1 Reset's off */
67
  }
68
  else
69
  {
70
    SCU_APBPeriphReset(__TIM23, DISABLE);    /* TIM2 & TIM3 Reset's off */
71
  }
72
 
73
  /* Set all the TIMx registers to thier default values */
74
  TIMx->OC1R = 0x8000;
75
  TIMx->OC2R = 0x8000;
76
  TIMx->CR1  = 0x0;
77
  TIMx->CR2  = 0x1;
78
  TIMx->CNTR = 0x1234;
79
  TIMx->SR   = 0x0;
80
}
81
 
82
/*******************************************************************************
83
* Function Name  : TIM_StructInit
84
* Description    : Fills in a TIM_InitTypeDef structure with the reset value of
85
*                  each parameter.
86
* Input          : TIM_InitStruct : pointer to a TIM_InitTypeDef structure
87
                   which will be initialized.
88
* Output         : None
89
* Return         : None.
90
*******************************************************************************/
91
void TIM_StructInit(TIM_InitTypeDef *TIM_InitStruct)
92
{
93
  TIM_InitStruct->TIM_Mode           = 0x0000;
94
  TIM_InitStruct->TIM_OC1_Modes      = 0x0000;
95
  TIM_InitStruct->TIM_OC2_Modes      = 0x0000;
96
  TIM_InitStruct->TIM_Clock_Source   = 0x0000;
97
  TIM_InitStruct->TIM_Clock_Edge     = 0x0000;
98
  TIM_InitStruct->TIM_OPM_INPUT_Edge = 0x0000;
99
  TIM_InitStruct->TIM_ICAP1_Edge     = 0x0000;
100
  TIM_InitStruct->TIM_ICAP2_Edge     = 0x0000;
101
  TIM_InitStruct->TIM_Prescaler      = 0x0000;
102
  TIM_InitStruct->TIM_Pulse_Level_1  = 0x0000;
103
  TIM_InitStruct->TIM_Pulse_Level_2  = 0x0000;
104
  TIM_InitStruct->TIM_Period_Level   = 0x0000;
105
  TIM_InitStruct->TIM_Pulse_Length_1 = 0x0000;
106
  TIM_InitStruct->TIM_Pulse_Length_2 = 0x0000;
107
  TIM_InitStruct->TIM_Full_Period    = 0x0000;
108
}
109
 
110
/*******************************************************************************
111
* Function Name  : TIM_Init
112
* Description    : Initializes TIM  peripheral according to the specified
113
*                  parameters in the TIM_InitTypeDef structure.
114
* Input1         : TIMx: where x can be from 0 to 3 to select the TIM
115
*                  peripheral.
116
* Input2         : TIM_InitStruct: pointer to a TIM_InitTypeDef structure that
117
*                  contains the configuration information for the specified
118
*                  TIM peripheral.
119
* Output         : None
120
* Return         : None
121
*******************************************************************************/
122
 
123
void TIM_Init(TIM_TypeDef *TIMx, TIM_InitTypeDef *TIM_InitStruct)
124
{
125
/***************************** Clock configuration ****************************/
126
 
127
  if (TIM_InitStruct->TIM_Clock_Source == TIM_CLK_APB)
128
  {
129
    /* APB clock */
130
    TIMx->CR1 &= TIM_CLK_APB;
131
  }
132
  else
133
  {
134
    /* External/SCU clock */
135
    TIMx->CR1 |= TIM_CLK_EXTERNAL;
136
    if (TIM_InitStruct->TIM_Clock_Edge == TIM_CLK_EDGE_RISING)
137
    {
138
      /* Clock rising edge */
139
      TIMx->CR1 |= TIM_CLK_EDGE_RISING;
140
    }
141
    else
142
    {
143
      /* Clock falling edge */
144
      TIMx->CR1 &= TIM_CLK_EDGE_FALLING;
145
    }
146
  }
147
 
148
/************************** Prescaler configuration ***************************/
149
 
150
  TIMx->CR2 =( TIMx->CR2 & 0xFF00 )|TIM_InitStruct->TIM_Prescaler ;
151
 
152
/********************************** TIM Modes *********************************/
153
 
154
  switch ( TIM_InitStruct->TIM_Mode)
155
  {
156
/******************************* PWM Input mode *******************************/
157
 
158
    case TIM_PWMI:
159
 
160
      /* Set the PWMI Bit */
161
      TIMx->CR1 |= TIM_PWMI;
162
 
163
      /* Set the first edge Level */
164
      if ( TIM_InitStruct->TIM_ICAP1_Edge == TIM_ICAP1_EDGE_RISING)
165
      {
166
        TIMx->CR1 |= TIM_ICAP1_EDGE_RISING;
167
      }
168
      else
169
      {
170
        TIMx->CR1 &= TIM_ICAP1_EDGE_FALLING;
171
      }
172
 
173
      /* Set the Second edge Level ( Opposite of the first level ) */
174
      if ( TIM_InitStruct->TIM_ICAP1_Edge == TIM_ICAP1_EDGE_RISING)
175
      {
176
        TIMx->CR1 &= TIM_ICAP2_EDGE_FALLING;
177
      }
178
      else
179
      {
180
        TIMx->CR1 |= TIM_ICAP2_EDGE_RISING;
181
      }
182
 
183
      break;
184
 
185
/************************** Output compare channel 1 **************************/
186
 
187
    case TIM_OCM_CHANNEL_1:
188
 
189
      if (TIM_InitStruct->TIM_Pulse_Level_1 == TIM_HIGH)
190
      {
191
        TIMx->CR1 |= TIM_OLVL1_SET_MASK;
192
      }
193
      else
194
      {
195
        TIMx->CR1 &= TIM_OLVL1_RESET_MASK;
196
      }
197
 
198
      TIMx->OC1R = TIM_InitStruct->TIM_Pulse_Length_1;
199
 
200
      if (TIM_InitStruct->TIM_OC1_Modes == TIM_TIMING)
201
      {
202
        TIMx->CR1 &= TIM_OC1_DISABLE_MASK;
203
      }
204
      else
205
      {
206
        TIMx->CR1 |= TIM_OC1_ENABLE_MASK;
207
      }
208
 
209
      break;
210
 
211
/************************** Output compare channel 2 **************************/
212
 
213
    case TIM_OCM_CHANNEL_2:
214
 
215
      if (TIM_InitStruct->TIM_Pulse_Level_2 == TIM_HIGH)
216
      {
217
        TIMx->CR1 |= TIM_OLVL2_SET_MASK;
218
      }
219
      else
220
      {
221
        TIMx->CR1 &= TIM_OLVL2_RESET_MASK;
222
      }
223
 
224
      TIMx->OC2R = TIM_InitStruct->TIM_Pulse_Length_2;
225
 
226
      if (TIM_InitStruct->TIM_OC2_Modes == TIM_TIMING)
227
      {
228
        TIMx->CR1 &= TIM_OC2_DISABLE_MASK;
229
      }
230
      else
231
      {
232
        TIMx->CR1 |= TIM_OC2_ENABLE_MASK;
233
      }
234
 
235
      break;
236
 
237
/************************ Output compare channel 1 & 2 ************************/
238
 
239
   case TIM_OCM_CHANNEL_12:
240
 
241
    TIMx->OC2R = TIM_InitStruct->TIM_Pulse_Length_2;
242
    TIMx->OC1R = TIM_InitStruct->TIM_Pulse_Length_1;
243
 
244
    if (TIM_InitStruct->TIM_OC2_Modes == TIM_TIMING)
245
    {
246
      TIMx->CR1 &= TIM_OC2_DISABLE_MASK;
247
    }
248
    else
249
    {
250
      TIMx->CR1 |= TIM_OC2_ENABLE_MASK;
251
    }
252
 
253
    if (TIM_InitStruct->TIM_OC1_Modes == TIM_TIMING)
254
    {
255
      TIMx->CR1 &= TIM_OC1_DISABLE_MASK;
256
    }
257
    else
258
    {
259
      TIMx->CR1 |= TIM_OC1_ENABLE_MASK;
260
    }
261
 
262
    if (TIM_InitStruct->TIM_Pulse_Level_1 == TIM_HIGH)
263
    {
264
      TIMx->CR1 |= TIM_OLVL1_SET_MASK;
265
    }
266
    else
267
    {
268
      TIMx->CR1 &= TIM_OLVL1_RESET_MASK;
269
    }
270
 
271
    if (TIM_InitStruct->TIM_Pulse_Level_2 == TIM_HIGH)
272
    {
273
      TIMx->CR1 |= TIM_OLVL2_SET_MASK;
274
    }
275
    else
276
    {
277
      TIMx->CR1 &= TIM_OLVL2_RESET_MASK;
278
    }
279
 
280
    break;
281
 
282
/********************************** PWM mode **********************************/
283
 
284
    case TIM_PWM:
285
 
286
      /* Set the Level During the pulse */
287
      if ( TIM_InitStruct->TIM_Pulse_Level_1 == TIM_HIGH)
288
      {
289
        TIMx->CR1 |= TIM_OLVL2_SET_MASK;
290
      }
291
      else
292
      {
293
        TIMx->CR1 &= TIM_OLVL2_RESET_MASK;
294
      }
295
 
296
      /* Set the Level after the pulse */
297
      if (TIM_InitStruct->TIM_Period_Level == TIM_HIGH)
298
      {
299
        TIMx->CR1 |= TIM_OLVL1_SET_MASK;
300
      }
301
      else
302
      {
303
        TIMx->CR1 &= TIM_OLVL1_RESET_MASK;
304
      }
305
 
306
      /* Set the OCAE */
307
      TIMx->CR1 |= TIM_OC1_ENABLE_MASK;
308
 
309
      /* Set the PWM Bit */
310
      TIMx->CR1 |= TIM_PWM_MASK;
311
 
312
      /* Set the Duty Cycle value */
313
 
314
      TIMx->OC1R = TIM_InitStruct->TIM_Pulse_Length_1 ;
315
 
316
      /* Set the Full Period */
317
 
318
      TIMx->OC2R = TIM_InitStruct->TIM_Full_Period ;
319
 
320
      break;
321
 
322
/******************************* One pulse mode *******************************/
323
 
324
    case TIM_OPM:
325
 
326
      /* Set the Level During the pulse */
327
      if (TIM_InitStruct->TIM_Pulse_Level_1 == TIM_HIGH)
328
      {
329
        TIMx->CR1 |= TIM_OLVL2_SET_MASK;
330
      }
331
 
332
      /* Set the Level after the pulse  */
333
      if (TIM_InitStruct->TIM_Period_Level == TIM_HIGH)
334
      {
335
        TIMx->CR1 |= TIM_OLVL1_SET_MASK;
336
      }
337
 
338
      /* Set the Activation Edge on the ICAP 1 */
339
      if (TIM_InitStruct->TIM_OPM_INPUT_Edge == TIM_OPM_EDGE_RISING)
340
      {
341
        TIMx->CR1 |= TIM_OPM_EDGE_RISING;
342
      }
343
 
344
      /* Set the Output Compare Function  */
345
      TIMx->CR1 |= TIM_OC1_ENABLE_MASK;
346
 
347
      /* Set the One pulse mode */
348
      TIMx->CR1 |= TIM_OPM_MASK;
349
 
350
      /* Set the Pulse length  */
351
      TIMx->OC1R = TIM_InitStruct->TIM_Pulse_Length_1;
352
 
353
      break;
354
 
355
/*************************** Input capture channel 1 **************************/
356
 
357
    case TIM_ICAP_CHANNEL_1:
358
 
359
      if (TIM_InitStruct->TIM_ICAP1_Edge == TIM_ICAP1_EDGE_RISING)
360
      {
361
        TIMx->CR1 |= TIM_ICAP1_EDGE_RISING;
362
      }
363
      else
364
      {
365
        TIMx->CR1 &= TIM_ICAP1_EDGE_FALLING;
366
      }
367
 
368
      break;
369
 
370
/*************************** Input capture channel 2 **************************/
371
 
372
    case TIM_ICAP_CHANNEL_2:
373
 
374
      if (TIM_InitStruct->TIM_ICAP2_Edge == TIM_ICAP2_EDGE_RISING)
375
      {
376
        TIMx->CR1 |= TIM_ICAP2_EDGE_RISING;
377
      }
378
      else
379
      {
380
        TIMx->CR1 &= TIM_ICAP2_EDGE_FALLING;
381
      }
382
 
383
      break;
384
 
385
/************************* Input capture channel 1 & 2 ************************/
386
 
387
    case TIM_ICAP_CHANNEL_12:
388
      if (TIM_InitStruct->TIM_ICAP2_Edge == TIM_ICAP2_EDGE_RISING)
389
      {
390
        TIMx->CR1 |= TIM_ICAP2_EDGE_RISING;
391
      }
392
      else
393
      {
394
        TIMx->CR1 &= TIM_ICAP2_EDGE_FALLING;
395
      }
396
 
397
      if (TIM_InitStruct->TIM_ICAP1_Edge == TIM_ICAP1_EDGE_RISING)
398
      {
399
        TIMx->CR1 |= TIM_ICAP1_EDGE_RISING;
400
      }
401
      else
402
      {
403
        TIMx->CR1 &= TIM_ICAP1_EDGE_FALLING;
404
      }
405
 
406
      break;
407
 
408
    default:
409
      break;
410
  }
411
}
412
 
413
/*******************************************************************************
414
* Function Name  : TIM_CounterCmd
415
* Description    : Enables or disables TIMx Counter peripheral.
416
* Input1         : TIMx: where x can be from 0 to 3 to select the TIM
417
*                  peripheral.
418
* Input2         : TIM_operation: specifies the new state of the TIMx Counter.
419
*                  This parameter can be one of the following values:
420
*                       - TIM_START: Start the timer counter.
421
*                       - TIM_STOP : Stop the timer counter.
422
*                       - TIM_CLEAR: Clear the timer counter.
423
* Output         : None
424
* Return         : None
425
*******************************************************************************/
426
void TIM_CounterCmd(TIM_TypeDef *TIMx, TIM_CounterOperations TIM_operation)
427
{
428
  switch (TIM_operation)
429
  {
430
    case TIM_START:
431
      TIMx->CR1 |= TIM_ENABLE_MASK;
432
      break;
433
 
434
    case TIM_STOP:
435
      TIMx->CR1 &= TIM_DISABLE_MASK;
436
      break;
437
 
438
    case TIM_CLEAR:
439
      TIMx->CNTR = 0x1234;
440
      break;
441
 
442
    default:
443
      break;
444
  }
445
}
446
 
447
/*******************************************************************************
448
* Function Name  : TIM_PrescalerConfig
449
* Description    : This routine is used to configure the TIMx prescaler value
450
*                  (when using the APB clock).
451
* Input1         : TIMx: where x can be from 0 to 3 to select the TIM
452
*                  peripheral.
453
* Input2         : TIM_Prescaler: specifies the prescaler value. This parameter
454
*                  can be a value from 0x0 to 0xFF.
455
* Output         : None
456
* Return         : None
457
*******************************************************************************/
458
void TIM_PrescalerConfig(TIM_TypeDef *TIMx, u8 TIM_Prescaler)
459
{
460
  TIMx->CR2 &= 0xFF00;
461
  TIMx->CR2 |= TIM_Prescaler;
462
 
463
}
464
/*******************************************************************************
465
* Function Name  : TIM_GetPrescalerValue
466
* Description    : This routine is used to get the TIMx prescaler value
467
*                  (when using the APB clock).
468
* Input          : TIMx: where x can be from 0 to 3 to select the TIM
469
*                  peripheral.
470
* Output         : None
471
* Return         : The prescaler value.
472
*******************************************************************************/
473
u8 TIM_GetPrescalerValue(TIM_TypeDef *TIMx)
474
{
475
  return TIMx->CR2 & 0x00FF;
476
}
477
 
478
/*******************************************************************************
479
* Function Name  : TIM_GetCounterValue
480
* Description    : This routine is used to get the TIMx counter value.
481
* Input          : TIMx: where x can be from 0 to 3 to select the TIM
482
*                  peripheral.
483
* Output         : None
484
* Return         : The counter value.
485
*******************************************************************************/
486
u16 TIM_GetCounterValue(TIM_TypeDef *TIMx)
487
{
488
  return TIMx->CNTR;
489
}
490
 
491
/*******************************************************************************
492
* Function Name  : TIM_GetICAP1Value
493
* Description    : This routine is used to get the Input Capture 1 value.
494
* Input          : TIMx: where x can be from 0 to 3 to select the TIM
495
*                  peripheral.
496
* Output         : None
497
* Return         : The Input Capture 1 value.
498
*******************************************************************************/
499
u16 TIM_GetICAP1Value(TIM_TypeDef *TIMx)
500
{
501
  return TIMx->IC1R;
502
}
503
 
504
/*******************************************************************************
505
* Function Name  : TIM_GetICAP2Value
506
* Description    : This routine is used to get the Input Capture 2 value.
507
* Input          : TIMx: where x can be from 0 to 3 to select the TIM
508
*                  peripheral.
509
* Output         : None
510
* Return         : The Input Capture 2 value.
511
*******************************************************************************/
512
u16 TIM_GetICAP2Value(TIM_TypeDef *TIMx)
513
{
514
  return TIMx->IC2R;
515
}
516
 
517
/*******************************************************************************
518
* Function Name  : TIM_SetPulse
519
* Description    : This routine is used to set the pulse value.
520
* Input1         : TIMx: where x can be from 0 to 3 to select the TIM
521
*                  peripheral.
522
* Input2         : TIM_Channel: specifies the needed channel.
523
*                  This parameter can be one of the following values:
524
*                       - TIM_PWM_OC1_Channel: PWM/Output Compare 1 Channel
525
*                       - TIM_OC2_Channel    : Output Compare 2 Channel
526
* Input3         : TIM_Pulse: specifies the new pulse value.
527
* Output         : None
528
* Return         : None
529
*******************************************************************************/
530
void TIM_SetPulse(TIM_TypeDef *TIMx,u16 TIM_Channel ,u16 TIM_Pulse)
531
{
532
  if (TIM_Channel == TIM_PWM_OC1_Channel)
533
  {
534
    TIMx->OC1R = TIM_Pulse;
535
  }
536
  else
537
  {
538
    TIMx->OC2R = TIM_Pulse;
539
  }
540
}
541
/*******************************************************************************
542
* Function Name  : TIM_GetFlagStatus
543
* Description    : Checks whether the specified TIMx flag is set or not.
544
* Input1         : TIMx: where x can be from 0 to 3 to select the TIM
545
*                  peripheral.
546
* Input2         : TIM_Flag: specifies the flag to check.
547
*                  This parameter can be one of the following values:
548
*                       - TIM_FLAG_IC1: Input Capture Channel 1 Flag
549
*                       - TIM_FLAG_IC2: Input Capture Channel 2 Flag
550
*                       - TIM_FLAG_TO : Timer Overflow Flag
551
*                       - TIM_FLAG_OC1: Output Compare Channel 1 Flag
552
*                       - TIM_FLAG_OC2: Output Compare Channel 2 Flag
553
* Output         : None
554
* Return         : The NewState of the TIM_Flag (SET or RESET).
555
*******************************************************************************/
556
FlagStatus TIM_GetFlagStatus(TIM_TypeDef *TIMx, u16 TIM_Flag)
557
{
558
  if((TIMx->SR & TIM_Flag) == RESET)
559
  {
560
    return RESET;
561
  }
562
  else
563
  {
564
    return SET;
565
  }
566
}
567
 
568
/*******************************************************************************
569
* Function Name  : TIM_ClearFlag
570
* Description    : Clears the TIM Flag passed as a parameter.
571
* Input1         : TIMx: where x can be from 0 to 3 to select the TIM
572
*                    peripheral.
573
* Input2         : TIM_Flag: specifies the flag to clear.
574
*                  This parameter can be one of the following values:
575
*                       - TIM_FLAG_IC1: Input Capture Channel 1 Flag
576
*                       - TIM_FLAG_IC2: Input Capture Channel 2 Flag
577
*                       - TIM_FLAG_TO : Timer Overflow Flag
578
*                       - TIM_FLAG_OC1: Output Compare Channel 1 Flag
579
*                       - TIM_FLAG_OC2: Output Compare Channel 2 Flag
580
* Output         : None
581
* Return         : None
582
*******************************************************************************/
583
void TIM_ClearFlag(TIM_TypeDef *TIMx, u16 TIM_Flag)
584
{
585
  /* Clear TIM_Flag */
586
  TIMx->SR &= ~TIM_Flag;
587
}
588
 
589
/*******************************************************************************
590
* Function Name  : TIM_GetPWMIPulse
591
* Description    : This routine is used to get the Pulse value in PWMI Mode.
592
* Input          : TIMx: where x can be from 0 to 3 to select the TIM
593
*                  peripheral.
594
* Output         : None
595
* Return         : The pulse value.
596
*******************************************************************************/
597
u16 TIM_GetPWMIPulse(TIM_TypeDef *TIMx)
598
{
599
  return TIMx->IC2R;
600
}
601
 
602
/*******************************************************************************
603
* Function Name  : TIM_GetPWMIPeriod
604
* Description    : This routine is used to get the Period value in PWMI Mode.
605
* Input          : TIMx: where x can be from 0 to 3 to select the TIM
606
*                  peripheral.
607
* Output         : None
608
* Return         : The period value.
609
*******************************************************************************/
610
u16 TIM_GetPWMIPeriod(TIM_TypeDef *TIMx)
611
{
612
  return TIMx->IC1R;
613
}
614
 
615
/*******************************************************************************
616
* Function Name  : TIM_ITConfig
617
* Description    : Configures the Timer interrupt source.
618
* Input1         : TIMx: where x can be from 0 to 3 to select the TIM
619
*                  peripheral.
620
* Input2         : TIM_IT: specifies the TIM interrupt source to be enabled.
621
*                  This parameter can be one of the following values:
622
*                       - TIM_IT_IC1: Input Capture 1 Interrupt source.
623
*                       - TIM_IT_OC1: Output Compare 1 Interrupt source.
624
*                       - TIM_IT_TO : Timer Overflow Interrupt source.
625
*                       - TIM_IT_IC2: Input Capture 2 Interrupt source.
626
*                       - TIM_IT_OC2: Output Compare 2 Interrupt source.
627
* Input3         : TIM_Newstate: specifies the new state of the  TIMx IT.
628
*                  This parameter can be one of the following values:
629
*                       - ENABLE : Enable the needed interrupt.
630
*                       - DISABLE: Disable the needed interrupt.
631
* Output         : None
632
* Return         : None
633
*******************************************************************************/
634
void TIM_ITConfig(TIM_TypeDef *TIMx, u16 TIM_IT, FunctionalState TIM_Newstate)
635
{
636
  if(TIM_Newstate == ENABLE)
637
  {
638
    TIMx->CR2 = (TIMx->CR2 & 0x00FF) | TIM_IT;
639
  }
640
  else
641
  {
642
    TIMx->CR2 &= ~TIM_IT;
643
  }
644
}
645
 
646
/*******************************************************************************
647
* Function Name  : TIM_DMAConfig
648
* Description    : Configures the Timer DMA source.
649
* Input1         : TIMx: where x can be from 0 to 3 to select the TIM
650
*                  peripheral.
651
* Input2         : TIM_DMA_Souces: specifies the TIM DMA source to be selected.
652
*                  This parameter can be one of the following values:
653
*                       - TIM_DMA_IC1: Input Capture 1 DMA source.
654
*                       - TIM_DMA_OCA1 Output Compare 1 DMA source.
655
*                       - TIM_DMA_TO: Timer Overflow DMA source.
656
*                       - TIM_DMA_IC2: Input Capture 2 DMA source.
657
*                       - TIM_DMA_OC2: Output Compare 2 DMA source.
658
* Output         : None
659
* Return         : None
660
*******************************************************************************/
661
void TIM_DMAConfig(TIM_TypeDef *TIMx, u16 TIM_DMA_Sources)
662
{
663
  /* Reset the DMAS[1:0] bits */
664
  TIMx->CR1 &= TIM_DMA_CLEAR_MASK;
665
  /* Set the DMAS[1:0] bits according to TIM_DMA_Sources parameter */
666
  TIMx->CR1 |= TIM_DMA_Sources;
667
}
668
 
669
/*******************************************************************************
670
* Function Name  : TIM_DMACmd
671
* Description    : Enables or disables TIMx DMA peripheral.
672
* Input1         : TIMx: where x can be from 0 to 3 to select the TIM
673
*                  peripheral.
674
* Input2         : TIM_Newstate: new state of the  TIMx DMA peripheral
675
*                  This parameter can be one of the following values:
676
*                       - ENABLE : Enable the TIMx DMA.
677
*                       - DISABLE: Disable the TIMx DMA.
678
* Output         : None
679
* Return         : None
680
*******************************************************************************/
681
void TIM_DMACmd(TIM_TypeDef *TIMx, FunctionalState TIM_Newstate)
682
{
683
  if (TIM_Newstate == ENABLE)
684
  {
685
    TIMx->CR2 |= TIM_DMA_ENABLE;
686
  }
687
  else
688
  {
689
    TIMx->CR2 &= TIM_DMA_DISABLE;
690
  }
691
}
692
/******************* (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.