コード例 #1
0
/*FUNCTION**********************************************************************
*
* Function Name : TSI_DRV_ChangeMode
* Description   : The function change the current mode.
*
*END**************************************************************************/
tsi_status_t TSI_DRV_ChangeMode(uint32_t instance, const tsi_modes_t mode)
{
    assert(instance < TSI_INSTANCE_COUNT);

    TSI_Type * base = g_tsiBase[instance];
    tsi_state_t * tsiState = g_tsiStatePtr[instance];

    if((mode == tsiState->opMode) || (mode == tsi_OpModeNoChange))
    {
        return  kStatus_TSI_Success;
    }

    if(mode >= tsi_OpModeCnt)
    {
        return kStatus_TSI_InvalidMode;
    }

    /* Critical section. Access to global variable */
    if (kStatus_OSA_Success != OSA_MutexLock(&tsiState->lockChangeMode, OSA_WAIT_FOREVER))
    {
        return kStatus_TSI_Error;
    }

    if (tsiState->status != kStatus_TSI_Initialized)
    {
        /* End of critical section. */
        OSA_MutexUnlock(&tsiState->lockChangeMode);
        
        return tsiState->status;
    }
    
    if(mode == tsi_OpModeNoise)
    {
        if(!tsiState->opModesData[mode].config.mode)
        {
            /* End of critical section. */
            OSA_MutexUnlock(&tsiState->lockChangeMode);

            return kStatus_TSI_InvalidMode;
        }
    }else
    {
        if(tsiState->opModesData[mode].config.mode)
        {
            /* End of critical section. */
            OSA_MutexUnlock(&tsiState->lockChangeMode);

            return kStatus_TSI_InvalidMode;
        }
    }
    
    tsiState->opMode = mode;

    TSI_HAL_SetConfiguration(base, &tsiState->opModesData[mode].config);

    /* End of critical section. */
    OSA_MutexUnlock(&tsiState->lockChangeMode);

    return  kStatus_TSI_Success;
}
/*FUNCTION**********************************************************************
*
* Function Name : TSI_DRV_Measure
* Description   : This function gets (measure) capacitance of enabled electrodes
*               from the TSI module using a non-blocking method.
*
*END**************************************************************************/
tsi_status_t TSI_DRV_Measure(uint32_t instance)
{
    assert(instance < TSI_INSTANCE_COUNT);

    TSI_Type * base = g_tsiBase[instance];
    tsi_state_t * tsiState = g_tsiStatePtr[instance];

    /* Critical section. Access to global variable */
    if (kStatus_OSA_Success != OSA_MutexLock(&tsiState->lock, OSA_WAIT_FOREVER))
    {
        return kStatus_TSI_Error;
    }

    if (tsiState->status != kStatus_TSI_Initialized)
    {
        /* End of critical section. */
        OSA_MutexUnlock(&tsiState->lock);

        return tsiState->status;
    }

    tsiState->status = kStatus_TSI_Busy;

    /* End of critical section. */
    OSA_MutexUnlock(&tsiState->lock);

    TSI_HAL_DisableModule(base);
    TSI_HAL_EnableSoftwareTriggerScan(base);
    TSI_HAL_EnableModule(base);
    TSI_HAL_StartSoftwareTrigger(base);

    return kStatus_TSI_Success;
}
コード例 #3
0
/*FUNCTION**********************************************************************
*
* Function Name : TSI_DRV_SetCallBackFunc
* Description   : Set the TSI call back function pointer for non blocking measurement
*
*
*END**************************************************************************/
tsi_status_t TSI_DRV_SetCallBackFunc(uint32_t instance, const tsi_callback_t pFuncCallBack, void * usrData)
{
    assert(instance < TSI_INSTANCE_COUNT);
    tsi_state_t * tsiState = g_tsiStatePtr[instance];

    /* Critical section. Access to global variable */
    if (kStatus_OSA_Success != OSA_MutexLock(&tsiState->lock, OSA_WAIT_FOREVER))
    {
        return kStatus_TSI_Error;
    }

    if (g_tsiStatePtr[instance]->status != kStatus_TSI_Initialized)
    {
        /* End of critical section. */
        OSA_MutexUnlock(&tsiState->lock);

        return g_tsiStatePtr[instance]->status;
    }

    g_tsiStatePtr[instance]->pCallBackFunc = pFuncCallBack;
    g_tsiStatePtr[instance]->usrData = usrData;

    /* End of critical section. */
    OSA_MutexUnlock(&tsiState->lock);

    return kStatus_TSI_Success;
}
コード例 #4
0
ファイル: fsl_hwtimer_pit.c プロジェクト: 70year/MICO
/*!
 * @cond DOXYGEN_PRIVATE
 *
 * @brief Initialization of pit timer module
 *
 * Called by hwtimer_deinit. Disables the peripheral. Unregisters ISR.
 *
 * @param hwtimer[in] Pointer to hwtimer structure.
 *
 * @return kHwtimerSuccess              Success.
 * @return kHwtimerLockError            When Locking failed.
 * @return kHwtimerRegisterHandlerError When un-registration of the interrupt service routine failed.
 *
 * @see HWTIMER_SYS_PitInit
 * @see HWTIMER_SYS_PitSetDiv
 * @see HWTIMER_SYS_PitStart
 * @see HWTIMER_SYS_PitStop
 * @see HWTIMER_SYS_PitGetTime
 * @see HWTIMER_SYS_PitIsr
 * @see HWTIMER_SYS_PitIsrShared
 */
static _hwtimer_error_code_t HWTIMER_SYS_PitDeinit(hwtimer_t * hwtimer)
{
    /* We belive that if isr is shared ,than is shared for every chanells */
    uint32_t baseAddr = g_pitBaseAddr[0];
    uint32_t pitChannel;
    int i;

    assert(NULL != hwtimer);

    pitChannel = hwtimer->llContext[0U];
    assert(pitChannel < FSL_FEATURE_PIT_TIMER_COUNT);

    /* Remove Hwtimer from global array and disable interrupt on this channel */
    PIT_HAL_StopTimer(baseAddr, pitChannel);
    PIT_HAL_SetIntCmd(baseAddr, pitChannel, false);
    PIT_HAL_ClearIntFlag(baseAddr, pitChannel);

    /* Critical section. Access to global variable */
    if (kStatus_OSA_Success != OSA_MutexLock(g_lock, OSA_WAIT_FOREVER))
    {
        return kHwtimerLockError;
    }
    /* Pit can have shared interrupt vectors. We need un-register interrupt only when all hwtimers are de-inited(set to NULL) */
    g_hwtimersPit[pitChannel] = NULL;

    if (kStatus_OSA_Success != OSA_MutexUnlock(g_lock))
    {
        return kHwtimerLockError;
    }

    /* Check if this is last hwtimer in pit_hwtimers_array */
    for (i = 0U; i < FSL_FEATURE_PIT_TIMER_COUNT; i++)
    {
        if (NULL != g_hwtimersPit[i])
        {
            break;
        }
    }

    if (i == FSL_FEATURE_PIT_TIMER_COUNT)
    {
        if(kStatus_OSA_Success != OSA_InstallIntHandler(kpitIrqIds[pitChannel], NULL))
        {
            return kHwtimerRegisterHandlerError;
        }
    }

    /* Release lock if does not exists*/
    /* Enter critical section to avoid interrupt release locking */
    OSA_EnterCritical(kCriticalDisableInt);
    if (kStatus_OSA_Success != OSA_MutexUnlock(g_lock))
    {
        return kHwtimerLockError;
    }
    g_lock = NULL;
    OSA_ExitCritical(kCriticalDisableInt);


    return kHwtimerSuccess;
}
/*FUNCTION**********************************************************************
*
* Function Name : TSI_DRV_EnableElectrode
* Description   : Enables/Disables the electrode for measuring.
*
*END**************************************************************************/
tsi_status_t TSI_DRV_EnableElectrode(uint32_t instance, const uint32_t channel, const bool enable)
{
    assert(instance < TSI_INSTANCE_COUNT);
    assert(channel < FSL_FEATURE_TSI_CHANNEL_COUNT);

    TSI_Type * base = g_tsiBase[instance];
    tsi_state_t * tsiState = g_tsiStatePtr[instance];

    /* Critical section. Access to global variable */
    if (kStatus_OSA_Success != OSA_MutexLock(&tsiState->lock, OSA_WAIT_FOREVER))
    {
        return kStatus_TSI_Error;
    }

    if (tsiState->status != kStatus_TSI_Initialized)
    {
        /* End of critical section. */
        OSA_MutexUnlock(&tsiState->lock);

        return tsiState->status;
    }

    /* Check the condition for low power mode. */
    if((tsiState->opMode == tsi_OpModeLowPower) || (tsiState->opMode == tsi_OpModeProximity))
    {
      if(tsiState->opModesData[tsi_OpModeLowPower].enabledElectrodes != 0)
      {
          /* Only one elctrode can be enabled in low power mode and proximity. */

          /* Disable al previous enabled. */
          TSI_HAL_DisableChannels(base, 0xffffffff);
      }
    }

    if(enable)
    {
        tsiState->opModesData[tsiState->opMode].enabledElectrodes |= (1U << channel);
        TSI_HAL_EnableChannel(base, channel);
    }
    else
    {
        tsiState->opModesData[tsiState->opMode].enabledElectrodes &= ~(1U << channel);
        TSI_HAL_DisableChannel(base, channel);
    }

    /* End of critical section. */
    OSA_MutexUnlock(&tsiState->lock);

    return kStatus_TSI_Success;
}
コード例 #6
0
/*FUNCTION**********************************************************************
*
* Function Name : TSI_DRV_Measure
* Description   : This function gets (measure) capacitance of enabled electrodes
*               from the TSI module using a non-blocking method.
*
*END**************************************************************************/
tsi_status_t TSI_DRV_Measure(uint32_t instance)
{
    assert(instance < TSI_INSTANCE_COUNT);

    TSI_Type * base = g_tsiBase[instance];
    tsi_state_t * tsiState = g_tsiStatePtr[instance];
    uint32_t    first_pen, pen;
    
    /* Critical section. Access to global variable */
    if (kStatus_OSA_Success != OSA_MutexLock(&tsiState->lock, OSA_WAIT_FOREVER))
    {
        return kStatus_TSI_Error;
    }

    if (tsiState->status != kStatus_TSI_Initialized)
    {
        /* End of critical section. */
        OSA_MutexUnlock(&tsiState->lock);

        return tsiState->status;
    }

    if(!tsiState->opModesData[tsiState->opMode].enabledElectrodes)
    {
        /* End of critical section. */
        OSA_MutexUnlock(&tsiState->lock);

        return kStatus_TSI_InvalidChannel;
    }
    
    tsiState->status = kStatus_TSI_Busy;

    first_pen = 0U;
    pen = tsiState->opModesData[tsiState->opMode].enabledElectrodes;
    while (((pen >> first_pen) & 0x1U) == 0U) {
        first_pen++;
    }
    
    /* End of critical section. */
    OSA_MutexUnlock(&tsiState->lock);

    TSI_HAL_DisableModule(base);
    TSI_HAL_SetMeasuredChannelNumber(base, first_pen);
    TSI_HAL_EnableSoftwareTriggerScan(base);
    TSI_HAL_EnableModule(base);
    TSI_HAL_StartSoftwareTrigger(base);

    return kStatus_TSI_Success;
}
コード例 #7
0
/*FUNCTION**********************************************************************
*
* Function Name : TSI_DRV_LoadConfiguration
* Description   : The function load the configuration for one mode of operation.
*
*END**************************************************************************/
tsi_status_t TSI_DRV_LoadConfiguration(uint32_t instance, const tsi_modes_t mode, const tsi_operation_mode_t * operationMode)
{
    assert(instance < TSI_INSTANCE_COUNT);
    assert(operationMode);
    TSI_Type * base;
    tsi_state_t * tsiState = g_tsiStatePtr[instance];
    
    if(mode >= tsi_OpModeCnt)
    {
        return kStatus_TSI_InvalidMode;
    }

    /* Critical section. Access to global variable */
    if (kStatus_OSA_Success != OSA_MutexLock(&tsiState->lock, OSA_WAIT_FOREVER))
    {
        return kStatus_TSI_Error;
    }

    tsiState->opModesData[mode] = *operationMode;

    /* In case that the loaded configuration is active one, update the HW also. */
    if(mode == tsiState->opMode)
    {
        base = g_tsiBase[instance];

        TSI_HAL_SetConfiguration(base, &tsiState->opModesData[mode].config);
        TSI_HAL_EnableInterrupt(base);
        TSI_HAL_EnableEndOfScanInterrupt(base);
    }

    /* End of critical section. */
    OSA_MutexUnlock(&tsiState->lock);

    return  kStatus_TSI_Success;
}
/*FUNCTION**********************************************************************
*
* Function Name : TSI_DRV_ChangeMode
* Description   : The function change the current mode.
*
*END**************************************************************************/
tsi_status_t TSI_DRV_ChangeMode(uint32_t instance, const tsi_modes_t mode)
{
    assert(instance < TSI_INSTANCE_COUNT);

    TSI_Type * base = g_tsiBase[instance];
    tsi_state_t * tsiState = g_tsiStatePtr[instance];

    if((mode == tsiState->opMode) || (mode == tsi_OpModeNoChange))
    {
        return  kStatus_TSI_Success;
    }

    if(mode >= tsi_OpModeNoise) /* Neither the noise mode is not supported in TSIv1&2 revision. */
    {
        return kStatus_TSI_InvalidMode;
    }

    /* Critical section. Access to global variable */
    if (kStatus_OSA_Success != OSA_MutexLock(&tsiState->lockChangeMode, OSA_WAIT_FOREVER))
    {
        return kStatus_TSI_Error;
    }

    if (tsiState->status != kStatus_TSI_Initialized)
    {
        /* End of critical section. */
        OSA_MutexUnlock(&tsiState->lockChangeMode);
        return tsiState->status;
    }

    tsiState->opMode = mode;

    TSI_HAL_SetConfiguration(base, &tsiState->opModesData[mode].config);

    /* Disable all electrodes */
    TSI_HAL_DisableChannels(base, 0xffff);

    /* Enable the set electrodes for current operation mode */
    TSI_HAL_EnableChannels(base, tsiState->opModesData[mode].enabledElectrodes);

    /* End of critical section. */
    OSA_MutexUnlock(&tsiState->lockChangeMode);

    return  kStatus_TSI_Success;
}
コード例 #9
0
/*FUNCTION**********************************************************************
*
* Function Name : TSI_DRV_EnableElectrode
* Description   : Enables/Disables the electrode for measuring.
*
*END**************************************************************************/
tsi_status_t TSI_DRV_EnableElectrode(uint32_t instance, const uint32_t channel, const bool enable)
{
    assert(instance < TSI_INSTANCE_COUNT);
    assert(channel < FSL_FEATURE_TSI_CHANNEL_COUNT);

    tsi_state_t * tsiState = g_tsiStatePtr[instance];

    /* Critical section. Access to global variable */
    if (kStatus_OSA_Success != OSA_MutexLock(&tsiState->lock, OSA_WAIT_FOREVER))
    {
        return kStatus_TSI_Error;
    }

    if (tsiState->status != kStatus_TSI_Initialized)
    {
        /* End of critical section. */
        OSA_MutexUnlock(&tsiState->lock);

        return tsiState->status;
    }

    /* Check the condition for low power mode. */
    if((tsiState->opMode == tsi_OpModeLowPower) || (tsiState->opMode == tsi_OpModeProximity))
    {
        tsiState->opModesData[tsiState->opMode].enabledElectrodes = 0;
    }

    if(enable)
    {
        tsiState->opModesData[tsiState->opMode].enabledElectrodes |= (1U << channel);
    }
    else
    {
        tsiState->opModesData[tsiState->opMode].enabledElectrodes &= ~(1U << channel);
    }

    /* End of critical section. */
    OSA_MutexUnlock(&tsiState->lock);

    return kStatus_TSI_Success;
}
コード例 #10
0
/*FUNCTION**********************************************************************
*
* Function Name : TSI_DRV_Recalibrate
* Description   : The function force the recalibration process of TSI parameters.
*
*END**************************************************************************/
tsi_status_t TSI_DRV_Recalibrate(uint32_t instance, uint32_t * lowestSignal)
{
    assert(instance < TSI_INSTANCE_COUNT);

    TSI_Type * base = g_tsiBase[instance];
    tsi_state_t * tsiState = g_tsiStatePtr[instance];
    
    /* Critical section. Access to global variable */
    if (kStatus_OSA_Success != OSA_MutexLock(&tsiState->lock, OSA_WAIT_FOREVER))
    {
        return kStatus_TSI_Error;
    }

    if (tsiState->status != kStatus_TSI_Initialized)
    {
        /* End of critical section. */
        OSA_MutexUnlock(&tsiState->lock);
        return tsiState->status;
    }

    tsiState->status = kStatus_TSI_Recalibration;

    *lowestSignal = TSI_HAL_Recalibrate(base, &(tsiState->opModesData[tsiState->opMode].config),
                                       tsiState->opModesData[tsiState->opMode].enabledElectrodes,
                                       g_tsiParamLimits[tsiState->opMode]);

    tsiState->status = kStatus_TSI_Initialized;

    /* End of critical section. */
    OSA_MutexUnlock(&tsiState->lock);

    if(*lowestSignal == 0)
    {
      return kStatus_TSI_Error;
    }
    else
    {
      return kStatus_TSI_Success;
    }
}
コード例 #11
0
/*FUNCTION**********************************************************************
*
* Function Name : TSI_DRV_DisableLowPower
* Description   : Enables/Disables the low power module.
*
*END**************************************************************************/
tsi_status_t TSI_DRV_DisableLowPower(uint32_t instance, const tsi_modes_t mode)
{
    assert(instance < TSI_INSTANCE_COUNT);

    TSI_Type * base = g_tsiBase[instance];
    tsi_state_t * tsiState = g_tsiStatePtr[instance];
    tsi_status_t status;

    /* Critical section. Access to global variable */
    if (kStatus_OSA_Success != OSA_MutexLock(&tsiState->lock, OSA_WAIT_FOREVER))
    {
        return kStatus_TSI_Error;
    }

    if (tsiState->status != kStatus_TSI_LowPower)
    {
        /* End of critical section. */
        OSA_MutexUnlock(&tsiState->lock);

        return tsiState->status;
    }

    TSI_HAL_DisableLowPower(base);
    TSI_HAL_EnableInterrupt(base);
    TSI_HAL_EnableEndOfScanInterrupt(base);
    TSI_HAL_EnableSoftwareTriggerScan(base);

    tsiState->status = kStatus_TSI_Initialized;

    /* End of critical section. */
    OSA_MutexUnlock(&tsiState->lock);

    status = TSI_DRV_ChangeMode(instance, mode);

    return status;
}
コード例 #12
0
ファイル: host_mcu_interface_tx.c プロジェクト: Btar/HEXIWEAR
/**
 * send data packet
 * @param pHostInterface_packet [description]
 */
static void HostInterface_FlushPacket(hostInterface_packet_t * pHostInterface_packet)
{
  osa_status_t
    status = OSA_MutexLock(&uartTxAccessMutex, OSA_WAIT_FOREVER );

  if ( kStatus_OSA_Success == status )
  {
#if defined( SEND_PACKETS_VIA_UART_INT )
    UART_DRV_SendDataBlocking( gHostInterface_instance, (uint8_t*)pHostInterface_packet, pHostInterface_packet->length + gHostInterface_headerSize + 1, UART_TIMEOUT );
#elif defined( SEND_PACKETS_VIA_UART_DMA )
    UART_DRV_EdmaSendDataBlocking( gHostInterface_instance, (uint8_t*)pHostInterface_packet, pHostInterface_packet->length + gHostInterface_headerSize + 1, UART_TIMEOUT );
#endif

#if defined( HEXIWEAR_DEBUG )
//    UART_DRV_SendDataBlocking( HEXIWEAR_DEBUG_UART_INSTANCE, (uint8_t*)pHostInterface_packet, pHostInterface_packet->length + gHostInterface_headerSize + 1, UART_TIMEOUT );
#endif
  }

  OSA_MutexUnlock(&uartTxAccessMutex);
}
コード例 #13
0
/*FUNCTION**********************************************************************
*
* Function Name : TSI_DRV_AbortMeasure
* Description   : This function aborts possible measure cycle.
*
*END**************************************************************************/
tsi_status_t TSI_DRV_AbortMeasure(uint32_t instance)
{
    assert(instance < TSI_INSTANCE_COUNT);

    TSI_Type * base = g_tsiBase[instance];
    tsi_status_t  status = kStatus_TSI_Success;
    tsi_state_t * tsiState = g_tsiStatePtr[instance];

    /* Critical section. Access to global variable */
    if (kStatus_OSA_Success != OSA_MutexLock(&tsiState->lock, OSA_WAIT_FOREVER))
    {
        return kStatus_TSI_Error;
    }

    if(tsiState->status == kStatus_TSI_Recalibration)
    {
       status = kStatus_TSI_Recalibration;
    }
    else if(tsiState->status != kStatus_TSI_Initialized)
    {
        TSI_HAL_ClearOutOfRangeFlag(base);
        TSI_HAL_ClearEndOfScanFlag(base);
        TSI_HAL_DisableModule(base);

        if(tsiState->isBlockingMeasure)
        {
            /* Signal the synchronous completion object. */
            OSA_SemaPost(&tsiState->irqSync);
            tsiState->isBlockingMeasure = false;
        }

        /* Return status of the driver to initialized state */
        tsiState->status = kStatus_TSI_Initialized;
    }

    /* End of critical section. */
    OSA_MutexUnlock(&tsiState->lock);

    return status;
}
コード例 #14
0
/**
 * send data packet
 * @param pHostInterface_packet [description]
 */
static void HostInterface_FlushPacket(hostInterface_packet_t * pHostInterface_packet)
{
  osa_status_t
    status = OSA_MutexLock(&uartTxAccessMutex, OSA_WAIT_FOREVER );

  if ( kStatus_OSA_Success == status )
  {
#if defined( SEND_VIA_UART_INT )

    GPIO_DRV_TogglePinOutput( PROBE_PIN );
    UART_DRV_SendDataBlocking( gHostInterface_instance, (uint8_t*)pHostInterface_packet, pHostInterface_packet->length + gHostInterface_headerSize + 1, 10 );

#elif defined( SEND_VIA_UART_DMA )
    UART_DRV_EdmaSendDataBlocking( gHostInterface_instance, (uint8_t*)pHostInterface_packet, pHostInterface_packet->length + gHostInterface_headerSize + 1, 100 );
#endif

#if defined( HEXIWEAR_DEBUG )
      UART_DRV_SendDataBlocking( HEXIWEAR_DEBUG_INSTANCE, (uint8_t*)pHostInterface_packet, pHostInterface_packet->length + gHostInterface_headerSize + 1, 100 );
    }
#endif

    OSA_MutexUnlock(&uartTxAccessMutex);
  }
コード例 #15
0
/*FUNCTION**********************************************************************
*
* Function Name : TSI_DRV_SaveConfiguration
* Description   : The function save the configuration for one mode of operation.
*
*END**************************************************************************/
tsi_status_t TSI_DRV_SaveConfiguration(uint32_t instance, const tsi_modes_t mode, tsi_operation_mode_t * operationMode)
{
    assert(instance < TSI_INSTANCE_COUNT);
    assert(operationMode);
    tsi_state_t * tsiState = g_tsiStatePtr[instance];
    
    if(mode >= tsi_OpModeCnt)
    {
        return kStatus_TSI_InvalidMode;
    }

    /* Critical section. Access to global variable */
    if (kStatus_OSA_Success != OSA_MutexLock(&tsiState->lock, OSA_WAIT_FOREVER))
    {
        return kStatus_TSI_Error;
    }

    *operationMode =  tsiState->opModesData[mode];

    /* End of critical section. */
    OSA_MutexUnlock(&tsiState->lock);

    return  kStatus_TSI_Success;
}
コード例 #16
0
ファイル: fsl_hwtimer_pit.c プロジェクト: 70year/MICO
/*!
 * @cond DOXYGEN_PRIVATE
 *
 * @brief This function initializes caller allocated structure according to given
 * numerical identifier of the timer.
 *
 * Called by hwtimer_init().
 * Initializes the HWTIMER structure.
 * Sets interrupt priority and registers ISR.
 *
 * @param hwtimer[in]   Returns initialized hwtimer structure handle.
 * @param pitId[in]     Determines PIT module and pit channel.
 * @param isrPrior[in]  Interrupt priority for PIT
 * @param data[in]      Specific data. Not used in this timer.
 *
 * @return kHwtimerSuccess              Success.
 * @return kHwtimerInvalidInput         When channel number does not exist in pit module.
 * @return kHwtimerLockError            When Locking failed.
 * @return kHwtimerRegisterHandlerError When registration of the interrupt service routine failed.
 *
 * @see HWTIMER_SYS_PitDeinit
 * @see HWTIMER_SYS_PitSetDiv
 * @see HWTIMER_SYS_PitStart
 * @see HWTIMER_SYS_PitStop
 * @see HWTIMER_SYS_PitGetTime
 * @see HWTIMER_SYS_PitIsr
 * @see HWTIMER_SYS_PitIsrShared
 */
static _hwtimer_error_code_t HWTIMER_SYS_PitInit(hwtimer_t * hwtimer, uint32_t pitId, uint32_t isrPrior, void *data)
{
    uint32_t pitChannel;
    uint32_t baseAddr = g_pitBaseAddr[0];
    if (FSL_FEATURE_PIT_TIMER_COUNT < pitId)
    {
        return kHwtimerInvalidInput;
    }

    assert(NULL != hwtimer);

    /* We need to store pitId of timer in context struct */
    hwtimer->llContext[0U] = pitId;

    pitChannel = hwtimer->llContext[0U];

   /* Un-gate pit clock */
    CLOCK_SYS_EnablePitClock(0U);

    /* Enable PIT module clock */
    PIT_HAL_Enable(baseAddr);

    /* Allows the timers to be stopped when the device enters the Debug mode. */
    PIT_HAL_SetTimerRunInDebugCmd(baseAddr, false);

    /* Disable timer and interrupt */
    PIT_HAL_StopTimer(baseAddr, pitChannel);
    PIT_HAL_SetIntCmd(baseAddr, pitChannel, false);
    /* Clear any pending interrupt */
    PIT_HAL_ClearIntFlag(baseAddr, pitChannel);

    /* Create lock if does not exists*/
    /* Enter critical section to avoid interrupt create locking */
    OSA_EnterCritical(kCriticalDisableInt);
    if (g_lock == NULL)
    {
        /* Initialize synchronization object */
        if (kStatus_OSA_Success != OSA_MutexCreate(&g_lock_data))
        {
            return kHwtimerLockError;
        }
        g_lock = &g_lock_data;
    }
    OSA_ExitCritical(kCriticalDisableInt);
    assert(g_lock == &g_lock_data);

    /* Critical section. Access to global variable */
    if (kStatus_OSA_Success != OSA_MutexLock(g_lock, OSA_WAIT_FOREVER))
    {
        return kHwtimerLockError;
    }
    /* Store hwtimer in global array */
    g_hwtimersPit[pitChannel] = hwtimer;

    if (kStatus_OSA_Success != OSA_MutexUnlock(g_lock))
    {
        return kHwtimerLockError;
    }

    /* Enable PIT interrupt.*/
    if (kStatus_OSA_Success != OSA_InstallIntHandler(kpitIrqIds[pitChannel], HWTIMER_SYS_PitIsr))
    {
        return kHwtimerRegisterHandlerError;
    }

    PIT_HAL_SetIntCmd(baseAddr, pitChannel, true);
    INT_SYS_EnableIRQ(kpitIrqIds[pitChannel]);

    return kHwtimerSuccess;
}
コード例 #17
0
/*FUNCTION**********************************************************************
*
* Function Name : TSI_DRV_Init
* Description   : Initialize whole the TSI peripheral to be ready to read capacitance changes
* To initialize the TSI driver, the configuration structure should be handled.
*
*END**************************************************************************/
tsi_status_t TSI_DRV_Init(uint32_t instance, tsi_state_t * tsiState, const tsi_user_config_t * tsiUserConfig)
{
    assert(instance < TSI_INSTANCE_COUNT);

    TSI_Type * base = g_tsiBase[instance];
    tsi_state_t * tsiSt = g_tsiStatePtr[instance];

    /* Critical section. */
    OSA_EnterCritical(kCriticalDisableInt);

    /* Exit if current instance is already initialized. */
    if(tsiSt)
    {
        /* End of critical section. */
        OSA_ExitCritical(kCriticalDisableInt);
        return kStatus_TSI_Initialized;
    }
    /* Save runtime structure pointer.*/
    tsiSt = g_tsiStatePtr[instance] = tsiState;

    /* Clear the state structure for this instance. */
    memset(tsiSt, 0, sizeof(tsi_state_t));

    /* Create the mutex used by whole driver. */
    OSA_MutexCreate(&tsiSt->lock);
    /* Create the mutex used by change mode function. */
    OSA_MutexCreate(&tsiSt->lockChangeMode);
    
    /* Critical section. Access to global variable */
    if (kStatus_OSA_Success != OSA_MutexLock(&tsiSt->lock, OSA_WAIT_FOREVER))
    {
        /* End of critical section. */
        OSA_ExitCritical(kCriticalDisableInt);  
        return kStatus_TSI_Error;
    }

    /* End of critical section. */
    OSA_ExitCritical(kCriticalDisableInt);

    tsiSt->opMode = tsi_OpModeNormal;

    tsiSt->opModesData[tsiSt->opMode].config = *tsiUserConfig->config; /* Store the hardware configuration. */

    tsiSt->pCallBackFunc = tsiUserConfig->pCallBackFunc;
    tsiSt->usrData = tsiUserConfig->usrData;
    tsiSt->isBlockingMeasure = false;
    /* Un-gate TSI module clock */
    CLOCK_SYS_EnableTsiClock(instance);

    /* Initialize the interrupt sync object. */
    OSA_SemaCreate(&tsiSt->irqSync, 0);

    TSI_HAL_Init(base);
    TSI_HAL_SetConfiguration(base, &tsiSt->opModesData[tsiSt->opMode].config);
    TSI_HAL_EnableInterrupt(base);
    TSI_HAL_EnableEndOfScanInterrupt(base);
    TSI_HAL_EnableSoftwareTriggerScan(base);

    /* Disable all electrodes */
    tsiState->opModesData[tsiState->opMode].enabledElectrodes = 0;

    /* Enable TSI interrupt on NVIC level. */
    INT_SYS_EnableIRQ(g_tsiIrqId[instance]);

    tsiSt->status = kStatus_TSI_Initialized;

    /* End of critical section. */
    OSA_MutexUnlock(&tsiSt->lock);

    return kStatus_TSI_Success;
}
コード例 #18
0
/*FUNCTION**********************************************************************
*
* Function Name : TSI_DRV_EnableLowPower
* Description   : Enables/Disables the low power module.
*
*END**************************************************************************/
tsi_status_t TSI_DRV_EnableLowPower(uint32_t instance)
{
    assert(instance < TSI_INSTANCE_COUNT);

    TSI_Type * base = g_tsiBase[instance];
    tsi_state_t * tsiState = g_tsiStatePtr[instance];
    tsi_status_t status;
    uint32_t i;
    int32_t channel = -1;

    /* Critical section. Access to global variable */
    if (kStatus_OSA_Success != OSA_MutexLock(&tsiState->lock, OSA_WAIT_FOREVER))
    {
        return kStatus_TSI_Error;
    }
    
    if((tsiState->opModesData[tsiState->opMode].config.thresl == 0) || (tsiState->opModesData[tsiState->opMode].config.thresh == 0))
    {
        /* End of critical section. */
        OSA_MutexUnlock(&tsiState->lock);

        return kStatus_TSI_Error;
    }
    
    if ((status = TSI_DRV_ChangeMode(instance, tsi_OpModeLowPower)) != kStatus_TSI_Success)
    {
        /* End of critical section. */
        OSA_MutexUnlock(&tsiState->lock);

        return status;
    }

    if(tsiState->opModesData[tsiState->opMode].enabledElectrodes == 0)
    {
        /* End of critical section. */
        OSA_MutexUnlock(&tsiState->lock);

        return kStatus_TSI_InvalidChannel;
    }

    /* Configurate the peripheral for next use */
    TSI_HAL_EnableOutOfRangeInterrupt(base);
    TSI_HAL_EnableHardwareTriggerScan(base);

    for(i = 0; i < FSL_FEATURE_TSI_CHANNEL_COUNT; i++)
    {
        if((uint32_t)(1 << i) & tsiState->opModesData[tsiState->opMode].enabledElectrodes)
        {
            channel = i;
            break;
        }
    }

    if(channel == -1)
    {
        /* End of critical section. */
        OSA_MutexUnlock(&tsiState->lock);

        return kStatus_TSI_InvalidChannel;  
    }
    
    tsiState->status = kStatus_TSI_LowPower;
    
    TSI_HAL_EnableLowPower(base);
    TSI_HAL_SetMeasuredChannelNumber(base, channel);
    TSI_HAL_EnableInterrupt(base);
    TSI_HAL_EnableModule(base);
    
    /* End of critical section. */
    OSA_MutexUnlock(&tsiState->lock);

    return kStatus_TSI_Success;
}
コード例 #19
0
uint32_t OS_Mutex_unlock(os_mutex_handle handle)
{
    return ((kStatus_OSA_Success == OSA_MutexUnlock((mutex_t*) (handle))) ? OS_MUTEX_OK : OS_MUTEX_ERROR);
}