📄 stm32f10x_tim.lst
字号:
402 /* Set the default configuration */
403 TIM_OCInitStruct->TIM_OCMode = TIM_OCMode_Timing;
404 TIM_OCInitStruct->TIM_Channel = TIM_Channel_1;
405 TIM_OCInitStruct->TIM_Pulse = TIM_Pulse_Reset_Mask;
406 TIM_OCInitStruct->TIM_OCPolarity = TIM_OCPolarity_High;
407 }
408
409 /*******************************************************************************
410 * Function Name : TIM_ICStructInit
411 * Description : Fills each TIM_InitStruct member with its default value.
412 * Input : - TIM_ICInitStruct: pointer to a TIM_ICInitTypeDef structure
413 * which will be initialized.
414 * Output : None
415 * Return : None
416 *******************************************************************************/
417 void TIM_ICStructInit(TIM_ICInitTypeDef* TIM_ICInitStruct)
418 {
419 /* Set the default configuration */
420 TIM_ICInitStruct->TIM_ICMode = TIM_ICMode_ICAP;
421 TIM_ICInitStruct->TIM_Channel = TIM_Channel_1;
422 TIM_ICInitStruct->TIM_ICPolarity = TIM_ICPolarity_Rising;
423 TIM_ICInitStruct->TIM_ICSelection = TIM_ICSelection_DirectTI;
424 TIM_ICInitStruct->TIM_ICPrescaler = TIM_ICPSC_DIV1;
425 TIM_ICInitStruct->TIM_ICFilter = TIM_ICFilter_Mask;
426 }
427
428 /*******************************************************************************
429 * Function Name : TIM_Cmd
430 * Description : Enables or disables the specified TIM peripheral.
431 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIMx peripheral.
432 * - Newstate: new state of the TIMx peripheral.
433 * This parameter can be: ENABLE or DISABLE.
434 * Output : None
435 * Return : None
436 *******************************************************************************/
437 void TIM_Cmd(TIM_TypeDef* TIMx, FunctionalState NewState)
438 {
439 /* Check the parameters */
440 assert(IS_FUNCTIONAL_STATE(NewState));
441
442 if (NewState != DISABLE)
443 {
444 /* Enable the TIM Counter */
445 TIMx->CR1 |= CR1_CEN_Set;
446 }
447 else
448 {
449 /* Disable the TIM Counter */
450 TIMx->CR1 &= CR1_CEN_Reset;
451 }
452 }
453
454 /*******************************************************************************
455 * Function Name : TIM_ITConfig
456 * Description : Enables or disables the TIMx interrupts.
457 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
458 * - TIM_IT: specifies the TIM interrupts sources to be enabled
459 * or disabled.
460 * This parameter can be any combination of the following values:
461 * - TIM_IT_Update: Timer update Interrupt
462 * - TIM_IT_CC1: Capture Compare 1 Interrupt
463 * - TIM_IT_CC2: Capture Compare 2 Interrupt
464 * - TIM_IT_CC3: Capture Compare 3 Interrupt
465 * - TIM_IT_CC4: Capture Compare 4 Interrupt
466 * - TIM_IT_Trigger: Trigger Interrupt
467 * - Newstate: new state of the specified TIMx interrupts.
468 * This parameter can be: ENABLE or DISABLE.
469 * Output : None
470 * Return : None
471 *******************************************************************************/
472 void TIM_ITConfig(TIM_TypeDef* TIMx, u16 TIM_IT, FunctionalState NewState)
473 {
474 /* Check the parameters */
475 assert(IS_TIM_IT(TIM_IT));
476 assert(IS_FUNCTIONAL_STATE(NewState));
477
478 if (NewState != DISABLE)
479 {
480 /* Enable the Interrupt sources */
481 TIMx->DIER |= TIM_IT;
482 }
483 else
484 {
485 /* Disable the Interrupt sources */
486 TIMx->DIER &= (u16)(~TIM_IT);
487 }
488 }
489
490 /*******************************************************************************
491 * Function Name : TIM_DMAConfig
492 * Description : Configures the TIMx抯 DMA interface.
493 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
494 * - TIM_DMABase: DMA Base address.
495 * This parameter can be one of the following values:
496 * - TIM_DMABase_CR1, TIM_DMABase_CR2, TIM_DMABase_SMCR,
497 * TIM_DMABase_DIER, TIM_DMABase_SR, TIM_DMABase_EGR,
498 * TIM_DMABase_CCMR1, TIM_DMABase_CCMR2, TIM_DMABase_CCER,
499 * TIM_DMABase_CNT, TIM_DMABase_PSC, TIM_DMABase_ARR,
500 * TIM_DMABase_CCR1, TIM_DMABase_CCR2, TIM_DMABase_CCR3,
501 * TIM_DMABase_CCR4, TIM_DMABase_DCR.
502 * - TIM_DMABurstLength: DMA Burst length.
503 * This parameter can be one value between:
504 * TIM_DMABurstLength_1Byte and TIM_DMABurstLength_18Bytes.
505 * Output : None
506 * Return : None
507 *******************************************************************************/
508 void TIM_DMAConfig(TIM_TypeDef* TIMx, u16 TIM_DMABase, u16 TIM_DMABurstLength)
509 {
510 u32 tmpdcr = 0;
511
512 /* Check the parameters */
513 assert(IS_TIM_DMA_BASE(TIM_DMABase));
514 assert(IS_TIM_DMA_LENGTH(TIM_DMABurstLength));
515
516 tmpdcr = TIMx->DCR;
517
518 /* Reset the DBA and the DBL Bits */
519 tmpdcr &= DCR_DMA_Mask;
520
521 /* Set the DMA Base and the DMA Burst Length */
522 tmpdcr |= TIM_DMABase | TIM_DMABurstLength;
523
524 TIMx->DCR = (u16)tmpdcr;
525 }
526
527 /*******************************************************************************
528 * Function Name : TIM_DMACmd
529 * Description : Enables or disables the TIMx抯 DMA Requests.
530 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
531 * - TIM_DMASources: specifies the DMA Request sources.
532 * This parameter can be any combination of the following values:
533 * - TIM_DMA_CC1: Capture Compare 1 DMA source
534 * - TIM_DMA_CC2: Capture Compare 2 DMA source
535 * - TIM_DMA_CC3: Capture Compare 3 DMA source
536 * - TIM_DMA_CC4: Capture Compare 4 DMA source
537 * - TIM_DMA_Trigger: Trigger DMA source
538 * - Newstate: new state of the DMA Request sources.
539 * This parameter can be: ENABLE or DISABLE.
540 * Output : None
541 * Return : None
542 *******************************************************************************/
543 void TIM_DMACmd(TIM_TypeDef* TIMx, u16 TIM_DMASource, FunctionalState Newstate)
544 {
545 u32 tmpdier = 0;
546
547 /* Check the parameters */
548 assert(IS_TIM_DMA_SOURCE(TIM_DMASource));
549 assert(IS_FUNCTIONAL_STATE(Newstate));
550
551 tmpdier = TIMx->DIER;
552
553 if (Newstate != DISABLE)
554 {
555 /* Enable the DMA sources */
556 tmpdier |= TIM_DMASource;
557 }
558 else
559 {
560 /* Disable the DMA sources */
561 tmpdier &= (u16)(~TIM_DMASource);
562 }
563 TIMx->DIER = (u16)tmpdier;
564 }
565
566 /*******************************************************************************
567 * Function Name : TIM_InternalClockConfig
568 * Description : Configures the TIMx interrnal Clock
569 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
570 * Output : None
571 * Return : None
572 *******************************************************************************/
573 void TIM_InternalClockConfig(TIM_TypeDef* TIMx)
574 {
575 /* Disable slave mode to clock the prescaler directly with the internal clock */
576 TIMx->SMCR &= SMCR_SMS_Mask;
577 }
578 /*******************************************************************************
579 * Function Name : TIM_ITRxExternalClockConfig
580 * Description : Configures the TIMx Internal Trigger as External Clock
581 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
582 * - TIM_ITRSource: Trigger source.
583 * This parameter can be one of the following values:
584 * - TIM_TS_ITR0: Internal Trigger 0
585 * - TIM_TS_ITR1: Internal Trigger 1
586 * - TIM_TS_ITR2: Internal Trigger 2
587 * - TIM_TS_ITR3: Internal Trigger 3
588 * Output : None
589 * Return : None
590 *******************************************************************************/
591 void TIM_ITRxExternalClockConfig(TIM_TypeDef* TIMx, u16 TIM_InputTriggerSource)
592 {
593 /* Check the parameters */
594 assert(IS_TIM_INTERNAL_TRIGGER_SELECTION(TIM_InputTriggerSource));
595
596 /* Select the Internal Trigger */
597 TIM_SelectInputTrigger(TIMx, TIM_InputTriggerSource);
598
599 /* Select the External clock mode1 */
600 TIMx->SMCR |= TIM_SlaveMode_External1;
601 }
602 /*******************************************************************************
603 * Function Name : TIM_TIxExternalClockConfig
604 * Description : Configures the TIMx Trigger as External Clock
605 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
606 * - TIM_TIxExternalCLKSource: Trigger source.
607 * This parameter can be one of the following values:
608 * - TIM_TS_TI1F_ED: TI1 Edge Detector
609 * - TIM_TS_TI1FP1: Filtered Timer Input 1
610 * - TIM_TS_TI2FP2: Filtered Timer Input 2
611 * - TIM_ICPolarity: specifies the TIx Polarity.
612 * This parameter can be:
613 * - TIM_ICPolarity_Rising
614 * - TIM_ICPolarity_Falling
615 * - ICFilter : specifies the filter value.
616 * This parameter must be a value between 0x0 and 0xF.
617 * Output : None
618 * Return : None
619 *******************************************************************************/
620 void TIM_TIxExternalClockConfig(TIM_TypeDef* TIMx, u16 TIM_TIxExternalCLKSource,
621 u16 TIM_ICPolarity, u8 ICFilter)
622 {
623 /* Check the parameters */
624 assert(IS_TIM_TIX_TRIGGER_SELECTION(TIM_TIxExternalCLKSource));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -