Ejemplo n.º 1
0
bool_t BuzzerInit(void)
{
  TmrConfig_t tmrConfig;
  TmrStatusCtrl_t tmrStatusCtrl;
  TmrComparatorStatusCtrl_t tmrComparatorStatusCtrl;
  /* Enable hw timer 1 */
  TmrEnable(gBeepTimer_c);
  /* Don't stat the timer yet */ 
  if (gTmrErrNoError_c != TmrSetMode(gBeepTimer_c, gTmrNoOperation_c)) /*set timer mode no operation*/
  {
    return FALSE;
  }
  /* Register the callback executed when an interrupt occur */
  if(gTmrErrNoError_c != TmrSetCallbackFunction(gBeepTimer_c, gTmrComp1Event_c, BuzzerTimerCallBack))
  {
    return FALSE;
  }
  tmrStatusCtrl.uintValue = 0x0000;
  tmrStatusCtrl.bitFields.OEN = 1;    //output enable
  if (gTmrErrNoError_c != TmrSetStatusControl(gBeepTimer_c, &tmrStatusCtrl))
  {
    return FALSE;
  }  
  tmrComparatorStatusCtrl.uintValue = 0x0000;
  tmrComparatorStatusCtrl.bitFields.TCF1EN = TRUE; /* Enable Compare 1 interrupt */
  if (gTmrErrNoError_c != TmrSetCompStatusControl(gBeepTimer_c, &tmrComparatorStatusCtrl))
  {
    return FALSE;
  }
  tmrConfig.tmrOutputMode = gTmrToggleOF_c; 
  tmrConfig.tmrCoInit = FALSE;  /*co-chanel counter/timers can not force a re-initialization of this counter/timer*/
  tmrConfig.tmrCntDir = FALSE;  /*count-up*/
  tmrConfig.tmrCntLen = TRUE;  /*count until compare*/
  tmrConfig.tmrCntOnce = FALSE;   /*count repeatedly*/
  tmrConfig.tmrSecondaryCntSrc = gTmrSecondaryCnt0Input_c;    /*secondary count source not needed*/
  tmrConfig.tmrPrimaryCntSrc = gTmrPrimaryClkDiv1_c;    /*primary count source is IP BUS clock divide by 1 prescaler*/
  if (gTmrErrNoError_c != TmrSetConfig(gBeepTimer_c, &tmrConfig))  /*set timer configuration */
  {
    return FALSE;
  }
  /* Config timer to raise interrupts each 0.1 ms */
  SetComp1Val(gBeepTimer_c, mToggleCompareValue_c);
  /* Config timer to start from 0 after compare event */
  SetLoadVal(gBeepTimer_c, 0);
  I2c_Init();
  Gpio_SetPinFunction(gGpioBeepTimer_c, gGpioAlternate1Mode_c); 
  Gpio_SetPinFunction(gGpioPin12_c, gGpioAlternate1Mode_c);
  Gpio_SetPinFunction(gGpioPin13_c, gGpioAlternate1Mode_c);
  return TRUE;
}
Ejemplo n.º 2
0
/* Initialize the timer module. */
void TMR_Init(void)
{
  
  TmrInit();
  TmrEnable(gTmrNumber_d);  /*enable timer*/
  TMR_SetReg(gTmrNumber_d);
  /*Create the timer task */
  mTimerTaskID = TS_CreateTask(gTsTimerTaskPriority_c, TMR_Task);
  /* Count to maximum (0xffff - 2*4ms(in ticks)), to be sure that the currentTimeInTicks 
  will never roll over previousTimeInTicks in the TMR_Task() */
  mMaxToCountDown_c = 0xFFFF - TmrTicksFromMilliseconds(8); 
  /* The TMR_Task()event will not be issued faster than 4ms*/
  mTicksFor4ms = TmrTicksFromMilliseconds(4);
  
}
Ejemplo n.º 3
0
void TMR_Init(void)
{
  TmrInit();  

  TmrDisable( gTmr0_c );
  TmrDisable( gTmr1_c );
  TmrDisable( gTmr3_c );  
  TmrEnable(  gTmr2_c );
  
// TMR2 ==> 62,50 ms; prescaler = 32
  TMR2_CTRL = 0x1A20;  
  TMR2_SCTRL = 0x0000; 
  TMR2_LOAD = 0x0000;  
  TMR2_COMP1 =  46875; 
  TMR2_CSCTRL =0x0040;  
}