Пример #1
0
/******************************************************************************
* Set_Pins
*
* Set a PIN with Direction Out, this PIN can be used as a LED.
*******************************************************************************/
void Set_Pins( LED_t LEDNr )
{
  if (LEDNr & LED1){
    Gpio_SetPinFunction(LED1_PIN, gGpioNormalMode_c);
    Gpio_SetPinReadSource(LED1_PIN, gGpioPinReadReg_c);
    Gpio_SetPinDir(LED1_PIN, gGpioDirOut_c);
    Gpio_SetPinData(LED1_PIN, LED_RESET);
  }
  if (LEDNr & LED2){
    Gpio_SetPinFunction(LED2_PIN, gGpioNormalMode_c);
    Gpio_SetPinReadSource(LED2_PIN, gGpioPinReadReg_c);
    Gpio_SetPinDir(LED2_PIN, gGpioDirOut_c);
    Gpio_SetPinData(LED2_PIN, LED_RESET);
  }
  if (LEDNr & LED3){
    Gpio_SetPinFunction(LED3_PIN, gGpioNormalMode_c);
    Gpio_SetPinReadSource(LED3_PIN, gGpioPinReadReg_c);
    Gpio_SetPinDir(LED3_PIN, gGpioDirOut_c);
    Gpio_SetPinData(LED3_PIN, LED_RESET);
  }
  if (LEDNr & LED4){
    Gpio_SetPinFunction(LED4_PIN, gGpioNormalMode_c);
    Gpio_SetPinReadSource(LED4_PIN, gGpioPinReadReg_c);
    Gpio_SetPinDir(LED4_PIN, gGpioDirOut_c);
    Gpio_SetPinData(LED4_PIN, LED_RESET);
  }
}
Пример #2
0
////////////////////////////////////////////////////////////////////////////////////////////////////
// Name     I2C_EEPROM_Init
// Author   Dorin Muica
// Brief    Init I2C Module
// Param    none
//          none
// Return   none 
////////////////////////////////////////////////////////////////////////////////////////////////////
void I2C_EEPROM_Init (void)
{
  Gpio_SetPinFunction(GPIO_EEPROM_WP , gGpioNormalMode_c);  
  Gpio_SetPinDir( GPIO_EEPROM_WP, gGpioDirOut_c );
  EEPROM_WRITE_DISABLE();
  
  Gpio_SetPinFunction( gGpioPin12_c, gGpioAlternate1Mode_c ); // Peripheral Control Mode of pin #22 SCL
  Gpio_SetPinFunction( gGpioPin13_c, gGpioAlternate1Mode_c ); // Peripheral Control Mode of pin #21 SDA
  
  I2c_Init();
  I2c_Enable();
  I2c_SetConfig(&stI2cConfig);
}
Пример #3
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;
}
Пример #4
0
/*****************************************************************************
*   IIC_ModuleInit
*
*   Initialize the IIC module
******************************************************************************/
void IIC_ModuleInit()
{  
#if gIIC_Enabled_d     
  /* Configure the pin to be used for signaling the master host that data for read is available.
     Default configuration is 'No Data for Read', meaning GPIO is set to high */ 
  Gpio_EnPinPullup(gTxDataAvailablePin_c, TRUE);
  Gpio_SetPinDir(gTxDataAvailablePin_c, gGpioDirOut_c);
  Gpio_SetPinData(gTxDataAvailablePin_c, gGpioPinStateHigh_c);
       
  mI2cModuleEx.Rxi2cCallback = NULL;
  mI2cModuleEx.Txi2cCallback = NULL;
  
  mI2cModuleEx.i2cStatus = I2C_DEFAULT_STATUS;
  mI2cModuleEx.sendBuff = 0;
  mI2cModuleEx.sentBytesNo = 0;
  mI2cModuleEx.sendBuffLength = 0;
  mI2cModuleEx.recvBuffLength = 0;

  I2C.ClockEn = CLOCK_ENABLE;
  I2C.Address = I2C.Address & ~I2C_ADR_MASK;
  I2C.FreqDiv = I2C.FreqDiv & ~I2C_FDIV_MASK;
  I2C.Control = I2C.Control & ~I2C_CTRL_MASK;
  I2C.Status = 0x00;
  I2C.Data = 0x00;
  I2C.DigitalFilter = I2C.DigitalFilter & ~I2C_DFILT_MASK;
  I2C.ClockEn = I2C.ClockEn & ~I2C_CKER_MASK;
  

  Gpio_SetPinFunction(gGpioPin12_c, gGpioAlternate1Mode_c);
  Gpio_SetPinFunction(gGpioPin13_c, gGpioAlternate1Mode_c);
  
  /* Register our own interrupt handler for the I2C peripheral */  
  IntAssignHandler(gI2cInt_c, (IntHandlerFunc_t)&IIC_IsrEx);
  ITC_SetPriority(gI2cInt_c, gItcFastPriority_c);
  ITC_EnableInterrupt(gI2cInt_c);
  IntEnableFIQ();
  /* Enable I2C module */  
  IIC_EnableEx();
  
  /* Configure I2C hardware peripheral */ 
  IIC_SetSlaveAddress(gI2CDefaultSlaveAddress_c);
  
  /* Prepare the Rx module of the I2C to receive a maximum length packet */    
  IIC_InitQueue(&mI2cModuleEx.recvQueue);  
  IIC_ReceiveDataEx(0x00, &internalRxBuffer[0], gIIC_QueueSz_c - 1, gI2cSlvTransfer_c);   
#endif
}